refractor string descriptors, allow one-stop configure descriptor for
- manufacturer, product etc ... (only english now)
This commit is contained in:
parent
abf1054745
commit
03d85acfc7
|
@ -81,6 +81,13 @@
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// DEVICE CONFIGURATION
|
// 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
|
#define TUSB_CFG_DEVICE_USE_ROM_DRIVER 1
|
||||||
|
|
||||||
//------------- CLASS -------------//
|
//------------- CLASS -------------//
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
||||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
|
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_PAGE ( HID_USAGE_PAGE_DESKTOP ),
|
||||||
HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ),
|
HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ),
|
||||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
|
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
|
||||||
|
@ -83,7 +83,7 @@ const uint8_t app_tusb_keyboard_desc_report[] = {
|
||||||
|
|
||||||
#if TUSB_CFG_DEVICE_HID_MOUSE
|
#if TUSB_CFG_DEVICE_HID_MOUSE
|
||||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
|
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_PAGE ( HID_USAGE_PAGE_DESKTOP ),
|
||||||
HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ),
|
HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ),
|
||||||
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
|
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
|
||||||
|
@ -120,7 +120,7 @@ const uint8_t mouse_report_descriptor[] = {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
|
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),
|
.bLength = sizeof(tusb_descriptor_device_t),
|
||||||
.bDescriptorType = TUSB_DESC_TYPE_DEVICE,
|
.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)
|
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 =
|
.configuration =
|
||||||
{
|
{
|
||||||
|
@ -379,7 +379,7 @@ const app_descriptor_configuration_t app_tusb_desc_configuration =
|
||||||
};
|
};
|
||||||
|
|
||||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4)
|
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 -------------//
|
//------------- index 0 -------------//
|
||||||
.language = {
|
.language = {
|
||||||
|
@ -392,20 +392,17 @@ const app_descriptor_string_t app_tusb_desc_strings =
|
||||||
.manufacturer = {
|
.manufacturer = {
|
||||||
.bLength = USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER)-1),
|
.bLength = USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER)-1),
|
||||||
.bDescriptorType = TUSB_DESC_TYPE_STRING,
|
.bDescriptorType = TUSB_DESC_TYPE_STRING,
|
||||||
.unicode_string = {'t', 'i', 'n', 'y', 'U', 'S', 'B'}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//------------- index 2 -------------//
|
//------------- index 2 -------------//
|
||||||
.product = {
|
.product = {
|
||||||
.bLength = USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_PRODUCT)-1),
|
.bLength = USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_PRODUCT)-1),
|
||||||
.bDescriptorType = TUSB_DESC_TYPE_STRING,
|
.bDescriptorType = TUSB_DESC_TYPE_STRING,
|
||||||
.unicode_string = {'D', 'e', 'v', 'i', 'c', 'e', ' ', 'K', 'e', 'y', 'b', 'o', 'a', 'r', 'd'}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//------------- index 3 -------------//
|
//------------- index 3 -------------//
|
||||||
.serials = {
|
.serial = {
|
||||||
.bLength = USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_SERIAL)-1),
|
.bLength = USB_STRING_LEN(sizeof(TUSB_CFG_DEVICE_STRING_SERIAL)-1),
|
||||||
.bDescriptorType = TUSB_DESC_TYPE_STRING,
|
.bDescriptorType = TUSB_DESC_TYPE_STRING,
|
||||||
.unicode_string = {'1', '2', '3', '4'}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,11 +35,7 @@
|
||||||
|
|
||||||
#include "tusb.h"
|
#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 */
|
/* USB Serial uses the MCUs unique 128-bit chip ID via an IAP call = 32 hex chars */
|
||||||
#define USB_STRING_SERIAL_LEN 32
|
#define USB_STRING_SERIAL_LEN 32
|
||||||
|
@ -81,7 +77,7 @@ typedef ATTR_PACKED_STRUCT(struct)
|
||||||
uint8_t const bLength;
|
uint8_t const bLength;
|
||||||
uint8_t const bDescriptorType;
|
uint8_t const bDescriptorType;
|
||||||
uint16_t unicode_string[sizeof(TUSB_CFG_DEVICE_STRING_SERIAL)-1]; // exclude null-character
|
uint16_t unicode_string[sizeof(TUSB_CFG_DEVICE_STRING_SERIAL)-1]; // exclude null-character
|
||||||
} serials;
|
} serial;
|
||||||
|
|
||||||
//------------- more string index -------------//
|
//------------- more string index -------------//
|
||||||
|
|
||||||
|
@ -180,11 +176,11 @@ typedef ATTR_PACKED_STRUCT(struct)
|
||||||
uint8_t null_termination; // NXP rom driver requires this to work
|
uint8_t null_termination; // NXP rom driver requires this to work
|
||||||
} app_descriptor_configuration_t;
|
} app_descriptor_configuration_t;
|
||||||
|
|
||||||
extern const tusb_descriptor_device_t app_tusb_desc_device;
|
extern tusb_descriptor_device_t app_tusb_desc_device;
|
||||||
extern const app_descriptor_configuration_t app_tusb_desc_configuration;
|
extern app_descriptor_configuration_t app_tusb_desc_configuration;
|
||||||
extern const app_descriptor_string_t app_tusb_desc_strings;
|
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[];
|
//extern const uint8_t HID_MouseReportDescriptor[];
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
:source:
|
:source:
|
||||||
- ../tinyusb/**
|
- ../tinyusb/**
|
||||||
- +:../demos/bsp/lpc43xx/**
|
- +:../demos/bsp/lpc43xx/**
|
||||||
|
- +:../demos/device/keyboard/*
|
||||||
- -:../demos/
|
- -:../demos/
|
||||||
- ../vendor/freertos/freertos/Source/*
|
- ../vendor/freertos/freertos/Source/*
|
||||||
- ../vendor/freertos/freertos/Source/portable/MSVC-MingW/*
|
- ../vendor/freertos/freertos/Source/portable/MSVC-MingW/*
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
#include "type_helper.h"
|
#include "type_helper.h"
|
||||||
|
|
||||||
|
#include "tusb_descriptors.h"
|
||||||
|
|
||||||
#include "mock_dcd.h"
|
#include "mock_dcd.h"
|
||||||
#include "usbd.h"
|
#include "usbd.h"
|
||||||
|
|
||||||
|
@ -71,3 +73,37 @@ void test_usbd_init_ok(void)
|
||||||
TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, usbd_init() );
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,12 +86,21 @@
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// DEVICE CONFIGURATION
|
// 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
|
#define TUSB_CFG_DEVICE_USE_ROM_DRIVER 1
|
||||||
|
|
||||||
//------------- CLASS -------------//
|
//------------- 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_CDC
|
||||||
#define TUSB_CFG_DEVICE_HID_KEYBOARD
|
|
||||||
//#define TUSB_CFG_DEVICE_HID_MOUSE
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// COMMON CONFIGURATION
|
// COMMON CONFIGURATION
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED )\
|
ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED )\
|
||||||
ENTRY(TUSB_ERROR_OSAL_SEMAPHORE_FAILED )\
|
ENTRY(TUSB_ERROR_OSAL_SEMAPHORE_FAILED )\
|
||||||
ENTRY(TUSB_ERROR_EHCI_NOT_ENOUGH_QTD )\
|
ENTRY(TUSB_ERROR_EHCI_NOT_ENOUGH_QTD )\
|
||||||
|
ENTRY(TUSB_ERROR_USBD_DESCRIPTOR_STRING )\
|
||||||
ENTRY(TUSB_ERROR_FAILED )\
|
ENTRY(TUSB_ERROR_FAILED )\
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
// INCLUDE
|
// INCLUDE
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
|
#include "tusb_descriptors.h" // TODO callback include
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// MACRO CONSTANT TYPEDEF
|
// MACRO CONSTANT TYPEDEF
|
||||||
|
@ -66,6 +67,30 @@
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
tusb_error_t usbd_init (void)
|
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() );
|
ASSERT_STATUS ( dcd_init() );
|
||||||
|
|
||||||
return TUSB_ERROR_NONE;
|
return TUSB_ERROR_NONE;
|
||||||
|
|
Loading…
Reference in New Issue