Skip to content

Commit ee507d5

Browse files
committed
update tinyusb API changes
1 parent 031c295 commit ee507d5

File tree

6 files changed

+87
-63
lines changed

6 files changed

+87
-63
lines changed

src/Adafruit_USBD_HID.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ extern "C" {
135135
// Invoked when received GET HID REPORT DESCRIPTOR
136136
// Application return pointer to descriptor, whose contents must exist long
137137
// enough for transfer to complete
138-
uint8_t const *tud_hid_descriptor_report_cb(void) {
138+
uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) {
139+
(void) itf;
140+
139141
if (!_hid_dev)
140142
return NULL;
141143

@@ -145,8 +147,10 @@ uint8_t const *tud_hid_descriptor_report_cb(void) {
145147
// Invoked when received GET_REPORT control request
146148
// Application must fill buffer report's content and return its length.
147149
// Return zero will cause the stack to STALL request
148-
uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type,
150+
uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type,
149151
uint8_t *buffer, uint16_t reqlen) {
152+
(void) itf;
153+
150154
if (!(_hid_dev && _hid_dev->_get_report_cb))
151155
return 0;
152156

@@ -155,8 +159,10 @@ uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type,
155159

156160
// Invoked when received SET_REPORT control request or
157161
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
158-
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type,
162+
void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type,
159163
uint8_t const *buffer, uint16_t bufsize) {
164+
(void) itf;
165+
160166
if (!(_hid_dev && _hid_dev->_set_report_cb))
161167
return;
162168

src/Adafruit_USBD_HID.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ class Adafruit_USBD_HID : public Adafruit_USBD_Interface {
8585
get_report_callback_t _get_report_cb;
8686
set_report_callback_t _set_report_cb;
8787

88-
friend uint16_t tud_hid_get_report_cb(uint8_t report_id,
88+
friend uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id,
8989
hid_report_type_t report_type,
9090
uint8_t *buffer, uint16_t reqlen);
91-
friend void tud_hid_set_report_cb(uint8_t report_id,
91+
friend void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id,
9292
hid_report_type_t report_type,
9393
uint8_t const *buffer, uint16_t bufsize);
94-
friend uint8_t const *tud_hid_descriptor_report_cb(void);
94+
friend uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf);
9595
};
9696

9797
#endif /* ADAFRUIT_USBD_HID_H_ */

src/Adafruit_USBD_MIDI.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ uint16_t Adafruit_USBD_MIDI::getDescriptor(uint8_t itfnum, uint8_t *buf,
9797

9898
int Adafruit_USBD_MIDI::read(void) {
9999
uint8_t ch;
100-
return tud_midi_read(&ch, 1) ? (int)ch : (-1);
100+
return tud_midi_stream_read(&ch, 1) ? (int)ch : (-1);
101101
}
102102

103-
size_t Adafruit_USBD_MIDI::write(uint8_t b) { return tud_midi_write(0, &b, 1); }
103+
size_t Adafruit_USBD_MIDI::write (uint8_t b) {
104+
return tud_midi_stream_write(0, &b, 1);
105+
}
104106

105-
int Adafruit_USBD_MIDI::available(void) { return tud_midi_available(); }
107+
int Adafruit_USBD_MIDI::available (void) {
108+
return tud_midi_available();
109+
}
106110

107111
int Adafruit_USBD_MIDI::peek(void) {
108112
// MIDI Library doen't use peek
@@ -113,12 +117,12 @@ void Adafruit_USBD_MIDI::flush(void) {
113117
// MIDI Library doen't use flush
114118
}
115119

116-
bool Adafruit_USBD_MIDI::send(const uint8_t packet[4]) {
117-
return tud_midi_send(packet);
120+
bool Adafruit_USBD_MIDI::writePacket(const uint8_t packet[4]) {
121+
return tud_midi_packet_write(packet);
118122
}
119123

120-
bool Adafruit_USBD_MIDI::receive(uint8_t packet[4]) {
121-
return tud_midi_receive(packet);
124+
bool Adafruit_USBD_MIDI::readPacket(uint8_t packet[4]) {
125+
return tud_midi_packet_read(packet);
122126
}
123127

124128
#endif

src/Adafruit_USBD_MIDI.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class Adafruit_USBD_MIDI : public Stream, public Adafruit_USBD_Interface {
4949
using Stream::write;
5050

5151
// Raw MIDI USB packet interface.
52-
bool send(const uint8_t packet[4]);
53-
bool receive(uint8_t packet[4]);
52+
bool writePacket(const uint8_t packet[4]);
53+
bool readPacket(uint8_t packet[4]);
5454

5555
// from Adafruit_USBD_Interface
5656
virtual uint16_t getDescriptor(uint8_t itfnum, uint8_t *buf,

src/Adafruit_USBD_WebUSB.cpp

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -209,58 +209,77 @@ size_t Adafruit_USBD_WebUSB::write(const uint8_t *buffer, size_t size) {
209209

210210
int Adafruit_USBD_WebUSB::peek(void) {
211211
uint8_t ch;
212-
return tud_vendor_peek(0, &ch) ? (int)ch : -1;
212+
return tud_vendor_peek(&ch) ? (int)ch : -1;
213213
}
214214

215215
void Adafruit_USBD_WebUSB::flush(void) {}
216216

217217
extern "C" {
218218

219-
// Invoked when received VENDOR control request
220-
bool tud_vendor_control_request_cb(uint8_t rhport,
221-
tusb_control_request_t const *request) {
219+
// Invoked when a control transfer occurred on an interface of this class
220+
// Driver response accordingly to the request and the transfer stage (setup/data/ack)
221+
// return false to stall control endpoint (e.g unsupported request)
222+
bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
223+
{
222224
if (!_webusb_dev)
223225
return false;
224226

225-
switch (request->bRequest) {
226-
case VENDOR_REQUEST_WEBUSB:
227-
// match vendor request in BOS descriptor
228-
// Get landing page url
229-
if (!_webusb_dev->_url)
227+
// nothing to with DATA & ACK stage
228+
if (stage != CONTROL_STAGE_SETUP) return true;
229+
230+
switch ( request->bmRequestType_bit.type )
231+
{
232+
case TUSB_REQ_TYPE_VENDOR:
233+
switch ( request->bRequest )
234+
{
235+
case VENDOR_REQUEST_WEBUSB:
236+
// match vendor request in BOS descriptor
237+
// Get landing page url
238+
if ( !_webusb_dev->_url )
239+
return false;
240+
return tud_control_xfer(rhport, request, (void*) _webusb_dev->_url,
241+
_webusb_dev->_url[0]);
242+
243+
case VENDOR_REQUEST_MICROSOFT:
244+
if ( request->wIndex == 7 )
245+
{
246+
// Get Microsoft OS 2.0 compatible descriptor
247+
uint16_t total_len;
248+
memcpy(&total_len, desc_ms_os_20 + 8, 2);
249+
250+
return tud_control_xfer(rhport, request, (void*) desc_ms_os_20,
251+
total_len);
252+
}
253+
else
254+
{
255+
return false;
256+
}
257+
258+
default: break;
259+
}
260+
break;
261+
262+
case TUSB_REQ_TYPE_CLASS:
263+
if (request->bRequest == 0x22)
264+
{
265+
// Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to
266+
// connect and disconnect.
267+
_webusb_dev->_connected = (request->wValue != 0);
268+
269+
// response with status OK
270+
tud_control_status(rhport, request);
271+
272+
// invoked callback if any (TODO should be done at ACK stage)
273+
if ( _webusb_dev->_linestate_cb )
274+
_webusb_dev->_linestate_cb(_webusb_dev->_connected);
275+
276+
return true;
277+
}
278+
break;
279+
280+
default:
281+
// stall unknown request
230282
return false;
231-
return tud_control_xfer(rhport, request, (void *)_webusb_dev->_url,
232-
_webusb_dev->_url[0]);
233-
234-
case VENDOR_REQUEST_MICROSOFT:
235-
if (request->wIndex == 7) {
236-
// Get Microsoft OS 2.0 compatible descriptor
237-
uint16_t total_len;
238-
memcpy(&total_len, desc_ms_os_20 + 8, 2);
239-
240-
return tud_control_xfer(rhport, request, (void *)desc_ms_os_20,
241-
total_len);
242-
} else {
243-
return false;
244-
}
245-
246-
case 0x22:
247-
// Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to
248-
// connect and disconnect.
249-
_webusb_dev->_connected = (request->wValue != 0);
250-
251-
// response with status OK
252-
tud_control_status(rhport, request);
253-
254-
// invoked callback if any
255-
if (_webusb_dev->_linestate_cb)
256-
_webusb_dev->_linestate_cb(_webusb_dev->_connected);
257-
258-
return true;
259-
;
260-
261-
default:
262-
// stall unknown request
263-
return false;
264283
}
265284

266285
return true;

src/Adafruit_USBD_WebUSB.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,7 @@ class Adafruit_USBD_WebUSB : public Stream, public Adafruit_USBD_Interface {
7070
linestate_callback_t _linestate_cb;
7171

7272
// Make all tinyusb callback friend to access private data
73-
friend bool
74-
tud_vendor_control_request_cb(uint8_t rhport,
75-
tusb_control_request_t const *request);
76-
friend bool
77-
tud_vendor_control_complete_cb(uint8_t rhport,
78-
tusb_control_request_t const *request);
73+
friend bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
7974
};
8075

8176
#endif /* ADAFRUIT_USBD_WEBUSB_H_ */

0 commit comments

Comments
 (0)