usb: Refactor USB status callback
Merge cb_usb_status_composite and cb_usb_status and use common forward_status_cb for both composite and normal devices. Fixes #14882 Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
parent
0c59471436
commit
721f3d1cd0
14 changed files with 71 additions and 181 deletions
|
@ -190,12 +190,9 @@ struct usb_cfg_data {
|
|||
/** Function for interface runtime configuration */
|
||||
usb_interface_config interface_config;
|
||||
/** Callback to be notified on USB connection status change */
|
||||
usb_dc_status_callback cb_usb_status;
|
||||
/** Composite callback */
|
||||
void (*cb_usb_status_composite)(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code cb_status,
|
||||
const u8_t *param);
|
||||
|
||||
void (*cb_usb_status)(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code cb_status,
|
||||
const u8_t *param);
|
||||
/** USB interface (Class) handler and storage space */
|
||||
struct usb_interface_cfg_data interface;
|
||||
/** Number of individual endpoints in the device configuration */
|
||||
|
|
|
@ -136,11 +136,14 @@ static struct usb_ep_cfg_data wpanusb_ep[] = {
|
|||
},
|
||||
};
|
||||
|
||||
static void wpanusb_status_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
static void wpanusb_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
struct wpanusb_dev_data_t * const dev_data = DEV_DATA(wpanusb_dev);
|
||||
|
||||
ARG_UNUSED(param);
|
||||
ARG_UNUSED(cfg);
|
||||
|
||||
/* Store the new status */
|
||||
dev_data->usb_status = status;
|
||||
|
|
|
@ -283,12 +283,12 @@ done:
|
|||
*
|
||||
* @return N/A.
|
||||
*/
|
||||
static void webusb_serial_dev_status_cb(enum usb_dc_status_code status,
|
||||
static void webusb_serial_dev_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(param);
|
||||
|
||||
LOG_DBG("");
|
||||
ARG_UNUSED(cfg);
|
||||
|
||||
/* Check the USB status and do needed action if required */
|
||||
switch (status) {
|
||||
|
|
|
@ -206,9 +206,12 @@ static void acl_read_cb(u8_t ep, int size, void *priv)
|
|||
BT_BUF_ACL_SIZE, USB_TRANS_READ, acl_read_cb, buf);
|
||||
}
|
||||
|
||||
static void bluetooth_status_cb(enum usb_dc_status_code status,
|
||||
static void bluetooth_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(cfg);
|
||||
|
||||
/* Check the USB status and do needed action if required */
|
||||
switch (status) {
|
||||
case USB_DC_ERROR:
|
||||
|
|
|
@ -416,10 +416,9 @@ static void cdc_acm_do_cb(struct cdc_acm_dev_data_t *dev_data,
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(CONFIG_USB_COMPOSITE_DEVICE)
|
||||
static void cdc_acm_dev_status_composite_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
static void cdc_acm_dev_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
struct cdc_acm_dev_data_t *dev_data;
|
||||
struct usb_dev_data *common;
|
||||
|
@ -436,26 +435,6 @@ static void cdc_acm_dev_status_composite_cb(struct usb_cfg_data *cfg,
|
|||
|
||||
cdc_acm_do_cb(dev_data, status, param);
|
||||
}
|
||||
#else
|
||||
static void cdc_acm_dev_status_cb(enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
struct cdc_acm_dev_data_t *dev_data;
|
||||
struct usb_dev_data *common;
|
||||
|
||||
/* Should be the only one element in the list */
|
||||
common = CONTAINER_OF(sys_slist_peek_head(&cdc_acm_data_devlist),
|
||||
struct usb_dev_data, node);
|
||||
if (common == NULL) {
|
||||
LOG_WRN("Device data not found");
|
||||
return;
|
||||
}
|
||||
|
||||
dev_data = CONTAINER_OF(common, struct cdc_acm_dev_data_t, common);
|
||||
|
||||
cdc_acm_do_cb(dev_data, status, param);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void cdc_interface_config(struct usb_desc_header *head,
|
||||
u8_t bInterfaceNumber)
|
||||
|
@ -956,24 +935,6 @@ static const struct uart_driver_api cdc_acm_driver_api = {
|
|||
INITIALIZER_EP_DATA(cdc_acm_bulk_in, in_ep_addr), \
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_COMPOSITE_DEVICE
|
||||
#define DEFINE_CDC_ACM_CFG_DATA(x) \
|
||||
USBD_CFG_DATA_DEFINE(cdc_acm) \
|
||||
struct usb_cfg_data cdc_acm_config_##x = { \
|
||||
.usb_device_description = NULL, \
|
||||
.interface_config = cdc_interface_config, \
|
||||
.interface_descriptor = &cdc_acm_cfg_##x.if0, \
|
||||
.cb_usb_status_composite = \
|
||||
cdc_acm_dev_status_composite_cb, \
|
||||
.interface = { \
|
||||
.class_handler = cdc_acm_class_handle_req, \
|
||||
.custom_handler = NULL, \
|
||||
.payload_data = NULL, \
|
||||
}, \
|
||||
.num_endpoints = ARRAY_SIZE(cdc_acm_ep_data_##x), \
|
||||
.endpoint = cdc_acm_ep_data_##x, \
|
||||
}
|
||||
#else /* CONFIG_USB_COMPOSITE_DEVICE */
|
||||
#define DEFINE_CDC_ACM_CFG_DATA(x) \
|
||||
USBD_CFG_DATA_DEFINE(cdc_acm) \
|
||||
struct usb_cfg_data cdc_acm_config_##x = { \
|
||||
|
@ -988,8 +949,7 @@ static const struct uart_driver_api cdc_acm_driver_api = {
|
|||
}, \
|
||||
.num_endpoints = ARRAY_SIZE(cdc_acm_ep_data_##x), \
|
||||
.endpoint = cdc_acm_ep_data_##x, \
|
||||
}
|
||||
#endif /* CONFIG_USB_COMPOSITE_DEVICE */
|
||||
};
|
||||
|
||||
#if CONFIG_USB_COMPOSITE_DEVICE
|
||||
#define DEFINE_CDC_ACM_DESCR(x, int_ep_addr, out_ep_addr, in_ep_addr) \
|
||||
|
|
|
@ -384,10 +384,9 @@ static void hid_do_status_cb(struct hid_device_info *dev_data,
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_COMPOSITE_DEVICE
|
||||
static void hid_status_composite_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
static void hid_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
struct hid_device_info *dev_data;
|
||||
struct usb_dev_data *common;
|
||||
|
@ -404,25 +403,6 @@ static void hid_status_composite_cb(struct usb_cfg_data *cfg,
|
|||
|
||||
hid_do_status_cb(dev_data, status, param);
|
||||
}
|
||||
#else
|
||||
static void hid_status_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
{
|
||||
struct hid_device_info *dev_data;
|
||||
struct usb_dev_data *common;
|
||||
|
||||
/* Should be the only one element in the list */
|
||||
common = CONTAINER_OF(sys_slist_peek_head(&usb_hid_devlist),
|
||||
struct usb_dev_data, node);
|
||||
if (common == NULL) {
|
||||
LOG_WRN("Device data not found");
|
||||
return;
|
||||
}
|
||||
|
||||
dev_data = CONTAINER_OF(common, struct hid_device_info, common);
|
||||
|
||||
hid_do_status_cb(dev_data, status, param);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int hid_class_handle_req(struct usb_setup_packet *setup,
|
||||
s32_t *len, u8_t **data)
|
||||
|
@ -653,23 +633,6 @@ static void hid_interface_config(struct usb_desc_header *head,
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_COMPOSITE_DEVICE
|
||||
#define DEFINE_HID_CFG_DATA(x) \
|
||||
USBD_CFG_DATA_DEFINE(hid) \
|
||||
struct usb_cfg_data hid_config_##x = { \
|
||||
.usb_device_description = NULL, \
|
||||
.interface_config = hid_interface_config, \
|
||||
.interface_descriptor = &hid_cfg_##x.if0, \
|
||||
.cb_usb_status_composite = hid_status_composite_cb, \
|
||||
.interface = { \
|
||||
.class_handler = hid_class_handle_req, \
|
||||
.custom_handler = hid_custom_handle_req, \
|
||||
.payload_data = NULL, \
|
||||
}, \
|
||||
.num_endpoints = ARRAY_SIZE(hid_ep_data_##x), \
|
||||
.endpoint = hid_ep_data_##x, \
|
||||
}
|
||||
#else
|
||||
#define DEFINE_HID_CFG_DATA(x) \
|
||||
USBD_CFG_DATA_DEFINE(hid) \
|
||||
struct usb_cfg_data hid_config_##x = { \
|
||||
|
@ -684,8 +647,7 @@ static void hid_interface_config(struct usb_desc_header *head,
|
|||
}, \
|
||||
.num_endpoints = ARRAY_SIZE(hid_ep_data_##x), \
|
||||
.endpoint = hid_ep_data_##x, \
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#if !defined(CONFIG_USB_COMPOSITE_DEVICE)
|
||||
static u8_t interface_data[CONFIG_USB_HID_MAX_PAYLOAD_SIZE];
|
||||
|
|
|
@ -102,9 +102,12 @@ static struct usb_ep_cfg_data ep_cfg[] = {
|
|||
};
|
||||
/* usb.rst endpoint configuration end */
|
||||
|
||||
static void loopback_status_cb(enum usb_dc_status_code status,
|
||||
static void loopback_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(cfg);
|
||||
|
||||
switch (status) {
|
||||
case USB_DC_CONFIGURED:
|
||||
loopback_in_cb(ep_cfg[LOOPBACK_IN_EP_IDX].ep_addr, 0);
|
||||
|
|
|
@ -801,10 +801,12 @@ static void mass_storage_bulk_in(u8_t ep,
|
|||
*
|
||||
* @return N/A.
|
||||
*/
|
||||
static void mass_storage_status_cb(enum usb_dc_status_code status,
|
||||
static void mass_storage_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(param);
|
||||
ARG_UNUSED(cfg);
|
||||
|
||||
/* Check the USB status and do needed action if required */
|
||||
switch (status) {
|
||||
|
|
|
@ -351,8 +351,12 @@ static inline void ecm_status_interface(const u8_t *iface)
|
|||
netusb_enable(&ecm_function);
|
||||
}
|
||||
|
||||
static void ecm_do_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
static void ecm_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(cfg);
|
||||
|
||||
/* Check the USB status and do needed action if required */
|
||||
switch (status) {
|
||||
case USB_DC_DISCONNECTED:
|
||||
|
@ -384,21 +388,6 @@ static void ecm_do_cb(enum usb_dc_status_code status, const u8_t *param)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_COMPOSITE_DEVICE
|
||||
static void ecm_status_composite_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(cfg);
|
||||
ecm_do_cb(status, param);
|
||||
}
|
||||
#else
|
||||
static void ecm_status_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
{
|
||||
ecm_do_cb(status, param);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct usb_cdc_ecm_mac_descr {
|
||||
u8_t bLength;
|
||||
u8_t bDescriptorType;
|
||||
|
@ -438,11 +427,7 @@ USBD_CFG_DATA_DEFINE(netusb) struct usb_cfg_data netusb_config = {
|
|||
.usb_device_description = NULL,
|
||||
.interface_config = ecm_interface_config,
|
||||
.interface_descriptor = &cdc_ecm_cfg.if0,
|
||||
#ifdef CONFIG_USB_COMPOSITE_DEVICE
|
||||
.cb_usb_status_composite = ecm_status_composite_cb,
|
||||
#else
|
||||
.cb_usb_status = ecm_status_cb,
|
||||
#endif
|
||||
.interface = {
|
||||
.class_handler = ecm_class_handler,
|
||||
.custom_handler = NULL,
|
||||
|
|
|
@ -232,8 +232,12 @@ static inline void eem_status_interface(const u8_t *iface)
|
|||
netusb_enable(&eem_function);
|
||||
}
|
||||
|
||||
static void eem_do_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
static void eem_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(cfg);
|
||||
|
||||
/* Check the USB status and do needed action if required */
|
||||
switch (status) {
|
||||
case USB_DC_DISCONNECTED:
|
||||
|
@ -265,21 +269,6 @@ static void eem_do_cb(enum usb_dc_status_code status, const u8_t *param)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_COMPOSITE_DEVICE
|
||||
static void eem_status_composite_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(cfg);
|
||||
eem_do_cb(status, param);
|
||||
}
|
||||
#else
|
||||
static void eem_status_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
{
|
||||
eem_do_cb(status, param);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void eem_interface_config(struct usb_desc_header *head,
|
||||
u8_t bInterfaceNumber)
|
||||
{
|
||||
|
@ -292,11 +281,7 @@ USBD_CFG_DATA_DEFINE(netusb) struct usb_cfg_data netusb_config = {
|
|||
.usb_device_description = NULL,
|
||||
.interface_config = eem_interface_config,
|
||||
.interface_descriptor = &cdc_eem_cfg.if0,
|
||||
#ifdef CONFIG_USB_COMPOSITE_DEVICE
|
||||
.cb_usb_status_composite = eem_status_composite_cb,
|
||||
#else
|
||||
.cb_usb_status = eem_status_cb,
|
||||
#endif
|
||||
.interface = {
|
||||
.class_handler = NULL,
|
||||
.custom_handler = NULL,
|
||||
|
|
|
@ -1113,8 +1113,12 @@ static struct netusb_function rndis_function = {
|
|||
.send_pkt = rndis_send,
|
||||
};
|
||||
|
||||
static void rndis_do_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
static void rndis_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(cfg);
|
||||
|
||||
/* Check the USB status and do needed action if required */
|
||||
switch (status) {
|
||||
case USB_DC_CONFIGURED:
|
||||
|
@ -1146,21 +1150,6 @@ static void rndis_do_cb(enum usb_dc_status_code status, const u8_t *param)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_COMPOSITE_DEVICE
|
||||
static void rndis_status_composite_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(cfg);
|
||||
rndis_do_cb(status, param);
|
||||
}
|
||||
#else
|
||||
static void rndis_status_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
{
|
||||
rndis_do_cb(status, param);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void netusb_interface_config(struct usb_desc_header *head,
|
||||
u8_t bInterfaceNumber)
|
||||
{
|
||||
|
@ -1179,11 +1168,7 @@ USBD_CFG_DATA_DEFINE(netusb) struct usb_cfg_data netusb_config = {
|
|||
.usb_device_description = NULL,
|
||||
.interface_config = netusb_interface_config,
|
||||
.interface_descriptor = &rndis_cfg.if0,
|
||||
#ifdef CONFIG_USB_COMPOSITE_DEVICE
|
||||
.cb_usb_status_composite = rndis_status_composite_cb,
|
||||
#else
|
||||
.cb_usb_status = rndis_status_cb,
|
||||
#endif
|
||||
.interface = {
|
||||
.class_handler = rndis_class_handler,
|
||||
.custom_handler = NULL,
|
||||
|
|
|
@ -592,9 +592,12 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
|
|||
*
|
||||
* @return N/A.
|
||||
*/
|
||||
static void dfu_status_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
static void dfu_status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(param);
|
||||
ARG_UNUSED(cfg);
|
||||
|
||||
/* Check the USB status and do needed action if required */
|
||||
switch (status) {
|
||||
|
|
|
@ -909,6 +909,19 @@ static void usb_register_status_callback(usb_dc_status_callback cb)
|
|||
usb_dev.status_callback = cb;
|
||||
}
|
||||
|
||||
static void forward_status_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
{
|
||||
size_t size = (__usb_data_end - __usb_data_start);
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
struct usb_cfg_data *cfg = &__usb_data_start[i];
|
||||
|
||||
if (cfg->cb_usb_status) {
|
||||
cfg->cb_usb_status(cfg, status, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief turn on/off USB VBUS voltage
|
||||
*
|
||||
|
@ -983,11 +996,6 @@ int usb_set_config(struct usb_cfg_data *config)
|
|||
config->interface.custom_handler);
|
||||
}
|
||||
|
||||
/* register status callback */
|
||||
if (config->cb_usb_status != NULL) {
|
||||
usb_register_status_callback(config->cb_usb_status);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1029,9 +1037,11 @@ int usb_enable(struct usb_cfg_data *config)
|
|||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = usb_dc_set_status_callback(config->cb_usb_status);
|
||||
if (ret < 0)
|
||||
usb_register_status_callback(forward_status_cb);
|
||||
ret = usb_dc_set_status_callback(forward_status_cb);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = usb_dc_attach();
|
||||
if (ret < 0)
|
||||
|
@ -1403,19 +1413,6 @@ int usb_wakeup_request(void)
|
|||
|
||||
static u8_t iface_data_buf[CONFIG_USB_COMPOSITE_BUFFER_SIZE];
|
||||
|
||||
static void forward_status_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
{
|
||||
size_t size = (__usb_data_end - __usb_data_start);
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
struct usb_cfg_data *cfg = &__usb_data_start[i];
|
||||
|
||||
if (cfg->cb_usb_status_composite) {
|
||||
cfg->cb_usb_status_composite(cfg, status, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The functions class_handler(), custom_handler() and vendor_handler()
|
||||
* go through the interfaces one after the other and compare the
|
||||
|
|
|
@ -88,8 +88,13 @@ static const struct dev_common_descriptor {
|
|||
|
||||
struct usb_desc_header *__usb_descriptor_start = (void *)&desc;
|
||||
|
||||
static void status_cb(enum usb_dc_status_code status, const u8_t *param)
|
||||
static void status_cb(struct usb_cfg_data *cfg,
|
||||
enum usb_dc_status_code status,
|
||||
const u8_t *param)
|
||||
{
|
||||
ARG_UNUSED(cfg);
|
||||
ARG_UNUSED(status);
|
||||
ARG_UNUSED(param);
|
||||
}
|
||||
|
||||
/* EP Bulk IN handler, used to send data to the Host */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue