Skip to content

Commit e02de0e

Browse files
authored
Merge pull request #91 from adafruit/fix-ci
Fix ci
2 parents d26aa1b + ea1d7f0 commit e02de0e

20 files changed

+572
-581
lines changed

.github/workflows/githubci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
arduino-platform:
12-
# Alphabetical order
12+
# nRF52
1313
- 'cpb'
14+
- 'nrf52840'
15+
# RP2040
16+
#- 'feather_rp2040_tinyusb'
17+
#- 'pico_rp2040_tinyusb'
18+
# SAMD
1419
- 'feather_m4_can_tinyusb'
1520
- 'metro_m0_tinyusb'
1621
- 'metro_m4_tinyusb'
17-
- 'nrf52840'
1822

1923
steps:
2024
- name: Setup Python
@@ -59,7 +63,7 @@ jobs:
5963
run: bash ci/actions_install.sh
6064

6165
- name: clang
62-
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
66+
run: python3 ci/run-clang-format.py -r src/arduino
6367

6468
- name: doxygen
6569
env:

examples/MassStorage/msc_sd/msc_sd.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ int32_t msc_read_cb (uint32_t lba, void* buffer, uint32_t bufsize)
9090
// return number of written bytes (must be multiple of block size)
9191
int32_t msc_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize)
9292
{
93+
(void) bufsize;
9394
return card.writeBlock(lba, buffer) ? 512 : -1;
9495
}
9596

src/arduino/Adafruit_TinyUSB_API.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,25 @@
3131
//--------------------------------------------------------------------+
3232
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
3333
//--------------------------------------------------------------------+
34-
extern "C"
35-
{
34+
extern "C" {
3635

37-
void TinyUSB_Device_Init(uint8_t rhport)
38-
{
36+
void TinyUSB_Device_Init(uint8_t rhport) {
37+
// Init USB Device controller and stack
3938
USBDevice.begin(rhport);
4039
}
4140

4241
// RP2040 has its own implementation since it needs mutex for dual core
4342
#ifndef ARDUINO_ARCH_RP2040
44-
void TinyUSB_Device_Task(void)
45-
{
43+
void TinyUSB_Device_Task(void) {
44+
// Run tinyusb device task
4645
tud_task();
4746
}
4847
#endif
4948

50-
void TinyUSB_Device_FlushCDC(void)
51-
{
49+
void TinyUSB_Device_FlushCDC(void) {
5250
// TODO multiple CDCs
5351
tud_cdc_n_write_flush(0);
5452
}
55-
5653
}
5754

5855
#endif

src/arduino/Adafruit_TinyUSB_API.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
#ifndef ADAFRUIT_TINYUSB_API_H_
2626
#define ADAFRUIT_TINYUSB_API_H_
2727

28-
#include <stdint.h>
2928
#include <stdbool.h>
29+
#include <stdint.h>
3030

3131
//--------------------------------------------------------------------+
3232
// Core API
3333
// Should be called by BSP Core to initialize, process task
3434
// Weak function allow compile arduino core before linking with this library
3535
//--------------------------------------------------------------------+
3636
#ifdef __cplusplus
37-
extern "C" {
37+
extern "C" {
3838
#endif
3939

4040
// Called by core/sketch to initialize usb device hardware and stack
@@ -48,7 +48,7 @@ void TinyUSB_Device_Task(void) __attribute__((weak));
4848
void TinyUSB_Device_FlushCDC(void) __attribute__((weak));
4949

5050
#ifdef __cplusplus
51-
}
51+
}
5252
#endif
5353

5454
//--------------------------------------------------------------------+

src/arduino/Adafruit_USBD_CDC.cpp

Lines changed: 53 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -27,186 +27,169 @@
2727
#if TUSB_OPT_DEVICE_ENABLED && CFG_TUD_CDC
2828

2929
#include "Arduino.h"
30+
3031
#include "Adafruit_TinyUSB_API.h"
3132

32-
#include "Adafruit_USBD_Device.h"
3333
#include "Adafruit_USBD_CDC.h"
34+
#include "Adafruit_USBD_Device.h"
3435

3536
// TODO Multiple instances supports
3637
// static uint8_t _itf_count;
3738
// static Adafruit_USBD_CDC* _itf_arr[]
3839

39-
#define EPOUT 0x00
40-
#define EPIN 0x80
40+
#define EPOUT 0x00
41+
#define EPIN 0x80
4142

4243
Adafruit_USBD_CDC Serial;
4344

44-
Adafruit_USBD_CDC::Adafruit_USBD_CDC(void)
45-
{
45+
Adafruit_USBD_CDC::Adafruit_USBD_CDC(void) {
4646
_begun = false;
4747
_itf = 0;
4848
}
4949

50-
uint16_t Adafruit_USBD_CDC::getInterfaceDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize)
51-
{
50+
uint16_t Adafruit_USBD_CDC::getInterfaceDescriptor(uint8_t itfnum, uint8_t *buf,
51+
uint16_t bufsize) {
5252
// CDC is mostly always existed for DFU
5353
// usb core will automatically update endpoint number
54-
uint8_t desc[] = { TUD_CDC_DESCRIPTOR(itfnum, 0, EPIN, 8, EPOUT, EPIN, 64) };
54+
uint8_t desc[] = {TUD_CDC_DESCRIPTOR(itfnum, 0, EPIN, 8, EPOUT, EPIN, 64)};
5555
uint16_t const len = sizeof(desc);
5656

57-
if ( bufsize < len ) return 0;
57+
if (bufsize < len) {
58+
return 0;
59+
}
5860

5961
memcpy(buf, desc, len);
6062
return len;
6163
}
6264

6365
// Baud and config is ignore in CDC
64-
void Adafruit_USBD_CDC::begin (uint32_t baud)
65-
{
66-
(void) baud;
66+
void Adafruit_USBD_CDC::begin(uint32_t baud) {
67+
(void)baud;
68+
69+
if (_begun) {
70+
return;
71+
}
6772

68-
if (_begun) return;
6973
_begun = true;
7074

7175
Serial.setStringDescriptor("TinyUSB Serial");
7276
USBDevice.addInterface(Serial);
7377
}
7478

75-
void Adafruit_USBD_CDC::begin (uint32_t baud, uint8_t config)
76-
{
77-
(void) config;
79+
void Adafruit_USBD_CDC::begin(uint32_t baud, uint8_t config) {
80+
(void)config;
7881
this->begin(baud);
7982
}
8083

81-
void Adafruit_USBD_CDC::end(void)
82-
{
84+
void Adafruit_USBD_CDC::end(void) {
85+
// Resset configuration descriptor without Serial as CDC
8386
USBDevice.clearConfiguration();
8487
}
8588

86-
uint32_t Adafruit_USBD_CDC::baud(void)
87-
{
89+
uint32_t Adafruit_USBD_CDC::baud(void) {
8890
cdc_line_coding_t coding;
8991
tud_cdc_get_line_coding(&coding);
9092

9193
return coding.bit_rate;
9294
}
9395

94-
uint8_t Adafruit_USBD_CDC::stopbits(void)
95-
{
96+
uint8_t Adafruit_USBD_CDC::stopbits(void) {
9697
cdc_line_coding_t coding;
9798
tud_cdc_get_line_coding(&coding);
9899

99100
return coding.stop_bits;
100101
}
101102

102-
uint8_t Adafruit_USBD_CDC::paritytype(void)
103-
{
103+
uint8_t Adafruit_USBD_CDC::paritytype(void) {
104104
cdc_line_coding_t coding;
105105
tud_cdc_get_line_coding(&coding);
106106

107107
return coding.parity;
108108
}
109109

110-
uint8_t Adafruit_USBD_CDC::numbits(void)
111-
{
110+
uint8_t Adafruit_USBD_CDC::numbits(void) {
112111
cdc_line_coding_t coding;
113112
tud_cdc_get_line_coding(&coding);
114113

115114
return coding.data_bits;
116115
}
117116

118-
int Adafruit_USBD_CDC::dtr(void)
119-
{
120-
return tud_cdc_connected();
121-
}
117+
int Adafruit_USBD_CDC::dtr(void) { return tud_cdc_connected(); }
122118

123-
Adafruit_USBD_CDC::operator bool()
124-
{
119+
Adafruit_USBD_CDC::operator bool() {
125120
bool ret = tud_cdc_connected();
126121

127122
// Add an yield to run usb background in case sketch block wait as follows
128123
// while( !Serial ) {}
129-
if ( !ret ) yield();
130-
124+
if (!ret) {
125+
yield();
126+
}
131127
return ret;
132128
}
133129

134-
int Adafruit_USBD_CDC::available(void)
135-
{
130+
int Adafruit_USBD_CDC::available(void) {
136131
uint32_t count = tud_cdc_available();
137132

138133
// Add an yield to run usb background in case sketch block wait as follows
139134
// while( !Serial.available() ) {}
140-
if (!count) yield();
135+
if (!count) {
136+
yield();
137+
}
141138

142139
return count;
143140
}
144141

145-
int Adafruit_USBD_CDC::peek(void)
146-
{
142+
int Adafruit_USBD_CDC::peek(void) {
147143
uint8_t ch;
148-
return tud_cdc_peek(&ch) ? (int) ch : -1;
144+
return tud_cdc_peek(&ch) ? (int)ch : -1;
149145
}
150146

151-
int Adafruit_USBD_CDC::read(void)
152-
{
153-
return (int) tud_cdc_read_char();
154-
}
147+
int Adafruit_USBD_CDC::read(void) { return (int)tud_cdc_read_char(); }
155148

156-
void Adafruit_USBD_CDC::flush(void)
157-
{
158-
tud_cdc_write_flush();
159-
}
149+
void Adafruit_USBD_CDC::flush(void) { tud_cdc_write_flush(); }
160150

161-
size_t Adafruit_USBD_CDC::write(uint8_t ch)
162-
{
163-
return write(&ch, 1);
164-
}
151+
size_t Adafruit_USBD_CDC::write(uint8_t ch) { return write(&ch, 1); }
165152

166-
size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size)
167-
{
153+
size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size) {
168154
size_t remain = size;
169-
while ( remain && tud_cdc_connected() )
170-
{
155+
while (remain && tud_cdc_connected()) {
171156
size_t wrcount = tud_cdc_write(buffer, remain);
172157
remain -= wrcount;
173158
buffer += wrcount;
174159

175160
// Write FIFO is full, run usb background to flush
176-
if ( remain ) yield();
161+
if (remain) {
162+
yield();
163+
}
177164
}
178165

179166
return size - remain;
180167
}
181168

182-
int Adafruit_USBD_CDC::availableForWrite(void)
183-
{
169+
int Adafruit_USBD_CDC::availableForWrite(void) {
184170
return tud_cdc_write_available();
185171
}
186172

187-
extern "C"
188-
{
173+
extern "C" {
189174

190175
// Invoked when cdc when line state changed e.g connected/disconnected
191176
// Use to reset to DFU when disconnect with 1200 bps
192-
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
193-
{
194-
(void) rts;
177+
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
178+
(void)rts;
195179

196180
// DTR = false is counted as disconnected
197-
if ( !dtr )
198-
{
181+
if (!dtr) {
199182
// touch1200 only with first CDC instance (Serial)
200-
if ( itf == 0 )
201-
{
183+
if (itf == 0) {
202184
cdc_line_coding_t coding;
203185
tud_cdc_get_line_coding(&coding);
204186

205-
if ( coding.bit_rate == 1200 ) TinyUSB_Port_EnterDFU();
187+
if (coding.bit_rate == 1200) {
188+
TinyUSB_Port_EnterDFU();
189+
}
206190
}
207191
}
208192
}
209-
210193
}
211194

212195
#endif // TUSB_OPT_DEVICE_ENABLED

0 commit comments

Comments
 (0)