Skip to content

Commit 320ae82

Browse files
committed
clang-formatted
1 parent 763f02a commit 320ae82

10 files changed

+523
-528
lines changed

src/Adafruit_TinyUSB.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach for Adafruit Industries
@@ -22,13 +22,11 @@
2222
* THE SOFTWARE.
2323
*/
2424

25-
#include "Arduino.h"
2625
#include "Adafruit_TinyUSB.h"
26+
#include "Arduino.h"
2727

2828
//--------------------------------------------------------------------+
2929
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
3030
//--------------------------------------------------------------------+
3131

32-
3332
//------------- IMPLEMENTATION -------------//
34-

src/Adafruit_TinyUSB.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach for Adafruit Industries
@@ -25,9 +25,9 @@
2525
#ifndef ADAFRUIT_TINYUSB_H_
2626
#define ADAFRUIT_TINYUSB_H_
2727

28-
#include "Adafruit_USBD_MSC.h"
2928
#include "Adafruit_USBD_HID.h"
3029
#include "Adafruit_USBD_MIDI.h"
30+
#include "Adafruit_USBD_MSC.h"
3131
#include "Adafruit_USBD_WebUSB.h"
3232

3333
#endif /* ADAFRUIT_TINYUSB_H_ */

src/Adafruit_USBD_HID.cpp

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach for Adafruit Industries
@@ -24,16 +24,15 @@
2424

2525
#include "Adafruit_USBD_HID.h"
2626

27-
#define EPOUT 0x00
28-
#define EPIN 0x80
27+
#define EPOUT 0x00
28+
#define EPIN 0x80
2929

30-
uint8_t const _ascii2keycode[128][2] = { HID_ASCII_TO_KEYCODE };
30+
uint8_t const _ascii2keycode[128][2] = {HID_ASCII_TO_KEYCODE};
3131

32-
static Adafruit_USBD_HID* _hid_dev = NULL;
32+
static Adafruit_USBD_HID *_hid_dev = NULL;
3333

3434
//------------- IMPLEMENTATION -------------//
35-
Adafruit_USBD_HID::Adafruit_USBD_HID(void)
36-
{
35+
Adafruit_USBD_HID::Adafruit_USBD_HID(void) {
3736
_interval_ms = 10;
3837
_protocol = HID_PROTOCOL_NONE;
3938

@@ -47,106 +46,107 @@ Adafruit_USBD_HID::Adafruit_USBD_HID(void)
4746
_set_report_cb = NULL;
4847
}
4948

50-
void Adafruit_USBD_HID::setPollInterval(uint8_t interval_ms)
51-
{
49+
void Adafruit_USBD_HID::setPollInterval(uint8_t interval_ms) {
5250
_interval_ms = interval_ms;
5351
}
5452

55-
void Adafruit_USBD_HID::setBootProtocol(uint8_t protocol)
56-
{
53+
void Adafruit_USBD_HID::setBootProtocol(uint8_t protocol) {
5754
_protocol = protocol;
5855
}
5956

60-
void Adafruit_USBD_HID::enableOutEndpoint(bool enable)
61-
{
57+
void Adafruit_USBD_HID::enableOutEndpoint(bool enable) {
6258
_out_endpoint = enable;
6359
}
6460

65-
void Adafruit_USBD_HID::setReportDescriptor(uint8_t const* desc_report, uint16_t len)
66-
{
61+
void Adafruit_USBD_HID::setReportDescriptor(uint8_t const *desc_report,
62+
uint16_t len) {
6763
_desc_report = desc_report;
6864
_desc_report_len = len;
6965
}
7066

71-
void Adafruit_USBD_HID::setReportCallback(get_report_callback_t get_report, set_report_callback_t set_report)
72-
{
67+
void Adafruit_USBD_HID::setReportCallback(get_report_callback_t get_report,
68+
set_report_callback_t set_report) {
7369
_get_report_cb = get_report;
7470
_set_report_cb = set_report;
7571
}
7672

77-
uint16_t Adafruit_USBD_HID::getDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize)
78-
{
79-
if ( !_desc_report_len ) return 0;
73+
uint16_t Adafruit_USBD_HID::getDescriptor(uint8_t itfnum, uint8_t *buf,
74+
uint16_t bufsize) {
75+
if (!_desc_report_len)
76+
return 0;
8077

81-
if ( _out_endpoint )
82-
{
78+
if (_out_endpoint) {
8379
// usb core will automatically update endpoint number
84-
uint8_t desc[] = { TUD_HID_INOUT_DESCRIPTOR(itfnum, 0, _protocol, _desc_report_len, EPOUT, EPIN, CFG_TUD_HID_BUFSIZE, _interval_ms) };
80+
uint8_t desc[] = {
81+
TUD_HID_INOUT_DESCRIPTOR(itfnum, 0, _protocol, _desc_report_len, EPOUT,
82+
EPIN, CFG_TUD_HID_BUFSIZE, _interval_ms)};
8583
uint16_t const len = sizeof(desc);
8684

87-
if ( bufsize < len ) return 0;
85+
if (bufsize < len)
86+
return 0;
8887
memcpy(buf, desc, len);
8988

9089
return len;
91-
}else
92-
{
90+
} else {
9391
// usb core will automatically update endpoint number
94-
uint8_t desc[] = { TUD_HID_DESCRIPTOR(itfnum, 0, _protocol, _desc_report_len, EPIN, CFG_TUD_HID_BUFSIZE, _interval_ms) };
92+
uint8_t desc[] = {TUD_HID_DESCRIPTOR(itfnum, 0, _protocol, _desc_report_len,
93+
EPIN, CFG_TUD_HID_BUFSIZE,
94+
_interval_ms)};
9595
uint16_t const len = sizeof(desc);
9696

97-
if ( bufsize < len ) return 0;
97+
if (bufsize < len)
98+
return 0;
9899
memcpy(buf, desc, len);
99100

100101
return len;
101102
}
102103
}
103104

104-
bool Adafruit_USBD_HID::begin(void)
105-
{
106-
if ( !USBDevice.addInterface(*this) ) return false;
105+
bool Adafruit_USBD_HID::begin(void) {
106+
if (!USBDevice.addInterface(*this))
107+
return false;
107108

108109
_hid_dev = this;
109110
return true;
110111
}
111112

112-
bool Adafruit_USBD_HID::ready(void)
113-
{
114-
return tud_hid_ready();
115-
}
113+
bool Adafruit_USBD_HID::ready(void) { return tud_hid_ready(); }
116114

117-
bool Adafruit_USBD_HID::sendReport(uint8_t report_id, void const* report, uint8_t len)
118-
{
115+
bool Adafruit_USBD_HID::sendReport(uint8_t report_id, void const *report,
116+
uint8_t len) {
119117
return tud_hid_report(report_id, report, len);
120118
}
121119

122120
//------------- TinyUSB callbacks -------------//
123-
extern "C"
124-
{
121+
extern "C" {
125122

126123
// Invoked when received GET HID REPORT DESCRIPTOR
127-
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
128-
uint8_t const * tud_hid_descriptor_report_cb(void)
129-
{
130-
if (!_hid_dev) return NULL;
124+
// Application return pointer to descriptor, whose contents must exist long
125+
// enough for transfer to complete
126+
uint8_t const *tud_hid_descriptor_report_cb(void) {
127+
if (!_hid_dev)
128+
return NULL;
131129

132130
return _hid_dev->_desc_report;
133131
}
134132

135133
// Invoked when received GET_REPORT control request
136134
// Application must fill buffer report's content and return its length.
137135
// Return zero will cause the stack to STALL request
138-
uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
139-
{
140-
if ( !(_hid_dev && _hid_dev->_get_report_cb) ) return 0;
136+
uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type,
137+
uint8_t *buffer, uint16_t reqlen) {
138+
if (!(_hid_dev && _hid_dev->_get_report_cb))
139+
return 0;
141140

142141
return _hid_dev->_get_report_cb(report_id, report_type, buffer, reqlen);
143142
}
144143

145144
// Invoked when received SET_REPORT control request or
146145
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
147-
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
148-
{
149-
if ( !(_hid_dev && _hid_dev->_set_report_cb) ) return;
146+
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type,
147+
uint8_t const *buffer, uint16_t bufsize) {
148+
if (!(_hid_dev && _hid_dev->_set_report_cb))
149+
return;
150150

151151
_hid_dev->_set_report_cb(report_id, report_type, buffer, bufsize);
152152
}
@@ -157,56 +157,52 @@ void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uin
157157
// Keyboard
158158
//--------------------------------------------------------------------+
159159

160-
bool Adafruit_USBD_HID::keyboardReport(uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
161-
{
160+
bool Adafruit_USBD_HID::keyboardReport(uint8_t report_id, uint8_t modifier,
161+
uint8_t keycode[6]) {
162162
return tud_hid_keyboard_report(report_id, modifier, keycode);
163163
}
164164

165-
bool Adafruit_USBD_HID::keyboardPress(uint8_t report_id, char ch)
166-
{
167-
uint8_t keycode[6] = { 0 };
168-
uint8_t modifier = 0;
165+
bool Adafruit_USBD_HID::keyboardPress(uint8_t report_id, char ch) {
166+
uint8_t keycode[6] = {0};
167+
uint8_t modifier = 0;
169168

170-
if ( _ascii2keycode[ch][0] ) modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
169+
if (_ascii2keycode[ch][0])
170+
modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
171171
keycode[0] = _ascii2keycode[ch][1];
172172

173173
return tud_hid_keyboard_report(report_id, modifier, keycode);
174174
}
175175

176-
bool Adafruit_USBD_HID::keyboardRelease(uint8_t report_id)
177-
{
176+
bool Adafruit_USBD_HID::keyboardRelease(uint8_t report_id) {
178177
return tud_hid_keyboard_report(report_id, 0, NULL);
179178
}
180179

181180
//--------------------------------------------------------------------+
182181
// Mouse
183182
//--------------------------------------------------------------------+
184183

185-
bool Adafruit_USBD_HID::mouseReport(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
186-
{
184+
bool Adafruit_USBD_HID::mouseReport(uint8_t report_id, uint8_t buttons,
185+
int8_t x, int8_t y, int8_t vertical,
186+
int8_t horizontal) {
187187
// cache mouse button for other API such as move, scroll
188188
_mouse_button = buttons;
189189

190190
return tud_hid_mouse_report(report_id, buttons, x, y, vertical, horizontal);
191191
}
192192

193-
bool Adafruit_USBD_HID::mouseMove(uint8_t report_id, int8_t x, int8_t y)
194-
{
193+
bool Adafruit_USBD_HID::mouseMove(uint8_t report_id, int8_t x, int8_t y) {
195194
return tud_hid_mouse_report(report_id, _mouse_button, x, y, 0, 0);
196195
}
197196

198-
bool Adafruit_USBD_HID::mouseScroll(uint8_t report_id, int8_t scroll, int8_t pan)
199-
{
197+
bool Adafruit_USBD_HID::mouseScroll(uint8_t report_id, int8_t scroll,
198+
int8_t pan) {
200199
return tud_hid_mouse_report(report_id, _mouse_button, 0, 0, scroll, pan);
201200
}
202201

203-
bool Adafruit_USBD_HID::mouseButtonPress(uint8_t report_id, uint8_t buttons)
204-
{
202+
bool Adafruit_USBD_HID::mouseButtonPress(uint8_t report_id, uint8_t buttons) {
205203
return tud_hid_mouse_report(report_id, buttons, 0, 0, 0, 0);
206204
}
207205

208-
bool Adafruit_USBD_HID::mouseButtonRelease(uint8_t report_id)
209-
{
206+
bool Adafruit_USBD_HID::mouseButtonRelease(uint8_t report_id) {
210207
return tud_hid_mouse_report(report_id, 0, 0, 0, 0, 0);
211208
}
212-

src/Adafruit_USBD_HID.h

Lines changed: 50 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* The MIT License (MIT)
33
*
44
* Copyright (c) 2019 Ha Thach for Adafruit Industries
@@ -27,55 +27,66 @@
2727

2828
#include "Adafruit_TinyUSB_Core.h"
2929

30-
class Adafruit_USBD_HID : Adafruit_USBD_Interface
31-
{
32-
public:
33-
typedef uint16_t (*get_report_callback_t) (uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
34-
typedef void (*set_report_callback_t)(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
30+
class Adafruit_USBD_HID : Adafruit_USBD_Interface {
31+
public:
32+
typedef uint16_t (*get_report_callback_t)(uint8_t report_id,
33+
hid_report_type_t report_type,
34+
uint8_t *buffer, uint16_t reqlen);
35+
typedef void (*set_report_callback_t)(uint8_t report_id,
36+
hid_report_type_t report_type,
37+
uint8_t const *buffer,
38+
uint16_t bufsize);
3539

36-
Adafruit_USBD_HID(void);
40+
Adafruit_USBD_HID(void);
3741

38-
void setPollInterval(uint8_t interval_ms);
39-
void setBootProtocol(uint8_t protocol); // 0: None, 1: Keyboard, 2:Mouse
40-
void enableOutEndpoint(bool enable);
41-
void setReportDescriptor(uint8_t const* desc_report, uint16_t len);
42-
void setReportCallback(get_report_callback_t get_report, set_report_callback_t set_report);
42+
void setPollInterval(uint8_t interval_ms);
43+
void setBootProtocol(uint8_t protocol); // 0: None, 1: Keyboard, 2:Mouse
44+
void enableOutEndpoint(bool enable);
45+
void setReportDescriptor(uint8_t const *desc_report, uint16_t len);
46+
void setReportCallback(get_report_callback_t get_report,
47+
set_report_callback_t set_report);
4348

44-
bool begin(void);
49+
bool begin(void);
4550

46-
bool ready(void);
47-
bool sendReport(uint8_t report_id, void const* report, uint8_t len);
51+
bool ready(void);
52+
bool sendReport(uint8_t report_id, void const *report, uint8_t len);
4853

49-
//------------- Keyboard API -------------//
50-
bool keyboardReport(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
51-
bool keyboardPress(uint8_t report_id, char ch);
52-
bool keyboardRelease(uint8_t report_id);
54+
//------------- Keyboard API -------------//
55+
bool keyboardReport(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
56+
bool keyboardPress(uint8_t report_id, char ch);
57+
bool keyboardRelease(uint8_t report_id);
5358

54-
//------------- Mouse API -------------//
55-
bool mouseReport(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
56-
bool mouseMove(uint8_t report_id, int8_t x, int8_t y);
57-
bool mouseScroll(uint8_t report_id, int8_t scroll, int8_t pan);
58-
bool mouseButtonPress(uint8_t report_id, uint8_t buttons);
59-
static inline bool mouseButtonRelease(uint8_t report_id);
59+
//------------- Mouse API -------------//
60+
bool mouseReport(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y,
61+
int8_t vertical, int8_t horizontal);
62+
bool mouseMove(uint8_t report_id, int8_t x, int8_t y);
63+
bool mouseScroll(uint8_t report_id, int8_t scroll, int8_t pan);
64+
bool mouseButtonPress(uint8_t report_id, uint8_t buttons);
65+
static inline bool mouseButtonRelease(uint8_t report_id);
6066

61-
// from Adafruit_USBD_Interface
62-
virtual uint16_t getDescriptor(uint8_t itfnum, uint8_t* buf, uint16_t bufsize);
67+
// from Adafruit_USBD_Interface
68+
virtual uint16_t getDescriptor(uint8_t itfnum, uint8_t *buf,
69+
uint16_t bufsize);
6370

64-
private:
65-
uint8_t _interval_ms;
66-
uint8_t _protocol;
67-
bool _out_endpoint;
68-
uint8_t _mouse_button;
71+
private:
72+
uint8_t _interval_ms;
73+
uint8_t _protocol;
74+
bool _out_endpoint;
75+
uint8_t _mouse_button;
6976

70-
uint16_t _desc_report_len;
71-
uint8_t const* _desc_report;
77+
uint16_t _desc_report_len;
78+
uint8_t const *_desc_report;
7279

73-
get_report_callback_t _get_report_cb;
74-
set_report_callback_t _set_report_cb;
80+
get_report_callback_t _get_report_cb;
81+
set_report_callback_t _set_report_cb;
7582

76-
friend uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
77-
friend void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
78-
friend uint8_t const * tud_hid_descriptor_report_cb(void);
83+
friend uint16_t tud_hid_get_report_cb(uint8_t report_id,
84+
hid_report_type_t report_type,
85+
uint8_t *buffer, uint16_t reqlen);
86+
friend void tud_hid_set_report_cb(uint8_t report_id,
87+
hid_report_type_t report_type,
88+
uint8_t const *buffer, uint16_t bufsize);
89+
friend uint8_t const *tud_hid_descriptor_report_cb(void);
7990
};
8091

8192
#endif /* ADAFRUIT_USBD_HID_H_ */

0 commit comments

Comments
 (0)