Skip to content

Commit 9675803

Browse files
committed
change port TinyUSB_Port_InitDevice() to also call tusb_init() for flexibility
1 parent a4a9303 commit 9675803

6 files changed

+14
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ It is rather easy if you want to integrate TinyUSB lib to your ArduinoCore.
4040

4141
In addition to core changes, library need to be ported to your platform. Don't worry, tinyusb stack has already done most of heavy-lifting. You only need to write a few APIs
4242

43-
1. `TinyUSB_Port_InitDeviceController()` hardware specific (clock, phy) to enable usb hardware. This API is called as part of TinyUSB_Device_Init() invocation.
43+
1. `TinyUSB_Port_InitDevice()` hardware specific (clock, phy) to enable usb hardware then call tud_init(). This API is called as part of TinyUSB_Device_Init() invocation.
4444
2. `TinyUSB_Port_EnterDFU()` which is called when device need to enter DFU mode, usually by touch1200 feature
4545
3. `TinyUSB_Port_GetSerialNumber()` which is called to get unique MCU Serial ID to used as Serial string descriptor.

src/arduino/Adafruit_TinyUSB_API.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void TinyUSB_Port_EnterDFU(void);
6262

6363
// Init device hardware.
6464
// Called by USBDevice.begin()
65-
void TinyUSB_Port_InitDeviceController(uint8_t rhport);
65+
void TinyUSB_Port_InitDevice(uint8_t rhport);
6666

6767
// Get unique serial number, needed for Serial String Descriptor
6868
// Fill serial_id (raw bytes) and return its length (limit to 16 bytes)

src/arduino/Adafruit_USBD_Device.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@ bool Adafruit_USBD_Device::begin(uint8_t rhport)
238238

239239
Serial.begin(115200);
240240

241-
TinyUSB_Port_InitDeviceController(rhport);
241+
// Init device hardware and call tusb_init()
242+
TinyUSB_Port_InitDevice(rhport);
242243

243-
return tusb_init();
244+
return true;
244245
}
245246

246247
void Adafruit_USBD_Device::task(void)

src/arduino/ports/Adafruit_TinyUSB_nrf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void usb_device_task(void* param)
7979
}
8080
}
8181

82-
void TinyUSB_Port_InitDeviceController(uint8_t rhport)
82+
void TinyUSB_Port_InitDevice(uint8_t rhport)
8383
{
8484
(void) rhport;
8585

src/arduino/ports/Adafruit_TinyUSB_rp2040.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
// Porting API
4343
//--------------------------------------------------------------------+
4444

45-
void TinyUSB_Port_InitDeviceController(uint8_t rhport)
45+
void TinyUSB_Port_InitDevice(uint8_t rhport)
4646
{
4747
(void) rhport;
4848

src/arduino/ports/Adafruit_TinyUSB_samd.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
#if defined ARDUINO_ARCH_SAMD & TUSB_OPT_DEVICE_ENABLED
2828

2929
#include "Arduino.h"
30-
#include "arduino/Adafruit_USBD_Device.h"
31-
3230
#include <Reset.h> // Needed for auto-reset with 1200bps port touch
3331

32+
#include "tusb.h"
33+
#include "arduino/Adafruit_TinyUSB_API.h"
34+
3435
//--------------------------------------------------------------------+
3536
// Forward USB interrupt events to TinyUSB IRQ Handler
3637
//--------------------------------------------------------------------+
@@ -76,7 +77,7 @@ extern "C" int serial1_printf(const char *__restrict format, ...)
7677
//--------------------------------------------------------------------+
7778
// Porting API
7879
//--------------------------------------------------------------------+
79-
void TinyUSB_Port_InitDeviceController(uint8_t rhport)
80+
void TinyUSB_Port_InitDevice(uint8_t rhport)
8081
{
8182
(void) rhport;
8283

@@ -120,6 +121,8 @@ void TinyUSB_Port_InitDeviceController(uint8_t rhport)
120121

121122
NVIC_SetPriority((IRQn_Type) USB_IRQn, 0UL);
122123
#endif
124+
125+
tusb_init();
123126
}
124127

125128
void TinyUSB_Port_EnterDFU(void)
@@ -147,4 +150,4 @@ uint8_t TinyUSB_Port_GetSerialNumber(uint8_t serial_id[16])
147150
return 16;
148151
}
149152

150-
#endif // USE_TINYUSB
153+
#endif

0 commit comments

Comments
 (0)