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
41 changes: 41 additions & 0 deletions cores/rp2040/sdkoverride/hid_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdint.h>
#include <tusb.h>

extern void hidd_init() __attribute__((weak));
void hidd_init() {
}

extern bool hidd_deinit() __attribute__((weak));
bool hidd_deinit() {
return true;
}

extern void hidd_reset(uint8_t rhport) __attribute__((weak));
void hidd_reset(uint8_t rhport) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
}

extern uint16_t hidd_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) __attribute__((weak));
uint16_t hidd_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) desc_itf;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) max_len;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return 0;
}

extern bool hidd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_request_t* request) __attribute__((weak));
bool hidd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_request_t* request) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) stage;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) request;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return false;
}

extern bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) __attribute__((weak));
bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) ep_addr;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) result;
(void) xferred_bytes;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return false;
}
41 changes: 41 additions & 0 deletions cores/rp2040/sdkoverride/midi_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdint.h>
#include <tusb.h>

extern void midid_init() __attribute__((weak));
void midid_init() {
}

extern bool midid_deinit() __attribute__((weak));
bool midid_deinit() {
return true;
}

extern void midid_reset(uint8_t rhport) __attribute__((weak));
void midid_reset(uint8_t rhport) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
}

extern uint16_t midid_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) __attribute__((weak));
uint16_t midid_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) desc_itf;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) max_len;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return 0;
}

extern bool midid_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_request_t* request) __attribute__((weak));
bool midid_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_request_t* request) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) stage;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) request;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return false;
}

extern bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) __attribute__((weak));
bool midid_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) ep_addr;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) result;
(void) xferred_bytes;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return false;
}
41 changes: 41 additions & 0 deletions cores/rp2040/sdkoverride/msc_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdint.h>
#include <tusb.h>

extern void mscd_init() __attribute__((weak));
void mscd_init() {
}

extern bool mscd_deinit() __attribute__((weak));
bool mscd_deinit() {
return true;
}

extern void mscd_reset(uint8_t rhport) __attribute__((weak));
void mscd_reset(uint8_t rhport) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
}

extern uint16_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len) __attribute__((weak));
uint16_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) itf_desc;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) max_len;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return 0;
}

extern bool mscd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) __attribute__((weak));
bool mscd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) stage;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) request;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return false;
}

bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) __attribute__((weak));
bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) ep_addr;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) event;
(void) xferred_bytes;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return false;
}
41 changes: 41 additions & 0 deletions cores/rp2040/sdkoverride/ncm_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdint.h>
#include <tusb.h>

extern void netd_init() __attribute__((weak));
void netd_init() {
}

extern bool netd_deinit() __attribute__((weak));
bool netd_deinit() {
return true;
}

extern void netd_reset(uint8_t rhport) __attribute__((weak));
void netd_reset(uint8_t rhport) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
}

extern uint16_t netd_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) __attribute__((weak));
uint16_t netd_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) desc_itf;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) max_len;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return 0;
}

extern bool netd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_request_t* request) __attribute__((weak));
bool netd_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_request_t* request) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) stage;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) request;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return false;
}

extern bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) __attribute__((weak));
bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
(void) rhport;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) ep_addr;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
(void) result;
(void) xferred_bytes;

Check warning

Code scanning / CodeQL

Expression has no effect Warning

This expression has no effect.
return false;
}
14 changes: 14 additions & 0 deletions docs/usb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ to the polling period:
....
}
Native TinyUSB Sketches
-----------------------
Sketches or libraries which want to implement their own low-level TinyUSB
callbacks need to include the appropriate header to have real TinyUSB driver
support for HID, MSC (USB stick), MIDI, and NCM (network).

.. code:: cpp
// Include one or more headers from the following list
#include <tusb-hid.h>
#include <tusb-midi.h>
#include <tush-msc.h>
#include <tusb-ncm.h>
Adafruit TinyUSB Arduino Support
--------------------------------
Examples are provided in the Adafruit_TinyUSB_Arduino for the more
Expand Down
25 changes: 24 additions & 1 deletion include/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,42 @@
#define CFG_TUD_MSC (1)
#define CFG_TUD_MIDI (1)
#define CFG_TUD_VENDOR (0)
#define CFG_TUD_NCM (1)

#define CFG_TUD_CDC_RX_BUFSIZE (256)
#define CFG_TUD_CDC_TX_BUFSIZE (256)

#define CFG_TUD_MSC_EP_BUFSIZE (64)

// HID buffer size Should be sufficient to hold ID (if any) + Data
#define CFG_TUD_HID_EP_BUFSIZE (64)
#define CFG_TUD_HID_EP_BUFSIZE (512)

// MIDI
#define CFG_TUD_MIDI_RX_BUFSIZE (64)
#define CFG_TUD_MIDI_TX_BUFSIZE (64)

//--------------------------------------------------------------------
// NCM CLASS CONFIGURATION, SEE "ncm.h" FOR PERFORMANCE TUNING
//--------------------------------------------------------------------
#include "lwipopts.h"
// Must be >> MTU
// Can be set to 2048 without impact
#define CFG_TUD_NCM_IN_NTB_MAX_SIZE (2 * TCP_MSS + 100)

// Must be >> MTU
// Can be set to smaller values if wNtbOutMaxDatagrams==1
#define CFG_TUD_NCM_OUT_NTB_MAX_SIZE (2 * TCP_MSS + 100)

// Number of NCM transfer blocks for reception side
#ifndef CFG_TUD_NCM_OUT_NTB_N
#define CFG_TUD_NCM_OUT_NTB_N 1
#endif

// Number of NCM transfer blocks for transmission side
#ifndef CFG_TUD_NCM_IN_NTB_N
#define CFG_TUD_NCM_IN_NTB_N 1
#endif

#ifdef __cplusplus
}
#endif
Expand Down
Binary file modified lib/rp2040/libpico.a
Binary file not shown.
Binary file modified lib/rp2350-riscv/libpico.a
Binary file not shown.
Binary file modified lib/rp2350/libpico.a
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void setup() {
FatFSUSB.driveReady(mountable);
// Start FatFS USB drive mode
FatFSUSB.begin();
delay(2000); // TinyUSB seems to have a race condition, see https://github.com/hathach/tinyusb/discussions/1764
Serial.println("FatFSUSB started.");
Serial.println("Connect drive via USB to upload/erase files and re-display");
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/FatFSUSB/src/FatFSUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

#include "FatFSUSB.h"
#include <FatFS.h>
#include <tusb-msc.h>
#include <class/msc/msc.h>
#include <device/usbd.h>
#include <USB.h>

FatFSUSBClass FatFSUSB;
#define USBD_MSC_EPSIZE 64

FatFSUSBClass::FatFSUSBClass() {
}
Expand Down Expand Up @@ -62,7 +62,7 @@ bool FatFSUSBClass::begin() {
USB.disconnect();
_epIn = USB.registerEndpointIn();
_epOut = USB.registerEndpointOut();
static uint8_t msd_desc[] = { TUD_MSC_DESCRIPTOR(1 /* placeholder */, 0, _epOut, _epIn, USBD_MSC_EPSIZE) };
static uint8_t msd_desc[] = { TUD_MSC_DESCRIPTOR(1 /* placeholder */, 0, _epOut, _epIn, CFG_TUD_MSC_EP_BUFSIZE) };
_id = USB.registerInterface(1, USBClass::simpleInterface, msd_desc, sizeof(msd_desc), 2, 0);
USB.connect();

Expand Down
1 change: 1 addition & 0 deletions libraries/Joystick/src/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <USB.h>

#include "tusb.h"
#include <tusb-hid.h>
#include "class/hid/hid_device.h"
#include <sdkoverride/tusb_gamepad16.h>

Expand Down
1 change: 1 addition & 0 deletions libraries/Keyboard/src/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#error Keyboard is not compatible with Adafruit TinyUSB
#endif

#include <tusb-hid.h>
#include <HID_Keyboard.h>

class Keyboard_ : public HID_Keyboard {
Expand Down
2 changes: 1 addition & 1 deletion libraries/MIDIUSB
1 change: 1 addition & 0 deletions libraries/Mouse/src/Mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <USB.h>

#include "tusb.h"
#include <tusb-hid.h>
#include "class/hid/hid_device.h"

//================================================================================
Expand Down
1 change: 1 addition & 0 deletions libraries/MouseAbsolute/src/MouseAbsolute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <USB.h>

#include "tusb.h"
#include <tusb-hid.h>
#include "class/hid/hid_device.h"

static const uint8_t desc_hid_report_absmouse[] = { TUD_HID_REPORT_DESC_ABSMOUSE(HID_REPORT_ID(1)) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void setup() {
singleFileDrive.onPlug(plug);
singleFileDrive.onUnplug(unplug);
singleFileDrive.begin("data.csv", "Recorded data from the Raspberry Pi Pico.csv");
delay(2000); // TinyUSB seems to have a race condition, see https://github.com/hathach/tinyusb/discussions/1764

// Find the last written data
File f = LittleFS.open("data.csv", "r");
Expand Down
5 changes: 2 additions & 3 deletions libraries/SingleFileDrive/src/SingleFileDrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <SingleFileDrive.h>
#include <LittleFS.h>
#include <tusb-msc.h>
#include <class/msc/msc.h>
#include <class/msc/msc_device.h>
#include <device/usbd.h>
Expand All @@ -29,8 +30,6 @@ SingleFileDrive singleFileDrive;
static const uint32_t _hddsize = (256 * 1024 * 1024); // 256MB
static const uint32_t _hddsects = _hddsize / 512;

#define USBD_MSC_EPSIZE 64

SingleFileDrive::SingleFileDrive() {
}

Expand Down Expand Up @@ -60,7 +59,7 @@ bool SingleFileDrive::begin(const char *localFile, const char *dosFile) {
USB.disconnect();
_epIn = USB.registerEndpointIn();
_epOut = USB.registerEndpointOut();
static uint8_t msd_desc[] = { TUD_MSC_DESCRIPTOR(1 /* placeholder */, 0, _epOut, _epIn, USBD_MSC_EPSIZE) };
static uint8_t msd_desc[] = { TUD_MSC_DESCRIPTOR(1 /* placeholder */, 0, _epOut, _epIn, CFG_TUD_MSC_EP_BUFSIZE) };
_id = USB.registerInterface(1, USBClass::simpleInterface, msd_desc, sizeof(msd_desc), 2, 0);
USB.connect();
_localFile = strdup(localFile);
Expand Down
9 changes: 9 additions & 0 deletions libraries/tusb-hid/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=tusb-hid
version=1.0.0
author=Earle F. Philhower, III <[email protected]>
maintainer=Earle F. Philhower, III <[email protected]>
sentence=Include the TinyUSB HID code
paragraph=Include the TinyUSB HID source code in a build
category=Device Control
url=https://github.com/earlephilhower/arduino-pico
architectures=rp2040
1 change: 1 addition & 0 deletions libraries/tusb-hid/src/hid_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../../../pico-sdk/lib/tinyusb/src/class/hid/hid_device.c"
1 change: 1 addition & 0 deletions libraries/tusb-hid/src/tusb-hid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// dummy
9 changes: 9 additions & 0 deletions libraries/tusb-midi/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=tusb-midi
version=1.0.0
author=Earle F. Philhower, III <[email protected]>
maintainer=Earle F. Philhower, III <[email protected]>
sentence=Include the TinyUSB MIDI code
paragraph=Include the TinyUSB MIDI source code
category=Device Control
url=https://github.com/earlephilhower/arduino-pico
architectures=rp2040
1 change: 1 addition & 0 deletions libraries/tusb-midi/src/midi_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../../../pico-sdk/lib/tinyusb/src/class/midi/midi_device.c"
1 change: 1 addition & 0 deletions libraries/tusb-midi/src/tusb-midi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// dummy
9 changes: 9 additions & 0 deletions libraries/tusb-msc/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=tusb-msc
version=1.0.0
author=Earle F. Philhower, III <[email protected]>
maintainer=Earle F. Philhower, III <[email protected]>
sentence=Include the TinyUSB MSC code
paragraph=Include the TinyUSB MSC source code
category=Device Control
url=https://github.com/earlephilhower/arduino-pico
architectures=rp2040
1 change: 1 addition & 0 deletions libraries/tusb-msc/src/msc_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../../../pico-sdk/lib/tinyusb/src/class/msc/msc_device.c"
1 change: 1 addition & 0 deletions libraries/tusb-msc/src/tusb-msc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// dummy
9 changes: 9 additions & 0 deletions libraries/tusb-ncm/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=tusb-ncm
version=1.0.0
author=Earle F. Philhower, III <[email protected]>
maintainer=Earle F. Philhower, III <[email protected]>
sentence=Include the TinyUSB NCM code
paragraph=Include the TinyUSB NCM source code
category=Device Control
url=https://github.com/earlephilhower/arduino-pico
architectures=rp2040
1 change: 1 addition & 0 deletions libraries/tusb-ncm/src/ncm_device.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../../../pico-sdk/lib/tinyusb/src/class/net/ncm_device.c"
1 change: 1 addition & 0 deletions libraries/tusb-ncm/src/tusb-ncm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// dummy
1 change: 1 addition & 0 deletions tools/libpico/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ foreach(tgt pico lwip lwip-bt)
add_custom_command(TARGET ${tgt}-${cpu} POST_BUILD
COMMAND arm-none-eabi-ar d lib${tgt}-${cpu}.a pico_malloc.c.o newlib_interface.c.o stdlib.c.o stdio.c.o stdio_uart.c.o new_delete.cpp.o
COMMAND arm-none-eabi-ar d lib${tgt}-${cpu}.a btstack_flash_bank.c.o # Need to override with our own implementation
COMMAND arm-none-eabi-ar d lib${tgt}-${cpu}.a msc_device.c.o midi_device.c.o hid_device.c.o ncm_device.c.o # TinyUSB devices stubbed out
COMMAND cp lib${tgt}-${cpu}.a ../../../lib/${cpu}/lib${tgt}.a
)
endforeach()
Expand Down