Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHCh Upgrade: Improved FTDI and CP210x support, add PL2303 support, bugfixes #2488

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b9c44ee
improved tusb_config.h comment
heikokue Feb 10, 2024
ab6b9e3
Merge remote-tracking branch 'remotes/hathach/master' into cdch_upgrade
heikokue Feb 22, 2024
069c68a
sorted driver functions into Control Request, Driver API, Enumeration…
heikokue Feb 23, 2024
47777a6
improved TU_LOGs
heikokue Feb 20, 2024
829ea52
splitted cdch_internal_control_complete() into driver's _internal_con…
heikokue Feb 22, 2024
2f50f5a
changed to use of p_cdc->requested_line_coding
heikokue Feb 22, 2024
7dd435c
changed to use of p_cdc->requested_line_state
heikokue Feb 20, 2024
dcadf8c
created set_function_call()
heikokue Feb 22, 2024
ea86bbe
added continue enum after config fail
heikokue Feb 21, 2024
22a12c7
improved ACM checks
heikokue Feb 22, 2024
138567a
fixed #2448 CH34x ch34x_set_line_coding() callback bug
heikokue Feb 18, 2024
db511fb
fixed CFG_TUH_CDC_LINE_CONTROL_ON_ENUM handling. only set if defined.…
heikokue Feb 19, 2024
0b5f85e
created set_line_coding_sequence() and void set_line_coding_stage1_co…
heikokue Feb 21, 2024
7fef594
improved FTDI support
heikokue Feb 24, 2024
4547737
improved CP210x support
heikokue Feb 22, 2024
aabee25
added PL2303 support
heikokue Feb 22, 2024
ea175a7
updated contribution, readme and some comments
heikokue Feb 24, 2024
2b507db
small changes & code style
heikokue Feb 24, 2024
da93fcf
improved TU_LOGs
heikokue Feb 22, 2024
46a861b
improved PL2303 TU_LOGs
heikokue Feb 23, 2024
af5e75c
Merge remote-tracking branch 'remotes/hathach/master' into cdch_upgrade
heikokue Feb 24, 2024
7f7576f
Merge remote-tracking branch 'remotes/hathach/master' into cdch_upgrade
heikokue Feb 29, 2024
f97e312
FTDI fixed itf_num and some improvement
heikokue Feb 28, 2024
d3d61da
improved & fixed compiler warnings device descriptor handling
heikokue Feb 25, 2024
edf1320
removed expendable ACM check
heikokue Feb 28, 2024
3cf9cb9
small PL2303 improvements
heikokue Feb 28, 2024
e7308e3
improved TU_LOGs
heikokue Feb 28, 2024
e6d27b6
fixed IAR compile error
heikokue Feb 29, 2024
dea27d2
added explicite (uint16_t) casts inside tu_htole16()
heikokue Feb 29, 2024
e055104
added use of cdc_line_control_state_t type in CDCh
heikokue Mar 3, 2024
a9cc07f
added line control function using cdc_line_control_state_t
heikokue Mar 10, 2024
ee92e58
added defines CFG_TUH_CDC_DTR_CONTROL_ON_ENUM & CFG_TUH_CDC_RTS_CONTR…
heikokue Mar 3, 2024
2786a61
fixed FTDI set control line
heikokue Mar 3, 2024
cb69ed0
code style and clean up CDC serial header files
heikokue Mar 21, 2024
1bbd658
Merge remote-tracking branch 'remotes/hathach/master' into work
heikokue Mar 21, 2024
e2a5630
Merge remote-tracking branch 'remotes/hathach/master' into cdch_upgrade
heikokue Apr 4, 2024
5e67b92
fixed compile warnings
heikokue Apr 4, 2024
e07ee4a
CP210x removed baudrate check, fixed data bits check
heikokue Apr 4, 2024
a1b1c1f
foxed FTDI flow control config
heikokue Apr 4, 2024
e02a309
disable PL2303 flow control config
heikokue Apr 4, 2024
68602e4
small change process config complete
heikokue Apr 4, 2024
0c5e14c
updated doc
heikokue Apr 4, 2024
f00e698
Merge remote-tracking branch 'remotes/hathach/master' into cdch_upgrade
heikokue Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions CONTRIBUTORS.rst
Expand Up @@ -31,6 +31,13 @@ Notable contributors
- Most features development


`Heiko Kuester <https://github.com/IngHK>`__
--------------------------------------------

- Add CH34x and PL2303 support (CDC host)
- Improve FTDI and CP210x support (CDC host)


`Hristo Gochkov <https://github.com/me-no-dev>`__
-------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -77,7 +77,7 @@ Host Stack
- Human Interface Device (HID): Keyboard, Mouse, Generic
- Mass Storage Class (MSC)
- Communication Device Class: CDC-ACM
- Vendor serial over USB: FTDI, CP210x
- Vendor serial over USB: FTDI, CP210x, CH34x, PL2303
- Hub with multiple-level support

Similar to the Device Stack, if you have a special requirement, `usbh_app_driver_get_cb()` can be used to write your own class driver without modifying the stack.
Expand Down
3 changes: 2 additions & 1 deletion examples/host/cdc_msc_hid/src/tusb_config.h
Expand Up @@ -102,10 +102,11 @@
#define CFG_TUH_ENUMERATION_BUFSIZE 256

#define CFG_TUH_HUB 1 // number of supported hubs
#define CFG_TUH_CDC 1 // CDC ACM
#define CFG_TUH_CDC 1 // number of supported CDC devices. also activates CDC ACM
#define CFG_TUH_CDC_FTDI 1 // FTDI Serial. FTDI is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_CDC_CP210X 1 // CP210x Serial. CP210X is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_CDC_CH34X 1 // CH340 or CH341 Serial. CH34X is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_CDC_PL2303 1 // PL2303 Serial. PL2303 is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX) // typical keyboard + mouse device can have 3-4 HID interfaces
#define CFG_TUH_MSC 1
#define CFG_TUH_VENDOR 0
Expand Down
3 changes: 2 additions & 1 deletion examples/host/cdc_msc_hid_freertos/src/tusb_config.h
Expand Up @@ -107,10 +107,11 @@
#define CFG_TUH_ENUMERATION_BUFSIZE 256

#define CFG_TUH_HUB 1 // number of supported hubs
#define CFG_TUH_CDC 1 // CDC ACM
#define CFG_TUH_CDC 1 // number of supported CDC devices. also activates CDC ACM
#define CFG_TUH_CDC_FTDI 1 // FTDI Serial. FTDI is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_CDC_CP210X 1 // CP210x Serial. CP210X is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_CDC_CH34X 1 // CH340 or CH341 Serial. CH34X is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_CDC_PL2303 1 // PL2303 Serial. PL2303 is not part of CDC class, only to re-use CDC driver API
#define CFG_TUH_HID (3*CFG_TUH_DEVICE_MAX) // typical keyboard + mouse device can have 3-4 HID interfaces
#define CFG_TUH_MSC 1
#define CFG_TUH_VENDOR 0
Expand Down
3,020 changes: 2,135 additions & 885 deletions src/class/cdc/cdc_host.c

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions src/class/cdc/cdc_host.h
Expand Up @@ -37,16 +37,6 @@
// Class Driver Configuration
//--------------------------------------------------------------------+

// Set Line Control state on enumeration/mounted: DTR ( bit 0), RTS (bit 1)
#ifndef CFG_TUH_CDC_LINE_CONTROL_ON_ENUM
#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0
#endif

// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t
//#ifndef CFG_TUH_CDC_LINE_CODING_ON_ENUM
//#define CFG_TUH_CDC_LINE_CODING_ON_ENUM { 115200, CDC_LINE_CODING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 }
//#endif

// RX FIFO size
#ifndef CFG_TUH_CDC_RX_BUFSIZE
#define CFG_TUH_CDC_RX_BUFSIZE USBH_EPSIZE_BULK_MAX
Expand Down
63 changes: 62 additions & 1 deletion src/class/cdc/serial/cp210x.h
Expand Up @@ -28,7 +28,8 @@
// Protocol details can be found at AN571: CP210x Virtual COM Port Interface
// https://www.silabs.com/documents/public/application-notes/AN571.pdf

#define TU_CP210X_VID 0x10C4
// parts are overtaken from vendors driver
// https://www.silabs.com/documents/public/software/cp210x-3.1.0.tar.gz

/* Config request codes */
#define CP210X_IFC_ENABLE 0x00
Expand Down Expand Up @@ -59,4 +60,64 @@
#define CP210X_SET_BAUDRATE 0x1E
#define CP210X_VENDOR_SPECIFIC 0xFF // GPIO, Recipient must be Device

/* SILABSER_IFC_ENABLE_REQUEST_CODE */
#define CP210X_UART_ENABLE 0x0001
#define CP210X_UART_DISABLE 0x0000

/* SILABSER_SET_BAUDDIV_REQUEST_CODE */
#define CP210X_BAUD_RATE_GEN_FREQ 0x384000

/*SILABSER_SET_LINE_CTL_REQUEST_CODE */
#define CP210X_BITS_DATA_MASK 0x0f00
#define CP210X_BITS_DATA_5 0x0500
#define CP210X_BITS_DATA_6 0x0600
#define CP210X_BITS_DATA_7 0x0700
#define CP210X_BITS_DATA_8 0x0800
#define CP210X_BITS_DATA_9 0x0900

#define CP210X_BITS_PARITY_MASK 0x00f0
#define CP210X_BITS_PARITY_NONE 0x0000
#define CP210X_BITS_PARITY_ODD 0x0010
#define CP210X_BITS_PARITY_EVEN 0x0020
#define CP210X_BITS_PARITY_MARK 0x0030
#define CP210X_BITS_PARITY_SPACE 0x0040

#define CP210X_BITS_STOP_MASK 0x000f
#define CP210X_BITS_STOP_1 0x0000
#define CP210X_BITS_STOP_1_5 0x0001
#define CP210X_BITS_STOP_2 0x0002

/* SILABSER_SET_BREAK_REQUEST_CODE */
#define CP210X_BREAK_ON 0x0001
#define CP210X_BREAK_OFF 0x0000

/* SILABSER_SET_MHS_REQUEST_CODE */
#define CP210X_MCR_DTR 0x0001
#define CP210X_MCR_RTS 0x0002
#define CP210X_MCR_ALL 0x0003
#define CP210X_MSR_CTS 0x0010
#define CP210X_MSR_DSR 0x0020
#define CP210X_MSR_RING 0x0040
#define CP210X_MSR_DCD 0x0080
#define CP210X_MSR_ALL 0x00F0

#define CP210X_CONTROL_WRITE_DTR 0x0100
#define CP210X_CONTROL_WRITE_RTS 0x0200

#define CP210X_LSR_BREAK 0x0001
#define CP210X_LSR_FRAMING_ERROR 0x0002
#define CP210X_LSR_HW_OVERRUN 0x0004
#define CP210X_LSR_QUEUE_OVERRUN 0x0008
#define CP210X_LSR_PARITY_ERROR 0x0010
#define CP210X_LSR_ALL 0x001F

// supported baudrates
// reference: datasheets and AN205 "CP210x Baud Rate Support"
#define CP210X_SUPPORTED_BAUDRATES_LIST { \
300, 600, \
1200, 1800, 2400, 4000, 4800, 7200, 9600, \
14400, 16000, 19200, 28800, 38400, 51200, 56000, 57600, 64000, 76800, \
115200, 128000, 153600, 230400, 250000, 256000, 460800, 500000, 576000, 921600, \
0 }

#endif //TUSB_CP210X_H