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/class/custom/custom_device.c | 105 +++++++++++++++++++++++++ src/class/custom/custom_device.h | 71 +++++++++++++++++ src/class/custom/custom_host.c | 160 +++++++++++++++++++++++++++++++++++++++ src/class/custom/custom_host.h | 87 +++++++++++++++++++++ 4 files changed, 423 insertions(+) create mode 100644 src/class/custom/custom_device.c create mode 100644 src/class/custom/custom_device.h create mode 100644 src/class/custom/custom_host.c create mode 100644 src/class/custom/custom_host.h (limited to 'src/class/custom') diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c new file mode 100644 index 000000000..3d0453001 --- /dev/null +++ b/src/class/custom/custom_device.c @@ -0,0 +1,105 @@ +/**************************************************************************/ +/*! + @file custom_device.c + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2018, Adafruit Industries (adafruit.com) + 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. +*/ +/**************************************************************************/ + +#include "tusb_option.h" + +#if (MODE_DEVICE_SUPPORTED && CFG_TUD_CUSTOM_CLASS) + +#define _TINY_USB_SOURCE_FILE_ + +#include "common/tusb_common.h" +#include "custom_device.h" +#include "device/usbd_pvt.h" + +/*------------------------------------------------------------------*/ +/* MACRO TYPEDEF CONSTANT ENUM + *------------------------------------------------------------------*/ + +/*------------------------------------------------------------------*/ +/* VARIABLE DECLARATION + *------------------------------------------------------------------*/ +typedef struct { + uint8_t itf_num; + + uint8_t ep_in; + uint8_t ep_out; + +} cusd_interface_t; + +static cusd_interface_t _cusd_itf; + +/*------------------------------------------------------------------*/ +/* FUNCTION DECLARATION + *------------------------------------------------------------------*/ +void cusd_init(void) +{ + varclr_(&_cusd_itf); +} + +tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len) +{ + cusd_interface_t* p_itf = &_cusd_itf; + + // Open endpoint pair with usbd helper + tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_desc_itf ); + TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_itf->ep_out, &p_itf->ep_in) ); + + p_itf->itf_num = p_desc_itf->bInterfaceNumber; + + (*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); + + // TODO Prepare for incoming data +// TU_ASSERT( dcd_edpt_xfer(rhport, p_itf->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)), TUSB_ERROR_DCD_EDPT_XFER ); + + return TUSB_ERROR_NONE; +} + +tusb_error_t cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request) +{ + return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; +} + +tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes) +{ + return TUSB_ERROR_NONE; +} + +void cusd_close(uint8_t rhport) +{ + +} + +#endif diff --git a/src/class/custom/custom_device.h b/src/class/custom/custom_device.h new file mode 100644 index 000000000..08f4f7f4a --- /dev/null +++ b/src/class/custom/custom_device.h @@ -0,0 +1,71 @@ +/**************************************************************************/ +/*! + @file custom_device.h + @author hathach (tinyusb.org) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2018, Adafruit Industries (adafruit.com) + 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. +*/ +/**************************************************************************/ + +#ifndef _TUSB_CUSTOM_DEVICE_H_ +#define _TUSB_CUSTOM_DEVICE_H_ + +#include "common/tusb_common.h" +#include "device/usbd.h" + +//--------------------------------------------------------------------+ +// APPLICATION API (Multiple Root Ports) +// Should be used only with MCU that support more than 1 ports +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// APPLICATION API (Single Port) +// Should be used with MCU supporting only 1 USB port for code simplicity +//--------------------------------------------------------------------+ + + +//--------------------------------------------------------------------+ +// APPLICATION CALLBACK API (WEAK is optional) +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// USBD-CLASS DRIVER API +//--------------------------------------------------------------------+ +#ifdef _TINY_USB_SOURCE_FILE_ + +void cusd_init(void); +tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); +tusb_error_t cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request); +tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); +void cusd_close(uint8_t rhport); +#endif + + +#endif /* _TUSB_CUSTOM_DEVICE_H_ */ diff --git a/src/class/custom/custom_host.c b/src/class/custom/custom_host.c new file mode 100644 index 000000000..ad3315980 --- /dev/null +++ b/src/class/custom/custom_host.c @@ -0,0 +1,160 @@ +/**************************************************************************/ +/*! + @file custom_host.c + @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. +*/ +/**************************************************************************/ + +#include "tusb_option.h" + +#if (MODE_HOST_SUPPORTED && CFG_TUSB_HOST_CUSTOM_CLASS) + +#define _TINY_USB_SOURCE_FILE_ + +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ +#include "common/tusb_common.h" +#include "custom_host.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ +custom_interface_info_t custom_interface[CFG_TUSB_HOST_DEVICE_MAX]; + +static tusb_error_t cush_validate_paras(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length) +{ + if ( !tusbh_custom_is_mounted(dev_addr, vendor_id, product_id) ) + { + return TUSB_ERROR_DEVICE_NOT_READY; + } + + TU_ASSERT( p_buffer != NULL && length != 0, TUSB_ERROR_INVALID_PARA); + + return TUSB_ERROR_NONE; +} +//--------------------------------------------------------------------+ +// APPLICATION API (need to check parameters) +//--------------------------------------------------------------------+ +tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length) +{ + TU_ASSERT_ERR( cush_validate_paras(dev_addr, vendor_id, product_id, p_buffer, length) ); + + if ( !hcd_pipe_is_idle(custom_interface[dev_addr-1].pipe_in) ) + { + return TUSB_ERROR_INTERFACE_IS_BUSY; + } + + (void) hcd_pipe_xfer( custom_interface[dev_addr-1].pipe_in, p_buffer, length, true); + + return TUSB_ERROR_NONE; +} + +tusb_error_t tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void const * p_data, uint16_t length) +{ + TU_ASSERT_ERR( cush_validate_paras(dev_addr, vendor_id, product_id, p_data, length) ); + + if ( !hcd_pipe_is_idle(custom_interface[dev_addr-1].pipe_out) ) + { + return TUSB_ERROR_INTERFACE_IS_BUSY; + } + + (void) hcd_pipe_xfer( custom_interface[dev_addr-1].pipe_out, p_data, length, true); + + return TUSB_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// USBH-CLASS API +//--------------------------------------------------------------------+ +void cush_init(void) +{ + memclr_(&custom_interface, sizeof(custom_interface_info_t) * CFG_TUSB_HOST_DEVICE_MAX); +} + +tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +{ + // FIXME quick hack to test lpc1k custom class with 2 bulk endpoints + uint8_t const *p_desc = (uint8_t const *) p_interface_desc; + p_desc = descriptor_next(p_desc); + + //------------- Bulk Endpoints Descriptor -------------// + for(uint32_t i=0; i<2; i++) + { + tusb_desc_endpoint_t const *p_endpoint = (tusb_desc_endpoint_t const *) p_desc; + TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType, TUSB_ERROR_INVALID_PARA); + + pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ? + &custom_interface[dev_addr-1].pipe_in : &custom_interface[dev_addr-1].pipe_out; + *p_pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC); + TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED ); + + p_desc = descriptor_next(p_desc); + } + + (*p_length) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); + return TUSB_ERROR_NONE; +} + +void cush_isr(pipe_handle_t pipe_hdl, tusb_event_t event) +{ + +} + +void cush_close(uint8_t dev_addr) +{ + tusb_error_t err1, err2; + custom_interface_info_t * p_interface = &custom_interface[dev_addr-1]; + + // TODO re-consider to check pipe valid before calling pipe_close + if( pipehandle_is_valid( p_interface->pipe_in ) ) + { + err1 = hcd_pipe_close( p_interface->pipe_in ); + } + + if ( pipehandle_is_valid( p_interface->pipe_out ) ) + { + err2 = hcd_pipe_close( p_interface->pipe_out ); + } + + memclr_(p_interface, sizeof(custom_interface_info_t)); + + TU_ASSERT(err1 == TUSB_ERROR_NONE && err2 == TUSB_ERROR_NONE, (void) 0 ); +} + +#endif diff --git a/src/class/custom/custom_host.h b/src/class/custom/custom_host.h new file mode 100644 index 000000000..2bf3a8d3c --- /dev/null +++ b/src/class/custom/custom_host.h @@ -0,0 +1,87 @@ +/**************************************************************************/ +/*! + @file custom_host.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_class + * \defgroup Group_Custom Custom Class (not supported yet) + * @{ */ + +#ifndef _TUSB_CUSTOM_HOST_H_ +#define _TUSB_CUSTOM_HOST_H_ + +#include "common/tusb_common.h" +#include "host/usbh.h" + +#ifdef __cplusplus + extern "C" { +#endif + +typedef struct { + pipe_handle_t pipe_in; + pipe_handle_t pipe_out; +}custom_interface_info_t; + +//--------------------------------------------------------------------+ +// USBH-CLASS DRIVER API +//--------------------------------------------------------------------+ +static inline bool tusbh_custom_is_mounted(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id) +{ + (void) vendor_id; // TODO check this later + (void) product_id; +// return (tusbh_device_get_mounted_class_flag(dev_addr) & BIT_(TUSB_CLASS_MAPPED_INDEX_END-1) ) != 0; + return false; +} + +tusb_error_t tusbh_custom_read(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void * p_buffer, uint16_t length); +tusb_error_t tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t product_id, void const * p_data, uint16_t length); + +#ifdef _TINY_USB_SOURCE_FILE_ + +void cush_init(void); +tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; +void cush_isr(pipe_handle_t pipe_hdl, tusb_event_t event); +void cush_close(uint8_t dev_addr); + +#endif + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_CUSTOM_HOST_H_ */ + +/** @} */ -- cgit v1.3.1 From dccb06ba7d7c1a162ea84b98b1429ff8f4b74b0e Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 13 Jul 2018 16:09:26 +0700 Subject: rename class driver close() to reset() --- src/class/cdc/cdc_device.c | 2 +- src/class/cdc/cdc_device.h | 2 +- src/class/custom/custom_device.c | 2 +- src/class/custom/custom_device.h | 2 +- src/class/hid/hid_device.c | 2 +- src/class/hid/hid_device.h | 2 +- src/class/msc/msc_device.c | 2 +- src/class/msc/msc_device.h | 2 +- src/device/usbd.c | 18 ++++++++++++------ 9 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src/class/custom') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index 9c991b5ab..643706269 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -232,7 +232,7 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface return TUSB_ERROR_NONE; } -void cdcd_close(uint8_t rhport) +void cdcd_reset(uint8_t rhport) { // no need to close opened pipe, dcd bus reset will put controller's endpoints to default state (void) rhport; diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index a754669df..bdce0f86e 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -99,7 +99,7 @@ void cdcd_init (void); tusb_error_t cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); tusb_error_t cdcd_control_request_st (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); -void cdcd_close (uint8_t rhport); +void cdcd_reset (uint8_t rhport); #if CFG_TUD_CDC_FLUSH_ON_SOF void cdcd_sof(uint8_t rhport); diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index 3d0453001..e4dc1a839 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -97,7 +97,7 @@ tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, return TUSB_ERROR_NONE; } -void cusd_close(uint8_t rhport) +void cusd_reset(uint8_t rhport) { } diff --git a/src/class/custom/custom_device.h b/src/class/custom/custom_device.h index 08f4f7f4a..3e46c06a7 100644 --- a/src/class/custom/custom_device.h +++ b/src/class/custom/custom_device.h @@ -64,7 +64,7 @@ void cusd_init(void); tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); tusb_error_t cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); -void cusd_close(uint8_t rhport); +void cusd_reset(uint8_t rhport); #endif diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index a6080e69d..bc2ee8c64 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -168,7 +168,7 @@ void hidd_init(void) } } -void hidd_close(uint8_t rhport) +void hidd_reset(uint8_t rhport) { for(uint8_t i=0; i 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/class/custom') 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 5dd02cbdd37e09de4265105cc9dbb7df00a5f3f7 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 27 Jul 2018 16:59:57 +0700 Subject: house keeping --- examples/obsolete/host/src/msc_cli.c | 2 ++ examples/obsolete/host/src/msc_cli.h | 2 ++ hw/bsp/pca10056/board_pca10056.c | 2 ++ hw/bsp/pca10056/board_pca10056.h | 2 ++ src/class/custom/custom_device.c | 4 +++- src/class/custom/custom_device.h | 4 +++- src/common/tusb_verify.h | 2 ++ src/device/usbd_desc.c | 4 +++- src/device/usbd_pvt.h | 2 ++ src/portable/nordic/nrf5x/dcd_nrf5x.c | 2 ++ src/portable/nordic/nrf5x/hal_nrf5x.c | 2 ++ 11 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src/class/custom') diff --git a/examples/obsolete/host/src/msc_cli.c b/examples/obsolete/host/src/msc_cli.c index aeadb4933..0182a6df9 100644 --- a/examples/obsolete/host/src/msc_cli.c +++ b/examples/obsolete/host/src/msc_cli.c @@ -31,6 +31,8 @@ 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. */ /**************************************************************************/ diff --git a/examples/obsolete/host/src/msc_cli.h b/examples/obsolete/host/src/msc_cli.h index 052ad05ee..9e41bfd06 100644 --- a/examples/obsolete/host/src/msc_cli.h +++ b/examples/obsolete/host/src/msc_cli.h @@ -31,6 +31,8 @@ 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_MSC_CLI_H_ diff --git a/hw/bsp/pca10056/board_pca10056.c b/hw/bsp/pca10056/board_pca10056.c index 85e32cf2d..c6815917e 100644 --- a/hw/bsp/pca10056/board_pca10056.c +++ b/hw/bsp/pca10056/board_pca10056.c @@ -31,6 +31,8 @@ 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. */ /**************************************************************************/ diff --git a/hw/bsp/pca10056/board_pca10056.h b/hw/bsp/pca10056/board_pca10056.h index cb477aab8..86544fcc1 100644 --- a/hw/bsp/pca10056/board_pca10056.h +++ b/hw/bsp/pca10056/board_pca10056.h @@ -31,6 +31,8 @@ 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 BOARD_PCA10056_H_ diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index c895deb18..2c3783e35 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -7,7 +7,7 @@ Software License Agreement (BSD License) - Copyright (c) 2018, Adafruit Industries (adafruit.com) + Copyright (c) 2018, hathach (tinyusb.org) All rights reserved. Redistribution and use in source and binary forms, with or without @@ -31,6 +31,8 @@ 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. */ /**************************************************************************/ diff --git a/src/class/custom/custom_device.h b/src/class/custom/custom_device.h index 3e46c06a7..81a074ce3 100644 --- a/src/class/custom/custom_device.h +++ b/src/class/custom/custom_device.h @@ -7,7 +7,7 @@ Software License Agreement (BSD License) - Copyright (c) 2018, Adafruit Industries (adafruit.com) + Copyright (c) 2018, hathach (tinyusb.org) All rights reserved. Redistribution and use in source and binary forms, with or without @@ -31,6 +31,8 @@ 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. */ /**************************************************************************/ diff --git a/src/common/tusb_verify.h b/src/common/tusb_verify.h index 95816a0e7..adcdfc97f 100644 --- a/src/common/tusb_verify.h +++ b/src/common/tusb_verify.h @@ -31,6 +31,8 @@ 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_VERIFY_H_ diff --git a/src/device/usbd_desc.c b/src/device/usbd_desc.c index 7e9feae90..095464051 100644 --- a/src/device/usbd_desc.c +++ b/src/device/usbd_desc.c @@ -7,7 +7,7 @@ Software License Agreement (BSD License) - Copyright (c) 2018, Adafruit Industries (adafruit.com) + Copyright (c) 2018, hathach (tinyusb.org) All rights reserved. Redistribution and use in source and binary forms, with or without @@ -31,6 +31,8 @@ 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. */ /**************************************************************************/ diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index 343aade77..205057db6 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -31,6 +31,8 @@ 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 USBD_PVT_H_ diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 44d1b93e2..339b8df1f 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -31,6 +31,8 @@ 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. */ /**************************************************************************/ diff --git a/src/portable/nordic/nrf5x/hal_nrf5x.c b/src/portable/nordic/nrf5x/hal_nrf5x.c index 870f8899a..7ace69ef6 100644 --- a/src/portable/nordic/nrf5x/hal_nrf5x.c +++ b/src/portable/nordic/nrf5x/hal_nrf5x.c @@ -31,6 +31,8 @@ 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. */ /**************************************************************************/ -- cgit v1.3.1 From c7340f4b0eb8dcf15fa93f6bf6589a94fb59dc95 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 23 Oct 2018 12:19:32 +0700 Subject: clean up helper func --- examples/obsolete/device/src/mouse_device_app.c | 2 +- examples/obsolete/host/src/cdc_serial_host_app.c | 4 +-- examples/obsolete/host/src/keyboard_host_app.c | 2 +- examples/obsolete/host/src/mouse_host_app.c | 2 +- examples/obsolete/host/src/msc_cli.c | 6 ++-- src/class/cdc/cdc_device.c | 4 +-- src/class/cdc/cdc_host.c | 4 +-- src/class/cdc/cdc_rndis_host.c | 8 ++--- src/class/custom/custom_device.c | 2 +- src/class/custom/custom_host.c | 4 +-- src/class/hid/hid_device.c | 8 ++--- src/class/hid/hid_host.c | 6 ++-- src/class/msc/msc_device.c | 12 ++++---- src/class/msc/msc_host.c | 4 +-- src/common/tusb_common.h | 34 +++------------------- src/device/usbd.c | 4 +-- src/host/ehci/ehci.c | 8 ++--- src/host/hub.c | 4 +-- src/host/ohci/ohci.c | 6 ++-- src/host/usbh.c | 2 +- src/osal/osal_mynewt.h | 2 +- src/portable/nordic/nrf5x/dcd_nrf5x.c | 2 +- .../nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c | 4 +-- src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c | 6 ++-- src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c | 8 ++--- tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c | 8 ++--- tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c | 2 +- .../test/host/ehci/test_pipe_bulk_open.c | 2 +- .../test/host/ehci/test_pipe_bulk_xfer.c | 4 +-- .../test/host/ehci/test_pipe_control_open.c | 2 +- .../test/host/ehci/test_pipe_control_xfer.c | 4 +-- .../test/host/ehci/test_pipe_interrupt_open.c | 4 +-- .../test/host/ehci/test_pipe_interrupt_xfer.c | 4 +-- .../test/host/ehci/test_pipe_isochronous_open.c | 2 +- .../test/host/hid/test_hidh_keyboard.c | 2 +- tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c | 2 +- tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c | 2 +- tests/support/ehci_controller_fake.c | 4 +-- tests/support/type_helper.h | 4 +-- 39 files changed, 83 insertions(+), 111 deletions(-) (limited to 'src/class/custom') diff --git a/examples/obsolete/device/src/mouse_device_app.c b/examples/obsolete/device/src/mouse_device_app.c index d6145026a..077cecc7c 100644 --- a/examples/obsolete/device/src/mouse_device_app.c +++ b/examples/obsolete/device/src/mouse_device_app.c @@ -126,7 +126,7 @@ void mouse_app_subtask(void) enum { MOUSE_RESOLUTION = 5 }; uint32_t button_mask = board_buttons(); - memclr_(&mouse_report, sizeof(hid_mouse_report_t)); + tu_memclr(&mouse_report, sizeof(hid_mouse_report_t)); if ( BIT_TEST_(button_mask, BUTTON_UP ) ) mouse_report.y = -MOUSE_RESOLUTION; if ( BIT_TEST_(button_mask, BUTTON_DOWN ) ) mouse_report.y = MOUSE_RESOLUTION; diff --git a/examples/obsolete/host/src/cdc_serial_host_app.c b/examples/obsolete/host/src/cdc_serial_host_app.c index e21a3a67d..30ed6698e 100644 --- a/examples/obsolete/host/src/cdc_serial_host_app.c +++ b/examples/obsolete/host/src/cdc_serial_host_app.c @@ -61,8 +61,8 @@ void tuh_cdc_mounted_cb(uint8_t dev_addr) { // application set-up printf("\na CDC device (address %d) is mounted\n", dev_addr); - memclr_(serial_in_buffer, sizeof(serial_in_buffer)); - memclr_(serial_out_buffer, sizeof(serial_out_buffer)); + tu_memclr(serial_in_buffer, sizeof(serial_in_buffer)); + tu_memclr(serial_out_buffer, sizeof(serial_out_buffer)); received_bytes = 0; osal_semaphore_reset(sem_hdl); diff --git a/examples/obsolete/host/src/keyboard_host_app.c b/examples/obsolete/host/src/keyboard_host_app.c index 26b1a0800..21ace3bbf 100644 --- a/examples/obsolete/host/src/keyboard_host_app.c +++ b/examples/obsolete/host/src/keyboard_host_app.c @@ -100,7 +100,7 @@ void tuh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event) //--------------------------------------------------------------------+ void keyboard_host_app_init(void) { - memclr_(&usb_keyboard_report, sizeof(hid_keyboard_report_t)); + tu_memclr(&usb_keyboard_report, sizeof(hid_keyboard_report_t)); queue_kbd_hdl = osal_queue_create( QUEUE_KEYBOARD_REPORT_DEPTH, sizeof(hid_keyboard_report_t) ); TU_ASSERT( queue_kbd_hdl, VOID_RETURN ); diff --git a/examples/obsolete/host/src/mouse_host_app.c b/examples/obsolete/host/src/mouse_host_app.c index c326becb8..e242c7caa 100644 --- a/examples/obsolete/host/src/mouse_host_app.c +++ b/examples/obsolete/host/src/mouse_host_app.c @@ -101,7 +101,7 @@ void tuh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event) //--------------------------------------------------------------------+ void mouse_host_app_init(void) { - memclr_(&usb_mouse_report, sizeof(hid_mouse_report_t)); + tu_memclr(&usb_mouse_report, sizeof(hid_mouse_report_t)); queue_mouse_hdl = osal_queue_create( QUEUE_MOUSE_REPORT_DEPTH, sizeof(hid_mouse_report_t) ); TU_ASSERT( queue_mouse_hdl, VOID_RETURN); diff --git a/examples/obsolete/host/src/msc_cli.c b/examples/obsolete/host/src/msc_cli.c index 0182a6df9..1f7b1f5ec 100644 --- a/examples/obsolete/host/src/msc_cli.c +++ b/examples/obsolete/host/src/msc_cli.c @@ -176,12 +176,12 @@ void cli_command_prompt(void) (volume_label[0] !=0) ? volume_label : "No Label", cli_buffer); - memclr_(cli_buffer, CLI_MAX_BUFFER); + tu_memclr(cli_buffer, CLI_MAX_BUFFER); } void cli_init(void) { - memclr_(cli_buffer, CLI_MAX_BUFFER); + tu_memclr(cli_buffer, CLI_MAX_BUFFER); f_getlabel(NULL, volume_label, NULL); cli_command_prompt(); } @@ -197,7 +197,7 @@ void cli_poll(char ch) }else { puts("cli buffer overflows"); - memclr_(cli_buffer, CLI_MAX_BUFFER); + tu_memclr(cli_buffer, CLI_MAX_BUFFER); } } else if ( ch == ASCII_BACKSPACE && strlen(cli_buffer)) diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index 70d51c258..06530bc7a 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -185,7 +185,7 @@ bool tud_cdc_n_write_flush (uint8_t itf) //--------------------------------------------------------------------+ void cdcd_init(void) { - arrclr_( _cdcd_itf ); + tu_memclr(_cdcd_itf, sizeof(_cdcd_itf)); for(uint8_t i=0; ipipe_in); (void) hcd_pipe_close(p_cdc->pipe_out); - memclr_(p_cdc, sizeof(cdch_data_t)); + tu_memclr(p_cdc, sizeof(cdch_data_t)); tuh_cdc_unmounted_cb(dev_addr); diff --git a/src/class/cdc/cdc_rndis_host.c b/src/class/cdc/cdc_rndis_host.c index 4d28b0e0c..9b7684f77 100644 --- a/src/class/cdc/cdc_rndis_host.c +++ b/src/class/cdc/cdc_rndis_host.c @@ -117,7 +117,7 @@ static tusb_error_t rndis_body_subtask(void) //--------------------------------------------------------------------+ void rndish_init(void) { - memclr_(rndish_data, sizeof(rndish_data_t)*CFG_TUSB_HOST_DEVICE_MAX); + tu_memclr(rndish_data, sizeof(rndish_data_t)*CFG_TUSB_HOST_DEVICE_MAX); //------------- Task creation -------------// @@ -131,7 +131,7 @@ void rndish_init(void) void rndish_close(uint8_t dev_addr) { osal_semaphore_reset( rndish_data[dev_addr-1].sem_notification_hdl ); -// memclr_(&rndish_data[dev_addr-1], sizeof(rndish_data_t)); TODO need to move semaphore & its handle out before memclr +// tu_memclr(&rndish_data[dev_addr-1], sizeof(rndish_data_t)); TODO need to move semaphore & its handle out before memclr } @@ -189,7 +189,7 @@ tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc) //------------- Message Query 802.3 Permanent Address -------------// memcpy(msg_payload, &msg_query_permanent_addr, sizeof(rndis_msg_query_t)); - memclr_(msg_payload + sizeof(rndis_msg_query_t), 6); // 6 bytes for MAC address + tu_memclr(msg_payload + sizeof(rndis_msg_query_t), 6); // 6 bytes for MAC address STASK_INVOKE( send_message_get_response_subtask( dev_addr, p_cdc, @@ -205,7 +205,7 @@ tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc) //------------- Set OID_GEN_CURRENT_PACKET_FILTER to (DIRECTED | MULTICAST | BROADCAST) -------------// memcpy(msg_payload, &msg_set_packet_filter, sizeof(rndis_msg_set_t)); - memclr_(msg_payload + sizeof(rndis_msg_set_t), 4); // 4 bytes for filter flags + tu_memclr(msg_payload + sizeof(rndis_msg_set_t), 4); // 4 bytes for filter flags ((rndis_msg_set_t*) msg_payload)->oid_buffer[0] = (RNDIS_PACKET_TYPE_DIRECTED | RNDIS_PACKET_TYPE_MULTICAST | RNDIS_PACKET_TYPE_BROADCAST); STASK_INVOKE( diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index 2c3783e35..d43a86b14 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -68,7 +68,7 @@ static cusd_interface_t _cusd_itf; *------------------------------------------------------------------*/ void cusd_init(void) { - varclr_(&_cusd_itf); + tu_varclr(&_cusd_itf); } tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len) diff --git a/src/class/custom/custom_host.c b/src/class/custom/custom_host.c index ad3315980..329012fda 100644 --- a/src/class/custom/custom_host.c +++ b/src/class/custom/custom_host.c @@ -104,7 +104,7 @@ tusb_error_t tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t p //--------------------------------------------------------------------+ void cush_init(void) { - memclr_(&custom_interface, sizeof(custom_interface_info_t) * CFG_TUSB_HOST_DEVICE_MAX); + tu_memclr(&custom_interface, sizeof(custom_interface_info_t) * CFG_TUSB_HOST_DEVICE_MAX); } tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) @@ -152,7 +152,7 @@ void cush_close(uint8_t dev_addr) err2 = hcd_pipe_close( p_interface->pipe_out ); } - memclr_(p_interface, sizeof(custom_interface_info_t)); + tu_memclr(p_interface, sizeof(custom_interface_info_t)); TU_ASSERT(err1 == TUSB_ERROR_NONE && err2 == TUSB_ERROR_NONE, (void) 0 ); } diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index b1cd1d1bd..d8696f137 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -188,7 +188,7 @@ bool tud_hid_keyboard_keycode(uint8_t modifier, uint8_t keycode[6]) memcpy(report.keycode, keycode, 6); }else { - memclr_(report.keycode, 6); + tu_memclr(report.keycode, 6); } return hidd_kbd_report(&report); @@ -307,14 +307,14 @@ void hidd_init(void) void hidd_reset(uint8_t rhport) { - arrclr_(_hidd_itf); + tu_memclr(_hidd_itf, sizeof(_hidd_itf)); #if CFG_TUD_HID_KEYBOARD - varclr_(&_kbd_rpt); + tu_varclr(&_kbd_rpt); #endif #if CFG_TUD_HID_MOUSE - varclr_(&_mse_rpt); + tu_varclr(&_mse_rpt); #endif } diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 369dad638..518297eec 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -68,7 +68,7 @@ static inline tusb_error_t hidh_interface_open(uint8_t dev_addr, uint8_t interfa static inline void hidh_interface_close(hidh_interface_info_t *p_hid) { (void) hcd_pipe_close(p_hid->pipe_hdl); - memclr_(p_hid, sizeof(hidh_interface_info_t)); + tu_memclr(p_hid, sizeof(hidh_interface_info_t)); } // called from public API need to validate parameters @@ -164,11 +164,11 @@ tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void * report) void hidh_init(void) { #if CFG_TUSB_HOST_HID_KEYBOARD - memclr_(&keyboardh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX); + tu_memclr(&keyboardh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX); #endif #if CFG_TUSB_HOST_HID_MOUSE - memclr_(&mouseh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX); + tu_memclr(&mouseh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX); #endif #if CFG_TUSB_HOST_HID_GENERIC diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 3335ad9b3..830ce85b7 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -62,9 +62,9 @@ enum typedef struct { CFG_TUSB_MEM_ALIGN msc_cbw_t cbw; -#if defined (__ICCARM__) && (CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13UXX) - uint8_t padding1[64-sizeof(msc_cbw_t)]; // IAR cannot align struct's member -#endif +//#if defined (__ICCARM__) && (CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13UXX) +// uint8_t padding1[64-sizeof(msc_cbw_t)]; // IAR cannot align struct's member +//#endif CFG_TUSB_MEM_ALIGN msc_csw_t csw; @@ -141,12 +141,12 @@ bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, u //--------------------------------------------------------------------+ void mscd_init(void) { - memclr_(&_mscd_itf, sizeof(mscd_interface_t)); + tu_memclr(&_mscd_itf, sizeof(mscd_interface_t)); } void mscd_reset(uint8_t rhport) { - memclr_(&_mscd_itf, sizeof(mscd_interface_t)); + tu_memclr(&_mscd_itf, sizeof(mscd_interface_t)); } tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len) @@ -302,7 +302,6 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u { case MSC_STAGE_CMD: //------------- new CBW received -------------// - // Complete IN while waiting for CMD is usually Status of previous SCSI op, ignore it if(ep_addr != p_msc->ep_out) return TUSB_ERROR_NONE; @@ -332,7 +331,6 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u // 1. Zero : Invoke app callback, skip DATA and move to STATUS stage // 2. OUT : queue transfer (invoke app callback after done) // 3. IN : invoke app callback to get response - if ( p_cbw->xfer_bytes == 0) { int32_t const cb_result = tud_msc_scsi_cb(p_cbw->lun, p_cbw->command, NULL, 0); diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 7e6396389..9250b8df7 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -288,7 +288,7 @@ tusb_error_t tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * p_buffe //--------------------------------------------------------------------+ void msch_init(void) { - memclr_(msch_data, sizeof(msch_interface_t)*CFG_TUSB_HOST_DEVICE_MAX); + tu_memclr(msch_data, sizeof(msch_interface_t)*CFG_TUSB_HOST_DEVICE_MAX); msch_sem_hdl = osal_semaphore_create(1, 0); } @@ -416,7 +416,7 @@ void msch_close(uint8_t dev_addr) (void) hcd_pipe_close(msch_data[dev_addr-1].bulk_in); (void) hcd_pipe_close(msch_data[dev_addr-1].bulk_out); - memclr_(&msch_data[dev_addr-1], sizeof(msch_interface_t)); + tu_memclr(&msch_data[dev_addr-1], sizeof(msch_interface_t)); osal_semaphore_reset(msch_sem_hdl); tuh_msc_unmounted_cb(dev_addr); // invoke Application Callback diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 778e70676..85bd15d43 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -73,8 +73,7 @@ //--------------------------------------------------------------------+ // MACROS //--------------------------------------------------------------------+ -#define MAX_OF(a, b) ( (a) > (b) ? (a) : (b) ) -#define MIN_OF(a, b) ( (a) < (b) ? (a) : (b) ) +#define TU_ARRAY_SZIE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) ) #define U16_HIGH_U8(u16) ((uint8_t) (((u16) >> 8) & 0x00ff)) #define U16_LOW_U8(u16) ((uint8_t) ((u16) & 0x00ff)) @@ -137,12 +136,10 @@ //--------------------------------------------------------------------+ // INLINE FUNCTION //--------------------------------------------------------------------+ -#define memclr_(buffer, size) memset((buffer), 0, (size)) -#define varclr_(_var) memclr_(_var, sizeof(*(_var))) -#define arrclr_(_arr) memclr_(_arr, sizeof(_arr)) -#define arrcount_(_arr) ( sizeof(_arr) / sizeof(_arr[0]) ) +#define tu_memclr(buffer, size) memset((buffer), 0, (size)) +#define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var))) -static inline bool mem_all_zero(void const* buffer, uint32_t size) +static inline bool tu_mem_test_zero (void const* buffer, uint32_t size) { uint8_t const* p_mem = (uint8_t const*) buffer; for(uint32_t i=0; i y) ? x : y; } -static inline uint16_t tu_max16(uint16_t x, uint16_t y) -{ - return (x > y) ? x : y; -} - //------------- Align -------------// static inline uint32_t tu_align32 (uint32_t value) { @@ -249,24 +241,6 @@ static inline uint8_t tu_log2(uint32_t value) return result; } -// return the number of set bits in value -static inline uint8_t tu_cardof(uint32_t value) -{ - // Brian Kernighan's method goes through as many iterations as there are set bits. So if we have a 32-bit word with only - // the high bit set, then it will only go once through the loop - // Published in 1988, the C Programming Language 2nd Ed. (by Brian W. Kernighan and Dennis M. Ritchie) - // mentions this in exercise 2-9. On April 19, 2006 Don Knuth pointed out to me that this method - // "was first published by Peter Wegner in CACM 3 (1960), 322. (Also discovered independently by Derrick Lehmer and - // published in 1964 in a book edited by Beckenbach.)" - uint8_t count; - for (count = 0; value; count++) - { - value &= value - 1; // clear the least significant bit set - } - - return count; -} - #ifdef __cplusplus } #endif diff --git a/src/device/usbd.c b/src/device/usbd.c index 89dd4b722..146f8ec89 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -274,7 +274,7 @@ static tusb_error_t usbd_main_st(void) tusb_error_t err; err = TUSB_ERROR_NONE; - memclr_(&event, sizeof(usbd_task_event_t)); + tu_memclr(&event, sizeof(usbd_task_event_t)); osal_queue_receive(_usbd_q, &event, OSAL_TIMEOUT_WAIT_FOREVER, &err); @@ -318,7 +318,7 @@ static tusb_error_t usbd_main_st(void) static void usbd_reset(uint8_t rhport) { - varclr_(&_usbd_dev); + tu_varclr(&_usbd_dev); memset(_usbd_dev.itf2drv, 0xff, sizeof(_usbd_dev.itf2drv)); // invalid mapping memset(_usbd_dev.ep2drv , 0xff, sizeof(_usbd_dev.ep2drv )); // invalid mapping diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 84821e3f5..99e7fdb65 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -130,7 +130,7 @@ static tusb_error_t hcd_controller_stop(uint8_t hostid) ATTR_WARN_UNUSED_RESULT tusb_error_t hcd_init(void) { //------------- Data Structure init -------------// - memclr_(&ehci_data, sizeof(ehci_data_t)); + tu_memclr(&ehci_data, sizeof(ehci_data_t)); #if (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST) TU_ASSERT_ERR (hcd_controller_init(0)); @@ -192,7 +192,7 @@ static tusb_error_t hcd_controller_init(uint8_t hostid) //------------- Asynchronous List -------------// ehci_qhd_t * const async_head = get_async_head(hostid); - memclr_(async_head, sizeof(ehci_qhd_t)); + tu_memclr(async_head, sizeof(ehci_qhd_t)); async_head->next.address = (uint32_t) async_head; // circular list, next is itself async_head->next.type = EHCI_QUEUE_ELEMENT_QHD; @@ -938,7 +938,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si // address 0 is used as async head, which always on the list --> cannot be cleared (ehci halted otherwise) if (dev_addr != 0) { - memclr_(p_qhd, sizeof(ehci_qhd_t)); + tu_memclr(p_qhd, sizeof(ehci_qhd_t)); } p_qhd->device_address = dev_addr; @@ -1004,7 +1004,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si static void qtd_init(ehci_qtd_t* p_qtd, uint32_t data_ptr, uint16_t total_bytes) { - memclr_(p_qtd, sizeof(ehci_qtd_t)); + tu_memclr(p_qtd, sizeof(ehci_qtd_t)); p_qtd->used = 1; diff --git a/src/host/hub.c b/src/host/hub.c index 063cef61a..624e43563 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -152,7 +152,7 @@ tusb_speed_t hub_port_get_speed(void) //--------------------------------------------------------------------+ void hub_init(void) { - memclr_(hub_data, CFG_TUSB_HOST_DEVICE_MAX*sizeof(usbh_hub_t)); + tu_memclr(hub_data, CFG_TUSB_HOST_DEVICE_MAX*sizeof(usbh_hub_t)); // hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) ); } @@ -237,7 +237,7 @@ void hub_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes) void hub_close(uint8_t dev_addr) { (void) hcd_pipe_close(hub_data[dev_addr-1].pipe_status); - memclr_(&hub_data[dev_addr-1], sizeof(usbh_hub_t)); + tu_memclr(&hub_data[dev_addr-1], sizeof(usbh_hub_t)); // osal_semaphore_reset(hub_enum_sem_hdl); } diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index 1c9f3f293..b9183a025 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -164,7 +164,7 @@ static ohci_ed_t * ed_list_find_previous(ohci_ed_t const * p_head, ohci_ed_t con tusb_error_t hcd_init(void) { //------------- Data Structure init -------------// - memclr_(&ohci_data, sizeof(ohci_data_t)); + tu_memclr(&ohci_data, sizeof(ohci_data_t)); for(uint8_t i=0; i<32; i++) { // assign all interrupt pointes to period head ed ohci_data.hcca.interrupt_table[i] = (uint32_t) &ohci_data.period_head_ed; @@ -245,7 +245,7 @@ static void ed_init(ohci_ed_t *p_ed, uint8_t dev_addr, uint16_t max_packet_size, // address 0 is used as async head, which always on the list --> cannot be cleared if (dev_addr != 0) { - memclr_(p_ed, sizeof(ohci_ed_t)); + tu_memclr(p_ed, sizeof(ohci_ed_t)); } p_ed->device_address = dev_addr; @@ -261,7 +261,7 @@ static void ed_init(ohci_ed_t *p_ed, uint8_t dev_addr, uint16_t max_packet_size, static void gtd_init(ohci_gtd_t* p_td, void* data_ptr, uint16_t total_bytes) { - memclr_(p_td, sizeof(ohci_gtd_t)); + tu_memclr(p_td, sizeof(ohci_gtd_t)); p_td->used = 1; p_td->expected_bytes = total_bytes; diff --git a/src/host/usbh.c b/src/host/usbh.c index 8b858b2de..b849de9b9 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -142,7 +142,7 @@ uint32_t tuh_device_get_mounted_class_flag(uint8_t dev_addr) //--------------------------------------------------------------------+ tusb_error_t usbh_init(void) { - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); + tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); TU_ASSERT_ERR( hcd_init() ); diff --git a/src/osal/osal_mynewt.h b/src/osal/osal_mynewt.h index db65ac553..59cd1b821 100644 --- a/src/osal/osal_mynewt.h +++ b/src/osal/osal_mynewt.h @@ -145,7 +145,7 @@ static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * da os_memblock_put(&queue_hdl->mpool, ptr); return false; } - memclr_(ev, sizeof(struct os_event)); + tu_memclr(ev, sizeof(struct os_event)); ev->ev_arg = ptr; os_eventq_put(&queue_hdl->evq, ev); diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 01926c76e..371c291a3 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -108,7 +108,7 @@ void bus_reset(void) NRF_USBD->TASKS_STARTISOIN = 0; NRF_USBD->TASKS_STARTISOOUT = 0; - varclr_(&_dcd); + tu_varclr(&_dcd); } /*------------------------------------------------------------------*/ 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 292d1fa6d..8e5a4d1aa 100644 --- a/src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c +++ b/src/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c @@ -201,7 +201,7 @@ bool dcd_init(uint8_t rhport) static void bus_reset(void) { - memclr_(&dcd_data, sizeof(dcd_11u_13u_data_t)); + tu_memclr(&dcd_data, sizeof(dcd_11u_13u_data_t)); for(uint8_t ep_id = 2; ep_id < DCD_11U_13U_QHD_COUNT; ep_id++) { // disable all non-control endpoints on bus reset dcd_data.qhd[ep_id][0].disable = dcd_data.qhd[ep_id][1].disable = 1; @@ -473,7 +473,7 @@ edpt_hdl_t dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint TU_ASSERT( dcd_data.qhd[ep_id][0].disable && dcd_data.qhd[ep_id][1].disable, null_handle ); // endpoint must not previously opened, normally this means running out of endpoints - memclr_(dcd_data.qhd[ep_id], 2*sizeof(dcd_11u_13u_qhd_t)); + tu_memclr(dcd_data.qhd[ep_id], 2*sizeof(dcd_11u_13u_qhd_t)); dcd_data.qhd[ep_id][0].is_isochronous = dcd_data.qhd[ep_id][1].is_isochronous = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS); dcd_data.class_code[ep_id] = class_code; diff --git a/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c b/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c index 4d3687830..189521d25 100644 --- a/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c +++ b/src/portable/nxp/lpc17xx/dcd_lpc175x_6x.c @@ -119,7 +119,7 @@ static void bus_reset(void) LPC_USB->USBNDDRIntClr = 0xFFFFFFFF; LPC_USB->USBSysErrIntClr = 0xFFFFFFFF; - memclr_(&dcd_data, sizeof(dcd_data_t)); + tu_memclr(&dcd_data, sizeof(dcd_data_t)); } bool dcd_init(uint8_t rhport) @@ -432,7 +432,7 @@ edpt_hdl_t dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint //------------- first DD prepare -------------// dcd_dma_descriptor_t* const p_dd = &dcd_data.dd[ep_id][0]; - memclr_(p_dd, sizeof(dcd_dma_descriptor_t)); + tu_memclr(p_dd, sizeof(dcd_dma_descriptor_t)); p_dd->is_isochronous = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) ? 1 : 0; p_dd->max_packet_size = p_endpoint_desc->wMaxPacketSize.size; @@ -498,7 +498,7 @@ tusb_error_t dcd_edpt_xfer(edpt_hdl_t edpt_hdl, uint8_t* buffer, uint16_t total_ { // setup new dd dcd_dma_descriptor_t* const p_dd = &dcd_data.dd[ edpt_hdl.index ][1]; - memclr_(p_dd, sizeof(dcd_dma_descriptor_t)); + tu_memclr(p_dd, sizeof(dcd_dma_descriptor_t)); dd_xfer_init(p_dd, buffer, total_bytes); diff --git a/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c b/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c index 7368542b8..5a7d61004 100644 --- a/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c +++ b/src/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c @@ -133,7 +133,7 @@ static void bus_reset(uint8_t rhport) //------------- Queue Head & Queue TD -------------// dcd_data_t* p_dcd = dcd_data_ptr[rhport]; - memclr_(p_dcd, sizeof(dcd_data_t)); + tu_memclr(p_dcd, sizeof(dcd_data_t)); //------------- Set up Control Endpoints (0 OUT, 1 IN) -------------// p_dcd->qhd[0].zero_length_termination = p_dcd->qhd[1].zero_length_termination = 1; @@ -149,7 +149,7 @@ bool dcd_init(uint8_t rhport) LPC_USB0_Type* const lpc_usb = LPC_USB[rhport]; dcd_data_t* p_dcd = dcd_data_ptr[rhport]; - memclr_(p_dcd, sizeof(dcd_data_t)); + tu_memclr(p_dcd, sizeof(dcd_data_t)); lpc_usb->ENDPOINTLISTADDR = (uint32_t) p_dcd->qhd; // Endpoint List Address has to be 2K alignment lpc_usb->USBSTS_D = lpc_usb->USBSTS_D; @@ -196,7 +196,7 @@ static inline uint8_t edpt_phy2log(uint8_t physical_endpoint) static void qtd_init(dcd_qtd_t* p_qtd, void * data_ptr, uint16_t total_bytes) { - memclr_(p_qtd, sizeof(dcd_qtd_t)); + tu_memclr(p_qtd, sizeof(dcd_qtd_t)); p_qtd->used = 1; @@ -303,7 +303,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) uint8_t ep_idx = edpt_addr2phy(p_endpoint_desc->bEndpointAddress); dcd_qhd_t * p_qhd = &dcd_data_ptr[rhport]->qhd[ep_idx]; - memclr_(p_qhd, sizeof(dcd_qhd_t)); + tu_memclr(p_qhd, sizeof(dcd_qhd_t)); p_qhd->zero_length_termination = 1; p_qhd->max_package_size = p_endpoint_desc->wMaxPacketSize.size; diff --git a/tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c b/tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c index ef084fc77..31baa5f5c 100644 --- a/tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c +++ b/tests/lpc175x_6x/test/test_dcd_lpc175x_6x.c @@ -51,9 +51,9 @@ extern dcd_dma_descriptor_t dcd_dd[DCD_MAX_DD]; void setUp(void) { - memclr_(dcd_udca, 32*4); - memclr_(dcd_dd, sizeof(dcd_dma_descriptor_t)*DCD_MAX_DD); - memclr_(&lpc_usb, sizeof(LPC_USB_TypeDef)); + tu_memclr(dcd_udca, 32*4); + tu_memclr(dcd_dd, sizeof(dcd_dma_descriptor_t)*DCD_MAX_DD); + tu_memclr(&lpc_usb, sizeof(LPC_USB_TypeDef)); } void tearDown(void) @@ -129,7 +129,7 @@ void test_dcd_configure_endpoint_in(void) }; dcd_init(); - memclr_(&lpc_usb, sizeof(LPC_USB_TypeDef)); // clear to examine register after CUT + tu_memclr(&lpc_usb, sizeof(LPC_USB_TypeDef)); // clear to examine register after CUT //------------- Code Under Test -------------// dcd_pipe_open(0, &desc_endpoint); diff --git a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c index a74270e8b..5077eea93 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c +++ b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c @@ -71,7 +71,7 @@ void setUp(void) length = 0; dev_addr = 1; - memclr_(cdch_data, sizeof(cdch_data_t)*CFG_TUSB_HOST_DEVICE_MAX); + tu_memclr(cdch_data, sizeof(cdch_data_t)*CFG_TUSB_HOST_DEVICE_MAX); } void tearDown(void) diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c index a26b990d3..581488d7d 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c @@ -70,7 +70,7 @@ void setUp(void) dev_addr = 1; hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); + tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH); async_head = get_async_head( hostid ); diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c index a52c721fe..2e9e29fdc 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c @@ -90,8 +90,8 @@ tusb_desc_endpoint_t const desc_ept_bulk_out = void setUp(void) { ehci_controller_init(); - memclr_(xfer_data, sizeof(xfer_data)); - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); + tu_memclr(xfer_data, sizeof(xfer_data)); + tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); TEST_ASSERT_STATUS( hcd_init() ); diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_open.c index 22cbf7569..426fed9f2 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_open.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_open.c @@ -67,7 +67,7 @@ static ehci_qhd_t *p_control_qhd; //--------------------------------------------------------------------+ void setUp(void) { - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); + tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); TEST_ASSERT_STATUS( hcd_init() ); diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_xfer.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_xfer.c index 286aae113..ffd7ffb67 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_xfer.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_control_xfer.c @@ -74,8 +74,8 @@ void setUp(void) { ehci_controller_init(); - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); - memclr_(xfer_data, sizeof(xfer_data)); + tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); + tu_memclr(xfer_data, sizeof(xfer_data)); TEST_ASSERT_STATUS( hcd_init() ); diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c index f39021ef2..b243a468e 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c @@ -67,7 +67,7 @@ static pipe_handle_t pipe_hdl; //--------------------------------------------------------------------+ void setUp(void) { - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); + tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); hcd_init(); @@ -78,7 +78,7 @@ void setUp(void) period_head_arr = get_period_head( hostid, 1 ); p_int_qhd = NULL; - memclr_(&pipe_hdl, sizeof(pipe_handle_t)); + tu_memclr(&pipe_hdl, sizeof(pipe_handle_t)); } void tearDown(void) diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c index aeb094932..827db2897 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c @@ -91,8 +91,8 @@ void setUp(void) { ehci_controller_init(); - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); - memclr_(xfer_data, sizeof(xfer_data)); + tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); + tu_memclr(xfer_data, sizeof(xfer_data)); TEST_ASSERT_STATUS( hcd_init() ); diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c index 584c44471..1feff94e5 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c @@ -63,7 +63,7 @@ static ehci_qhd_t *period_head_arr; //--------------------------------------------------------------------+ void setUp(void) { - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); + tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); hcd_init(); 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 75c8f8a90..b3b49c172 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c @@ -73,7 +73,7 @@ tusb_desc_endpoint_t const *p_kdb_endpoint_desc = &desc_configuration.keyboard void setUp(void) { hidh_init(); - memclr_(&report, sizeof(hid_keyboard_report_t)); + tu_memclr(&report, sizeof(hid_keyboard_report_t)); dev_addr = RANDOM(CFG_TUSB_HOST_DEVICE_MAX)+1; p_hidh_kbd = &keyboardh_data[dev_addr-1]; 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 741f54428..b1a3558e6 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c @@ -62,7 +62,7 @@ void setUp(void) { hidh_init(); - memclr_(&report, sizeof(hid_mouse_report_t)); + tu_memclr(&report, sizeof(hid_mouse_report_t)); dev_addr = RANDOM(CFG_TUSB_HOST_DEVICE_MAX)+1; p_hidh_mouse = &mouseh_data[dev_addr-1]; diff --git a/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c b/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c index 7aeba21a0..a85c3c48a 100644 --- a/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c +++ b/tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c @@ -73,7 +73,7 @@ enum { void setUp(void) { - memclr_(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); + tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1)); osal_queue_receive_StubWithCallback(queue_recv_stub); osal_semaphore_wait_StubWithCallback(semaphore_wait_success_stub); diff --git a/tests/support/ehci_controller_fake.c b/tests/support/ehci_controller_fake.c index 041e1dbb5..acd40cc0b 100644 --- a/tests/support/ehci_controller_fake.c +++ b/tests/support/ehci_controller_fake.c @@ -61,8 +61,8 @@ extern usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; //--------------------------------------------------------------------+ void ehci_controller_init(void) { - memclr_(&lpc_usb0, sizeof(LPC_USB0_Type)); - memclr_(&lpc_usb1, sizeof(LPC_USB1_Type)); + tu_memclr(&lpc_usb0, sizeof(LPC_USB0_Type)); + tu_memclr(&lpc_usb1, sizeof(LPC_USB1_Type)); } void ehci_controller_control_xfer_proceed(uint8_t dev_addr, uint8_t p_data[]) diff --git a/tests/support/type_helper.h b/tests/support/type_helper.h index 3e27cef2e..36502ba35 100644 --- a/tests/support/type_helper.h +++ b/tests/support/type_helper.h @@ -75,7 +75,7 @@ ({\ uint32_t value=0;\ struct_type str;\ - memclr_((void*)&str, sizeof(struct_type));\ + tu_memclr((void*)&str, sizeof(struct_type));\ str.member.bitfield_member = 1;\ memcpy(&value, (void*)&str.member, sizeof(str.member));\ tu_log2( value );\ @@ -84,7 +84,7 @@ #define BITFIELD_OFFSET_OF_UINT32(struct_type, offset, bitfield_member) \ ({\ struct_type str;\ - memclr_(&str, sizeof(struct_type));\ + tu_memclr(&str, sizeof(struct_type));\ str.bitfield_member = 1;\ tu_log2( ((uint32_t*) &str)[offset] );\ }) -- cgit v1.3.1 From 30e3c64134789416e10ed867fa12c210b808e98f Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 8 Nov 2018 13:45:30 -0800 Subject: Polish up control split and treat it more like a normal endpoint. --- src/class/cdc/cdc_device.c | 28 +++++-- src/class/cdc/cdc_device.h | 1 + src/class/custom/custom_device.c | 2 +- src/class/custom/custom_device.h | 1 + src/class/hid/hid_device.c | 32 +++++--- src/class/hid/hid_device.h | 1 + src/class/msc/msc_device.c | 5 ++ src/class/msc/msc_device.h | 1 + src/device/control.c | 14 +++- src/device/control.h | 3 + src/device/usbd.c | 16 ++++ src/portable/nordic/nrf5x/dcd_nrf5x.c | 136 ++++++++-------------------------- 12 files changed, 114 insertions(+), 126 deletions(-) (limited to 'src/class/custom') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index 81d7fa526..ab9addc93 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -288,6 +288,21 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface return TUSB_ERROR_NONE; } +void cdcd_control_request_complete(uint8_t rhport, tusb_control_request_t const * p_request) +{ + //------------- Class Specific Request -------------// + if (p_request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS) return; + + // TODO Support multiple interfaces + uint8_t const itf = 0; + cdcd_interface_t* p_cdc = &_cdcd_itf[itf]; + + // Invoke callback + if (CDC_REQUEST_SET_LINE_CODING == p_request->bRequest) { + if ( tud_cdc_line_coding_cb ) tud_cdc_line_coding_cb(itf, &p_cdc->line_coding); + } +} + tusb_error_t cdcd_control_request(uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent) { //------------- Class Specific Request -------------// @@ -297,16 +312,15 @@ tusb_error_t cdcd_control_request(uint8_t rhport, tusb_control_request_t const * uint8_t const itf = 0; cdcd_interface_t* p_cdc = &_cdcd_itf[itf]; - if ( (CDC_REQUEST_GET_LINE_CODING == p_request->bRequest) || (CDC_REQUEST_SET_LINE_CODING == p_request->bRequest) ) + if ((CDC_REQUEST_SET_LINE_CODING == p_request->bRequest) ) + { + uint16_t len = tu_min16(sizeof(cdc_line_coding_t), p_request->wLength); + dcd_edpt_xfer(rhport, 0, (uint8_t*) &p_cdc->line_coding, len); + } + else if ( (CDC_REQUEST_GET_LINE_CODING == p_request->bRequest)) { uint16_t len = tu_min16(sizeof(cdc_line_coding_t), p_request->wLength); dcd_edpt_xfer(rhport, TUSB_DIR_IN_MASK, (uint8_t*) &p_cdc->line_coding, len); - - // Invoke callback - if (CDC_REQUEST_SET_LINE_CODING == p_request->bRequest) - { - if ( tud_cdc_line_coding_cb ) tud_cdc_line_coding_cb(itf, &p_cdc->line_coding); - } } else if (CDC_REQUEST_SET_CONTROL_LINE_STATE == p_request->bRequest ) { diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 88d37a83c..2f902ae04 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -113,6 +113,7 @@ ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_li void cdcd_init (void); tusb_error_t cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); tusb_error_t cdcd_control_request (uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent); +void cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); void cdcd_reset (uint8_t rhport); diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index d43a86b14..1b36f1331 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -89,7 +89,7 @@ tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, return TUSB_ERROR_NONE; } -tusb_error_t cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request) +tusb_error_t cusd_control_request(uint8_t rhport, tusb_control_request_t const * p_request) { return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; } diff --git a/src/class/custom/custom_device.h b/src/class/custom/custom_device.h index 81a074ce3..116c6897d 100644 --- a/src/class/custom/custom_device.h +++ b/src/class/custom/custom_device.h @@ -65,6 +65,7 @@ void cusd_init(void); tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); tusb_error_t cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request); +void cusd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); void cusd_reset(uint8_t rhport); #endif diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index aa7a8008e..efa602ad6 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -455,15 +455,6 @@ tusb_error_t hidd_control_request(uint8_t rhport, tusb_control_request_t const * else if ( HID_REQ_CONTROL_SET_REPORT == p_request->bRequest ) { dcd_edpt_xfer(rhport, 0, _shared_control_buffer, p_request->wLength); - - // wValue = Report Type | Report ID - uint8_t const report_type = tu_u16_high(p_request->wValue); - uint8_t const report_id = tu_u16_low(p_request->wValue); - - if ( p_hid->set_report_cb ) - { - p_hid->set_report_cb(report_id, (hid_report_type_t) report_type, _shared_control_buffer, p_request->wLength); - } } else if (HID_REQ_CONTROL_SET_IDLE == p_request->bRequest) { @@ -495,6 +486,29 @@ tusb_error_t hidd_control_request(uint8_t rhport, tusb_control_request_t const * return TUSB_ERROR_NONE; } +void hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const * p_request) +{ + hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex ); + if (p_hid == NULL) { + return; + } + + if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS) + { + if ( HID_REQ_CONTROL_SET_REPORT == p_request->bRequest ) + { + // wValue = Report Type | Report ID + uint8_t const report_type = tu_u16_high(p_request->wValue); + uint8_t const report_id = tu_u16_low(p_request->wValue); + + if ( p_hid->set_report_cb ) + { + p_hid->set_report_cb(report_id, (hid_report_type_t) report_type, _shared_control_buffer, p_request->wLength); + } + } + } +} + tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes) { // nothing to do diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 10aea10ac..1dc40af57 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -379,6 +379,7 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(uint8_t report_id, hid_report_type_t void hidd_init(void); tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); tusb_error_t hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent); +void hidd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); void hidd_reset(uint8_t rhport); diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 3c9997b95..32ad90102 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -167,6 +167,11 @@ tusb_error_t mscd_control_request(uint8_t rhport, tusb_control_request_t const * return TUSB_ERROR_NONE; } +void mscd_control_request_complete(uint8_t rhport, tusb_control_request_t const * p_request) +{ + return; +} + // For backwards compatibility we support static block counts. #if defined(CFG_TUD_MSC_BLOCK_NUM) && defined(CFG_TUD_MSC_BLOCK_SZ) ATTR_WEAK bool tud_lun_capacity_cb(uint8_t lun, uint32_t* last_valid_sector, uint16_t* block_size) { diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index a5bc54ff9..ac3eade22 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -199,6 +199,7 @@ ATTR_WEAK bool tud_lun_capacity_cb(uint8_t lun, uint32_t* last_valid_sector, uin void mscd_init(void); tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); tusb_error_t mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent); +void mscd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); void mscd_reset(uint8_t rhport); diff --git a/src/device/control.c b/src/device/control.c index 4944a999e..5856f0628 100644 --- a/src/device/control.c +++ b/src/device/control.c @@ -59,8 +59,13 @@ void controld_init(void) { // Note dir is value of direction bit in setup packet (i.e DATA stage direction) static inline bool dcd_control_status(uint8_t rhport, uint8_t dir) { + uint8_t ep_addr = 0; + // Invert the direction. + if (dir == TUSB_DIR_OUT) { + ep_addr |= TUSB_DIR_IN_MASK; + } // status direction is reversed to one in the setup packet - return dcd_edpt_xfer(rhport, 1-dir, NULL, 0); + return dcd_edpt_xfer(rhport, ep_addr, NULL, 0); } static inline void dcd_control_stall(uint8_t rhport) @@ -140,6 +145,12 @@ tusb_error_t controld_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t ev if (p_request->wLength == control_state.total_transferred || xferred_bytes < 64) { control_state.current_stage = CONTROL_STAGE_STATUS; dcd_control_status(rhport, p_request->bmRequestType_bit.direction); + + // Do the user callback after queueing the STATUS packet because the callback could be slow. + if ( TUSB_REQ_RCPT_INTERFACE == p_request->bmRequestType_bit.recipient ) + { + tud_control_interface_control_complete_cb(rhport, tu_u16_low(p_request->wIndex), p_request); + } } else { if (TUSB_REQ_RCPT_INTERFACE == p_request->bmRequestType_bit.recipient) { error = tud_control_interface_control_cb(rhport, tu_u16_low(p_request->wIndex), p_request, control_state.total_transferred); @@ -161,7 +172,6 @@ tusb_error_t controld_process_setup_request(uint8_t rhport, tusb_control_request control_state.total_transferred = 0; } - if ( TUSB_REQ_RCPT_INTERFACE == p_request->bmRequestType_bit.recipient ) { error = tud_control_interface_control_cb(rhport, tu_u16_low(p_request->wIndex), p_request, 0); diff --git a/src/device/control.h b/src/device/control.h index 24f0d0a14..881c99ead 100644 --- a/src/device/control.h +++ b/src/device/control.h @@ -68,6 +68,9 @@ tusb_error_t controld_process_setup_request(uint8_t rhport, tusb_control_request // Callback when the configuration of the device is changed. tusb_error_t tud_control_set_config_cb(uint8_t rhport, uint8_t config_number); +// Called when the DATA stage of a control transaction is complete. +void tud_control_interface_control_complete_cb(uint8_t rhport, uint8_t interface, tusb_control_request_t const * const p_request); + tusb_error_t tud_control_interface_control_cb(uint8_t rhport, uint8_t interface, tusb_control_request_t const * const p_request, uint16_t bytes_already_sent); //--------------------------------------------------------------------+ diff --git a/src/device/usbd.c b/src/device/usbd.c index 3c77fefba..c9d5e5642 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -96,6 +96,7 @@ typedef struct { tusb_error_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t* p_length); // Control request is called one or more times for a request and can queue multiple data packets. tusb_error_t (* control_request ) (uint8_t rhport, tusb_control_request_t const *, uint16_t bytes_already_sent); + void (* control_request_complete ) (uint8_t rhport, tusb_control_request_t const *); tusb_error_t (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, tusb_event_t, uint32_t); void (* sof ) (uint8_t rhport); void (* reset ) (uint8_t); @@ -108,6 +109,7 @@ static usbd_class_driver_t const usbd_class_drivers[] = .init = controld_init, .open = NULL, .control_request = NULL, + .control_request_complete = NULL, .xfer_cb = controld_xfer_cb, .sof = NULL, .reset = controld_reset @@ -118,6 +120,7 @@ static usbd_class_driver_t const usbd_class_drivers[] = .init = cdcd_init, .open = cdcd_open, .control_request = cdcd_control_request, + .control_request_complete = cdcd_control_request_complete, .xfer_cb = cdcd_xfer_cb, .sof = NULL, .reset = cdcd_reset @@ -130,6 +133,7 @@ static usbd_class_driver_t const usbd_class_drivers[] = .init = mscd_init, .open = mscd_open, .control_request = mscd_control_request, + .control_request_complete = mscd_control_request_complete, .xfer_cb = mscd_xfer_cb, .sof = NULL, .reset = mscd_reset @@ -143,6 +147,7 @@ static usbd_class_driver_t const usbd_class_drivers[] = .init = hidd_init, .open = hidd_open, .control_request = hidd_control_request, + .control_request_complete = hidd_control_request_complete, .xfer_cb = hidd_xfer_cb, .sof = NULL, .reset = hidd_reset @@ -155,6 +160,7 @@ static usbd_class_driver_t const usbd_class_drivers[] = .init = cusd_init, .open = cusd_open, .control_request = cusd_control_request, + .control_request_complete = cusd_control_request_complete, .xfer_cb = cusd_xfer_cb, .sof = NULL, .reset = cusd_reset @@ -309,6 +315,16 @@ static tusb_error_t usbd_main_st(void) return err; } +void tud_control_interface_control_complete_cb(uint8_t rhport, uint8_t interface, tusb_control_request_t const * const p_request) { + if (_usbd_dev.itf2drv[ interface ] < USBD_CLASS_DRIVER_COUNT) + { + const usbd_class_driver_t *driver = &usbd_class_drivers[_usbd_dev.itf2drv[interface]]; + if (driver->control_request_complete != NULL) { + driver->control_request_complete(rhport, p_request); + } + } +} + tusb_error_t tud_control_interface_control_cb(uint8_t rhport, uint8_t interface, tusb_control_request_t const * const p_request, uint16_t bytes_already_sent) { if (_usbd_dev.itf2drv[ interface ] < USBD_CLASS_DRIVER_COUNT) { diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index 1e3dc4cba..74b7bb7b8 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -82,17 +82,8 @@ typedef struct /*static*/ struct { - struct - { - uint8_t* buffer; - uint16_t total_len; - volatile uint16_t actual_len; - - uint8_t dir; - }control; - - // Non control: 7 endpoints IN & OUT (offset 1) - nom_xfer_t xfer[7][2]; + // All 8 endpoints including control IN & OUT (offset 1) + nom_xfer_t xfer[8][2]; volatile bool dma_running; }_dcd; @@ -109,6 +100,8 @@ void bus_reset(void) NRF_USBD->TASKS_STARTISOOUT = 0; tu_varclr(&_dcd); + _dcd.xfer[0][TUSB_DIR_IN].mps = MAX_PACKET_SIZE; + _dcd.xfer[0][TUSB_DIR_OUT].mps = MAX_PACKET_SIZE; } /*------------------------------------------------------------------*/ @@ -176,65 +169,13 @@ static void edpt_dma_end(void) _dcd.dma_running = false; } -static void xact_control_start(void) -{ - // Each transaction is up to 64 bytes - uint8_t const xact_len = tu_min16(_dcd.control.total_len-_dcd.control.actual_len, MAX_PACKET_SIZE); - - if ( _dcd.control.dir == TUSB_DIR_OUT ) - { - // TODO control out - NRF_USBD->EPOUT[0].PTR = (uint32_t) _dcd.control.buffer; - NRF_USBD->EPOUT[0].MAXCNT = xact_len; - - NRF_USBD->TASKS_EP0RCVOUT = 1; - __ISB(); __DSB(); - }else - { - NRF_USBD->EPIN[0].PTR = (uint32_t) _dcd.control.buffer; - NRF_USBD->EPIN[0].MAXCNT = xact_len; - - edpt_dma_start(&NRF_USBD->TASKS_STARTEPIN[0]); - } - - _dcd.control.buffer += xact_len; - _dcd.control.actual_len += xact_len; -} - -bool dcd_control_xfer (uint8_t rhport, uint8_t dir, uint8_t * buffer, uint16_t length) -{ - (void) rhport; - - if ( length ) - { - // Data Phase - _dcd.control.total_len = length; - _dcd.control.actual_len = 0; - _dcd.control.buffer = buffer; - _dcd.control.dir = dir; - - xact_control_start(); - }else - { - NRF_USBD->EPIN[0].PTR = 0; - NRF_USBD->EPIN[0].MAXCNT = 0; - // Status Phase also require Easy DMA has to be free as well !!!! - NRF_USBD->TASKS_EP0STATUS = 1; - - // The nRF doesn't interrupt on status transmit so we queue up a success response. - dcd_event_xfer_complete(0, 0, 0, DCD_XFER_SUCCESS, false); - } - - return true; -} - /*------------------------------------------------------------------*/ /* *------------------------------------------------------------------*/ static inline nom_xfer_t* get_td(uint8_t epnum, uint8_t dir) { - return &_dcd.xfer[epnum-1][dir]; + return &_dcd.xfer[epnum][dir]; } /*------------- Bulk/Int OUT transfer -------------*/ @@ -296,7 +237,7 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) uint8_t const epnum = edpt_number(desc_edpt->bEndpointAddress); uint8_t const dir = edpt_dir(desc_edpt->bEndpointAddress); - _dcd.xfer[epnum-1][dir].mps = desc_edpt->wMaxPacketSize.size; + _dcd.xfer[epnum][dir].mps = desc_edpt->wMaxPacketSize.size; if ( dir == TUSB_DIR_OUT ) { @@ -312,6 +253,16 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) return true; } +void control_status_token(uint8_t addr) { + NRF_USBD->EPIN[0].PTR = 0; + NRF_USBD->EPIN[0].MAXCNT = 0; + // Status Phase also require Easy DMA has to be free as well !!!! + NRF_USBD->TASKS_EP0STATUS = 1; + + // The nRF doesn't interrupt on status transmit so we queue up a success response. + dcd_event_xfer_complete(0, addr, 0, DCD_XFER_SUCCESS, false); +} + bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes) { (void) rhport; @@ -325,7 +276,10 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t xfer->total_len = total_bytes; xfer->actual_len = 0; - if ( dir == TUSB_DIR_OUT ) + // How does the control endpoint handle a ZLP in the data phase? + if (epnum == 0 && total_bytes == 0) { + control_status_token(ep_addr); + } else if ( dir == TUSB_DIR_OUT ) { if ( xfer->data_received ) { @@ -431,47 +385,15 @@ void USBD_IRQHandler(void) edpt_dma_end(); } - /*------------- Control Transfer -------------*/ + // Setup tokens are specific to the Control endpoint. if ( int_status & USBD_INTEN_EP0SETUP_Msk ) { uint8_t setup[8] = { NRF_USBD->BMREQUESTTYPE , NRF_USBD->BREQUEST, NRF_USBD->WVALUEL , NRF_USBD->WVALUEH, NRF_USBD->WINDEXL , NRF_USBD->WINDEXH , NRF_USBD->WLENGTHL, NRF_USBD->WLENGTHH }; - dcd_event_setup_received(0, setup, true); - } - - if ( int_status & USBD_INTEN_EP0DATADONE_Msk ) - { - if ( _dcd.control.dir == TUSB_DIR_OUT ) - { - // Control OUT: data from Host -> Endpoint - // Trigger DMA to move Endpoint -> SRAM - edpt_dma_start(&NRF_USBD->TASKS_STARTEPOUT[0]); - }else - { - // Control IN: data transferred from Endpoint -> Host - if ( _dcd.control.actual_len < _dcd.control.total_len ) - { - xact_control_start(); - }else - { - // Control IN complete - dcd_event_xfer_complete(0, 0, _dcd.control.actual_len, DCD_XFER_SUCCESS, true); - } - } - } - - // Control OUT: data from Endpoint -> SRAM - if ( int_status & USBD_INTEN_ENDEPOUT0_Msk) - { - if ( _dcd.control.actual_len < _dcd.control.total_len ) - { - xact_control_start(); - }else - { - // Control OUT complete - dcd_event_xfer_complete(0, 0, _dcd.control.actual_len, DCD_XFER_SUCCESS, true); + if (setup[1] != TUSB_REQ_SET_ADDRESS) { + dcd_event_setup_received(0, setup, true); } } @@ -482,9 +404,9 @@ void USBD_IRQHandler(void) * We must handle this stage before Host -> Endpoint just in case * 2 event happens at once */ - for(uint8_t epnum=1; epnum<8; epnum++) + for(uint8_t epnum=0; epnum<8; epnum++) { - if ( BIT_TEST_(int_status, USBD_INTEN_ENDEPOUT0_Pos+epnum) ) + if ( BIT_TEST_(int_status, USBD_INTEN_ENDEPOUT0_Pos+epnum)) { nom_xfer_t* xfer = get_td(epnum, TUSB_DIR_OUT); @@ -509,16 +431,16 @@ void USBD_IRQHandler(void) // Ended event for Bulk/Int : nothing to do } - if ( int_status & USBD_INTEN_EPDATA_Msk) + if ( int_status & USBD_INTEN_EPDATA_Msk || int_status & USBD_INTEN_EP0DATADONE_Msk) { uint32_t data_status = NRF_USBD->EPDATASTATUS; nrf_usbd_epdatastatus_clear(data_status); // Bulk/Int In: data from Endpoint -> Host - for(uint8_t epnum=1; epnum<8; epnum++) + for(uint8_t epnum=0; epnum<8; epnum++) { - if ( BIT_TEST_(data_status, epnum ) ) + if ( BIT_TEST_(data_status, epnum ) || (epnum == 0 && BIT_TEST_(int_status, USBD_INTEN_EP0DATADONE_Pos))) { nom_xfer_t* xfer = get_td(epnum, TUSB_DIR_IN); @@ -537,7 +459,7 @@ void USBD_IRQHandler(void) } // Bulk/Int OUT: data from Host -> Endpoint - for(uint8_t epnum=1; epnum<8; epnum++) + for(uint8_t epnum=0; epnum<8; epnum++) { if ( BIT_TEST_(data_status, 16+epnum ) ) { -- cgit v1.3.1 From 215f8603b14cc29e08d8a25e08f8eca44ed90826 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 16 Nov 2018 21:56:39 +0700 Subject: nrf5x: refactor device control transfer. - make control transfer as part of usbd. Class driver must use usbd_control_ API() instead of dcd_ api. - change the signature of class driver's control_request - allow control request complete to stall in staus stage - move control request parser & handling to usbd. --- src/class/cdc/cdc_device.c | 90 +++++++------- src/class/cdc/cdc_device.h | 4 +- src/class/custom/custom_device.c | 4 +- src/class/custom/custom_device.h | 4 +- src/class/hid/hid_device.c | 141 ++++++++++----------- src/class/hid/hid_device.h | 5 +- src/class/msc/msc_device.c | 71 ++++++++--- src/class/msc/msc_device.h | 30 +---- src/common/tusb_types.h | 6 +- src/device/control.c | 261 +++++++++++++-------------------------- src/device/control.h | 38 ------ src/device/dcd.h | 4 + src/device/usbd.c | 236 ++++++++++++++++++++++++++++------- src/device/usbd_pvt.h | 17 ++- src/tusb_option.h | 4 +- 15 files changed, 477 insertions(+), 438 deletions(-) (limited to 'src/class/custom') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index bc16699f1..d8ade9c7f 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -45,7 +45,6 @@ // INCLUDE //--------------------------------------------------------------------+ #include "cdc_device.h" -#include "device/control.h" #include "device/usbd_pvt.h" //--------------------------------------------------------------------+ @@ -63,7 +62,7 @@ typedef struct /*------------- From this point, data is not cleared by bus reset -------------*/ char wanted_char; - CFG_TUSB_MEM_ALIGN cdc_line_coding_t line_coding; + cdc_line_coding_t line_coding; // FIFO tu_fifo_t rx_ff; @@ -199,23 +198,23 @@ void cdcd_init(void) for(uint8_t i=0; iwanted_char = -1; + p_cdc->wanted_char = -1; // default line coding is : stop bit = 1, parity = none, data bits = 8 - ser->line_coding.bit_rate = 115200; - ser->line_coding.stop_bits = 0; - ser->line_coding.parity = 0; - ser->line_coding.data_bits = 8; + p_cdc->line_coding.bit_rate = 115200; + p_cdc->line_coding.stop_bits = 0; + p_cdc->line_coding.parity = 0; + p_cdc->line_coding.data_bits = 8; // config fifo - tu_fifo_config(&ser->rx_ff, ser->rx_ff_buf, CFG_TUD_CDC_RX_BUFSIZE, 1, true); - tu_fifo_config(&ser->tx_ff, ser->tx_ff_buf, CFG_TUD_CDC_TX_BUFSIZE, 1, false); + tu_fifo_config(&p_cdc->rx_ff, p_cdc->rx_ff_buf, CFG_TUD_CDC_RX_BUFSIZE, 1, true); + tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, CFG_TUD_CDC_TX_BUFSIZE, 1, false); #if CFG_FIFO_MUTEX - tu_fifo_config_mutex(&ser->rx_ff, osal_mutex_create(&ser->rx_ff_mutex)); - tu_fifo_config_mutex(&ser->tx_ff, osal_mutex_create(&ser->tx_ff_mutex)); + tu_fifo_config_mutex(&p_cdc->rx_ff, osal_mutex_create(&p_cdc->rx_ff_mutex)); + tu_fifo_config_mutex(&p_cdc->tx_ff, osal_mutex_create(&p_cdc->tx_ff_mutex)); #endif } } @@ -299,57 +298,64 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface return TUSB_ERROR_NONE; } -void cdcd_control_request_complete(uint8_t rhport, tusb_control_request_t const * p_request) +// Invoked when class request DATA stage is finished. +// return false to stall control endpoint (e.g Host send non-sense DATA) +bool cdcd_control_request_complete(uint8_t rhport, tusb_control_request_t const * request) { //------------- Class Specific Request -------------// - if (p_request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS) return; + TU_VERIFY (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS); // TODO Support multiple interfaces uint8_t const itf = 0; cdcd_interface_t* p_cdc = &_cdcd_itf[itf]; // Invoke callback - if (CDC_REQUEST_SET_LINE_CODING == p_request->bRequest) { + if ( CDC_REQUEST_SET_LINE_CODING == request->bRequest ) + { if ( tud_cdc_line_coding_cb ) tud_cdc_line_coding_cb(itf, &p_cdc->line_coding); } + + return true; } -tusb_error_t cdcd_control_request(uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent) +// Handle class control request +// return false to stall control endpoint (e.g unsupported request) +bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request) { //------------- Class Specific Request -------------// - if (p_request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS) return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; + TU_ASSERT(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS); // TODO Support multiple interfaces uint8_t const itf = 0; cdcd_interface_t* p_cdc = &_cdcd_itf[itf]; - if ((CDC_REQUEST_SET_LINE_CODING == p_request->bRequest) ) - { - uint16_t len = tu_min16(sizeof(cdc_line_coding_t), p_request->wLength); - dcd_edpt_xfer(rhport, 0, (uint8_t*) &p_cdc->line_coding, len); - } - else if ( (CDC_REQUEST_GET_LINE_CODING == p_request->bRequest)) - { - uint16_t len = tu_min16(sizeof(cdc_line_coding_t), p_request->wLength); - dcd_edpt_xfer(rhport, TUSB_DIR_IN_MASK, (uint8_t*) &p_cdc->line_coding, len); - } - else if (CDC_REQUEST_SET_CONTROL_LINE_STATE == p_request->bRequest ) - { - // CDC PSTN v1.2 section 6.3.12 - // Bit 0: Indicates if DTE is present or not. - // This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR (Data Terminal Ready) - // Bit 1: Carrier control for half-duplex modems. - // This signal corresponds to V.24 signal 105 and RS-232 signal RTS (Request to Send) - p_cdc->line_state = (uint8_t) p_request->wValue; - - // Invoke callback - if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, BIT_TEST_(p_request->wValue, 0), BIT_TEST_(p_request->wValue, 1)); - } - else + switch ( request->bRequest ) { - return TUSB_ERROR_FAILED; // stall unsupported request + case CDC_REQUEST_SET_LINE_CODING: + usbd_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t)); + break; + + case CDC_REQUEST_GET_LINE_CODING: + usbd_control_xfer(rhport, request, &p_cdc->line_coding, sizeof(cdc_line_coding_t)); + break; + + case CDC_REQUEST_SET_CONTROL_LINE_STATE: + // CDC PSTN v1.2 section 6.3.12 + // Bit 0: Indicates if DTE is present or not. + // This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR (Data Terminal Ready) + // Bit 1: Carrier control for half-duplex modems. + // This signal corresponds to V.24 signal 105 and RS-232 signal RTS (Request to Send) + p_cdc->line_state = (uint8_t) request->wValue; + + // Invoke callback + if ( tud_cdc_line_state_cb) tud_cdc_line_state_cb(itf, BIT_TEST_(request->wValue, 0), BIT_TEST_(request->wValue, 1)); + usbd_control_status(rhport, request); + break; + + default: return false; // stall unsupported request } - return TUSB_ERROR_NONE; + + return true; } tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, uint32_t xferred_bytes) diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 9d0b93c6d..749351a54 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -114,8 +114,8 @@ ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_li void cdcd_init (void); tusb_error_t cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); -tusb_error_t cdcd_control_request (uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent); -void cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); +bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * p_request); +bool cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); void cdcd_reset (uint8_t rhport); diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index 1b36f1331..cc440fc7e 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -89,9 +89,9 @@ tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, return TUSB_ERROR_NONE; } -tusb_error_t cusd_control_request(uint8_t rhport, tusb_control_request_t const * p_request) +bool cusd_control_request(uint8_t rhport, tusb_control_request_t const * p_request) { - return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; + return false; } tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes) diff --git a/src/class/custom/custom_device.h b/src/class/custom/custom_device.h index 116c6897d..704c4127b 100644 --- a/src/class/custom/custom_device.h +++ b/src/class/custom/custom_device.h @@ -64,8 +64,8 @@ void cusd_init(void); tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); -tusb_error_t cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request); -void cusd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); +bool cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request); +bool cusd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); void cusd_reset(uint8_t rhport); #endif diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index efa602ad6..b5586a488 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -46,7 +46,6 @@ //--------------------------------------------------------------------+ #include "common/tusb_common.h" #include "hid_device.h" -#include "device/control.h" #include "device/usbd_pvt.h" //--------------------------------------------------------------------+ @@ -403,110 +402,112 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u return TUSB_ERROR_NONE; } -tusb_error_t hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent) +// Handle class control request +// return false to stall control endpoint (e.g unsupported request) +bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request) { hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex ); - TU_ASSERT(p_hid, TUSB_ERROR_FAILED); + TU_ASSERT(p_hid); - //------------- STD Request -------------// if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD) { + //------------- STD Request -------------// uint8_t const desc_type = tu_u16_high(p_request->wValue); 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) { - // TODO: Handle zero length packet. - uint16_t remaining_bytes = p_hid->desc_len - bytes_already_sent; - if (remaining_bytes > 64) { - remaining_bytes = 64; - } - memcpy(_shared_control_buffer, p_hid->desc_report + bytes_already_sent, remaining_bytes); - - dcd_edpt_xfer(rhport, TUSB_DIR_IN_MASK, _shared_control_buffer, remaining_bytes); + usbd_control_xfer(rhport, p_request, p_hid->desc_report, p_hid->desc_len); }else { - return TUSB_ERROR_FAILED; + return false; // stall unsupported request } } - //------------- Class Specific Request -------------// else if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS) { - if( HID_REQ_CONTROL_GET_REPORT == p_request->bRequest ) + //------------- Class Specific Request -------------// + switch( p_request->bRequest ) { - // wValue = Report Type | Report ID - uint8_t const report_type = tu_u16_high(p_request->wValue); - uint8_t const report_id = tu_u16_low(p_request->wValue); - - uint16_t xferlen; - if ( p_hid->get_report_cb ) + case HID_REQ_CONTROL_GET_REPORT: { - xferlen = p_hid->get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->report_buf, p_request->wLength); - }else + // wValue = Report Type | Report ID + uint8_t const report_type = tu_u16_high(p_request->wValue); + uint8_t const report_id = tu_u16_low(p_request->wValue); + + uint16_t xferlen; + if ( p_hid->get_report_cb ) + { + xferlen = p_hid->get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->report_buf, p_request->wLength); + }else + { + // For boot Interface only: re-use report_buf -> report has no change + xferlen = p_request->wLength; + } + + TU_ASSERT( xferlen > 0 ); + usbd_control_xfer(rhport, p_request, p_hid->report_buf, xferlen); + } + break; + + case HID_REQ_CONTROL_SET_REPORT: + usbd_control_xfer(rhport, p_request, p_hid->report_buf, p_request->wLength); + break; + + case HID_REQ_CONTROL_SET_IDLE: + // TODO idle rate of report + p_hid->idle_rate = tu_u16_high(p_request->wValue); + usbd_control_status(rhport, p_request); + break; + + case HID_REQ_CONTROL_GET_IDLE: + // TODO idle rate of report + usbd_control_xfer(rhport, p_request, &p_hid->idle_rate, 1); + break; + + case HID_REQ_CONTROL_GET_PROTOCOL: { - // For boot Interface only: re-use report_buf -> report has no change - xferlen = p_request->wLength; + uint8_t protocol = 1-p_hid->boot_protocol; // 0 is Boot, 1 is Report protocol + usbd_control_xfer(rhport, p_request, &protocol, 1); } + break; - TU_ASSERT( xferlen > 0 ); - dcd_edpt_xfer(rhport, TUSB_DIR_IN_MASK, _shared_control_buffer, xferlen); - } - else if ( HID_REQ_CONTROL_SET_REPORT == p_request->bRequest ) - { - dcd_edpt_xfer(rhport, 0, _shared_control_buffer, p_request->wLength); - } - else if (HID_REQ_CONTROL_SET_IDLE == p_request->bRequest) - { - // TODO idle rate of report - p_hid->idle_rate = tu_u16_high(p_request->wValue); - } - else if (HID_REQ_CONTROL_GET_IDLE == p_request->bRequest) - { - // TODO idle rate of report - _shared_control_buffer[0] = p_hid->idle_rate; - dcd_edpt_xfer(rhport, TUSB_DIR_IN_MASK, _shared_control_buffer, 1); - } - else if (HID_REQ_CONTROL_GET_PROTOCOL == p_request->bRequest ) - { - _shared_control_buffer[0] = 1-p_hid->boot_protocol; // 0 is Boot, 1 is Report protocol - dcd_edpt_xfer(rhport, TUSB_DIR_IN_MASK, _shared_control_buffer, 1); - } - else if (HID_REQ_CONTROL_SET_PROTOCOL == p_request->bRequest ) - { - p_hid->boot_protocol = 1 - p_request->wValue; // 0 is Boot, 1 is Report protocol - }else - { - return TUSB_ERROR_FAILED; + case HID_REQ_CONTROL_SET_PROTOCOL: + p_hid->boot_protocol = 1 - p_request->wValue; // 0 is Boot, 1 is Report protocol + usbd_control_status(rhport, p_request); + break; + + default: return false; // stall unsupported request } }else { - return TUSB_ERROR_FAILED; + return false; // stall unsupported request } - return TUSB_ERROR_NONE; + + return true; } -void hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const * p_request) +// Invoked when class request DATA stage is finished. +// return false to stall control endpoint (e.g Host send non-sense DATA) +bool hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const * p_request) { hidd_interface_t* p_hid = get_interface_by_itfnum( (uint8_t) p_request->wIndex ); - if (p_hid == NULL) { - return; - } + TU_ASSERT(p_hid); - if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS) + if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS && + p_request->bRequest == HID_REQ_CONTROL_SET_REPORT) { - if ( HID_REQ_CONTROL_SET_REPORT == p_request->bRequest ) - { - // wValue = Report Type | Report ID - uint8_t const report_type = tu_u16_high(p_request->wValue); - uint8_t const report_id = tu_u16_low(p_request->wValue); + // wValue = Report Type | Report ID + uint8_t const report_type = tu_u16_high(p_request->wValue); + uint8_t const report_id = tu_u16_low(p_request->wValue); - if ( p_hid->set_report_cb ) - { - p_hid->set_report_cb(report_id, (hid_report_type_t) report_type, _shared_control_buffer, p_request->wLength); - } + if ( p_hid->set_report_cb ) + { + p_hid->set_report_cb(report_id, (hid_report_type_t) report_type, p_hid->report_buf, p_request->wLength); } } + + return true; } tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes) diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 1dc40af57..7f8cd0fa7 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -378,8 +378,8 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(uint8_t report_id, hid_report_type_t void hidd_init(void); tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); -tusb_error_t hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent); -void hidd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); +bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); +bool hidd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); void hidd_reset(uint8_t rhport); @@ -390,3 +390,4 @@ void hidd_reset(uint8_t rhport); #endif #endif /* _TUSB_HID_DEVICE_H_ */ + diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 32ad90102..92bc4c6c8 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -47,7 +47,6 @@ #include "common/tusb_common.h" #include "msc_device.h" -#include "device/control.h" #include "device/usbd_pvt.h" //--------------------------------------------------------------------+ @@ -60,7 +59,31 @@ enum MSC_STAGE_STATUS }; -CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN mscd_interface_t _mscd_itf; +typedef struct { + CFG_TUSB_MEM_ALIGN msc_cbw_t cbw; + +//#if defined (__ICCARM__) && (CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13UXX) +// uint8_t padding1[64-sizeof(msc_cbw_t)]; // IAR cannot align struct's member +//#endif + + CFG_TUSB_MEM_ALIGN msc_csw_t csw; + + uint8_t itf_num; + uint8_t ep_in; + uint8_t ep_out; + + // Bulk Only Transfer (BOT) Protocol + uint8_t stage; + uint32_t total_len; + uint32_t xferred_len; // numbered of bytes transferred so far in the Data Stage + + // Sense Response Data + uint8_t sense_key; + uint8_t add_sense_code; + uint8_t add_sense_qualifier; +}mscd_interface_t; + +CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN static mscd_interface_t _mscd_itf; CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN static uint8_t _mscd_buf[CFG_TUD_MSC_BUFSIZE]; //--------------------------------------------------------------------+ @@ -147,29 +170,39 @@ tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, return TUSB_ERROR_NONE; } -tusb_error_t mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent) +// Handle class control request +// return false to stall control endpoint (e.g unsupported request) +bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request) { - TU_ASSERT(p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS, TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT); + TU_ASSERT(p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS); - if(MSC_REQ_RESET == p_request->bRequest) - { - // TODO: Actually reset. - } - else if (MSC_REQ_GET_MAX_LUN == p_request->bRequest) + switch ( p_request->bRequest ) { - // returned MAX LUN is minus 1 by specs - _shared_control_buffer[0] = CFG_TUD_MSC_MAXLUN-1; - dcd_edpt_xfer(rhport, TUSB_DIR_IN_MASK, _shared_control_buffer, 1); - }else - { - return TUSB_ERROR_FAILED; // stall unsupported request + case MSC_REQ_RESET: + // TODO: Actually reset interface. + usbd_control_status(rhport, p_request); + break; + + case MSC_REQ_GET_MAX_LUN: + { + // returned MAX LUN is minus 1 by specs + uint8_t maxlun = CFG_TUD_MSC_MAXLUN-1; + usbd_control_xfer(rhport, p_request, &maxlun, 1); + } + break; + + default: return false; // stall unsupported request } - return TUSB_ERROR_NONE; + + return true; } -void mscd_control_request_complete(uint8_t rhport, tusb_control_request_t const * p_request) +// Invoked when class request DATA stage is finished. +// return false to stall control endpoint (e.g Host send non-sense DATA) +bool mscd_control_request_complete(uint8_t rhport, tusb_control_request_t const * p_request) { - return; + // nothing to do + return true; } // For backwards compatibility we support static block counts. @@ -296,7 +329,7 @@ int32_t proc_builtin_scsi(msc_cbw_t const * p_cbw, uint8_t* buffer, uint32_t buf return ret; } -tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, uint8_t event, uint32_t xferred_bytes) +tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, uint32_t xferred_bytes) { mscd_interface_t* p_msc = &_mscd_itf; msc_cbw_t const * p_cbw = &p_msc->cbw; diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index ac3eade22..d08d9f9cb 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -81,32 +81,6 @@ TU_VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct"); extern "C" { #endif -typedef struct { - CFG_TUSB_MEM_ALIGN msc_cbw_t cbw; - -//#if defined (__ICCARM__) && (CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13UXX) -// uint8_t padding1[64-sizeof(msc_cbw_t)]; // IAR cannot align struct's member -//#endif - - CFG_TUSB_MEM_ALIGN msc_csw_t csw; - - uint8_t itf_num; - uint8_t ep_in; - uint8_t ep_out; - - // Bulk Only Transfer (BOT) Protocol - uint8_t stage; - uint32_t total_len; - uint32_t xferred_len; // numbered of bytes transferred so far in the Data Stage - - // Sense Response Data - uint8_t sense_key; - uint8_t add_sense_code; - uint8_t add_sense_qualifier; -}mscd_interface_t; - -extern mscd_interface_t _mscd_itf; - /** \addtogroup ClassDriver_MSC * @{ * \defgroup MSC_Device Device @@ -198,8 +172,8 @@ ATTR_WEAK bool tud_lun_capacity_cb(uint8_t lun, uint32_t* last_valid_sector, uin void mscd_init(void); tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); -tusb_error_t mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent); -void mscd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); +bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); +bool mscd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); void mscd_reset(uint8_t rhport); diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index 5c226f556..32632cd90 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -203,12 +203,14 @@ typedef enum TUSB_EVENT_XFER_STALLED, }tusb_event_t; -enum { +enum +{ DESC_OFFSET_LEN = 0, DESC_OFFSET_TYPE = 1 }; -enum { +enum +{ INTERFACE_INVALID_NUMBER = 0xff }; diff --git a/src/device/control.c b/src/device/control.c index 35ae536e1..7ab1e16ab 100644 --- a/src/device/control.c +++ b/src/device/control.c @@ -46,216 +46,125 @@ #include "control.h" #include "device/usbd_pvt.h" +enum +{ + EDPT_CTRL_OUT = 0x00, + EDPT_CTRL_IN = 0x80 +}; + +typedef struct { + tusb_control_request_t request; + + void* buffer; + uint16_t total_len; + uint16_t total_transferred; + + bool (*complete_cb) (uint8_t, tusb_control_request_t const * ); +} control_t; + control_t control_state; -CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t _shared_control_buffer[64]; +CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t _usbd_ctrl_buf[CFG_TUD_ENDOINT0_SIZE]; -void controld_reset(uint8_t rhport) { - control_state.current_stage = CONTROL_STAGE_SETUP; +void usbd_control_reset (uint8_t rhport) +{ + tu_varclr(&control_state); } -// Helper to send STATUS (zero length) packet -// Note dir is value of direction bit in setup packet (i.e DATA stage direction) -static inline bool dcd_control_status(uint8_t rhport, uint8_t dir) +void usbd_control_stall(uint8_t rhport) { - uint8_t ep_addr = 0; - // Invert the direction. - if (dir == TUSB_DIR_OUT) { - ep_addr |= TUSB_DIR_IN_MASK; - } - // status direction is reversed to one in the setup packet - return dcd_edpt_xfer(rhport, ep_addr, NULL, 0); + dcd_edpt_stall(rhport, 0); } -static inline void dcd_control_stall(uint8_t rhport) +bool usbd_control_status(uint8_t rhport, tusb_control_request_t const * request) { - dcd_edpt_stall(rhport, 0 | TUSB_DIR_IN_MASK); + // status direction is reversed to one in the setup packet + return dcd_edpt_xfer(rhport, request->bmRequestType_bit.direction ? EDPT_CTRL_OUT : EDPT_CTRL_IN, NULL, 0); } -// return len of descriptor and change pointer to descriptor's buffer -static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * const p_request, uint8_t const ** pp_buffer) +// Each transaction is up to endpoint0's max packet size +static bool start_control_data_xact(uint8_t rhport) { - (void) rhport; - - tusb_desc_type_t const desc_type = (tusb_desc_type_t) tu_u16_high(p_request->wValue); - uint8_t const desc_index = tu_u16_low( p_request->wValue ); + uint16_t const xact_len = tu_min16(control_state.total_len - control_state.total_transferred, CFG_TUD_ENDOINT0_SIZE); - uint8_t const * desc_data = NULL ; - uint16_t len = 0; + uint8_t ep_addr = EDPT_CTRL_OUT; - switch(desc_type) + if ( control_state.request.bmRequestType_bit.direction == TUSB_DIR_IN ) { - case TUSB_DESC_DEVICE: - desc_data = (uint8_t const *) usbd_desc_set->device; - len = sizeof(tusb_desc_device_t); - break; - - case TUSB_DESC_CONFIGURATION: - 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]; - TU_VERIFY( desc_data != NULL, 0 ); - - len = desc_data[0]; // first byte of descriptor is its size - }else - { - // out of range - /* The 0xee string is indeed a Microsoft USB extension. - * It can be used to tell Windows what driver it should use for the device !!! - */ - return 0; - } - break; - - case TUSB_DESC_DEVICE_QUALIFIER: - // TODO If not highspeed capable stall this request otherwise - // return the descriptor that could work in highspeed - return 0; - break; - - default: return 0; + ep_addr = EDPT_CTRL_IN; + memcpy(_usbd_ctrl_buf, control_state.buffer, xact_len); } - TU_ASSERT( desc_data != NULL, 0); - - // up to Host's length - len = tu_min16(p_request->wLength, len ); - (*pp_buffer) = desc_data; - - return len; + return dcd_edpt_xfer(rhport, ep_addr, _usbd_ctrl_buf, xact_len); } -tusb_error_t controld_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes) { - if (control_state.current_stage == CONTROL_STAGE_STATUS && xferred_bytes == 0) { - control_state.current_stage = CONTROL_STAGE_SETUP; - return TUSB_ERROR_NONE; - } - tusb_error_t error = TUSB_ERROR_NONE; - control_state.total_transferred += xferred_bytes; - tusb_control_request_t const *p_request = &control_state.current_request; - - if (p_request->wLength == control_state.total_transferred || xferred_bytes < 64) { - control_state.current_stage = CONTROL_STAGE_STATUS; - dcd_control_status(rhport, p_request->bmRequestType_bit.direction); - - // Do the user callback after queueing the STATUS packet because the callback could be slow. - if ( TUSB_REQ_RCPT_INTERFACE == p_request->bmRequestType_bit.recipient ) - { - tud_control_interface_control_complete_cb(rhport, tu_u16_low(p_request->wIndex), p_request); - } - } else { - if (TUSB_REQ_RCPT_INTERFACE == p_request->bmRequestType_bit.recipient) { - error = tud_control_interface_control_cb(rhport, tu_u16_low(p_request->wIndex), p_request, control_state.total_transferred); - } else { - error = controld_process_control_request(rhport, p_request, control_state.total_transferred); - } - } - return error; +// TODO may find a better way +void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_request_t const * ) ) +{ + control_state.complete_cb = fp; } -// This tracks the state of a control request. -tusb_error_t controld_process_setup_request(uint8_t rhport, tusb_control_request_t const * p_request) { - tusb_error_t error = TUSB_ERROR_NONE; - memcpy(&control_state.current_request, p_request, sizeof(tusb_control_request_t)); - if (p_request->wLength == 0) { - control_state.current_stage = CONTROL_STAGE_STATUS; - } else { - control_state.current_stage = CONTROL_STAGE_DATA; - control_state.total_transferred = 0; - } +bool usbd_control_xfer(uint8_t rhport, tusb_control_request_t const * request, void* buffer, uint16_t len) +{ + control_state.request = (*request); + control_state.buffer = buffer; + control_state.total_len = tu_min16(len, request->wLength); + control_state.total_transferred = 0; - if ( TUSB_REQ_RCPT_INTERFACE == p_request->bmRequestType_bit.recipient ) + if ( buffer != NULL && len ) { - error = tud_control_interface_control_cb(rhport, tu_u16_low(p_request->wIndex), p_request, 0); - } else { - error = controld_process_control_request(rhport, p_request, 0); + // Data stage + TU_ASSERT( start_control_data_xact(rhport) ); + }else + { + // Status stage + TU_ASSERT( usbd_control_status(rhport, request) ); } - if (error != TUSB_ERROR_NONE) { - dcd_control_stall(rhport); // Stall errored requests - } else if (control_state.current_stage == CONTROL_STAGE_STATUS) { - dcd_control_status(rhport, p_request->bmRequestType_bit.direction); - } - return error; + return true; } -// This handles the actual request and its response. -tusb_error_t controld_process_control_request(uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent) +// callback when a transaction complete on DATA stage of control endpoint +tusb_error_t usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, tusb_event_t event, uint32_t xferred_bytes) { - tusb_error_t error = TUSB_ERROR_NONE; - uint8_t ep_addr = 0; - if (p_request->bmRequestType_bit.direction == TUSB_DIR_IN) { - ep_addr |= TUSB_DIR_IN_MASK; + if ( control_state.request.bmRequestType_bit.direction == TUSB_DIR_OUT ) + { + memcpy(control_state.buffer, _usbd_ctrl_buf, xferred_bytes); } - //------------- Standard Request e.g in enumeration -------------// - if( TUSB_REQ_RCPT_DEVICE == p_request->bmRequestType_bit.recipient && - TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type ) { - switch (p_request->bRequest) { - case TUSB_REQ_GET_DESCRIPTOR: { - uint8_t const * buffer = NULL; - uint16_t const len = get_descriptor(rhport, p_request, &buffer); - - if (len) { - uint16_t remaining_bytes = len - bytes_already_sent; - if (remaining_bytes > 64) { - remaining_bytes = 64; - } - memcpy(_shared_control_buffer, buffer + bytes_already_sent, remaining_bytes); - dcd_edpt_xfer(rhport, ep_addr, _shared_control_buffer, remaining_bytes); - } else { - return TUSB_ERROR_FAILED; - } - break; - } - case TUSB_REQ_GET_CONFIGURATION: - memcpy(_shared_control_buffer, &control_state.config, 1); - dcd_edpt_xfer(rhport, ep_addr, _shared_control_buffer, 1); - break; - case TUSB_REQ_SET_ADDRESS: - dcd_set_address(rhport, (uint8_t) p_request->wValue); - break; - case TUSB_REQ_SET_CONFIGURATION: - control_state.config = p_request->wValue; - tud_control_set_config_cb (rhport, control_state.config); - break; - default: - return TUSB_ERROR_FAILED; + control_state.total_transferred += xferred_bytes; + control_state.buffer += xferred_bytes; + + if ( control_state.total_len == control_state.total_transferred || xferred_bytes < CFG_TUD_ENDOINT0_SIZE ) + { + // DATA stage is complete + bool is_ok = true; + + // invoke complete callback if set + // callback can still stall control in status phase e.g out data does not make sense + if ( control_state.complete_cb ) + { + is_ok = control_state.complete_cb(rhport, &control_state.request); } - } else if (p_request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_ENDPOINT && - p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD) { - //------------- Endpoint Request -------------// - switch (p_request->bRequest) { - case TUSB_REQ_GET_STATUS: { - uint16_t status = dcd_edpt_stalled(rhport, tu_u16_low(p_request->wIndex)) ? 0x0001 : 0x0000; - memcpy(_shared_control_buffer, &status, 2); - - dcd_edpt_xfer(rhport, ep_addr, _shared_control_buffer, 2); - break; - } - case TUSB_REQ_CLEAR_FEATURE: - // only endpoint feature is halted/stalled - dcd_edpt_clear_stall(rhport, tu_u16_low(p_request->wIndex)); - break; - case TUSB_REQ_SET_FEATURE: - // only endpoint feature is halted/stalled - dcd_edpt_stall(rhport, tu_u16_low(p_request->wIndex)); - break; - default: - return TUSB_ERROR_FAILED; + + if ( is_ok ) + { + // Send status + TU_ASSERT( usbd_control_status(rhport, &control_state.request), TUSB_ERROR_FAILED ); + }else + { + // stall due to callback + usbd_control_stall(rhport); } - } else { - //------------- Unsupported Request -------------// - return TUSB_ERROR_FAILED; } - return error; + else + { + // More data to transfer + TU_ASSERT(start_control_data_xact(rhport), TUSB_ERROR_FAILED); + } + + return TUSB_ERROR_NONE; } #endif diff --git a/src/device/control.h b/src/device/control.h index e8dcf76f9..e1709bcee 100644 --- a/src/device/control.h +++ b/src/device/control.h @@ -48,44 +48,6 @@ #include "tusb.h" -typedef enum { - CONTROL_STAGE_SETUP, // Waiting for a setup token. - CONTROL_STAGE_DATA, // In the process of sending or receiving data. - CONTROL_STAGE_STATUS // In the process of transmitting the STATUS ZLP. -} control_stage_t; - -typedef struct { - control_stage_t current_stage; - tusb_control_request_t current_request; - uint16_t total_transferred; - uint8_t config; -} control_t; - -extern uint8_t _shared_control_buffer[64]; - -tusb_error_t controld_process_setup_request(uint8_t rhport, tusb_control_request_t const * const p_request); - -// Callback when the configuration of the device is changed. -tusb_error_t tud_control_set_config_cb(uint8_t rhport, uint8_t config_number); - -// Called when the DATA stage of a control transaction is complete. -void tud_control_interface_control_complete_cb(uint8_t rhport, uint8_t interface, tusb_control_request_t const * const p_request); - -tusb_error_t tud_control_interface_control_cb(uint8_t rhport, uint8_t interface, tusb_control_request_t const * const p_request, uint16_t bytes_already_sent); - -//--------------------------------------------------------------------+ -// INTERNAL API -//--------------------------------------------------------------------+ -tusb_error_t controld_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); - -// This tracks the state of a control request. -tusb_error_t controld_process_setup_request(uint8_t rhport, tusb_control_request_t const * p_request); - -// This handles the actual request and its response. -tusb_error_t controld_process_control_request(uint8_t rhport, tusb_control_request_t const * p_request, uint16_t bytes_already_sent); - -tusb_error_t controld_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); -void controld_reset(uint8_t rhport); #ifdef __cplusplus } diff --git a/src/device/dcd.h b/src/device/dcd.h index ff836f405..bd0ea852e 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -124,6 +124,10 @@ void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_ /*------------------------------------------------------------------*/ /* Endpoint API + * Note: + * - Address of control endpoint OUT is 0x00, In is 0x80 + * - When stalling control endpoint both control OUT and IN must be stalled + * (according to USB spec, stalled control is only recovered with setup token) *------------------------------------------------------------------*/ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc); bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes); diff --git a/src/device/usbd.c b/src/device/usbd.c index 13cc7f332..e9ac24c4b 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -68,11 +68,10 @@ typedef struct { uint8_t config_num; - // map interface number to driver (0xff is invalid) - uint8_t itf2drv[16]; + uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid) + uint8_t ep2drv[2][8]; // map endpoint to driver ( 0xff is invalid ) + - // map endpoint to driver ( 0xff is invalid ) - uint8_t ep2drv[2][8]; }usbd_device_t; static usbd_device_t _usbd_dev; @@ -94,9 +93,8 @@ typedef struct { void (* init ) (void); tusb_error_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t* p_length); - // Control request is called one or more times for a request and can queue multiple data packets. - tusb_error_t (* control_request ) (uint8_t rhport, tusb_control_request_t const *, uint16_t bytes_already_sent); - void (* control_request_complete ) (uint8_t rhport, tusb_control_request_t const *); + bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request); + bool (* control_request_complete ) (uint8_t rhport, tusb_control_request_t const * request); tusb_error_t (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, tusb_event_t, uint32_t); void (* sof ) (uint8_t rhport); void (* reset ) (uint8_t); @@ -171,9 +169,16 @@ OSAL_QUEUE_DEF(_usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t); static osal_queue_t _usbd_q; //--------------------------------------------------------------------+ -// INTERNAL FUNCTION +// Prototypes //--------------------------------------------------------------------+ static void mark_interface_endpoint(uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id); +static bool process_control_request(uint8_t rhport, tusb_control_request_t const * p_request); +static bool process_set_config(uint8_t rhport, uint8_t config_number); +static void const* get_descriptor(tusb_control_request_t const * p_request, uint16_t* desc_len); + +void usbd_control_reset (uint8_t rhport); +tusb_error_t usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, tusb_event_t event, uint32_t xferred_bytes); +void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_request_t const * ) ); //--------------------------------------------------------------------+ // APPLICATION API @@ -184,7 +189,7 @@ bool tud_mounted(void) } //--------------------------------------------------------------------+ -// IMPLEMENTATION +// USBD Task //--------------------------------------------------------------------+ tusb_error_t usbd_init (void) { @@ -214,7 +219,7 @@ static void usbd_reset(uint8_t rhport) memset(_usbd_dev.itf2drv, 0xff, sizeof(_usbd_dev.itf2drv)); // invalid mapping memset(_usbd_dev.ep2drv , 0xff, sizeof(_usbd_dev.ep2drv )); // invalid mapping - controld_reset(rhport); + usbd_control_reset(rhport); for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) { @@ -222,20 +227,24 @@ static void usbd_reset(uint8_t rhport) } } +// Main device task implementation static void usbd_task_body(void) { - dcd_event_t event; - // Loop until there is no more events in the queue while (1) { + dcd_event_t event; + if ( !osal_queue_receive(_usbd_q, &event) ) return; switch ( event.event_id ) { case DCD_EVENT_SETUP_RECEIVED: - // Setup tokens are unique to the Control endpoint so we delegate to it directly. - controld_process_setup_request(event.rhport, &event.setup_received); + // Process control request, if failed control endpoint is stalled + if ( !process_control_request(event.rhport, &event.setup_received) ) + { + usbd_control_stall(event.rhport); + } break; case DCD_EVENT_XFER_COMPLETE: @@ -245,8 +254,8 @@ static void usbd_task_body(void) if ( 0 == edpt_number(ep_addr) ) { - // control transfer - controld_xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); + // control transfer DATA stage callback + usbd_control_xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); } else { @@ -312,66 +321,142 @@ void usbd_task( void* param) #endif } -void tud_control_interface_control_complete_cb(uint8_t rhport, uint8_t interface, tusb_control_request_t const * const p_request) { - if (_usbd_dev.itf2drv[ interface ] < USBD_CLASS_DRIVER_COUNT) +//--------------------------------------------------------------------+ +// Control Request Parser & Handling +//--------------------------------------------------------------------+ + +// This handles the actual request and its response. +// return false will cause its caller to stall control endpoint +static bool process_control_request(uint8_t rhport, tusb_control_request_t const * p_request) +{ + usbd_control_set_complete_callback(NULL); + + if ( TUSB_REQ_RCPT_DEVICE == p_request->bmRequestType_bit.recipient && + TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type ) + { + //------------- Standard Device Requests e.g in enumeration -------------// + void* data_buf = NULL; + uint16_t data_len = 0; + + switch ( p_request->bRequest ) { - const usbd_class_driver_t *driver = &usbd_class_drivers[_usbd_dev.itf2drv[interface]]; - if (driver->control_request_complete != NULL) { - driver->control_request_complete(rhport, p_request); + case TUSB_REQ_SET_ADDRESS: + dcd_set_address(rhport, (uint8_t) p_request->wValue); + break; + + case TUSB_REQ_GET_CONFIGURATION: + data_buf = &_usbd_dev.config_num; + data_len = 1; + break; + + case TUSB_REQ_SET_CONFIGURATION: + { + uint8_t const config = (uint8_t) p_request->wValue; + + dcd_set_config(rhport, config); + _usbd_dev.config_num = config; + + TU_ASSERT( TUSB_ERROR_NONE == process_set_config(rhport, config) ); } + break; + + case TUSB_REQ_GET_DESCRIPTOR: + data_buf = (void*) get_descriptor(p_request, &data_len); + if ( data_buf == NULL || data_len == 0 ) return false; + break; + + default: return false; } -} -tusb_error_t tud_control_interface_control_cb(uint8_t rhport, uint8_t interface, tusb_control_request_t const * const p_request, uint16_t bytes_already_sent) { - if (_usbd_dev.itf2drv[ interface ] < USBD_CLASS_DRIVER_COUNT) + usbd_control_xfer(rhport, p_request, data_buf, data_len); + } + else if ( TUSB_REQ_RCPT_INTERFACE == p_request->bmRequestType_bit.recipient ) + { + //------------- Class/Interface Specific Request -------------// + uint8_t const itf = tu_u16_low(p_request->wIndex); + uint8_t const drvid = _usbd_dev.itf2drv[ itf ]; + + TU_VERIFY (drvid < USBD_CLASS_DRIVER_COUNT ); + + usbd_control_set_complete_callback(usbd_class_drivers[drvid].control_request_complete ); + + // control endpoint will be stalled if driver return false + return usbd_class_drivers[drvid].control_request(rhport, p_request); + } + else if ( p_request->bmRequestType_bit.recipient == TUSB_REQ_RCPT_ENDPOINT && + p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD ) + { + //------------- Endpoint Request -------------// + switch ( p_request->bRequest ) { - return usbd_class_drivers[_usbd_dev.itf2drv[interface]].control_request(rhport, p_request, bytes_already_sent); + case TUSB_REQ_GET_STATUS: + { + uint16_t status = dcd_edpt_stalled(rhport, tu_u16_low(p_request->wIndex)) ? 0x0001 : 0x0000; + usbd_control_xfer(rhport, p_request, &status, 2); + } + break; + + case TUSB_REQ_CLEAR_FEATURE: + // only endpoint feature is halted/stalled + dcd_edpt_clear_stall(rhport, tu_u16_low(p_request->wIndex)); + usbd_control_status(rhport, p_request); + break; + + case TUSB_REQ_SET_FEATURE: + // only endpoint feature is halted/stalled + dcd_edpt_stall(rhport, tu_u16_low(p_request->wIndex)); + usbd_control_status(rhport, p_request); + break; + + default: return false; } - return TUSB_ERROR_FAILED; + } + else + { + //------------- Unsupported Request -------------// + return false; + } + + return true; } // Process Set Configure Request -// TODO Host (windows) can get HID report descriptor before set configured -// may need to open interface before set configured -tusb_error_t tud_control_set_config_cb(uint8_t rhport, uint8_t config_number) +// This function parse configuration descriptor & open drivers accordingly +static bool process_set_config(uint8_t rhport, uint8_t config_number) { - dcd_set_config(rhport, config_number); - - _usbd_dev.config_num = config_number; - - //------------- parse configuration & open drivers -------------// uint8_t const * desc_cfg = (uint8_t const *) usbd_desc_set->config; - TU_ASSERT(desc_cfg != NULL, TUSB_ERROR_DESCRIPTOR_CORRUPTED); + TU_ASSERT(desc_cfg != NULL); + uint8_t const * p_desc = desc_cfg + sizeof(tusb_desc_configuration_t); uint16_t const cfg_len = ((tusb_desc_configuration_t*)desc_cfg)->wTotalLength; while( p_desc < desc_cfg + cfg_len ) { + // Each interface always starts with Interface or Association descriptor if ( TUSB_DESC_INTERFACE_ASSOCIATION == descriptor_type(p_desc) ) { p_desc = descriptor_next(p_desc); // ignore Interface Association }else { - TU_ASSERT( TUSB_DESC_INTERFACE == descriptor_type(p_desc), TUSB_ERROR_NOT_SUPPORTED_YET ); + TU_ASSERT( TUSB_DESC_INTERFACE == descriptor_type(p_desc) ); - tusb_desc_interface_t* p_desc_itf = (tusb_desc_interface_t*) p_desc; - uint8_t const class_code = p_desc_itf->bInterfaceClass; + tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc; // Check if class is supported uint8_t drv_id; for (drv_id = 0; drv_id < USBD_CLASS_DRIVER_COUNT; drv_id++) { - if ( usbd_class_drivers[drv_id].class_code == class_code ) break; + if ( usbd_class_drivers[drv_id].class_code == desc_itf->bInterfaceClass ) break; } - TU_ASSERT( drv_id < USBD_CLASS_DRIVER_COUNT, TUSB_ERROR_NOT_SUPPORTED_YET ); + TU_ASSERT( drv_id < USBD_CLASS_DRIVER_COUNT ); // unsupported class - // Interface number must not be used - TU_ASSERT( 0xff == _usbd_dev.itf2drv[p_desc_itf->bInterfaceNumber], TUSB_ERROR_FAILED); - _usbd_dev.itf2drv[p_desc_itf->bInterfaceNumber] = drv_id; + // Interface number must not be used already TODO alternate interface + TU_ASSERT( 0xff == _usbd_dev.itf2drv[desc_itf->bInterfaceNumber] ); + _usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id; uint16_t len=0; - TU_ASSERT_ERR( usbd_class_drivers[drv_id].open( rhport, p_desc_itf, &len ) ); - TU_ASSERT( len >= sizeof(tusb_desc_interface_t), TUSB_ERROR_FAILED ); + TU_ASSERT_ERR( usbd_class_drivers[drv_id].open( rhport, desc_itf, &len ), false ); + TU_ASSERT( len >= sizeof(tusb_desc_interface_t) ); mark_interface_endpoint(p_desc, len, drv_id); @@ -404,8 +489,62 @@ static void mark_interface_endpoint(uint8_t const* p_desc, uint16_t desc_len, ui } } +// return descriptor's buffer and update desc_len +static void const* get_descriptor(tusb_control_request_t const * p_request, uint16_t* desc_len) +{ + tusb_desc_type_t const desc_type = (tusb_desc_type_t) tu_u16_high(p_request->wValue); + uint8_t const desc_index = tu_u16_low( p_request->wValue ); + + uint8_t const * desc_data = NULL; + uint16_t len = 0; + + *desc_len = 0; + + switch(desc_type) + { + case TUSB_DESC_DEVICE: + desc_data = (uint8_t const *) usbd_desc_set->device; + len = sizeof(tusb_desc_device_t); + break; + + case TUSB_DESC_CONFIGURATION: + 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]; + TU_VERIFY( desc_data != NULL, NULL ); + + len = desc_data[0]; // first byte of descriptor is its size + }else + { + // out of range + /* The 0xEE index string is a Microsoft USB extension. + * It can be used to tell Windows what driver it should use for the device !!! + */ + return NULL; + } + break; + + case TUSB_DESC_DEVICE_QUALIFIER: + // TODO If not highspeed capable stall this request otherwise + // return the descriptor that could work in highspeed + return NULL; + break; + + default: return NULL; + } + + *desc_len = len; + return desc_data; +} + //--------------------------------------------------------------------+ -// USBD-DCD Callback API +// DCD Event Handler //--------------------------------------------------------------------+ void dcd_event_handler(dcd_event_t const * event, bool in_isr) { @@ -430,6 +569,9 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) break; case DCD_EVENT_XFER_COMPLETE: + // skip zero-length control status complete event, should dcd notifies us. + if ( 0 == edpt_number(event->xfer_complete.ep_addr) && event->xfer_complete.len == 0) break; + osal_queue_send(_usbd_q, event, in_isr); TU_ASSERT(event->xfer_complete.result == DCD_XFER_SUCCESS,); break; @@ -438,8 +580,6 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) } } -void dcd_event_handler(dcd_event_t const * event, bool in_isr); - // helper to send bus signal event void dcd_event_bus_signal (uint8_t rhport, dcd_eventid_t eid, bool in_isr) { diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index bbbe0a604..30f010887 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -54,15 +54,24 @@ extern tud_desc_set_t const* usbd_desc_set; tusb_error_t usbd_init (void); void usbd_task (void* param); + +// Carry out Data and Status stage of control transfer +// - If len = 0, it is equivalent to sending status only +// - If len > wLength : it will be truncated +bool usbd_control_xfer(uint8_t rhport, tusb_control_request_t const * request, void* buffer, uint16_t len); + +// Send STATUS (zero length) packet +bool usbd_control_status(uint8_t rhport, tusb_control_request_t const * request); + +// Stall control endpoint until new setup packet arrived +void usbd_control_stall(uint8_t rhport); + /*------------------------------------------------------------------*/ -/* Endpoint helper +/* Helper *------------------------------------------------------------------*/ // helper to parse an pair of In and Out endpoint descriptors. They must be consecutive tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_desc_ep, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in); -/*------------------------------------------------------------------*/ -/* Other Helpers - *------------------------------------------------------------------*/ void usbd_defer_func( osal_task_func_t func, void* param, bool in_isr ); diff --git a/src/tusb_option.h b/src/tusb_option.h index d027ea0e6..f19ff4076 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -148,10 +148,8 @@ #define CFG_TUD_ENDOINT0_SIZE 64 #endif - #ifndef CFG_TUD_ENUM_BUFFER_SIZE + #ifndef CFG_TUD_CTRL_BUFSIZE #define CFG_TUD_CTRL_BUFSIZE 256 - #else - #define CFG_TUD_CTRL_BUFSIZE CFG_TUD_ENUM_BUFFER_SIZE #endif #ifndef CFG_TUD_DESC_AUTO -- cgit v1.3.1 From cb8782e5f28b4897e73520c91296d1ac7d71da81 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 23 Nov 2018 15:14:47 +0700 Subject: rename tusb_event_t to xfer_result_t --- examples/obsolete/device/src/keyboard_device_app.c | 2 +- examples/obsolete/device/src/mouse_device_app.c | 2 +- examples/obsolete/host/src/cdc_serial_host_app.c | 2 +- examples/obsolete/host/src/keyboard_host_app.c | 2 +- examples/obsolete/host/src/mouse_host_app.c | 2 +- examples/obsolete/host/src/msc_host_app.c | 2 +- src/class/cdc/cdc_device.c | 2 +- src/class/cdc/cdc_device.h | 2 +- src/class/cdc/cdc_host.c | 2 +- src/class/cdc/cdc_host.h | 6 +++--- src/class/cdc/cdc_rndis_host.c | 2 +- src/class/cdc/cdc_rndis_host.h | 2 +- src/class/custom/custom_device.c | 2 +- src/class/custom/custom_device.h | 2 +- src/class/custom/custom_host.c | 2 +- src/class/custom/custom_host.h | 2 +- src/class/hid/hid_device.c | 2 +- src/class/hid/hid_device.h | 2 +- src/class/hid/hid_host.c | 2 +- src/class/hid/hid_host.h | 12 ++++++------ src/class/msc/msc_device.c | 4 ++-- src/class/msc/msc_device.h | 2 +- src/class/msc/msc_host.c | 2 +- src/class/msc/msc_host.h | 6 +++--- src/common/tusb_types.h | 3 +-- src/device/usbd.c | 4 ++-- src/device/usbd_control.c | 2 +- src/host/ehci/ehci.c | 2 +- src/host/hub.c | 2 +- src/host/hub.h | 2 +- src/host/ohci/ohci.c | 2 +- src/host/usbh.c | 2 +- src/host/usbh.h | 2 +- src/host/usbh_hcd.h | 2 +- tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h | 2 +- tests/lpc18xx_43xx/test/host/hid/hidh_callback.h | 4 ++-- tests/lpc18xx_43xx/test/host/msc/msch_callback.h | 2 +- 37 files changed, 49 insertions(+), 50 deletions(-) (limited to 'src/class/custom') diff --git a/examples/obsolete/device/src/keyboard_device_app.c b/examples/obsolete/device/src/keyboard_device_app.c index f6ef77c10..6c413464e 100644 --- a/examples/obsolete/device/src/keyboard_device_app.c +++ b/examples/obsolete/device/src/keyboard_device_app.c @@ -66,7 +66,7 @@ void keyboard_app_umount(uint8_t rhport) } -void tud_hid_keyboard_cb(uint8_t rhport, tusb_event_t event, uint32_t xferred_bytes) +void tud_hid_keyboard_cb(uint8_t rhport, xfer_result_t event, uint32_t xferred_bytes) { switch(event) { diff --git a/examples/obsolete/device/src/mouse_device_app.c b/examples/obsolete/device/src/mouse_device_app.c index db685daf6..4c4d322d7 100644 --- a/examples/obsolete/device/src/mouse_device_app.c +++ b/examples/obsolete/device/src/mouse_device_app.c @@ -66,7 +66,7 @@ void mouse_app_umount(uint8_t rhport) } -void tud_hid_mouse_cb(uint8_t rhport, tusb_event_t event, uint32_t xferred_bytes) +void tud_hid_mouse_cb(uint8_t rhport, xfer_result_t event, uint32_t xferred_bytes) { switch(event) { diff --git a/examples/obsolete/host/src/cdc_serial_host_app.c b/examples/obsolete/host/src/cdc_serial_host_app.c index d16a9b411..afb2b8937 100644 --- a/examples/obsolete/host/src/cdc_serial_host_app.c +++ b/examples/obsolete/host/src/cdc_serial_host_app.c @@ -75,7 +75,7 @@ void tuh_cdc_unmounted_cb(uint8_t dev_addr) } // invoked ISR context -void tuh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes) +void tuh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes) { (void) dev_addr; // compiler warnings diff --git a/examples/obsolete/host/src/keyboard_host_app.c b/examples/obsolete/host/src/keyboard_host_app.c index 6d10e96e1..27d10b9e7 100644 --- a/examples/obsolete/host/src/keyboard_host_app.c +++ b/examples/obsolete/host/src/keyboard_host_app.c @@ -77,7 +77,7 @@ void tuh_hid_keyboard_unmounted_cb(uint8_t dev_addr) } // invoked ISR context -void tuh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event) +void tuh_hid_keyboard_isr(uint8_t dev_addr, xfer_result_t event) { switch(event) { diff --git a/examples/obsolete/host/src/mouse_host_app.c b/examples/obsolete/host/src/mouse_host_app.c index 563b911c2..05135693b 100644 --- a/examples/obsolete/host/src/mouse_host_app.c +++ b/examples/obsolete/host/src/mouse_host_app.c @@ -76,7 +76,7 @@ void tuh_hid_mouse_unmounted_cb(uint8_t dev_addr) } // invoked ISR context -void tuh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event) +void tuh_hid_mouse_isr(uint8_t dev_addr, xfer_result_t event) { switch(event) { diff --git a/examples/obsolete/host/src/msc_host_app.c b/examples/obsolete/host/src/msc_host_app.c index 3648cb94b..1cfe9ec60 100644 --- a/examples/obsolete/host/src/msc_host_app.c +++ b/examples/obsolete/host/src/msc_host_app.c @@ -129,7 +129,7 @@ void tuh_msc_unmounted_cb(uint8_t dev_addr) } // invoked ISR context -void tuh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes) +void tuh_msc_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes) { (void) dev_addr; (void) event; diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index a0abd42f6..b68a6a7ff 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -358,7 +358,7 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request return true; } -tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, uint32_t xferred_bytes) +tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { // TODO Support multiple interfaces uint8_t const itf = 0; diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 749351a54..ad1100e9c 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -116,7 +116,7 @@ void cdcd_init (void); tusb_error_t cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * p_request); bool cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); +tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); void cdcd_reset (uint8_t rhport); #endif diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index af2e2c444..0a3661878 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -221,7 +221,7 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ OSAL_SUBTASK_END } -void cdch_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes) +void cdch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) { tuh_cdc_xfer_isr( pipe_hdl.dev_addr, event, get_app_pipeid(pipe_hdl), xferred_bytes ); } diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h index b3e995470..8cfe6e5b7 100644 --- a/src/class/cdc/cdc_host.h +++ b/src/class/cdc/cdc_host.h @@ -118,7 +118,7 @@ void tuh_cdc_unmounted_cb(uint8_t dev_addr); /** \brief Callback function that is invoked when an transferring event occurred * \param[in] dev_addr Address of device - * \param[in] event an value from \ref tusb_event_t + * \param[in] event an value from \ref xfer_result_t * \param[in] pipe_id value from \ref cdc_pipeid_t indicate the pipe * \param[in] xferred_bytes Number of bytes transferred via USB bus * \note event can be one of following @@ -127,7 +127,7 @@ void tuh_cdc_unmounted_cb(uint8_t dev_addr); * - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device. * \note */ -void tuh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); +void tuh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); /// @} // group CDC_Serial_Host /// @} @@ -151,7 +151,7 @@ extern cdch_data_t cdch_data[CFG_TUSB_HOST_DEVICE_MAX]; // TODO consider to move void cdch_init(void); tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void cdch_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes); +void cdch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); void cdch_close(uint8_t dev_addr); #endif diff --git a/src/class/cdc/cdc_rndis_host.c b/src/class/cdc/cdc_rndis_host.c index 42722fd0d..89ea3b32f 100644 --- a/src/class/cdc/cdc_rndis_host.c +++ b/src/class/cdc/cdc_rndis_host.c @@ -224,7 +224,7 @@ tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc) OSAL_SUBTASK_END } -void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes) +void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) { if ( pipehandle_is_equal(pipe_hdl, p_cdc->pipe_notification) ) { diff --git a/src/class/cdc/cdc_rndis_host.h b/src/class/cdc/cdc_rndis_host.h index c4597daa8..3b92d3f23 100644 --- a/src/class/cdc/cdc_rndis_host.h +++ b/src/class/cdc/cdc_rndis_host.h @@ -65,7 +65,7 @@ typedef struct { void rndish_init(void); tusb_error_t rndish_open_subtask(uint8_t dev_addr, cdch_data_t *p_cdc) ATTR_WARN_UNUSED_RESULT; -void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes); +void rndish_xfer_isr(cdch_data_t *p_cdc, pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); void rndish_close(uint8_t dev_addr); #endif diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index cc440fc7e..194963c17 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -94,7 +94,7 @@ bool cusd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque return false; } -tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes) +tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes) { return TUSB_ERROR_NONE; } diff --git a/src/class/custom/custom_device.h b/src/class/custom/custom_device.h index 704c4127b..0a8f05e7d 100644 --- a/src/class/custom/custom_device.h +++ b/src/class/custom/custom_device.h @@ -66,7 +66,7 @@ void cusd_init(void); tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request); bool cusd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); +tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); void cusd_reset(uint8_t rhport); #endif diff --git a/src/class/custom/custom_host.c b/src/class/custom/custom_host.c index 329012fda..9f0b70afb 100644 --- a/src/class/custom/custom_host.c +++ b/src/class/custom/custom_host.c @@ -131,7 +131,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ return TUSB_ERROR_NONE; } -void cush_isr(pipe_handle_t pipe_hdl, tusb_event_t event) +void cush_isr(pipe_handle_t pipe_hdl, xfer_result_t event) { } diff --git a/src/class/custom/custom_host.h b/src/class/custom/custom_host.h index 2bf3a8d3c..5f9c25dda 100644 --- a/src/class/custom/custom_host.h +++ b/src/class/custom/custom_host.h @@ -73,7 +73,7 @@ tusb_error_t tusbh_custom_write(uint8_t dev_addr, uint16_t vendor_id, uint16_t p void cush_init(void); tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void cush_isr(pipe_handle_t pipe_hdl, tusb_event_t event); +void cush_isr(pipe_handle_t pipe_hdl, xfer_result_t event); void cush_close(uint8_t dev_addr); #endif diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index cece06ea0..f1ecec3c7 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -510,7 +510,7 @@ bool hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const return true; } -tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes) +tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t 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 357c71082..7aff7f34d 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -380,7 +380,7 @@ void hidd_init(void); tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool hidd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); +tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); void hidd_reset(uint8_t rhport); #endif diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 7129562c5..6aa0748df 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -251,7 +251,7 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ OSAL_SUBTASK_END } -void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes) +void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) { (void) xferred_bytes; // TODO may need to use this para later diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h index 3acc05bf7..fb10a614f 100644 --- a/src/class/hid/hid_host.h +++ b/src/class/hid/hid_host.h @@ -93,14 +93,14 @@ tusb_error_t tuh_hid_keyboard_get_report(uint8_t dev_addr, void * p_report) /*A //------------- Application Callback -------------// /** \brief Callback function that is invoked when an transferring event occurred * \param[in] dev_addr Address of device - * \param[in] event an value from \ref tusb_event_t + * \param[in] event an value from \ref xfer_result_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. * \note Application should schedule the next report by calling \ref tuh_hid_keyboard_get_report within this callback */ -void tuh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event); +void tuh_hid_keyboard_isr(uint8_t dev_addr, xfer_result_t event); /** \brief Callback function that will be invoked when a device with Keyboard interface is mounted * \param[in] dev_addr Address of newly mounted device @@ -158,14 +158,14 @@ tusb_error_t tuh_hid_mouse_get_report(uint8_t dev_addr, void* p_report) /*ATTR_ //------------- Application Callback -------------// /** \brief Callback function that is invoked when an transferring event occurred * \param[in] dev_addr Address of device - * \param[in] event an value from \ref tusb_event_t + * \param[in] event an value from \ref xfer_result_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. * \note Application should schedule the next report by calling \ref tuh_hid_mouse_get_report within this callback */ -void tuh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event); +void tuh_hid_mouse_isr(uint8_t dev_addr, xfer_result_t event); /** \brief Callback function that will be invoked when a device with Mouse interface is mounted * \param[in] dev_addr Address of newly mounted device @@ -199,7 +199,7 @@ tusb_interface_status_t tuh_hid_generic_get_status(uint8_t dev_addr) ATTR_WARN_U tusb_interface_status_t tuh_hid_generic_set_status(uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT; //------------- Application Callback -------------// -void tuh_hid_generic_isr(uint8_t dev_addr, tusb_event_t event); +void tuh_hid_generic_isr(uint8_t dev_addr, xfer_result_t event); /** @} */ // Generic_Host /** @} */ // ClassDriver_HID_Generic @@ -217,7 +217,7 @@ typedef struct { void hidh_init(void); tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes); +void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); void hidh_close(uint8_t dev_addr); #endif diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 78e6d0a6b..1f4252f22 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -324,7 +324,7 @@ int32_t proc_builtin_scsi(msc_cbw_t const * p_cbw, uint8_t* buffer, uint32_t buf return ret; } -tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, uint32_t xferred_bytes) +tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { mscd_interface_t* p_msc = &_mscd_itf; msc_cbw_t const * p_cbw = &p_msc->cbw; @@ -337,7 +337,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u // Complete IN while waiting for CMD is usually Status of previous SCSI op, ignore it if(ep_addr != p_msc->ep_out) return TUSB_ERROR_NONE; - TU_ASSERT( event == DCD_XFER_SUCCESS && + TU_ASSERT( ((uint8_t) event) == DCD_XFER_SUCCESS && xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE, TUSB_ERROR_INVALID_PARA ); p_csw->signature = MSC_CSW_SIGNATURE; diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index c1c51255a..c4476f56f 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -180,7 +180,7 @@ void mscd_init(void); tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool mscd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes); +tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); void mscd_reset(uint8_t rhport); #endif diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index bd3e92de1..baef7ff44 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -397,7 +397,7 @@ tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ OSAL_SUBTASK_END } -void msch_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes) +void msch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) { if ( pipehandle_is_equal(pipe_hdl, msch_data[pipe_hdl.dev_addr-1].bulk_in) ) { diff --git a/src/class/msc/msc_host.h b/src/class/msc/msc_host.h index 6d95cfe34..0afe5c515 100644 --- a/src/class/msc/msc_host.h +++ b/src/class/msc/msc_host.h @@ -171,7 +171,7 @@ void tuh_msc_unmounted_cb(uint8_t dev_addr); /** \brief Callback function that is invoked when an transferring event occurred * \param[in] dev_addr Address of device - * \param[in] event an value from \ref tusb_event_t + * \param[in] event an value from \ref xfer_result_t * \param[in] xferred_bytes Number of bytes transferred via USB bus * \note event can be one of following * - TUSB_EVENT_XFER_COMPLETE : previously scheduled transfer completes successfully. @@ -179,7 +179,7 @@ void tuh_msc_unmounted_cb(uint8_t dev_addr); * - TUSB_EVENT_XFER_STALLED : previously scheduled transfer is stalled by device. * \note */ -void tuh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes); +void tuh_msc_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes); //--------------------------------------------------------------------+ @@ -205,7 +205,7 @@ typedef struct { void msch_init(void); tusb_error_t msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void msch_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes); +void msch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); void msch_close(uint8_t dev_addr); #endif diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index 32632cd90..7b5268d4f 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -197,11 +197,10 @@ typedef enum typedef enum { - TUSB_EVENT_NONE = 0, TUSB_EVENT_XFER_COMPLETE, TUSB_EVENT_XFER_ERROR, TUSB_EVENT_XFER_STALLED, -}tusb_event_t; +}xfer_result_t; enum { diff --git a/src/device/usbd.c b/src/device/usbd.c index f39605987..710eba553 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -92,7 +92,7 @@ typedef struct { tusb_error_t (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t* p_length); bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request); bool (* control_request_complete ) (uint8_t rhport, tusb_control_request_t const * request); - tusb_error_t (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, tusb_event_t, uint32_t); + tusb_error_t (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t, uint32_t); void (* sof ) (uint8_t rhport); void (* reset ) (uint8_t); } usbd_class_driver_t; @@ -174,7 +174,7 @@ static bool process_set_config(uint8_t rhport, uint8_t config_number); static void const* get_descriptor(tusb_control_request_t const * p_request, uint16_t* desc_len); void usbd_control_reset (uint8_t rhport); -bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, tusb_event_t event, uint32_t xferred_bytes); +bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_request_t const * ) ); //--------------------------------------------------------------------+ diff --git a/src/device/usbd_control.c b/src/device/usbd_control.c index 33de6d064..31d74edf0 100644 --- a/src/device/usbd_control.c +++ b/src/device/usbd_control.c @@ -126,7 +126,7 @@ bool usbd_control_xfer(uint8_t rhport, tusb_control_request_t const * request, v } // callback when a transaction complete on DATA stage of control endpoint -bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, tusb_event_t event, uint32_t xferred_bytes) +bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { if ( _control_state.request.bmRequestType_bit.direction == TUSB_DIR_OUT ) { diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index b3d897537..2fc99ffcd 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -638,7 +638,7 @@ static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd) qhd_has_xact_error(p_qhd) ) { // current qhd has error in transaction tusb_xfer_type_t const xfer_type = qhd_get_xfer_type(p_qhd); - tusb_event_t error_event; + xfer_result_t error_event; // no error bits are set, endpoint is halted due to STALL error_event = qhd_has_xact_error(p_qhd) ? TUSB_EVENT_XFER_ERROR : TUSB_EVENT_XFER_STALLED; diff --git a/src/host/hub.c b/src/host/hub.c index e4c08c9d1..9635bcc0b 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -209,7 +209,7 @@ tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_i } // is the response of interrupt endpoint polling -void hub_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes) +void hub_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) { (void) xferred_bytes; // TODO can be more than 1 for hub with lots of ports diff --git a/src/host/hub.h b/src/host/hub.h index 67c02f2e3..9376a2698 100644 --- a/src/host/hub.h +++ b/src/host/hub.h @@ -196,7 +196,7 @@ tusb_error_t hub_status_pipe_queue(uint8_t dev_addr); void hub_init(void); tusb_error_t hub_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT; -void hub_isr(pipe_handle_t pipe_hdl, tusb_event_t event, uint32_t xferred_bytes); +void hub_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes); void hub_close(uint8_t dev_addr); #endif diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index f058f8348..58738a236 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -617,7 +617,7 @@ static void done_queue_isr(uint8_t hostid) // TODO check if td_head is iso td //------------- Non ISO transfer -------------// ohci_gtd_t * const p_qtd = (ohci_gtd_t *) td_head; - tusb_event_t const event = (p_qtd->condition_code == OHCI_CCODE_NO_ERROR) ? TUSB_EVENT_XFER_COMPLETE : + xfer_result_t const event = (p_qtd->condition_code == OHCI_CCODE_NO_ERROR) ? TUSB_EVENT_XFER_COMPLETE : (p_qtd->condition_code == OHCI_CCODE_STALL) ? TUSB_EVENT_XFER_STALLED : TUSB_EVENT_XFER_ERROR; p_qtd->used = 0; // free TD diff --git a/src/host/usbh.c b/src/host/usbh.c index 196a45ee7..ed21bf3da 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -256,7 +256,7 @@ static inline uint8_t std_class_code_to_index(uint8_t std_class_code) // USBH-HCD ISR/Callback API //--------------------------------------------------------------------+ // interrupt caused by a TD (with IOC=1) in pipe of class class_code -void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t event, uint32_t xferred_bytes) +void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, xfer_result_t event, uint32_t xferred_bytes) { uint8_t class_index = std_class_code_to_index(class_code); if (TUSB_XFER_CONTROL == pipe_hdl.xfer_type) diff --git a/src/host/usbh.h b/src/host/usbh.h index 5aaeb4186..22fdef162 100644 --- a/src/host/usbh.h +++ b/src/host/usbh.h @@ -66,7 +66,7 @@ typedef enum tusb_interface_status_{ typedef struct { void (* const init) (void); tusb_error_t (* const open_subtask)(uint8_t, tusb_desc_interface_t const *, uint16_t*); - void (* const isr) (pipe_handle_t, tusb_event_t, uint32_t); + void (* const isr) (pipe_handle_t, xfer_result_t, uint32_t); void (* const close) (uint8_t); } host_class_driver_t; //--------------------------------------------------------------------+ diff --git a/src/host/usbh_hcd.h b/src/host/usbh_hcd.h index 1c2c4ad0b..f6b72273a 100644 --- a/src/host/usbh_hcd.h +++ b/src/host/usbh_hcd.h @@ -101,7 +101,7 @@ extern usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including //--------------------------------------------------------------------+ // callback from HCD ISR //--------------------------------------------------------------------+ -void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t event, uint32_t xferred_bytes); +void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, xfer_result_t event, uint32_t xferred_bytes); void usbh_hcd_rhport_plugged_isr(uint8_t hostid); void usbh_hcd_rhport_unplugged_isr(uint8_t hostid); diff --git a/tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h b/tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h index b1aea64b0..1eb608b91 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h +++ b/tests/lpc18xx_43xx/test/host/cdc/cdc_callback.h @@ -55,7 +55,7 @@ void tusbh_cdc_mounted_cb(uint8_t dev_addr); void tusbh_cdc_unmounted_cb(uint8_t dev_addr); -void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); +void tusbh_cdc_xfer_isr(uint8_t dev_addr, xfer_result_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes); void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr); void tusbh_cdc_rndis_unmounted_isr(uint8_t dev_addr); diff --git a/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h b/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h index 4b76bd3cd..b0945c1d1 100644 --- a/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h +++ b/tests/lpc18xx_43xx/test/host/hid/hidh_callback.h @@ -59,11 +59,11 @@ #include "common/common.h" //------------- hidh -------------// -void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event); +void tusbh_hid_keyboard_isr(uint8_t dev_addr, xfer_result_t event); void tusbh_hid_keyboard_mounted_cb(uint8_t dev_addr); void tusbh_hid_keyboard_unmounted_cb(uint8_t dev_addr); -void tusbh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event); +void tusbh_hid_mouse_isr(uint8_t dev_addr, xfer_result_t event); void tusbh_hid_mouse_mounted_cb(uint8_t dev_addr); void tusbh_hid_mouse_unmounted_cb(uint8_t dev_addr); diff --git a/tests/lpc18xx_43xx/test/host/msc/msch_callback.h b/tests/lpc18xx_43xx/test/host/msc/msch_callback.h index 26b301a00..275245bec 100644 --- a/tests/lpc18xx_43xx/test/host/msc/msch_callback.h +++ b/tests/lpc18xx_43xx/test/host/msc/msch_callback.h @@ -54,7 +54,7 @@ void tusbh_msc_mounted_cb(uint8_t dev_addr); void tusbh_msc_unmounted_cb(uint8_t dev_addr); -void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes); +void tusbh_msc_isr(uint8_t dev_addr, xfer_result_t event, uint32_t xferred_bytes); #ifdef __cplusplus -- cgit v1.3.1 From 607658d047a3c27a096b9f6a25ea0a76f3d8735d Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 7 Dec 2018 23:38:52 +0700 Subject: rename MODE_HOST_SUPPORTED to TUSB_OPT_HOST_ENABLED --- hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c | 2 +- src/class/cdc/cdc_host.c | 2 +- src/class/cdc/cdc_rndis_host.c | 2 +- src/class/custom/custom_host.c | 2 +- src/class/hid/hid_host.c | 2 +- src/class/msc/msc_host.c | 2 +- src/host/ehci/ehci.c | 2 +- src/host/hcd.h | 2 +- src/host/hub.c | 2 +- src/host/ohci/ohci.c | 2 +- src/host/usbh.c | 2 +- src/osal/osal_none.h | 6 +++--- src/portable/nxp/lpc17_40/hal_lpc17_40.c | 2 +- src/portable/nxp/lpc18_43/hal_lpc18_43.c | 4 ++-- src/tusb.c | 4 ++-- src/tusb.h | 2 +- src/tusb_option.h | 11 ++--------- 17 files changed, 22 insertions(+), 29 deletions(-) (limited to 'src/class/custom') diff --git a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c index 0c5f5189c..427e8733c 100644 --- a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c +++ b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c @@ -148,7 +148,7 @@ void board_init(void) LPC_USB->OTGClkCtrl = clk_en; while ( (LPC_USB->OTGClkSt & clk_en) != clk_en ); -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED // set portfunc to host !!! LPC_USB->StCtrl = 0x3; // should be 1 #endif diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index c4ec88416..8d7c2bd40 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && CFG_TUH_CDC) +#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_CDC) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/class/cdc/cdc_rndis_host.c b/src/class/cdc/cdc_rndis_host.c index df4a29938..ae61bf8b5 100644 --- a/src/class/cdc/cdc_rndis_host.c +++ b/src/class/cdc/cdc_rndis_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && CFG_TUH_CDC && CFG_TUH_CDC_RNDIS) +#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_CDC && CFG_TUH_CDC_RNDIS) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/class/custom/custom_host.c b/src/class/custom/custom_host.c index 9f0b70afb..2a8206e36 100644 --- a/src/class/custom/custom_host.c +++ b/src/class/custom/custom_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && CFG_TUSB_HOST_CUSTOM_CLASS) +#if (TUSB_OPT_HOST_ENABLED && CFG_TUSB_HOST_CUSTOM_CLASS) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 14398aa67..980381bf5 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && HOST_CLASS_HID) +#if (TUSB_OPT_HOST_ENABLED && HOST_CLASS_HID) #define _TINY_USB_SOURCE_FILE_ //--------------------------------------------------------------------+ diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 0c52011df..57a409ffd 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if MODE_HOST_SUPPORTED & CFG_TUH_MSC +#if TUSB_OPT_HOST_ENABLED & CFG_TUH_MSC #define _TINY_USB_SOURCE_FILE_ diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index 8e40804d5..d18f19195 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -38,7 +38,7 @@ #include "common/tusb_common.h" -#if MODE_HOST_SUPPORTED && (CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX) +#if TUSB_OPT_HOST_ENABLED && (CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX) //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ diff --git a/src/host/hcd.h b/src/host/hcd.h index db80994c0..387fbcf1c 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -79,7 +79,7 @@ typedef struct } hcd_event_t; -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED // Max number of endpoints per device enum { HCD_MAX_ENDPOINT = CFG_TUH_HUB + CFG_TUH_HID_KEYBOARD + CFG_TUH_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC + diff --git a/src/host/hub.c b/src/host/hub.c index 28814ebd7..04618d448 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -38,7 +38,7 @@ #include "tusb_option.h" -#if (MODE_HOST_SUPPORTED && CFG_TUH_HUB) +#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_HUB) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index 3944d72d0..2c22a3c98 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -38,7 +38,7 @@ #include -#if MODE_HOST_SUPPORTED && (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC40XX) +#if TUSB_OPT_HOST_ENABLED && (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC40XX) //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ diff --git a/src/host/usbh.c b/src/host/usbh.c index 4c4fd5319..d97b4b0d3 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -38,7 +38,7 @@ #include "common/tusb_common.h" -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED #define _TINY_USB_SOURCE_FILE_ diff --git a/src/osal/osal_none.h b/src/osal/osal_none.h index 4da5cffc8..ff37113c6 100644 --- a/src/osal/osal_none.h +++ b/src/osal/osal_none.h @@ -134,7 +134,7 @@ extern void dcd_int_disable(uint8_t rhport); extern void dcd_int_enable(uint8_t rhport); #endif -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED extern void hcd_int_disable(uint8_t rhport); extern void hcd_int_enable(uint8_t rhport); #endif @@ -167,7 +167,7 @@ static inline void _osal_q_lock(osal_queue_t qhdl) if (qhdl->role == OPT_MODE_DEVICE) dcd_int_disable(TUD_OPT_RHPORT); #endif -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED if (qhdl->role == OPT_MODE_HOST) hcd_int_disable(TUH_OPT_RHPORT); #endif } @@ -179,7 +179,7 @@ static inline void _osal_q_unlock(osal_queue_t qhdl) if (qhdl->role == OPT_MODE_DEVICE) dcd_int_enable(TUD_OPT_RHPORT); #endif -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED if (qhdl->role == OPT_MODE_HOST) hcd_int_enable(TUH_OPT_RHPORT); #endif } diff --git a/src/portable/nxp/lpc17_40/hal_lpc17_40.c b/src/portable/nxp/lpc17_40/hal_lpc17_40.c index 2acd19f6e..04aebf920 100644 --- a/src/portable/nxp/lpc17_40/hal_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/hal_lpc17_40.c @@ -47,7 +47,7 @@ extern void hal_dcd_isr(uint8_t rhport); void USB_IRQHandler(void) { - #if MODE_HOST_SUPPORTED + #if TUSB_OPT_HOST_ENABLED hal_hcd_isr(0); #endif diff --git a/src/portable/nxp/lpc18_43/hal_lpc18_43.c b/src/portable/nxp/lpc18_43/hal_lpc18_43.c index 48a25f99a..ef3977995 100644 --- a/src/portable/nxp/lpc18_43/hal_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/hal_lpc18_43.c @@ -48,7 +48,7 @@ extern void hal_hcd_isr(uint8_t hostid); #if CFG_TUSB_RHPORT0_MODE void USB0_IRQHandler(void) { - #if MODE_HOST_SUPPORTED + #if TUSB_OPT_HOST_ENABLED hal_hcd_isr(0); #endif @@ -61,7 +61,7 @@ void USB0_IRQHandler(void) #if CFG_TUSB_RHPORT1_MODE void USB1_IRQHandler(void) { - #if MODE_HOST_SUPPORTED + #if TUSB_OPT_HOST_ENABLED hal_hcd_isr(1); #endif diff --git a/src/tusb.c b/src/tusb.c index 931cc0ebe..4f7996664 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -55,7 +55,7 @@ bool tusb_init(void) // skip if already initialized if (_initialized) return true; -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED TU_VERIFY( usbh_init() ); // init host stack #endif @@ -71,7 +71,7 @@ bool tusb_init(void) #if CFG_TUSB_OS == OPT_OS_NONE void tusb_task(void) { - #if MODE_HOST_SUPPORTED + #if TUSB_OPT_HOST_ENABLED usbh_task(NULL); #endif diff --git a/src/tusb.h b/src/tusb.h index e31513f87..4d65c80e1 100644 --- a/src/tusb.h +++ b/src/tusb.h @@ -52,7 +52,7 @@ #include "common/tusb_fifo.h" //------------- HOST -------------// -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED #include "host/usbh.h" #if HOST_CLASS_HID diff --git a/src/tusb_option.h b/src/tusb_option.h index ad5025235..e8baf4149 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -109,13 +109,6 @@ #error "tinyusb does not support same modes on more than 1 roothub port" #endif -// TODO remove -#define CONTROLLER_HOST_NUMBER (\ - ((CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST) ? 1 : 0) + \ - ((CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST) ? 1 : 0)) - -#define MODE_HOST_SUPPORTED (CONTROLLER_HOST_NUMBER > 0) - // Which roothub port is configured as host #define TUH_OPT_RHPORT ( (CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST) ? 0 : ((CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST) ? 1 : -1) ) #define TUSB_OPT_HOST_ENABLED ( TUH_OPT_RHPORT >= 0 ) @@ -206,7 +199,7 @@ //-------------------------------------------------------------------- // HOST OPTIONS //-------------------------------------------------------------------- -#if MODE_HOST_SUPPORTED +#if TUSB_OPT_HOST_ENABLED #ifndef CFG_TUSB_HOST_DEVICE_MAX #define CFG_TUSB_HOST_DEVICE_MAX 1 #warning CFG_TUSB_HOST_DEVICE_MAX is not defined, default value is 1 @@ -228,7 +221,7 @@ #endif //------------- CLASS -------------// -#endif // MODE_HOST_SUPPORTED +#endif // TUSB_OPT_HOST_ENABLED //------------------------------------------------------------------ -- cgit v1.3.1 From 0d04e6eb96935723f17969bf43a33532fcebcbf6 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 11 Dec 2018 13:12:21 +0700 Subject: rename to hcd_edpt_open() --- src/class/cdc/cdc_host.c | 4 ++-- src/class/custom/custom_host.c | 2 +- src/class/hid/hid_host.c | 2 +- src/class/msc/msc_host.c | 2 +- src/host/ehci/ehci.c | 2 +- src/host/hcd.h | 6 ++--- src/host/hub.c | 2 +- src/host/ohci/ohci.c | 2 +- src/host/usbh.c | 2 +- tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c | 26 +++++++++++----------- .../test/host/cdc/test_cdc_rndis_host.c | 6 ++--- .../host/ehci/test_ehci_usbh_hcd_integration.c | 2 +- .../test/host/ehci/test_pipe_bulk_open.c | 6 ++--- .../test/host/ehci/test_pipe_bulk_xfer.c | 4 ++-- .../test/host/ehci/test_pipe_interrupt_open.c | 26 +++++++++++----------- .../test/host/ehci/test_pipe_interrupt_xfer.c | 4 ++-- .../test/host/ehci/test_pipe_isochronous_open.c | 2 +- tests/lpc18xx_43xx/test/host/hid/test_hid_host.c | 2 +- .../test/host/hid/test_hidh_keyboard.c | 2 +- tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c | 2 +- tests/lpc18xx_43xx/test/host/msc/test_msc_host.c | 14 ++++++------ 21 files changed, 60 insertions(+), 60 deletions(-) (limited to 'src/class/custom') diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 78b338f15..f889c8c90 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -173,7 +173,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it // notification endpoint tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) p_desc; - TU_ASSERT( hcd_pipe_open(rhport, dev_addr, ep_desc) ); + TU_ASSERT( hcd_edpt_open(rhport, dev_addr, ep_desc) ); p_cdc->ep_notif = ep_desc->bEndpointAddress; (*p_length) += p_desc[DESC_OFFSET_LEN]; @@ -194,7 +194,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer); - TU_ASSERT(hcd_pipe_open(rhport, dev_addr, ep_desc)); + TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { diff --git a/src/class/custom/custom_host.c b/src/class/custom/custom_host.c index 2a8206e36..e840a2829 100644 --- a/src/class/custom/custom_host.c +++ b/src/class/custom/custom_host.c @@ -121,7 +121,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ? &custom_interface[dev_addr-1].pipe_in : &custom_interface[dev_addr-1].pipe_out; - *p_pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC); + *p_pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC); TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED ); p_desc = descriptor_next(p_desc); diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 980381bf5..8d7dce70a 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -56,7 +56,7 @@ //--------------------------------------------------------------------+ static inline bool hidh_interface_open(uint8_t dev_addr, uint8_t interface_number, tusb_desc_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid) { - p_hid->pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID); + p_hid->pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID); p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor p_hid->interface_number = interface_number; diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 1053d42d2..8e51debcf 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -307,7 +307,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer); - TU_ASSERT(hcd_pipe_open(rhport, dev_addr, ep_desc)); + TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index ce74476bb..94796c9dd 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -313,7 +313,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet //--------------------------------------------------------------------+ // BULK/INT/ISO PIPE API //--------------------------------------------------------------------+ -bool hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) +bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) { // TODO not support ISO yet TU_ASSERT (ep_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); diff --git a/src/host/hcd.h b/src/host/hcd.h index dcc2bdf53..9b7b99321 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -128,15 +128,15 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev //--------------------------------------------------------------------+ // Endpoints API //--------------------------------------------------------------------+ -bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]); -bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen); +bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); +bool hcd_edpt_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); +bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen); //--------------------------------------------------------------------+ // PIPE API //--------------------------------------------------------------------+ // TODO control xfer should be used via usbh layer -bool hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes); // only queue, not transferring yet bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete); bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); // TODO remove diff --git a/src/host/hub.c b/src/host/hub.c index f755928e8..411e1ae95 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -168,7 +168,7 @@ bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_i TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); TU_ASSERT(TUSB_XFER_INTERRUPT == ep_desc->bmAttributes.xfer); - TU_ASSERT(hcd_pipe_open(rhport, dev_addr, ep_desc)); + TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); hub_data[dev_addr-1].itf_num = p_interface_desc->bInterfaceNumber; hub_data[dev_addr-1].ep_status = ep_desc->bEndpointAddress; diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index 5923be936..37de86c60 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -481,7 +481,7 @@ static void ed_list_remove(ohci_ed_t * p_head, ohci_ed_t * p_ed) p_ed->used = 0; // free ED } -pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_desc_endpoint_t const * p_endpoint_desc, uint8_t class_code) +pipe_handle_t hcd_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * p_endpoint_desc, uint8_t class_code) { pipe_handle_t const null_handle = { .dev_addr = 0, .xfer_type = 0, .index = 0 }; diff --git a/src/host/usbh.c b/src/host/usbh.c index 3ab3bd71e..ff4343fd2 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -236,7 +236,7 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) .bInterval = 0 }; - hcd_pipe_open(_usbh_devices[dev_addr].rhport, dev_addr, &ep0_desc); + hcd_edpt_open(_usbh_devices[dev_addr].rhport, dev_addr, &ep0_desc); return TUSB_ERROR_NONE; } diff --git a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c index 1b73e649f..1f8410461 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c +++ b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c @@ -86,7 +86,7 @@ void test_cdch_open_failed_to_open_notification_endpoint(void) { pipe_handle_t null_hdl = {0}; - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, null_hdl); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, null_hdl); //------------- CUT -------------// TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length)); @@ -98,8 +98,8 @@ void test_cdch_open_failed_to_open_data_endpoint_out(void) pipe_handle_t dummy_hld = { .dev_addr = 1 }; pipe_handle_t null_hdl = {0}; - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, dummy_hld); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, null_hdl); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, dummy_hld); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, null_hdl); //------------- CUT -------------// TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length)); @@ -111,9 +111,9 @@ void test_cdch_open_failed_to_open_data_endpoint_in(void) pipe_handle_t dummy_hld = { .dev_addr = 1 }; pipe_handle_t null_hdl = {0}; - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, dummy_hld); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, dummy_hld); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, null_hdl); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, dummy_hld); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, dummy_hld); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, null_hdl); //------------- CUT -------------// TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_OPEN_PIPE_FAILED, cdch_open(dev_addr, p_comm_interface, &length)); @@ -131,7 +131,7 @@ void test_cdch_open_length_check(void) sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); pipe_handle_t dummy_hld = { .dev_addr = 1 }; - hcd_pipe_open_IgnoreAndReturn(dummy_hld); + hcd_edpt_open_IgnoreAndReturn(dummy_hld); tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// @@ -143,7 +143,7 @@ void test_cdch_open_length_check(void) void test_cdch_open_interface_number_check(void) { pipe_handle_t dummy_hld = { .dev_addr = 1 }; - hcd_pipe_open_IgnoreAndReturn(dummy_hld); + hcd_edpt_open_IgnoreAndReturn(dummy_hld); tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// @@ -156,7 +156,7 @@ void test_cdch_open_interface_number_check(void) void test_cdch_open_protocol_check(void) { pipe_handle_t dummy_hld = { .dev_addr = 1 }; - hcd_pipe_open_IgnoreAndReturn(dummy_hld); + hcd_edpt_open_IgnoreAndReturn(dummy_hld); tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// @@ -169,7 +169,7 @@ void test_cdch_open_protocol_check(void) void test_cdch_open_acm_capacity_check(void) { pipe_handle_t dummy_hld = { .dev_addr = 1 }; - hcd_pipe_open_IgnoreAndReturn(dummy_hld); + hcd_edpt_open_IgnoreAndReturn(dummy_hld); tusbh_cdc_mounted_cb_Expect(dev_addr); //------------- CUT -------------// @@ -187,9 +187,9 @@ void test_cdch_close_device(void) pipe_handle_t pipe_out = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 0 }; pipe_handle_t pipe_int = { .dev_addr = 1, .xfer_type = TUSB_XFER_BULK, .index = 1 }; - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_int); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_int); tusbh_cdc_mounted_cb_Expect(dev_addr); TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, cdch_open(dev_addr, p_comm_interface, &length) ); diff --git a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_rndis_host.c b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_rndis_host.c index 86d6c2890..ca478b129 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_rndis_host.c +++ b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_rndis_host.c @@ -103,9 +103,9 @@ void setUp(void) osal_mutex_wait_StubWithCallback(stub_mutex_wait); osal_mutex_release_IgnoreAndReturn(TUSB_ERROR_NONE); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_in); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_notification, TUSB_CLASS_CDC, pipe_notification); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_out, TUSB_CLASS_CDC, pipe_out); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_endpoint_in, TUSB_CLASS_CDC, pipe_in); } void tearDown(void) diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_ehci_usbh_hcd_integration.c b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_usbh_hcd_integration.c index e17b2ba74..8fa5af5d5 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_ehci_usbh_hcd_integration.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_ehci_usbh_hcd_integration.c @@ -168,7 +168,7 @@ void test_bulk_pipe_close(void) }; uint8_t xfer_data[100]; - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); + pipe_handle_t pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), 100) ); TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), 50) ); diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c index 52cf40555..5b86750ef 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_open.c @@ -155,7 +155,7 @@ void test_open_bulk_qhd_data(void) tusb_desc_endpoint_t const * desc_endpoint = &desc_ept_bulk_in; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); + pipe_hdl = hcd_edpt_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_BULK, pipe_hdl.xfer_type); @@ -175,7 +175,7 @@ void test_open_bulk_hs_out_pingstate(void) pipe_handle_t pipe_hdl; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); + pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); p_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1 ].qhd[ pipe_hdl.index ]; TEST_ASSERT(p_qhd->qtd_overlay.pingstate_err); @@ -187,7 +187,7 @@ void test_open_bulk_hs_out_pingstate(void) void test_bulk_close(void) { tusb_desc_endpoint_t const * desc_endpoint = &desc_ept_bulk_in; - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); + pipe_handle_t pipe_hdl = hcd_edpt_open(dev_addr, desc_endpoint, TUSB_CLASS_MSC); ehci_qhd_t *p_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; //------------- Code Under TEST -------------// diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c index 634184ee2..47e8177a3 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_bulk_xfer.c @@ -102,7 +102,7 @@ void setUp(void) async_head = get_async_head( hostid ); //------------- pipe open -------------// - pipe_hdl_bulk = hcd_pipe_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); + pipe_hdl_bulk = hcd_edpt_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl_bulk.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_BULK, pipe_hdl_bulk.xfer_type); @@ -148,7 +148,7 @@ void test_bulk_xfer_hs_ping_out(void) { _usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH; - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); + pipe_handle_t pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl); //------------- Code Under Test -------------// diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c index f48b2c7f4..ff6dfef8f 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_open.c @@ -144,7 +144,7 @@ void check_int_endpoint_link(ehci_qhd_t *p_prev, ehci_qhd_t *p_qhd) void test_open_interrupt_qhd_hs(void) { //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl.xfer_type); @@ -162,7 +162,7 @@ void test_open_interrupt_hs_interval_1(void) int_edp_interval.bInterval = 1; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(0 , p_int_qhd->interval_ms); @@ -177,7 +177,7 @@ void test_open_interrupt_hs_interval_2(void) int_edp_interval.bInterval = 2; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(0 , p_int_qhd->interval_ms); @@ -191,7 +191,7 @@ void test_open_interrupt_hs_interval_3(void) int_edp_interval.bInterval = 3; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(0, p_int_qhd->interval_ms); @@ -205,7 +205,7 @@ void test_open_interrupt_hs_interval_4(void) int_edp_interval.bInterval = 4; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(1, p_int_qhd->interval_ms); @@ -219,7 +219,7 @@ void test_open_interrupt_hs_interval_5(void) int_edp_interval.bInterval = 5; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(2, p_int_qhd->interval_ms); @@ -233,7 +233,7 @@ void test_open_interrupt_hs_interval_6(void) int_edp_interval.bInterval = 6; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(4, p_int_qhd->interval_ms); @@ -247,7 +247,7 @@ void test_open_interrupt_hs_interval_7(void) int_edp_interval.bInterval = 7; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(8, p_int_qhd->interval_ms); @@ -261,7 +261,7 @@ void test_open_interrupt_hs_interval_8(void) int_edp_interval.bInterval = 16; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(255, p_int_qhd->interval_ms); @@ -275,7 +275,7 @@ void test_open_interrupt_qhd_non_hs(void) _usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl.xfer_type); @@ -297,7 +297,7 @@ void test_open_interrupt_qhd_non_hs_9(void) _usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; //------------- Code Under TEST -------------// - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = &ehci_data.device[ pipe_hdl.dev_addr-1].qhd[ pipe_hdl.index ]; TEST_ASSERT_EQUAL(int_edp_interval.bInterval, p_int_qhd->interval_ms); @@ -310,7 +310,7 @@ void test_open_interrupt_qhd_non_hs_9(void) //--------------------------------------------------------------------+ void test_interrupt_close(void) { - pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); p_int_qhd = qhd_get_from_pipe_handle(pipe_hdl); //------------- Code Under TEST -------------// @@ -328,7 +328,7 @@ void test_interrupt_256ms_close(void) tusb_desc_endpoint_t int_edp_interval = desc_ept_interrupt_out; int_edp_interval.bInterval = 9; - pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); + pipe_hdl = hcd_edpt_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID); p_int_qhd = qhd_get_from_pipe_handle(pipe_hdl); //------------- Code Under TEST -------------// diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c index b55ec1d9a..d6a5e396c 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_interrupt_xfer.c @@ -104,7 +104,7 @@ void setUp(void) period_head_arr = (ehci_qhd_t*) get_period_head( hostid, 1 ); //------------- pipe open -------------// - pipe_hdl_interrupt = hcd_pipe_open(dev_addr, &desc_ept_interrupt_in, TUSB_CLASS_HID); + pipe_hdl_interrupt = hcd_edpt_open(dev_addr, &desc_ept_interrupt_in, TUSB_CLASS_HID); TEST_ASSERT_EQUAL(dev_addr, pipe_hdl_interrupt.dev_addr); TEST_ASSERT_EQUAL(TUSB_XFER_INTERRUPT, pipe_hdl_interrupt.xfer_type); @@ -220,7 +220,7 @@ void test_interrupt_xfer_complete_isr_interval_2ms(void) tusb_desc_endpoint_t desc_endpoint_2ms = desc_ept_interrupt_in; desc_endpoint_2ms.bInterval = 5; - pipe_handle_t pipe_hdl_2ms = hcd_pipe_open(dev_addr, &desc_endpoint_2ms, TUSB_CLASS_HID); + pipe_handle_t pipe_hdl_2ms = hcd_edpt_open(dev_addr, &desc_endpoint_2ms, TUSB_CLASS_HID); ehci_qhd_t * p_qhd_2ms = &ehci_data.device[ dev_addr -1].qhd[ pipe_hdl_2ms.index ]; TEST_ASSERT_STATUS( hcd_pipe_xfer(pipe_hdl_2ms, xfer_data, sizeof(xfer_data), false) ); diff --git a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c index 51381381f..92dd2b474 100644 --- a/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c +++ b/tests/lpc18xx_43xx/test/host/ehci/test_pipe_isochronous_open.c @@ -94,6 +94,6 @@ tusb_desc_endpoint_t const desc_ept_iso_in = void test_open_isochronous(void) { - pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_iso_in, TUSB_CLASS_AUDIO); + pipe_handle_t pipe_hdl = hcd_edpt_open(dev_addr, &desc_ept_iso_in, TUSB_CLASS_AUDIO); TEST_ASSERT_EQUAL(0, pipe_hdl.dev_addr); } diff --git a/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c b/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c index 59ad54c88..963c344ab 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hid_host.c @@ -75,7 +75,7 @@ void tearDown(void) // uint16_t length=0; // // // TODO expect get HID report descriptor -// hcd_pipe_open_IgnoreAndReturn( pipe_hdl ); +// hcd_edpt_open_IgnoreAndReturn( pipe_hdl ); // // //------------- Code Under TEST -------------// // TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, p_kbd_interface_desc, &length) ); 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 de3581423..49bb26342 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_keyboard.c @@ -146,7 +146,7 @@ void test_keyboard_open_ok(void) usbh_control_xfer_subtask_ExpectAndReturn(dev_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RECIPIENT_INTERFACE), 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); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); tusbh_hid_keyboard_mounted_cb_Expect(dev_addr); //------------- Code Under TEST -------------// 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 541c2caef..bf71a7438 100644 --- a/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c +++ b/tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c @@ -117,7 +117,7 @@ void test_mouse_open_ok(void) usbh_control_xfer_subtask_ExpectAndReturn(dev_addr, bm_request_type(TUSB_DIR_HOST_TO_DEV, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RECIPIENT_INTERFACE), 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); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_mouse_endpoint_desc, TUSB_CLASS_HID, pipe_hdl); tusbh_hid_mouse_mounted_cb_Expect(dev_addr); //------------- Code Under TEST -------------// diff --git a/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c b/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c index b89a716c2..abdcbaf1f 100644 --- a/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c +++ b/tests/lpc18xx_43xx/test/host/msc/test_msc_host.c @@ -84,15 +84,15 @@ void tearDown(void) void test_open_pipe_in_failed(void) { - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_null); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_null); TEST_ASSERT(TUSB_ERROR_NONE != msch_open(dev_addr, p_msc_interface_desc, &length)); } void test_open_pipe_out_failed(void) { - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, (pipe_handle_t) {1} ); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_null); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, (pipe_handle_t) {1} ); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_null); TEST_ASSERT(TUSB_ERROR_NONE != msch_open(dev_addr, p_msc_interface_desc, &length)); } @@ -121,8 +121,8 @@ tusb_error_t stub_control_xfer(uint8_t dev_addr, uint8_t bmRequestType, uint8_t #if 0 // TODO TEST enable this void test_open_desc_length(void) { - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_in); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_out); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_in); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_out); usbh_control_xfer_subtask_IgnoreAndReturn(TUSB_ERROR_NONE); hcd_pipe_xfer_IgnoreAndReturn(TUSB_ERROR_NONE); @@ -137,8 +137,8 @@ void test_open_desc_length(void) void test_open_ok(void) { - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_in); - hcd_pipe_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_out); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_in, TUSB_CLASS_MSC, pipe_in); + hcd_edpt_open_ExpectAndReturn(dev_addr, p_edp_out, TUSB_CLASS_MSC, pipe_out); //------------- get max lun -------------// usbh_control_xfer_subtask_StubWithCallback(stub_control_xfer); -- cgit v1.3.1 From 6d86db3977aa60963d78d1bceaa7e3def60f1957 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 12 Dec 2018 11:51:31 +0700 Subject: rename edpt_dir/number/addr to tu_edpt_* --- docs/porting.md | 6 +++--- examples/host/cdc_msc_hid/src/tusb_config.h | 2 +- src/class/cdc/cdc_device.h | 2 +- src/class/cdc/cdc_host.c | 2 +- src/class/custom/custom_device.c | 2 +- src/class/custom/custom_device.h | 2 +- src/class/hid/hid_device.c | 2 +- src/class/hid/hid_device.h | 2 +- src/class/msc/msc_device.h | 2 +- src/class/msc/msc_host.c | 2 +- src/common/tusb_types.h | 6 +++--- src/device/usbd.c | 10 ++++----- src/host/ehci/ehci.c | 30 +++++++++++--------------- src/host/ohci/ohci.c | 10 ++++----- src/host/usbh.c | 10 ++++----- src/portable/microchip/samd21/dcd_samd21.c | 24 ++++++++++----------- src/portable/microchip/samd51/dcd_samd51.c | 24 ++++++++++----------- src/portable/nordic/nrf5x/dcd_nrf5x.c | 22 +++++++++---------- src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c | 6 +++--- src/portable/nxp/lpc17_40/dcd_lpc17_40.c | 8 +++---- src/portable/nxp/lpc18_43/dcd_lpc18_43.c | 24 ++++++++++----------- src/portable/nxp/lpc18_43/hcd_lpc18_43.c | 7 ++++++ tests/support/tusb_config.h | 2 +- 23 files changed, 104 insertions(+), 103 deletions(-) (limited to 'src/class/custom') diff --git a/docs/porting.md b/docs/porting.md index 5a464fa6b..040112d9c 100644 --- a/docs/porting.md +++ b/docs/porting.md @@ -113,10 +113,10 @@ As before with `dcd_event_bus_signal` the first argument is the USB peripheral n Endpoints are the core of the USB data transfer process. They come in a few forms such as control, isochronous, bulk, and interrupt. We won't cover the details here except with some caveats in open below. In general, data is transferred by setting up a buffer of a given length to be transferred on a given endpoint address and then waiting for an interrupt to signal that the transfer is finished. Further details below. -Endpoints within USB have an address which encodes both the number and direction of an endpoint. TinyUSB provides `edpt_number` and `edpt_dir` to unpack this data from the address. Here is a snippet that does it. +Endpoints within USB have an address which encodes both the number and direction of an endpoint. TinyUSB provides `tu_edpt_number` and `tu_edpt_dir` to unpack this data from the address. Here is a snippet that does it. - uint8_t epnum = edpt_number(ep_addr); - uint8_t dir = edpt_dir(ep_addr); + uint8_t epnum = tu_edpt_number(ep_addr); + uint8_t dir = tu_edpt_dir(ep_addr); ##### dcd_edpt_open diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index 07764fa90..cc06ae93d 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -84,7 +84,7 @@ #define CFG_TUH_CDC 1 #define CFG_TUH_HID_KEYBOARD 0 #define CFG_TUH_HID_MOUSE 0 -#define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) +#define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) #define CFG_TUH_MSC 0 #define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 0a17aa916..9dd837d7d 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -116,7 +116,7 @@ void cdcd_init (void); tusb_error_t cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * p_request); bool cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes); +tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); void cdcd_reset (uint8_t rhport); #endif diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 159a13990..d660cc39f 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -196,7 +196,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); - if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) + if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { p_cdc->ep_in = ep_desc->bEndpointAddress; }else diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index 194963c17..5abffacf6 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -94,7 +94,7 @@ bool cusd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque return false; } -tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes) +tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { return TUSB_ERROR_NONE; } diff --git a/src/class/custom/custom_device.h b/src/class/custom/custom_device.h index 0a8f05e7d..f223a4d3c 100644 --- a/src/class/custom/custom_device.h +++ b/src/class/custom/custom_device.h @@ -66,7 +66,7 @@ void cusd_init(void); tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request); bool cusd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); +tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void cusd_reset(uint8_t rhport); #endif diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 6e2ea27db..fa76ee015 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -510,7 +510,7 @@ bool hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const return true; } -tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes) +tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t 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 7aff7f34d..42c61a47b 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -380,7 +380,7 @@ void hidd_init(void); tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool hidd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); +tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void hidd_reset(uint8_t rhport); #endif diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index 4053679b8..55bfba83c 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -174,7 +174,7 @@ void mscd_init(void); tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool mscd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, xfer_result_t event, uint32_t xferred_bytes); +tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void mscd_reset(uint8_t rhport); #endif diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 2c9b2dec7..dd771440d 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -309,7 +309,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); - if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) + if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { p_msc->ep_in = ep_desc->bEndpointAddress; }else diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index d0a10acef..cbddd4156 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -376,18 +376,18 @@ static inline uint8_t bm_request_type(uint8_t direction, uint8_t type, uint8_t r //--------------------------------------------------------------------+ // Get direction from Endpoint address -static inline tusb_dir_t edpt_dir(uint8_t addr) +static inline tusb_dir_t tu_edpt_dir(uint8_t addr) { return (addr & TUSB_DIR_IN_MASK) ? TUSB_DIR_IN : TUSB_DIR_OUT; } // Get Endpoint number from address -static inline uint8_t edpt_number(uint8_t addr) +static inline uint8_t tu_edpt_number(uint8_t addr) { return addr & (~TUSB_DIR_IN_MASK); } -static inline uint8_t edpt_addr(uint8_t num, uint8_t dir) +static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir) { return num | (dir ? TUSB_DIR_IN_MASK : 0); } diff --git a/src/device/usbd.c b/src/device/usbd.c index ad40e3c9f..b63dcb131 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -246,14 +246,14 @@ static void usbd_task_body(void) // Invoke the class callback associated with the endpoint address uint8_t const ep_addr = event.xfer_complete.ep_addr; - if ( 0 == edpt_number(ep_addr) ) + if ( 0 == tu_edpt_number(ep_addr) ) { // control transfer DATA stage callback usbd_control_xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); } else { - uint8_t const drv_id = _usbd_dev.ep2drv[edpt_number(ep_addr)][edpt_dir(ep_addr)]; + uint8_t const drv_id = _usbd_dev.ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)]; TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT,); usbd_class_drivers[drv_id].xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); @@ -484,7 +484,7 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, { uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress; - ep2drv[edpt_number(ep_addr)][edpt_dir(ep_addr)] = driver_id; + ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = driver_id; } len += descriptor_len(p_desc); @@ -576,7 +576,7 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) case DCD_EVENT_XFER_COMPLETE: // skip zero-length control status complete event, should dcd notifies us. - if ( 0 == edpt_number(event->xfer_complete.ep_addr) && event->xfer_complete.len == 0) break; + if ( 0 == tu_edpt_number(event->xfer_complete.ep_addr) && event->xfer_complete.len == 0) break; osal_queue_send(_usbd_q, event, in_isr); TU_ASSERT(event->xfer_complete.result == XFER_RESULT_SUCCESS,); @@ -633,7 +633,7 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_ TU_ASSERT( dcd_edpt_open(rhport, ep_desc), TUSB_ERROR_DCD_OPEN_PIPE_FAILED ); - if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) + if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) { (*ep_in) = ep_desc->bEndpointAddress; }else diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index ef5510a6d..278765585 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -48,9 +48,6 @@ #include "../usbh_hcd.h" #include "ehci.h" -// TODO remove -#include "chip.h" - //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ @@ -61,13 +58,8 @@ // Periodic frame list must be 4K alignment CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4096) static ehci_data_t ehci_data; -//------------- Validation -------------// -// TODO static assert for memory placement on some known MCU such as lpc43xx - -uint32_t hcd_ehci_register_addr(uint8_t rhport) -{ - return (uint32_t) (rhport ? &LPC_USB1->USBCMD_H : &LPC_USB0->USBCMD_H ); -} +// EHCI portable +uint32_t hcd_ehci_register_addr(uint8_t rhport); //--------------------------------------------------------------------+ // PROTOTYPE @@ -279,7 +271,8 @@ static bool ehci_init(uint8_t hostid) return true; } -static void hcd_controller_stop(uint8_t rhport) +#if 0 +static void ehci_stop(uint8_t rhport) { (void) rhport; @@ -290,6 +283,7 @@ static void hcd_controller_stop(uint8_t rhport) // USB Spec: controller has to stop within 16 uframe = 2 frames while( regs->status_bm.hc_halted == 0 ) {} } +#endif //--------------------------------------------------------------------+ // CONTROL PIPE API @@ -298,8 +292,8 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); // FIXME control only for now if ( epnum == 0 ) @@ -505,7 +499,7 @@ static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd) { // end of request // call USBH callback - hcd_event_xfer_complete(p_qhd->dev_addr, edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes); + hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes); p_qhd->total_xferred_bytes = 0; } } @@ -592,7 +586,7 @@ static void qhd_xfer_error_isr(ehci_qhd_t * p_qhd) } // call USBH callback - hcd_event_xfer_complete(p_qhd->dev_addr, edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), error_event, p_qhd->total_xferred_bytes); + hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), error_event, p_qhd->total_xferred_bytes); p_qhd->total_xferred_bytes = 0; } @@ -718,7 +712,7 @@ static inline ehci_qhd_t* qhd_get_from_addr(uint8_t dev_addr, uint8_t ep_addr) for(uint32_t i=0; idev_addr = dev_addr; p_qhd->fl_inactive_next_xact = 0; - p_qhd->ep_number = edpt_number(ep_desc->bEndpointAddress); + p_qhd->ep_number = tu_edpt_number(ep_desc->bEndpointAddress); p_qhd->ep_speed = _usbh_devices[dev_addr].speed; p_qhd->data_toggle_control= (xfer_type == TUSB_XFER_CONTROL) ? 1 : 0; p_qhd->head_list_flag = (dev_addr == 0) ? 1 : 0; // addr0's endpoint is the static asyn list head @@ -826,7 +820,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c p_qhd->removing = 0; p_qhd->p_qtd_list_head = NULL; p_qhd->p_qtd_list_tail = NULL; - p_qhd->pid = edpt_dir(ep_desc->bEndpointAddress) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint + p_qhd->pid = tu_edpt_dir(ep_desc->bEndpointAddress) ? EHCI_PID_IN : EHCI_PID_OUT; // PID for TD under this endpoint //------------- active, but no TD list -------------// p_qhd->qtd_overlay.halted = 0; diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index c35eaa77b..bebb8a2ef 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -315,8 +315,8 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); // FIXME control only for now if ( epnum == 0 ) @@ -344,14 +344,14 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * //--------------------------------------------------------------------+ static inline ohci_ed_t * ed_from_addr(uint8_t dev_addr, uint8_t ep_addr) { - if ( edpt_number(ep_addr) == 0 ) return &ohci_data.control[dev_addr].ed; + if ( tu_edpt_number(ep_addr) == 0 ) return &ohci_data.control[dev_addr].ed; ohci_ed_t* ed_pool = ohci_data.ed_pool; for(uint32_t i=0; idev_addr, - edpt_addr(p_ed->ep_number, p_ed->pid == OHCI_PID_IN), + tu_edpt_addr(p_ed->ep_number, p_ed->pid == OHCI_PID_IN), event, xferred_bytes); } diff --git a/src/host/usbh.c b/src/host/usbh.c index 962dc04dc..369ddd2a5 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -205,12 +205,12 @@ bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8 // Data stage : first data toggle is always 1 if ( request->wLength ) { - hcd_edpt_xfer(rhport, dev_addr, edpt_addr(0, request->bmRequestType_bit.direction), data, request->wLength); + hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, request->bmRequestType_bit.direction), data, request->wLength); TU_VERIFY(osal_semaphore_wait(dev->control.sem_hdl, OSAL_TIMEOUT_NORMAL)); } // Status : data toggle is always 1 - hcd_edpt_xfer(rhport, dev_addr, edpt_addr(0, 1-request->bmRequestType_bit.direction), NULL, 0); + hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, 1-request->bmRequestType_bit.direction), NULL, 0); TU_VERIFY(osal_semaphore_wait(dev->control.sem_hdl, OSAL_TIMEOUT_NORMAL)); osal_mutex_unlock(dev->control.mutex_hdl); @@ -249,7 +249,7 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev { usbh_device_t* dev = &_usbh_devices[ dev_addr ]; - if (0 == edpt_number(ep_addr)) + if (0 == tu_edpt_number(ep_addr)) { dev->control.pipe_status = event; // usbh_devices[ pipe_hdl.dev_addr ].control.xferred_bytes = xferred_bytes; not yet neccessary @@ -257,7 +257,7 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t ev } else { - uint8_t drv_id = dev->ep2drv[edpt_number(ep_addr)][edpt_dir(ep_addr)]; + uint8_t drv_id = dev->ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)]; TU_ASSERT(drv_id < USBH_CLASS_DRIVER_COUNT, ); if (usbh_class_drivers[drv_id].isr) @@ -689,7 +689,7 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, { uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress; - ep2drv[ edpt_number(ep_addr) ][ edpt_dir(ep_addr) ] = driver_id; + ep2drv[ tu_edpt_number(ep_addr) ][ tu_edpt_dir(ep_addr) ] = driver_id; } len += descriptor_len(p_desc); diff --git a/src/portable/microchip/samd21/dcd_samd21.c b/src/portable/microchip/samd21/dcd_samd21.c index 57c4c4d9d..af0721ec3 100644 --- a/src/portable/microchip/samd21/dcd_samd21.c +++ b/src/portable/microchip/samd21/dcd_samd21.c @@ -132,8 +132,8 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) { (void) rhport; - uint8_t const epnum = edpt_number(desc_edpt->bEndpointAddress); - uint8_t const dir = edpt_dir(desc_edpt->bEndpointAddress); + uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress); + uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress); UsbDeviceDescBank* bank = &sram_registers[epnum][dir]; uint32_t size_value = 0; @@ -168,8 +168,8 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); UsbDeviceDescBank* bank = &sram_registers[epnum][dir]; UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; @@ -208,19 +208,19 @@ bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr) return false; } - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - return (edpt_dir(ep_addr) == TUSB_DIR_IN ) ? ep->EPINTFLAG.bit.STALL1 : ep->EPINTFLAG.bit.STALL0; + return (tu_edpt_dir(ep_addr) == TUSB_DIR_IN ) ? ep->EPINTFLAG.bit.STALL1 : ep->EPINTFLAG.bit.STALL0; } void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1; } else { ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0; @@ -236,10 +236,10 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { ep->EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1; } else { ep->EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ0; @@ -253,10 +253,10 @@ bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr) // USBD shouldn't check control endpoint state if ( 0 == ep_addr ) return false; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { return ep->EPINTFLAG.bit.TRCPT1 == 0 && ep->EPSTATUS.bit.BK1RDY == 1; } return ep->EPINTFLAG.bit.TRCPT0 == 0 && ep->EPSTATUS.bit.BK0RDY == 1; diff --git a/src/portable/microchip/samd51/dcd_samd51.c b/src/portable/microchip/samd51/dcd_samd51.c index ba53d5598..ce66b8245 100644 --- a/src/portable/microchip/samd51/dcd_samd51.c +++ b/src/portable/microchip/samd51/dcd_samd51.c @@ -137,8 +137,8 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) { (void) rhport; - uint8_t const epnum = edpt_number(desc_edpt->bEndpointAddress); - uint8_t const dir = edpt_dir(desc_edpt->bEndpointAddress); + uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress); + uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress); UsbDeviceDescBank* bank = &sram_registers[epnum][dir]; uint32_t size_value = 0; @@ -173,8 +173,8 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); UsbDeviceDescBank* bank = &sram_registers[epnum][dir]; UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; @@ -212,19 +212,19 @@ bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr) return false; } - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - return (edpt_dir(ep_addr) == TUSB_DIR_IN ) ? ep->EPINTFLAG.bit.STALL1 : ep->EPINTFLAG.bit.STALL0; + return (tu_edpt_dir(ep_addr) == TUSB_DIR_IN ) ? ep->EPINTFLAG.bit.STALL1 : ep->EPINTFLAG.bit.STALL0; } void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1; } else { ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0; @@ -240,10 +240,10 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { ep->EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ1; } else { ep->EPSTATUSCLR.reg = USB_DEVICE_EPSTATUSCLR_STALLRQ0; @@ -257,10 +257,10 @@ bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr) // USBD shouldn't check control endpoint state if ( 0 == ep_addr ) return false; - uint8_t const epnum = edpt_number(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum]; - if (edpt_dir(ep_addr) == TUSB_DIR_IN) { + if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { return ep->EPINTFLAG.bit.TRCPT1 == 0 && ep->EPSTATUS.bit.BK1RDY == 1; } return ep->EPINTFLAG.bit.TRCPT0 == 0 && ep->EPSTATUS.bit.BK0RDY == 1; diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c index c7a4f413f..ad5090eb0 100644 --- a/src/portable/nordic/nrf5x/dcd_nrf5x.c +++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c @@ -225,8 +225,8 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt) { (void) rhport; - uint8_t const epnum = edpt_number(desc_edpt->bEndpointAddress); - uint8_t const dir = edpt_dir(desc_edpt->bEndpointAddress); + uint8_t const epnum = tu_edpt_number(desc_edpt->bEndpointAddress); + uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress); _dcd.xfer[epnum][dir].mps = desc_edpt->wMaxPacketSize.size; @@ -248,8 +248,8 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t { (void) rhport; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); xfer_td_t* xfer = get_td(epnum, dir); @@ -295,15 +295,15 @@ bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr) // control is never got halted if ( ep_addr == 0 ) return false; - uint8_t const epnum = edpt_number(ep_addr); - return (edpt_dir(ep_addr) == TUSB_DIR_IN ) ? NRF_USBD->HALTED.EPIN[epnum] : NRF_USBD->HALTED.EPOUT[epnum]; + uint8_t const epnum = tu_edpt_number(ep_addr); + return (tu_edpt_dir(ep_addr) == TUSB_DIR_IN ) ? NRF_USBD->HALTED.EPIN[epnum] : NRF_USBD->HALTED.EPOUT[epnum]; } void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - if ( edpt_number(ep_addr) == 0 ) + if ( tu_edpt_number(ep_addr) == 0 ) { NRF_USBD->TASKS_EP0STALL = 1; }else @@ -318,7 +318,7 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr) { (void) rhport; - if ( edpt_number(ep_addr) ) + if ( tu_edpt_number(ep_addr) ) { NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_UnStall << USBD_EPSTALL_STALL_Pos) | ep_addr; __ISB(); __DSB(); @@ -330,10 +330,10 @@ bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr) (void) rhport; // USBD shouldn't check control endpoint state - if ( 0 == edpt_number(ep_addr) ) return false; + if ( 0 == tu_edpt_number(ep_addr) ) return false; - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); xfer_td_t* xfer = get_td(epnum, dir); diff --git a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c index aa7f5e7e6..c910bf1ec 100644 --- a/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c +++ b/src/portable/nxp/lpc11_13_15/dcd_lpc11_13_15.c @@ -189,7 +189,7 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) { (void) rhport; - if ( edpt_number(ep_addr) == 0 ) + if ( tu_edpt_number(ep_addr) == 0 ) { // TODO cannot able to STALL Control OUT endpoint !!!!! FIXME try some walk-around _dcd.ep[0][0].stall = _dcd.ep[1][0].stall = 1; @@ -209,11 +209,11 @@ bool dcd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) return _dcd.ep[ep_id][0].stall; } -void dcd_edpt_clear_stall(uint8_t rhport, uint8_t edpt_addr) +void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) { (void) rhport; - uint8_t const ep_id = ep_addr2id(edpt_addr); + uint8_t const ep_id = ep_addr2id(ep_addr); _dcd.ep[ep_id][0].stall = 0; _dcd.ep[ep_id][0].toggle_reset = 1; diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index 84eb0c121..82d3c3cac 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -285,7 +285,7 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) { (void) rhport; - uint8_t const epnum = edpt_number(p_endpoint_desc->bEndpointAddress); + uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress); uint8_t const ep_id = ep_addr2idx(p_endpoint_desc->bEndpointAddress); // Endpoint type is fixed to endpoint number @@ -336,7 +336,7 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) { (void) rhport; - if ( edpt_number(ep_addr) == 0 ) + if ( tu_edpt_number(ep_addr) == 0 ) { sie_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+0, 1, SIE_SET_ENDPOINT_STALLED_MASK | SIE_SET_ENDPOINT_CONDITION_STALLED_MASK); }else @@ -394,9 +394,9 @@ static bool control_xact(uint8_t rhport, uint8_t dir, uint8_t * buffer, uint8_t bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t total_bytes) { // Control transfer is not DMA support, and must be done in slave mode - if ( edpt_number(ep_addr) == 0 ) + if ( tu_edpt_number(ep_addr) == 0 ) { - return control_xact(rhport, edpt_dir(ep_addr), buffer, (uint8_t) total_bytes); + return control_xact(rhport, tu_edpt_dir(ep_addr), buffer, (uint8_t) total_bytes); } else { diff --git a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c index d524d9dea..70b34d848 100644 --- a/src/portable/nxp/lpc18_43/dcd_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/dcd_lpc18_43.c @@ -205,8 +205,8 @@ static void qtd_init(dcd_qtd_t* p_qtd, void * data_ptr, uint16_t total_bytes) //--------------------------------------------------------------------+ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) { - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); if ( epnum == 0) { @@ -220,16 +220,16 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr) { - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); return LPC_USB[rhport]->ENDPTCTRL[epnum] & (ENDPTCTRL_MASK_STALL << (dir ? 16 : 0)); } void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) { - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); // data toggle also need to be reset LPC_USB[rhport]->ENDPTCTRL[epnum] |= ENDPTCTRL_MASK_TOGGLE_RESET << ( dir ? 16 : 0 ); @@ -241,8 +241,8 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) // TODO not support ISO yet TU_VERIFY ( p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS); - uint8_t const epnum = edpt_number(p_endpoint_desc->bEndpointAddress); - uint8_t const dir = edpt_dir(p_endpoint_desc->bEndpointAddress); + uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress); + uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress); uint8_t const ep_idx = 2*epnum + dir; // USB0 has 5, USB1 has 3 non-control endpoints @@ -264,8 +264,8 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) bool dcd_edpt_busy(uint8_t rhport, uint8_t ep_addr) { - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); uint8_t const ep_idx = 2*epnum + dir; dcd_qtd_t * p_qtd = &dcd_data_ptr[rhport]->qtd[ep_idx]; @@ -276,8 +276,8 @@ bool dcd_edpt_busy(uint8_t rhport, uint8_t ep_addr) bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes) { - uint8_t const epnum = edpt_number(ep_addr); - uint8_t const dir = edpt_dir(ep_addr); + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const dir = tu_edpt_dir(ep_addr); uint8_t const ep_idx = 2*epnum + dir; if ( epnum == 0 ) diff --git a/src/portable/nxp/lpc18_43/hcd_lpc18_43.c b/src/portable/nxp/lpc18_43/hcd_lpc18_43.c index efdf8fea4..092030056 100644 --- a/src/portable/nxp/lpc18_43/hcd_lpc18_43.c +++ b/src/portable/nxp/lpc18_43/hcd_lpc18_43.c @@ -42,6 +42,8 @@ #include "chip.h" +// LPC18xx and 43xx use EHCI driver + void hcd_int_enable(uint8_t rhport) { NVIC_EnableIRQ(rhport ? USB1_IRQn : USB0_IRQn); @@ -52,4 +54,9 @@ void hcd_int_disable(uint8_t rhport) NVIC_DisableIRQ(rhport ? USB1_IRQn : USB0_IRQn); } +uint32_t hcd_ehci_register_addr(uint8_t rhport) +{ + return (uint32_t) (rhport ? &LPC_USB1->USBCMD_H : &LPC_USB0->USBCMD_H ); +} + #endif diff --git a/tests/support/tusb_config.h b/tests/support/tusb_config.h index 4ff3965e1..fe3d59ef1 100644 --- a/tests/support/tusb_config.h +++ b/tests/support/tusb_config.h @@ -55,7 +55,7 @@ #define CFG_TUSB_HOST_DEVICE_MAX 5 // TODO be a part of HUB config //------------- CLASS -------------// -#define CFG_TUH_HUB 0 +#define CFG_TUH_HUB 1 #define CFG_TUH_HID_KEYBOARD 1 #define CFG_TUH_HID_MOUSE 1 #define CFG_TUH_MSC 1 -- cgit v1.3.1 From 6c0b0917e15ca0acf7ce9bed0f3735a794abb807 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 12 Dec 2018 12:01:15 +0700 Subject: rename descriptor_* helper to tu_desc_* --- src/class/cdc/cdc_device.c | 18 +++++++++--------- src/class/cdc/cdc_host.c | 10 +++++----- src/class/custom/custom_device.c | 2 +- src/class/custom/custom_host.c | 4 ++-- src/class/msc/msc_device.c | 10 +++++----- src/class/msc/msc_host.c | 4 ++-- src/common/tusb_types.h | 13 +++++++------ src/device/usbd.c | 14 +++++++------- src/host/hub.c | 8 ++++---- src/host/usbh.c | 14 +++++++------- 10 files changed, 49 insertions(+), 48 deletions(-) (limited to 'src/class/custom') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index d477a0d23..a865ba3c5 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -229,13 +229,13 @@ void cdcd_reset(uint8_t rhport) } } -tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length) +tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length) { - if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != p_interface_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS; + if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != itf_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS; // Only support AT commands, no protocol and vendor specific commands. - if ( !(tu_within(CDC_COMM_PROTOCOL_NONE, p_interface_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || - p_interface_desc->bInterfaceProtocol == 0xff ) ) + if ( !(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) || + itf_desc->bInterfaceProtocol == 0xff ) ) { return TUSB_ERROR_CDC_UNSUPPORTED_PROTOCOL; } @@ -252,16 +252,16 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface } //------------- Control Interface -------------// - p_cdc->itf_num = p_interface_desc->bInterfaceNumber; + p_cdc->itf_num = itf_desc->bInterfaceNumber; - uint8_t const * p_desc = descriptor_next ( (uint8_t const *) p_interface_desc ); + uint8_t const * p_desc = tu_desc_next( itf_desc ); (*p_length) = sizeof(tusb_desc_interface_t); // Communication Functional Descriptors while( TUSB_DESC_CLASS_SPECIFIC == p_desc[DESC_OFFSET_TYPE] ) { (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE]) @@ -271,7 +271,7 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface p_cdc->ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress; (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } //------------- Data Interface (if any) -------------// @@ -280,7 +280,7 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface { // next to endpoint descritpor (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); // Open endpoint pair with usbd helper tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) p_desc; diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index d660cc39f..d6767d0a7 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -146,7 +146,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it uint8_t const * p_desc; cdch_data_t * p_cdc; - p_desc = descriptor_next ( (uint8_t const *) itf_desc ); + p_desc = tu_desc_next(itf_desc); p_cdc = &cdch_data[dev_addr-1]; p_cdc->itf_num = itf_desc->bInterfaceNumber; @@ -165,7 +165,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it } (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE]) @@ -177,7 +177,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it p_cdc->ep_notif = ep_desc->bEndpointAddress; (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } //------------- Data Interface (if any) -------------// @@ -185,7 +185,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) ) { (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); // data endpoints expected to be in pairs for(uint32_t i=0; i<2; i++) @@ -205,7 +205,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it } (*p_length) += p_desc[DESC_OFFSET_LEN]; - p_desc = descriptor_next( p_desc ); + p_desc = tu_desc_next( p_desc ); } } diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index 5abffacf6..bec6f42d1 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -76,7 +76,7 @@ tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, cusd_interface_t* p_itf = &_cusd_itf; // Open endpoint pair with usbd helper - tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_desc_itf ); + tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next( (uint8_t const*) p_desc_itf ); TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_itf->ep_out, &p_itf->ep_in) ); p_itf->itf_num = p_desc_itf->bInterfaceNumber; diff --git a/src/class/custom/custom_host.c b/src/class/custom/custom_host.c index e840a2829..894e641e8 100644 --- a/src/class/custom/custom_host.c +++ b/src/class/custom/custom_host.c @@ -111,7 +111,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ { // FIXME quick hack to test lpc1k custom class with 2 bulk endpoints uint8_t const *p_desc = (uint8_t const *) p_interface_desc; - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); //------------- Bulk Endpoints Descriptor -------------// for(uint32_t i=0; i<2; i++) @@ -124,7 +124,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ *p_pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC); TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED ); - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } (*p_length) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 83c9990d8..48f23688d 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -150,19 +150,19 @@ void mscd_reset(uint8_t rhport) tu_memclr(&_mscd_itf, sizeof(mscd_interface_t)); } -tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len) +tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_len) { // only support SCSI's BOT protocol - TU_VERIFY( ( MSC_SUBCLASS_SCSI == p_desc_itf->bInterfaceSubClass && - MSC_PROTOCOL_BOT == p_desc_itf->bInterfaceProtocol ), TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL ); + TU_VERIFY( ( MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass && + MSC_PROTOCOL_BOT == itf_desc->bInterfaceProtocol ), TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL ); mscd_interface_t * p_msc = &_mscd_itf; // Open endpoint pair with usbd helper - tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_desc_itf ); + tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next( itf_desc ); TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in) ); - p_msc->itf_num = p_desc_itf->bInterfaceNumber; + p_msc->itf_num = itf_desc->bInterfaceNumber; (*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); //------------- Queue Endpoint OUT for Command Block Wrapper -------------// diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index dd771440d..86669b279 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -300,7 +300,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it msch_interface_t* p_msc = &msch_data[dev_addr-1]; //------------- Open Data Pipe -------------// - tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) itf_desc ); + tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc); for(uint32_t i=0; i<2; i++) { @@ -317,7 +317,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it p_msc->ep_out = ep_desc->bEndpointAddress; } - ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) ep_desc ); + ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc); } p_msc->itf_numr = itf_desc->bInterfaceNumber; diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index cbddd4156..cf02952ab 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -395,19 +395,20 @@ static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir) //--------------------------------------------------------------------+ // Descriptor helper //--------------------------------------------------------------------+ -static inline uint8_t const * descriptor_next(uint8_t const p_desc[]) +static inline uint8_t const * tu_desc_next(void const* desc) { - return p_desc + p_desc[DESC_OFFSET_LEN]; + uint8_t const* desc8 = (uint8_t const*) desc; + return desc8 + desc8[DESC_OFFSET_LEN]; } -static inline uint8_t descriptor_type(uint8_t const p_desc[]) +static inline uint8_t tu_desc_type(void const* desc) { - return p_desc[DESC_OFFSET_TYPE]; + return ((uint8_t const*) desc)[DESC_OFFSET_TYPE]; } -static inline uint8_t descriptor_len(uint8_t const p_desc[]) +static inline uint8_t tu_desc_len(void const* desc) { - return p_desc[DESC_OFFSET_LEN]; + return ((uint8_t const*) desc)[DESC_OFFSET_LEN]; } // Length of the string descriptors in bytes with slen characters diff --git a/src/device/usbd.c b/src/device/usbd.c index b63dcb131..096437747 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -436,12 +436,12 @@ static bool process_set_config(uint8_t rhport) while( p_desc < desc_cfg + cfg_len ) { // Each interface always starts with Interface or Association descriptor - if ( TUSB_DESC_INTERFACE_ASSOCIATION == descriptor_type(p_desc) ) + if ( TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc) ) { - p_desc = descriptor_next(p_desc); // ignore Interface Association + p_desc = tu_desc_next(p_desc); // ignore Interface Association }else { - TU_ASSERT( TUSB_DESC_INTERFACE == descriptor_type(p_desc) ); + TU_ASSERT( TUSB_DESC_INTERFACE == tu_desc_type(p_desc) ); tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc; @@ -480,15 +480,15 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, while( len < desc_len ) { - if ( TUSB_DESC_ENDPOINT == descriptor_type(p_desc) ) + if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) ) { uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress; ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = driver_id; } - len += descriptor_len(p_desc); - p_desc = descriptor_next(p_desc); + len += tu_desc_len(p_desc); + p_desc = tu_desc_next(p_desc); } } @@ -641,7 +641,7 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_ (*ep_out) = ep_desc->bEndpointAddress; } - ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) ep_desc ); + ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc); } return TUSB_ERROR_NONE; diff --git a/src/host/hub.c b/src/host/hub.c index e2e91d73d..e9f9dc7de 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -156,21 +156,21 @@ void hub_init(void) // hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) ); } -bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length) { // not support multiple TT yet - if ( p_interface_desc->bInterfaceProtocol > 1 ) return false; + if ( itf_desc->bInterfaceProtocol > 1 ) return false; //------------- Open Interrupt Status Pipe -------------// tusb_desc_endpoint_t const *ep_desc; - ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_interface_desc ); + ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc); TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType); TU_ASSERT(TUSB_XFER_INTERRUPT == ep_desc->bmAttributes.xfer); TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc)); - hub_data[dev_addr-1].itf_num = p_interface_desc->bInterfaceNumber; + hub_data[dev_addr-1].itf_num = itf_desc->bInterfaceNumber; hub_data[dev_addr-1].ep_status = ep_desc->bEndpointAddress; (*p_length) = sizeof(tusb_desc_interface_t) + sizeof(tusb_desc_endpoint_t); diff --git a/src/host/usbh.c b/src/host/usbh.c index 369ddd2a5..bbe60362a 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -560,9 +560,9 @@ bool enum_task(hcd_event_t* event) while( p_desc < _usbh_ctrl_buf + ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength ) { // skip until we see interface descriptor - if ( TUSB_DESC_INTERFACE != descriptor_type(p_desc) ) + if ( TUSB_DESC_INTERFACE != tu_desc_type(p_desc) ) { - p_desc = descriptor_next(p_desc); // skip the descriptor, increase by the descriptor's length + p_desc = tu_desc_next(p_desc); // skip the descriptor, increase by the descriptor's length }else { tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc; @@ -577,7 +577,7 @@ bool enum_task(hcd_event_t* event) if( drv_id >= USBH_CLASS_DRIVER_COUNT ) { // skip unsupported class - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } else { @@ -589,7 +589,7 @@ bool enum_task(hcd_event_t* event) { // TODO Attach hub to Hub is not currently supported // skip this interface - p_desc = descriptor_next(p_desc); + p_desc = tu_desc_next(p_desc); } else { @@ -685,15 +685,15 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, while( len < desc_len ) { - if ( TUSB_DESC_ENDPOINT == descriptor_type(p_desc) ) + if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) ) { uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress; ep2drv[ tu_edpt_number(ep_addr) ][ tu_edpt_dir(ep_addr) ] = driver_id; } - len += descriptor_len(p_desc); - p_desc = descriptor_next(p_desc); + len += tu_desc_len(p_desc); + p_desc = tu_desc_next(p_desc); } } -- cgit v1.3.1 From c1c501e0c2f3ad2c910b11bb358396c2e57ec624 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 12 Dec 2018 13:12:06 +0700 Subject: change usbd xfer_cb return type to bool --- src/class/cdc/cdc_device.c | 8 ++++---- src/class/cdc/cdc_device.h | 2 +- src/class/custom/custom_device.c | 14 +++++++------- src/class/custom/custom_device.h | 4 ++-- src/class/hid/hid_device.c | 4 ++-- src/class/hid/hid_device.h | 2 +- src/class/msc/msc_device.c | 16 ++++++++-------- src/class/msc/msc_device.h | 2 +- src/device/usbd.c | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) (limited to 'src/class/custom') diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index fc124627d..7d9e196aa 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -357,7 +357,7 @@ bool cdcd_control_request(uint8_t rhport, tusb_control_request_t const * request return true; } -tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) +bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) { (void) result; @@ -382,13 +382,13 @@ tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, // invoke receive callback (if there is still data) if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf); - // prepare for next - TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE), TUSB_ERROR_DCD_EDPT_XFER ); + // prepare for incoming data + TU_ASSERT( dcd_edpt_xfer(rhport, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE) ); } // nothing to do with in and notif endpoint - return TUSB_ERROR_NONE; + return true; } #endif diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h index 03aa2485e..5ee649c4b 100644 --- a/src/class/cdc/cdc_device.h +++ b/src/class/cdc/cdc_device.h @@ -116,7 +116,7 @@ void cdcd_init (void); bool cdcd_open (uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); bool cdcd_control_request (uint8_t rhport, tusb_control_request_t const * p_request); bool cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); +bool cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); void cdcd_reset (uint8_t rhport); #endif diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c index bec6f42d1..129d405a4 100644 --- a/src/class/custom/custom_device.c +++ b/src/class/custom/custom_device.c @@ -71,22 +71,22 @@ void cusd_init(void) tu_varclr(&_cusd_itf); } -tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len) +bool cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len) { cusd_interface_t* p_itf = &_cusd_itf; // Open endpoint pair with usbd helper - tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next( (uint8_t const*) p_desc_itf ); - TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_itf->ep_out, &p_itf->ep_in) ); + tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next(p_desc_itf); + TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_itf->ep_out, &p_itf->ep_in) ); p_itf->itf_num = p_desc_itf->bInterfaceNumber; (*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t); // TODO Prepare for incoming data -// TU_ASSERT( dcd_edpt_xfer(rhport, p_itf->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)), TUSB_ERROR_DCD_EDPT_XFER ); +// TU_ASSERT( dcd_edpt_xfer(rhport, p_itf->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) ); - return TUSB_ERROR_NONE; + return true; } bool cusd_control_request(uint8_t rhport, tusb_control_request_t const * p_request) @@ -94,9 +94,9 @@ bool cusd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque return false; } -tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) +bool cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { - return TUSB_ERROR_NONE; + return true; } void cusd_reset(uint8_t rhport) diff --git a/src/class/custom/custom_device.h b/src/class/custom/custom_device.h index f223a4d3c..aae06d503 100644 --- a/src/class/custom/custom_device.h +++ b/src/class/custom/custom_device.h @@ -63,10 +63,10 @@ #ifdef _TINY_USB_SOURCE_FILE_ void cusd_init(void); -tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); +bool cusd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length); bool cusd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request); bool cusd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); +bool cusd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void cusd_reset(uint8_t rhport); #endif diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index cfb1a698d..bd49c157a 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -508,10 +508,10 @@ bool hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const return true; } -tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) +bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { // nothing to do - return TUSB_ERROR_NONE; + return true; } diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 2f0047d81..885f33443 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -380,7 +380,7 @@ void hidd_init(void); bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length); bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool hidd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); +bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void hidd_reset(uint8_t rhport); #endif diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c index 14a7e593a..d4d115bce 100644 --- a/src/class/msc/msc_device.c +++ b/src/class/msc/msc_device.c @@ -329,7 +329,7 @@ int32_t proc_builtin_scsi(msc_cbw_t const * p_cbw, uint8_t* buffer, uint32_t buf return ret; } -tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) +bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) { mscd_interface_t* p_msc = &_mscd_itf; msc_cbw_t const * p_cbw = &p_msc->cbw; @@ -340,10 +340,10 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, case MSC_STAGE_CMD: //------------- new CBW received -------------// // Complete IN while waiting for CMD is usually Status of previous SCSI op, ignore it - if(ep_addr != p_msc->ep_out) return TUSB_ERROR_NONE; + if(ep_addr != p_msc->ep_out) return true; TU_ASSERT( event == XFER_RESULT_SUCCESS && - xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE, TUSB_ERROR_INVALID_PARA ); + xferred_bytes == sizeof(msc_cbw_t) && p_cbw->signature == MSC_CBW_SIGNATURE ); p_csw->signature = MSC_CSW_SIGNATURE; p_csw->tag = p_cbw->tag; @@ -388,7 +388,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, else if ( !BIT_TEST_(p_cbw->dir, 7) ) { // OUT transfer - TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len), TUSB_ERROR_DCD_EDPT_XFER ); + TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) ); } else { @@ -409,8 +409,8 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, p_msc->total_len = (uint32_t) cb_result; p_csw->status = MSC_CSW_STATUS_PASSED; - TU_ASSERT( p_cbw->total_bytes >= p_msc->total_len, TUSB_ERROR_INVALID_PARA ); // cannot return more than host expect - TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len), TUSB_ERROR_DCD_EDPT_XFER ); + TU_ASSERT( p_cbw->total_bytes >= p_msc->total_len ); // cannot return more than host expect + TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len) ); }else { p_msc->total_len = 0; @@ -474,7 +474,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, // simulate an transfer complete with adjusted parameters --> this driver callback will fired again dcd_event_xfer_complete(rhport, p_msc->ep_out, xferred_bytes-nbytes, XFER_RESULT_SUCCESS, false); - return TUSB_ERROR_NONE; // skip the rest + return true; // skip the rest } else { @@ -549,7 +549,7 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, } } - return TUSB_ERROR_NONE; + return true; } /*------------------------------------------------------------------*/ diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h index 80e47d84b..c9e4139e9 100644 --- a/src/class/msc/msc_device.h +++ b/src/class/msc/msc_device.h @@ -174,7 +174,7 @@ void mscd_init(void); bool mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length); bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request); bool mscd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request); -tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); +bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void mscd_reset(uint8_t rhport); #endif diff --git a/src/device/usbd.c b/src/device/usbd.c index bf7fd950a..8c685d5b3 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -92,7 +92,7 @@ typedef struct { bool (* open ) (uint8_t rhport, tusb_desc_interface_t const * desc_intf, uint16_t* p_length); bool (* control_request ) (uint8_t rhport, tusb_control_request_t const * request); bool (* control_request_complete ) (uint8_t rhport, tusb_control_request_t const * request); - tusb_error_t (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t, uint32_t); + bool (* xfer_cb ) (uint8_t rhport, uint8_t ep_addr, xfer_result_t, uint32_t); void (* sof ) (uint8_t rhport); void (* reset ) (uint8_t); } usbd_class_driver_t; -- cgit v1.3.1