summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-11-27 00:03:59 +0700
committerhathach <[email protected]>2025-11-27 00:03:59 +0700
commitd6c50c7ce2735999e16e05a3da60ff98f8032e96 (patch)
treef5e8446c302f8a600c0bd6895e2365b400531548 /src/class
parent02e67c8fa199c168dc771222c1994556744161e9 (diff)
add tud_cdc_n_notify_msg()
Diffstat (limited to 'src/class')
-rw-r--r--src/class/cdc/cdc_device.c60
-rw-r--r--src/class/cdc/cdc_device.h6
2 files changed, 36 insertions, 30 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index fbca5b574..a77dfb140 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -66,13 +66,11 @@ typedef struct {
#define ITF_MEM_RESET_SIZE offsetof(cdcd_interface_t, line_coding)
-#if CFG_TUD_EDPT_DEDICATED_HWFIFO == 0 || CFG_TUD_CDC_NOTIFY
-typedef struct {
- // Don't use local EP buffer if dedicated hw FIFO is supported
+// Skip local EP buffer if dedicated hw FIFO is supported
#if CFG_TUD_EDPT_DEDICATED_HWFIFO == 0
+typedef struct {
TUD_EPBUF_DEF(epout, CFG_TUD_CDC_EP_BUFSIZE);
TUD_EPBUF_DEF(epin, CFG_TUD_CDC_EP_BUFSIZE);
- #endif
#if CFG_TUD_CDC_NOTIFY
TUD_EPBUF_TYPE_DEF(cdc_notify_msg_t, epnotify);
@@ -172,42 +170,44 @@ void tud_cdc_n_get_line_coding(uint8_t itf, cdc_line_coding_t *coding) {
}
#if CFG_TUD_CDC_NOTIFY
-bool tud_cdc_n_notify_uart_state (uint8_t itf, const cdc_notify_uart_state_t *state) {
+bool tud_cdc_n_notify_msg(uint8_t itf, cdc_notify_msg_t *msg) {
TU_VERIFY(itf < CFG_TUD_CDC);
- cdcd_interface_t *p_cdc = &_cdcd_itf[itf];
- cdcd_epbuf_t *p_epbuf = &_cdcd_epbuf[itf];
+ cdcd_interface_t *p_cdc = &_cdcd_itf[itf];
+ cdcd_epbuf_t *p_epbuf = &_cdcd_epbuf[itf];
+ cdc_notify_msg_t *notify_msg = &p_epbuf->epnotify;
+
+ *notify_msg = *msg;
+ notify_msg->request.wIndex = p_cdc->itf_num;
+
TU_VERIFY(tud_ready() && p_cdc->ep_notify != 0);
TU_VERIFY(usbd_edpt_claim(p_cdc->rhport, p_cdc->ep_notify));
+ return usbd_edpt_xfer(p_cdc->rhport, p_cdc->ep_notify, (uint8_t *)msg, 8 + msg->request.wLength, false);
+}
- cdc_notify_msg_t* notify_msg = &p_epbuf->epnotify;
- notify_msg->request.bmRequestType = CDC_REQ_TYPE_NOTIF;
- notify_msg->request.bRequest = CDC_NOTIF_SERIAL_STATE;
- notify_msg->request.wValue = 0;
- notify_msg->request.wIndex = p_cdc->itf_num;
- notify_msg->request.wLength = sizeof(cdc_notify_uart_state_t);
- notify_msg->serial_state = *state;
+bool tud_cdc_n_notify_uart_state (uint8_t itf, const cdc_notify_uart_state_t *state) {
+ cdc_notify_msg_t notify_msg;
+ notify_msg.request.bmRequestType = CDC_REQ_TYPE_NOTIF;
+ notify_msg.request.bRequest = CDC_NOTIF_SERIAL_STATE;
+ notify_msg.request.wValue = 0;
+ notify_msg.request.wIndex = 0; // filled later
+ notify_msg.request.wLength = sizeof(cdc_notify_uart_state_t);
+ notify_msg.serial_state = *state;
- return usbd_edpt_xfer(p_cdc->rhport, p_cdc->ep_notify, (uint8_t *)notify_msg, 8 + sizeof(cdc_notify_uart_state_t), false);
+ return tud_cdc_n_notify_msg(itf, &notify_msg);
}
bool tud_cdc_n_notify_conn_speed_change(uint8_t itf, const cdc_notify_conn_speed_change_t* conn_speed_change) {
- TU_VERIFY(itf < CFG_TUD_CDC);
- cdcd_interface_t *p_cdc = &_cdcd_itf[itf];
- cdcd_epbuf_t *p_epbuf = &_cdcd_epbuf[itf];
- TU_VERIFY(tud_ready() && p_cdc->ep_notify != 0);
- TU_VERIFY(usbd_edpt_claim(p_cdc->rhport, p_cdc->ep_notify));
+ cdc_notify_msg_t notify_msg;
+ notify_msg.request.bmRequestType = CDC_REQ_TYPE_NOTIF;
+ notify_msg.request.bRequest = CDC_NOTIF_CONNECTION_SPEED_CHANGE;
+ notify_msg.request.wValue = 0;
+ notify_msg.request.wIndex = 0; // filled later
+ notify_msg.request.wLength = sizeof(cdc_notify_conn_speed_change_t);
+ notify_msg.conn_speed_change = *conn_speed_change;
- cdc_notify_msg_t* notify_msg = &p_epbuf->epnotify;
- notify_msg->request.bmRequestType = CDC_REQ_TYPE_NOTIF;
- notify_msg->request.bRequest = CDC_NOTIF_CONNECTION_SPEED_CHANGE;
- notify_msg->request.wValue = 0;
- notify_msg->request.wIndex = p_cdc->itf_num;
- notify_msg->request.wLength = sizeof(cdc_notify_conn_speed_change_t);
- notify_msg->conn_speed_change = *conn_speed_change;
-
- return usbd_edpt_xfer(p_cdc->rhport, p_cdc->ep_notify, (uint8_t *)notify_msg, 8 + sizeof(cdc_notify_conn_speed_change_t), false);
+ return tud_cdc_n_notify_msg(itf, &notify_msg);
}
-#endif
+ #endif
void tud_cdc_n_set_wanted_char(uint8_t itf, char wanted) {
TU_VERIFY(itf < CFG_TUD_CDC, );
diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h
index 8b5761747..6596022df 100644
--- a/src/class/cdc/cdc_device.h
+++ b/src/class/cdc/cdc_device.h
@@ -141,12 +141,18 @@ bool tud_cdc_n_write_clear(uint8_t itf);
#if CFG_TUD_CDC_NOTIFY
+bool tud_cdc_n_notify_msg(uint8_t itf, cdc_notify_msg_t *msg);
+
// Send UART status notification: DCD, DSR etc ..
bool tud_cdc_n_notify_uart_state(uint8_t itf, const cdc_notify_uart_state_t *state);
// Send connection speed change notification
bool tud_cdc_n_notify_conn_speed_change(uint8_t itf, const cdc_notify_conn_speed_change_t* conn_speed_change);
+TU_ATTR_ALWAYS_INLINE static inline bool tud_cdc_notify_msg(cdc_notify_msg_t *msg) {
+ return tud_cdc_n_notify_msg(0, msg);
+}
+
TU_ATTR_ALWAYS_INLINE static inline bool tud_cdc_notify_uart_state(const cdc_notify_uart_state_t* state) {
return tud_cdc_n_notify_uart_state(0, state);
}