From 58c86bae1d30b4f3a06959b01a769204bd91c071 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 10 Apr 2018 20:41:04 +0700 Subject: [PATCH] clean up --- lib/sdk/components/libraries/hci/hci_slip.c | 2 +- src/msc_device_app.c | 2 +- src/msc_device_app.h | 4 +- src/msc_device_ramdisk.c | 4 +- src/tusb_config.h | 58 ++++++++++----------- src/tusb_descriptors.c | 6 +-- src/tusb_descriptors.h | 8 +-- 7 files changed, 40 insertions(+), 44 deletions(-) diff --git a/lib/sdk/components/libraries/hci/hci_slip.c b/lib/sdk/components/libraries/hci/hci_slip.c index 4dd23e3..d5d0a68 100644 --- a/lib/sdk/components/libraries/hci/hci_slip.c +++ b/lib/sdk/components/libraries/hci/hci_slip.c @@ -397,7 +397,7 @@ static uint32_t slip_uart_open(void) void tud_cdc_rx_cb(uint8_t port) { - while ( tud_cdc_available() ) + while ( tud_cdc_available() && !rx_buffer_overflowed() ) { int8_t ch = tud_cdc_read_char(); handle_rx_byte((uint8_t) ch); diff --git a/src/msc_device_app.c b/src/msc_device_app.c index 401a32d..6609257 100644 --- a/src/msc_device_app.c +++ b/src/msc_device_app.c @@ -38,7 +38,7 @@ #include "msc_device_app.h" -#if TUSB_CFG_DEVICE_MSC +#if CFG_TUSB_DEVICE_MSC //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ diff --git a/src/msc_device_app.h b/src/msc_device_app.h index f10cd7f..20d8056 100644 --- a/src/msc_device_app.h +++ b/src/msc_device_app.h @@ -49,7 +49,7 @@ extern "C" { #endif -#if TUSB_CFG_DEVICE_MSC +#if CFG_TUSB_DEVICE_MSC enum { @@ -62,7 +62,7 @@ enum If you find any bugs or get any questions, feel free to file an\r\n\ issue at github.com/hathach/tinyusb" -#if TUSB_CFG_MCU==MCU_LPC11UXX || TUSB_CFG_MCU==MCU_LPC13UXX +#if CFG_TUSB_MCU==MCU_LPC11UXX || CFG_TUSB_MCU==MCU_LPC13UXX #define MSCD_APP_ROMDISK #else // defaults is ram disk #define MSCD_APP_RAMDISK diff --git a/src/msc_device_ramdisk.c b/src/msc_device_ramdisk.c index fefbfdf..45932e0 100644 --- a/src/msc_device_ramdisk.c +++ b/src/msc_device_ramdisk.c @@ -38,7 +38,7 @@ #include "msc_device_app.h" -#if TUSB_CFG_DEVICE_MSC && defined (MSCD_APP_RAMDISK) +#if CFG_TUSB_DEVICE_MSC && defined (MSCD_APP_RAMDISK) //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF @@ -47,7 +47,7 @@ //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -TUSB_CFG_ATTR_USBRAM ATTR_USB_MIN_ALIGNMENT +CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t msc_device_ramdisk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] = { //------------- Boot Sector -------------// diff --git a/src/tusb_config.h b/src/tusb_config.h index 8d1d865..9b1c48b 100644 --- a/src/tusb_config.h +++ b/src/tusb_config.h @@ -36,60 +36,56 @@ */ /**************************************************************************/ -#ifndef _TUSB_TUSB_CONFIG_H_ -#define _TUSB_TUSB_CONFIG_H_ +#ifndef _TUSB_CONFIG_H_ +#define _TUSB_CONFIG_H_ #ifdef __cplusplus extern "C" { #endif //--------------------------------------------------------------------+ -// CONTROLLER CONFIGURATION +// COMMON CONFIGURATION //--------------------------------------------------------------------+ -//#define TUSB_CFG_MCU will be passed from IDE/command line for easy board/mcu switching +#define CFG_TUSB_CONTROLLER_0_MODE (TUSB_MODE_DEVICE) -#define TUSB_CFG_CONTROLLER_0_MODE (TUSB_MODE_DEVICE) -//#define TUSB_CFG_CONTROLLER_1_MODE (TUSB_MODE_DEVICE) +#define CFG_TUSB_DEBUG 2 + +#define CFG_TUSB_OS TUSB_OS_NONE +//#define CFG_TUSB_OS_TASK_PRIO 0 //--------------------------------------------------------------------+ // DEVICE CONFIGURATION //--------------------------------------------------------------------+ -#define TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE 64 +#define CFG_TUSB_DEVICE_ENDOINT0_SIZE 64 //------------- CLASS -------------// -#define TUSB_CFG_DEVICE_HID_KEYBOARD 0 -#define TUSB_CFG_DEVICE_HID_MOUSE 0 -#define TUSB_CFG_DEVICE_HID_GENERIC 0 // not supported yet -#define TUSB_CFG_DEVICE_MSC 0 -#define TUSB_CFG_DEVICE_CDC 1 +#define CFG_TUSB_DEVICE_HID_KEYBOARD 0 +#define CFG_TUSB_DEVICE_HID_MOUSE 0 +#define CFG_TUSB_DEVICE_HID_GENERIC 0 // not supported yet +#define CFG_TUSB_DEVICE_MSC 0 +#define CFG_TUSB_DEVICE_CDC 1 -//--------------------------------------------------------------------+ -// COMMON CONFIGURATION -//--------------------------------------------------------------------+ -#define TUSB_CFG_DEBUG 2 -#define TUSB_CFG_OS TUSB_OS_NONE // be passed from IDE/command line for easy project switching -//#define TUSB_CFG_OS_TASK_PRIO 0 // be passed from IDE/command line for easy project switching -#define TUSB_CFG_TICKS_HZ 1000 +/*------------------------------------------------------------------*/ +/* CLASS + * TUD Stand for Tiny Usb Device + *------------------------------------------------------------------*/ -//#define TUSB_CFG_OS TUSB_OS_NONE +// FIFO size of CDC TX and RX +#define CFG_TUD_CDC_BUFSIZE 1024 + +// TX is sent automatically in 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 //--------------------------------------------------------------------+ -#define TUSB_CFG_ATTR_USBRAM - -// LPC11uxx and LPC13uxx requires each buffer has to be 64-byte alignment -#if TUSB_CFG_MCU == MCU_LPC11UXX || TUSB_CFG_MCU == MCU_LPC13UXX - #define ATTR_USB_MIN_ALIGNMENT ATTR_ALIGNED(64) -#elif defined NRF52840_XXAA - #define ATTR_USB_MIN_ALIGNMENT ATTR_ALIGNED(4) -#else - #define ATTR_USB_MIN_ALIGNMENT -#endif +#define CFG_TUSB_ATTR_USBRAM +#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4) #ifdef __cplusplus } #endif -#endif /* _TUSB_TUSB_CONFIG_H_ */ +#endif /* _TUSB_CONFIG_H_ */ diff --git a/src/tusb_descriptors.c b/src/tusb_descriptors.c index 9176543..4bf3ee2 100644 --- a/src/tusb_descriptors.c +++ b/src/tusb_descriptors.c @@ -53,7 +53,7 @@ tusb_desc_device_t const desc_device = .bDeviceSubClass = MISC_SUBCLASS_COMMON, .bDeviceProtocol = MISC_PROTOCOL_IAD, - .bMaxPacketSize0 = TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE, + .bMaxPacketSize0 = CFG_TUSB_DEVICE_ENDOINT0_SIZE, .idVendor = CFG_VENDORID, .idProduct = CFG_PRODUCTID, @@ -85,7 +85,7 @@ app_descriptor_configuration_t const desc_configuration = .bMaxPower = TUSB_DESC_CONFIG_POWER_MA(500) }, -#if TUSB_CFG_DEVICE_CDC +#if CFG_TUSB_DEVICE_CDC // IAD points to CDC Interfaces .cdc = { @@ -199,7 +199,7 @@ app_descriptor_configuration_t const desc_configuration = }, #endif -#if TUSB_CFG_DEVICE_MSC +#if CFG_TUSB_DEVICE_MSC .msc = { .interface = diff --git a/src/tusb_descriptors.h b/src/tusb_descriptors.h index b1a0002..7a140c3 100644 --- a/src/tusb_descriptors.h +++ b/src/tusb_descriptors.h @@ -50,7 +50,7 @@ // 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) ( (TUSB_CFG_DEVICE_##interface) << (n) ) + #define PRODUCTID_BITMAP(interface, n) ( (CFG_TUSB_DEVICE_##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) ) ) @@ -60,7 +60,7 @@ #define ITF_NUM_MSC 2 // total number of interfaces -#define ITF_TOTAL (TUSB_CFG_DEVICE_CDC*2 + TUSB_CFG_DEVICE_MSC) +#define ITF_TOTAL (CFG_TUSB_DEVICE_CDC*2 + CFG_TUSB_DEVICE_MSC) //--------------------------------------------------------------------+ // Endpoints Address & Max Packet Size @@ -87,7 +87,7 @@ typedef struct ATTR_PACKED { tusb_desc_configuration_t configuration; -#if TUSB_CFG_DEVICE_CDC +#if CFG_TUSB_DEVICE_CDC struct ATTR_PACKED { tusb_desc_interface_assoc_t iad; @@ -107,7 +107,7 @@ typedef struct ATTR_PACKED }cdc; #endif -#if TUSB_CFG_DEVICE_MSC +#if CFG_TUSB_DEVICE_MSC struct ATTR_PACKED { tusb_desc_interface_t interface;