summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
authorhathach <[email protected]>2014-03-23 16:57:39 +0700
committerhathach <[email protected]>2014-03-23 16:57:39 +0700
commit58892299f3f6658de4e35fe588fb3c016c4fd591 (patch)
tree062c4524480c6905c4e6912497a1aa989a36a347 /tinyusb
parente0fd3efa70619167e198195c02f3ec0eb066af1a (diff)
use internal buffer for hid report descriptor as well.
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/class/hid_device.c18
-rw-r--r--tinyusb/device/usbd.h3
2 files changed, 12 insertions, 9 deletions
diff --git a/tinyusb/class/hid_device.c b/tinyusb/class/hid_device.c
index e2fb9f62f..7e2454d31 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 d0eeb6e49..01e7c0c04 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