hc32f460_i2s.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*******************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_i2s.h
  11. **
  12. ** A detailed description is available at
  13. ** @link I2sGroup Inter-IC Sound Bus description @endlink
  14. **
  15. ** - 2018-10-28 CDT First version for Device Driver Library of I2S.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_I2S_H__
  19. #define __HC32F460_I2S_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_I2S_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. ** \defgroup I2sGroup Inter-IC Sound(I2S)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /**
  41. *******************************************************************************
  42. ** \brief I2S function
  43. ******************************************************************************/
  44. typedef enum en_i2s_func
  45. {
  46. TxEn = 0u, ///< Transfer enable function
  47. TxIntEn = 1u, ///< Transfer interrupt enable function
  48. RxEn = 2u, ///< receive enable function
  49. RxIntEn = 3u, ///< receive interrupt enable function
  50. ErrIntEn = 4u, ///< error interrupt enable function
  51. }en_i2s_func_t;
  52. /**
  53. *******************************************************************************
  54. ** \brief I2S status flag
  55. ******************************************************************************/
  56. typedef enum en_i2s_std
  57. {
  58. TxBufAlarmFlag = 0u,
  59. RxBufAlarmFlag = 1u,
  60. TxBufEmptFlag = 2u,
  61. TxBufFullFlag = 3u,
  62. RxBufEmptFlag = 4u,
  63. RxBufFullFlag = 5u,
  64. }en_i2s_std_t;
  65. /**
  66. *******************************************************************************
  67. ** \brief I2S clr flag
  68. ******************************************************************************/
  69. typedef enum en_i2s_err_flag
  70. {
  71. ClrTxErrFlag = 0u,
  72. ClrRxErrFlag = 1u,
  73. }en_i2s_err_flag_t;
  74. /**
  75. *******************************************************************************
  76. ** \brief I2S mode
  77. ******************************************************************************/
  78. typedef enum en_i2s_mode
  79. {
  80. I2sMaster = 0u, ///< I2S Master mode
  81. I2sSlave = 1u, ///< I2S Slave mode
  82. }en_i2s_mode_t;
  83. /**
  84. *******************************************************************************
  85. ** \brief I2S full duplex mode
  86. ******************************************************************************/
  87. typedef enum en_i2s_full_duplex_mode
  88. {
  89. I2s_HalfDuplex = 0u, ///< I2S half duplex
  90. I2s_FullDuplex = 1u, ///< I2S full duplex
  91. }en_i2s_full_duplex_mode_t;
  92. /**
  93. *******************************************************************************
  94. ** \brief I2S standard
  95. ******************************************************************************/
  96. typedef enum en_i2s_standard
  97. {
  98. Std_Philips = 0u, ///< I2S Philips standard
  99. Std_MSBJust = 1u, ///< I2S MSB justified standart
  100. Std_LSBJust = 2u, ///< I2S LSB justified standart
  101. Std_PCM = 3u, ///< I2S PCM standart
  102. }en_i2s_standard_t;
  103. /**
  104. *******************************************************************************
  105. ** \brief I2S channel data length
  106. ******************************************************************************/
  107. typedef enum en_i2s_ch_len
  108. {
  109. I2s_ChLen_16Bit = 0u,
  110. I2s_ChLen_32Bit = 1u,
  111. }en_i2s_ch_len_t;
  112. /**
  113. *******************************************************************************
  114. ** \brief I2S data length
  115. ******************************************************************************/
  116. typedef enum en_i2s_data_len
  117. {
  118. I2s_DataLen_16Bit = 0u,
  119. I2s_DataLen_24Bit = 1u,
  120. I2s_DataLen_32Bit = 2u,
  121. }en_i2s_data_len_t;
  122. /**
  123. *******************************************************************************
  124. ** \brief I2S configuration structure
  125. ******************************************************************************/
  126. typedef struct stc_i2s_config
  127. {
  128. en_i2s_mode_t enMode; ///< I2S mode
  129. en_i2s_full_duplex_mode_t enFullDuplexMode; ///< I2S full duplex mode
  130. uint32_t u32I2sInterClkFreq; ///< I2S internal clock frequency
  131. en_i2s_standard_t enStandrad; ///< I2S standard
  132. en_i2s_data_len_t enDataBits; ///< I2S data format, data bits
  133. en_i2s_ch_len_t enChanelLen; ///< I2S channel length
  134. en_functional_state_t enMcoOutEn; ///< I2S MCK output config
  135. en_functional_state_t enExckEn; ///< I2S EXCK function config
  136. uint32_t u32AudioFreq; ///< I2S audio frequecy
  137. }stc_i2s_config_t;
  138. /*******************************************************************************
  139. * Global pre-processor symbols/macros ('#define')
  140. ******************************************************************************/
  141. /* define audio frequency */
  142. #define I2S_AudioFreq_192k (192000ul)
  143. #define I2S_AudioFreq_96k (96000ul)
  144. #define I2S_AudioFreq_48k (48000ul)
  145. #define I2S_AudioFreq_44k (44100ul)
  146. #define I2S_AudioFreq_32k (32000ul)
  147. #define I2S_AudioFreq_22k (22050ul)
  148. #define I2S_AudioFreq_16k (16000ul)
  149. #define I2S_AudioFreq_11k (11025ul)
  150. #define I2S_AudioFreq_8k (8000ul)
  151. #define I2S_AudioFreq_Default (2ul)
  152. /* if use external clock open this define */
  153. #define I2S_EXTERNAL_CLOCK_VAL (12288000ul)
  154. /* 0,1 or 2 config for tx or tx buffer interrupt warning level */
  155. #define RXBUF_IRQ_WL (1ul)
  156. #define TXBUF_IRQ_WL (1ul)
  157. /* 0: Short frame synchronization; 1: Long frame synchronization */
  158. #define PCM_SYNC_FRAME (0ul)
  159. /*******************************************************************************
  160. * Global variable definitions ('extern')
  161. ******************************************************************************/
  162. /*******************************************************************************
  163. Global function prototypes (definition in C source)
  164. ******************************************************************************/
  165. en_result_t I2s_Init(M4_I2S_TypeDef* pstcI2sReg, const stc_i2s_config_t* pstcI2sCfg);
  166. void I2S_SendData(M4_I2S_TypeDef* pstcI2sReg, uint32_t u32Data);
  167. uint32_t I2S_RevData(const M4_I2S_TypeDef* pstcI2sReg);
  168. void I2S_FuncCmd(M4_I2S_TypeDef* pstcI2sReg, en_i2s_func_t enFunc, en_functional_state_t enNewState);
  169. en_flag_status_t I2S_GetStatus(M4_I2S_TypeDef* pstcI2sReg, en_i2s_std_t enStd);
  170. en_flag_status_t I2S_GetErrFlag(M4_I2S_TypeDef* pstcI2sReg, en_i2s_err_flag_t enErrFlag);
  171. void I2S_ClrErrFlag(M4_I2S_TypeDef* pstcI2sReg, en_i2s_err_flag_t enErrFlag);
  172. en_result_t I2s_DeInit(M4_I2S_TypeDef* pstcI2sReg);
  173. //@} // I2sGroup
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #endif /* DDL_I2S_ENABLE */
  178. #endif /* __HC32F460_I2S_H__ */
  179. /*******************************************************************************
  180. * EOF (not truncated)
  181. ******************************************************************************/