tusb_option.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. #ifndef _TUSB_OPTION_H_
  27. #define _TUSB_OPTION_H_
  28. // To avoid GCC compiler warnings when -pedantic option is used (strict ISO C)
  29. typedef int make_iso_compilers_happy;
  30. #include "common/tusb_compiler.h"
  31. #define TUSB_VERSION_MAJOR 0
  32. #define TUSB_VERSION_MINOR 13
  33. #define TUSB_VERSION_REVISION 0
  34. #define TUSB_VERSION_STRING TU_STRING(TUSB_VERSION_MAJOR) "." TU_STRING(TUSB_VERSION_MINOR) "." TU_STRING(TUSB_VERSION_REVISION)
  35. //--------------------------------------------------------------------+
  36. // Supported MCUs
  37. // CFG_TUSB_MCU must be defined to one of following value
  38. //--------------------------------------------------------------------+
  39. #define OPT_MCU_NONE 0
  40. // LPC
  41. #define OPT_MCU_LPC11UXX 1 ///< NXP LPC11Uxx
  42. #define OPT_MCU_LPC13XX 2 ///< NXP LPC13xx
  43. #define OPT_MCU_LPC15XX 3 ///< NXP LPC15xx
  44. #define OPT_MCU_LPC175X_6X 4 ///< NXP LPC175x, LPC176x
  45. #define OPT_MCU_LPC177X_8X 5 ///< NXP LPC177x, LPC178x
  46. #define OPT_MCU_LPC18XX 6 ///< NXP LPC18xx
  47. #define OPT_MCU_LPC40XX 7 ///< NXP LPC40xx
  48. #define OPT_MCU_LPC43XX 8 ///< NXP LPC43xx
  49. #define OPT_MCU_LPC51UXX 9 ///< NXP LPC51U6x
  50. #define OPT_MCU_LPC54XXX 10 ///< NXP LPC54xxx
  51. #define OPT_MCU_LPC55XX 11 ///< NXP LPC55xx
  52. // NRF
  53. #define OPT_MCU_NRF5X 100 ///< Nordic nRF5x series
  54. // SAM
  55. #define OPT_MCU_SAMD21 200 ///< MicroChip SAMD21
  56. #define OPT_MCU_SAMD51 201 ///< MicroChip SAMD51
  57. #define OPT_MCU_SAMG 202 ///< MicroChip SAMDG series
  58. #define OPT_MCU_SAME5X 203 ///< MicroChip SAM E5x
  59. #define OPT_MCU_SAMD11 204 ///< MicroChip SAMD11
  60. #define OPT_MCU_SAML22 205 ///< MicroChip SAML22
  61. #define OPT_MCU_SAML21 206 ///< MicroChip SAML21
  62. #define OPT_MCU_SAMX7X 207 ///< MicroChip SAME70, S70, V70, V71 family
  63. // STM32
  64. #define OPT_MCU_STM32F0 300 ///< ST F0
  65. #define OPT_MCU_STM32F1 301 ///< ST F1
  66. #define OPT_MCU_STM32F2 302 ///< ST F2
  67. #define OPT_MCU_STM32F3 303 ///< ST F3
  68. #define OPT_MCU_STM32F4 304 ///< ST F4
  69. #define OPT_MCU_STM32F7 305 ///< ST F7
  70. #define OPT_MCU_STM32H7 306 ///< ST H7
  71. #define OPT_MCU_STM32L1 308 ///< ST L1
  72. #define OPT_MCU_STM32L0 307 ///< ST L0
  73. #define OPT_MCU_STM32L4 309 ///< ST L4
  74. #define OPT_MCU_STM32G0 310 ///< ST G0
  75. #define OPT_MCU_STM32G4 311 ///< ST G4
  76. #define OPT_MCU_STM32WB 312 ///< ST WB
  77. // Sony
  78. #define OPT_MCU_CXD56 400 ///< SONY CXD56
  79. // TI
  80. #define OPT_MCU_MSP430x5xx 500 ///< TI MSP430x5xx
  81. #define OPT_MCU_MSP432E4 510 ///< TI MSP432E4xx
  82. #define OPT_MCU_TM4C123 511 ///< TI Tiva-C 123x
  83. #define OPT_MCU_TM4C129 512 ///< TI Tiva-C 129x
  84. // ValentyUSB eptri
  85. #define OPT_MCU_VALENTYUSB_EPTRI 600 ///< Fomu eptri config
  86. // NXP iMX RT
  87. #define OPT_MCU_MIMXRT 700 ///< NXP iMX RT Series
  88. #define OPT_MCU_MIMXRT10XX OPT_MCU_MIMXRT ///< RT10xx
  89. #define OPT_MCU_MIMXRT11XX OPT_MCU_MIMXRT ///< RT11xx
  90. // Nuvoton
  91. #define OPT_MCU_NUC121 800
  92. #define OPT_MCU_NUC126 801
  93. #define OPT_MCU_NUC120 802
  94. #define OPT_MCU_NUC505 803
  95. // Espressif
  96. #define OPT_MCU_ESP32S2 900 ///< Espressif ESP32-S2
  97. #define OPT_MCU_ESP32S3 901 ///< Espressif ESP32-S3
  98. // Dialog
  99. #define OPT_MCU_DA1469X 1000 ///< Dialog Semiconductor DA1469x
  100. // Raspberry Pi
  101. #define OPT_MCU_RP2040 1100 ///< Raspberry Pi RP2040
  102. // NXP Kinetis
  103. #define OPT_MCU_MKL25ZXX 1200 ///< NXP MKL25Zxx
  104. #define OPT_MCU_K32L2BXX 1201 ///< NXP K32L2Bxx
  105. // Silabs
  106. #define OPT_MCU_EFM32GG 1300 ///< Silabs EFM32GG
  107. // Renesas RX
  108. #define OPT_MCU_RX63X 1400 ///< Renesas RX63N/631
  109. #define OPT_MCU_RX65X 1401 ///< Renesas RX65N/RX651
  110. #define OPT_MCU_RX72N 1402 ///< Renesas RX72N
  111. // Mind Motion
  112. #define OPT_MCU_MM32F327X 1500 ///< Mind Motion MM32F327
  113. // GigaDevice
  114. #define OPT_MCU_GD32VF103 1600 ///< GigaDevice GD32VF103
  115. // Broadcom
  116. #define OPT_MCU_BCM2711 1700 ///< Broadcom BCM2711
  117. #define OPT_MCU_BCM2835 1701 ///< Broadcom BCM2835
  118. #define OPT_MCU_BCM2837 1702 ///< Broadcom BCM2837
  119. // Infineon
  120. #define OPT_MCU_XMC4000 1800 ///< Infineon XMC4000
  121. // PIC
  122. #define OPT_MCU_PIC32MZ 1900 ///< MicroChip PIC32MZ family
  123. // BridgeTek
  124. #define OPT_MCU_FT90X 2000 ///< BridgeTek FT90x
  125. #define OPT_MCU_FT93X 2001 ///< BridgeTek FT93x
  126. // Allwinner
  127. #define OPT_MCU_F1C100S 2100 ///< Allwinner F1C100s family
  128. // HPMicro
  129. #define OPT_MCU_HPM 9000 ///< HPMicro HPM6000
  130. // Helper to check if configured MCU is one of listed
  131. // Apply _TU_CHECK_MCU with || as separator to list of input
  132. #define _TU_CHECK_MCU(_m) (CFG_TUSB_MCU == _m)
  133. #define TU_CHECK_MCU(...) (TU_ARGS_APPLY(_TU_CHECK_MCU, ||, __VA_ARGS__))
  134. //--------------------------------------------------------------------+
  135. // Supported OS
  136. //--------------------------------------------------------------------+
  137. #define OPT_OS_NONE 1 ///< No RTOS
  138. #define OPT_OS_FREERTOS 2 ///< FreeRTOS
  139. #define OPT_OS_MYNEWT 3 ///< Mynewt OS
  140. #define OPT_OS_CUSTOM 4 ///< Custom OS is implemented by application
  141. #define OPT_OS_PICO 5 ///< Raspberry Pi Pico SDK
  142. #define OPT_OS_RTTHREAD 6 ///< RT-Thread
  143. #define OPT_OS_RTX4 7 ///< Keil RTX 4
  144. // Allow to use command line to change the config name/location
  145. #ifdef CFG_TUSB_CONFIG_FILE
  146. #include CFG_TUSB_CONFIG_FILE
  147. #else
  148. #include "tusb_config.h"
  149. #endif
  150. #include "common/tusb_mcu.h"
  151. //--------------------------------------------------------------------
  152. // RootHub Mode Configuration
  153. // CFG_TUSB_RHPORTx_MODE contains operation mode and speed for that port
  154. //--------------------------------------------------------------------
  155. // Low byte is operational mode
  156. #define OPT_MODE_NONE 0x0000 ///< Disabled
  157. #define OPT_MODE_DEVICE 0x0001 ///< Device Mode
  158. #define OPT_MODE_HOST 0x0002 ///< Host Mode
  159. // High byte is max operational speed (corresponding to tusb_speed_t)
  160. #define OPT_MODE_DEFAULT_SPEED 0x0000 ///< Default (max) speed supported by MCU
  161. #define OPT_MODE_LOW_SPEED 0x0100 ///< Low Speed
  162. #define OPT_MODE_FULL_SPEED 0x0200 ///< Full Speed
  163. #define OPT_MODE_HIGH_SPEED 0x0400 ///< High Speed
  164. #define OPT_MODE_SPEED_MASK 0xff00
  165. //------------- Roothub as Device -------------//
  166. #if defined(CFG_TUSB_RHPORT0_MODE) && ((CFG_TUSB_RHPORT0_MODE) & OPT_MODE_DEVICE)
  167. #define TUD_RHPORT_MODE (CFG_TUSB_RHPORT0_MODE)
  168. #define TUD_OPT_RHPORT 0
  169. #elif defined(CFG_TUSB_RHPORT1_MODE) && ((CFG_TUSB_RHPORT1_MODE) & OPT_MODE_DEVICE)
  170. #define TUD_RHPORT_MODE (CFG_TUSB_RHPORT1_MODE)
  171. #define TUD_OPT_RHPORT 1
  172. #else
  173. #define TUD_RHPORT_MODE OPT_MODE_NONE
  174. #endif
  175. #ifndef CFG_TUD_ENABLED
  176. // fallback to use CFG_TUSB_RHPORTx_MODE
  177. #define CFG_TUD_ENABLED (TUD_RHPORT_MODE & OPT_MODE_DEVICE)
  178. #endif
  179. #ifndef CFG_TUD_MAX_SPEED
  180. // fallback to use CFG_TUSB_RHPORTx_MODE
  181. #define CFG_TUD_MAX_SPEED (TUD_RHPORT_MODE & OPT_MODE_SPEED_MASK)
  182. #endif
  183. // For backward compatible
  184. #define TUSB_OPT_DEVICE_ENABLED CFG_TUD_ENABLED
  185. // highspeed support indicator
  186. #define TUD_OPT_HIGH_SPEED (CFG_TUD_MAX_SPEED ? CFG_TUD_MAX_SPEED : TUP_RHPORT_HIGHSPEED)
  187. //------------- Roothub as Host -------------//
  188. #if defined(CFG_TUSB_RHPORT0_MODE) && ((CFG_TUSB_RHPORT0_MODE) & OPT_MODE_HOST)
  189. #define TUH_RHPORT_MODE (CFG_TUSB_RHPORT0_MODE)
  190. #define TUH_OPT_RHPORT 0
  191. #elif defined(CFG_TUSB_RHPORT1_MODE) && ((CFG_TUSB_RHPORT1_MODE) & OPT_MODE_HOST)
  192. #define TUH_RHPORT_MODE (CFG_TUSB_RHPORT1_MODE)
  193. #define TUH_OPT_RHPORT 1
  194. #else
  195. #define TUH_RHPORT_MODE OPT_MODE_NONE
  196. #endif
  197. #ifndef CFG_TUH_ENABLED
  198. // fallback to use CFG_TUSB_RHPORTx_MODE
  199. #define CFG_TUH_ENABLED (TUH_RHPORT_MODE & OPT_MODE_HOST)
  200. #endif
  201. #ifndef CFG_TUH_MAX_SPEED
  202. // fallback to use CFG_TUSB_RHPORTx_MODE
  203. #define CFG_TUH_MAX_SPEED (TUH_RHPORT_MODE & OPT_MODE_SPEED_MASK)
  204. #endif
  205. // For backward compatible
  206. #define TUSB_OPT_HOST_ENABLED CFG_TUH_ENABLED
  207. //--------------------------------------------------------------------+
  208. // TODO move later
  209. //--------------------------------------------------------------------+
  210. // TUP_MCU_STRICT_ALIGN will overwrite TUP_ARCH_STRICT_ALIGN.
  211. // In case TUP_MCU_STRICT_ALIGN = 1 and TUP_ARCH_STRICT_ALIGN =0, we will not reply on compiler
  212. // to generate unaligned access code.
  213. // LPC_IP3511 Highspeed cannot access unaligned memory on USB_RAM
  214. #if TUD_OPT_HIGH_SPEED && (CFG_TUSB_MCU == OPT_MCU_LPC54XXX || CFG_TUSB_MCU == OPT_MCU_LPC55XX)
  215. #define TUP_MCU_STRICT_ALIGN 1
  216. #else
  217. #define TUP_MCU_STRICT_ALIGN 0
  218. #endif
  219. //--------------------------------------------------------------------+
  220. // Common Options (Default)
  221. //--------------------------------------------------------------------+
  222. // Debug enable to print out error message
  223. #ifndef CFG_TUSB_DEBUG
  224. #define CFG_TUSB_DEBUG 0
  225. #endif
  226. // place data in accessible RAM for usb controller
  227. #ifndef CFG_TUSB_MEM_SECTION
  228. #define CFG_TUSB_MEM_SECTION
  229. #endif
  230. // alignment requirement of buffer used for endpoint transferring
  231. #ifndef CFG_TUSB_MEM_ALIGN
  232. #define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
  233. #endif
  234. // OS selection
  235. #ifndef CFG_TUSB_OS
  236. #define CFG_TUSB_OS OPT_OS_NONE
  237. #endif
  238. #ifndef CFG_TUSB_OS_INC_PATH
  239. #define CFG_TUSB_OS_INC_PATH
  240. #endif
  241. // mutex is only needed for RTOS TODO also required with multiple core MCUs
  242. #define TUSB_OPT_MUTEX (CFG_TUSB_OS != OPT_OS_NONE)
  243. //--------------------------------------------------------------------
  244. // Device Options (Default)
  245. //--------------------------------------------------------------------
  246. #ifndef CFG_TUD_ENDPOINT0_SIZE
  247. #define CFG_TUD_ENDPOINT0_SIZE 64
  248. #endif
  249. #ifndef CFG_TUD_INTERFACE_MAX
  250. #define CFG_TUD_INTERFACE_MAX 16
  251. #endif
  252. #ifndef CFG_TUD_CDC
  253. #define CFG_TUD_CDC 0
  254. #endif
  255. #ifndef CFG_TUD_MSC
  256. #define CFG_TUD_MSC 0
  257. #endif
  258. #ifndef CFG_TUD_HID
  259. #define CFG_TUD_HID 0
  260. #endif
  261. #ifndef CFG_TUD_AUDIO
  262. #define CFG_TUD_AUDIO 0
  263. #endif
  264. #ifndef CFG_TUD_VIDEO
  265. #define CFG_TUD_VIDEO 0
  266. #endif
  267. #ifndef CFG_TUD_MIDI
  268. #define CFG_TUD_MIDI 0
  269. #endif
  270. #ifndef CFG_TUD_VENDOR
  271. #define CFG_TUD_VENDOR 0
  272. #endif
  273. #ifndef CFG_TUD_USBTMC
  274. #define CFG_TUD_USBTMC 0
  275. #endif
  276. #ifndef CFG_TUD_DFU_RUNTIME
  277. #define CFG_TUD_DFU_RUNTIME 0
  278. #endif
  279. #ifndef CFG_TUD_DFU
  280. #define CFG_TUD_DFU 0
  281. #endif
  282. #ifndef CFG_TUD_BTH
  283. #define CFG_TUD_BTH 0
  284. #endif
  285. #ifndef CFG_TUD_ECM_RNDIS
  286. #ifdef CFG_TUD_NET
  287. #warning "CFG_TUD_NET is renamed to CFG_TUD_ECM_RNDIS"
  288. #define CFG_TUD_ECM_RNDIS CFG_TUD_NET
  289. #else
  290. #define CFG_TUD_ECM_RNDIS 0
  291. #endif
  292. #endif
  293. #ifndef CFG_TUD_NCM
  294. #define CFG_TUD_NCM 0
  295. #endif
  296. //--------------------------------------------------------------------
  297. // Host Options (Default)
  298. //--------------------------------------------------------------------
  299. #if CFG_TUH_ENABLED
  300. #ifndef CFG_TUH_DEVICE_MAX
  301. #define CFG_TUH_DEVICE_MAX 1
  302. #endif
  303. #ifndef CFG_TUH_ENUMERATION_BUFSIZE
  304. #define CFG_TUH_ENUMERATION_BUFSIZE 256
  305. #endif
  306. #endif // CFG_TUH_ENABLED
  307. //------------- CLASS -------------//
  308. #ifndef CFG_TUH_HUB
  309. #define CFG_TUH_HUB 0
  310. #endif
  311. #ifndef CFG_TUH_CDC
  312. #define CFG_TUH_CDC 0
  313. #endif
  314. #ifndef CFG_TUH_HID
  315. #define CFG_TUH_HID 0
  316. #endif
  317. #ifndef CFG_TUH_MIDI
  318. #define CFG_TUH_MIDI 0
  319. #endif
  320. #ifndef CFG_TUH_MSC
  321. #define CFG_TUH_MSC 0
  322. #endif
  323. #ifndef CFG_TUH_VENDOR
  324. #define CFG_TUH_VENDOR 0
  325. #endif
  326. #ifndef CFG_TUH_API_EDPT_XFER
  327. #define CFG_TUH_API_EDPT_XFER 0
  328. #endif
  329. // Enable PIO-USB software host controller
  330. #ifndef CFG_TUH_RPI_PIO_USB
  331. #define CFG_TUH_RPI_PIO_USB 0
  332. #endif
  333. #ifndef CFG_TUD_RPI_PIO_USB
  334. #define CFG_TUD_RPI_PIO_USB 0
  335. #endif
  336. //------------------------------------------------------------------
  337. // Configuration Validation
  338. //------------------------------------------------------------------
  339. #if CFG_TUD_ENDPOINT0_SIZE > 64
  340. #error Control Endpoint Max Packet Size cannot be larger than 64
  341. #endif
  342. #endif /* _TUSB_OPTION_H_ */
  343. /** @} */