add tud_cdc_n_notify_msg()

This commit is contained in:
hathach
2025-11-27 00:03:59 +07:00
parent 02e67c8fa1
commit d6c50c7ce2
2 changed files with 36 additions and 30 deletions

View File

@ -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, );

View File

@ -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);
}