usb: use new USB framework header

Replace all macros and types with the new ones from
usb/usb_ch9.h header.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
Johann Fischer 2021-05-12 11:12:29 +02:00 committed by Carles Cufí
commit 6408d40fd6
21 changed files with 246 additions and 279 deletions

View file

@ -21,7 +21,7 @@
#ifndef ZEPHYR_INCLUDE_USB_CLASS_AUDIO_H_ #ifndef ZEPHYR_INCLUDE_USB_CLASS_AUDIO_H_
#define ZEPHYR_INCLUDE_USB_CLASS_AUDIO_H_ #define ZEPHYR_INCLUDE_USB_CLASS_AUDIO_H_
#include <usb/usb_common.h> #include <usb/usb_ch9.h>
#include <device.h> #include <device.h>
#include <net/buf.h> #include <net/buf.h>
#include <sys/util.h> #include <sys/util.h>

View file

@ -32,6 +32,7 @@
/** Communications Class Protocol Codes */ /** Communications Class Protocol Codes */
#define AT_CMD_V250_PROTOCOL 0x01 #define AT_CMD_V250_PROTOCOL 0x01
#define EEM_PROTOCOL 0x07 #define EEM_PROTOCOL 0x07
#define ACM_VENDOR_PROTOCOL 0xFF
/** /**
* @brief Data Class Interface Codes * @brief Data Class Interface Codes

View file

@ -39,7 +39,7 @@
#define ZEPHYR_INCLUDE_USB_USB_DEVICE_H_ #define ZEPHYR_INCLUDE_USB_USB_DEVICE_H_
#include <drivers/usb/usb_dc.h> #include <drivers/usb/usb_dc.h>
#include <usb/usbstruct.h> #include <usb/usb_ch9.h>
#include <logging/log.h> #include <logging/log.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -83,15 +83,6 @@ extern "C" {
* USB application interface * 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 * @brief USB Device Core Layer API
* @defgroup _usb_device_core_api USB Device Core API * @defgroup _usb_device_core_api USB Device Core API

View file

@ -9,7 +9,6 @@
#include <sys/__assert.h> #include <sys/__assert.h>
#include <sys/byteorder.h> #include <sys/byteorder.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <tracing_core.h> #include <tracing_core.h>
#include <tracing_buffer.h> #include <tracing_buffer.h>
#include <tracing_backend.h> #include <tracing_backend.h>
@ -35,11 +34,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_device_desc dev_desc = {
*/ */
.if0 = { .if0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 2, .bNumEndpoints = 2,
.bInterfaceClass = CUSTOM_CLASS, .bInterfaceClass = USB_BCC_VENDOR,
.bInterfaceSubClass = 0, .bInterfaceSubClass = 0,
.bInterfaceProtocol = 0, .bInterfaceProtocol = 0,
.iInterface = 0, .iInterface = 0,
@ -50,7 +49,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_device_desc dev_desc = {
*/ */
.if0_in_ep = { .if0_in_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = TRACING_IF_IN_EP_ADDR, .bEndpointAddress = TRACING_IF_IN_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = sys_cpu_to_le16(CONFIG_TRACING_USB_MPS), .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 = { .if0_out_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = TRACING_IF_OUT_EP_ADDR, .bEndpointAddress = TRACING_IF_OUT_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = sys_cpu_to_le16(CONFIG_TRACING_USB_MPS), .wMaxPacketSize = sys_cpu_to_le16(CONFIG_TRACING_USB_MPS),

View file

@ -11,7 +11,6 @@ LOG_MODULE_REGISTER(usb_bos);
#include <zephyr.h> #include <zephyr.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb/bos.h> #include <usb/bos.h>
@ -20,7 +19,7 @@ extern const uint8_t __usb_bos_desc_end[];
USB_DEVICE_BOS_DESC_DEFINE_HDR struct usb_bos_descriptor bos_hdr = { USB_DEVICE_BOS_DESC_DEFINE_HDR struct usb_bos_descriptor bos_hdr = {
.bLength = sizeof(struct usb_bos_descriptor), .bLength = sizeof(struct usb_bos_descriptor),
.bDescriptorType = USB_BINARY_OBJECT_STORE_DESC, .bDescriptorType = USB_DESC_BOS,
.wTotalLength = 0, /* should be corrected with register */ .wTotalLength = 0, /* should be corrected with register */
.bNumDeviceCaps = 0, /* should be set 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, int usb_handle_bos(struct usb_setup_packet *setup,
int32_t *len, uint8_t **data) 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"); LOG_DBG("Read BOS descriptor");
*data = (uint8_t *)usb_bos_get_header(); *data = (uint8_t *)usb_bos_get_header();
*len = usb_bos_get_length(); *len = usb_bos_get_length();

View file

@ -12,10 +12,8 @@
*/ */
#include <kernel.h> #include <kernel.h>
#include <usb/usb_common.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
#include <usb/usbstruct.h>
#include <usb/class/usb_audio.h> #include <usb/class/usb_audio.h>
#include "usb_audio_internal.h" #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; uint8_t iface = (pSetup->wIndex) & 0xFF;
if (REQTYPE_GET_RECIP(pSetup->bmRequestType) != if (pSetup->RequestType.recipient != USB_REQTYPE_RECIPIENT_INTERFACE) {
REQTYPE_RECIP_INTERFACE) {
return -EINVAL; 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); 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) { if (ep_desc->bEndpointAddress & USB_EP_DIR_MASK) {
audio_dev_data->tx_enable = pSetup->wValue; audio_dev_data->tx_enable = pSetup->wValue;
} else { } else {
@ -760,8 +757,8 @@ static int audio_class_handle_req(struct usb_setup_packet *pSetup,
pSetup->bmRequestType, pSetup->bRequest, pSetup->wValue, pSetup->bmRequestType, pSetup->bRequest, pSetup->wValue,
pSetup->wIndex, pSetup->wLength); pSetup->wIndex, pSetup->wLength);
switch (REQTYPE_GET_RECIP(pSetup->bmRequestType)) { switch (pSetup->RequestType.recipient) {
case REQTYPE_RECIP_INTERFACE: case USB_REQTYPE_RECIPIENT_INTERFACE:
return handle_interface_req(pSetup, len, data); return handle_interface_req(pSetup, len, data);
default: default:
LOG_ERR("Request recipient invalid"); LOG_ERR("Request recipient invalid");

View file

@ -319,10 +319,10 @@ struct dev##_feature_unit_descriptor_##i { \
#define INIT_IAD(iface_subclass, if_cnt) \ #define INIT_IAD(iface_subclass, if_cnt) \
{ \ { \
.bLength = sizeof(struct usb_association_descriptor), \ .bLength = sizeof(struct usb_association_descriptor), \
.bDescriptorType = USB_ASSOCIATION_DESC, \ .bDescriptorType = USB_DESC_INTERFACE_ASSOC, \
.bFirstInterface = 0, \ .bFirstInterface = 0, \
.bInterfaceCount = if_cnt, \ .bInterfaceCount = if_cnt, \
.bFunctionClass = AUDIO_CLASS, \ .bFunctionClass = USB_BCC_AUDIO, \
.bFunctionSubClass = iface_subclass, \ .bFunctionSubClass = iface_subclass, \
.bFunctionProtocol = 0, \ .bFunctionProtocol = 0, \
.iFunction = 0, \ .iFunction = 0, \
@ -385,11 +385,11 @@ struct dev##_descriptor_##i { \
#define INIT_STD_IF(iface_subclass, iface_num, alt_setting, eps_num) \ #define INIT_STD_IF(iface_subclass, iface_num, alt_setting, eps_num) \
{ \ { \
.bLength = sizeof(struct usb_if_descriptor), \ .bLength = sizeof(struct usb_if_descriptor), \
.bDescriptorType = USB_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_INTERFACE, \
.bInterfaceNumber = iface_num, \ .bInterfaceNumber = iface_num, \
.bAlternateSetting = alt_setting, \ .bAlternateSetting = alt_setting, \
.bNumEndpoints = eps_num, \ .bNumEndpoints = eps_num, \
.bInterfaceClass = AUDIO_CLASS, \ .bInterfaceClass = USB_BCC_AUDIO, \
.bInterfaceSubClass = iface_subclass, \ .bInterfaceSubClass = iface_subclass, \
.bInterfaceProtocol = 0, \ .bInterfaceProtocol = 0, \
.iInterface = 0, \ .iInterface = 0, \
@ -398,7 +398,7 @@ struct dev##_descriptor_##i { \
#define INIT_CS_AC_IF(dev, i, ifaces) \ #define INIT_CS_AC_IF(dev, i, ifaces) \
{ \ { \
.bLength = sizeof(struct dev##_cs_ac_if_descriptor_##i), \ .bLength = sizeof(struct dev##_cs_ac_if_descriptor_##i), \
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = USB_AUDIO_HEADER, \ .bDescriptorSubtype = USB_AUDIO_HEADER, \
.bcdADC = sys_cpu_to_le16(0x0100), \ .bcdADC = sys_cpu_to_le16(0x0100), \
.wTotalLength = sys_cpu_to_le16( \ .wTotalLength = sys_cpu_to_le16( \
@ -413,7 +413,7 @@ struct dev##_descriptor_##i { \
#define INIT_CS_AC_IF_BIDIR(dev, i, ifaces) \ #define INIT_CS_AC_IF_BIDIR(dev, i, ifaces) \
{ \ { \
.bLength = sizeof(struct dev##_cs_ac_if_descriptor_##i), \ .bLength = sizeof(struct dev##_cs_ac_if_descriptor_##i), \
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = USB_AUDIO_HEADER, \ .bDescriptorSubtype = USB_AUDIO_HEADER, \
.bcdADC = sys_cpu_to_le16(0x0100), \ .bcdADC = sys_cpu_to_le16(0x0100), \
.wTotalLength = sys_cpu_to_le16( \ .wTotalLength = sys_cpu_to_le16( \
@ -429,7 +429,7 @@ struct dev##_descriptor_##i { \
#define INIT_IN_TERMINAL(dev, i, terminal_id, type) \ #define INIT_IN_TERMINAL(dev, i, terminal_id, type) \
{ \ { \
.bLength = INPUT_TERMINAL_DESC_SIZE, \ .bLength = INPUT_TERMINAL_DESC_SIZE, \
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = USB_AUDIO_INPUT_TERMINAL, \ .bDescriptorSubtype = USB_AUDIO_INPUT_TERMINAL, \
.bTerminalID = terminal_id, \ .bTerminalID = terminal_id, \
.wTerminalType = sys_cpu_to_le16(type), \ .wTerminalType = sys_cpu_to_le16(type), \
@ -443,7 +443,7 @@ struct dev##_descriptor_##i { \
#define INIT_OUT_TERMINAL(terminal_id, source_id, type) \ #define INIT_OUT_TERMINAL(terminal_id, source_id, type) \
{ \ { \
.bLength = OUTPUT_TERMINAL_DESC_SIZE, \ .bLength = OUTPUT_TERMINAL_DESC_SIZE, \
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = USB_AUDIO_OUTPUT_TERMINAL,\ .bDescriptorSubtype = USB_AUDIO_OUTPUT_TERMINAL,\
.bTerminalID = terminal_id, \ .bTerminalID = terminal_id, \
.wTerminalType = sys_cpu_to_le16(type), \ .wTerminalType = sys_cpu_to_le16(type), \
@ -457,7 +457,7 @@ struct dev##_descriptor_##i { \
#define INIT_FEATURE_UNIT(dev, i, unit_id, source_id) \ #define INIT_FEATURE_UNIT(dev, i, unit_id, source_id) \
{ \ { \
.bLength = sizeof(struct dev##_feature_unit_descriptor_##i), \ .bLength = sizeof(struct dev##_feature_unit_descriptor_##i), \
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = USB_AUDIO_FEATURE_UNIT, \ .bDescriptorSubtype = USB_AUDIO_FEATURE_UNIT, \
.bUnitID = unit_id, \ .bUnitID = unit_id, \
.bSourceID = source_id, \ .bSourceID = source_id, \
@ -470,7 +470,7 @@ struct dev##_descriptor_##i { \
#define INIT_AS_GENERAL(link) \ #define INIT_AS_GENERAL(link) \
{ \ { \
.bLength = USB_AC_CS_IF_DESC_SIZE, \ .bLength = USB_AC_CS_IF_DESC_SIZE, \
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = USB_AUDIO_AS_GENERAL, \ .bDescriptorSubtype = USB_AUDIO_AS_GENERAL, \
.bTerminalLink = link, \ .bTerminalLink = link, \
.bDelay = 0, \ .bDelay = 0, \
@ -484,7 +484,7 @@ struct dev##_descriptor_##i { \
#define INIT_AS_FORMAT_I(ch_cnt, res) \ #define INIT_AS_FORMAT_I(ch_cnt, res) \
{ \ { \
.bLength = sizeof(struct format_type_i_descriptor), \ .bLength = sizeof(struct format_type_i_descriptor), \
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = USB_AUDIO_FORMAT_TYPE, \ .bDescriptorSubtype = USB_AUDIO_FORMAT_TYPE, \
.bFormatType = 0x01, \ .bFormatType = 0x01, \
.bNrChannels = MAX(1, ch_cnt), \ .bNrChannels = MAX(1, ch_cnt), \
@ -497,7 +497,7 @@ struct dev##_descriptor_##i { \
#define INIT_STD_AS_AD_EP(dev, i, addr) \ #define INIT_STD_AS_AD_EP(dev, i, addr) \
{ \ { \
.bLength = sizeof(struct std_as_ad_endpoint_descriptor), \ .bLength = sizeof(struct std_as_ad_endpoint_descriptor), \
.bDescriptorType = USB_ENDPOINT_DESC, \ .bDescriptorType = USB_DESC_ENDPOINT, \
.bEndpointAddress = addr, \ .bEndpointAddress = addr, \
.bmAttributes = (USB_DC_EP_ISOCHRONOUS | SYNC_TYPE(dev, i)), \ .bmAttributes = (USB_DC_EP_ISOCHRONOUS | SYNC_TYPE(dev, i)), \
.wMaxPacketSize = sys_cpu_to_le16(EP_SIZE(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 \ #define INIT_CS_AS_AD_EP \
{ \ { \
.bLength = sizeof(struct cs_as_ad_ep_descriptor), \ .bLength = sizeof(struct cs_as_ad_ep_descriptor), \
.bDescriptorType = USB_CS_ENDPOINT_DESC, \ .bDescriptorType = USB_DESC_CS_ENDPOINT, \
.bDescriptorSubtype = 0x01, \ .bDescriptorSubtype = 0x01, \
.bmAttributes = 0x00, \ .bmAttributes = 0x00, \
.bLockDelayUnits = 0x00, \ .bLockDelayUnits = 0x00, \

View file

@ -10,7 +10,6 @@
#include <sys/byteorder.h> #include <sys/byteorder.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
#include <net/buf.h> #include <net/buf.h>
@ -25,6 +24,9 @@
#include <logging/log.h> #include <logging/log.h>
LOG_MODULE_REGISTER(usb_bluetooth); 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(rx_queue);
static K_FIFO_DEFINE(tx_queue); static K_FIFO_DEFINE(tx_queue);
@ -56,20 +58,20 @@ USBD_CLASS_DESCR_DEFINE(primary, 0)
/* Interface descriptor 0 */ /* Interface descriptor 0 */
.if0 = { .if0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 3, .bNumEndpoints = 3,
.bInterfaceClass = WIRELESS_DEVICE_CLASS, .bInterfaceClass = USB_BCC_WIRELESS_CONTROLLER,
.bInterfaceSubClass = RF_SUBCLASS, .bInterfaceSubClass = USB_RF_SUBCLASS,
.bInterfaceProtocol = BLUETOOTH_PROTOCOL, .bInterfaceProtocol = USB_BLUETOOTH_PROTOCOL,
.iInterface = 0, .iInterface = 0,
}, },
/* Interrupt Endpoint */ /* Interrupt Endpoint */
.if0_int_ep = { .if0_int_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = BLUETOOTH_INT_EP_ADDR, .bEndpointAddress = BLUETOOTH_INT_EP_ADDR,
.bmAttributes = USB_DC_EP_INTERRUPT, .bmAttributes = USB_DC_EP_INTERRUPT,
.wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_INT_MPS), .wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_INT_MPS),
@ -79,7 +81,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0)
/* Data Endpoint OUT */ /* Data Endpoint OUT */
.if0_out_ep = { .if0_out_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = BLUETOOTH_OUT_EP_ADDR, .bEndpointAddress = BLUETOOTH_OUT_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_BULK_MPS), .wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_BULK_MPS),
@ -89,7 +91,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0)
/* Data Endpoint IN */ /* Data Endpoint IN */
.if0_in_ep = { .if0_in_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = BLUETOOTH_IN_EP_ADDR, .bEndpointAddress = BLUETOOTH_IN_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_BULK_MPS), .wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_BULK_MPS),

View file

@ -10,7 +10,6 @@
#include <sys/byteorder.h> #include <sys/byteorder.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
#include <net/buf.h> #include <net/buf.h>
@ -52,11 +51,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_bt_h4_config bt_h4_cfg = {
/* Interface descriptor 0 */ /* Interface descriptor 0 */
.if0 = { .if0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 2, .bNumEndpoints = 2,
.bInterfaceClass = CUSTOM_CLASS, /* TBD */ .bInterfaceClass = USB_BCC_VENDOR, /* TBD */
.bInterfaceSubClass = 0, .bInterfaceSubClass = 0,
.bInterfaceProtocol = 0, .bInterfaceProtocol = 0,
.iInterface = 0, .iInterface = 0,
@ -65,7 +64,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_bt_h4_config bt_h4_cfg = {
/* Data Endpoint OUT */ /* Data Endpoint OUT */
.if0_out_ep = { .if0_out_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = BT_H4_OUT_EP_ADDR, .bEndpointAddress = BT_H4_OUT_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_BULK_MPS), .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 */ /* Data Endpoint IN */
.if0_in_ep = { .if0_in_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = BT_H4_IN_EP_ADDR, .bEndpointAddress = BT_H4_IN_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = sys_cpu_to_le16(USB_MAX_FS_BULK_MPS), .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", LOG_DBG("Class request: bRequest 0x%x bmRequestType 0x%x len %d",
setup->bRequest, setup->bmRequestType, *len); setup->bRequest, setup->bmRequestType, *len);
if (REQTYPE_GET_RECIP(setup->bmRequestType) != REQTYPE_RECIP_DEVICE) { if (setup->RequestType.recipient != USB_REQTYPE_RECIPIENT_DEVICE) {
return -ENOTSUP; return -ENOTSUP;
} }
if (REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_DEVICE && if (usb_reqtype_is_to_device(setup) &&
setup->bRequest == 0x5b) { setup->bRequest == 0x5b) {
LOG_DBG("Host-to-Device, data %p", *data); LOG_DBG("Host-to-Device, data %p", *data);
return 0; return 0;
} }
if ((REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_HOST) && if ((usb_reqtype_is_to_host(setup)) &&
(setup->bRequest == 0x5c)) { (setup->bRequest == 0x5c)) {
LOG_DBG("Device-to-Host, wLength %d, data %p", LOG_DBG("Device-to-Host, wLength %d, data %p",
setup->wLength, *data); setup->wLength, *data);

View file

@ -46,7 +46,6 @@
#include <sys/byteorder.h> #include <sys/byteorder.h>
#include <usb/class/usb_cdc.h> #include <usb/class/usb_cdc.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
#include <usb_work_q.h> #include <usb_work_q.h>
@ -95,10 +94,10 @@ struct usb_cdc_acm_config {
#define INITIALIZER_IAD \ #define INITIALIZER_IAD \
{ \ { \
.bLength = sizeof(struct usb_association_descriptor), \ .bLength = sizeof(struct usb_association_descriptor), \
.bDescriptorType = USB_ASSOCIATION_DESC, \ .bDescriptorType = USB_DESC_INTERFACE_ASSOC, \
.bFirstInterface = 0, \ .bFirstInterface = 0, \
.bInterfaceCount = 0x02, \ .bInterfaceCount = 0x02, \
.bFunctionClass = COMMUNICATION_DEVICE_CLASS, \ .bFunctionClass = USB_BCC_CDC_CONTROL, \
.bFunctionSubClass = ACM_SUBCLASS, \ .bFunctionSubClass = ACM_SUBCLASS, \
.bFunctionProtocol = 0, \ .bFunctionProtocol = 0, \
.iFunction = 0, \ .iFunction = 0, \
@ -107,7 +106,7 @@ struct usb_cdc_acm_config {
#define INITIALIZER_IF(iface_num, num_ep, class, subclass) \ #define INITIALIZER_IF(iface_num, num_ep, class, subclass) \
{ \ { \
.bLength = sizeof(struct usb_if_descriptor), \ .bLength = sizeof(struct usb_if_descriptor), \
.bDescriptorType = USB_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_INTERFACE, \
.bInterfaceNumber = iface_num, \ .bInterfaceNumber = iface_num, \
.bAlternateSetting = 0, \ .bAlternateSetting = 0, \
.bNumEndpoints = num_ep, \ .bNumEndpoints = num_ep, \
@ -120,15 +119,15 @@ struct usb_cdc_acm_config {
#define INITIALIZER_IF_HDR \ #define INITIALIZER_IF_HDR \
{ \ { \
.bFunctionLength = sizeof(struct cdc_header_descriptor),\ .bFunctionLength = sizeof(struct cdc_header_descriptor),\
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = HEADER_FUNC_DESC, \ .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 \ #define INITIALIZER_IF_CM \
{ \ { \
.bFunctionLength = sizeof(struct cdc_cm_descriptor), \ .bFunctionLength = sizeof(struct cdc_cm_descriptor), \
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = CALL_MANAGEMENT_FUNC_DESC, \ .bDescriptorSubtype = CALL_MANAGEMENT_FUNC_DESC, \
.bmCapabilities = 0x02, \ .bmCapabilities = 0x02, \
.bDataInterface = 1, \ .bDataInterface = 1, \
@ -143,7 +142,7 @@ struct usb_cdc_acm_config {
#define INITIALIZER_IF_ACM \ #define INITIALIZER_IF_ACM \
{ \ { \
.bFunctionLength = sizeof(struct cdc_acm_descriptor), \ .bFunctionLength = sizeof(struct cdc_acm_descriptor), \
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = ACM_FUNC_DESC, \ .bDescriptorSubtype = ACM_FUNC_DESC, \
.bmCapabilities = 0x02, \ .bmCapabilities = 0x02, \
} }
@ -151,7 +150,7 @@ struct usb_cdc_acm_config {
#define INITIALIZER_IF_UNION \ #define INITIALIZER_IF_UNION \
{ \ { \
.bFunctionLength = sizeof(struct cdc_union_descriptor), \ .bFunctionLength = sizeof(struct cdc_union_descriptor), \
.bDescriptorType = USB_CS_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_CS_INTERFACE, \
.bDescriptorSubtype = UNION_FUNC_DESC, \ .bDescriptorSubtype = UNION_FUNC_DESC, \
.bControlInterface = 0, \ .bControlInterface = 0, \
.bSubordinateInterface0 = 1, \ .bSubordinateInterface0 = 1, \
@ -160,7 +159,7 @@ struct usb_cdc_acm_config {
#define INITIALIZER_IF_EP(addr, attr, mps, interval) \ #define INITIALIZER_IF_EP(addr, attr, mps, interval) \
{ \ { \
.bLength = sizeof(struct usb_ep_descriptor), \ .bLength = sizeof(struct usb_ep_descriptor), \
.bDescriptorType = USB_ENDPOINT_DESC, \ .bDescriptorType = USB_DESC_ENDPOINT, \
.bEndpointAddress = addr, \ .bEndpointAddress = addr, \
.bmAttributes = attr, \ .bmAttributes = attr, \
.wMaxPacketSize = sys_cpu_to_le16(mps), \ .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) #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) \ USBD_CLASS_DESCR_DEFINE(primary, x) \
struct usb_cdc_acm_config cdc_acm_cfg_##x = { \ struct usb_cdc_acm_config cdc_acm_cfg_##x = { \
.iad_cdc = INITIALIZER_IAD, \ .iad_cdc = INITIALIZER_IAD, \
.if0 = INITIALIZER_IF(0, 1, COMMUNICATION_DEVICE_CLASS, \ .if0 = INITIALIZER_IF(0, 1, USB_BCC_CDC_CONTROL, \
ACM_SUBCLASS), \ ACM_SUBCLASS), \
.if0_header = INITIALIZER_IF_HDR, \ .if0_header = INITIALIZER_IF_HDR, \
.if0_cm = INITIALIZER_IF_CM, \ .if0_cm = INITIALIZER_IF_CM, \
@ -1058,7 +1057,7 @@ static const struct uart_driver_api cdc_acm_driver_api = {
USB_DC_EP_INTERRUPT, \ USB_DC_EP_INTERRUPT, \
CONFIG_CDC_ACM_INTERRUPT_EP_MPS,\ CONFIG_CDC_ACM_INTERRUPT_EP_MPS,\
0x0A), \ 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, \ .if1_in_ep = INITIALIZER_IF_EP(in_ep_addr, \
USB_DC_EP_BULK, \ USB_DC_EP_BULK, \
CONFIG_CDC_ACM_BULK_EP_MPS, \ CONFIG_CDC_ACM_BULK_EP_MPS, \
@ -1069,10 +1068,10 @@ static const struct uart_driver_api cdc_acm_driver_api = {
0x00), \ 0x00), \
} }
#else /* (CONFIG_USB_COMPOSITE_DEVICE || CONFIG_CDC_ACM_IAD) */ #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) \ USBD_CLASS_DESCR_DEFINE(primary, x) \
struct usb_cdc_acm_config cdc_acm_cfg_##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), \ ACM_SUBCLASS), \
.if0_header = INITIALIZER_IF_HDR, \ .if0_header = INITIALIZER_IF_HDR, \
.if0_cm = INITIALIZER_IF_CM, \ .if0_cm = INITIALIZER_IF_CM, \
@ -1082,7 +1081,7 @@ static const struct uart_driver_api cdc_acm_driver_api = {
USB_DC_EP_INTERRUPT, \ USB_DC_EP_INTERRUPT, \
CONFIG_CDC_ACM_INTERRUPT_EP_MPS,\ CONFIG_CDC_ACM_INTERRUPT_EP_MPS,\
0x0A), \ 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, \ .if1_in_ep = INITIALIZER_IF_EP(in_ep_addr, \
USB_DC_EP_BULK, \ USB_DC_EP_BULK, \
CONFIG_CDC_ACM_BULK_EP_MPS, \ 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, \ CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&cdc_acm_driver_api); &cdc_acm_driver_api);
#define DEFINE_CDC_ACM_DESCR_AUTO(x, _) \ #define DEFINE_CDC_ACM_DESC_AUTO(x, _) \
DEFINE_CDC_ACM_DESCR(x, AUTO_EP_IN, AUTO_EP_OUT, AUTO_EP_IN); DEFINE_CDC_ACM_DESC(x, AUTO_EP_IN, AUTO_EP_OUT, AUTO_EP_IN);
#define DEFINE_CDC_ACM_EP_AUTO(x, _) \ #define DEFINE_CDC_ACM_EP_AUTO(x, _) \
DEFINE_CDC_ACM_EP(x, AUTO_EP_IN, AUTO_EP_OUT, AUTO_EP_IN); 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_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_CFG_DATA, _)
UTIL_LISTIFY(CONFIG_USB_CDC_ACM_DEVICE_COUNT, DEFINE_CDC_ACM_DEV_DATA, _) UTIL_LISTIFY(CONFIG_USB_CDC_ACM_DEVICE_COUNT, DEFINE_CDC_ACM_DEV_DATA, _)

View file

@ -48,7 +48,6 @@
#include <dfu/flash_img.h> #include <dfu/flash_img.h>
#include <sys/byteorder.h> #include <sys/byteorder.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb/class/usb_dfu.h> #include <usb/class/usb_dfu.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
#include <usb_work_q.h> #include <usb_work_q.h>
@ -89,11 +88,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_dfu_config dfu_cfg = {
/* Interface descriptor */ /* Interface descriptor */
.if0 = { .if0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 0, .bNumEndpoints = 0,
.bInterfaceClass = DFU_DEVICE_CLASS, .bInterfaceClass = USB_BCC_APPLICATION,
.bInterfaceSubClass = DFU_SUBCLASS, .bInterfaceSubClass = DFU_SUBCLASS,
.bInterfaceProtocol = DFU_RT_PROTOCOL, .bInterfaceProtocol = DFU_RT_PROTOCOL,
.iInterface = 0, .iInterface = 0,
@ -133,8 +132,8 @@ struct dev_dfu_mode_descriptor dfu_mode_desc = {
/* Device descriptor */ /* Device descriptor */
.device_descriptor = { .device_descriptor = {
.bLength = sizeof(struct usb_device_descriptor), .bLength = sizeof(struct usb_device_descriptor),
.bDescriptorType = USB_DEVICE_DESC, .bDescriptorType = USB_DESC_DEVICE,
.bcdUSB = sys_cpu_to_le16(USB_2_0), .bcdUSB = sys_cpu_to_le16(USB_SRN_2_0),
.bDeviceClass = 0, .bDeviceClass = 0,
.bDeviceSubClass = 0, .bDeviceSubClass = 0,
.bDeviceProtocol = 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), .idVendor = sys_cpu_to_le16((uint16_t)CONFIG_USB_DEVICE_VID),
.idProduct = .idProduct =
sys_cpu_to_le16((uint16_t)CONFIG_USB_DEVICE_DFU_PID), 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, .iManufacturer = 1,
.iProduct = 2, .iProduct = 2,
.iSerialNumber = 3, .iSerialNumber = 3,
@ -151,23 +150,23 @@ struct dev_dfu_mode_descriptor dfu_mode_desc = {
/* Configuration descriptor */ /* Configuration descriptor */
.cfg_descr = { .cfg_descr = {
.bLength = sizeof(struct usb_cfg_descriptor), .bLength = sizeof(struct usb_cfg_descriptor),
.bDescriptorType = USB_CONFIGURATION_DESC, .bDescriptorType = USB_DESC_CONFIGURATION,
.wTotalLength = 0, .wTotalLength = 0,
.bNumInterfaces = 1, .bNumInterfaces = 1,
.bConfigurationValue = 1, .bConfigurationValue = 1,
.iConfiguration = 0, .iConfiguration = 0,
.bmAttributes = USB_CONFIGURATION_ATTRIBUTES, .bmAttributes = USB_SCD_ATTRIBUTES,
.bMaxPower = CONFIG_USB_MAX_POWER, .bMaxPower = CONFIG_USB_MAX_POWER,
}, },
.sec_dfu_cfg = { .sec_dfu_cfg = {
/* Interface descriptor */ /* Interface descriptor */
.if0 = { .if0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 0, .bNumEndpoints = 0,
.bInterfaceClass = DFU_DEVICE_CLASS, .bInterfaceClass = USB_BCC_APPLICATION,
.bInterfaceSubClass = DFU_SUBCLASS, .bInterfaceSubClass = DFU_SUBCLASS,
.bInterfaceProtocol = DFU_MODE_PROTOCOL, .bInterfaceProtocol = DFU_MODE_PROTOCOL,
.iInterface = 4, .iInterface = 4,
@ -175,11 +174,11 @@ struct dev_dfu_mode_descriptor dfu_mode_desc = {
#if FLASH_AREA_LABEL_EXISTS(image_1) #if FLASH_AREA_LABEL_EXISTS(image_1)
.if1 = { .if1 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 1, .bAlternateSetting = 1,
.bNumEndpoints = 0, .bNumEndpoints = 0,
.bInterfaceClass = DFU_DEVICE_CLASS, .bInterfaceClass = USB_BCC_APPLICATION,
.bInterfaceSubClass = DFU_SUBCLASS, .bInterfaceSubClass = DFU_SUBCLASS,
.bInterfaceProtocol = DFU_MODE_PROTOCOL, .bInterfaceProtocol = DFU_MODE_PROTOCOL,
.iInterface = 5, .iInterface = 5,
@ -241,34 +240,34 @@ USBD_STRING_DESCR_DEFINE(secondary)
struct usb_string_desription string_descr = { struct usb_string_desription string_descr = {
.lang_descr = { .lang_descr = {
.bLength = sizeof(struct usb_string_descriptor), .bLength = sizeof(struct usb_string_descriptor),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = sys_cpu_to_le16(0x0409), .bString = sys_cpu_to_le16(0x0409),
}, },
/* Manufacturer String Descriptor */ /* Manufacturer String Descriptor */
.utf16le_mfr = { .utf16le_mfr = {
.bLength = USB_STRING_DESCRIPTOR_LENGTH( .bLength = USB_STRING_DESCRIPTOR_LENGTH(
CONFIG_USB_DEVICE_MANUFACTURER), CONFIG_USB_DEVICE_MANUFACTURER),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = CONFIG_USB_DEVICE_MANUFACTURER, .bString = CONFIG_USB_DEVICE_MANUFACTURER,
}, },
/* Product String Descriptor */ /* Product String Descriptor */
.utf16le_product = { .utf16le_product = {
.bLength = USB_STRING_DESCRIPTOR_LENGTH( .bLength = USB_STRING_DESCRIPTOR_LENGTH(
CONFIG_USB_DEVICE_PRODUCT), CONFIG_USB_DEVICE_PRODUCT),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = CONFIG_USB_DEVICE_PRODUCT, .bString = CONFIG_USB_DEVICE_PRODUCT,
}, },
/* Serial Number String Descriptor */ /* Serial Number String Descriptor */
.utf16le_sn = { .utf16le_sn = {
.bLength = USB_STRING_DESCRIPTOR_LENGTH(CONFIG_USB_DEVICE_SN), .bLength = USB_STRING_DESCRIPTOR_LENGTH(CONFIG_USB_DEVICE_SN),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = CONFIG_USB_DEVICE_SN, .bString = CONFIG_USB_DEVICE_SN,
}, },
/* Image 0 String Descriptor */ /* Image 0 String Descriptor */
.utf16le_image0 = { .utf16le_image0 = {
.bLength = USB_STRING_DESCRIPTOR_LENGTH( .bLength = USB_STRING_DESCRIPTOR_LENGTH(
FIRMWARE_IMAGE_0_LABEL), FIRMWARE_IMAGE_0_LABEL),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = FIRMWARE_IMAGE_0_LABEL, .bString = FIRMWARE_IMAGE_0_LABEL,
}, },
#if FLASH_AREA_LABEL_EXISTS(image_1) #if FLASH_AREA_LABEL_EXISTS(image_1)
@ -276,7 +275,7 @@ struct usb_string_desription string_descr = {
.utf16le_image1 = { .utf16le_image1 = {
.bLength = USB_STRING_DESCRIPTOR_LENGTH( .bLength = USB_STRING_DESCRIPTOR_LENGTH(
FIRMWARE_IMAGE_1_LABEL), FIRMWARE_IMAGE_1_LABEL),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = FIRMWARE_IMAGE_1_LABEL, .bString = FIRMWARE_IMAGE_1_LABEL,
}, },
#endif #endif
@ -681,9 +680,8 @@ static int dfu_custom_handle_req(struct usb_setup_packet *pSetup,
{ {
ARG_UNUSED(data); ARG_UNUSED(data);
if (REQTYPE_GET_RECIP(pSetup->bmRequestType) == if (pSetup->RequestType.recipient == USB_REQTYPE_RECIPIENT_INTERFACE) {
REQTYPE_RECIP_INTERFACE) { if (pSetup->bRequest == USB_SREQ_SET_INTERFACE) {
if (pSetup->bRequest == REQ_SET_INTERFACE) {
LOG_DBG("DFU alternate setting %d", pSetup->wValue); LOG_DBG("DFU alternate setting %d", pSetup->wValue);
const struct flash_area *fa; const struct flash_area *fa;

View file

@ -13,7 +13,6 @@ LOG_MODULE_REGISTER(usb_hid);
#include <sys/byteorder.h> #include <sys/byteorder.h>
#include <usb_device.h> #include <usb_device.h>
#include <usb_common.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
#include <class/usb_hid.h> #include <class/usb_hid.h>
@ -55,11 +54,11 @@ struct usb_hid_config {
#define INITIALIZER_IF \ #define INITIALIZER_IF \
{ \ { \
.bLength = sizeof(struct usb_if_descriptor), \ .bLength = sizeof(struct usb_if_descriptor), \
.bDescriptorType = USB_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_INTERFACE, \
.bInterfaceNumber = 0, \ .bInterfaceNumber = 0, \
.bAlternateSetting = 0, \ .bAlternateSetting = 0, \
.bNumEndpoints = 1, \ .bNumEndpoints = 1, \
.bInterfaceClass = HID_CLASS, \ .bInterfaceClass = USB_BCC_HID, \
.bInterfaceSubClass = 1, \ .bInterfaceSubClass = 1, \
.bInterfaceProtocol = CONFIG_USB_HID_PROTOCOL_CODE, \ .bInterfaceProtocol = CONFIG_USB_HID_PROTOCOL_CODE, \
.iInterface = 0, \ .iInterface = 0, \
@ -68,11 +67,11 @@ struct usb_hid_config {
#define INITIALIZER_IF \ #define INITIALIZER_IF \
{ \ { \
.bLength = sizeof(struct usb_if_descriptor), \ .bLength = sizeof(struct usb_if_descriptor), \
.bDescriptorType = USB_INTERFACE_DESC, \ .bDescriptorType = USB_DESC_INTERFACE, \
.bInterfaceNumber = 0, \ .bInterfaceNumber = 0, \
.bAlternateSetting = 0, \ .bAlternateSetting = 0, \
.bNumEndpoints = 1, \ .bNumEndpoints = 1, \
.bInterfaceClass = HID_CLASS, \ .bInterfaceClass = USB_BCC_HID, \
.bInterfaceSubClass = 0, \ .bInterfaceSubClass = 0, \
.bInterfaceProtocol = 0, \ .bInterfaceProtocol = 0, \
.iInterface = 0, \ .iInterface = 0, \
@ -83,12 +82,12 @@ struct usb_hid_config {
#define INITIALIZER_IF_HID \ #define INITIALIZER_IF_HID \
{ \ { \
.bLength = sizeof(struct usb_hid_descriptor), \ .bLength = sizeof(struct usb_hid_descriptor), \
.bDescriptorType = USB_HID_DESC, \ .bDescriptorType = USB_DESC_HID, \
.bcdHID = sys_cpu_to_le16(USB_1_1), \ .bcdHID = sys_cpu_to_le16(USB_SRN_1_1), \
.bCountryCode = 0, \ .bCountryCode = 0, \
.bNumDescriptors = 1, \ .bNumDescriptors = 1, \
.subdesc[0] = { \ .subdesc[0] = { \
.bDescriptorType = USB_HID_REPORT_DESC, \ .bDescriptorType = USB_DESC_HID_REPORT, \
.wDescriptorLength = 0, \ .wDescriptorLength = 0, \
}, \ }, \
} }
@ -96,7 +95,7 @@ struct usb_hid_config {
#define INITIALIZER_IF_EP(addr, attr, mps) \ #define INITIALIZER_IF_EP(addr, attr, mps) \
{ \ { \
.bLength = sizeof(struct usb_ep_descriptor), \ .bLength = sizeof(struct usb_ep_descriptor), \
.bDescriptorType = USB_ENDPOINT_DESC, \ .bDescriptorType = USB_DESC_ENDPOINT, \
.bEndpointAddress = addr, \ .bEndpointAddress = addr, \
.bmAttributes = attr, \ .bmAttributes = attr, \
.wMaxPacketSize = sys_cpu_to_le16(mps), \ .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_data = CONTAINER_OF(common, struct hid_device_info, common);
dev = common->dev; dev = common->dev;
if (REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_HOST) { if (usb_reqtype_is_to_host(setup)) {
switch (setup->bRequest) { switch (setup->bRequest) {
case USB_HID_GET_IDLE: case USB_HID_GET_IDLE:
return hid_on_get_idle(dev_data, setup, len, data); 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", "bRequest 0x%02x, bmRequestType 0x%02x, len %d",
setup->bRequest, setup->bmRequestType, *len); setup->bRequest, setup->bmRequestType, *len);
if (REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_HOST && if (usb_reqtype_is_to_host(setup) &&
REQTYPE_GET_RECIP(setup->bmRequestType) == setup->RequestType.recipient == USB_REQTYPE_RECIPIENT_INTERFACE &&
REQTYPE_RECIP_INTERFACE && setup->bRequest == USB_SREQ_GET_DESCRIPTOR) {
setup->bRequest == REQ_GET_DESCRIPTOR) {
uint8_t value = (uint8_t)(setup->wValue >> 8); uint8_t value = (uint8_t)(setup->wValue >> 8);
uint8_t iface_num = (uint8_t)setup->wIndex; uint8_t iface_num = (uint8_t)setup->wIndex;
struct hid_device_info *dev_data; struct hid_device_info *dev_data;

View file

@ -10,7 +10,6 @@
#include <sys/byteorder.h> #include <sys/byteorder.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
#define LOG_LEVEL CONFIG_USB_DEVICE_LOG_LEVEL #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 */ /* Interface descriptor 0 */
.if0 = { .if0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 2, .bNumEndpoints = 2,
.bInterfaceClass = CUSTOM_CLASS, .bInterfaceClass = USB_BCC_VENDOR,
.bInterfaceSubClass = 0, .bInterfaceSubClass = 0,
.bInterfaceProtocol = 0, .bInterfaceProtocol = 0,
.iInterface = 0, .iInterface = 0,
@ -49,7 +48,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_loopback_config loopback_cfg = {
/* Data Endpoint OUT */ /* Data Endpoint OUT */
.if0_out_ep = { .if0_out_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = LOOPBACK_OUT_EP_ADDR, .bEndpointAddress = LOOPBACK_OUT_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = sys_cpu_to_le16(CONFIG_LOOPBACK_BULK_EP_MPS), .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 */ /* Data Endpoint IN */
.if0_in_ep = { .if0_in_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = LOOPBACK_IN_EP_ADDR, .bEndpointAddress = LOOPBACK_IN_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = sys_cpu_to_le16(CONFIG_LOOPBACK_BULK_EP_MPS), .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", LOG_DBG("Class request: bRequest 0x%x bmRequestType 0x%x len %d",
setup->bRequest, setup->bmRequestType, *len); setup->bRequest, setup->bmRequestType, *len);
if (REQTYPE_GET_RECIP(setup->bmRequestType) != REQTYPE_RECIP_DEVICE) { if (setup->RequestType.recipient != USB_REQTYPE_RECIPIENT_DEVICE) {
return -ENOTSUP; return -ENOTSUP;
} }
if (REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_DEVICE && if (usb_reqtype_is_to_device(setup) &&
setup->bRequest == 0x5b) { setup->bRequest == 0x5b) {
LOG_DBG("Host-to-Device, data %p", *data); LOG_DBG("Host-to-Device, data %p", *data);
return 0; return 0;
} }
if ((REQTYPE_GET_DIR(setup->bmRequestType) == REQTYPE_DIR_TO_HOST) && if ((usb_reqtype_is_to_host(setup)) &&
(setup->bRequest == 0x5c)) { (setup->bRequest == 0x5c)) {
LOG_DBG("Device-to-Host, wLength %d, data %p", LOG_DBG("Device-to-Host, wLength %d, data %p",
setup->wLength, *data); setup->wLength, *data);

View file

@ -41,7 +41,6 @@
#include <storage/disk_access.h> #include <storage/disk_access.h>
#include <usb/class/usb_msc.h> #include <usb/class/usb_msc.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
#define LOG_LEVEL CONFIG_USB_MASS_STORAGE_LOG_LEVEL #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 */ /* Interface descriptor */
.if0 = { .if0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 2, .bNumEndpoints = 2,
.bInterfaceClass = MASS_STORAGE_CLASS, .bInterfaceClass = USB_BCC_MASS_STORAGE,
.bInterfaceSubClass = SCSI_TRANSPARENT_SUBCLASS, .bInterfaceSubClass = SCSI_TRANSPARENT_SUBCLASS,
.bInterfaceProtocol = BULK_ONLY_PROTOCOL, .bInterfaceProtocol = BULK_ONLY_TRANSPORT_PROTOCOL,
.iInterface = 0, .iInterface = 0,
}, },
/* First Endpoint IN */ /* First Endpoint IN */
.if0_in_ep = { .if0_in_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = MASS_STORAGE_IN_EP_ADDR, .bEndpointAddress = MASS_STORAGE_IN_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = .wMaxPacketSize =
@ -93,7 +92,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_mass_config mass_cfg = {
/* Second Endpoint OUT */ /* Second Endpoint OUT */
.if0_out_ep = { .if0_out_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = MASS_STORAGE_OUT_EP_ADDR, .bEndpointAddress = MASS_STORAGE_OUT_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = .wMaxPacketSize =

View file

@ -16,7 +16,6 @@ LOG_MODULE_REGISTER(usb_ecm);
#include <net_private.h> #include <net_private.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb/class/usb_cdc.h> #include <usb/class/usb_cdc.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
@ -53,10 +52,10 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = {
#ifdef CONFIG_USB_COMPOSITE_DEVICE #ifdef CONFIG_USB_COMPOSITE_DEVICE
.iad = { .iad = {
.bLength = sizeof(struct usb_association_descriptor), .bLength = sizeof(struct usb_association_descriptor),
.bDescriptorType = USB_ASSOCIATION_DESC, .bDescriptorType = USB_DESC_INTERFACE_ASSOC,
.bFirstInterface = 0, .bFirstInterface = 0,
.bInterfaceCount = 0x02, .bInterfaceCount = 0x02,
.bFunctionClass = COMMUNICATION_DEVICE_CLASS, .bFunctionClass = USB_BCC_CDC_CONTROL,
.bFunctionSubClass = ECM_SUBCLASS, .bFunctionSubClass = ECM_SUBCLASS,
.bFunctionProtocol = 0, .bFunctionProtocol = 0,
.iFunction = 0, .iFunction = 0,
@ -66,11 +65,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = {
/* CDC Communication interface */ /* CDC Communication interface */
.if0 = { .if0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 1, .bNumEndpoints = 1,
.bInterfaceClass = COMMUNICATION_DEVICE_CLASS, .bInterfaceClass = USB_BCC_CDC_CONTROL,
.bInterfaceSubClass = ECM_SUBCLASS, .bInterfaceSubClass = ECM_SUBCLASS,
.bInterfaceProtocol = 0, .bInterfaceProtocol = 0,
.iInterface = 0, .iInterface = 0,
@ -78,14 +77,14 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = {
/* Header Functional Descriptor */ /* Header Functional Descriptor */
.if0_header = { .if0_header = {
.bFunctionLength = sizeof(struct cdc_header_descriptor), .bFunctionLength = sizeof(struct cdc_header_descriptor),
.bDescriptorType = USB_CS_INTERFACE_DESC, .bDescriptorType = USB_DESC_CS_INTERFACE,
.bDescriptorSubtype = HEADER_FUNC_DESC, .bDescriptorSubtype = HEADER_FUNC_DESC,
.bcdCDC = sys_cpu_to_le16(USB_1_1), .bcdCDC = sys_cpu_to_le16(USB_SRN_1_1),
}, },
/* Union Functional Descriptor */ /* Union Functional Descriptor */
.if0_union = { .if0_union = {
.bFunctionLength = sizeof(struct cdc_union_descriptor), .bFunctionLength = sizeof(struct cdc_union_descriptor),
.bDescriptorType = USB_CS_INTERFACE_DESC, .bDescriptorType = USB_DESC_CS_INTERFACE,
.bDescriptorSubtype = UNION_FUNC_DESC, .bDescriptorSubtype = UNION_FUNC_DESC,
.bControlInterface = 0, .bControlInterface = 0,
.bSubordinateInterface0 = 1, .bSubordinateInterface0 = 1,
@ -93,7 +92,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = {
/* Ethernet Networking Functional descriptor */ /* Ethernet Networking Functional descriptor */
.if0_netfun_ecm = { .if0_netfun_ecm = {
.bFunctionLength = sizeof(struct cdc_ecm_descriptor), .bFunctionLength = sizeof(struct cdc_ecm_descriptor),
.bDescriptorType = USB_CS_INTERFACE_DESC, .bDescriptorType = USB_DESC_CS_INTERFACE,
.bDescriptorSubtype = ETHERNET_FUNC_DESC, .bDescriptorSubtype = ETHERNET_FUNC_DESC,
.iMACAddress = 4, .iMACAddress = 4,
.bmEthernetStatistics = sys_cpu_to_le32(0), /* None */ .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 */ /* Notification EP Descriptor */
.if0_int_ep = { .if0_int_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = CDC_ECM_INT_EP_ADDR, .bEndpointAddress = CDC_ECM_INT_EP_ADDR,
.bmAttributes = USB_DC_EP_INTERRUPT, .bmAttributes = USB_DC_EP_INTERRUPT,
.wMaxPacketSize = .wMaxPacketSize =
@ -117,11 +116,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = {
/* CDC Data Interface */ /* CDC Data Interface */
.if1_0 = { .if1_0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 1, .bInterfaceNumber = 1,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 0, .bNumEndpoints = 0,
.bInterfaceClass = COMMUNICATION_DEVICE_CLASS_DATA, .bInterfaceClass = USB_BCC_CDC_DATA,
.bInterfaceSubClass = 0, .bInterfaceSubClass = 0,
.bInterfaceProtocol = 0, .bInterfaceProtocol = 0,
.iInterface = 0, .iInterface = 0,
@ -131,11 +130,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = {
/* CDC Data Interface */ /* CDC Data Interface */
.if1_1 = { .if1_1 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 1, .bInterfaceNumber = 1,
.bAlternateSetting = 1, .bAlternateSetting = 1,
.bNumEndpoints = 2, .bNumEndpoints = 2,
.bInterfaceClass = COMMUNICATION_DEVICE_CLASS_DATA, .bInterfaceClass = USB_BCC_CDC_DATA,
.bInterfaceSubClass = ECM_SUBCLASS, .bInterfaceSubClass = ECM_SUBCLASS,
.bInterfaceProtocol = 0, .bInterfaceProtocol = 0,
.iInterface = 0, .iInterface = 0,
@ -143,7 +142,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = {
/* Data Endpoint IN */ /* Data Endpoint IN */
.if1_1_in_ep = { .if1_1_in_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = CDC_ECM_IN_EP_ADDR, .bEndpointAddress = CDC_ECM_IN_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = .wMaxPacketSize =
@ -154,7 +153,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_ecm_config cdc_ecm_cfg = {
/* Data Endpoint OUT */ /* Data Endpoint OUT */
.if1_1_out_ep = { .if1_1_out_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = CDC_ECM_OUT_EP_ADDR, .bEndpointAddress = CDC_ECM_OUT_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = .wMaxPacketSize =
@ -402,7 +401,7 @@ struct usb_cdc_ecm_mac_descr {
USBD_STRING_DESCR_DEFINE(primary) struct usb_cdc_ecm_mac_descr utf16le_mac = { USBD_STRING_DESCR_DEFINE(primary) struct usb_cdc_ecm_mac_descr utf16le_mac = {
.bLength = USB_STRING_DESCRIPTOR_LENGTH( .bLength = USB_STRING_DESCRIPTOR_LENGTH(
CONFIG_USB_DEVICE_NETWORK_ECM_MAC), CONFIG_USB_DEVICE_NETWORK_ECM_MAC),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = CONFIG_USB_DEVICE_NETWORK_ECM_MAC .bString = CONFIG_USB_DEVICE_NETWORK_ECM_MAC
}; };

View file

@ -13,7 +13,6 @@ LOG_MODULE_REGISTER(usb_eem);
#include <net_private.h> #include <net_private.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb/class/usb_cdc.h> #include <usb/class/usb_cdc.h>
#include "netusb.h" #include "netusb.h"
@ -36,11 +35,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_eem_config cdc_eem_cfg = {
/* CDC Communication interface */ /* CDC Communication interface */
.if0 = { .if0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 2, .bNumEndpoints = 2,
.bInterfaceClass = COMMUNICATION_DEVICE_CLASS, .bInterfaceClass = USB_BCC_CDC_CONTROL,
.bInterfaceSubClass = EEM_SUBCLASS, .bInterfaceSubClass = EEM_SUBCLASS,
.bInterfaceProtocol = EEM_PROTOCOL, .bInterfaceProtocol = EEM_PROTOCOL,
.iInterface = 0, .iInterface = 0,
@ -49,7 +48,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_eem_config cdc_eem_cfg = {
/* Data Endpoint IN */ /* Data Endpoint IN */
.if0_in_ep = { .if0_in_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = CDC_EEM_IN_EP_ADDR, .bEndpointAddress = CDC_EEM_IN_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = .wMaxPacketSize =
@ -60,7 +59,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_cdc_eem_config cdc_eem_cfg = {
/* Data Endpoint OUT */ /* Data Endpoint OUT */
.if0_out_ep = { .if0_out_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = CDC_EEM_OUT_EP_ADDR, .bEndpointAddress = CDC_EEM_OUT_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = .wMaxPacketSize =

View file

@ -17,7 +17,6 @@ LOG_MODULE_REGISTER(usb_rndis);
#include <net_private.h> #include <net_private.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb/class/usb_cdc.h> #include <usb/class/usb_cdc.h>
#include <os_desc.h> #include <os_desc.h>
@ -64,10 +63,10 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = {
#ifdef CONFIG_USB_COMPOSITE_DEVICE #ifdef CONFIG_USB_COMPOSITE_DEVICE
.iad = { .iad = {
.bLength = sizeof(struct usb_association_descriptor), .bLength = sizeof(struct usb_association_descriptor),
.bDescriptorType = USB_ASSOCIATION_DESC, .bDescriptorType = USB_DESC_INTERFACE_ASSOC,
.bFirstInterface = 0, .bFirstInterface = 0,
.bInterfaceCount = 0x02, .bInterfaceCount = 0x02,
.bFunctionClass = COMMUNICATION_DEVICE_CLASS, .bFunctionClass = USB_BCC_CDC_CONTROL,
.bFunctionSubClass = 6, .bFunctionSubClass = 6,
.bFunctionProtocol = 0, .bFunctionProtocol = 0,
.iFunction = 0, .iFunction = 0,
@ -77,11 +76,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = {
/* CDC Communication interface */ /* CDC Communication interface */
.if0 = { .if0 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 0, .bInterfaceNumber = 0,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 1, .bNumEndpoints = 1,
.bInterfaceClass = COMMUNICATION_DEVICE_CLASS, .bInterfaceClass = USB_BCC_CDC_CONTROL,
.bInterfaceSubClass = ACM_SUBCLASS, .bInterfaceSubClass = ACM_SUBCLASS,
.bInterfaceProtocol = ACM_VENDOR_PROTOCOL, .bInterfaceProtocol = ACM_VENDOR_PROTOCOL,
.iInterface = 0, .iInterface = 0,
@ -89,14 +88,14 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = {
/* Header Functional Descriptor */ /* Header Functional Descriptor */
.if0_header = { .if0_header = {
.bFunctionLength = sizeof(struct cdc_header_descriptor), .bFunctionLength = sizeof(struct cdc_header_descriptor),
.bDescriptorType = USB_CS_INTERFACE_DESC, .bDescriptorType = USB_DESC_CS_INTERFACE,
.bDescriptorSubtype = HEADER_FUNC_DESC, .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 */ /* Call Management Functional Descriptor */
.if0_cm = { .if0_cm = {
.bFunctionLength = sizeof(struct cdc_cm_descriptor), .bFunctionLength = sizeof(struct cdc_cm_descriptor),
.bDescriptorType = USB_CS_INTERFACE_DESC, .bDescriptorType = USB_DESC_CS_INTERFACE,
.bDescriptorSubtype = CALL_MANAGEMENT_FUNC_DESC, .bDescriptorSubtype = CALL_MANAGEMENT_FUNC_DESC,
.bmCapabilities = 0x00, .bmCapabilities = 0x00,
.bDataInterface = 1, .bDataInterface = 1,
@ -104,7 +103,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = {
/* ACM Functional Descriptor */ /* ACM Functional Descriptor */
.if0_acm = { .if0_acm = {
.bFunctionLength = sizeof(struct cdc_acm_descriptor), .bFunctionLength = sizeof(struct cdc_acm_descriptor),
.bDescriptorType = USB_CS_INTERFACE_DESC, .bDescriptorType = USB_DESC_CS_INTERFACE,
.bDescriptorSubtype = ACM_FUNC_DESC, .bDescriptorSubtype = ACM_FUNC_DESC,
/* Device supports the request combination of: /* Device supports the request combination of:
* Set_Line_Coding, * Set_Line_Coding,
@ -117,7 +116,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = {
/* Union Functional Descriptor */ /* Union Functional Descriptor */
.if0_union = { .if0_union = {
.bFunctionLength = sizeof(struct cdc_union_descriptor), .bFunctionLength = sizeof(struct cdc_union_descriptor),
.bDescriptorType = USB_CS_INTERFACE_DESC, .bDescriptorType = USB_DESC_CS_INTERFACE,
.bDescriptorSubtype = UNION_FUNC_DESC, .bDescriptorSubtype = UNION_FUNC_DESC,
.bControlInterface = 0, .bControlInterface = 0,
.bSubordinateInterface0 = 1, .bSubordinateInterface0 = 1,
@ -125,7 +124,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = {
/* Notification EP Descriptor */ /* Notification EP Descriptor */
.if0_int_ep = { .if0_int_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = RNDIS_INT_EP_ADDR, .bEndpointAddress = RNDIS_INT_EP_ADDR,
.bmAttributes = USB_DC_EP_INTERRUPT, .bmAttributes = USB_DC_EP_INTERRUPT,
.wMaxPacketSize = .wMaxPacketSize =
@ -137,11 +136,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = {
/* CDC Data Interface */ /* CDC Data Interface */
.if1 = { .if1 = {
.bLength = sizeof(struct usb_if_descriptor), .bLength = sizeof(struct usb_if_descriptor),
.bDescriptorType = USB_INTERFACE_DESC, .bDescriptorType = USB_DESC_INTERFACE,
.bInterfaceNumber = 1, .bInterfaceNumber = 1,
.bAlternateSetting = 0, .bAlternateSetting = 0,
.bNumEndpoints = 2, .bNumEndpoints = 2,
.bInterfaceClass = COMMUNICATION_DEVICE_CLASS_DATA, .bInterfaceClass = USB_BCC_CDC_DATA,
.bInterfaceSubClass = 0, .bInterfaceSubClass = 0,
.bInterfaceProtocol = 0, .bInterfaceProtocol = 0,
.iInterface = 0, .iInterface = 0,
@ -149,7 +148,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = {
/* Data Endpoint IN */ /* Data Endpoint IN */
.if1_in_ep = { .if1_in_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = RNDIS_IN_EP_ADDR, .bEndpointAddress = RNDIS_IN_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = .wMaxPacketSize =
@ -159,7 +158,7 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct usb_rndis_config rndis_cfg = {
/* Data Endpoint OUT */ /* Data Endpoint OUT */
.if1_out_ep = { .if1_out_ep = {
.bLength = sizeof(struct usb_ep_descriptor), .bLength = sizeof(struct usb_ep_descriptor),
.bDescriptorType = USB_ENDPOINT_DESC, .bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = RNDIS_OUT_EP_ADDR, .bEndpointAddress = RNDIS_OUT_EP_ADDR,
.bmAttributes = USB_DC_EP_BULK, .bmAttributes = USB_DC_EP_BULK,
.wMaxPacketSize = .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 && 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 * Instead of handling here, queue
* handle_encapsulated_cmd(*data, *len); * handle_encapsulated_cmd(*data, *len);
*/ */
queue_encapsulated_cmd(*data, *len); queue_encapsulated_cmd(*data, *len);
} else if (setup->bRequest == CDC_GET_ENC_RSP && } else if (setup->bRequest == CDC_GET_ENC_RSP &&
REQTYPE_GET_DIR(setup->bmRequestType) == usb_reqtype_is_to_host(setup)) {
REQTYPE_DIR_TO_HOST) {
handle_encapsulated_rsp(data, len); handle_encapsulated_rsp(data, len);
} else { } else {
*len = 0; /* FIXME! */ *len = 0; /* FIXME! */
@ -1015,7 +1013,7 @@ static struct string_desc {
uint8_t bPad; uint8_t bPad;
} __packed msosv1_string_descriptor = { } __packed msosv1_string_descriptor = {
.bLength = MSOS_STRING_LENGTH, .bLength = MSOS_STRING_LENGTH,
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
/* Signature MSFT100 */ /* Signature MSFT100 */
.bString = { .bString = {
'M', 0x00, 'S', 0x00, 'F', 0x00, 'T', 0x00, 'M', 0x00, 'S', 0x00, 'F', 0x00, 'T', 0x00,

View file

@ -16,7 +16,6 @@ LOG_MODULE_REGISTER(usb_net);
#include <net_private.h> #include <net_private.h>
#include <usb_device.h> #include <usb_device.h>
#include <usb_common.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
#include "netusb.h" #include "netusb.h"

View file

@ -11,7 +11,6 @@ LOG_MODULE_REGISTER(usb_os_desc);
#include <zephyr.h> #include <zephyr.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <os_desc.h> #include <os_desc.h>
static struct usb_os_descriptor *os_desc; static struct usb_os_descriptor *os_desc;
@ -23,8 +22,8 @@ int usb_handle_os_desc(struct usb_setup_packet *setup,
return -ENOTSUP; return -ENOTSUP;
} }
if (GET_DESC_TYPE(setup->wValue) == USB_STRING_DESC && if (USB_GET_DESCRIPTOR_TYPE(setup->wValue) == USB_DESC_STRING &&
GET_DESC_INDEX(setup->wValue) == USB_OSDESC_STRING_DESC_INDEX) { USB_GET_DESCRIPTOR_INDEX(setup->wValue) == USB_OSDESC_STRING_DESC_INDEX) {
LOG_DBG("MS OS Descriptor string read"); LOG_DBG("MS OS Descriptor string read");
*data = os_desc->string; *data = os_desc->string;
*len = os_desc->string_len; *len = os_desc->string_len;

View file

@ -10,9 +10,7 @@
#include <string.h> #include <string.h>
#include <sys/byteorder.h> #include <sys/byteorder.h>
#include <sys/__assert.h> #include <sys/__assert.h>
#include <usb/usbstruct.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usb_common.h>
#include "usb_descriptor.h" #include "usb_descriptor.h"
#include <drivers/hwinfo.h> #include <drivers/hwinfo.h>
@ -59,14 +57,14 @@ USBD_DEVICE_DESCR_DEFINE(primary) struct common_descriptor common_desc = {
/* Device descriptor */ /* Device descriptor */
.device_descriptor = { .device_descriptor = {
.bLength = sizeof(struct usb_device_descriptor), .bLength = sizeof(struct usb_device_descriptor),
.bDescriptorType = USB_DEVICE_DESC, .bDescriptorType = USB_DESC_DEVICE,
#ifdef CONFIG_USB_DEVICE_BOS #ifdef CONFIG_USB_DEVICE_BOS
.bcdUSB = sys_cpu_to_le16(USB_2_1), .bcdUSB = sys_cpu_to_le16(USB_SRN_2_1),
#else #else
.bcdUSB = sys_cpu_to_le16(USB_2_0), .bcdUSB = sys_cpu_to_le16(USB_SRN_2_0),
#endif #endif
#ifdef CONFIG_USB_COMPOSITE_DEVICE #ifdef CONFIG_USB_COMPOSITE_DEVICE
.bDeviceClass = MISC_CLASS, .bDeviceClass = USB_BCC_MISCELLANEOUS,
.bDeviceSubClass = 0x02, .bDeviceSubClass = 0x02,
.bDeviceProtocol = 0x01, .bDeviceProtocol = 0x01,
#else #else
@ -77,7 +75,7 @@ USBD_DEVICE_DESCR_DEFINE(primary) struct common_descriptor common_desc = {
.bMaxPacketSize0 = USB_MAX_CTRL_MPS, .bMaxPacketSize0 = USB_MAX_CTRL_MPS,
.idVendor = sys_cpu_to_le16((uint16_t)CONFIG_USB_DEVICE_VID), .idVendor = sys_cpu_to_le16((uint16_t)CONFIG_USB_DEVICE_VID),
.idProduct = sys_cpu_to_le16((uint16_t)CONFIG_USB_DEVICE_PID), .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, .iManufacturer = USB_DESC_MANUFACTURER_IDX,
.iProduct = USB_DESC_PRODUCT_IDX, .iProduct = USB_DESC_PRODUCT_IDX,
.iSerialNumber = USB_DESC_SERIAL_NUMBER_IDX, .iSerialNumber = USB_DESC_SERIAL_NUMBER_IDX,
@ -86,13 +84,13 @@ USBD_DEVICE_DESCR_DEFINE(primary) struct common_descriptor common_desc = {
/* Configuration descriptor */ /* Configuration descriptor */
.cfg_descr = { .cfg_descr = {
.bLength = sizeof(struct usb_cfg_descriptor), .bLength = sizeof(struct usb_cfg_descriptor),
.bDescriptorType = USB_CONFIGURATION_DESC, .bDescriptorType = USB_DESC_CONFIGURATION,
/*wTotalLength will be fixed in usb_fix_descriptor() */ /*wTotalLength will be fixed in usb_fix_descriptor() */
.wTotalLength = 0, .wTotalLength = 0,
.bNumInterfaces = 0, .bNumInterfaces = 0,
.bConfigurationValue = 1, .bConfigurationValue = 1,
.iConfiguration = 0, .iConfiguration = 0,
.bmAttributes = USB_CONFIGURATION_ATTRIBUTES, .bmAttributes = USB_SCD_ATTRIBUTES,
.bMaxPower = CONFIG_USB_MAX_POWER, .bMaxPower = CONFIG_USB_MAX_POWER,
}, },
}; };
@ -127,27 +125,27 @@ struct usb_string_desription {
USBD_STRING_DESCR_DEFINE(primary) struct usb_string_desription string_descr = { USBD_STRING_DESCR_DEFINE(primary) struct usb_string_desription string_descr = {
.lang_descr = { .lang_descr = {
.bLength = sizeof(struct usb_string_descriptor), .bLength = sizeof(struct usb_string_descriptor),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = sys_cpu_to_le16(0x0409), .bString = sys_cpu_to_le16(0x0409),
}, },
/* Manufacturer String Descriptor */ /* Manufacturer String Descriptor */
.utf16le_mfr = { .utf16le_mfr = {
.bLength = USB_STRING_DESCRIPTOR_LENGTH( .bLength = USB_STRING_DESCRIPTOR_LENGTH(
CONFIG_USB_DEVICE_MANUFACTURER), CONFIG_USB_DEVICE_MANUFACTURER),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = CONFIG_USB_DEVICE_MANUFACTURER, .bString = CONFIG_USB_DEVICE_MANUFACTURER,
}, },
/* Product String Descriptor */ /* Product String Descriptor */
.utf16le_product = { .utf16le_product = {
.bLength = USB_STRING_DESCRIPTOR_LENGTH( .bLength = USB_STRING_DESCRIPTOR_LENGTH(
CONFIG_USB_DEVICE_PRODUCT), CONFIG_USB_DEVICE_PRODUCT),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = CONFIG_USB_DEVICE_PRODUCT, .bString = CONFIG_USB_DEVICE_PRODUCT,
}, },
/* Serial Number String Descriptor */ /* Serial Number String Descriptor */
.utf16le_sn = { .utf16le_sn = {
.bLength = USB_STRING_DESCRIPTOR_LENGTH(CONFIG_USB_DEVICE_SN), .bLength = USB_STRING_DESCRIPTOR_LENGTH(CONFIG_USB_DEVICE_SN),
.bDescriptorType = USB_STRING_DESC, .bDescriptorType = USB_DESC_STRING,
.bString = CONFIG_USB_DEVICE_SN, .bString = CONFIG_USB_DEVICE_SN,
}, },
}; };
@ -198,7 +196,7 @@ int usb_get_str_descriptor_idx(void *ptr)
while (head->bLength != 0U) { while (head->bLength != 0U) {
switch (head->bDescriptorType) { switch (head->bDescriptorType) {
case USB_STRING_DESC: case USB_DESC_STRING:
if (head == (struct usb_desc_header *)str) { if (head == (struct usb_desc_header *)str) {
return str_descr_idx; return str_descr_idx;
} }
@ -380,14 +378,14 @@ static int usb_fix_descriptor(struct usb_desc_header *head)
while (head->bLength != 0U) { while (head->bLength != 0U) {
switch (head->bDescriptorType) { switch (head->bDescriptorType) {
case USB_CONFIGURATION_DESC: case USB_DESC_CONFIGURATION:
cfg_descr = (struct usb_cfg_descriptor *)head; cfg_descr = (struct usb_cfg_descriptor *)head;
LOG_DBG("Configuration descriptor %p", head); LOG_DBG("Configuration descriptor %p", head);
break; break;
case USB_ASSOCIATION_DESC: case USB_DESC_INTERFACE_ASSOC:
LOG_DBG("Association descriptor %p", head); LOG_DBG("Association descriptor %p", head);
break; break;
case USB_INTERFACE_DESC: case USB_DESC_INTERFACE:
if_descr = (struct usb_if_descriptor *)head; if_descr = (struct usb_if_descriptor *)head;
LOG_DBG("Interface descriptor %p", head); LOG_DBG("Interface descriptor %p", head);
if (if_descr->bAlternateSetting) { if (if_descr->bAlternateSetting) {
@ -411,7 +409,7 @@ static int usb_fix_descriptor(struct usb_desc_header *head)
numof_ifaces++; numof_ifaces++;
break; break;
case USB_ENDPOINT_DESC: case USB_DESC_ENDPOINT:
if (!cfg_data) { if (!cfg_data) {
LOG_ERR("Uninitialized usb_cfg_data pointer, " LOG_ERR("Uninitialized usb_cfg_data pointer, "
"corrupted device descriptor?"); "corrupted device descriptor?");
@ -429,7 +427,7 @@ static int usb_fix_descriptor(struct usb_desc_header *head)
break; break;
case 0: case 0:
case USB_STRING_DESC: case USB_DESC_STRING:
/* /*
* Copy runtime SN string descriptor first, if has * Copy runtime SN string descriptor first, if has
*/ */

View file

@ -2,6 +2,7 @@
* LPCUSB, an USB device driver for LPC microcontrollers * LPCUSB, an USB device driver for LPC microcontrollers
* Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) * Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl)
* Copyright (c) 2016 Intel Corporation * Copyright (c) 2016 Intel Corporation
* Copyright (c) 2020 PHYTEC Messtechnik GmbH
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -64,9 +65,8 @@
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <sys/byteorder.h> #include <sys/byteorder.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/usbstruct.h>
#include <usb/usb_common.h>
#include <usb_descriptor.h> #include <usb_descriptor.h>
#include <usb/class/usb_audio.h>
#define LOG_LEVEL CONFIG_USB_DEVICE_LOG_LEVEL #define LOG_LEVEL CONFIG_USB_DEVICE_LOG_LEVEL
#include <logging/log.h> #include <logging/log.h>
@ -99,10 +99,6 @@ LOG_MODULE_REGISTER(usb_device);
#define MAX_NUM_REQ_HANDLERS 4U #define MAX_NUM_REQ_HANDLERS 4U
#define MAX_STD_REQ_MSG_SIZE 8U #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 */ /* Linker-defined symbols bound the USB descriptor structs */
extern struct usb_cfg_data __usb_data_start[]; extern struct usb_cfg_data __usb_data_start[];
extern struct usb_cfg_data __usb_data_end[]; 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, static bool usb_handle_request(struct usb_setup_packet *setup,
int32_t *len, uint8_t **data) int32_t *len, uint8_t **data)
{ {
uint32_t type = REQTYPE_GET_TYPE(setup->bmRequestType); uint32_t type = setup->RequestType.type;
usb_request_handler handler = usb_dev.req_handlers[type]; usb_request_handler handler;
if (type >= MAX_NUM_REQ_HANDLERS) { if (type >= MAX_NUM_REQ_HANDLERS) {
LOG_DBG("Error Incorrect iType %d", type); LOG_DBG("Error Incorrect iType %d", type);
return false; return false;
} }
handler = usb_dev.req_handlers[type];
if (handler == NULL) { if (handler == NULL) {
LOG_DBG("No handler for reqtype %d", type); LOG_DBG("No handler for reqtype %d", type);
return false; return false;
@ -245,7 +242,7 @@ static void usb_data_to_host(void)
uint32_t chunk = usb_dev.data_buf_residue; uint32_t chunk = usb_dev.data_buf_residue;
/*Always EP0 for control*/ /*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_residue, &chunk);
usb_dev.data_buf += chunk; usb_dev.data_buf += chunk;
usb_dev.data_buf_residue -= chunk; usb_dev.data_buf_residue -= chunk;
@ -269,7 +266,7 @@ static void usb_data_to_host(void)
} else { } else {
usb_dev.zlp_flag = false; 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); 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, * OUT transfer, Setup packet,
* reset request message state machine * 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, if (usb_dc_ep_read(ep, (uint8_t *)&setup_raw,
sizeof(setup_raw), NULL) < 0) { sizeof(setup_raw), NULL) < 0) {
LOG_DBG("Read Setup Packet failed"); 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; return;
} }
@ -310,11 +307,10 @@ static void usb_handle_control_transfer(uint8_t ep,
setup->wLength = sys_le16_to_cpu(setup_raw.wLength); setup->wLength = sys_le16_to_cpu(setup_raw.wLength);
if (setup->wLength > CONFIG_USB_REQUEST_BUFFER_SIZE) { if (setup->wLength > CONFIG_USB_REQUEST_BUFFER_SIZE) {
if (REQTYPE_GET_DIR(setup->bmRequestType) if (usb_reqtype_is_to_device(setup)) {
!= REQTYPE_DIR_TO_HOST) {
LOG_ERR("Request buffer too small"); LOG_ERR("Request buffer too small");
usb_dc_ep_set_stall(USB_CONTROL_IN_EP0); usb_dc_ep_set_stall(USB_CONTROL_EP_IN);
usb_dc_ep_set_stall(USB_CONTROL_OUT_EP0); usb_dc_ep_set_stall(USB_CONTROL_EP_OUT);
return; return;
} }
} }
@ -324,9 +320,7 @@ static void usb_handle_control_transfer(uint8_t ep,
usb_dev.data_buf_len = setup->wLength; usb_dev.data_buf_len = setup->wLength;
usb_dev.zlp_flag = false; usb_dev.zlp_flag = false;
if (setup->wLength && if (setup->wLength && usb_reqtype_is_to_device(setup)) {
REQTYPE_GET_DIR(setup->bmRequestType)
== REQTYPE_DIR_TO_DEVICE) {
return; return;
} }
@ -335,7 +329,7 @@ static void usb_handle_control_transfer(uint8_t ep,
&usb_dev.data_buf_len, &usb_dev.data_buf_len,
&usb_dev.data_buf)) { &usb_dev.data_buf)) {
LOG_DBG("usb_handle_request failed"); 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; return;
} }
@ -344,24 +338,24 @@ static void usb_handle_control_transfer(uint8_t ep,
setup->wLength); setup->wLength);
/* Send first part (possibly a zero-length status message) */ /* Send first part (possibly a zero-length status message) */
usb_data_to_host(); usb_data_to_host();
} else if (ep == USB_CONTROL_OUT_EP0) { } else if (ep == USB_CONTROL_EP_OUT) {
/* OUT transfer, data or status packets */ /* OUT transfer, data or status packets */
if (usb_dev.data_buf_residue <= 0) { if (usb_dev.data_buf_residue <= 0) {
/* absorb zero-length status message */ /* 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) { usb_dev.data_buf, 0, &chunk) < 0) {
LOG_DBG("Read DATA Packet failed"); 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; 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,
usb_dev.data_buf_residue, &chunk) < 0) { usb_dev.data_buf_residue, &chunk) < 0) {
LOG_DBG("Read DATA Packet failed"); LOG_DBG("Read DATA Packet failed");
usb_dc_ep_set_stall(USB_CONTROL_IN_EP0); usb_dc_ep_set_stall(USB_CONTROL_EP_IN);
usb_dc_ep_set_stall(USB_CONTROL_OUT_EP0); usb_dc_ep_set_stall(USB_CONTROL_EP_OUT);
return; return;
} }
@ -374,7 +368,7 @@ static void usb_handle_control_transfer(uint8_t ep,
&usb_dev.data_buf_len, &usb_dev.data_buf_len,
&usb_dev.data_buf)) { &usb_dev.data_buf)) {
LOG_DBG("usb_handle_request1 failed"); 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; return;
} }
@ -382,7 +376,7 @@ static void usb_handle_control_transfer(uint8_t ep,
LOG_DBG(">> usb_data_to_host(2)"); LOG_DBG(">> usb_data_to_host(2)");
usb_data_to_host(); usb_data_to_host();
} }
} else if (ep == USB_CONTROL_IN_EP0) { } else if (ep == USB_CONTROL_EP_IN) {
/* Send more data if available */ /* Send more data if available */
if (usb_dev.data_buf_residue != 0 || usb_dev.zlp_flag == true) { if (usb_dev.data_buf_residue != 0 || usb_dev.zlp_flag == true) {
usb_data_to_host(); usb_data_to_host();
@ -395,7 +389,7 @@ static void usb_handle_control_transfer(uint8_t ep,
/* /*
* @brief register a callback for handling requests * @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 * @param [in] handler Callback function pointer
* *
* @return N/A * @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*/ /*Avoid compiler warning until this is used for something*/
ARG_UNUSED(lang_id); ARG_UNUSED(lang_id);
type = GET_DESC_TYPE(type_index); type = USB_GET_DESCRIPTOR_TYPE(type_index);
index = GET_DESC_INDEX(type_index); index = USB_GET_DESCRIPTOR_INDEX(type_index);
/* /*
* Invalid types of descriptors, * Invalid types of descriptors,
* see USB Spec. Revision 2.0, 9.4.3 Get Descriptor * see USB Spec. Revision 2.0, 9.4.3 Get Descriptor
*/ */
if ((type == USB_INTERFACE_DESC) || (type == USB_ENDPOINT_DESC) || if ((type == USB_DESC_INTERFACE) || (type == USB_DESC_ENDPOINT) ||
(type > USB_OTHER_SPEED)) { (type > USB_DESC_OTHER_SPEED)) {
return false; return false;
} }
@ -475,7 +469,7 @@ static bool usb_get_descriptor(uint16_t type_index, uint16_t lang_id,
/* set data pointer */ /* set data pointer */
*data = p; *data = p;
/* get length from structure */ /* get length from structure */
if (type == USB_CONFIGURATION_DESC) { if (type == USB_DESC_CONFIGURATION) {
/* configuration descriptor is an /* configuration descriptor is an
* exception, length is at offset * exception, length is at offset
* 2 and 3 * 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 */ /* configure endpoints for this configuration/altsetting */
while (p[DESC_bLength] != 0U) { while (p[DESC_bLength] != 0U) {
switch (p[DESC_bDescriptorType]) { switch (p[DESC_bDescriptorType]) {
case USB_CONFIGURATION_DESC: case USB_DESC_CONFIGURATION:
/* remember current configuration index */ /* remember current configuration index */
cur_config = p[CONF_DESC_bConfigurationValue]; cur_config = p[CONF_DESC_bConfigurationValue];
if (cur_config == config_index) { if (cur_config == config_index) {
@ -630,13 +624,13 @@ static bool usb_set_configuration(uint8_t config_index, uint8_t alt_setting)
break; break;
case USB_INTERFACE_DESC: case USB_DESC_INTERFACE:
/* remember current alternate setting */ /* remember current alternate setting */
cur_alt_setting = cur_alt_setting =
p[INTF_DESC_bAlternateSetting]; p[INTF_DESC_bAlternateSetting];
break; break;
case USB_ENDPOINT_DESC: case USB_DESC_ENDPOINT:
if ((cur_config != config_index) || if ((cur_config != config_index) ||
(cur_alt_setting != alt_setting)) { (cur_alt_setting != alt_setting)) {
break; break;
@ -681,7 +675,7 @@ static bool usb_set_interface(uint8_t iface, uint8_t alt_setting)
while (p[DESC_bLength] != 0U) { while (p[DESC_bLength] != 0U) {
switch (p[DESC_bDescriptorType]) { switch (p[DESC_bDescriptorType]) {
case USB_INTERFACE_DESC: case USB_DESC_INTERFACE:
/* remember current alternate setting */ /* remember current alternate setting */
cur_alt_setting = p[INTF_DESC_bAlternateSetting]; cur_alt_setting = p[INTF_DESC_bAlternateSetting];
cur_iface = p[INTF_DESC_bInterfaceNumber]; 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", LOG_DBG("Current iface %u alt setting %u",
cur_iface, cur_alt_setting); cur_iface, cur_alt_setting);
break; break;
case USB_ENDPOINT_DESC: case USB_DESC_ENDPOINT:
if (cur_iface == iface) { if (cur_iface == iface) {
ep = (struct usb_ep_descriptor *)p; ep = (struct usb_ep_descriptor *)p;
ret = usb_eps_reconfigure(ep, cur_alt_setting, 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; uint8_t cur_iface;
while (p[DESC_bLength] != 0U) { 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]; cur_iface = p[INTF_DESC_bInterfaceNumber];
if (cur_iface == setup->wIndex) { if (cur_iface == setup->wIndex) {
data[0] = usb_get_alt_setting(cur_iface); 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; uint8_t *data = *data_buf;
switch (setup->bRequest) { switch (setup->bRequest) {
case REQ_GET_STATUS: case USB_SREQ_GET_STATUS:
LOG_DBG("REQ_GET_STATUS"); LOG_DBG("USB_SREQ_GET_STATUS");
/* bit 0: self-powered */ /* bit 0: self-powered */
/* bit 1: remote wakeup */ /* bit 1: remote wakeup */
data[0] = 0U; data[0] = 0U;
data[1] = 0U; data[1] = 0U;
if (IS_ENABLED(CONFIG_USB_SELF_POWERED)) { 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)) { if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) {
data[0] |= (usb_dev.remote_wakeup ? data[0] |= (usb_dev.remote_wakeup ?
DEVICE_STATUS_REMOTE_WAKEUP : 0); USB_GET_STATUS_REMOTE_WAKEUP : 0);
} }
*len = 2; *len = 2;
break; break;
case REQ_SET_ADDRESS: case USB_SREQ_SET_ADDRESS:
LOG_DBG("REQ_SET_ADDRESS, addr 0x%x", value); LOG_DBG("USB_SREQ_SET_ADDRESS, addr 0x%x", value);
usb_dc_set_address(value); usb_dc_set_address(value);
break; break;
case REQ_GET_DESCRIPTOR: case USB_SREQ_GET_DESCRIPTOR:
LOG_DBG("REQ_GET_DESCRIPTOR"); LOG_DBG("USB_SREQ_GET_DESCRIPTOR");
ret = usb_get_descriptor(value, index, len, data_buf); ret = usb_get_descriptor(value, index, len, data_buf);
break; break;
case REQ_GET_CONFIGURATION: case USB_SREQ_GET_CONFIGURATION:
LOG_DBG("REQ_GET_CONFIGURATION"); LOG_DBG("USB_SREQ_GET_CONFIGURATION");
/* indicate if we are configured */ /* indicate if we are configured */
data[0] = usb_dev.configuration; data[0] = usb_dev.configuration;
*len = 1; *len = 1;
break; break;
case REQ_SET_CONFIGURATION: case USB_SREQ_SET_CONFIGURATION:
value &= 0xFF; 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)) { if (!usb_set_configuration(value, 0)) {
LOG_DBG("USB Set Configuration failed"); LOG_DBG("USB Set Configuration failed");
ret = false; ret = false;
@ -822,34 +816,34 @@ static bool usb_handle_std_device_req(struct usb_setup_packet *setup,
} }
break; break;
case REQ_CLEAR_FEATURE: case USB_SREQ_CLEAR_FEATURE:
LOG_DBG("REQ_CLEAR_FEATURE"); LOG_DBG("USB_SREQ_CLEAR_FEATURE");
ret = false; ret = false;
if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) { if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) {
if (value == FEA_REMOTE_WAKEUP) { if (value == USB_SFS_REMOTE_WAKEUP) {
usb_dev.remote_wakeup = false; usb_dev.remote_wakeup = false;
ret = true; ret = true;
} }
} }
break; break;
case REQ_SET_FEATURE: case USB_SREQ_SET_FEATURE:
LOG_DBG("REQ_SET_FEATURE"); LOG_DBG("USB_SREQ_SET_FEATURE");
ret = false; ret = false;
if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) { if (IS_ENABLED(CONFIG_USB_DEVICE_REMOTE_WAKEUP)) {
if (value == FEA_REMOTE_WAKEUP) { if (value == USB_SFS_REMOTE_WAKEUP) {
usb_dev.remote_wakeup = true; usb_dev.remote_wakeup = true;
ret = true; ret = true;
} }
} }
if (value == FEA_TEST_MODE) { if (value == USB_SFS_TEST_MODE) {
/* put TEST_MODE code here */ /* put USB_SFS_TEST_MODE code here */
} }
break; break;
case REQ_SET_DESCRIPTOR: case USB_SREQ_SET_DESCRIPTOR:
LOG_DBG("Device req 0x%02x not implemented", setup->bRequest); LOG_DBG("Device req 0x%02x not implemented", setup->bRequest);
ret = false; ret = false;
break; break;
@ -880,7 +874,7 @@ static bool is_interface_valid(uint8_t interface)
/* Search through descriptor for matching interface */ /* Search through descriptor for matching interface */
while (p[DESC_bLength] != 0U) { 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; cfg_descr = (const struct usb_cfg_descriptor *)p;
if (interface < cfg_descr->bNumInterfaces) { if (interface < cfg_descr->bNumInterfaces) {
return true; return true;
@ -915,23 +909,23 @@ static bool usb_handle_std_interface_req(struct usb_setup_packet *setup,
} }
switch (setup->bRequest) { switch (setup->bRequest) {
case REQ_GET_STATUS: case USB_SREQ_GET_STATUS:
/* no bits specified */ /* no bits specified */
data[0] = 0U; data[0] = 0U;
data[1] = 0U; data[1] = 0U;
*len = 2; *len = 2;
break; break;
case REQ_CLEAR_FEATURE: case USB_SREQ_CLEAR_FEATURE:
case REQ_SET_FEATURE: case USB_SREQ_SET_FEATURE:
/* not defined for interface */ /* not defined for interface */
return false; return false;
case REQ_GET_INTERFACE: case USB_SREQ_GET_INTERFACE:
return usb_get_interface(setup, len, data_buf); return usb_get_interface(setup, len, data_buf);
case REQ_SET_INTERFACE: case USB_SREQ_SET_INTERFACE:
LOG_DBG("REQ_SET_INTERFACE"); LOG_DBG("USB_SREQ_SET_INTERFACE");
usb_set_interface(setup->wIndex, setup->wValue); usb_set_interface(setup->wIndex, setup->wValue);
*len = 0; *len = 0;
break; break;
@ -1001,7 +995,7 @@ static bool usb_handle_std_endpoint_req(struct usb_setup_packet *setup,
} }
switch (setup->bRequest) { switch (setup->bRequest) {
case REQ_GET_STATUS: case USB_SREQ_GET_STATUS:
/** This request is valid for Control Endpoints when /** This request is valid for Control Endpoints when
* the device is not yet configured. For other * the device is not yet configured. For other
* Endpoints the device must be configured. * Endpoints the device must be configured.
@ -1018,8 +1012,8 @@ static bool usb_handle_std_endpoint_req(struct usb_setup_packet *setup,
} }
return false; return false;
case REQ_CLEAR_FEATURE: case USB_SREQ_CLEAR_FEATURE:
if (setup->wValue == FEA_ENDPOINT_HALT) { if (setup->wValue == USB_SFS_ENDPOINT_HALT) {
/** This request is valid for Control Endpoints when /** This request is valid for Control Endpoints when
* the device is not yet configured. For other * the device is not yet configured. For other
* Endpoints the device must be configured. * Endpoints the device must be configured.
@ -1037,11 +1031,11 @@ static bool usb_handle_std_endpoint_req(struct usb_setup_packet *setup,
break; break;
} }
} }
/* only ENDPOINT_HALT defined for endpoints */ /* only USB_SFS_ENDPOINT_HALT defined for endpoints */
return false; return false;
case REQ_SET_FEATURE: case USB_SREQ_SET_FEATURE:
if (setup->wValue == FEA_ENDPOINT_HALT) { if (setup->wValue == USB_SFS_ENDPOINT_HALT) {
/** This request is valid for Control Endpoints when /** This request is valid for Control Endpoints when
* the device is not yet configured. For other * the device is not yet configured. For other
* Endpoints the device must be configured. * Endpoints the device must be configured.
@ -1060,10 +1054,10 @@ static bool usb_handle_std_endpoint_req(struct usb_setup_packet *setup,
break; break;
} }
} }
/* only ENDPOINT_HALT defined for endpoints */ /* only USB_SFS_ENDPOINT_HALT defined for endpoints */
return false; return false;
case REQ_SYNCH_FRAME: case USB_SREQ_SYNCH_FRAME:
/* For Synch Frame request the device must be configured */ /* For Synch Frame request the device must be configured */
if (is_device_configured()) { if (is_device_configured()) {
/* Not supported, return false anyway */ /* Not supported, return false anyway */
@ -1108,18 +1102,18 @@ static int usb_handle_standard_request(struct usb_setup_packet *setup,
return 0; return 0;
} }
switch (REQTYPE_GET_RECIP(setup->bmRequestType)) { switch (setup->RequestType.recipient) {
case REQTYPE_RECIP_DEVICE: case USB_REQTYPE_RECIPIENT_DEVICE:
if (usb_handle_std_device_req(setup, len, data_buf) == false) { if (usb_handle_std_device_req(setup, len, data_buf) == false) {
rc = -EINVAL; rc = -EINVAL;
} }
break; break;
case REQTYPE_RECIP_INTERFACE: case USB_REQTYPE_RECIPIENT_INTERFACE:
if (usb_handle_std_interface_req(setup, len, data_buf) == false) { if (usb_handle_std_interface_req(setup, len, data_buf) == false) {
rc = -EINVAL; rc = -EINVAL;
} }
break; break;
case REQTYPE_RECIP_ENDPOINT: case USB_REQTYPE_RECIPIENT_ENDPOINT:
if (usb_handle_std_endpoint_req(setup, len, data_buf) == false) { if (usb_handle_std_endpoint_req(setup, len, data_buf) == false) {
rc = -EINVAL; rc = -EINVAL;
} }
@ -1280,10 +1274,10 @@ int usb_deconfig(void)
usb_register_descriptors(NULL); usb_register_descriptors(NULL);
/* unegister standard request handler */ /* 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*/ /* 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*/ /* unregister class request handlers for each interface*/
usb_register_custom_req_handler(NULL); 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 * The class does not actively engage in request
* handling and therefore we can ignore return value. * 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); (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); usb_register_descriptors(device_descriptor);
/* register standard request handler */ /* register standard request handler */
usb_register_request_handler(REQTYPE_TYPE_STANDARD, usb_register_request_handler(USB_REQTYPE_TYPE_STANDARD,
usb_handle_standard_request); usb_handle_standard_request);
/* register class request handlers for each interface*/ /* 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 */ /* 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*/ /* register class request handlers for each interface*/
usb_register_custom_req_handler(custom_handler); 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_mps = USB_MAX_CTRL_MPS;
ep0_cfg.ep_type = USB_DC_EP_CONTROL; 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); ret = usb_dc_ep_configure(&ep0_cfg);
if (ret < 0) { if (ret < 0) {
goto out; 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); ret = usb_dc_ep_configure(&ep0_cfg);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }
/* Register endpoint 0 handlers*/ /* 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); usb_handle_control_transfer);
if (ret < 0) { if (ret < 0) {
goto out; 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); usb_handle_control_transfer);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
@ -1601,12 +1595,12 @@ int usb_enable(usb_dc_status_callback status_cb)
} }
/* Enable control EP */ /* Enable control EP */
ret = usb_dc_ep_enable(USB_CONTROL_OUT_EP0); ret = usb_dc_ep_enable(USB_CONTROL_EP_OUT);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }
ret = usb_dc_ep_enable(USB_CONTROL_IN_EP0); ret = usb_dc_ep_enable(USB_CONTROL_EP_IN);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }