mikroSDK Reference Manual
tusb_option.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
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 * This file is part of the TinyUSB stack.
25 */
26
27#ifndef _TUSB_OPTION_H_
28#define _TUSB_OPTION_H_
29
30#include "common/tusb_compiler.h"
31
32#define TUSB_VERSION_MAJOR 0
33#define TUSB_VERSION_MINOR 15
34#define TUSB_VERSION_REVISION 0
35#define TUSB_VERSION_STRING TU_STRING(TUSB_VERSION_MAJOR) "." TU_STRING(TUSB_VERSION_MINOR) "." TU_STRING(TUSB_VERSION_REVISION)
36
37//--------------------------------------------------------------------+
38// Supported MCUs
39// CFG_TUSB_MCU must be defined to one of following value
40//--------------------------------------------------------------------+
41
42#define OPT_MCU_NONE 0
43
44// LPC
45#define OPT_MCU_LPC11UXX 1
46#define OPT_MCU_LPC13XX 2
47#define OPT_MCU_LPC15XX 3
48#define OPT_MCU_LPC175X_6X 4
49#define OPT_MCU_LPC177X_8X 5
50#define OPT_MCU_LPC18XX 6
51#define OPT_MCU_LPC40XX 7
52#define OPT_MCU_LPC43XX 8
53#define OPT_MCU_LPC51UXX 9
54#define OPT_MCU_LPC54XXX 10
55#define OPT_MCU_LPC55XX 11
56
57// NRF
58#define OPT_MCU_NRF5X 100
59
60// SAM
61#define OPT_MCU_SAMD21 200
62#define OPT_MCU_SAMD51 201
63#define OPT_MCU_SAMG 202
64#define OPT_MCU_SAME5X 203
65#define OPT_MCU_SAMD11 204
66#define OPT_MCU_SAML22 205
67#define OPT_MCU_SAML21 206
68#define OPT_MCU_SAMX7X 207
69
70// STM32
71#define OPT_MCU_STM32F0 300
72#define OPT_MCU_STM32F1 301
73#define OPT_MCU_STM32F2 302
74#define OPT_MCU_STM32F3 303
75#define OPT_MCU_STM32F4 304
76#define OPT_MCU_STM32F7 305
77#define OPT_MCU_STM32H7 306
78#define OPT_MCU_STM32L1 308
79#define OPT_MCU_STM32L0 307
80#define OPT_MCU_STM32L4 309
81#define OPT_MCU_STM32G0 310
82#define OPT_MCU_STM32G4 311
83#define OPT_MCU_STM32WB 312
84#define OPT_MCU_STM32U5 313
85#define OPT_MCU_STM32L5 314
86
87// Sony
88#define OPT_MCU_CXD56 400
89
90// TI
91#define OPT_MCU_MSP430x5xx 500
92#define OPT_MCU_MSP432E4 510
93#define OPT_MCU_TM4C123 511
94#define OPT_MCU_TM4C129 512
95
96// ValentyUSB eptri
97#define OPT_MCU_VALENTYUSB_EPTRI 600
98
99// NXP iMX RT
100#define OPT_MCU_MIMXRT1XXX 700
101#define OPT_MCU_MIMXRT10XX OPT_MCU_MIMXRT1XXX
102#define OPT_MCU_MIMXRT11XX OPT_MCU_MIMXRT1XXX
103
104// Nuvoton
105#define OPT_MCU_NUC121 800
106#define OPT_MCU_NUC126 801
107#define OPT_MCU_NUC120 802
108#define OPT_MCU_NUC505 803
109
110// Espressif
111#define OPT_MCU_ESP32S2 900
112#define OPT_MCU_ESP32S3 901
113
114// Dialog
115#define OPT_MCU_DA1469X 1000
116
117// Raspberry Pi
118#define OPT_MCU_RP2040 1100
119
120// NXP Kinetis
121#define OPT_MCU_KINETIS_KL 1200
122#define OPT_MCU_KINETIS_K32L 1201
123#define OPT_MCU_KINETIS_K32 1201
124
125#define OPT_MCU_MKL25ZXX 1200
126#define OPT_MCU_K32L2BXX 1201
127
128// Silabs
129#define OPT_MCU_EFM32GG 1300
130
131// Renesas RX
132#define OPT_MCU_RX63X 1400
133#define OPT_MCU_RX65X 1401
134#define OPT_MCU_RX72N 1402
135#define OPT_MCU_RAXXX 1403
136
137
138// Mind Motion
139#define OPT_MCU_MM32F327X 1500
140
141// GigaDevice
142#define OPT_MCU_GD32VF103 1600
143
144// Broadcom
145#define OPT_MCU_BCM2711 1700
146#define OPT_MCU_BCM2835 1701
147#define OPT_MCU_BCM2837 1702
148
149// Infineon
150#define OPT_MCU_XMC4000 1800
151
152// PIC
153#define OPT_MCU_PIC32MZ 1900
154#define OPT_MCU_PIC32MM 1901
155#define OPT_MCU_PIC32MX 1902
156#define OPT_MCU_PIC32MK 1903
157#define OPT_MCU_PIC24 1910
158#define OPT_MCU_DSPIC33 1911
159
160// BridgeTek
161#define OPT_MCU_FT90X 2000
162#define OPT_MCU_FT93X 2001
163
164// Allwinner
165#define OPT_MCU_F1C100S 2100
166
167// WCH
168#define OPT_MCU_CH32V307 2200
169
170
171// NXP LPC MCX
172#define OPT_MCU_MCXN9 2300
173
174// Helper to check if configured MCU is one of listed
175// Apply _TU_CHECK_MCU with || as separator to list of input
176#define _TU_CHECK_MCU(_m) (CFG_TUSB_MCU == _m)
177#define TU_CHECK_MCU(...) (TU_ARGS_APPLY(_TU_CHECK_MCU, ||, __VA_ARGS__))
178
179//--------------------------------------------------------------------+
180// Supported OS
181//--------------------------------------------------------------------+
182
183#define OPT_OS_NONE 1
184#define OPT_OS_FREERTOS 2
185#define OPT_OS_MYNEWT 3
186#define OPT_OS_CUSTOM 4
187#define OPT_OS_PICO 5
188#define OPT_OS_RTTHREAD 6
189#define OPT_OS_RTX4 7
190
191// Allow to use command line to change the config name/location
192#ifdef CFG_TUSB_CONFIG_FILE
193 #include CFG_TUSB_CONFIG_FILE
194#else
195 #include "tusb_config.h"
196#endif
197
198#include "common/tusb_mcu.h"
199
200//--------------------------------------------------------------------
201// RootHub Mode Configuration
202// CFG_TUSB_RHPORTx_MODE contains operation mode and speed for that port
203//--------------------------------------------------------------------
204
205// Low byte is operational mode
206#define OPT_MODE_NONE 0x0000
207#define OPT_MODE_DEVICE 0x0001
208#define OPT_MODE_HOST 0x0002
209
210// High byte is max operational speed (corresponding to tusb_speed_t)
211#define OPT_MODE_DEFAULT_SPEED 0x0000
212#define OPT_MODE_LOW_SPEED 0x0100
213#define OPT_MODE_FULL_SPEED 0x0200
214#define OPT_MODE_HIGH_SPEED 0x0400
215#define OPT_MODE_SPEED_MASK 0xff00
216
217//------------- Roothub as Device -------------//
218
219#if defined(CFG_TUSB_RHPORT0_MODE) && ((CFG_TUSB_RHPORT0_MODE) & OPT_MODE_DEVICE)
220 #define TUD_RHPORT_MODE (CFG_TUSB_RHPORT0_MODE)
221 #define TUD_OPT_RHPORT 0
222#elif defined(CFG_TUSB_RHPORT1_MODE) && ((CFG_TUSB_RHPORT1_MODE) & OPT_MODE_DEVICE)
223 #define TUD_RHPORT_MODE (CFG_TUSB_RHPORT1_MODE)
224 #define TUD_OPT_RHPORT 1
225#else
226 #define TUD_RHPORT_MODE OPT_MODE_NONE
227#endif
228
229#ifndef CFG_TUD_ENABLED
230 // fallback to use CFG_TUSB_RHPORTx_MODE
231 #define CFG_TUD_ENABLED (TUD_RHPORT_MODE & OPT_MODE_DEVICE)
232#endif
233
234#ifndef CFG_TUD_MAX_SPEED
235 // fallback to use CFG_TUSB_RHPORTx_MODE
236 #define CFG_TUD_MAX_SPEED (TUD_RHPORT_MODE & OPT_MODE_SPEED_MASK)
237#endif
238
239// For backward compatible
240#define TUSB_OPT_DEVICE_ENABLED CFG_TUD_ENABLED
241
242// highspeed support indicator
243#define TUD_OPT_HIGH_SPEED (CFG_TUD_MAX_SPEED ? (CFG_TUD_MAX_SPEED & OPT_MODE_HIGH_SPEED) : TUP_RHPORT_HIGHSPEED)
244
245//------------- Roothub as Host -------------//
246
247#if defined(CFG_TUSB_RHPORT0_MODE) && ((CFG_TUSB_RHPORT0_MODE) & OPT_MODE_HOST)
248 #define TUH_RHPORT_MODE (CFG_TUSB_RHPORT0_MODE)
249 #define TUH_OPT_RHPORT 0
250#elif defined(CFG_TUSB_RHPORT1_MODE) && ((CFG_TUSB_RHPORT1_MODE) & OPT_MODE_HOST)
251 #define TUH_RHPORT_MODE (CFG_TUSB_RHPORT1_MODE)
252 #define TUH_OPT_RHPORT 1
253#else
254 #define TUH_RHPORT_MODE OPT_MODE_NONE
255#endif
256
257#ifndef CFG_TUH_ENABLED
258 // fallback to use CFG_TUSB_RHPORTx_MODE
259 #define CFG_TUH_ENABLED (TUH_RHPORT_MODE & OPT_MODE_HOST)
260#endif
261
262#ifndef CFG_TUH_MAX_SPEED
263 // fallback to use CFG_TUSB_RHPORTx_MODE
264 #define CFG_TUH_MAX_SPEED (TUH_RHPORT_MODE & OPT_MODE_SPEED_MASK)
265#endif
266
267// For backward compatible
268#define TUSB_OPT_HOST_ENABLED CFG_TUH_ENABLED
269
270// highspeed support indicator
271#define TUH_OPT_HIGH_SPEED (CFG_TUH_MAX_SPEED ? (CFG_TUH_MAX_SPEED & OPT_MODE_HIGH_SPEED) : TUP_RHPORT_HIGHSPEED)
272
273
274//--------------------------------------------------------------------+
275// TODO move later
276//--------------------------------------------------------------------+
277
278// TUP_MCU_STRICT_ALIGN will overwrite TUP_ARCH_STRICT_ALIGN.
279// In case TUP_MCU_STRICT_ALIGN = 1 and TUP_ARCH_STRICT_ALIGN =0, we will not reply on compiler
280// to generate unaligned access code.
281// LPC_IP3511 Highspeed cannot access unaligned memory on USB_RAM
282#if TUD_OPT_HIGH_SPEED && TU_CHECK_MCU(OPT_MCU_LPC54XXX, OPT_MCU_LPC55XX)
283 #define TUP_MCU_STRICT_ALIGN 1
284#else
285 #define TUP_MCU_STRICT_ALIGN 0
286#endif
287
288
289//--------------------------------------------------------------------+
290// Common Options (Default)
291//--------------------------------------------------------------------+
292
293// Debug enable to print out error message
294#ifndef CFG_TUSB_DEBUG
295 #define CFG_TUSB_DEBUG 0
296#endif
297
298// Memory section for placing buffer used for usb transferring. If MEM_SECTION is different for
299// host and device use: CFG_TUD_MEM_SECTION, CFG_TUH_MEM_SECTION instead
300#ifndef CFG_TUSB_MEM_SECTION
301 #define CFG_TUSB_MEM_SECTION
302#endif
303
304// Alignment requirement of buffer used for usb transferring. if MEM_ALIGN is different for
305// host and device controller use: CFG_TUD_MEM_ALIGN, CFG_TUH_MEM_ALIGN instead
306#ifndef CFG_TUSB_MEM_ALIGN
307 #define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
308#endif
309
310// OS selection
311#ifndef CFG_TUSB_OS
312 #define CFG_TUSB_OS OPT_OS_NONE
313#endif
314
315#ifndef CFG_TUSB_OS_INC_PATH
316 #define CFG_TUSB_OS_INC_PATH
317#endif
318
319//--------------------------------------------------------------------
320// Device Options (Default)
321//--------------------------------------------------------------------
322
323// Attribute to place data in accessible RAM for device controller (default: CFG_TUSB_MEM_SECTION)
324#ifndef CFG_TUD_MEM_SECTION
325 #define CFG_TUD_MEM_SECTION CFG_TUSB_MEM_SECTION
326#endif
327
328// Attribute to align memory for device controller (default: CFG_TUSB_MEM_ALIGN)
329#ifndef CFG_TUD_MEM_ALIGN
330 #define CFG_TUD_MEM_ALIGN CFG_TUSB_MEM_ALIGN
331#endif
332
333#ifndef CFG_TUD_ENDPOINT0_SIZE
334 #define CFG_TUD_ENDPOINT0_SIZE 64
335#endif
336
337#ifndef CFG_TUD_INTERFACE_MAX
338 #define CFG_TUD_INTERFACE_MAX 16
339#endif
340
341#ifndef CFG_TUD_CDC
342 #define CFG_TUD_CDC 0
343#endif
344
345#ifndef CFG_TUD_MSC
346 #define CFG_TUD_MSC 0
347#endif
348
349#ifndef CFG_TUD_HID
350 #define CFG_TUD_HID 0
351#endif
352
353#ifndef CFG_TUD_AUDIO
354 #define CFG_TUD_AUDIO 0
355#endif
356
357#ifndef CFG_TUD_VIDEO
358 #define CFG_TUD_VIDEO 0
359#endif
360
361#ifndef CFG_TUD_MIDI
362 #define CFG_TUD_MIDI 0
363#endif
364
365#ifndef CFG_TUD_VENDOR
366 #define CFG_TUD_VENDOR 0
367#endif
368
369#ifndef CFG_TUD_USBTMC
370 #define CFG_TUD_USBTMC 0
371#endif
372
373#ifndef CFG_TUD_DFU_RUNTIME
374 #define CFG_TUD_DFU_RUNTIME 0
375#endif
376
377#ifndef CFG_TUD_DFU
378 #define CFG_TUD_DFU 0
379#endif
380
381#ifndef CFG_TUD_BTH
382 #define CFG_TUD_BTH 0
383#endif
384
385#ifndef CFG_TUD_ECM_RNDIS
386 #ifdef CFG_TUD_NET
387 #warning "CFG_TUD_NET is renamed to CFG_TUD_ECM_RNDIS"
388 #define CFG_TUD_ECM_RNDIS CFG_TUD_NET
389 #else
390 #define CFG_TUD_ECM_RNDIS 0
391 #endif
392#endif
393
394#ifndef CFG_TUD_NCM
395 #define CFG_TUD_NCM 0
396#endif
397
398//--------------------------------------------------------------------
399// Host Options (Default)
400//--------------------------------------------------------------------
401#if CFG_TUH_ENABLED
402 #ifndef CFG_TUH_DEVICE_MAX
403 #define CFG_TUH_DEVICE_MAX 1
404 #endif
405
406 #ifndef CFG_TUH_ENUMERATION_BUFSIZE
407 #define CFG_TUH_ENUMERATION_BUFSIZE 256
408 #endif
409#endif // CFG_TUH_ENABLED
410
411// Attribute to place data in accessible RAM for host controller (default: CFG_TUSB_MEM_SECTION)
412#ifndef CFG_TUH_MEM_SECTION
413 #define CFG_TUH_MEM_SECTION CFG_TUSB_MEM_SECTION
414#endif
415
416// Attribute to align memory for host controller
417#ifndef CFG_TUH_MEM_ALIGN
418 #define CFG_TUH_MEM_ALIGN CFG_TUSB_MEM_ALIGN
419#endif
420
421//------------- CLASS -------------//
422
423#ifndef CFG_TUH_HUB
424#define CFG_TUH_HUB 0
425#endif
426
427#ifndef CFG_TUH_CDC
428#define CFG_TUH_CDC 0
429#endif
430
431#ifndef CFG_TUH_CDC_FTDI
432 // FTDI is not part of CDC class, only to re-use CDC driver API
433 #define CFG_TUH_CDC_FTDI 0
434#endif
435
436#ifndef CFG_TUH_CDC_CP210X
437 // CP210X is not part of CDC class, only to re-use CDC driver API
438 #define CFG_TUH_CDC_CP210X 0
439#endif
440
441#ifndef CFG_TUH_HID
442#define CFG_TUH_HID 0
443#endif
444
445#ifndef CFG_TUH_MIDI
446#define CFG_TUH_MIDI 0
447#endif
448
449#ifndef CFG_TUH_MSC
450#define CFG_TUH_MSC 0
451#endif
452
453#ifndef CFG_TUH_VENDOR
454#define CFG_TUH_VENDOR 0
455#endif
456
457#ifndef CFG_TUH_API_EDPT_XFER
458#define CFG_TUH_API_EDPT_XFER 0
459#endif
460
461// Enable PIO-USB software host controller
462#ifndef CFG_TUH_RPI_PIO_USB
463#define CFG_TUH_RPI_PIO_USB 0
464#endif
465
466#ifndef CFG_TUD_RPI_PIO_USB
467#define CFG_TUD_RPI_PIO_USB 0
468#endif
469
470
471//--------------------------------------------------------------------+
472// TypeC Options (Default)
473//--------------------------------------------------------------------+
474
475#ifndef CFG_TUC_ENABLED
476#define CFG_TUC_ENABLED 0
477
478#define tuc_int_handler(_p)
479#endif
480
481//------------------------------------------------------------------
482// Configuration Validation
483//------------------------------------------------------------------
484#if CFG_TUD_ENDPOINT0_SIZE > 64
485 #error Control Endpoint Max Packet Size cannot be larger than 64
486#endif
487
488// To avoid GCC compiler warnings when -pedantic option is used (strict ISO C)
489typedef int make_iso_compilers_happy;
490
491#endif /* _TUSB_OPTION_H_ */
492