Skip to content

Commit 00d0801

Browse files
authored
Merge pull request #640 from adafruit/rework-tinyusb-lib
Rework tinyusb lib
2 parents 8eb3e2b + 5485717 commit 00d0801

File tree

55 files changed

+97
-226
lines changed

Some content is hidden

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

55 files changed

+97
-226
lines changed

.github/workflows/githubci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ jobs:
6262
# https://github.com/firmata/arduino/pull/438
6363
git clone --depth 1 https://github.com/firmata/arduino.git $HOME/Arduino/libraries/firmata
6464
65+
# TODO temporarily remove TinyUSB pre-1.0.0 version install by arduino-cli
66+
rm -r $HOME/Arduino/libraries/Adafruit_TinyUSB_Library
67+
6568
# Library summary
6669
arduino-cli lib list
6770

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
# Ignore local overrides of platform.txt and boards.txt,
2121
/boards.local.txt
2222
/platform.local.txt
23+
/libraries/**/build/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "libraries/Adafruit_nRFCrypto"]
55
path = libraries/Adafruit_nRFCrypto
66
url = https://github.com/adafruit/Adafruit_nRFCrypto.git
7+
[submodule "libraries/Adafruit_TinyUSB_Arduino"]
8+
path = libraries/Adafruit_TinyUSB_Arduino
9+
url = https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git

cores/nRF5/Arduino.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,21 @@ void resumeLoop(void);
5757
#include "pulse.h"
5858
#include "HardwarePWM.h"
5959
#include "utility/SoftwareTimer.h"
60-
6160
#include "Uart.h"
6261
#endif
6362

63+
#ifdef USE_TINYUSB
64+
// Needed for declaring Serial
65+
#include "Adafruit_USBD_CDC.h"
66+
#endif
67+
6468
#include "delay.h"
6569
#include "binary.h"
6670
#include "common_inc.h"
6771
#include "utility/debug.h"
6872
#include "utility/utilities.h"
6973
#include "utility/AdaCallback.h"
7074

71-
#ifdef USE_TINYUSB
72-
#include "Adafruit_TinyUSB_Core.h"
73-
#endif
7475

7576
// Include board variant
7677
#include "variant.h"

cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp

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

cores/nRF5/common_inc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@
3636
#ifndef COMMON_INC_H_
3737
#define COMMON_INC_H_
3838

39+
#define ATTR_PACKED __attribute__ ((packed))
40+
#define ATTR_WEAK __attribute__((weak))
41+
3942
#include <stdint.h>
4043
#include <stdbool.h>
4144
#include <stddef.h>
4245

43-
#include "compiler_macro.h"
4446
#include "common_func.h"
4547
#include "verify.h"
4648

cores/nRF5/compiler_macro.h

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

cores/nRF5/delay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void delay( uint32_t ms )
3737
#ifdef USE_TINYUSB
3838
// Take chance to flush usb cdc
3939
uint32_t flush_tick = xTaskGetTickCount();
40-
tud_cdc_write_flush();
40+
TinyUSB_Device_FlushCDC();
4141

4242
flush_tick = xTaskGetTickCount()-flush_tick;
4343
if (flush_tick >= ticks) return;

cores/nRF5/main.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@
1515

1616
#define ARDUINO_MAIN
1717
#include "Arduino.h"
18+
1819
#if (CFG_LOGGER == 2)
1920
#include <SEGGER_RTT.h>
2021
#endif
2122

23+
// From the UI, setting debug level to 3 will enable SysView
24+
#if CFG_SYSVIEW
25+
#include "SEGGER_RTT.h"
26+
#include "SEGGER_SYSVIEW.h"
27+
#endif
28+
2229
// DEBUG Level 1
2330
#if CFG_DEBUG
2431
// weak function to avoid compilation error with
@@ -27,15 +34,6 @@ void Bluefruit_printInfo() __attribute__((weak));
2734
void Bluefruit_printInfo() {}
2835
#endif
2936

30-
// From the UI, setting debug level to 3 will enable SysView
31-
#if CFG_SYSVIEW
32-
#include "SEGGER_RTT.h"
33-
#include "SEGGER_SYSVIEW.h"
34-
#endif
35-
36-
static TaskHandle_t _loopHandle;
37-
38-
3937
// Weak empty variant initialization function.
4038
// May be redefined by variant files.
4139
void initVariant() __attribute__((weak));
@@ -44,10 +42,16 @@ void initVariant() { }
4442
#define LOOP_STACK_SZ (256*4)
4543
#define CALLBACK_STACK_SZ (256*3)
4644

45+
static TaskHandle_t _loopHandle;
46+
4747
static void loop_task(void* arg)
4848
{
4949
(void) arg;
5050

51+
#ifdef USE_TINYUSB
52+
TinyUSB_Device_Init(0);
53+
#endif
54+
5155
#if CFG_DEBUG
5256
// If Serial is not begin(), call it to avoid hard fault
5357
if(!Serial) Serial.begin(115200);
@@ -80,12 +84,8 @@ int main( void )
8084
SEGGER_SYSVIEW_Conf();
8185
#endif
8286

83-
#ifdef USE_TINYUSB
84-
Adafruit_TinyUSB_Core_init();
85-
#endif
86-
8787
// Create a task for loop()
88-
xTaskCreate( loop_task, "loop", LOOP_STACK_SZ, NULL, TASK_PRIO_LOW, &_loopHandle);
88+
xTaskCreate(loop_task, "loop", LOOP_STACK_SZ, NULL, TASK_PRIO_LOW, &_loopHandle);
8989

9090
// Initialize callback task
9191
ada_callback_init(CALLBACK_STACK_SZ);

cores/nRF5/rtos.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extern "C"
7575
void yield(void)
7676
{
7777
#ifdef USE_TINYUSB
78-
tud_cdc_write_flush();
78+
TinyUSB_Device_FlushCDC();
7979
#endif
8080

8181
taskYIELD();
File renamed without changes.

cores/nRF5/verify.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,16 @@
4040
#ifndef _VERIFY_H_
4141
#define _VERIFY_H_
4242

43-
#include "compiler_macro.h"
43+
//--------------------------------------------------------------------+
44+
// Compile-time Assert
45+
//--------------------------------------------------------------------+
46+
#define VERIFY_STATIC(const_expr) _Static_assert(const_expr, "Assert failed")
4447

4548
#ifdef __cplusplus
4649
extern "C"
4750
{
4851
#endif
4952

50-
//--------------------------------------------------------------------+
51-
// Compile-time Assert
52-
//--------------------------------------------------------------------+
53-
#define VERIFY_STATIC(const_expr) TU_VERIFY_STATIC(const_expr, "Assert failed")
54-
5553
//--------------------------------------------------------------------+
5654
// VERIFY Helper
5755
//--------------------------------------------------------------------+
@@ -132,8 +130,6 @@ extern "C"
132130
*/
133131
#define VERIFY(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_2ARGS, VERIFY_1ARGS)(__VA_ARGS__)
134132

135-
// TODO VERIFY with final statement
136-
137133
#ifdef __cplusplus
138134
}
139135
#endif

libraries/Adafruit_TinyUSB_Arduino

libraries/Bluefruit52Lib/examples/Hardware/Fading/Fading.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
1818
*/
1919

20+
#include <Arduino.h>
21+
#include <Adafruit_TinyUSB.h> // for Serial
2022

2123
int ledPin = LED_RED; // LED connected to digital pin 9
2224

libraries/Bluefruit52Lib/examples/Hardware/Serial1_test/Serial1_test.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
* Note: Bluefruit nRF52832 does not support Serial1
1919
*/
2020

21-
#include "Arduino.h"
21+
#include <Arduino.h>
22+
#include <Adafruit_TinyUSB.h> // for Serial
2223

2324
void setup()
2425
{

libraries/Bluefruit52Lib/examples/Hardware/SerialEcho/SerialEcho.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*********************************************************************/
1414

1515
#include <Arduino.h>
16+
#include <Adafruit_TinyUSB.h> // for Serial
1617

1718
const int baudrate = 115200;
1819

0 commit comments

Comments
 (0)