usb: device_next: use USB notification in CDC ACM implementation
Add message types for line coding and contol line state updates. Add a publish message function that takes a pointer to a device structure as payload, and use USB notification in the CDC ACM implementation. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
3aef852fc0
commit
567827add8
|
@ -44,6 +44,10 @@ enum usbd_msg_type {
|
|||
USBD_MSG_UDC_ERROR,
|
||||
/** Unrecoverable device stack error message */
|
||||
USBD_MSG_STACK_ERROR,
|
||||
/** CDC ACM Line Coding update */
|
||||
USBD_MSG_CDC_ACM_LINE_CODING,
|
||||
/** CDC ACM Line State update */
|
||||
USBD_MSG_CDC_ACM_CONTROL_LINE_STATE,
|
||||
/** Maximum number of message types */
|
||||
USBD_MSG_MAX_NUMBER,
|
||||
};
|
||||
|
@ -57,6 +61,8 @@ static const char *const usbd_msg_type_list[] = {
|
|||
"Bus reset",
|
||||
"Controller error",
|
||||
"Stack error",
|
||||
"CDC ACM line coding",
|
||||
"CDC ACM control line state",
|
||||
};
|
||||
|
||||
BUILD_ASSERT(ARRAY_SIZE(usbd_msg_type_list) == USBD_MSG_MAX_NUMBER,
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include <zephyr/drivers/usb/udc.h>
|
||||
|
||||
#include "usbd_msg.h"
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(usbd_cdc_acm, CONFIG_USBD_CDC_ACM_LOG_LEVEL);
|
||||
|
||||
|
@ -359,6 +361,7 @@ static int usbd_cdc_acm_ctd(struct usbd_class_node *const c_nd,
|
|||
const struct usb_setup_packet *const setup,
|
||||
const struct net_buf *const buf)
|
||||
{
|
||||
struct usbd_contex *uds_ctx = c_nd->data->uds_ctx;
|
||||
const struct device *dev = c_nd->data->priv;
|
||||
struct cdc_acm_uart_data *data = dev->data;
|
||||
size_t len;
|
||||
|
@ -373,11 +376,13 @@ static int usbd_cdc_acm_ctd(struct usbd_class_node *const c_nd,
|
|||
|
||||
memcpy(&data->line_coding, buf->data, len);
|
||||
cdc_acm_update_uart_cfg(data);
|
||||
usbd_msg_pub_device(uds_ctx, USBD_MSG_CDC_ACM_LINE_CODING, dev);
|
||||
return 0;
|
||||
|
||||
case SET_CONTROL_LINE_STATE:
|
||||
data->line_state = setup->wValue;
|
||||
cdc_acm_update_linestate(data);
|
||||
usbd_msg_pub_device(uds_ctx, USBD_MSG_CDC_ACM_CONTROL_LINE_STATE, dev);
|
||||
return 0;
|
||||
|
||||
default:
|
||||
|
|
|
@ -94,3 +94,16 @@ void usbd_msg_pub_simple(struct usbd_contex *const ctx,
|
|||
usbd_msg_pub(ctx, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_msg_pub_device(struct usbd_contex *const ctx,
|
||||
const enum usbd_msg_type type, const struct device *const dev)
|
||||
{
|
||||
const struct usbd_msg msg = {
|
||||
.type = type,
|
||||
.dev = dev,
|
||||
};
|
||||
|
||||
if (ctx->msg_cb != NULL) {
|
||||
usbd_msg_pub(ctx, msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,4 +19,14 @@
|
|||
void usbd_msg_pub_simple(struct usbd_contex *const ctx,
|
||||
const enum usbd_msg_type type, const int status);
|
||||
|
||||
/**
|
||||
* @brief Publish USB device message with pointer to a device payload
|
||||
*
|
||||
* @param[in] uds_ctx Pointer to a device context
|
||||
* @param[in] type Message type
|
||||
* @param[in] dev Pointer to a device structure
|
||||
*/
|
||||
void usbd_msg_pub_device(struct usbd_contex *const ctx,
|
||||
const enum usbd_msg_type type, const struct device *const dev);
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_USBD_MSG_H */
|
||||
|
|
Loading…
Reference in a new issue