Skip to content

Commit 9ce304a

Browse files
committed
Update TinyUSB to version 3.7.3
1 parent 357c2e8 commit 9ce304a

File tree

260 files changed

+44552
-17303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

260 files changed

+44552
-17303
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
run: |
118118
cat > example/platformio.ini << EOF
119119
[env]
120-
platform = https://github.com/h2zero/platform-n-able.git#1.1.3
120+
platform = https://github.com/h2zero/platform-n-able.git
121121
platform_packages = framework-n-able-arduino @ file://./framework
122122
framework = arduino
123123
${{ matrix.flags }}

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ For example: `'-DCONFIG_MAIN_TASK_STACK_SIZE=512'` This will set the main task s
139139
* `CONFIG_RTOS_MIN_TASK_STACK_SIZE` - set the minimum task stack size.
140140
* `CONFIG_RTOS_TIMER_QUEUE_LENGTH` - set the queue size for the FreeRTOS timers.
141141
* `CONFIG_RTOS_TIMER_STACK_DEPTH` - set the timer task stack size **in 32bit words**.
142+
* `CONFIG_RTOS_THREAD_LOCAL_STORAGE_POINTERS` - set the number of thread local storage pointers for FreeRTOS tasks (default 1, used for printf buffer management).
142143
* `CONFIG_WDT_TIMEOUT_SECONDS` - set the number of seconds before the watchdog times out (0 = disable watchdog, default = 0).
144+
* `CONFIG_PRINTF_BUFFER_SIZE` - set the size of the buffer used for `printf` and `Serial.printf` (default 128 bytes, set to 1 for no buffer).
145+
* `CONFIG_PRINTF_BUFFER_INDEX` - set the FreeRTOS storage pointer index used for managing the `printf` buffer (default 0).
143146
* Nimble configuration options can also be included, the list of those can be found [here](https://h2zero.github.io/NimBLE-Arduino/md__command_line_config.html)
144147
* Other compiler options or definitions for other libraries can also be specified.
145148

@@ -158,6 +161,10 @@ There are a few useful functions available to help with your project.
158161
* `uint32_t getResetReason();` - Returns the reset reason for the last boot.
159162
* `void systemPowerOff();` - Shuts down the MCU.
160163
* `void systemRestart();` - Reboot.
164+
* For USB supported boards, additional USB functions beyond CDC are available by including the TinyUSB library (built in) by adding the following to your sketch:
165+
```cpp
166+
#include "Adafruit_TinyUSB.h"
167+
```
161168

162169
## Bootloader
163170
Currently only some boards have Adafruit bootloaders available which are provided as options. You may choose to use the bootloader or none.

cores/nRF5/Arduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void loop( void ) ;
6262
#endif
6363

6464
#ifdef USE_TINYUSB
65-
#include "Adafruit_TinyUSB_Core.h"
65+
#include "Adafruit_USBD_CDC.h"
6666
#endif
6767

6868
// Include board variant
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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_USBD_Device.h"
30+
#include "Arduino.h"
31+
32+
extern "C" {
33+
34+
uint32_t tusb_time_millis_api(void) { return millis(); }
35+
36+
//--------------------------------------------------------------------+
37+
// Device
38+
//--------------------------------------------------------------------+
39+
#if CFG_TUD_ENABLED
40+
void TinyUSB_Device_Init(uint8_t rhport) {
41+
// Init USB Device controller and stack
42+
TinyUSBDevice.begin(rhport);
43+
}
44+
45+
// RP2040 has its own implementation since it needs mutex for dual core
46+
#ifndef ARDUINO_ARCH_RP2040
47+
void TinyUSB_Device_Task(void) {
48+
// Run tinyusb device task
49+
tud_task();
50+
}
51+
#endif
52+
53+
#ifndef ARDUINO_ARCH_ESP32
54+
void TinyUSB_Device_FlushCDC(void) {
55+
uint8_t const cdc_instance = Adafruit_USBD_CDC::getInstanceCount();
56+
for (uint8_t instance = 0; instance < cdc_instance; instance++) {
57+
tud_cdc_n_write_flush(instance);
58+
}
59+
}
60+
#endif
61+
#endif // CFG_TUD_ENABLED
62+
63+
//------------- Debug log with Serial1 -------------//
64+
#if CFG_TUSB_DEBUG && defined(CFG_TUSB_DEBUG_PRINTF) && \
65+
!defined(ARDUINO_ARCH_ESP32)
66+
67+
// #define USE_SEGGER_RTT
68+
#ifndef SERIAL_TUSB_DEBUG
69+
#define SERIAL_TUSB_DEBUG Serial1
70+
#endif
71+
72+
#ifdef USE_SEGGER_RTT
73+
#include "SEGGER_RTT/RTT/SEGGER_RTT.h"
74+
#endif
75+
76+
__attribute__((used)) int CFG_TUSB_DEBUG_PRINTF(const char *__restrict format,
77+
...) {
78+
char buf[256];
79+
int len;
80+
va_list ap;
81+
va_start(ap, format);
82+
len = vsnprintf(buf, sizeof(buf), format, ap);
83+
84+
#ifdef USE_SEGGER_RTT
85+
SEGGER_RTT_Write(0, buf, len);
86+
#else
87+
static volatile bool ser_inited = false;
88+
if (!ser_inited) {
89+
ser_inited = true;
90+
SERIAL_TUSB_DEBUG.begin(115200);
91+
// SERIAL_TUSB_DEBUG.begin(921600);
92+
}
93+
SERIAL_TUSB_DEBUG.write(buf);
94+
#endif
95+
96+
va_end(ap);
97+
return len;
98+
}
99+
#endif // CFG_TUSB_DEBUG
100+
101+
} // extern C
102+
103+
#endif // CFG_TUD_ENABLED || CFG_TUH_ENABLED
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 <stdbool.h>
29+
#include <stdint.h>
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+
//--------------------------------------------------------------------+
36+
// Core API
37+
// Should be called by BSP Core to initialize, process task
38+
// Weak function allow compile arduino core before linking with this library
39+
//--------------------------------------------------------------------+
40+
#ifdef __cplusplus
41+
extern "C" {
42+
#endif
43+
44+
// Called by core/sketch to initialize usb device hardware and stack
45+
// This also initialize Serial as CDC device
46+
void TinyUSB_Device_Init(uint8_t rhport) __attribute__((weak));
47+
48+
// Called by core/sketch to handle device event
49+
void TinyUSB_Device_Task(void) __attribute__((weak));
50+
51+
// Called by core/sketch to flush write on CDC
52+
void TinyUSB_Device_FlushCDC(void) __attribute__((weak));
53+
54+
#ifdef __cplusplus
55+
}
56+
#endif
57+
58+
//--------------------------------------------------------------------+
59+
// Port API
60+
// Must be implemented by each BSP core/platform
61+
//--------------------------------------------------------------------+
62+
63+
// To enter/reboot to bootloader
64+
// usually when host disconnects cdc at baud 1200 (touch 1200)
65+
void TinyUSB_Port_EnterDFU(void);
66+
67+
// Init device hardware.
68+
// Called by TinyUSB_Device_Init()
69+
void TinyUSB_Port_InitDevice(uint8_t rhport);
70+
71+
// Get unique serial number, needed for Serial String Descriptor
72+
// Fill serial_id (raw bytes) and return its length (limit to 16 bytes)
73+
// Note: Serial descriptor can be overwritten by user API
74+
uint8_t TinyUSB_Port_GetSerialNumber(uint8_t serial_id[16]);
75+
76+
#endif

0 commit comments

Comments
 (0)