summaryrefslogtreecommitdiff
path: root/src/class/cdc
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2025-09-27 20:38:03 +0700
committerGitHub <[email protected]>2025-09-27 20:38:03 +0700
commit152d25ed621393a991561b7de61c2f01bbadeb71 (patch)
tree7a75a0a3da032421907e26616f67f7f1d55b2d09 /src/class/cdc
parent1f9c41566165b23ff573bf1b9bfd077cfbe9067f (diff)
parent0655f98359de7e9299d8047d94a1087bdd3618ac (diff)
Merge pull request #3256 from hathach/weak_cb
Migrate weak function override to new syntax, update delay api usage
Diffstat (limited to 'src/class/cdc')
-rw-r--r--src/class/cdc/cdc_device.c60
-rw-r--r--src/class/cdc/cdc_device.h14
-rw-r--r--src/class/cdc/cdc_host.c39
-rw-r--r--src/class/cdc/cdc_host.h8
-rw-r--r--src/class/cdc/cdc_rndis_host.c2
5 files changed, 79 insertions, 44 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index 4e4e01eaf..f1c4a3bbf 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -120,6 +120,42 @@ static bool _prep_out_transaction(uint8_t itf) {
}
//--------------------------------------------------------------------+
+// Weak stubs: invoked if no strong implementation is available
+//--------------------------------------------------------------------+
+TU_ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf) {
+ (void) itf;
+}
+
+TU_ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) {
+ (void) itf;
+ (void) wanted_char;
+}
+
+TU_ATTR_WEAK void tud_cdc_tx_complete_cb(uint8_t itf) {
+ (void) itf;
+}
+
+TU_ATTR_WEAK void tud_cdc_notify_complete_cb(uint8_t itf) {
+ (void) itf;
+}
+
+TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
+ (void) itf;
+ (void) dtr;
+ (void) rts;
+}
+
+TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding) {
+ (void) itf;
+ (void) p_line_coding;
+}
+
+TU_ATTR_WEAK void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms) {
+ (void) itf;
+ (void) duration_ms;
+}
+
+//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
bool tud_cdc_configure(const tud_cdc_configure_t* driver_cfg) {
@@ -419,9 +455,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_requ
TU_LOG_DRV(" Set Line Coding\r\n");
tud_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t));
} else if (stage == CONTROL_STAGE_ACK) {
- if (tud_cdc_line_coding_cb) {
- tud_cdc_line_coding_cb(itf, &p_cdc->line_coding);
- }
+ tud_cdc_line_coding_cb(itf, &p_cdc->line_coding);
}
break;
@@ -456,9 +490,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_requ
TU_LOG_DRV(" Set Control Line State: DTR = %d, RTS = %d\r\n", dtr, rts);
// Invoke callback
- if (tud_cdc_line_state_cb) {
- tud_cdc_line_state_cb(itf, dtr, rts);
- }
+ tud_cdc_line_state_cb(itf, dtr, rts);
}
break;
@@ -467,9 +499,7 @@ bool cdcd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_requ
tud_control_status(rhport, request);
} else if (stage == CONTROL_STAGE_ACK) {
TU_LOG_DRV(" Send Break\r\n");
- if (tud_cdc_send_break_cb) {
- tud_cdc_send_break_cb(itf, request->wValue);
- }
+ tud_cdc_send_break_cb(itf, request->wValue);
}
break;
@@ -501,7 +531,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
tu_fifo_write_n(&p_cdc->rx_ff, p_epbuf->epout, (uint16_t) xferred_bytes);
// Check for wanted char and invoke callback if needed
- if (tud_cdc_rx_wanted_cb && (((signed char) p_cdc->wanted_char) != -1)) {
+ if (((signed char) p_cdc->wanted_char) != -1) {
for (uint32_t i = 0; i < xferred_bytes; i++) {
if ((p_cdc->wanted_char == p_epbuf->epout[i]) && !tu_fifo_empty(&p_cdc->rx_ff)) {
tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
@@ -510,7 +540,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
}
// invoke receive callback (if there is still data)
- if (tud_cdc_rx_cb && !tu_fifo_empty(&p_cdc->rx_ff)) {
+ if (!tu_fifo_empty(&p_cdc->rx_ff)) {
tud_cdc_rx_cb(itf);
}
@@ -523,9 +553,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
// Though maybe the baudrate is not really important !!!
if (ep_addr == p_cdc->ep_in) {
// invoke transmit callback to possibly refill tx fifo
- if (tud_cdc_tx_complete_cb) {
- tud_cdc_tx_complete_cb(itf);
- }
+ tud_cdc_tx_complete_cb(itf);
if (0 == tud_cdc_n_write_flush(itf)) {
// If there is no data left, a ZLP should be sent if
@@ -540,9 +568,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
// Sent notification to host
if (ep_addr == p_cdc->ep_notify) {
- if (tud_cdc_notify_complete_cb) {
- tud_cdc_notify_complete_cb(itf);
- }
+ tud_cdc_notify_complete_cb(itf);
}
return true;
diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h
index a34e07e1d..9673b9807 100644
--- a/src/class/cdc/cdc_device.h
+++ b/src/class/cdc/cdc_device.h
@@ -220,28 +220,28 @@ TU_ATTR_ALWAYS_INLINE static inline bool tud_cdc_write_clear(void) {
//--------------------------------------------------------------------+
// Invoked when received new data
-TU_ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf);
+void tud_cdc_rx_cb(uint8_t itf);
// Invoked when received `wanted_char`
-TU_ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
+void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
// Invoked when a TX is complete and therefore space becomes available in TX buffer
-TU_ATTR_WEAK void tud_cdc_tx_complete_cb(uint8_t itf);
+void tud_cdc_tx_complete_cb(uint8_t itf);
// Invoked when a notification is sent to host
-TU_ATTR_WEAK void tud_cdc_notify_complete_cb(uint8_t itf);
+void tud_cdc_notify_complete_cb(uint8_t itf);
// Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE
-TU_ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
+void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
// Invoked when line coding is change via SET_LINE_CODING
-TU_ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
+void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
// Invoked when received send break
// \param[in] itf interface for which send break was received.
// \param[in] duration_ms the length of time, in milliseconds, of the break signal. If a value of FFFFh, then the
// device will send a break until another SendBreak request is received with value 0000h.
-TU_ATTR_WEAK void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms);
+void tud_cdc_send_break_cb(uint8_t itf, uint16_t duration_ms);
//--------------------------------------------------------------------+
// INTERNAL USBD-CLASS DRIVER API
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c
index f9a37ed35..beef03eff 100644
--- a/src/class/cdc/cdc_host.c
+++ b/src/class/cdc/cdc_host.c
@@ -392,6 +392,25 @@ static cdch_interface_t * make_new_itf(uint8_t daddr, tusb_desc_interface_t cons
static bool open_ep_stream_pair(cdch_interface_t * p_cdc , tusb_desc_endpoint_t const *desc_ep);
//--------------------------------------------------------------------+
+// Weak stubs: invoked if no strong implementation is available
+//--------------------------------------------------------------------+
+TU_ATTR_WEAK void tuh_cdc_mount_cb(uint8_t idx) {
+ (void) idx;
+}
+
+TU_ATTR_WEAK void tuh_cdc_umount_cb(uint8_t idx) {
+ (void) idx;
+}
+
+TU_ATTR_WEAK void tuh_cdc_rx_cb(uint8_t idx) {
+ (void) idx;
+}
+
+TU_ATTR_WEAK void tuh_cdc_tx_complete_cb(uint8_t idx) {
+ (void) idx;
+}
+
+//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
@@ -657,9 +676,7 @@ void cdch_close(uint8_t daddr) {
TU_LOG_CDC(p_cdc, "close");
// Invoke application callback
- if (tuh_cdc_umount_cb) {
- tuh_cdc_umount_cb(idx);
- }
+ tuh_cdc_umount_cb(idx);
p_cdc->daddr = 0;
p_cdc->bInterfaceNumber = 0;
@@ -680,9 +697,7 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
if (ep_addr == p_cdc->stream.tx.ep_addr) {
// invoke tx complete callback to possibly refill tx fifo
- if (tuh_cdc_tx_complete_cb) {
- tuh_cdc_tx_complete_cb(idx);
- }
+ tuh_cdc_tx_complete_cb(idx);
if (0 == tu_edpt_stream_write_xfer(daddr, &p_cdc->stream.tx)) {
// If there is no data left, a ZLP should be sent if:
@@ -697,18 +712,14 @@ bool cdch_xfer_cb(uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t
if (xferred_bytes > 2) {
tu_edpt_stream_read_xfer_complete_with_buf(&p_cdc->stream.rx, p_cdc->stream.rx.ep_buf + 2, xferred_bytes - 2);
- if (tuh_cdc_rx_cb) {
- tuh_cdc_rx_cb(idx); // invoke receive callback
- }
+ tuh_cdc_rx_cb(idx); // invoke receive callback
}
} else
#endif
{
tu_edpt_stream_read_xfer_complete(&p_cdc->stream.rx, xferred_bytes);
- if (tuh_cdc_rx_cb) {
- tuh_cdc_rx_cb(idx); // invoke receive callback
- }
+ tuh_cdc_rx_cb(idx); // invoke receive callback
}
// prepare for next transfer if needed
@@ -794,9 +805,7 @@ static void set_config_complete(cdch_interface_t *p_cdc, bool success) {
if (success) {
const uint8_t idx = get_idx_by_ptr(p_cdc);
p_cdc->mounted = true;
- if (tuh_cdc_mount_cb) {
- tuh_cdc_mount_cb(idx);
- }
+ tuh_cdc_mount_cb(idx);
// Prepare for incoming data
tu_edpt_stream_read_xfer(p_cdc->daddr, &p_cdc->stream.rx);
} else {
diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h
index 37bfca270..bf6711d7e 100644
--- a/src/class/cdc/cdc_host.h
+++ b/src/class/cdc/cdc_host.h
@@ -230,16 +230,16 @@ TU_ATTR_ALWAYS_INLINE static inline tusb_xfer_result_t tuh_cdc_disconnect_sync(u
// Invoked when a device with CDC interface is mounted
// idx is index of cdc interface in the internal pool.
-TU_ATTR_WEAK extern void tuh_cdc_mount_cb(uint8_t idx);
+extern void tuh_cdc_mount_cb(uint8_t idx);
// Invoked when a device with CDC interface is unmounted
-TU_ATTR_WEAK extern void tuh_cdc_umount_cb(uint8_t idx);
+extern void tuh_cdc_umount_cb(uint8_t idx);
// Invoked when received new data
-TU_ATTR_WEAK extern void tuh_cdc_rx_cb(uint8_t idx);
+extern void tuh_cdc_rx_cb(uint8_t idx);
// Invoked when a TX is complete and therefore space becomes available in TX buffer
-TU_ATTR_WEAK extern void tuh_cdc_tx_complete_cb(uint8_t idx);
+extern void tuh_cdc_tx_complete_cb(uint8_t idx);
//--------------------------------------------------------------------+
// Internal Class Driver API
diff --git a/src/class/cdc/cdc_rndis_host.c b/src/class/cdc/cdc_rndis_host.c
index 11a5355aa..e975ea440 100644
--- a/src/class/cdc/cdc_rndis_host.c
+++ b/src/class/cdc/cdc_rndis_host.c
@@ -103,7 +103,7 @@ static tusb_error_t rndis_body_subtask(void)
}
- osal_task_delay(100);
+ tusb_time_delay_ms_api(100);
OSAL_SUBTASK_END
}