Skip to content

Rework tinyusb lib #640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ jobs:
# https://github.com/firmata/arduino/pull/438
git clone --depth 1 https://github.com/firmata/arduino.git $HOME/Arduino/libraries/firmata

# TODO temporarily remove TinyUSB pre-1.0.0 version install by arduino-cli
rm -r $HOME/Arduino/libraries/Adafruit_TinyUSB_Library

# Library summary
arduino-cli lib list

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
# Ignore local overrides of platform.txt and boards.txt,
/boards.local.txt
/platform.local.txt
/libraries/**/build/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "libraries/Adafruit_nRFCrypto"]
path = libraries/Adafruit_nRFCrypto
url = https://github.com/adafruit/Adafruit_nRFCrypto.git
[submodule "libraries/Adafruit_TinyUSB_Arduino"]
path = libraries/Adafruit_TinyUSB_Arduino
url = https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git
9 changes: 5 additions & 4 deletions cores/nRF5/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ void resumeLoop(void);
#include "pulse.h"
#include "HardwarePWM.h"
#include "utility/SoftwareTimer.h"

#include "Uart.h"
#endif

#ifdef USE_TINYUSB
// Needed for declaring Serial
#include "Adafruit_USBD_CDC.h"
#endif

#include "delay.h"
#include "binary.h"
#include "common_inc.h"
#include "utility/debug.h"
#include "utility/utilities.h"
#include "utility/AdaCallback.h"

#ifdef USE_TINYUSB
#include "Adafruit_TinyUSB_Core.h"
#endif

// Include board variant
#include "variant.h"
Expand Down
1 change: 0 additions & 1 deletion cores/nRF5/TinyUSB/Adafruit_TinyUSB_ArduinoCore
Submodule Adafruit_TinyUSB_ArduinoCore deleted from e7b892
137 changes: 0 additions & 137 deletions cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp

This file was deleted.

4 changes: 3 additions & 1 deletion cores/nRF5/common_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
#ifndef COMMON_INC_H_
#define COMMON_INC_H_

#define ATTR_PACKED __attribute__ ((packed))
#define ATTR_WEAK __attribute__((weak))

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

#include "compiler_macro.h"
#include "common_func.h"
#include "verify.h"

Expand Down
48 changes: 0 additions & 48 deletions cores/nRF5/compiler_macro.h

This file was deleted.

2 changes: 1 addition & 1 deletion cores/nRF5/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void delay( uint32_t ms )
#ifdef USE_TINYUSB
// Take chance to flush usb cdc
uint32_t flush_tick = xTaskGetTickCount();
tud_cdc_write_flush();
TinyUSB_Device_FlushCDC();

flush_tick = xTaskGetTickCount()-flush_tick;
if (flush_tick >= ticks) return;
Expand Down
28 changes: 14 additions & 14 deletions cores/nRF5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@

#define ARDUINO_MAIN
#include "Arduino.h"

#if (CFG_LOGGER == 2)
#include <SEGGER_RTT.h>
#endif

// From the UI, setting debug level to 3 will enable SysView
#if CFG_SYSVIEW
#include "SEGGER_RTT.h"
#include "SEGGER_SYSVIEW.h"
#endif

// DEBUG Level 1
#if CFG_DEBUG
// weak function to avoid compilation error with
Expand All @@ -27,15 +34,6 @@ void Bluefruit_printInfo() __attribute__((weak));
void Bluefruit_printInfo() {}
#endif

// From the UI, setting debug level to 3 will enable SysView
#if CFG_SYSVIEW
#include "SEGGER_RTT.h"
#include "SEGGER_SYSVIEW.h"
#endif

static TaskHandle_t _loopHandle;


// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
Expand All @@ -44,10 +42,16 @@ void initVariant() { }
#define LOOP_STACK_SZ (256*4)
#define CALLBACK_STACK_SZ (256*3)

static TaskHandle_t _loopHandle;

static void loop_task(void* arg)
{
(void) arg;

#ifdef USE_TINYUSB
TinyUSB_Device_Init(0);
#endif

#if CFG_DEBUG
// If Serial is not begin(), call it to avoid hard fault
if(!Serial) Serial.begin(115200);
Expand Down Expand Up @@ -80,12 +84,8 @@ int main( void )
SEGGER_SYSVIEW_Conf();
#endif

#ifdef USE_TINYUSB
Adafruit_TinyUSB_Core_init();
#endif

// Create a task for loop()
xTaskCreate( loop_task, "loop", LOOP_STACK_SZ, NULL, TASK_PRIO_LOW, &_loopHandle);
xTaskCreate(loop_task, "loop", LOOP_STACK_SZ, NULL, TASK_PRIO_LOW, &_loopHandle);

// Initialize callback task
ada_callback_init(CALLBACK_STACK_SZ);
Expand Down
2 changes: 1 addition & 1 deletion cores/nRF5/rtos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extern "C"
void yield(void)
{
#ifdef USE_TINYUSB
tud_cdc_write_flush();
TinyUSB_Device_FlushCDC();
#endif

taskYIELD();
Expand Down
File renamed without changes.
12 changes: 4 additions & 8 deletions cores/nRF5/verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@
#ifndef _VERIFY_H_
#define _VERIFY_H_

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

#ifdef __cplusplus
extern "C"
{
#endif

//--------------------------------------------------------------------+
// Compile-time Assert
//--------------------------------------------------------------------+
#define VERIFY_STATIC(const_expr) TU_VERIFY_STATIC(const_expr, "Assert failed")

//--------------------------------------------------------------------+
// VERIFY Helper
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -132,8 +130,6 @@ extern "C"
*/
#define VERIFY(...) _GET_3RD_ARG(__VA_ARGS__, VERIFY_2ARGS, VERIFY_1ARGS)(__VA_ARGS__)

// TODO VERIFY with final statement

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions libraries/Adafruit_TinyUSB_Arduino
2 changes: 1 addition & 1 deletion libraries/Adafruit_nRFCrypto
2 changes: 2 additions & 0 deletions libraries/Bluefruit52Lib/examples/Hardware/Fading/Fading.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

*/

#include <Arduino.h>
#include <Adafruit_TinyUSB.h> // for Serial

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
* Note: Bluefruit nRF52832 does not support Serial1
*/

#include "Arduino.h"
#include <Arduino.h>
#include <Adafruit_TinyUSB.h> // for Serial

void setup()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*********************************************************************/

#include <Arduino.h>
#include <Adafruit_TinyUSB.h> // for Serial

const int baudrate = 115200;

Expand Down
Loading