From 424735d44041fc478b572f973d997829b402153d Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 18 Jun 2018 14:05:24 +0700 Subject: rename subfolder source to src --- src/device/usbd.h | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/device/usbd.h (limited to 'src/device/usbd.h') diff --git a/src/device/usbd.h b/src/device/usbd.h new file mode 100644 index 000000000..8e4d9f1a0 --- /dev/null +++ b/src/device/usbd.h @@ -0,0 +1,114 @@ +/**************************************************************************/ +/*! + @file usbd.h + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2013, hathach (tinyusb.org) + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +/** \ingroup group_usbd + * @{ */ + +#ifndef _TUSB_USBD_H_ +#define _TUSB_USBD_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ +#include +#include "osal/osal.h" +#include "device/dcd.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ + +/// \brief Descriptor pointer collector to all the needed. +typedef struct { + uint8_t const * device; ///< pointer to device descriptor \ref tusb_desc_device_t + uint8_t const * configuration; ///< 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 * p_hid_keyboard_report; ///< pointer to HID report descriptor of Keyboard interface. Only needed if CFG_TUD_HID_KEYBOARD is enabled + uint8_t const * p_hid_mouse_report; ///< pointer to HID report descriptor of Mouse interface. Only needed if CFG_TUD_HID_MOUSE is enabled +}tud_desc_init_t; + +//--------------------------------------------------------------------+ +// APPLICATION API (Multiple Root Ports) +// Should be used only with MCU that support more than 1 ports +//--------------------------------------------------------------------+ +bool tud_n_mounted(uint8_t rhport); +bool tud_n_set_descriptors(uint8_t rhport, tud_desc_init_t const* desc_cfg); + +//--------------------------------------------------------------------+ +// APPLICATION API (Single Port) +// Should be used with MCU supporting only 1 USB port for code simplicity +//--------------------------------------------------------------------+ +static inline bool tud_mounted(void) +{ + return tud_n_mounted(0); +} + +static inline bool tud_set_descriptors(tud_desc_init_t const* desc_cfg) +{ + return tud_n_set_descriptors(0, desc_cfg); +} + +//--------------------------------------------------------------------+ +// APPLICATION CALLBACK +//--------------------------------------------------------------------+ +/** \brief Callback function that will be invoked device is mounted (configured) by USB host + * \param[in] rhport USB Controller ID of the interface + * \note This callback should be used by Application to \b set-up application data + */ +void tud_mount_cb(uint8_t rhport); + +/** \brief Callback function that will be invoked when device is unmounted (bus reset/unplugged) + * \param[in] rhport USB Controller ID of the interface + * \note This callback should be used by Application to \b tear-down application data + */ +void tud_umount_cb(uint8_t rhport); + +//void tud_device_suspended_cb(uint8_t rhport); + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_USBD_H_ */ + +/** @} */ -- cgit v1.3.1 From ff219f1f019a90df4a5e9de9632cbe057a4c35ef Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 1 Jul 2018 15:11:58 +0700 Subject: add CFG_TUD_DESC_AUTO for auto descritpor (device, config) --- .../device_virtual_com/src/tusb_descriptors.c | 6 +- .../device_virtual_com/src/tusb_descriptors.h | 2 +- examples/device/nrf52840/src/main.c | 1 - examples/device/nrf52840/src/tusb_config.h | 19 +- examples/device/nrf52840/src/tusb_descriptors.c | 211 +-------------------- examples/device/nrf52840/src/tusb_descriptors.h | 2 +- examples/obsolete/device/src/tusb_descriptors.h | 2 +- src/device/usbd.c | 70 +++---- src/device/usbd.h | 21 +- 9 files changed, 64 insertions(+), 270 deletions(-) (limited to 'src/device/usbd.h') diff --git a/examples/device/device_virtual_com/src/tusb_descriptors.c b/examples/device/device_virtual_com/src/tusb_descriptors.c index c28534738..85f8c12d8 100644 --- a/examples/device/device_virtual_com/src/tusb_descriptors.c +++ b/examples/device/device_virtual_com/src/tusb_descriptors.c @@ -202,7 +202,7 @@ app_descriptor_configuration_t const desc_configuration = #define ENDIAN_BE16_FROM( high, low) ENDIAN_BE16(high << 8 | low) // array of pointer to string descriptors -uint16_t const * const string_descriptor_arr [] = +uint16_t const * const string_desc_arr [] = { [0] = (uint16_t []) { // supported language ENDIAN_BE16_FROM( STRING_LEN_UNICODE(1), TUSB_DESC_STRING ), @@ -247,9 +247,9 @@ uint16_t const * const string_descriptor_arr [] = /*------------- Variable used by tud_set_descriptors -------------*/ -tud_desc_init_t usb_desc_init = +tud_desc_set_t usb_desc_init = { .device = (uint8_t const * ) &desc_device, .configuration = (uint8_t const * ) &desc_configuration, - .string_arr = (uint8_t const **) string_descriptor_arr, + .string_arr = (uint8_t const **) string_desc_arr, }; diff --git a/examples/device/device_virtual_com/src/tusb_descriptors.h b/examples/device/device_virtual_com/src/tusb_descriptors.h index a7c81e2b0..0c072fd40 100644 --- a/examples/device/device_virtual_com/src/tusb_descriptors.h +++ b/examples/device/device_virtual_com/src/tusb_descriptors.h @@ -100,6 +100,6 @@ typedef struct ATTR_PACKED -extern tud_desc_init_t usb_desc_init; +extern tud_desc_set_t usb_desc_init; #endif diff --git a/examples/device/nrf52840/src/main.c b/examples/device/nrf52840/src/main.c index 793f8b5b5..162d034eb 100644 --- a/examples/device/nrf52840/src/main.c +++ b/examples/device/nrf52840/src/main.c @@ -65,7 +65,6 @@ int main(void) print_greeting(); tusb_init(); - tud_set_descriptors(&usb_desc_init); while (1) { diff --git a/examples/device/nrf52840/src/tusb_config.h b/examples/device/nrf52840/src/tusb_config.h index 8e031ea3b..7d347a393 100644 --- a/examples/device/nrf52840/src/tusb_config.h +++ b/examples/device/nrf52840/src/tusb_config.h @@ -50,22 +50,25 @@ #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE #define CFG_TUSB_DEBUG 2 - #define CFG_TUSB_OS OPT_OS_NONE // be passed from IDE/command line for easy project switching -//#define CFG_TUD_TASK_PRIO 0 // be passed from IDE/command line for easy project switching - //--------------------------------------------------------------------+ // DEVICE CONFIGURATION //--------------------------------------------------------------------+ -#define CFG_TUD_ENDOINT0_SIZE 64 +//#define CFG_TUD_TASK_PRIO 0 // be passed from IDE/command line for easy project switching + +#define CFG_TUD_DESC_AUTO 1 + +// #define CFG_TUD_DESC_VID 0xCAFE +// #define CFG_TUD_DESC_PID 0x0001 //------------- 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_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 /*------------------------------------------------------------------*/ /* CLASS DRIVER diff --git a/examples/device/nrf52840/src/tusb_descriptors.c b/examples/device/nrf52840/src/tusb_descriptors.c index dec7bac26..995a54ef9 100644 --- a/examples/device/nrf52840/src/tusb_descriptors.c +++ b/examples/device/nrf52840/src/tusb_descriptors.c @@ -38,202 +38,6 @@ #include "tusb_descriptors.h" -//--------------------------------------------------------------------+ -// USB DEVICE DESCRIPTOR -//--------------------------------------------------------------------+ -tusb_desc_device_t const desc_device = -{ - .bLength = sizeof(tusb_desc_device_t), - .bDescriptorType = TUSB_DESC_DEVICE, - .bcdUSB = 0x0200, - - // Use Interface Association Descriptor (IAD) for CDC - // As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1) - .bDeviceClass = TUSB_CLASS_MISC, - .bDeviceSubClass = MISC_SUBCLASS_COMMON, - .bDeviceProtocol = MISC_PROTOCOL_IAD, - - .bMaxPacketSize0 = CFG_TUD_ENDOINT0_SIZE, - - .idVendor = CFG_VENDORID, - .idProduct = CFG_PRODUCTID, - .bcdDevice = 0x0100, - - .iManufacturer = 0x01, - .iProduct = 0x02, - .iSerialNumber = 0x03, - - .bNumConfigurations = 0x01 -}; - -//--------------------------------------------------------------------+ -// USB COFNIGURATION DESCRIPTOR -//--------------------------------------------------------------------+ -app_descriptor_configuration_t const desc_configuration = -{ - .configuration = - { - .bLength = sizeof(tusb_desc_configuration_t), - .bDescriptorType = TUSB_DESC_CONFIGURATION, - - .wTotalLength = sizeof(app_descriptor_configuration_t), - .bNumInterfaces = ITF_TOTAL, - - .bConfigurationValue = 1, - .iConfiguration = 0x00, - .bmAttributes = TUSB_DESC_CONFIG_ATT_BUS_POWER, - .bMaxPower = TUSB_DESC_CONFIG_POWER_MA(500) - }, - - // IAD points to CDC Interfaces - .cdc = - { - .iad = - { - .bLength = sizeof(tusb_desc_interface_assoc_t), - .bDescriptorType = TUSB_DESC_INTERFACE_ASSOCIATION, - - .bFirstInterface = ITF_NUM_CDC, - .bInterfaceCount = 2, - - .bFunctionClass = TUSB_CLASS_CDC, - .bFunctionSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, - .bFunctionProtocol = CDC_COMM_PROTOCOL_ATCOMMAND, - .iFunction = 0 - }, - - //------------- CDC Communication Interface -------------// - .comm_itf = - { - .bLength = sizeof(tusb_desc_interface_t), - .bDescriptorType = TUSB_DESC_INTERFACE, - .bInterfaceNumber = ITF_NUM_CDC, - .bAlternateSetting = 0, - .bNumEndpoints = 1, - .bInterfaceClass = TUSB_CLASS_CDC, - .bInterfaceSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, - .bInterfaceProtocol = CDC_COMM_PROTOCOL_ATCOMMAND, - .iInterface = 0x00 - }, - - .header = - { - .bLength = sizeof(cdc_desc_func_header_t), - .bDescriptorType = TUSB_DESC_CLASS_SPECIFIC, - .bDescriptorSubType = CDC_FUNC_DESC_HEADER, - .bcdCDC = 0x0120 - }, - - .call = - { - .bLength = sizeof(cdc_desc_func_call_management_t), - .bDescriptorType = TUSB_DESC_CLASS_SPECIFIC, - .bDescriptorSubType = CDC_FUNC_DESC_CALL_MANAGEMENT, - .bmCapabilities = { 0 }, - .bDataInterface = ITF_NUM_CDC+1, - }, - - .acm = - { - .bLength = sizeof(cdc_desc_func_acm_t), - .bDescriptorType = TUSB_DESC_CLASS_SPECIFIC, - .bDescriptorSubType = CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, - .bmCapabilities = { // 0x02 - .support_line_request = 1, - } - }, - - .union_func = - { - .bLength = sizeof(cdc_desc_func_union_t), // plus number of - .bDescriptorType = TUSB_DESC_CLASS_SPECIFIC, - .bDescriptorSubType = CDC_FUNC_DESC_UNION, - .bControlInterface = ITF_NUM_CDC, - .bSubordinateInterface = ITF_NUM_CDC+1, - }, - - .ep_notif = - { - .bLength = sizeof(tusb_desc_endpoint_t), - .bDescriptorType = TUSB_DESC_ENDPOINT, - .bEndpointAddress = CDC_EDPT_NOTIF, - .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT }, - .wMaxPacketSize = { .size = CDC_EDPT_NOTIF_SIZE }, - .bInterval = 0x10 - }, - - //------------- CDC Data Interface -------------// - .data_itf = - { - .bLength = sizeof(tusb_desc_interface_t), - .bDescriptorType = TUSB_DESC_INTERFACE, - .bInterfaceNumber = ITF_NUM_CDC+1, - .bAlternateSetting = 0x00, - .bNumEndpoints = 2, - .bInterfaceClass = TUSB_CLASS_CDC_DATA, - .bInterfaceSubClass = 0, - .bInterfaceProtocol = 0, - .iInterface = 0x00 - }, - - .ep_out = - { - .bLength = sizeof(tusb_desc_endpoint_t), - .bDescriptorType = TUSB_DESC_ENDPOINT, - .bEndpointAddress = CDC_EDPT_OUT, - .bmAttributes = { .xfer = TUSB_XFER_BULK }, - .wMaxPacketSize = { .size = CDC_EDPT_SIZE }, - .bInterval = 0 - }, - - .ep_in = - { - .bLength = sizeof(tusb_desc_endpoint_t), - .bDescriptorType = TUSB_DESC_ENDPOINT, - .bEndpointAddress = CDC_EDPT_IN, - .bmAttributes = { .xfer = TUSB_XFER_BULK }, - .wMaxPacketSize = { .size = CDC_EDPT_SIZE }, - .bInterval = 0 - }, - }, - - .msc = - { - .interface = - { - .bLength = sizeof(tusb_desc_interface_t), - .bDescriptorType = TUSB_DESC_INTERFACE, - .bInterfaceNumber = ITF_NUM_MSC, - .bAlternateSetting = 0x00, - .bNumEndpoints = 2, - .bInterfaceClass = TUSB_CLASS_MSC, - .bInterfaceSubClass = MSC_SUBCLASS_SCSI, - .bInterfaceProtocol = MSC_PROTOCOL_BOT, - .iInterface = 0x07 - }, - - .ep_out = - { - .bLength = sizeof(tusb_desc_endpoint_t), - .bDescriptorType = TUSB_DESC_ENDPOINT, - .bEndpointAddress = MSC_EDPT_OUT, - .bmAttributes = { .xfer = TUSB_XFER_BULK }, - .wMaxPacketSize = { .size = MSC_EDPT_SIZE}, - .bInterval = 1 - }, - - .ep_in = - { - .bLength = sizeof(tusb_desc_endpoint_t), - .bDescriptorType = TUSB_DESC_ENDPOINT, - .bEndpointAddress = MSC_EDPT_IN, - .bmAttributes = { .xfer = TUSB_XFER_BULK }, - .wMaxPacketSize = { .size = MSC_EDPT_SIZE}, - .bInterval = 1 - } - } -}; - //--------------------------------------------------------------------+ // STRING DESCRIPTORS //--------------------------------------------------------------------+ @@ -241,7 +45,7 @@ app_descriptor_configuration_t const desc_configuration = #define ENDIAN_BE16_FROM( high, low) ENDIAN_BE16(high << 8 | low) // array of pointer to string descriptors -uint16_t const * const string_descriptor_arr [] = +uint16_t const * const string_desc_arr [] = { [0] = (uint16_t []) { // supported language ENDIAN_BE16_FROM( STRING_LEN_UNICODE(1), TUSB_DESC_STRING ), @@ -284,11 +88,12 @@ uint16_t const * const string_descriptor_arr [] = } }; - -/*------------- Variable used by tud_set_descriptors -------------*/ -tud_desc_init_t usb_desc_init = +// tud_desc_set is required by tinyusb stack +// since CFG_TUD_DESC_AUTO is enabled, we only need to set string_arr +tud_desc_set_t tud_desc_set = { - .device = (uint8_t const * ) &desc_device, - .configuration = (uint8_t const * ) &desc_configuration, - .string_arr = (uint8_t const **) string_descriptor_arr, + .device = NULL, + .config = NULL, + .string_arr = (uint8_t const **) string_desc_arr, + .hid_report = NULL }; diff --git a/examples/device/nrf52840/src/tusb_descriptors.h b/examples/device/nrf52840/src/tusb_descriptors.h index bfa52a293..03aa66c49 100644 --- a/examples/device/nrf52840/src/tusb_descriptors.h +++ b/examples/device/nrf52840/src/tusb_descriptors.h @@ -115,6 +115,6 @@ typedef struct ATTR_PACKED -extern tud_desc_init_t usb_desc_init; +extern tud_desc_set_t usb_desc_init; #endif diff --git a/examples/obsolete/device/src/tusb_descriptors.h b/examples/obsolete/device/src/tusb_descriptors.h index c5c3f177f..83d8c665d 100644 --- a/examples/obsolete/device/src/tusb_descriptors.h +++ b/examples/obsolete/device/src/tusb_descriptors.h @@ -177,6 +177,6 @@ typedef struct ATTR_PACKED -extern tud_desc_init_t usb_desc_init; +extern tud_desc_set_t usb_desc_init; #endif diff --git a/src/device/usbd.c b/src/device/usbd.c index a58196583..31a53fc1d 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -72,24 +72,17 @@ typedef struct { void (* close ) (uint8_t); } usbd_class_driver_t; - -enum { - USBD_INTERFACE_NUM_MAX = 16 // USB specs specify up to 16 endpoints per device -}; - typedef struct { volatile uint8_t state; uint8_t config_num; - uint8_t interface2class[USBD_INTERFACE_NUM_MAX]; // determine interface number belongs to which class + uint8_t itf2class[16]; // determine interface number belongs to which class }usbd_device_info_t; //--------------------------------------------------------------------+ // Class & Device Driver //--------------------------------------------------------------------+ CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t usbd_enum_buffer[CFG_TUD_ENUM_BUFFER_SIZE]; - -tud_desc_init_t _usbd_descs[CONTROLLER_DEVICE_NUMBER]; usbd_device_info_t usbd_devices[CONTROLLER_DEVICE_NUMBER]; static usbd_class_driver_t const usbd_class_drivers[] = @@ -145,14 +138,6 @@ static usbd_class_driver_t const usbd_class_drivers[] = enum { USBD_CLASS_DRIVER_COUNT = sizeof(usbd_class_drivers) / sizeof(usbd_class_driver_t) }; -//tusb_desc_device_qualifier_t _device_qual = -//{ -// .bLength = sizeof(tusb_desc_device_qualifier_t), -// .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER, -// .bcdUSB = 0x0200, -// .bDeviceClass = -//}; - //--------------------------------------------------------------------+ // DCD Event @@ -216,12 +201,6 @@ bool tud_n_mounted(uint8_t rhport) return usbd_devices[rhport].state == TUSB_DEVICE_STATE_CONFIGURED; } -bool tud_n_set_descriptors(uint8_t rhport, tud_desc_init_t const* desc_cfg) -{ - _usbd_descs[rhport] = *desc_cfg; - return true; -} - //--------------------------------------------------------------------+ // IMPLEMENTATION //--------------------------------------------------------------------+ @@ -248,7 +227,6 @@ tusb_error_t usbd_init (void) osal_task_create(&_usbd_task_def); //------------- Core init -------------// - arrclr_( _usbd_descs ); //------------- class init -------------// for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) @@ -378,7 +356,7 @@ static tusb_error_t proc_control_request_st(uint8_t rhport, tusb_control_request else if ( TUSB_REQ_RCPT_INTERFACE == p_request->bmRequestType_bit.recipient) { static uint8_t drid; - uint8_t const class_code = usbd_devices[rhport].interface2class[ u16_low_u8(p_request->wIndex) ]; + uint8_t const class_code = usbd_devices[rhport].itf2class[ u16_low_u8(p_request->wIndex) ]; for (drid = 0; drid < USBD_CLASS_DRIVER_COUNT; drid++) { @@ -427,14 +405,19 @@ static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number) usbd_devices[rhport].config_num = config_number; //------------- parse configuration & open drivers -------------// - uint8_t const * p_desc_config = _usbd_descs[rhport].configuration; - TU_ASSERT(p_desc_config != NULL, TUSB_ERROR_DESCRIPTOR_CORRUPTED); +#if CFG_TUD_DESC_AUTO + extern uint8_t const * const _desc_auto_config; + uint8_t const * desc_cfg = _desc_auto_config; +#else + uint8_t const * desc_cfg = tud_desc_set.config; + TU_ASSERT(desc_cfg != NULL, TUSB_ERROR_DESCRIPTOR_CORRUPTED); +#endif - uint8_t const * p_desc = p_desc_config + sizeof(tusb_desc_configuration_t); + uint8_t const * p_desc = desc_cfg + sizeof(tusb_desc_configuration_t); - uint16_t const config_len = ((tusb_desc_configuration_t*)p_desc_config)->wTotalLength; + uint16_t const cfg_len = ((tusb_desc_configuration_t*)desc_cfg)->wTotalLength; - while( p_desc < p_desc_config + config_len ) + while( p_desc < desc_cfg + cfg_len ) { if ( TUSB_DESC_INTERFACE_ASSOCIATION == p_desc[DESCRIPTOR_OFFSET_TYPE]) { @@ -455,8 +438,8 @@ static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number) TU_ASSERT( drid < USBD_CLASS_DRIVER_COUNT, TUSB_ERROR_NOT_SUPPORTED_YET ); // Check duplicate interface number TODO support alternate setting - TU_ASSERT( 0 == usbd_devices[rhport].interface2class[p_desc_itf->bInterfaceNumber], TUSB_ERROR_FAILED); - usbd_devices[rhport].interface2class[p_desc_itf->bInterfaceNumber] = class_code; + TU_ASSERT( 0 == usbd_devices[rhport].itf2class[p_desc_itf->bInterfaceNumber], TUSB_ERROR_FAILED); + usbd_devices[rhport].itf2class[p_desc_itf->bInterfaceNumber] = class_code; uint16_t length=0; TU_ASSERT_ERR( usbd_class_drivers[drid].open( rhport, p_desc_itf, &length ) ); @@ -480,26 +463,33 @@ static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * co uint8_t const * desc_data = NULL ; uint16_t len = 0; - //------------- Descriptor Check -------------// - tud_desc_init_t const* descs = &_usbd_descs[rhport]; + tud_desc_set_t descs = tud_desc_set; + +#if CFG_TUD_DESC_AUTO + extern tusb_desc_device_t const _desc_auto_device; + extern uint8_t const * const _desc_auto_config; + + descs.device = (uint8_t const*) &_desc_auto_device; + descs.config = _desc_auto_config; +#endif switch(desc_type) { case TUSB_DESC_DEVICE: - desc_data = descs->device; + desc_data = descs.device; len = sizeof(tusb_desc_device_t); break; case TUSB_DESC_CONFIGURATION: - desc_data = descs->configuration; - len = ((tusb_desc_configuration_t*)descs->configuration)->wTotalLength; + desc_data = descs.config; + len = ((tusb_desc_configuration_t const*) desc_data)->wTotalLength; break; case TUSB_DESC_STRING: // windows sometimes ask for string at index 238 !!! if ( !(desc_index < 100) ) return 0; - desc_data = descs->string_arr[desc_index]; + desc_data = descs.string_arr[desc_index]; VERIFY( desc_data != NULL, 0 ); len = desc_data[0]; // first byte of descriptor is its size @@ -538,7 +528,7 @@ void dcd_bus_event(uint8_t rhport, usbd_bus_event_type_t bus_event) switch(bus_event) { case USBD_BUS_EVENT_RESET : - memclr_(&usbd_devices[rhport], sizeof(usbd_device_info_t)); + varclr_(&usbd_devices[rhport]); osal_queue_flush(_usbd_q); osal_semaphore_reset_isr(_usbd_ctrl_sem); for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) @@ -561,8 +551,8 @@ void dcd_bus_event(uint8_t rhport, usbd_bus_event_type_t bus_event) break; case USBD_BUS_EVENT_UNPLUGGED: - // invoke callback - tud_umount_cb(rhport); + varclr_(&usbd_devices[rhport]); + tud_umount_cb(rhport); // invoke callback break; case USBD_BUS_EVENT_SUSPENDED: diff --git a/src/device/usbd.h b/src/device/usbd.h index 8e4d9f1a0..e40c86577 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -59,20 +59,22 @@ /// \brief Descriptor pointer collector to all the needed. typedef struct { - uint8_t const * device; ///< pointer to device descriptor \ref tusb_desc_device_t - uint8_t const * configuration; ///< 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 * 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 +}tud_desc_set_t; + + +// Must be defined by application +extern tud_desc_set_t tud_desc_set; - uint8_t const * p_hid_keyboard_report; ///< pointer to HID report descriptor of Keyboard interface. Only needed if CFG_TUD_HID_KEYBOARD is enabled - uint8_t const * p_hid_mouse_report; ///< pointer to HID report descriptor of Mouse interface. Only needed if CFG_TUD_HID_MOUSE is enabled -}tud_desc_init_t; //--------------------------------------------------------------------+ // APPLICATION API (Multiple Root Ports) // Should be used only with MCU that support more than 1 ports //--------------------------------------------------------------------+ bool tud_n_mounted(uint8_t rhport); -bool tud_n_set_descriptors(uint8_t rhport, tud_desc_init_t const* desc_cfg); //--------------------------------------------------------------------+ // APPLICATION API (Single Port) @@ -83,11 +85,6 @@ static inline bool tud_mounted(void) return tud_n_mounted(0); } -static inline bool tud_set_descriptors(tud_desc_init_t const* desc_cfg) -{ - return tud_n_set_descriptors(0, desc_cfg); -} - //--------------------------------------------------------------------+ // APPLICATION CALLBACK //--------------------------------------------------------------------+ -- cgit v1.3.1 From 3134d21b24e74eacbee7874f53769d624a110132 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 12 Jul 2018 22:25:06 +0700 Subject: dropping multiple port device support --- src/device/usbd.c | 26 +++++++++++++------------- src/device/usbd.h | 15 ++------------- 2 files changed, 15 insertions(+), 26 deletions(-) (limited to 'src/device/usbd.h') diff --git a/src/device/usbd.c b/src/device/usbd.c index 31a53fc1d..60819bd58 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -83,7 +83,7 @@ typedef struct { // Class & Device Driver //--------------------------------------------------------------------+ CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t usbd_enum_buffer[CFG_TUD_ENUM_BUFFER_SIZE]; -usbd_device_info_t usbd_devices[CONTROLLER_DEVICE_NUMBER]; +static usbd_device_info_t _usbd_dev; static usbd_class_driver_t const usbd_class_drivers[] = { @@ -196,9 +196,9 @@ static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * co //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ -bool tud_n_mounted(uint8_t rhport) +bool tud_mounted(void) { - return usbd_devices[rhport].state == TUSB_DEVICE_STATE_CONFIGURED; + return _usbd_dev.state == TUSB_DEVICE_STATE_CONFIGURED; } //--------------------------------------------------------------------+ @@ -329,13 +329,13 @@ static tusb_error_t proc_control_request_st(uint8_t rhport, tusb_control_request } else if (TUSB_REQ_GET_CONFIGURATION == p_request->bRequest ) { - memcpy(usbd_enum_buffer, &usbd_devices[rhport].config_num, 1); + memcpy(usbd_enum_buffer, &_usbd_dev.config_num, 1); usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, (uint8_t*) usbd_enum_buffer, 1); } else if ( TUSB_REQ_SET_ADDRESS == p_request->bRequest ) { dcd_set_address(rhport, (uint8_t) p_request->wValue); - usbd_devices[rhport].state = TUSB_DEVICE_STATE_ADDRESSED; + _usbd_dev.state = TUSB_DEVICE_STATE_ADDRESSED; #if CFG_TUSB_MCU != OPT_MCU_NRF5X // nrf5x auto handle set address, we must not return status dcd_control_status(rhport, p_request->bmRequestType_bit.direction); @@ -356,7 +356,7 @@ static tusb_error_t proc_control_request_st(uint8_t rhport, tusb_control_request else if ( TUSB_REQ_RCPT_INTERFACE == p_request->bmRequestType_bit.recipient) { static uint8_t drid; - uint8_t const class_code = usbd_devices[rhport].itf2class[ u16_low_u8(p_request->wIndex) ]; + uint8_t const class_code = _usbd_dev.itf2class[ u16_low_u8(p_request->wIndex) ]; for (drid = 0; drid < USBD_CLASS_DRIVER_COUNT; drid++) { @@ -401,8 +401,8 @@ static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number) { dcd_set_config(rhport, config_number); - usbd_devices[rhport].state = TUSB_DEVICE_STATE_CONFIGURED; - usbd_devices[rhport].config_num = config_number; + _usbd_dev.state = TUSB_DEVICE_STATE_CONFIGURED; + _usbd_dev.config_num = config_number; //------------- parse configuration & open drivers -------------// #if CFG_TUD_DESC_AUTO @@ -438,8 +438,8 @@ static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number) TU_ASSERT( drid < USBD_CLASS_DRIVER_COUNT, TUSB_ERROR_NOT_SUPPORTED_YET ); // Check duplicate interface number TODO support alternate setting - TU_ASSERT( 0 == usbd_devices[rhport].itf2class[p_desc_itf->bInterfaceNumber], TUSB_ERROR_FAILED); - usbd_devices[rhport].itf2class[p_desc_itf->bInterfaceNumber] = class_code; + TU_ASSERT( 0 == _usbd_dev.itf2class[p_desc_itf->bInterfaceNumber], TUSB_ERROR_FAILED); + _usbd_dev.itf2class[p_desc_itf->bInterfaceNumber] = class_code; uint16_t length=0; TU_ASSERT_ERR( usbd_class_drivers[drid].open( rhport, p_desc_itf, &length ) ); @@ -528,7 +528,7 @@ void dcd_bus_event(uint8_t rhport, usbd_bus_event_type_t bus_event) switch(bus_event) { case USBD_BUS_EVENT_RESET : - varclr_(&usbd_devices[rhport]); + varclr_(&_usbd_dev); osal_queue_flush(_usbd_q); osal_semaphore_reset_isr(_usbd_ctrl_sem); for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) @@ -551,12 +551,12 @@ void dcd_bus_event(uint8_t rhport, usbd_bus_event_type_t bus_event) break; case USBD_BUS_EVENT_UNPLUGGED: - varclr_(&usbd_devices[rhport]); + varclr_(&_usbd_dev); tud_umount_cb(rhport); // invoke callback break; case USBD_BUS_EVENT_SUSPENDED: - usbd_devices[rhport].state = TUSB_DEVICE_STATE_SUSPENDED; + _usbd_dev.state = TUSB_DEVICE_STATE_SUSPENDED; break; default: break; diff --git a/src/device/usbd.h b/src/device/usbd.h index e40c86577..ac577bcef 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -69,21 +69,10 @@ typedef struct { // Must be defined by application extern tud_desc_set_t tud_desc_set; - -//--------------------------------------------------------------------+ -// APPLICATION API (Multiple Root Ports) -// Should be used only with MCU that support more than 1 ports -//--------------------------------------------------------------------+ -bool tud_n_mounted(uint8_t rhport); - //--------------------------------------------------------------------+ -// APPLICATION API (Single Port) -// Should be used with MCU supporting only 1 USB port for code simplicity +// APPLICATION API //--------------------------------------------------------------------+ -static inline bool tud_mounted(void) -{ - return tud_n_mounted(0); -} +bool tud_mounted(void); //--------------------------------------------------------------------+ // APPLICATION CALLBACK -- cgit v1.3.1 From 584b6f716dca8831b0483641d1a4e779b4bd5694 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 13 Jul 2018 14:26:40 +0700 Subject: more clean up --- examples/device/device_virtual_com/src/main.c | 4 ++-- examples/device/nrf52840/src/main.c | 4 ++-- examples/obsolete/device/src/main.c | 6 ++++-- src/device/usbd.c | 12 ++++++------ src/device/usbd.h | 8 +++----- 5 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/device/usbd.h') diff --git a/examples/device/device_virtual_com/src/main.c b/examples/device/device_virtual_com/src/main.c index 033d313eb..60f93a000 100644 --- a/examples/device/device_virtual_com/src/main.c +++ b/examples/device/device_virtual_com/src/main.c @@ -94,12 +94,12 @@ void virtual_com_task(void) //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void tud_mount_cb(uint8_t port) +void tud_mount_cb(void) { } -void tud_umount_cb(uint8_t port) +void tud_umount_cb(void) { } diff --git a/examples/device/nrf52840/src/main.c b/examples/device/nrf52840/src/main.c index 1ac56423d..e6a6388bf 100644 --- a/examples/device/nrf52840/src/main.c +++ b/examples/device/nrf52840/src/main.c @@ -95,12 +95,12 @@ void virtual_com_task(void) //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void tud_mount_cb(uint8_t rhport) +void tud_mount_cb(void) { } -void tud_umount_cb(uint8_t rhport) +void tud_umount_cb(void) { } diff --git a/examples/obsolete/device/src/main.c b/examples/obsolete/device/src/main.c index 5e053aa57..00633335a 100644 --- a/examples/obsolete/device/src/main.c +++ b/examples/obsolete/device/src/main.c @@ -111,15 +111,17 @@ int main(void) //--------------------------------------------------------------------+ // tinyusb callbacks //--------------------------------------------------------------------+ -void tud_mount_cb(uint8_t rhport) +void tud_mount_cb(void) { + uint8_t rhport = 0; // TODO remove cdc_serial_app_mount(rhport); keyboard_app_mount(rhport); msc_app_mount(rhport); } -void tud_umount_cb(uint8_t rhport) +void tud_umount_cb(void) { + uint8_t rhport = 0; // TODO remove cdc_serial_app_umount(rhport); keyboard_app_umount(rhport); msc_app_umount(rhport); diff --git a/src/device/usbd.c b/src/device/usbd.c index 971f7dd05..33b310d42 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -323,7 +323,7 @@ static tusb_error_t proc_control_request_st(uint8_t rhport, tusb_control_request { TU_ASSERT( len <= CFG_TUD_CTRL_BUFSIZE, TUSB_ERROR_NOT_ENOUGH_MEMORY); memcpy(_usbd_ctrl_buf, buffer, len); - usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, (uint8_t*) _usbd_ctrl_buf, len ); + usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, _usbd_ctrl_buf, len ); }else { dcd_control_stall(rhport); // stall unsupported descriptor @@ -332,7 +332,7 @@ static tusb_error_t proc_control_request_st(uint8_t rhport, tusb_control_request else if (TUSB_REQ_GET_CONFIGURATION == p_request->bRequest ) { memcpy(_usbd_ctrl_buf, &_usbd_dev.config_num, 1); - usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, (uint8_t*) _usbd_ctrl_buf, 1); + usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, _usbd_ctrl_buf, 1); } else if ( TUSB_REQ_SET_ADDRESS == p_request->bRequest ) { @@ -452,7 +452,7 @@ static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number) } // invoke callback - tud_mount_cb(rhport); + tud_mount_cb(); return TUSB_ERROR_NONE; } @@ -551,7 +551,7 @@ void dcd_bus_event(uint8_t rhport, usbd_bus_event_type_t bus_event) case USBD_BUS_EVENT_UNPLUGGED: varclr_(&_usbd_dev); - tud_umount_cb(rhport); // invoke callback + tud_umount_cb(); // invoke callback break; case USBD_BUS_EVENT_SUSPENDED: @@ -632,8 +632,8 @@ void usbd_defer_func(osal_task_func_t func, void* param, bool isr ) { usbd_task_event_t event = { - .rhport = 0, - .event_id = USBD_EVT_FUNC_CALL, + .rhport = 0, + .event_id = USBD_EVT_FUNC_CALL, }; event.func_call.func = func; diff --git a/src/device/usbd.h b/src/device/usbd.h index ac577bcef..7fc440637 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -78,18 +78,16 @@ bool tud_mounted(void); // APPLICATION CALLBACK //--------------------------------------------------------------------+ /** \brief Callback function that will be invoked device is mounted (configured) by USB host - * \param[in] rhport USB Controller ID of the interface * \note This callback should be used by Application to \b set-up application data */ -void tud_mount_cb(uint8_t rhport); +void tud_mount_cb(void); /** \brief Callback function that will be invoked when device is unmounted (bus reset/unplugged) - * \param[in] rhport USB Controller ID of the interface * \note This callback should be used by Application to \b tear-down application data */ -void tud_umount_cb(uint8_t rhport); +void tud_umount_cb(void); -//void tud_device_suspended_cb(uint8_t rhport); +//void tud_device_suspended_cb(void); #ifdef __cplusplus } -- cgit v1.3.1 From 4342325ee1359d3361acca6de4f8accf013e8e39 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 23 Jul 2018 15:25:45 +0700 Subject: reworking device hid class driver --- .../device/device_virtual_com/src/tusb_config.h | 1 - examples/device/nrf52840/src/tusb_config.h | 66 +-- examples/device/nrf52840/src/tusb_descriptors.c | 12 +- examples/obsolete/device/src/keyboard_device_app.c | 14 +- examples/obsolete/device/src/mouse_device_app.c | 13 +- examples/obsolete/device/src/tusb_config.h | 5 +- hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c | 2 +- src/class/cdc/cdc_device.c | 6 +- src/class/custom/custom_device.c | 2 +- src/class/hid/hid.h | 20 +- src/class/hid/hid_device.c | 328 ++++++++------- src/class/hid/hid_device.h | 61 +-- src/class/hid/hid_host.c | 2 +- src/class/msc/msc_device.c | 2 +- src/device/usbd.c | 4 +- src/device/usbd.h | 10 +- src/device/usbd_desc.c | 459 ++++++++++++--------- src/portable/nordic/nrf5x/dcd_nrf5x.c | 2 +- src/portable/nordic/nrf5x/hal_nrf5x.c | 2 +- .../nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c | 2 +- src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c | 2 +- src/portable/nxp/lpc17xx/hal_lpc175x_6x.c | 4 +- src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c | 2 +- src/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c | 4 +- src/tusb.c | 4 +- src/tusb.h | 4 +- src/tusb_option.h | 30 +- tests/lpc175x_6x/test/test_usbd.c | 2 +- .../test/host/hid/test_hidh_keyboard.c | 4 +- tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c | 2 +- tests/support/tusb_config.h | 5 +- 31 files changed, 579 insertions(+), 497 deletions(-) (limited to 'src/device/usbd.h') diff --git a/examples/device/device_virtual_com/src/tusb_config.h b/examples/device/device_virtual_com/src/tusb_config.h index 511b81b78..38930505b 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 62c788413..da7dc793b 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 e5d73333d..c088fec7f 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 df9172c68..4e4de8996 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 9bbb799df..d6145026a 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 8c8d32514..fc6807aef 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 9fd6483a6..196199d61 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 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; 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) { - 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; 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 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, - }, +#if CFG_TUD_HID_BOOT_PROTOCOL - .keyboard_hid = +#if CFG_TUD_HID_KEYBOARD + .hid_kbd = { - .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) + .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 - .keyboard_endpoint = + //------------- HID Mouse -------------// +#if CFG_TUD_HID_MOUSE + .hid_mse = { - .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 + .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 + }, }, - #endif - //------------- 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 - }, +#endif // mouse - .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) - }, +#else - .mouse_endpoint = +#if CFG_TUD_HID_KEYBOARD || CFG_TUD_HID_MOUSE + //------------- HID Keyboard + Mouse 9multiple reports) -------------// + .hid_composite = { - .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 + .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_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) + }, + + .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 -}; - -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 // boot protocol }; -#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 */ +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) diff --git a/tests/lpc175x_6x/test/test_usbd.c b/tests/lpc175x_6x/test/test_usbd.c index 5cb7c232d..b70f4592c 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 2b109729d..75c8f8a90 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 31349798d..741f54428 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 757ac7bac..e46d6f04d 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 //--------------------------------------------------------------------+ -- cgit v1.3.1 From 262be103e0478fc70fcc4e392c5ad1ad60bc074b Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 23 Jul 2018 16:12:14 +0700 Subject: add descriptor string count for tud_desc_set_t --- examples/device/nrf52840/src/tusb_descriptors.c | 4 +++- src/device/usbd.c | 18 +++++++++++------- src/device/usbd.h | 8 +++++--- 3 files changed, 19 insertions(+), 11 deletions(-) (limited to 'src/device/usbd.h') diff --git a/examples/device/nrf52840/src/tusb_descriptors.c b/examples/device/nrf52840/src/tusb_descriptors.c index b9d4332ee..7dc3642aa 100644 --- a/examples/device/nrf52840/src/tusb_descriptors.c +++ b/examples/device/nrf52840/src/tusb_descriptors.c @@ -85,7 +85,9 @@ tud_desc_set_t tud_desc_set = { .device = NULL, .config = NULL, - .string_arr = (uint8_t const **) string_desc_arr, + + .string_arr = (uint8_t const **) string_desc_arr, + .string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]), .hid_report = { diff --git a/src/device/usbd.c b/src/device/usbd.c index 0319ec8fd..7ae2f44c5 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -315,7 +315,7 @@ static void usbd_reset(uint8_t rhport) extern tusb_desc_device_t const _desc_auto_device; extern uint8_t const * const _desc_auto_config; - tud_desc_set.device = &_desc_auto_device; + tud_desc_set.device = (uint8_t const*) &_desc_auto_device; tud_desc_set.config = _desc_auto_config; #if CFG_TUD_HID_BOOT_PROTOCOL @@ -509,13 +509,17 @@ static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * co break; case TUSB_DESC_STRING: - // windows sometimes ask for string at index 238 !!! - if ( !(desc_index < 100) ) return 0; - - desc_data = tud_desc_set.string_arr[desc_index]; - VERIFY( desc_data != NULL, 0 ); + if ( desc_index < tud_desc_set.string_count ) + { + desc_data = tud_desc_set.string_arr[desc_index]; + VERIFY( desc_data != NULL, 0 ); - len = desc_data[0]; // first byte of descriptor is its size + len = desc_data[0]; // first byte of descriptor is its size + }else + { + // out of range + return 0; + } break; case TUSB_DESC_DEVICE_QUALIFIER: diff --git a/src/device/usbd.h b/src/device/usbd.h index c2b05f8ff..8413aa15e 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -59,9 +59,11 @@ /// \brief Descriptor pointer collector to all the needed. typedef struct { - 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 * 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 + uint16_t string_count; struct { uint8_t const* composite; -- cgit v1.3.1 From 9f61493020821ba7e3226e67b56a062501feb429 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 28 Jul 2018 12:38:45 +0700 Subject: change HID config, move HID boot config to part of auto descriptor only --- examples/device/nrf52840/src/tusb_config.h | 33 ++++++----- examples/device/nrf52840/src/tusb_descriptors.c | 2 +- src/class/hid/hid_device.c | 49 ++++++++++----- src/class/hid/hid_device.h | 34 ++++++++--- src/common/tusb_error.h | 2 + src/device/usbd.c | 6 +- src/device/usbd.h | 2 +- src/device/usbd_desc.c | 79 +++++++++++-------------- src/tusb.h | 2 +- src/tusb_option.h | 2 - tests/lpc175x_6x/test/test_usbd.c | 2 +- 11 files changed, 120 insertions(+), 93 deletions(-) (limited to 'src/device/usbd.h') diff --git a/examples/device/nrf52840/src/tusb_config.h b/examples/device/nrf52840/src/tusb_config.h index aad189429..9ef739bcd 100644 --- a/examples/device/nrf52840/src/tusb_config.h +++ b/examples/device/nrf52840/src/tusb_config.h @@ -61,33 +61,38 @@ // DEVICE CONFIGURATION //-------------------------------------------------------------------- -/*------------- Core -------------*/ +#define CFG_TUD_ENDOINT0_SIZE 64 + +/*------------- Descriptors -------------*/ + +/* Enable auto generated descriptor, tinyusb will try its best to create + * descriptor ( device, configuration, hid ) that matches enabled CFG_* in this file + * + * Note: All CFG_TUD_DESC_* are relevant only if CFG_TUD_DESC_AUTO is enabled + */ #define CFG_TUD_DESC_AUTO 1 +/* USB VID/PID if not defined, tinyusb to use default value + * Note: different class combination e.g CDC and (CDC + MSC) should have different + * PID since Host OS will "remembered" device driver after the first plug */ // #define CFG_TUD_DESC_VID 0xCAFE // #define CFG_TUD_DESC_PID 0x0001 -#define CFG_TUD_ENDOINT0_SIZE 64 +/* Use Boot Protocol for Keyboard, Mouse. Enable this will create separated HID interface + * require more IN endpoints. If disabled, they they are all packed into a single + * multiple report interface called "Generic". + */ +#define CFG_TUD_DESC_BOOT_KEYBOARD 1 +#define CFG_TUD_DESC_BOOT_MOUSE 1 //------------- CLASS -------------// #define CFG_TUD_CDC 1 #define CFG_TUD_MSC 1 +#define CFG_TUD_HID 1 #define CFG_TUD_HID_KEYBOARD 1 #define CFG_TUD_HID_MOUSE 1 -//#define CFG_TUD_HID_GENERIC 0 - -/* 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 -#define CFG_TUD_HID_KEYBOARD_BOOT 1 -#define CFG_TUD_HID_MOUSE_BOOT 1 //-------------------------------------------------------------------- // CDC diff --git a/examples/device/nrf52840/src/tusb_descriptors.c b/examples/device/nrf52840/src/tusb_descriptors.c index 7dc3642aa..2b219c87a 100644 --- a/examples/device/nrf52840/src/tusb_descriptors.c +++ b/examples/device/nrf52840/src/tusb_descriptors.c @@ -91,7 +91,7 @@ tud_desc_set_t tud_desc_set = .hid_report = { - .composite = NULL, + .generic = NULL, .boot_keyboard = NULL, .boot_mouse = NULL } diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index e58b7dc5c..bd9d800d1 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (TUSB_OPT_DEVICE_ENABLED && TUD_OPT_HID_ENABLED) +#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_HID) #define _TINY_USB_SOURCE_FILE_ //--------------------------------------------------------------------+ @@ -82,9 +82,16 @@ CFG_TUSB_ATTR_USBRAM static hidd_interface_t _kbd_itf; CFG_TUSB_ATTR_USBRAM static hidd_interface_t _mse_itf; #endif -#if 0 // CFG_TUD_HID_BOOT_PROTOCOL -CFG_TUSB_ATTR_USBRAM static hidd_interface_t _composite_itf; -#endif +CFG_TUSB_ATTR_USBRAM static hidd_interface_t _hidd_itf; + + +//--------------------------------------------------------------------+ +// HID GENERIC API +//--------------------------------------------------------------------+ +bool tud_hid_generic_ready(void) +{ + +} //--------------------------------------------------------------------+ // KEYBOARD APPLICATION API @@ -173,6 +180,7 @@ bool tud_hid_keyboard_key_sequence(const char* str, uint32_t interval_ms) } } + return true; } #endif // CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP @@ -268,23 +276,25 @@ void hidd_reset(uint8_t rhport) #endif } -tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_length) +tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_len) { 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); + TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType, ERR_TUD_INVALID_DESCRIPTOR); //------------- 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); + TU_ASSERT(TUSB_DESC_ENDPOINT == desc_edpt->bDescriptorType, ERR_TUD_INVALID_DESCRIPTOR); + + *p_len = 0; if (desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT) { - TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE); + TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE, ERR_TUD_INVALID_DESCRIPTOR); hidd_interface_t * p_hid = NULL; @@ -293,7 +303,6 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u { p_hid = &_kbd_itf; p_hid->report_desc = tud_desc_set.hid_report.boot_keyboard; - p_hid->boot_protocol = CFG_TUD_HID_KEYBOARD_BOOT; // default mode is BOOT if enabled p_hid->get_report_cb = tud_hid_keyboard_get_report_cb; p_hid->set_report_cb = tud_hid_keyboard_set_report_cb; } @@ -304,13 +313,12 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u { p_hid = &_mse_itf; p_hid->report_desc = tud_desc_set.hid_report.boot_mouse; - p_hid->boot_protocol = CFG_TUD_HID_MOUSE_BOOT; // default mode is BOOT if enabled 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); + TU_ASSERT(p_hid, ERR_TUD_INVALID_DESCRIPTOR); VERIFY(p_hid->report_desc, TUSB_ERROR_DESCRIPTOR_CORRUPTED); TU_ASSERT( dcd_edpt_open(rhport, desc_edpt), TUSB_ERROR_DCD_FAILED ); @@ -319,15 +327,26 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u p_hid->itf_num = desc_itf->bInterfaceNumber; p_hid->ep_in = desc_edpt->bEndpointAddress; p_hid->report_id = 0; + p_hid->boot_protocol = true; // default mode is BOOT - *p_length = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t); + *p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t); } else { // TODO HID generic + hidd_interface_t * p_hid = &_hidd_itf; + + p_hid->itf_num = desc_itf->bInterfaceNumber; + p_hid->ep_in = desc_edpt->bEndpointAddress; + // TODO parse report ID for keyboard, mouse - *p_length = 0; - return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE; + p_hid->report_id = 0; + p_hid->report_len = 0; + p_hid->report_desc = NULL; + //p_hid->get_report_cb = tud_hid_get_report_cb; + //p_hid->set_report_cb = tud_hid_set_report_cb; + + return ERR_TUD_INVALID_DESCRIPTOR; } return TUSB_ERROR_NONE; @@ -352,7 +371,7 @@ tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t cons { STASK_ASSERT ( p_hid->report_len <= CFG_TUD_CTRL_BUFSIZE ); - // use device control buffer (in USB SRAM) + // use device control buffer memcpy(_usbd_ctrl_buf, p_hid->report_desc, p_hid->report_len); usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, _usbd_ctrl_buf, p_hid->report_len); diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index e8f5b40f4..06c07d446 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -49,8 +49,19 @@ //--------------------------------------------------------------------+ -// KEYBOARD APPLICATION API +// HID GENERIC API //--------------------------------------------------------------------+ +bool tud_hid_generic_ready(void); +bool tud_hid_generic_report(void); + +/*------------- Callbacks -------------*/ +ATTR_WEAK uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); +ATTR_WEAK void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); + +//--------------------------------------------------------------------+ +// KEYBOARD API +//--------------------------------------------------------------------+ +#if CFG_TUD_HID_KEYBOARD /** \addtogroup ClassDriver_HID_Keyboard Keyboard * @{ */ /** \defgroup Keyboard_Device Device @@ -78,7 +89,9 @@ typedef struct{ extern const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128]; #endif -/*------------- Callbacks, ATTR_WEAK means optional -------------*/ +#endif + +/*------------- Callbacks -------------*/ /** Callback invoked when USB host request \ref HID_REQ_CONTROL_GET_REPORT. * \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests @@ -109,8 +122,9 @@ ATTR_WEAK void tud_hid_keyboard_set_report_cb(hid_report_type_t report_type, uin /** @} */ //--------------------------------------------------------------------+ -// MOUSE APPLICATION API +// MOUSE API //--------------------------------------------------------------------+ +#if CFG_TUD_HID_MOUSE /** \addtogroup ClassDriver_HID_Mouse Mouse * @{ */ /** \defgroup Mouse_Device Device @@ -141,10 +155,10 @@ static inline bool tud_hid_mouse_button_release(void) /*------------- Callbacks -------------*/ -/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_GET_REPORT - * via control endpoint. +/** + * Callback function that is invoked when USB host request \ref HID_REQ_CONTROL_GET_REPORT. * \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests - * \param[out] buffer buffer that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM) + * \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 @@ -154,8 +168,8 @@ static inline bool tud_hid_mouse_button_release(void) */ 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. +/** + * Callback function that is invoked when USB host request \ref HID_REQ_CONTROL_SET_REPORT. * \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests * \param[in] buffer buffer containing the report's data * \param[in] bufsize number of bytes in the \a p_report_data @@ -166,13 +180,15 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(hid_report_type_t report_type, uint8_ //ATTR_WEAK void tud_hid_mouse_set_protocol_cb(bool boot_protocol); +#endif + /** @} */ /** @} */ //--------------------------------------------------------------------+ -// USBD-CLASS DRIVER API +// INTERNAL API //--------------------------------------------------------------------+ #ifdef _TINY_USB_SOURCE_FILE_ diff --git a/src/common/tusb_error.h b/src/common/tusb_error.h index 339f6ced1..e7c7f69f9 100644 --- a/src/common/tusb_error.h +++ b/src/common/tusb_error.h @@ -91,6 +91,8 @@ ENTRY(TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED )\ ENTRY(TUSB_ERROR_NOT_ENOUGH_MEMORY )\ ENTRY(TUSB_ERROR_FAILED )\ + \ + ENTRY(ERR_TUD_INVALID_DESCRIPTOR) /// \brief Error Code returned diff --git a/src/device/usbd.c b/src/device/usbd.c index 8f406d0bd..f6b55a81d 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -116,7 +116,7 @@ static usbd_class_driver_t const usbd_class_drivers[] = #endif - #if TUD_OPT_HID_ENABLED + #if CFG_TUD_HID { .class_code = TUSB_CLASS_HID, .init = hidd_init, @@ -318,12 +318,12 @@ static void usbd_reset(uint8_t rhport) tud_desc_set.device = (uint8_t const*) &_desc_auto_device; tud_desc_set.config = _desc_auto_config; - #if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT + #if CFG_TUD_HID_KEYBOARD && CFG_TUD_DESC_BOOT_KEYBOARD extern uint8_t const _desc_auto_hid_kbd_report[]; tud_desc_set.hid_report.boot_keyboard = _desc_auto_hid_kbd_report; #endif - #if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT + #if CFG_TUD_HID_MOUSE && CFG_TUD_DESC_BOOT_MOUSE extern uint8_t const _desc_auto_hid_mse_report[]; tud_desc_set.hid_report.boot_mouse = _desc_auto_hid_mse_report; #endif diff --git a/src/device/usbd.h b/src/device/usbd.h index 8413aa15e..8ef1209e1 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -66,7 +66,7 @@ typedef struct { uint16_t string_count; struct { - uint8_t const* composite; + uint8_t const* generic; uint8_t const* boot_keyboard; uint8_t const* boot_mouse; } hid_report; diff --git a/src/device/usbd_desc.c b/src/device/usbd_desc.c index b1bb07809..1a37c6f58 100644 --- a/src/device/usbd_desc.c +++ b/src/device/usbd_desc.c @@ -47,9 +47,13 @@ #if CFG_TUD_DESC_AUTO +// Generic (multiple) Report : Keyboard + Mouse + Gamepad + Joystick +#define HID_GENERIC (CFG_TUD_HID && ( (CFG_TUD_HID_KEYBOARD && !CFG_TUD_DESC_BOOT_KEYBOARD) || \ + (CFG_TUD_HID_MOUSE && !CFG_TUD_DESC_BOOT_MOUSE) )) + /*------------- VID/PID -------------*/ #ifndef CFG_TUD_DESC_VID -#define CFG_TUD_DESC_VID 0xCAFE +#define CFG_TUD_DESC_VID 0xCAFE #endif #ifndef CFG_TUD_DESC_PID @@ -58,11 +62,11 @@ * Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC. * * Auto ProductID layout's Bitmap: - * [MSB] HID Generic | HID Composite | HID Mouse | HID Keyboard | MSC | CDC [LSB] + * [MSB] HID Generic | Boot Mouse | Boot Keyboard | MSC | CDC [LSB] */ -#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) ) -#define CFG_TUD_DESC_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | \ - _PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) /*| _PID_MAP(HID_GENERIC, 5)*/ ) +#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) ) +#define CFG_TUD_DESC_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \ + _PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) | (HID_GENERIC << 4) ) #endif /*------------- Interface Numbering -------------*/ @@ -76,8 +80,8 @@ #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_MSE + CFG_TUD_HID_MOUSE) - +#define ITF_NUM_HID_GEN (ITF_NUM_HID_MSE + CFG_TUD_HID_MOUSE) +#define ITF_TOTAL (ITF_NUM_HID_GEN + HID_GENERIC) /*------------- Endpoint Numbering & Size -------------*/ #define _EP_IN(x) (0x80 | (x)) @@ -96,23 +100,24 @@ // HID Keyboard with boot protocol -#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT +#if CFG_TUD_HID_KEYBOARD && CFG_TUD_DESC_BOOT_KEYBOARD #define EP_HID_KBD_BOOT _EP_IN (ITF_NUM_HID_KBD+1) #define EP_HID_KBD_BOOT_SZ 8 - #endif // HID Mouse with boot protocol -#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT +#if CFG_TUD_HID_MOUSE && CFG_TUD_DESC_BOOT_MOUSE #define EP_HID_MSE_BOOT _EP_IN (ITF_NUM_HID_MSE+1) #define EP_HID_MSE_BOOT_SZ 8 #endif -#if 0 // CFG_TUD_HID_BOOT_PROTOCOL + + +#if HID_GENERIC // HID composite = keyboard + mouse -#define EP_HID_COMP _EP_IN (ITF_NUM_HID_KBD+1) -#define EP_HID_COMP_SIZE 16 +#define EP_HID_GEN _EP_IN (EP_HID_MSE_BOOT+1) +#define EP_HID_GEN_SIZE 16 #endif @@ -307,7 +312,7 @@ typedef struct ATTR_PACKED #endif //------------- HID -------------// -#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT +#if CFG_TUD_HID_KEYBOARD && CFG_TUD_DESC_BOOT_KEYBOARD struct ATTR_PACKED { tusb_desc_interface_t itf; @@ -316,7 +321,7 @@ typedef struct ATTR_PACKED } hid_kbd_boot; #endif -#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT +#if CFG_TUD_HID_MOUSE && CFG_TUD_DESC_BOOT_MOUSE struct ATTR_PACKED { tusb_desc_interface_t itf; @@ -325,20 +330,18 @@ typedef struct ATTR_PACKED } hid_mse_boot; #endif -#if 0 // CFG_TUD_HID_BOOT_PROTOCOL +#if HID_GENERIC -#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 + #if 0 // CFG_TUD_HID_KEYBOARD tusb_desc_endpoint_t ep_out; #endif - } hid_composite; -#endif + } hid_generic; #endif @@ -513,7 +516,7 @@ desc_auto_cfg_t const _desc_auto_config_struct = }, #endif // msc -#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT +#if CFG_TUD_HID_KEYBOARD && CFG_TUD_DESC_BOOT_KEYBOARD .hid_kbd_boot = { .itf = @@ -553,7 +556,7 @@ desc_auto_cfg_t const _desc_auto_config_struct = #endif // boot keyboard //------------- HID Mouse -------------// -#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT +#if CFG_TUD_HID_MOUSE && CFG_TUD_DESC_BOOT_MOUSE .hid_mse_boot = { .itf = @@ -593,23 +596,22 @@ desc_auto_cfg_t const _desc_auto_config_struct = #endif // boot mouse -#if 0 +#if HID_GENERIC -#if CFG_TUD_HID_KEYBOARD || CFG_TUD_HID_MOUSE - //------------- HID Keyboard + Mouse (multiple reports) -------------// + //------------- HID Generic Multiple report -------------// .hid_composite = { .itf = { .bLength = sizeof(tusb_desc_interface_t), .bDescriptorType = TUSB_DESC_INTERFACE, - .bInterfaceNumber = ITF_NUM_HID_KBD, + .bInterfaceNumber = ITF_NUM_HID_GEN, .bAlternateSetting = 0x00, .bNumEndpoints = 2, .bInterfaceClass = TUSB_CLASS_HID, .bInterfaceSubClass = 0, .bInterfaceProtocol = 0, - .iInterface = 4 + CFG_TUD_CDC + CFG_TUD_MSC, + .iInterface = 0, // 4 + CFG_TUD_CDC + CFG_TUD_MSC, }, .hid_desc = @@ -620,41 +622,26 @@ desc_auto_cfg_t const _desc_auto_config_struct = .bCountryCode = HID_Local_NotSupported, .bNumDescriptors = 1, .bReportType = HID_DESC_TYPE_REPORT, - .wReportLength = sizeof(_desc_auto_hid_composite_report) + .wReportLength = sizeof(_desc_auto_hid_generic_report) }, .ep_in = { .bLength = sizeof(tusb_desc_endpoint_t), .bDescriptorType = TUSB_DESC_ENDPOINT, - .bEndpointAddress = EP_HID_COMP, + .bEndpointAddress = EP_HID_GEN, .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT }, - .wMaxPacketSize = { .size = EP_HID_COMP_SIZE }, + .wMaxPacketSize = { .size = EP_HID_GEN_SIZE }, .bInterval = 0x0A } } -#endif -#endif // boot protocol +#endif // hid generic }; uint8_t const * const _desc_auto_config = (uint8_t const*) &_desc_auto_config_struct; #endif -/*------------------------------------------------------------------*/ -/* MACRO TYPEDEF CONSTANT ENUM - *------------------------------------------------------------------*/ - -/*------------------------------------------------------------------*/ -/* VARIABLE DECLARATION - *------------------------------------------------------------------*/ - -/*------------------------------------------------------------------*/ -/* FUNCTION DECLARATION - *------------------------------------------------------------------*/ - - - #endif diff --git a/src/tusb.h b/src/tusb.h index 8f25e2867..01fdf5ed3 100644 --- a/src/tusb.h +++ b/src/tusb.h @@ -76,7 +76,7 @@ #if TUSB_OPT_DEVICE_ENABLED #include "device/usbd.h" - #if TUD_OPT_HID_ENABLED + #if CFG_TUD_HID #include "class/hid/hid_device.h" #endif diff --git a/src/tusb_option.h b/src/tusb_option.h index a7b18d504..251fb2470 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -151,8 +151,6 @@ //-------------------------------------------------------------------- #if TUSB_OPT_DEVICE_ENABLED - #define TUD_OPT_HID_ENABLED ( CFG_TUD_HID_KEYBOARD + CFG_TUD_HID_MOUSE ) - #ifndef CFG_TUD_ENDOINT0_SIZE #define CFG_TUD_ENDOINT0_SIZE 64 #endif diff --git a/tests/lpc175x_6x/test/test_usbd.c b/tests/lpc175x_6x/test/test_usbd.c index b70f4592c..1dd041a41 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 TUD_OPT_HID_ENABLED +#if CFG_TUD_HID hidd_init_StubWithCallback(stub_hidd_init); #endif } -- cgit v1.3.1 From 6d96b12e27ae60ca500365ee2137105145ada9dd Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 1 Aug 2018 00:50:04 +0700 Subject: improve auto descriptor --- src/class/hid/hid_device.c | 6 ++--- src/device/usbd.c | 43 +++++++++++------------------------ src/device/usbd.h | 4 ++-- src/device/usbd_auto_desc.c | 37 ++++++++++++++++++++++++------ src/device/usbd_pvt.h | 3 +++ src/portable/nordic/nrf5x/dcd_nrf5x.c | 3 +++ 6 files changed, 54 insertions(+), 42 deletions(-) (limited to 'src/device/usbd.h') diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 2616155b8..0527c14bf 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -346,7 +346,7 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD) { p_hid = &_hidd_itf[ITF_IDX_BOOT_KBD]; - p_hid->desc_report = tud_desc_set.hid_report.boot_keyboard; + p_hid->desc_report = usbd_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; @@ -362,7 +362,7 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE) { p_hid = &_hidd_itf[ITF_IDX_BOOT_MSE]; - p_hid->desc_report = tud_desc_set.hid_report.boot_mouse; + p_hid->desc_report = usbd_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; @@ -383,7 +383,7 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u // TODO parse report ID for keyboard, mouse p_hid = &_hidd_itf[ITF_IDX_GENERIC]; - p_hid->desc_report = tud_desc_set.hid_report.generic; + p_hid->desc_report = usbd_desc_set->hid_report.generic; p_hid->get_report_cb = tud_hid_generic_get_report_cb; p_hid->set_report_cb = tud_hid_generic_set_report_cb; diff --git a/src/device/usbd.c b/src/device/usbd.c index 5f83728ef..219562fa6 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -75,6 +75,15 @@ typedef struct { CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t _usbd_ctrl_buf[CFG_TUD_CTRL_BUFSIZE]; static usbd_device_t _usbd_dev; + +// Auto descriptor is enabled, descriptor set point to auto generated one +#if CFG_TUD_DESC_AUTO +extern tud_desc_set_t const _usbd_auto_desc_set; +tud_desc_set_t const* usbd_desc_set = &_usbd_auto_desc_set; +#else +tud_desc_set_t const* usbd_desc_set = &tud_desc_set; +#endif + //--------------------------------------------------------------------+ // Class Driver //--------------------------------------------------------------------+ @@ -310,33 +319,6 @@ static void usbd_reset(uint8_t rhport) { if ( usbd_class_drivers[i].reset ) usbd_class_drivers[i].reset( rhport ); } - -#if CFG_TUD_DESC_AUTO - extern tusb_desc_device_t const _desc_auto_device; - extern uint8_t const * const _desc_auto_config; - - tud_desc_set.device = (uint8_t const*) &_desc_auto_device; - tud_desc_set.config = _desc_auto_config; - -#if CFG_TUD_HID - #if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT - extern uint8_t const _desc_auto_hid_boot_kbd_report[]; - tud_desc_set.hid_report.boot_keyboard = _desc_auto_hid_boot_kbd_report; - #endif - - #if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT - extern uint8_t const _desc_auto_hid_boot_mse_report[]; - tud_desc_set.hid_report.boot_mouse = _desc_auto_hid_boot_mse_report; - #endif - - #if TUD_OPT_HID_GENERIC - extern uint8_t const _desc_auto_hid_generic_report[]; - tud_desc_set.hid_report.generic = _desc_auto_hid_generic_report; - #endif -#endif // CFG_TUD_HID - -#endif // CFG_TUD_DESC_AUTO - } //--------------------------------------------------------------------+ @@ -452,7 +434,7 @@ static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number) _usbd_dev.config_num = config_number; //------------- parse configuration & open drivers -------------// - uint8_t const * desc_cfg = tud_desc_set.config; + uint8_t const * desc_cfg = (uint8_t const *) usbd_desc_set->config; TU_ASSERT(desc_cfg != NULL, TUSB_ERROR_DESCRIPTOR_CORRUPTED); uint8_t const * p_desc = desc_cfg + sizeof(tusb_desc_configuration_t); uint16_t const cfg_len = ((tusb_desc_configuration_t*)desc_cfg)->wTotalLength; @@ -511,16 +493,17 @@ static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * co switch(desc_type) { case TUSB_DESC_DEVICE: - desc_data = tud_desc_set.device; + desc_data = (uint8_t const *) usbd_desc_set->device; len = sizeof(tusb_desc_device_t); break; case TUSB_DESC_CONFIGURATION: - desc_data = tud_desc_set.config; + desc_data = (uint8_t const *) usbd_desc_set->config; len = ((tusb_desc_configuration_t const*) desc_data)->wTotalLength; break; case TUSB_DESC_STRING: + // String Descriptor always uses the desc set from user if ( desc_index < tud_desc_set.string_count ) { desc_data = tud_desc_set.string_arr[desc_index]; diff --git a/src/device/usbd.h b/src/device/usbd.h index 8ef1209e1..1e59c0a7e 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -59,8 +59,8 @@ /// \brief Descriptor pointer collector to all the needed. typedef struct { - uint8_t 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 + void const * device; ///< pointer to device descriptor \ref tusb_desc_device_t + void 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 uint16_t string_count; diff --git a/src/device/usbd_auto_desc.c b/src/device/usbd_auto_desc.c index eaa866af0..a42af1ef5 100644 --- a/src/device/usbd_auto_desc.c +++ b/src/device/usbd_auto_desc.c @@ -49,8 +49,8 @@ // Auto Description Default Configure & Validation //--------------------------------------------------------------------+ -// IF HID Generic is required, it is multiple Report : Keyboard + Mouse + Gamepad + Joystick -#define TUD_OPT_HID_GENERIC (CFG_TUD_HID && ((CFG_TUD_HID_KEYBOARD && !CFG_TUD_HID_KEYBOARD_BOOT) || \ +// If HID Generic interface is generated +#define AUTO_DESC_HID_GENERIC (CFG_TUD_HID && ((CFG_TUD_HID_KEYBOARD && !CFG_TUD_HID_KEYBOARD_BOOT) || \ (CFG_TUD_HID_MOUSE && !CFG_TUD_HID_MOUSE_BOOT)) ) /*------------- VID/PID -------------*/ #ifndef CFG_TUD_DESC_VID @@ -67,7 +67,7 @@ */ #define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) ) #define CFG_TUD_DESC_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \ - _PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) | (TUD_OPT_HID_GENERIC << 4) ) + _PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) | (AUTO_DESC_HID_GENERIC << 4) ) #endif //--------------------------------------------------------------------+ @@ -85,7 +85,7 @@ #define ITF_NUM_HID_BOOT_MSE (ITF_NUM_HID_BOOT_KBD + CFG_TUD_HID_KEYBOARD_BOOT) #define ITF_NUM_HID_GEN (ITF_NUM_HID_BOOT_MSE + CFG_TUD_HID_MOUSE_BOOT) -#define ITF_TOTAL (ITF_NUM_HID_GEN + TUD_OPT_HID_GENERIC) +#define ITF_TOTAL (ITF_NUM_HID_GEN + AUTO_DESC_HID_GENERIC) /*------------- Endpoint Numbering & Size -------------*/ #define _EP_IN(x) (0x80 | (x)) @@ -132,7 +132,7 @@ uint8_t const _desc_auto_hid_boot_mse_report[] = { HID_REPORT_DESC_MOUSE() }; /*------------- Generic (composite) Descriptor -------------*/ -#if TUD_OPT_HID_GENERIC +#if AUTO_DESC_HID_GENERIC // Report ID: 0 if there is only 1 report // starting from 1 if there is multiple reports @@ -255,7 +255,7 @@ typedef struct ATTR_PACKED } hid_mse_boot; #endif -#if TUD_OPT_HID_GENERIC +#if AUTO_DESC_HID_GENERIC struct ATTR_PACKED { @@ -521,7 +521,7 @@ desc_auto_cfg_t const _desc_auto_config_struct = #endif // boot mouse -#if TUD_OPT_HID_GENERIC +#if AUTO_DESC_HID_GENERIC //------------- HID Generic Multiple report -------------// .hid_generic = @@ -566,6 +566,29 @@ desc_auto_cfg_t const _desc_auto_config_struct = uint8_t const * const _desc_auto_config = (uint8_t const*) &_desc_auto_config_struct; +tud_desc_set_t const _usbd_auto_desc_set = +{ + .device = &_desc_auto_device, + .config = &_desc_auto_config_struct, + + .hid_report = + { +#if AUTO_DESC_HID_GENERIC + .generic = _desc_auto_hid_generic_report, +#else + .generic = NULL, +#endif + +#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT + .boot_keyboard = _desc_auto_hid_boot_kbd_report, +#endif + +#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT + .boot_mouse = _desc_auto_hid_boot_mse_report +#endif + } +}; + #endif diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index 205057db6..707e8036f 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -48,6 +48,9 @@ extern osal_semaphore_t _usbd_ctrl_sem; extern uint8_t _usbd_ctrl_buf[CFG_TUD_CTRL_BUFSIZE]; +// Either point to tud_desc_set or usbd_auto_desc_set depending on CFG_TUD_DESC_AUTO +extern tud_desc_set_t const* usbd_desc_set; + //--------------------------------------------------------------------+ // INTERNAL API for stack management //--------------------------------------------------------------------+ diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 339b8df1f..b9bd6ef1a 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -46,6 +46,9 @@ #include "nrf_clock.h" #include "device/dcd.h" + +// TODO remove later +#include "device/usbd.h" #include "device/usbd_pvt.h" // to use defer function helper /*------------------------------------------------------------------*/ -- cgit v1.3.1 From 030c64b9cd7ea7ea0a9686f6436ed84736ff80b4 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 24 Aug 2018 18:35:46 +0700 Subject: make tud_mount_cb() and tud_umount_cb() optional --- src/device/usbd.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'src/device/usbd.h') diff --git a/src/device/usbd.h b/src/device/usbd.h index 1e59c0a7e..f9e0d8f4d 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -83,17 +83,14 @@ extern tud_desc_set_t tud_desc_set; bool tud_mounted(void); //--------------------------------------------------------------------+ -// APPLICATION CALLBACK +// APPLICATION CALLBACK (WEAK is optional) //--------------------------------------------------------------------+ -/** \brief Callback function that will be invoked device is mounted (configured) by USB host - * \note This callback should be used by Application to \b set-up application data - */ -void tud_mount_cb(void); - -/** \brief Callback function that will be invoked when device is unmounted (bus reset/unplugged) - * \note This callback should be used by Application to \b tear-down application data - */ -void tud_umount_cb(void); + +/** Callback invoked when device is mounted (configured) */ +ATTR_WEAK void tud_mount_cb(void); + +/** Callback invoked when device is unmounted (bus reset/unplugged) */ +ATTR_WEAK void tud_umount_cb(void); //void tud_device_suspended_cb(void); -- cgit v1.3.1