Skip to content

Commit f898cca

Browse files
authored
Merge pull request #335 from adafruit/update-tinyusb-b394ae1786911a89ea3437d7090cda477ca7df6c
update tinyusb to commit b394ae1786911a89ea3437d7090cda477ca7df6c
2 parents a465c3c + c038be8 commit f898cca

File tree

28 files changed

+429
-595
lines changed

28 files changed

+429
-595
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2018, hathach for Adafruit
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#ifndef _TUSB_CONFIG_ESP32_H_
26+
#define _TUSB_CONFIG_ESP32_H_
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
// ESP32 Arduino core already integrated tinyusb using lib arduino_tinyusb
33+
// https://github.com/espressif/esp32-arduino-lib-builder/tree/master/components/arduino_tinyusb
34+
// Although it is possible to use .c files in this library for linking instead
35+
// of lib arduino_tinyusb. However, include path of lib arduino_tinyusb is first
36+
// in order. Therefore, changes in this Adafruit TinyUSB library's header are
37+
// not picked up by its .c file. Due to the version difference between the 2
38+
// libraries, this file is used to make it compatible with ESP32 Arduino core.
39+
40+
// This file also contains additional configuration for EPS32 in addition to
41+
// tools/sdk/esp32xx/include/arduino_tinyusb/include/tusb_config.h
42+
43+
//--------------------------------------------------------------------+
44+
// ESP32 out-of-sync
45+
//--------------------------------------------------------------------+
46+
#ifndef tu_static
47+
#define tu_static static
48+
49+
#include <stddef.h>
50+
#include <string.h>
51+
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) {
52+
if (count > destsz) {
53+
return -1;
54+
}
55+
memset(dest, ch, count);
56+
return 0;
57+
}
58+
static inline int tu_memcpy_s(void *dest, size_t destsz, const void *src,
59+
size_t count) {
60+
if (count > destsz) {
61+
return -1;
62+
}
63+
memcpy(dest, src, count);
64+
return 0;
65+
}
66+
#endif
67+
68+
#ifndef CFG_TUD_MEM_SECTION
69+
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
70+
#endif
71+
72+
#ifndef CFG_TUD_LOG_LEVEL
73+
#define CFG_TUD_LOG_LEVEL 2
74+
#endif
75+
76+
#if 0
77+
//--------------------------------------------------------------------
78+
// COMMON CONFIGURATION
79+
//--------------------------------------------------------------------
80+
#define CFG_TUSB_MCU OPT_MCU_NRF5X
81+
82+
#define CFG_TUSB_OS OPT_OS_FREERTOS
83+
#define CFG_TUSB_MEM_SECTION
84+
#define CFG_TUSB_MEM_ALIGN __attribute__((aligned(4)))
85+
86+
#ifndef CFG_TUSB_DEBUG
87+
#define CFG_TUSB_DEBUG 0
88+
#endif
89+
90+
// For selectively disable device log (when > CFG_TUSB_DEBUG)
91+
// #define CFG_TUD_LOG_LEVEL 3
92+
93+
#ifdef USE_TINYUSB
94+
// Enable device stack
95+
#define CFG_TUD_ENABLED 1
96+
97+
// Enable host stack with MAX3421E (host shield)
98+
#define CFG_TUH_ENABLED 1
99+
#define CFG_TUH_MAX3421 1
100+
101+
#else
102+
#define CFG_TUD_ENABLED 0
103+
#define CFG_TUH_ENABLED 0
104+
#endif
105+
106+
//--------------------------------------------------------------------
107+
// DEVICE CONFIGURATION
108+
//--------------------------------------------------------------------
109+
110+
//--------------------------------------------------------------------
111+
// Host Configuration
112+
//--------------------------------------------------------------------
113+
114+
// Size of buffer to hold descriptors and other data used for enumeration
115+
#define CFG_TUH_ENUMERATION_BUFSIZE 256
116+
117+
// Number of hub devices
118+
#define CFG_TUH_HUB 1
119+
120+
// max device support (excluding hub device): 1 hub typically has 4 ports
121+
#define CFG_TUH_DEVICE_MAX (3 * CFG_TUH_HUB + 1)
122+
123+
// Enable tuh_edpt_xfer() API
124+
// #define CFG_TUH_API_EDPT_XFER 1
125+
126+
// Number of mass storage
127+
#define CFG_TUH_MSC 1
128+
129+
// Number of HIDs
130+
// typical keyboard + mouse device can have 3,4 HID interfaces
131+
#define CFG_TUH_HID (3 * CFG_TUH_DEVICE_MAX)
132+
133+
// Number of CDC interfaces
134+
// FTDI and CP210x are not part of CDC class, only to re-use CDC driver API
135+
#define CFG_TUH_CDC 1
136+
#define CFG_TUH_CDC_FTDI 1
137+
#define CFG_TUH_CDC_CP210X 1
138+
139+
// RX & TX fifo size
140+
#define CFG_TUH_CDC_RX_BUFSIZE 64
141+
#define CFG_TUH_CDC_TX_BUFSIZE 64
142+
143+
// Set Line Control state on enumeration/mounted:
144+
// DTR ( bit 0), RTS (bit 1)
145+
#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03
146+
147+
// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t
148+
// bit rate = 115200, 1 stop bit, no parity, 8 bit data width
149+
// This need Pico-PIO-USB at least 0.5.1
150+
#define CFG_TUH_CDC_LINE_CODING_ON_ENUM \
151+
{ 115200, CDC_LINE_CONDING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 }
152+
153+
#endif
154+
155+
#ifdef __cplusplus
156+
}
157+
#endif
158+
159+
#endif

src/class/audio/audio_device.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,16 @@
5454

5555
//--------------------------------------------------------------------+
5656
// INCLUDE
57-
//--------------------------------------------------------------------+
58-
#include "device/usbd.h"
59-
#include "device/usbd_pvt.h"
60-
61-
#include "audio_device.h"
62-
6357
//--------------------------------------------------------------------+
6458
// ESP32 out-of-sync
65-
//--------------------------------------------------------------------+
66-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
67-
#define tu_static static
68-
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
69-
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
59+
#ifdef ARDUINO_ARCH_ESP32
60+
#include "arduino/ports/esp32/tusb_config_esp32.h"
7061
#endif
7162

72-
#ifndef CFG_TUD_MEM_SECTION
73-
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
74-
#endif
63+
#include "device/usbd.h"
64+
#include "device/usbd_pvt.h"
7565

76-
#ifndef CFG_TUD_LOG_LEVEL
77-
#define CFG_TUD_LOG_LEVEL 2
78-
#endif
66+
#include "audio_device.h"
7967

8068
//--------------------------------------------------------------------+
8169
// MACRO CONSTANT TYPEDEF

src/class/bth/bth_device.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,14 @@
3131
//--------------------------------------------------------------------+
3232
// INCLUDE
3333
//--------------------------------------------------------------------+
34-
#include "bth_device.h"
35-
#include <device/usbd_pvt.h>
3634

37-
//--------------------------------------------------------------------+
3835
// ESP32 out-of-sync
39-
//--------------------------------------------------------------------+
40-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
41-
#define tu_static static
42-
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
43-
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
36+
#ifdef ARDUINO_ARCH_ESP32
37+
#include "arduino/ports/esp32/tusb_config_esp32.h"
4438
#endif
4539

46-
#ifndef CFG_TUD_MEM_SECTION
47-
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
48-
#endif
49-
50-
#ifndef CFG_TUD_LOG_LEVEL
51-
#define CFG_TUD_LOG_LEVEL 2
52-
#endif
40+
#include "bth_device.h"
41+
#include <device/usbd_pvt.h>
5342

5443
//--------------------------------------------------------------------+
5544
// MACRO CONSTANT TYPEDEF

src/class/cdc/cdc_device.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,15 @@
2828

2929
#if (CFG_TUD_ENABLED && CFG_TUD_CDC)
3030

31-
#include "device/usbd.h"
32-
#include "device/usbd_pvt.h"
33-
34-
#include "cdc_device.h"
35-
36-
//--------------------------------------------------------------------+
3731
// ESP32 out-of-sync
38-
//--------------------------------------------------------------------+
39-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
40-
#define tu_static static
41-
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
42-
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
32+
#ifdef ARDUINO_ARCH_ESP32
33+
#include "arduino/ports/esp32/tusb_config_esp32.h"
4334
#endif
4435

45-
#ifndef CFG_TUD_MEM_SECTION
46-
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
47-
#endif
48-
49-
#ifndef CFG_TUD_LOG_LEVEL
50-
#define CFG_TUD_LOG_LEVEL 2
51-
#endif
36+
#include "device/usbd.h"
37+
#include "device/usbd_pvt.h"
5238

53-
//--------------------------------------------------------------------+
54-
//
55-
//--------------------------------------------------------------------+
39+
#include "cdc_device.h"
5640

5741
// Level where CFG_TUSB_DEBUG must be at least for this driver is logged
5842
#ifndef CFG_TUD_CDC_LOG_LEVEL

src/class/dfu/dfu_device.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,15 @@
2828

2929
#if (CFG_TUD_ENABLED && CFG_TUD_DFU)
3030

31-
#include "device/usbd.h"
32-
#include "device/usbd_pvt.h"
33-
34-
#include "dfu_device.h"
35-
36-
//--------------------------------------------------------------------+
3731
// ESP32 out-of-sync
38-
//--------------------------------------------------------------------+
39-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
40-
#define tu_static static
41-
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
42-
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
32+
#ifdef ARDUINO_ARCH_ESP32
33+
#include "arduino/ports/esp32/tusb_config_esp32.h"
4334
#endif
4435

45-
#ifndef CFG_TUD_MEM_SECTION
46-
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
47-
#endif
36+
#include "device/usbd.h"
37+
#include "device/usbd_pvt.h"
4838

49-
#ifndef CFG_TUD_LOG_LEVEL
50-
#define CFG_TUD_LOG_LEVEL 2
51-
#endif
39+
#include "dfu_device.h"
5240

5341
//--------------------------------------------------------------------+
5442
// MACRO CONSTANT TYPEDEF

src/class/dfu/dfu_rt_device.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,15 @@
2828

2929
#if (CFG_TUD_ENABLED && CFG_TUD_DFU_RUNTIME)
3030

31-
#include "device/usbd.h"
32-
#include "device/usbd_pvt.h"
33-
34-
#include "dfu_rt_device.h"
35-
36-
//--------------------------------------------------------------------+
3731
// ESP32 out-of-sync
38-
//--------------------------------------------------------------------+
39-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
40-
#define tu_static static
41-
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
42-
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
32+
#ifdef ARDUINO_ARCH_ESP32
33+
#include "arduino/ports/esp32/tusb_config_esp32.h"
4334
#endif
4435

45-
#ifndef CFG_TUD_MEM_SECTION
46-
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
47-
#endif
36+
#include "device/usbd.h"
37+
#include "device/usbd_pvt.h"
4838

49-
#ifndef CFG_TUD_LOG_LEVEL
50-
#define CFG_TUD_LOG_LEVEL 2
51-
#endif
39+
#include "dfu_rt_device.h"
5240

5341
//--------------------------------------------------------------------+
5442
// MACRO CONSTANT TYPEDEF

src/class/hid/hid_device.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,16 @@
3131
//--------------------------------------------------------------------+
3232
// INCLUDE
3333
//--------------------------------------------------------------------+
34-
#include "device/usbd.h"
35-
#include "device/usbd_pvt.h"
36-
37-
#include "hid_device.h"
3834

39-
//--------------------------------------------------------------------+
4035
// ESP32 out-of-sync
41-
//--------------------------------------------------------------------+
42-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
43-
#define tu_static static
44-
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
45-
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
36+
#ifdef ARDUINO_ARCH_ESP32
37+
#include "arduino/ports/esp32/tusb_config_esp32.h"
4638
#endif
4739

48-
#ifndef CFG_TUD_MEM_SECTION
49-
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
50-
#endif
40+
#include "device/usbd.h"
41+
#include "device/usbd_pvt.h"
5142

52-
#ifndef CFG_TUD_LOG_LEVEL
53-
#define CFG_TUD_LOG_LEVEL 2
54-
#endif
43+
#include "hid_device.h"
5544

5645
//--------------------------------------------------------------------+
5746
// MACRO CONSTANT TYPEDEF

src/class/midi/midi_device.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,16 @@
3131
//--------------------------------------------------------------------+
3232
// INCLUDE
3333
//--------------------------------------------------------------------+
34-
#include "device/usbd.h"
35-
#include "device/usbd_pvt.h"
36-
37-
#include "midi_device.h"
3834

39-
//--------------------------------------------------------------------+
4035
// ESP32 out-of-sync
41-
//--------------------------------------------------------------------+
42-
#if defined(ARDUINO_ARCH_ESP32) && !defined(tu_static)
43-
#define tu_static static
44-
static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) { if (count > destsz) { return -1; } memset(dest, ch, count); return 0; }
45-
static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count ) { if (count > destsz) { return -1; } memcpy(dest, src, count); return 0; }
36+
#ifdef ARDUINO_ARCH_ESP32
37+
#include "arduino/ports/esp32/tusb_config_esp32.h"
4638
#endif
4739

48-
#ifndef CFG_TUD_MEM_SECTION
49-
#define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
50-
#endif
40+
#include "device/usbd.h"
41+
#include "device/usbd_pvt.h"
5142

52-
#ifndef CFG_TUD_LOG_LEVEL
53-
#define CFG_TUD_LOG_LEVEL 2
54-
#endif
43+
#include "midi_device.h"
5544

5645
//--------------------------------------------------------------------+
5746
// MACRO CONSTANT TYPEDEF

0 commit comments

Comments
 (0)