summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2014-03-23 14:14:00 +0700
committerhathach <[email protected]>2014-03-23 14:14:00 +0700
commit1af381c2de10b0e7a8955ebc3d40fb5fb58e4f1a (patch)
tree8933de8cafae474edcc8230787213785ada925cb
parente28170db2f43db51e0baff1e79c87490064c1258 (diff)
remove TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT
refractor descriptor to array of pointer, adding interface descriptor as well
-rw-r--r--demos/device/device_os_none/.cproject8
-rw-r--r--demos/device/src/tusb_config.h1
-rw-r--r--demos/device/src/tusb_descriptors.c80
-rw-r--r--tinyusb/device/usbd.c10
-rw-r--r--tinyusb/device/usbd.h10
5 files changed, 59 insertions, 50 deletions
diff --git a/demos/device/device_os_none/.cproject b/demos/device/device_os_none/.cproject
index 165299b9b..68ace4a6a 100644
--- a/demos/device/device_os_none/.cproject
+++ b/demos/device/device_os_none/.cproject
@@ -561,10 +561,7 @@
<projectStorage>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&#13;
&lt;TargetConfig&gt;&#13;
&lt;Properties property_0="" property_2="LPC11_12_13_64K_8K.cfx" property_3="NXP" property_4="LPC1347" property_count="5" version="60100"/&gt;&#13;
-&lt;infoList vendor="NXP"&gt;&#13;
-&lt;info chip="LPC1347" flash_driver="LPC11_12_13_64K_8K.cfx" match_id="0x08020543" name="LPC1347" stub="crt_emu_lpc11_13_nxp"&gt;&#13;
-&lt;chip&gt;&#13;
-&lt;name&gt;LPC1347&lt;/name&gt;&#13;
+&lt;infoList vendor="NXP"&gt;&lt;info chip="LPC1347" flash_driver="LPC11_12_13_64K_8K.cfx" match_id="0x08020543" name="LPC1347" stub="crt_emu_lpc11_13_nxp"&gt;&lt;chip&gt;&lt;name&gt;LPC1347&lt;/name&gt;&#13;
&lt;family&gt;LPC13xx (12bit ADC)&lt;/family&gt;&#13;
&lt;vendor&gt;NXP (formerly Philips)&lt;/vendor&gt;&#13;
&lt;reset board="None" core="Real" sys="Real"/&gt;&#13;
@@ -602,8 +599,7 @@
&lt;peripheralInstance derived_from="USB" determined="infoFile" id="USB" location="0x40080000"/&gt;&#13;
&lt;peripheralInstance derived_from="GPIO-PORT" determined="infoFile" id="GPIO-PORT" location="0x50000000"/&gt;&#13;
&lt;/chip&gt;&#13;
-&lt;processor&gt;&#13;
-&lt;name gcc_name="cortex-m3"&gt;Cortex-M3&lt;/name&gt;&#13;
+&lt;processor&gt;&lt;name gcc_name="cortex-m3"&gt;Cortex-M3&lt;/name&gt;&#13;
&lt;family&gt;Cortex-M&lt;/family&gt;&#13;
&lt;/processor&gt;&#13;
&lt;link href="nxp_lpc13Uxx_peripheral.xme" show="embed" type="simple"/&gt;&#13;
diff --git a/demos/device/src/tusb_config.h b/demos/device/src/tusb_config.h
index 13a81e248..f7e577685 100644
--- a/demos/device/src/tusb_config.h
+++ b/demos/device/src/tusb_config.h
@@ -54,7 +54,6 @@
// DEVICE CONFIGURATION
//--------------------------------------------------------------------+
#define TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE 64
-#define TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT 4
#define TUSB_CFG_DEVICE_FULLSPEED 1 // TODO refractor, remove
diff --git a/demos/device/src/tusb_descriptors.c b/demos/device/src/tusb_descriptors.c
index 646addcd3..98479988d 100644
--- a/demos/device/src/tusb_descriptors.c
+++ b/demos/device/src/tusb_descriptors.c
@@ -267,7 +267,7 @@ app_descriptor_configuration_t desc_configuration =
.bInterfaceClass = TUSB_CLASS_CDC_DATA,
.bInterfaceSubClass = 0,
.bInterfaceProtocol = 0,
- .iInterface = 0x00
+ .iInterface = 0x04
},
.cdc_endpoint_out =
@@ -303,7 +303,7 @@ app_descriptor_configuration_t desc_configuration =
.bInterfaceClass = TUSB_CLASS_HID,
.bInterfaceSubClass = HID_SUBCLASS_BOOT,
.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
- .iInterface = 0x00
+ .iInterface = 0x05
},
.keyboard_hid =
@@ -340,7 +340,7 @@ app_descriptor_configuration_t desc_configuration =
.bInterfaceClass = TUSB_CLASS_HID,
.bInterfaceSubClass = HID_SUBCLASS_BOOT,
.bInterfaceProtocol = HID_PROTOCOL_MOUSE,
- .iInterface = 0x00
+ .iInterface = 0x06
},
.mouse_hid =
@@ -377,7 +377,7 @@ app_descriptor_configuration_t desc_configuration =
.bInterfaceClass = TUSB_CLASS_MSC,
.bInterfaceSubClass = MSC_SUBCLASS_SCSI,
.bInterfaceProtocol = MSC_PROTOCOL_BOT,
- .iInterface = 0x00
+ .iInterface = 0x07
},
.msc_endpoint_in =
@@ -408,28 +408,48 @@ app_descriptor_configuration_t desc_configuration =
#define STRING_LEN_UNICODE(n) (2 + (2*(n))) // also includes 2 byte header
#define ENDIAN_BE16_FROM( high, low) ENDIAN_BE16(high << 8 | low)
-uint16_t desc_string_language[] =
+// array of pointer to string descriptors
+uint16_t const * const string_descriptor_arr [] =
{
- ENDIAN_BE16_FROM( STRING_LEN_UNICODE(1), TUSB_DESC_TYPE_STRING ),
- 0x0409
-};
+ [0] = (uint16_t []) { // supported language
+ ENDIAN_BE16_FROM( STRING_LEN_UNICODE(1), TUSB_DESC_TYPE_STRING ),
+ 0x0409 // English
+ },
-uint16_t desc_string_manufacturer[] =
-{
- ENDIAN_BE16_FROM( STRING_LEN_UNICODE(11), TUSB_DESC_TYPE_STRING),
- 't', 'i', 'n', 'y', 'u', 's', 'b', '.', 'o', 'r', 'g' // len = 11
-};
+ [1] = (uint16_t []) { // manufacturer
+ ENDIAN_BE16_FROM( STRING_LEN_UNICODE(11), TUSB_DESC_TYPE_STRING),
+ 't', 'i', 'n', 'y', 'u', 's', 'b', '.', 'o', 'r', 'g' // len = 11
+ },
-uint16_t desc_string_product[] =
-{
- ENDIAN_BE16_FROM( STRING_LEN_UNICODE(14), TUSB_DESC_TYPE_STRING),
- 't', 'i', 'n', 'y', 'u', 's', 'b', ' ', 'D', 'e', 'v', 'i', 'c', 'e' // len = 14
-};
+ [2] = (uint16_t []) { // product
+ ENDIAN_BE16_FROM( STRING_LEN_UNICODE(14), TUSB_DESC_TYPE_STRING),
+ 't', 'i', 'n', 'y', 'u', 's', 'b', ' ', 'd', 'e', 'v', 'i', 'c', 'e' // len = 14
+ },
-uint16_t desc_string_serial[] =
-{
- ENDIAN_BE16_FROM( STRING_LEN_UNICODE(4), TUSB_DESC_TYPE_STRING),
- '1', '2', '3', '4' // len = 4
+ [3] = (uint16_t []) { // serials
+ ENDIAN_BE16_FROM( STRING_LEN_UNICODE(4), TUSB_DESC_TYPE_STRING),
+ '1', '2', '3', '4' // len = 4
+ },
+
+ [4] = (uint16_t []) { // CDC Interface
+ ENDIAN_BE16_FROM( STRING_LEN_UNICODE(3), TUSB_DESC_TYPE_STRING),
+ 'c', 'd', 'c' // len = 3
+ },
+
+ [5] = (uint16_t []) { // Keyboard Interface
+ ENDIAN_BE16_FROM( STRING_LEN_UNICODE(5), TUSB_DESC_TYPE_STRING),
+ 'm', 'o', 'u', 's', 'e' // len = 5
+ },
+
+ [6] = (uint16_t []) { // Keyboard Interface
+ ENDIAN_BE16_FROM( STRING_LEN_UNICODE(8), TUSB_DESC_TYPE_STRING),
+ 'k', 'e', 'y', 'b', 'o', 'a', 'r', 'd' // len = 8
+ },
+
+ [7] = (uint16_t []) { // MSC Interface
+ ENDIAN_BE16_FROM( STRING_LEN_UNICODE(3), TUSB_DESC_TYPE_STRING),
+ 'm', 's', 'c' // len = 3
+ }
};
//--------------------------------------------------------------------+
@@ -437,21 +457,15 @@ uint16_t desc_string_serial[] =
//--------------------------------------------------------------------+
tusbd_descriptor_pointer_t tusbd_descriptor_pointers =
{
- .p_device = (uint8_t*) &desc_device,
- .p_configuration = (uint8_t*) &desc_configuration,
- .p_string_arr =
- { // up to TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT (including language - index=0)
- (uint8_t*) desc_string_language,
- (uint8_t*) desc_string_manufacturer,
- (uint8_t*) desc_string_product,
- (uint8_t*) desc_string_serial
- },
+ .p_device = (uint8_t const * ) &desc_device,
+ .p_configuration = (uint8_t const * ) &desc_configuration,
+ .p_string_arr = (uint8_t const **) string_descriptor_arr,
#if TUSB_CFG_DEVICE_HID_KEYBOARD
- .p_hid_keyboard_report = desc_keyboard_report,
+ .p_hid_keyboard_report = (uint8_t const *) desc_keyboard_report,
#endif
#if TUSB_CFG_DEVICE_HID_MOUSE
- .p_hid_mouse_report = desc_mouse_report,
+ .p_hid_mouse_report = (uint8_t const *) desc_mouse_report,
#endif
};
diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c
index 2df0916aa..4a5db91aa 100644
--- a/tinyusb/device/usbd.c
+++ b/tinyusb/device/usbd.c
@@ -97,7 +97,7 @@ enum { USBD_CLASS_DRIVER_COUNT = sizeof(usbd_class_drivers) / sizeof(usbd_class_
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
static tusb_error_t usbd_set_configure_received(uint8_t coreid, uint8_t config_number);
-static tusb_error_t get_descriptor(uint8_t coreid, tusb_control_request_t const * const p_request, uint8_t ** pp_buffer, uint16_t * p_length);
+static tusb_error_t get_descriptor(uint8_t coreid, tusb_control_request_t const * const p_request, uint8_t const ** pp_buffer, uint16_t * p_length);
//--------------------------------------------------------------------+
// APPLICATION INTERFACE
@@ -158,14 +158,14 @@ tusb_error_t usbd_control_request_subtask(uint8_t coreid, tusb_control_request_t
{
if ( TUSB_REQUEST_GET_DESCRIPTOR == p_request->bRequest )
{
- uint8_t* p_buffer = NULL;
+ uint8_t const * p_buffer = NULL;
uint16_t length = 0;
error = get_descriptor(coreid, p_request, &p_buffer, &length);
if ( TUSB_ERROR_NONE == error )
{
- dcd_pipe_control_xfer(coreid, (tusb_direction_t) p_request->bmRequestType_bit.direction, p_buffer, length, false);
+ dcd_pipe_control_xfer(coreid, (tusb_direction_t) p_request->bmRequestType_bit.direction, (uint8_t*) p_buffer, length, false);
}
}
else if ( TUSB_REQUEST_SET_ADDRESS == p_request->bRequest )
@@ -330,7 +330,7 @@ static tusb_error_t usbd_set_configure_received(uint8_t coreid, uint8_t config_n
return TUSB_ERROR_NONE;
}
-static tusb_error_t get_descriptor(uint8_t coreid, tusb_control_request_t const * const p_request, uint8_t ** pp_buffer, uint16_t * p_length)
+static tusb_error_t get_descriptor(uint8_t coreid, tusb_control_request_t const * const p_request, uint8_t const ** pp_buffer, uint16_t * p_length)
{
tusb_std_descriptor_type_t const desc_type = (tusb_std_descriptor_type_t) u16_high_u8(p_request->wValue);
uint8_t const desc_index = u16_low_u8( p_request->wValue );
@@ -347,7 +347,7 @@ static tusb_error_t get_descriptor(uint8_t coreid, tusb_control_request_t const
}
else if ( TUSB_DESC_TYPE_STRING == desc_type )
{
- if ( !(desc_index < TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT) ) return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
+ if ( !(desc_index < 100) ) return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; // windows sometimes ask for string at index 238 !!!
uint8_t const * const p_desc_string = tusbd_descriptor_pointers.p_string_arr[desc_index];
ASSERT( p_desc_string != NULL && p_desc_string[0] <= TUSB_CFG_DEVICE_ENUM_BUFFER_SIZE, TUSB_ERROR_NOT_ENOUGH_MEMORY);
diff --git a/tinyusb/device/usbd.h b/tinyusb/device/usbd.h
index c8665d033..d0eeb6e49 100644
--- a/tinyusb/device/usbd.h
+++ b/tinyusb/device/usbd.h
@@ -66,12 +66,12 @@
/// \brief Descriptor pointer collector to all the needed. All the addresses pointed
/// must be accessible by USB controller (see \ref TUSB_CFG_ATTR_USBRAM)
typedef struct {
- uint8_t * p_device; ///< pointer to device descritpor \ref tusb_descriptor_device_t
- uint8_t * p_configuration; ///< pointer to the whole configuration descriptor, starting by \ref tusb_descriptor_configuration_t
- uint8_t * p_string_arr[TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT]; ///< a array of pointers to string descriptors
+ uint8_t const * p_device; ///< pointer to device descritpor \ref tusb_descriptor_device_t
+ uint8_t const * p_configuration; ///< pointer to the whole configuration descriptor, starting by \ref tusb_descriptor_configuration_t
+ uint8_t const** p_string_arr; ///< a array of pointers to string descriptors
- uint8_t * p_hid_keyboard_report; ///< pointer to HID report descriptor of Keybaord interface. Only needed if TUSB_CFG_DEVICE_HID_KEYBOARD is enabled
- uint8_t * p_hid_mouse_report; ///< pointer to HID report descriptor of Mouse interface. Only needed if TUSB_CFG_DEVICE_HID_MOUSE is enabled
+ uint8_t const * p_hid_keyboard_report; ///< pointer to HID report descriptor of Keybaord interface. Only needed if TUSB_CFG_DEVICE_HID_KEYBOARD is enabled
+ uint8_t const * p_hid_mouse_report; ///< pointer to HID report descriptor of Mouse interface. Only needed if TUSB_CFG_DEVICE_HID_MOUSE is enabled
}tusbd_descriptor_pointer_t;
// define by application