Skip to content

Commit c767d57

Browse files
committed
clang format
1 parent 5cd4480 commit c767d57

18 files changed

+564
-578
lines changed

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

src/arduino/Adafruit_USBD_CDC.h

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,51 @@
2929

3030
#ifdef __cplusplus
3131

32-
#include "Stream.h"
3332
#include "Adafruit_USBD_Interface.h"
33+
#include "Stream.h"
3434

35-
class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface
36-
{
35+
class Adafruit_USBD_CDC : public Stream, public Adafruit_USBD_Interface {
3736
public:
38-
Adafruit_USBD_CDC(void);
37+
Adafruit_USBD_CDC(void);
3938

40-
// fron Adafruit_USBD_Interface
41-
virtual uint16_t getInterfaceDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize);
39+
// fron Adafruit_USBD_Interface
40+
virtual uint16_t getInterfaceDescriptor(uint8_t itfnum, uint8_t *buf,
41+
uint16_t bufsize);
4242

43-
void setPins(uint8_t pin_rx, uint8_t pin_tx) { (void) pin_rx; (void) pin_tx; }
44-
void begin(uint32_t baud);
45-
void begin(uint32_t baud, uint8_t config);
46-
void end(void);
43+
void setPins(uint8_t pin_rx, uint8_t pin_tx) {
44+
(void)pin_rx;
45+
(void)pin_tx;
46+
}
47+
void begin(uint32_t baud);
48+
void begin(uint32_t baud, uint8_t config);
49+
void end(void);
4750

48-
// return line coding set by host
49-
uint32_t baud(void);
50-
uint8_t stopbits(void);
51-
uint8_t paritytype(void);
52-
uint8_t numbits(void);
53-
int dtr(void);
51+
// return line coding set by host
52+
uint32_t baud(void);
53+
uint8_t stopbits(void);
54+
uint8_t paritytype(void);
55+
uint8_t numbits(void);
56+
int dtr(void);
5457

55-
// Stream API
56-
virtual int available(void);
57-
virtual int peek(void);
58-
virtual int read(void);
59-
virtual void flush(void);
60-
virtual size_t write(uint8_t);
58+
// Stream API
59+
virtual int available(void);
60+
virtual int peek(void);
61+
virtual int read(void);
62+
virtual void flush(void);
63+
virtual size_t write(uint8_t);
6164

62-
virtual size_t write(const uint8_t *buffer, size_t size);
63-
size_t write(const char *buffer, size_t size) {
64-
return write((const uint8_t *)buffer, size);
65-
}
65+
virtual size_t write(const uint8_t *buffer, size_t size);
66+
size_t write(const char *buffer, size_t size) {
67+
return write((const uint8_t *)buffer, size);
68+
}
6669

67-
virtual int availableForWrite(void);
68-
using Print::write; // pull in write(str) from Print
69-
operator bool();
70+
virtual int availableForWrite(void);
71+
using Print::write; // pull in write(str) from Print
72+
operator bool();
7073

7174
private:
72-
bool _begun;
73-
uint8_t _itf;
75+
bool _begun;
76+
uint8_t _itf;
7477
};
7578

7679
extern Adafruit_USBD_CDC Serial;

0 commit comments

Comments
 (0)