Преглед изворни кода

adding usbd_enum_buffer to usbd
remove string descriptor USB RAM requirement

hathach пре 12 година
родитељ
комит
e28170db2f

+ 0 - 4
demos/device/src/tusb_descriptors.c

@@ -408,28 +408,24 @@ 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)
 
-TUSB_CFG_ATTR_USBRAM
 uint16_t desc_string_language[] =
 {
     ENDIAN_BE16_FROM( STRING_LEN_UNICODE(1), TUSB_DESC_TYPE_STRING ),
     0x0409
 };
 
-TUSB_CFG_ATTR_USBRAM
 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
 };
 
-TUSB_CFG_ATTR_USBRAM
 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
 };
 
-TUSB_CFG_ATTR_USBRAM
 uint16_t desc_string_serial[] =
 {
     ENDIAN_BE16_FROM( STRING_LEN_UNICODE(4), TUSB_DESC_TYPE_STRING),

+ 7 - 3
demos/host/host_os_none/.cproject

@@ -554,8 +554,11 @@
 	<storageModule moduleId="com.crt.config">
 		<projectStorage>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&#13;
 &lt;TargetConfig&gt;&#13;
-&lt;Properties property_0="" property_2="LPC18x7_43x7_2x512_BootA.cfx" property_3="NXP" property_4="LPC4357" property_count="5" version="1"/&gt;&#13;
-&lt;infoList vendor="NXP"&gt;&lt;info chip="LPC4357" flash_driver="LPC18x7_43x7_2x512_BootA.cfx" match_id="0x0" name="LPC4357" resetscript="LPC18LPC43InternalFLASHBootResetscript.scp" stub="crt_emu_lpc18_43_nxp"&gt;&lt;chip&gt;&lt;name&gt;LPC4357&lt;/name&gt;&#13;
+&lt;Properties property_0="" property_2="LPC18x7_43x7_2x512_BootA.cfx" property_3="NXP" property_4="LPC4357" property_count="5" version="60100"/&gt;&#13;
+&lt;infoList vendor="NXP"&gt;&#13;
+&lt;info chip="LPC4357" flash_driver="LPC18x7_43x7_2x512_BootA.cfx" match_id="0x0" name="LPC4357" resetscript="LPC18LPC43InternalFLASHBootResetscript.scp" stub="crt_emu_lpc18_43_nxp"&gt;&#13;
+&lt;chip&gt;&#13;
+&lt;name&gt;LPC4357&lt;/name&gt;&#13;
 &lt;family&gt;LPC43xx&lt;/family&gt;&#13;
 &lt;vendor&gt;NXP (formerly Philips)&lt;/vendor&gt;&#13;
 &lt;reset board="None" core="Real" sys="Real"/&gt;&#13;
@@ -630,7 +633,8 @@
 &lt;peripheralInstance derived_from="SPI" determined="infoFile" id="SPI" location="0x40100000"/&gt;&#13;
 &lt;peripheralInstance derived_from="SGPIO" determined="infoFile" id="SGPIO" location="0x40101000"/&gt;&#13;
 &lt;/chip&gt;&#13;
-&lt;processor&gt;&lt;name gcc_name="cortex-m4"&gt;Cortex-M4&lt;/name&gt;&#13;
+&lt;processor&gt;&#13;
+&lt;name gcc_name="cortex-m4"&gt;Cortex-M4&lt;/name&gt;&#13;
 &lt;family&gt;Cortex-M&lt;/family&gt;&#13;
 &lt;/processor&gt;&#13;
 &lt;link href="nxp_lpc43xx_peripheral.xme" show="embed" type="simple"/&gt;&#13;

+ 6 - 2
tinyusb/device/usbd.c

@@ -52,6 +52,7 @@
 // MACRO CONSTANT TYPEDEF
 //--------------------------------------------------------------------+
 usbd_device_info_t usbd_devices[CONTROLLER_DEVICE_NUMBER];
+TUSB_CFG_ATTR_USBRAM uint8_t usbd_enum_buffer[TUSB_CFG_DEVICE_ENUM_BUFFER_SIZE];
 
 static usbd_class_driver_t const usbd_class_drivers[] =
 {
@@ -346,9 +347,12 @@ 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 && tusbd_descriptor_pointers.p_string_arr[desc_index] != NULL) ) return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
+    if ( !(desc_index < TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT) ) return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
+    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);
 
-    (*pp_buffer) = tusbd_descriptor_pointers.p_string_arr[desc_index];
+    memcpy(usbd_enum_buffer, p_desc_string, p_desc_string[0]); // first byte of descriptor is its size
+    (*pp_buffer) = usbd_enum_buffer;
     (*p_length)  = **pp_buffer;
   }else
   {

+ 7 - 3
tinyusb/tusb_option.h

@@ -163,11 +163,15 @@
 //--------------------------------------------------------------------+
 #if MODE_DEVICE_SUPPORTED
 
-#define DEVICE_CLASS_HID ( TUSB_CFG_DEVICE_HID_KEYBOARD + TUSB_CFG_DEVICE_HID_MOUSE + TUSB_CFG_DEVICE_HID_GENERIC )
+ #define DEVICE_CLASS_HID ( TUSB_CFG_DEVICE_HID_KEYBOARD + TUSB_CFG_DEVICE_HID_MOUSE + TUSB_CFG_DEVICE_HID_GENERIC )
 
-#if TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE > 64
+ #if TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE > 64
   #error Control Endpoint Max Package Size cannot larger than 64
-#endif
+ #endif
+
+ #ifndef TUSB_CFG_DEVICE_ENUM_BUFFER_SIZE
+   #define TUSB_CFG_DEVICE_ENUM_BUFFER_SIZE 256
+ #endif
 
 #endif // MODE_DEVICE_SUPPORTED