Skip to content

Commit

Permalink
Merge pull request #298 from adafruit/rework-tinyusb
Browse files Browse the repository at this point in the history
Rework tinyusb lib
  • Loading branch information
hathach authored May 19, 2021
2 parents 32b62c8 + 461f855 commit 7585cb7
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 232 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ jobs:
strategy:
fail-fast: false
matrix:
arduino-platform: ['metro_m0', 'hallowing', 'circuitplayground_m0',
'metro_m4', 'pybadge_m4', 'pygamer_m4', 'hallowing_m4', 'pyportal_m4', 'pyportal_m4_titano']
arduino-platform:
# Alphabetical order
- 'metro_m0'
- 'hallowing'
- 'circuitplayground_m0'
- 'metro_m4'
- 'pybadge_m4'
- 'pygamer_m4'
- 'hallowing_m4'
- 'pyportal_m4'
- 'pyportal_m4_titano'
- 'feather_m4_can'

runs-on: ubuntu-latest

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.atsuo

bootloaders/*/build/
*~
*~
/libraries/**/build/
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "cores/arduino/TinyUSB/Adafruit_TinyUSB_ArduinoCore"]
path = cores/arduino/TinyUSB/Adafruit_TinyUSB_ArduinoCore
url = https://github.com/adafruit/Adafruit_TinyUSB_ArduinoCore.git
[submodule "libraries/Adafruit_TinyUSB_Arduino"]
path = libraries/Adafruit_TinyUSB_Arduino
url = https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git
11 changes: 6 additions & 5 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ void loop( void ) ;

// USB
#ifdef USE_TINYUSB
#include "Adafruit_TinyUSB_Core.h"
// Needed for declaring Serial
#include "Adafruit_USBD_CDC.h"
#else
#include "USB/USBDesc.h"
#include "USB/USBCore.h"
#include "USB/USBAPI.h"
#include "USB/USB_host.h"
#include "USB/USBDesc.h"
#include "USB/USBCore.h"
#include "USB/USBAPI.h"
#include "USB/USB_host.h"
#endif

#endif // Arduino_h
1 change: 0 additions & 1 deletion cores/arduino/TinyUSB/Adafruit_TinyUSB_ArduinoCore
Submodule Adafruit_TinyUSB_ArduinoCore deleted from e7b892
195 changes: 0 additions & 195 deletions cores/arduino/TinyUSB/Adafruit_TinyUSB_SAMD.cpp

This file was deleted.

11 changes: 11 additions & 0 deletions cores/arduino/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ void SysTick_DefaultHandler(void)
tickReset();
}

#if defined(USE_TINYUSB)

// run TinyUSB background task when yield()
void yield(void)
{
TinyUSB_Device_Task();
TinyUSB_Device_FlushCDC();
}

#endif

#ifdef __cplusplus
}
#endif
13 changes: 1 addition & 12 deletions cores/arduino/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main( void )
delay(1);

#if defined(USE_TINYUSB)
Adafruit_TinyUSB_Core_init();
TinyUSB_Device_Init(0);
#elif defined(USBCON)
USBDevice.init();
USBDevice.attach();
Expand All @@ -59,14 +59,3 @@ int main( void )

return 0;
}

#if defined(USE_TINYUSB)

// run TinyUSB background task when yield()
extern "C" void yield(void)
{
tud_task();
tud_cdc_write_flush();
}

#endif
File renamed without changes.
6 changes: 5 additions & 1 deletion extras/build_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
metavar='board',
nargs='*',
help='list of boards to be built -- Note that the fqbn is created by prepending "{}"'.format(FQBN_PREFIX),
default= [ 'metro_m0', 'metro_m4', 'circuitplayground_m0' ]
default= [ 'metro_m0', 'metro_m4', 'circuitplayground_m0', 'feather_m4_can' ]
)
args = parser.parse_args()

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

for sketch in glob.iglob('libraries/**/*.ino', recursive=True):
# TODO skip TinyUSB library examples for now
if "libraries/Adafruit_TinyUSB_Arduino" in sketch:
continue

start_time = time.monotonic()

# Skip if contains: ".board.test.skip" or ".all.test.skip"
Expand Down
1 change: 1 addition & 0 deletions libraries/Adafruit_TinyUSB_Arduino
16 changes: 10 additions & 6 deletions libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,21 +332,25 @@ void SPIClass::dmaAllocate(void) {
totalDescriptors * sizeof(DmacDescriptor)))) {
use_dma = true; // Everything allocated successfully
extraWriteDescriptors = &extraReadDescriptors[numReadDescriptors];

// dmac.h didn't include extern "C" which cause
// DmacDescriptor and its members are defined as C++ struct therefore
// memcpy will throw warning on copying where simple assignment won't work
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"

// Initialize descriptors (copy from first ones)
for(int i=0; i<numReadDescriptors; i++) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
memcpy(&extraReadDescriptors[i], firstReadDescriptor,
sizeof(DmacDescriptor));
#pragma GCC diagnostic pop
}
for(int i=0; i<numWriteDescriptors; i++) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wclass-memaccess"
memcpy(&extraWriteDescriptors[i], firstWriteDescriptor,
sizeof(DmacDescriptor));
#pragma GCC diagnostic pop
}

#pragma GCC diagnostic pop

} // end malloc
} // end extra descriptor check

Expand Down
2 changes: 1 addition & 1 deletion platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ compiler.libraries.ldflags=

# USB Flags
# ---------
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"
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"

# Default advertised device power setting in mA
build.usb_power=100
Expand Down
7 changes: 2 additions & 5 deletions variants/circuitplay/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,7 @@ extern Uart Serial1;
//
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
// pins are NOT connected to anything by default.
#define SERIAL_PORT_USBVIRTUAL SerialUSB
#define SERIAL_PORT_MONITOR SerialUSB
#define SERIAL_PORT_USBVIRTUAL Serial
#define SERIAL_PORT_MONITOR Serial
#define SERIAL_PORT_HARDWARE Serial1
#define SERIAL_PORT_HARDWARE_OPEN Serial1

// Alias Serial to SerialUSB
#define Serial SerialUSB

0 comments on commit 7585cb7

Please sign in to comment.