usbd_conf.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*!
  2. \file usbd_conf.h
  3. \brief the header file of USB device configuration
  4. \version 2023-06-30, V2.1.6, firmware for GD32F30x
  5. */
  6. /*
  7. Copyright (c) 2023, GigaDevice Semiconductor Inc.
  8. Redistribution and use in source and binary forms, with or without modification,
  9. are permitted provided that the following conditions are met:
  10. 1. Redistributions of source code must retain the above copyright notice, this
  11. list of conditions and the following disclaimer.
  12. 2. Redistributions in binary form must reproduce the above copyright notice,
  13. this list of conditions and the following disclaimer in the documentation
  14. and/or other materials provided with the distribution.
  15. 3. Neither the name of the copyright holder nor the names of its contributors
  16. may be used to endorse or promote products derived from this software without
  17. specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  21. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  26. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  27. OF SUCH DAMAGE.
  28. */
  29. #ifndef __USBD_CONF_H
  30. #define __USBD_CONF_H
  31. #include "usb_conf.h"
  32. /* USB configure exported defines */
  33. #define USBD_CFG_MAX_NUM 1U
  34. #define USBD_ITF_MAX_NUM 2U
  35. #define USBD_AD_INTERFACE 0U
  36. #define USB_STR_DESC_MAX_SIZE 255U
  37. /* Audio class layer parameter */
  38. #define AD_OUT_EP EP_OUT(3)
  39. #define AD_IN_EP EP_IN(1)
  40. #define AD_FEEDBACK_IN_EP EP_IN(2)
  41. #define USB_STRING_COUNT 4U
  42. /* micro-phone parameter */
  43. #define USBD_MIC_FREQ USBD_AD_FREQ_8K
  44. #define MIC_IN_BIT_RESOLUTION 16
  45. #define MIC_IN_CHANNEL_NBR 2 /* Mono = 1, Stereo = 2 */
  46. #define MIC_IN_PACKET (uint32_t)(((USBD_MIC_FREQ * \
  47. (MIC_IN_BIT_RESOLUTION/8) *\
  48. MIC_IN_CHANNEL_NBR) /1000))
  49. /* speaker parameter */
  50. #define USBD_SPEAKER_FREQ USBD_AD_FREQ_16K
  51. #define SPEAKER_OUT_BIT_RESOLUTION 16
  52. #define SPEAKER_OUT_CHANNEL_NBR 2 /* Mono = 1, Stereo = 2 */
  53. #define SPEAKER_OUT_PACKET (uint32_t)(((USBD_SPEAKER_FREQ * \
  54. (SPEAKER_OUT_BIT_RESOLUTION/8) *\
  55. SPEAKER_OUT_CHANNEL_NBR) /1000))
  56. /* feedback parameter */
  57. #define FEEDBACK_FREQ_OFFSET (USBD_SPEAKER_FREQ/100)
  58. #define FEEDBACK_IN_PACKET 3
  59. #define FEEDBACK_IN_INTERVAL 5
  60. #define SPEAKER_OUT_MAX_PACKET (SPEAKER_OUT_PACKET + 20)
  61. /* audio frequency in Hz */
  62. #define USBD_AD_FREQ_48K 48000U
  63. #define USBD_AD_FREQ_44K 44100U
  64. #define USBD_AD_FREQ_22K 22000U
  65. #define USBD_AD_FREQ_16K 16000U
  66. #define USBD_AD_FREQ_8K 8000U
  67. #define DEFAULT_VOLUME 65U /* Default volume in % (Mute=0%, Max = 100%) in Logarithmic values.
  68. To get accurate volume variations, it is possible to use a logarithmic
  69. coversion table to convert from percentage to logarithmic law.
  70. In order to keep this example code simple, this conversion is not used.*/
  71. /*!
  72. \brief get the calculate value of i2s sample frequency
  73. \param[in] set_freq: setting sample frequence
  74. \param[out] none
  75. \retval i2s sample frequency
  76. \note Users need to calculate the actual sampling frequency
  77. of I2S module at different frequency points by themselves.
  78. */
  79. __STATIC_INLINE uint32_t I2S_ACTUAL_SAM_FREQ(uint32_t set_freq)
  80. {
  81. uint32_t actual_freq;
  82. switch(set_freq){
  83. case USBD_AD_FREQ_48K:
  84. actual_freq = 46800;
  85. break;
  86. case USBD_AD_FREQ_44K:
  87. actual_freq = 41600;
  88. break;
  89. case USBD_AD_FREQ_16K:
  90. actual_freq = 16300;
  91. break;
  92. case USBD_AD_FREQ_8K:
  93. actual_freq = 7900;
  94. break;
  95. default:
  96. actual_freq = set_freq;
  97. break;
  98. }
  99. return actual_freq;
  100. }
  101. #endif /* __USBD_CONF_H */