Skip to content

Commit 7585cb7

Browse files
authored
Merge pull request #298 from adafruit/rework-tinyusb
Rework tinyusb lib
2 parents 32b62c8 + 461f855 commit 7585cb7

File tree

14 files changed

+54
-232
lines changed

14 files changed

+54
-232
lines changed

.github/workflows/githubci.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
arduino-platform: ['metro_m0', 'hallowing', 'circuitplayground_m0',
11-
'metro_m4', 'pybadge_m4', 'pygamer_m4', 'hallowing_m4', 'pyportal_m4', 'pyportal_m4_titano']
10+
arduino-platform:
11+
# Alphabetical order
12+
- 'metro_m0'
13+
- 'hallowing'
14+
- 'circuitplayground_m0'
15+
- 'metro_m4'
16+
- 'pybadge_m4'
17+
- 'pygamer_m4'
18+
- 'hallowing_m4'
19+
- 'pyportal_m4'
20+
- 'pyportal_m4_titano'
21+
- 'feather_m4_can'
1222

1323
runs-on: ubuntu-latest
1424

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
*.atsuo
33

44
bootloaders/*/build/
5-
*~
5+
*~
6+
/libraries/**/build/

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "cores/arduino/TinyUSB/Adafruit_TinyUSB_ArduinoCore"]
2-
path = cores/arduino/TinyUSB/Adafruit_TinyUSB_ArduinoCore
3-
url = https://github.com/adafruit/Adafruit_TinyUSB_ArduinoCore.git
1+
[submodule "libraries/Adafruit_TinyUSB_Arduino"]
2+
path = libraries/Adafruit_TinyUSB_Arduino
3+
url = https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git

cores/arduino/Arduino.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,13 @@ void loop( void ) ;
150150

151151
// USB
152152
#ifdef USE_TINYUSB
153-
#include "Adafruit_TinyUSB_Core.h"
153+
// Needed for declaring Serial
154+
#include "Adafruit_USBD_CDC.h"
154155
#else
155-
#include "USB/USBDesc.h"
156-
#include "USB/USBCore.h"
157-
#include "USB/USBAPI.h"
158-
#include "USB/USB_host.h"
156+
#include "USB/USBDesc.h"
157+
#include "USB/USBCore.h"
158+
#include "USB/USBAPI.h"
159+
#include "USB/USB_host.h"
159160
#endif
160161

161162
#endif // Arduino_h
Lines changed: 0 additions & 1 deletion
This file was deleted.

cores/arduino/TinyUSB/Adafruit_TinyUSB_SAMD.cpp

Lines changed: 0 additions & 195 deletions
This file was deleted.

cores/arduino/delay.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ void SysTick_DefaultHandler(void)
117117
tickReset();
118118
}
119119

120+
#if defined(USE_TINYUSB)
121+
122+
// run TinyUSB background task when yield()
123+
void yield(void)
124+
{
125+
TinyUSB_Device_Task();
126+
TinyUSB_Device_FlushCDC();
127+
}
128+
129+
#endif
130+
120131
#ifdef __cplusplus
121132
}
122133
#endif

cores/arduino/main.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main( void )
4141
delay(1);
4242

4343
#if defined(USE_TINYUSB)
44-
Adafruit_TinyUSB_Core_init();
44+
TinyUSB_Device_Init(0);
4545
#elif defined(USBCON)
4646
USBDevice.init();
4747
USBDevice.attach();
@@ -59,14 +59,3 @@ int main( void )
5959

6060
return 0;
6161
}
62-
63-
#if defined(USE_TINYUSB)
64-
65-
// run TinyUSB background task when yield()
66-
extern "C" void yield(void)
67-
{
68-
tud_task();
69-
tud_cdc_write_flush();
70-
}
71-
72-
#endif
File renamed without changes.

extras/build_all.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
metavar='board',
2828
nargs='*',
2929
help='list of boards to be built -- Note that the fqbn is created by prepending "{}"'.format(FQBN_PREFIX),
30-
default= [ 'metro_m0', 'metro_m4', 'circuitplayground_m0' ]
30+
default= [ 'metro_m0', 'metro_m4', 'circuitplayground_m0', 'feather_m4_can' ]
3131
)
3232
args = parser.parse_args()
3333

@@ -59,6 +59,10 @@ def build_examples(variant: str):
5959
fqbn = "{}{}".format(FQBN_PREFIX, variant)
6060

6161
for sketch in glob.iglob('libraries/**/*.ino', recursive=True):
62+
# TODO skip TinyUSB library examples for now
63+
if "libraries/Adafruit_TinyUSB_Arduino" in sketch:
64+
continue
65+
6266
start_time = time.monotonic()
6367

6468
# Skip if contains: ".board.test.skip" or ".all.test.skip"

libraries/Adafruit_TinyUSB_Arduino

libraries/SPI/SPI.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,21 +332,25 @@ void SPIClass::dmaAllocate(void) {
332332
totalDescriptors * sizeof(DmacDescriptor)))) {
333333
use_dma = true; // Everything allocated successfully
334334
extraWriteDescriptors = &extraReadDescriptors[numReadDescriptors];
335+
336+
// dmac.h didn't include extern "C" which cause
337+
// DmacDescriptor and its members are defined as C++ struct therefore
338+
// memcpy will throw warning on copying where simple assignment won't work
339+
#pragma GCC diagnostic push
340+
#pragma GCC diagnostic ignored "-Wclass-memaccess"
341+
335342
// Initialize descriptors (copy from first ones)
336343
for(int i=0; i<numReadDescriptors; i++) {
337-
#pragma GCC diagnostic push
338-
#pragma GCC diagnostic ignored "-Wclass-memaccess"
339344
memcpy(&extraReadDescriptors[i], firstReadDescriptor,
340345
sizeof(DmacDescriptor));
341-
#pragma GCC diagnostic pop
342346
}
343347
for(int i=0; i<numWriteDescriptors; i++) {
344-
#pragma GCC diagnostic push
345-
#pragma GCC diagnostic ignored "-Wclass-memaccess"
346348
memcpy(&extraWriteDescriptors[i], firstWriteDescriptor,
347349
sizeof(DmacDescriptor));
348-
#pragma GCC diagnostic pop
349350
}
351+
352+
#pragma GCC diagnostic pop
353+
350354
} // end malloc
351355
} // end extra descriptor check
352356

platform.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ compiler.libraries.ldflags=
7777

7878
# USB Flags
7979
# ---------
80-
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON -DUSB_CONFIG_POWER={build.usb_power} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' {build.flags.usbstack} {build.flags.debug} "-I{build.core.path}/TinyUSB" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore" "-I{build.core.path}/TinyUSB/Adafruit_TinyUSB_ArduinoCore/tinyusb/src"
80+
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON -DUSB_CONFIG_POWER={build.usb_power} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}' {build.flags.usbstack} {build.flags.debug} "-I{runtime.platform.path}/libraries/Adafruit_TinyUSB_Arduino/src/arduino"
8181

8282
# Default advertised device power setting in mA
8383
build.usb_power=100

variants/circuitplay/variant.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,7 @@ extern Uart Serial1;
242242
//
243243
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
244244
// pins are NOT connected to anything by default.
245-
#define SERIAL_PORT_USBVIRTUAL SerialUSB
246-
#define SERIAL_PORT_MONITOR SerialUSB
245+
#define SERIAL_PORT_USBVIRTUAL Serial
246+
#define SERIAL_PORT_MONITOR Serial
247247
#define SERIAL_PORT_HARDWARE Serial1
248248
#define SERIAL_PORT_HARDWARE_OPEN Serial1
249-
250-
// Alias Serial to SerialUSB
251-
#define Serial SerialUSB

0 commit comments

Comments
 (0)