tusb_config.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. // Board Specific Configuration
  32. //--------------------------------------------------------------------+
  33. // RHPort number used for device can be defined by board.mk, default to port 0
  34. #ifndef BOARD_TUD_RHPORT
  35. #define BOARD_TUD_RHPORT 0
  36. #endif
  37. // RHPort max operational speed can defined by board.mk
  38. #ifndef BOARD_TUD_MAX_SPEED
  39. #define BOARD_TUD_MAX_SPEED OPT_MODE_DEFAULT_SPEED
  40. #endif
  41. //--------------------------------------------------------------------
  42. // COMMON CONFIGURATION
  43. //--------------------------------------------------------------------
  44. // defined by compiler flags for flexibility
  45. #ifndef CFG_TUSB_MCU
  46. #error CFG_TUSB_MCU must be defined
  47. #endif
  48. #ifndef CFG_TUSB_OS
  49. #define CFG_TUSB_OS OPT_OS_NONE
  50. #endif
  51. #ifndef CFG_TUSB_DEBUG
  52. #define CFG_TUSB_DEBUG 0
  53. #endif
  54. // Enable Device stack
  55. #define CFG_TUD_ENABLED 1
  56. // Default is max speed that hardware controller could support with on-chip PHY
  57. #define CFG_TUD_MAX_SPEED BOARD_TUD_MAX_SPEED
  58. /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
  59. * Tinyusb use follows macros to declare transferring memory so that they can be put
  60. * into those specific section.
  61. * e.g
  62. * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") ))
  63. * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4)))
  64. */
  65. #ifndef CFG_TUSB_MEM_SECTION
  66. #define CFG_TUSB_MEM_SECTION
  67. #endif
  68. #ifndef CFG_TUSB_MEM_ALIGN
  69. #define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
  70. #endif
  71. //--------------------------------------------------------------------
  72. // DEVICE CONFIGURATION
  73. //--------------------------------------------------------------------
  74. #ifndef CFG_TUD_ENDPOINT0_SIZE
  75. #define CFG_TUD_ENDPOINT0_SIZE 64
  76. #endif
  77. //------------- CLASS -------------//
  78. #define CFG_TUD_AUDIO 1
  79. #define CFG_TUD_CDC 0
  80. #define CFG_TUD_MSC 0
  81. #define CFG_TUD_HID 0
  82. #define CFG_TUD_MIDI 0
  83. #define CFG_TUD_VENDOR 0
  84. //--------------------------------------------------------------------
  85. // AUDIO CLASS DRIVER CONFIGURATION
  86. //--------------------------------------------------------------------
  87. // Have a look into audio_device.h for all configurations
  88. #define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_MIC_FOUR_CH_DESC_LEN
  89. #define CFG_TUD_AUDIO_FUNC_1_N_AS_INT 1
  90. #define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64
  91. #define CFG_TUD_AUDIO_ENABLE_EP_IN 1
  92. #define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX 2 // This value is not required by the driver, it parses this information from the descriptor once the alternate interface is set by the host - we use it for the setup
  93. #define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 4 // This value is not required by the driver, it parses this information from the descriptor once the alternate interface is set by the host - we use it for the setup
  94. #define CFG_TUD_AUDIO_EP_SZ_IN (48 + 1) * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX // 48 Samples (48 kHz) x 2 Bytes/Sample x CFG_TUD_AUDIO_N_CHANNELS_TX Channels - the Windows driver always needs an extra sample per channel of space more, otherwise it complains... found by trial and error
  95. #define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX CFG_TUD_AUDIO_EP_SZ_IN
  96. #define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ CFG_TUD_AUDIO_EP_SZ_IN
  97. #define CFG_TUD_AUDIO_ENABLE_ENCODING 1
  98. #define CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING 1
  99. #define CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX 2 // One I2S stream contains two channels, each stream is saved within one support FIFO - this value is currently fixed, the driver does not support a changing value
  100. #define CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO (CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX / CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX)
  101. #define CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ (CFG_TUD_AUDIO_EP_SZ_IN / CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO)
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif /* _TUSB_CONFIG_H_ */