From 5872753e2dbdca5b252470c5210cdf54ee1788dd Mon Sep 17 00:00:00 2001 From: laforge Date: Mon, 25 Sep 2006 21:23:52 +0000 Subject: - Include tool for Converting ASCII to UTF-16LE in C-Header - Build UTF-16LE USB String descriptors from ASCII File - Introduce USB String Descriptor to DFU and runtime firmware git-svn-id: https://svn.openpcd.org:2342/trunk@227 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- firmware/src/dfu/dfu.c | 51 +++++++++++++++++++++++++++++++------------------- firmware/src/dfu/dfu.h | 12 ++++++++++++ 2 files changed, 44 insertions(+), 19 deletions(-) (limited to 'firmware/src/dfu') diff --git a/firmware/src/dfu/dfu.c b/firmware/src/dfu/dfu.c index 56f7ef0..40ad64f 100644 --- a/firmware/src/dfu/dfu.c +++ b/firmware/src/dfu/dfu.c @@ -26,6 +26,8 @@ #include #include +#include + #include #include #include @@ -547,11 +549,11 @@ __dfustruct const struct usb_device_descriptor dfu_dev_descriptor = { .bDeviceSubClass = 0x00, .bDeviceProtocol = 0x00, .bMaxPacketSize0 = 8, - .idVendor = OPENPCD_VENDOR_ID, - .idProduct = OPENPCD_PRODUCT_ID, + .idVendor = USB_VENDOR_ID, + .idProduct = USB_PRODUCT_ID, .bcdDevice = 0x0000, - .iManufacturer = 0x00, - .iProduct = 0x00, + .iManufacturer = 1, + .iProduct = 2, .iSerialNumber = 0x00, .bNumConfigurations = 0x01, }; @@ -566,7 +568,7 @@ __dfustruct const struct _dfu_desc dfu_cfg_descriptor = { USB_DT_DFU_SIZE, .bNumInterfaces = 1, .bConfigurationValue = 1, - .iConfiguration = 0, + .iConfiguration = 3, .bmAttributes = USB_CONFIG_ATT_ONE, .bMaxPower = 100, }, @@ -579,7 +581,7 @@ __dfustruct const struct _dfu_desc dfu_cfg_descriptor = { .bInterfaceClass = 0xfe, .bInterfaceSubClass = 0x01, .bInterfaceProtocol = 0x02, - .iInterface = 0, + .iInterface = 4, }, .uif[1] = { .bLength = USB_DT_INTERFACE_SIZE, @@ -590,7 +592,7 @@ __dfustruct const struct _dfu_desc dfu_cfg_descriptor = { .bInterfaceClass = 0xfe, .bInterfaceSubClass = 0x01, .bInterfaceProtocol = 0x02, - .iInterface = 0, + .iInterface = 5, }, .func_dfu = DFU_FUNC_DESC, @@ -650,37 +652,48 @@ static __dfufunc void dfu_udp_ep0_handler(void) /* Handle supported standard device request Cf Table 9-3 in USB * speciication Rev 1.1 */ switch ((bRequest << 8) | bmRequestType) { + u_int8_t desc_type, desc_index; case STD_GET_DESCRIPTOR: DEBUGE("GET_DESCRIPTOR "); - if (wValue == 0x100) { + desc_type = wValue >> 8; + desc_index = wValue & 0xff; + switch (desc_type) { + case USB_DT_DEVICE: /* Return Device Descriptor */ udp_ep0_send_data((const char *) &dfu_dev_descriptor, MIN(sizeof(dfu_dev_descriptor), wLength)); - } else if (wValue == 0x200) { + break; + case USB_DT_CONFIG: /* Return Configuration Descriptor */ udp_ep0_send_data((const char *) &dfu_cfg_descriptor, MIN(sizeof(dfu_cfg_descriptor), wLength)); -#if 0 - } else if (wValue == 0x400) { - /* Return Interface descriptor */ - if (wIndex != 0x01) + break; + case USB_DT_STRING: + /* Return String Descriptor */ + if (desc_index > ARRAY_SIZE(usb_strings)) { udp_ep0_send_stall(); - udp_ep0_send_data((const char *) - &dfu_if_descriptor, - MIN(sizeof(dfu_if_descriptor), + break; + } + DEBUGP("bLength=%u, wLength=%u\n", + usb_strings[desc_index]->bLength, wLength); + udp_ep0_send_data((const char *) usb_strings[desc_index], + MIN(usb_strings[desc_index]->bLength, wLength)); -#endif - } else if (wValue == 0x2100) { + break; + case USB_DT_CS_DEVICE: /* Return Function descriptor */ udp_ep0_send_data((const char *) &dfu_cfg_descriptor.func_dfu, MIN(sizeof(dfu_cfg_descriptor.func_dfu), wLength)); - } else + break; + default: udp_ep0_send_stall(); + break; + } break; case STD_SET_ADDRESS: DEBUGE("SET_ADDRESS "); diff --git a/firmware/src/dfu/dfu.h b/firmware/src/dfu/dfu.h index 4d53ce7..084883b 100644 --- a/firmware/src/dfu/dfu.h +++ b/firmware/src/dfu/dfu.h @@ -39,6 +39,7 @@ /* USB Interface descriptor in Runtime mode */ #define DFU_RT_IF_DESC { \ + { \ .bLength = USB_DT_INTERFACE_SIZE, \ .bDescriptorType = USB_DT_INTERFACE, \ .bInterfaceNumber = 0x01, \ @@ -48,6 +49,17 @@ .bInterfaceSubClass = 0x01, \ .bInterfaceProtocol = 0x01, \ .iInterface = 1, \ + }, { \ + .bLength = USB_DT_INTERFACE_SIZE, \ + .bDescriptorType = USB_DT_INTERFACE, \ + .bInterfaceNumber = 0x02, \ + .bAlternateSetting = 0x00, \ + .bNumEndpoints = 0x00, \ + .bInterfaceClass = 0xfe, \ + .bInterfaceSubClass = 0x01, \ + .bInterfaceProtocol = 0x01, \ + .iInterface = 2, \ + }, \ } #define __dfufunctab __attribute__ ((section (".dfu.functab"))) -- cgit v1.2.3