HAL_I2S.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. ******************************************************************************
  3. * @file HAL_I2S.h
  4. * @version V1.0.0
  5. * @date 2020
  6. * @brief Header file of I2S HAL module.
  7. ******************************************************************************
  8. */
  9. #ifndef __HAL_I2S_H__
  10. #define __HAL_I2S_H__
  11. #include "ACM32Fxx_HAL.h"
  12. /************************************************************************************/
  13. /* Registers Bits Definition */
  14. /************************************************************************************/
  15. /**************** Bit definition for I2S CTL Register ***********************/
  16. #define I2S_CTL_I2SEN (BIT10)
  17. #define I2S_CTL_I2SOPMOD (BIT9|BIT8)
  18. #define I2S_CTL_PCMSMOD (BIT7)
  19. #define I2S_CTL_I2SSTD (BIT5|BIT4)
  20. #define I2S_CTL_CKPL (BIT3)
  21. #define I2S_CTL_DTLEN (BIT2|BIT1)
  22. #define I2S_CTL_CHLEN (BIT0)
  23. /**************** Bit definition for I2S PSC Register ***********************/
  24. #define I2S_PSC_MCKOEN (BIT10)
  25. #define I2S_PSC_OF (BIT9)
  26. #define I2S_PSC_DIV (0x1FF)
  27. /**************** Bit definition for I2S DIE Register ***********************/
  28. #define I2S_DIE_TBEIE (BIT7)
  29. #define I2S_DIE_RBNEIE (BIT6)
  30. #define I2S_DIE_ERRIE (BIT5)
  31. #define I2S_DIE_DMATEN (BIT1)
  32. #define I2S_DIE_DMAREN (BIT0)
  33. /**************** Bit definition for I2S STATUS Register ***********************/
  34. #define I2S_STATUS_FERR (BIT8)
  35. #define I2S_STATUS_TRANS (BIT7)
  36. #define I2S_STATUS_RXORERR (BIT6)
  37. #define I2S_STATUS_TXURERR (BIT3)
  38. #define I2S_STATUS_I2SCH (BIT2)
  39. #define I2S_STATUS_TXBE (BIT1)
  40. #define I2S_STATUS_RXBNE (BIT0)
  41. /** @defgroup I2S_Mode I2S Mode
  42. * @{
  43. */
  44. #define I2S_MODE_SLAVE_TX (0x00000000)
  45. #define I2S_MODE_SLAVE_RX (0x00000100)
  46. #define I2S_MODE_MASTER_TX (0x00000200)
  47. #define I2S_MODE_MASTER_RX (I2S_CTL_I2SOPMOD)
  48. /**
  49. * @}
  50. */
  51. /** @defgroup I2S_Standard I2S Standard
  52. * @{
  53. */
  54. #define I2S_STANDARD_PHILIPS (0x00000000U)
  55. #define I2S_STANDARD_MSB (0x00000010U)
  56. #define I2S_STANDARD_LSB (0x00000020U)
  57. #define I2S_STANDARD_PCM_SHORT (I2S_CTL_I2SSTD)
  58. #define I2S_STANDARD_PCM_LONG (I2S_CTL_I2SSTD | I2S_CTL_PCMSMOD)
  59. /**
  60. * @}
  61. */
  62. /** @defgroup I2S_Data_Format I2S Data Format
  63. * @{
  64. */
  65. #define I2S_DATAFORMAT_16B (0x00000000U)
  66. #define I2S_DATAFORMAT_16B_EXTENDED (I2S_CTL_CHLEN)
  67. #define I2S_DATAFORMAT_24B (I2S_CTL_CHLEN | 0x02)
  68. #define I2S_DATAFORMAT_32B (I2S_CTL_CHLEN | 0x04)
  69. /**
  70. * @}
  71. */
  72. /** @defgroup I2S_MCLK_Output I2S MCLK Output
  73. * @{
  74. */
  75. #define I2S_MCLKOUTPUT_ENABLE (I2S_PSC_MCKOEN)
  76. #define I2S_MCLKOUTPUT_DISABLE (0x00000000U)
  77. /**
  78. * @}
  79. */
  80. /** @defgroup I2S_Clock_Polarity I2S Clock Polarity
  81. * @{
  82. */
  83. #define I2S_CPOL_LOW (0x00000000U)
  84. #define I2S_CPOL_HIGH (I2S_CTL_CKPL)
  85. /**
  86. * @}
  87. */
  88. /** @defgroup I2S_Audio_FrequencyOF I2S Clock Frequency OF
  89. * @{
  90. */
  91. #define I2S_FREQ_OF_DISABLE (0x00000000U)
  92. #define I2S_FREQ_OF_ENABLE (I2S_PSC_OF)
  93. /**
  94. * @}
  95. */
  96. /**
  97. * @brief HAL State structures definition
  98. */
  99. typedef enum
  100. {
  101. HAL_I2S_STATE_RESET = 0x00U, /*!< I2S not yet initialized or disabled */
  102. HAL_I2S_STATE_READY = 0x01U, /*!< I2S initialized and ready for use */
  103. HAL_I2S_STATE_BUSY = 0x02U, /*!< I2S internal process is ongoing */
  104. HAL_I2S_STATE_BUSY_TX = 0x03U, /*!< Data Transmission process is ongoing */
  105. HAL_I2S_STATE_BUSY_RX = 0x04U, /*!< Data Reception process is ongoing */
  106. HAL_I2S_STATE_TIMEOUT = 0x06U, /*!< I2S timeout state */
  107. HAL_I2S_STATE_ERROR = 0x07U /*!< I2S error state */
  108. }enum_I2S_State;
  109. /**
  110. * @brief I2S Init structure definition
  111. */
  112. typedef struct
  113. {
  114. uint32_t u32_Mode; /*!< Specifies the I2S operating mode.
  115. This parameter can be a value of @ref I2S_Mode */
  116. uint32_t u32_Standard; /*!< Specifies the standard used for the I2S communication.
  117. This parameter can be a value of @ref I2S_Standard */
  118. uint32_t u32_DataFormat; /*!< Specifies the data format for the I2S communication.
  119. This parameter can be a value of @ref I2S_Data_Format */
  120. uint32_t u32_MCLKOutput; /*!< Specifies whether the I2S MCLK output is enabled or not.
  121. This parameter can be a value of @ref I2S_MCLK_Output */
  122. uint32_t u32_CPOL; /*!< Specifies the idle state of the I2S clock.
  123. This parameter can be a value of @ref I2S_Clock_Polarity */
  124. uint32_t u32_FreqOF; /*!< Specifies the frequency selected for the I2S communication.
  125. This parameter can be a value of @ref I2S_Audio_FrequencyFO */
  126. uint32_t u32_FreqDIV; /*!< Specifies the frequency selected for the I2S communication.
  127. This parameter must be a number between Min_Data = 0x001 and Max_Data = 0x1FF */
  128. }I2S_InitTypeDef;
  129. /**
  130. * @brief I2S handle Structure definition
  131. */
  132. typedef struct
  133. {
  134. I2S_TypeDef *Instance; /*!< I2S registers base address */
  135. I2S_InitTypeDef Init; /*!< I2S communication parameters */
  136. enum_I2S_State I2S_Status;
  137. uint32_t *u32_Rx_Buffer; /* I2S Rx Buffer */
  138. uint32_t *u32_Tx_Buffer; /* I2S Tx Buffer */
  139. uint32_t u32_Rx_Size; /* I2S Rx Size */
  140. uint32_t u32_Tx_Size; /* I2S Tx Size */
  141. uint32_t u32_Rx_Count; /* I2S RX Count */
  142. uint32_t u32_Tx_Count; /* I2S TX Count */
  143. DMA_HandleTypeDef *HDMA_Rx; /* SPI Rx DMA handle parameters */
  144. DMA_HandleTypeDef *HDMA_Tx; /* SPI Tx DMA handle parameters */
  145. }I2S_HandleTypeDef;
  146. /** @defgroup RTC Private Macros
  147. * @{
  148. */
  149. #define IS_I2S_MODE(__MODE__) (((__MODE__) == I2S_MODE_SLAVE_TX) || \
  150. ((__MODE__) == I2S_MODE_SLAVE_RX) || \
  151. ((__MODE__) == I2S_MODE_MASTER_TX) || \
  152. ((__MODE__) == I2S_MODE_MASTER_RX))
  153. #define IS_I2S_STANDARD(__STANDARD__) (((__STANDARD__) == I2S_STANDARD_PHILIPS) || \
  154. ((__STANDARD__) == I2S_STANDARD_MSB) || \
  155. ((__STANDARD__) == I2S_STANDARD_LSB) || \
  156. ((__STANDARD__) == I2S_STANDARD_PCM_SHORT) || \
  157. ((__STANDARD__) == I2S_STANDARD_PCM_LONG))
  158. #define IS_I2S_DATAFORMAT(__DATAFORMAT__) (((__DATAFORMAT__) == I2S_DATAFORMAT_16B) || \
  159. ((__DATAFORMAT__) == I2S_DATAFORMAT_16B_EXTENDED) || \
  160. ((__DATAFORMAT__) == I2S_DATAFORMAT_24B) || \
  161. ((__DATAFORMAT__) == I2S_DATAFORMAT_32B))
  162. #define IS_I2S_MCLK_OUTPUT(__MCLK_OUTPUT__) (((__MCLK_OUTPUT__) == I2S_MCLKOUTPUT_ENABLE) || \
  163. ((__MCLK_OUTPUT__) == I2S_MCLKOUTPUT_DISABLE))
  164. #define IS_I2S_MCLK_CPOL(__CPOL__) (((__CPOL__) == I2S_CPOL_LOW) || \
  165. ((__CPOL__) == I2S_CPOL_HIGH))
  166. #define IS_I2S_OF(__OF__) (((__OF__) == I2S_FREQ_OF_DISABLE) || \
  167. ((__OF__) == I2S_FREQ_OF_ENABLE))
  168. #define IS_I2S_DIV(__DIV__) ((__DIV__) >= 0x001 && (__DIV__) <= 0x1FF)
  169. /**
  170. * @}
  171. */
  172. /* HAL_I2S_IRQHandler */
  173. void HAL_I2S_IRQHandler(I2S_HandleTypeDef *hi2s);
  174. /* HAL_I2S_MspInit */
  175. void HAL_I2S_MspInit(I2S_HandleTypeDef *hspi);
  176. /* HAL_I2S_Init */
  177. HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s);
  178. /* HAL_I2S_Transmit */
  179. HAL_StatusTypeDef HAL_I2S_Transmit(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size, uint32_t fu32_Timeout);
  180. /* HAL_I2S_Receive */
  181. HAL_StatusTypeDef HAL_I2S_Receive(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size, uint32_t fu32_Timeout);
  182. /* HAL_I2S_Transmit_IT */
  183. HAL_StatusTypeDef HAL_I2S_Transmit_IT(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size);
  184. /* HAL_I2S_Receive_IT */
  185. HAL_StatusTypeDef HAL_I2S_Receive_IT(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size);
  186. /* HAL_I2S_Transmit_DMA */
  187. HAL_StatusTypeDef HAL_I2S_Transmit_DMA(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size);
  188. /* HAL_I2S_Receive_DMA */
  189. HAL_StatusTypeDef HAL_I2S_Receive_DMA(I2S_HandleTypeDef *hi2s, uint32_t *fp32_Data, uint32_t fu32_Size);
  190. #endif