refractor string descriptors, allow one-stop configure descriptor for

- manufacturer, product etc ... (only english now)
This commit is contained in:
hathach
2013-05-31 18:21:31 +07:00
parent abf1054745
commit 03d85acfc7
8 changed files with 93 additions and 21 deletions

View File

@@ -30,6 +30,7 @@
:source:
- ../tinyusb/**
- +:../demos/bsp/lpc43xx/**
- +:../demos/device/keyboard/*
- -:../demos/
- ../vendor/freertos/freertos/Source/*
- ../vendor/freertos/freertos/Source/portable/MSVC-MingW/*

View File

@@ -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]);
}
}

View File

@@ -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