├── .codespell
├── exclude-file.txt
└── ignore-words.txt
├── .codespellrc
├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.yml
│ ├── config.yml
│ └── feature_request.md
└── workflows
│ └── githubci.yml
├── .gitignore
├── .pre-commit-config.yaml
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── changelog.md
├── docs
└── examples
│ ├── webusb-rgb
│ ├── application.css
│ ├── application.js
│ ├── index.html
│ └── serial.js
│ └── webusb-serial
│ ├── application.css
│ ├── application.js
│ ├── index.html
│ └── serial.js
├── examples
├── CDC
│ ├── cdc_multi
│ │ ├── .skip.txt
│ │ └── cdc_multi.ino
│ ├── no_serial
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ └── no_serial.ino
│ └── serial_echo
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ └── serial_echo.ino
├── Composite
│ └── mouse_ramdisk
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ ├── mouse_ramdisk.ino
│ │ └── ramdisk.h
├── DualRole
│ ├── CDC
│ │ └── serial_host_bridge
│ │ │ ├── .skip.txt
│ │ │ ├── serial_host_bridge.ino
│ │ │ └── usbh_helper.h
│ ├── HID
│ │ ├── hid_device_report
│ │ │ ├── .skip.txt
│ │ │ ├── hid_device_report.ino
│ │ │ └── usbh_helper.h
│ │ ├── hid_mouse_log_filter
│ │ │ ├── .skip.txt
│ │ │ ├── hid_mouse_log_filter.ino
│ │ │ └── usbh_helper.h
│ │ ├── hid_mouse_tremor_filter
│ │ │ ├── .skip.txt
│ │ │ ├── hid_mouse_tremor_filter.ino
│ │ │ └── usbh_helper.h
│ │ └── hid_remapper
│ │ │ ├── .skip.txt
│ │ │ ├── hid_remapper.ino
│ │ │ └── usbh_helper.h
│ ├── MassStorage
│ │ ├── msc_data_logger
│ │ │ ├── .skip.txt
│ │ │ ├── msc_data_logger.ino
│ │ │ └── usbh_helper.h
│ │ └── msc_file_explorer
│ │ │ ├── .skip.txt
│ │ │ ├── msc_file_explorer.ino
│ │ │ └── usbh_helper.h
│ └── Simple
│ │ ├── device_info
│ │ ├── .skip.txt
│ │ ├── device_info.ino
│ │ └── usbh_helper.h
│ │ └── device_info_max3421e
│ │ ├── .skip.txt
│ │ └── device_info_max3421e.ino
├── HID
│ ├── hid_boot_keyboard
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ └── hid_boot_keyboard.ino
│ ├── hid_boot_mouse
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ └── hid_boot_mouse.ino
│ ├── hid_composite
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ └── hid_composite.ino
│ ├── hid_composite_joy_featherwing
│ │ ├── .skip.txt
│ │ └── hid_composite_joy_featherwing.ino
│ ├── hid_dual_interfaces
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ └── hid_dual_interfaces.ino
│ ├── hid_gamepad
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ └── hid_gamepad.ino
│ └── hid_generic_inout
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ ├── README.md
│ │ ├── boards.js
│ │ ├── hid_generic_inout.ino
│ │ ├── hid_test.js
│ │ ├── hid_test.py
│ │ └── package.json
├── Host
│ └── Simple
│ │ └── host_device_info
│ │ ├── .pico_rp2040_tinyusb_host.test.only
│ │ └── host_device_info.ino
├── MIDI
│ ├── midi_multi_ports
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ └── midi_multi_ports.ino
│ ├── midi_pizza_box_dj
│ │ ├── .cpb.test.only
│ │ ├── .cpx_ada.test.only
│ │ └── midi_pizza_box_dj.ino
│ └── midi_test
│ │ ├── .pico_rp2040_tinyusb_host.test.skip
│ │ └── midi_test.ino
├── MassStorage
│ ├── msc_esp32_file_browser
│ │ ├── .funhouse.test.only
│ │ ├── .magtag.test.only
│ │ ├── .metroesp32s2.test.only
│ │ ├── data
│ │ │ ├── edit.htm
│ │ │ ├── favicon.ico
│ │ │ ├── graphs.js
│ │ │ └── index.htm
│ │ └── msc_esp32_file_browser.ino
│ ├── msc_external_flash
│ │ ├── .skip.txt
│ │ ├── flash_config.h
│ │ └── msc_external_flash.ino
│ ├── msc_external_flash_sdcard
│ │ ├── .skip.txt
│ │ ├── flash_config.h
│ │ └── msc_external_flash_sdcard.ino
│ ├── msc_internal_flash_samd
│ │ ├── .metro_m0_tinyusb.test.only
│ │ └── msc_internal_flash_samd.ino
│ ├── msc_ramdisk
│ │ ├── .skip.txt
│ │ ├── msc_ramdisk.ino
│ │ └── ramdisk.h
│ ├── msc_ramdisk_dual
│ │ ├── .skip.txt
│ │ ├── msc_ramdisk_dual.ino
│ │ └── ramdisk.h
│ ├── msc_sd
│ │ ├── .skip.txt
│ │ └── msc_sd.ino
│ └── msc_sdfat
│ │ ├── .skip.txt
│ │ └── msc_sdfat.ino
├── Vendor
│ └── i2c_tiny_usb_adapter
│ │ ├── .skip.txt
│ │ ├── Adafruit_USBD_I2C.cpp
│ │ ├── Adafruit_USBD_I2C.h
│ │ ├── i2c_tiny_usb_adapter.ino
│ │ └── i2c_usb.py
├── Video
│ └── video_capture
│ │ ├── .skip.txt
│ │ └── video_capture.ino
└── WebUSB
│ ├── webusb_rgb
│ ├── .skip.txt
│ └── webusb_rgb.ino
│ └── webusb_serial
│ ├── .skip.txt
│ └── webusb_serial.ino
├── library.json
├── library.properties
├── src
├── Adafruit_TinyUSB.h
├── arduino
│ ├── Adafruit_TinyUSB_API.cpp
│ ├── Adafruit_TinyUSB_API.h
│ ├── Adafruit_USBD_CDC.cpp
│ ├── Adafruit_USBD_CDC.h
│ ├── Adafruit_USBD_Device.cpp
│ ├── Adafruit_USBD_Device.h
│ ├── Adafruit_USBD_Interface.cpp
│ ├── Adafruit_USBD_Interface.h
│ ├── Adafruit_USBH_Host.cpp
│ ├── Adafruit_USBH_Host.h
│ ├── cdc
│ │ ├── Adafruit_USBH_CDC.cpp
│ │ └── Adafruit_USBH_CDC.h
│ ├── hid
│ │ ├── Adafruit_USBD_HID.cpp
│ │ └── Adafruit_USBD_HID.h
│ ├── midi
│ │ ├── Adafruit_USBD_MIDI.cpp
│ │ └── Adafruit_USBD_MIDI.h
│ ├── msc
│ │ ├── Adafruit_USBD_MSC.cpp
│ │ ├── Adafruit_USBD_MSC.h
│ │ ├── Adafruit_USBH_MSC.cpp
│ │ └── Adafruit_USBH_MSC.h
│ ├── ports
│ │ ├── ch32
│ │ │ ├── Adafruit_TinyUSB_ch32.cpp
│ │ │ └── tusb_config_ch32.h
│ │ ├── esp32
│ │ │ ├── Adafruit_TinyUSB_esp32.cpp
│ │ │ └── tusb_config_esp32.h
│ │ ├── nrf
│ │ │ ├── Adafruit_TinyUSB_nrf.cpp
│ │ │ └── tusb_config_nrf.h
│ │ ├── rp2040
│ │ │ ├── Adafruit_TinyUSB_rp2040.cpp
│ │ │ └── tusb_config_rp2040.h
│ │ └── samd
│ │ │ ├── Adafruit_TinyUSB_samd.cpp
│ │ │ └── tusb_config_samd.h
│ ├── video
│ │ ├── Adafruit_USBD_Video.cpp
│ │ └── Adafruit_USBD_Video.h
│ └── webusb
│ │ ├── Adafruit_USBD_WebUSB.cpp
│ │ └── Adafruit_USBD_WebUSB.h
├── class
│ ├── audio
│ │ ├── audio.h
│ │ ├── audio_device.c
│ │ └── audio_device.h
│ ├── bth
│ │ ├── bth_device.c
│ │ └── bth_device.h
│ ├── cdc
│ │ ├── cdc.h
│ │ ├── cdc_device.c
│ │ ├── cdc_device.h
│ │ ├── cdc_host.c
│ │ ├── cdc_host.h
│ │ └── serial
│ │ │ ├── ch34x.h
│ │ │ ├── cp210x.h
│ │ │ └── ftdi_sio.h
│ ├── dfu
│ │ ├── dfu.h
│ │ ├── dfu_device.c
│ │ ├── dfu_device.h
│ │ ├── dfu_rt_device.c
│ │ └── dfu_rt_device.h
│ ├── hid
│ │ ├── hid.h
│ │ ├── hid_device.c
│ │ ├── hid_device.h
│ │ ├── hid_host.c
│ │ └── hid_host.h
│ ├── midi
│ │ ├── midi.h
│ │ ├── midi_device.c
│ │ └── midi_device.h
│ ├── msc
│ │ ├── msc.h
│ │ ├── msc_device.c
│ │ ├── msc_device.h
│ │ ├── msc_host.c
│ │ └── msc_host.h
│ ├── net
│ │ ├── ecm_rndis_device.c
│ │ ├── ncm.h
│ │ ├── ncm_device.c
│ │ └── net_device.h
│ ├── usbtmc
│ │ ├── usbtmc.h
│ │ ├── usbtmc_device.c
│ │ └── usbtmc_device.h
│ ├── vendor
│ │ ├── vendor_device.c
│ │ └── vendor_device.h
│ └── video
│ │ ├── video.h
│ │ ├── video_device.c
│ │ └── video_device.h
├── common
│ ├── tusb_common.h
│ ├── tusb_compiler.h
│ ├── tusb_debug.h
│ ├── tusb_fifo.c
│ ├── tusb_fifo.h
│ ├── tusb_mcu.h
│ ├── tusb_private.h
│ ├── tusb_types.h
│ └── tusb_verify.h
├── device
│ ├── dcd.h
│ ├── usbd.c
│ ├── usbd.h
│ ├── usbd_control.c
│ └── usbd_pvt.h
├── host
│ ├── hcd.h
│ ├── hub.c
│ ├── hub.h
│ ├── usbh.c
│ ├── usbh.h
│ └── usbh_pvt.h
├── osal
│ ├── osal.h
│ ├── osal_freertos.h
│ ├── osal_mynewt.h
│ ├── osal_none.h
│ ├── osal_pico.h
│ ├── osal_rtthread.h
│ └── osal_rtx4.h
├── portable
│ ├── analog
│ │ └── max3421
│ │ │ └── hcd_max3421.c
│ ├── microchip
│ │ └── samd
│ │ │ └── dcd_samd.c
│ ├── nordic
│ │ └── nrf5x
│ │ │ └── dcd_nrf5x.c
│ ├── raspberrypi
│ │ ├── pio_usb
│ │ │ ├── dcd_pio_usb.c
│ │ │ └── hcd_pio_usb.c
│ │ └── rp2040
│ │ │ ├── dcd_rp2040.c
│ │ │ ├── hcd_rp2040.c
│ │ │ ├── rp2040_usb.c
│ │ │ └── rp2040_usb.h
│ ├── st
│ │ └── stm32_fsdev
│ │ │ ├── dcd_stm32_fsdev.c
│ │ │ ├── fsdev_ch32.h
│ │ │ ├── fsdev_stm32.h
│ │ │ └── fsdev_type.h
│ ├── synopsys
│ │ └── dwc2
│ │ │ ├── dcd_dwc2.c
│ │ │ ├── dwc2_bcm.h
│ │ │ ├── dwc2_efm32.h
│ │ │ ├── dwc2_esp32.h
│ │ │ ├── dwc2_gd32.h
│ │ │ ├── dwc2_stm32.h
│ │ │ ├── dwc2_type.h
│ │ │ └── dwc2_xmc.h
│ └── wch
│ │ ├── ch32_usbfs_reg.h
│ │ ├── ch32_usbhs_reg.h
│ │ ├── dcd_ch32_usbfs.c
│ │ └── dcd_ch32_usbhs.c
├── tusb.c
├── tusb.h
├── tusb_config.h
└── tusb_option.h
└── tools
├── build_all.py
└── update-usbh_helper.py
/.codespell/exclude-file.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/.codespell/exclude-file.txt
--------------------------------------------------------------------------------
/.codespell/ignore-words.txt:
--------------------------------------------------------------------------------
1 | synopsys
2 | sie
3 | inout
4 | busses
5 | thre
6 |
7 |
--------------------------------------------------------------------------------
/.codespellrc:
--------------------------------------------------------------------------------
1 | # See: https://github.com/codespell-project/codespell#using-a-config-file
2 | [codespell]
3 | # In the event of a false positive, add the problematic word, in all lowercase, to 'ignore-words.txt' (one word per line).
4 | # Or copy & paste the whole problematic line to 'exclude-file.txt'
5 | ignore-words = .codespell/ignore-words.txt
6 | exclude-file = .codespell/exclude-file.txt
7 | check-filenames =
8 | check-hidden =
9 | count =
10 | skip = .git
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.yml:
--------------------------------------------------------------------------------
1 | name: Bug Report
2 | description: Report a problem with TinyUSB Library
3 | labels: 'Bug'
4 | body:
5 | - type: markdown
6 | attributes:
7 | value: |
8 | Thanks for taking the time to fill out this bug report!
9 | It's okay to leave some blank if it doesn't apply to your problem.
10 |
11 | - type: dropdown
12 | attributes:
13 | label: Operating System
14 | options:
15 | - Linux
16 | - MacOS
17 | - RaspberryPi OS
18 | - Windows 7
19 | - Windows 10
20 | - Windows 11
21 | - Others
22 | validations:
23 | required: true
24 |
25 | - type: input
26 | attributes:
27 | label: Arduino IDE version
28 | placeholder: e.g Arduino 1.8.15
29 | validations:
30 | required: true
31 |
32 | - type: input
33 | attributes:
34 | label: Board
35 | placeholder: e.g Feather nRF52840 Express
36 | validations:
37 | required: true
38 |
39 | - type: input
40 | attributes:
41 | label: ArduinoCore version
42 | description: Can be found under "Board Manager" menu
43 | validations:
44 | required: true
45 |
46 | - type: input
47 | attributes:
48 | label: TinyUSB Library version
49 | placeholder: "Release version or github latest"
50 | validations:
51 | required: true
52 |
53 | - type: textarea
54 | attributes:
55 | label: Sketch as ATTACHED TXT
56 | placeholder: |
57 | e.g examples/MassStorage/msc_ramdisk.
58 | If it is custom sketch, please provide it as **ATTACHED** files or link to it.
59 | Pasting raw long code that hurts readability can get your issue **closed**
60 | validations:
61 | required: true
62 |
63 | - type: textarea
64 | attributes:
65 | label: Compiled Log as ATTACHED TXT
66 | placeholder: |
67 | Compiled log from Arduino IDE as **ATTACHED** txt.
68 | Pasting raw long log that hurts readability can get your issue **closed**
69 | validations:
70 | required: true
71 |
72 | - type: textarea
73 | attributes:
74 | label: What happened ?
75 | placeholder: A clear and concise description of what the bug is.
76 | validations:
77 | required: true
78 |
79 | - type: textarea
80 | attributes:
81 | label: How to reproduce ?
82 | placeholder: |
83 | 1. Go to '...'
84 | 2. Click on '....'
85 | 3. See error
86 | validations:
87 | required: true
88 |
89 | - type: textarea
90 | attributes:
91 | label: Debug Log
92 | placeholder: |
93 | TinyUSB debug log where the issue occurred as attached txt file, best with comments to explain the actual events.
94 | validations:
95 | required: false
96 |
97 | - type: textarea
98 | attributes:
99 | label: Screenshots
100 | description: If applicable, add screenshots to help explain your problem.
101 | validations:
102 | required: false
103 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: Adafruit Support Forum
4 | url: https://forums.adafruit.com
5 | about: If you have other questions or need help, post it here.
6 | - name: TinyUSB Arduino Discussion
7 | url: https://github.com/adafruit/Adafruit_TinyUSB_Arduino/discussions
8 | about: If you have other questions or need help, post it here.
9 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: 'Feature'
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/githubci.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on: [pull_request, push, repository_dispatch]
4 |
5 | concurrency:
6 | group: ${{ github.workflow }}-${{ github.ref }}
7 | cancel-in-progress: true
8 |
9 | env:
10 | ARDUINO_LIBS: "\"Adafruit SPIFlash\" \"Adafruit seesaw Library\" \"Adafruit NeoPixel\" \"Adafruit Circuit Playground\" \"Adafruit InternalFlash\" \"SdFat - Adafruit Fork\" \"SD\" \"MIDI Library\" \"Pico PIO USB\""
11 |
12 | jobs:
13 | pre-commit:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - name: Checkout code
17 | uses: actions/checkout@v4
18 |
19 | - name: Run pre-commit
20 | uses: pre-commit/action@v3.0.1
21 |
22 | - name: Checkout adafruit/ci-arduino
23 | uses: actions/checkout@v4
24 | with:
25 | repository: adafruit/ci-arduino
26 | path: ci
27 |
28 | - name: pre-install
29 | run: bash ci/actions_install.sh
30 |
31 | # - name: clang
32 | # run: python3 ci/run-clang-format.py -r src/arduino
33 |
34 | - name: doxygen
35 | env:
36 | GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
37 | PRETTYNAME : "Adafruit TinyUSB Library"
38 | run: bash ci/doxy_gen_and_deploy.sh
39 |
40 | # ---------------------------------------
41 | # Main
42 | # ---------------------------------------
43 | build:
44 | runs-on: ubuntu-latest
45 | needs: pre-commit
46 | strategy:
47 | fail-fast: false
48 | matrix:
49 | arduino-platform:
50 | # ESP32 ci use dev json
51 | - 'feather_esp32s2'
52 | - 'feather_esp32s3'
53 | # nRF52
54 | - 'cpb'
55 | - 'nrf52840'
56 | # RP2040
57 | - 'feather_rp2040_tinyusb'
58 | - 'pico_rp2040_tinyusb_host'
59 | # SAMD
60 | - 'metro_m0_tinyusb'
61 | - 'metro_m4_tinyusb'
62 | # Ch32v2
63 | - 'CH32V20x_EVT'
64 | steps:
65 | - name: Checkout code
66 | uses: actions/checkout@v4
67 |
68 | - name: Checkout adafruit/ci-arduino
69 | uses: actions/checkout@v4
70 | with:
71 | repository: adafruit/ci-arduino
72 | path: ci
73 |
74 | - name: pre-install
75 | run: bash ci/actions_install.sh
76 |
77 | - name: Install Libraries
78 | run: |
79 | arduino-cli lib install ${{ env.ARDUINO_LIBS }}
80 | arduino-cli lib list
81 |
82 | - name: test platforms
83 | run: python3 ci/build_platform.py ${{ matrix.arduino-platform }}
84 |
85 | # ---------------------------------------
86 | # Build ESP32 v2
87 | # ---------------------------------------
88 | build-esp32-v2:
89 | if: false
90 | runs-on: ubuntu-latest
91 | needs: pre-commit
92 | strategy:
93 | fail-fast: false
94 | matrix:
95 | arduino-platform:
96 | - 'feather_esp32s2'
97 | - 'feather_esp32s3'
98 | esp32-version:
99 | - '2.0.17'
100 |
101 | steps:
102 | - name: Checkout code
103 | uses: actions/checkout@v4
104 |
105 | - name: Checkout adafruit/ci-arduino
106 | uses: actions/checkout@v4
107 | with:
108 | repository: adafruit/ci-arduino
109 | path: ci
110 |
111 | - name: pre-install
112 | run: bash ci/actions_install.sh
113 |
114 | - name: Install arduino-esp32 v2 and Libraries
115 | env:
116 | BSP_URLS: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
117 | run: |
118 | arduino-cli core install esp32:esp32@${{ matrix.esp32-version }} --additional-urls $BSP_URLS
119 | arduino-cli lib install ${{ env.ARDUINO_LIBS }}
120 | arduino-cli core list
121 | arduino-cli lib list
122 |
123 | - name: Create custom build script
124 | working-directory: ${{ github.workspace }}/ci
125 | run: |
126 | echo 'import build_platform' > build_esp32_v2.py
127 | echo 'build_platform.test_examples_in_folder("'${{ matrix.arduino-platform }}'", build_platform.BUILD_DIR)' >> build_esp32_v2.py
128 | echo 'exit(build_platform.success)' >> build_esp32_v2.py
129 | cat build_esp32_v2.py
130 |
131 | - name: test platforms
132 | run: |
133 | python3 ci/build_esp32_v2.py
134 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /examples/**/build/
2 | /.development
3 | .idea
4 | platformio.ini
5 | .pio/
6 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | # SPDX-FileCopyrightText: 2020 Diego Elio Pettenò
2 | #
3 | # SPDX-License-Identifier: Unlicense
4 |
5 | repos:
6 | - repo: https://github.com/pre-commit/mirrors-clang-format
7 | rev: v15.0.7
8 | hooks:
9 | - id: clang-format
10 | exclude: |
11 | (?x)^(
12 | examples/|
13 | src/class|
14 | src/common|
15 | src/device|
16 | src/host|
17 | src/osal|
18 | src/portable|
19 | src/tusb_option.h|
20 | src/tusb.c|
21 | src/tusb.h
22 | )
23 | types_or: [c++, c, header]
24 |
25 | - repo: https://github.com/codespell-project/codespell
26 | rev: v2.2.4
27 | hooks:
28 | - id: codespell
29 | args: [-w]
30 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at . All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2019 Ha Thach for Adafruit Industries
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/docs/examples/webusb-rgb/application.css:
--------------------------------------------------------------------------------
1 | .main-content {
2 | width: 1440px;
3 | margin: auto;
4 | font-size: 14px;
5 | }
6 |
7 | .connect-container {
8 | margin: 20px 0;
9 | }
10 |
11 | .button::before {
12 | -webkit-border-radius: 3px;
13 | -moz-border-radius: 3px;
14 | -webkit-box-shadow: #959595 0 2px 5px;
15 | -moz-box-shadow: #959595 0 2px 5px;
16 | border-radius: 3px;
17 | box-shadow: #959595 0 2px 5px;
18 | content: "";
19 | display: block;
20 | left: 0;
21 | padding: 2px 0 0;
22 | position: absolute;
23 | top: 0;
24 | }
25 |
26 | .button:active::before { padding: 1px 0 0; }
27 |
28 | .button.black {
29 | background: #656565;
30 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#656565), to(#444));
31 | background: -moz-linear-gradient(#656565, #444);
32 | background: linear-gradient(#656565, #444);
33 | border: solid 1px #535353;
34 | border-bottom: solid 3px #414141;
35 | box-shadow: inset 0 0 0 1px #939393;
36 | color: #fff;
37 | text-shadow: 0 1px 0 #2f2f2f;
38 | padding: 8px 16px;
39 | outline: none;
40 | }
41 |
42 | .button.black:hover {
43 | background: #4c4c4c;
44 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#4c4c4c), to(#565656));
45 | background: -moz-linear-gradient(#4c4c4c, #565656);
46 | background: linear-gradient(#4c4c4c, #565656);
47 | border: solid 1px #464646;
48 | border-bottom: solid 3px #414141;
49 | box-shadow: inset 0 0 0 1px #818181;
50 | }
51 |
52 | .button.black:active {
53 | background: #474747;
54 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#474747), to(#444));
55 | background: -moz-linear-gradient(#474747, #444);
56 | background: linear-gradient(#474747, #444);
57 | border: solid 1px #2f2f2f;
58 | box-shadow: inset 0 10px 15px 0 #3e3e3e;
59 | }
60 |
61 | .color-picker-container {
62 | width: 100px;
63 | height: 100px;
64 | border-radius: 50px;
65 | overflow: hidden;
66 | }
67 |
68 | .color-picker {
69 | padding: 0;
70 | border: none;
71 | width: 200px;
72 | height: 200px;
73 | outline: none;
74 | transform: translate(-25%, -25%)
75 | }
76 |
--------------------------------------------------------------------------------
/docs/examples/webusb-rgb/application.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | 'use strict';
3 |
4 | document.addEventListener('DOMContentLoaded', event => {
5 | let connectButton = document.querySelector("#connect");
6 | let statusDisplay = document.querySelector('#status');
7 | let port;
8 |
9 | function connect() {
10 | port.connect().then(() => {
11 | statusDisplay.textContent = '';
12 | connectButton.textContent = 'Disconnect';
13 |
14 | port.onReceiveError = error => {
15 | console.error(error);
16 | };
17 | }, error => {
18 | statusDisplay.textContent = error;
19 | });
20 | }
21 |
22 | connectButton.addEventListener('click', function() {
23 | if (port) {
24 | port.disconnect();
25 | connectButton.textContent = 'Connect';
26 | statusDisplay.textContent = '';
27 | port = null;
28 | } else {
29 | serial.requestPort().then(selectedPort => {
30 | port = selectedPort;
31 | connect();
32 | }).catch(error => {
33 | statusDisplay.textContent = error;
34 | });
35 | }
36 | });
37 |
38 | serial.getPorts().then(ports => {
39 | if (ports.length === 0) {
40 | statusDisplay.textContent = 'No device found.';
41 | } else {
42 | statusDisplay.textContent = 'Connecting...';
43 | port = ports[0];
44 | connect();
45 | }
46 | });
47 |
48 | let colorPicker = document.getElementById("color_picker");
49 |
50 | colorPicker.addEventListener("change", function(event) {
51 | port.send(new TextEncoder("utf-8").encode(colorPicker.value));
52 | });
53 | });
54 | })();
55 |
--------------------------------------------------------------------------------
/docs/examples/webusb-rgb/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TinyUSB
5 |
6 |
7 |
8 |
9 |
10 |
11 |
TinyUSB - WebUSB RGB Example
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/docs/examples/webusb-rgb/serial.js:
--------------------------------------------------------------------------------
1 | var serial = {};
2 |
3 | (function() {
4 | 'use strict';
5 |
6 | serial.getPorts = function() {
7 | return navigator.usb.getDevices().then(devices => {
8 | return devices.map(device => new serial.Port(device));
9 | });
10 | };
11 |
12 | serial.requestPort = function() {
13 | const filters = [
14 | { 'vendorId': 0xcafe }, // TinyUSB
15 | { 'vendorId': 0x239a }, // Adafruit
16 | { 'vendorId': 0x2e8a }, // Raspberry Pi
17 | { 'vendorId': 0x303a }, // Espressif
18 | { 'vendorId': 0x2341 }, // Arduino
19 | ];
20 | return navigator.usb.requestDevice({ 'filters': filters }).then(
21 | device => new serial.Port(device)
22 | );
23 | }
24 |
25 | serial.Port = function(device) {
26 | this.device_ = device;
27 | this.interfaceNumber = 0;
28 | this.endpointIn = 0;
29 | this.endpointOut = 0;
30 | };
31 |
32 | serial.Port.prototype.connect = function() {
33 | let readLoop = () => {
34 | this.device_.transferIn(this.endpointIn, 64).then(result => {
35 | this.onReceive(result.data);
36 | readLoop();
37 | }, error => {
38 | this.onReceiveError(error);
39 | });
40 | };
41 |
42 | return this.device_.open()
43 | .then(() => {
44 | if (this.device_.configuration === null) {
45 | return this.device_.selectConfiguration(1);
46 | }
47 | })
48 | .then(() => {
49 | var interfaces = this.device_.configuration.interfaces;
50 | interfaces.forEach(element => {
51 | element.alternates.forEach(elementalt => {
52 | if (elementalt.interfaceClass==0xFF) {
53 | this.interfaceNumber = element.interfaceNumber;
54 | elementalt.endpoints.forEach(elementendpoint => {
55 | if (elementendpoint.direction == "out") {
56 | this.endpointOut = elementendpoint.endpointNumber;
57 | }
58 | if (elementendpoint.direction=="in") {
59 | this.endpointIn =elementendpoint.endpointNumber;
60 | }
61 | })
62 | }
63 | })
64 | })
65 | })
66 | .then(() => this.device_.claimInterface(this.interfaceNumber))
67 | .then(() => this.device_.selectAlternateInterface(this.interfaceNumber, 0))
68 | .then(() => this.device_.controlTransferOut({
69 | 'requestType': 'class',
70 | 'recipient': 'interface',
71 | 'request': 0x22,
72 | 'value': 0x01,
73 | 'index': this.interfaceNumber}))
74 | .then(() => {
75 | readLoop();
76 | });
77 | };
78 |
79 | serial.Port.prototype.disconnect = function() {
80 | return this.device_.controlTransferOut({
81 | 'requestType': 'class',
82 | 'recipient': 'interface',
83 | 'request': 0x22,
84 | 'value': 0x00,
85 | 'index': this.interfaceNumber})
86 | .then(() => this.device_.close());
87 | };
88 |
89 | serial.Port.prototype.send = function(data) {
90 | return this.device_.transferOut(this.endpointOut, data);
91 | };
92 | })();
93 |
--------------------------------------------------------------------------------
/docs/examples/webusb-serial/application.css:
--------------------------------------------------------------------------------
1 | .main-content {
2 | width: 1440px;
3 | margin: auto;
4 | font-size: 14px;
5 | }
6 |
7 | .connect-container {
8 | margin: 20px 0;
9 | }
10 |
11 | .container {
12 | display: flex;
13 | }
14 |
15 | .sender, .receiver {
16 | flex: 1;
17 | }
18 |
19 | .sender {
20 | margin-right: 8px;
21 | }
22 |
23 | .receiver {
24 | margin-left: 8px;
25 | }
26 |
27 | .lines-header {
28 | height: 30px;
29 | width: 100%;
30 | box-sizing: border-box;
31 | background-color: #444;
32 | line-height: 30px;
33 | color: white;
34 | padding-left: 10px;
35 | }
36 |
37 | .lines-body {
38 | width: 100%;
39 | background-color: #222;
40 | min-height: 300px;
41 | padding: 10px 0 20px 0;
42 | }
43 |
44 | .line, .command-line {
45 | box-sizing: border-box;
46 | width: 100%;
47 | color: #f1f1f1;
48 | background-color: #222;
49 | outline: none;
50 | border: none;
51 | padding: 5px 10px;
52 | font-size: 14px;
53 | }
54 |
55 | .line:hover {
56 | background-color: #444;
57 | }
58 |
59 | .button::before {
60 | -webkit-border-radius: 3px;
61 | -moz-border-radius: 3px;
62 | -webkit-box-shadow: #959595 0 2px 5px;
63 | -moz-box-shadow: #959595 0 2px 5px;
64 | border-radius: 3px;
65 | box-shadow: #959595 0 2px 5px;
66 | content: "";
67 | display: block;
68 | left: 0;
69 | padding: 2px 0 0;
70 | position: absolute;
71 | top: 0;
72 | }
73 |
74 | .button:active::before { padding: 1px 0 0; }
75 |
76 | .button.black {
77 | background: #656565;
78 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#656565), to(#444));
79 | background: -moz-linear-gradient(#656565, #444);
80 | background: linear-gradient(#656565, #444);
81 | border: solid 1px #535353;
82 | border-bottom: solid 3px #414141;
83 | box-shadow: inset 0 0 0 1px #939393;
84 | color: #fff;
85 | text-shadow: 0 1px 0 #2f2f2f;
86 | padding: 8px 16px;
87 | outline: none;
88 | }
89 |
90 | .button.black:hover {
91 | background: #4c4c4c;
92 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#4c4c4c), to(#565656));
93 | background: -moz-linear-gradient(#4c4c4c, #565656);
94 | background: linear-gradient(#4c4c4c, #565656);
95 | border: solid 1px #464646;
96 | border-bottom: solid 3px #414141;
97 | box-shadow: inset 0 0 0 1px #818181;
98 | }
99 |
100 | .button.black:active {
101 | background: #474747;
102 | background: -webkit-gradient(linear, 0 0, 0 bottom, from(#474747), to(#444));
103 | background: -moz-linear-gradient(#474747, #444);
104 | background: linear-gradient(#474747, #444);
105 | border: solid 1px #2f2f2f;
106 | box-shadow: inset 0 10px 15px 0 #3e3e3e;
107 | }
108 |
--------------------------------------------------------------------------------
/docs/examples/webusb-serial/application.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | 'use strict';
3 |
4 | document.addEventListener('DOMContentLoaded', event => {
5 | let connectButton = document.querySelector("#connect");
6 | let statusDisplay = document.querySelector('#status');
7 | let port;
8 |
9 | function addLine(linesId, text) {
10 | var senderLine = document.createElement("div");
11 | senderLine.className = 'line';
12 | var textnode = document.createTextNode(text);
13 | senderLine.appendChild(textnode);
14 | document.getElementById(linesId).appendChild(senderLine);
15 | return senderLine;
16 | }
17 |
18 | let currentReceiverLine;
19 |
20 | function appendLines(linesId, text) {
21 | const lines = text.split('\r');
22 | if (currentReceiverLine) {
23 | currentReceiverLine.innerHTML = currentReceiverLine.innerHTML + lines[0];
24 | for (let i = 1; i < lines.length; i++) {
25 | currentReceiverLine = addLine(linesId, lines[i]);
26 | }
27 | } else {
28 | for (let i = 0; i < lines.length; i++) {
29 | currentReceiverLine = addLine(linesId, lines[i]);
30 | }
31 | }
32 | }
33 |
34 | function connect() {
35 | port.connect().then(() => {
36 | statusDisplay.textContent = '';
37 | connectButton.textContent = 'Disconnect';
38 |
39 | port.onReceive = data => {
40 | let textDecoder = new TextDecoder();
41 | console.log(textDecoder.decode(data));
42 | if (data.getInt8() === 13) {
43 | currentReceiverLine = null;
44 | } else {
45 | appendLines('receiver_lines', textDecoder.decode(data));
46 | }
47 | };
48 | port.onReceiveError = error => {
49 | console.error(error);
50 | };
51 | }, error => {
52 | statusDisplay.textContent = error;
53 | });
54 | }
55 |
56 | connectButton.addEventListener('click', function() {
57 | if (port) {
58 | port.disconnect();
59 | connectButton.textContent = 'Connect';
60 | statusDisplay.textContent = '';
61 | port = null;
62 | } else {
63 | serial.requestPort().then(selectedPort => {
64 | port = selectedPort;
65 | connect();
66 | }).catch(error => {
67 | statusDisplay.textContent = error;
68 | });
69 | }
70 | });
71 |
72 | serial.getPorts().then(ports => {
73 | if (ports.length === 0) {
74 | statusDisplay.textContent = 'No device found.';
75 | } else {
76 | statusDisplay.textContent = 'Connecting...';
77 | port = ports[0];
78 | connect();
79 | }
80 | });
81 |
82 |
83 | let commandLine = document.getElementById("command_line");
84 |
85 | commandLine.addEventListener("keypress", function(event) {
86 | if (event.keyCode === 13) {
87 | if (commandLine.value.length > 0) {
88 | addLine('sender_lines', commandLine.value);
89 | commandLine.value = '';
90 | }
91 | }
92 |
93 | port.send(new TextEncoder('utf-8').encode(String.fromCharCode(event.which || event.keyCode)));
94 | });
95 | });
96 | })();
97 |
--------------------------------------------------------------------------------
/docs/examples/webusb-serial/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | TinyUSB
5 |
6 |
7 |
8 |
9 |
10 |
11 |
TinyUSB - WebUSB Serial Example
12 |
13 |
14 |
15 |
16 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/docs/examples/webusb-serial/serial.js:
--------------------------------------------------------------------------------
1 | var serial = {};
2 |
3 | (function() {
4 | 'use strict';
5 |
6 | serial.getPorts = function() {
7 | return navigator.usb.getDevices().then(devices => {
8 | return devices.map(device => new serial.Port(device));
9 | });
10 | };
11 |
12 | serial.requestPort = function() {
13 | const filters = [
14 | { 'vendorId': 0xcafe }, // TinyUSB
15 | { 'vendorId': 0x239a }, // Adafruit
16 | { 'vendorId': 0x2e8a }, // Raspberry Pi
17 | { 'vendorId': 0x303a }, // Espressif
18 | { 'vendorId': 0x2341 }, // Arduino
19 | ];
20 | return navigator.usb.requestDevice({ 'filters': filters }).then(
21 | device => new serial.Port(device)
22 | );
23 | }
24 |
25 | serial.Port = function(device) {
26 | this.device_ = device;
27 | this.interfaceNumber = 0;
28 | this.endpointIn = 0;
29 | this.endpointOut = 0;
30 | };
31 |
32 | serial.Port.prototype.connect = function() {
33 | let readLoop = () => {
34 | this.device_.transferIn(this.endpointIn, 64).then(result => {
35 | this.onReceive(result.data);
36 | readLoop();
37 | }, error => {
38 | this.onReceiveError(error);
39 | });
40 | };
41 |
42 | return this.device_.open()
43 | .then(() => {
44 | if (this.device_.configuration === null) {
45 | return this.device_.selectConfiguration(1);
46 | }
47 | })
48 | .then(() => {
49 | var interfaces = this.device_.configuration.interfaces;
50 | interfaces.forEach(element => {
51 | element.alternates.forEach(elementalt => {
52 | if (elementalt.interfaceClass==0xFF) {
53 | this.interfaceNumber = element.interfaceNumber;
54 | elementalt.endpoints.forEach(elementendpoint => {
55 | if (elementendpoint.direction == "out") {
56 | this.endpointOut = elementendpoint.endpointNumber;
57 | }
58 | if (elementendpoint.direction=="in") {
59 | this.endpointIn =elementendpoint.endpointNumber;
60 | }
61 | })
62 | }
63 | })
64 | })
65 | })
66 | .then(() => this.device_.claimInterface(this.interfaceNumber))
67 | .then(() => this.device_.selectAlternateInterface(this.interfaceNumber, 0))
68 | .then(() => this.device_.controlTransferOut({
69 | 'requestType': 'class',
70 | 'recipient': 'interface',
71 | 'request': 0x22,
72 | 'value': 0x01,
73 | 'index': this.interfaceNumber}))
74 | .then(() => {
75 | readLoop();
76 | });
77 | };
78 |
79 | serial.Port.prototype.disconnect = function() {
80 | return this.device_.controlTransferOut({
81 | 'requestType': 'class',
82 | 'recipient': 'interface',
83 | 'request': 0x22,
84 | 'value': 0x00,
85 | 'index': this.interfaceNumber})
86 | .then(() => this.device_.close());
87 | };
88 |
89 | serial.Port.prototype.send = function(data) {
90 | return this.device_.transferOut(this.endpointOut, data);
91 | };
92 | })();
93 |
--------------------------------------------------------------------------------
/examples/CDC/cdc_multi/.skip.txt:
--------------------------------------------------------------------------------
1 | feather_esp32s2
2 | feather_esp32s3
3 | funhouse
4 | magtag
5 | metroesp32s2
6 | pico_rp2040_tinyusb_host
7 |
--------------------------------------------------------------------------------
/examples/CDC/cdc_multi/cdc_multi.ino:
--------------------------------------------------------------------------------
1 | /*
2 | This example demonstrates the use of multiple USB CDC/ACM "Virtual
3 | Serial" ports
4 |
5 | Written by Bill Westfield (aka WestfW), June 2021.
6 | Copyright 2021 by Bill Westfield
7 | MIT license, check LICENSE for more information
8 | */
9 |
10 |
11 | /* The example creates two virtual serial ports. Text entered on
12 | * any of the ports will be echoed to the all ports with
13 | * - all lower case in port0 (Serial)
14 | * - all upper case in port1
15 | *
16 | * Requirement:
17 | * The max number of CDC ports (CFG_TUD_CDC) has to be changed to at least 2.
18 | * Config file is located in Adafruit_TinyUSB_Arduino/src/arduino/ports/{platform}/tusb_config_{platform}.h
19 | * where platform is one of: nrf, rp2040, samd
20 | *
21 | * NOTE: Currnetly multiple CDCs on ESP32-Sx is not yet supported.
22 | * An PR to update core/esp32/USBCDC and/or pre-built libusb are needed.
23 | * We would implement this later when we could.
24 | */
25 |
26 | #include
27 |
28 | #define LED LED_BUILTIN
29 |
30 | // Create 2nd instance of CDC Ports.
31 | #ifdef ARDUINO_ARCH_ESP32
32 | #error "Currently multiple CDCs on ESP32-Sx is not yet supported. An PR to update core/esp32/USBCDC and/or pre-built libusb are needed."
33 | // for ESP32, we need to specify instance number when declaring object
34 | Adafruit_USBD_CDC USBSer1(1);
35 | #else
36 | Adafruit_USBD_CDC USBSer1;
37 | #endif
38 |
39 | void setup() {
40 | pinMode(LED, OUTPUT);
41 |
42 | Serial.begin(115200);
43 |
44 | // check to see if multiple CDCs are enabled
45 | if ( CFG_TUD_CDC < 2 ) {
46 | digitalWrite(LED, HIGH); // LED on for error indicator
47 |
48 | while(1) {
49 | Serial.printf("CFG_TUD_CDC must be at least 2, current value is %u\n", CFG_TUD_CDC);
50 | Serial.println(" Config file is located in Adafruit_TinyUSB_Arduino/src/arduino/ports/{platform}/tusb_config_{platform}.h");
51 | Serial.println(" where platform is one of: nrf, rp2040, samd");
52 | delay(1000);
53 | }
54 | }
55 |
56 | // initialize 2nd CDC interface
57 | USBSer1.begin(115200);
58 |
59 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
60 | if (TinyUSBDevice.mounted()) {
61 | TinyUSBDevice.detach();
62 | delay(10);
63 | TinyUSBDevice.attach();
64 | }
65 |
66 | while (!Serial || !USBSer1) {
67 | if (Serial) {
68 | Serial.println("Waiting for other USB ports");
69 | }
70 |
71 | if (USBSer1) {
72 | USBSer1.println("Waiting for other USB ports");
73 | }
74 |
75 | delay(1000);
76 | }
77 |
78 | Serial.print("You are port 0\n\r\n0> ");
79 | USBSer1.print("You are port 1\n\r\n1> ");
80 | }
81 |
82 | int LEDstate = 0;
83 |
84 | void loop() {
85 | int ch;
86 |
87 | ch = Serial.read();
88 | if (ch > 0) {
89 | printAll(ch);
90 | }
91 |
92 | ch = USBSer1.read();
93 | if (ch > 0) {
94 | printAll(ch);
95 | }
96 |
97 | if (delay_without_delaying(500)) {
98 | LEDstate = !LEDstate;
99 | digitalWrite(LED, LEDstate);
100 | }
101 | }
102 |
103 | // print to all CDC ports
104 | void printAll(int ch) {
105 | // always lower case
106 | Serial.write(tolower(ch));
107 |
108 | // always upper case
109 | USBSer1.write(toupper(ch));
110 | }
111 |
112 | // Helper: non-blocking "delay" alternative.
113 | boolean delay_without_delaying(unsigned long time) {
114 | // return false if we're still "delaying", true if time ms has passed.
115 | // this should look a lot like "blink without delay"
116 | static unsigned long previousmillis = 0;
117 | unsigned long currentmillis = millis();
118 | if (currentmillis - previousmillis >= time) {
119 | previousmillis = currentmillis;
120 | return true;
121 | }
122 | return false;
123 | }
124 |
--------------------------------------------------------------------------------
/examples/CDC/no_serial/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/CDC/no_serial/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/CDC/no_serial/no_serial.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #include "Adafruit_TinyUSB.h"
13 |
14 | /* This sketch demonstrates USB CDC Serial can be dropped by simply
15 | * call Serial.end() within setup(). This must be called before any
16 | * other USB interfaces (MSC / HID) begin to have a clean configuration
17 | *
18 | * Note: this will cause device to loose the touch1200 and require
19 | * user manual interaction to put device into bootloader/DFU mode.
20 | */
21 |
22 | int led = LED_BUILTIN;
23 |
24 | void setup()
25 | {
26 | // Manual begin() is required on core without built-in support e.g. mbed rp2040
27 | if (!TinyUSBDevice.isInitialized()) {
28 | TinyUSBDevice.begin(0);
29 | }
30 |
31 | // clear configuration will remove all USB interfaces including CDC (Serial)
32 | TinyUSBDevice.clearConfiguration();
33 |
34 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
35 | if (TinyUSBDevice.mounted()) {
36 | TinyUSBDevice.detach();
37 | delay(10);
38 | TinyUSBDevice.attach();
39 | }
40 |
41 | pinMode(led, OUTPUT);
42 | }
43 |
44 | void loop()
45 | {
46 | #ifdef TINYUSB_NEED_POLLING_TASK
47 | // Manual call tud_task since it isn't called by Core's background
48 | TinyUSBDevice.task();
49 | #endif
50 |
51 | // toggle LED
52 | static uint32_t ms = 0;
53 | static uint8_t led_state = 0;
54 | if (millis() - ms > 1000) {
55 | ms = millis();
56 | digitalWrite(LED_BUILTIN, 1-led_state);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/examples/CDC/serial_echo/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/CDC/serial_echo/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/CDC/serial_echo/serial_echo.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #include "Adafruit_TinyUSB.h"
13 |
14 | /* This sketch demonstrates USB CDC Serial echo (convert to upper case) using SerialTinyUSB which
15 | * is available for both core with built-in USB support and without.
16 | * Note: on core with built-in support Serial is alias to SerialTinyUSB
17 | */
18 |
19 | void setup() {
20 | // Manual begin() is required on core without built-in support e.g. mbed rp2040
21 | if (!TinyUSBDevice.isInitialized()) {
22 | TinyUSBDevice.begin(0);
23 | }
24 | }
25 |
26 | void loop() {
27 | #ifdef TINYUSB_NEED_POLLING_TASK
28 | // Manual call tud_task since it isn't called by Core's background
29 | TinyUSBDevice.task();
30 | #endif
31 |
32 | uint8_t buf[64];
33 | uint32_t count = 0;
34 | while (SerialTinyUSB.available()) {
35 | buf[count++] = (uint8_t) toupper(SerialTinyUSB.read());
36 | }
37 |
38 | if (count) {
39 | SerialTinyUSB.write(buf, count);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/examples/Composite/mouse_ramdisk/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/Composite/mouse_ramdisk/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/DualRole/CDC/serial_host_bridge/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/DualRole/CDC/serial_host_bridge/usbh_helper.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #ifndef USBH_HELPER_H
13 | #define USBH_HELPER_H
14 |
15 | #ifdef ARDUINO_ARCH_RP2040
16 | // pio-usb is required for rp2040 host
17 | #include "pio_usb.h"
18 |
19 | // Pin D+ for host, D- = D+ + 1
20 | #ifndef PIN_USB_HOST_DP
21 | #define PIN_USB_HOST_DP 16
22 | #endif
23 |
24 | // Pin for enabling Host VBUS. comment out if not used
25 | #ifndef PIN_5V_EN
26 | #define PIN_5V_EN 18
27 | #endif
28 |
29 | #ifndef PIN_5V_EN_STATE
30 | #define PIN_5V_EN_STATE 1
31 | #endif
32 | #endif // ARDUINO_ARCH_RP2040
33 |
34 | #include "Adafruit_TinyUSB.h"
35 |
36 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37 | // USB Host using MAX3421E: SPI, CS, INT
38 | #include "SPI.h"
39 |
40 | #if defined(ARDUINO_METRO_ESP32S2)
41 | Adafruit_USBH_Host USBHost(&SPI, 15, 14);
42 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2)
43 | Adafruit_USBH_Host USBHost(&SPI, 33, 15);
44 | #else
45 | // Default CS and INT are pin 10, 9
46 | Adafruit_USBH_Host USBHost(&SPI, 10, 9);
47 | #endif
48 | #else
49 | // Native USB Host such as rp2040
50 | Adafruit_USBH_Host USBHost;
51 | #endif
52 |
53 | //--------------------------------------------------------------------+
54 | // Helper Functions
55 | //--------------------------------------------------------------------+
56 |
57 | #ifdef ARDUINO_ARCH_RP2040
58 | static void rp2040_configure_pio_usb(void) {
59 | //while ( !Serial ) delay(10); // wait for native usb
60 | Serial.println("Core1 setup to run TinyUSB host with pio-usb");
61 |
62 | // Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
63 | uint32_t cpu_hz = clock_get_hz(clk_sys);
64 | if (cpu_hz != 120000000UL && cpu_hz != 240000000UL) {
65 | while (!Serial) {
66 | delay(10); // wait for native usb
67 | }
68 | Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
69 | Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n");
70 | while (1) {
71 | delay(1);
72 | }
73 | }
74 |
75 | #ifdef PIN_5V_EN
76 | pinMode(PIN_5V_EN, OUTPUT);
77 | digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
78 | #endif
79 |
80 | pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
81 | pio_cfg.pin_dp = PIN_USB_HOST_DP;
82 |
83 | #if defined(ARDUINO_RASPBERRY_PI_PICO_W)
84 | // For pico-w, PIO is also used to communicate with cyw43
85 | // Therefore we need to alternate the pio-usb configuration
86 | // details https://github.com/sekigon-gonnoc/Pico-PIO-USB/issues/46
87 | pio_cfg.sm_tx = 3;
88 | pio_cfg.sm_rx = 2;
89 | pio_cfg.sm_eop = 3;
90 | pio_cfg.pio_rx_num = 0;
91 | pio_cfg.pio_tx_num = 1;
92 | pio_cfg.tx_ch = 9;
93 | #endif
94 |
95 | USBHost.configure_pio_usb(1, &pio_cfg);
96 | }
97 | #endif
98 |
99 | #endif
100 |
--------------------------------------------------------------------------------
/examples/DualRole/HID/hid_device_report/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/DualRole/HID/hid_device_report/usbh_helper.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #ifndef USBH_HELPER_H
13 | #define USBH_HELPER_H
14 |
15 | #ifdef ARDUINO_ARCH_RP2040
16 | // pio-usb is required for rp2040 host
17 | #include "pio_usb.h"
18 |
19 | // Pin D+ for host, D- = D+ + 1
20 | #ifndef PIN_USB_HOST_DP
21 | #define PIN_USB_HOST_DP 16
22 | #endif
23 |
24 | // Pin for enabling Host VBUS. comment out if not used
25 | #ifndef PIN_5V_EN
26 | #define PIN_5V_EN 18
27 | #endif
28 |
29 | #ifndef PIN_5V_EN_STATE
30 | #define PIN_5V_EN_STATE 1
31 | #endif
32 | #endif // ARDUINO_ARCH_RP2040
33 |
34 | #include "Adafruit_TinyUSB.h"
35 |
36 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37 | // USB Host using MAX3421E: SPI, CS, INT
38 | #include "SPI.h"
39 |
40 | #if defined(ARDUINO_METRO_ESP32S2)
41 | Adafruit_USBH_Host USBHost(&SPI, 15, 14);
42 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2)
43 | Adafruit_USBH_Host USBHost(&SPI, 33, 15);
44 | #else
45 | // Default CS and INT are pin 10, 9
46 | Adafruit_USBH_Host USBHost(&SPI, 10, 9);
47 | #endif
48 | #else
49 | // Native USB Host such as rp2040
50 | Adafruit_USBH_Host USBHost;
51 | #endif
52 |
53 | //--------------------------------------------------------------------+
54 | // Helper Functions
55 | //--------------------------------------------------------------------+
56 |
57 | #ifdef ARDUINO_ARCH_RP2040
58 | static void rp2040_configure_pio_usb(void) {
59 | //while ( !Serial ) delay(10); // wait for native usb
60 | Serial.println("Core1 setup to run TinyUSB host with pio-usb");
61 |
62 | // Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
63 | uint32_t cpu_hz = clock_get_hz(clk_sys);
64 | if (cpu_hz != 120000000UL && cpu_hz != 240000000UL) {
65 | while (!Serial) {
66 | delay(10); // wait for native usb
67 | }
68 | Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
69 | Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n");
70 | while (1) {
71 | delay(1);
72 | }
73 | }
74 |
75 | #ifdef PIN_5V_EN
76 | pinMode(PIN_5V_EN, OUTPUT);
77 | digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
78 | #endif
79 |
80 | pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
81 | pio_cfg.pin_dp = PIN_USB_HOST_DP;
82 |
83 | #if defined(ARDUINO_RASPBERRY_PI_PICO_W)
84 | // For pico-w, PIO is also used to communicate with cyw43
85 | // Therefore we need to alternate the pio-usb configuration
86 | // details https://github.com/sekigon-gonnoc/Pico-PIO-USB/issues/46
87 | pio_cfg.sm_tx = 3;
88 | pio_cfg.sm_rx = 2;
89 | pio_cfg.sm_eop = 3;
90 | pio_cfg.pio_rx_num = 0;
91 | pio_cfg.pio_tx_num = 1;
92 | pio_cfg.tx_ch = 9;
93 | #endif
94 |
95 | USBHost.configure_pio_usb(1, &pio_cfg);
96 | }
97 | #endif
98 |
99 | #endif
100 |
--------------------------------------------------------------------------------
/examples/DualRole/HID/hid_mouse_log_filter/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/DualRole/HID/hid_mouse_log_filter/usbh_helper.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #ifndef USBH_HELPER_H
13 | #define USBH_HELPER_H
14 |
15 | #ifdef ARDUINO_ARCH_RP2040
16 | // pio-usb is required for rp2040 host
17 | #include "pio_usb.h"
18 |
19 | // Pin D+ for host, D- = D+ + 1
20 | #ifndef PIN_USB_HOST_DP
21 | #define PIN_USB_HOST_DP 16
22 | #endif
23 |
24 | // Pin for enabling Host VBUS. comment out if not used
25 | #ifndef PIN_5V_EN
26 | #define PIN_5V_EN 18
27 | #endif
28 |
29 | #ifndef PIN_5V_EN_STATE
30 | #define PIN_5V_EN_STATE 1
31 | #endif
32 | #endif // ARDUINO_ARCH_RP2040
33 |
34 | #include "Adafruit_TinyUSB.h"
35 |
36 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37 | // USB Host using MAX3421E: SPI, CS, INT
38 | #include "SPI.h"
39 |
40 | #if defined(ARDUINO_METRO_ESP32S2)
41 | Adafruit_USBH_Host USBHost(&SPI, 15, 14);
42 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2)
43 | Adafruit_USBH_Host USBHost(&SPI, 33, 15);
44 | #else
45 | // Default CS and INT are pin 10, 9
46 | Adafruit_USBH_Host USBHost(&SPI, 10, 9);
47 | #endif
48 | #else
49 | // Native USB Host such as rp2040
50 | Adafruit_USBH_Host USBHost;
51 | #endif
52 |
53 | //--------------------------------------------------------------------+
54 | // Helper Functions
55 | //--------------------------------------------------------------------+
56 |
57 | #ifdef ARDUINO_ARCH_RP2040
58 | static void rp2040_configure_pio_usb(void) {
59 | //while ( !Serial ) delay(10); // wait for native usb
60 | Serial.println("Core1 setup to run TinyUSB host with pio-usb");
61 |
62 | // Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
63 | uint32_t cpu_hz = clock_get_hz(clk_sys);
64 | if (cpu_hz != 120000000UL && cpu_hz != 240000000UL) {
65 | while (!Serial) {
66 | delay(10); // wait for native usb
67 | }
68 | Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
69 | Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n");
70 | while (1) {
71 | delay(1);
72 | }
73 | }
74 |
75 | #ifdef PIN_5V_EN
76 | pinMode(PIN_5V_EN, OUTPUT);
77 | digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
78 | #endif
79 |
80 | pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
81 | pio_cfg.pin_dp = PIN_USB_HOST_DP;
82 |
83 | #if defined(ARDUINO_RASPBERRY_PI_PICO_W)
84 | // For pico-w, PIO is also used to communicate with cyw43
85 | // Therefore we need to alternate the pio-usb configuration
86 | // details https://github.com/sekigon-gonnoc/Pico-PIO-USB/issues/46
87 | pio_cfg.sm_tx = 3;
88 | pio_cfg.sm_rx = 2;
89 | pio_cfg.sm_eop = 3;
90 | pio_cfg.pio_rx_num = 0;
91 | pio_cfg.pio_tx_num = 1;
92 | pio_cfg.tx_ch = 9;
93 | #endif
94 |
95 | USBHost.configure_pio_usb(1, &pio_cfg);
96 | }
97 | #endif
98 |
99 | #endif
100 |
--------------------------------------------------------------------------------
/examples/DualRole/HID/hid_mouse_tremor_filter/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/DualRole/HID/hid_mouse_tremor_filter/usbh_helper.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #ifndef USBH_HELPER_H
13 | #define USBH_HELPER_H
14 |
15 | #ifdef ARDUINO_ARCH_RP2040
16 | // pio-usb is required for rp2040 host
17 | #include "pio_usb.h"
18 |
19 | // Pin D+ for host, D- = D+ + 1
20 | #ifndef PIN_USB_HOST_DP
21 | #define PIN_USB_HOST_DP 16
22 | #endif
23 |
24 | // Pin for enabling Host VBUS. comment out if not used
25 | #ifndef PIN_5V_EN
26 | #define PIN_5V_EN 18
27 | #endif
28 |
29 | #ifndef PIN_5V_EN_STATE
30 | #define PIN_5V_EN_STATE 1
31 | #endif
32 | #endif // ARDUINO_ARCH_RP2040
33 |
34 | #include "Adafruit_TinyUSB.h"
35 |
36 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37 | // USB Host using MAX3421E: SPI, CS, INT
38 | #include "SPI.h"
39 |
40 | #if defined(ARDUINO_METRO_ESP32S2)
41 | Adafruit_USBH_Host USBHost(&SPI, 15, 14);
42 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2)
43 | Adafruit_USBH_Host USBHost(&SPI, 33, 15);
44 | #else
45 | // Default CS and INT are pin 10, 9
46 | Adafruit_USBH_Host USBHost(&SPI, 10, 9);
47 | #endif
48 | #else
49 | // Native USB Host such as rp2040
50 | Adafruit_USBH_Host USBHost;
51 | #endif
52 |
53 | //--------------------------------------------------------------------+
54 | // Helper Functions
55 | //--------------------------------------------------------------------+
56 |
57 | #ifdef ARDUINO_ARCH_RP2040
58 | static void rp2040_configure_pio_usb(void) {
59 | //while ( !Serial ) delay(10); // wait for native usb
60 | Serial.println("Core1 setup to run TinyUSB host with pio-usb");
61 |
62 | // Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
63 | uint32_t cpu_hz = clock_get_hz(clk_sys);
64 | if (cpu_hz != 120000000UL && cpu_hz != 240000000UL) {
65 | while (!Serial) {
66 | delay(10); // wait for native usb
67 | }
68 | Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
69 | Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n");
70 | while (1) {
71 | delay(1);
72 | }
73 | }
74 |
75 | #ifdef PIN_5V_EN
76 | pinMode(PIN_5V_EN, OUTPUT);
77 | digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
78 | #endif
79 |
80 | pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
81 | pio_cfg.pin_dp = PIN_USB_HOST_DP;
82 |
83 | #if defined(ARDUINO_RASPBERRY_PI_PICO_W)
84 | // For pico-w, PIO is also used to communicate with cyw43
85 | // Therefore we need to alternate the pio-usb configuration
86 | // details https://github.com/sekigon-gonnoc/Pico-PIO-USB/issues/46
87 | pio_cfg.sm_tx = 3;
88 | pio_cfg.sm_rx = 2;
89 | pio_cfg.sm_eop = 3;
90 | pio_cfg.pio_rx_num = 0;
91 | pio_cfg.pio_tx_num = 1;
92 | pio_cfg.tx_ch = 9;
93 | #endif
94 |
95 | USBHost.configure_pio_usb(1, &pio_cfg);
96 | }
97 | #endif
98 |
99 | #endif
100 |
--------------------------------------------------------------------------------
/examples/DualRole/HID/hid_remapper/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/DualRole/HID/hid_remapper/usbh_helper.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #ifndef USBH_HELPER_H
13 | #define USBH_HELPER_H
14 |
15 | #ifdef ARDUINO_ARCH_RP2040
16 | // pio-usb is required for rp2040 host
17 | #include "pio_usb.h"
18 |
19 | // Pin D+ for host, D- = D+ + 1
20 | #ifndef PIN_USB_HOST_DP
21 | #define PIN_USB_HOST_DP 16
22 | #endif
23 |
24 | // Pin for enabling Host VBUS. comment out if not used
25 | #ifndef PIN_5V_EN
26 | #define PIN_5V_EN 18
27 | #endif
28 |
29 | #ifndef PIN_5V_EN_STATE
30 | #define PIN_5V_EN_STATE 1
31 | #endif
32 | #endif // ARDUINO_ARCH_RP2040
33 |
34 | #include "Adafruit_TinyUSB.h"
35 |
36 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37 | // USB Host using MAX3421E: SPI, CS, INT
38 | #include "SPI.h"
39 |
40 | #if defined(ARDUINO_METRO_ESP32S2)
41 | Adafruit_USBH_Host USBHost(&SPI, 15, 14);
42 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2)
43 | Adafruit_USBH_Host USBHost(&SPI, 33, 15);
44 | #else
45 | // Default CS and INT are pin 10, 9
46 | Adafruit_USBH_Host USBHost(&SPI, 10, 9);
47 | #endif
48 | #else
49 | // Native USB Host such as rp2040
50 | Adafruit_USBH_Host USBHost;
51 | #endif
52 |
53 | //--------------------------------------------------------------------+
54 | // Helper Functions
55 | //--------------------------------------------------------------------+
56 |
57 | #ifdef ARDUINO_ARCH_RP2040
58 | static void rp2040_configure_pio_usb(void) {
59 | //while ( !Serial ) delay(10); // wait for native usb
60 | Serial.println("Core1 setup to run TinyUSB host with pio-usb");
61 |
62 | // Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
63 | uint32_t cpu_hz = clock_get_hz(clk_sys);
64 | if (cpu_hz != 120000000UL && cpu_hz != 240000000UL) {
65 | while (!Serial) {
66 | delay(10); // wait for native usb
67 | }
68 | Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
69 | Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n");
70 | while (1) {
71 | delay(1);
72 | }
73 | }
74 |
75 | #ifdef PIN_5V_EN
76 | pinMode(PIN_5V_EN, OUTPUT);
77 | digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
78 | #endif
79 |
80 | pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
81 | pio_cfg.pin_dp = PIN_USB_HOST_DP;
82 |
83 | #if defined(ARDUINO_RASPBERRY_PI_PICO_W)
84 | // For pico-w, PIO is also used to communicate with cyw43
85 | // Therefore we need to alternate the pio-usb configuration
86 | // details https://github.com/sekigon-gonnoc/Pico-PIO-USB/issues/46
87 | pio_cfg.sm_tx = 3;
88 | pio_cfg.sm_rx = 2;
89 | pio_cfg.sm_eop = 3;
90 | pio_cfg.pio_rx_num = 0;
91 | pio_cfg.pio_tx_num = 1;
92 | pio_cfg.tx_ch = 9;
93 | #endif
94 |
95 | USBHost.configure_pio_usb(1, &pio_cfg);
96 | }
97 | #endif
98 |
99 | #endif
100 |
--------------------------------------------------------------------------------
/examples/DualRole/MassStorage/msc_data_logger/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/DualRole/MassStorage/msc_data_logger/usbh_helper.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #ifndef USBH_HELPER_H
13 | #define USBH_HELPER_H
14 |
15 | #ifdef ARDUINO_ARCH_RP2040
16 | // pio-usb is required for rp2040 host
17 | #include "pio_usb.h"
18 |
19 | // Pin D+ for host, D- = D+ + 1
20 | #ifndef PIN_USB_HOST_DP
21 | #define PIN_USB_HOST_DP 16
22 | #endif
23 |
24 | // Pin for enabling Host VBUS. comment out if not used
25 | #ifndef PIN_5V_EN
26 | #define PIN_5V_EN 18
27 | #endif
28 |
29 | #ifndef PIN_5V_EN_STATE
30 | #define PIN_5V_EN_STATE 1
31 | #endif
32 | #endif // ARDUINO_ARCH_RP2040
33 |
34 | #include "Adafruit_TinyUSB.h"
35 |
36 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37 | // USB Host using MAX3421E: SPI, CS, INT
38 | #include "SPI.h"
39 |
40 | #if defined(ARDUINO_METRO_ESP32S2)
41 | Adafruit_USBH_Host USBHost(&SPI, 15, 14);
42 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2)
43 | Adafruit_USBH_Host USBHost(&SPI, 33, 15);
44 | #else
45 | // Default CS and INT are pin 10, 9
46 | Adafruit_USBH_Host USBHost(&SPI, 10, 9);
47 | #endif
48 | #else
49 | // Native USB Host such as rp2040
50 | Adafruit_USBH_Host USBHost;
51 | #endif
52 |
53 | //--------------------------------------------------------------------+
54 | // Helper Functions
55 | //--------------------------------------------------------------------+
56 |
57 | #ifdef ARDUINO_ARCH_RP2040
58 | static void rp2040_configure_pio_usb(void) {
59 | //while ( !Serial ) delay(10); // wait for native usb
60 | Serial.println("Core1 setup to run TinyUSB host with pio-usb");
61 |
62 | // Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
63 | uint32_t cpu_hz = clock_get_hz(clk_sys);
64 | if (cpu_hz != 120000000UL && cpu_hz != 240000000UL) {
65 | while (!Serial) {
66 | delay(10); // wait for native usb
67 | }
68 | Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
69 | Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n");
70 | while (1) {
71 | delay(1);
72 | }
73 | }
74 |
75 | #ifdef PIN_5V_EN
76 | pinMode(PIN_5V_EN, OUTPUT);
77 | digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
78 | #endif
79 |
80 | pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
81 | pio_cfg.pin_dp = PIN_USB_HOST_DP;
82 |
83 | #if defined(ARDUINO_RASPBERRY_PI_PICO_W)
84 | // For pico-w, PIO is also used to communicate with cyw43
85 | // Therefore we need to alternate the pio-usb configuration
86 | // details https://github.com/sekigon-gonnoc/Pico-PIO-USB/issues/46
87 | pio_cfg.sm_tx = 3;
88 | pio_cfg.sm_rx = 2;
89 | pio_cfg.sm_eop = 3;
90 | pio_cfg.pio_rx_num = 0;
91 | pio_cfg.pio_tx_num = 1;
92 | pio_cfg.tx_ch = 9;
93 | #endif
94 |
95 | USBHost.configure_pio_usb(1, &pio_cfg);
96 | }
97 | #endif
98 |
99 | #endif
100 |
--------------------------------------------------------------------------------
/examples/DualRole/MassStorage/msc_file_explorer/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/DualRole/MassStorage/msc_file_explorer/msc_file_explorer.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | /* This example demonstrates use of both device and host, where
13 | * - Device run on native usb controller (roothub port0)
14 | * - Host depending on MCUs run on either:
15 | * - rp2040: bit-banging 2 GPIOs with the help of Pico-PIO-USB library (roothub port1)
16 | * - samd21/51, nrf52840, esp32: using MAX3421e controller (host shield)
17 | *
18 | * Requirements:
19 | * - For rp2040:
20 | * - [Pico-PIO-USB](https://github.com/sekigon-gonnoc/Pico-PIO-USB) library
21 | * - 2 consecutive GPIOs: D+ is defined by PIN_USB_HOST_DP, D- = D+ +1
22 | * - Provide VBus (5v) and GND for peripheral
23 | * - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
24 | * - For samd21/51, nrf52840, esp32:
25 | * - Additional MAX2341e USB Host shield or featherwing is required
26 | * - SPI instance, CS pin, INT pin are correctly configured in usbh_helper.h
27 | */
28 |
29 | // SdFat is required for using Adafruit_USBH_MSC_SdFatDevice
30 | #include "SdFat.h"
31 |
32 | // USBHost is defined in usbh_helper.h
33 | #include "usbh_helper.h"
34 |
35 | // USB Host MSC Block Device object which implemented API for use with SdFat
36 | Adafruit_USBH_MSC_BlockDevice msc_block_dev;
37 |
38 | // file system object from SdFat
39 | FatVolume fatfs;
40 |
41 | // if file system is successfully mounted on usb block device
42 | bool is_mounted = false;
43 |
44 | void setup() {
45 | Serial.begin(115200);
46 |
47 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
48 | // init host stack on controller (rhport) 1
49 | // For rp2040: this is called in core1's setup1()
50 | USBHost.begin(1);
51 | #endif
52 |
53 | // while ( !Serial ) delay(10); // wait for native usb
54 | Serial.println("TinyUSB Host Mass Storage File Explorer Example");
55 | }
56 |
57 |
58 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
59 | //--------------------------------------------------------------------+
60 | // Using Host shield MAX3421E controller
61 | //--------------------------------------------------------------------+
62 | void loop() {
63 | USBHost.task();
64 | Serial.flush();
65 | }
66 |
67 | #elif defined(ARDUINO_ARCH_RP2040)
68 | //--------------------------------------------------------------------+
69 | // For RP2040 use both core0 for device stack, core1 for host stack
70 | //--------------------------------------------------------------------+
71 | void loop() {
72 | }
73 |
74 | //------------- Core1 -------------//
75 | void setup1() {
76 | // configure pio-usb: defined in usbh_helper.h
77 | rp2040_configure_pio_usb();
78 |
79 | // run host stack on controller (rhport) 1
80 | // Note: For rp2040 pico-pio-usb, calling USBHost.begin() on core1 will have most of the
81 | // host bit-banging processing works done in core1 to free up core0 for other works
82 | USBHost.begin(1);
83 | }
84 |
85 | void loop1() {
86 | USBHost.task();
87 | }
88 |
89 | #endif
90 |
91 | //--------------------------------------------------------------------+
92 | // TinyUSB Host callbacks
93 | //--------------------------------------------------------------------+
94 | extern "C"
95 | {
96 |
97 | // Invoked when device is mounted (configured)
98 | void tuh_mount_cb(uint8_t daddr) {
99 | (void) daddr;
100 | }
101 |
102 | /// Invoked when device is unmounted (bus reset/unplugged)
103 | void tuh_umount_cb(uint8_t daddr) {
104 | (void) daddr;
105 | }
106 |
107 | // Invoked when a device with MassStorage interface is mounted
108 | void tuh_msc_mount_cb(uint8_t dev_addr) {
109 | Serial.printf("Device attached, address = %d\r\n", dev_addr);
110 |
111 | // Initialize block device with MSC device address
112 | msc_block_dev.begin(dev_addr);
113 |
114 | // For simplicity this example only support LUN 0
115 | msc_block_dev.setActiveLUN(0);
116 |
117 | is_mounted = fatfs.begin(&msc_block_dev);
118 |
119 | if (is_mounted) {
120 | fatfs.ls(&Serial, LS_SIZE);
121 | }
122 | }
123 |
124 | // Invoked when a device with MassStorage interface is unmounted
125 | void tuh_msc_umount_cb(uint8_t dev_addr) {
126 | Serial.printf("Device removed, address = %d\r\n", dev_addr);
127 |
128 | // unmount file system
129 | is_mounted = false;
130 | fatfs.end();
131 |
132 | // end block device
133 | msc_block_dev.end();
134 | }
135 |
136 | }
--------------------------------------------------------------------------------
/examples/DualRole/MassStorage/msc_file_explorer/usbh_helper.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #ifndef USBH_HELPER_H
13 | #define USBH_HELPER_H
14 |
15 | #ifdef ARDUINO_ARCH_RP2040
16 | // pio-usb is required for rp2040 host
17 | #include "pio_usb.h"
18 |
19 | // Pin D+ for host, D- = D+ + 1
20 | #ifndef PIN_USB_HOST_DP
21 | #define PIN_USB_HOST_DP 16
22 | #endif
23 |
24 | // Pin for enabling Host VBUS. comment out if not used
25 | #ifndef PIN_5V_EN
26 | #define PIN_5V_EN 18
27 | #endif
28 |
29 | #ifndef PIN_5V_EN_STATE
30 | #define PIN_5V_EN_STATE 1
31 | #endif
32 | #endif // ARDUINO_ARCH_RP2040
33 |
34 | #include "Adafruit_TinyUSB.h"
35 |
36 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37 | // USB Host using MAX3421E: SPI, CS, INT
38 | #include "SPI.h"
39 |
40 | #if defined(ARDUINO_METRO_ESP32S2)
41 | Adafruit_USBH_Host USBHost(&SPI, 15, 14);
42 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2)
43 | Adafruit_USBH_Host USBHost(&SPI, 33, 15);
44 | #else
45 | // Default CS and INT are pin 10, 9
46 | Adafruit_USBH_Host USBHost(&SPI, 10, 9);
47 | #endif
48 | #else
49 | // Native USB Host such as rp2040
50 | Adafruit_USBH_Host USBHost;
51 | #endif
52 |
53 | //--------------------------------------------------------------------+
54 | // Helper Functions
55 | //--------------------------------------------------------------------+
56 |
57 | #ifdef ARDUINO_ARCH_RP2040
58 | static void rp2040_configure_pio_usb(void) {
59 | //while ( !Serial ) delay(10); // wait for native usb
60 | Serial.println("Core1 setup to run TinyUSB host with pio-usb");
61 |
62 | // Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
63 | uint32_t cpu_hz = clock_get_hz(clk_sys);
64 | if (cpu_hz != 120000000UL && cpu_hz != 240000000UL) {
65 | while (!Serial) {
66 | delay(10); // wait for native usb
67 | }
68 | Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
69 | Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n");
70 | while (1) {
71 | delay(1);
72 | }
73 | }
74 |
75 | #ifdef PIN_5V_EN
76 | pinMode(PIN_5V_EN, OUTPUT);
77 | digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
78 | #endif
79 |
80 | pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
81 | pio_cfg.pin_dp = PIN_USB_HOST_DP;
82 |
83 | #if defined(ARDUINO_RASPBERRY_PI_PICO_W)
84 | // For pico-w, PIO is also used to communicate with cyw43
85 | // Therefore we need to alternate the pio-usb configuration
86 | // details https://github.com/sekigon-gonnoc/Pico-PIO-USB/issues/46
87 | pio_cfg.sm_tx = 3;
88 | pio_cfg.sm_rx = 2;
89 | pio_cfg.sm_eop = 3;
90 | pio_cfg.pio_rx_num = 0;
91 | pio_cfg.pio_tx_num = 1;
92 | pio_cfg.tx_ch = 9;
93 | #endif
94 |
95 | USBHost.configure_pio_usb(1, &pio_cfg);
96 | }
97 | #endif
98 |
99 | #endif
100 |
--------------------------------------------------------------------------------
/examples/DualRole/Simple/device_info/.skip.txt:
--------------------------------------------------------------------------------
1 | CH32V20x_EVT
2 |
--------------------------------------------------------------------------------
/examples/DualRole/Simple/device_info/usbh_helper.h:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #ifndef USBH_HELPER_H
13 | #define USBH_HELPER_H
14 |
15 | #ifdef ARDUINO_ARCH_RP2040
16 | // pio-usb is required for rp2040 host
17 | #include "pio_usb.h"
18 |
19 | // Pin D+ for host, D- = D+ + 1
20 | #ifndef PIN_USB_HOST_DP
21 | #define PIN_USB_HOST_DP 16
22 | #endif
23 |
24 | // Pin for enabling Host VBUS. comment out if not used
25 | #ifndef PIN_5V_EN
26 | #define PIN_5V_EN 18
27 | #endif
28 |
29 | #ifndef PIN_5V_EN_STATE
30 | #define PIN_5V_EN_STATE 1
31 | #endif
32 | #endif // ARDUINO_ARCH_RP2040
33 |
34 | #include "Adafruit_TinyUSB.h"
35 |
36 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37 | // USB Host using MAX3421E: SPI, CS, INT
38 | #include "SPI.h"
39 |
40 | #if defined(ARDUINO_METRO_ESP32S2)
41 | Adafruit_USBH_Host USBHost(&SPI, 15, 14);
42 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_ESP32_V2)
43 | Adafruit_USBH_Host USBHost(&SPI, 33, 15);
44 | #else
45 | // Default CS and INT are pin 10, 9
46 | Adafruit_USBH_Host USBHost(&SPI, 10, 9);
47 | #endif
48 | #else
49 | // Native USB Host such as rp2040
50 | Adafruit_USBH_Host USBHost;
51 | #endif
52 |
53 | //--------------------------------------------------------------------+
54 | // Helper Functions
55 | //--------------------------------------------------------------------+
56 |
57 | #ifdef ARDUINO_ARCH_RP2040
58 | static void rp2040_configure_pio_usb(void) {
59 | //while ( !Serial ) delay(10); // wait for native usb
60 | Serial.println("Core1 setup to run TinyUSB host with pio-usb");
61 |
62 | // Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
63 | uint32_t cpu_hz = clock_get_hz(clk_sys);
64 | if (cpu_hz != 120000000UL && cpu_hz != 240000000UL) {
65 | while (!Serial) {
66 | delay(10); // wait for native usb
67 | }
68 | Serial.printf("Error: CPU Clock = %lu, PIO USB require CPU clock must be multiple of 120 Mhz\r\n", cpu_hz);
69 | Serial.printf("Change your CPU Clock to either 120 or 240 Mhz in Menu->CPU Speed \r\n");
70 | while (1) {
71 | delay(1);
72 | }
73 | }
74 |
75 | #ifdef PIN_5V_EN
76 | pinMode(PIN_5V_EN, OUTPUT);
77 | digitalWrite(PIN_5V_EN, PIN_5V_EN_STATE);
78 | #endif
79 |
80 | pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
81 | pio_cfg.pin_dp = PIN_USB_HOST_DP;
82 |
83 | #if defined(ARDUINO_RASPBERRY_PI_PICO_W)
84 | // For pico-w, PIO is also used to communicate with cyw43
85 | // Therefore we need to alternate the pio-usb configuration
86 | // details https://github.com/sekigon-gonnoc/Pico-PIO-USB/issues/46
87 | pio_cfg.sm_tx = 3;
88 | pio_cfg.sm_rx = 2;
89 | pio_cfg.sm_eop = 3;
90 | pio_cfg.pio_rx_num = 0;
91 | pio_cfg.pio_tx_num = 1;
92 | pio_cfg.tx_ch = 9;
93 | #endif
94 |
95 | USBHost.configure_pio_usb(1, &pio_cfg);
96 | }
97 | #endif
98 |
99 | #endif
100 |
--------------------------------------------------------------------------------
/examples/DualRole/Simple/device_info_max3421e/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/HID/hid_boot_keyboard/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/HID/hid_boot_keyboard/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/HID/hid_boot_mouse/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/HID/hid_boot_mouse/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/HID/hid_boot_mouse/hid_boot_mouse.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #include "Adafruit_TinyUSB.h"
13 |
14 | /* This sketch demonstrates USB HID mouse
15 | * Press button pin will move
16 | * - mouse toward bottom right of monitor
17 | *
18 | * Depending on the board, the button pin
19 | * and its active state (when pressed) are different
20 | */
21 | #if defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(ARDUINO_NRF52840_CIRCUITPLAY)
22 | const int pin = 4; // Left Button
23 | bool activeState = true;
24 |
25 | #elif defined(ARDUINO_FUNHOUSE_ESP32S2)
26 | const int pin = BUTTON_DOWN;
27 | bool activeState = true;
28 |
29 | #elif defined PIN_BUTTON1
30 | const int pin = PIN_BUTTON1;
31 | bool activeState = false;
32 |
33 | #elif defined(ARDUINO_ARCH_ESP32)
34 | const int pin = 0;
35 | bool activeState = false;
36 |
37 | #elif defined(ARDUINO_ARCH_RP2040)
38 | const int pin = D0;
39 | bool activeState = false;
40 | #else
41 | const int pin = A0;
42 | bool activeState = false;
43 | #endif
44 |
45 |
46 | // HID report descriptor using TinyUSB's template
47 | // Single Report (no ID) descriptor
48 | uint8_t const desc_hid_report[] = {
49 | TUD_HID_REPORT_DESC_MOUSE()
50 | };
51 |
52 | // USB HID object
53 | Adafruit_USBD_HID usb_hid;
54 |
55 | // the setup function runs once when you press reset or power the board
56 | void setup() {
57 | // Manual begin() is required on core without built-in support e.g. mbed rp2040
58 | if (!TinyUSBDevice.isInitialized()) {
59 | TinyUSBDevice.begin(0);
60 | }
61 |
62 | Serial.begin(115200);
63 |
64 | // Set up button, pullup opposite to active state
65 | pinMode(pin, activeState ? INPUT_PULLDOWN : INPUT_PULLUP);
66 |
67 | // Set up HID
68 | usb_hid.setBootProtocol(HID_ITF_PROTOCOL_MOUSE);
69 | usb_hid.setPollInterval(2);
70 | usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
71 | usb_hid.setStringDescriptor("TinyUSB Mouse");
72 | usb_hid.begin();
73 |
74 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
75 | if (TinyUSBDevice.mounted()) {
76 | TinyUSBDevice.detach();
77 | delay(10);
78 | TinyUSBDevice.attach();
79 | }
80 |
81 | Serial.println("Adafruit TinyUSB HID Mouse example");
82 | }
83 |
84 | void process_hid() {
85 | // Whether button is pressed
86 | bool btn_pressed = (digitalRead(pin) == activeState);
87 |
88 | // nothing to do if button is not pressed
89 | if (!btn_pressed) return;
90 |
91 | // Remote wakeup
92 | if (TinyUSBDevice.suspended()) {
93 | // Wake up host if we are in suspend mode
94 | // and REMOTE_WAKEUP feature is enabled by host
95 | TinyUSBDevice.remoteWakeup();
96 | }
97 |
98 | if (usb_hid.ready()) {
99 | uint8_t const report_id = 0; // no ID
100 | int8_t const delta = 5;
101 | usb_hid.mouseMove(report_id, delta, delta); // right + down
102 | }
103 | }
104 |
105 | void loop() {
106 | #ifdef TINYUSB_NEED_POLLING_TASK
107 | // Manual call tud_task since it isn't called by Core's background
108 | TinyUSBDevice.task();
109 | #endif
110 |
111 | // not enumerated()/mounted() yet: nothing to do
112 | if (!TinyUSBDevice.mounted()) {
113 | return;
114 | }
115 |
116 | // poll gpio once each 10 ms
117 | static uint32_t ms = 0;
118 | if (millis() - ms > 10) {
119 | ms = millis();
120 | process_hid();
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/examples/HID/hid_composite/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/HID/hid_composite/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/HID/hid_composite_joy_featherwing/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/HID/hid_dual_interfaces/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/HID/hid_dual_interfaces/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/HID/hid_gamepad/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/HID/hid_gamepad/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/HID/hid_generic_inout/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/HID/hid_generic_inout/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/HID/hid_generic_inout/README.md:
--------------------------------------------------------------------------------
1 | Instructions for node.js based example
2 |
3 | ===Setup===
4 |
5 | 1. Upload example code to your board
6 | 2. Install node.js if you haven't already
7 | 3. Run `npm install` to install the dependencies
8 | 4. If this should fail on windows try installing the build tools via `npm i -g windows-build-tools`
9 | 5. While the board is connected run `node hid_test.js`
10 | 6. If this should fail make sure the VID and PID of your board is listed in boards.js
--------------------------------------------------------------------------------
/examples/HID/hid_generic_inout/boards.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "Adafruit Boards":[0x239A,0xFFFF],
3 | "TinyUSB example":[0xCAFE,0xFFFF]
4 | }
5 |
--------------------------------------------------------------------------------
/examples/HID/hid_generic_inout/hid_generic_inout.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | /* This example demonstrate HID Generic raw Input & Output.
13 | * It will receive data from Host (In endpoint) and echo back (Out endpoint).
14 | * HID Report descriptor use vendor for usage page (using template TUD_HID_REPORT_DESC_GENERIC_INOUT)
15 | *
16 | * There are 2 ways to test the sketch
17 | * 1. Using nodejs
18 | * - Install nodejs and npm to your PC
19 | *
20 | * - Install excellent node-hid (https://github.com/node-hid/node-hid) by
21 | * $ npm install node-hid
22 | *
23 | * - Run provided hid test script
24 | * $ node hid_test.js
25 | *
26 | * 2. Using python
27 | * - Install `hid` package (https://pypi.org/project/hid/) by
28 | * $ pip install hid
29 | *
30 | * - hid package replies on hidapi (https://github.com/libusb/hidapi) for backend,
31 | * which already available in Linux. However on windows, you may need to download its dlls from their release page and
32 | * copy it over to folder where python is installed.
33 | *
34 | * - Run provided hid test script to send and receive data to this device.
35 | * $ python3 hid_test.py
36 | */
37 |
38 | #include "Adafruit_TinyUSB.h"
39 |
40 | // HID report descriptor using TinyUSB's template
41 | // Generic In Out with 64 bytes report (max)
42 | uint8_t const desc_hid_report[] = {
43 | TUD_HID_REPORT_DESC_GENERIC_INOUT(64)
44 | };
45 |
46 | // USB HID object
47 | Adafruit_USBD_HID usb_hid;
48 |
49 | // the setup function runs once when you press reset or power the board
50 | void setup() {
51 | // Manual begin() is required on core without built-in support e.g. mbed rp2040
52 | if (!TinyUSBDevice.isInitialized()) {
53 | TinyUSBDevice.begin(0);
54 | }
55 |
56 | Serial.begin(115200);
57 |
58 | // Notes: following commented-out functions has no affect on ESP32
59 | usb_hid.enableOutEndpoint(true);
60 | usb_hid.setPollInterval(2);
61 | usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
62 | usb_hid.setStringDescriptor("TinyUSB HID Generic");
63 | usb_hid.setReportCallback(get_report_callback, set_report_callback);
64 | usb_hid.begin();
65 |
66 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
67 | if (TinyUSBDevice.mounted()) {
68 | TinyUSBDevice.detach();
69 | delay(10);
70 | TinyUSBDevice.attach();
71 | }
72 |
73 | Serial.println("Adafruit TinyUSB HID Generic In Out example");
74 | }
75 |
76 | void loop() {
77 | #ifdef TINYUSB_NEED_POLLING_TASK
78 | // Manual call tud_task since it isn't called by Core's background
79 | TinyUSBDevice.task();
80 | #endif
81 | }
82 |
83 | // Invoked when received GET_REPORT control request
84 | // Application must fill buffer report's content and return its length.
85 | // Return zero will cause the stack to STALL request
86 | uint16_t get_report_callback(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) {
87 | // not used in this example
88 | (void) report_id;
89 | (void) report_type;
90 | (void) buffer;
91 | (void) reqlen;
92 | return 0;
93 | }
94 |
95 | // Invoked when received SET_REPORT control request or
96 | // received data on OUT endpoint ( Report ID = 0, Type = 0 )
97 | void set_report_callback(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
98 | // This example doesn't use multiple report and report ID
99 | (void) report_id;
100 | (void) report_type;
101 |
102 | // echo back anything we received from host
103 | usb_hid.sendReport(0, buffer, bufsize);
104 | }
105 |
--------------------------------------------------------------------------------
/examples/HID/hid_generic_inout/hid_test.js:
--------------------------------------------------------------------------------
1 | // IMPORTANT: install the dependency via 'npm i node-hid' in the same location as the script
2 | // If the install fails on windows you may need to run 'npm i -g windows-build-tools' first to be able to compile native code needed for this library
3 |
4 | var HID = require('node-hid');
5 | var os = require('os')
6 | // list of supported devices
7 | var boards = require('./boards.js')
8 | var devices = HID.devices();
9 |
10 | // this will choose any device found in the boards.js file
11 | var deviceInfo = devices.find(anySupportedBoard);
12 | var reportLen = 64;
13 |
14 | var message = "Hello World!"
15 |
16 | // Turn our string into an array of integers e.g. 'ascii codes', though charCodeAt spits out UTF-16
17 | // This means if you have characters in your string that are not Latin-1 you will have to add additional logic for character codes above 255
18 | var messageBuffer = Array.from(message, function(c){return c.charCodeAt(0)});
19 |
20 | // HIDAPI requires us to prepend a 0 for single hid report as dummy reportID
21 | messageBuffer.unshift(0)
22 |
23 | // Some OSes expect that you always send a buffer that equals your report length
24 | // So lets fill up the rest of the buffer with zeros
25 | var paddingBuf = Array(reportLen-messageBuffer.length);
26 | paddingBuf.fill(0)
27 | messageBuffer = messageBuffer.concat(paddingBuf)
28 |
29 | // check if we actually found a device and if so send our messageBuffer to it
30 | if( deviceInfo ) {
31 | console.log(deviceInfo)
32 | var device = new HID.HID( deviceInfo.path );
33 |
34 | // register an event listener for data coming from the device
35 | device.on("data", function(data) {
36 | // Print what we get from the device
37 | console.log(data.toString('ascii'));
38 | });
39 |
40 | // the same for any error that occur
41 | device.on("error", function(err) {console.log(err)});
42 |
43 | // send our message to the device every 500ms
44 | setInterval(function () {
45 | device.write(messageBuffer);
46 | },500)
47 | }
48 |
49 |
50 | function anySupportedBoard(d) {
51 |
52 | for (var key in boards) {
53 | if (boards.hasOwnProperty(key)) {
54 | if (isDevice(boards[key],d)) {
55 | console.log("Found " + d.product);
56 | return true;
57 | }
58 | }
59 | }
60 | return false;
61 | }
62 |
63 |
64 | function isDevice(board,d){
65 | // product id 0xff is matches all
66 | return d.vendorId==board[0] && (d.productId==board[1] || board[1] == 0xFFFF);
67 | }
68 |
69 |
--------------------------------------------------------------------------------
/examples/HID/hid_generic_inout/hid_test.py:
--------------------------------------------------------------------------------
1 | # Install python3 HID package https://pypi.org/project/hid/
2 | import hid
3 |
4 | # default is TinyUSB (0xcafe), Adafruit (0x239a), RaspberryPi (0x2e8a), Espressif (0x303a) VID
5 | USB_VID = (0xcafe, 0x239a, 0x2e8a, 0x303a)
6 |
7 | print("VID list: " + ", ".join('%02x' % v for v in USB_VID))
8 |
9 | for vid in USB_VID:
10 | for dict in hid.enumerate(vid):
11 | print(dict)
12 | dev = hid.Device(dict['vendor_id'], dict['product_id'])
13 | if dev:
14 | while True:
15 | # Get input from console and encode to UTF8 for array of chars.
16 | # hid generic inout is single report therefore by HIDAPI requirement
17 | # it must be preceded with 0x00 as dummy reportID
18 | str_out = b'\x00'
19 | str_out += input("Send text to HID Device : ").encode('utf-8')
20 | dev.write(str_out)
21 | str_in = dev.read(64)
22 | print("Received from HID Device:", str_in, '\n')
23 |
--------------------------------------------------------------------------------
/examples/HID/hid_generic_inout/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hid_example",
3 | "version": "1.0.0",
4 | "description": "Test application for hid_generic_inout example sketch",
5 | "main": "hid_test.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "author": "Timon, Tod E. Kurt",
10 | "license": "MIT",
11 | "dependencies": {
12 | "node-hid": "^0.7.9"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/examples/Host/Simple/host_device_info/.pico_rp2040_tinyusb_host.test.only:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/Host/Simple/host_device_info/.pico_rp2040_tinyusb_host.test.only
--------------------------------------------------------------------------------
/examples/MIDI/midi_multi_ports/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/MIDI/midi_multi_ports/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/MIDI/midi_multi_ports/midi_multi_ports.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | // This sketch is enumerated as USB MIDI device with multiple ports
13 | // and how to set their name
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | // USB MIDI object with 3 ports
20 | Adafruit_USBD_MIDI usb_midi(3);
21 |
22 | void setup() {
23 | pinMode(LED_BUILTIN, OUTPUT);
24 |
25 | // Manual begin() is required on core without built-in support e.g. mbed rp2040
26 | if (!TinyUSBDevice.isInitialized()) {
27 | TinyUSBDevice.begin(0);
28 | }
29 |
30 | // Set name for each cable, must be done before usb_midi.begin()
31 | usb_midi.setCableName(1, "Keyboard");
32 | usb_midi.setCableName(2, "Drum Pads");
33 | usb_midi.setCableName(3, "Lights");
34 | usb_midi.begin();
35 |
36 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
37 | if (TinyUSBDevice.mounted()) {
38 | TinyUSBDevice.detach();
39 | delay(10);
40 | TinyUSBDevice.attach();
41 | }
42 | }
43 |
44 | void loop() {
45 | #ifdef TINYUSB_NEED_POLLING_TASK
46 | // Manual call tud_task since it isn't called by Core's background
47 | TinyUSBDevice.task();
48 | #endif
49 |
50 | // toggle LED
51 | static uint32_t ms = 0;
52 | static uint8_t led_state = 0;
53 | if (millis() - ms > 1000) {
54 | ms = millis();
55 | digitalWrite(LED_BUILTIN, 1-led_state);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/examples/MIDI/midi_pizza_box_dj/.cpb.test.only:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/MIDI/midi_pizza_box_dj/.cpb.test.only
--------------------------------------------------------------------------------
/examples/MIDI/midi_pizza_box_dj/.cpx_ada.test.only:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/MIDI/midi_pizza_box_dj/.cpx_ada.test.only
--------------------------------------------------------------------------------
/examples/MIDI/midi_test/.pico_rp2040_tinyusb_host.test.skip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/MIDI/midi_test/.pico_rp2040_tinyusb_host.test.skip
--------------------------------------------------------------------------------
/examples/MIDI/midi_test/midi_test.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | /* This sketch is enumerated as USB MIDI device.
13 | * Following library is required
14 | * - MIDI Library by Forty Seven Effects
15 | * https://github.com/FortySevenEffects/arduino_midi_library
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | // USB MIDI object
23 | Adafruit_USBD_MIDI usb_midi;
24 |
25 | // Create a new instance of the Arduino MIDI Library,
26 | // and attach usb_midi as the transport.
27 | MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDI);
28 |
29 | // Variable that holds the current position in the sequence.
30 | uint32_t position = 0;
31 |
32 | // Store example melody as an array of note values
33 | byte note_sequence[] = {
34 | 74, 78, 81, 86, 90, 93, 98, 102, 57, 61, 66, 69, 73, 78, 81, 85, 88, 92, 97, 100, 97, 92, 88, 85, 81, 78,
35 | 74, 69, 66, 62, 57, 62, 66, 69, 74, 78, 81, 86, 90, 93, 97, 102, 97, 93, 90, 85, 81, 78, 73, 68, 64, 61,
36 | 56, 61, 64, 68, 74, 78, 81, 86, 90, 93, 98, 102
37 | };
38 |
39 | void setup() {
40 | // Manual begin() is required on core without built-in support e.g. mbed rp2040
41 | if (!TinyUSBDevice.isInitialized()) {
42 | TinyUSBDevice.begin(0);
43 | }
44 |
45 | Serial.begin(115200);
46 |
47 | pinMode(LED_BUILTIN, OUTPUT);
48 |
49 | usb_midi.setStringDescriptor("TinyUSB MIDI");
50 |
51 | // Initialize MIDI, and listen to all MIDI channels
52 | // This will also call usb_midi's begin()
53 | MIDI.begin(MIDI_CHANNEL_OMNI);
54 |
55 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
56 | if (TinyUSBDevice.mounted()) {
57 | TinyUSBDevice.detach();
58 | delay(10);
59 | TinyUSBDevice.attach();
60 | }
61 |
62 | // Attach the handleNoteOn function to the MIDI Library. It will
63 | // be called whenever the Bluefruit receives MIDI Note On messages.
64 | MIDI.setHandleNoteOn(handleNoteOn);
65 |
66 | // Do the same for MIDI Note Off messages.
67 | MIDI.setHandleNoteOff(handleNoteOff);
68 | }
69 |
70 | void loop() {
71 | #ifdef TINYUSB_NEED_POLLING_TASK
72 | // Manual call tud_task since it isn't called by Core's background
73 | TinyUSBDevice.task();
74 | #endif
75 |
76 | // not enumerated()/mounted() yet: nothing to do
77 | if (!TinyUSBDevice.mounted()) {
78 | return;
79 | }
80 |
81 | static uint32_t start_ms = 0;
82 | if (millis() - start_ms > 266) {
83 | start_ms += 266;
84 |
85 | // Setup variables for the current and previous
86 | // positions in the note sequence.
87 | int previous = position - 1;
88 |
89 | // If we currently are at position 0, set the
90 | // previous position to the last note in the sequence.
91 | if (previous < 0) {
92 | previous = sizeof(note_sequence) - 1;
93 | }
94 |
95 | // Send Note On for current position at full velocity (127) on channel 1.
96 | MIDI.sendNoteOn(note_sequence[position], 127, 1);
97 |
98 | // Send Note Off for previous note.
99 | MIDI.sendNoteOff(note_sequence[previous], 0, 1);
100 |
101 | // Increment position
102 | position++;
103 |
104 | // If we are at the end of the sequence, start over.
105 | if (position >= sizeof(note_sequence)) {
106 | position = 0;
107 | }
108 | }
109 |
110 | // read any new MIDI messages
111 | MIDI.read();
112 | }
113 |
114 | void handleNoteOn(byte channel, byte pitch, byte velocity) {
115 | // Log when a note is pressed.
116 | Serial.print("Note on: channel = ");
117 | Serial.print(channel);
118 |
119 | Serial.print(" pitch = ");
120 | Serial.print(pitch);
121 |
122 | Serial.print(" velocity = ");
123 | Serial.println(velocity);
124 | }
125 |
126 | void handleNoteOff(byte channel, byte pitch, byte velocity) {
127 | // Log when a note is released.
128 | Serial.print("Note off: channel = ");
129 | Serial.print(channel);
130 |
131 | Serial.print(" pitch = ");
132 | Serial.print(pitch);
133 |
134 | Serial.print(" velocity = ");
135 | Serial.println(velocity);
136 | }
137 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_esp32_file_browser/.funhouse.test.only:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/MassStorage/msc_esp32_file_browser/.funhouse.test.only
--------------------------------------------------------------------------------
/examples/MassStorage/msc_esp32_file_browser/.magtag.test.only:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/MassStorage/msc_esp32_file_browser/.magtag.test.only
--------------------------------------------------------------------------------
/examples/MassStorage/msc_esp32_file_browser/.metroesp32s2.test.only:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/MassStorage/msc_esp32_file_browser/.metroesp32s2.test.only
--------------------------------------------------------------------------------
/examples/MassStorage/msc_esp32_file_browser/data/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/MassStorage/msc_esp32_file_browser/data/favicon.ico
--------------------------------------------------------------------------------
/examples/MassStorage/msc_esp32_file_browser/data/graphs.js:
--------------------------------------------------------------------------------
1 | eval(function(p,a,c,k,e,r){e=function(c){return(c35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('8 H(t){K 21.1Y(t)}8 9(a,b){a.1S(b)}8 1O(b,t,w,h,l,m,d,f,j){6(Q b==="S"||!b)K 1f;6(Q d==="S"||!d)d=1P;w=(w>1b)?w:1b;h=(h<1N)?1N:h;4 k=1M 1L();4 n="V";4 o=(Q f==="S"&&f)?"1J":f;4 p="#1I";4 q=(Q j==="S"&&j)?1f:j;4 r=m;4 s=0;4 u=1;4 x=l;4 y=h+20;b.7.1H="1G";b.7.1F="#1s";b.7.1c="12 11 "+p;b.7.1D="N";b.7.1C="N";b.7.P=(w+2)+"1B";4 g=H("1a");g.7.1c="12 11 "+p;g.7.1z="N";g.P=w;g.1w=y;4 c=g.1v("2d");4 z=H("1j");z.M="1u: ";z.7.1m="N";4 A=H("1p");A.1i="1r";A.1e=3;A.I=u;A.1h=8(e){u=A.I};4 B=H("T");B.M="-";B.U=8(e){6(u>1)u--;A.I=u};4 C=H("T");C.M="+";C.U=8(e){u++;A.I=1n(u)};4 D=H("1j");D.M="1Q: ";D.7.1m="N";4 E=H("1p");E.1i="1r";E.1e=5;E.I=x;E.1h=8(e){x=1n(E.I)};4 F=H("T");F.M="-";F.U=8(e){6(x>l)x--;E.I=x};4 G=H("T");G.M="+";G.U=8(e){6(x(((m-l)/u)+x))K h;K 1d.1o((v-x)*(h/((m-l)/u)))}g.1x=8(v){6(q)v=q(v);k.1y(v);6(vs)s=v;6(k.L>w)k.1A();c.1a.P=w;c.1g=1;c.17=2;c.Y="V";c.O=p;c.J(0,0,w,20);c.O=o;c.X="1q Z";4 a=t+": "+(k[k.L-1])+" | 1U: "+r+" | 23: "+s;c.W(a,5,15);c.O=n;c.J(0,20,w,y);c.1K=o;18(4 i=0;i1b)?w:1b;h=(h<20)?20:h;4 l=1M 1L();4 n="V";4 o=(Q k==="S"&&k)?"1X":k;4 q="#1I";4 r=1;4 u=h+20;j.7.1H="1G";j.7.1F="#1s";j.7.1c="12 11 "+q;j.7.1D="N";j.7.1C="N";j.7.P=(w+2)+"1B";4 g=H("1a");g.7.1c="12 11 "+q;g.7.1z="N";g.P=w;g.1w=u;4 c=g.1v("2d");4 x=H("1j");x.M="1u: ";x.7.1m="N";4 y=H("1p");y.1i="1r";y.1e=3;y.I=r;y.1h=8(e){r=y.I};4 z=H("T");z.M="-";z.U=8(e){6(r>1)r--;y.I=r};4 A=H("T");A.M="+";A.U=8(e){r++;y.I=1n(r)};9(j,x);9(j,z);9(j,y);9(j,A);9(j,H("1E"));9(j,g);8 1l(p){4 a=1d.1Z(((h-((m.L-1)*2))/m.L));4 s=(p*2)+(p*a);K[s,s+a]}8 1k(i,p){K((l[i]&(1<w)l.1A();c.1a.P=w;c.1g=1;c.17=2;c.Y="V";c.O=q;c.J(0,0,w,20);c.O=o;c.X="1q Z";c.W(t,5,15);c.O=n;c.J(0,20,w,u);c.1K=q;c.1g=1;c.17=0;c.Y="";18(4 p=0;p
18 |
19 |
20 |
21 |
22 | ESP Monitor
23 |
24 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_external_flash/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_external_flash/flash_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef FLASH_CONFIG_H_
26 | #define FLASH_CONFIG_H_
27 |
28 | // Un-comment to run example with custom SPI and SS e.g with FRAM breakout
29 | // #define CUSTOM_CS A5
30 | // #define CUSTOM_SPI SPI
31 |
32 | #if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
33 | Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
34 |
35 | #elif defined(ARDUINO_ARCH_ESP32)
36 |
37 | // ESP32 use same flash device that store code for file system.
38 | // SPIFlash will parse partition.cvs to detect FATFS partition to use
39 | Adafruit_FlashTransport_ESP32 flashTransport;
40 |
41 | #elif defined(ARDUINO_ARCH_RP2040)
42 |
43 | // RP2040 use same flash device that store code for file system. Therefore we
44 | // only need to specify start address and size (no need SPI or SS)
45 | // By default (start=0, size=0), values that match file system setting in
46 | // 'Tools->Flash Size' menu selection will be used.
47 | Adafruit_FlashTransport_RP2040 flashTransport;
48 |
49 | // To be compatible with CircuitPython partition scheme (start_address = 1 MB,
50 | // size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
51 | // subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
52 | // following line:
53 | // Adafruit_FlashTransport_RP2040
54 | // flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
55 | // Adafruit_FlashTransport_RP2040::CPY_SIZE);
56 | // Adafruit_FlashTransport_RP2040_CPY flashTransport;
57 |
58 | #else
59 |
60 | // On-board external flash (QSPI or SPI) macros should already
61 | // defined in your board variant if supported
62 | // - EXTERNAL_FLASH_USE_QSPI
63 | // - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
64 |
65 | #if defined(EXTERNAL_FLASH_USE_QSPI)
66 |
67 | Adafruit_FlashTransport_QSPI flashTransport;
68 |
69 | #elif defined(EXTERNAL_FLASH_USE_SPI)
70 |
71 | Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
72 | EXTERNAL_FLASH_USE_SPI);
73 |
74 | #else
75 | #error No (Q)SPI flash are defined for your board !
76 | #endif
77 | #endif
78 |
79 | #endif
80 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_external_flash_sdcard/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_external_flash_sdcard/flash_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef FLASH_CONFIG_H_
26 | #define FLASH_CONFIG_H_
27 |
28 | // Un-comment to run example with custom SPI and SS e.g with FRAM breakout
29 | // #define CUSTOM_CS A5
30 | // #define CUSTOM_SPI SPI
31 |
32 | #if defined(CUSTOM_CS) && defined(CUSTOM_SPI)
33 | Adafruit_FlashTransport_SPI flashTransport(CUSTOM_CS, CUSTOM_SPI);
34 |
35 | #elif defined(ARDUINO_ARCH_ESP32)
36 |
37 | // ESP32 use same flash device that store code for file system.
38 | // SPIFlash will parse partition.cvs to detect FATFS partition to use
39 | Adafruit_FlashTransport_ESP32 flashTransport;
40 |
41 | #elif defined(ARDUINO_ARCH_RP2040)
42 |
43 | // RP2040 use same flash device that store code for file system. Therefore we
44 | // only need to specify start address and size (no need SPI or SS)
45 | // By default (start=0, size=0), values that match file system setting in
46 | // 'Tools->Flash Size' menu selection will be used.
47 | Adafruit_FlashTransport_RP2040 flashTransport;
48 |
49 | // To be compatible with CircuitPython partition scheme (start_address = 1 MB,
50 | // size = total flash - 1 MB) use const value (CPY_START_ADDR, CPY_SIZE) or
51 | // subclass Adafruit_FlashTransport_RP2040_CPY. Un-comment either of the
52 | // following line:
53 | // Adafruit_FlashTransport_RP2040
54 | // flashTransport(Adafruit_FlashTransport_RP2040::CPY_START_ADDR,
55 | // Adafruit_FlashTransport_RP2040::CPY_SIZE);
56 | // Adafruit_FlashTransport_RP2040_CPY flashTransport;
57 |
58 | #else
59 |
60 | // On-board external flash (QSPI or SPI) macros should already
61 | // defined in your board variant if supported
62 | // - EXTERNAL_FLASH_USE_QSPI
63 | // - EXTERNAL_FLASH_USE_CS/EXTERNAL_FLASH_USE_SPI
64 |
65 | #if defined(EXTERNAL_FLASH_USE_QSPI)
66 |
67 | Adafruit_FlashTransport_QSPI flashTransport;
68 |
69 | #elif defined(EXTERNAL_FLASH_USE_SPI)
70 |
71 | Adafruit_FlashTransport_SPI flashTransport(EXTERNAL_FLASH_USE_CS,
72 | EXTERNAL_FLASH_USE_SPI);
73 |
74 | #else
75 | #error No (Q)SPI flash are defined for your board !
76 | #endif
77 | #endif
78 |
79 | #endif
80 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_internal_flash_samd/.metro_m0_tinyusb.test.only:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pschatzmann/Adafruit_TinyUSB_Arduino/43ad4172584f6daca62557c0e012ca3047c6c546/examples/MassStorage/msc_internal_flash_samd/.metro_m0_tinyusb.test.only
--------------------------------------------------------------------------------
/examples/MassStorage/msc_ramdisk/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_ramdisk/msc_ramdisk.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #include "Adafruit_TinyUSB.h"
13 |
14 | // 8KB is the smallest size that windows allow to mount
15 | #define DISK_BLOCK_NUM 16
16 | #define DISK_BLOCK_SIZE 512
17 |
18 | #include "ramdisk.h"
19 |
20 | Adafruit_USBD_MSC usb_msc;
21 |
22 | // Eject button to demonstrate medium is not ready e.g SDCard is not present
23 | // whenever this button is pressed and hold, it will report to host as not ready
24 | #if defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(ARDUINO_NRF52840_CIRCUITPLAY)
25 | #define BTN_EJECT 4 // Left Button
26 | bool activeState = true;
27 |
28 | #elif defined(ARDUINO_FUNHOUSE_ESP32S2)
29 | #define BTN_EJECT BUTTON_DOWN
30 | bool activeState = true;
31 |
32 | #elif defined PIN_BUTTON1
33 | #define BTN_EJECT PIN_BUTTON1
34 | bool activeState = false;
35 | #endif
36 |
37 |
38 | // the setup function runs once when you press reset or power the board
39 | void setup() {
40 | // Manual begin() is required on core without built-in support e.g. mbed rp2040
41 | if (!TinyUSBDevice.isInitialized()) {
42 | TinyUSBDevice.begin(0);
43 | }
44 |
45 | Serial.begin(115200);
46 |
47 | #ifdef BTN_EJECT
48 | pinMode(BTN_EJECT, activeState ? INPUT_PULLDOWN : INPUT_PULLUP);
49 | #endif
50 |
51 | // Set disk vendor id, product id and revision with string up to 8, 16, 4 characters respectively
52 | usb_msc.setID("Adafruit", "Mass Storage", "1.0");
53 |
54 | // Set disk size
55 | usb_msc.setCapacity(DISK_BLOCK_NUM, DISK_BLOCK_SIZE);
56 |
57 | // Set callback
58 | usb_msc.setReadWriteCallback(msc_read_callback, msc_write_callback, msc_flush_callback);
59 | usb_msc.setStartStopCallback(msc_start_stop_callback);
60 | usb_msc.setReadyCallback(msc_ready_callback);
61 |
62 | // Set Lun ready (RAM disk is always ready)
63 | usb_msc.setUnitReady(true);
64 | usb_msc.begin();
65 |
66 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
67 | if (TinyUSBDevice.mounted()) {
68 | TinyUSBDevice.detach();
69 | delay(10);
70 | TinyUSBDevice.attach();
71 | }
72 |
73 | // while ( !Serial ) delay(10); // wait for native usb
74 | Serial.println("Adafruit TinyUSB Mass Storage RAM Disk example");
75 | }
76 |
77 | void loop() {
78 | #ifdef TINYUSB_NEED_POLLING_TASK
79 | // Manual call tud_task since it isn't called by Core's background
80 | TinyUSBDevice.task();
81 | #endif
82 | }
83 |
84 | // Callback invoked when received READ10 command.
85 | // Copy disk's data to buffer (up to bufsize) and
86 | // return number of copied bytes (must be multiple of block size)
87 | int32_t msc_read_callback(uint32_t lba, void* buffer, uint32_t bufsize) {
88 | uint8_t const* addr = msc_disk[lba];
89 | memcpy(buffer, addr, bufsize);
90 |
91 | return bufsize;
92 | }
93 |
94 | // Callback invoked when received WRITE10 command.
95 | // Process data in buffer to disk's storage and
96 | // return number of written bytes (must be multiple of block size)
97 | int32_t msc_write_callback(uint32_t lba, uint8_t* buffer, uint32_t bufsize) {
98 | uint8_t* addr = msc_disk[lba];
99 | memcpy(addr, buffer, bufsize);
100 |
101 | return bufsize;
102 | }
103 |
104 | // Callback invoked when WRITE10 command is completed (status received and accepted by host).
105 | // used to flush any pending cache.
106 | void msc_flush_callback(void) {
107 | // nothing to do
108 | }
109 |
110 | bool msc_start_stop_callback(uint8_t power_condition, bool start, bool load_eject) {
111 | Serial.printf("Start/Stop callback: power condition %u, start %u, load_eject %u\n", power_condition, start, load_eject);
112 | return true;
113 | }
114 |
115 | // Invoked when received Test Unit Ready command.
116 | // return true allowing host to read/write this LUN e.g SD card inserted
117 | bool msc_ready_callback(void) {
118 | #ifdef BTN_EJECT
119 | // button not active --> medium ready
120 | return digitalRead(BTN_EJECT) != activeState;
121 | #else
122 | return true;
123 | #endif
124 | }
125 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_ramdisk_dual/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_ramdisk_dual/msc_ramdisk_dual.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #include "Adafruit_TinyUSB.h"
13 |
14 | // 8KB is the smallest size that windows allow to mount
15 | #define DISK_BLOCK_NUM 16
16 | #define DISK_BLOCK_SIZE 512
17 |
18 | #include "ramdisk.h"
19 |
20 | Adafruit_USBD_MSC usb_msc;
21 |
22 | // the setup function runs once when you press reset or power the board
23 | void setup() {
24 | // Manual begin() is required on core without built-in support e.g. mbed rp2040
25 | if (!TinyUSBDevice.isInitialized()) {
26 | TinyUSBDevice.begin(0);
27 | }
28 |
29 | Serial.begin(115200);
30 |
31 | usb_msc.setMaxLun(2);
32 |
33 | // Set disk size and callback for Logical Unit 0 (LUN 0)
34 | usb_msc.setID(0, "Adafruit", "Lun0", "1.0");
35 | usb_msc.setCapacity(0, DISK_BLOCK_NUM, DISK_BLOCK_SIZE);
36 | usb_msc.setReadWriteCallback(0, ram0_read_cb, ram0_write_cb, ram0_flush_cb);
37 | usb_msc.setUnitReady(0, true);
38 |
39 | // Set disk size and callback for Logical Unit 1 (LUN 1)
40 | usb_msc.setID(1, "Adafruit", "Lun1", "1.0");
41 | usb_msc.setCapacity(1, DISK_BLOCK_NUM, DISK_BLOCK_SIZE);
42 | usb_msc.setReadWriteCallback(1, ram1_read_cb, ram1_write_cb, ram1_flush_cb);
43 | usb_msc.setUnitReady(1, true);
44 |
45 | usb_msc.begin();
46 |
47 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
48 | if (TinyUSBDevice.mounted()) {
49 | TinyUSBDevice.detach();
50 | delay(10);
51 | TinyUSBDevice.attach();
52 | }
53 |
54 | //while ( !Serial ) delay(10); // wait for native usb
55 | Serial.println("Adafruit TinyUSB Mass Storage Dual RAM Disks example");
56 | }
57 |
58 | void loop() {
59 | #ifdef TINYUSB_NEED_POLLING_TASK
60 | // Manual call tud_task since it isn't called by Core's background
61 | TinyUSBDevice.task();
62 | #endif
63 | }
64 |
65 |
66 | //--------------------------------------------------------------------+
67 | // LUN 0 callback
68 | //--------------------------------------------------------------------+
69 |
70 | // Callback invoked when received READ10 command.
71 | // Copy disk's data to buffer (up to bufsize) and
72 | // return number of copied bytes (must be multiple of block size)
73 | int32_t ram0_read_cb(uint32_t lba, void* buffer, uint32_t bufsize) {
74 | uint8_t const* addr = msc_disk0[lba];
75 | memcpy(buffer, addr, bufsize);
76 |
77 | return bufsize;
78 | }
79 |
80 | // Callback invoked when received WRITE10 command.
81 | // Process data in buffer to disk's storage and
82 | // return number of written bytes (must be multiple of block size)
83 | int32_t ram0_write_cb(uint32_t lba, uint8_t* buffer, uint32_t bufsize) {
84 | uint8_t* addr = msc_disk0[lba];
85 | memcpy(addr, buffer, bufsize);
86 |
87 | return bufsize;
88 | }
89 |
90 | // Callback invoked when WRITE10 command is completed (status received and accepted by host).
91 | // used to flush any pending cache.
92 | void ram0_flush_cb(void) {
93 | // nothing to do
94 | }
95 |
96 |
97 | //--------------------------------------------------------------------+
98 | // LUN 1 callback
99 | //--------------------------------------------------------------------+
100 |
101 | // Callback invoked when received READ10 command.
102 | // Copy disk's data to buffer (up to bufsize) and
103 | // return number of copied bytes (must be multiple of block size)
104 | int32_t ram1_read_cb(uint32_t lba, void* buffer, uint32_t bufsize) {
105 | uint8_t const* addr = msc_disk1[lba];
106 | memcpy(buffer, addr, bufsize);
107 |
108 | return bufsize;
109 | }
110 |
111 | // Callback invoked when received WRITE10 command.
112 | // Process data in buffer to disk's storage and
113 | // return number of written bytes (must be multiple of block size)
114 | int32_t ram1_write_cb(uint32_t lba, uint8_t* buffer, uint32_t bufsize) {
115 | uint8_t* addr = msc_disk1[lba];
116 | memcpy(addr, buffer, bufsize);
117 |
118 | return bufsize;
119 | }
120 |
121 | // Callback invoked when WRITE10 command is completed (status received and accepted by host).
122 | // used to flush any pending cache.
123 | void ram1_flush_cb(void) {
124 | // nothing to do
125 | }
126 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_sd/.skip.txt:
--------------------------------------------------------------------------------
1 | feather_esp32s2
2 | feather_esp32s3
3 | funhouse
4 | magtag
5 | metroesp32s2
6 | feather_rp2040_tinyusb
7 | pico_rp2040_tinyusb_host
8 | CH32V20x_EVT
9 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_sd/msc_sd.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | /* This example expose SD card as mass storage using
13 | * default SD Library
14 | */
15 |
16 | #include "SD.h"
17 | #include "Adafruit_TinyUSB.h"
18 |
19 | const int chipSelect = 10;
20 |
21 | Adafruit_USBD_MSC usb_msc;
22 |
23 | Sd2Card card;
24 | SdVolume volume;
25 |
26 | // the setup function runs once when you press reset or power the board
27 | void setup()
28 | {
29 | Serial.begin(115200);
30 |
31 | // Set disk vendor id, product id and revision with string up to 8, 16, 4 characters respectively
32 | usb_msc.setID("Adafruit", "SD Card", "1.0");
33 |
34 | // Set read write callback
35 | usb_msc.setReadWriteCallback(msc_read_cb, msc_write_cb, msc_flush_cb);
36 |
37 | // Still initialize MSC but tell usb stack that MSC is not ready to read/write
38 | // If we don't initialize, board will be enumerated as CDC only
39 | usb_msc.setUnitReady(false);
40 | usb_msc.begin();
41 |
42 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
43 | if (TinyUSBDevice.mounted()) {
44 | TinyUSBDevice.detach();
45 | delay(10);
46 | TinyUSBDevice.attach();
47 | }
48 |
49 | //while ( !Serial ) delay(10); // wait for native usb
50 | Serial.println("Adafruit TinyUSB Mass Storage SD Card example");
51 | Serial.println("\nInitializing SD card...");
52 |
53 | if ( !card.init(SPI_HALF_SPEED, chipSelect) ) {
54 | Serial.println("initialization failed. Things to check:");
55 | Serial.println("* is a card inserted?");
56 | Serial.println("* is your wiring correct?");
57 | Serial.println("* did you change the chipSelect pin to match your shield or module?");
58 | while (1) delay(1);
59 | }
60 |
61 | // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
62 | if (!volume.init(card)) {
63 | Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
64 | while (1) delay(1);
65 | }
66 |
67 | uint32_t block_count = volume.blocksPerCluster()*volume.clusterCount();
68 |
69 | Serial.print("Volume size (MB): ");
70 | Serial.println((block_count/2) / 1024);
71 |
72 | // Set disk size, SD block size is always 512
73 | usb_msc.setCapacity(block_count, 512);
74 |
75 | // MSC is ready for read/write
76 | usb_msc.setUnitReady(true);
77 | }
78 |
79 | void loop() {
80 | // nothing to do
81 | }
82 |
83 | // Callback invoked when received READ10 command.
84 | // Copy disk's data to buffer (up to bufsize) and
85 | // return number of copied bytes (must be multiple of block size)
86 | int32_t msc_read_cb (uint32_t lba, void* buffer, uint32_t bufsize) {
87 | (void) bufsize;
88 | return card.readBlock(lba, (uint8_t*) buffer) ? 512 : -1;
89 | }
90 |
91 | // Callback invoked when received WRITE10 command.
92 | // Process data in buffer to disk's storage and
93 | // return number of written bytes (must be multiple of block size)
94 | int32_t msc_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize) {
95 | (void) bufsize;
96 | return card.writeBlock(lba, buffer) ? 512 : -1;
97 | }
98 |
99 | // Callback invoked when WRITE10 command is completed (status received and accepted by host).
100 | // used to flush any pending cache.
101 | void msc_flush_cb (void) {
102 | // nothing to do
103 | }
104 |
--------------------------------------------------------------------------------
/examples/MassStorage/msc_sdfat/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 |
--------------------------------------------------------------------------------
/examples/Vendor/i2c_tiny_usb_adapter/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/Vendor/i2c_tiny_usb_adapter/i2c_tiny_usb_adapter.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | #include
13 | #include "Adafruit_TinyUSB.h"
14 |
15 | #include "Adafruit_USBD_I2C.h"
16 |
17 | /* This sketch demonstrates how to use tinyusb vendor interface to implement
18 | * i2c-tiny-usb adapter to use with Linux
19 | *
20 | * Reference:
21 | * - https://github.com/torvalds/linux/blob/master/drivers/i2c/busses/i2c-tiny-usb.c
22 | * - https://github.com/harbaum/I2C-Tiny-USB
23 | *
24 | * Requirement:
25 | * - Install i2c-tools with
26 | * sudo apt install i2c-tools
27 | *
28 | * How to test example:
29 | * - Compile and flash this sketch on your board with an i2c device, it should enumerated as
30 | * ID 1c40:0534 EZPrototypes i2c-tiny-usb interface
31 | *
32 | * - Run "i2cdetect -l" to find our bus ID e.g
33 | * i2c-8 i2c i2c-tiny-usb at bus 003 device 039 I2C adapter
34 | *
35 | * - Run "i2cdetect -y 8" to scan for on-board device (8 is the above bus ID)
36 | * 0 1 2 3 4 5 6 7 8 9 a b c d e f
37 | 00: -- -- -- -- -- -- -- --
38 | 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
39 | 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40 | 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
41 | 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
42 | 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
43 | 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
44 | 70: -- -- -- -- -- -- -- 77
45 |
46 | - You can then interact with sensor using following commands:
47 | i2cget i2cset i2cdump i2ctransfer or using any driver/tools that work on i2c device.
48 |
49 | Adafruit CircuitPython library for PC
50 | - You can use run CircuitPython library with Extended Bus to read sensor data.
51 | - 'i2c_usb.py' is provided a sample script
52 | */
53 |
54 | static uint8_t i2c_buf[800];
55 |
56 | #define MyWire Wire
57 | //#define MyWire Wire1
58 |
59 | Adafruit_USBD_I2C i2c_usb(&MyWire);
60 |
61 | void setup() {
62 | Serial.begin(115200);
63 |
64 | // init i2c usb with buffer and size
65 | i2c_usb.begin(i2c_buf, sizeof(i2c_buf));
66 |
67 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
68 | if (TinyUSBDevice.mounted()) {
69 | TinyUSBDevice.detach();
70 | delay(10);
71 | TinyUSBDevice.attach();
72 | }
73 | }
74 |
75 | void loop() {
76 | }
77 |
78 |
79 | // callback from tinyusb
80 | bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const* request)
81 | {
82 | return i2c_usb.handleControlTransfer(rhport, stage, request);
83 | }
84 |
85 |
--------------------------------------------------------------------------------
/examples/Vendor/i2c_tiny_usb_adapter/i2c_usb.py:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env python3
2 | #
3 | # before running, install required libraries:
4 | # pip3 install adafruit-extended-bus
5 | # pip3 install adafruit-circuitpython-bme280
6 |
7 | import time
8 | import adafruit_extended_bus
9 | from adafruit_bme280 import basic as adafruit_bme280
10 |
11 | # Run "i2cdetect -l" to find your bus number
12 | i2c_usb = adafruit_extended_bus.ExtendedI2C(8)
13 | bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c_usb)
14 | while 1:
15 | print("\nTemperature: %0.1f C" % bme280.temperature)
16 | print("Humidity: %0.1f %%" % bme280.humidity)
17 | print("Pressure: %0.1f hPa" % bme280.pressure)
18 | time.sleep(1)
--------------------------------------------------------------------------------
/examples/Video/video_capture/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 |
--------------------------------------------------------------------------------
/examples/WebUSB/webusb_rgb/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 | # CH32V20x_EVT is not supported due to Adafruit_Neopixel
--------------------------------------------------------------------------------
/examples/WebUSB/webusb_serial/.skip.txt:
--------------------------------------------------------------------------------
1 | pico_rp2040_tinyusb_host
2 | CH32V20x_EVT
3 | # CH32V20x_EVT is not supported due to lacking of HardwareSerial::read(uint8_t [64], int)
--------------------------------------------------------------------------------
/examples/WebUSB/webusb_serial/webusb_serial.ino:
--------------------------------------------------------------------------------
1 | /*********************************************************************
2 | Adafruit invests time and resources providing this open source code,
3 | please support Adafruit and open-source hardware by purchasing
4 | products from Adafruit!
5 |
6 | MIT license, check LICENSE for more information
7 | Copyright (c) 2019 Ha Thach for Adafruit Industries
8 | All text above, and the splash screen below must be included in
9 | any redistribution
10 | *********************************************************************/
11 |
12 | /* This sketch demonstrates WebUSB as web serial with browser with WebUSB support (e.g Chrome).
13 | * After enumerated successfully, Browser will pop-up notification
14 | * with URL to landing page, click on it to test
15 | * - Click "Connect" and select device, When connected the on-board LED will litted up.
16 | * - Any charters received from either webusb/Serial will be echo back to webusb and Serial
17 | *
18 | * Note:
19 | * - The WebUSB landing page notification is currently disabled in Chrome
20 | * on Windows due to Chromium issue 656702 (https://crbug.com/656702). You have to
21 | * go to landing page (below) to test
22 | *
23 | * - On Windows 7 and prior: You need to use Zadig tool to manually bind the
24 | * WebUSB interface with the WinUSB driver for Chrome to access. From windows 8 and 10, this
25 | * is done automatically by firmware.
26 | */
27 |
28 | #include "Adafruit_TinyUSB.h"
29 |
30 | // USB WebUSB object
31 | Adafruit_USBD_WebUSB usb_web;
32 |
33 | // Landing Page: scheme (0: http, 1: https), url
34 | // Page source can be found at https://github.com/hathach/tinyusb-webusb-page/tree/main/webusb-serial
35 | WEBUSB_URL_DEF(landingPage, 1 /*https*/, "example.tinyusb.org/webusb-serial/index.html");
36 |
37 | int led_pin = LED_BUILTIN;
38 |
39 | // the setup function runs once when you press reset or power the board
40 | void setup() {
41 | // Manual begin() is required on core without built-in support e.g. mbed rp2040
42 | if (!TinyUSBDevice.isInitialized()) {
43 | TinyUSBDevice.begin(0);
44 | }
45 | Serial.begin(115200);
46 |
47 | pinMode(led_pin, OUTPUT);
48 | digitalWrite(led_pin, LOW);
49 |
50 | usb_web.setLandingPage(&landingPage);
51 | usb_web.setLineStateCallback(line_state_callback);
52 | //usb_web.setStringDescriptor("TinyUSB WebUSB");
53 | usb_web.begin();
54 |
55 | // If already enumerated, additional class driverr begin() e.g msc, hid, midi won't take effect until re-enumeration
56 | if (TinyUSBDevice.mounted()) {
57 | TinyUSBDevice.detach();
58 | delay(10);
59 | TinyUSBDevice.attach();
60 | }
61 |
62 | // wait until device mounted
63 | while (!TinyUSBDevice.mounted()) delay(1);
64 |
65 | Serial.println("TinyUSB WebUSB Serial example");
66 | }
67 |
68 | // function to echo to both Serial and WebUSB
69 | void echo_all(uint8_t buf[], uint32_t count) {
70 | if (usb_web.connected()) {
71 | usb_web.write(buf, count);
72 | usb_web.flush();
73 | }
74 |
75 | if (Serial) {
76 | for (uint32_t i = 0; i < count; i++) {
77 | Serial.write(buf[i]);
78 | if (buf[i] == '\r') Serial.write('\n');
79 | }
80 | Serial.flush();
81 | }
82 | }
83 |
84 | void loop() {
85 | #ifdef TINYUSB_NEED_POLLING_TASK
86 | // Manual call tud_task since it isn't called by Core's background
87 | TinyUSBDevice.task();
88 | #endif
89 |
90 | uint8_t buf[64];
91 | uint32_t count;
92 |
93 | // From Serial to both Serial & webUSB
94 | if (Serial.available()) {
95 | count = Serial.read(buf, 64);
96 | echo_all(buf, count);
97 | }
98 |
99 | // from WebUSB to both Serial & webUSB
100 | if (usb_web.available()) {
101 | count = usb_web.read(buf, 64);
102 | echo_all(buf, count);
103 | }
104 | }
105 |
106 | void line_state_callback(bool connected) {
107 | digitalWrite(led_pin, connected);
108 |
109 | if (connected) {
110 | usb_web.println("WebUSB interface connected !!");
111 | usb_web.flush();
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/library.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Adafruit TinyUSB Library",
3 | "keywords": "usb, arduino, tinyusb",
4 | "description": "Arduino library for TinyUSB",
5 | "version": "3.4.1",
6 | "repository": {
7 | "type": "git",
8 | "url": "https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git"
9 | },
10 | "frameworks": "*",
11 | "platforms": "*",
12 | "build": {
13 | "libArchive": false,
14 | "flags": "-DUSE_TINYUSB"
15 | },
16 | "authors":
17 | [
18 | {
19 | "name": "Adafruit",
20 | "maintainer": true
21 | }
22 | ]
23 | }
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=Adafruit TinyUSB Library
2 | version=3.4.2
3 | author=Adafruit
4 | maintainer=Adafruit
5 | sentence=TinyUSB library for Arduino
6 | paragraph=Support nRF5x, SAMD21, SAMD51, RP2040, ESP32-S2/S3, CH32V
7 | category=Communication
8 | url=https://github.com/adafruit/Adafruit_TinyUSB_Arduino
9 | architectures=*
10 | includes=Adafruit_TinyUSB.h
11 | depends=Adafruit SPIFlash, MIDI Library, SdFat - Adafruit Fork
12 |
--------------------------------------------------------------------------------
/src/Adafruit_TinyUSB.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 Ha Thach for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef ADAFRUIT_TINYUSB_H_
26 | #define ADAFRUIT_TINYUSB_H_
27 |
28 | // ESP32 out-of-sync
29 | #ifdef ARDUINO_ARCH_ESP32
30 | #include "arduino/ports/esp32/tusb_config_esp32.h"
31 | #endif
32 |
33 | #include "tusb_option.h"
34 |
35 | // Device
36 | #if CFG_TUD_ENABLED
37 |
38 | #include "arduino/Adafruit_USBD_Device.h"
39 |
40 | #if CFG_TUD_CDC
41 | #include "arduino/Adafruit_USBD_CDC.h"
42 | #endif
43 |
44 | #if CFG_TUD_HID
45 | #include "arduino/hid/Adafruit_USBD_HID.h"
46 | #endif
47 |
48 | #if CFG_TUD_MIDI
49 | #include "arduino/midi/Adafruit_USBD_MIDI.h"
50 | #endif
51 |
52 | #if CFG_TUD_MSC
53 | #include "arduino/msc/Adafruit_USBD_MSC.h"
54 | #endif
55 |
56 | #if CFG_TUD_VENDOR
57 | #include "arduino/webusb/Adafruit_USBD_WebUSB.h"
58 | #endif
59 |
60 | #if CFG_TUD_VIDEO
61 | #include "arduino/video/Adafruit_USBD_Video.h"
62 | #endif
63 |
64 | // Initialize device hardware, stack, also Serial as CDC
65 | // Wrapper for TinyUSBDevice.begin(rhport)
66 | void TinyUSB_Device_Init(uint8_t rhport);
67 |
68 | #endif
69 |
70 | // Host
71 | #if CFG_TUH_ENABLED
72 |
73 | #include "arduino/Adafruit_USBH_Host.h"
74 |
75 | #if CFG_TUH_CDC
76 | #include "arduino/cdc/Adafruit_USBH_CDC.h"
77 | #endif
78 |
79 | #if CFG_TUH_MSC
80 | #include "arduino/msc/Adafruit_USBH_MSC.h"
81 | #endif
82 |
83 | #endif
84 |
85 | #endif /* ADAFRUIT_TINYUSB_H_ */
86 |
--------------------------------------------------------------------------------
/src/arduino/Adafruit_TinyUSB_API.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 Ha Thach for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #include "tusb_option.h"
26 |
27 | #if CFG_TUD_ENABLED || CFG_TUH_ENABLED
28 |
29 | #include "Adafruit_TinyUSB.h"
30 | #include "Arduino.h"
31 |
32 | extern "C" {
33 |
34 | //--------------------------------------------------------------------+
35 | // Device
36 | //--------------------------------------------------------------------+
37 | #if CFG_TUD_ENABLED
38 | void TinyUSB_Device_Init(uint8_t rhport) {
39 | // Init USB Device controller and stack
40 | TinyUSBDevice.begin(rhport);
41 | }
42 |
43 | // RP2040 has its own implementation since it needs mutex for dual core
44 | #ifndef ARDUINO_ARCH_RP2040
45 | void TinyUSB_Device_Task(void) {
46 | // Run tinyusb device task
47 | tud_task();
48 | }
49 | #endif
50 |
51 | #ifndef ARDUINO_ARCH_ESP32
52 | void TinyUSB_Device_FlushCDC(void) {
53 | uint8_t const cdc_instance = Adafruit_USBD_CDC::getInstanceCount();
54 | for (uint8_t instance = 0; instance < cdc_instance; instance++) {
55 | tud_cdc_n_write_flush(instance);
56 | }
57 | }
58 | #endif
59 | #endif // CFG_TUD_ENABLED
60 |
61 | //------------- Debug log with Serial1 -------------//
62 | #if CFG_TUSB_DEBUG && defined(CFG_TUSB_DEBUG_PRINTF) && \
63 | !defined(ARDUINO_ARCH_ESP32)
64 |
65 | // #define USE_SEGGER_RTT
66 | #ifndef SERIAL_TUSB_DEBUG
67 | #define SERIAL_TUSB_DEBUG Serial1
68 | #endif
69 |
70 | #ifdef USE_SEGGER_RTT
71 | #include "SEGGER_RTT/RTT/SEGGER_RTT.h"
72 | #endif
73 |
74 | __attribute__((used)) int CFG_TUSB_DEBUG_PRINTF(const char *__restrict format,
75 | ...) {
76 | char buf[256];
77 | int len;
78 | va_list ap;
79 | va_start(ap, format);
80 | len = vsnprintf(buf, sizeof(buf), format, ap);
81 |
82 | #ifdef USE_SEGGER_RTT
83 | SEGGER_RTT_Write(0, buf, len);
84 | #else
85 | static volatile bool ser_inited = false;
86 | if (!ser_inited) {
87 | ser_inited = true;
88 | SERIAL_TUSB_DEBUG.begin(115200);
89 | // SERIAL_TUSB_DEBUG.begin(921600);
90 | }
91 | SERIAL_TUSB_DEBUG.write(buf);
92 | #endif
93 |
94 | va_end(ap);
95 | return len;
96 | }
97 | #endif // CFG_TUSB_DEBUG
98 |
99 | } // extern C
100 |
101 | #endif // CFG_TUD_ENABLED || CFG_TUH_ENABLED
102 |
--------------------------------------------------------------------------------
/src/arduino/Adafruit_TinyUSB_API.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 Ha Thach for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef ADAFRUIT_TINYUSB_API_H_
26 | #define ADAFRUIT_TINYUSB_API_H_
27 |
28 | #include
29 | #include
30 |
31 | // API Version, need to be updated when there is changes for
32 | // TinyUSB_API, USBD_CDC, USBD_Device, USBD_Interface,
33 | #define TINYUSB_API_VERSION 30000
34 |
35 | #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_NRF52_ADAFRUIT) || \
36 | defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_CH32) || \
37 | (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED))
38 | #define TINYUSB_HAS_BUITLTIN_CORE_SUPPORT
39 | #endif
40 |
41 | // Core that has built-in support: Adafruit SAMD, Adafruit nRF, rp2040, esp32
42 | #if !defined(TINYUSB_HAS_BUITLTIN_CORE_SUPPORT)
43 | #define TINYUSB_NEED_POLLING_TASK
44 | #endif
45 |
46 | // Error message for Core that must select TinyUSB via menu (built-in except
47 | // esp32)
48 | #if !defined(USE_TINYUSB) && (defined(TINYUSB_HAS_BUITLTIN_CORE_SUPPORT) && \
49 | !defined(ARDUINO_ARCH_ESP32))
50 | #error TinyUSB is not selected, please select it in "Tools->Menu->USB Stack"
51 | #endif
52 |
53 | //--------------------------------------------------------------------+
54 | // Core API
55 | // Should be called by BSP Core to initialize, process task
56 | // Weak function allow compile arduino core before linking with this library
57 | //--------------------------------------------------------------------+
58 | #ifdef __cplusplus
59 | extern "C" {
60 | #endif
61 |
62 | // Called by core/sketch to initialize usb device hardware and stack
63 | // This also initialize Serial as CDC device
64 | void TinyUSB_Device_Init(uint8_t rhport) __attribute__((weak));
65 |
66 | // Called by core/sketch to handle device event
67 | void TinyUSB_Device_Task(void) __attribute__((weak));
68 |
69 | // Called by core/sketch to flush write on CDC
70 | void TinyUSB_Device_FlushCDC(void) __attribute__((weak));
71 |
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 |
76 | //--------------------------------------------------------------------+
77 | // Port API
78 | // Must be implemented by each BSP core/platform
79 | //--------------------------------------------------------------------+
80 |
81 | // To enter/reboot to bootloader
82 | // usually when host disconnects cdc at baud 1200 (touch 1200)
83 | void TinyUSB_Port_EnterDFU(void);
84 |
85 | // Init device hardware.
86 | // Called by TinyUSB_Device_Init()
87 | void TinyUSB_Port_InitDevice(uint8_t rhport);
88 |
89 | // Get unique serial number, needed for Serial String Descriptor
90 | // Fill serial_id (raw bytes) and return its length (limit to 16 bytes)
91 | // Note: Serial descriptor can be overwritten by user API
92 | uint8_t TinyUSB_Port_GetSerialNumber(uint8_t serial_id[16]);
93 |
94 | #endif
95 |
--------------------------------------------------------------------------------
/src/arduino/Adafruit_USBD_CDC.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 Ha Thach for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef ADAFRUIT_USBD_CDC_H_
26 | #define ADAFRUIT_USBD_CDC_H_
27 |
28 | #include "Adafruit_TinyUSB_API.h"
29 |
30 | #if defined(__cplusplus)
31 |
32 | #if defined(ARDUINO_ARCH_ESP32)
33 |
34 | // For ESP32 use USBCDC as it is compatible
35 | #define Adafruit_USBD_CDC USBCDC
36 | #define SerialTinyUSB Serial
37 |
38 | #else
39 |
40 | #include "Adafruit_USBD_Interface.h"
41 | #include "Stream.h"
42 |
43 | class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface {
44 | public:
45 | Adafruit_USBD_CDC(void);
46 |
47 | static uint8_t getInstanceCount(void) { return _instance_count; }
48 |
49 | void setPins(uint8_t pin_rx, uint8_t pin_tx) {
50 | (void)pin_rx;
51 | (void)pin_tx;
52 | }
53 | void begin(uint32_t baud);
54 | void begin(uint32_t baud, uint8_t config);
55 | void end(void);
56 |
57 | // return line coding set by host
58 | uint32_t baud(void);
59 | uint8_t stopbits(void);
60 | uint8_t paritytype(void);
61 | uint8_t numbits(void);
62 | int dtr(void);
63 |
64 | // Stream API
65 | virtual int available(void);
66 | virtual int peek(void);
67 |
68 | virtual int read(void);
69 | size_t read(uint8_t *buffer, size_t size);
70 |
71 | virtual void flush(void);
72 | virtual size_t write(uint8_t);
73 |
74 | virtual size_t write(const uint8_t *buffer, size_t size);
75 | size_t write(const char *buffer, size_t size) {
76 | return write((const uint8_t *)buffer, size);
77 | }
78 |
79 | virtual int availableForWrite(void);
80 | using Print::write; // pull in write(str) from Print
81 | operator bool();
82 |
83 | // from Adafruit_USBD_Interface
84 | virtual uint16_t getInterfaceDescriptor(uint8_t itfnum_deprecated,
85 | uint8_t *buf, uint16_t bufsize);
86 |
87 | private:
88 | enum { INVALID_INSTANCE = 0xffu };
89 | static uint8_t _instance_count;
90 |
91 | uint8_t _instance;
92 |
93 | bool isValid(void) { return _instance != INVALID_INSTANCE; }
94 | };
95 |
96 | extern Adafruit_USBD_CDC SerialTinyUSB;
97 |
98 | // Built-in support "Serial" is assigned to TinyUSB CDC
99 | // CH32 defines Serial as alias in WSerial.h
100 | #if defined(USE_TINYUSB) && !defined(ARDUINO_ARCH_CH32)
101 | #define SerialTinyUSB Serial
102 | #endif
103 |
104 | extern Adafruit_USBD_CDC SerialTinyUSB;
105 |
106 | #endif // else of ESP32
107 | #endif // __cplusplus
108 |
109 | #endif
110 |
--------------------------------------------------------------------------------
/src/arduino/Adafruit_USBD_Interface.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #include "tusb_option.h"
26 |
27 | #if CFG_TUD_ENABLED
28 |
29 | #include "Adafruit_USBD_Device.h"
30 |
31 | void Adafruit_USBD_Interface::setStringDescriptor(const char *str) {
32 | _strid = TinyUSBDevice.addStringDescriptor(str);
33 | }
34 |
35 | #endif
--------------------------------------------------------------------------------
/src/arduino/Adafruit_USBD_Interface.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef ADAFRUIT_USBD_INTERFACE_H_
26 | #define ADAFRUIT_USBD_INTERFACE_H_
27 |
28 | #include
29 | #include
30 |
31 | #if defined(ARDUINO_ARCH_CH32) || defined(CH32V20x) || defined(CH32V30x)
32 | // HACK: required for ch32 core version 1.0.4 or prior, removed when 1.0.5 is
33 | // released
34 | extern "C" void yield(void);
35 | #endif
36 |
37 | class Adafruit_USBD_Interface {
38 | protected:
39 | uint8_t _strid;
40 |
41 | public:
42 | Adafruit_USBD_Interface(void) { _strid = 0; }
43 |
44 | // Get Interface Descriptor
45 | // Fill the descriptor (if buf is not NULL) and return its length
46 | virtual uint16_t getInterfaceDescriptor(uint8_t itfnum_deprecated,
47 | uint8_t *buf, uint16_t bufsize) = 0;
48 | // Get Interface Descriptor Length
49 | uint16_t getInterfaceDescriptorLen() {
50 | return getInterfaceDescriptor(0, NULL, 0);
51 | }
52 |
53 | void setStringDescriptor(const char *str);
54 | };
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/src/arduino/Adafruit_USBH_Host.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 Ha Thach for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef ADAFRUIT_USBH_HOST_H_
26 | #define ADAFRUIT_USBH_HOST_H_
27 |
28 | #include "Adafruit_USBD_Interface.h"
29 | #include "tusb.h"
30 | #include
31 |
32 | #ifdef ARDUINO_ARCH_ESP32
33 | #include "esp32-hal-tinyusb.h"
34 | #endif
35 |
36 | #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
37 | extern "C" {
38 | void tuh_max3421_spi_cs_api(uint8_t rhport, bool active);
39 | bool tuh_max3421_spi_xfer_api(uint8_t rhport, uint8_t const *tx_buf,
40 | uint8_t *rx_buf, size_t xfer_bytes);
41 | void tuh_max3421_int_api(uint8_t rhport, bool enabled);
42 | }
43 |
44 | class Adafruit_USBH_Host {
45 | private:
46 | SPIClass *_spi;
47 | int8_t _cs;
48 | int8_t _intr;
49 |
50 | // for esp32 or using softwareSPI
51 | int8_t _sck, _mosi, _miso;
52 |
53 | public:
54 | // constructor for using MAX3421E (host shield)
55 | Adafruit_USBH_Host(SPIClass *spi, int8_t cs, int8_t intr);
56 | Adafruit_USBH_Host(SPIClass *spi, int8_t sck, int8_t mosi, int8_t miso,
57 | int8_t cs, int8_t intr);
58 |
59 | uint8_t max3421_readRegister(uint8_t reg, bool in_isr);
60 | bool max3421_writeRegister(uint8_t reg, uint8_t data, bool in_isr);
61 | bool max3421_writeIOPINS1(uint8_t data, bool in_isr) {
62 | enum { IOPINS1_ADDR = 20u << 3 }; // 0xA0
63 | return max3421_writeRegister(IOPINS1_ADDR, data, in_isr);
64 | }
65 | bool max3421_writeIOPINS2(uint8_t data, bool in_isr) {
66 | enum { IOPINS2_ADDR = 21u << 3 }; // 0xA8
67 | return max3421_writeRegister(IOPINS2_ADDR, data, in_isr);
68 | }
69 |
70 | private:
71 | friend void tuh_max3421_spi_cs_api(uint8_t rhport, bool active);
72 | friend bool tuh_max3421_spi_xfer_api(uint8_t rhport, uint8_t const *tx_buf,
73 | uint8_t *rx_buf, size_t xfer_bytes);
74 | friend void tuh_max3421_int_api(uint8_t rhport, bool enabled);
75 | #else
76 |
77 | class Adafruit_USBH_Host {
78 | #endif
79 |
80 | public:
81 | // default constructor
82 | Adafruit_USBH_Host(void);
83 |
84 | bool configure(uint8_t rhport, uint32_t cfg_id, const void *cfg_param);
85 |
86 | #ifdef ARDUINO_ARCH_RP2040
87 | bool configure_pio_usb(uint8_t rhport, const void *cfg_param);
88 | #endif
89 |
90 | bool begin(uint8_t rhport);
91 | void task(uint32_t timeout_ms = UINT32_MAX, bool in_isr = false);
92 |
93 | //------------- internal usage -------------//
94 | static Adafruit_USBH_Host *_instance;
95 |
96 | private:
97 | uint8_t _rhport;
98 | };
99 |
100 | #endif
101 |
--------------------------------------------------------------------------------
/src/arduino/cdc/Adafruit_USBH_CDC.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef ADAFRUIT_USBH_CDC_H_
26 | #define ADAFRUIT_USBH_CDC_H_
27 |
28 | #include "HardwareSerial.h"
29 |
30 | class Adafruit_USBH_CDC : public HardwareSerial {
31 | public:
32 | Adafruit_USBH_CDC(void);
33 |
34 | // Set/Get index of cdc interface
35 | void setInterfaceIndex(uint8_t idx) { _idx = idx; }
36 | uint8_t getInterfaceIndex(void) { return _idx; }
37 |
38 | void begin(unsigned long baudrate);
39 | void begin(unsigned long baudrate, uint16_t config);
40 |
41 | bool mount(uint8_t idx);
42 | void umount(uint8_t idx);
43 |
44 | // unbind cdc interface
45 | void end(void);
46 |
47 | // If cdc is mounted
48 | bool mounted(void);
49 | operator bool() { return mounted(); }
50 |
51 | // if cdc's DTR is asserted
52 | bool connected(void);
53 |
54 | // Line encoding
55 | uint32_t baud();
56 |
57 | //------------- Control API -------------//
58 | bool setDtrRts(bool dtr, bool rts, tuh_xfer_cb_t complete_cb = NULL,
59 | uintptr_t user_data = 0);
60 | bool setBaudrate(uint32_t baudrate, tuh_xfer_cb_t complete_cb = NULL,
61 | uintptr_t user_data = 0);
62 |
63 | //------------- Stream API -------------//
64 | virtual int available(void);
65 | virtual int peek(void);
66 |
67 | virtual int read(void);
68 | size_t read(uint8_t *buffer, size_t size);
69 |
70 | virtual void flush(void);
71 | virtual size_t write(uint8_t ch);
72 |
73 | virtual size_t write(const uint8_t *buffer, size_t size);
74 | size_t write(const char *buffer, size_t size) {
75 | return write((const uint8_t *)buffer, size);
76 | }
77 |
78 | virtual int availableForWrite(void);
79 | using Print::write; // pull in write(str) from Print
80 |
81 | private:
82 | uint8_t _idx; // TinyUSB CDC Interface Index
83 | uint32_t _baud;
84 | };
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/src/arduino/midi/Adafruit_USBD_MIDI.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 hathach for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef ADAFRUIT_USBD_MIDI_H_
26 | #define ADAFRUIT_USBD_MIDI_H_
27 |
28 | #include "Stream.h"
29 | #include "arduino/Adafruit_USBD_Device.h"
30 |
31 | class Adafruit_USBD_MIDI : public Stream, public Adafruit_USBD_Interface {
32 | public:
33 | Adafruit_USBD_MIDI(uint8_t n_cables = 1);
34 |
35 | void setCables(uint8_t n_cables);
36 |
37 | // Set the cable number with a USB device descriptor string
38 | // Note: per MIDI specs cable_id (or jackid/elementid) starting from 1. 0 is
39 | // reserved for undefined ID.
40 | bool setCableName(uint8_t cable_id, const char *str);
41 | bool begin(void);
42 |
43 | // for MIDI library
44 | bool begin(uint32_t baud) {
45 | (void)baud;
46 | return begin();
47 | }
48 |
49 | // Stream interface to use with MIDI Library
50 | virtual int read(void);
51 | virtual size_t write(uint8_t b);
52 | virtual int available(void);
53 | virtual int peek(void);
54 | virtual void flush(void);
55 |
56 | using Stream::write;
57 |
58 | // Raw MIDI USB packet interface.
59 | bool writePacket(const uint8_t packet[4]);
60 | bool readPacket(uint8_t packet[4]);
61 |
62 | // from Adafruit_USBD_Interface
63 | virtual uint16_t getInterfaceDescriptor(uint8_t itfnum_deprecated,
64 | uint8_t *buf, uint16_t bufsize);
65 |
66 | private:
67 | uint8_t _n_cables;
68 | uint8_t _cable_name_strid[16];
69 | };
70 |
71 | #endif /* ADAFRUIT_USBD_MIDI_H_ */
72 |
--------------------------------------------------------------------------------
/src/arduino/msc/Adafruit_USBH_MSC.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2022 Ha Thach (tinyusb.org) for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef ADAFRUIT_USBH_MSC_H_
26 | #define ADAFRUIT_USBH_MSC_H_
27 |
28 | #include "tusb.h"
29 |
30 | // define SdFat host helper class if SdFat library is available
31 | #if __has_include("SdFat.h")
32 |
33 | #include "SdFat.h"
34 |
35 | class Adafruit_USBH_MSC_BlockDevice : public FsBlockDeviceInterface {
36 | public:
37 | Adafruit_USBH_MSC_BlockDevice();
38 |
39 | bool begin(uint8_t dev_addr);
40 | void end(void);
41 |
42 | bool mounted(void);
43 |
44 | // Set active LUN
45 | bool setActiveLUN(uint8_t lun);
46 | void setWriteCompleteCallback(tuh_msc_complete_cb_t cb);
47 |
48 | //------------- SdFat v2 FsBlockDeviceInterface API -------------//
49 | virtual bool isBusy();
50 | virtual uint32_t sectorCount();
51 | virtual bool syncDevice();
52 |
53 | virtual bool readSector(uint32_t block, uint8_t *dst);
54 | virtual bool readSectors(uint32_t block, uint8_t *dst, size_t ns);
55 | virtual bool writeSector(uint32_t block, const uint8_t *src);
56 | virtual bool writeSectors(uint32_t block, const uint8_t *src, size_t ns);
57 |
58 | //------------- Internal APIs -------------//
59 | bool _io_complete_cb(uint8_t dev_addr,
60 | tuh_msc_complete_data_t const *cb_data);
61 |
62 | private:
63 | uint8_t _daddr;
64 | uint8_t _lun;
65 |
66 | // TODO use mutex to prevent race condition or atomic for better
67 | // implementation
68 | volatile bool _busy;
69 |
70 | tuh_msc_complete_cb_t _wr_cb;
71 |
72 | bool wait_for_io(void);
73 | };
74 |
75 | #endif
76 |
77 | #endif
78 |
--------------------------------------------------------------------------------
/src/arduino/video/Adafruit_USBD_Video.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2024 Ha Thach (tinyusb.org)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | * This file is part of the TinyUSB stack.
25 | */
26 |
27 | #ifndef ADAFRUIT_USBD_VIDEO_H
28 | #define ADAFRUIT_USBD_VIDEO_H
29 |
30 | #include "arduino/Adafruit_USBD_Device.h"
31 |
32 | class Adafruit_USBD_Video : public Adafruit_USBD_Interface {
33 | public:
34 | Adafruit_USBD_Video(void);
35 |
36 | bool begin();
37 |
38 | //------------- Video Control -------------//
39 | // bool isStreaming(uint8_t stream_idx);
40 | bool
41 | addTerminal(tusb_desc_video_control_camera_terminal_t const *camera_terminal);
42 | bool
43 | addTerminal(tusb_desc_video_control_output_terminal_t const *output_terminal);
44 |
45 | //------------- Video Streaming -------------//
46 | // bool setIsochronousStreaming(bool enabled);
47 |
48 | // Add format descriptor, return format index
49 | bool addFormat(tusb_desc_video_format_uncompressed_t const *format);
50 | bool addFrame(tusb_desc_video_frame_uncompressed_continuous_t const *frame);
51 | void
52 | addColorMatching(tusb_desc_video_streaming_color_matching_t const *color);
53 |
54 | // from Adafruit_USBD_Interface
55 | virtual uint16_t getInterfaceDescriptor(uint8_t itfnum_deprecated,
56 | uint8_t *buf, uint16_t bufsize);
57 |
58 | private:
59 | uint8_t _vc_id;
60 |
61 | tusb_desc_video_control_camera_terminal_t _camera_terminal;
62 | tusb_desc_video_control_output_terminal_t _output_terminal;
63 |
64 | // currently only support 1 format
65 | union {
66 | tusb_desc_video_format_uncompressed_t uncompressed;
67 | tusb_desc_video_format_mjpeg_t mjpeg;
68 | } _format;
69 |
70 | union {
71 | tusb_desc_video_frame_uncompressed_continuous_t uncompressed_cont;
72 | tusb_desc_video_frame_mjpeg_continuous_t mjpeg;
73 | } _frame;
74 |
75 | tusb_desc_video_streaming_color_matching_t _color_matching;
76 | };
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/src/arduino/webusb/Adafruit_USBD_WebUSB.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 hathach for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef ADAFRUIT_USBD_WEBUSB_H_
26 | #define ADAFRUIT_USBD_WEBUSB_H_
27 |
28 | #include "Stream.h"
29 | #include "arduino/Adafruit_USBD_Device.h"
30 |
31 | #define WEBUSB_URL_DEF(_name, _scheme, _url) \
32 | struct TU_ATTR_PACKED { \
33 | uint8_t bLength; \
34 | uint8_t bDescriptorType; \
35 | uint8_t bScheme; \
36 | char url[3 + sizeof(_url)]; \
37 | } const _name = {3 + sizeof(_url) - 1, 3, _scheme, _url}
38 |
39 | class Adafruit_USBD_WebUSB : public Stream, public Adafruit_USBD_Interface {
40 | public:
41 | typedef void (*linestate_callback_t)(bool connected);
42 | Adafruit_USBD_WebUSB(const void *url = NULL);
43 |
44 | bool begin(void);
45 |
46 | bool setLandingPage(const void *url);
47 | void setLineStateCallback(linestate_callback_t fp);
48 |
49 | // Stream API
50 | virtual int available(void);
51 | virtual int peek(void);
52 |
53 | virtual int read(void);
54 | size_t read(uint8_t *buffer, size_t size);
55 |
56 | virtual void flush(void);
57 | virtual size_t write(uint8_t b);
58 |
59 | virtual size_t write(const uint8_t *buffer, size_t size);
60 | size_t write(const char *buffer, size_t size) {
61 | return write((const uint8_t *)buffer, size);
62 | }
63 |
64 | bool connected(void);
65 | operator bool();
66 |
67 | // from Adafruit_USBD_Interface
68 | virtual uint16_t getInterfaceDescriptor(uint8_t itfnum_deprecated,
69 | uint8_t *buf, uint16_t bufsize);
70 |
71 | private:
72 | bool _connected;
73 | const uint8_t *_url;
74 | linestate_callback_t _linestate_cb;
75 |
76 | // Make all tinyusb callback friend to access private data
77 | friend bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage,
78 | tusb_control_request_t const *request);
79 | };
80 |
81 | #endif /* ADAFRUIT_USBD_WEBUSB_H_ */
82 |
--------------------------------------------------------------------------------
/src/class/cdc/serial/ch34x.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2023 Heiko Kuester
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | * This file is part of the TinyUSB stack.
25 | */
26 |
27 | #ifndef _CH34X_H_
28 | #define _CH34X_H_
29 |
30 | // There is no official documentation for the CH34x (CH340, CH341) chips. Reference can be found
31 | // - https://github.com/WCHSoftGroup/ch341ser_linux
32 | // - https://github.com/torvalds/linux/blob/master/drivers/usb/serial/ch341.c
33 | // - https://github.com/freebsd/freebsd-src/blob/main/sys/dev/usb/serial/uchcom.c
34 |
35 | // set line_coding @ enumeration
36 | #ifdef CFG_TUH_CDC_LINE_CODING_ON_ENUM
37 | #define CFG_TUH_CDC_LINE_CODING_ON_ENUM_CH34X CFG_TUH_CDC_LINE_CODING_ON_ENUM
38 | #else // this default is necessary to work properly
39 | #define CFG_TUH_CDC_LINE_CODING_ON_ENUM_CH34X { 9600, CDC_LINE_CONDING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 }
40 | #endif
41 |
42 | // USB requests
43 | #define CH34X_REQ_READ_VERSION 0x5F // dec 95
44 | #define CH34X_REQ_WRITE_REG 0x9A // dec 154
45 | #define CH34X_REQ_READ_REG 0x95 // dec 149
46 | #define CH34X_REQ_SERIAL_INIT 0xA1 // dec 161
47 | #define CH34X_REQ_MODEM_CTRL 0xA4 // dev 164
48 |
49 | // registers
50 | #define CH34X_REG_BREAK 0x05
51 | #define CH34X_REG_PRESCALER 0x12
52 | #define CH34X_REG_DIVISOR 0x13
53 | #define CH34X_REG_LCR 0x18
54 | #define CH34X_REG_LCR2 0x25
55 | #define CH34X_REG_MCR_MSR 0x06
56 | #define CH34X_REG_MCR_MSR2 0x07
57 | #define CH34X_NBREAK_BITS 0x01
58 |
59 | #define CH341_REG_0x0F 0x0F // undocumented register
60 | #define CH341_REG_0x2C 0x2C // undocumented register
61 | #define CH341_REG_0x27 0x27 // hardware flow control (cts/rts)
62 |
63 | #define CH34X_REG16_DIVISOR_PRESCALER TU_U16(CH34X_REG_DIVISOR, CH34X_REG_PRESCALER)
64 | #define CH32X_REG16_LCR2_LCR TU_U16(CH34X_REG_LCR2, CH34X_REG_LCR)
65 |
66 | // modem control bits
67 | #define CH34X_BIT_RTS ( 1 << 6 )
68 | #define CH34X_BIT_DTR ( 1 << 5 )
69 |
70 | // line control bits
71 | #define CH34X_LCR_ENABLE_RX 0x80
72 | #define CH34X_LCR_ENABLE_TX 0x40
73 | #define CH34X_LCR_MARK_SPACE 0x20
74 | #define CH34X_LCR_PAR_EVEN 0x10
75 | #define CH34X_LCR_ENABLE_PAR 0x08
76 | #define CH34X_LCR_PAR_MASK 0x38 // all parity bits
77 | #define CH34X_LCR_STOP_BITS_2 0x04
78 | #define CH34X_LCR_CS8 0x03
79 | #define CH34X_LCR_CS7 0x02
80 | #define CH34X_LCR_CS6 0x01
81 | #define CH34X_LCR_CS5 0x00
82 | #define CH34X_LCR_CS_MASK 0x03 // all CSx bits
83 |
84 | #endif /* _CH34X_H_ */
85 |
--------------------------------------------------------------------------------
/src/class/cdc/serial/cp210x.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2023 Ha Thach (thach@tinyusb.org) for Adafruit Industries
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef TUSB_CP210X_H
26 | #define TUSB_CP210X_H
27 |
28 | // Protocol details can be found at AN571: CP210x Virtual COM Port Interface
29 | // https://www.silabs.com/documents/public/application-notes/AN571.pdf
30 |
31 | #define TU_CP210X_VID 0x10C4
32 |
33 | /* Config request codes */
34 | #define CP210X_IFC_ENABLE 0x00
35 | #define CP210X_SET_BAUDDIV 0x01
36 | #define CP210X_GET_BAUDDIV 0x02
37 | #define CP210X_SET_LINE_CTL 0x03 // Set parity, data bits, stop bits
38 | #define CP210X_GET_LINE_CTL 0x04
39 | #define CP210X_SET_BREAK 0x05
40 | #define CP210X_IMM_CHAR 0x06
41 | #define CP210X_SET_MHS 0x07 // Set DTR, RTS
42 | #define CP210X_GET_MDMSTS 0x08 // Get modem status (DTR, RTS, CTS, DSR, RI, DCD)
43 | #define CP210X_SET_XON 0x09
44 | #define CP210X_SET_XOFF 0x0A
45 | #define CP210X_SET_EVENTMASK 0x0B
46 | #define CP210X_GET_EVENTMASK 0x0C
47 | #define CP210X_SET_CHAR 0x0D
48 | #define CP210X_GET_CHARS 0x0E
49 | #define CP210X_GET_PROPS 0x0F
50 | #define CP210X_GET_COMM_STATUS 0x10
51 | #define CP210X_RESET 0x11
52 | #define CP210X_PURGE 0x12
53 | #define CP210X_SET_FLOW 0x13
54 | #define CP210X_GET_FLOW 0x14
55 | #define CP210X_EMBED_EVENTS 0x15
56 | #define CP210X_GET_EVENTSTATE 0x16
57 | #define CP210X_SET_CHARS 0x19
58 | #define CP210X_GET_BAUDRATE 0x1D
59 | #define CP210X_SET_BAUDRATE 0x1E
60 | #define CP210X_VENDOR_SPECIFIC 0xFF // GPIO, Recipient must be Device
61 |
62 | #endif //TUSB_CP210X_H
63 |
--------------------------------------------------------------------------------
/src/class/dfu/dfu.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2021 XMOS LIMITED
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | * This file is part of the TinyUSB stack.
25 | */
26 |
27 | #ifndef _TUSB_DFU_H_
28 | #define _TUSB_DFU_H_
29 |
30 | #include "common/tusb_common.h"
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | //--------------------------------------------------------------------+
37 | // Common Definitions
38 | //--------------------------------------------------------------------+
39 |
40 | // DFU Protocol
41 | typedef enum
42 | {
43 | DFU_PROTOCOL_RT = 0x01,
44 | DFU_PROTOCOL_DFU = 0x02,
45 | } dfu_protocol_type_t;
46 |
47 | // DFU Descriptor Type
48 | typedef enum
49 | {
50 | DFU_DESC_FUNCTIONAL = 0x21,
51 | } dfu_descriptor_type_t;
52 |
53 | // DFU Requests
54 | typedef enum {
55 | DFU_REQUEST_DETACH = 0,
56 | DFU_REQUEST_DNLOAD = 1,
57 | DFU_REQUEST_UPLOAD = 2,
58 | DFU_REQUEST_GETSTATUS = 3,
59 | DFU_REQUEST_CLRSTATUS = 4,
60 | DFU_REQUEST_GETSTATE = 5,
61 | DFU_REQUEST_ABORT = 6,
62 | } dfu_requests_t;
63 |
64 | // DFU States
65 | typedef enum {
66 | APP_IDLE = 0,
67 | APP_DETACH = 1,
68 | DFU_IDLE = 2,
69 | DFU_DNLOAD_SYNC = 3,
70 | DFU_DNBUSY = 4,
71 | DFU_DNLOAD_IDLE = 5,
72 | DFU_MANIFEST_SYNC = 6,
73 | DFU_MANIFEST = 7,
74 | DFU_MANIFEST_WAIT_RESET = 8,
75 | DFU_UPLOAD_IDLE = 9,
76 | DFU_ERROR = 10,
77 | } dfu_state_t;
78 |
79 | // DFU Status
80 | typedef enum {
81 | DFU_STATUS_OK = 0x00,
82 | DFU_STATUS_ERR_TARGET = 0x01,
83 | DFU_STATUS_ERR_FILE = 0x02,
84 | DFU_STATUS_ERR_WRITE = 0x03,
85 | DFU_STATUS_ERR_ERASE = 0x04,
86 | DFU_STATUS_ERR_CHECK_ERASED = 0x05,
87 | DFU_STATUS_ERR_PROG = 0x06,
88 | DFU_STATUS_ERR_VERIFY = 0x07,
89 | DFU_STATUS_ERR_ADDRESS = 0x08,
90 | DFU_STATUS_ERR_NOTDONE = 0x09,
91 | DFU_STATUS_ERR_FIRMWARE = 0x0A,
92 | DFU_STATUS_ERR_VENDOR = 0x0B,
93 | DFU_STATUS_ERR_USBR = 0x0C,
94 | DFU_STATUS_ERR_POR = 0x0D,
95 | DFU_STATUS_ERR_UNKNOWN = 0x0E,
96 | DFU_STATUS_ERR_STALLEDPKT = 0x0F,
97 | } dfu_status_t;
98 |
99 | #define DFU_ATTR_CAN_DOWNLOAD (1u << 0)
100 | #define DFU_ATTR_CAN_UPLOAD (1u << 1)
101 | #define DFU_ATTR_MANIFESTATION_TOLERANT (1u << 2)
102 | #define DFU_ATTR_WILL_DETACH (1u << 3)
103 |
104 | // DFU Status Request Payload
105 | typedef struct TU_ATTR_PACKED
106 | {
107 | uint8_t bStatus;
108 | uint8_t bwPollTimeout[3];
109 | uint8_t bState;
110 | uint8_t iString;
111 | } dfu_status_response_t;
112 |
113 | TU_VERIFY_STATIC( sizeof(dfu_status_response_t) == 6, "size is not correct");
114 |
115 | #ifdef __cplusplus
116 | }
117 | #endif
118 |
119 | #endif /* _TUSB_DFU_H_ */
120 |
--------------------------------------------------------------------------------
/src/class/dfu/dfu_rt_device.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 Sylvain Munaut
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | * This file is part of the TinyUSB stack.
25 | */
26 |
27 | #ifndef _TUSB_DFU_RT_DEVICE_H_
28 | #define _TUSB_DFU_RT_DEVICE_H_
29 |
30 | #include "dfu.h"
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | //--------------------------------------------------------------------+
37 | // Application Callback API (weak is optional)
38 | //--------------------------------------------------------------------+
39 | // Invoked when a DFU_DETACH request is received and bitWillDetach is set
40 | void tud_dfu_runtime_reboot_to_dfu_cb(void);
41 |
42 | //--------------------------------------------------------------------+
43 | // Internal Class Driver API
44 | //--------------------------------------------------------------------+
45 | void dfu_rtd_init(void);
46 | bool dfu_rtd_deinit(void);
47 | void dfu_rtd_reset(uint8_t rhport);
48 | uint16_t dfu_rtd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
49 | bool dfu_rtd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
50 |
51 | #ifdef __cplusplus
52 | }
53 | #endif
54 |
55 | #endif /* _TUSB_DFU_RT_DEVICE_H_ */
56 |
--------------------------------------------------------------------------------
/src/class/net/net_device.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2020 Peter Lawrence
5 | * Copyright (c) 2019 Ha Thach (tinyusb.org)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | *
25 | * This file is part of the TinyUSB stack.
26 | */
27 |
28 | #ifndef _TUSB_NET_DEVICE_H_
29 | #define _TUSB_NET_DEVICE_H_
30 |
31 | #include
32 | #include "class/cdc/cdc.h"
33 |
34 | #if CFG_TUD_ECM_RNDIS && CFG_TUD_NCM
35 | #error "Cannot enable both ECM_RNDIS and NCM network drivers"
36 | #endif
37 |
38 | /* declared here, NOT in usb_descriptors.c, so that the driver can intelligently ZLP as needed */
39 | #define CFG_TUD_NET_ENDPOINT_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
40 |
41 | /* Maximum Transmission Unit (in bytes) of the network, including Ethernet header */
42 | #ifndef CFG_TUD_NET_MTU
43 | #define CFG_TUD_NET_MTU 1514
44 | #endif
45 |
46 |
47 | // Table 4.3 Data Class Interface Protocol Codes
48 | typedef enum
49 | {
50 | NCM_DATA_PROTOCOL_NETWORK_TRANSFER_BLOCK = 0x01
51 | } ncm_data_interface_protocol_code_t;
52 |
53 |
54 | #ifdef __cplusplus
55 | extern "C" {
56 | #endif
57 |
58 | //--------------------------------------------------------------------+
59 | // Application API
60 | //--------------------------------------------------------------------+
61 |
62 | // indicate to network driver that client has finished with the packet provided to network_recv_cb()
63 | void tud_network_recv_renew(void);
64 |
65 | // poll network driver for its ability to accept another packet to transmit
66 | bool tud_network_can_xmit(uint16_t size);
67 |
68 | // if network_can_xmit() returns true, network_xmit() can be called once
69 | void tud_network_xmit(void *ref, uint16_t arg);
70 |
71 | //--------------------------------------------------------------------+
72 | // Application Callbacks (WEAK is optional)
73 | //--------------------------------------------------------------------+
74 |
75 | // client must provide this: return false if the packet buffer was not accepted
76 | bool tud_network_recv_cb(const uint8_t *src, uint16_t size);
77 |
78 | // client must provide this: copy from network stack packet pointer to dst
79 | uint16_t tud_network_xmit_cb(uint8_t *dst, void *ref, uint16_t arg);
80 |
81 | //------------- ECM/RNDIS -------------//
82 |
83 | // client must provide this: initialize any network state back to the beginning
84 | void tud_network_init_cb(void);
85 |
86 | // client must provide this: 48-bit MAC address
87 | // TODO removed later since it is not part of tinyusb stack
88 | extern uint8_t tud_network_mac_address[6];
89 |
90 | //--------------------------------------------------------------------+
91 | // INTERNAL USBD-CLASS DRIVER API
92 | //--------------------------------------------------------------------+
93 | void netd_init (void);
94 | bool netd_deinit (void);
95 | void netd_reset (uint8_t rhport);
96 | uint16_t netd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
97 | bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
98 | bool netd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
99 | void netd_report (uint8_t *buf, uint16_t len);
100 |
101 | #ifdef __cplusplus
102 | }
103 | #endif
104 |
105 | #endif /* _TUSB_NET_DEVICE_H_ */
106 |
--------------------------------------------------------------------------------
/src/class/video/video_device.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 | * Copyright (c) 2021 Koji KITAYAMA
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | *
25 | * This file is part of the TinyUSB stack.
26 | */
27 |
28 | #ifndef TUSB_VIDEO_DEVICE_H_
29 | #define TUSB_VIDEO_DEVICE_H_
30 |
31 | #include "common/tusb_common.h"
32 | #include "video.h"
33 |
34 | #ifdef __cplusplus
35 | extern "C" {
36 | #endif
37 |
38 | //--------------------------------------------------------------------+
39 | // Application API (Multiple Ports)
40 | // CFG_TUD_VIDEO > 1
41 | //--------------------------------------------------------------------+
42 |
43 | /** Return true if streaming
44 | *
45 | * @param[in] ctl_idx Destination control interface index
46 | * @param[in] stm_idx Destination streaming interface index */
47 | bool tud_video_n_streaming(uint_fast8_t ctl_idx, uint_fast8_t stm_idx);
48 |
49 | /** Transfer a frame
50 | *
51 | * @param[in] ctl_idx Destination control interface index
52 | * @param[in] stm_idx Destination streaming interface index
53 | * @param[in] buffer Frame buffer. The caller must not use this buffer until the operation is completed.
54 | * @param[in] bufsize Byte size of the frame buffer */
55 | bool tud_video_n_frame_xfer(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, void *buffer, size_t bufsize);
56 |
57 | /*------------- Optional callbacks -------------*/
58 | /** Invoked when compeletion of a frame transfer
59 | *
60 | * @param[in] ctl_idx Destination control interface index
61 | * @param[in] stm_idx Destination streaming interface index */
62 | TU_ATTR_WEAK void tud_video_frame_xfer_complete_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx);
63 |
64 | //--------------------------------------------------------------------+
65 | // Application Callback API (weak is optional)
66 | //--------------------------------------------------------------------+
67 |
68 | /** Invoked when SET_POWER_MODE request received
69 | *
70 | * @param[in] ctl_idx Destination control interface index
71 | * @param[in] stm_idx Destination streaming interface index
72 | * @return video_error_code_t */
73 | TU_ATTR_WEAK int tud_video_power_mode_cb(uint_fast8_t ctl_idx, uint8_t power_mod);
74 |
75 | /** Invoked when VS_COMMIT_CONTROL(SET_CUR) request received
76 | *
77 | * @param[in] ctl_idx Destination control interface index
78 | * @param[in] stm_idx Destination streaming interface index
79 | * @param[in] parameters Video streaming parameters
80 | * @return video_error_code_t */
81 | TU_ATTR_WEAK int tud_video_commit_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx,
82 | video_probe_and_commit_control_t const *parameters);
83 |
84 | //--------------------------------------------------------------------+
85 | // INTERNAL USBD-CLASS DRIVER API
86 | //--------------------------------------------------------------------+
87 | void videod_init (void);
88 | bool videod_deinit (void);
89 | void videod_reset (uint8_t rhport);
90 | uint16_t videod_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
91 | bool videod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
92 | bool videod_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
93 |
94 | #ifdef __cplusplus
95 | }
96 | #endif
97 |
98 | #endif
99 |
--------------------------------------------------------------------------------
/src/osal/osal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | * This file is part of the TinyUSB stack.
25 | */
26 |
27 | #ifndef _TUSB_OSAL_H_
28 | #define _TUSB_OSAL_H_
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | #include "common/tusb_common.h"
35 |
36 | typedef void (*osal_task_func_t)( void * );
37 |
38 | // Timeout
39 | #define OSAL_TIMEOUT_NOTIMEOUT (0) // Return immediately
40 | #define OSAL_TIMEOUT_NORMAL (10) // Default timeout
41 | #define OSAL_TIMEOUT_WAIT_FOREVER (UINT32_MAX) // Wait forever
42 | #define OSAL_TIMEOUT_CONTROL_XFER OSAL_TIMEOUT_WAIT_FOREVER
43 |
44 | // Mutex is required when using a preempted RTOS or MCU has multiple cores
45 | #if (CFG_TUSB_OS == OPT_OS_NONE) && !TUP_MCU_MULTIPLE_CORE
46 | #define OSAL_MUTEX_REQUIRED 0
47 | #define OSAL_MUTEX_DEF(_name) uint8_t :0
48 | #else
49 | #define OSAL_MUTEX_REQUIRED 1
50 | #define OSAL_MUTEX_DEF(_name) osal_mutex_def_t _name
51 | #endif
52 |
53 | // OS thin implementation
54 | #if CFG_TUSB_OS == OPT_OS_NONE
55 | #include "osal_none.h"
56 | #elif CFG_TUSB_OS == OPT_OS_FREERTOS
57 | #include "osal_freertos.h"
58 | #elif CFG_TUSB_OS == OPT_OS_MYNEWT
59 | #include "osal_mynewt.h"
60 | #elif CFG_TUSB_OS == OPT_OS_PICO
61 | #include "osal_pico.h"
62 | #elif CFG_TUSB_OS == OPT_OS_RTTHREAD
63 | #include "osal_rtthread.h"
64 | #elif CFG_TUSB_OS == OPT_OS_RTX4
65 | #include "osal_rtx4.h"
66 | #elif CFG_TUSB_OS == OPT_OS_CUSTOM
67 | #include "tusb_os_custom.h" // implemented by application
68 | #else
69 | #error OS is not supported yet
70 | #endif
71 |
72 | //--------------------------------------------------------------------+
73 | // OSAL Porting API
74 | // Should be implemented as static inline function in osal_port.h header
75 | /*
76 | osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef);
77 | bool osal_semaphore_delete(osal_semaphore_t semd_hdl);
78 | bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr);
79 | bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec);
80 | void osal_semaphore_reset(osal_semaphore_t sem_hdl); // TODO removed
81 |
82 | osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef);
83 | bool osal_mutex_delete(osal_mutex_t mutex_hdl)
84 | bool osal_mutex_lock (osal_mutex_t sem_hdl, uint32_t msec);
85 | bool osal_mutex_unlock(osal_mutex_t mutex_hdl);
86 |
87 | osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
88 | bool osal_queue_delete(osal_queue_t qhdl);
89 | bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec);
90 | bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr);
91 | bool osal_queue_empty(osal_queue_t qhdl);
92 | */
93 | //--------------------------------------------------------------------+
94 |
95 | #ifdef __cplusplus
96 | }
97 | #endif
98 |
99 | #endif /* _TUSB_OSAL_H_ */
100 |
--------------------------------------------------------------------------------
/src/portable/synopsys/dwc2/dwc2_bcm.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2021, Ha Thach (tinyusb.org)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | * This file is part of the TinyUSB stack.
25 | */
26 |
27 | #ifndef _TUSB_DWC2_BCM_H_
28 | #define _TUSB_DWC2_BCM_H_
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif
33 |
34 | #include "broadcom/defines.h"
35 | #include "broadcom/interrupts.h"
36 | #include "broadcom/caches.h"
37 |
38 | #define DWC2_EP_MAX 8
39 |
40 | static const dwc2_controller_t _dwc2_controller[] =
41 | {
42 | { .reg_base = USB_OTG_GLOBAL_BASE, .irqnum = USB_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 16384 }
43 | };
44 |
45 | #define dcache_clean(_addr, _size) data_clean(_addr, _size)
46 | #define dcache_invalidate(_addr, _size) data_invalidate(_addr, _size)
47 | #define dcache_clean_invalidate(_addr, _size) data_clean_and_invalidate(_addr, _size)
48 |
49 | TU_ATTR_ALWAYS_INLINE
50 | static inline void dwc2_dcd_int_enable(uint8_t rhport)
51 | {
52 | BP_EnableIRQ(_dwc2_controller[rhport].irqnum);
53 | }
54 |
55 | TU_ATTR_ALWAYS_INLINE
56 | static inline void dwc2_dcd_int_disable (uint8_t rhport)
57 | {
58 | BP_DisableIRQ(_dwc2_controller[rhport].irqnum);
59 | }
60 |
61 | static inline void dwc2_remote_wakeup_delay(void)
62 | {
63 | // try to delay for 1 ms
64 | // TODO implement later
65 | }
66 |
67 | // MCU specific PHY init, called BEFORE core reset
68 | static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
69 | {
70 | (void) dwc2;
71 | (void) hs_phy_type;
72 |
73 | // nothing to do
74 | }
75 |
76 | // MCU specific PHY update, it is called AFTER init() and core reset
77 | static inline void dwc2_phy_update(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
78 | {
79 | (void) dwc2;
80 | (void) hs_phy_type;
81 |
82 | // nothing to do
83 | }
84 |
85 | #ifdef __cplusplus
86 | }
87 | #endif
88 |
89 | #endif
90 |
--------------------------------------------------------------------------------
/src/portable/synopsys/dwc2/dwc2_efm32.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2021 Rafael Silva (@perigoso)
5 | * Copyright (c) 2021, Ha Thach (tinyusb.org)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | *
25 | * This file is part of the TinyUSB stack.
26 | */
27 |
28 | #ifndef _DWC2_EFM32_H_
29 | #define _DWC2_EFM32_H_
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | #include "em_device.h"
36 |
37 | // EFM32 has custom control register before DWC registers
38 | #define DWC2_REG_BASE (USB_BASE + offsetof(USB_TypeDef, GOTGCTL))
39 | #define DWC2_EP_MAX 7
40 |
41 | static const dwc2_controller_t _dwc2_controller[] =
42 | {
43 | { .reg_base = DWC2_REG_BASE, .irqnum = USB_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 2048 }
44 | };
45 |
46 | TU_ATTR_ALWAYS_INLINE
47 | static inline void dwc2_dcd_int_enable(uint8_t rhport)
48 | {
49 | NVIC_EnableIRQ(_dwc2_controller[rhport].irqnum);
50 | }
51 |
52 | TU_ATTR_ALWAYS_INLINE
53 | static inline void dwc2_dcd_int_disable (uint8_t rhport)
54 | {
55 | NVIC_DisableIRQ(_dwc2_controller[rhport].irqnum);
56 | }
57 |
58 | static inline void dwc2_remote_wakeup_delay(void)
59 | {
60 | // try to delay for 1 ms
61 | // uint32_t count = SystemCoreClock / 1000;
62 | // while ( count-- ) __NOP();
63 | }
64 |
65 | // MCU specific PHY init, called BEFORE core reset
66 | static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
67 | {
68 | (void) dwc2;
69 | (void) hs_phy_type;
70 |
71 | // Enable PHY
72 | USB->ROUTE = USB_ROUTE_PHYPEN;
73 | }
74 |
75 | // MCU specific PHY update, it is called AFTER init() and core reset
76 | static inline void dwc2_phy_update(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
77 | {
78 | (void) dwc2;
79 | (void) hs_phy_type;
80 |
81 | // EFM32 Manual: turn around must be 5 (reset & default value)
82 | // dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_TRDT_Msk) | (5u << GUSBCFG_TRDT_Pos);
83 | }
84 |
85 | #ifdef __cplusplus
86 | }
87 | #endif
88 |
89 | #endif
90 |
--------------------------------------------------------------------------------
/src/portable/synopsys/dwc2/dwc2_esp32.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2021, Ha Thach (tinyusb.org)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | * This file is part of the TinyUSB stack.
25 | */
26 |
27 |
28 | #ifndef _DWC2_ESP32_H_
29 | #define _DWC2_ESP32_H_
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | #include "freertos/task.h"
36 |
37 | #include "esp_intr_alloc.h"
38 | #include "soc/periph_defs.h"
39 | #include "soc/usb_wrap_struct.h"
40 |
41 | #if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
42 | #define DWC2_FS_REG_BASE 0x60080000UL
43 | #define DWC2_EP_MAX 7
44 |
45 | static const dwc2_controller_t _dwc2_controller[] = {
46 | { .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 }
47 | };
48 |
49 | #elif TU_CHECK_MCU(OPT_MCU_ESP32P4)
50 | #define DWC2_FS_REG_BASE 0x50040000UL
51 | #define DWC2_HS_REG_BASE 0x50000000UL
52 | #define DWC2_EP_MAX 16
53 |
54 | // On ESP32 for consistency we associate
55 | // - Port0 to OTG_FS, and Port1 to OTG_HS
56 | static const dwc2_controller_t _dwc2_controller[] = {
57 | { .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_OTG11_CH0_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 },
58 | { .reg_base = DWC2_HS_REG_BASE, .irqnum = ETS_USB_OTG_INTR_SOURCE, .ep_count = 16, .ep_in_count = 8, .ep_fifo_size = 4096 }
59 | };
60 | #endif
61 |
62 | static intr_handle_t usb_ih[TU_ARRAY_SIZE(_dwc2_controller)];
63 |
64 | static void dcd_int_handler_wrap(void* arg) {
65 | const uint8_t rhport = (uint8_t)(uintptr_t) arg;
66 | dcd_int_handler(rhport);
67 | }
68 |
69 | TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_enable(uint8_t rhport) {
70 | esp_intr_alloc(_dwc2_controller[rhport].irqnum, ESP_INTR_FLAG_LOWMED,
71 | dcd_int_handler_wrap, (void*)(uintptr_t) rhport, &usb_ih[rhport]);
72 | }
73 |
74 | TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_disable(uint8_t rhport) {
75 | esp_intr_free(usb_ih[rhport]);
76 | }
77 |
78 | TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) {
79 | vTaskDelay(pdMS_TO_TICKS(1));
80 | }
81 |
82 | // MCU specific PHY init, called BEFORE core reset
83 | TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
84 | (void)dwc2;
85 | (void)hs_phy_type;
86 | // nothing to do
87 | }
88 |
89 | // MCU specific PHY update, it is called AFTER init() and core reset
90 | TU_ATTR_ALWAYS_INLINE static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint8_t hs_phy_type) {
91 | (void)dwc2;
92 | (void)hs_phy_type;
93 | // nothing to do
94 | }
95 |
96 | #ifdef __cplusplus
97 | }
98 | #endif
99 |
100 | #endif
101 |
--------------------------------------------------------------------------------
/src/portable/synopsys/dwc2/dwc2_gd32.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2021, Ha Thach (tinyusb.org)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | *
24 | * This file is part of the TinyUSB stack.
25 | */
26 |
27 |
28 | #ifndef DWC2_GD32_H_
29 | #define DWC2_GD32_H_
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | #define DWC2_REG_BASE 0x50000000UL
36 | #define DWC2_EP_MAX 4
37 |
38 | static const dwc2_controller_t _dwc2_controller[] =
39 | {
40 | { .reg_base = DWC2_REG_BASE, .irqnum = 86, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 1280 }
41 | };
42 |
43 | extern uint32_t SystemCoreClock;
44 |
45 | // The GD32VF103 is a RISC-V MCU, which implements the ECLIC Core-Local
46 | // Interrupt Controller by Nuclei. It is nearly API compatible to the
47 | // NVIC used by ARM MCUs.
48 | #define ECLIC_INTERRUPT_ENABLE_BASE 0xD2001001UL
49 |
50 | TU_ATTR_ALWAYS_INLINE
51 | static inline void __eclic_enable_interrupt (uint32_t irq) {
52 | *(volatile uint8_t*)(ECLIC_INTERRUPT_ENABLE_BASE + (irq * 4)) = 1;
53 | }
54 |
55 | TU_ATTR_ALWAYS_INLINE
56 | static inline void __eclic_disable_interrupt (uint32_t irq){
57 | *(volatile uint8_t*)(ECLIC_INTERRUPT_ENABLE_BASE + (irq * 4)) = 0;
58 | }
59 |
60 | TU_ATTR_ALWAYS_INLINE
61 | static inline void dwc2_dcd_int_enable(uint8_t rhport)
62 | {
63 | __eclic_enable_interrupt(_dwc2_controller[rhport].irqnum);
64 | }
65 |
66 | TU_ATTR_ALWAYS_INLINE
67 | static inline void dwc2_dcd_int_disable (uint8_t rhport)
68 | {
69 | __eclic_disable_interrupt(_dwc2_controller[rhport].irqnum);
70 | }
71 |
72 | static inline void dwc2_remote_wakeup_delay(void)
73 | {
74 | // try to delay for 1 ms
75 | uint32_t count = SystemCoreClock / 1000;
76 | while ( count-- ) __asm volatile ("nop");
77 | }
78 |
79 | // MCU specific PHY init, called BEFORE core reset
80 | static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
81 | {
82 | (void) dwc2;
83 | (void) hs_phy_type;
84 |
85 | // nothing to do
86 | }
87 |
88 | // MCU specific PHY update, it is called AFTER init() and core reset
89 | static inline void dwc2_phy_update(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
90 | {
91 | (void) dwc2;
92 | (void) hs_phy_type;
93 |
94 | // nothing to do
95 | }
96 |
97 | #ifdef __cplusplus
98 | }
99 | #endif
100 |
101 | #endif /* DWC2_GD32_H_ */
102 |
--------------------------------------------------------------------------------
/src/portable/synopsys/dwc2/dwc2_xmc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2021 Rafael Silva (@perigoso)
5 | * Copyright (c) 2021, Ha Thach (tinyusb.org)
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | *
25 | * This file is part of the TinyUSB stack.
26 | */
27 |
28 | #ifndef _DWC2_XMC_H_
29 | #define _DWC2_XMC_H_
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | #include "xmc_device.h"
36 |
37 | #define DWC2_EP_MAX 7
38 |
39 | static const dwc2_controller_t _dwc2_controller[] =
40 | {
41 | // Note: XMC has some custom control registers before DWC registers
42 | { .reg_base = USB0_BASE, .irqnum = USB0_0_IRQn, .ep_count = DWC2_EP_MAX, .ep_fifo_size = 2048 }
43 | };
44 |
45 | TU_ATTR_ALWAYS_INLINE
46 | static inline void dwc2_dcd_int_enable(uint8_t rhport)
47 | {
48 | NVIC_EnableIRQ(_dwc2_controller[rhport].irqnum);
49 | }
50 |
51 | TU_ATTR_ALWAYS_INLINE
52 | static inline void dwc2_dcd_int_disable (uint8_t rhport)
53 | {
54 | NVIC_DisableIRQ(_dwc2_controller[rhport].irqnum);
55 | }
56 |
57 | static inline void dwc2_remote_wakeup_delay(void)
58 | {
59 | // try to delay for 1 ms
60 | // uint32_t count = SystemCoreClock / 1000;
61 | // while ( count-- ) __NOP();
62 | }
63 |
64 | // MCU specific PHY init, called BEFORE core reset
65 | static inline void dwc2_phy_init(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
66 | {
67 | (void) dwc2;
68 | (void) hs_phy_type;
69 |
70 | // Enable PHY
71 | //USB->ROUTE = USB_ROUTE_PHYPEN;
72 | }
73 |
74 | // MCU specific PHY update, it is called AFTER init() and core reset
75 | static inline void dwc2_phy_update(dwc2_regs_t * dwc2, uint8_t hs_phy_type)
76 | {
77 | (void) dwc2;
78 | (void) hs_phy_type;
79 |
80 | // XMC Manual: turn around must be 5 (reset & default value)
81 | // dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_TRDT_Msk) | (5u << GUSBCFG_TRDT_Pos);
82 | }
83 |
84 | #ifdef __cplusplus
85 | }
86 | #endif
87 |
88 | #endif
89 |
--------------------------------------------------------------------------------
/src/tusb_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2018, hathach for Adafruit
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #ifndef TUSB_CONFIG_ARDUINO_H_
26 | #define TUSB_CONFIG_ARDUINO_H_
27 |
28 | #ifdef __cplusplus
29 | extern "C" {
30 | #endif
31 |
32 | #if defined(ARDUINO_ARCH_SAMD)
33 | #include "arduino/ports/samd/tusb_config_samd.h"
34 |
35 | #elif defined(ARDUINO_NRF52_ADAFRUIT)
36 | #include "arduino/ports/nrf/tusb_config_nrf.h"
37 |
38 | #elif defined(ARDUINO_ARCH_RP2040)
39 | #include "arduino/ports/rp2040/tusb_config_rp2040.h"
40 |
41 | #elif defined(ARDUINO_ARCH_ESP32)
42 | // Note: when compiling core Arduino IDEs will include tusb_config.h in the BSP
43 | // sdk/include/arduino_tinyusb/include. While compiling .c file in this library this
44 | // file will be used instead. For consistency: include the one in BSP here as well
45 | #include "sdkconfig.h"
46 | #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
47 | #include "../../arduino_tinyusb/include/tusb_config.h"
48 | #else
49 | #include "arduino/ports/esp32/tusb_config_esp32.h"
50 | #endif
51 |
52 | // Note: For platformio prioritize this file over the one in BSP in all cases
53 |
54 | #elif defined(ARDUINO_ARCH_CH32) || defined(CH32V20x) || defined(CH32V30x)
55 | #include "arduino/ports/ch32/tusb_config_ch32.h"
56 | #else
57 | #error TinyUSB Arduino Library does not support your core yet
58 | #endif
59 |
60 | // Debug TinyUSB with Serial1
61 | #if CFG_TUSB_DEBUG
62 | #define CFG_TUSB_DEBUG_PRINTF log_printf
63 | #endif
64 |
65 | #ifdef __cplusplus
66 | }
67 | #endif
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/tools/update-usbh_helper.py:
--------------------------------------------------------------------------------
1 | from pathlib import Path
2 | import click
3 | import sys
4 | import shutil
5 |
6 | @click.command()
7 | @click.argument('dir', type=click.Path(), required=True)
8 | def main(dir):
9 | """
10 | This script takes a mandatory 'dir' argument, which is a path to pivot example to update for all DualRole's examples
11 | """
12 | sample_dir = Path(dir)
13 | if not sample_dir.is_dir():
14 | # add examples/DualRoles to the path
15 | sample_dir = Path('examples/DualRole') / sample_dir
16 | if not sample_dir.is_dir():
17 | click.echo(f"The specified dir '{dir}' does not exist or is not a valid dir.")
18 | sys.exit(1)
19 |
20 | sample_file = sample_dir / 'usbh_helper.h'
21 | f_list = sorted(Path('examples/DualRole').glob('**/usbh_helper.h'))
22 | for f in f_list:
23 | if f != sample_file:
24 | click.echo(f"Updating {f}")
25 | shutil.copy(sample_file, f)
26 |
27 |
28 | if __name__ == '__main__':
29 | main()
--------------------------------------------------------------------------------