diff --git a/include/usb/class/usb_audio.h b/include/usb/class/usb_audio.h index 082ae41558c..6326d2262bc 100644 --- a/include/usb/class/usb_audio.h +++ b/include/usb/class/usb_audio.h @@ -21,7 +21,7 @@ #ifndef ZEPHYR_INCLUDE_USB_CLASS_AUDIO_H_ #define ZEPHYR_INCLUDE_USB_CLASS_AUDIO_H_ -#include +#include #include #include #include diff --git a/include/usb/class/usb_cdc.h b/include/usb/class/usb_cdc.h index 9cd4b5e8765..1824026db18 100644 --- a/include/usb/class/usb_cdc.h +++ b/include/usb/class/usb_cdc.h @@ -32,6 +32,7 @@ /** Communications Class Protocol Codes */ #define AT_CMD_V250_PROTOCOL 0x01 #define EEM_PROTOCOL 0x07 +#define ACM_VENDOR_PROTOCOL 0xFF /** * @brief Data Class Interface Codes diff --git a/include/usb/usb_device.h b/include/usb/usb_device.h index f159c68e1d8..727973e9293 100644 --- a/include/usb/usb_device.h +++ b/include/usb/usb_device.h @@ -39,7 +39,7 @@ #define ZEPHYR_INCLUDE_USB_USB_DEVICE_H_ #include -#include +#include #include #ifdef __cplusplus @@ -83,15 +83,6 @@ extern "C" { * USB application interface **************************************************************************/ -/** setup packet definitions */ -struct usb_setup_packet { - uint8_t bmRequestType; /**< characteristics of the specific request */ - uint8_t bRequest; /**< specific request */ - uint16_t wValue; /**< request specific parameter */ - uint16_t wIndex; /**< request specific parameter */ - uint16_t wLength; /**< length of data transferred in data phase */ -}; - /** * @brief USB Device Core Layer API * @defgroup _usb_device_core_api USB Device Core API diff --git a/subsys/tracing/tracing_backend_usb.c b/subsys/tracing/tracing_backend_usb.c index 9e5ea788beb..113ef6d8771 100644 --- a/subsys/tracing/tracing_backend_usb.c +++ b/subsys/tracing/tracing_backend_usb.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -35,11 +34,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_device_desc dev_desc = { */ .if0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 0, .bNumEndpoints = 2, - .bInterfaceClass = CUSTOM_CLASS, + .bInterfaceClass = USB_BCC_VENDOR, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0, .iInterface = 0, @@ -50,7 +49,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_device_desc dev_desc = { */ .if0_in_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = TRACING_IF_IN_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = sys_cpu_to_le16(CONFIG_TRACING_USB_MPS), @@ -62,7 +61,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_device_desc dev_desc = { */ .if0_out_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = TRACING_IF_OUT_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = sys_cpu_to_le16(CONFIG_TRACING_USB_MPS), diff --git a/subsys/usb/bos.c b/subsys/usb/bos.c index 00277b8e453..4d451e355d9 100644 --- a/subsys/usb/bos.c +++ b/subsys/usb/bos.c @@ -11,7 +11,6 @@ LOG_MODULE_REGISTER(usb_bos); #include #include -#include #include @@ -20,7 +19,7 @@ extern const uint8_t __usb_bos_desc_end[]; USB_DEVICE_BOS_DESC_DEFINE_HDR struct usb_bos_descriptor bos_hdr = { .bLength = sizeof(struct usb_bos_descriptor), - .bDescriptorType = USB_BINARY_OBJECT_STORE_DESC, + .bDescriptorType = USB_DESC_BOS, .wTotalLength = 0, /* should be corrected with register */ .bNumDeviceCaps = 0, /* should be set with register */ }; @@ -51,7 +50,7 @@ void usb_bos_register_cap(struct usb_bos_platform_descriptor *desc) int usb_handle_bos(struct usb_setup_packet *setup, int32_t *len, uint8_t **data) { - if (GET_DESC_TYPE(setup->wValue) == DESCRIPTOR_TYPE_BOS) { + if (USB_GET_DESCRIPTOR_TYPE(setup->wValue) == USB_DESC_BOS) { LOG_DBG("Read BOS descriptor"); *data = (uint8_t *)usb_bos_get_header(); *len = usb_bos_get_length(); diff --git a/subsys/usb/class/audio/audio.c b/subsys/usb/class/audio/audio.c index 2b5edbfe24c..3fc4b52db5c 100644 --- a/subsys/usb/class/audio/audio.c +++ b/subsys/usb/class/audio/audio.c @@ -12,10 +12,8 @@ */ #include -#include #include #include -#include #include #include "usb_audio_internal.h" @@ -693,8 +691,7 @@ static int audio_custom_handler(struct usb_setup_packet *pSetup, int32_t *len, uint8_t iface = (pSetup->wIndex) & 0xFF; - if (REQTYPE_GET_RECIP(pSetup->bmRequestType) != - REQTYPE_RECIP_INTERFACE) { + if (pSetup->RequestType.recipient != USB_REQTYPE_RECIPIENT_INTERFACE) { return -EINVAL; } @@ -733,7 +730,7 @@ static int audio_custom_handler(struct usb_setup_packet *pSetup, int32_t *len, USB_FORMAT_TYPE_I_DESC_SIZE); } - if (pSetup->bRequest == REQ_SET_INTERFACE) { + if (pSetup->bRequest == USB_SREQ_SET_INTERFACE) { if (ep_desc->bEndpointAddress & USB_EP_DIR_MASK) { audio_dev_data->tx_enable = pSetup->wValue; } else { @@ -760,8 +757,8 @@ static int audio_class_handle_req(struct usb_setup_packet *pSetup, pSetup->bmRequestType, pSetup->bRequest, pSetup->wValue, pSetup->wIndex, pSetup->wLength); - switch (REQTYPE_GET_RECIP(pSetup->bmRequestType)) { - case REQTYPE_RECIP_INTERFACE: + switch (pSetup->RequestType.recipient) { + case USB_REQTYPE_RECIPIENT_INTERFACE: return handle_interface_req(pSetup, len, data); default: LOG_ERR("Request recipient invalid"); diff --git a/subsys/usb/class/audio/usb_audio_internal.h b/subsys/usb/class/audio/usb_audio_internal.h index e4e7cc0516d..e207b4ced4c 100644 --- a/subsys/usb/class/audio/usb_audio_internal.h +++ b/subsys/usb/class/audio/usb_audio_internal.h @@ -319,10 +319,10 @@ struct dev##_feature_unit_descriptor_##i { \ #define INIT_IAD(iface_subclass, if_cnt) \ { \ .bLength = sizeof(struct usb_association_descriptor), \ - .bDescriptorType = USB_ASSOCIATION_DESC, \ + .bDescriptorType = USB_DESC_INTERFACE_ASSOC, \ .bFirstInterface = 0, \ .bInterfaceCount = if_cnt, \ - .bFunctionClass = AUDIO_CLASS, \ + .bFunctionClass = USB_BCC_AUDIO, \ .bFunctionSubClass = iface_subclass, \ .bFunctionProtocol = 0, \ .iFunction = 0, \ @@ -385,11 +385,11 @@ struct dev##_descriptor_##i { \ #define INIT_STD_IF(iface_subclass, iface_num, alt_setting, eps_num) \ { \ .bLength = sizeof(struct usb_if_descriptor), \ - .bDescriptorType = USB_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_INTERFACE, \ .bInterfaceNumber = iface_num, \ .bAlternateSetting = alt_setting, \ .bNumEndpoints = eps_num, \ - .bInterfaceClass = AUDIO_CLASS, \ + .bInterfaceClass = USB_BCC_AUDIO, \ .bInterfaceSubClass = iface_subclass, \ .bInterfaceProtocol = 0, \ .iInterface = 0, \ @@ -398,7 +398,7 @@ struct dev##_descriptor_##i { \ #define INIT_CS_AC_IF(dev, i, ifaces) \ { \ .bLength = sizeof(struct dev##_cs_ac_if_descriptor_##i), \ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = USB_AUDIO_HEADER, \ .bcdADC = sys_cpu_to_le16(0x0100), \ .wTotalLength = sys_cpu_to_le16( \ @@ -413,7 +413,7 @@ struct dev##_descriptor_##i { \ #define INIT_CS_AC_IF_BIDIR(dev, i, ifaces) \ { \ .bLength = sizeof(struct dev##_cs_ac_if_descriptor_##i), \ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = USB_AUDIO_HEADER, \ .bcdADC = sys_cpu_to_le16(0x0100), \ .wTotalLength = sys_cpu_to_le16( \ @@ -429,7 +429,7 @@ struct dev##_descriptor_##i { \ #define INIT_IN_TERMINAL(dev, i, terminal_id, type) \ { \ .bLength = INPUT_TERMINAL_DESC_SIZE, \ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = USB_AUDIO_INPUT_TERMINAL, \ .bTerminalID = terminal_id, \ .wTerminalType = sys_cpu_to_le16(type), \ @@ -443,7 +443,7 @@ struct dev##_descriptor_##i { \ #define INIT_OUT_TERMINAL(terminal_id, source_id, type) \ { \ .bLength = OUTPUT_TERMINAL_DESC_SIZE, \ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = USB_AUDIO_OUTPUT_TERMINAL,\ .bTerminalID = terminal_id, \ .wTerminalType = sys_cpu_to_le16(type), \ @@ -457,7 +457,7 @@ struct dev##_descriptor_##i { \ #define INIT_FEATURE_UNIT(dev, i, unit_id, source_id) \ { \ .bLength = sizeof(struct dev##_feature_unit_descriptor_##i), \ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = USB_AUDIO_FEATURE_UNIT, \ .bUnitID = unit_id, \ .bSourceID = source_id, \ @@ -470,7 +470,7 @@ struct dev##_descriptor_##i { \ #define INIT_AS_GENERAL(link) \ { \ .bLength = USB_AC_CS_IF_DESC_SIZE, \ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = USB_AUDIO_AS_GENERAL, \ .bTerminalLink = link, \ .bDelay = 0, \ @@ -484,7 +484,7 @@ struct dev##_descriptor_##i { \ #define INIT_AS_FORMAT_I(ch_cnt, res) \ { \ .bLength = sizeof(struct format_type_i_descriptor), \ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = USB_AUDIO_FORMAT_TYPE, \ .bFormatType = 0x01, \ .bNrChannels = MAX(1, ch_cnt), \ @@ -497,7 +497,7 @@ struct dev##_descriptor_##i { \ #define INIT_STD_AS_AD_EP(dev, i, addr) \ { \ .bLength = sizeof(struct std_as_ad_endpoint_descriptor), \ - .bDescriptorType = USB_ENDPOINT_DESC, \ + .bDescriptorType = USB_DESC_ENDPOINT, \ .bEndpointAddress = addr, \ .bmAttributes = (USB_DC_EP_ISOCHRONOUS | SYNC_TYPE(dev, i)), \ .wMaxPacketSize = sys_cpu_to_le16(EP_SIZE(dev, i)), \ @@ -509,7 +509,7 @@ struct dev##_descriptor_##i { \ #define INIT_CS_AS_AD_EP \ { \ .bLength = sizeof(struct cs_as_ad_ep_descriptor), \ - .bDescriptorType = USB_CS_ENDPOINT_DESC, \ + .bDescriptorType = USB_DESC_CS_ENDPOINT, \ .bDescriptorSubtype = 0x01, \ .bmAttributes = 0x00, \ .bLockDelayUnits = 0x00, \ diff --git a/subsys/usb/class/bluetooth.c b/subsys/usb/class/bluetooth.c index 173f35e48fa..f91270f5d3c 100644 --- a/subsys/usb/class/bluetooth.c +++ b/subsys/usb/class/bluetooth.c @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -25,6 +24,9 @@ #include LOG_MODULE_REGISTER(usb_bluetooth); +#define USB_RF_SUBCLASS 0x01 +#define USB_BLUETOOTH_PROTOCOL 0x01 + static K_FIFO_DEFINE(rx_queue); static K_FIFO_DEFINE(tx_queue); @@ -56,20 +58,20 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) /* Interface descriptor 0 */ .if0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 0, .bNumEndpoints = 3, - .bInterfaceClass = WIRELESS_DEVICE_CLASS, - .bInterfaceSubClass = RF_SUBCLASS, - .bInterfaceProtocol = BLUETOOTH_PROTOCOL, + .bInterfaceClass = USB_BCC_WIRELESS_CONTROLLER, + .bInterfaceSubClass = USB_RF_SUBCLASS, + .bInterfaceProtocol = USB_BLUETOOTH_PROTOCOL, .iInterface = 0, }, /* Interrupt Endpoint */ .if0_int_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = BLUETOOTH_INT_EP_ADDR, .bmAttributes = USB_DC_EP_INTERRUPT, .wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_INT_MPS), @@ -79,7 +81,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) /* Data Endpoint OUT */ .if0_out_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = BLUETOOTH_OUT_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_BULK_MPS), @@ -89,7 +91,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) /* Data Endpoint IN */ .if0_in_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = BLUETOOTH_IN_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_BULK_MPS), diff --git a/subsys/usb/class/bt_h4.c b/subsys/usb/class/bt_h4.c index 6995f5ea6df..56bd8f70d7b 100644 --- a/subsys/usb/class/bt_h4.c +++ b/subsys/usb/class/bt_h4.c @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -52,11 +51,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_bt_h4_config bt_h4_cfg = { /* Interface descriptor 0 */ .if0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 0, .bNumEndpoints = 2, - .bInterfaceClass = CUSTOM_CLASS, /* TBD */ + .bInterfaceClass = USB_BCC_VENDOR, /* TBD */ .bInterfaceSubClass = 0, .bInterfaceProtocol = 0, .iInterface = 0, @@ -65,7 +64,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_bt_h4_config bt_h4_cfg = { /* Data Endpoint OUT */ .if0_out_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = BT_H4_OUT_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_BULK_MPS), @@ -75,7 +74,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_bt_h4_config bt_h4_cfg = { /* Data Endpoint IN */ .if0_in_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = BT_H4_IN_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_BULK_MPS), @@ -203,17 +202,17 @@ static int bt_h4_vendor_handler(struct usb_setup_packet *setup, LOG_DBG("Class request: bRequest 0x%x bmRequestType 0x%x len %d", setup->bRequest, setup->bmRequestType, *len); - if (REQTYPE_GET_RECIP(setup->bmRequestType) != REQTYPE_RECIP_DEVICE) { + if (setup->RequestType.recipient != USB_REQTYPE_RECIPIENT_DEVICE) { return -ENOTSUP; } - if (REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_DEVICE && + if (usb_reqtype_is_to_device(setup) && setup->bRequest == 0x5b) { LOG_DBG("Host-to-Device, data %p", *data); return 0; } - if ((REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_HOST) && + if ((usb_reqtype_is_to_host(setup)) && (setup->bRequest == 0x5c)) { LOG_DBG("Device-to-Host, wLength %d, data %p", setup->wLength, *data); diff --git a/subsys/usb/class/cdc_acm.c b/subsys/usb/class/cdc_acm.c index 621f433152a..0a1ed585145 100644 --- a/subsys/usb/class/cdc_acm.c +++ b/subsys/usb/class/cdc_acm.c @@ -46,7 +46,6 @@ #include #include #include -#include #include #include @@ -95,10 +94,10 @@ struct usb_cdc_acm_config { #define INITIALIZER_IAD \ { \ .bLength = sizeof(struct usb_association_descriptor), \ - .bDescriptorType = USB_ASSOCIATION_DESC, \ + .bDescriptorType = USB_DESC_INTERFACE_ASSOC, \ .bFirstInterface = 0, \ .bInterfaceCount = 0x02, \ - .bFunctionClass = COMMUNICATION_DEVICE_CLASS, \ + .bFunctionClass = USB_BCC_CDC_CONTROL, \ .bFunctionSubClass = ACM_SUBCLASS, \ .bFunctionProtocol = 0, \ .iFunction = 0, \ @@ -107,7 +106,7 @@ struct usb_cdc_acm_config { #define INITIALIZER_IF(iface_num, num_ep, class, subclass) \ { \ .bLength = sizeof(struct usb_if_descriptor), \ - .bDescriptorType = USB_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_INTERFACE, \ .bInterfaceNumber = iface_num, \ .bAlternateSetting = 0, \ .bNumEndpoints = num_ep, \ @@ -120,15 +119,15 @@ struct usb_cdc_acm_config { #define INITIALIZER_IF_HDR \ { \ .bFunctionLength = sizeof(struct cdc_header_descriptor),\ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = HEADER_FUNC_DESC, \ - .bcdCDC = sys_cpu_to_le16(USB_1_1), \ + .bcdCDC = sys_cpu_to_le16(USB_SRN_1_1), \ } #define INITIALIZER_IF_CM \ { \ .bFunctionLength = sizeof(struct cdc_cm_descriptor), \ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = CALL_MANAGEMENT_FUNC_DESC, \ .bmCapabilities = 0x02, \ .bDataInterface = 1, \ @@ -143,7 +142,7 @@ struct usb_cdc_acm_config { #define INITIALIZER_IF_ACM \ { \ .bFunctionLength = sizeof(struct cdc_acm_descriptor), \ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = ACM_FUNC_DESC, \ .bmCapabilities = 0x02, \ } @@ -151,7 +150,7 @@ struct usb_cdc_acm_config { #define INITIALIZER_IF_UNION \ { \ .bFunctionLength = sizeof(struct cdc_union_descriptor), \ - .bDescriptorType = USB_CS_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_CS_INTERFACE, \ .bDescriptorSubtype = UNION_FUNC_DESC, \ .bControlInterface = 0, \ .bSubordinateInterface0 = 1, \ @@ -160,7 +159,7 @@ struct usb_cdc_acm_config { #define INITIALIZER_IF_EP(addr, attr, mps, interval) \ { \ .bLength = sizeof(struct usb_ep_descriptor), \ - .bDescriptorType = USB_ENDPOINT_DESC, \ + .bDescriptorType = USB_DESC_ENDPOINT, \ .bEndpointAddress = addr, \ .bmAttributes = attr, \ .wMaxPacketSize = sys_cpu_to_le16(mps), \ @@ -1044,11 +1043,11 @@ static const struct uart_driver_api cdc_acm_driver_api = { }; #if (CONFIG_USB_COMPOSITE_DEVICE || CONFIG_CDC_ACM_IAD) -#define DEFINE_CDC_ACM_DESCR(x, int_ep_addr, out_ep_addr, in_ep_addr) \ +#define DEFINE_CDC_ACM_DESC(x, int_ep_addr, out_ep_addr, in_ep_addr) \ USBD_CLASS_DESCR_DEFINE(primary, x) \ struct usb_cdc_acm_config cdc_acm_cfg_##x = { \ .iad_cdc = INITIALIZER_IAD, \ - .if0 = INITIALIZER_IF(0, 1, COMMUNICATION_DEVICE_CLASS, \ + .if0 = INITIALIZER_IF(0, 1, USB_BCC_CDC_CONTROL, \ ACM_SUBCLASS), \ .if0_header = INITIALIZER_IF_HDR, \ .if0_cm = INITIALIZER_IF_CM, \ @@ -1058,7 +1057,7 @@ static const struct uart_driver_api cdc_acm_driver_api = { USB_DC_EP_INTERRUPT, \ CONFIG_CDC_ACM_INTERRUPT_EP_MPS,\ 0x0A), \ - .if1 = INITIALIZER_IF(1, 2, COMMUNICATION_DEVICE_CLASS_DATA, 0),\ + .if1 = INITIALIZER_IF(1, 2, USB_BCC_CDC_DATA, 0), \ .if1_in_ep = INITIALIZER_IF_EP(in_ep_addr, \ USB_DC_EP_BULK, \ CONFIG_CDC_ACM_BULK_EP_MPS, \ @@ -1069,10 +1068,10 @@ static const struct uart_driver_api cdc_acm_driver_api = { 0x00), \ } #else /* (CONFIG_USB_COMPOSITE_DEVICE || CONFIG_CDC_ACM_IAD) */ -#define DEFINE_CDC_ACM_DESCR(x, int_ep_addr, out_ep_addr, in_ep_addr) \ +#define DEFINE_CDC_ACM_DESC(x, int_ep_addr, out_ep_addr, in_ep_addr) \ USBD_CLASS_DESCR_DEFINE(primary, x) \ struct usb_cdc_acm_config cdc_acm_cfg_##x = { \ - .if0 = INITIALIZER_IF(0, 1, COMMUNICATION_DEVICE_CLASS, \ + .if0 = INITIALIZER_IF(0, 1, USB_BCC_CDC_CONTROL, \ ACM_SUBCLASS), \ .if0_header = INITIALIZER_IF_HDR, \ .if0_cm = INITIALIZER_IF_CM, \ @@ -1082,7 +1081,7 @@ static const struct uart_driver_api cdc_acm_driver_api = { USB_DC_EP_INTERRUPT, \ CONFIG_CDC_ACM_INTERRUPT_EP_MPS,\ 0x0A), \ - .if1 = INITIALIZER_IF(1, 2, COMMUNICATION_DEVICE_CLASS_DATA, 0),\ + .if1 = INITIALIZER_IF(1, 2, USB_BCC_CDC_DATA, 0), \ .if1_in_ep = INITIALIZER_IF_EP(in_ep_addr, \ USB_DC_EP_BULK, \ CONFIG_CDC_ACM_BULK_EP_MPS, \ @@ -1115,13 +1114,13 @@ static const struct uart_driver_api cdc_acm_driver_api = { CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ &cdc_acm_driver_api); -#define DEFINE_CDC_ACM_DESCR_AUTO(x, _) \ - DEFINE_CDC_ACM_DESCR(x, AUTO_EP_IN, AUTO_EP_OUT, AUTO_EP_IN); +#define DEFINE_CDC_ACM_DESC_AUTO(x, _) \ + DEFINE_CDC_ACM_DESC(x, AUTO_EP_IN, AUTO_EP_OUT, AUTO_EP_IN); #define DEFINE_CDC_ACM_EP_AUTO(x, _) \ DEFINE_CDC_ACM_EP(x, AUTO_EP_IN, AUTO_EP_OUT, AUTO_EP_IN); -UTIL_LISTIFY(CONFIG_USB_CDC_ACM_DEVICE_COUNT, DEFINE_CDC_ACM_DESCR_AUTO, _) +UTIL_LISTIFY(CONFIG_USB_CDC_ACM_DEVICE_COUNT, DEFINE_CDC_ACM_DESC_AUTO, _) UTIL_LISTIFY(CONFIG_USB_CDC_ACM_DEVICE_COUNT, DEFINE_CDC_ACM_EP_AUTO, _) UTIL_LISTIFY(CONFIG_USB_CDC_ACM_DEVICE_COUNT, DEFINE_CDC_ACM_CFG_DATA, _) UTIL_LISTIFY(CONFIG_USB_CDC_ACM_DEVICE_COUNT, DEFINE_CDC_ACM_DEV_DATA, _) diff --git a/subsys/usb/class/dfu/usb_dfu.c b/subsys/usb/class/dfu/usb_dfu.c index 93ff2e1ff1a..3f837d2af50 100644 --- a/subsys/usb/class/dfu/usb_dfu.c +++ b/subsys/usb/class/dfu/usb_dfu.c @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -89,11 +88,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_dfu_config dfu_cfg = { /* Interface descriptor */ .if0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 0, .bNumEndpoints = 0, - .bInterfaceClass = DFU_DEVICE_CLASS, + .bInterfaceClass = USB_BCC_APPLICATION, .bInterfaceSubClass = DFU_SUBCLASS, .bInterfaceProtocol = DFU_RT_PROTOCOL, .iInterface = 0, @@ -133,8 +132,8 @@ struct dev_dfu_mode_descriptor dfu_mode_desc = { /* Device descriptor */ .device_descriptor = { .bLength = sizeof(struct usb_device_descriptor), - .bDescriptorType = USB_DEVICE_DESC, - .bcdUSB = sys_cpu_to_le16(USB_2_0), + .bDescriptorType = USB_DESC_DEVICE, + .bcdUSB = sys_cpu_to_le16(USB_SRN_2_0), .bDeviceClass = 0, .bDeviceSubClass = 0, .bDeviceProtocol = 0, @@ -142,7 +141,7 @@ struct dev_dfu_mode_descriptor dfu_mode_desc = { .idVendor = sys_cpu_to_le16((uint16_t)CONFIG_USB_DEVICE_VID), .idProduct = sys_cpu_to_le16((uint16_t)CONFIG_USB_DEVICE_DFU_PID), - .bcdDevice = sys_cpu_to_le16(BCDDEVICE_RELNUM), + .bcdDevice = sys_cpu_to_le16(USB_BCD_DRN), .iManufacturer = 1, .iProduct = 2, .iSerialNumber = 3, @@ -151,23 +150,23 @@ struct dev_dfu_mode_descriptor dfu_mode_desc = { /* Configuration descriptor */ .cfg_descr = { .bLength = sizeof(struct usb_cfg_descriptor), - .bDescriptorType = USB_CONFIGURATION_DESC, + .bDescriptorType = USB_DESC_CONFIGURATION, .wTotalLength = 0, .bNumInterfaces = 1, .bConfigurationValue = 1, .iConfiguration = 0, - .bmAttributes = USB_CONFIGURATION_ATTRIBUTES, + .bmAttributes = USB_SCD_ATTRIBUTES, .bMaxPower = CONFIG_USB_MAX_POWER, }, .sec_dfu_cfg = { /* Interface descriptor */ .if0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 0, .bNumEndpoints = 0, - .bInterfaceClass = DFU_DEVICE_CLASS, + .bInterfaceClass = USB_BCC_APPLICATION, .bInterfaceSubClass = DFU_SUBCLASS, .bInterfaceProtocol = DFU_MODE_PROTOCOL, .iInterface = 4, @@ -175,11 +174,11 @@ struct dev_dfu_mode_descriptor dfu_mode_desc = { #if FLASH_AREA_LABEL_EXISTS(image_1) .if1 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 1, .bNumEndpoints = 0, - .bInterfaceClass = DFU_DEVICE_CLASS, + .bInterfaceClass = USB_BCC_APPLICATION, .bInterfaceSubClass = DFU_SUBCLASS, .bInterfaceProtocol = DFU_MODE_PROTOCOL, .iInterface = 5, @@ -241,34 +240,34 @@ USBD_STRING_DESCR_DEFINE(secondary) struct usb_string_desription string_descr = { .lang_descr = { .bLength = sizeof(struct usb_string_descriptor), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = sys_cpu_to_le16(0x0409), }, /* Manufacturer String Descriptor */ .utf16le_mfr = { .bLength = USB_STRING_DESCRIPTOR_LENGTH( CONFIG_USB_DEVICE_MANUFACTURER), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = CONFIG_USB_DEVICE_MANUFACTURER, }, /* Product String Descriptor */ .utf16le_product = { .bLength = USB_STRING_DESCRIPTOR_LENGTH( CONFIG_USB_DEVICE_PRODUCT), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = CONFIG_USB_DEVICE_PRODUCT, }, /* Serial Number String Descriptor */ .utf16le_sn = { .bLength = USB_STRING_DESCRIPTOR_LENGTH(CONFIG_USB_DEVICE_SN), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = CONFIG_USB_DEVICE_SN, }, /* Image 0 String Descriptor */ .utf16le_image0 = { .bLength = USB_STRING_DESCRIPTOR_LENGTH( FIRMWARE_IMAGE_0_LABEL), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = FIRMWARE_IMAGE_0_LABEL, }, #if FLASH_AREA_LABEL_EXISTS(image_1) @@ -276,7 +275,7 @@ struct usb_string_desription string_descr = { .utf16le_image1 = { .bLength = USB_STRING_DESCRIPTOR_LENGTH( FIRMWARE_IMAGE_1_LABEL), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = FIRMWARE_IMAGE_1_LABEL, }, #endif @@ -681,9 +680,8 @@ static int dfu_custom_handle_req(struct usb_setup_packet *pSetup, { ARG_UNUSED(data); - if (REQTYPE_GET_RECIP(pSetup->bmRequestType) == - REQTYPE_RECIP_INTERFACE) { - if (pSetup->bRequest == REQ_SET_INTERFACE) { + if (pSetup->RequestType.recipient == USB_REQTYPE_RECIPIENT_INTERFACE) { + if (pSetup->bRequest == USB_SREQ_SET_INTERFACE) { LOG_DBG("DFU alternate setting %d", pSetup->wValue); const struct flash_area *fa; diff --git a/subsys/usb/class/hid/core.c b/subsys/usb/class/hid/core.c index f715689f242..f8cc88c1dfe 100644 --- a/subsys/usb/class/hid/core.c +++ b/subsys/usb/class/hid/core.c @@ -13,7 +13,6 @@ LOG_MODULE_REGISTER(usb_hid); #include #include -#include #include #include @@ -55,11 +54,11 @@ struct usb_hid_config { #define INITIALIZER_IF \ { \ .bLength = sizeof(struct usb_if_descriptor), \ - .bDescriptorType = USB_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_INTERFACE, \ .bInterfaceNumber = 0, \ .bAlternateSetting = 0, \ .bNumEndpoints = 1, \ - .bInterfaceClass = HID_CLASS, \ + .bInterfaceClass = USB_BCC_HID, \ .bInterfaceSubClass = 1, \ .bInterfaceProtocol = CONFIG_USB_HID_PROTOCOL_CODE, \ .iInterface = 0, \ @@ -68,11 +67,11 @@ struct usb_hid_config { #define INITIALIZER_IF \ { \ .bLength = sizeof(struct usb_if_descriptor), \ - .bDescriptorType = USB_INTERFACE_DESC, \ + .bDescriptorType = USB_DESC_INTERFACE, \ .bInterfaceNumber = 0, \ .bAlternateSetting = 0, \ .bNumEndpoints = 1, \ - .bInterfaceClass = HID_CLASS, \ + .bInterfaceClass = USB_BCC_HID, \ .bInterfaceSubClass = 0, \ .bInterfaceProtocol = 0, \ .iInterface = 0, \ @@ -83,12 +82,12 @@ struct usb_hid_config { #define INITIALIZER_IF_HID \ { \ .bLength = sizeof(struct usb_hid_descriptor), \ - .bDescriptorType = USB_HID_DESC, \ - .bcdHID = sys_cpu_to_le16(USB_1_1), \ + .bDescriptorType = USB_DESC_HID, \ + .bcdHID = sys_cpu_to_le16(USB_SRN_1_1), \ .bCountryCode = 0, \ .bNumDescriptors = 1, \ .subdesc[0] = { \ - .bDescriptorType = USB_HID_REPORT_DESC, \ + .bDescriptorType = USB_DESC_HID_REPORT, \ .wDescriptorLength = 0, \ }, \ } @@ -96,7 +95,7 @@ struct usb_hid_config { #define INITIALIZER_IF_EP(addr, attr, mps) \ { \ .bLength = sizeof(struct usb_ep_descriptor), \ - .bDescriptorType = USB_ENDPOINT_DESC, \ + .bDescriptorType = USB_DESC_ENDPOINT, \ .bEndpointAddress = addr, \ .bmAttributes = attr, \ .wMaxPacketSize = sys_cpu_to_le16(mps), \ @@ -449,7 +448,7 @@ static int hid_class_handle_req(struct usb_setup_packet *setup, dev_data = CONTAINER_OF(common, struct hid_device_info, common); dev = common->dev; - if (REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_HOST) { + if (usb_reqtype_is_to_host(setup)) { switch (setup->bRequest) { case USB_HID_GET_IDLE: return hid_on_get_idle(dev_data, setup, len, data); @@ -499,10 +498,9 @@ static int hid_custom_handle_req(struct usb_setup_packet *setup, "bRequest 0x%02x, bmRequestType 0x%02x, len %d", setup->bRequest, setup->bmRequestType, *len); - if (REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_HOST && - REQTYPE_GET_RECIP(setup->bmRequestType) == - REQTYPE_RECIP_INTERFACE && - setup->bRequest == REQ_GET_DESCRIPTOR) { + if (usb_reqtype_is_to_host(setup) && + setup->RequestType.recipient == USB_REQTYPE_RECIPIENT_INTERFACE && + setup->bRequest == USB_SREQ_GET_DESCRIPTOR) { uint8_t value = (uint8_t)(setup->wValue >> 8); uint8_t iface_num = (uint8_t)setup->wIndex; struct hid_device_info *dev_data; diff --git a/subsys/usb/class/loopback.c b/subsys/usb/class/loopback.c index a49c51e691f..ecd79133cf3 100644 --- a/subsys/usb/class/loopback.c +++ b/subsys/usb/class/loopback.c @@ -10,7 +10,6 @@ #include #include -#include #include #define LOG_LEVEL CONFIG_USB_DEVICE_LOG_LEVEL @@ -36,11 +35,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_loopback_config loopback_cfg = { /* Interface descriptor 0 */ .if0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 0, .bNumEndpoints = 2, - .bInterfaceClass = CUSTOM_CLASS, + .bInterfaceClass = USB_BCC_VENDOR, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0, .iInterface = 0, @@ -49,7 +48,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_loopback_config loopback_cfg = { /* Data Endpoint OUT */ .if0_out_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = LOOPBACK_OUT_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = sys_cpu_to_le16(CONFIG_LOOPBACK_BULK_EP_MPS), @@ -59,7 +58,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_loopback_config loopback_cfg = { /* Data Endpoint IN */ .if0_in_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = LOOPBACK_IN_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = sys_cpu_to_le16(CONFIG_LOOPBACK_BULK_EP_MPS), @@ -129,17 +128,17 @@ static int loopback_vendor_handler(struct usb_setup_packet *setup, LOG_DBG("Class request: bRequest 0x%x bmRequestType 0x%x len %d", setup->bRequest, setup->bmRequestType, *len); - if (REQTYPE_GET_RECIP(setup->bmRequestType) != REQTYPE_RECIP_DEVICE) { + if (setup->RequestType.recipient != USB_REQTYPE_RECIPIENT_DEVICE) { return -ENOTSUP; } - if (REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_DEVICE && + if (usb_reqtype_is_to_device(setup) && setup->bRequest == 0x5b) { LOG_DBG("Host-to-Device, data %p", *data); return 0; } - if ((REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_HOST) && + if ((usb_reqtype_is_to_host(setup)) && (setup->bRequest == 0x5c)) { LOG_DBG("Device-to-Host, wLength %d, data %p", setup->wLength, *data); diff --git a/subsys/usb/class/msc.c b/subsys/usb/class/msc.c index 62cf15d9542..8e4e6d6b61d 100644 --- a/subsys/usb/class/msc.c +++ b/subsys/usb/class/msc.c @@ -41,7 +41,6 @@ #include #include #include -#include #include #define LOG_LEVEL CONFIG_USB_MASS_STORAGE_LOG_LEVEL @@ -71,19 +70,19 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_mass_config mass_cfg = { /* Interface descriptor */ .if0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 0, .bNumEndpoints = 2, - .bInterfaceClass = MASS_STORAGE_CLASS, + .bInterfaceClass = USB_BCC_MASS_STORAGE, .bInterfaceSubClass = SCSI_TRANSPARENT_SUBCLASS, - .bInterfaceProtocol = BULK_ONLY_PROTOCOL, + .bInterfaceProtocol = BULK_ONLY_TRANSPORT_PROTOCOL, .iInterface = 0, }, /* First Endpoint IN */ .if0_in_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = MASS_STORAGE_IN_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = @@ -93,7 +92,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_mass_config mass_cfg = { /* Second Endpoint OUT */ .if0_out_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = MASS_STORAGE_OUT_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = diff --git a/subsys/usb/class/netusb/function_ecm.c b/subsys/usb/class/netusb/function_ecm.c index c0d42e991dc..17259c810d5 100644 --- a/subsys/usb/class/netusb/function_ecm.c +++ b/subsys/usb/class/netusb/function_ecm.c @@ -16,7 +16,6 @@ LOG_MODULE_REGISTER(usb_ecm); #include #include -#include #include #include @@ -53,10 +52,10 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = { #ifdef CONFIG_USB_COMPOSITE_DEVICE .iad = { .bLength = sizeof(struct usb_association_descriptor), - .bDescriptorType = USB_ASSOCIATION_DESC, + .bDescriptorType = USB_DESC_INTERFACE_ASSOC, .bFirstInterface = 0, .bInterfaceCount = 0x02, - .bFunctionClass = COMMUNICATION_DEVICE_CLASS, + .bFunctionClass = USB_BCC_CDC_CONTROL, .bFunctionSubClass = ECM_SUBCLASS, .bFunctionProtocol = 0, .iFunction = 0, @@ -66,11 +65,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = { /* CDC Communication interface */ .if0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 0, .bNumEndpoints = 1, - .bInterfaceClass = COMMUNICATION_DEVICE_CLASS, + .bInterfaceClass = USB_BCC_CDC_CONTROL, .bInterfaceSubClass = ECM_SUBCLASS, .bInterfaceProtocol = 0, .iInterface = 0, @@ -78,14 +77,14 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = { /* Header Functional Descriptor */ .if0_header = { .bFunctionLength = sizeof(struct cdc_header_descriptor), - .bDescriptorType = USB_CS_INTERFACE_DESC, + .bDescriptorType = USB_DESC_CS_INTERFACE, .bDescriptorSubtype = HEADER_FUNC_DESC, - .bcdCDC = sys_cpu_to_le16(USB_1_1), + .bcdCDC = sys_cpu_to_le16(USB_SRN_1_1), }, /* Union Functional Descriptor */ .if0_union = { .bFunctionLength = sizeof(struct cdc_union_descriptor), - .bDescriptorType = USB_CS_INTERFACE_DESC, + .bDescriptorType = USB_DESC_CS_INTERFACE, .bDescriptorSubtype = UNION_FUNC_DESC, .bControlInterface = 0, .bSubordinateInterface0 = 1, @@ -93,7 +92,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = { /* Ethernet Networking Functional descriptor */ .if0_netfun_ecm = { .bFunctionLength = sizeof(struct cdc_ecm_descriptor), - .bDescriptorType = USB_CS_INTERFACE_DESC, + .bDescriptorType = USB_DESC_CS_INTERFACE, .bDescriptorSubtype = ETHERNET_FUNC_DESC, .iMACAddress = 4, .bmEthernetStatistics = sys_cpu_to_le32(0), /* None */ @@ -104,7 +103,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = { /* Notification EP Descriptor */ .if0_int_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = CDC_ECM_INT_EP_ADDR, .bmAttributes = USB_DC_EP_INTERRUPT, .wMaxPacketSize = @@ -117,11 +116,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = { /* CDC Data Interface */ .if1_0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 1, .bAlternateSetting = 0, .bNumEndpoints = 0, - .bInterfaceClass = COMMUNICATION_DEVICE_CLASS_DATA, + .bInterfaceClass = USB_BCC_CDC_DATA, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0, .iInterface = 0, @@ -131,11 +130,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = { /* CDC Data Interface */ .if1_1 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 1, .bAlternateSetting = 1, .bNumEndpoints = 2, - .bInterfaceClass = COMMUNICATION_DEVICE_CLASS_DATA, + .bInterfaceClass = USB_BCC_CDC_DATA, .bInterfaceSubClass = ECM_SUBCLASS, .bInterfaceProtocol = 0, .iInterface = 0, @@ -143,7 +142,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = { /* Data Endpoint IN */ .if1_1_in_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = CDC_ECM_IN_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = @@ -154,7 +153,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = { /* Data Endpoint OUT */ .if1_1_out_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = CDC_ECM_OUT_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = @@ -402,7 +401,7 @@ struct usb_cdc_ecm_mac_descr { USBD_STRING_DESCR_DEFINE(primary) struct usb_cdc_ecm_mac_descr utf16le_mac = { .bLength = USB_STRING_DESCRIPTOR_LENGTH( CONFIG_USB_DEVICE_NETWORK_ECM_MAC), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = CONFIG_USB_DEVICE_NETWORK_ECM_MAC }; diff --git a/subsys/usb/class/netusb/function_eem.c b/subsys/usb/class/netusb/function_eem.c index f625c97f223..33d35504cb9 100644 --- a/subsys/usb/class/netusb/function_eem.c +++ b/subsys/usb/class/netusb/function_eem.c @@ -13,7 +13,6 @@ LOG_MODULE_REGISTER(usb_eem); #include #include -#include #include #include "netusb.h" @@ -36,11 +35,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_eem_config cdc_eem_cfg = { /* CDC Communication interface */ .if0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 0, .bNumEndpoints = 2, - .bInterfaceClass = COMMUNICATION_DEVICE_CLASS, + .bInterfaceClass = USB_BCC_CDC_CONTROL, .bInterfaceSubClass = EEM_SUBCLASS, .bInterfaceProtocol = EEM_PROTOCOL, .iInterface = 0, @@ -49,7 +48,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_eem_config cdc_eem_cfg = { /* Data Endpoint IN */ .if0_in_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = CDC_EEM_IN_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = @@ -60,7 +59,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_eem_config cdc_eem_cfg = { /* Data Endpoint OUT */ .if0_out_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = CDC_EEM_OUT_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = diff --git a/subsys/usb/class/netusb/function_rndis.c b/subsys/usb/class/netusb/function_rndis.c index c8c83b8f2ba..a61ae1e2553 100644 --- a/subsys/usb/class/netusb/function_rndis.c +++ b/subsys/usb/class/netusb/function_rndis.c @@ -17,7 +17,6 @@ LOG_MODULE_REGISTER(usb_rndis); #include #include -#include #include #include @@ -64,10 +63,10 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = { #ifdef CONFIG_USB_COMPOSITE_DEVICE .iad = { .bLength = sizeof(struct usb_association_descriptor), - .bDescriptorType = USB_ASSOCIATION_DESC, + .bDescriptorType = USB_DESC_INTERFACE_ASSOC, .bFirstInterface = 0, .bInterfaceCount = 0x02, - .bFunctionClass = COMMUNICATION_DEVICE_CLASS, + .bFunctionClass = USB_BCC_CDC_CONTROL, .bFunctionSubClass = 6, .bFunctionProtocol = 0, .iFunction = 0, @@ -77,11 +76,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = { /* CDC Communication interface */ .if0 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 0, .bAlternateSetting = 0, .bNumEndpoints = 1, - .bInterfaceClass = COMMUNICATION_DEVICE_CLASS, + .bInterfaceClass = USB_BCC_CDC_CONTROL, .bInterfaceSubClass = ACM_SUBCLASS, .bInterfaceProtocol = ACM_VENDOR_PROTOCOL, .iInterface = 0, @@ -89,14 +88,14 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = { /* Header Functional Descriptor */ .if0_header = { .bFunctionLength = sizeof(struct cdc_header_descriptor), - .bDescriptorType = USB_CS_INTERFACE_DESC, + .bDescriptorType = USB_DESC_CS_INTERFACE, .bDescriptorSubtype = HEADER_FUNC_DESC, - .bcdCDC = sys_cpu_to_le16(USB_1_1), + .bcdCDC = sys_cpu_to_le16(USB_SRN_1_1), }, /* Call Management Functional Descriptor */ .if0_cm = { .bFunctionLength = sizeof(struct cdc_cm_descriptor), - .bDescriptorType = USB_CS_INTERFACE_DESC, + .bDescriptorType = USB_DESC_CS_INTERFACE, .bDescriptorSubtype = CALL_MANAGEMENT_FUNC_DESC, .bmCapabilities = 0x00, .bDataInterface = 1, @@ -104,7 +103,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = { /* ACM Functional Descriptor */ .if0_acm = { .bFunctionLength = sizeof(struct cdc_acm_descriptor), - .bDescriptorType = USB_CS_INTERFACE_DESC, + .bDescriptorType = USB_DESC_CS_INTERFACE, .bDescriptorSubtype = ACM_FUNC_DESC, /* Device supports the request combination of: * Set_Line_Coding, @@ -117,7 +116,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = { /* Union Functional Descriptor */ .if0_union = { .bFunctionLength = sizeof(struct cdc_union_descriptor), - .bDescriptorType = USB_CS_INTERFACE_DESC, + .bDescriptorType = USB_DESC_CS_INTERFACE, .bDescriptorSubtype = UNION_FUNC_DESC, .bControlInterface = 0, .bSubordinateInterface0 = 1, @@ -125,7 +124,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = { /* Notification EP Descriptor */ .if0_int_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = RNDIS_INT_EP_ADDR, .bmAttributes = USB_DC_EP_INTERRUPT, .wMaxPacketSize = @@ -137,11 +136,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = { /* CDC Data Interface */ .if1 = { .bLength = sizeof(struct usb_if_descriptor), - .bDescriptorType = USB_INTERFACE_DESC, + .bDescriptorType = USB_DESC_INTERFACE, .bInterfaceNumber = 1, .bAlternateSetting = 0, .bNumEndpoints = 2, - .bInterfaceClass = COMMUNICATION_DEVICE_CLASS_DATA, + .bInterfaceClass = USB_BCC_CDC_DATA, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0, .iInterface = 0, @@ -149,7 +148,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = { /* Data Endpoint IN */ .if1_in_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = RNDIS_IN_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = @@ -159,7 +158,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = { /* Data Endpoint OUT */ .if1_out_ep = { .bLength = sizeof(struct usb_ep_descriptor), - .bDescriptorType = USB_ENDPOINT_DESC, + .bDescriptorType = USB_DESC_ENDPOINT, .bEndpointAddress = RNDIS_OUT_EP_ADDR, .bmAttributes = USB_DC_EP_BULK, .wMaxPacketSize = @@ -903,15 +902,14 @@ static int rndis_class_handler(struct usb_setup_packet *setup, int32_t *len, } if (setup->bRequest == CDC_SEND_ENC_CMD && - REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_DEVICE) { + usb_reqtype_is_to_device(setup)) { /* * Instead of handling here, queue * handle_encapsulated_cmd(*data, *len); */ queue_encapsulated_cmd(*data, *len); } else if (setup->bRequest == CDC_GET_ENC_RSP && - REQTYPE_GET_DIR(setup->bmRequestType) == - REQTYPE_DIR_TO_HOST) { + usb_reqtype_is_to_host(setup)) { handle_encapsulated_rsp(data, len); } else { *len = 0; /* FIXME! */ @@ -1015,7 +1013,7 @@ static struct string_desc { uint8_t bPad; } __packed msosv1_string_descriptor = { .bLength = MSOS_STRING_LENGTH, - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, /* Signature MSFT100 */ .bString = { 'M', 0x00, 'S', 0x00, 'F', 0x00, 'T', 0x00, diff --git a/subsys/usb/class/netusb/netusb.c b/subsys/usb/class/netusb/netusb.c index b6f2edfc048..49ffac85477 100644 --- a/subsys/usb/class/netusb/netusb.c +++ b/subsys/usb/class/netusb/netusb.c @@ -16,7 +16,6 @@ LOG_MODULE_REGISTER(usb_net); #include #include -#include #include #include "netusb.h" diff --git a/subsys/usb/os_desc.c b/subsys/usb/os_desc.c index 08b51e2d5e5..d9da425f3ad 100644 --- a/subsys/usb/os_desc.c +++ b/subsys/usb/os_desc.c @@ -11,7 +11,6 @@ LOG_MODULE_REGISTER(usb_os_desc); #include #include -#include #include static struct usb_os_descriptor *os_desc; @@ -23,8 +22,8 @@ int usb_handle_os_desc(struct usb_setup_packet *setup, return -ENOTSUP; } - if (GET_DESC_TYPE(setup->wValue) == USB_STRING_DESC && - GET_DESC_INDEX(setup->wValue) == USB_OSDESC_STRING_DESC_INDEX) { + if (USB_GET_DESCRIPTOR_TYPE(setup->wValue) == USB_DESC_STRING && + USB_GET_DESCRIPTOR_INDEX(setup->wValue) == USB_OSDESC_STRING_DESC_INDEX) { LOG_DBG("MS OS Descriptor string read"); *data = os_desc->string; *len = os_desc->string_len; diff --git a/subsys/usb/usb_descriptor.c b/subsys/usb/usb_descriptor.c index 3b621fda05e..071afb6c475 100644 --- a/subsys/usb/usb_descriptor.c +++ b/subsys/usb/usb_descriptor.c @@ -10,9 +10,7 @@ #include #include #include -#include #include -#include #include "usb_descriptor.h" #include @@ -59,14 +57,14 @@ USBD_DEVICE_DESCR_DEFINE(primary) struct common_descriptor common_desc = { /* Device descriptor */ .device_descriptor = { .bLength = sizeof(struct usb_device_descriptor), - .bDescriptorType = USB_DEVICE_DESC, + .bDescriptorType = USB_DESC_DEVICE, #ifdef CONFIG_USB_DEVICE_BOS - .bcdUSB = sys_cpu_to_le16(USB_2_1), + .bcdUSB = sys_cpu_to_le16(USB_SRN_2_1), #else - .bcdUSB = sys_cpu_to_le16(USB_2_0), + .bcdUSB = sys_cpu_to_le16(USB_SRN_2_0), #endif #ifdef CONFIG_USB_COMPOSITE_DEVICE - .bDeviceClass = MISC_CLASS, + .bDeviceClass = USB_BCC_MISCELLANEOUS, .bDeviceSubClass = 0x02, .bDeviceProtocol = 0x01, #else @@ -77,7 +75,7 @@ USBD_DEVICE_DESCR_DEFINE(primary) struct common_descriptor common_desc = { .bMaxPacketSize0 = USB_MAX_CTRL_MPS, .idVendor = sys_cpu_to_le16((uint16_t)CONFIG_USB_DEVICE_VID), .idProduct = sys_cpu_to_le16((uint16_t)CONFIG_USB_DEVICE_PID), - .bcdDevice = sys_cpu_to_le16(BCDDEVICE_RELNUM), + .bcdDevice = sys_cpu_to_le16(USB_BCD_DRN), .iManufacturer = USB_DESC_MANUFACTURER_IDX, .iProduct = USB_DESC_PRODUCT_IDX, .iSerialNumber = USB_DESC_SERIAL_NUMBER_IDX, @@ -86,13 +84,13 @@ USBD_DEVICE_DESCR_DEFINE(primary) struct common_descriptor common_desc = { /* Configuration descriptor */ .cfg_descr = { .bLength = sizeof(struct usb_cfg_descriptor), - .bDescriptorType = USB_CONFIGURATION_DESC, + .bDescriptorType = USB_DESC_CONFIGURATION, /*wTotalLength will be fixed in usb_fix_descriptor() */ .wTotalLength = 0, .bNumInterfaces = 0, .bConfigurationValue = 1, .iConfiguration = 0, - .bmAttributes = USB_CONFIGURATION_ATTRIBUTES, + .bmAttributes = USB_SCD_ATTRIBUTES, .bMaxPower = CONFIG_USB_MAX_POWER, }, }; @@ -127,27 +125,27 @@ struct usb_string_desription { USBD_STRING_DESCR_DEFINE(primary) struct usb_string_desription string_descr = { .lang_descr = { .bLength = sizeof(struct usb_string_descriptor), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = sys_cpu_to_le16(0x0409), }, /* Manufacturer String Descriptor */ .utf16le_mfr = { .bLength = USB_STRING_DESCRIPTOR_LENGTH( CONFIG_USB_DEVICE_MANUFACTURER), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = CONFIG_USB_DEVICE_MANUFACTURER, }, /* Product String Descriptor */ .utf16le_product = { .bLength = USB_STRING_DESCRIPTOR_LENGTH( CONFIG_USB_DEVICE_PRODUCT), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = CONFIG_USB_DEVICE_PRODUCT, }, /* Serial Number String Descriptor */ .utf16le_sn = { .bLength = USB_STRING_DESCRIPTOR_LENGTH(CONFIG_USB_DEVICE_SN), - .bDescriptorType = USB_STRING_DESC, + .bDescriptorType = USB_DESC_STRING, .bString = CONFIG_USB_DEVICE_SN, }, }; @@ -198,7 +196,7 @@ int usb_get_str_descriptor_idx(void *ptr) while (head->bLength != 0U) { switch (head->bDescriptorType) { - case USB_STRING_DESC: + case USB_DESC_STRING: if (head == (struct usb_desc_header *)str) { return str_descr_idx; } @@ -380,14 +378,14 @@ static int usb_fix_descriptor(struct usb_desc_header *head) while (head->bLength != 0U) { switch (head->bDescriptorType) { - case USB_CONFIGURATION_DESC: + case USB_DESC_CONFIGURATION: cfg_descr = (struct usb_cfg_descriptor *)head; LOG_DBG("Configuration descriptor %p", head); break; - case USB_ASSOCIATION_DESC: + case USB_DESC_INTERFACE_ASSOC: LOG_DBG("Association descriptor %p", head); break; - case USB_INTERFACE_DESC: + case USB_DESC_INTERFACE: if_descr = (struct usb_if_descriptor *)head; LOG_DBG("Interface descriptor %p", head); if (if_descr->bAlternateSetting) { @@ -411,7 +409,7 @@ static int usb_fix_descriptor(struct usb_desc_header *head) numof_ifaces++; break; - case USB_ENDPOINT_DESC: + case USB_DESC_ENDPOINT: if (!cfg_data) { LOG_ERR("Uninitialized usb_cfg_data pointer, " "corrupted device descriptor?"); @@ -429,7 +427,7 @@ static int usb_fix_descriptor(struct usb_desc_header *head) break; case 0: - case USB_STRING_DESC: + case USB_DESC_STRING: /* * Copy runtime SN string descriptor first, if has */ diff --git a/subsys/usb/usb_device.c b/subsys/usb/usb_device.c index dc890844e57..388dc80f6c2 100644 --- a/subsys/usb/usb_device.c +++ b/subsys/usb/usb_device.c @@ -2,6 +2,7 @@ * LPCUSB, an USB device driver for LPC microcontrollers * Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) * Copyright (c) 2016 Intel Corporation + * Copyright (c) 2020 PHYTEC Messtechnik GmbH * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -64,9 +65,8 @@ #include #include #include -#include -#include #include +#include #define LOG_LEVEL CONFIG_USB_DEVICE_LOG_LEVEL #include @@ -99,10 +99,6 @@ LOG_MODULE_REGISTER(usb_device); #define MAX_NUM_REQ_HANDLERS 4U #define MAX_STD_REQ_MSG_SIZE 8U -/* Default USB control EP, always 0 and 0x80 */ -#define USB_CONTROL_OUT_EP0 0 -#define USB_CONTROL_IN_EP0 0x80 - /* Linker-defined symbols bound the USB descriptor structs */ extern struct usb_cfg_data __usb_data_start[]; extern struct usb_cfg_data __usb_data_end[]; @@ -212,14 +208,15 @@ static uint8_t usb_get_alt_setting(uint8_t iface) static bool usb_handle_request(struct usb_setup_packet *setup, int32_t *len, uint8_t **data) { - uint32_t type = REQTYPE_GET_TYPE(setup->bmRequestType); - usb_request_handler handler = usb_dev.req_handlers[type]; + uint32_t type = setup->RequestType.type; + usb_request_handler handler; if (type >= MAX_NUM_REQ_HANDLERS) { LOG_DBG("Error Incorrect iType %d", type); return false; } + handler = usb_dev.req_handlers[type]; if (handler == NULL) { LOG_DBG("No handler for reqtype %d", type); return false; @@ -245,7 +242,7 @@ static void usb_data_to_host(void) uint32_t chunk = usb_dev.data_buf_residue; /*Always EP0 for control*/ - usb_write(USB_CONTROL_IN_EP0, usb_dev.data_buf, + usb_write(USB_CONTROL_EP_IN, usb_dev.data_buf, usb_dev.data_buf_residue, &chunk); usb_dev.data_buf += chunk; usb_dev.data_buf_residue -= chunk; @@ -269,7 +266,7 @@ static void usb_data_to_host(void) } else { usb_dev.zlp_flag = false; - usb_dc_ep_write(USB_CONTROL_IN_EP0, NULL, 0, NULL); + usb_dc_ep_write(USB_CONTROL_EP_IN, NULL, 0, NULL); } } @@ -290,7 +287,7 @@ static void usb_handle_control_transfer(uint8_t ep, LOG_DBG("ep 0x%02x, status 0x%02x", ep, ep_status); - if (ep == USB_CONTROL_OUT_EP0 && ep_status == USB_DC_EP_SETUP) { + if (ep == USB_CONTROL_EP_OUT && ep_status == USB_DC_EP_SETUP) { /* * OUT transfer, Setup packet, * reset request message state machine @@ -298,7 +295,7 @@ static void usb_handle_control_transfer(uint8_t ep, if (usb_dc_ep_read(ep, (uint8_t *)&setup_raw, sizeof(setup_raw), NULL) < 0) { LOG_DBG("Read Setup Packet failed"); - usb_dc_ep_set_stall(USB_CONTROL_IN_EP0); + usb_dc_ep_set_stall(USB_CONTROL_EP_IN); return; } @@ -310,11 +307,10 @@ static void usb_handle_control_transfer(uint8_t ep, setup->wLength = sys_le16_to_cpu(setup_raw.wLength); if (setup->wLength > CONFIG_USB_REQUEST_BUFFER_SIZE) { - if (REQTYPE_GET_DIR(setup->bmRequestType) - != REQTYPE_DIR_TO_HOST) { + if (usb_reqtype_is_to_device(setup)) { LOG_ERR("Request buffer too small"); - usb_dc_ep_set_stall(USB_CONTROL_IN_EP0); - usb_dc_ep_set_stall(USB_CONTROL_OUT_EP0); + usb_dc_ep_set_stall(USB_CONTROL_EP_IN); + usb_dc_ep_set_stall(USB_CONTROL_EP_OUT); return; } } @@ -324,9 +320,7 @@ static void usb_handle_control_transfer(uint8_t ep, usb_dev.data_buf_len = setup->wLength; usb_dev.zlp_flag = false; - if (setup->wLength && - REQTYPE_GET_DIR(setup->bmRequestType) - == REQTYPE_DIR_TO_DEVICE) { + if (setup->wLength && usb_reqtype_is_to_device(setup)) { return; } @@ -335,7 +329,7 @@ static void usb_handle_control_transfer(uint8_t ep, &usb_dev.data_buf_len, &usb_dev.data_buf)) { LOG_DBG("usb_handle_request failed"); - usb_dc_ep_set_stall(USB_CONTROL_IN_EP0); + usb_dc_ep_set_stall(USB_CONTROL_EP_IN); return; } @@ -344,24 +338,24 @@ static void usb_handle_control_transfer(uint8_t ep, setup->wLength); /* Send first part (possibly a zero-length status message) */ usb_data_to_host(); - } else if (ep == USB_CONTROL_OUT_EP0) { + } else if (ep == USB_CONTROL_EP_OUT) { /* OUT transfer, data or status packets */ if (usb_dev.data_buf_residue <= 0) { /* absorb zero-length status message */ - if (usb_dc_ep_read(USB_CONTROL_OUT_EP0, + if (usb_dc_ep_read(USB_CONTROL_EP_OUT, usb_dev.data_buf, 0, &chunk) < 0) { LOG_DBG("Read DATA Packet failed"); - usb_dc_ep_set_stall(USB_CONTROL_IN_EP0); + usb_dc_ep_set_stall(USB_CONTROL_EP_IN); } return; } - if (usb_dc_ep_read(USB_CONTROL_OUT_EP0, + if (usb_dc_ep_read(USB_CONTROL_EP_OUT, usb_dev.data_buf, usb_dev.data_buf_residue, &chunk) < 0) { LOG_DBG("Read DATA Packet failed"); - usb_dc_ep_set_stall(USB_CONTROL_IN_EP0); - usb_dc_ep_set_stall(USB_CONTROL_OUT_EP0); + usb_dc_ep_set_stall(USB_CONTROL_EP_IN); + usb_dc_ep_set_stall(USB_CONTROL_EP_OUT); return; } @@ -374,7 +368,7 @@ static void usb_handle_control_transfer(uint8_t ep, &usb_dev.data_buf_len, &usb_dev.data_buf)) { LOG_DBG("usb_handle_request1 failed"); - usb_dc_ep_set_stall(USB_CONTROL_IN_EP0); + usb_dc_ep_set_stall(USB_CONTROL_EP_IN); return; } @@ -382,7 +376,7 @@ static void usb_handle_control_transfer(uint8_t ep, LOG_DBG(">> usb_data_to_host(2)"); usb_data_to_host(); } - } else if (ep == USB_CONTROL_IN_EP0) { + } else if (ep == USB_CONTROL_EP_IN) { /* Send more data if available */ if (usb_dev.data_buf_residue != 0 || usb_dev.zlp_flag == true) { usb_data_to_host(); @@ -395,7 +389,7 @@ static void usb_handle_control_transfer(uint8_t ep, /* * @brief register a callback for handling requests * - * @param [in] type Type of request, e.g. REQTYPE_TYPE_STANDARD + * @param [in] type Type of request, e.g. USB_REQTYPE_TYPE_STANDARD * @param [in] handler Callback function pointer * * @return N/A @@ -444,15 +438,15 @@ static bool usb_get_descriptor(uint16_t type_index, uint16_t lang_id, /*Avoid compiler warning until this is used for something*/ ARG_UNUSED(lang_id); - type = GET_DESC_TYPE(type_index); - index = GET_DESC_INDEX(type_index); + type = USB_GET_DESCRIPTOR_TYPE(type_index); + index = USB_GET_DESCRIPTOR_INDEX(type_index); /* * Invalid types of descriptors, * see USB Spec. Revision 2.0, 9.4.3 Get Descriptor */ - if ((type == USB_INTERFACE_DESC) || (type == USB_ENDPOINT_DESC) || - (type > USB_OTHER_SPEED)) { + if ((type == USB_DESC_INTERFACE) || (type == USB_DESC_ENDPOINT) || + (type > USB_DESC_OTHER_SPEED)) { return false; } @@ -475,7 +469,7 @@ static bool usb_get_descriptor(uint16_t type_index, uint16_t lang_id, /* set data pointer */ *data = p; /* get length from structure */ - if (type == USB_CONFIGURATION_DESC) { + if (type == USB_DESC_CONFIGURATION) { /* configuration descriptor is an * exception, length is at offset * 2 and 3 @@ -621,7 +615,7 @@ static bool usb_set_configuration(uint8_t config_index, uint8_t alt_setting) /* configure endpoints for this configuration/altsetting */ while (p[DESC_bLength] != 0U) { switch (p[DESC_bDescriptorType]) { - case USB_CONFIGURATION_DESC: + case USB_DESC_CONFIGURATION: /* remember current configuration index */ cur_config = p[CONF_DESC_bConfigurationValue]; if (cur_config == config_index) { @@ -630,13 +624,13 @@ static bool usb_set_configuration(uint8_t config_index, uint8_t alt_setting) break; - case USB_INTERFACE_DESC: + case USB_DESC_INTERFACE: /* remember current alternate setting */ cur_alt_setting = p[INTF_DESC_bAlternateSetting]; break; - case USB_ENDPOINT_DESC: + case USB_DESC_ENDPOINT: if ((cur_config != config_index) || (cur_alt_setting != alt_setting)) { break; @@ -681,7 +675,7 @@ static bool usb_set_interface(uint8_t iface, uint8_t alt_setting) while (p[DESC_bLength] != 0U) { switch (p[DESC_bDescriptorType]) { - case USB_INTERFACE_DESC: + case USB_DESC_INTERFACE: /* remember current alternate setting */ cur_alt_setting = p[INTF_DESC_bAlternateSetting]; cur_iface = p[INTF_DESC_bInterfaceNumber]; @@ -695,7 +689,7 @@ static bool usb_set_interface(uint8_t iface, uint8_t alt_setting) LOG_DBG("Current iface %u alt setting %u", cur_iface, cur_alt_setting); break; - case USB_ENDPOINT_DESC: + case USB_DESC_ENDPOINT: if (cur_iface == iface) { ep = (struct usb_ep_descriptor *)p; ret = usb_eps_reconfigure(ep, cur_alt_setting, @@ -725,7 +719,7 @@ static bool usb_get_interface(struct usb_setup_packet *setup, uint8_t cur_iface; while (p[DESC_bLength] != 0U) { - if (p[DESC_bDescriptorType] == USB_INTERFACE_DESC) { + if (p[DESC_bDescriptorType] == USB_DESC_INTERFACE) { cur_iface = p[INTF_DESC_bInterfaceNumber]; if (cur_iface == setup->wIndex) { data[0] = usb_get_alt_setting(cur_iface); @@ -771,45 +765,45 @@ static bool usb_handle_std_device_req(struct usb_setup_packet *setup, uint8_t *data = *data_buf; switch (setup->bRequest) { - case REQ_GET_STATUS: - LOG_DBG("REQ_GET_STATUS"); + case USB_SREQ_GET_STATUS: + LOG_DBG("USB_SREQ_GET_STATUS"); /* bit 0: self-powered */ /* bit 1: remote wakeup */ data[0] = 0U; data[1] = 0U; if (IS_ENABLED(CONFIG_USB_SELF_POWERED)) { - data[0] |= DEVICE_STATUS_SELF_POWERED; + data[0] |= USB_GET_STATUS_SELF_POWERED; } if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) { data[0] |= (usb_dev.remote_wakeup ? - DEVICE_STATUS_REMOTE_WAKEUP : 0); + USB_GET_STATUS_REMOTE_WAKEUP : 0); } *len = 2; break; - case REQ_SET_ADDRESS: - LOG_DBG("REQ_SET_ADDRESS, addr 0x%x", value); + case USB_SREQ_SET_ADDRESS: + LOG_DBG("USB_SREQ_SET_ADDRESS, addr 0x%x", value); usb_dc_set_address(value); break; - case REQ_GET_DESCRIPTOR: - LOG_DBG("REQ_GET_DESCRIPTOR"); + case USB_SREQ_GET_DESCRIPTOR: + LOG_DBG("USB_SREQ_GET_DESCRIPTOR"); ret = usb_get_descriptor(value, index, len, data_buf); break; - case REQ_GET_CONFIGURATION: - LOG_DBG("REQ_GET_CONFIGURATION"); + case USB_SREQ_GET_CONFIGURATION: + LOG_DBG("USB_SREQ_GET_CONFIGURATION"); /* indicate if we are configured */ data[0] = usb_dev.configuration; *len = 1; break; - case REQ_SET_CONFIGURATION: + case USB_SREQ_SET_CONFIGURATION: value &= 0xFF; - LOG_DBG("REQ_SET_CONFIGURATION, conf 0x%x", value); + LOG_DBG("USB_SREQ_SET_CONFIGURATION, conf 0x%x", value); if (!usb_set_configuration(value, 0)) { LOG_DBG("USB Set Configuration failed"); ret = false; @@ -822,34 +816,34 @@ static bool usb_handle_std_device_req(struct usb_setup_packet *setup, } break; - case REQ_CLEAR_FEATURE: - LOG_DBG("REQ_CLEAR_FEATURE"); + case USB_SREQ_CLEAR_FEATURE: + LOG_DBG("USB_SREQ_CLEAR_FEATURE"); ret = false; if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) { - if (value == FEA_REMOTE_WAKEUP) { + if (value == USB_SFS_REMOTE_WAKEUP) { usb_dev.remote_wakeup = false; ret = true; } } break; - case REQ_SET_FEATURE: - LOG_DBG("REQ_SET_FEATURE"); + case USB_SREQ_SET_FEATURE: + LOG_DBG("USB_SREQ_SET_FEATURE"); ret = false; if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) { - if (value == FEA_REMOTE_WAKEUP) { + if (value == USB_SFS_REMOTE_WAKEUP) { usb_dev.remote_wakeup = true; ret = true; } } - if (value == FEA_TEST_MODE) { - /* put TEST_MODE code here */ + if (value == USB_SFS_TEST_MODE) { + /* put USB_SFS_TEST_MODE code here */ } break; - case REQ_SET_DESCRIPTOR: + case USB_SREQ_SET_DESCRIPTOR: LOG_DBG("Device req 0x%02x not implemented", setup->bRequest); ret = false; break; @@ -880,7 +874,7 @@ static bool is_interface_valid(uint8_t interface) /* Search through descriptor for matching interface */ while (p[DESC_bLength] != 0U) { - if (p[DESC_bDescriptorType] == USB_CONFIGURATION_DESC) { + if (p[DESC_bDescriptorType] == USB_DESC_CONFIGURATION) { cfg_descr = (const struct usb_cfg_descriptor *)p; if (interface < cfg_descr->bNumInterfaces) { return true; @@ -915,23 +909,23 @@ static bool usb_handle_std_interface_req(struct usb_setup_packet *setup, } switch (setup->bRequest) { - case REQ_GET_STATUS: + case USB_SREQ_GET_STATUS: /* no bits specified */ data[0] = 0U; data[1] = 0U; *len = 2; break; - case REQ_CLEAR_FEATURE: - case REQ_SET_FEATURE: + case USB_SREQ_CLEAR_FEATURE: + case USB_SREQ_SET_FEATURE: /* not defined for interface */ return false; - case REQ_GET_INTERFACE: + case USB_SREQ_GET_INTERFACE: return usb_get_interface(setup, len, data_buf); - case REQ_SET_INTERFACE: - LOG_DBG("REQ_SET_INTERFACE"); + case USB_SREQ_SET_INTERFACE: + LOG_DBG("USB_SREQ_SET_INTERFACE"); usb_set_interface(setup->wIndex, setup->wValue); *len = 0; break; @@ -1001,7 +995,7 @@ static bool usb_handle_std_endpoint_req(struct usb_setup_packet *setup, } switch (setup->bRequest) { - case REQ_GET_STATUS: + case USB_SREQ_GET_STATUS: /** This request is valid for Control Endpoints when * the device is not yet configured. For other * Endpoints the device must be configured. @@ -1018,8 +1012,8 @@ static bool usb_handle_std_endpoint_req(struct usb_setup_packet *setup, } return false; - case REQ_CLEAR_FEATURE: - if (setup->wValue == FEA_ENDPOINT_HALT) { + case USB_SREQ_CLEAR_FEATURE: + if (setup->wValue == USB_SFS_ENDPOINT_HALT) { /** This request is valid for Control Endpoints when * the device is not yet configured. For other * Endpoints the device must be configured. @@ -1037,11 +1031,11 @@ static bool usb_handle_std_endpoint_req(struct usb_setup_packet *setup, break; } } - /* only ENDPOINT_HALT defined for endpoints */ + /* only USB_SFS_ENDPOINT_HALT defined for endpoints */ return false; - case REQ_SET_FEATURE: - if (setup->wValue == FEA_ENDPOINT_HALT) { + case USB_SREQ_SET_FEATURE: + if (setup->wValue == USB_SFS_ENDPOINT_HALT) { /** This request is valid for Control Endpoints when * the device is not yet configured. For other * Endpoints the device must be configured. @@ -1060,10 +1054,10 @@ static bool usb_handle_std_endpoint_req(struct usb_setup_packet *setup, break; } } - /* only ENDPOINT_HALT defined for endpoints */ + /* only USB_SFS_ENDPOINT_HALT defined for endpoints */ return false; - case REQ_SYNCH_FRAME: + case USB_SREQ_SYNCH_FRAME: /* For Synch Frame request the device must be configured */ if (is_device_configured()) { /* Not supported, return false anyway */ @@ -1108,18 +1102,18 @@ static int usb_handle_standard_request(struct usb_setup_packet *setup, return 0; } - switch (REQTYPE_GET_RECIP(setup->bmRequestType)) { - case REQTYPE_RECIP_DEVICE: + switch (setup->RequestType.recipient) { + case USB_REQTYPE_RECIPIENT_DEVICE: if (usb_handle_std_device_req(setup, len, data_buf) == false) { rc = -EINVAL; } break; - case REQTYPE_RECIP_INTERFACE: + case USB_REQTYPE_RECIPIENT_INTERFACE: if (usb_handle_std_interface_req(setup, len, data_buf) == false) { rc = -EINVAL; } break; - case REQTYPE_RECIP_ENDPOINT: + case USB_REQTYPE_RECIPIENT_ENDPOINT: if (usb_handle_std_endpoint_req(setup, len, data_buf) == false) { rc = -EINVAL; } @@ -1280,10 +1274,10 @@ int usb_deconfig(void) usb_register_descriptors(NULL); /* unegister standard request handler */ - usb_register_request_handler(REQTYPE_TYPE_STANDARD, NULL); + usb_register_request_handler(USB_REQTYPE_TYPE_STANDARD, NULL); /* unregister class request handlers for each interface*/ - usb_register_request_handler(REQTYPE_TYPE_CLASS, NULL); + usb_register_request_handler(USB_REQTYPE_TYPE_CLASS, NULL); /* unregister class request handlers for each interface*/ usb_register_custom_req_handler(NULL); @@ -1453,7 +1447,7 @@ static int custom_handler(struct usb_setup_packet *pSetup, * The class does not actively engage in request * handling and therefore we can ignore return value. */ - if (if_descr->bInterfaceClass == AUDIO_CLASS) { + if (if_descr->bInterfaceClass == USB_BCC_AUDIO) { (void)iface->custom_handler(pSetup, len, data); } } @@ -1514,14 +1508,14 @@ int usb_set_config(const uint8_t *device_descriptor) usb_register_descriptors(device_descriptor); /* register standard request handler */ - usb_register_request_handler(REQTYPE_TYPE_STANDARD, + usb_register_request_handler(USB_REQTYPE_TYPE_STANDARD, usb_handle_standard_request); /* register class request handlers for each interface*/ - usb_register_request_handler(REQTYPE_TYPE_CLASS, class_handler); + usb_register_request_handler(USB_REQTYPE_TYPE_CLASS, class_handler); /* register vendor request handler */ - usb_register_request_handler(REQTYPE_TYPE_VENDOR, vendor_handler); + usb_register_request_handler(USB_REQTYPE_TYPE_VENDOR, vendor_handler); /* register class request handlers for each interface*/ usb_register_custom_req_handler(custom_handler); @@ -1569,26 +1563,26 @@ int usb_enable(usb_dc_status_callback status_cb) ep0_cfg.ep_mps = USB_MAX_CTRL_MPS; ep0_cfg.ep_type = USB_DC_EP_CONTROL; - ep0_cfg.ep_addr = USB_CONTROL_OUT_EP0; + ep0_cfg.ep_addr = USB_CONTROL_EP_OUT; ret = usb_dc_ep_configure(&ep0_cfg); if (ret < 0) { goto out; } - ep0_cfg.ep_addr = USB_CONTROL_IN_EP0; + ep0_cfg.ep_addr = USB_CONTROL_EP_IN; ret = usb_dc_ep_configure(&ep0_cfg); if (ret < 0) { goto out; } /* Register endpoint 0 handlers*/ - ret = usb_dc_ep_set_callback(USB_CONTROL_OUT_EP0, + ret = usb_dc_ep_set_callback(USB_CONTROL_EP_OUT, usb_handle_control_transfer); if (ret < 0) { goto out; } - ret = usb_dc_ep_set_callback(USB_CONTROL_IN_EP0, + ret = usb_dc_ep_set_callback(USB_CONTROL_EP_IN, usb_handle_control_transfer); if (ret < 0) { goto out; @@ -1601,12 +1595,12 @@ int usb_enable(usb_dc_status_callback status_cb) } /* Enable control EP */ - ret = usb_dc_ep_enable(USB_CONTROL_OUT_EP0); + ret = usb_dc_ep_enable(USB_CONTROL_EP_OUT); if (ret < 0) { goto out; } - ret = usb_dc_ep_enable(USB_CONTROL_IN_EP0); + ret = usb_dc_ep_enable(USB_CONTROL_EP_IN); if (ret < 0) { goto out; }