summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-07-23 15:25:45 +0700
committerhathach <[email protected]>2018-07-23 15:25:45 +0700
commit4342325ee1359d3361acca6de4f8accf013e8e39 (patch)
treec869f399e0ef1f8588842a8927a22e528dadc503 /src/class
parent141ac25e3b3aaf72a50ace257d2bda41d1ebe702 (diff)
reworking device hid class driver
Diffstat (limited to 'src/class')
-rw-r--r--src/class/cdc/cdc_device.c6
-rw-r--r--src/class/custom/custom_device.c2
-rw-r--r--src/class/hid/hid.h20
-rw-r--r--src/class/hid/hid_device.c328
-rw-r--r--src/class/hid/hid_device.h61
-rw-r--r--src/class/hid/hid_host.c2
-rw-r--r--src/class/msc/msc_device.c2
7 files changed, 200 insertions, 221 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index 8848ddca0..bbf1c8ceb 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -38,7 +38,7 @@
#include "tusb_option.h"
-#if (MODE_DEVICE_SUPPORTED && CFG_TUD_CDC)
+#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_CDC)
#define _TINY_USB_SOURCE_FILE_
//--------------------------------------------------------------------+
@@ -157,13 +157,13 @@ uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize)
bool tud_cdc_n_write_flush (uint8_t itf)
{
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
- VERIFY( !dcd_edpt_busy(TUD_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete
+ VERIFY( !dcd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete
uint16_t count = tu_fifo_read_n(&_cdcd_itf[itf].tx_ff, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
VERIFY( tud_cdc_n_connected(itf) ); // fifo is empty if not connected
- if ( count ) TU_ASSERT( dcd_edpt_xfer(TUD_RHPORT, p_cdc->ep_in, p_cdc->epout_buf, count) );
+ if ( count ) TU_ASSERT( dcd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epout_buf, count) );
return true;
}
diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c
index e4dc1a839..c895deb18 100644
--- a/src/class/custom/custom_device.c
+++ b/src/class/custom/custom_device.c
@@ -36,7 +36,7 @@
#include "tusb_option.h"
-#if (MODE_DEVICE_SUPPORTED && CFG_TUD_CUSTOM_CLASS)
+#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_CUSTOM_CLASS)
#define _TINY_USB_SOURCE_FILE_
diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h
index d53eb979d..a12a13800 100644
--- a/src/class/hid/hid.h
+++ b/src/class/hid/hid.h
@@ -81,20 +81,20 @@ typedef enum
/// HID Request Report Type
typedef enum
{
- HID_REQUEST_REPORT_INPUT = 1, ///< Input
- HID_REQUEST_REPORT_OUTPUT, ///< Output
- HID_REQUEST_REPORT_FEATURE ///< Feature
-}hid_request_report_type_t;
+ HID_REPORT_TYPE_INPUT = 1, ///< Input
+ HID_REPORT_TYPE_OUTPUT, ///< Output
+ HID_REPORT_TYPE_FEATURE ///< Feature
+}hid_report_type_t;
/// HID Class Specific Control Request
typedef enum
{
- HID_REQUEST_CONTROL_GET_REPORT = 0x01, ///< Get Report
- HID_REQUEST_CONTROL_GET_IDLE = 0x02, ///< Get Idle
- HID_REQUEST_CONTROL_GET_PROTOCOL = 0x03, ///< Get Protocol
- HID_REQUEST_CONTROL_SET_REPORT = 0x09, ///< Set Report
- HID_REQUEST_CONTROL_SET_IDLE = 0x0a, ///< Set Idle
- HID_REQUEST_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol
+ HID_REQ_CONTROL_GET_REPORT = 0x01, ///< Get Report
+ HID_REQ_CONTROL_GET_IDLE = 0x02, ///< Get Idle
+ HID_REQ_CONTROL_GET_PROTOCOL = 0x03, ///< Get Protocol
+ HID_REQ_CONTROL_SET_REPORT = 0x09, ///< Set Report
+ HID_REQ_CONTROL_SET_IDLE = 0x0a, ///< Set Idle
+ HID_REQ_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol
}hid_request_type_t;
/// USB HID Descriptor
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index 9f22697a6..7b2c1da2d 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -38,7 +38,7 @@
#include "tusb_option.h"
-#if (MODE_DEVICE_SUPPORTED && DEVICE_CLASS_HID)
+#if (TUSB_OPT_DEVICE_ENABLED && TUD_OPT_HID_ENABLED)
#define _TINY_USB_SOURCE_FILE_
//--------------------------------------------------------------------+
@@ -51,75 +51,53 @@
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
-enum {
- HIDD_NUMBER_OF_SUBCLASS = 3,
- HIDD_BUFFER_SIZE = 128
-};
+
+// Max report len is keyboard's one with 8 byte + 1 byte report id
+#define REPORT_BUFSIZE 9
typedef struct {
- uint8_t const * p_report_desc;
- uint16_t report_length;
+ uint8_t itf_num;
+ uint8_t ep_in;
+ uint8_t idle_rate;
+
+ uint8_t report_id;
+ uint16_t report_len;
+ uint8_t const * report_desc;
- uint8_t edpt_addr;
- uint8_t interface_number;
+ // class specific control request
+ uint16_t (*get_report_cb) (hid_report_type_t type, uint8_t* buffer, uint16_t reqlen);
+ void (*set_report_cb) (hid_report_type_t type, uint8_t const* buffer, uint16_t bufsize);
+
+ CFG_TUSB_MEM_ALIGN uint8_t report_buf[REPORT_BUFSIZE];
}hidd_interface_t;
-typedef struct {
- hidd_interface_t * const p_interface;
- void (* const xfer_cb) (uint8_t, tusb_event_t, uint32_t);
- uint16_t (* const get_report_cb) (uint8_t, hid_request_report_type_t, void**, uint16_t );
- void (* const set_report_cb) (uint8_t, hid_request_report_type_t, uint8_t[], uint16_t);
-}hidd_class_driver_t;
+#if CFG_TUD_HID_BOOT_PROTOCOL
-extern ATTR_WEAK hidd_interface_t keyboardd_data;
-extern ATTR_WEAK hidd_interface_t moused_data;
+CFG_TUSB_ATTR_USBRAM static hidd_interface_t _kbd_itf;
+CFG_TUSB_ATTR_USBRAM static hidd_interface_t _mse_itf;
-static hidd_class_driver_t const hidd_class_driver[HIDD_NUMBER_OF_SUBCLASS] =
-{
-// [HID_PROTOCOL_NONE] = for HID Generic
+#else
-#if CFG_TUD_HID_KEYBOARD
- [HID_PROTOCOL_KEYBOARD] =
- {
- .p_interface = &keyboardd_data,
- .xfer_cb = tud_hid_keyboard_cb,
- .get_report_cb = tud_hid_keyboard_get_report_cb,
- .set_report_cb = tud_hid_keyboard_set_report_cb
- },
-#endif
+CFG_TUSB_ATTR_USBRAM static hidd_interface_t _composite_itf;
-#if CFG_TUD_HID_MOUSE
- [HID_PROTOCOL_MOUSE] =
- {
- .p_interface = &moused_data,
- .xfer_cb = tud_hid_mouse_cb,
- .get_report_cb = tud_hid_mouse_get_report_cb,
- .set_report_cb = tud_hid_mouse_set_report_cb
- }
#endif
-};
-
-// internal buffer for transferring data
-CFG_TUSB_ATTR_USBRAM STATIC_VAR uint8_t m_hid_buffer[ HIDD_BUFFER_SIZE ];
//--------------------------------------------------------------------+
// KEYBOARD APPLICATION API
//--------------------------------------------------------------------+
#if CFG_TUD_HID_KEYBOARD
-STATIC_VAR hidd_interface_t keyboardd_data;
-
-bool tud_hid_keyboard_busy(uint8_t rhport)
+bool tud_hid_keyboard_busy(void)
{
- return dcd_edpt_busy(rhport, keyboardd_data.edpt_addr);
+ return dcd_edpt_busy(TUD_OPT_RHPORT, _kbd_itf.ep_in);
}
-tusb_error_t tud_hid_keyboard_send(uint8_t rhport, hid_keyboard_report_t const *p_report)
+tusb_error_t tud_hid_keyboard_send(hid_keyboard_report_t const *p_report)
{
VERIFY(tud_mounted(), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
- hidd_interface_t * p_kbd = &keyboardd_data; // TODO &keyboardd_data[rhport];
+ hidd_interface_t * p_kbd = &_kbd_itf;
- TU_ASSERT( dcd_edpt_xfer(rhport, p_kbd->edpt_addr, (void*) p_report, sizeof(hid_keyboard_report_t)), TUSB_ERROR_DCD_EDPT_XFER ) ;
+ TU_ASSERT( dcd_edpt_xfer(TUD_OPT_RHPORT, p_kbd->ep_in, (void*) p_report, sizeof(hid_keyboard_report_t)), TUSB_ERROR_DCD_EDPT_XFER ) ;
return TUSB_ERROR_NONE;
}
@@ -129,66 +107,130 @@ tusb_error_t tud_hid_keyboard_send(uint8_t rhport, hid_keyboard_report_t const *
// MOUSE APPLICATION API
//--------------------------------------------------------------------+
#if CFG_TUD_HID_MOUSE
-STATIC_VAR hidd_interface_t moused_data;
-
-bool tud_hid_mouse_is_busy(uint8_t rhport)
+bool tud_hid_mouse_is_busy(void)
{
- return dcd_edpt_busy(rhport, moused_data.edpt_addr);
+ return dcd_edpt_busy(TUD_OPT_RHPORT, _mse_itf.ep_in);
}
-tusb_error_t tud_hid_mouse_send(uint8_t rhport, hid_mouse_report_t const *p_report)
+tusb_error_t tud_hid_mouse_send(hid_mouse_report_t const *p_report)
{
VERIFY(tud_mounted(), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
- hidd_interface_t * p_mouse = &moused_data; // TODO &keyboardd_data[rhport];
+ hidd_interface_t * p_mouse = &_mse_itf;
- TU_ASSERT( dcd_edpt_xfer(rhport, p_mouse->edpt_addr, (void*) p_report, sizeof(hid_mouse_report_t)), TUSB_ERROR_DCD_EDPT_XFER ) ;
+ TU_ASSERT( dcd_edpt_xfer(TUD_OPT_RHPORT, p_mouse->ep_in, (void*) p_report, sizeof(hid_mouse_report_t)), TUSB_ERROR_DCD_EDPT_XFER ) ;
return TUSB_ERROR_NONE;
}
#endif
-//--------------------------------------------------------------------+
-// USBD-CLASS API
-//--------------------------------------------------------------------+
-static void interface_clear(hidd_interface_t * p_interface)
+static inline hidd_interface_t* get_interface_by_edpt(uint8_t ep_addr)
{
- if ( p_interface != NULL )
- {
- memclr_(p_interface, sizeof(hidd_interface_t));
- p_interface->interface_number = INTERFACE_INVALID_NUMBER;
- }
+ return ( ep_addr == _kbd_itf.ep_in ) ? &_kbd_itf :
+ ( ep_addr == _mse_itf.ep_in ) ? &_mse_itf : NULL;
+}
+
+static inline hidd_interface_t* get_interface_by_number(uint8_t itf_num)
+{
+ return ( itf_num == _kbd_itf.itf_num ) ? &_kbd_itf :
+ ( itf_num == _mse_itf.itf_num ) ? &_mse_itf : NULL;
}
+//--------------------------------------------------------------------+
+// USBD-CLASS API
+//--------------------------------------------------------------------+
void hidd_init(void)
{
- for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
- {
- interface_clear( hidd_class_driver[i].p_interface );
- }
+ hidd_reset(TUD_OPT_RHPORT);
}
void hidd_reset(uint8_t rhport)
{
- for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
- {
- interface_clear(hidd_class_driver[i].p_interface);
- }
+ #if CFG_TUD_HID_MOUSE
+ varclr_(&_mse_itf);
+ #endif
+
+ #if CFG_TUD_HID_KEYBOARD
+ varclr_(&_kbd_itf);
+ #endif
}
-tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request)
+tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_length)
{
- uint8_t subclass_idx;
- for(subclass_idx=0; subclass_idx<HIDD_NUMBER_OF_SUBCLASS; subclass_idx++)
+ uint8_t const *p_desc = (uint8_t const *) desc_itf;
+
+ //------------- HID descriptor -------------//
+ p_desc += p_desc[DESC_OFFSET_LEN];
+ tusb_hid_descriptor_hid_t const *desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
+ TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
+
+ //------------- Endpoint Descriptor -------------//
+ p_desc += p_desc[DESC_OFFSET_LEN];
+ tusb_desc_endpoint_t const *desc_edpt = (tusb_desc_endpoint_t const *) p_desc;
+ TU_ASSERT(TUSB_DESC_ENDPOINT == desc_edpt->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
+
+ if (desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT)
{
- hidd_interface_t * const p_interface = hidd_class_driver[subclass_idx].p_interface;
- if ( (p_interface != NULL) && (p_request->wIndex == p_interface->interface_number) ) break;
+#if CFG_TUD_HID_BOOT_PROTOCOL
+ if ( (desc_itf->bInterfaceProtocol != HID_PROTOCOL_KEYBOARD) && (desc_itf->bInterfaceProtocol != HID_PROTOCOL_MOUSE) )
+ {
+ // unknown, unsupported protocol
+ return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
+ }else
+ {
+ hidd_interface_t * p_hid = NULL;
+
+ #if CFG_TUD_HID_KEYBOARD
+ if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD)
+ {
+ p_hid = &_kbd_itf;
+ p_hid->report_desc = tud_desc_set.hid_report.boot_keyboard;
+ p_hid->get_report_cb = tud_hid_keyboard_get_report_cb;
+ p_hid->set_report_cb = tud_hid_keyboard_set_report_cb;
+ }
+ #endif
+
+ #if CFG_TUD_HID_MOUSE
+ if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE)
+ {
+ p_hid = &_mse_itf;
+ p_hid->report_desc = tud_desc_set.hid_report.boot_mouse;
+ p_hid->get_report_cb = tud_hid_mouse_get_report_cb;
+ p_hid->set_report_cb = tud_hid_mouse_set_report_cb;
+ }
+ #endif
+
+ TU_ASSERT(p_hid, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
+ VERIFY(p_hid->report_desc, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
+
+ TU_ASSERT( dcd_edpt_open(rhport, desc_edpt), TUSB_ERROR_DCD_FAILED );
+
+ p_hid->report_len = desc_hid->wReportLength;
+ p_hid->itf_num = desc_itf->bInterfaceNumber;
+ p_hid->ep_in = desc_edpt->bEndpointAddress;
+ p_hid->report_id = 0;
+
+ *p_length = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t);
+ }
+#else
+ return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
+#endif
+ }
+ else
+ {
+ // TODO HID generic
+ // TODO parse report ID for keyboard, mouse
+ *p_length = 0;
+ return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
}
- TU_ASSERT(subclass_idx < HIDD_NUMBER_OF_SUBCLASS, TUSB_ERROR_FAILED);
+ return TUSB_ERROR_NONE;
+}
- hidd_class_driver_t const * const p_driver = &hidd_class_driver[subclass_idx];
- hidd_interface_t* const p_hid = p_driver->p_interface;
+tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request)
+{
+ hidd_interface_t* p_hid = get_interface_by_number( (uint8_t) p_request->wIndex );
+ TU_ASSERT(p_hid, TUSB_ERROR_FAILED);
OSAL_SUBTASK_BEGIN
@@ -202,12 +244,12 @@ tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t cons
if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
{
- STASK_ASSERT ( p_hid->report_length <= HIDD_BUFFER_SIZE );
+ STASK_ASSERT ( p_hid->report_len <= CFG_TUD_CTRL_BUFSIZE );
- // copy to allow report descriptor not to be in USBRAM
- memcpy(m_hid_buffer, p_hid->p_report_desc, p_hid->report_length);
+ // use device control buffer (in USB SRAM)
+ memcpy(_usbd_ctrl_buf, p_hid->report_desc, p_hid->report_len);
- usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, m_hid_buffer, p_hid->report_length);
+ usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, _usbd_ctrl_buf, p_hid->report_len);
}else
{
dcd_control_stall(rhport);
@@ -216,34 +258,59 @@ tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t cons
//------------- Class Specific Request -------------//
else if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS)
{
- if( (HID_REQUEST_CONTROL_GET_REPORT == p_request->bRequest) && (p_driver->get_report_cb != NULL) )
+ if( HID_REQ_CONTROL_GET_REPORT == p_request->bRequest )
{
// wValue = Report Type | Report ID
- void* p_buffer = NULL;
+ uint8_t const report_type = u16_high_u8(p_request->wValue);
+ uint8_t const report_id = u16_low_u8(p_request->wValue);
- uint16_t actual_length = p_driver->get_report_cb(rhport, (hid_request_report_type_t) u16_high_u8(p_request->wValue),
- &p_buffer, p_request->wLength);
- STASK_ASSERT( p_buffer != NULL && actual_length > 0 );
+ // Composite interface need to determine it is Keyboard, Mouse or Gamepad
+ if ( report_id > 0 )
+ {
+
+ }
+
+ uint16_t xferlen;
+ if ( p_hid->get_report_cb )
+ {
+ xferlen = p_hid->get_report_cb((hid_report_type_t) report_type, p_hid->report_buf, p_request->wLength);
+ }else
+ {
+ xferlen = p_request->wLength;
+ // re-use report_buf -> report has no change
+ }
- usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, p_buffer, actual_length);
+ STASK_ASSERT( xferlen > 0 );
+ usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, p_hid->report_buf, xferlen);
}
- else if ( (HID_REQUEST_CONTROL_SET_REPORT == p_request->bRequest) && (p_driver->set_report_cb != NULL) )
+ else if ( HID_REQ_CONTROL_SET_REPORT == p_request->bRequest )
{
- // return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; // TODO test STALL control out endpoint (with mouse+keyboard)
// wValue = Report Type | Report ID
- usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, m_hid_buffer, p_request->wLength);
+ usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, _usbd_ctrl_buf, p_request->wLength);
- p_driver->set_report_cb(rhport, u16_high_u8(p_request->wValue), m_hid_buffer, p_request->wLength);
+ if ( p_hid->set_report_cb )
+ {
+ p_hid->set_report_cb(u16_high_u8(p_request->wValue), _usbd_ctrl_buf, p_request->wLength);
+ }
}
- else if (HID_REQUEST_CONTROL_SET_IDLE == p_request->bRequest)
+ else if (HID_REQ_CONTROL_SET_IDLE == p_request->bRequest)
{
- // uint8_t idle_rate = u16_high_u8(p_request->wValue);
+ p_hid->idle_rate = u16_high_u8(p_request->wValue);
dcd_control_status(rhport, p_request->bmRequestType_bit.direction);
- }else
+ }
+ else if (HID_REQ_CONTROL_GET_IDLE == p_request->bRequest)
{
-// HID_REQUEST_CONTROL_GET_IDLE:
-// HID_REQUEST_CONTROL_GET_PROTOCOL:
-// HID_REQUEST_CONTROL_SET_PROTOCOL:
+ _usbd_ctrl_buf[0] = p_hid->idle_rate;
+ usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, _usbd_ctrl_buf, 1);
+ }
+ else if (HID_REQ_CONTROL_GET_PROTOCOL == p_request->bRequest )
+ {
+ _usbd_ctrl_buf[0] = 1 - CFG_TUD_HID_BOOT_PROTOCOL; // 0 is Boot, 1 is Report protocol
+ usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, _usbd_ctrl_buf, 1);
+ }
+ else
+ {
+// HID_REQ_CONTROL_SET_PROTOCOL:
dcd_control_stall(rhport);
}
}else
@@ -254,68 +321,9 @@ tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t cons
OSAL_SUBTASK_END
}
-tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length)
-{
- uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
-
- //------------- HID descriptor -------------//
- p_desc += p_desc[DESC_OFFSET_LEN];
- tusb_hid_descriptor_hid_t const *p_desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
- TU_ASSERT(HID_DESC_TYPE_HID == p_desc_hid->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
-
- //------------- Endpoint Descriptor -------------//
- p_desc += p_desc[DESC_OFFSET_LEN];
- tusb_desc_endpoint_t const *p_desc_endpoint = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT(TUSB_DESC_ENDPOINT == p_desc_endpoint->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
-
- if (p_interface_desc->bInterfaceSubClass == HID_SUBCLASS_BOOT)
- {
- switch(p_interface_desc->bInterfaceProtocol)
- {
- case HID_PROTOCOL_KEYBOARD:
- case HID_PROTOCOL_MOUSE:
- {
- hidd_class_driver_t const * const p_driver = &hidd_class_driver[p_interface_desc->bInterfaceProtocol];
- hidd_interface_t * const p_hid = p_driver->p_interface;
-
- VERIFY(p_hid, TUSB_ERROR_FAILED);
-
- VERIFY( dcd_edpt_open(rhport, p_desc_endpoint), TUSB_ERROR_DCD_FAILED );
-
- p_hid->edpt_addr = p_desc_endpoint->bEndpointAddress;
-
- p_hid->interface_number = p_interface_desc->bInterfaceNumber;
- p_hid->p_report_desc = (p_interface_desc->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD) ? tusbd_descriptor_pointers.p_hid_keyboard_report : tusbd_descriptor_pointers.p_hid_mouse_report;
- p_hid->report_length = p_desc_hid->wReportLength;
-
- VERIFY(p_hid->p_report_desc, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
- }
- break;
-
- default: // TODO unknown, unsupported protocol --> skip this interface
- return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
- }
- *p_length = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t);
- }else
- {
- // open generic
- *p_length = 0;
- return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
- }
- return TUSB_ERROR_NONE;
-}
-
tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes)
{
- for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
- {
- hidd_interface_t * const p_interface = hidd_class_driver[i].p_interface;
- if ( (p_interface != NULL) && (edpt_addr == p_interface->edpt_addr) )
- {
- hidd_class_driver[i].xfer_cb(rhport, event, xferred_bytes);
- }
- }
-
+ // nothing to do
return TUSB_ERROR_NONE;
}
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h
index 855421eca..a2238473d 100644
--- a/src/class/hid/hid_device.h
+++ b/src/class/hid/hid_device.h
@@ -57,12 +57,11 @@
* @{ */
/** \brief Check if the interface is currently busy or not
- * \param[in] rhport USB Controller ID
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to host
* \note This function is primarily used for polling/waiting result after \ref tusbd_hid_keyboard_send.
*/
-bool tud_hid_keyboard_busy(uint8_t rhport);
+bool tud_hid_keyboard_busy(void);
/** \brief Submit USB transfer
* \param[in] rhport USB Controller ID
@@ -75,29 +74,17 @@ bool tud_hid_keyboard_busy(uint8_t rhport);
* \note This function is non-blocking and returns immediately. Data will be transferred when USB Host work with this interface.
* The result of usb transfer will be reported by the interface's callback function
*/
-tusb_error_t tud_hid_keyboard_send(uint8_t rhport, hid_keyboard_report_t const *p_report);
+tusb_error_t tud_hid_keyboard_send(hid_keyboard_report_t const *p_report);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK API
//--------------------------------------------------------------------+
-/** \brief Callback function that is invoked when an transferring event occurred
- * after invoking \ref tusbd_hid_keyboard_send
- * \param[in] rhport USB Controller ID
- * \param[in] event an value from \ref tusb_event_t
- * \note event can be one of following
- * - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
- * - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
- * - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
- */
-void tud_hid_keyboard_cb(uint8_t rhport, tusb_event_t event, uint32_t xferred_bytes);
-
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_GET_REPORT
* via control endpoint.
- * \param[in] rhport USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
- * \param[out] pp_report pointer to buffer that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM)
- * \param[in] requested_length number of bytes that host requested
+ * \param[out] buffer data that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM)
+ * \param[in] reqlen number of bytes that host requested
* \retval non-zero Actual number of bytes in the response's buffer.
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
* sending STALL in the data phase.
@@ -105,18 +92,17 @@ void tud_hid_keyboard_cb(uint8_t rhport, tusb_event_t event, uint32_t xferred_by
* the completion of this control request will not be reported to application.
* For Keyboard, USB host often uses this to turn on/off the LED for CAPLOCKS, NUMLOCK (\ref hid_keyboard_led_bm_t)
*/
-uint16_t tud_hid_keyboard_get_report_cb(uint8_t rhport, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length);
+ATTR_WEAK uint16_t tud_hid_keyboard_get_report_cb(hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_SET_REPORT
* via control endpoint.
- * \param[in] rhport USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
- * \param[in] p_report_data buffer containing the report's data
- * \param[in] length number of bytes in the \a p_report_data
+ * \param[in] buffer containing the report's data
+ * \param[in] bufsize number of bytes in the \a buffer
* \note By the time this callback is invoked, the USB control transfer is already completed in the hardware side.
* Application are free to handle data at its own will.
*/
-void tud_hid_keyboard_set_report_cb(uint8_t rhport, hid_request_report_type_t report_type, uint8_t p_report_data[], uint16_t length);
+ATTR_WEAK void tud_hid_keyboard_set_report_cb(hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
/** @} */
/** @} */
@@ -130,15 +116,13 @@ void tud_hid_keyboard_set_report_cb(uint8_t rhport, hid_request_report_type_t re
* @{ */
/** \brief Check if the interface is currently busy or not
- * \param[in] rhport USB Controller ID
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to host
* \note This function is primarily used for polling/waiting result after \ref tusbd_hid_mouse_send.
*/
-bool tud_hid_mouse_is_busy(uint8_t rhport);
+bool tud_hid_mouse_is_busy(void);
/** \brief Perform transfer queuing
- * \param[in] rhport USB Controller ID
* \param[in,out] p_report address that is used to store data from device. Must be accessible by usb controller (see \ref CFG_TUSB_ATTR_USBRAM)
* \returns \ref tusb_error_t type to indicate success or error condition.
* \retval TUSB_ERROR_NONE on success
@@ -148,47 +132,34 @@ bool tud_hid_mouse_is_busy(uint8_t rhport);
* \note This function is non-blocking and returns immediately. Data will be transferred when USB Host work with this interface.
* The result of usb transfer will be reported by the interface's callback function
*/
-tusb_error_t tud_hid_mouse_send(uint8_t rhport, hid_mouse_report_t const *p_report);
+tusb_error_t tud_hid_mouse_send(hid_mouse_report_t const *p_report);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK API
//--------------------------------------------------------------------+
-/** \brief Callback function that is invoked when an transferring event occurred
- * after invoking \ref tusbd_hid_mouse_send
- * \param[in] rhport USB Controller ID
- * \param[in] event an value from \ref tusb_event_t
- * \note event can be one of following
- * - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully.
- * - TUSB_EVENT_XFER_ERROR : previously scheduled transfer encountered a transaction error.
- * - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device.
- */
-void tud_hid_mouse_cb(uint8_t rhport, tusb_event_t event, uint32_t xferred_bytes);
-
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_GET_REPORT
* via control endpoint.
- * \param[in] rhport USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
- * \param[out] pp_report pointer to buffer that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM)
- * \param[in] requested_length number of bytes that host requested
+ * \param[out] buffer buffer that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM)
+ * \param[in] reqlen number of bytes that host requested
* \retval non-zero Actual number of bytes in the response's buffer.
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
* sending STALL in the data phase.
* \note After this callback, the request is silently executed by the tinyusb stack, thus
* the completion of this control request will not be reported to application
*/
-uint16_t tud_hid_mouse_get_report_cb(uint8_t rhport, hid_request_report_type_t report_type, void** pp_report, uint16_t requested_length);
+ATTR_WEAK uint16_t tud_hid_mouse_get_report_cb(hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_SET_REPORT
* via control endpoint.
- * \param[in] rhport USB Controller ID
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
- * \param[in] p_report_data buffer containing the report's data
- * \param[in] length number of bytes in the \a p_report_data
+ * \param[in] buffer buffer containing the report's data
+ * \param[in] bufsize number of bytes in the \a p_report_data
* \note By the time this callback is invoked, the USB control transfer is already completed in the hardware side.
* Application are free to handle data at its own will.
*/
-void tud_hid_mouse_set_report_cb(uint8_t rhport, hid_request_report_type_t report_type, uint8_t p_report_data[], uint16_t length);
+ATTR_WEAK void tud_hid_mouse_set_report_cb(hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
/** @} */
/** @} */
diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c
index fe0b7748b..fa617c5b0 100644
--- a/src/class/hid/hid_host.c
+++ b/src/class/hid/hid_host.c
@@ -200,7 +200,7 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_
//------------- SET IDLE (0) request -------------//
STASK_INVOKE(
usbh_control_xfer_subtask( dev_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_INTERFACE),
- HID_REQUEST_CONTROL_SET_IDLE, 0, p_interface_desc->bInterfaceNumber,
+ HID_REQ_CONTROL_SET_IDLE, 0, p_interface_desc->bInterfaceNumber,
0, NULL ),
error
);
diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c
index b0839ecb0..f32a1f833 100644
--- a/src/class/msc/msc_device.c
+++ b/src/class/msc/msc_device.c
@@ -38,7 +38,7 @@
#include "tusb_option.h"
-#if (MODE_DEVICE_SUPPORTED && CFG_TUD_MSC)
+#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_MSC)
//--------------------------------------------------------------------+
// INCLUDE