From 915f52730d4bd91642bfcf74a8ebfb18536517e9 Mon Sep 17 00:00:00 2001 From: Nathan Conrad Date: Tue, 17 Sep 2019 11:28:29 -0400 Subject: Implement HID desc request. --- src/class/hid/hid_device.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 572f2cad2..2d579f475 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -202,7 +202,29 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque uint8_t const desc_index = tu_u16_low (p_request->wValue); (void) desc_index; - if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT) + if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_HID) + { + // FIXME: Should check which is the active configuration, but no callback in usbd currently exists to do that + tusb_desc_configuration_t const* desc_cfg = + (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(0); + uint8_t const * p_desc = ((uint8_t const*) desc_cfg) + sizeof(tusb_desc_configuration_t); + uint8_t const * desc_end = ((uint8_t const*) desc_cfg) + desc_cfg->wTotalLength; + + while( p_desc < desc_end ) + { + tusb_hid_descriptor_hid_t *p_desc_hid =(tusb_hid_descriptor_hid_t*)p_desc; + if(p_desc_hid->bDescriptorType == HID_DESC_TYPE_HID) { + tud_control_xfer(rhport, p_request, (void*) p_desc_hid, p_desc_hid->bLength); + break; + } + p_desc += p_desc_hid->bLength; // next desc + } + if(p_desc >= desc_end) + { + return false; + } + } + else if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT) { uint8_t const * desc_report = tud_hid_descriptor_report_cb(); tud_control_xfer(rhport, p_request, (void*) desc_report, p_hid->reprot_desc_len); -- cgit v1.3.1 From 05164c5a27eaad25f28a4fc8926297d6cd32e3fc Mon Sep 17 00:00:00 2001 From: Nathan Conrad Date: Thu, 19 Sep 2019 21:04:51 -0400 Subject: Cache pointer to HID descriptor. --- src/class/hid/hid_device.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 2d579f475..7dabdbc17 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -46,12 +46,13 @@ typedef struct uint8_t boot_protocol; // Boot mouse or keyboard bool boot_mode; // default = false (Report) uint8_t idle_rate; // up to application to handle idle rate - uint16_t reprot_desc_len; + uint16_t report_desc_len; CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_HID_BUFSIZE]; CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_HID_BUFSIZE]; -}hidd_interface_t; + tusb_hid_descriptor_hid_t const * hid_descriptor; +} hidd_interface_t; CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[CFG_TUD_HID]; @@ -167,8 +168,8 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t //------------- HID descriptor -------------// p_desc = tu_desc_next(p_desc); - 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); + p_hid->hid_descriptor = (tusb_hid_descriptor_hid_t const *) p_desc; + TU_ASSERT(HID_DESC_TYPE_HID == p_hid->hid_descriptor->bDescriptorType); //------------- Endpoint Descriptor -------------// p_desc = tu_desc_next(p_desc); @@ -178,7 +179,7 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t p_hid->boot_mode = false; // default mode is REPORT p_hid->itf_num = desc_itf->bInterfaceNumber; - memcpy(&p_hid->reprot_desc_len, &desc_hid->wReportLength, 2); + memcpy(&p_hid->report_desc_len, &(p_hid->hid_descriptor->wReportLength), 2); *p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t); @@ -205,6 +206,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_HID) { // FIXME: Should check which is the active configuration, but no callback in usbd currently exists to do that + TU_VERIFY(p_hid->hid_descriptor != NULL); tusb_desc_configuration_t const* desc_cfg = (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(0); uint8_t const * p_desc = ((uint8_t const*) desc_cfg) + sizeof(tusb_desc_configuration_t); @@ -227,7 +229,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque else if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT) { uint8_t const * desc_report = tud_hid_descriptor_report_cb(); - tud_control_xfer(rhport, p_request, (void*) desc_report, p_hid->reprot_desc_len); + tud_control_xfer(rhport, p_request, (void*) desc_report, p_hid->report_desc_len); }else { return false; // stall unsupported request @@ -273,7 +275,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque case HID_REQ_CONTROL_GET_PROTOCOL: { - uint8_t protocol = 1-p_hid->boot_mode; // 0 is Boot, 1 is Report protocol + uint8_t protocol = (uint8_t)(1-p_hid->boot_mode); // 0 is Boot, 1 is Report protocol tud_control_xfer(rhport, p_request, &protocol, 1); } break; -- cgit v1.3.1 From 7b2f8cc73a758eefc2a308813d0081f08ddfeb2b Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 20 Sep 2019 13:49:33 +0700 Subject: added stm32 L0 support close #125 --- examples/device/board_test/Makefile | 3 - examples/make.mk | 1 + hw/bsp/stm32l0538disco/board.mk | 2 +- src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 38 ++++++----- .../st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h | 79 ++++++++++++---------- 5 files changed, 64 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/examples/device/board_test/Makefile b/examples/device/board_test/Makefile index e0c6d6ce2..5a455078e 100644 --- a/examples/device/board_test/Makefile +++ b/examples/device/board_test/Makefile @@ -5,9 +5,6 @@ INC += \ src \ $(TOP)/hw \ -# stop on the first build error, which is quite a lot of porting new board -CFLAGS += -Wfatal-errors - # Example source EXAMPLE_SOURCE += $(wildcard src/*.c) SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) diff --git a/examples/make.mk b/examples/make.mk index b0aa5659e..f35195fde 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -58,6 +58,7 @@ CFLAGS += \ -Wall \ -Werror \ -Werror-implicit-function-declaration \ + -Wfatal-errors \ -Wfloat-equal \ -Wundef \ -Wshadow \ diff --git a/hw/bsp/stm32l0538disco/board.mk b/hw/bsp/stm32l0538disco/board.mk index f4088ba77..3b84159d1 100644 --- a/hw/bsp/stm32l0538disco/board.mk +++ b/hw/bsp/stm32l0538disco/board.mk @@ -6,9 +6,9 @@ CFLAGS += \ -mcpu=cortex-m0plus \ -mfloat-abi=soft \ -nostdlib -nostartfiles \ + -DCFG_EXAMPLE_MSC_READONLY \ -DCFG_TUSB_MCU=OPT_MCU_STM32L0 -# -DCFG_EXAMPLE_MSC_READONLY \ ST_HAL_DRIVER = hw/mcu/st/st_driver/STM32L0xx_HAL_Driver ST_CMSIS = hw/mcu/st/st_driver/CMSIS/Device/ST/STM32L0xx diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c index aec8ea0c7..d83098fd9 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c @@ -106,14 +106,17 @@ #include "tusb_option.h" +#define STM32F1_FSDEV ( \ + defined(STM32F102x6) || defined(STM32F102xB) || \ + defined(STM32F103x6) || defined(STM32F103xB) || \ + defined(STM32F103xE) || defined(STM32F103xG) \ +) + #if (TUSB_OPT_DEVICE_ENABLED) && ( \ - ((CFG_TUSB_MCU) == OPT_MCU_STM32F0) || \ - (((CFG_TUSB_MCU) == OPT_MCU_STM32F1) && ( \ - defined(stm32f102x6) || defined(stm32f102xb) || \ - defined(stm32f103x6) || defined(stm32f103xb) || \ - defined(stm32f103xe) || defined(stm32f103xg) \ - )) || \ - ((CFG_TUSB_MCU) == OPT_MCU_STM32F3) \ + (CFG_TUSB_MCU == OPT_MCU_STM32F0 ) || \ + (CFG_TUSB_MCU == OPT_MCU_STM32F1 && STM32F1_FSDEV ) || \ + (CFG_TUSB_MCU == OPT_MCU_STM32F3 ) || \ + (CFG_TUSB_MCU == OPT_MCU_STM32L0 ) \ ) // In order to reduce the dependance on HAL, we undefine this. @@ -165,7 +168,7 @@ typedef struct static xfer_ctl_t xfer_status[MAX_EP_COUNT][2]; -static xfer_ctl_t* xfer_ctl_ptr(uint32_t epnum, uint32_t dir) +static inline xfer_ctl_t* xfer_ctl_ptr(uint32_t epnum, uint32_t dir) { return &xfer_status[epnum][dir]; } @@ -252,9 +255,10 @@ void dcd_init (uint8_t rhport) void dcd_int_enable (uint8_t rhport) { (void)rhport; -#if defined(STM32F0) + +#if CFG_TUSB_MCU == OPT_MCU_STM32F0 || CFG_TUSB_MCU == OPT_MCU_STM32L0 NVIC_EnableIRQ(USB_IRQn); -#elif defined(STM32F3) +#elif CFG_TUSB_MCU == OPT_MCU_STM32F3 NVIC_EnableIRQ(USB_HP_CAN_TX_IRQn); NVIC_EnableIRQ(USB_LP_CAN_RX0_IRQn); NVIC_EnableIRQ(USBWakeUp_IRQn); @@ -265,14 +269,15 @@ void dcd_int_enable (uint8_t rhport) void dcd_int_disable(uint8_t rhport) { (void)rhport; -#if defined(STM32F0) + +#if CFG_TUSB_MCU == OPT_MCU_STM32F0 || CFG_TUSB_MCU == OPT_MCU_STM32L0 NVIC_DisableIRQ(USB_IRQn); -#elif defined(STM32F3) +#elif CFG_TUSB_MCU == OPT_MCU_STM32F3 NVIC_DisableIRQ(USB_HP_CAN_TX_IRQn); NVIC_DisableIRQ(USB_LP_CAN_RX0_IRQn); NVIC_DisableIRQ(USBWakeUp_IRQn); #else -#error Unknown arch in USB driver + #error Unknown arch in USB driver #endif // I'm not convinced that memory synchronization is completely necessary, but // it isn't a bad idea. @@ -305,7 +310,7 @@ void dcd_remote_wakeup(uint8_t rhport) { (void) rhport; - USB->CNTR |= (uint16_t)USB_CNTR_RESUME; + USB->CNTR |= (uint16_t) USB_CNTR_RESUME; remoteWakeCountdown = 4u; // required to be 1 to 15 ms, ESOF should trigger every 1ms. } @@ -448,14 +453,11 @@ static uint16_t dcd_ep_ctr_handler(void) { pcd_set_ep_rx_status(USB, EPindex, USB_EP_RX_VALID);// Await next SETUP } - } - } } else /* Decode and service non control endpoints interrupt */ { - /* process related endpoint register */ wEPVal = pcd_get_endpoint(USB, EPindex); if ((wEPVal & USB_EP_CTR_RX) != 0U) // OUT @@ -809,7 +811,7 @@ static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, size_t wN // Interrupt handlers -#if (CFG_TUSB_MCU) == (OPT_MCU_STM32F0) +#if CFG_TUSB_MCU == OPT_MCU_STM32F0 || CFG_TUSB_MCU == OPT_MCU_STM32L0 void USB_IRQHandler(void) { dcd_fs_irqHandler(); diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h index ff25df048..30538541a 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev_pvt_st.h @@ -41,51 +41,56 @@ #ifndef PORTABLE_ST_STM32F0_DCD_STM32F0_FSDEV_PVT_ST_H_ #define PORTABLE_ST_STM32F0_DCD_STM32F0_FSDEV_PVT_ST_H_ -#if defined(STM32F042x6) | \ - defined(STM32F070x6) | defined(STM32F070xB) | \ - defined(STM32F072xB) | \ +#if defined(STM32F042x6) || \ + defined(STM32F070x6) || defined(STM32F070xB) || \ + defined(STM32F072xB) || \ defined(STM32F078xx) -#include "stm32f0xx.h" -#define PMA_LENGTH (1024u) -// F0x2 models are crystal-less -// All have internal D+ pull-up -// 070RB: 2 x 16 bits/word memory LPM Support, BCD Support -// PMA dedicated to USB (no sharing with CAN) -#elif defined(STM32F102x6) | defined(STM32F102x6) | \ - defined(STM32F103x6) | defined(STM32F103xB) | \ - defined(STM32F103xE) | defined(STM32F103xB) -#include "stm32f1xx.h" -#define PMA_LENGTH (512u) -// NO internal Pull-ups -// *B, and *C: 2 x 16 bits/word -#error The F102/F103 driver is expected not to work, but it might? Try it? - -#elif defined(STM32F302xB) | defined(STM32F302xC) | \ - defined(STM32F303xB) | defined(STM32F303xC) | \ + #include "stm32f0xx.h" + #define PMA_LENGTH (1024u) + // F0x2 models are crystal-less + // All have internal D+ pull-up + // 070RB: 2 x 16 bits/word memory LPM Support, BCD Support + // PMA dedicated to USB (no sharing with CAN) + +#elif STM32F1_FSDEV + #include "stm32f1xx.h" + #define PMA_LENGTH (512u) + // NO internal Pull-ups + // *B, and *C: 2 x 16 bits/word + #error The F102/F103 driver is expected not to work, but it might? Try it? + +#elif defined(STM32F302xB) || defined(STM32F302xC) || \ + defined(STM32F303xB) || defined(STM32F303xC) || \ defined(STM32F373xC) -#include "stm32f3xx.h" -#define PMA_LENGTH (512u) -// NO internal Pull-ups -// *B, and *C: 1 x 16 bits/word -// PMA dedicated to USB (no sharing with CAN) -#elif defined(STM32F302x6) | defined(STM32F302x8) | \ - defined(STM32F302xD) | defined(STM32F302xE) | \ - defined(STM32F303xD) | defined(STM32F303xE) | \ -#include "stm32f3xx.h" -#define PMA_LENGTH (1024u) -// NO internal Pull-ups -// *6, *8, *D, and *E: 2 x 16 bits/word LPM Support -// When CAN clock is enabled, USB can use first 768 bytes ONLY. + #include "stm32f3xx.h" + #define PMA_LENGTH (512u) + // NO internal Pull-ups + // *B, and *C: 1 x 16 bits/word + // PMA dedicated to USB (no sharing with CAN) + +#elif defined(STM32F302x6) || defined(STM32F302x8) || \ + defined(STM32F302xD) || defined(STM32F302xE) || \ + defined(STM32F303xD) || defined(STM32F303xE) + #include "stm32f3xx.h" + #define PMA_LENGTH (1024u) + // NO internal Pull-ups + // *6, *8, *D, and *E: 2 x 16 bits/word LPM Support + // When CAN clock is enabled, USB can use first 768 bytes ONLY. + +#elif CFG_TUSB_MCU == OPT_MCU_STM32L0 + #include "stm32l0xx.h" + #define PMA_LENGTH (1024u) + #else -#error You are using an untested or unimplemented STM32 variant. Please update the driver. -// This includes L0x2, L0x3, L1x0, L1x1, L1x2, L4x2 and L4x3, G1x1, G1x3, and G1x4 + #error You are using an untested or unimplemented STM32 variant. Please update the driver. + // This includes L1x0, L1x1, L1x2, L4x2 and L4x3, G1x1, G1x3, and G1x4 #endif // For purposes of accessing the packet #if ((PMA_LENGTH) == 512u) -#define PMA_STRIDE (2u) + #define PMA_STRIDE (2u) #elif ((PMA_LENGTH) == 1024u) -#define PMA_STRIDE (1u) + #define PMA_STRIDE (1u) #endif // And for type-safety create a new macro for the volatile address of PMAADDR -- cgit v1.3.1 From 94c9cf0eff7973475e4f6d93cc96c2c86b541b08 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 20 Sep 2019 16:14:35 +0700 Subject: doc update --- README.md | 26 +++++++++++++------------- docs/boards.md | 1 + src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c | 5 +---- 3 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/README.md b/README.md index 0fbfaec37..a811e3b49 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,17 @@ TinyUSB is an open-source cross-platform USB Host/Device stack for embedded syst └── tools # Files used internally ``` +## Supported MCUs + +The stack supports the following MCUs + +- **Nordic:** nRF52840 +- **NXP:** LPC11Uxx, LPC13xx, LPC175x_6x, LPC177x_8x, LPC18xx, LPC40xx, LPC43xx, LPC51Uxx +- **MicroChip:** SAMD21, SAMD51 (device only) +- **ST:** STM32 series: L0, F0, F2, F3, F4, F7, H7 (device only) + +[Here is the list of supported Boards](docs/boards.md) that can be used with provided examples. + ## Device Stack Support multiple device configurations by dynamically changing usb descriptors. Low power functions such as suspend, resume and remote wakeup. Following device classes are supported: @@ -42,23 +53,12 @@ Support multiple device configurations by dynamically changing usb descriptors. ## OS Abtraction layer -Currently the following OS are supported with tinyusb out of the box with a simple change of **CFG_TUSB_OS** macro. +TinyUSB is completely thread-safe by pushing all ISR events into a central queue, then process it later in the non-ISR context. It also uses semphore/mutex to access shared resource such as CDC fifo. Therefore the stack needs to use some of OS's basic APIs. Following OSes are already supported out of the box. -- **No OS** +- **No OS** : Disabling USB IRQ is used as way to provide mutex - **FreeRTOS** - **Mynewt** Due to the newt package build system, Mynewt examples are better to be on its [own repo](https://github.com/hathach/mynewt-tinyusb-example) -## Supported MCUs - -The stack supports the following MCUs - -- **Nordic:** nRF52840 -- **NXP:** LPC11Uxx, LPC13xx, LPC175x_6x, LPC177x_8x, LPC18xx, LPC40xx, LPC43xx, LPC51Uxx -- **MicroChip:** SAMD21, SAMD51 (device only) -- **ST:** STM32F0, STM32F2, STM32F3, STM32F4, STM32F7, STM32H7 (device only) - -[Here is the list of supported Boards](docs/boards.md) - ## Compiler & IDE The stack is developed with GCC compiler, and should be compilable with others. Folder `examples` provide Makefile and Segger Embedded Studio build support. [Here is instruction to build example](examples/readme.md). diff --git a/docs/boards.md b/docs/boards.md index fef682f48..b6b48a7f1 100644 --- a/docs/boards.md +++ b/docs/boards.md @@ -43,6 +43,7 @@ This code base already had supported for a handful of following boards - Adafruit Feather STM32F405 - [Micro Python PyBoard v1.1](https://store.micropython.org/product/PYBv1.1) +- [STM32 L035c8 Discovery](https://www.st.com/en/evaluation-tools/32l0538discovery.html) - [STM32 F070rb Nucleo](https://www.st.com/en/evaluation-tools/nucleo-f070rb.html) - [STM32 F072rb Discovery](https://www.st.com/en/evaluation-tools/32f072bdiscovery.html) - [STM32 F207zg Nucleo](https://www.st.com/en/evaluation-tools/nucleo-f207zg.html) diff --git a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c index d83098fd9..9bd4d2362 100644 --- a/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c +++ b/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c @@ -30,10 +30,7 @@ /********************************************** * This driver has been tested with the following MCUs: - * - * - * STM32F070RB - * + * - F070, F072, L053 * * It also should work with minimal changes for any ST MCU with an "USB A"/"PCD"/"HCD" peripheral. This * covers: -- cgit v1.3.1 From a8a65d6ceae244971405a13bc493ee923861be1f Mon Sep 17 00:00:00 2001 From: Nathan Conrad Date: Fri, 20 Sep 2019 08:46:17 -0400 Subject: Use cached HID descriptor. --- src/class/hid/hid_device.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 7dabdbc17..fee44e30c 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -205,32 +205,15 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_HID) { - // FIXME: Should check which is the active configuration, but no callback in usbd currently exists to do that TU_VERIFY(p_hid->hid_descriptor != NULL); - tusb_desc_configuration_t const* desc_cfg = - (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(0); - uint8_t const * p_desc = ((uint8_t const*) desc_cfg) + sizeof(tusb_desc_configuration_t); - uint8_t const * desc_end = ((uint8_t const*) desc_cfg) + desc_cfg->wTotalLength; - - while( p_desc < desc_end ) - { - tusb_hid_descriptor_hid_t *p_desc_hid =(tusb_hid_descriptor_hid_t*)p_desc; - if(p_desc_hid->bDescriptorType == HID_DESC_TYPE_HID) { - tud_control_xfer(rhport, p_request, (void*) p_desc_hid, p_desc_hid->bLength); - break; - } - p_desc += p_desc_hid->bLength; // next desc - } - if(p_desc >= desc_end) - { - return false; - } + TU_VERIFY(tud_control_xfer(rhport, p_request, (void*) p_hid->hid_descriptor, p_hid->hid_descriptor->bLength)); } else if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT) { uint8_t const * desc_report = tud_hid_descriptor_report_cb(); tud_control_xfer(rhport, p_request, (void*) desc_report, p_hid->report_desc_len); - }else + } + else { return false; // stall unsupported request } -- cgit v1.3.1 From f241ff389f9494836cdc45e621726c0b69b8daed Mon Sep 17 00:00:00 2001 From: Nathan Conrad Date: Fri, 20 Sep 2019 08:56:46 -0400 Subject: Also need to just return false in the case that it isn't an interface control event. We shouldn't assert. This normally isn't an error, either, so I don't want to use TU_VERIFY. --- src/class/hid/hid_device.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index fee44e30c..b57d6219f 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -193,6 +193,10 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t // return false to stall control endpoint (e.g unsupported request) bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request) { + if (p_request->bmRequestType_bit.recipient != TUSB_REQ_RCPT_INTERFACE) + { + return false; + } hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex ); TU_ASSERT(p_hid); -- cgit v1.3.1 From 2281a514846402af68aa4c97fcd206611c0969a1 Mon Sep 17 00:00:00 2001 From: Nathan Conrad Date: Fri, 20 Sep 2019 12:27:41 -0400 Subject: Revert "Also need to just return false in the case that it isn't an interface control event. We shouldn't assert. This normally isn't an" This reverts commit f241ff389f9494836cdc45e621726c0b69b8daed. --- src/class/hid/hid_device.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index b57d6219f..fee44e30c 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -193,10 +193,6 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t // return false to stall control endpoint (e.g unsupported request) bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request) { - if (p_request->bmRequestType_bit.recipient != TUSB_REQ_RCPT_INTERFACE) - { - return false; - } hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex ); TU_ASSERT(p_hid); -- cgit v1.3.1 From 8a688cd8d0fed2325aaacdfbb5159a04dfe03ac1 Mon Sep 17 00:00:00 2001 From: Nathan Conrad Date: Fri, 20 Sep 2019 12:58:26 -0400 Subject: Revert "Revert "Also need to just return false in the case that it isn't an interface control event. We shouldn't assert. This normally isn't an"" This reverts commit 2281a514846402af68aa4c97fcd206611c0969a1. --- src/class/hid/hid_device.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index fee44e30c..b57d6219f 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -193,6 +193,10 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t // return false to stall control endpoint (e.g unsupported request) bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request) { + if (p_request->bmRequestType_bit.recipient != TUSB_REQ_RCPT_INTERFACE) + { + return false; + } hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex ); TU_ASSERT(p_hid); -- cgit v1.3.1