mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-15 21:40:18 +00:00
- add new API tuh_cdc_set_data_format()
- add typedef for cdc enum
This commit is contained in:
parent
c196a2ed9c
commit
55cb713264
@ -136,8 +136,7 @@ typedef enum{
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// Communication Interface Management Element Request Codes
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
CDC_REQUEST_SEND_ENCAPSULATED_COMMAND = 0x00, ///< is used to issue a command in the format of the supported control protocol of the Communications Class interface
|
||||
CDC_REQUEST_GET_ENCAPSULATED_RESPONSE = 0x01, ///< is used to request a response in the format of the supported control protocol of the Communications Class interface.
|
||||
CDC_REQUEST_SET_COMM_FEATURE = 0x02,
|
||||
@ -180,39 +179,38 @@ typedef enum
|
||||
CDC_REQUEST_GET_ATM_VC_STATISTICS = 0x53,
|
||||
|
||||
CDC_REQUEST_MDLM_SEMANTIC_MODEL = 0x60,
|
||||
}cdc_management_request_t;
|
||||
} cdc_management_request_t;
|
||||
|
||||
enum {
|
||||
typedef enum {
|
||||
CDC_CONTROL_LINE_STATE_DTR = 0x01,
|
||||
CDC_CONTROL_LINE_STATE_RTS = 0x02,
|
||||
};
|
||||
} cdc_control_line_state_t;
|
||||
|
||||
enum {
|
||||
typedef enum {
|
||||
CDC_LINE_CODING_STOP_BITS_1 = 0, // 1 bit
|
||||
CDC_LINE_CODING_STOP_BITS_1_5 = 1, // 1.5 bits
|
||||
CDC_LINE_CODING_STOP_BITS_2 = 2, // 2 bits
|
||||
};
|
||||
} cdc_line_coding_stopbits_t;
|
||||
|
||||
// TODO Backward compatible for typos. Maybe removed in the future release
|
||||
#define CDC_LINE_CONDING_STOP_BITS_1 CDC_LINE_CODING_STOP_BITS_1
|
||||
#define CDC_LINE_CONDING_STOP_BITS_1_5 CDC_LINE_CODING_STOP_BITS_1_5
|
||||
#define CDC_LINE_CONDING_STOP_BITS_2 CDC_LINE_CODING_STOP_BITS_2
|
||||
|
||||
enum {
|
||||
typedef enum {
|
||||
CDC_LINE_CODING_PARITY_NONE = 0,
|
||||
CDC_LINE_CODING_PARITY_ODD = 1,
|
||||
CDC_LINE_CODING_PARITY_EVEN = 2,
|
||||
CDC_LINE_CODING_PARITY_MARK = 3,
|
||||
CDC_LINE_CODING_PARITY_SPACE = 4,
|
||||
};
|
||||
} cdc_line_coding_parity_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Management Element Notification (Notification Endpoint)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
/// 6.3 Notification Codes
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
CDC_NOTIF_NETWORK_CONNECTION = 0x00, ///< This notification allows the device to notify the host about network connection status.
|
||||
CDC_NOTIF_RESPONSE_AVAILABLE = 0x01, ///< This notification allows the device to notify the hostthat a response is available. This response can be retrieved with a subsequent \ref CDC_REQUEST_GET_ENCAPSULATED_RESPONSE request.
|
||||
CDC_NOTIF_AUX_JACK_HOOK_STATE = 0x08,
|
||||
|
@ -90,9 +90,10 @@ static cdch_interface_t cdch_data[CFG_TUH_CDC];
|
||||
static bool acm_open(uint8_t daddr, tusb_desc_interface_t const *itf_desc, uint16_t max_len);
|
||||
static void acm_process_config(tuh_xfer_t* xfer);
|
||||
|
||||
static bool acm_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool acm_set_data_format(cdch_interface_t* p_cdc, uint8_t stop_bits, uint8_t parity, uint8_t data_bits, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool acm_set_line_coding(cdch_interface_t* p_cdc, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool acm_set_control_line_state(cdch_interface_t* p_cdc, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool acm_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
|
||||
//------------- FTDI prototypes -------------//
|
||||
#if CFG_TUH_CDC_FTDI
|
||||
@ -100,15 +101,13 @@ static bool acm_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfe
|
||||
|
||||
static uint16_t const ftdi_vid_pid_list[][2] = {CFG_TUH_CDC_FTDI_VID_PID_LIST};
|
||||
|
||||
// Store last request baudrate since divisor to baudrate is not easy
|
||||
// static uint32_t _ftdi_requested_baud;
|
||||
|
||||
static bool ftdi_open(uint8_t daddr, const tusb_desc_interface_t *itf_desc, uint16_t max_len);
|
||||
static void ftdi_process_config(tuh_xfer_t* xfer);
|
||||
|
||||
static bool ftdi_sio_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool ftdi_set_data_format(cdch_interface_t* p_cdc, uint8_t stop_bits, uint8_t parity, uint8_t data_bits, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool ftdi_set_line_coding(cdch_interface_t* p_cdc, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool ftdi_sio_set_modem_ctrl(cdch_interface_t* p_cdc, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool ftdi_sio_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
#endif
|
||||
|
||||
//------------- CP210X prototypes -------------//
|
||||
@ -120,9 +119,10 @@ static uint16_t const cp210x_vid_pid_list[][2] = {CFG_TUH_CDC_CP210X_VID_PID_LIS
|
||||
static bool cp210x_open(uint8_t daddr, tusb_desc_interface_t const *itf_desc, uint16_t max_len);
|
||||
static void cp210x_process_config(tuh_xfer_t* xfer);
|
||||
|
||||
static bool cp210x_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool cp210x_set_data_format(cdch_interface_t* p_cdc, uint8_t stop_bits, uint8_t parity, uint8_t data_bits, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool cp210x_set_line_coding(cdch_interface_t* p_cdc, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool cp210x_set_modem_ctrl(cdch_interface_t* p_cdc, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool cp210x_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
#endif
|
||||
|
||||
//------------- CH34x prototypes -------------//
|
||||
@ -131,16 +131,16 @@ static bool cp210x_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_
|
||||
|
||||
static uint16_t const ch34x_vid_pid_list[][2] = {CFG_TUH_CDC_CH34X_VID_PID_LIST};
|
||||
|
||||
static bool ch34x_open ( uint8_t daddr, tusb_desc_interface_t const *itf_desc, uint16_t max_len );
|
||||
static void ch34x_process_config ( tuh_xfer_t* xfer );
|
||||
static bool ch34x_open(uint8_t daddr, tusb_desc_interface_t const* itf_desc, uint16_t max_len);
|
||||
static void ch34x_process_config(tuh_xfer_t* xfer);
|
||||
|
||||
static bool ch34x_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool ch34x_set_data_format(cdch_interface_t* p_cdc, uint8_t stop_bits, uint8_t parity, uint8_t data_bits, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool ch34x_set_line_coding(cdch_interface_t* p_cdc, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
static bool ch34x_set_modem_ctrl ( cdch_interface_t* p_cdc, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data );
|
||||
static bool ch34x_set_baudrate ( cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data );
|
||||
static bool ch34x_set_modem_ctrl(cdch_interface_t* p_cdc, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
#endif
|
||||
|
||||
//------------- Common -------------//
|
||||
|
||||
enum {
|
||||
SERIAL_DRIVER_ACM = 0,
|
||||
|
||||
@ -166,6 +166,7 @@ typedef struct {
|
||||
void (*const process_set_config)(tuh_xfer_t* xfer);
|
||||
bool (*const set_control_line_state)(cdch_interface_t* p_cdc, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
bool (*const set_baudrate)(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
bool (*const set_data_format)(cdch_interface_t* p_cdc, uint8_t stop_bits, uint8_t parity, uint8_t data_bits, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
bool (*const set_line_coding)(cdch_interface_t* p_cdc, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
} cdch_serial_driver_t;
|
||||
|
||||
@ -178,6 +179,7 @@ static const cdch_serial_driver_t serial_drivers[] = {
|
||||
.process_set_config = acm_process_config,
|
||||
.set_control_line_state = acm_set_control_line_state,
|
||||
.set_baudrate = acm_set_baudrate,
|
||||
.set_data_format = acm_set_data_format,
|
||||
.set_line_coding = acm_set_line_coding
|
||||
},
|
||||
|
||||
@ -189,6 +191,7 @@ static const cdch_serial_driver_t serial_drivers[] = {
|
||||
.process_set_config = ftdi_process_config,
|
||||
.set_control_line_state = ftdi_sio_set_modem_ctrl,
|
||||
.set_baudrate = ftdi_sio_set_baudrate,
|
||||
.set_data_format = ftdi_set_data_format,
|
||||
.set_line_coding = ftdi_set_line_coding
|
||||
},
|
||||
#endif
|
||||
@ -201,6 +204,7 @@ static const cdch_serial_driver_t serial_drivers[] = {
|
||||
.process_set_config = cp210x_process_config,
|
||||
.set_control_line_state = cp210x_set_modem_ctrl,
|
||||
.set_baudrate = cp210x_set_baudrate,
|
||||
.set_data_format = cp210x_set_data_format,
|
||||
.set_line_coding = cp210x_set_line_coding
|
||||
},
|
||||
#endif
|
||||
@ -213,6 +217,7 @@ static const cdch_serial_driver_t serial_drivers[] = {
|
||||
.process_set_config = ch34x_process_config,
|
||||
.set_control_line_state = ch34x_set_modem_ctrl,
|
||||
.set_baudrate = ch34x_set_baudrate,
|
||||
.set_data_format = ch34x_set_data_format,
|
||||
.set_line_coding = ch34x_set_line_coding
|
||||
},
|
||||
#endif
|
||||
@ -562,6 +567,32 @@ bool tuh_cdc_set_baudrate(uint8_t idx, uint32_t baudrate, tuh_xfer_cb_t complete
|
||||
}
|
||||
}
|
||||
|
||||
bool tuh_cdc_set_data_format(uint8_t idx, uint8_t stop_bits, uint8_t parity, uint8_t data_bits,
|
||||
tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
|
||||
cdch_interface_t* p_cdc = get_itf(idx);
|
||||
TU_VERIFY(p_cdc && p_cdc->serial_drid < SERIAL_DRIVER_COUNT);
|
||||
cdch_serial_driver_t const* driver = &serial_drivers[p_cdc->serial_drid];
|
||||
|
||||
if (complete_cb) {
|
||||
return driver->set_data_format(p_cdc, stop_bits, parity, data_bits, complete_cb, user_data);
|
||||
} else {
|
||||
// blocking
|
||||
xfer_result_t result = XFER_RESULT_INVALID;
|
||||
bool ret = driver->set_data_format(p_cdc, stop_bits, parity, data_bits, complete_cb, (uintptr_t) &result);
|
||||
|
||||
if (user_data) {
|
||||
// user_data is not NULL, return result via user_data
|
||||
*((xfer_result_t*) user_data) = result;
|
||||
}
|
||||
|
||||
TU_VERIFY(ret && result == XFER_RESULT_SUCCESS);
|
||||
p_cdc->line_coding.stop_bits = stop_bits;
|
||||
p_cdc->line_coding.parity = parity;
|
||||
p_cdc->line_coding.data_bits = data_bits;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool tuh_cdc_set_line_coding(uint8_t idx, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
|
||||
cdch_interface_t* p_cdc = get_itf(idx);
|
||||
TU_VERIFY(p_cdc && p_cdc->serial_drid < SERIAL_DRIVER_COUNT);
|
||||
@ -900,6 +931,19 @@ static bool acm_set_line_coding(cdch_interface_t* p_cdc, cdc_line_coding_t const
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool acm_set_data_format(cdch_interface_t* p_cdc, uint8_t stop_bits, uint8_t parity, uint8_t data_bits,
|
||||
tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
|
||||
TU_LOG_DRV("CDC ACM Set Data Format\r\n");
|
||||
|
||||
cdc_line_coding_t line_coding;
|
||||
line_coding.bit_rate = p_cdc->line_coding.bit_rate;
|
||||
line_coding.stop_bits = stop_bits;
|
||||
line_coding.parity = parity;
|
||||
line_coding.data_bits = data_bits;
|
||||
|
||||
return acm_set_line_coding(p_cdc, &line_coding, complete_cb, user_data);
|
||||
}
|
||||
|
||||
static bool acm_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
|
||||
TU_VERIFY(p_cdc->acm_capability.support_line_request);
|
||||
cdc_line_coding_t line_coding = p_cdc->line_coding;
|
||||
@ -968,6 +1012,18 @@ static bool ftdi_sio_reset(cdch_interface_t* p_cdc, tuh_xfer_cb_t complete_cb, u
|
||||
return ftdi_sio_set_request(p_cdc, FTDI_SIO_RESET, FTDI_SIO_RESET_SIO, complete_cb, user_data);
|
||||
}
|
||||
|
||||
static bool ftdi_set_data_format(cdch_interface_t* p_cdc, uint8_t stop_bits, uint8_t parity, uint8_t data_bits,
|
||||
tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
|
||||
(void) p_cdc;
|
||||
(void) stop_bits;
|
||||
(void) parity;
|
||||
(void) data_bits;
|
||||
(void) complete_cb;
|
||||
(void) user_data;
|
||||
// TODO not implemented yet
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ftdi_set_line_coding(cdch_interface_t* p_cdc, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
|
||||
(void) p_cdc;
|
||||
(void) line_coding;
|
||||
@ -1161,6 +1217,18 @@ static bool cp210x_set_baudrate(cdch_interface_t* p_cdc, uint32_t baudrate, tuh_
|
||||
complete_cb ? cdch_internal_control_complete : NULL, user_data);
|
||||
}
|
||||
|
||||
static bool cp210x_set_data_format(cdch_interface_t* p_cdc, uint8_t stop_bits, uint8_t parity, uint8_t data_bits,
|
||||
tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
|
||||
(void) p_cdc;
|
||||
(void) stop_bits;
|
||||
(void) parity;
|
||||
(void) data_bits;
|
||||
(void) complete_cb;
|
||||
(void) user_data;
|
||||
// TODO not implemented yet
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool cp210x_set_modem_ctrl(cdch_interface_t* p_cdc, uint16_t line_state, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
|
||||
TU_LOG_DRV("CDC CP210x Set Control Line State\r\n");
|
||||
p_cdc->user_control_cb = complete_cb;
|
||||
|
@ -148,8 +148,11 @@ bool tuh_cdc_set_control_line_state(uint8_t idx, uint16_t line_state, tuh_xfer_c
|
||||
// Request to set baudrate
|
||||
bool tuh_cdc_set_baudrate(uint8_t idx, uint32_t baudrate, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
|
||||
// Request to Set Line Coding (ACM only)
|
||||
// Should only use if you don't work with serial devices such as FTDI/CP210x
|
||||
// Request to set data format
|
||||
bool tuh_cdc_set_data_format(uint8_t idx, uint8_t stop_bits, uint8_t parity, uint8_t data_bits, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
|
||||
// Request to Set Line Coding = baudrate + data format
|
||||
// Note: only implemented by ACM and CH34x, not supported by FTDI and CP210x yet
|
||||
bool tuh_cdc_set_line_coding(uint8_t idx, cdc_line_coding_t const* line_coding, tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||
|
||||
// Request to Get Line Coding (ACM only)
|
||||
@ -159,15 +162,13 @@ bool tuh_cdc_set_line_coding(uint8_t idx, cdc_line_coding_t const* line_coding,
|
||||
|
||||
// Connect by set both DTR, RTS
|
||||
TU_ATTR_ALWAYS_INLINE static inline
|
||||
bool tuh_cdc_connect(uint8_t idx, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
|
||||
{
|
||||
bool tuh_cdc_connect(uint8_t idx, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
|
||||
return tuh_cdc_set_control_line_state(idx, CDC_CONTROL_LINE_STATE_DTR | CDC_CONTROL_LINE_STATE_RTS, complete_cb, user_data);
|
||||
}
|
||||
|
||||
// Disconnect by clear both DTR, RTS
|
||||
TU_ATTR_ALWAYS_INLINE static inline
|
||||
bool tuh_cdc_disconnect(uint8_t idx, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
|
||||
{
|
||||
bool tuh_cdc_disconnect(uint8_t idx, tuh_xfer_cb_t complete_cb, uintptr_t user_data) {
|
||||
return tuh_cdc_set_control_line_state(idx, 0x00, complete_cb, user_data);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user