summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2026-03-13 00:41:09 +0700
committerGitHub <[email protected]>2026-03-13 00:41:09 +0700
commit1fcb49fc638635337dc3d757767428bc3cb8c4b7 (patch)
treec5e382bc885812eeb0c1c880a9534dba3da33857 /src/class
parentac61a5b176b44db503d8bcc287a622463b65e48e (diff)
parentc6e13e8c15fc6372589b685f5aa4ee60f0cd28f7 (diff)
Merge pull request #3549 from hathach/remove-cdc-configure
remove tud cdc configure
Diffstat (limited to 'src/class')
-rw-r--r--src/class/cdc/cdc_device.c50
-rw-r--r--src/class/cdc/cdc_device.h40
2 files changed, 47 insertions, 43 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index c7547c92b..c499756b9 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -116,7 +116,6 @@ TU_ATTR_WEAK void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms) {
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
-static tud_cdc_configure_t _cdcd_cfg = CFG_TUD_CDC_CONFIGURE_DEFAULT();
TU_ATTR_ALWAYS_INLINE static inline uint8_t find_cdc_itf(uint8_t ep_addr) {
for (uint8_t idx = 0; idx < CFG_TUD_CDC; idx++) {
@@ -132,12 +131,6 @@ TU_ATTR_ALWAYS_INLINE static inline uint8_t find_cdc_itf(uint8_t ep_addr) {
//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
-bool tud_cdc_configure(const tud_cdc_configure_t* driver_cfg) {
- TU_VERIFY(driver_cfg != NULL);
- _cdcd_cfg = *driver_cfg;
- return true;
-}
-
bool tud_cdc_n_ready(uint8_t itf) {
TU_VERIFY(itf < CFG_TUD_CDC);
TU_VERIFY(tud_ready());
@@ -272,7 +265,7 @@ void cdcd_init(void) {
// TX fifo can be configured to change to overwritable if not connected (DTR bit not set). Without DTR we do not
// know if data is actually polled by terminal. This way the most current data is prioritized.
// Default: is overwritable
- tu_edpt_stream_init(&p_cdc->tx_stream, false, true, _cdcd_cfg.tx_overwritabe_if_not_connected, p_cdc->tx_ff_buf,
+ tu_edpt_stream_init(&p_cdc->tx_stream, false, true, CFG_TUD_CDC_TX_OVERWRITABLE_IF_NOT_CONNECTED, p_cdc->tx_ff_buf,
CFG_TUD_CDC_TX_BUFSIZE, epin_buf);
}
}
@@ -293,7 +286,7 @@ void cdcd_reset(uint8_t rhport) {
cdcd_interface_t* p_cdc = &_cdcd_itf[i];
tu_memclr(p_cdc, ITF_MEM_RESET_SIZE);
- tu_fifo_set_overwritable(&p_cdc->tx_stream.ff, _cdcd_cfg.tx_overwritabe_if_not_connected); // back to default
+ tu_fifo_set_overwritable(&p_cdc->tx_stream.ff, CFG_TUD_CDC_TX_OVERWRITABLE_IF_NOT_CONNECTED); // back to default
tu_edpt_stream_close(&p_cdc->rx_stream);
tu_edpt_stream_close(&p_cdc->tx_stream);
}
@@ -348,18 +341,26 @@ uint16_t cdcd_open(uint8_t rhport, const tusb_desc_interface_t* itf_desc, uint16
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
tu_edpt_stream_t *stream_tx = &p_cdc->tx_stream;
tu_edpt_stream_open(stream_tx, rhport, desc_ep, CFG_TUD_CDC_TX_EPSIZE);
- if (_cdcd_cfg.tx_persistent) {
- tu_edpt_stream_write_xfer(stream_tx); // flush pending data
- } else {
- tu_edpt_stream_clear(stream_tx);
- }
+
+ #if CFG_TUD_CDC_TX_PERSISTENT
+ tu_edpt_stream_write_xfer(stream_tx); // flush pending data
+ #else
+ tu_edpt_stream_clear(stream_tx);
+ #endif
} else {
tu_edpt_stream_t *stream_rx = &p_cdc->rx_stream;
- tu_edpt_stream_open(stream_rx, rhport, desc_ep,
- CFG_TUD_CDC_RX_NEED_ZLP ? CFG_TUD_CDC_RX_EPSIZE : tu_edpt_packet_size(desc_ep));
- if (!_cdcd_cfg.rx_persistent) {
- tu_edpt_stream_clear(stream_rx);
- }
+ #if CFG_TUD_CDC_RX_NEED_ZLP
+ const uint16_t xfer_len = CFG_TUD_CDC_RX_EPSIZE;
+ #else
+ const uint16_t xfer_len = tu_edpt_packet_size(desc_ep);
+ #endif
+
+ tu_edpt_stream_open(stream_rx, rhport, desc_ep, xfer_len);
+
+ #if !CFG_TUD_CDC_RX_PERSISTENT
+ tu_edpt_stream_clear(stream_rx);
+ #endif
+
TU_ASSERT(tu_edpt_stream_read_xfer(stream_rx) > 0, 0); // prepare for incoming data
}
}
@@ -424,12 +425,13 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_requ
p_cdc->line_state = (uint8_t) request->wValue;
// If enabled: fifo overwriting is disabled if DTR bit is set and vice versa
- if (_cdcd_cfg.tx_overwritabe_if_not_connected) {
- tu_fifo_set_overwritable(&p_cdc->tx_stream.ff, !dtr);
- } else {
- tu_fifo_set_overwritable(&p_cdc->tx_stream.ff, false);
- }
+ #if CFG_TUD_CDC_TX_OVERWRITABLE_IF_NOT_CONNECTED
+ const bool is_overwritable = !dtr;
+ #else
+ const bool is_overwritable = false;
+ #endif
+ tu_fifo_set_overwritable(&p_cdc->tx_stream.ff, is_overwritable);
TU_LOG_DRV(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
tud_cdc_line_state_cb(itf, dtr, rts); // invoke callback
} else {
diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h
index 0348bd2ec..9ac6bc58a 100644
--- a/src/class/cdc/cdc_device.h
+++ b/src/class/cdc/cdc_device.h
@@ -70,30 +70,32 @@
#define CFG_TUD_CDC_RX_NEED_ZLP 0
#endif
-#ifndef CFG_TUD_CDC_CONFIGURE_DEFAULT
- #define CFG_TUD_CDC_CONFIGURE_DEFAULT() \
- { \
- .rx_persistent = false, \
- .tx_persistent = false, \
- .tx_overwritabe_if_not_connected = true, \
- }
+// Keep rx fifo data even with bus reset or disconnect
+#ifndef CFG_TUD_CDC_RX_PERSISTENT
+ #define CFG_TUD_CDC_RX_PERSISTENT 0
#endif
-//--------------------------------------------------------------------+
-// Driver Configuration
-//--------------------------------------------------------------------+
+// Keep tx fifo data even with bus reset or disconnect
+#ifndef CFG_TUD_CDC_TX_PERSISTENT
+ #define CFG_TUD_CDC_TX_PERSISTENT 0
+#endif
+
+// If not connected, tx fifo can be overwritten
+#ifndef CFG_TUD_CDC_TX_OVERWRITABLE_IF_NOT_CONNECTED
+ #define CFG_TUD_CDC_TX_OVERWRITABLE_IF_NOT_CONNECTED 1
+#endif
+
+// Backward compatible: tud_cdc_configure_t and tud_cdc_configure() are no longer used.
+// Configuration is now done via compile-time macros above.
typedef struct {
- bool rx_persistent; // keep rx fifo data even with bus reset or disconnect
- bool tx_persistent; // keep tx fifo data even with reset or disconnect
- bool tx_overwritabe_if_not_connected; // if not connected, tx fifo can be overwritten
+ bool rx_persistent;
+ bool tx_persistent;
+ bool tx_overwritabe_if_not_connected;
} tud_cdc_configure_t;
-// Configure CDC driver behavior
-bool tud_cdc_configure(const tud_cdc_configure_t* driver_cfg);
-
-// Backward compatible
-#define tud_cdc_configure_fifo_t tud_cdc_configure_t
-#define tud_cdc_configure_fifo tud_cdc_configure
+#define tud_cdc_configure(_cfg) ((void)(_cfg))
+#define tud_cdc_configure_fifo_t tud_cdc_configure_t
+#define tud_cdc_configure_fifo(_cfg) ((void)(_cfg))
//--------------------------------------------------------------------+
// Application API (Multiple Ports) i.e. CFG_TUD_CDC > 1