Skip to content

Commit f0f9240

Browse files
committed
clean up webusb
1 parent 1511181 commit f0f9240

File tree

2 files changed

+16
-60
lines changed

2 files changed

+16
-60
lines changed

src/arduino/webusb/Adafruit_USBD_WebUSB.cpp

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -122,40 +122,10 @@ TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size");
122122
//--------------------------------------------------------------------+
123123
// IMPLEMENTATION
124124
//--------------------------------------------------------------------+
125-
126-
#ifdef ARDUINO_ARCH_ESP32
127-
static uint16_t webusb_load_descriptor(uint8_t *dst, uint8_t *itf) {
128-
// uint8_t str_index = tinyusb_add_string_descriptor("TinyUSB MSC");
129-
130-
uint8_t ep_in = tinyusb_get_free_in_endpoint();
131-
uint8_t ep_out = tinyusb_get_free_out_endpoint();
132-
TU_VERIFY(ep_in && ep_out);
133-
ep_in |= 0x80;
134-
135-
uint16_t desc_len = _webusb_dev->getInterfaceDescriptorLen();
136-
desc_len = _webusb_dev->makeItfDesc(*itf, dst, desc_len, ep_in, ep_out);
137-
138-
*itf += 1;
139-
return desc_len;
140-
}
141-
#endif
142-
143125
Adafruit_USBD_WebUSB::Adafruit_USBD_WebUSB(const void *url) {
144126
_connected = false;
145127
_url = (const uint8_t *)url;
146128
_linestate_cb = NULL;
147-
148-
#ifdef ARDUINO_ARCH_ESP32
149-
// ESP32 requires setup configuration descriptor within constructor
150-
151-
// WebUSB requires USB version at least 2.1 (or 3.x)
152-
USB.usbVersion(0x0210);
153-
154-
_webusb_dev = this;
155-
uint16_t const desc_len = getInterfaceDescriptorLen();
156-
tinyusb_enable_interface(USB_INTERFACE_VENDOR, desc_len,
157-
webusb_load_descriptor);
158-
#endif
159129
}
160130

161131
bool Adafruit_USBD_WebUSB::begin(void) {
@@ -179,29 +149,6 @@ void Adafruit_USBD_WebUSB::setLineStateCallback(linestate_callback_t fp) {
179149
_linestate_cb = fp;
180150
}
181151

182-
uint16_t Adafruit_USBD_WebUSB::makeItfDesc(uint8_t itfnum, uint8_t *buf,
183-
uint16_t bufsize, uint8_t ep_in,
184-
uint8_t ep_out) {
185-
uint8_t desc[] = {
186-
TUD_VENDOR_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, EPSIZE)};
187-
uint16_t const len = sizeof(desc);
188-
189-
// null buffer for length only
190-
if (buf) {
191-
if (bufsize < len) {
192-
return 0;
193-
}
194-
195-
memcpy(buf, desc, len);
196-
197-
// update the bFirstInterface in MS OS 2.0 descriptor
198-
// that is binded to WinUSB driver
199-
desc_ms_os_20[0x0a + 0x08 + 4] = itfnum;
200-
}
201-
202-
return len;
203-
}
204-
205152
uint16_t Adafruit_USBD_WebUSB::getInterfaceDescriptor(uint8_t itfnum_deprecated,
206153
uint8_t *buf,
207154
uint16_t bufsize) {
@@ -212,11 +159,25 @@ uint16_t Adafruit_USBD_WebUSB::getInterfaceDescriptor(uint8_t itfnum_deprecated,
212159
}
213160

214161
uint8_t const itfnum = TinyUSBDevice.allocInterface(1);
215-
;
216162
uint8_t const ep_in = TinyUSBDevice.allocEndpoint(TUSB_DIR_IN);
217163
uint8_t const ep_out = TinyUSBDevice.allocEndpoint(TUSB_DIR_OUT);
218164

219-
return makeItfDesc(itfnum, buf, bufsize, ep_in, ep_out);
165+
uint8_t desc[] = {
166+
TUD_VENDOR_DESCRIPTOR(itfnum, _strid, ep_out, ep_in, EPSIZE)};
167+
uint16_t const len = sizeof(desc);
168+
169+
// null buffer for length only
170+
if (bufsize < len) {
171+
return 0;
172+
}
173+
174+
memcpy(buf, desc, len);
175+
176+
// update the bFirstInterface in MS OS 2.0 descriptor
177+
// that is bound to WinUSB driver
178+
desc_ms_os_20[0x0a + 0x08 + 4] = itfnum;
179+
180+
return len;
220181
}
221182

222183
bool Adafruit_USBD_WebUSB::connected(void) {

src/arduino/webusb/Adafruit_USBD_WebUSB.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ class Adafruit_USBD_WebUSB : public Stream, public Adafruit_USBD_Interface {
6767
// from Adafruit_USBD_Interface
6868
virtual uint16_t getInterfaceDescriptor(uint8_t itfnum_deprecated,
6969
uint8_t *buf, uint16_t bufsize);
70-
71-
// internal use only
72-
uint16_t makeItfDesc(uint8_t itfnum, uint8_t *buf, uint16_t bufsize,
73-
uint8_t ep_in, uint8_t ep_out);
74-
7570
private:
7671
bool _connected;
7772
const uint8_t *_url;

0 commit comments

Comments
 (0)