Git Product home page Git Product logo

adafruit_tinyusb_arduino's Introduction

Adafruit TinyUSB Library for Arduino

Build Status License

This library is a Arduino-friendly version of TinyUSB stack. It is designed with structure and APIs that are easily integrated to an Arduino Core.

Features

Currently only support device mode only, supported class drivers are:

  • Communication (CDC): which is used to implement Serial monitor
  • Human Interface Device (HID): Generic (In & Out), Keyboard, Mouse, Gamepad etc ...
  • Mass Storage Class (MSC): with multiple LUNs
  • Musical Instrument Digital Interface (MIDI)
  • WebUSB with vendor specific class

Supported Cores

There are 2 type of supported cores: with and without built-in support for TinyUSB. Built-in support provide seamless integration but requires extra code added to core's source code. Unfortunately it is not always easy or possible to make those modification.

Cores with built-in support

Following core has TinyUSB as either the primary usb stack or selectable via menu Tools->USB Stack. You only need to include <Adafruit_TinyUSB.h> in your sketch to use.

Cores without built-in support

Following is cores without built-in support

  • mbed_rp2040

It is still possible to use TinyUSB but with some limits such as:

  • TinyUSB_Device_Init() need to be manually called in setup()
  • TinyUSB_Device_Task() and/or TinyUSB_Device_FlushCDC() may (or not) need to be manually called in loop()
  • Use SerialTinyUSB name instead of Serial for serial monitor
  • And there could be more other issues, using on these cores should be considered as experimental

Class Driver API

More document to write ...

Porting Guide

To integrate TinyUSB library to a Arduino core, you will need to make changes to the core for built-in support and library for porting the mcu/platform.

Arduino Core Changes

If possible, making changes to core will allow it to have built-in which make it almost transparent to user sketch

  1. Add this repo as submodule (or have local copy) at your ArduioCore/libraries/Adafruit_TinyUSB_Arduino (much like SPI).
  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".
  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.
  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:
  • Use USB IRQn to set flag then invoke function later on after exiting IRQ.
  • Just invoke function after the loop(), within yield(), and delay()
  1. TinyUSB_Device_FlushCDC() should also be called often to send out Serial data as well.
  2. 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 adafruit/circuitpython#2956

Library Changes

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

  1. TinyUSB_Port_InitDevice() hardware specific (clock, phy) to enable usb hardware then call tud_init(). This API is called as part of TinyUSB_Device_Init() invocation.
  2. TinyUSB_Port_EnterDFU() which is called when device need to enter DFU mode, usually by touch1200 feature
  3. TinyUSB_Port_GetSerialNumber() which is called to get unique MCU Serial ID to used as Serial string descriptor.

adafruit_tinyusb_arduino's People

Contributors

hathach avatar evaherrada avatar ladyada avatar westfw avatar kaysievers avatar nekuneko avatar siddacious avatar earlephilhower avatar henrygab avatar lyusupov avatar bjc avatar hoffmannjan avatar mzero avatar timonsku avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.