diff options
| author | hathach <[email protected]> | 2013-05-31 18:21:31 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-05-31 18:21:31 +0700 |
| commit | 03d85acfc7cb18a5469146f98c210a5747218cb3 (patch) | |
| tree | cf1f4ffac5cf99befadb1ee34f4ada66c78a1504 | |
| parent | abf105474529a9831851ea78bcc06d1e5ad4e173 (diff) | |
refractor string descriptors, allow one-stop configure descriptor for
- manufacturer, product etc ... (only english now)
| -rw-r--r-- | demos/device/keyboard/tusb_config.h | 7 | ||||
| -rw-r--r-- | demos/device/keyboard/tusb_descriptors.c | 15 | ||||
| -rw-r--r-- | demos/device/keyboard/tusb_descriptors.h | 16 | ||||
| -rw-r--r-- | tests/project.yml | 1 | ||||
| -rw-r--r-- | tests/test/device/usbd/test_usbd.c | 36 | ||||
| -rw-r--r-- | tests/test/support/tusb_config.h | 13 | ||||
| -rw-r--r-- | tinyusb/common/errors.h | 1 | ||||
| -rw-r--r-- | tinyusb/device/usbd.c | 25 |
8 files changed, 93 insertions, 21 deletions
diff --git a/demos/device/keyboard/tusb_config.h b/demos/device/keyboard/tusb_config.h index 0d1e861e5..3169c83db 100644 --- a/demos/device/keyboard/tusb_config.h +++ b/demos/device/keyboard/tusb_config.h @@ -81,6 +81,13 @@ //--------------------------------------------------------------------+ // DEVICE CONFIGURATION //--------------------------------------------------------------------+ +#define TUSB_CFG_DEVICE_STRING_MANUFACTURER "tinyusb.org" +#define TUSB_CFG_DEVICE_STRING_PRODUCT "Device Example" +#define TUSB_CFG_DEVICE_STRING_SERIAL "1234" +#define TUSB_CFG_DEVICE_VENDORID 0x1FC9 // NXP +//#define TUSB_CFG_DEVICE_PRODUCTID 0x4567 + + #define TUSB_CFG_DEVICE_USE_ROM_DRIVER 1 //------------- CLASS -------------// diff --git a/demos/device/keyboard/tusb_descriptors.c b/demos/device/keyboard/tusb_descriptors.c index 527a56730..c3e9c5fd1 100644 --- a/demos/device/keyboard/tusb_descriptors.c +++ b/demos/device/keyboard/tusb_descriptors.c @@ -39,7 +39,7 @@ #if TUSB_CFG_DEVICE_HID_KEYBOARD TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) -const uint8_t app_tusb_keyboard_desc_report[] = { +uint8_t app_tusb_keyboard_desc_report[] = { HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ), HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ), HID_COLLECTION ( HID_COLLECTION_APPLICATION ), @@ -83,7 +83,7 @@ const uint8_t app_tusb_keyboard_desc_report[] = { #if TUSB_CFG_DEVICE_HID_MOUSE TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) -const uint8_t mouse_report_descriptor[] = { +uint8_t mouse_report_descriptor[] = { HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ), HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ), HID_COLLECTION ( HID_COLLECTION_APPLICATION ), @@ -120,7 +120,7 @@ const uint8_t mouse_report_descriptor[] = { #endif TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) -tusb_descriptor_device_t const app_tusb_desc_device = +tusb_descriptor_device_t app_tusb_desc_device = { .bLength = sizeof(tusb_descriptor_device_t), .bDescriptorType = TUSB_DESC_TYPE_DEVICE, @@ -144,7 +144,7 @@ tusb_descriptor_device_t const app_tusb_desc_device = TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) -const app_descriptor_configuration_t app_tusb_desc_configuration = +app_descriptor_configuration_t app_tusb_desc_configuration = { .configuration = { @@ -379,7 +379,7 @@ const app_descriptor_configuration_t app_tusb_desc_configuration = }; TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) -const app_descriptor_string_t app_tusb_desc_strings = +app_descriptor_string_t app_tusb_desc_strings = { //------------- index 0 -------------// .language = { @@ -392,20 +392,17 @@ const app_descriptor_string_t app_tusb_desc_strings = .manufacturer = { .bLength = USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER)-1), .bDescriptorType = TUSB_DESC_TYPE_STRING, - .unicode_string = {'t', 'i', 'n', 'y', 'U', 'S', 'B'} }, //------------- index 2 -------------// .product = { .bLength = USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_PRODUCT)-1), .bDescriptorType = TUSB_DESC_TYPE_STRING, - .unicode_string = {'D', 'e', 'v', 'i', 'c', 'e', ' ', 'K', 'e', 'y', 'b', 'o', 'a', 'r', 'd'} }, //------------- index 3 -------------// - .serials = { + .serial = { .bLength = USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_SERIAL)-1), .bDescriptorType = TUSB_DESC_TYPE_STRING, - .unicode_string = {'1', '2', '3', '4'} } }; diff --git a/demos/device/keyboard/tusb_descriptors.h b/demos/device/keyboard/tusb_descriptors.h index 8a9edad84..3116e84d8 100644 --- a/demos/device/keyboard/tusb_descriptors.h +++ b/demos/device/keyboard/tusb_descriptors.h @@ -35,11 +35,7 @@ #include "tusb.h" -#define TUSB_CFG_DEVICE_STRING_MANUFACTURER "tinyUSB" -#define TUSB_CFG_DEVICE_STRING_PRODUCT "Device Keyboard" -#define TUSB_CFG_DEVICE_STRING_SERIAL "1234" -#define TUSB_CFG_DEVICE_VENDORID 0x1FC9 // NXP -//#define TUSB_CFG_DEVICE_PRODUCTID + /* USB Serial uses the MCUs unique 128-bit chip ID via an IAP call = 32 hex chars */ #define USB_STRING_SERIAL_LEN 32 @@ -81,7 +77,7 @@ typedef ATTR_PACKED_STRUCT(struct) uint8_t const bLength; uint8_t const bDescriptorType; uint16_t unicode_string[sizeof(TUSB_CFG_DEVICE_STRING_SERIAL)-1]; // exclude null-character - } serials; + } serial; //------------- more string index -------------// @@ -180,11 +176,11 @@ typedef ATTR_PACKED_STRUCT(struct) uint8_t null_termination; // NXP rom driver requires this to work } app_descriptor_configuration_t; -extern const tusb_descriptor_device_t app_tusb_desc_device; -extern const app_descriptor_configuration_t app_tusb_desc_configuration; -extern const app_descriptor_string_t app_tusb_desc_strings; +extern tusb_descriptor_device_t app_tusb_desc_device; +extern app_descriptor_configuration_t app_tusb_desc_configuration; +extern app_descriptor_string_t app_tusb_desc_strings; -extern const uint8_t app_tusb_keyboard_desc_report[]; +extern uint8_t app_tusb_keyboard_desc_report[]; //extern const uint8_t HID_MouseReportDescriptor[]; diff --git a/tests/project.yml b/tests/project.yml index 8aed8b07a..135280b98 100644 --- a/tests/project.yml +++ b/tests/project.yml @@ -30,6 +30,7 @@ :source: - ../tinyusb/** - +:../demos/bsp/lpc43xx/** + - +:../demos/device/keyboard/* - -:../demos/ - ../vendor/freertos/freertos/Source/* - ../vendor/freertos/freertos/Source/portable/MSVC-MingW/* diff --git a/tests/test/device/usbd/test_usbd.c b/tests/test/device/usbd/test_usbd.c index 8054cab4d..05c338199 100644 --- a/tests/test/device/usbd/test_usbd.c +++ b/tests/test/device/usbd/test_usbd.c @@ -41,6 +41,8 @@ #include "errors.h" #include "type_helper.h" +#include "tusb_descriptors.h" + #include "mock_dcd.h" #include "usbd.h" @@ -71,3 +73,37 @@ void test_usbd_init_ok(void) TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, usbd_init() ); } + +void test_usbd_string_descriptor(void) +{ + dcd_init_IgnoreAndReturn(TUSB_ERROR_FAILED); + + //------------- Code Under Test -------------// + TEST_ASSERT_EQUAL( TUSB_ERROR_FAILED, usbd_init() ); + + + //------------- manufacturer string descriptor -------------// + uint32_t const manufacturer_len = sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER) - 1; + TEST_ASSERT_EQUAL(manufacturer_len*2 + 2, app_tusb_desc_strings.manufacturer.bLength); + for(uint32_t i=0; i<manufacturer_len; i++) + { + TEST_ASSERT_EQUAL(TUSB_CFG_DEVICE_STRING_MANUFACTURER[i], app_tusb_desc_strings.manufacturer.unicode_string[i]); + } + + //------------- product string descriptor -------------// + uint32_t const product_len = sizeof(TUSB_CFG_DEVICE_STRING_PRODUCT) - 1; + TEST_ASSERT_EQUAL(product_len*2 + 2, app_tusb_desc_strings.product.bLength); + for(uint32_t i=0; i < product_len; i++) + { + TEST_ASSERT_EQUAL(TUSB_CFG_DEVICE_STRING_PRODUCT[i], app_tusb_desc_strings.product.unicode_string[i]); + } + + //------------- serial string descriptor -------------// + uint32_t const serial_len = sizeof(TUSB_CFG_DEVICE_STRING_SERIAL) - 1; + TEST_ASSERT_EQUAL(serial_len*2 + 2, app_tusb_desc_strings.serial.bLength); + for(uint32_t i=0; i<serial_len; i++) + { + TEST_ASSERT_EQUAL(TUSB_CFG_DEVICE_STRING_SERIAL[i], app_tusb_desc_strings.serial.unicode_string[i]); + } +} + diff --git a/tests/test/support/tusb_config.h b/tests/test/support/tusb_config.h index ad882c65c..7498c717e 100644 --- a/tests/test/support/tusb_config.h +++ b/tests/test/support/tusb_config.h @@ -86,12 +86,21 @@ //--------------------------------------------------------------------+ // DEVICE CONFIGURATION //--------------------------------------------------------------------+ +#define TUSB_CFG_DEVICE_STRING_MANUFACTURER "tinyusb.org" +#define TUSB_CFG_DEVICE_STRING_PRODUCT "Device Example" +#define TUSB_CFG_DEVICE_STRING_SERIAL "1234" +#define TUSB_CFG_DEVICE_VENDORID 0x1FC9 // NXP +//#define TUSB_CFG_DEVICE_PRODUCTID 0x4567 + + #define TUSB_CFG_DEVICE_USE_ROM_DRIVER 1 //------------- CLASS -------------// +#define TUSB_CFG_DEVICE_HID_KEYBOARD 1 +#define TUSB_CFG_DEVICE_HID_MOUSE 0 +#define TUSB_CFG_DEVICE_HID_GENERIC 0 +#define TUSB_CFG_DEVICE_MSC 0 //#define TUSB_CFG_DEVICE_CDC -#define TUSB_CFG_DEVICE_HID_KEYBOARD -//#define TUSB_CFG_DEVICE_HID_MOUSE //--------------------------------------------------------------------+ // COMMON CONFIGURATION diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h index 061f08ab3..02d9d6824 100644 --- a/tinyusb/common/errors.h +++ b/tinyusb/common/errors.h @@ -73,6 +73,7 @@ ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED )\ ENTRY(TUSB_ERROR_OSAL_SEMAPHORE_FAILED )\ ENTRY(TUSB_ERROR_EHCI_NOT_ENOUGH_QTD )\ + ENTRY(TUSB_ERROR_USBD_DESCRIPTOR_STRING )\ ENTRY(TUSB_ERROR_FAILED )\ diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c index efcf29ced..bed745985 100644 --- a/tinyusb/device/usbd.c +++ b/tinyusb/device/usbd.c @@ -46,6 +46,7 @@ // INCLUDE //--------------------------------------------------------------------+ #include "tusb.h" +#include "tusb_descriptors.h" // TODO callback include //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF @@ -66,6 +67,30 @@ //--------------------------------------------------------------------+ tusb_error_t usbd_init (void) { + ASSERT_INT( USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER)-1), + app_tusb_desc_strings.manufacturer.bLength, TUSB_ERROR_USBD_DESCRIPTOR_STRING); + + ASSERT_INT( USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_PRODUCT)-1) , + app_tusb_desc_strings.product.bLength , TUSB_ERROR_USBD_DESCRIPTOR_STRING); + + ASSERT_INT( USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_SERIAL)-1) , + app_tusb_desc_strings.serial.bLength , TUSB_ERROR_USBD_DESCRIPTOR_STRING); + + for(uint32_t i=0; i < sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER)-1; i++) + { + app_tusb_desc_strings.manufacturer.unicode_string[i] = TUSB_CFG_DEVICE_STRING_MANUFACTURER[i]; + } + + for(uint32_t i=0; i < sizeof(TUSB_CFG_DEVICE_STRING_PRODUCT)-1; i++) + { + app_tusb_desc_strings.product.unicode_string[i] = TUSB_CFG_DEVICE_STRING_PRODUCT[i]; + } + + for(uint32_t i=0; i < sizeof(TUSB_CFG_DEVICE_STRING_SERIAL)-1; i++) + { + app_tusb_desc_strings.serial.unicode_string[i] = TUSB_CFG_DEVICE_STRING_SERIAL[i]; + } + ASSERT_STATUS ( dcd_init() ); return TUSB_ERROR_NONE; |
