usb: Cleanup for multiplied defines

Some of defines are present in several header files.
Those defines are the same with value but with different naming.

Common defines are brought to usb_common.h

Signed-off-by: Emil Obalski <emil.obalski@nordicsemi.no>
This commit is contained in:
Emil Obalski 2019-11-28 14:36:53 +01:00 committed by Anas Nashif
commit c1f5e11bb6
8 changed files with 18 additions and 33 deletions

View file

@ -75,7 +75,7 @@ static void usbip_header_dump(struct usbip_header *hdr)
void get_interface(u8_t *descriptors)
{
while (descriptors[0]) {
if (descriptors[1] == DESC_INTERFACE) {
if (descriptors[1] == USB_INTERFACE_DESC) {
LOG_DBG("interface found");
}
@ -94,7 +94,7 @@ static int send_interfaces(const u8_t *descriptors, int connfd)
} __packed iface;
while (descriptors[0]) {
if (descriptors[1] == DESC_INTERFACE) {
if (descriptors[1] == USB_INTERFACE_DESC) {
struct usb_if_descriptor *desc = (void *)descriptors;
iface.bInterfaceClass = desc->bInterfaceClass;

View file

@ -39,13 +39,6 @@
*/
#define DATA_INTERFACE_CLASS 0x0A
/**
* @brief Values for the bDescriptorType Field
* @note CDC120-20101103-track.pdf, 5.2.3, Table 12
*/
#define CS_INTERFACE 0x24
#define CS_ENDPOINT 0x25
/**
* @brief bDescriptor SubType for Communications
* Class Functional Descriptors

View file

@ -65,10 +65,14 @@
#define USB_INTERFACE_DESC 0x04
#define USB_ENDPOINT_DESC 0x05
#define USB_DEVICE_QUAL_DESC 0x06
#define USB_OTHER_SPEED 0x07
#define USB_INTERFACE_POWER 0x08
#define USB_INTERFACE_ASSOC_DESC 0x0B
#define USB_DEVICE_CAPABILITY_DESC 0x10
#define USB_HID_DESC 0x21
#define USB_HID_REPORT_DESC 0x22
#define CS_INTERFACE 0x24
#define CS_ENDPOINT 0x25
#define USB_DFU_FUNCTIONAL_DESC 0x21
#define USB_ASSOCIATION_DESC 0x0B
#define USB_BINARY_OBJECT_STORE_DESC 0x0F

View file

@ -84,18 +84,6 @@ struct usb_desc_header {
u8_t bDescriptorType; /**< descriptor type */
};
#define DESC_DEVICE 1
#define DESC_CONFIGURATION 2
#define DESC_STRING 3
#define DESC_INTERFACE 4
#define DESC_ENDPOINT 5
#define DESC_DEVICE_QUALIFIER 6
#define DESC_OTHER_SPEED 7
#define DESC_INTERFACE_POWER 8
#define CS_INTERFACE 0x24
#define CS_ENDPOINT 0x25
#define GET_DESC_TYPE(x) (((x)>>8)&0xFF)
#define GET_DESC_INDEX(x) ((x)&0xFF)

View file

@ -202,7 +202,7 @@ static const u8_t msos1_compatid_descriptor[] = {
int custom_handle_req(struct usb_setup_packet *pSetup,
s32_t *len, u8_t **data)
{
if (GET_DESC_TYPE(pSetup->wValue) == DESC_STRING &&
if (GET_DESC_TYPE(pSetup->wValue) == USB_STRING_DESC &&
GET_DESC_INDEX(pSetup->wValue) == 0xEE) {
*data = (u8_t *)(&msos1_string_descriptor);
*len = sizeof(msos1_string_descriptor);

View file

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

View file

@ -440,8 +440,8 @@ static bool usb_get_descriptor(u16_t type_index, u16_t lang_id,
* Invalid types of descriptors,
* see USB Spec. Revision 2.0, 9.4.3 Get Descriptor
*/
if ((type == DESC_INTERFACE) || (type == DESC_ENDPOINT) ||
(type > DESC_OTHER_SPEED)) {
if ((type == USB_INTERFACE_DESC) || (type == USB_ENDPOINT_DESC) ||
(type > USB_OTHER_SPEED)) {
return false;
}
@ -464,7 +464,7 @@ static bool usb_get_descriptor(u16_t type_index, u16_t lang_id,
/* set data pointer */
*data = p;
/* get length from structure */
if (type == DESC_CONFIGURATION) {
if (type == USB_CONFIGURATION_DESC) {
/* configuration descriptor is an
* exception, length is at offset
* 2 and 3
@ -539,7 +539,7 @@ static bool usb_set_configuration(u8_t config_index, u8_t alt_setting)
/* configure endpoints for this configuration/altsetting */
while (p[DESC_bLength] != 0U) {
switch (p[DESC_bDescriptorType]) {
case DESC_CONFIGURATION:
case USB_CONFIGURATION_DESC:
/* remember current configuration index */
cur_config = p[CONF_DESC_bConfigurationValue];
if (cur_config == config_index) {
@ -548,13 +548,13 @@ static bool usb_set_configuration(u8_t config_index, u8_t alt_setting)
break;
case DESC_INTERFACE:
case USB_INTERFACE_DESC:
/* remember current alternate setting */
cur_alt_setting =
p[INTF_DESC_bAlternateSetting];
break;
case DESC_ENDPOINT:
case USB_ENDPOINT_DESC:
if ((cur_config != config_index) ||
(cur_alt_setting != alt_setting)) {
break;
@ -598,7 +598,7 @@ static bool usb_set_interface(u8_t iface, u8_t alt_setting)
while (p[DESC_bLength] != 0U) {
switch (p[DESC_bDescriptorType]) {
case DESC_INTERFACE:
case USB_INTERFACE_DESC:
/* remember current alternate setting */
cur_alt_setting = p[INTF_DESC_bAlternateSetting];
cur_iface = p[INTF_DESC_bInterfaceNumber];
@ -610,10 +610,9 @@ static bool usb_set_interface(u8_t iface, u8_t alt_setting)
LOG_DBG("iface_num %u alt_set %u", iface, alt_setting);
break;
case DESC_ENDPOINT:
case USB_ENDPOINT_DESC:
if ((cur_iface != iface) ||
(cur_alt_setting != alt_setting)) {
break;
}
found = set_endpoint((struct usb_ep_descriptor *)p);

View file

@ -95,7 +95,7 @@ static void test_handle_os_desc(void)
u8_t *data = NULL;
int ret;
setup.wValue = (DESC_STRING & 0xFF) << 8;
setup.wValue = (USB_STRING_DESC & 0xFF) << 8;
setup.wValue |= USB_OSDESC_STRING_DESC_INDEX;
ret = usb_handle_os_desc(&setup, &len, &data);