Просмотр исходного кода

use internal buffer for hid report descriptor as well.

hathach 12 лет назад
Родитель
Сommit
58892299f3
3 измененных файлов с 14 добавлено и 13 удалено
  1. 2 4
      demos/device/src/tusb_descriptors.c
  2. 11 7
      tinyusb/class/hid_device.c
  3. 1 2
      tinyusb/device/usbd.h

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

@@ -42,8 +42,7 @@
 // Keyboard Report Descriptor
 // Keyboard Report Descriptor
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 #if TUSB_CFG_DEVICE_HID_KEYBOARD
 #if TUSB_CFG_DEVICE_HID_KEYBOARD
-TUSB_CFG_ATTR_USBRAM
-uint8_t desc_keyboard_report[] = {
+uint8_t const desc_keyboard_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 ),
@@ -89,8 +88,7 @@ uint8_t desc_keyboard_report[] = {
 // Mouse Report Descriptor
 // Mouse Report Descriptor
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 #if TUSB_CFG_DEVICE_HID_MOUSE
 #if TUSB_CFG_DEVICE_HID_MOUSE
-TUSB_CFG_ATTR_USBRAM
-uint8_t desc_mouse_report[] = {
+uint8_t const desc_mouse_report[] = {
   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 ),

+ 11 - 7
tinyusb/class/hid_device.c

@@ -50,7 +50,10 @@
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // MACRO CONSTANT TYPEDEF
 // MACRO CONSTANT TYPEDEF
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
-enum { HIDD_NUMBER_OF_SUBCLASS = 3 };
+enum {
+  HIDD_NUMBER_OF_SUBCLASS = 3,
+  HIDD_BUFFER_SIZE = 128
+};
 
 
 typedef struct {
 typedef struct {
   uint8_t const * p_report_desc;
   uint8_t const * p_report_desc;
@@ -101,9 +104,8 @@ static hidd_class_driver_t const hidd_class_driver[HIDD_NUMBER_OF_SUBCLASS] =
 #endif
 #endif
 };
 };
 
 
-// TODO [HID] generic
-TUSB_CFG_ATTR_USBRAM
-static uint8_t m_control_report[ MAX_OF(sizeof(hid_keyboard_report_t), sizeof(hid_mouse_report_t)) ];
+// internal buffer for transferring data
+TUSB_CFG_ATTR_USBRAM static uint8_t m_hid_buffer[ HIDD_BUFFER_SIZE ];
 
 
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // KEYBOARD APPLICATION API
 // KEYBOARD APPLICATION API
@@ -204,8 +206,10 @@ tusb_error_t hidd_control_request_subtask(uint8_t coreid, tusb_control_request_t
 
 
     ASSERT ( p_request->bRequest == TUSB_REQUEST_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT,
     ASSERT ( p_request->bRequest == TUSB_REQUEST_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT,
              TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT);
              TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT);
+    ASSERT ( p_hid->report_length <= HIDD_BUFFER_SIZE, TUSB_ERROR_NOT_ENOUGH_MEMORY);
 
 
-    dcd_pipe_control_xfer(coreid, TUSB_DIR_DEV_TO_HOST, (uint8_t*) p_hid->p_report_desc, p_hid->report_length, false);
+    memcpy(m_hid_buffer, p_hid->p_report_desc, p_hid->report_length); // to allow report descriptor not to be in USBRAM
+    dcd_pipe_control_xfer(coreid, TUSB_DIR_DEV_TO_HOST, m_hid_buffer, p_hid->report_length, false);
   }
   }
   //------------- Class Specific Request -------------//
   //------------- Class Specific Request -------------//
   else if (p_request->bmRequestType_bit.type == TUSB_REQUEST_TYPE_CLASS)
   else if (p_request->bmRequestType_bit.type == TUSB_REQUEST_TYPE_CLASS)
@@ -229,13 +233,13 @@ tusb_error_t hidd_control_request_subtask(uint8_t coreid, tusb_control_request_t
       // wValue = Report Type | Report ID
       // wValue = Report Type | Report ID
       tusb_error_t error;
       tusb_error_t error;
 
 
-      dcd_pipe_control_xfer(coreid, (tusb_direction_t) p_request->bmRequestType_bit.direction, m_control_report, p_request->wLength, true);
+      dcd_pipe_control_xfer(coreid, (tusb_direction_t) p_request->bmRequestType_bit.direction, m_hid_buffer, p_request->wLength, true);
 
 
       osal_semaphore_wait(usbd_control_xfer_sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // wait for control xfer complete
       osal_semaphore_wait(usbd_control_xfer_sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // wait for control xfer complete
       SUBTASK_ASSERT_STATUS(error);
       SUBTASK_ASSERT_STATUS(error);
 
 
       p_driver->set_report_cb(coreid, (hid_request_report_type_t) u16_high_u8(p_request->wValue),
       p_driver->set_report_cb(coreid, (hid_request_report_type_t) u16_high_u8(p_request->wValue),
-                              m_control_report, p_request->wLength);
+                              m_hid_buffer, p_request->wLength);
     }
     }
     else if (HID_REQUEST_CONTROL_SET_IDLE == p_request->bRequest)
     else if (HID_REQUEST_CONTROL_SET_IDLE == p_request->bRequest)
     {
     {

+ 1 - 2
tinyusb/device/usbd.h

@@ -63,8 +63,7 @@
  #define ATTR_USB_MIN_ALIGNMENT
  #define ATTR_USB_MIN_ALIGNMENT
 #endif
 #endif
 
 
-/// \brief Descriptor pointer collector to all the needed. All the addresses pointed
-/// must be accessible by USB controller (see \ref TUSB_CFG_ATTR_USBRAM)
+/// \brief Descriptor pointer collector to all the needed.
 typedef struct {
 typedef struct {
   uint8_t const * p_device;              ///< pointer to device descritpor \ref tusb_descriptor_device_t
   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_configuration;       ///< pointer to the whole configuration descriptor, starting by \ref tusb_descriptor_configuration_t