summaryrefslogtreecommitdiff
path: root/src
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
parent141ac25e3b3aaf72a50ace257d2bda41d1ebe702 (diff)
reworking device hid class driver
Diffstat (limited to 'src')
-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
-rw-r--r--src/device/usbd.c4
-rw-r--r--src/device/usbd.h10
-rw-r--r--src/device/usbd_desc.c453
-rw-r--r--src/portable/nordic/nrf5x/dcd_nrf5x.c2
-rw-r--r--src/portable/nordic/nrf5x/hal_nrf5x.c2
-rw-r--r--src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c2
-rw-r--r--src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c2
-rw-r--r--src/portable/nxp/lpc17xx/hal_lpc175x_6x.c4
-rw-r--r--src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c2
-rw-r--r--src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c4
-rw-r--r--src/tusb.c4
-rw-r--r--src/tusb.h4
-rw-r--r--src/tusb_option.h30
20 files changed, 506 insertions, 438 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
diff --git a/src/device/usbd.c b/src/device/usbd.c
index e8dfd83dd..2aabd1892 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -38,7 +38,7 @@
#include "tusb_option.h"
-#if MODE_DEVICE_SUPPORTED
+#if TUSB_OPT_DEVICE_ENABLED
#define _TINY_USB_SOURCE_FILE_
@@ -116,7 +116,7 @@ static usbd_class_driver_t const usbd_class_drivers[] =
#endif
- #if DEVICE_CLASS_HID
+ #if TUD_OPT_HID_ENABLED
{
.class_code = TUSB_CLASS_HID,
.init = hidd_init,
diff --git a/src/device/usbd.h b/src/device/usbd.h
index 7fc440637..c2b05f8ff 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -59,10 +59,16 @@
/// \brief Descriptor pointer collector to all the needed.
typedef struct {
- uint8_t const * device; ///< pointer to device descriptor \ref tusb_desc_device_t
+ void const * device; ///< pointer to device descriptor \ref tusb_desc_device_t
uint8_t const * config; ///< pointer to the whole configuration descriptor, starting by \ref tusb_desc_configuration_t
uint8_t const** string_arr; ///< a array of pointers to string descriptors
- uint8_t const * hid_report; ///< pointer to HID report descriptor only needed if CFG_TUD_HID_* is enabled
+
+ struct {
+ uint8_t const* composite;
+ uint8_t const* boot_keyboard;
+ uint8_t const* boot_mouse;
+ } hid_report;
+
}tud_desc_set_t;
diff --git a/src/device/usbd_desc.c b/src/device/usbd_desc.c
index d672ddfaf..c2674d11a 100644
--- a/src/device/usbd_desc.c
+++ b/src/device/usbd_desc.c
@@ -36,7 +36,7 @@
#include "tusb_option.h"
-#if MODE_DEVICE_SUPPORTED
+#if TUSB_OPT_DEVICE_ENABLED
#define _TINY_USB_SOURCE_FILE_
@@ -60,7 +60,7 @@
*/
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
#define CFG_TUD_DESC_PID (0x8000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | \
- _PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) | _PID_MAP(HID_GENERIC, 4) )
+ _PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) )
#endif
/*------------- Interface Numbering -------------*/
@@ -69,43 +69,145 @@
*/
#define ITF_NUM_CDC 0
-#define ITF_NUM_MSC (ITF_NUM_CDC + 2*CFG_TUD_CDC)
+#define ITF_NUM_MSC (ITF_NUM_CDC + 2*CFG_TUD_CDC)
-#define ITF_NUM_HID_KEYBOARD (ITF_NUM_MSC + CFG_TUD_MSC )
-#define ITF_NUM_HID_MOUSE (ITF_NUM_HID_KEYBOARD + CFG_TUD_HID_KEYBOARD )
-#define ITF_NUM_HID_GENERIC (ITF_NUM_HID_MOUSE + CFG_TUD_HID_MOUSE )
+#define ITF_NUM_HID_KBD (ITF_NUM_MSC + CFG_TUD_MSC)
+#define ITF_NUM_HID_MSE (ITF_NUM_HID_KBD + CFG_TUD_HID_KEYBOARD)
-#define ITF_TOTAL (ITF_NUM_HID_GENERIC + CFG_TUD_HID_GENERIC)
+#define ITF_TOTAL (ITF_NUM_HID_MSE + CFG_TUD_HID_MOUSE)
/*------------- Endpoint Numbering & Size -------------*/
-#define _EP_IN(x) (0x80 | (x))
-#define _EP_OUT(x) (x)
+#define _EP_IN(x) (0x80 | (x))
+#define _EP_OUT(x) (x)
// CDC
-#define EP_CDC_NOTIF _EP_IN (ITF_NUM_CDC+1)
-#define EP_CDC_NOTIF_SIZE 8
+#define EP_CDC_NOTIF _EP_IN (ITF_NUM_CDC+1)
+#define EP_CDC_NOTIF_SIZE 8
-#define EP_CDC_OUT _EP_OUT(ITF_NUM_CDC+2)
-#define EP_CDC_IN _EP_IN (ITF_NUM_CDC+2)
+#define EP_CDC_OUT _EP_OUT(ITF_NUM_CDC+2)
+#define EP_CDC_IN _EP_IN (ITF_NUM_CDC+2)
// Mass Storage
-#define EP_MSC_OUT _EP_OUT(ITF_NUM_MSC+1)
-#define EP_MSC_IN _EP_IN (ITF_NUM_MSC+1)
+#define EP_MSC_OUT _EP_OUT(ITF_NUM_MSC+1)
+#define EP_MSC_IN _EP_IN (ITF_NUM_MSC+1)
-#if 0
+// Boot protocol each report has its own interface
+#if CFG_TUD_HID_BOOT_PROTOCOL
// HID Keyboard
-#define EP_HID_KBD _EP_IN (INTERFACE_NO_HID_KEYBOARD+1)
-#define EP_HID_KBD_SZIE 8
+#define EP_HID_KBD _EP_IN (ITF_NUM_HID_KBD+1)
+#define EP_HID_KBD_SIZE 8
// HID Mouse
-#define EP_HID_MSE _EP_IN (INTERFACE_NO_HID_MOUSE+1)
-#define EP_HID_MSE_SIZE 8
+#define EP_HID_MSE _EP_IN (ITF_NUM_HID_MSE+1)
+#define EP_HID_MSE_SIZE 8
+
+#else
+
+// HID composite = keyboard + mouse
+#define EP_HID_COMP _EP_IN (ITF_NUM_HID_KBD+1)
+#define EP_HID_COMP_SIZE 16
-// HID Generic
#endif
+// TODO HID Generic
+
+
+//--------------------------------------------------------------------+
+// Keyboard Report Descriptor
+//--------------------------------------------------------------------+
+#if CFG_TUD_HID_KEYBOARD
+uint8_t const _desc_auto_hid_kbd_report[] = {
+ HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
+ HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ),
+ HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
+ HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ),
+ HID_USAGE_MIN ( 224 ),
+ HID_USAGE_MAX ( 231 ),
+ HID_LOGICAL_MIN ( 0 ),
+ HID_LOGICAL_MAX ( 1 ),
+
+ HID_REPORT_SIZE ( 1 ),
+ HID_REPORT_COUNT ( 8 ), /* 8 bits */
+ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* maskable modifier key */
+
+ HID_REPORT_SIZE ( 8 ),
+ HID_REPORT_COUNT ( 1 ),
+ HID_INPUT ( HID_CONSTANT ), /* reserved */
+
+ HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ),
+ HID_USAGE_MIN ( 1 ),
+ HID_USAGE_MAX ( 5 ),
+ HID_REPORT_COUNT ( 5 ),
+ HID_REPORT_SIZE ( 1 ),
+ HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* 5-bit Led report */
+
+ HID_REPORT_SIZE ( 3 ), /* led padding */
+ HID_REPORT_COUNT ( 1 ),
+ HID_OUTPUT ( HID_CONSTANT ),
+
+ HID_USAGE_PAGE (HID_USAGE_PAGE_KEYBOARD),
+ HID_USAGE_MIN ( 0 ),
+ HID_USAGE_MAX ( 101 ),
+ HID_LOGICAL_MIN ( 0 ),
+ HID_LOGICAL_MAX ( 101 ),
+
+ HID_REPORT_SIZE ( 8 ),
+ HID_REPORT_COUNT ( 6 ),
+ HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ), /* keycodes array 6 items */
+ HID_COLLECTION_END
+};
+#endif
+
+//--------------------------------------------------------------------+
+// Mouse Report Descriptor
+//--------------------------------------------------------------------+
+#if CFG_TUD_HID_MOUSE
+uint8_t const _desc_auto_hid_mse_report[] = {
+ HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
+ HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ),
+ HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
+ HID_USAGE (HID_USAGE_DESKTOP_POINTER),
+
+ HID_COLLECTION ( HID_COLLECTION_PHYSICAL ),
+ HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ),
+ HID_USAGE_MIN ( 1 ),
+ HID_USAGE_MAX ( 3 ),
+ HID_LOGICAL_MIN ( 0 ),
+ HID_LOGICAL_MAX ( 1 ),
+
+ HID_REPORT_SIZE ( 1 ),
+ HID_REPORT_COUNT ( 3 ), /* Left, Right and Middle mouse*/
+ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
+
+ HID_REPORT_SIZE ( 5 ),
+ HID_REPORT_COUNT ( 1 ),
+ HID_INPUT ( HID_CONSTANT ), /* 5 bit padding followed 3 bit buttons */
+
+ HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
+ HID_USAGE ( HID_USAGE_DESKTOP_X ),
+ HID_USAGE ( HID_USAGE_DESKTOP_Y ),
+ HID_LOGICAL_MIN ( 0x81 ), /* -127 */
+ HID_LOGICAL_MAX ( 0x7f ), /* 127 */
+
+ HID_REPORT_SIZE ( 8 ),
+ HID_REPORT_COUNT ( 2 ), /* X, Y position */
+ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), /* relative values */
+
+ HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ), /* mouse scroll */
+ HID_LOGICAL_MIN ( 0x81 ), /* -127 */
+ HID_LOGICAL_MAX ( 0x7f ), /* 127 */
+ HID_REPORT_COUNT( 1 ),
+ HID_REPORT_SIZE ( 8 ), /* 8-bit value */
+ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), /* relative values */
+
+ HID_COLLECTION_END,
+
+ HID_COLLECTION_END
+};
+#endif
+
/*------------------------------------------------------------------*/
/* Auto generate descriptor
@@ -179,30 +281,52 @@ typedef struct ATTR_PACKED
}cdc;
#endif
-//------------- Mass Storage -------------//
+ //------------- Mass Storage -------------//
#if CFG_TUD_MSC
struct ATTR_PACKED
{
tusb_desc_interface_t itf;
tusb_desc_endpoint_t ep_out;
tusb_desc_endpoint_t ep_in;
- }msc;
+ } msc;
#endif
-#if 0
- //------------- HID Keyboard -------------//
+ //------------- HID -------------//
+#if CFG_TUD_HID_BOOT_PROTOCOL
+
#if CFG_TUD_HID_KEYBOARD
- tusb_desc_interface_t keyboard_interface;
- tusb_hid_descriptor_hid_t keyboard_hid;
- tusb_desc_endpoint_t keyboard_endpoint;
+ struct ATTR_PACKED
+ {
+ tusb_desc_interface_t itf;
+ tusb_hid_descriptor_hid_t hid_desc;
+ tusb_desc_endpoint_t ep_in;
+ } hid_kbd;
#endif
-//------------- HID Mouse -------------//
#if CFG_TUD_HID_MOUSE
- tusb_desc_interface_t mouse_interface;
- tusb_hid_descriptor_hid_t mouse_hid;
- tusb_desc_endpoint_t mouse_endpoint;
+ struct ATTR_PACKED
+ {
+ tusb_desc_interface_t itf;
+ tusb_hid_descriptor_hid_t hid_desc;
+ tusb_desc_endpoint_t ep_in;
+ } hid_mse;
+#endif
+
+#else
+
+#if CFG_TUD_HID_KEYBOARD || CFG_TUD_HID_MOUSE
+ struct ATTR_PACKED
+ {
+ tusb_desc_interface_t itf;
+ tusb_hid_descriptor_hid_t hid_desc;
+ tusb_desc_endpoint_t ep_in;
+
+ #if CFG_TUD_HID_KEYBOARD
+ tusb_desc_endpoint_t ep_out;
+ #endif
+ } hid_composite;
#endif
+
#endif
} desc_auto_cfg_t;
@@ -338,6 +462,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
#endif
#if CFG_TUD_MSC
+ //------------- Mass Storage-------------//
.msc =
{
.itf =
@@ -375,179 +500,137 @@ desc_auto_cfg_t const _desc_auto_config_struct =
},
#endif
-#if 0
- //------------- HID Keyboard -------------//
- #if CFG_TUD_HID_KEYBOARD
- .keyboard_interface =
- {
- .bLength = sizeof(tusb_desc_interface_t),
- .bDescriptorType = TUSB_DESC_INTERFACE,
- .bInterfaceNumber = ITF_NUM_HID_KEYBOARD,
- .bAlternateSetting = 0x00,
- .bNumEndpoints = 1,
- .bInterfaceClass = TUSB_CLASS_HID,
- .bInterfaceSubClass = HID_SUBCLASS_BOOT,
- .bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
- .iInterface = ITF_NUM_HID_KEYBOARD + 3,
- },
-
- .keyboard_hid =
- {
- .bLength = sizeof(tusb_hid_descriptor_hid_t),
- .bDescriptorType = HID_DESC_TYPE_HID,
- .bcdHID = 0x0111,
- .bCountryCode = HID_Local_NotSupported,
- .bNumDescriptors = 1,
- .bReportType = HID_DESC_TYPE_REPORT,
- .wReportLength = sizeof(desc_keyboard_report)
- },
+#if CFG_TUD_HID_BOOT_PROTOCOL
- .keyboard_endpoint =
+#if CFG_TUD_HID_KEYBOARD
+ .hid_kbd =
{
- .bLength = sizeof(tusb_desc_endpoint_t),
- .bDescriptorType = TUSB_DESC_ENDPOINT,
- .bEndpointAddress = EP_HID_KBD,
- .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
- .wMaxPacketSize = { .size = EP_HID_KBD_SZIE },
- .bInterval = 0x0A
- },
- #endif
+ .itf =
+ {
+ .bLength = sizeof(tusb_desc_interface_t),
+ .bDescriptorType = TUSB_DESC_INTERFACE,
+ .bInterfaceNumber = ITF_NUM_HID_KBD,
+ .bAlternateSetting = 0x00,
+ .bNumEndpoints = 2,
+ .bInterfaceClass = TUSB_CLASS_HID,
+ .bInterfaceSubClass = HID_SUBCLASS_BOOT,
+ .bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
+ .iInterface = 4 + CFG_TUD_CDC + CFG_TUD_MSC
+ },
- //------------- HID Mouse -------------//
- #if CFG_TUD_HID_MOUSE
- .mouse_interface =
- {
- .bLength = sizeof(tusb_desc_interface_t),
- .bDescriptorType = TUSB_DESC_INTERFACE,
- .bInterfaceNumber = ITF_NUM_HID_MOUSE,
- .bAlternateSetting = 0x00,
- .bNumEndpoints = 1,
- .bInterfaceClass = TUSB_CLASS_HID,
- .bInterfaceSubClass = HID_SUBCLASS_BOOT,
- .bInterfaceProtocol = HID_PROTOCOL_MOUSE,
- .iInterface = ITF_NUM_HID_MOUSE+3
- },
+ .hid_desc =
+ {
+ .bLength = sizeof(tusb_hid_descriptor_hid_t),
+ .bDescriptorType = HID_DESC_TYPE_HID,
+ .bcdHID = 0x0111,
+ .bCountryCode = HID_Local_NotSupported,
+ .bNumDescriptors = 1,
+ .bReportType = HID_DESC_TYPE_REPORT,
+ .wReportLength = sizeof(_desc_auto_hid_kbd_report)
+ },
- .mouse_hid =
- {
- .bLength = sizeof(tusb_hid_descriptor_hid_t),
- .bDescriptorType = HID_DESC_TYPE_HID,
- .bcdHID = 0x0111,
- .bCountryCode = HID_Local_NotSupported,
- .bNumDescriptors = 1,
- .bReportType = HID_DESC_TYPE_REPORT,
- .wReportLength = sizeof(desc_mouse_report)
+ .ep_in =
+ {
+ .bLength = sizeof(tusb_desc_endpoint_t),
+ .bDescriptorType = TUSB_DESC_ENDPOINT,
+ .bEndpointAddress = EP_HID_KBD,
+ .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
+ .wMaxPacketSize = { .size = EP_HID_KBD_SIZE },
+ .bInterval = 0x0A
+ }
},
+#endif // keyboard
- .mouse_endpoint =
+ //------------- HID Mouse -------------//
+#if CFG_TUD_HID_MOUSE
+ .hid_mse =
{
- .bLength = sizeof(tusb_desc_endpoint_t),
- .bDescriptorType = TUSB_DESC_ENDPOINT,
- .bEndpointAddress = EP_HID_MSE, // TODO
- .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
- .wMaxPacketSize = { .size = EP_HID_MSE_SIZE },
- .bInterval = 0x0A
- },
- #endif
-#endif
-};
-
-uint8_t const * const _desc_auto_config = (uint8_t const*) &_desc_auto_config_struct;
-
+ .itf =
+ {
+ .bLength = sizeof(tusb_desc_interface_t),
+ .bDescriptorType = TUSB_DESC_INTERFACE,
+ .bInterfaceNumber = ITF_NUM_HID_MSE,
+ .bAlternateSetting = 0x00,
+ .bNumEndpoints = 1,
+ .bInterfaceClass = TUSB_CLASS_HID,
+ .bInterfaceSubClass = HID_SUBCLASS_BOOT,
+ .bInterfaceProtocol = HID_PROTOCOL_MOUSE,
+ .iInterface = 4 + CFG_TUD_CDC + CFG_TUD_MSC + CFG_TUD_HID_KEYBOARD
+ },
-//--------------------------------------------------------------------+
-// Keyboard Report Descriptor
-//--------------------------------------------------------------------+
-#if CFG_TUD_HID_KEYBOARD
-uint8_t const desc_keyboard_report[] = {
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
- HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ),
- HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
- HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ),
- HID_USAGE_MIN ( 224 ),
- HID_USAGE_MAX ( 231 ),
- HID_LOGICAL_MIN ( 0 ),
- HID_LOGICAL_MAX ( 1 ),
+ .hid_desc =
+ {
+ .bLength = sizeof(tusb_hid_descriptor_hid_t),
+ .bDescriptorType = HID_DESC_TYPE_HID,
+ .bcdHID = 0x0111,
+ .bCountryCode = HID_Local_NotSupported,
+ .bNumDescriptors = 1,
+ .bReportType = HID_DESC_TYPE_REPORT,
+ .wReportLength = sizeof(_desc_auto_hid_mse_report)
+ },
- HID_REPORT_SIZE ( 1 ),
- HID_REPORT_COUNT ( 8 ), /* 8 bits */
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* maskable modifier key */
+ .ep_in =
+ {
+ .bLength = sizeof(tusb_desc_endpoint_t),
+ .bDescriptorType = TUSB_DESC_ENDPOINT,
+ .bEndpointAddress = EP_HID_MSE,
+ .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
+ .wMaxPacketSize = { .size = EP_HID_MSE_SIZE },
+ .bInterval = 0x0A
+ },
+ },
- HID_REPORT_SIZE ( 8 ),
- HID_REPORT_COUNT ( 1 ),
- HID_INPUT ( HID_CONSTANT ), /* reserved */
+#endif // mouse
- HID_USAGE_PAGE ( HID_USAGE_PAGE_LED ),
- HID_USAGE_MIN ( 1 ),
- HID_USAGE_MAX ( 5 ),
- HID_REPORT_COUNT ( 5 ),
- HID_REPORT_SIZE ( 1 ),
- HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ), /* 5-bit Led report */
+#else
- HID_REPORT_SIZE ( 3 ), /* led padding */
- HID_REPORT_COUNT ( 1 ),
- HID_OUTPUT ( HID_CONSTANT ),
+#if CFG_TUD_HID_KEYBOARD || CFG_TUD_HID_MOUSE
+ //------------- HID Keyboard + Mouse 9multiple reports) -------------//
+ .hid_composite =
+ {
+ .itf =
+ {
+ .bLength = sizeof(tusb_desc_interface_t),
+ .bDescriptorType = TUSB_DESC_INTERFACE,
+ .bInterfaceNumber = ITF_NUM_HID_KBD,
+ .bAlternateSetting = 0x00,
+ .bNumEndpoints = 2,
+ .bInterfaceClass = TUSB_CLASS_HID,
+ .bInterfaceSubClass = 0,
+ .bInterfaceProtocol = 0,
+ .iInterface = 4 + CFG_TUD_CDC + CFG_TUD_MSC,
+ },
- HID_USAGE_PAGE (HID_USAGE_PAGE_KEYBOARD),
- HID_USAGE_MIN ( 0 ),
- HID_USAGE_MAX ( 101 ),
- HID_LOGICAL_MIN ( 0 ),
- HID_LOGICAL_MAX ( 101 ),
+ .hid_desc =
+ {
+ .bLength = sizeof(tusb_hid_descriptor_hid_t),
+ .bDescriptorType = HID_DESC_TYPE_HID,
+ .bcdHID = 0x0111,
+ .bCountryCode = HID_Local_NotSupported,
+ .bNumDescriptors = 1,
+ .bReportType = HID_DESC_TYPE_REPORT,
+ .wReportLength = sizeof(_desc_auto_hid_composite_report)
+ },
- HID_REPORT_SIZE ( 8 ),
- HID_REPORT_COUNT ( 6 ),
- HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ), /* keycodes array 6 items */
- HID_COLLECTION_END
-};
+ .ep_in =
+ {
+ .bLength = sizeof(tusb_desc_endpoint_t),
+ .bDescriptorType = TUSB_DESC_ENDPOINT,
+ .bEndpointAddress = EP_HID_COMP,
+ .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
+ .wMaxPacketSize = { .size = EP_HID_COMP_SIZE },
+ .bInterval = 0x0A
+ }
+ }
#endif
-//--------------------------------------------------------------------+
-// Mouse Report Descriptor
-//--------------------------------------------------------------------+
-#if CFG_TUD_HID_MOUSE
-uint8_t const desc_mouse_report[] = {
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
- HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ),
- HID_COLLECTION ( HID_COLLECTION_APPLICATION ),
- HID_USAGE (HID_USAGE_DESKTOP_POINTER),
-
- HID_COLLECTION ( HID_COLLECTION_PHYSICAL ),
- HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ),
- HID_USAGE_MIN ( 1 ),
- HID_USAGE_MAX ( 3 ),
- HID_LOGICAL_MIN ( 0 ),
- HID_LOGICAL_MAX ( 1 ),
-
- HID_REPORT_SIZE ( 1 ),
- HID_REPORT_COUNT ( 3 ), /* Left, Right and Middle mouse*/
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),
-
- HID_REPORT_SIZE ( 5 ),
- HID_REPORT_COUNT ( 1 ),
- HID_INPUT ( HID_CONSTANT ), /* 5 bit padding followed 3 bit buttons */
-
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ),
- HID_USAGE ( HID_USAGE_DESKTOP_X ),
- HID_USAGE ( HID_USAGE_DESKTOP_Y ),
- HID_LOGICAL_MIN ( 0x81 ), /* -127 */
- HID_LOGICAL_MAX ( 0x7f ), /* 127 */
+#endif // boot protocol
+};
- HID_REPORT_SIZE ( 8 ),
- HID_REPORT_COUNT ( 2 ), /* X, Y position */
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), /* relative values */
+uint8_t const * const _desc_auto_config = (uint8_t const*) &_desc_auto_config_struct;
- HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ), /* mouse scroll */
- HID_LOGICAL_MIN ( 0x81 ), /* -127 */
- HID_LOGICAL_MAX ( 0x7f ), /* 127 */
- HID_REPORT_COUNT( 1 ),
- HID_REPORT_SIZE ( 8 ), /* 8-bit value */
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), /* relative values */
- HID_COLLECTION_END,
- HID_COLLECTION_END
-};
-#endif
#endif
diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c
index db424f650..5444a0e97 100644
--- a/src/portable/nordic/nrf5x/dcd_nrf5x.c
+++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c
@@ -36,7 +36,7 @@
#include "tusb_option.h"
-#if MODE_DEVICE_SUPPORTED && CFG_TUSB_MCU == OPT_MCU_NRF5X
+#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_NRF5X
#include "nrf.h"
#include "nrf_power.h"
diff --git a/src/portable/nordic/nrf5x/hal_nrf5x.c b/src/portable/nordic/nrf5x/hal_nrf5x.c
index 806d8f098..f04867676 100644
--- a/src/portable/nordic/nrf5x/hal_nrf5x.c
+++ b/src/portable/nordic/nrf5x/hal_nrf5x.c
@@ -36,7 +36,7 @@
#include "tusb_option.h"
-#if MODE_DEVICE_SUPPORTED && CFG_TUSB_MCU == OPT_MCU_NRF5X
+#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_NRF5X
#include "nrf.h"
#include "nrf_gpio.h"
diff --git a/src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c b/src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c
index a9f05f573..f0472f41d 100644
--- a/src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c
+++ b/src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c
@@ -38,7 +38,7 @@
#include "tusb_option.h"
-#if MODE_DEVICE_SUPPORTED && (CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13UXX)
+#if TUSB_OPT_DEVICE_ENABLED && (CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13UXX)
#define _TINY_USB_SOURCE_FILE_
diff --git a/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c b/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c
index 18947997f..948572129 100644
--- a/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c
+++ b/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c
@@ -38,7 +38,7 @@
#include "tusb_option.h"
-#if MODE_DEVICE_SUPPORTED && (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X)
+#if TUSB_OPT_DEVICE_ENABLED && (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X)
#define _TINY_USB_SOURCE_FILE_
//--------------------------------------------------------------------+
diff --git a/src/portable/nxp/lpc17xx/hal_lpc175x_6x.c b/src/portable/nxp/lpc17xx/hal_lpc175x_6x.c
index 5fa5ecfa0..de9d9a86e 100644
--- a/src/portable/nxp/lpc17xx/hal_lpc175x_6x.c
+++ b/src/portable/nxp/lpc17xx/hal_lpc175x_6x.c
@@ -80,7 +80,7 @@ bool tusb_hal_init(void)
LPC_USB->OTGStCtrl = 0x3;
#endif
-#if MODE_DEVICE_SUPPORTED
+#if TUSB_OPT_DEVICE_ENABLED
LPC_PINCON->PINSEL4 = bit_set_range(LPC_PINCON->PINSEL4, 18, 19, BIN8(01)); // P2_9 as USB Connect
// P1_30 as VBUS, ignore if it is already in VBUS mode
@@ -106,7 +106,7 @@ void USB_IRQHandler(void)
hal_hcd_isr(0);
#endif
- #if MODE_DEVICE_SUPPORTED
+ #if TUSB_OPT_DEVICE_ENABLED
hal_dcd_isr(0);
#endif
}
diff --git a/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c b/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c
index ef586c9e3..a08e20a3f 100644
--- a/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c
+++ b/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c
@@ -38,7 +38,7 @@
#include "tusb_option.h"
-#if MODE_DEVICE_SUPPORTED && CFG_TUSB_MCU == OPT_MCU_LPC43XX
+#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_LPC43XX
//--------------------------------------------------------------------+
// INCLUDE
diff --git a/src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c b/src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c
index a25710d3f..92f9f1cf0 100644
--- a/src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c
+++ b/src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c
@@ -136,7 +136,7 @@ void USB0_IRQHandler(void)
hal_hcd_isr(0);
#endif
- #if MODE_DEVICE_SUPPORTED
+ #if TUSB_OPT_DEVICE_ENABLED
hal_dcd_isr(0);
#endif
}
@@ -149,7 +149,7 @@ void USB1_IRQHandler(void)
hal_hcd_isr(1);
#endif
- #if MODE_DEVICE_SUPPORTED
+ #if TUSB_OPT_DEVICE_ENABLED
hal_dcd_isr(1);
#endif
}
diff --git a/src/tusb.c b/src/tusb.c
index fde29c24f..0ef1301a4 100644
--- a/src/tusb.c
+++ b/src/tusb.c
@@ -55,7 +55,7 @@ tusb_error_t tusb_init(void)
TU_ASSERT_ERR( usbh_init() ); // host stack init
#endif
-#if MODE_DEVICE_SUPPORTED
+#if TUSB_OPT_DEVICE_ENABLED
TU_ASSERT_ERR ( usbd_init() ); // device stack init
#endif
@@ -71,7 +71,7 @@ void tusb_task(void)
usbh_enumeration_task(NULL);
#endif
- #if MODE_DEVICE_SUPPORTED
+ #if TUSB_OPT_DEVICE_ENABLED
usbd_task(NULL);
#endif
}
diff --git a/src/tusb.h b/src/tusb.h
index 3f70546c8..8f25e2867 100644
--- a/src/tusb.h
+++ b/src/tusb.h
@@ -73,10 +73,10 @@
#endif
//------------- DEVICE -------------//
-#if MODE_DEVICE_SUPPORTED
+#if TUSB_OPT_DEVICE_ENABLED
#include "device/usbd.h"
- #if DEVICE_CLASS_HID
+ #if TUD_OPT_HID_ENABLED
#include "class/hid/hid_device.h"
#endif
diff --git a/src/tusb_option.h b/src/tusb_option.h
index 04374bc19..a7b18d504 100644
--- a/src/tusb_option.h
+++ b/src/tusb_option.h
@@ -77,9 +77,9 @@
/** \addtogroup group_configuration
* @{ */
-//--------------------------------------------------------------------+
+//--------------------------------------------------------------------
// CONTROLLER
-//--------------------------------------------------------------------+
+//--------------------------------------------------------------------
/** \defgroup group_mode Controller Mode Selection
* \brief CFG_TUSB_CONTROLLER_N_MODE must be defined with these
* @{ */
@@ -105,11 +105,11 @@
((CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE) ? 1 : 0))
#define MODE_HOST_SUPPORTED (CONTROLLER_HOST_NUMBER > 0)
-#define MODE_DEVICE_SUPPORTED (CONTROLLER_DEVICE_NUMBER > 0)
+#define TUSB_OPT_DEVICE_ENABLED (CONTROLLER_DEVICE_NUMBER > 0)
-#define TUD_RHPORT ((CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE) ? 0 : ((CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE) ? 1 : -1))
+#define TUD_OPT_RHPORT ((CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE) ? 0 : ((CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE) ? 1 : -1))
-#if !MODE_HOST_SUPPORTED && !MODE_DEVICE_SUPPORTED
+#if !MODE_HOST_SUPPORTED && !TUSB_OPT_DEVICE_ENABLED
#error please configure at least 1 CFG_TUSB_CONTROLLER_N_MODE to OPT_MODE_HOST and/or OPT_MODE_DEVICE
#endif
@@ -146,12 +146,12 @@
#define tu_free free
#endif
-//--------------------------------------------------------------------+
+//--------------------------------------------------------------------
// DEVICE OPTIONS
-//--------------------------------------------------------------------+
-#if MODE_DEVICE_SUPPORTED
+//--------------------------------------------------------------------
+#if TUSB_OPT_DEVICE_ENABLED
- #define DEVICE_CLASS_HID ( CFG_TUD_HID_KEYBOARD + CFG_TUD_HID_MOUSE + CFG_TUD_HID_GENERIC )
+ #define TUD_OPT_HID_ENABLED ( CFG_TUD_HID_KEYBOARD + CFG_TUD_HID_MOUSE )
#ifndef CFG_TUD_ENDOINT0_SIZE
#define CFG_TUD_ENDOINT0_SIZE 64
@@ -173,11 +173,11 @@
#define CFG_TUD_MSC 0
#endif
-#endif // MODE_DEVICE_SUPPORTED
+#endif // TUSB_OPT_DEVICE_ENABLED
-//--------------------------------------------------------------------+
+//--------------------------------------------------------------------
// HOST OPTIONS
-//--------------------------------------------------------------------+
+//--------------------------------------------------------------------
#if MODE_HOST_SUPPORTED
#ifndef CFG_TUSB_HOST_DEVICE_MAX
#define CFG_TUSB_HOST_DEVICE_MAX 1
@@ -203,9 +203,9 @@
#endif // MODE_HOST_SUPPORTED
-/*------------------------------------------------------------------*/
-/* Config Verification
- *------------------------------------------------------------------*/
+//------------------------------------------------------------------
+// Config Verification
+//------------------------------------------------------------------
#if (CFG_TUSB_OS != OPT_OS_NONE) && !defined (CFG_TUD_TASK_PRIO)
#error CFG_TUD_TASK_PRIO need to be defined (hint: use the highest if possible)