Skip to content

Commit a82f6bd

Browse files
Updated drivers
1 parent 8c81d02 commit a82f6bd

File tree

8 files changed

+60
-29
lines changed

8 files changed

+60
-29
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
The CH341 and CH340 USB controllers are commonly found on 3rd party Arduinos and to use them with the Arduino IDE or CLI you need to install extra drivers.
44

55
This repo contains the drivers for Windows, macOS, and Linux. Just download the repo and follow the instructions in the corresponding folder. If you have a previously installed a version of these USB drivers, you will likely need to uninstall them before installing the new ones.
6+
7+
| OS | Source URL |
8+
|---------|-----------------------------------------------------|
9+
| Linux | http://www.wch.cn/downloads/CH341SER_LINUX_ZIP.html |
10+
| macOS | http://www.wch.cn/downloads/CH341SER_MAC_ZIP.html |
11+
| Windows | http://www.wch.cn/download/CH341SER_EXE.html |

linux/Makefile

100755100644
File mode changed.

linux/README.txt

100755100644
File mode changed.

linux/ch34x.c

100755100644
Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -329,29 +329,44 @@ static int set_control_lines( struct usb_serial *serial,
329329
}
330330

331331
static int ch34x_get_baud_rate( unsigned int baud_rate,
332-
unsigned char *a, unsigned char *b )
332+
unsigned char *factor, unsigned char *divisor)
333333
{
334-
unsigned long factor = 0;
335-
short divisor = 0;
336-
337-
if( !baud_rate )
338-
return -EINVAL;
339-
340-
factor = (CH34x_BAUDRATE_FACTOR / baud_rate);
341-
divisor = CH34x_BAUDRATE_DIVMAX;
342-
343-
while( (factor > 0xfff0) && divisor ) {
344-
factor >>= 3;
345-
divisor --;
334+
unsigned char a;
335+
unsigned char b;
336+
unsigned long c;
337+
338+
switch ( baud_rate ) {
339+
case 921600:
340+
a = 0xf3;
341+
b = 7;
342+
break;
343+
case 307200:
344+
a = 0xd9;
345+
b = 7;
346+
break;
347+
default:
348+
if ( baud_rate > 6000000/255 ) {
349+
b = 3;
350+
c = 6000000;
351+
} else if ( baud_rate > 750000/255 ) {
352+
b = 2;
353+
c = 750000;
354+
} else if (baud_rate > 93750/255) {
355+
b = 1;
356+
c = 93750;
357+
} else {
358+
b = 0;
359+
c = 11719;
360+
}
361+
a = (unsigned char)(c / baud_rate);
362+
if (a == 0 || a == 0xFF) return -EINVAL;
363+
if ((c / a - baud_rate) > (baud_rate - c / (a + 1)))
364+
a ++;
365+
a = 256 - a;
366+
break;
346367
}
347-
348-
if( factor > 0xfff0 )
349-
return -EINVAL;
350-
351-
factor = 0x10000 - factor;
352-
*a = (factor & 0xff00) >> 8;
353-
*b = divisor;
354-
368+
*factor = a;
369+
*divisor = b;
355370
return 0;
356371
}
357372

@@ -443,15 +458,25 @@ static void ch34x_set_termios( struct usb_serial_port *port,
443458
dbg_ch34x("%s - stop bits = 1", __func__);
444459

445460
// Determine the parity
446-
if( cflag & PARENB )
447-
if( cflag & PARODD ) {
448-
reg_value |= (0x08 | 0x00);
449-
dbg_ch34x("%s - parity = odd", __func__);
450-
}
451-
else {
452-
reg_value |= (0x08 | 0x10);
453-
dbg_ch34x("%s - parity = even", __func__);
461+
if (cflag & PARENB) {
462+
if (cflag & CMSPAR) {
463+
if (cflag & PARODD) {
464+
reg_value |= (0x28 | 0x00);
465+
dbg_ch34x("%s - parity = mark", __func__);
466+
} else {
467+
reg_value |= (0x38 | 0x10);
468+
dbg_ch34x("%s - parity = space", __func__);
469+
}
470+
} else {
471+
if (cflag & PARODD) {
472+
reg_value |= (0x08 | 0x00);
473+
dbg_ch34x("%s - parity = odd", __func__);
474+
} else {
475+
reg_value |= (0x18 | 0x10);
476+
dbg_ch34x("%s - parity = even", __func__);
477+
}
454478
}
479+
}
455480
else
456481
dbg_ch34x("%s - parity = none", __func__);
457482

macos/CH34x_Install_V1.4.pkg

-25.6 KB
Binary file not shown.

macos/CH34x_Install_V1.5.pkg

25.6 KB
Binary file not shown.

macos/README.pdf

100755100644
File mode changed.

windows/CH341SER.EXE

39.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)