Skip to content

Commit 4d04364

Browse files
committed
update to work better with arduino-esp32 master and latest release 2.0.14
1 parent 33c2a08 commit 4d04364

File tree

8 files changed

+26
-194
lines changed

8 files changed

+26
-194
lines changed

src/arduino/Adafruit_USBH_Host.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
// ESP32 out-of-sync
2626
#ifdef ARDUINO_ARCH_ESP32
2727
#include "arduino/ports/esp32/tusb_config_esp32.h"
28+
#include "driver/gpio.h"
2829
#define MSBFIRST SPI_MSBFIRST
2930
#endif
3031

@@ -39,8 +40,11 @@ Adafruit_USBH_Host *Adafruit_USBH_Host::_instance = NULL;
3940

4041
Adafruit_USBH_Host::Adafruit_USBH_Host(void) {
4142
Adafruit_USBH_Host::_instance = this;
43+
44+
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
4245
_spi = NULL;
4346
_cs = _intr = _sck = _mosi = _miso = -1;
47+
#endif
4448
}
4549

4650
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
@@ -161,11 +165,12 @@ TU_ATTR_WEAK void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance,
161165

162166
#if defined(ARDUINO_ARCH_ESP32)
163167

164-
#ifdef PLATFORMIO
165-
#define tuh_int_handler_esp32 tuh_int_handler
166-
#else
168+
#if ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(2, 0, 14) && \
169+
!defined(PLATFORMIO)
167170
extern "C" void hcd_int_handler_esp32(uint8_t rhport, bool in_isr);
168171
#define tuh_int_handler_esp32 hcd_int_handler_esp32
172+
#else
173+
#define tuh_int_handler_esp32 tuh_int_handler
169174
#endif
170175

171176
static void max3421_intr_task(void *param) {

src/arduino/ports/esp32/tusb_config_esp32.h

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -43,65 +43,20 @@ extern "C" {
4343
//--------------------------------------------------------------------+
4444
// ESP32 out-of-sync
4545
//--------------------------------------------------------------------+
46-
#include "esp_idf_version.h"
47-
48-
// IDF 4.4.4 and prior is using tinyusb 0.14.0
49-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 5)
50-
#include <stddef.h>
51-
#include <string.h>
52-
53-
#define tu_static static
54-
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) {
55-
if (count > destsz) {
56-
return -1;
57-
}
58-
memset(dest, ch, count);
59-
return 0;
60-
}
61-
static inline int tu_memcpy_s(void *dest, size_t destsz, const void *src,
62-
size_t count) {
63-
if (count > destsz) {
64-
return -1;
65-
}
66-
memcpy(dest, src, count);
67-
return 0;
68-
}
69-
70-
enum {
71-
TUSB_EPSIZE_BULK_FS = 64,
72-
TUSB_EPSIZE_BULK_HS = 512,
73-
74-
TUSB_EPSIZE_ISO_FS_MAX = 1023,
75-
TUSB_EPSIZE_ISO_HS_MAX = 1024,
76-
};
77-
78-
enum { TUSB_INDEX_INVALID_8 = 0xFFu };
79-
#endif
80-
81-
#ifndef CFG_TUD_MEM_SECTION
82-
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
83-
#endif
84-
85-
#ifndef CFG_TUH_MEM_SECTION
86-
#define CFG_TUH_MEM_SECTION CFG_TUSB_MEM_SECTION
87-
#endif
88-
89-
#ifndef CFG_TUH_MEM_ALIGN
90-
#define CFG_TUH_MEM_ALIGN CFG_TUSB_MEM_ALIGN
91-
#endif
46+
#include "esp_arduino_version.h"
9247

9348
#ifndef CFG_TUD_LOG_LEVEL
9449
#define CFG_TUD_LOG_LEVEL 2
9550
#endif
9651

97-
// #ifndef CFG_TUH_LOG_LEVEL
98-
// #define CFG_TUH_LOG_LEVEL 2
99-
// #endif
100-
101-
#ifndef CFG_TUSB_DEBUG
102-
#define CFG_TUSB_DEBUG 0
52+
#ifndef CFG_TUH_LOG_LEVEL
53+
#define CFG_TUH_LOG_LEVEL 2
10354
#endif
10455

56+
// #ifndef CFG_TUSB_DEBUG
57+
// #define CFG_TUSB_DEBUG 0
58+
// #endif
59+
10560
// For selectively disable device log (when > CFG_TUSB_DEBUG)
10661
// #define CFG_TUD_LOG_LEVEL 3
10762

@@ -118,7 +73,8 @@ enum { TUSB_INDEX_INVALID_8 = 0xFFu };
11873

11974
// Enable host stack with MAX3421E (host shield)
12075
#define CFG_TUH_ENABLED 1
121-
#define CFG_TUH_MAX_SPEED OPT_MODE_HIGH_SPEED
76+
#define CFG_TUH_MAX_SPEED OPT_MODE_FULL_SPEED
77+
12278
#ifndef TUH_OPT_HIGH_SPEED
12379
#define TUH_OPT_HIGH_SPEED 0
12480
#endif

src/class/cdc/cdc_host.c

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -36,125 +36,8 @@
3636
#include "host/usbh.h"
3737
#include "host/usbh_pvt.h"
3838

39-
//--------------------------------------------------------------------+
40-
// ESP32 out-of-sync
41-
//--------------------------------------------------------------------+
42-
#if defined(ARDUINO_ARCH_ESP32) && !defined(PLATFORMIO)
43-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 5)
44-
typedef struct {
45-
uint8_t daddr;
46-
tusb_desc_interface_t desc;
47-
} tuh_itf_info_t;
48-
49-
typedef struct {
50-
bool is_host; // host or device most
51-
union {
52-
uint8_t daddr;
53-
uint8_t rhport;
54-
uint8_t hwid;
55-
};
56-
uint8_t ep_addr;
57-
uint8_t ep_speed;
58-
59-
uint16_t ep_packetsize;
60-
uint16_t ep_bufsize;
61-
62-
// TODO xfer_fifo can skip this buffer
63-
uint8_t* ep_buf;
64-
65-
tu_fifo_t ff;
66-
67-
// mutex: read if ep rx, write if e tx
68-
OSAL_MUTEX_DEF(ff_mutex);
69-
70-
}tu_edpt_stream_t;
71-
72-
// Init an stream, should only be called once
73-
bool tu_edpt_stream_init(tu_edpt_stream_t* s, bool is_host, bool is_tx, bool overwritable,
74-
void* ff_buf, uint16_t ff_bufsize, uint8_t* ep_buf, uint16_t ep_bufsize);
75-
76-
// Open an stream for an endpoint
77-
// hwid is either device address (host mode) or rhport (device mode)
78-
TU_ATTR_ALWAYS_INLINE static inline
79-
void tu_edpt_stream_open(tu_edpt_stream_t* s, uint8_t hwid, tusb_desc_endpoint_t const *desc_ep) {
80-
tu_fifo_clear(&s->ff);
81-
s->hwid = hwid;
82-
s->ep_addr = desc_ep->bEndpointAddress;
83-
s->ep_packetsize = tu_edpt_packet_size(desc_ep);
84-
}
85-
86-
TU_ATTR_ALWAYS_INLINE static inline
87-
void tu_edpt_stream_close(tu_edpt_stream_t* s) {
88-
s->hwid = 0;
89-
s->ep_addr = 0;
90-
}
91-
92-
// Clear fifo
93-
TU_ATTR_ALWAYS_INLINE static inline
94-
bool tu_edpt_stream_clear(tu_edpt_stream_t* s) {
95-
return tu_fifo_clear(&s->ff);
96-
}
97-
98-
//--------------------------------------------------------------------+
99-
// Stream Write
100-
//--------------------------------------------------------------------+
101-
102-
// Write to stream
103-
uint32_t tu_edpt_stream_write(tu_edpt_stream_t* s, void const *buffer, uint32_t bufsize);
104-
105-
// Start an usb transfer if endpoint is not busy
106-
uint32_t tu_edpt_stream_write_xfer(tu_edpt_stream_t* s);
107-
108-
// Start an zero-length packet if needed
109-
bool tu_edpt_stream_write_zlp_if_needed(tu_edpt_stream_t* s, uint32_t last_xferred_bytes);
110-
111-
// Get the number of bytes available for writing
112-
TU_ATTR_ALWAYS_INLINE static inline
113-
uint32_t tu_edpt_stream_write_available(tu_edpt_stream_t* s)
114-
{
115-
return (uint32_t) tu_fifo_remaining(&s->ff);
116-
}
117-
118-
//--------------------------------------------------------------------+
119-
// Stream Read
120-
//--------------------------------------------------------------------+
121-
122-
// Read from stream
123-
uint32_t tu_edpt_stream_read(tu_edpt_stream_t* s, void* buffer, uint32_t bufsize);
124-
125-
// Start an usb transfer if endpoint is not busy
126-
uint32_t tu_edpt_stream_read_xfer(tu_edpt_stream_t* s);
127-
128-
// Must be called in the transfer complete callback
129-
TU_ATTR_ALWAYS_INLINE static inline
130-
void tu_edpt_stream_read_xfer_complete(tu_edpt_stream_t* s, uint32_t xferred_bytes) {
131-
tu_fifo_write_n(&s->ff, s->ep_buf, (uint16_t) xferred_bytes);
132-
}
133-
134-
// Same as tu_edpt_stream_read_xfer_complete but skip the first n bytes
135-
TU_ATTR_ALWAYS_INLINE static inline
136-
void tu_edpt_stream_read_xfer_complete_offset(tu_edpt_stream_t* s, uint32_t xferred_bytes, uint32_t skip_offset) {
137-
if (skip_offset < xferred_bytes) {
138-
tu_fifo_write_n(&s->ff, s->ep_buf + skip_offset, (uint16_t) (xferred_bytes - skip_offset));
139-
}
140-
}
141-
142-
// Get the number of bytes available for reading
143-
TU_ATTR_ALWAYS_INLINE static inline
144-
uint32_t tu_edpt_stream_read_available(tu_edpt_stream_t* s) {
145-
return (uint32_t) tu_fifo_count(&s->ff);
146-
}
147-
148-
TU_ATTR_ALWAYS_INLINE static inline
149-
bool tu_edpt_stream_peek(tu_edpt_stream_t* s, uint8_t* ch) {
150-
return tu_fifo_peek(&s->ff, ch);
151-
}
152-
#endif
153-
#endif
154-
15539
#include "cdc_host.h"
15640

157-
15841
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
15942
#ifndef CFG_TUH_CDC_LOG_LEVEL
16043
#define CFG_TUH_CDC_LOG_LEVEL CFG_TUH_LOG_LEVEL

src/class/hid/hid_host.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@
3636
#include "host/usbh.h"
3737
#include "host/usbh_pvt.h"
3838

39-
// ESP32 out-of-sync
40-
#if defined(ARDUINO_ARCH_ESP32) && !defined(PLATFORMIO)
41-
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 5)
42-
typedef struct {
43-
uint8_t daddr;
44-
tusb_desc_interface_t desc;
45-
} tuh_itf_info_t;
46-
#endif
47-
#endif
48-
4939
#include "hid_host.h"
5040

5141
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged

src/class/vendor/vendor_device.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
*/
2626

2727
// ESP32 out-of-sync
28-
// Somehow we have linking issue: multiple definition of vendor APIs with arduino-esp32 master
29-
// skip this driver entirely and used the pre-compiled libarduino_tinyusb.a instead
3028
#ifdef ARDUINO_ARCH_ESP32
3129
#include "arduino/ports/esp32/tusb_config_esp32.h"
32-
#else
30+
#endif
3331

3432
#include "tusb_option.h"
3533

@@ -292,4 +290,3 @@ bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint
292290
}
293291

294292
#endif
295-
#endif

src/device/usbd.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
// ESP32 out-of-sync
4545
//--------------------------------------------------------------------+
4646
#if defined(ARDUINO_ARCH_ESP32) && !defined(PLATFORMIO)
47-
TU_ATTR_WEAK bool dcd_edpt_iso_alloc(uint8_t rhport, uint8_t ep_addr, uint16_t largest_packet_size);
48-
TU_ATTR_WEAK bool dcd_edpt_iso_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
49-
5047
#ifndef TU_LOG_BUF
5148
#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL
5249
static inline void tu_print_buf(uint8_t const* buf, uint32_t bufsize) {

src/host/usbh.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
// ESP32 out-of-sync
5555
//--------------------------------------------------------------------+
5656
#ifdef ARDUINO_ARCH_ESP32
57+
58+
#if ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(2, 0, 14) && !defined(PLATFORMIO)
59+
extern bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr);
60+
#endif
61+
5762
#ifndef TU_LOG_BUF
5863
#if CFG_TUSB_DEBUG >= CFG_TUH_LOG_LEVEL
5964
static inline void tu_print_buf(uint8_t const* buf, uint32_t bufsize) {
@@ -65,8 +70,7 @@
6570
#endif
6671
#endif
6772

68-
extern bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr);
69-
#endif
73+
#endif // ESP32
7074

7175
#ifndef TU_LOG_USBH
7276
#define TU_LOG_USBH(...) TU_LOG(CFG_TUH_LOG_LEVEL, __VA_ARGS__)

src/portable/analog/max3421/hcd_max3421.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t daddr, uint8_t const setup_packet[8]
677677
}
678678

679679
// ESP32 out-of-sync
680-
#if defined(ARDUINO_ARCH_ESP32) && !defined(PLATFORMIO)
680+
#if defined(ARDUINO_ARCH_ESP32) && ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(2, 0, 14) && !defined(PLATFORMIO)
681681
bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr) {
682682
#else
683683
// clear stall, data toggle is also reset to DATA0
@@ -875,7 +875,7 @@ void print_hirq(uint8_t hirq) {
875875
#endif
876876

877877
// ESP32 out-of-sync
878-
#if defined(ARDUINO_ARCH_ESP32) && !defined(PLATFORMIO)
878+
#if defined(ARDUINO_ARCH_ESP32) && ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(2, 0, 14) && !defined(PLATFORMIO)
879879
void hcd_int_handler_esp32(uint8_t rhport, bool in_isr) {
880880
#else
881881
// Interrupt handler

0 commit comments

Comments
 (0)