diff --git a/examples/device/device_virtual_com/src/tusb_config.h b/examples/device/device_virtual_com/src/tusb_config.h index 511b81b7..38930505 100644 --- a/examples/device/device_virtual_com/src/tusb_config.h +++ b/examples/device/device_virtual_com/src/tusb_config.h @@ -77,7 +77,6 @@ #define CFG_TUD_MSC 0 #define CFG_TUD_HID_KEYBOARD 0 #define CFG_TUD_HID_MOUSE 0 -#define CFG_TUD_HID_GENERIC 0 // not supported yet /*------------------------------------------------------------------*/ diff --git a/examples/device/nrf52840/src/tusb_config.h b/examples/device/nrf52840/src/tusb_config.h index 62c78841..da7dc793 100644 --- a/examples/device/nrf52840/src/tusb_config.h +++ b/examples/device/nrf52840/src/tusb_config.h @@ -43,61 +43,60 @@ extern "C" { #endif -//--------------------------------------------------------------------+ +//-------------------------------------------------------------------- // COMMON CONFIGURATION -//--------------------------------------------------------------------+ -#define CFG_TUSB_MCU OPT_MCU_NRF5X -#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE +//-------------------------------------------------------------------- +#define CFG_TUSB_MCU OPT_MCU_NRF5X +#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE -#define CFG_TUSB_DEBUG 2 +#define CFG_TUSB_DEBUG 2 /*------------- RTOS -------------*/ -#define CFG_TUSB_OS OPT_OS_NONE // be passed from IDE/command line for easy project switching +#define CFG_TUSB_OS OPT_OS_NONE // be passed from IDE/command line for easy project switching //#define CFG_TUD_TASK_PRIO 0 //#define CFG_TUD_TASK_QUEUE_SZ 16 //#define CFG_TUD_TASK_STACK_SZ 150 -//--------------------------------------------------------------------+ +//-------------------------------------------------------------------- // DEVICE CONFIGURATION -//--------------------------------------------------------------------+ +//-------------------------------------------------------------------- /*------------- Core -------------*/ -#define CFG_TUD_DESC_AUTO 1 +#define CFG_TUD_DESC_AUTO 1 // #define CFG_TUD_DESC_VID 0xCAFE // #define CFG_TUD_DESC_PID 0x0001 -#define CFG_TUD_ENDOINT0_SIZE 64 +#define CFG_TUD_ENDOINT0_SIZE 64 //------------- CLASS -------------// -#define CFG_TUD_CDC 1 -#define CFG_TUD_MSC 1 +#define CFG_TUD_CDC 1 +#define CFG_TUD_MSC 1 -#define CFG_TUD_HID_KEYBOARD 0 // TODO need update -#define CFG_TUD_HID_MOUSE 0 // TODO need update -#define CFG_TUD_HID_GENERIC 0 // TODO need update +#define CFG_TUD_HID_KEYBOARD 1 +#define CFG_TUD_HID_MOUSE 1 -/*------------------------------------------------------------------*/ -/* CDC DEVICE - *------------------------------------------------------------------*/ +//-------------------------------------------------------------------- +// CDC +//-------------------------------------------------------------------- // FIFO size of CDC TX and RX -#define CFG_TUD_CDC_RX_BUFSIZE 64 -#define CFG_TUD_CDC_TX_BUFSIZE 64 +#define CFG_TUD_CDC_RX_BUFSIZE 64 +#define CFG_TUD_CDC_TX_BUFSIZE 64 // TX is sent automatically every Start of Frame event. // If not enabled, application must call tud_cdc_write_flush() periodically #define CFG_TUD_CDC_FLUSH_ON_SOF 0 -/*------------------------------------------------------------------*/ -/* MSC DEVICE - *------------------------------------------------------------------*/ +//-------------------------------------------------------------------- +// MSC +//-------------------------------------------------------------------- // Number of supported Logical Unit Number (At least 1) -#define CFG_TUD_MSC_MAXLUN 1 +#define CFG_TUD_MSC_MAXLUN 1 // Buffer size of Device Mass storage -#define CFG_TUD_MSC_BUFSIZE 512 +#define CFG_TUD_MSC_BUFSIZE 512 // Number of Blocks #define CFG_TUD_MSC_BLOCK_NUM 16 @@ -114,9 +113,22 @@ // Product revision string included in Inquiry response, max 4 bytes #define CFG_TUD_MSC_PRODUCT_REV "1.0" -//--------------------------------------------------------------------+ +//-------------------------------------------------------------------- +// HID +//-------------------------------------------------------------------- + +/* Enable boot protocol will create separated HID interface for Keyboard, + * Consumer Key and Mouse --> require more In endpoints. Otherwise they + * are all packed into a single Multiple Report Interface. + * + * Note: If your device is meant to work with simple host running on + * an MCU (e.g with tinyusb host), boot protocol should be enabled. + */ +#define CFG_TUD_HID_BOOT_PROTOCOL 1 + +//-------------------------------------------------------------------- // USB RAM PLACEMENT -//--------------------------------------------------------------------+ +//-------------------------------------------------------------------- #define CFG_TUSB_ATTR_USBRAM #define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4) diff --git a/examples/device/nrf52840/src/tusb_descriptors.c b/examples/device/nrf52840/src/tusb_descriptors.c index e5d73333..c088fec7 100644 --- a/examples/device/nrf52840/src/tusb_descriptors.c +++ b/examples/device/nrf52840/src/tusb_descriptors.c @@ -57,11 +57,15 @@ uint16_t const * const string_desc_arr [] = // 3: Serials TODO use chip ID TUD_DESC_STRCONV('1', '2', '3', '4', '5', '6'), +#if CFG_TUD_CDC // 4: CDC Interface TUD_DESC_STRCONV('t','u','s','b',' ','c','d','c'), +#endif +#if CFG_TUD_MSC // 5: MSC Interface TUD_DESC_STRCONV('t','u','s','b',' ','m','s','c'), +#endif }; // tud_desc_set is required by tinyusb stack @@ -71,5 +75,11 @@ tud_desc_set_t tud_desc_set = .device = NULL, .config = NULL, .string_arr = (uint8_t const **) string_desc_arr, - .hid_report = NULL + + .hid_report = + { + .composite = NULL, + .boot_keyboard = NULL, + .boot_mouse = NULL + } }; diff --git a/examples/obsolete/device/src/keyboard_device_app.c b/examples/obsolete/device/src/keyboard_device_app.c index df9172c6..4e4de899 100644 --- a/examples/obsolete/device/src/keyboard_device_app.c +++ b/examples/obsolete/device/src/keyboard_device_app.c @@ -77,21 +77,21 @@ void tud_hid_keyboard_cb(uint8_t rhport, tusb_event_t event, uint32_t xferred_by } } -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) +uint16_t tud_hid_keyboard_get_report_cb(hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { // get other than input report is not supported by this keyboard demo - if ( report_type != HID_REQUEST_REPORT_INPUT ) return 0; + if ( report_type != HID_REPORT_TYPE_INPUT ) return 0; - (*pp_report) = &keyboard_report; - return requested_length; + memcpy(buffer, &keyboard_report, reqlen); + return reqlen; } -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) +void tud_hid_keyboard_set_report_cb(hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { // set other than output report is not supported by this keyboard demo - if ( report_type != HID_REQUEST_REPORT_OUTPUT ) return; + if ( report_type != HID_REPORT_TYPE_OUTPUT ) return; - uint8_t kbd_led = p_report_data[0]; + uint8_t kbd_led = buffer[0]; uint32_t interval_divider = 1; // each LED will reduce blinking interval by a half if (kbd_led & KEYBOARD_LED_NUMLOCK ) interval_divider *= 2; diff --git a/examples/obsolete/device/src/mouse_device_app.c b/examples/obsolete/device/src/mouse_device_app.c index 9bbb799d..d6145026 100644 --- a/examples/obsolete/device/src/mouse_device_app.c +++ b/examples/obsolete/device/src/mouse_device_app.c @@ -77,17 +77,12 @@ void tud_hid_mouse_cb(uint8_t rhport, tusb_event_t event, uint32_t xferred_bytes } } -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) +uint16_t tud_hid_mouse_get_report_cb(hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { - if ( report_type != HID_REQUEST_REPORT_INPUT ) return 0; // not support other report type for this mouse demo + if ( report_type != HID_REPORT_TYPE_INPUT ) return 0; // not support other report type for this mouse demo - (*pp_report) = &mouse_report; - return requested_length; -} - -void tud_hid_mouse_set_report_cb(uint8_t rhport, hid_request_report_type_t report_type, uint8_t report_data[], uint16_t length) -{ - // mouse demo does not support set report --> do nothing + memcpy(buffer, &mouse_report, reqlen); + return reqlen; } //--------------------------------------------------------------------+ diff --git a/examples/obsolete/device/src/tusb_config.h b/examples/obsolete/device/src/tusb_config.h index 8c8d3251..fc6807ae 100644 --- a/examples/obsolete/device/src/tusb_config.h +++ b/examples/obsolete/device/src/tusb_config.h @@ -72,11 +72,10 @@ #define CFG_TUD_ENDOINT0_SIZE 64 //------------- CLASS -------------// -#define CFG_TUD_HID_KEYBOARD 0 -#define CFG_TUD_HID_MOUSE 0 -#define CFG_TUD_HID_GENERIC 0 // not supported yet #define CFG_TUD_MSC 1 #define CFG_TUD_CDC 1 +#define CFG_TUD_HID_KEYBOARD 0 +#define CFG_TUD_HID_MOUSE 0 /*------------------------------------------------------------------*/ /* CLASS DRIVER diff --git a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c index 9fd6483a..196199d6 100644 --- a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c +++ b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c @@ -77,7 +77,7 @@ void board_init(void) //------------- BUTTON -------------// for(uint8_t i=0; iep_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 e4dc1a83..c895deb1 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 d53eb979..a12a1380 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 9f22697a..7b2c1da2 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 edpt_addr; - uint8_t interface_number; + uint8_t report_id; + uint16_t report_len; + uint8_t const * report_desc; + + // 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 + +CFG_TUSB_ATTR_USBRAM static hidd_interface_t _composite_itf; -#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 -#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 +static inline hidd_interface_t* get_interface_by_edpt(uint8_t ep_addr) +{ + 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 //--------------------------------------------------------------------+ -static void interface_clear(hidd_interface_t * p_interface) -{ - if ( p_interface != NULL ) - { - memclr_(p_interface, sizeof(hidd_interface_t)); - p_interface->interface_number = INTERFACE_INVALID_NUMBER; - } -} - void hidd_init(void) { - for(uint8_t i=0; ibDescriptorType, 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) { - interface_clear(hidd_class_driver[i].p_interface); +#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; + } + + return TUSB_ERROR_NONE; } tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request) { - uint8_t subclass_idx; - for(subclass_idx=0; subclass_idxwIndex == p_interface->interface_number) ) break; - } - - TU_ASSERT(subclass_idx < HIDD_NUMBER_OF_SUBCLASS, TUSB_ERROR_FAILED); - - hidd_class_driver_t const * const p_driver = &hidd_class_driver[subclass_idx]; - hidd_interface_t* const p_hid = p_driver->p_interface; + 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 ) + { - usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, p_buffer, actual_length); + } + + 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 + } + + 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; iedpt_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 855421ec..a2238473 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 fe0b7748..fa617c5b 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 b0839ecb..f32a1f83 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 e8dfd83d..2aabd189 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 7fc44063..c2b05f8f 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 d672ddfa..c2674d11 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 = +#if CFG_TUD_HID_BOOT_PROTOCOL + +#if CFG_TUD_HID_KEYBOARD + .hid_kbd = { - .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, + .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_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) + }, + + .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 + + //------------- HID Mouse -------------// +#if CFG_TUD_HID_MOUSE + .hid_mse = + { + .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 + }, + + .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) + }, + + .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 + }, }, - .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) - }, +#endif // mouse - .keyboard_endpoint = - { - .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 +#else - //------------- HID Mouse -------------// - #if CFG_TUD_HID_MOUSE - .mouse_interface = +#if CFG_TUD_HID_KEYBOARD || CFG_TUD_HID_MOUSE + //------------- HID Keyboard + Mouse 9multiple reports) -------------// + .hid_composite = { - .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 - }, + .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, + }, - .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) - }, + .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) + }, - .mouse_endpoint = - { - .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 + .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 + +#endif // boot protocol }; uint8_t const * const _desc_auto_config = (uint8_t const*) &_desc_auto_config_struct; -//--------------------------------------------------------------------+ -// 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_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_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 */ - - 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 #endif diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index db424f65..5444a0e9 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 806d8f09..f0486767 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 a9f05f57..f0472f41 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 18947997..94857212 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 5fa5ecfa..de9d9a86 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 ef586c9e..a08e20a3 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 a25710d3..92f9f1cf 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 fde29c24..0ef1301a 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 3f70546c..8f25e286 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 04374bc1..a7b18d50 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) diff --git a/tests/lpc175x_6x/test/test_usbd.c b/tests/lpc175x_6x/test/test_usbd.c index 5cb7c232..b70f4592 100644 --- a/tests/lpc175x_6x/test/test_usbd.c +++ b/tests/lpc175x_6x/test/test_usbd.c @@ -87,7 +87,7 @@ tusb_error_t stub_hidd_init(uint8_t coreid, tusb_desc_interface_t const* p_inter void class_init_epxect(void) { -#if DEVICE_CLASS_HID +#if TUD_OPT_HID_ENABLED hidd_init_StubWithCallback(stub_hidd_init); #endif } diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c b/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c index 2b109729..75c8f8a9 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c @@ -127,7 +127,7 @@ tusb_error_t stub_set_idle_request(uint8_t address, tusb_control_request_t const TEST_ASSERT_EQUAL(TUSB_DIR_HOST_TO_DEV , p_request->bmRequestType_bit.direction); TEST_ASSERT_EQUAL(TUSB_REQ_TYPE_CLASS , p_request->bmRequestType_bit.type); TEST_ASSERT_EQUAL(TUSB_REQ_RECIPIENT_INTERFACE , p_request->bmRequestType_bit.recipient); - TEST_ASSERT_EQUAL(HID_REQUEST_CONTROL_SET_IDLE , p_request->bRequest); + TEST_ASSERT_EQUAL(HID_REQ_CONTROL_SET_IDLE , p_request->bRequest); TEST_ASSERT_EQUAL(0 , p_request->wValue); TEST_ASSERT_EQUAL(p_kbd_interface_desc->bInterfaceNumber , p_request->wIndex); @@ -144,7 +144,7 @@ void test_keyboard_open_ok(void) hidh_init(); usbh_control_xfer_subtask_ExpectAndReturn(dev_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RECIPIENT_INTERFACE), - HID_REQUEST_CONTROL_SET_IDLE, 0, p_kbd_interface_desc->bInterfaceNumber, 0, NULL, + HID_REQ_CONTROL_SET_IDLE, 0, p_kbd_interface_desc->bInterfaceNumber, 0, NULL, TUSB_ERROR_NONE); hcd_pipe_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); tusbh_hid_keyboard_mounted_cb_Expect(dev_addr); diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c b/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c index 31349798..741f5442 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c @@ -115,7 +115,7 @@ void test_mouse_open_ok(void) hidh_init(); usbh_control_xfer_subtask_ExpectAndReturn(dev_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RECIPIENT_INTERFACE), - HID_REQUEST_CONTROL_SET_IDLE, 0, p_mouse_interface_desc->bInterfaceNumber, 0, NULL, + HID_REQ_CONTROL_SET_IDLE, 0, p_mouse_interface_desc->bInterfaceNumber, 0, NULL, TUSB_ERROR_NONE); hcd_pipe_open_ExpectAndReturn(dev_addr, p_mouse_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); tusbh_hid_mouse_mounted_cb_Expect(dev_addr); diff --git a/tests/support/tusb_config.h b/tests/support/tusb_config.h index 757ac7ba..e46d6f04 100644 --- a/tests/support/tusb_config.h +++ b/tests/support/tusb_config.h @@ -73,11 +73,10 @@ #define CFG_TUD_ENDOINT0_SIZE 64 //------------- CLASS -------------// +#define CFG_TUD_CDC 1 +#define CFG_TUD_MSC 1 #define CFG_TUD_HID_KEYBOARD 1 #define CFG_TUD_HID_MOUSE 1 -#define CFG_TUD_HID_GENERIC 0 -#define CFG_TUD_MSC 1 -#define CFG_TUD_CDC 1 //--------------------------------------------------------------------+