⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
run: |
cat > example/platformio.ini << EOF
[env]
platform = https://github.com/h2zero/platform-n-able.git#1.1.3
platform = https://github.com/h2zero/platform-n-able.git
platform_packages = framework-n-able-arduino @ file://./framework
framework = arduino
${{ matrix.flags }}
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ For example: `'-DCONFIG_MAIN_TASK_STACK_SIZE=512'` This will set the main task s
* `CONFIG_RTOS_MIN_TASK_STACK_SIZE` - set the minimum task stack size.
* `CONFIG_RTOS_TIMER_QUEUE_LENGTH` - set the queue size for the FreeRTOS timers.
* `CONFIG_RTOS_TIMER_STACK_DEPTH` - set the timer task stack size **in 32bit words**.
* `CONFIG_RTOS_THREAD_LOCAL_STORAGE_POINTERS` - set the number of thread local storage pointers for FreeRTOS tasks (default 1, used for printf buffer management).
* `CONFIG_WDT_TIMEOUT_SECONDS` - set the number of seconds before the watchdog times out (0 = disable watchdog, default = 0).
* `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).
* `CONFIG_PRINTF_BUFFER_INDEX` - set the FreeRTOS storage pointer index used for managing the `printf` buffer (default 0).
* 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)
* Other compiler options or definitions for other libraries can also be specified.

Expand All @@ -158,6 +161,10 @@ There are a few useful functions available to help with your project.
* `uint32_t getResetReason();` - Returns the reset reason for the last boot.
* `void systemPowerOff();` - Shuts down the MCU.
* `void systemRestart();` - Reboot.
* 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:
```cpp
#include "Adafruit_TinyUSB.h"
```

## Bootloader
Currently only some boards have Adafruit bootloaders available which are provided as options. You may choose to use the bootloader or none.
Expand Down
2 changes: 1 addition & 1 deletion cores/nRF5/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void loop( void ) ;
#endif

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

// Include board variant
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "tusb_option.h"

#if CFG_TUD_ENABLED || CFG_TUH_ENABLED

#include "Adafruit_USBD_Device.h"
#include "Arduino.h"

extern "C" {

uint32_t tusb_time_millis_api(void) { return millis(); }

//--------------------------------------------------------------------+
// Device
//--------------------------------------------------------------------+
#if CFG_TUD_ENABLED
void TinyUSB_Device_Init(uint8_t rhport) {
// Init USB Device controller and stack
TinyUSBDevice.begin(rhport);
}

// RP2040 has its own implementation since it needs mutex for dual core
#ifndef ARDUINO_ARCH_RP2040
void TinyUSB_Device_Task(void) {
// Run tinyusb device task
tud_task();
}
#endif

#ifndef ARDUINO_ARCH_ESP32
void TinyUSB_Device_FlushCDC(void) {
uint8_t const cdc_instance = Adafruit_USBD_CDC::getInstanceCount();
for (uint8_t instance = 0; instance < cdc_instance; instance++) {
tud_cdc_n_write_flush(instance);
}
}
#endif
#endif // CFG_TUD_ENABLED

//------------- Debug log with Serial1 -------------//
#if CFG_TUSB_DEBUG && defined(CFG_TUSB_DEBUG_PRINTF) && \
!defined(ARDUINO_ARCH_ESP32)

// #define USE_SEGGER_RTT
#ifndef SERIAL_TUSB_DEBUG
#define SERIAL_TUSB_DEBUG Serial1
#endif

#ifdef USE_SEGGER_RTT
#include "SEGGER_RTT/RTT/SEGGER_RTT.h"
#endif

__attribute__((used)) int CFG_TUSB_DEBUG_PRINTF(const char *__restrict format,
...) {
char buf[256];
int len;
va_list ap;
va_start(ap, format);
len = vsnprintf(buf, sizeof(buf), format, ap);

#ifdef USE_SEGGER_RTT
SEGGER_RTT_Write(0, buf, len);
#else
static volatile bool ser_inited = false;
if (!ser_inited) {
ser_inited = true;
SERIAL_TUSB_DEBUG.begin(115200);
// SERIAL_TUSB_DEBUG.begin(921600);
}
SERIAL_TUSB_DEBUG.write(buf);
#endif

va_end(ap);
return len;
}
#endif // CFG_TUSB_DEBUG

} // extern C

#endif // CFG_TUD_ENABLED || CFG_TUH_ENABLED
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef ADAFRUIT_TINYUSB_API_H_
#define ADAFRUIT_TINYUSB_API_H_

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

// API Version, need to be updated when there is changes for
// TinyUSB_API, USBD_CDC, USBD_Device, USBD_Interface,
#define TINYUSB_API_VERSION 30000

//--------------------------------------------------------------------+
// Core API
// Should be called by BSP Core to initialize, process task
// Weak function allow compile arduino core before linking with this library
//--------------------------------------------------------------------+
#ifdef __cplusplus
extern "C" {
#endif

// Called by core/sketch to initialize usb device hardware and stack
// This also initialize Serial as CDC device
void TinyUSB_Device_Init(uint8_t rhport) __attribute__((weak));

// Called by core/sketch to handle device event
void TinyUSB_Device_Task(void) __attribute__((weak));

// Called by core/sketch to flush write on CDC
void TinyUSB_Device_FlushCDC(void) __attribute__((weak));

#ifdef __cplusplus
}
#endif

//--------------------------------------------------------------------+
// Port API
// Must be implemented by each BSP core/platform
//--------------------------------------------------------------------+

// To enter/reboot to bootloader
// usually when host disconnects cdc at baud 1200 (touch 1200)
void TinyUSB_Port_EnterDFU(void);

// Init device hardware.
// Called by TinyUSB_Device_Init()
void TinyUSB_Port_InitDevice(uint8_t rhport);

// Get unique serial number, needed for Serial String Descriptor
// Fill serial_id (raw bytes) and return its length (limit to 16 bytes)
// Note: Serial descriptor can be overwritten by user API
uint8_t TinyUSB_Port_GetSerialNumber(uint8_t serial_id[16]);

#endif
Loading