From e28170db2f43db51e0baff1e79c87490064c1258 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 23 Mar 2014 10:15:32 +0700 Subject: [PATCH] adding usbd_enum_buffer to usbd remove string descriptor USB RAM requirement --- demos/device/src/tusb_descriptors.c | 4 ---- demos/host/host_os_none/.cproject | 10 +++++++--- tinyusb/device/usbd.c | 8 ++++++-- tinyusb/tusb_option.h | 10 +++++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/demos/device/src/tusb_descriptors.c b/demos/device/src/tusb_descriptors.c index 33fc895b4..646addcd3 100644 --- a/demos/device/src/tusb_descriptors.c +++ b/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), diff --git a/demos/host/host_os_none/.cproject b/demos/host/host_os_none/.cproject index 973d8f762..5497fa4e4 100644 --- a/demos/host/host_os_none/.cproject +++ b/demos/host/host_os_none/.cproject @@ -554,8 +554,11 @@ <?xml version="1.0" encoding="UTF-8"?> <TargetConfig> -<Properties property_0="" property_2="LPC18x7_43x7_2x512_BootA.cfx" property_3="NXP" property_4="LPC4357" property_count="5" version="1"/> -<infoList vendor="NXP"><info chip="LPC4357" flash_driver="LPC18x7_43x7_2x512_BootA.cfx" match_id="0x0" name="LPC4357" resetscript="LPC18LPC43InternalFLASHBootResetscript.scp" stub="crt_emu_lpc18_43_nxp"><chip><name>LPC4357</name> +<Properties property_0="" property_2="LPC18x7_43x7_2x512_BootA.cfx" property_3="NXP" property_4="LPC4357" property_count="5" version="60100"/> +<infoList vendor="NXP"> +<info chip="LPC4357" flash_driver="LPC18x7_43x7_2x512_BootA.cfx" match_id="0x0" name="LPC4357" resetscript="LPC18LPC43InternalFLASHBootResetscript.scp" stub="crt_emu_lpc18_43_nxp"> +<chip> +<name>LPC4357</name> <family>LPC43xx</family> <vendor>NXP (formerly Philips)</vendor> <reset board="None" core="Real" sys="Real"/> @@ -630,7 +633,8 @@ <peripheralInstance derived_from="SPI" determined="infoFile" id="SPI" location="0x40100000"/> <peripheralInstance derived_from="SGPIO" determined="infoFile" id="SGPIO" location="0x40101000"/> </chip> -<processor><name gcc_name="cortex-m4">Cortex-M4</name> +<processor> +<name gcc_name="cortex-m4">Cortex-M4</name> <family>Cortex-M</family> </processor> <link href="nxp_lpc43xx_peripheral.xme" show="embed" type="simple"/> diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c index b64b25f4a..2df0916aa 100644 --- a/tinyusb/device/usbd.c +++ b/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 { diff --git a/tinyusb/tusb_option.h b/tinyusb/tusb_option.h index b23941584..467abf397 100644 --- a/tinyusb/tusb_option.h +++ b/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