Skip to content

Commit a106cbc

Browse files
committed
move files to arduino sub folder, separate port api header
1 parent 003c5e0 commit a106cbc

15 files changed

+67
-30
lines changed

src/Adafruit_TinyUSB.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@
3131

3232
#ifdef USE_TINYUSB
3333

34-
#include "Adafruit_USBD_Device.h"
34+
#include "arduino/Adafruit_USBD_Device.h"
35+
36+
// CDC can be part of the core
3537
#include "Adafruit_USBD_CDC.h"
36-
#include "Adafruit_USBD_HID.h"
37-
#include "Adafruit_USBD_MIDI.h"
38-
#include "Adafruit_USBD_MSC.h"
39-
#include "Adafruit_USBD_WebUSB.h"
4038

41-
// Called by main.cpp to initialize usb device typically with CDC device for Serial
42-
void Adafruit_TinyUSB_Device_init(uint8_t rhport);
39+
#include "arduino/Adafruit_USBD_HID.h"
40+
#include "arduino/Adafruit_USBD_MIDI.h"
41+
#include "arduino/Adafruit_USBD_MSC.h"
42+
#include "arduino/Adafruit_USBD_WebUSB.h"
4343

44-
// Invoked when host disconnects cdc at baud 1200, usually touch feature to go into DFU mode
45-
void Adafruit_TinyUSB_touch1200(void);
44+
// Initialize device hardware, stack, also Serial as CDC
45+
// Wrapper for USBDevice.begin(rhport)
46+
void TinyUSB_Device_Init(uint8_t rhport);
4647

4748
#endif
4849

src/Adafruit_TinyUSB.cpp renamed to src/arduino/Adafruit_TinyUSB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
3131
//--------------------------------------------------------------------+
3232

33-
void Adafruit_TinyUSB_Device_init(uint8_t rhport)
33+
void TinyUSB_Device_init(uint8_t rhport)
3434
{
3535
USBDevice.begin(rhport);
3636
}

src/Adafruit_USBD_CDC.cpp renamed to src/arduino/Adafruit_USBD_CDC.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "tusb.h"
2929
#include "Adafruit_USBD_CDC.h"
3030

31-
void Adafruit_TinyUSB_touch1200(void);
31+
#include "arduino/ports/Adafruit_TinyUSB_Port.h"
3232

3333
#define EPOUT 0x00
3434
#define EPIN 0x80
@@ -178,16 +178,19 @@ extern "C"
178178
// Use to reset to DFU when disconnect with 1200 bps
179179
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
180180
{
181-
(void) itf; // interface ID, not used
182181
(void) rts;
183182

184183
// DTR = false is counted as disconnected
185184
if ( !dtr )
186185
{
187-
cdc_line_coding_t coding;
188-
tud_cdc_get_line_coding(&coding);
189-
190-
if ( coding.bit_rate == 1200 ) Adafruit_TinyUSB_touch1200();
186+
// touch1200 only with first CDC instance (Serial)
187+
if ( itf == 0 )
188+
{
189+
cdc_line_coding_t coding;
190+
tud_cdc_get_line_coding(&coding);
191+
192+
if ( coding.bit_rate == 1200 ) TinyUSB_Port_EnterDFU();
193+
}
191194
}
192195
}
193196

src/Adafruit_USBD_Device.cpp renamed to src/arduino/Adafruit_USBD_Device.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "Adafruit_USBD_Device.h"
2828
#include "Adafruit_USBD_CDC.h"
29+
#include "arduino/ports/Adafruit_TinyUSB_Port.h"
2930

3031
#ifndef USB_MANUFACTURER
3132
#define USB_MANUFACTURER "Unknown"
@@ -213,7 +214,7 @@ bool Adafruit_USBD_Device::begin(uint8_t rhport)
213214
USBDevice.addInterface(Serial);
214215
USBDevice.setID(USB_VID, USB_PID);
215216

216-
portInitHardware(rhport);
217+
TinyUSB_Port_InitDeviceController(rhport);
217218

218219
return tusb_init();
219220
}

src/Adafruit_USBD_Device.h renamed to src/arduino/Adafruit_USBD_Device.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@
2828
#include "tusb.h"
2929
#include "Adafruit_USBD_Interface.h"
3030

31-
extern "C"
32-
{
33-
uint8_t const * tud_descriptor_device_cb(void);
34-
uint8_t const * tud_descriptor_configuration_cb(uint8_t index);
35-
uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid);
36-
}
37-
3831
class Adafruit_USBD_Device
3932
{
4033
private:
@@ -88,7 +81,8 @@ class Adafruit_USBD_Device
8881
uint8_t getSerialDescriptor(uint16_t* serial_str);
8982

9083
private:
91-
void portInitHardware(uint8_t rhport);
84+
void port_InitHardware(uint8_t rhport);
85+
void port_Touch1200(void);
9286

9387
private:
9488
uint16_t const* descriptor_string_cb(uint8_t index, uint16_t langid);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_TINYUSB_PORT_H_
26+
#define ADAFRUIT_TINYUSB_PORT_H_
27+
28+
//--------------------------------------------------------------------+
29+
// Porting API
30+
//--------------------------------------------------------------------+
31+
32+
// To enter/reboot to bootloader
33+
// usually when host disconnects cdc at baud 1200 (touch 1200)
34+
void TinyUSB_Port_EnterDFU(void);
35+
36+
// Init device hardware.
37+
// Called by USBDevice.begin()
38+
void TinyUSB_Port_InitDeviceController(uint8_t rhport);
39+
40+
#endif

src/Adafruit_TinyUSB_samd.cpp renamed to src/arduino/ports/Adafruit_TinyUSB_samd.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#if defined ARDUINO_ARCH_SAMD & defined USE_TINYUSB
2626

2727
#include "Arduino.h"
28-
#include "tusb.h"
29-
#include "Adafruit_USBD_Device.h"
30-
#include "Adafruit_USBD_CDC.h"
28+
#include "arduino/Adafruit_USBD_Device.h"
3129

3230
#include <Reset.h> // Needed for auto-reset with 1200bps port touch
3331

@@ -74,7 +72,7 @@ extern "C" int serial1_printf(const char *__restrict format, ...)
7472
// Core Init & Touch1200
7573
//--------------------------------------------------------------------+
7674

77-
void Adafruit_TinyUSB_touch1200(void)
75+
void TinyUSB_Port_EnterDFU(void)
7876
{
7977
initiateReset(250);
8078
}
@@ -89,7 +87,7 @@ extern "C" void yield(void)
8987
//--------------------------------------------------------------------+
9088
// Adafruit_USBD_Device platform dependent
9189
//--------------------------------------------------------------------+
92-
void Adafruit_USBD_Device::portInitHardware(uint8_t rhport)
90+
void TinyUSB_Port_InitDeviceController(uint8_t rhport)
9391
{
9492
/* Enable USB clock */
9593
#if defined(__SAMD51__)

0 commit comments

Comments
 (0)