Skip to content

Commit e064cee

Browse files
committed
feat(tinyusb): Made an idf component
1 parent 933ac29 commit e064cee

File tree

5 files changed

+152
-0
lines changed

5 files changed

+152
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Push TinyUSB to Espressif Component Service
2+
3+
# If the commit is tagged, it will be uploaded. Other scenario silently fail.
4+
on:
5+
push:
6+
tags:
7+
- v*
8+
9+
jobs:
10+
upload_components:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Remove unneeded files
16+
shell: bash
17+
run: rm -rf docs tools lib/embedded-cli lib/fatfs lib/SEGGER_RTT
18+
19+
- name: Upload components to component service
20+
uses: espressif/upload-components-ci-action@v1
21+
with:
22+
name: "tinyusb"
23+
version: ${{ github.ref_name }}
24+
namespace: "espressif"
25+
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}

CMakeLists.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
idf_build_get_property(target IDF_TARGET)
2+
3+
if(target STREQUAL "esp32s3")
4+
set(tusb_mcu "OPT_MCU_ESP32S3")
5+
set(tusb_family "esp32sx")
6+
elseif(target STREQUAL "esp32s2")
7+
set(tusb_mcu "OPT_MCU_ESP32S2")
8+
set(tusb_family "esp32sx")
9+
elseif(target STREQUAL "esp32p4")
10+
set(tusb_mcu "OPT_MCU_ESP32P4")
11+
set(tusb_family "esp32px")
12+
endif()
13+
14+
set(compile_options
15+
"-DCFG_TUSB_MCU=${tusb_mcu}"
16+
)
17+
18+
idf_component_get_property(freertos_include freertos ORIG_INCLUDE_PATH)
19+
20+
set(includes_private
21+
"src/"
22+
"src/device"
23+
"lib/networking" # For RNDIS definitions
24+
)
25+
26+
set(includes_public
27+
"src/"
28+
# The FreeRTOS API include convention in tinyusb is different from esp-idf
29+
"${freertos_include}"
30+
)
31+
32+
set(srcs
33+
"src/class/cdc/cdc_device.c"
34+
"src/class/hid/hid_device.c"
35+
"src/class/midi/midi_device.c"
36+
"src/class/msc/msc_device.c"
37+
"src/class/vendor/vendor_device.c"
38+
"src/class/audio/audio_device.c"
39+
"src/class/video/video_device.c"
40+
"src/class/bth/bth_device.c"
41+
# NET class
42+
"src/class/net/ecm_rndis_device.c"
43+
"lib/networking/rndis_reports.c"
44+
"src/class/net/ncm_device.c"
45+
# DFU
46+
"src/class/dfu/dfu_device.c"
47+
"src/class/dfu/dfu_rt_device.c"
48+
# Common, device-mode related
49+
"src/portable/synopsys/dwc2/dcd_dwc2.c"
50+
"src/common/tusb_fifo.c"
51+
"src/device/usbd_control.c"
52+
"src/device/usbd.c"
53+
"src/tusb.c"
54+
)
55+
56+
idf_component_register(SRCS ${srcs}
57+
INCLUDE_DIRS ${includes_public}
58+
PRIV_INCLUDE_DIRS ${includes_private}
59+
PRIV_REQUIRES esp_netif # required by rndis_reports.c: #include "netif/ethernet.h"
60+
)
61+
62+
target_compile_options(${COMPONENT_LIB} PUBLIC ${compile_options})
63+
64+
# when no builtin class driver is enabled, an uint8_t data compared with `BUILTIN_DRIVER_COUNT` will always be false
65+
set_source_files_properties("src/device/usbd.c" PROPERTIES COMPILE_FLAGS "-Wno-type-limits")

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Espressif TinyUSB fork
2+
3+
This is a fork of upstream [TinyUSB](https://github.com/hathach/tinyusb) with integration into ESP-IDF build system.
4+
It is used mostly for rapid bugfixing and for releases independent from the upstream project.
5+
We try to push all bugfixes and features to the upstream.
6+
7+
## How to use
8+
9+
There are two options of using TinyUSB with Espressif's SoCs.
10+
11+
### 1. Use this component together with [Espressif TinyUSB additions](https://github.com/espressif/idf-extra-components/tree/master/usb/esp_tinyusb/)
12+
13+
This is identical approach as in ESP-IDF 4.x releases. You can configure TinyUSB using Kconfig, as usual. Just add ``idf_component.yml`` to your main component with the following content::
14+
15+
```yaml
16+
## IDF Component Manager Manifest File
17+
dependencies:
18+
esp_tinyusb: "^1.0.0" # Automatically update minor releases
19+
```
20+
21+
Or simply run:
22+
```
23+
idf.py add-dependency "esp_tinyusb^1.0.0"
24+
```
25+
### 2. Use TinyUSB only, without the [additions](https://github.com/espressif/idf-extra-components/tree/master/usb/esp_tinyusb/)
26+
27+
Use this option for custom TinyUSB applications.
28+
In this case you will have to provide configuration header file ``tusb_config.h``. More information about TinyUSB configuration can be found [in official TinyUSB documentation](https://docs.tinyusb.org/en/latest/reference/getting_started.html).
29+
30+
You will also have to tell TinyUSB where to find the configuration file. This can be achieved by adding following CMake snippet to you main component's ``CMakeLists.txt``:
31+
32+
```cmake
33+
idf_component_get_property(tusb_lib espressif__tinyusb COMPONENT_LIB)
34+
target_include_directories(${tusb_lib} PRIVATE path_to_your_tusb_config)
35+
```
36+
37+
Again, you can add this component to your project by adding ``idf_component.yml`` file:
38+
39+
```yaml
40+
## IDF Component Manager Manifest File
41+
dependencies:
42+
tinyusb: "~0.15.1" # Automatically update bugfix releases. TinyUSB does not guarantee backward compatibility
43+
```
44+
45+
Or simply run:
46+
```
47+
idf.py add-dependency "tinyusb~0.15.1"
48+
```
49+
50+
README from the upstream TinyUSB can be found in [hathach/tinyusb/README](https://github.com/hathach/tinyusb/blob/master/README.rst).

idf_component.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
description: TinyUSB ported to Espressif's SoCs
2+
url: https://docs.tinyusb.org/en/latest/
3+
documentation: "https://docs.tinyusb.org/en/latest/"
4+
repository: "https://github.com/espressif/tinyusb.git"
5+
dependencies:
6+
idf: '>=5.0' # IDF 4.x contains TinyUSB as submodule
7+
targets:
8+
- esp32s2
9+
- esp32s3
10+
- esp32p4

sbom.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
supplier: 'Organization: Espressif Systems (Shanghai) CO LTD'
2+
originator: 'Person: Ha Thach <[email protected]>'

0 commit comments

Comments
 (0)