tusb_config.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. */
  25. #ifndef _TUSB_CONFIG_H_
  26. #define _TUSB_CONFIG_H_
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. //--------------------------------------------------------------------
  31. // COMMON CONFIGURATION
  32. //--------------------------------------------------------------------
  33. // defined by board.mk
  34. #ifndef CFG_TUSB_MCU
  35. #error CFG_TUSB_MCU must be defined
  36. #endif
  37. // RHPort number used for device can be defined by board.mk, default to port 0
  38. #ifndef BOARD_DEVICE_RHPORT_NUM
  39. #define BOARD_DEVICE_RHPORT_NUM 0
  40. #endif
  41. // RHPort max operational speed can defined by board.mk
  42. // Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
  43. #ifndef BOARD_DEVICE_RHPORT_SPEED
  44. #if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
  45. CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56 || \
  46. CFG_TUSB_MCU == OPT_MCU_FT90X || CFG_TUSB_MCU == OPT_MCU_FT93X)
  47. #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
  48. #else
  49. #define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
  50. #endif
  51. #endif
  52. // Device mode with rhport and speed defined by board.mk
  53. #if BOARD_DEVICE_RHPORT_NUM == 0
  54. #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
  55. #elif BOARD_DEVICE_RHPORT_NUM == 1
  56. #define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
  57. #else
  58. #error "Incorrect RHPort configuration"
  59. #endif
  60. #ifndef CFG_TUSB_OS
  61. #define CFG_TUSB_OS OPT_OS_NONE
  62. #endif
  63. // CFG_TUSB_DEBUG is defined by compiler in DEBUG build
  64. // #define CFG_TUSB_DEBUG 0
  65. /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
  66. * Tinyusb use follows macros to declare transferring memory so that they can be put
  67. * into those specific section.
  68. * e.g
  69. * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") ))
  70. * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4)))
  71. */
  72. #ifndef CFG_TUSB_MEM_SECTION
  73. #define CFG_TUSB_MEM_SECTION
  74. #endif
  75. #ifndef CFG_TUSB_MEM_ALIGN
  76. #define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
  77. #endif
  78. //--------------------------------------------------------------------
  79. // DEVICE CONFIGURATION
  80. //--------------------------------------------------------------------
  81. #ifndef CFG_TUD_ENDPOINT0_SIZE
  82. #define CFG_TUD_ENDPOINT0_SIZE 64
  83. #endif
  84. //------------- CLASS -------------//
  85. #define CFG_TUD_HID 2
  86. #define CFG_TUD_CDC 0
  87. #define CFG_TUD_MSC 0
  88. #define CFG_TUD_MIDI 0
  89. #define CFG_TUD_VENDOR 0
  90. // HID buffer size Should be sufficient to hold ID (if any) + Data
  91. #define CFG_TUD_HID_EP_BUFSIZE 8
  92. #ifdef __cplusplus
  93. }
  94. #endif
  95. #endif /* _TUSB_CONFIG_H_ */