tusb_config.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Ha Thach (tinyusb.org)
3  * 2022 Gunar Schorcht
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE.
22  */
23 
24 #pragma once
25 
36 /* defined by the application */
37 #if __has_include("tinyusb_app_config.h")
38 #include "tinyusb_app_config.h"
39 #endif
40 #include "tinyusb.h"
41 
42 #if MODULE_TINYUSB_CLASS_NET
43 #include "net/ethernet.h"
44 #endif
45 
46 #if !DOXYGEN
47 
48 #if MODULE_TINYUSB_CLASS_NET_CDC_NCM && (MODULE_TINYUSB_CLASS_NET_CDC_ECM || MODULE_TINYUSB_CLASS_NET_RNDIS)
49 #error "CDC NCM device class cannot be used together with CDC ECM or RNDIS device class"
50 #endif
51 
52 #ifndef CONFIG_TUSBD_AUDIO_NUMOF
53 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_AUDIO
54 #define CONFIG_TUSBD_AUDIO_NUMOF 1
55 #else
56 #define CONFIG_TUSBD_AUDIO_NUMOF 0
57 #endif
58 #endif
59 
60 #ifndef CONFIG_TUSBD_BTH_NUMOF
61 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_BTH
62 #define CONFIG_TUSBD_BTH_NUMOF 1
63 #else
64 #define CONFIG_TUSBD_BTH_NUMOF 0
65 #endif
66 #endif
67 
68 #ifndef CONFIG_TUSBD_CDC_NUMOF
69 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_CDC
70 #define CONFIG_TUSBD_CDC_NUMOF 1
71 #else
72 #define CONFIG_TUSBD_CDC_NUMOF 0
73 #endif
74 #endif
75 
76 #ifndef CONFIG_TUSBD_DFU_NUMOF
77 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_DFU
78 #define CONFIG_TUSBD_DFU_NUMOF 1
79 #else
80 #define CONFIG_TUSBD_DFU_NUMOF 0
81 #endif
82 #endif
83 
84 #ifndef CONFIG_TUSBD_DFU_RT_NUMOF
85 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_DFU_RUNTIME
86 #define CONFIG_TUSBD_DFU_RT_NUMOF 1
87 #else
88 #define CONFIG_TUSBD_DFU_RT_NUMOF 0
89 #endif
90 #endif
91 
92 #ifndef CONFIG_TUSBD_HID_NUMOF
93 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_HID
94 #define CONFIG_TUSBD_HID_NUMOF 1
95 #else
96 #define CONFIG_TUSBD_HID_NUMOF 0
97 #endif
98 #endif
99 
100 #ifndef CONFIG_TUSBD_MIDI_NUMOF
101 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_MIDI
102 #define CONFIG_TUSBD_MIDI_NUMOF 1
103 #else
104 #define CONFIG_TUSBD_MIDI_NUMOF 0
105 #endif
106 #endif
107 
108 #ifndef CONFIG_TUSBD_MSC_NUMOF
109 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_MSC
110 #define CONFIG_TUSBD_MSC_NUMOF 1
111 #else
112 #define CONFIG_TUSBD_MSC_NUMOF 0
113 #endif
114 #endif
115 
116 #ifndef CONFIG_TUSBD_USBTMC_NUMOF
117 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_USBTMC
118 #define CONFIG_TUSBD_USBTMC_NUMOF 1
119 #else
120 #define CONFIG_TUSBD_USBTMC_NUMOF 0
121 #endif
122 #endif
123 
124 #ifndef CONFIG_TUSBD_VENDOR_NUMOF
125 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_VENDOR
126 #define CONFIG_TUSBD_VENDOR_NUMOF 1
127 #else
128 #define CONFIG_TUSBD_VENDOR_NUMOF 0
129 #endif
130 #endif
131 
132 #ifndef CONFIG_TUSBD_VIDEO_NUMOF
133 #if MODULE_TINYUSB_DEVICE && MODULE_TINYUSB_CLASS_VIDEO
134 #define CONFIG_TUSBD_VIDEO_NUMOF 1
135 #else
136 #define CONFIG_TUSBD_VIDEO_NUMOF 0
137 #endif
138 #endif
139 
140 #ifndef CONFIG_TUSBH_CDC_NUMOF
141 #if MODULE_TINYUSB_HOST && MODULE_TINYUSB_CLASS_CDC
142 #define CONFIG_TUSBH_CDC_NUMOF 1
143 #else
144 #define CONFIG_TUSBH_CDC_NUMOF 0
145 #endif
146 #endif
147 
148 #ifndef CONFIG_TUSBH_HID_NUMOF
149 #if MODULE_TINYUSB_HOST && MODULE_TINYUSB_CLASS_HID
150 #define CONFIG_TUSBH_HID_NUMOF 1
151 #else
152 #define CONFIG_TUSBH_HID_NUMOF 0
153 #endif
154 #endif
155 
156 #ifndef CONFIG_TUSBH_HUB_NUMOF
157 #if MODULE_TINYUSB_HOST && MODULE_TINYUSB_CLASS_HUB
158 #define CONFIG_TUSBH_HUB_NUMOF 1
159 #else
160 #define CONFIG_TUSBH_HUB_NUMOF 0
161 #endif
162 #endif
163 
164 #ifndef CONFIG_TUSBH_MSC_NUMOF
165 #if MODULE_TINYUSB_HOST && MODULE_TINYUSB_CLASS_MSC
166 #define CONFIG_TUSBH_MSC_NUMOF 1
167 #else
168 #define CONFIG_TUSBH_MSC_NUMOF 0
169 #endif
170 #endif
171 
172 #ifndef CONFIG_TUSBH_VENDOR_NUMOF
173 #if MODULE_TINYUSB_HOST && MODULE_TINYUSB_CLASS_VENDOR
174 #define CONFIG_TUSBH_VENDOR_NUMOF 1
175 #else
176 #define CONFIG_TUSBH_VENDOR_NUMOF 0
177 #endif
178 #endif
179 
180 #ifndef CONFIG_TUSBD_EP0_SIZE
181 #define CONFIG_TUSBD_EP0_SIZE 64
182 #endif
183 
184 #ifndef CONFIG_TUSBD_FS_EP_SIZE
185 #define CONFIG_TUSBD_FS_EP_SIZE 64
186 #endif
187 
188 #ifndef CONFIG_TUSBD_HS_EP_SIZE
189 #define CONFIG_TUSBD_HS_EP_SIZE 512
190 #endif
191 
192 #ifndef CONFIG_TUSBD_CDC_NOTIF_EP_SIZE
193 #define CONFIG_TUSBD_CDC_NOTIF_EP_SIZE 8
194 #endif
195 
196 #ifndef CONFIG_TUSBD_CDC_FS_EP_SIZE
197 #define CONFIG_TUSBD_CDC_FS_EP_SIZE CONFIG_TUSBD_FS_EP_SIZE
198 #endif
199 
200 #ifndef CONFIG_TUSBD_CDC_HS_EP_SIZE
201 #define CONFIG_TUSBD_CDC_HS_EP_SIZE CONFIG_TUSBD_HS_EP_SIZE
202 #endif
203 
204 #ifndef CONFIG_TUSBD_DFU_ATTR
205 #define CONFIG_TUSBD_DFU_ATTR (DFU_ATTR_CAN_DOWNLOAD | \
206  DFU_ATTR_WILL_DETACH | \
207  DFU_ATTR_MANIFESTATION_TOLERANT)
208 #endif
209 
210 #ifndef CONFIG_TUSBD_DFU_DETACH_TIMEOUT
211 #define CONFIG_TUSBD_DFU_DETACH_TIMEOUT 1000
212 #endif
213 
214 #ifndef CONFIG_TUSBD_DFU_POLL_TIMEOUT
215 #define CONFIG_TUSBD_DFU_POLL_TIMEOUT 1
216 #endif
217 
218 #ifndef CONFIG_TUSBD_DFU_RESET_DELAY
219 #define CONFIG_TUSBD_DFU_RESET_DELAY 2
220 #endif
221 
222 #ifndef CONFIG_TUSBD_DFU_FS_XFER_SIZE
223 #define CONFIG_TUSBD_DFU_FS_XFER_SIZE CONFIG_TUSBD_FS_EP_SIZE
224 #endif
225 
226 #ifndef CONFIG_TUSBD_DFU_HS_XFER_SIZE
227 #define CONFIG_TUSBD_DFU_HS_XFER_SIZE CONFIG_TUSBD_HS_EP_SIZE
228 #endif
229 
230 #ifndef CONFIG_TUSBD_HID_EP_SIZE
231 #define CONFIG_TUSBD_HID_EP_SIZE CONFIG_TUSBD_FS_EP_SIZE
232 #endif
233 
234 #ifndef CONFIG_TUSBD_DFU_RT_DETACH_TIMEOUT
235 #define CONFIG_TUSBD_DFU_RT_DETACH_TIMEOUT 1000
236 #endif
237 
238 #ifndef CONFIG_TUSBD_DFU_RT_FS_XFER_SIZE
239 #define CONFIG_TUSBD_DFU_RT_FS_XFER_SIZE CONFIG_TUSBD_FS_EP_SIZE
240 #endif
241 
242 #ifndef CONFIG_TUSBD_DFU_RT_HS_XFER_SIZE
243 #define CONFIG_TUSBD_DFU_RT_HS_XFER_SIZE CONFIG_TUSBD_HS_EP_SIZE
244 #endif
245 
246 #ifndef CONFIG_TUSBD_HID_EP_SIZE
247 #define CONFIG_TUSBD_HID_EP_SIZE CONFIG_TUSBD_FS_EP_SIZE
248 #endif
249 
250 #ifndef CONFIG_TUSBD_HID_0_POLL_INTERVALL
251 #define CONFIG_TUSBD_HID_0_POLL_INTERVALL 10
252 #endif
253 
254 #ifndef CONFIG_TUSBD_HID_1_POLL_INTERVALL
255 #define CONFIG_TUSBD_HID_1_POLL_INTERVALL 10
256 #endif
257 
258 #ifndef CONFIG_TUSBD_MSC_FS_EP_SIZE
259 #define CONFIG_TUSBD_MSC_FS_EP_SIZE CONFIG_TUSBD_FS_EP_SIZE
260 #endif
261 
262 #ifndef CONFIG_TUSBD_MSC_HS_EP_SIZE
263 #define CONFIG_TUSBD_MSC_HS_EP_SIZE CONFIG_TUSBD_HS_EP_SIZE
264 #endif
265 
266 #ifndef CONFIG_TUSBD_NET_FS_EP_SIZE
267 #define CONFIG_TUSBD_NET_FS_EP_SIZE CONFIG_TUSBD_FS_EP_SIZE
268 #endif
269 
270 #ifndef CONFIG_TUSBD_NET_HS_EP_SIZE
271 #define CONFIG_TUSBD_NET_HS_EP_SIZE CONFIG_TUSBD_HS_EP_SIZE
272 #endif
273 
274 #ifndef CONFIG_TUSBD_VENDOR_FS_EP_SIZE
275 #define CONFIG_TUSBD_VENDOR_FS_EP_SIZE CONFIG_TUSBD_FS_EP_SIZE
276 #endif
277 
278 #ifndef CONFIG_TUSBD_VENDOR_HS_EP_SIZE
279 #define CONFIG_TUSBD_VENDOR_HS_EP_SIZE CONFIG_TUSBD_HS_EP_SIZE
280 #endif
281 
282 #ifndef CONFIG_TUSBD_NET_NOTIF_EP_SIZE
283 #define CONFIG_TUSBD_NET_NOTIF_EP_SIZE 64
284 #endif
285 
286 #ifndef CONFIG_TUSBD_NET_MTU_SIZE
287 #define CONFIG_TUSBD_NET_MTU_SIZE ETHERNET_FRAME_LEN
288 #endif
289 
290 #if MODULE_TINYUSB_CLASS_NET_CDC_ECM
291 #define CONFIG_TUSBD_NET_CDC_ECM 1
292 #else
293 #define CONFIG_TUSBD_NET_CDC_ECM 0
294 #endif
295 
296 #if MODULE_TINYUSB_CLASS_NET_CDC_NCM
297 #define CONFIG_TUSBD_NET_CDC_NCM 1
298 #else
299 #define CONFIG_TUSBD_NET_CDC_NCM 0
300 #endif
301 
302 #if MODULE_TINYUSB_CLASS_NET_RNDIS
303 #define CONFIG_TUSBD_NET_RNDIS 1
304 #else
305 #define CONFIG_TUSBD_NET_RNDIS 0
306 #endif
307 
308 #if CONFIG_TUSBD_NET_CDC_ECM || CONFIG_TUSBD_NET_CDC_NCM || CONFIG_TUSBD_NET_RNDIS
309 #define CONFIG_TUSBD_NET_NUMOF 1
310 #else
311 #define CONFIG_TUSBD_NET_NUMOF 0
312 #endif
313 
314 #ifndef CONFIG_TUSBH_ENUM_SIZE
315 #define CONFIG_TUSBH_ENUM_SIZE 256
316 #endif
317 
318 #ifndef CONFIG_TUSBH_HID_EPIN_SIZE
319 #define CONFIG_TUSBH_HID_EPIN_SIZE CONFIG_TUSBD_HID_EP_SIZE
320 #endif
321 
322 #ifndef CONFIG_TUSBH_HID_EPOUT_SIZE
323 #define CONFIG_TUSBH_HID_EPOUT_SIZE CONFIG_TUSBD_HID_EP_SIZE
324 #endif
325 
331 #ifndef CFG_TUSB_MCU
332 #error CFG_TUSB_MCU must be defined
333 #endif
334 
336 #define CFG_TUSB_OS OPT_OS_CUSTOM
337 
339 #ifndef CFG_TUSB_DEBUG
340 #define CFG_TUSB_DEBUG 0
341 #endif
342 
351 #define CFG_TUSB_MEM_SECTION
352 #define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
353 
360 #define CFG_TUD_ENABLED MODULE_TINYUSB_DEVICE
361 
362 #define CFG_TUD_ENDPOINT0_SIZE CONFIG_TUSBD_EP0_SIZE
363 
364 #define CFG_TUD_AUDIO CONFIG_TUSBD_AUDIO_NUMOF
365 #define CFG_TUD_BTH CONFIG_TUSBD_BTH_NUMOF
366 #define CFG_TUD_CDC CONFIG_TUSBD_CDC_NUMOF
367 #define CFG_TUD_ECM_RNDIS (CONFIG_TUSBD_NET_CDC_ECM || CONFIG_TUSBD_NET_RNDIS)
368 #define CFG_TUD_DFU CONFIG_TUSBD_DFU_NUMOF
369 #define CFG_TUD_DFU_RUNTIME CONFIG_TUSBD_DFU_RT_NUMOF
370 #define CFG_TUD_HID CONFIG_TUSBD_HID_NUMOF
371 #define CFG_TUD_MIDI CONFIG_TUSBD_MIDI_NUMOF
372 #define CFG_TUD_MSC CONFIG_TUSBD_MSC_NUMOF
373 #define CFG_TUD_NCM CONFIG_TUSBD_NET_CDC_NCM
374 #define CFG_TUD_USBTMC CONFIG_TUSBD_USBTMC_NUMOF
375 #define CFG_TUD_VENDOR CONFIG_TUSBD_VENDOR_NUMOF
376 #define CFG_TUD_VIDEO CONFIG_TUSBD_VIDEO_NUMOF
377 
384 #define CFG_TUH_ENABLED MODULE_TINYUSB_HOST
385 
386 #define CFG_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED
387 
388 #define CFG_TUH_ENUMERATION_BUFSIZE CONFIG_TUSBH_ENUM_SIZE
389 
391 #define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1)
392 
393 #define CFG_TUH_CDC CONFIG_TUSBH_CDC_NUMOF
394 #define CFG_TUH_HID CONFIG_TUSBH_HID_NUMOF
395 #define CFG_TUH_HUB CONFIG_TUSBH_HUB_NUMOF
396 #define CFG_TUH_MSC CONFIG_TUSBH_MSC_NUMOF
397 #define CFG_TUH_VENDOR CONFIG_TUSBH_VENDOR_NUMOF
398 
405 #define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? CONFIG_TUSBD_CDC_HS_EP_SIZE \
406  : CONFIG_TUSBD_CDC_FS_EP_SIZE)
407 #define CFG_TUD_CDC_RX_BUFSIZE CFG_TUD_CDC_EP_BUFSIZE
408 #define CFG_TUD_CDC_TX_BUFSIZE CFG_TUD_CDC_EP_BUFSIZE
409 
416 #define CFG_TUD_DFU_XFER_BUFSIZE (TUD_OPT_HIGH_SPEED ? CONFIG_TUSBD_DFU_HS_XFER_SIZE \
417  : CONFIG_TUSBD_DFU_FS_XFER_SIZE)
424 #define CFG_TUD_HID_EP_BUFSIZE CONFIG_TUSBD_HID_EP_SIZE
431 #define CFG_TUD_MIDI_RX_BUFSIZE CFG_TUD_MIDI_EP_BUFSIZE
432 #define CFG_TUD_MIDI_TX_BUFSIZE CFG_TUD_MIDI_EP_BUFSIZE
439 #define CFG_TUD_MSC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? CONFIG_TUSBD_MSC_HS_EP_SIZE \
440  : CONFIG_TUSBD_MSC_FS_EP_SIZE)
447 #define CFG_TUD_NET_MTU CONFIG_TUSBD_NET_MTU_SIZE
448 
453 #define CFG_TUH_HID_EPIN_BUFSIZE CONFIG_TUSBH_HID_EPIN_SIZE
454 #define CFG_TUH_HID_EPOUT_BUFSIZE CONFIG_TUSBH_HID_EPOUT_SIZE
457 #ifdef __cplusplus
458 extern "C" {
459 #endif
460 
461 #ifdef __cplusplus
462 }
463 #endif
464 
465 #endif /* !DOXYGEN */
Definitions for Ethernet.
TinyUSB API.