|
2 | 2 |
|
3 | 3 | [](https://github.com/adafruit/Adafruit_TinyUSB_Arduino/actions) [](https://opensource.org/licenses/MIT)
|
4 | 4 |
|
5 |
| -This library works with platform that includes [TinyUSB stack](https://github.com/hathach/tinyusb), typically you will see **Adafruit_TinyUSB_Core** inside core folder. Supported platform are: |
| 5 | +This library is a Arduino-friendly version of [TinyUSB](https://github.com/hathach/tinyusb) stack. It is designed with structure and APIs that are easily integrated to existing or new Arduino Core. Supported platform including: |
6 | 6 |
|
7 | 7 | - [Adafruit_nRF52_Arduino](https://github.com/adafruit/Adafruit_nRF52_Arduino)
|
8 | 8 | - [Adafruit ArduinoCore-samd](https://github.com/adafruit/ArduinoCore-samd) **TinyUSB** must be selected in menu `Tools->USB Stack`
|
9 | 9 |
|
10 |
| -In addition to CDC that provided by the platform core, this library provide platform-independent for |
| 10 | +Current class drivers supported are |
11 | 11 |
|
| 12 | +- Communication (CDC): which is used to implement `Serial` monitor |
12 | 13 | - Human Interface Device (HID): Generic (In & Out), Keyboard, Mouse, Gamepad etc ...
|
13 | 14 | - Mass Storage Class (MSC): with multiple LUNs
|
14 | 15 | - Musical Instrument Digital Interface (MIDI)
|
15 | 16 | - WebUSB with vendor specific class
|
16 | 17 |
|
| 18 | +For supported ArduinoCore, to use this library, you only need to have `<Adafruit_TinyUSB.h>` in your sketch. If your ArduinoCore does not support TinyUSB library yet, it is rather simple to port. |
| 19 | + |
| 20 | +## Class Driver API |
| 21 | + |
17 | 22 | More document to write ...
|
| 23 | + |
| 24 | +## Porting Guide |
| 25 | + |
| 26 | +It is rather easy if you want to integrate TinyUSB lib to your ArduinoCore. |
| 27 | + |
| 28 | +### ArduinoCore Changes |
| 29 | + |
| 30 | +1. Add this repo as submodule (or have local copy) at your ArduioCore/libraries/Adafruit_TinyUSB_Arduino (much like SPI). |
| 31 | +2. Since Serial as CDC is considered as part of the core, we need to have `#include "Adafruit_USBD_CDC.h"` within your `Arduino.h`. For this to work, your `platform.txt` include path need to have `"-I{runtime.platform.path}/libraries/Adafruit_TinyUSB_Arduino/src/arduino"`. |
| 32 | +3. In your `main.cpp` before setup() invoke the `TinyUSB_Device_Init(rhport)`. This will initialize usb device hardware and tinyusb stack and also include Serial as an instance of CDC class. |
| 33 | +4. `TinyUSB_Device_Task()` must be called whenever there is new USB event. Depending on your core and MCU with or without RTOS. There are many ways to run the task. For example: |
| 34 | + - Use USB IRQn to set flag then invoke function later on after exiting IRQ. |
| 35 | + - Just invoke function after the loop(), within yield(), and delay() |
| 36 | +5. `TinyUSB_Device_FlushCDC()` should also be called often to send out Serial data as well. |
| 37 | +6. Note: For low power platform that make use of WFI()/WFE(), extra care is required before mcu go into low power mode. Check out my PR to circuipython for reference https://github.com/adafruit/circuitpython/pull/2956 |
| 38 | + |
| 39 | +### Library Changes |
| 40 | + |
| 41 | +In addition to core changes, library need to be ported to your platform. Don't worry, tinyusb stack has already done most of heavy-lifting. You only need to write a few APIs |
| 42 | + |
| 43 | +1. `TinyUSB_Port_InitDeviceController()` hardware specific (clock, phy) to enable usb hardware. This API is called as part of TinyUSB_Device_Init() invocation. |
| 44 | +2. `TinyUSB_Port_EnterDFU()` which is called when device need to enter DFU mode, usually by touch1200 feature |
| 45 | +3. `TinyUSB_Port_GetSerialNumber()` which is called to get unique MCU Serial ID to used as Serial string descriptor. |
0 commit comments