29#if (CFG_TUD_ENABLED && CFG_TUD_CDC)
37#ifndef CFG_TUD_CDC_LOG_LEVEL
38 #define CFG_TUD_CDC_LOG_LEVEL CFG_TUD_LOG_LEVEL
41#define TU_LOG_DRV(...) TU_LOG(CFG_TUD_CDC_LOG_LEVEL, __VA_ARGS__)
46#define BULK_PACKET_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
65 uint8_t rx_ff_buf[CFG_TUD_CDC_RX_BUFSIZE];
66 uint8_t tx_ff_buf[CFG_TUD_CDC_TX_BUFSIZE];
72 CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_CDC_EP_BUFSIZE];
73 CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_CDC_EP_BUFSIZE];
76#define ITF_MEM_RESET_SIZE offsetof(cdcd_interface_t, wanted_char)
85 uint8_t
const rhport = 0;
96 TU_VERIFY(available >=
sizeof(p_cdc->epout_buf));
104 if ( available >=
sizeof(p_cdc->epout_buf) ) {
177 #
if CFG_TUD_CDC_TX_BUFSIZE < BULK_PACKET_SIZE
196 uint8_t
const rhport = 0;
202 uint16_t
const count =
tu_fifo_read_n(&p_cdc->tx_ff, p_cdc->epin_buf,
sizeof(p_cdc->epin_buf));
230 for (uint8_t i = 0; i < CFG_TUD_CDC; i++) {
236 p_cdc->line_coding.bit_rate = 115200;
237 p_cdc->line_coding.stop_bits = 0;
238 p_cdc->line_coding.parity = 0;
239 p_cdc->line_coding.data_bits = 8;
242 tu_fifo_config(&p_cdc->rx_ff, p_cdc->rx_ff_buf, TU_ARRAY_SIZE(p_cdc->rx_ff_buf), 1,
false);
247 tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, TU_ARRAY_SIZE(p_cdc->tx_ff_buf), 1,
true);
249 #if OSAL_MUTEX_REQUIRED
252 TU_ASSERT(mutex_rd != NULL && mutex_wr != NULL, );
261 #if OSAL_MUTEX_REQUIRED
262 for(uint8_t i=0; i<CFG_TUD_CDC; i++) {
285 for (uint8_t i = 0; i < CFG_TUD_CDC; i++) {
288 tu_memclr(p_cdc, ITF_MEM_RESET_SIZE);
302 for (uint8_t cdc_id = 0; cdc_id < CFG_TUD_CDC; cdc_id++) {
363 for (;; itf++, p_cdc++) {
364 if (itf >= TU_ARRAY_SIZE(
_cdcd_itf))
return false;
372 TU_LOG_DRV(
" Set Line Coding\r\n");
381 TU_LOG_DRV(
" Get Line Coding\r\n");
403 TU_LOG_DRV(
" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
414 TU_LOG_DRV(
" Send Break\r\n");
433 for (itf = 0; itf < CFG_TUD_CDC; itf++) {
435 if ((ep_addr == p_cdc->
ep_out) || (ep_addr == p_cdc->
ep_in))
break;
437 TU_ASSERT(itf < CFG_TUD_CDC);
440 if (ep_addr == p_cdc->
ep_out) {
441 tu_fifo_write_n(&p_cdc->rx_ff, p_cdc->epout_buf, (uint16_t) xferred_bytes);
445 for (uint32_t i = 0; i < xferred_bytes; i++) {
462 if (ep_addr == p_cdc->
ep_in) {
469 if (!
tu_fifo_count(&p_cdc->tx_ff) && xferred_bytes && (0 == (xferred_bytes & (BULK_PACKET_SIZE - 1)))) {
uint32_t tud_cdc_n_write_flush(uint8_t itf)
uint16_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
bool tud_cdc_n_ready(uint8_t itf)
bool tud_cdc_n_write_clear(uint8_t itf)
static bool _prep_out_transaction(cdcd_interface_t *p_cdc)
void tud_cdc_n_set_wanted_char(uint8_t itf, char wanted)
void cdcd_reset(uint8_t rhport)
static CFG_TUD_MEM_SECTION cdcd_interface_t _cdcd_itf[CFG_TUD_CDC]
void tud_cdc_n_get_line_coding(uint8_t itf, cdc_line_coding_t *coding)
uint8_t tud_cdc_n_get_line_state(uint8_t itf)
bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *request)
static tud_cdc_configure_fifo_t _cdcd_fifo_cfg
bool tud_cdc_n_connected(uint8_t itf)
bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
uint32_t tud_cdc_n_write_available(uint8_t itf)
void tud_cdc_n_read_flush(uint8_t itf)
bool tud_cdc_configure_fifo(tud_cdc_configure_fifo_t const *cfg)
bool tud_cdc_n_peek(uint8_t itf, uint8_t *chr)
uint32_t tud_cdc_n_read(uint8_t itf, void *buffer, uint32_t bufsize)
uint32_t tud_cdc_n_write(uint8_t itf, void const *buffer, uint32_t bufsize)
uint32_t tud_cdc_n_available(uint8_t itf)
TU_ATTR_WEAK void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms)
TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const *p_line_coding)
TU_ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char)
struct TU_ATTR_ALIGNED(4)
void tud_cdc_tx_complete_cb(uint8_t itf)
void tud_cdc_rx_cb(uint8_t itf)
@ CDC_REQUEST_SET_LINE_CODING
@ CDC_REQUEST_GET_LINE_CODING
@ CDC_REQUEST_SET_CONTROL_LINE_STATE
static TU_ATTR_ALWAYS_INLINE bool osal_mutex_delete(osal_mutex_t mutex_hdl)
SemaphoreHandle_t osal_mutex_t
static TU_ATTR_ALWAYS_INLINE osal_mutex_t osal_mutex_create(osal_mutex_def_t *mdef)
AUDIO Channel Cluster Descriptor (4.1)
struct TU_ATTR_PACKED::@16::TU_ATTR_PACKED bmRequestType_bit
uint8_t bInterfaceClass
Class code (assigned by the USB-IF).
uint8_t bInterfaceSubClass
Subclass code (assigned by the USB-IF). These codes are qualified by the value of the bInterfaceCla...
uint8_t bRequest
Request type audio_cs_req_t.
uint8_t bInterfaceNumber
Number of this interface. Zero-based value identifying the index in the array of concurrent interface...
static TU_ATTR_ALWAYS_INLINE bool tu_bit_test(uint32_t value, uint8_t pos)
uint16_t tu_fifo_count(tu_fifo_t *f)
Get number of items in FIFO.
bool tu_fifo_config(tu_fifo_t *f, void *buffer, uint16_t depth, uint16_t item_size, bool overwritable)
bool tu_fifo_set_overwritable(tu_fifo_t *f, bool overwritable)
Change the fifo mode to overwritable or not overwritable.
uint16_t tu_fifo_write_n(tu_fifo_t *f, const void *data, uint16_t n)
This function will write n elements into the array index specified by the write pointer and increment...
bool tu_fifo_peek(tu_fifo_t *f, void *p_buffer)
Read one item without removing it from the FIFO. This function checks for an overflow and corrects re...
bool tu_fifo_full(tu_fifo_t *f)
Check if FIFO is full.
uint16_t tu_fifo_read_n(tu_fifo_t *f, void *buffer, uint16_t n)
This function will read n elements from the array index specified by the read pointer and increment t...
bool tu_fifo_empty(tu_fifo_t *f)
Check if FIFO is empty.
uint16_t tu_fifo_remaining(tu_fifo_t *f)
Get remaining space in FIFO.
bool tu_fifo_clear(tu_fifo_t *f)
Clear the fifo read and write pointers.
static TU_ATTR_ALWAYS_INLINE void tu_fifo_config_mutex(tu_fifo_t *f, osal_mutex_t wr_mutex, osal_mutex_t rd_mutex)
static TU_ATTR_ALWAYS_INLINE uint8_t tu_desc_len(void const *desc)
struct TU_ATTR_PACKED tusb_desc_endpoint_t
USB Endpoint Descriptor.
static TU_ATTR_ALWAYS_INLINE uint8_t tu_desc_type(void const *desc)
struct TU_ATTR_PACKED tusb_desc_interface_t
USB Interface Descriptor.
static TU_ATTR_ALWAYS_INLINE uint8_t const * tu_desc_next(void const *desc)
bool usbd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
bool usbd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_ep)
bool usbd_edpt_claim(uint8_t rhport, uint8_t ep_addr)
bool usbd_edpt_release(uint8_t rhport, uint8_t ep_addr)
bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const *p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t *ep_out, uint8_t *ep_in)
bool tud_control_xfer(uint8_t rhport, tusb_control_request_t const *request, void *buffer, uint16_t len)
static TU_ATTR_ALWAYS_INLINE bool tud_ready(void)
bool tud_control_status(uint8_t rhport, tusb_control_request_t const *request)
CFG_TUH_MEM_ALIGN tusb_control_request_t request
static OSAL_MUTEX_DEF(usbtmcLockBuffer)