-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add support for TinyUSB Arduino Library #5333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hi @hathach :) is there any way that we can have a talk about this? Maybe there is a better way to do it :) BTW Arduino does not use TinyUSB from IDF, it has it's own and is regularly updated to the latest version (actually any time the IDF libs are built, latest TinyUSB is introduced. I think it should be possible to use the tinyUSB we provide and just have the rest of te adafruit included. Maybe we need to sync up the config, but that should be more or less it. |
libraries/Adafruit_TinyUSB_Arduino/src/arduino/ports/esp32/Adafruit_TinyUSB_esp32.cpp
Outdated
Show resolved
Hide resolved
Yeah, I know, it just an user-friendly term :D to make it easier for user to understand. Let me know which name you would prefer.
Yeah, sure once of the issue is with the tinyusb callback, since the library is designed to run all on cores. It does assume it has to done everything from constructing the configuration descriptor, handling all the callbacks etc ... I will probably requires lots of coupling between the core and library. This is actually best way so far I could come up. It is actually not that interfered to the core. Don't worry about the file changes, it is mostly only the inclusion of the library file. If you do a core file compare, it has little changes to core and how core manage USB. If you have some time, please give it a try. PS: There is no duplication code in the flash otherwise we could have linker error. The linker just prefer to pick function from the library than the arduino_tinyusb one. |
So, Adafruit_TinyUSB has two parts inside: The Arduino code and your TinyUSB source. What I proposed is to not include the TinyUSB source at all since that is already present and precompiled. If you just decouple our Arduino USB code from it, you should be set to use just the Arduino part of Adafruit and skip compiling the whole TinyUSB all over again. |
the config and patched DCD for persistence (WIP). when persistence is stable and make it into TinyUSB itself, that source file will disappear as well. |
Ah that would be doable, though, since the library is also used by other MCU such as samd/nrf core which does has built-in tinyusb support. Those files still need to be there since it is currently used on nrf,samd and rp2040.
I could write a script to wrap all tinyusb sources within
Ah I see, If you prefer the library to link with it. There should be no problems at all, though sometime there could be some API changes where the library/stack move a bit more aggressive than the one come with IDF. But it is all solvable with Anyway, please take your time to try it out and if possible, make any adjustment/modification as you see fit. I am not in rush, I actually expect this PR to be in review for quite some time. It is always a big PR to add it to a core BSP. |
@hathach the version of TinyUSB in ESP-IDF is not related to Arduino at all :) For example, the lib builder pushed new libs to this PR last night: #5336 |
Superb !! That is great to hear, that could simplify the menu selection without having to pick the correct include path to tusb_config.h. I will do more update with the PR, let me know if there is any other modification that you want to make :) |
If you find that the included config is missing something, please add PR to the lib builder's usb config and that will then be pushed on the next build :) https://github.com/espressif/esp32-arduino-lib-builder/blob/master/components/arduino_tinyusb/include/tusb_config.h |
Sure thing, that repo is kind of new to me as well. I don't quite catch up with changes from ESP 😅 I am looking to hear more feedback from you for the implementation and usage. Once checkout, you could run most examples in https://github.com/adafruit/arduino-esp32/tree/add-tinyusb-arduino/libraries/Adafruit_TinyUSB_Arduino/examples . There are some that aren't compatible mostly with |
5f73f2e
to
1d61f79
Compare
@me-no-dev I have updated the PR following your request, using In addition, I need a bit of help to fix ci build. All the examples within the
|
@hathach I need to figure out how to implement custom board definitions for particular example builds in CI. No worries, will get to it :) |
I hope that wouldn't be issue, we can either skip all examples in CI or remove it for now to get CI happy. More importantly is the rest of modification, please give it a try, I would love to hear your feedback. |
thanks to #5466 that declared most of tinyusb callback as weak function. It is possible now to have external USB libraries (Adafruit_TinyUSB_Arduino) co-exist with with usb code from core. This PR is superseded by adafruit/Adafruit_TinyUSB_Arduino#126 and can be safely closed now. Thank @me-no-dev for making the changes to allow this since Note: there is an esp32s2 port limit: dynamically changes the configurations is not possible since esp32-hal-tinyusb.c requires all descriptors must be config/set in constructor manner ( pre-setup() ) |
Adafruit has an Arduino version of TinyUSB https://github.com/adafruit/Adafruit_TinyUSB_Arduino, which provide cross-platform API for nrf, samd, rp2040 and is growing. I am hoping we could add support for esp32s2/s3 as well and this PR is doing just that with:
USE_TINYUSB
is macro to indicate the library is selected by user. (kind of odds since both use tinyusb, however, the name is introduced way back when we doing this for samd core which use Arduino pluggable stack). This menu option allow this PR to not change any behavior of existing cores at all.Some background note: Unlike SPI/I2C, USB library is particularly difficult to be standalone, since arduino consider CDC Serial as part of the core, which require cdc header must be included by Arduino. This can be resolved by adding USB as one of bundles libraries and adding include path
"-I{runtime.platform.path}/libraries/Adafruit_TinyUSB_Arduino/src/arduino"
to prevent compile error. I am sorry for huge file changes of this PR due to addition of the libary. Normally I would do a submodule, however, I figure out this core does not use submodule. Normally this library does not need to be updated, since the newer version installed via IDE will overwrite this. Though, when there is breaking changes in API (only with cdc header), I will take responsibility to make update PR to get it all in sync with other MCU cores.Please let me know if you are interested in the PR (or want to change its implementation etc ..). This will have an great addition, since Adafruit already has a numerous of library built around this TinyUSB API.
@ladyada