gr55xx_hal_i2s.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file gr55xx_hal_i2s.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of I2S HAL library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2019 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  ****************************************************************************************
36  */
37 
38 /** @addtogroup PERIPHERAL Peripheral Driver
39  * @{
40  */
41 
42 /** @addtogroup HAL_DRIVER HAL Driver
43  * @{
44  */
45 
46 /** @defgroup HAL_I2S I2S
47  * @brief I2S HAL module driver.
48  * @{
49  */
50 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_I2S_H__
53 #define __GR55xx_HAL_I2S_H__
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_i2s.h"
61 #include "gr55xx_hal_def.h"
62 
63 /* Exported types ------------------------------------------------------------*/
64 /** @addtogroup HAL_I2S_ENUMERATIONS Enumerations
65  * @{
66  */
67 
68 /** @defgroup HAL_I2S_state HAL I2S state
69  * @{
70  */
71 
72 /**
73  * @brief HAL I2S State Enumerations definition
74  */
75 typedef enum
76 {
77  HAL_I2S_STATE_RESET = 0x00, /**< Peripheral not initialized */
78  HAL_I2S_STATE_READY = 0x01, /**< Peripheral initialized and ready for use */
79  HAL_I2S_STATE_BUSY = 0x02, /**< An internal process is ongoing */
80  HAL_I2S_STATE_BUSY_TX = 0x12, /**< Data Transmission process is ongoing */
81  HAL_I2S_STATE_BUSY_RX = 0x22, /**< Data Reception process is ongoing */
82  HAL_I2S_STATE_BUSY_TX_RX = 0x32, /**< Data Transmission and Reception process is ongoing */
83  HAL_I2S_STATE_ABORT = 0x08, /**< Peripheral with abort request ongoing */
84  HAL_I2S_STATE_ERROR = 0x04 /**< Peripheral in error */
85 
87 
88 /** @} */
89 
90 /** @} */
91 
92 /** @addtogroup HAL_I2S_STRUCTURES Structures
93  * @{
94  */
95 
96 /** @defgroup I2S_Configuration I2S Configuration
97  * @{
98  */
99 
100 /**
101  * @brief I2S init Structure definition
102  */
103 typedef struct _i2s_init
104 {
105  uint32_t data_size; /**< Specifies the data size for I2S communication.
106  This parameter can be a value of @ref I2S_Data_Size */
107 
108  uint32_t clock_source; /**< Specifies the source of the I2S clock.
109  This parameter can be a value of @ref I2S_Clock_Source */
110 
111  uint32_t ws_cycles; /**< Specifies the Word Select Line Cycles.
112  This parameter can be a value of @ref I2S_WS_CYCLES.*/
113 
114  uint32_t audio_freq; /**< Specifies the frequency selected for the I2S communication.
115  @note The communication clock is derived from the master
116  clock. The slave clock does not need to be set. */
117 #if I2S_CHANNEL_NUM > 1
118  uint32_t channel_active; /**< Specifies the active channels for I2S communication.
119  This parameter can be one or more value of @ref I2S_Channel */
120 #endif
121 
123 /** @} */
124 
125 /** @defgroup I2S_handle I2S handle
126  * @{
127  */
128 
129 /**
130  * @brief I2S handle Structure definition
131  */
132 typedef struct _i2s_handle
133 {
134  i2s_regs_t *p_instance; /**< I2S registers base address */
135 
136  i2s_init_t init; /**< I2S communication parameters */
137 
138  uint16_t *p_tx_buffer; /**< Pointer to I2S TX transfer Buffer */
139 
140  __IO uint32_t tx_xfer_size; /**< I2S TX Transfer size */
141 
142  __IO uint32_t tx_xfer_count; /**< I2S TX Transfer Counter */
143 
144  uint16_t *p_rx_buffer; /**< Pointer to I2S RX transfer Buffer */
145 
146  __IO uint32_t rx_xfer_size; /**< I2S RX Transfer size */
147 
148  __IO uint32_t rx_xfer_count; /**< I2S RX Transfer Counter */
149 
150  void (*write_fifo)(struct _i2s_handle *p_i2s); /**< Pointer to I2S Tx transfer FIFO write function */
151 
152  void (*read_fifo)(struct _i2s_handle *p_i2s); /**< Pointer to I2S Rx transfer FIFO read function */
153 
154  dma_handle_t *p_dmatx; /**< I2S TX DMA Handle parameters */
155 
156  dma_handle_t *p_dmarx; /**< I2S RX DMA Handle parameters */
157 
158  __IO hal_lock_t lock; /**< Locking object */
159 
160  __IO hal_i2s_state_t state; /**< I2S communication state */
161 
162  __IO uint32_t error_code; /**< I2S Error code */
163 
164  uint32_t timeout; /**< Timeout for the I2S memory access */
165 
166  uint32_t retention[7]; /**< I2S important register information. */
168 /** @} */
169 
170 /** @} */
171 
172 /** @addtogroup HAL_I2S_CALLBACK_STRUCTURES Callback Structures
173  * @{
174  */
175 
176 /** @defgroup HAL_I2S_Callback Callback
177  * @{
178  */
179 
180 /**
181  * @brief HAL_I2S Callback function definition
182  */
183 
184 typedef struct _i2s_callback
185 {
186  void (*i2s_msp_init)(i2s_handle_t *p_i2s); /**< I2S init MSP callback */
187  void (*i2s_msp_deinit)(i2s_handle_t *p_i2s); /**< I2S de-init MSP callback */
188  void (*i2s_error_callback)(i2s_handle_t *p_i2s); /**< I2S error callback */
189  void (*i2s_rx_cplt_callback)(i2s_handle_t *p_i2s); /**< I2S rx transfer completed callback */
190  void (*i2s_tx_cplt_callback)(i2s_handle_t *p_i2s); /**< I2S tx transfer completed callbac */
191  void (*i2s_tx_rx_cplt_callback)(i2s_handle_t *p_i2s); /**< I2S tx/rx transfer completed callback */
193 
194 /** @} */
195 
196 /** @} */
197 
198 /**
199  * @defgroup HAL_I2S_MACRO Defines
200  * @{
201  */
202 
203 /* Exported constants --------------------------------------------------------*/
204 /** @defgroup I2S_Exported_Constants I2S Exported Constants
205  * @{
206  */
207 
208 /** @defgroup I2S_Direction I2S Direction
209  * @{
210  */
211 #define I2S_DIRECTION_FULL_DUPLEX LL_I2S_FULL_DUPLEX /**< Full Duplex: Transmit & Receive */
212 #define I2S_DIRECTION_SIMPLEX_TX LL_I2S_SIMPLEX_TX /**< Simplex TX: Transmit only */
213 #define I2S_DIRECTION_SIMPLEX_RX LL_I2S_SIMPLEX_RX /**< Simplex RX: Receive only */
214 /** @} */
215 
216 /** @defgroup I2S_Error_Code I2S Error Code
217  * @{
218  */
219 #define HAL_I2S_ERROR_NONE ((uint32_t)0x00000000) /**< No error */
220 #define HAL_I2S_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */
221 #define HAL_I2S_ERROR_TRANSFER ((uint32_t)0x00000002) /**< Transfer error */
222 #define HAL_I2S_ERROR_DMA ((uint32_t)0x00000004) /**< DMA transfer error */
223 #define HAL_I2S_ERROR_INVALID_PARAM ((uint32_t)0x00000008) /**< Invalid parameters error */
224 /** @} */
225 
226 /** @defgroup I2S_Data_Size I2S Data Size
227  * @{
228  */
229 #define I2S_DATASIZE_12BIT LL_I2S_DATASIZE_12BIT /**< 12-bit serial data transfer */
230 #define I2S_DATASIZE_16BIT LL_I2S_DATASIZE_16BIT /**< 16-bit serial data transfer */
231 #define I2S_DATASIZE_20BIT LL_I2S_DATASIZE_20BIT /**< 20-bit serial data transfer */
232 #define I2S_DATASIZE_24BIT LL_I2S_DATASIZE_24BIT /**< 24-bit serial data transfer */
233 #define I2S_DATASIZE_32BIT LL_I2S_DATASIZE_32BIT /**< 32-bit serial data transfer */
234 /** @} */
235 
236 /** @defgroup I2S_Clock_Source I2S Clock Source
237  * @{
238  */
239 #define I2S_CLOCK_SRC_96M LL_I2S_CLOCK_SRC_96M /**< I2S clock source select: 96M */
240 #define I2S_CLOCK_SRC_64M LL_I2S_CLOCK_SRC_64M /**< I2S clock source select: 64M */
241 #define I2S_CLOCK_SRC_32M LL_I2S_CLOCK_SRC_32M /**< I2S clock source select: 32M */
242 /** @} */
243 
244 /** @defgroup I2S_WS_CYCLES I2S Word Select Line Cycles
245  * @{
246  */
247 #define I2S_WS_CYCLES_16 LL_I2S_WS_CYCLES_16 /**< 16 SCLK cycles in word select line. */
248 #define I2S_WS_CYCLES_24 LL_I2S_WS_CYCLES_24 /**< 24 SCLK cycles in word select line. */
249 #define I2S_WS_CYCLES_32 LL_I2S_WS_CYCLES_32 /**< 32 SCLK cycles in word select line. */
250 /** @} */
251 
252 /** @defgroup I2S_FIFO_LEVEL_MAX I2S FIFO Level Max
253  * @{
254  */
255 #define I2S_TX_FIFO_LEVEL_MAX 16 /**< I2S TX FIFO Level Max Value */
256 #define I2S_RX_FIFO_LEVEL_MAX 16 /**< I2S RX FIFO Level Max Value */
257 /** @} */
258 
259 /** @defgroup I2S_Flags_definition I2S Flags Definition
260  * @{
261  */
262 #define I2S_FLAG_TXFO LL_I2S_STATUS_TXFO /**< TX FIFO write overflow flag */
263 #define I2S_FLAG_TXFE LL_I2S_STATUS_TXFE /**< TX FIFO empty trigger flag */
264 #define I2S_FLAG_RXFO LL_I2S_STATUS_RXFO /**< RX FIFO receive overflow flag */
265 #define I2S_FLAG_RXDA LL_I2S_STATUS_RXDA /**< RX FIFO data available flag */
266 /** @} */
267 
268 /** @defgroup I2S_Interrupt_definition I2S Interrupt Definition
269  * @{
270  */
271 #define I2S_IT_TXFO LL_I2S_INT_TXFO /**< TX FIFO write overflow interrupt */
272 #define I2S_IT_TXFE LL_I2S_INT_TXFE /**< TX FIFO empty trigger interrupt */
273 #define I2S_IT_RXFO LL_I2S_INT_RXFO /**< RX FIFO receive overflow interrupt */
274 #define I2S_IT_RXDA LL_I2S_INT_RXDA /**< RX FIFO data available interrupt */
275 /** @} */
276 
277 /** @defgroup I2S_Timeout_definition I2S Timeout_definition
278  * @{
279  */
280 #define HAL_I2S_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000) /**< 5s */
281 /** @} */
282 
283 /** @} */
284 
285 /* Exported macro ------------------------------------------------------------*/
286 /** @defgroup I2S_Exported_Macros I2S Exported Macros
287  * @{
288  */
289 
290 /** @brief Reset I2S handle states.
291  * @param __HANDLE__ I2S handle.
292  * @retval None
293  */
294 #define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_I2S_STATE_RESET)
295 
296 /** @brief Enable the specified I2S peripheral.
297  * @param __HANDLE__ Specifies the I2S Handle.
298  * @retval None
299  */
300 #define __HAL_I2S_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->EN, I2S_EN_I2S_EN)
301 /** @brief Disable the specified I2S peripheral.
302  * @param __HANDLE__ Specifies the I2S Handle.
303  * @retval None
304  */
305 
306 #define __HAL_I2S_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->EN, I2S_EN_I2S_EN)
307 
308 /** @brief Enable the specified I2S clock.
309  * @param __HANDLE__ Specifies the I2S Handle.
310  * @retval None
311  */
312 
313 #if !defined (GR551xx)
314 #define __HAL_I2S_ENABLE_CLOCK(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CLK_EN, I2S_CLK_EN_CLK_EN)
315 #else
316 #define __HAL_I2S_ENABLE_CLOCK(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CLKEN, I2S_CLKEN_EN)
317 #endif
318 
319 /** @brief Disable the specified I2S clock.
320  * @param __HANDLE__ Specifies the I2S Handle.
321  * @retval None
322  */
323 
324 #if !defined (GR551xx)
325 #define __HAL_I2S_DISABLE_CLOCK(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CLK_EN, I2S_CLK_EN_CLK_EN)
326 #else
327 #define __HAL_I2S_DISABLE_CLOCK(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CLKEN, I2S_CLKEN_EN)
328 #endif
329 /** @brief Enable the specified I2S transmitter block.
330  * @param __HANDLE__ Specifies the I2S Handle.
331  * @retval None
332  */
333 #define __HAL_I2S_ENABLE_TX_BLOCK(__HANDLE__) ll_i2s_enable_txblock((__HANDLE__)->p_instance)
334 
335 /** @brief Disable the specified I2S transmitter block.
336  * @param __HANDLE__ Specifies the I2S Handle.
337  * @retval None
338  */
339 #define __HAL_I2S_DISABLE_TX_BLOCK(__HANDLE__) ll_i2s_disable_txblock((__HANDLE__)->p_instance)
340 
341 /** @brief Enable the specified I2S receiver block.
342  * @param __HANDLE__ Specifies the I2S Handle.
343  * @retval None
344  */
345 #define __HAL_I2S_ENABLE_RX_BLOCK(__HANDLE__) ll_i2s_enable_rxblock((__HANDLE__)->p_instance)
346 
347 /** @brief Disable the specified I2S receiver block.
348  * @param __HANDLE__ Specifies the I2S Handle.
349  * @retval None
350  */
351 #define __HAL_I2S_DISABLE_RX_BLOCK(__HANDLE__) ll_i2s_disable_rxblock((__HANDLE__)->p_instance)
352 
353 /** @brief Enable the specified I2S transmitter channel.
354  * @param __HANDLE__ Specifies the I2S Handle.
355  * @retval None
356  */
357 
358 #define __HAL_I2S_ENABLE_TX_CHANNEL(__HANDLE__) ll_i2s_enable_tx((__HANDLE__)->p_instance)
359 
360 /** @brief Disable the specified I2S transmitter channel.
361  * @param __HANDLE__ Specifies the I2S Handle.
362  * @retval None
363  */
364 
365 #define __HAL_I2S_DISABLE_TX_CHANNEL(__HANDLE__) ll_i2s_disable_tx((__HANDLE__)->p_instance)
366 
367 /** @brief Enable the specified I2S receiver channel.
368  * @param __HANDLE__ Specifies the I2S Handle.
369  * @retval None
370  */
371 
372 #define __HAL_I2S_ENABLE_RX_CHANNEL(__HANDLE__) ll_i2s_enable_rx((__HANDLE__)->p_instance)
373 
374 /** @brief Disable the specified I2S receiver channel.
375  * @param __HANDLE__ Specifies the I2S Handle.
376  * @retval None
377  */
378 
379 #define __HAL_I2S_DISABLE_RX_CHANNEL(__HANDLE__) ll_i2s_disable_rx((__HANDLE__)->p_instance)
380 
381 /** @brief Flush the I2S transmitter FIFO.
382  * @param __HANDLE__ Specifies the I2S Handle.
383  * @retval None
384  */
385 #define __HAL_I2S_FLUSH_TX_FIFO(__HANDLE__) ll_i2s_clr_txfifo_all((__HANDLE__)->p_instance)
386 
387 /** @brief Flush the I2S receiver FIFO.
388  * @param __HANDLE__ Specifies the I2S Handle.
389  * @retval None
390  */
391 #define __HAL_I2S_FLUSH_RX_FIFO(__HANDLE__) ll_i2s_clr_rxfifo_all((__HANDLE__)->p_instance)
392 
393 /** @brief Enable the I2S DMA Request.
394  * @param __HANDLE__ Specifies the I2S Handle.
395  * @retval None
396  */
397 #define __HAL_I2S_ENABLE_DMA(__HANDLE__) ll_i2s_enable_dma(__HANDLE__->p_instance)
398 
399 /** @brief Disable the I2S DMA Request.
400  * @param __HANDLE__ Specifies the I2S Handle.
401  * @retval None
402  */
403 #define __HAL_I2S_DISABLE_DMA(__HANDLE__) ll_i2s_disable_dma(__HANDLE__->p_instance)
404 
405 /** @brief Reset the I2S TX DMA request to the lowest enabled channel.
406  * @param __HANDLE__ Specifies the I2S Handle.
407  * @retval None
408  */
409 
410 #define __HAL_I2S_RESET_TXDMA(__HANDLE__) WRITE_REG((__HANDLE__)->p_instance->RST_TX_DMA, I2S_RST_TX_DMA_RST_TX_DMA)
411 
412 /** @brief Enable the I2S DMA mode.
413  * @param __HANDLE__ Specifies the I2S Handle.
414  * @retval None
415  */
416 #define __HAL_I2S_ENABLE_DMA_MODE(__HANDLE__) ll_i2s_enable_dma_mode(__HANDLE__->p_instance)
417 
418 /** @brief Disable the I2S DMA mode.
419  * @param __HANDLE__ Specifies the I2S Handle.
420  * @retval None
421  */
422 #define __HAL_I2S_DISABLE_DMA_MODE(__HANDLE__) ll_i2s_disable_dma_mode(__HANDLE__->p_instance)
423 
424 /** @brief Reset the I2S RX DMA request to the lowest enabled channel.
425  * @param __HANDLE__ Specifies the I2S Handle.
426  * @retval None
427  */
428 
429 #define __HAL_I2S_RESET_RXDMA(__HANDLE__) WRITE_REG((__HANDLE__)->p_instance->RST_RX_DMA, I2S_RST_RX_DMA_RST_RX_DMA)
430 
431 /** @brief Enable the specified I2S interrupts.
432  * @param __HANDLE__ Specifies the I2S Handle.
433  * @param __INTERRUPT__ Specifies the interrupt source to enable.
434  * This parameter can be one of the following values:
435  * @arg @ref I2S_IT_TXFO TX FIFO write overflow interrupt
436  * @arg @ref I2S_IT_TXFE TX FIFO empty trigger interrupt
437  * @arg @ref I2S_IT_RXFO RX FIFO receive overflow interrupt
438  * @arg @ref I2S_IT_RXDA RX FIFO data available interrupt
439  * @retval None
440  */
441 
442 #define __HAL_I2S_ENABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__))
443 
444 /** @brief Disable the specified I2S interrupts.
445  * @param __HANDLE__ Specifies the I2S handle.
446  * @param __INTERRUPT__ Specifies the interrupt source to disable.
447  * This parameter can be one of the following values:
448  * @arg @ref I2S_IT_TXFO TX FIFO write overflow interrupt
449  * @arg @ref I2S_IT_TXFE TX FIFO empty trigger interrupt
450  * @arg @ref I2S_IT_RXFO RX FIFO receive overflow interrupt
451  * @arg @ref I2S_IT_RXDA RX FIFO data available interrupt
452  * @retval None
453  */
454 
455 #define __HAL_I2S_DISABLE_IT(__HANDLE__, __INTERRUPT__) SET_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__))
456 
457 /** @brief Check whether the specified I2S flag is set or not.
458  * @param __HANDLE__ Specifies the I2S Handle.
459  * @param __FLAG__ Specifies the flag to check.
460  * This parameter can be one of the following values:
461  * @arg @ref I2S_FLAG_TXFO TX FIFO write overflow flag
462  * @arg @ref I2S_FLAG_TXFE TX FIFO empty trigger flag
463  * @arg @ref I2S_FLAG_RXFO RX FIFO receive overflow flag
464  * @arg @ref I2S_FLAG_RXDA RX FIFO data available flag
465  * @retval The new state of __FLAG__ (TRUE or FALSE).
466  */
467 
468 #define __HAL_I2S_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BITS((__HANDLE__)->p_instance->INT_STAT, (__FLAG__)) != 0) ? SET : RESET)
469 
470 /** @brief Clear the specified I2S flag.
471  * @param __HANDLE__ Specifies the I2S Handle.
472  * @param __FLAG__ Specifies the flag to check.
473  * This parameter can be one of the following values:
474  * @arg @ref I2S_FLAG_TXFO TX FIFO write overflow flag
475  * @arg @ref I2S_FLAG_RXFO RX FIFO receive overflow flag
476  * @retval None
477  */
478 
479 #define __HAL_I2S_CLEAR_FLAG(__HANDLE__, __FLAG__) do { \
480  if ((__FLAG__) & I2S_FLAG_RXFO) \
481  { \
482  READ_BITS((__HANDLE__)->p_instance->RX_OVER, I2S_RX_OVER_RX_CLR_FDO);\
483  } \
484  if ((__FLAG__) & I2S_FLAG_TXFO) \
485  { \
486  READ_BITS((__HANDLE__)->p_instance->TX_OVER, I2S_TX_OVER_TX_CLR_FDO);\
487  } \
488  } while(0);
489 
490 /** @} */
491 
492 /* Private macros ------------------------------------------------------------*/
493 /** @defgroup I2S_Private_Macro I2S Private Macros
494  * @{
495  */
496 
497 /** @brief Check if I2S Direction Mode is valid.
498  * @param __MODE__ I2S Direction Mode.
499  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
500  */
501 #define IS_I2S_DIRECTION(__MODE__) (((__MODE__) == I2S_DIRECTION_FULL_DUPLEX) || \
502  ((__MODE__) == I2S_DIRECTION_SIMPLEX_TX) || \
503  ((__MODE__) == I2S_DIRECTION_SIMPLEX_RX))
504 
505 /** @brief Check if I2S Data Size is valid.
506  * @param __DATASIZE__ I2S Data Size.
507  * @retval SET (__DATASIZE__ is valid) or RESET (__DATASIZE__ is invalid)
508  */
509 #define IS_I2S_DATASIZE(__DATASIZE__) (((__DATASIZE__) == I2S_DATASIZE_12BIT) || \
510  ((__DATASIZE__) == I2S_DATASIZE_16BIT) || \
511  ((__DATASIZE__) == I2S_DATASIZE_20BIT) || \
512  ((__DATASIZE__) == I2S_DATASIZE_24BIT) || \
513  ((__DATASIZE__) == I2S_DATASIZE_32BIT))
514 
515 /** @brief Check if I2S Clock Polarity is valid.
516  * @param __CPOL__ I2S Clock Polarity.
517  * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
518  */
519 #define IS_I2S_CPOL(__CPOL__) (((__CPOL__) == I2S_POLARITY_LOW) || \
520  ((__CPOL__) == I2S_POLARITY_HIGH))
521 
522 /** @brief Check if I2S Audio Frequency is valid.
523  * @param __FREQUENCY__ I2S Audio Frequency.
524  * @retval SET (__FREQUENCY__ is valid) or RESET (__FREQUENCY__ is invalid)
525  */
526 #define IS_I2S_AUDIO_FREQUENCY(__FREQUENCY__) (((__FREQUENCY__) > 0) && ((__FREQUENCY__) <= 1500000))
527 
528 /** @brief Check if I2S FIFO Threshold is valid.
529  * @param __THR__ I2S FIFO Threshold.
530  * @retval SET (__THR__ is valid) or RESET (__THR__ is invalid)
531  */
532 #define IS_I2S_FIFO_THRESHOLD(__THR__) (((__THR__) >= 0) && ((__THR__) <= I2S_TX_FIFO_LEVEL_MAX))
533 
534 /** @} */
535 
536 /** @} */
537 
538 /* Exported functions --------------------------------------------------------*/
539 /** @addtogroup HAL_I2S_DRIVER_FUNCTIONS Functions
540  * @{
541  */
542 
543 /** @defgroup I2S_Exported_Functions_Group1 Initialization and de-initialization functions
544  * @brief Initialization and de-initializations functions
545  *
546 @verbatim
547  ===============================================================================
548  ##### Initialization and de-initialization functions #####
549  ===============================================================================
550  [..] This subsection provides a set of functions allowing to initialize and
551  de-initialize the I2Sx peripheral:
552 
553  (+) User must implement hal_i2s_msp_init() function in which he configures
554  all related peripherals resources (GPIO, DMA, IT and NVIC ).
555 
556  (+) Call the function hal_i2s_init() to configure the selected device with
557  the selected configuration:
558  (++) Data Size
559  (++) Clock Polarity
560  (++) Audio Frequency
561 
562  (+) Call the function hal_i2s_deinit() to restore the default configuration
563  of the selected I2Sx peripheral.
564 
565 @endverbatim
566  * @{
567  */
568 
569 /**
570  ****************************************************************************************
571  * @brief Initialize the I2S according to the specified parameters
572  * in the i2s_init_t and initialize the associated handle.
573  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
574  * @retval ::HAL_OK: Operation is OK.
575  * @retval ::HAL_ERROR: Parameter error or operation not supported.
576  * @retval ::HAL_BUSY: Driver is busy.
577  * @retval ::HAL_TIMEOUT: Timeout occurred.
578  ****************************************************************************************
579  */
581 
582 /**
583  ****************************************************************************************
584  * @brief De-initialize the I2S peripheral.
585  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
586  * @retval ::HAL_OK: Operation is OK.
587  * @retval ::HAL_ERROR: Parameter error or operation not supported.
588  * @retval ::HAL_BUSY: Driver is busy.
589  * @retval ::HAL_TIMEOUT: Timeout occurred.
590  ****************************************************************************************
591  */
593 
594 /**
595  ****************************************************************************************
596  * @brief Initialize the I2S MSP.
597  * @note This function should not be modified. When the callback is needed,
598  the hal_i2s_msp_deinit can be implemented in the user file.
599  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
600  ****************************************************************************************
601  */
603 
604 /**
605  ****************************************************************************************
606  * @brief De-initialize the I2S MSP.
607  * @note This function should not be modified. When the callback is needed,
608  the hal_i2s_msp_deinit can be implemented in the user file.
609  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
610  ****************************************************************************************
611  */
613 
614 /** @} */
615 
616 /** @defgroup I2S_Exported_Functions_Group2 IO operation functions
617  * @brief Data transfers functions
618  *
619 @verbatim
620  ==============================================================================
621  ##### IO operation functions #####
622  ===============================================================================
623  [..]
624  This subsection provides a set of functions allowing to manage the I2S
625  data transfers.
626 
627  [..] The I2S supports master and slave mode:
628 
629  (#) There are two modes of transfer:
630  (++) Blocking mode: The communication is performed in polling mode.
631  The HAL status of all data processing is returned by the same function
632  after finishing transfer.
633  (++) No-Blocking mode: The communication is performed using Interrupts
634  or DMA, These APIs return the HAL status.
635  The end of the data processing will be indicated through the
636  dedicated I2S IRQ when using Interrupt mode or the DMA IRQ when
637  using DMA mode.
638  The hal_i2s_tx_cplt_callback(), hal_i2s_rx_cplt_callback() and hal_i2s_tx_rx_cplt_callback() user callbacks
639  will be executed respectively at the end of the transmit or Receive process
640  The hal_i2s_error_callback() user callback will be executed when a communication error is detected.
641 
642  (#) APIs provided for these 2 transfer modes (Blocking mode or Non blocking mode using either Interrupt or DMA)
643  exist for 1-Line (simplex) and 2-Line (full duplex) modes.
644 
645 @endverbatim
646  * @{
647  */
648 
649 /**
650  ****************************************************************************************
651  * @brief Transmit an amount of data in blocking mode.
652  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
653  * @param[in] p_data: Pointer to data buffer
654  * @param[in] length: Amount of data to be sent in halfword, data of a channel.
655  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
656  * @param[in] timeout: Timeout duration
657  * @retval ::HAL_OK: Operation is OK.
658  * @retval ::HAL_ERROR: Parameter error or operation not supported.
659  * @retval ::HAL_BUSY: Driver is busy.
660  * @retval ::HAL_TIMEOUT: Timeout occurred.
661  ****************************************************************************************
662  */
663 hal_status_t hal_i2s_transmit(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length, uint32_t timeout);
664 
665 /**
666  ****************************************************************************************
667  * @brief Receive an amount of data in blocking mode.
668  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
669  * @param[out] p_data: Pointer to data buffer
670  * @param[in] length: Amount of data to be received in halfword, data of a channel.
671  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
672  * @param[in] timeout: Timeout duration
673  * @retval ::HAL_OK: Operation is OK.
674  * @retval ::HAL_ERROR: Parameter error or operation not supported.
675  * @retval ::HAL_BUSY: Driver is busy.
676  * @retval ::HAL_TIMEOUT: Timeout occurred.
677  ****************************************************************************************
678  */
679 hal_status_t hal_i2s_receive(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length, uint32_t timeout);
680 
681 /**
682  ****************************************************************************************
683  * @brief Transmit and Receive an amount of data in blocking mode.
684  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration information for the specified I2S module.
685  * @param[in] p_tx_data: Pointer to transmission data buffer
686  * @param[out] p_rx_data: Pointer to reception data buffer
687  * @param[in] length: Amount of data to be sent and received in bytes
688  * @param[in] timeout: Timeout duration
689  * @retval ::HAL_OK: Operation is OK.
690  * @retval ::HAL_ERROR: Parameter error or operation not supported.
691  * @retval ::HAL_BUSY: Driver is busy.
692  * @retval ::HAL_TIMEOUT: Timeout occurred.
693  ****************************************************************************************
694  */
695 hal_status_t hal_i2s_transmit_receive(i2s_handle_t *p_i2s, uint16_t *p_tx_data, uint16_t *p_rx_data, uint32_t length, uint32_t timeout);
696 
697 /**
698  ****************************************************************************************
699  * @brief Transmit an amount of data in non-blocking mode with Interrupt.
700  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
701  * @param[in] p_data: Pointer to data buffer
702  * @param[in] length: Amount of data to be sent in halfword, data of a channel.
703  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
704  * @retval ::HAL_OK: Operation is OK.
705  * @retval ::HAL_ERROR: Parameter error or operation not supported.
706  * @retval ::HAL_BUSY: Driver is busy.
707  * @retval ::HAL_TIMEOUT: Timeout occurred.
708  ****************************************************************************************
709  */
710 hal_status_t hal_i2s_transmit_it(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length);
711 
712 /**
713  ****************************************************************************************
714  * @brief Receive an amount of data in non-blocking mode with Interrupt.
715  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
716  * @param[out] p_data: Pointer to data buffer
717  * @param[in] length: Amount of data to be sent in halfword, data of a channel.
718  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
719  * @retval ::HAL_OK: Operation is OK.
720  * @retval ::HAL_ERROR: Parameter error or operation not supported.
721  * @retval ::HAL_BUSY: Driver is busy.
722  * @retval ::HAL_TIMEOUT: Timeout occurred.
723  ****************************************************************************************
724  */
725 hal_status_t hal_i2s_receive_it(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length);
726 
727 /**
728  ****************************************************************************************
729  * @brief Transmit and Receive an amount of data in non-blocking mode with Interrupt.
730  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration information for the specified SPI module.
731  * @param[in] p_tx_data: Pointer to transmission data buffer
732  * @param[out] p_rx_data: Pointer to reception data buffer
733  * @param[in] length: Amount of data to be sent and received in bytes
734  * @retval ::HAL_OK: Operation is OK.
735  * @retval ::HAL_ERROR: Parameter error or operation not supported.
736  * @retval ::HAL_BUSY: Driver is busy.
737  * @retval ::HAL_TIMEOUT: Timeout occurred.
738  ****************************************************************************************
739  */
740 hal_status_t hal_i2s_transmit_receive_it(i2s_handle_t *p_i2s, uint16_t *p_tx_data, uint16_t *p_rx_data, uint32_t length);
741 
742 /**
743  ****************************************************************************************
744  * @brief Transmit an amount of data in non-blocking mode with DMA.
745  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
746  * @param[in] p_data: Pointer to data buffer
747  * @param[in] length: Amount of data to be sent in halfword, data of a channel, ranging between 1 and 4095.
748  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
749  * @retval ::HAL_OK: Operation is OK.
750  * @retval ::HAL_ERROR: Parameter error or operation not supported.
751  * @retval ::HAL_BUSY: Driver is busy.
752  * @retval ::HAL_TIMEOUT: Timeout occurred.
753  ****************************************************************************************
754  */
755 hal_status_t hal_i2s_transmit_dma(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length);
756 
757 /**
758  ****************************************************************************************
759  * @brief Receive an amount of data in non-blocking mode with DMA.
760  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
761  * @param[out] p_data: Pointer to data buffer
762  * @param[in] length: Amount of data to be sent in halfword, data of a channel, ranging between 1 and 4095.
763  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
764  * @retval ::HAL_OK: Operation is OK.
765  * @retval ::HAL_ERROR: Parameter error or operation not supported.
766  * @retval ::HAL_BUSY: Driver is busy.
767  * @retval ::HAL_TIMEOUT: Timeout occurred.
768  ****************************************************************************************
769  */
770 hal_status_t hal_i2s_receive_dma(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length);
771 
772 /**
773  ****************************************************************************************
774  * @brief Transmit and Receive an amount of data in non-blocking mode with DMA.
775  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration information for the specified I2S module.
776  * @param[in] p_tx_data: Pointer to transmission data buffer
777  * @param[out] p_rx_data: Pointer to reception data buffer
778  * @param[in] length: Amount of data to be sent in bytes, ranging between 1 and 4095.
779  * @retval ::HAL_OK: Operation is OK.
780  * @retval ::HAL_ERROR: Parameter error or operation not supported.
781  * @retval ::HAL_BUSY: Driver is busy.
782  * @retval ::HAL_TIMEOUT: Timeout occurred.
783  ****************************************************************************************
784  */
785 hal_status_t hal_i2s_transmit_receive_dma(i2s_handle_t *p_i2s, uint16_t *p_tx_data, uint16_t *p_rx_data, uint32_t length);
786 
787 /**
788  ****************************************************************************************
789  * @brief Transmit an amount of data in non-blocking mode with DMA.
790  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
791  * @param[in] p_data: Pointer to data buffer
792  * @param[in] length: Amount of data to be sent in halfword, data of a channel, ranging between 1 and 4095.
793  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
794  * @param[in] p_sg_llp_config: Pointer to the config of source and destination's SG and LLP.
795  * @retval ::HAL_OK: Operation is OK.
796  * @retval ::HAL_ERROR: Parameter error or operation not supported.
797  * @retval ::HAL_BUSY: Driver is busy.
798  * @retval ::HAL_TIMEOUT: Timeout occurred.
799  ****************************************************************************************
800  */
801 hal_status_t hal_i2s_transmit_dma_sg_llp(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length, dma_sg_llp_config_t *p_sg_llp_config);
802 
803 /**
804  ****************************************************************************************
805  * @brief Receive an amount of data in non-blocking mode with DMA.
806  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
807  * @param[out] p_data: Pointer to data buffer
808  * @param[in] length: Amount of data to be sent in halfword, data of a channel, ranging between 1 and 4095.
809  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
810  * @param[in] p_sg_llp_config: Pointer to the config of source and destination's SG and LLP.
811  * @retval ::HAL_OK: Operation is OK.
812  * @retval ::HAL_ERROR: Parameter error or operation not supported.
813  * @retval ::HAL_BUSY: Driver is busy.
814  * @retval ::HAL_TIMEOUT: Timeout occurred.
815  ****************************************************************************************
816  */
817 hal_status_t hal_i2s_receive_dma_sg_llp(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length, dma_sg_llp_config_t *p_sg_llp_config);
818 
819 /**
820  ****************************************************************************************
821  * @brief Transmit and Receive an amount of data in non-blocking mode with DMA.
822  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration information for the specified I2S module.
823  * @param[in] p_tx_data: Pointer to transmission data buffer
824  * @param[out] p_rx_data: Pointer to reception data buffer
825  * @param[in] length: Amount of data to be sent in bytes, ranging between 1 and 4095.
826  * @param[in] p_sg_llp_config: Pointer to the config of source and destination's SG and LLP.
827  * @retval ::HAL_OK: Operation is OK.
828  * @retval ::HAL_ERROR: Parameter error or operation not supported.
829  * @retval ::HAL_BUSY: Driver is busy.
830  * @retval ::HAL_TIMEOUT: Timeout occurred.
831  ****************************************************************************************
832  */
834  uint16_t *p_tx_data,
835  uint16_t *p_rx_data,
836  uint32_t length,
837  dma_sg_llp_config_t *p_sg_llp_config);
838 
839 
840 /**
841  ****************************************************************************************
842  * @brief Start the I2S master clock.
843  * @note In case of SLAVE mode, this function will not take effect.
844  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
845  * @retval ::HAL_OK: Operation is OK.
846  * @retval ::HAL_ERROR: Parameter error or operation not supported.
847  * @retval ::HAL_BUSY: Driver is busy.
848  * @retval ::HAL_TIMEOUT: Timeout occurred.
849  ****************************************************************************************
850  */
852 
853 /**
854  ****************************************************************************************
855  * @brief Stop the I2S master clock.
856  * @note In case of SLAVE mode, this function will not take effect.
857  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
858  * @retval ::HAL_OK: Operation is OK.
859  * @retval ::HAL_ERROR: Parameter error or operation not supported.
860  * @retval ::HAL_BUSY: Driver is busy.
861  * @retval ::HAL_TIMEOUT: Timeout occurred.
862  ****************************************************************************************
863  */
865 
866 /**
867  ****************************************************************************************
868  * @brief Abort ongoing transfer (blocking mode).
869  * @param[in] p_i2s: I2S handle.
870  * @note This procedure could be used for aborting any ongoing transfer (TX and RX),
871  * started in Interrupt or DMA mode.
872  * This procedure performs following operations :
873  * - Disable I2S Interrupts (depending of transfer direction)
874  * - Disable the DMA transfer in the peripheral register (if enabled)
875  * - Abort DMA transfer by calling hal_dma_abort (in case of transfer in DMA mode)
876  * - Set handle State to READY
877  * @note This procedure is executed in blocking mode: When exiting function, Abort is considered as completed.
878  * @retval ::HAL_OK: Operation is OK.
879  * @retval ::HAL_ERROR: Parameter error or operation not supported.
880  * @retval ::HAL_BUSY: Driver is busy.
881  * @retval ::HAL_TIMEOUT: Timeout occurred.
882  ****************************************************************************************
883  */
885 
886 /** @} */
887 
888 /** @addtogroup I2S_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
889  * @brief IRQ Handler and Callbacks functions
890  * @{
891  */
892 
893 /**
894  ****************************************************************************************
895  * @brief Handle I2S interrupt request.
896  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
897  ****************************************************************************************
898  */
900 
901 /**
902  ****************************************************************************************
903  * @brief TX Transfer completed callback.
904  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
905  ****************************************************************************************
906  */
908 
909 /**
910  ****************************************************************************************
911  * @brief RX Transfer completed callback.
912  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
913  ****************************************************************************************
914  */
916 
917 /**
918  ****************************************************************************************
919  * @brief TX/RX Transfer completed callback.
920  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
921  ****************************************************************************************
922  */
924 
925 /**
926  ****************************************************************************************
927  * @brief I2S error callback.
928  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
929  ****************************************************************************************
930  */
932 
933 /** @} */
934 
935 /** @defgroup I2S_Exported_Functions_Group3 Peripheral State and Errors functions
936  * @brief I2S control functions
937  *
938 @verbatim
939  ===============================================================================
940  ##### Peripheral State and Errors functions #####
941  ===============================================================================
942  [..]
943  This subsection provides a set of functions allowing to control the I2S.
944  (+) hal_i2s_get_state() API can be helpful to check in run-time the state of the I2S peripheral
945  (+) hal_i2s_get_error() check in run-time Errors occurring during communication
946  (+) hal_i2s_set_timeout() set the timeout during internal process
947  (+) hal_i2s_set_tx_fifo_threshold() set the TX FIFO Threshold
948  (+) hal_i2s_set_rx_fifo_threshold() set the RX FIFO Threshold
949  (+) hal_i2s_get_tx_fifo_threshold() get the TX FIFO Threshold
950  (+) hal_i2s_get_rx_fifo_threshold() get the RX FIFO Threshold
951 @endverbatim
952  * @{
953  */
954 
955 /**
956  ****************************************************************************************
957  * @brief Return the I2S handle state.
958  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
959  * @retval ::HAL_I2S_STATE_RESET: Peripheral not initialized.
960  * @retval ::HAL_I2S_STATE_READY: Peripheral initialized and ready for use.
961  * @retval ::HAL_I2S_STATE_BUSY: An internal process is ongoing.
962  * @retval ::HAL_I2S_STATE_BUSY_TX: Data Transmii2son process is ongoing.
963  * @retval ::HAL_I2S_STATE_BUSY_RX: Data Reception process is ongoing.
964  * @retval ::HAL_I2S_STATE_ABORT: Peripheral with abort request ongoing.
965  * @retval ::HAL_I2S_STATE_ERROR: Peripheral in error.
966  ****************************************************************************************
967  */
969 
970 /**
971  ****************************************************************************************
972  * @brief Return the I2S error code.
973  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
974  * @return I2S error code in bitmap format
975  ****************************************************************************************
976  */
978 
979 /**
980  ****************************************************************************************
981  * @brief Set the TX FIFO threshold.
982  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
983  * @param[in] threshold: TX FIFO threshold value ranging bwtween 0x0U ~ 0x7U.
984  * @retval ::HAL_OK: Operation is OK.
985  * @retval ::HAL_ERROR: Parameter error or operation not supported.
986  * @retval ::HAL_BUSY: Driver is busy.
987  * @retval ::HAL_TIMEOUT: Timeout occurred.
988  ****************************************************************************************
989  */
991 
992 /**
993  ****************************************************************************************
994  * @brief Set the RX FIFO threshold.
995  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
996  * @param[in] threshold: RX FIFO threshold value ranging bwtween 0x0U ~ 0x7U.
997  * @retval ::HAL_OK: Operation is OK.
998  * @retval ::HAL_ERROR: Parameter error or operation not supported.
999  * @retval ::HAL_BUSY: Driver is busy.
1000  * @retval ::HAL_TIMEOUT: Timeout occurred.
1001  ****************************************************************************************
1002  */
1004 
1005 /**
1006  ****************************************************************************************
1007  * @brief Get the TX FIFO threshold.
1008  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
1009  * @return TX FIFO threshold
1010  ****************************************************************************************
1011  */
1013 
1014 /**
1015  ****************************************************************************************
1016  * @brief Get the RX FIFO threshold.
1017  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
1018  * @return RX FIFO threshold
1019  ****************************************************************************************
1020  */
1022 
1023 /**
1024  ****************************************************************************************
1025  * @brief Suspend some registers related to I2S configuration before sleep.
1026  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration
1027  * information for the specified I2S module.
1028  * @retval ::HAL_OK: Operation is OK.
1029  * @retval ::HAL_ERROR: Parameter error or operation not supported.
1030  * @retval ::HAL_BUSY: Driver is busy.
1031  * @retval ::HAL_TIMEOUT: Timeout occurred.
1032  ****************************************************************************************
1033  */
1035 
1036 /**
1037  ****************************************************************************************
1038  * @brief Restore some registers related to I2S configuration after sleep.
1039  * This function must be used in conjunction with the hal_i2s_suspend_reg().
1040  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration
1041  * information for the specified I2S module.
1042  * @retval ::HAL_OK: Operation is OK.
1043  * @retval ::HAL_ERROR: Parameter error or operation not supported.
1044  * @retval ::HAL_BUSY: Driver is busy.
1045  * @retval ::HAL_TIMEOUT: Timeout occurred.
1046  ****************************************************************************************
1047  */
1049 
1050 
1051 /** @} */
1052 
1053 /** @} */
1054 
1055 #ifdef __cplusplus
1056 }
1057 #endif
1058 
1059 #endif /* __GR55xx_HAL_I2S_H__ */
1060 
1061 /** @} */
1062 
1063 /** @} */
1064 
1065 /** @} */
_i2s_init::data_size
uint32_t data_size
Definition: gr55xx_hal_i2s.h:105
_i2s_callback
HAL_I2S Callback function definition.
Definition: gr55xx_hal_i2s.h:185
HAL_I2S_STATE_BUSY_TX
@ HAL_I2S_STATE_BUSY_TX
Definition: gr55xx_hal_i2s.h:80
hal_i2s_init
hal_status_t hal_i2s_init(i2s_handle_t *p_i2s)
Initialize the I2S according to the specified parameters in the i2s_init_t and initialize the associa...
hal_i2s_receive_it
hal_status_t hal_i2s_receive_it(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length)
Receive an amount of data in non-blocking mode with Interrupt.
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
hal_i2s_deinit
hal_status_t hal_i2s_deinit(i2s_handle_t *p_i2s)
De-initialize the I2S peripheral.
_i2s_handle::p_rx_buffer
uint16_t * p_rx_buffer
Definition: gr55xx_hal_i2s.h:144
hal_i2s_transmit_receive_dma
hal_status_t hal_i2s_transmit_receive_dma(i2s_handle_t *p_i2s, uint16_t *p_tx_data, uint16_t *p_rx_data, uint32_t length)
Transmit and Receive an amount of data in non-blocking mode with DMA.
hal_i2s_tx_cplt_callback
void hal_i2s_tx_cplt_callback(i2s_handle_t *p_i2s)
TX Transfer completed callback.
HAL_I2S_STATE_BUSY_RX
@ HAL_I2S_STATE_BUSY_RX
Definition: gr55xx_hal_i2s.h:81
hal_i2s_receive
hal_status_t hal_i2s_receive(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length, uint32_t timeout)
Receive an amount of data in blocking mode.
_i2s_handle::write_fifo
void(* write_fifo)(struct _i2s_handle *p_i2s)
Definition: gr55xx_hal_i2s.h:150
HAL_I2S_STATE_ABORT
@ HAL_I2S_STATE_ABORT
Definition: gr55xx_hal_i2s.h:83
_i2s_handle::p_instance
i2s_regs_t * p_instance
Definition: gr55xx_hal_i2s.h:134
hal_i2s_error_callback
void hal_i2s_error_callback(i2s_handle_t *p_i2s)
I2S error callback.
_i2s_handle::read_fifo
void(* read_fifo)(struct _i2s_handle *p_i2s)
Definition: gr55xx_hal_i2s.h:152
hal_i2s_abort
hal_status_t hal_i2s_abort(i2s_handle_t *p_i2s)
Abort ongoing transfer (blocking mode).
_i2s_callback::i2s_rx_cplt_callback
void(* i2s_rx_cplt_callback)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:189
i2s_init_t
struct _i2s_init i2s_init_t
I2S init Structure definition.
_i2s_handle::error_code
__IO uint32_t error_code
Definition: gr55xx_hal_i2s.h:162
_i2s_handle::p_tx_buffer
uint16_t * p_tx_buffer
Definition: gr55xx_hal_i2s.h:138
hal_i2s_transmit_receive_dma_sg_llp
hal_status_t hal_i2s_transmit_receive_dma_sg_llp(i2s_handle_t *p_i2s, uint16_t *p_tx_data, uint16_t *p_rx_data, uint32_t length, dma_sg_llp_config_t *p_sg_llp_config)
Transmit and Receive an amount of data in non-blocking mode with DMA.
hal_i2s_receive_dma
hal_status_t hal_i2s_receive_dma(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length)
Receive an amount of data in non-blocking mode with DMA.
HAL_I2S_STATE_RESET
@ HAL_I2S_STATE_RESET
Definition: gr55xx_hal_i2s.h:77
_i2s_init::audio_freq
uint32_t audio_freq
Definition: gr55xx_hal_i2s.h:114
hal_i2s_transmit_receive_it
hal_status_t hal_i2s_transmit_receive_it(i2s_handle_t *p_i2s, uint16_t *p_tx_data, uint16_t *p_rx_data, uint32_t length)
Transmit and Receive an amount of data in non-blocking mode with Interrupt.
_i2s_callback::i2s_tx_cplt_callback
void(* i2s_tx_cplt_callback)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:190
_i2s_callback::i2s_tx_rx_cplt_callback
void(* i2s_tx_rx_cplt_callback)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:191
_i2s_handle::init
i2s_init_t init
Definition: gr55xx_hal_i2s.h:136
hal_i2s_tx_rx_cplt_callback
void hal_i2s_tx_rx_cplt_callback(i2s_handle_t *p_i2s)
TX/RX Transfer completed callback.
hal_i2s_transmit_it
hal_status_t hal_i2s_transmit_it(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length)
Transmit an amount of data in non-blocking mode with Interrupt.
_i2s_handle::tx_xfer_count
__IO uint32_t tx_xfer_count
Definition: gr55xx_hal_i2s.h:142
dma_sg_llp_config
LL DMA sg and llp config definition.
Definition: gr55xx_hal_dma.h:219
HAL_I2S_STATE_READY
@ HAL_I2S_STATE_READY
Definition: gr55xx_hal_i2s.h:78
hal_i2s_rx_cplt_callback
void hal_i2s_rx_cplt_callback(i2s_handle_t *p_i2s)
RX Transfer completed callback.
hal_i2s_get_tx_fifo_threshold
uint32_t hal_i2s_get_tx_fifo_threshold(i2s_handle_t *p_i2s)
Get the TX FIFO threshold.
hal_i2s_transmit_dma
hal_status_t hal_i2s_transmit_dma(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length)
Transmit an amount of data in non-blocking mode with DMA.
_i2s_handle::timeout
uint32_t timeout
Definition: gr55xx_hal_i2s.h:164
_i2s_init::clock_source
uint32_t clock_source
Definition: gr55xx_hal_i2s.h:108
i2s_handle_t
struct _i2s_handle i2s_handle_t
I2S handle Structure definition.
hal_i2s_resume_reg
hal_status_t hal_i2s_resume_reg(i2s_handle_t *p_i2s)
Restore some registers related to I2S configuration after sleep. This function must be used in conjun...
hal_i2s_transmit_dma_sg_llp
hal_status_t hal_i2s_transmit_dma_sg_llp(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length, dma_sg_llp_config_t *p_sg_llp_config)
Transmit an amount of data in non-blocking mode with DMA.
HAL_I2S_STATE_BUSY
@ HAL_I2S_STATE_BUSY
Definition: gr55xx_hal_i2s.h:79
gr55xx_ll_i2s.h
Header file containing functions prototypes of I2S LL library.
hal_i2s_get_state
hal_i2s_state_t hal_i2s_get_state(i2s_handle_t *p_i2s)
Return the I2S handle state.
hal_i2s_get_rx_fifo_threshold
uint32_t hal_i2s_get_rx_fifo_threshold(i2s_handle_t *p_i2s)
Get the RX FIFO threshold.
_i2s_handle
I2S handle Structure definition.
Definition: gr55xx_hal_i2s.h:133
_i2s_handle::state
__IO hal_i2s_state_t state
Definition: gr55xx_hal_i2s.h:160
_i2s_callback::i2s_msp_init
void(* i2s_msp_init)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:186
hal_i2s_start_clock
hal_status_t hal_i2s_start_clock(i2s_handle_t *p_i2s)
Start the I2S master clock.
_i2s_handle::tx_xfer_size
__IO uint32_t tx_xfer_size
Definition: gr55xx_hal_i2s.h:140
_i2s_handle::retention
uint32_t retention[7]
Definition: gr55xx_hal_i2s.h:166
hal_i2s_transmit_receive
hal_status_t hal_i2s_transmit_receive(i2s_handle_t *p_i2s, uint16_t *p_tx_data, uint16_t *p_rx_data, uint32_t length, uint32_t timeout)
Transmit and Receive an amount of data in blocking mode.
_i2s_init
I2S init Structure definition.
Definition: gr55xx_hal_i2s.h:104
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
hal_i2s_receive_dma_sg_llp
hal_status_t hal_i2s_receive_dma_sg_llp(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length, dma_sg_llp_config_t *p_sg_llp_config)
Receive an amount of data in non-blocking mode with DMA.
_i2s_init::ws_cycles
uint32_t ws_cycles
Definition: gr55xx_hal_i2s.h:111
_i2s_handle::lock
__IO hal_lock_t lock
Definition: gr55xx_hal_i2s.h:158
HAL_I2S_STATE_ERROR
@ HAL_I2S_STATE_ERROR
Definition: gr55xx_hal_i2s.h:84
HAL_I2S_STATE_BUSY_TX_RX
@ HAL_I2S_STATE_BUSY_TX_RX
Definition: gr55xx_hal_i2s.h:82
_i2s_handle::p_dmarx
dma_handle_t * p_dmarx
Definition: gr55xx_hal_i2s.h:156
hal_i2s_suspend_reg
hal_status_t hal_i2s_suspend_reg(i2s_handle_t *p_i2s)
Suspend some registers related to I2S configuration before sleep.
hal_i2s_transmit
hal_status_t hal_i2s_transmit(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length, uint32_t timeout)
Transmit an amount of data in blocking mode.
_i2s_callback::i2s_error_callback
void(* i2s_error_callback)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:188
hal_i2s_set_tx_fifo_threshold
hal_status_t hal_i2s_set_tx_fifo_threshold(i2s_handle_t *p_i2s, uint32_t threshold)
Set the TX FIFO threshold.
_i2s_callback::i2s_msp_deinit
void(* i2s_msp_deinit)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:187
i2s_callback_t
struct _i2s_callback i2s_callback_t
HAL_I2S Callback function definition.
hal_i2s_get_error
uint32_t hal_i2s_get_error(i2s_handle_t *p_i2s)
Return the I2S error code.
hal_i2s_msp_init
void hal_i2s_msp_init(i2s_handle_t *p_i2s)
Initialize the I2S MSP.
_i2s_handle::rx_xfer_count
__IO uint32_t rx_xfer_count
Definition: gr55xx_hal_i2s.h:148
hal_i2s_irq_handler
void hal_i2s_irq_handler(i2s_handle_t *p_i2s)
Handle I2S interrupt request.
hal_i2s_state_t
hal_i2s_state_t
HAL I2S State Enumerations definition.
Definition: gr55xx_hal_i2s.h:76
hal_i2s_msp_deinit
void hal_i2s_msp_deinit(i2s_handle_t *p_i2s)
De-initialize the I2S MSP.
hal_i2s_stop_clock
hal_status_t hal_i2s_stop_clock(i2s_handle_t *p_i2s)
Stop the I2S master clock.
_dma_handle
DMA handle Structure definition.
Definition: gr55xx_hal_dma.h:277
_i2s_handle::p_dmatx
dma_handle_t * p_dmatx
Definition: gr55xx_hal_i2s.h:154
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
_i2s_handle::rx_xfer_size
__IO uint32_t rx_xfer_size
Definition: gr55xx_hal_i2s.h:146
hal_i2s_set_rx_fifo_threshold
hal_status_t hal_i2s_set_rx_fifo_threshold(i2s_handle_t *p_i2s, uint32_t threshold)
Set the RX FIFO threshold.