From 5b09774ae05d15cb18ff9920864535b8444a1c3c Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Dec 2018 21:46:34 +0700 Subject: clean up usbh, rename doxygen folder to docs --- docs/changelog.md | 5 ++ docs/coding_standard.md | 80 +++++++++++++++++++++++ docs/configuration.txt | 77 ++++++++++++++++++++++ docs/getting_started.md | 63 ++++++++++++++++++ docs/group_def.txt | 22 +++++++ docs/header.html | 58 +++++++++++++++++ docs/porting.md | 167 ++++++++++++++++++++++++++++++++++++++++++++++++ docs/started_demo.md | 48 ++++++++++++++ 8 files changed, 520 insertions(+) create mode 100644 docs/changelog.md create mode 100644 docs/coding_standard.md create mode 100644 docs/configuration.txt create mode 100644 docs/getting_started.md create mode 100644 docs/group_def.txt create mode 100644 docs/header.html create mode 100644 docs/porting.md create mode 100644 docs/started_demo.md (limited to 'docs') diff --git a/docs/changelog.md b/docs/changelog.md new file mode 100644 index 000000000..a98db8a17 --- /dev/null +++ b/docs/changelog.md @@ -0,0 +1,5 @@ +# Change Log # + +## 0.4 ## + +Initial release. \ No newline at end of file diff --git a/docs/coding_standard.md b/docs/coding_standard.md new file mode 100644 index 000000000..3eb3c0d7d --- /dev/null +++ b/docs/coding_standard.md @@ -0,0 +1,80 @@ +# Coding Standards # + +C is a dangerous language by itself, plus tinyusb make use of goodies features of C99, which saves a tons of code lines (also means save a tons of bugs). However, those features can be misused and pave the way for bugs sneaking into. Therefore, to minimize bugs, the author try to comply with published Coding Standards like: + +- [MISRA-C](http://www.misra-c.com/Activities/MISRAC/tabid/160/Default.aspx) +- [Power of 10](http://spinroot.com/p10/) +- [Jet Propulsion Laboratory (JPL) for C](http://lars-lab.jpl.nasa.gov) + +Where is possible, standards are followed but it is almost impossible to follow all of these without making some exceptions. I am pretty sure this code base violates more than what are described below, if you can find any, please report it to me or file an issue on github. + +## MISRA-C 2004 Exceptions ## + +MISRA-C is well respected & a bar for industrial coding standard. + +- **Rule 2.2: use only** + + It has long passed the day that C99 comment style // will cause any issues, especially compiler's C99 mode is required to build tinyusb. + +- **Rule 8.5: No definitions of objects or function in a header file** + + function definitions in header files are used to allow 'inlining' + +- **Rule 14.7: A function shall have a single point of exit at the end of the function** + + Unfortunately, following this rule will have a lot of nesting if-else, I prefer to exit as soon as possible with assert style and flatten if-else. + +- **Rule 18.4: Unions shall not be used** + + sorry MISRA, union is required to effectively mapped to MCU's registers + +- expect to have more & more exceptions. + +## Power of 10 ## + +is a small & easy to remember but yet powerful coding guideline. Most (if not all) of the rules here are included in JPL. Because it is very small, all the rules will be listed here, those with *italic* are compliant, **bold** are violated. + +1. *Restrict to simple control flow constructs* + + yes, I hate goto statement, therefore there is none of those here + +2. *Give all loops a fixed upper-bound* + + one of my favorite rule + +3. *Do not use dynamic memory allocation after initialization* + + the tinyusb uses the static memory for all of its data. + +4. **Limit functions to no more than 60 lines of text** + + 60 is a little bit too strict, I will update the relaxing number later + +5. *Use minimally two assertions per function on average* + + not sure the exact number, but I use a tons of those assert + +6. *Declare data objects at the smallest possible level of scope* + + one of the best & easiest rule to follow + +7. *Check the return value of non-void functions, and check the validity of function parameters* + + I did check all of the public application API's parameters. For internal API, calling function needs to trust their caller to reduce duplicated check. + +8. **Limit the use of the preprocessor to file inclusion and simple macros** + + Although I prefer inline function, however C macros are far powerful than that. I simply cannot hold myself to use, for example X-Macro technique to simplify code. + +9. *Limit the use of pointers. Use no more than two levels of dereferencing per expression* + + never intend to get in trouble with complex pointer dereferencing. + +10. *Compile with all warnings enabled, and use one or more source code analyzers* + + I try to use all the defensive options of gnu, let me know if I miss some. + >-Wextra -Wswitch-default -Wunsafe-loop-optimizations -Wcast-align -Wlogical-op -Wpacked-bitfield-compat -Wnested-externs -Wredundant-decls -Winline + +## JPL ## + +coming soon ... diff --git a/docs/configuration.txt b/docs/configuration.txt new file mode 100644 index 000000000..896c9da6c --- /dev/null +++ b/docs/configuration.txt @@ -0,0 +1,77 @@ +/** \addtogroup group_configuration + * @{ */ + +//--------------------------------------------------------------------+ +// COMMON CONFIGURATION +//--------------------------------------------------------------------+ + +/// \brief tell the stack which mode (host/device/otg) the usb controller0 will be operated on. Possible value is +/// from \ref group_mode. Note the hardware usb controller must support the selected mode. +#define CFG_TUSB_RHPORT0_MODE + +/** USB controller in MCU often has limited access to specific RAM section. The Stack will use this macro to place internal variables + into the USB RAM section as follows. if your mcu's usb controller has no such limit, define CFG_TUSB_MEM_SECTION as empty macro. + + @code + CFG_TUSB_MEM_SECTION uint8_t usb_xfer_buffer[10]; + @endcode + */ +#define CFG_TUSB_MEM_SECTION + +#define CFG_TUSB_MCU ///< Select one of the supported MCU, the value must be from \ref group_mcu +#define CFG_TUSB_OS ///< Select one of the supported RTOS, the value must be from \ref group_supported_os. +#define CFG_TUD_TASK_PRIO ///< If \ref CFG_TUSB_OS is configured to use a real RTOS (other than OPT_OS_NONE). This determines the priority of the usb stack task. + +//--------------------------------------------------------------------+ +// HOST CONFIGURATION +//--------------------------------------------------------------------+ +/** \defgroup CFG_TUSB_HOST Host Options + * @{ */ + +/** \brief Maximum number of device host stack can manage + * \n If hub class is not enabled, set this equal to number of controllers in host mode + * \n If hub class is enabled, make sure hub is also counted */ +#define CFG_TUSB_HOST_DEVICE_MAX + +/// \brief Buffer size used for getting device configuration descriptor. You may want to increase this from default (256) +/// to support lengthy composite device especially with Audio or Video class +#define CFG_TUSB_HOST_ENUM_BUFFER_SIZE + +/** \defgroup config_host_class Class Driver + * \brief For each Class Driver a value of 1 means enable, value of 0 mean disable + * @{ */ +#define CFG_TUH_HUB ///< Enable Hub Class +#define CFG_TUSB_HOST_HID_KEYBOARD ///< Enable HID Class for Keyboard +#define CFG_TUSB_HOST_HID_MOUSE ///< Enable HID Class for Mouse +#define CFG_TUSB_HOST_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) +#define CFG_TUSB_HOST_MSC ///< Enable Mass Storage Class (SCSI subclass only) +#define CFG_TUSB_HOST_CDC ///< Enable Virtual Serial (Communication Device Class) +/** @} */ + +/** @} */ // group Host + +//--------------------------------------------------------------------+ +// DEVICE CONFIGURATION +//--------------------------------------------------------------------+ +/** \defgroup CFG_TUSB_DEVICE Device Options + * @{ */ + +#define CFG_TUD_ENDOINT0_SIZE ///< Max packet size of Cotnrol Endpoint, default is 64 + +/// Application MUST define this variable and initialize its pointers's member to all required USB descriptors including +/// Device Descriptor, Configuration Descriptor, String Descriptors, HID Report Descriptors etc ... +tud_desc_init_t tusbd_descriptor_pointers; + +/** \defgroup config_device_class Class Driver + * \brief For each Class Driver a value of 1 means enable, value of 0 mean disable + * @{ */ +#define CFG_TUD_HID_KEYBOARD ///< Enable HID Class for Keyboard +#define CFG_TUD_HID_MOUSE ///< Enable HID Class for Mouse +#define CFG_TUD_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) +#define CFG_TUD_MSC ///< Enable Mass Storage Class (SCSI subclass only) +#define CFG_TUD_CDC ///< Enable Virtual Serial (Communication Device Class) +/** @} */ + +/** @} */ // group Device + +/** @} */ diff --git a/docs/getting_started.md b/docs/getting_started.md new file mode 100644 index 000000000..6d6091c03 --- /dev/null +++ b/docs/getting_started.md @@ -0,0 +1,63 @@ +# Getting Started # + + + +**Table of Contents** + +- [Download](#download) +- [Add tinyusb to your project](#add-tinyusb-to-your-project) + + + +## Download + +tinyusb uses github as online repository https://github.com/hathach/tinyusb since it is the best place for open source project. + +If you are using Linux, you already know how to what to do. But If Windows is your OS, I would suggest to install [git](http://git-scm.com/) and front-end gui such as [tortoisegit](http://code.google.com/p/tortoisegit) to begin with. + +After downloading/cloning, the code base is composed of + +Folder | Description +----- | ------------- +doxygen | Documentation +examples| Folder where test examples are kept with Makefile and Segger Embedded build support +hw/bsp | Source files of supported boards +hw/mcu | Low level mcu core & peripheral drivers (e.g CMSIS ) +lib | Source files from 3rd party such as freeRTOS, fatfs etc ... +src | All sources files for tinyusb stack itself. +tests | Unit tests for the stack +tools | Files used internally + +*examples* is the folder where all the application & project files are located. There are demos for both device and hosts. For each, there are different projects for each of supported RTOS. Click to have more information on how to [build](../examples/readme.md) and run [device](../examples/device/readme.md) demos. + +## Add tinyusb to your project + +It is relatively simple to incorporate tinyusb to your (existing) project + +1. Copy or `git submodule` this repo into your project in a subfolder. Let's say it is *your_project/tinyusb* +2. Add all the .c in the src folder to your project settings (uvproj, ewp, makefile) +3. Add *your_project/tinysb* to your include path. Also make sure your current include path also contains the configuration file tusb_config.h. Or you could simply put the tusb_config.h into the tinyusb folder as well. +4. Make sure all required macros are all defined properly in tusb_config.h (configure file in demo application is sufficient, but you need to add a few more such as CFG_TUSB_MCU, CFG_TUSB_OS, CFG_TUD_TASK_PRIO since they are passed by IDE/compiler to maintain a unique configure for all demo projects). +5. If you use the device stack, make sure you have created/modified usb descriptors for your own need. Ultimately you need to fill out required pointers in tusbd_descriptor_pointers for that stack to work. +6. Add tusb_init() call to your reset initialization code. +7. Implement all enabled classes's callbacks. +8. If you don't use any RTOSes at all, you need to continuously and/or periodically call tusb_task() function. Most of the callbacks and functionality are handled and invoke within the call of that task runner. + +~~~{.c} +int main(void) +{ + your_init_code(); + tusb_init(); // initialize tinyusb stack + + while(1) // the mainloop + { + your_application_code(); + + tusb_task(); // handle tinyusb event, task etc ... + } +} +~~~ + +[//]: # (\subpage md_boards_readme) +[//]: # (\subpage md_doxygen_started_demo) +[//]: # (\subpage md_tools_readme) diff --git a/docs/group_def.txt b/docs/group_def.txt new file mode 100644 index 000000000..0f5419810 --- /dev/null +++ b/docs/group_def.txt @@ -0,0 +1,22 @@ +// define all the modules group to have the desired ordering since doxygen order module group by +// the order of files it is feed + +/// \defgroup group_demo Demos + +/// \defgroup group_class Application - Class Driver API + +/// \defgroup group_application_api Application - Stack API +/// \brief Non-Class driver API + +/// \defgroup group_configuration Configuration tusb_config.h + +/// \defgroup group_usbd USB Device Core (USBD) + +/// \defgroup group_usbh USB Host Core (USBH) + +/// \defgroup group_osal OS Abstraction Layer (OSAL) + +/// \defgroup group_usb_definitions USB Definitions + +/// \defgroup Group_Common Common Files + diff --git a/docs/header.html b/docs/header.html new file mode 100644 index 000000000..e75be44de --- /dev/null +++ b/docs/header.html @@ -0,0 +1,58 @@ + + + + + + + +$projectname: $title +$title + + + +$treeview +$search +$mathjax + +$extrastylesheet + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + +
+
$projectname +  $projectnumber +
+
$projectbrief
+
+ Click here to lend your support to tinyusb donation and make a donation at pledgie.com + +
$projectbrief
+
$searchbox
+
+ + diff --git a/docs/porting.md b/docs/porting.md new file mode 100644 index 000000000..5a464fa6b --- /dev/null +++ b/docs/porting.md @@ -0,0 +1,167 @@ +# Porting + +TinyUSB is designed to be a universal USB protocol stack for low-cost 32 bit microcontrollers. It +handles most of the high level USB protocol and relies on the microcontroller's USB peripheral for +data transactions on different endpoints. Porting is the process of adding low-level support for +the rest of the common stack. Once the low-level is implemented, it is very easy to add USB support +for the microcontroller to other projects, especially those already using TinyUSB such as CircuitPython. + +Below are instructions on how to get the cdc_msc_hid device example running on a new microcontroller. Doing so includes adding the common code necessary for other uses while minimizing other extra code. Whenever you see a phrase or word in <> it should be replaced. + +## Register defs + +The first step to adding support is including the register definitions and startup code for the +microcontroller in TinyUSB. We write the TinyUSB implementation against these structs instead of higher level functions to keep the code small and to prevent function name collisions in linking of larger projects. For ARM microcontrollers this is the CMSIS definitions. They should be +placed in the `hw/mcu//` directory. + +Once this is done, create a directory in `hw/bsp/` for the specific board you are using to test the code. (Duplicating an existing board's directory is the best way to get started.) The board should be a readily available development board so that others can also test. + +## Build +Now that those directories are in place, we can start our iteration process to get the example building successfully. To build, run from the root of TinyUSB: + +`make -C examples/device/cdc_msc_hid BOARD=` + +Unless, you've read ahead, this will fail miserably. Now, lets get it to fail less by updating the files in the board directory. The code in the board's directory is responsible for setting up the microcontroller's clocks and pins so that USB works. TinyUSB itself only operates on the USB peripheral. The board directory also includes information what files are needed to build the example. + +One of the first things to change is the `-DCFG_TUSB_MCU` cflag in the `board.mk` file. This is used to tell TinyUSB what platform is being built. So, add an entry to `src/tusb_option.h` and update the CFLAG to match. + +Also, add an entry for the board in `hw/bsp/board.h`. The CFLAG is auto-added. + +Update `board.mk`'s VENDOR and CHIP_FAMILY values when creating the directory for the struct files. Duplicate one of the other sources from `src/portable` into `src/portable//` and delete all of the implementation internals. We'll cover what everything there does later. For now, get it compiling. + +## Implementation +At this point you should get an error due to an implementation issue and hopefully the build is setup for the new MCU. You will still need to modify the `board.mk` to include specific CFLAGS, the linker script, linker flags, source files, include directories. All file paths are relative to the top of the TinyUSB repo. + +### Board Support (BSP) +The board support code is only used for self-contained examples and testing. It is not used when TinyUSB is part of a larger project. Its responsible for getting the MCU started and the USB peripheral clocked. It also optionally provides LED definitions that are used to blink an LED to show that the code is running. + +It is located in `hw/bsp//board_.c`. + +#### board_init +`board_init` is responsible for starting the MCU, setting up the USB clock and USB pins. It is also responsible for initializing LED pins. + +One useful clock debugging technique is to set up a PWM output at a known value such as 500hz based on the USB clock so that you can verify it is correct with a logic probe or oscilloscope. + +Setup your USB in a crystal-less mode when available. That makes the code easier to port across boards. + +#### board_led_control +Feel free to skip this until you want to verify your demo code is running. To implement, set the pin corresponding to the led to output a value that lights the LED when `state` is true. + +### OS Abstraction Layer (OSAL) + +The OS Abstraction Layer is responsible for providing basic data structures for TinyUSB that may allow for concurrency when used with an RTOS. Without an RTOS it simply handles concurrency issues between the main code and interrupts. + +The code is almost entirely agnostic of MCU and lives in `src/osal`. + +#### tusb_hal_millis + +The OPT_OS_NONE option is the only option which requires an MCU specific function. It needs `tusb_hal_millis` to measure the passage of time. On ARM this is commonly done with SysTick. The function returns the elapsed number of milliseconds since startup. + +`tusb_hal_millis` is also provided in `hw/bsp//board_.c` because it may vary with MCU use. + +### Device API + +After the USB device is setup, the USB device code works by processing events on the main thread (by calling `tusb_task`). These events are queued by the USB interrupt handler. So, there are three parts to the device low-level API: device setup, endpoint setup and interrupt processing. + +All of the code for the low-level device API is in `src/portable///dcd_.c`. + +#### Device Setup + +##### dcd_init +Initializes the USB peripheral for device mode and enables it. + +#### dcd_int_enable / dcd_int_disable + +Enables or disables the USB device interrupt(s). May be used to prevent concurrency issues when mutating data structures shared between main code and the interrupt handler. + +##### dcd_set_address +Called when the device is given a new bus address. + +If your peripheral automatically changes address during enumeration (like the nrf52) you may leave this empty and also no queue an event for the corresponding SETUP packet. + +##### dcd_set_config +Called when the device received SET_CONFIG request, you can leave this empty if your peripheral does not require any specific action. + +#### Special events +You must let TinyUSB know when certain events occur so that it can continue its work. There are a few methods you can call to queue events for TinyUSB to process. + +##### dcd_event_bus_signal + +There are a number of events that your peripheral may communicate about the state of the bus. Here is an overview of what they are. Events in **BOLD** must be provided for TinyUSB to work. + +* **DCD_EVENT_RESET** - Triggered when the host resets the bus causing the peripheral to reset. Do any other internal reset you need from the interrupt handler such as resetting the control endpoint. +* DCD_EVENT_SOF - Signals the start of a new USB frame. + +Calls to this look like: + + dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true); + +The first `0` is the USB peripheral number. Statically saying 0 is common for single USB device MCUs. + +The `true` indicates the call is from an interrupt handler and will always be the case when porting in this way. + +##### dcd_setup_received +SETUP packets are a special type of transaction that can occur at any time on the control endpoint, numbered `0`. Since they are unique, most peripherals have special handling for them. Their data is always 8 bytes in length as well. + +Calls to this look like: + + dcd_event_setup_received(0, setup, true); + +As before with `dcd_event_bus_signal` the first argument is the USB peripheral number and the third is true to signal its being called from an interrup handler. The middle argument is byte array of length 8 with the contents of the SETUP packet. It can be stack allocated because it is copied into the queue. + +#### Endpoints + +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. + + uint8_t epnum = edpt_number(ep_addr); + uint8_t dir = edpt_dir(ep_addr); + +##### dcd_edpt_open + +Opening an endpoint is done for all non-control endpoints once the host picks a configuration that the device should use. At this point, the endpoint should be enabled in the peripheral and configured to match the endpoint descriptor. Pay special attention to the direction of the endpoint you can get from the helper methods above. It will likely change what registers you are setting. + +Also make sure to enable endpoint specific interrupts. + +##### dcd_edpt_xfer + +`dcd_edpt_xfer` is responsible for configuring the peripheral to send or receive data from the host. "xfer" is short for "transfer". **This is one of the core methods you must implement for TinyUSB to work (one other is the interrupt handler).** Data from the host is the OUT direction and data to the host is IN. In other words, direction is relative to the host. + +`dcd_edpt_xfer` is used for all endpoints including the control endpoint 0. Make sure to handle the zero-length packet STATUS packet on endpoint 0 correctly. It may be a special transaction to the peripheral. + +Besides that, all other transactions are relatively straight-forward. The endpoint address provides the endpoint number and direction which usually determines where to write the buffer info. The buffer and its length are usually written to a specific location in memory and the peripheral is told the data is valid. (Maybe by writing a 1 to a register or setting a counter register to 0 for OUT or length for IN.) + +TODO: can we promise the buffer is word aligned? + +One potential pitfall is that the buffer may be longer than the maximum endpoint size of one USB packet. Some peripherals can handle transmitting multiple USB packets for a provided buffer (like the SAMD21). Others (like the nRF52) may need each USB packet queued individually. To make this work you'll need to track some state for yourself and queue up an intermediate USB packet from the interrupt handler. + +Once the transaction is going, the interrupt handler will notify TinyUSB of transfer completion. + +TODO: who handles zero-length data packets? + +##### dcd_xfer_complete + +Once a transfer completes you must call dcd_xfer_complete from the USB interrupt handler to let TinyUSB know that a transaction has completed. Here is a sample call: + + dcd_event_xfer_complete(0, ep_addr, xfer->actual_len, XFER_RESULT_SUCCESS, true); + +The arguments are: +* the USB peripheral number +* the endpoint address +* the actual length of the transfer. (OUT transfers may be smaller than the buffer given in `dcd_edpt_xfer`) +* the result of the transfer. Failure isn't handled yet. +* `true` to note the call is from an interrupt handler. + +##### dcd_edpt_stall / dcd_edpt_stalled / dcd_edpt_clear_stall + +Stalling is one way an endpoint can indicate failure such as when an unsupported command is transmitted. The trio of `dcd_edpt_stall`, `dcd_edpt_stalled`, `dcd_edpt_clear_stall` help manage the stall state of all endpoints. + +## Woohoo! + +At this point you should have everything working! ;-) Of course, you may not write perfect code. Here are some tips and tricks for debugging. + +Use [WireShark](https://www.wireshark.org/) or [a Beagle](https://www.totalphase.com/protocols/usb/) to sniff the USB traffic. When things aren't working its likely very early in the USB enumeration process. Figuring out where can help clue in where the issue is. For example: +* If the host sends a SETUP packet and its not ACKed then your USB peripheral probably isn't started correctly. +* If the peripheral is started correctly but it still didn't work, then verify your usb clock is correct. (You did output a PWM based on it right? ;-) ) +* If the SETUP packet is ACKed but nothing is sent back then you interrupt handler isn't queueing the setup packet correctly. (Also, if you are using your own code instead of an example `tusb_task` may not be called.) If thats OK, the `dcd_xfer_complete` may not be setting up the next transaction correctly. diff --git a/docs/started_demo.md b/docs/started_demo.md new file mode 100644 index 000000000..7e82596f5 --- /dev/null +++ b/docs/started_demo.md @@ -0,0 +1,48 @@ +# Demos # + +For simplicity and user's convenience, there are only 2 basic application demos which are *Device* and *Host* respectively. Each application demo, however, has a few projects, each for its supported RTOS. For instance, in addition to the *src* folder, you will also find in the /demo/device + +- device\_os\_none for no RTOS +- device\_freertos for freeRTOS +- device\_cmsis_rtx for ARM CMSIS with RTX implemenation + +To be able to have the same application code running across RTOSes, the application make use of the "internal" **OSAL layer**. Thus this makes the application code a bit weird and over-complicated than it should be in some (many) cases. This is absolutely not necessary in product development. User can just use the native API function of supported RTOS or a state machine or blocking wait in case of none OS. For example, instead of the blinking task in application + +~~~{.c} +OSAL_TASK_FUNCTION( led_blinking_task , p_task_para) +{ + OSAL_TASK_LOOP_BEGIN + + static uint32_t led_on_mask = 0; + + osal_task_delay(led_blink_interval_ms); + + board_leds(led_on_mask, 1 - led_on_mask); + led_on_mask = 1 - led_on_mask; // toggle + + OSAL_TASK_LOOP_END +} +~~~ + +can be written in FreeRTOS's native API + +~~~{.c} +void led_blinking_task( void * p_task_para ) +{ + while(1) + { + static uint32_t led_on_mask = 0; + + // FreeRTOS API's vTaskDelay is used in place of osal_task_delay. Note it takes input parameter in tick + vTaskDelay( (led_blink_interval_ms * CFG_TUSB_TICKS_HZ) / 1000); + + board_leds(led_on_mask, 1 - led_on_mask); + led_on_mask = 1 - led_on_mask; // toggle + } +} +~~~ + + +[//]: # (\subpage md_demos_readme) +[//]: # (\subpage md_demos_device_readme) +[//]: # (\subpage md_demos_host_readme) \ No newline at end of file -- cgit v1.3.1 From 7d3ff7aff6aed13377a4cd12f1d8f2ad91720f80 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 6 Dec 2018 22:24:31 +0700 Subject: rename CFG_TUSB_HOST_CDC/MSC to CFG_TUH_CDC/MSC --- docs/configuration.txt | 4 ++-- examples/host/cdc_msc_hid/src/main.c | 4 ++-- examples/host/cdc_msc_hid/src/tusb_config.h | 4 ++-- examples/obsolete/host/src/cdc_serial_host_app.c | 2 +- examples/obsolete/host/src/cdc_serial_host_app.h | 2 +- examples/obsolete/host/src/main.c | 4 ++-- examples/obsolete/host/src/msc_cli.c | 2 +- examples/obsolete/host/src/msc_host_app.c | 2 +- examples/obsolete/host/src/msc_host_app.h | 2 +- examples/obsolete/host/src/rndis_host_app.c | 2 +- examples/obsolete/host/src/rndis_host_app.h | 2 +- examples/obsolete/host/src/tusb_config.h | 4 ++-- lib/fatfs/ccsbcs.c | 4 ++-- lib/fatfs/diskio.c | 4 ++-- lib/fatfs/ff.c | 4 ++-- src/class/cdc/cdc_host.c | 2 +- src/class/cdc/cdc_rndis_host.c | 2 +- src/class/msc/msc_host.c | 2 +- src/host/hcd.h | 2 +- src/tusb.h | 4 ++-- tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c | 2 +- tests/lpc18xx_43xx/test/host/host_helper.h | 4 ++-- tests/support/tusb_config.h | 6 +++--- 23 files changed, 35 insertions(+), 35 deletions(-) (limited to 'docs') diff --git a/docs/configuration.txt b/docs/configuration.txt index 896c9da6c..33eb4efbf 100644 --- a/docs/configuration.txt +++ b/docs/configuration.txt @@ -44,8 +44,8 @@ #define CFG_TUSB_HOST_HID_KEYBOARD ///< Enable HID Class for Keyboard #define CFG_TUSB_HOST_HID_MOUSE ///< Enable HID Class for Mouse #define CFG_TUSB_HOST_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) -#define CFG_TUSB_HOST_MSC ///< Enable Mass Storage Class (SCSI subclass only) -#define CFG_TUSB_HOST_CDC ///< Enable Virtual Serial (Communication Device Class) +#define CFG_TUH_MSC ///< Enable Mass Storage Class (SCSI subclass only) +#define CFG_TUH_CDC ///< Enable Virtual Serial (Communication Device Class) /** @} */ /** @} */ // group Host diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c index c888f7bf7..81e8a172c 100644 --- a/examples/host/cdc_msc_hid/src/main.c +++ b/examples/host/cdc_msc_hid/src/main.c @@ -66,7 +66,7 @@ int main(void) led_blinking_task(); -#if CFG_TUSB_HOST_CDC +#if CFG_TUH_CDC virtual_com_task(); #endif @@ -81,7 +81,7 @@ int main(void) //--------------------------------------------------------------------+ // USB CDC //--------------------------------------------------------------------+ -#if CFG_TUSB_HOST_CDC +#if CFG_TUH_CDC void tuh_cdc_mounted_cb(uint8_t dev_addr) { diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index 8d3e39c64..a77d9ba5e 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -84,11 +84,11 @@ //-------------------------------------------------------------------- #define CFG_TUH_HUB 1 +#define CFG_TUH_CDC 1 #define CFG_TUSB_HOST_HID_KEYBOARD 0 #define CFG_TUSB_HOST_HID_MOUSE 0 #define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) -#define CFG_TUSB_HOST_MSC 0 -#define CFG_TUSB_HOST_CDC 1 +#define CFG_TUH_MSC 0 #define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports diff --git a/examples/obsolete/host/src/cdc_serial_host_app.c b/examples/obsolete/host/src/cdc_serial_host_app.c index 85604dcdf..1be2e9d8b 100644 --- a/examples/obsolete/host/src/cdc_serial_host_app.c +++ b/examples/obsolete/host/src/cdc_serial_host_app.c @@ -39,7 +39,7 @@ #include "cdc_serial_host_app.h" #include "app_os_prio.h" -#if CFG_TUSB_HOST_CDC +#if CFG_TUH_CDC #define QUEUE_SERIAL_DEPTH 100 diff --git a/examples/obsolete/host/src/cdc_serial_host_app.h b/examples/obsolete/host/src/cdc_serial_host_app.h index eef00bb55..f95cbbdab 100644 --- a/examples/obsolete/host/src/cdc_serial_host_app.h +++ b/examples/obsolete/host/src/cdc_serial_host_app.h @@ -53,7 +53,7 @@ extern "C" { #endif -#if CFG_TUSB_HOST_CDC +#if CFG_TUH_CDC void cdc_serial_host_app_init(void); void cdc_serial_host_app_task(void* param); diff --git a/examples/obsolete/host/src/main.c b/examples/obsolete/host/src/main.c index 0f2905fc6..320e1c8f5 100644 --- a/examples/obsolete/host/src/main.c +++ b/examples/obsolete/host/src/main.c @@ -138,6 +138,6 @@ void print_greeting(void) if (CFG_TUH_HUB ) puts(" - Hub (1 level only)"); if (CFG_TUSB_HOST_HID_MOUSE ) puts(" - HID Mouse"); if (CFG_TUSB_HOST_HID_KEYBOARD ) puts(" - HID Keyboard"); - if (CFG_TUSB_HOST_MSC ) puts(" - Mass Storage"); - if (CFG_TUSB_HOST_CDC ) puts(" - Communication Device Class"); + if (CFG_TUH_MSC ) puts(" - Mass Storage"); + if (CFG_TUH_CDC ) puts(" - Communication Device Class"); } diff --git a/examples/obsolete/host/src/msc_cli.c b/examples/obsolete/host/src/msc_cli.c index 75dbb1c01..fa1f986a5 100644 --- a/examples/obsolete/host/src/msc_cli.c +++ b/examples/obsolete/host/src/msc_cli.c @@ -39,7 +39,7 @@ #include "msc_cli.h" #include "ctype.h" -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC #include "ff.h" #include "diskio.h" diff --git a/examples/obsolete/host/src/msc_host_app.c b/examples/obsolete/host/src/msc_host_app.c index 1cfe9ec60..89993cefe 100644 --- a/examples/obsolete/host/src/msc_host_app.c +++ b/examples/obsolete/host/src/msc_host_app.c @@ -42,7 +42,7 @@ #include "msc_host_app.h" #include "app_os_prio.h" -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC #include "msc_cli.h" #include "ff.h" diff --git a/examples/obsolete/host/src/msc_host_app.h b/examples/obsolete/host/src/msc_host_app.h index c6e508e6c..0e153fc1d 100644 --- a/examples/obsolete/host/src/msc_host_app.h +++ b/examples/obsolete/host/src/msc_host_app.h @@ -54,7 +54,7 @@ extern "C" { #endif -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC void msc_host_app_init(void); void msc_host_app_task(void* param); diff --git a/examples/obsolete/host/src/rndis_host_app.c b/examples/obsolete/host/src/rndis_host_app.c index 5bb60182c..374e13a2a 100644 --- a/examples/obsolete/host/src/rndis_host_app.c +++ b/examples/obsolete/host/src/rndis_host_app.c @@ -39,7 +39,7 @@ #include "rndis_host_app.h" #include "app_os_prio.h" -#if CFG_TUSB_HOST_CDC && CFG_TUSB_HOST_CDC_RNDIS +#if CFG_TUH_CDC && CFG_TUH_CDC_RNDIS //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF diff --git a/examples/obsolete/host/src/rndis_host_app.h b/examples/obsolete/host/src/rndis_host_app.h index 9fa19351e..2e8437651 100644 --- a/examples/obsolete/host/src/rndis_host_app.h +++ b/examples/obsolete/host/src/rndis_host_app.h @@ -53,7 +53,7 @@ extern "C" { #endif -#if CFG_TUSB_HOST_CDC && CFG_TUSB_HOST_CDC_RNDIS +#if CFG_TUH_CDC && CFG_TUH_CDC_RNDIS void rndis_host_app_init(void); void rndis_host_app_task(void* param); diff --git a/examples/obsolete/host/src/tusb_config.h b/examples/obsolete/host/src/tusb_config.h index 3d0d5f3db..e555c8f35 100644 --- a/examples/obsolete/host/src/tusb_config.h +++ b/examples/obsolete/host/src/tusb_config.h @@ -58,8 +58,8 @@ #define CFG_TUSB_HOST_HID_KEYBOARD 1 #define CFG_TUSB_HOST_HID_MOUSE 1 #define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) -#define CFG_TUSB_HOST_MSC 1 -#define CFG_TUSB_HOST_CDC 1 +#define CFG_TUH_MSC 1 +#define CFG_TUH_CDC 1 #define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports diff --git a/lib/fatfs/ccsbcs.c b/lib/fatfs/ccsbcs.c index 5cf0dd503..07d6f0983 100644 --- a/lib/fatfs/ccsbcs.c +++ b/lib/fatfs/ccsbcs.c @@ -27,7 +27,7 @@ #include "ff.h" -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC #if _CODE_PAGE == 437 #define _TBLDEF 1 @@ -540,4 +540,4 @@ WCHAR ff_wtoupper ( /* Upper converted character */ return tbl_lower[i] ? tbl_upper[i] : chr; } -#endif // CFG_TUSB_HOST_MSC +#endif // CFG_TUH_MSC diff --git a/lib/fatfs/diskio.c b/lib/fatfs/diskio.c index 54a228019..939015c00 100644 --- a/lib/fatfs/diskio.c +++ b/lib/fatfs/diskio.c @@ -38,7 +38,7 @@ #include "tusb.h" -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ @@ -204,4 +204,4 @@ DWORD get_fattime (void) return timestamp.value; } -#endif // CFG_TUSB_HOST_MSC +#endif // CFG_TUH_MSC diff --git a/lib/fatfs/ff.c b/lib/fatfs/ff.c index 897965332..79414af07 100644 --- a/lib/fatfs/ff.c +++ b/lib/fatfs/ff.c @@ -99,7 +99,7 @@ #include "ff.h" /* FatFs configurations and declarations */ #include "diskio.h" /* Declarations of low level disk I/O functions */ -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC /*-------------------------------------------------------------------------- Module Private Definitions @@ -4327,4 +4327,4 @@ int f_printf ( #endif /* !_FS_READONLY */ #endif /* _USE_STRFUNC */ -#endif // CFG_TUSB_HOST_MSC +#endif // CFG_TUH_MSC diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 27ef502e0..2cf288a93 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_TUSB_HOST_CDC) +#if (MODE_HOST_SUPPORTED && 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 89ea3b32f..df4a29938 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_TUSB_HOST_CDC && CFG_TUSB_HOST_CDC_RNDIS) +#if (MODE_HOST_SUPPORTED && CFG_TUH_CDC && CFG_TUH_CDC_RNDIS) #define _TINY_USB_SOURCE_FILE_ diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index baef7ff44..12bffdf2d 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_TUSB_HOST_MSC +#if MODE_HOST_SUPPORTED & CFG_TUH_MSC #define _TINY_USB_SOURCE_FILE_ diff --git a/src/host/hcd.h b/src/host/hcd.h index a6b1b7027..9637ca661 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -82,7 +82,7 @@ typedef struct // Max number of endpoints per device enum { HCD_MAX_ENDPOINT = CFG_TUH_HUB + CFG_TUSB_HOST_HID_KEYBOARD + CFG_TUSB_HOST_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC + - CFG_TUSB_HOST_MSC*2 + CFG_TUSB_HOST_CDC*3, + CFG_TUH_MSC*2 + CFG_TUH_CDC*3, HCD_MAX_XFER = HCD_MAX_ENDPOINT*2, }; diff --git a/src/tusb.h b/src/tusb.h index 4f8918ce5..e31513f87 100644 --- a/src/tusb.h +++ b/src/tusb.h @@ -59,11 +59,11 @@ #include "class/hid/hid_host.h" #endif - #if CFG_TUSB_HOST_MSC + #if CFG_TUH_MSC #include "class/msc/msc_host.h" #endif - #if CFG_TUSB_HOST_CDC + #if CFG_TUH_CDC #include "class/cdc/cdc_host.h" #endif 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 12dce0528..fe7d05516 100644 --- a/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c +++ b/tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c @@ -51,7 +51,7 @@ #include "descriptor_cdc.h" #include "cdc_host.h" -#if CFG_TUSB_HOST_CDC_RNDIS // TODO enable +#if CFG_TUH_CDC_RNDIS // TODO enable #include "cdc_rndis_host.h" #endif diff --git a/tests/lpc18xx_43xx/test/host/host_helper.h b/tests/lpc18xx_43xx/test/host/host_helper.h index c293ec748..b8095b9aa 100644 --- a/tests/lpc18xx_43xx/test/host/host_helper.h +++ b/tests/lpc18xx_43xx/test/host/host_helper.h @@ -42,7 +42,7 @@ static inline void helper_class_init_expect(void) { // class code number order -#if CFG_TUSB_HOST_CDC +#if CFG_TUH_CDC cdch_init_Expect(); #endif @@ -50,7 +50,7 @@ static inline void helper_class_init_expect(void) hidh_init_Expect(); #endif -#if CFG_TUSB_HOST_MSC +#if CFG_TUH_MSC msch_init_Expect(); #endif diff --git a/tests/support/tusb_config.h b/tests/support/tusb_config.h index 3e5721019..3aacdabdc 100644 --- a/tests/support/tusb_config.h +++ b/tests/support/tusb_config.h @@ -58,10 +58,10 @@ #define CFG_TUH_HUB 0 #define CFG_TUSB_HOST_HID_KEYBOARD 1 #define CFG_TUSB_HOST_HID_MOUSE 1 -#define CFG_TUSB_HOST_MSC 1 +#define CFG_TUH_MSC 1 #define CFG_TUSB_HOST_HID_GENERIC 0 -#define CFG_TUSB_HOST_CDC 1 -#define CFG_TUSB_HOST_CDC_RNDIS 0 +#define CFG_TUH_CDC 1 +#define CFG_TUH_CDC_RNDIS 0 // Test support #define TEST_CONTROLLER_HOST_START_INDEX \ -- cgit v1.3.1 From 366ab797769b77dbf353b101ba862b20084dbc02 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 7 Dec 2018 14:57:58 +0700 Subject: able to build host hid --- docs/configuration.txt | 4 +- .../host/cdc_msc_hid/ses/lpc43xx/lpc43xx.emProject | 3 +- examples/host/cdc_msc_hid/src/main.c | 39 ++++++++++++- examples/host/cdc_msc_hid/src/tusb_config.h | 7 +-- examples/obsolete/host/src/keyboard_host_app.c | 2 +- examples/obsolete/host/src/keyboard_host_app.h | 2 +- examples/obsolete/host/src/main.c | 4 +- examples/obsolete/host/src/mouse_host_app.c | 2 +- examples/obsolete/host/src/mouse_host_app.h | 2 +- examples/obsolete/host/src/tusb_config.h | 4 +- src/class/hid/hid_host.c | 64 +++++++++++----------- src/class/hid/hid_host.h | 8 +-- src/class/msc/msc_host.c | 4 +- src/host/ehci/ehci.c | 3 + src/host/hcd.h | 2 +- src/host/hub.c | 1 - src/tusb_option.h | 2 +- tests/support/tusb_config.h | 4 +- 18 files changed, 98 insertions(+), 59 deletions(-) (limited to 'docs') diff --git a/docs/configuration.txt b/docs/configuration.txt index 33eb4efbf..49061a4a0 100644 --- a/docs/configuration.txt +++ b/docs/configuration.txt @@ -41,8 +41,8 @@ * \brief For each Class Driver a value of 1 means enable, value of 0 mean disable * @{ */ #define CFG_TUH_HUB ///< Enable Hub Class -#define CFG_TUSB_HOST_HID_KEYBOARD ///< Enable HID Class for Keyboard -#define CFG_TUSB_HOST_HID_MOUSE ///< Enable HID Class for Mouse +#define CFG_TUH_HID_KEYBOARD ///< Enable HID Class for Keyboard +#define CFG_TUH_HID_MOUSE ///< Enable HID Class for Mouse #define CFG_TUSB_HOST_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) #define CFG_TUH_MSC ///< Enable Mass Storage Class (SCSI subclass only) #define CFG_TUH_CDC ///< Enable Virtual Serial (Communication Device Class) diff --git a/examples/host/cdc_msc_hid/ses/lpc43xx/lpc43xx.emProject b/examples/host/cdc_msc_hid/ses/lpc43xx/lpc43xx.emProject index 3b8924309..425f42a58 100644 --- a/examples/host/cdc_msc_hid/ses/lpc43xx/lpc43xx.emProject +++ b/examples/host/cdc_msc_hid/ses/lpc43xx/lpc43xx.emProject @@ -18,11 +18,12 @@ arm_target_debug_interface_type="ADIv5" arm_target_device_name="LPC4357_M4" arm_target_interface_type="SWD" - build_treat_warnings_as_errors="Yes" + build_treat_warnings_as_errors="No" c_preprocessor_definitions="CORE_M4;__LPC4300_FAMILY;__LPC435x_SUBFAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_EA4357;CFG_TUSB_MCU=OPT_MCU_LPC43XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss2")))" c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/src;$(lpcDir)//inc;$(lpcDir)//inc/config_43xx" debug_register_definition_file="LPC43xx_Registers.xml" debug_target_connection="J-Link" + gcc_enable_all_warnings="Yes" gcc_entry_point="Reset_Handler" link_use_linker_script_file="No" linker_memory_map_file="LPC4357 Cortex-M4_MemoryMap.xml" diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c index 81e8a172c..88d7cd4de 100644 --- a/examples/host/cdc_msc_hid/src/main.c +++ b/examples/host/cdc_msc_hid/src/main.c @@ -111,12 +111,49 @@ void virtual_com_task(void) //--------------------------------------------------------------------+ // USB HID //--------------------------------------------------------------------+ -#if CFG_TUD_HID +#if CFG_TUH_HID_KEYBOARD void usb_hid_task(void) { } +void tuh_hid_keyboard_mounted_cb(uint8_t dev_addr) +{ + // application set-up + printf("\na Keyboard device (address %d) is mounted\n", dev_addr); +} + +void tuh_hid_keyboard_unmounted_cb(uint8_t dev_addr) +{ + // application tear-down + printf("\na Keyboard device (address %d) is unmounted\n", dev_addr); +} + +// invoked ISR context +void tuh_hid_keyboard_isr(uint8_t dev_addr, xfer_result_t event) +{ + +} + +#endif + +#if CFG_TUH_HID_MOUSE +void tuh_hid_mouse_mounted_cb(uint8_t dev_addr) +{ + // application set-up + printf("\na Mouse device (address %d) is mounted\n", dev_addr); +} + +void tuh_hid_mouse_unmounted_cb(uint8_t dev_addr) +{ + // application tear-down + printf("\na Mouse device (address %d) is unmounted\n", dev_addr); +} + +// invoked ISR context +void tuh_hid_mouse_isr(uint8_t dev_addr, xfer_result_t event) +{ +} #endif //--------------------------------------------------------------------+ diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index 6c6540b66..b7a766796 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -39,9 +39,6 @@ #ifndef _TUSB_CONFIG_H_ #define _TUSB_CONFIG_H_ -#include "tusb_option.h" -#include "bsp/board.h" - #ifdef __cplusplus extern "C" { #endif @@ -85,8 +82,8 @@ #define CFG_TUH_HUB 1 // not tested #define CFG_TUH_CDC 1 -#define CFG_TUSB_HOST_HID_KEYBOARD 0 -#define CFG_TUSB_HOST_HID_MOUSE 0 +#define CFG_TUH_HID_KEYBOARD 1 +#define CFG_TUH_HID_MOUSE 1 #define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) #define CFG_TUH_MSC 1 diff --git a/examples/obsolete/host/src/keyboard_host_app.c b/examples/obsolete/host/src/keyboard_host_app.c index fd51548c3..77fa8e5d3 100644 --- a/examples/obsolete/host/src/keyboard_host_app.c +++ b/examples/obsolete/host/src/keyboard_host_app.c @@ -42,7 +42,7 @@ #include "keyboard_host_app.h" #include "app_os_prio.h" -#if CFG_TUSB_HOST_HID_KEYBOARD +#if CFG_TUH_HID_KEYBOARD //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF diff --git a/examples/obsolete/host/src/keyboard_host_app.h b/examples/obsolete/host/src/keyboard_host_app.h index ff20d75df..965cd45cc 100644 --- a/examples/obsolete/host/src/keyboard_host_app.h +++ b/examples/obsolete/host/src/keyboard_host_app.h @@ -59,7 +59,7 @@ extern "C" { #endif -#if CFG_TUSB_HOST_HID_KEYBOARD +#if CFG_TUH_HID_KEYBOARD void keyboard_host_app_init(void); void keyboard_host_app_task(void* param); diff --git a/examples/obsolete/host/src/main.c b/examples/obsolete/host/src/main.c index 320e1c8f5..5da98fb68 100644 --- a/examples/obsolete/host/src/main.c +++ b/examples/obsolete/host/src/main.c @@ -136,8 +136,8 @@ void print_greeting(void) puts("This HOST demo is configured to support:"); printf(" - RTOS = %s\n", rtos_name[CFG_TUSB_OS]); if (CFG_TUH_HUB ) puts(" - Hub (1 level only)"); - if (CFG_TUSB_HOST_HID_MOUSE ) puts(" - HID Mouse"); - if (CFG_TUSB_HOST_HID_KEYBOARD ) puts(" - HID Keyboard"); + if (CFG_TUH_HID_MOUSE ) puts(" - HID Mouse"); + if (CFG_TUH_HID_KEYBOARD ) puts(" - HID Keyboard"); if (CFG_TUH_MSC ) puts(" - Mass Storage"); if (CFG_TUH_CDC ) puts(" - Communication Device Class"); } diff --git a/examples/obsolete/host/src/mouse_host_app.c b/examples/obsolete/host/src/mouse_host_app.c index 819c2b290..79af898c7 100644 --- a/examples/obsolete/host/src/mouse_host_app.c +++ b/examples/obsolete/host/src/mouse_host_app.c @@ -42,7 +42,7 @@ #include "mouse_host_app.h" #include "app_os_prio.h" -#if CFG_TUSB_HOST_HID_MOUSE +#if CFG_TUH_HID_MOUSE //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF diff --git a/examples/obsolete/host/src/mouse_host_app.h b/examples/obsolete/host/src/mouse_host_app.h index c5e9977ae..823107a5e 100644 --- a/examples/obsolete/host/src/mouse_host_app.h +++ b/examples/obsolete/host/src/mouse_host_app.h @@ -62,7 +62,7 @@ extern "C" { #endif -#if CFG_TUSB_HOST_HID_MOUSE +#if CFG_TUH_HID_MOUSE void mouse_host_app_init(void); void mouse_host_app_task(void* param); diff --git a/examples/obsolete/host/src/tusb_config.h b/examples/obsolete/host/src/tusb_config.h index e555c8f35..7a7951f89 100644 --- a/examples/obsolete/host/src/tusb_config.h +++ b/examples/obsolete/host/src/tusb_config.h @@ -55,8 +55,8 @@ //------------- CLASS -------------// #define CFG_TUH_HUB 1 -#define CFG_TUSB_HOST_HID_KEYBOARD 1 -#define CFG_TUSB_HOST_HID_MOUSE 1 +#define CFG_TUH_HID_KEYBOARD 1 +#define CFG_TUH_HID_MOUSE 1 #define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported) #define CFG_TUH_MSC 1 #define CFG_TUH_CDC 1 diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c index 6aa0748df..14398aa67 100644 --- a/src/class/hid/hid_host.c +++ b/src/class/hid/hid_host.c @@ -54,15 +54,15 @@ //--------------------------------------------------------------------+ // HID Interface common functions //--------------------------------------------------------------------+ -static inline tusb_error_t 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) +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->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor p_hid->interface_number = interface_number; - TU_ASSERT (pipehandle_is_valid(p_hid->pipe_hdl), TUSB_ERROR_HCD_FAILED); + TU_ASSERT (pipehandle_is_valid(p_hid->pipe_hdl)); - return TUSB_ERROR_NONE; + return true; } static inline void hidh_interface_close(hidh_interface_info_t *p_hid) @@ -78,7 +78,7 @@ tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_int // TODO change to use is configured function TU_ASSERT (TUSB_DEVICE_STATE_CONFIGURED == tuh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY); TU_VERIFY (report, TUSB_ERROR_INVALID_PARA); - TU_ASSSERT (!hcd_pipe_is_busy(p_hid->pipe_hdl), TUSB_ERROR_INTERFACE_IS_BUSY); + TU_ASSERT (!hcd_pipe_is_busy(p_hid->pipe_hdl), TUSB_ERROR_INTERFACE_IS_BUSY); TU_ASSERT_ERR( hcd_pipe_xfer(p_hid->pipe_hdl, report, p_hid->report_size, true) ) ; @@ -88,8 +88,9 @@ tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_int //--------------------------------------------------------------------+ // KEYBOARD //--------------------------------------------------------------------+ -#if CFG_TUSB_HOST_HID_KEYBOARD +#if CFG_TUH_HID_KEYBOARD +#if 0 #define EXPAND_KEYCODE_TO_ASCII(keycode, ascii, shift_modified) \ [0][keycode] = ascii,\ [1][keycode] = shift_modified,\ @@ -99,8 +100,9 @@ uint8_t const hid_keycode_to_ascii_tbl[2][128] = { HID_KEYCODE_TABLE(EXPAND_KEYCODE_TO_ASCII) }; +#endif -STATIC_VAR hidh_interface_info_t keyboardh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1 +static hidh_interface_info_t keyboardh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1 //------------- KEYBOARD PUBLIC API (parameter validation required) -------------// bool tuh_hid_keyboard_is_mounted(uint8_t dev_addr) @@ -124,7 +126,7 @@ bool tuh_hid_keyboard_is_busy(uint8_t dev_addr) //--------------------------------------------------------------------+ // MOUSE //--------------------------------------------------------------------+ -#if CFG_TUSB_HOST_HID_MOUSE +#if CFG_TUH_HID_MOUSE STATIC_VAR hidh_interface_info_t mouseh_data[CFG_TUSB_HOST_DEVICE_MAX]; // does not have addr0, index = dev_address-1 @@ -163,11 +165,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 +#if CFG_TUH_HID_KEYBOARD tu_memclr(&keyboardh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX); #endif -#if CFG_TUSB_HOST_HID_MOUSE +#if CFG_TUH_HID_MOUSE tu_memclr(&mouseh_data, sizeof(hidh_interface_info_t)*CFG_TUSB_HOST_DEVICE_MAX); #endif @@ -180,9 +182,8 @@ void hidh_init(void) CFG_TUSB_MEM_SECTION uint8_t report_descriptor[256]; #endif -tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) +bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) { - tusb_error_t error; uint8_t const *p_desc = (uint8_t const *) p_interface_desc; //------------- HID descriptor -------------// @@ -195,16 +196,15 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ tusb_desc_endpoint_t const * p_endpoint_desc = (tusb_desc_endpoint_t const *) p_desc; TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint_desc->bDescriptorType, TUSB_ERROR_INVALID_PARA); - OSAL_SUBTASK_BEGIN - //------------- 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_REQ_CONTROL_SET_IDLE, 0, p_interface_desc->bInterfaceNumber, - 0, NULL ), - error - ); - (void) error; // skip if set idle is failed + tusb_control_request_t request = { + .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_INTERFACE, .type = TUSB_REQ_TYPE_CLASS, .direction = TUSB_DIR_OUT }, + .bRequest = HID_REQ_CONTROL_SET_IDLE, + .wValue = 0, // idle_rate = 0 + .wIndex = p_interface_desc->bInterfaceNumber, + .wLength = 0 + }; + TU_ASSERT( usbh_control_xfer( dev_addr, &request, NULL ) ); #if 0 //------------- Get Report Descriptor TODO HID parser -------------// @@ -222,40 +222,42 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ if ( HID_SUBCLASS_BOOT == p_interface_desc->bInterfaceSubClass ) { - #if CFG_TUSB_HOST_HID_KEYBOARD + #if CFG_TUH_HID_KEYBOARD if ( HID_PROTOCOL_KEYBOARD == p_interface_desc->bInterfaceProtocol) { - STASK_ASSERT_ERR ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboardh_data[dev_addr-1]) ); + TU_ASSERT( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboardh_data[dev_addr-1]) ); tuh_hid_keyboard_mounted_cb(dev_addr); } else #endif - #if CFG_TUSB_HOST_HID_MOUSE + #if CFG_TUH_HID_MOUSE if ( HID_PROTOCOL_MOUSE == p_interface_desc->bInterfaceProtocol) { - STASK_ASSERT_ERR ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouseh_data[dev_addr-1]) ); + TU_ASSERT ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouseh_data[dev_addr-1]) ); tuh_hid_mouse_mounted_cb(dev_addr); } else #endif { - STASK_RETURN(TUSB_ERROR_HIDH_NOT_SUPPORTED_PROTOCOL); // exit & restart task + // TUSB_ERROR_HIDH_NOT_SUPPORTED_PROTOCOL + return false; } }else { - STASK_RETURN(TUSB_ERROR_HIDH_NOT_SUPPORTED_SUBCLASS); // exit & restart task + // TUSB_ERROR_HIDH_NOT_SUPPORTED_SUBCLASS + return false; } *p_length = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t); - OSAL_SUBTASK_END + return true; } 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 -#if CFG_TUSB_HOST_HID_KEYBOARD +#if CFG_TUH_HID_KEYBOARD if ( pipehandle_is_equal(pipe_hdl, keyboardh_data[pipe_hdl.dev_addr-1].pipe_hdl) ) { tuh_hid_keyboard_isr(pipe_hdl.dev_addr, event); @@ -263,7 +265,7 @@ void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_byte } #endif -#if CFG_TUSB_HOST_HID_MOUSE +#if CFG_TUH_HID_MOUSE if ( pipehandle_is_equal(pipe_hdl, mouseh_data[pipe_hdl.dev_addr-1].pipe_hdl) ) { tuh_hid_mouse_isr(pipe_hdl.dev_addr, event); @@ -278,7 +280,7 @@ void hidh_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_byte void hidh_close(uint8_t dev_addr) { -#if CFG_TUSB_HOST_HID_KEYBOARD +#if CFG_TUH_HID_KEYBOARD if ( pipehandle_is_valid( keyboardh_data[dev_addr-1].pipe_hdl ) ) { hidh_interface_close(&keyboardh_data[dev_addr-1]); @@ -286,7 +288,7 @@ void hidh_close(uint8_t dev_addr) } #endif -#if CFG_TUSB_HOST_HID_MOUSE +#if CFG_TUH_HID_MOUSE if( pipehandle_is_valid( mouseh_data[dev_addr-1].pipe_hdl ) ) { hidh_interface_close(&mouseh_data[dev_addr-1]); diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h index cb0230e8a..7336f5ada 100644 --- a/src/class/hid/hid_host.h +++ b/src/class/hid/hid_host.h @@ -215,10 +215,10 @@ typedef struct { uint8_t interface_number; }hidh_interface_info_t; -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, xfer_result_t event, uint32_t xferred_bytes); -void hidh_close(uint8_t dev_addr); +void hidh_init(void); +bool 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, xfer_result_t event, uint32_t xferred_bytes); +void hidh_close(uint8_t dev_addr); #endif diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index bb4d117e6..0c52011df 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -295,8 +295,6 @@ void msch_init(void) bool msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length) { - tusb_error_t error; - if (! ( MSC_SUBCLASS_SCSI == p_interface_desc->bInterfaceSubClass && MSC_PROTOCOL_BOT == p_interface_desc->bInterfaceProtocol ) ) { @@ -393,6 +391,8 @@ bool msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac msch_data[dev_addr-1].is_initialized = true; tuh_msc_mounted_cb(dev_addr); + + return true; } void msch_isr(pipe_handle_t pipe_hdl, xfer_result_t event, uint32_t xferred_bytes) diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index c9947a19c..84839b697 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -48,6 +48,9 @@ #include "../usbh_hcd.h" #include "ehci.h" +// TODO remove +#include "chip.h" + //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ diff --git a/src/host/hcd.h b/src/host/hcd.h index 3e3b966d0..104c78a36 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -82,7 +82,7 @@ typedef struct #if MODE_HOST_SUPPORTED // Max number of endpoints per device enum { - HCD_MAX_ENDPOINT = CFG_TUH_HUB + CFG_TUSB_HOST_HID_KEYBOARD + CFG_TUSB_HOST_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC + + HCD_MAX_ENDPOINT = CFG_TUH_HUB + CFG_TUH_HID_KEYBOARD + CFG_TUH_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC + CFG_TUH_MSC*2 + CFG_TUH_CDC*3, HCD_MAX_XFER = HCD_MAX_ENDPOINT*2, diff --git a/src/host/hub.c b/src/host/hub.c index 82ad2ba17..28814ebd7 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -105,7 +105,6 @@ bool hub_port_clear_feature_subtask(uint8_t hub_addr, uint8_t hub_port, uint8_t bool hub_port_reset_subtask(uint8_t hub_addr, uint8_t hub_port) { enum { RESET_DELAY = 200 }; // USB specs say only 50ms but many devices require much longer - tusb_error_t error; //------------- Set Port Reset -------------// tusb_control_request_t request = { diff --git a/src/tusb_option.h b/src/tusb_option.h index 07b39b5be..ad5025235 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -218,7 +218,7 @@ #endif //------------- HID CLASS -------------// - #define HOST_CLASS_HID ( CFG_TUSB_HOST_HID_KEYBOARD + CFG_TUSB_HOST_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC ) + #define HOST_CLASS_HID ( CFG_TUH_HID_KEYBOARD + CFG_TUH_HID_MOUSE + CFG_TUSB_HOST_HID_GENERIC ) // #if HOST_CLASS_HID // #define HOST_HCD_XFER_INTERRUPT // #endif diff --git a/tests/support/tusb_config.h b/tests/support/tusb_config.h index 3aacdabdc..4ff3965e1 100644 --- a/tests/support/tusb_config.h +++ b/tests/support/tusb_config.h @@ -56,8 +56,8 @@ //------------- CLASS -------------// #define CFG_TUH_HUB 0 -#define CFG_TUSB_HOST_HID_KEYBOARD 1 -#define CFG_TUSB_HOST_HID_MOUSE 1 +#define CFG_TUH_HID_KEYBOARD 1 +#define CFG_TUH_HID_MOUSE 1 #define CFG_TUH_MSC 1 #define CFG_TUSB_HOST_HID_GENERIC 0 #define CFG_TUH_CDC 1 -- 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 'docs') 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