From a08cb6e7274d307f704dafabbebbb7dd9ca73f30 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 1 Jul 2018 15:54:40 +0700 Subject: [PATCH] clean up --- examples/device/device_virtual_com/src/main.c | 2 - .../device_virtual_com/src/tusb_config.h | 48 ++++- .../device_virtual_com/src/tusb_descriptors.c | 171 +----------------- .../device_virtual_com/src/tusb_descriptors.h | 105 ----------- examples/device/nrf52840/src/tusb_config.h | 2 +- src/class/msc/msc_device.c | 4 +- src/tusb_option.h | 7 - 7 files changed, 52 insertions(+), 287 deletions(-) delete mode 100644 examples/device/device_virtual_com/src/tusb_descriptors.h diff --git a/examples/device/device_virtual_com/src/main.c b/examples/device/device_virtual_com/src/main.c index 8145d018..531733cd 100644 --- a/examples/device/device_virtual_com/src/main.c +++ b/examples/device/device_virtual_com/src/main.c @@ -45,7 +45,6 @@ #include "bsp/board.h" #include "tusb.h" -#include "tusb_descriptors.h" //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF @@ -65,7 +64,6 @@ int main(void) print_greeting(); tusb_init(); - tud_set_descriptors(&usb_desc_init); while (1) { diff --git a/examples/device/device_virtual_com/src/tusb_config.h b/examples/device/device_virtual_com/src/tusb_config.h index 16b93234..a69d2ecb 100644 --- a/examples/device/device_virtual_com/src/tusb_config.h +++ b/examples/device/device_virtual_com/src/tusb_config.h @@ -51,25 +51,47 @@ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE) //#define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE) +#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_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_VID 0xCAFE +// #define CFG_TUD_DESC_PID 0x0001 + #define CFG_TUD_ENDOINT0_SIZE 64 + //------------- CLASS -------------// +#define CFG_TUD_CDC 1 +#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 -#define CFG_TUD_MSC 0 -#define CFG_TUD_CDC 1 -//--------------------------------------------------------------------+ -// COMMON CONFIGURATION -//--------------------------------------------------------------------+ -#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 +/*------------------------------------------------------------------*/ +/* CLASS DRIVER + *------------------------------------------------------------------*/ + +// FIFO size of CDC TX and RX +#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_flush() periodically +#define CFG_TUD_CDC_FLUSH_ON_SOF 1 //--------------------------------------------------------------------+ // USB RAM PLACEMENT @@ -115,6 +137,16 @@ #endif +// LPC11uxx and LPC13uxx requires each buffer has to be 64-byte alignment +#if CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13UXX + #define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(64) +#elif CFG_TUSB_MCU == OPT_MCU_NRF5X + #define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4) +#else + #define CFG_TUSB_MEM_ALIGN +#endif + + #ifdef __cplusplus } #endif diff --git a/examples/device/device_virtual_com/src/tusb_descriptors.c b/examples/device/device_virtual_com/src/tusb_descriptors.c index 85f8c12d..2ba5434c 100644 --- a/examples/device/device_virtual_com/src/tusb_descriptors.c +++ b/examples/device/device_virtual_com/src/tusb_descriptors.c @@ -36,164 +36,7 @@ */ /**************************************************************************/ -#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 -------------// - .cdc_comm_interface = - { - .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 - }, - - .cdc_header = - { - .bLength = sizeof(cdc_desc_func_header_t), - .bDescriptorType = TUSB_DESC_CLASS_SPECIFIC, - .bDescriptorSubType = CDC_FUNC_DESC_HEADER, - .bcdCDC = 0x0120 - }, - - .cdc_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, - }, - - .cdc_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, - } - }, - - .cdc_union = - { - .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, - }, - - .cdc_endpoint_notification = - { - .bLength = sizeof(tusb_desc_endpoint_t), - .bDescriptorType = TUSB_DESC_ENDPOINT, - .bEndpointAddress = CDC_EDPT_NOTIF, - .bmAttributes = { .xfer = TUSB_XFER_INTERRUPT }, - .wMaxPacketSize = { .size = 0x08 }, - .bInterval = 0x10 - }, - - //------------- CDC Data Interface -------------// - .cdc_data_interface = - { - .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 - }, - - .cdc_endpoint_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 - }, - - .cdc_endpoint_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 - }, -}; +#include "tusb.h" //--------------------------------------------------------------------+ // STRING DESCRIPTORS @@ -246,10 +89,12 @@ uint16_t const * const string_desc_arr [] = }; -/*------------- Variable used by tud_set_descriptors -------------*/ -tud_desc_set_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_desc_arr, + .device = NULL, + .config = NULL, + .string_arr = (uint8_t const **) string_desc_arr, + .hid_report = NULL }; diff --git a/examples/device/device_virtual_com/src/tusb_descriptors.h b/examples/device/device_virtual_com/src/tusb_descriptors.h deleted file mode 100644 index 0c072fd4..00000000 --- a/examples/device/device_virtual_com/src/tusb_descriptors.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************/ -/*! - @file tusb_descriptors.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. -*/ -/**************************************************************************/ - -#ifndef _TUSB_DESCRIPTORS_H_ -#define _TUSB_DESCRIPTORS_H_ - -#include "tusb.h" - -//--------------------------------------------------------------------+ -// Descriptors Value (calculated by enabled Classes) -//--------------------------------------------------------------------+ -#define CFG_VENDORID 0xCAFE -//#define CFG_PRODUCTID 0x4567 // use auto product id to prevent conflict with pc's driver - -// each combination of interfaces need to have a unique productid, as windows will bind & remember device driver after the first plug. -// Auto ProductID layout's Bitmap: (MSB) MassStorage | Generic | Mouse | Key | CDC (LSB) -#ifndef CFG_PRODUCTID - #define PRODUCTID_BITMAP(interface, n) ( (CFG_TUD_##interface) << (n) ) - #define CFG_PRODUCTID (0x4000 | ( PRODUCTID_BITMAP(CDC, 0) | PRODUCTID_BITMAP(HID_KEYBOARD, 1) | \ - PRODUCTID_BITMAP(HID_MOUSE, 2) | PRODUCTID_BITMAP(HID_GENERIC, 3) | \ - PRODUCTID_BITMAP(MSC, 4) ) ) -#endif - -#define ITF_NUM_CDC 0 -#define ITF_TOTAL 2 - -//--------------------------------------------------------------------+ -// Endpoints Address & Max Packet Size -//--------------------------------------------------------------------+ -#define EDPT_IN(x) (0x80 | (x)) -#define EDPT_OUT(x) (x) - -#define CDC_EDPT_NOTIF EDPT_IN (1) -#define CDC_EDPT_NOTIFICATION_PACKETSIZE 64 - -#define CDC_EDPT_OUT EDPT_OUT(2) -#define CDC_EDPT_IN EDPT_IN (2) -#define CDC_EDPT_SIZE 64 - - -//--------------------------------------------------------------------+ -// CONFIGURATION DESCRIPTOR -//--------------------------------------------------------------------+ -typedef struct ATTR_PACKED -{ - tusb_desc_configuration_t configuration; - - //------------- CDC -------------// - tusb_desc_interface_assoc_t cdc_iad; - - //CDC Control Interface - tusb_desc_interface_t cdc_comm_interface; - cdc_desc_func_header_t cdc_header; - cdc_desc_func_call_management_t cdc_call; - cdc_desc_func_acm_t cdc_acm; - cdc_desc_func_union_t cdc_union; - tusb_desc_endpoint_t cdc_endpoint_notification; - - //CDC Data Interface - tusb_desc_interface_t cdc_data_interface; - tusb_desc_endpoint_t cdc_endpoint_out; - tusb_desc_endpoint_t cdc_endpoint_in; - -} app_descriptor_configuration_t; - - - -extern tud_desc_set_t usb_desc_init; - -#endif diff --git a/examples/device/nrf52840/src/tusb_config.h b/examples/device/nrf52840/src/tusb_config.h index 1857a821..4e7210bc 100644 --- a/examples/device/nrf52840/src/tusb_config.h +++ b/examples/device/nrf52840/src/tusb_config.h @@ -44,7 +44,7 @@ #endif //--------------------------------------------------------------------+ -// CONTROLLER CONFIGURATION +// COMMON CONFIGURATION //--------------------------------------------------------------------+ #define CFG_TUSB_MCU OPT_MCU_NRF5X #define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 3adcbc98..d61842c1 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -51,7 +51,9 @@ VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct"); #ifndef CFG_TUD_MSC_MAXLUN -#define CFG_TUD_MSC_MAXLUN 1 + #define CFG_TUD_MSC_MAXLUN 1 +#elif CFG_TUD_MSC_MAXLUN == 0 || CFG_TUD_MSC_MAXLUN > 16 + #error MSC Device: Incorrect setting of MAX LUN #endif //--------------------------------------------------------------------+ diff --git a/src/tusb_option.h b/src/tusb_option.h index 6cac0fe7..4c175d5d 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -205,13 +205,6 @@ #error Control Endpoint Max Package Size cannot larger than 64 #endif -#if CFG_TUD_MSC_MAXLUN == 0 || CFG_TUD_MSC_MAXLUN > 16 - #error MSC Device: Incorrect setting of MAX LUN -#endif - -//#if CFG_TUD_MSC_BUFSIZE - - #endif /* _TUSB_OPTION_H_ */ /** @} */