Skip to content

Commit c1f5e11

Browse files
Emil Obalskinashif
authored andcommitted
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 <[email protected]>
1 parent 44c947e commit c1f5e11

File tree

8 files changed

+18
-33
lines changed

8 files changed

+18
-33
lines changed

drivers/usb/device/usb_dc_native_posix_adapt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void usbip_header_dump(struct usbip_header *hdr)
7575
void get_interface(u8_t *descriptors)
7676
{
7777
while (descriptors[0]) {
78-
if (descriptors[1] == DESC_INTERFACE) {
78+
if (descriptors[1] == USB_INTERFACE_DESC) {
7979
LOG_DBG("interface found");
8080
}
8181

@@ -94,7 +94,7 @@ static int send_interfaces(const u8_t *descriptors, int connfd)
9494
} __packed iface;
9595

9696
while (descriptors[0]) {
97-
if (descriptors[1] == DESC_INTERFACE) {
97+
if (descriptors[1] == USB_INTERFACE_DESC) {
9898
struct usb_if_descriptor *desc = (void *)descriptors;
9999

100100
iface.bInterfaceClass = desc->bInterfaceClass;

include/usb/class/usb_cdc.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@
3939
*/
4040
#define DATA_INTERFACE_CLASS 0x0A
4141

42-
/**
43-
* @brief Values for the bDescriptorType Field
44-
* @note CDC120-20101103-track.pdf, 5.2.3, Table 12
45-
*/
46-
#define CS_INTERFACE 0x24
47-
#define CS_ENDPOINT 0x25
48-
4942
/**
5043
* @brief bDescriptor SubType for Communications
5144
* Class Functional Descriptors

include/usb/usb_common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@
6565
#define USB_INTERFACE_DESC 0x04
6666
#define USB_ENDPOINT_DESC 0x05
6767
#define USB_DEVICE_QUAL_DESC 0x06
68+
#define USB_OTHER_SPEED 0x07
69+
#define USB_INTERFACE_POWER 0x08
6870
#define USB_INTERFACE_ASSOC_DESC 0x0B
6971
#define USB_DEVICE_CAPABILITY_DESC 0x10
7072
#define USB_HID_DESC 0x21
7173
#define USB_HID_REPORT_DESC 0x22
74+
#define CS_INTERFACE 0x24
75+
#define CS_ENDPOINT 0x25
7276
#define USB_DFU_FUNCTIONAL_DESC 0x21
7377
#define USB_ASSOCIATION_DESC 0x0B
7478
#define USB_BINARY_OBJECT_STORE_DESC 0x0F

include/usb/usbstruct.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,6 @@ struct usb_desc_header {
8484
u8_t bDescriptorType; /**< descriptor type */
8585
};
8686

87-
#define DESC_DEVICE 1
88-
#define DESC_CONFIGURATION 2
89-
#define DESC_STRING 3
90-
#define DESC_INTERFACE 4
91-
#define DESC_ENDPOINT 5
92-
#define DESC_DEVICE_QUALIFIER 6
93-
#define DESC_OTHER_SPEED 7
94-
#define DESC_INTERFACE_POWER 8
95-
96-
#define CS_INTERFACE 0x24
97-
#define CS_ENDPOINT 0x25
98-
9987
#define GET_DESC_TYPE(x) (((x)>>8)&0xFF)
10088
#define GET_DESC_INDEX(x) ((x)&0xFF)
10189

samples/subsys/usb/webusb/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static const u8_t msos1_compatid_descriptor[] = {
202202
int custom_handle_req(struct usb_setup_packet *pSetup,
203203
s32_t *len, u8_t **data)
204204
{
205-
if (GET_DESC_TYPE(pSetup->wValue) == DESC_STRING &&
205+
if (GET_DESC_TYPE(pSetup->wValue) == USB_STRING_DESC &&
206206
GET_DESC_INDEX(pSetup->wValue) == 0xEE) {
207207
*data = (u8_t *)(&msos1_string_descriptor);
208208
*len = sizeof(msos1_string_descriptor);

subsys/usb/os_desc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LOG_MODULE_REGISTER(usb_os_desc);
1111
#include <zephyr.h>
1212

1313
#include <usb/usb_device.h>
14+
#include <usb/usb_common.h>
1415
#include <os_desc.h>
1516

1617
static struct usb_os_descriptor *os_desc;
@@ -22,7 +23,7 @@ int usb_handle_os_desc(struct usb_setup_packet *setup,
2223
return -ENOTSUP;
2324
}
2425

25-
if (GET_DESC_TYPE(setup->wValue) == DESC_STRING &&
26+
if (GET_DESC_TYPE(setup->wValue) == USB_STRING_DESC &&
2627
GET_DESC_INDEX(setup->wValue) == USB_OSDESC_STRING_DESC_INDEX) {
2728
LOG_DBG("MS OS Descriptor string read");
2829
*data = os_desc->string;

subsys/usb/usb_device.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,8 @@ static bool usb_get_descriptor(u16_t type_index, u16_t lang_id,
440440
* Invalid types of descriptors,
441441
* see USB Spec. Revision 2.0, 9.4.3 Get Descriptor
442442
*/
443-
if ((type == DESC_INTERFACE) || (type == DESC_ENDPOINT) ||
444-
(type > DESC_OTHER_SPEED)) {
443+
if ((type == USB_INTERFACE_DESC) || (type == USB_ENDPOINT_DESC) ||
444+
(type > USB_OTHER_SPEED)) {
445445
return false;
446446
}
447447

@@ -464,7 +464,7 @@ static bool usb_get_descriptor(u16_t type_index, u16_t lang_id,
464464
/* set data pointer */
465465
*data = p;
466466
/* get length from structure */
467-
if (type == DESC_CONFIGURATION) {
467+
if (type == USB_CONFIGURATION_DESC) {
468468
/* configuration descriptor is an
469469
* exception, length is at offset
470470
* 2 and 3
@@ -539,7 +539,7 @@ static bool usb_set_configuration(u8_t config_index, u8_t alt_setting)
539539
/* configure endpoints for this configuration/altsetting */
540540
while (p[DESC_bLength] != 0U) {
541541
switch (p[DESC_bDescriptorType]) {
542-
case DESC_CONFIGURATION:
542+
case USB_CONFIGURATION_DESC:
543543
/* remember current configuration index */
544544
cur_config = p[CONF_DESC_bConfigurationValue];
545545
if (cur_config == config_index) {
@@ -548,13 +548,13 @@ static bool usb_set_configuration(u8_t config_index, u8_t alt_setting)
548548

549549
break;
550550

551-
case DESC_INTERFACE:
551+
case USB_INTERFACE_DESC:
552552
/* remember current alternate setting */
553553
cur_alt_setting =
554554
p[INTF_DESC_bAlternateSetting];
555555
break;
556556

557-
case DESC_ENDPOINT:
557+
case USB_ENDPOINT_DESC:
558558
if ((cur_config != config_index) ||
559559
(cur_alt_setting != alt_setting)) {
560560
break;
@@ -598,7 +598,7 @@ static bool usb_set_interface(u8_t iface, u8_t alt_setting)
598598

599599
while (p[DESC_bLength] != 0U) {
600600
switch (p[DESC_bDescriptorType]) {
601-
case DESC_INTERFACE:
601+
case USB_INTERFACE_DESC:
602602
/* remember current alternate setting */
603603
cur_alt_setting = p[INTF_DESC_bAlternateSetting];
604604
cur_iface = p[INTF_DESC_bInterfaceNumber];
@@ -610,10 +610,9 @@ static bool usb_set_interface(u8_t iface, u8_t alt_setting)
610610

611611
LOG_DBG("iface_num %u alt_set %u", iface, alt_setting);
612612
break;
613-
case DESC_ENDPOINT:
613+
case USB_ENDPOINT_DESC:
614614
if ((cur_iface != iface) ||
615615
(cur_alt_setting != alt_setting)) {
616-
break;
617616
}
618617

619618
found = set_endpoint((struct usb_ep_descriptor *)p);

tests/subsys/usb/os_desc/src/usb_osdesc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void test_handle_os_desc(void)
9595
u8_t *data = NULL;
9696
int ret;
9797

98-
setup.wValue = (DESC_STRING & 0xFF) << 8;
98+
setup.wValue = (USB_STRING_DESC & 0xFF) << 8;
9999
setup.wValue |= USB_OSDESC_STRING_DESC_INDEX;
100100

101101
ret = usb_handle_os_desc(&setup, &len, &data);

0 commit comments

Comments
 (0)