Skip to content

Commit fc358ea

Browse files
committed
remove tinyusb core submodule, move tinyusb src to its own library to reduce dependency
1 parent 439c6b5 commit fc358ea

File tree

8 files changed

+132
-221
lines changed

8 files changed

+132
-221
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "cores/arduino/TinyUSB/Adafruit_TinyUSB_ArduinoCore"]
2-
path = cores/arduino/TinyUSB/Adafruit_TinyUSB_ArduinoCore
3-
url = https://github.com/adafruit/Adafruit_TinyUSB_ArduinoCore.git

cores/arduino/Arduino.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,13 @@ void loop( void ) ;
150150

151151
// USB
152152
#ifdef USE_TINYUSB
153-
#include "Adafruit_TinyUSB_Core.h"
153+
#include "Adafruit_USBD_Interface.h"
154+
#include "Adafruit_USBD_CDC.h"
154155
#else
155-
#include "USB/USBDesc.h"
156-
#include "USB/USBCore.h"
157-
#include "USB/USBAPI.h"
158-
#include "USB/USB_host.h"
156+
#include "USB/USBDesc.h"
157+
#include "USB/USBCore.h"
158+
#include "USB/USBAPI.h"
159+
#include "USB/USB_host.h"
159160
#endif
160161

161162
#endif // Arduino_h
Lines changed: 0 additions & 1 deletion
This file was deleted.

cores/arduino/TinyUSB/Adafruit_TinyUSB_SAMD.cpp

Lines changed: 0 additions & 195 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2019 Ha Thach for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef ADAFRUIT_USBD_CDC_H_
26+
#define ADAFRUIT_USBD_CDC_H_
27+
28+
#ifdef __cplusplus
29+
30+
#include "Adafruit_USBD_Interface.h"
31+
#include "Stream.h"
32+
33+
class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface
34+
{
35+
public:
36+
Adafruit_USBD_CDC(void);
37+
38+
// fron Adafruit_USBD_Interface
39+
virtual uint16_t getDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize);
40+
41+
void setPins(uint8_t pin_rx, uint8_t pin_tx) { (void) pin_rx; (void) pin_tx; }
42+
void begin(uint32_t baud_count);
43+
void begin(uint32_t baud, uint8_t config);
44+
void end(void);
45+
46+
// return line coding set by host
47+
uint32_t baud(void);
48+
uint8_t stopbits(void);
49+
uint8_t paritytype(void);
50+
uint8_t numbits(void);
51+
int dtr(void);
52+
53+
// Stream API
54+
virtual int available(void);
55+
virtual int peek(void);
56+
virtual int read(void);
57+
virtual void flush(void);
58+
virtual size_t write(uint8_t);
59+
60+
virtual size_t write(const uint8_t *buffer, size_t size);
61+
size_t write(const char *buffer, size_t size) {
62+
return write((const uint8_t *)buffer, size);
63+
}
64+
65+
virtual int availableForWrite(void);
66+
using Print::write; // pull in write(str) from Print
67+
operator bool();
68+
};
69+
70+
extern Adafruit_USBD_CDC Serial;
71+
72+
#endif // __cplusplus
73+
#endif
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2021 Ha Thach (tinyusb.org) for Adafruit Industries
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef ADAFRUIT_USBD_INTERFACE_H_
26+
#define ADAFRUIT_USBD_INTERFACE_H_
27+
28+
#ifdef __cplusplus
29+
30+
class Adafruit_USBD_Interface
31+
{
32+
protected:
33+
const char* _desc_str;
34+
35+
public:
36+
Adafruit_USBD_Interface(void) { _desc_str = NULL; }
37+
38+
virtual uint16_t getDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize) = 0;
39+
void setStringDescriptor(const char* str) { _desc_str = str; }
40+
const char* getStringDescriptor(void) { return _desc_str; }
41+
};
42+
43+
#endif
44+
45+
#endif

cores/arduino/main.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
void initVariant() __attribute__((weak));
2525
void initVariant() { }
2626

27+
#ifdef USE_TINYUSB
28+
// Called by main.cpp to initialize usb device typically with CDC device for Serial
29+
void Adafruit_TinyUSB_Device_init(uint8_t rhport) __attribute__((weak));
30+
#endif
31+
2732
// Initialize C library
2833
extern "C" void __libc_init_array(void);
2934

@@ -41,7 +46,7 @@ int main( void )
4146
delay(1);
4247

4348
#if defined(USE_TINYUSB)
44-
Adafruit_TinyUSB_Core_init();
49+
Adafruit_TinyUSB_Device_init(0);
4550
#elif defined(USBCON)
4651
USBDevice.init();
4752
USBDevice.attach();
@@ -59,14 +64,3 @@ int main( void )
5964

6065
return 0;
6166
}
62-
63-
#if defined(USE_TINYUSB)
64-
65-
// run TinyUSB background task when yield()
66-
extern "C" void yield(void)
67-
{
68-
tud_task();
69-
tud_cdc_write_flush();
70-
}
71-
72-
#endif

variants/circuitplay/variant.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,7 @@ extern Uart Serial1;
242242
//
243243
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
244244
// pins are NOT connected to anything by default.
245-
#define SERIAL_PORT_USBVIRTUAL SerialUSB
246-
#define SERIAL_PORT_MONITOR SerialUSB
245+
#define SERIAL_PORT_USBVIRTUAL Serial
246+
#define SERIAL_PORT_MONITOR Serial
247247
#define SERIAL_PORT_HARDWARE Serial1
248248
#define SERIAL_PORT_HARDWARE_OPEN Serial1
249-
250-
// Alias Serial to SerialUSB
251-
#define Serial SerialUSB

0 commit comments

Comments
 (0)