From 58892299f3f6658de4e35fe588fb3c016c4fd591 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 23 Mar 2014 16:57:39 +0700 Subject: [PATCH] use internal buffer for hid report descriptor as well. --- demos/device/src/tusb_descriptors.c | 6 ++---- tinyusb/class/hid_device.c | 18 +++++++++++------- tinyusb/device/usbd.h | 3 +-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/demos/device/src/tusb_descriptors.c b/demos/device/src/tusb_descriptors.c index cef2313e..8a23a250 100644 --- a/demos/device/src/tusb_descriptors.c +++ b/demos/device/src/tusb_descriptors.c @@ -42,8 +42,7 @@ // Keyboard Report Descriptor //--------------------------------------------------------------------+ #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 ( HID_USAGE_DESKTOP_KEYBOARD ), HID_COLLECTION ( HID_COLLECTION_APPLICATION ), @@ -89,8 +88,7 @@ uint8_t desc_keyboard_report[] = { // Mouse Report Descriptor //--------------------------------------------------------------------+ #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 ( HID_USAGE_DESKTOP_MOUSE ), HID_COLLECTION ( HID_COLLECTION_APPLICATION ), diff --git a/tinyusb/class/hid_device.c b/tinyusb/class/hid_device.c index e2fb9f62..7e2454d3 100644 --- a/tinyusb/class/hid_device.c +++ b/tinyusb/class/hid_device.c @@ -50,7 +50,10 @@ //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ -enum { HIDD_NUMBER_OF_SUBCLASS = 3 }; +enum { + HIDD_NUMBER_OF_SUBCLASS = 3, + HIDD_BUFFER_SIZE = 128 +}; typedef struct { uint8_t const * p_report_desc; @@ -101,9 +104,8 @@ static hidd_class_driver_t const hidd_class_driver[HIDD_NUMBER_OF_SUBCLASS] = #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 @@ -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, 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 -------------// 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 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 SUBTASK_ASSERT_STATUS(error); 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) { diff --git a/tinyusb/device/usbd.h b/tinyusb/device/usbd.h index d0eeb6e4..01e7c0c0 100644 --- a/tinyusb/device/usbd.h +++ b/tinyusb/device/usbd.h @@ -63,8 +63,7 @@ #define ATTR_USB_MIN_ALIGNMENT #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 { 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