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 _hal_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 #define HAL_I2S_ERROR_TX_OVERFLOW ((uint32_t)0x00000010) /**< Transmit overflow error */
225 #define HAL_I2S_ERROR_RX_OVERFLOW ((uint32_t)0x00000020) /**< Receive overflow error */
226 /** @} */
227 
228 /** @defgroup I2S_Data_Size I2S Data Size
229  * @{
230  */
231 #define I2S_DATASIZE_12BIT LL_I2S_DATASIZE_12BIT /**< 12-bit serial data transfer */
232 #define I2S_DATASIZE_16BIT LL_I2S_DATASIZE_16BIT /**< 16-bit serial data transfer */
233 #define I2S_DATASIZE_20BIT LL_I2S_DATASIZE_20BIT /**< 20-bit serial data transfer */
234 #define I2S_DATASIZE_24BIT LL_I2S_DATASIZE_24BIT /**< 24-bit serial data transfer */
235 #define I2S_DATASIZE_32BIT LL_I2S_DATASIZE_32BIT /**< 32-bit serial data transfer */
236 /** @} */
237 
238 /** @defgroup I2S_Clock_Source I2S Clock Source
239  * @{
240  */
241 #define I2S_CLOCK_SRC_96M LL_I2S_CLOCK_SRC_96M /**< I2S clock source select: 96M */
242 #define I2S_CLOCK_SRC_64M LL_I2S_CLOCK_SRC_64M /**< I2S clock source select: 64M */
243 #define I2S_CLOCK_SRC_32M LL_I2S_CLOCK_SRC_32M /**< I2S clock source select: 32M */
244 /** @} */
245 
246 /** @defgroup I2S_WS_CYCLES I2S Word Select Line Cycles
247  * @{
248  */
249 #define I2S_WS_CYCLES_16 LL_I2S_WS_CYCLES_16 /**< 16 SCLK cycles in word select line. */
250 #define I2S_WS_CYCLES_24 LL_I2S_WS_CYCLES_24 /**< 24 SCLK cycles in word select line. */
251 #define I2S_WS_CYCLES_32 LL_I2S_WS_CYCLES_32 /**< 32 SCLK cycles in word select line. */
252 /** @} */
253 
254 /** @defgroup I2S_FIFO_LEVEL_MAX I2S FIFO Level Max
255  * @{
256  */
257 #define I2S_TX_FIFO_LEVEL_MAX 16 /**< I2S TX FIFO Level Max Value */
258 #define I2S_RX_FIFO_LEVEL_MAX 16 /**< I2S RX FIFO Level Max Value */
259 /** @} */
260 
261 /** @defgroup I2S_Flags_definition I2S Flags Definition
262  * @{
263  */
264 #define I2S_FLAG_TXFO LL_I2S_STATUS_TXFO /**< TX FIFO write overflow flag */
265 #define I2S_FLAG_TXFE LL_I2S_STATUS_TXFE /**< TX FIFO empty trigger flag */
266 #define I2S_FLAG_RXFO LL_I2S_STATUS_RXFO /**< RX FIFO receive overflow flag */
267 #define I2S_FLAG_RXDA LL_I2S_STATUS_RXDA /**< RX FIFO data available flag */
268 /** @} */
269 
270 /** @defgroup I2S_Interrupt_definition I2S Interrupt Definition
271  * @{
272  */
273 #define I2S_IT_TXFO LL_I2S_INT_TXFO /**< TX FIFO write overflow interrupt */
274 #define I2S_IT_TXFE LL_I2S_INT_TXFE /**< TX FIFO empty trigger interrupt */
275 #define I2S_IT_RXFO LL_I2S_INT_RXFO /**< RX FIFO receive overflow interrupt */
276 #define I2S_IT_RXDA LL_I2S_INT_RXDA /**< RX FIFO data available interrupt */
277 /** @} */
278 
279 /** @defgroup I2S_Timeout_definition I2S Timeout_definition
280  * @{
281  */
282 #define HAL_I2S_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000) /**< 5s */
283 /** @} */
284 
285 /** @} */
286 
287 /* Exported macro ------------------------------------------------------------*/
288 /** @defgroup I2S_Exported_Macros I2S Exported Macros
289  * @{
290  */
291 
292 /** @brief Reset I2S handle states.
293  * @param __HANDLE__ I2S handle.
294  * @retval None
295  */
296 #define __HAL_I2S_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_I2S_STATE_RESET)
297 
298 /** @brief Enable the specified I2S peripheral.
299  * @param __HANDLE__ Specifies the I2S Handle.
300  * @retval None
301  */
302 #define __HAL_I2S_ENABLE(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->EN, I2S_EN_I2S_EN)
303 /** @brief Disable the specified I2S peripheral.
304  * @param __HANDLE__ Specifies the I2S Handle.
305  * @retval None
306  */
307 
308 #define __HAL_I2S_DISABLE(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->EN, I2S_EN_I2S_EN)
309 
310 /** @brief Enable the specified I2S clock.
311  * @param __HANDLE__ Specifies the I2S Handle.
312  * @retval None
313  */
314 
315 #if !defined (GR551xx)
316 #define __HAL_I2S_ENABLE_CLOCK(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CLK_EN, I2S_CLK_EN_CLK_EN)
317 #else
318 #define __HAL_I2S_ENABLE_CLOCK(__HANDLE__) SET_BITS((__HANDLE__)->p_instance->CLKEN, I2S_CLKEN_EN)
319 #endif
320 
321 /** @brief Disable the specified I2S clock.
322  * @param __HANDLE__ Specifies the I2S Handle.
323  * @retval None
324  */
325 
326 #if !defined (GR551xx)
327 #define __HAL_I2S_DISABLE_CLOCK(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CLK_EN, I2S_CLK_EN_CLK_EN)
328 #else
329 #define __HAL_I2S_DISABLE_CLOCK(__HANDLE__) CLEAR_BITS((__HANDLE__)->p_instance->CLKEN, I2S_CLKEN_EN)
330 #endif
331 /** @brief Enable the specified I2S transmitter block.
332  * @param __HANDLE__ Specifies the I2S Handle.
333  * @retval None
334  */
335 #define __HAL_I2S_ENABLE_TX_BLOCK(__HANDLE__) ll_i2s_enable_txblock((__HANDLE__)->p_instance)
336 
337 /** @brief Disable the specified I2S transmitter block.
338  * @param __HANDLE__ Specifies the I2S Handle.
339  * @retval None
340  */
341 #define __HAL_I2S_DISABLE_TX_BLOCK(__HANDLE__) ll_i2s_disable_txblock((__HANDLE__)->p_instance)
342 
343 /** @brief Enable the specified I2S receiver block.
344  * @param __HANDLE__ Specifies the I2S Handle.
345  * @retval None
346  */
347 #define __HAL_I2S_ENABLE_RX_BLOCK(__HANDLE__) ll_i2s_enable_rxblock((__HANDLE__)->p_instance)
348 
349 /** @brief Disable the specified I2S receiver block.
350  * @param __HANDLE__ Specifies the I2S Handle.
351  * @retval None
352  */
353 #define __HAL_I2S_DISABLE_RX_BLOCK(__HANDLE__) ll_i2s_disable_rxblock((__HANDLE__)->p_instance)
354 
355 /** @brief Enable the specified I2S transmitter channel.
356  * @param __HANDLE__ Specifies the I2S Handle.
357  * @retval None
358  */
359 
360 #define __HAL_I2S_ENABLE_TX_CHANNEL(__HANDLE__) ll_i2s_enable_tx((__HANDLE__)->p_instance)
361 
362 /** @brief Disable the specified I2S transmitter channel.
363  * @param __HANDLE__ Specifies the I2S Handle.
364  * @retval None
365  */
366 
367 #define __HAL_I2S_DISABLE_TX_CHANNEL(__HANDLE__) ll_i2s_disable_tx((__HANDLE__)->p_instance)
368 
369 /** @brief Enable the specified I2S receiver channel.
370  * @param __HANDLE__ Specifies the I2S Handle.
371  * @retval None
372  */
373 
374 #define __HAL_I2S_ENABLE_RX_CHANNEL(__HANDLE__) ll_i2s_enable_rx((__HANDLE__)->p_instance)
375 
376 /** @brief Disable the specified I2S receiver channel.
377  * @param __HANDLE__ Specifies the I2S Handle.
378  * @retval None
379  */
380 
381 #define __HAL_I2S_DISABLE_RX_CHANNEL(__HANDLE__) ll_i2s_disable_rx((__HANDLE__)->p_instance)
382 
383 /** @brief Flush the I2S transmitter FIFO.
384  * @param __HANDLE__ Specifies the I2S Handle.
385  * @retval None
386  */
387 #define __HAL_I2S_FLUSH_TX_FIFO(__HANDLE__) ll_i2s_clr_txfifo_all((__HANDLE__)->p_instance)
388 
389 /** @brief Flush the I2S receiver FIFO.
390  * @param __HANDLE__ Specifies the I2S Handle.
391  * @retval None
392  */
393 #define __HAL_I2S_FLUSH_RX_FIFO(__HANDLE__) ll_i2s_clr_rxfifo_all((__HANDLE__)->p_instance)
394 
395 /** @brief Enable the I2S DMA Request.
396  * @param __HANDLE__ Specifies the I2S Handle.
397  * @retval None
398  */
399 #define __HAL_I2S_ENABLE_DMA(__HANDLE__) ll_i2s_enable_dma(__HANDLE__->p_instance)
400 
401 /** @brief Disable the I2S DMA Request.
402  * @param __HANDLE__ Specifies the I2S Handle.
403  * @retval None
404  */
405 #define __HAL_I2S_DISABLE_DMA(__HANDLE__) ll_i2s_disable_dma(__HANDLE__->p_instance)
406 
407 /** @brief Reset the I2S TX DMA request to the lowest enabled channel.
408  * @param __HANDLE__ Specifies the I2S Handle.
409  * @retval None
410  */
411 
412 #define __HAL_I2S_RESET_TXDMA(__HANDLE__) WRITE_REG((__HANDLE__)->p_instance->RST_TX_DMA, I2S_RST_TX_DMA_RST_TX_DMA)
413 
414 /** @brief Enable the I2S DMA mode.
415  * @param __HANDLE__ Specifies the I2S Handle.
416  * @retval None
417  */
418 #define __HAL_I2S_ENABLE_DMA_MODE(__HANDLE__) ll_i2s_enable_dma_mode(__HANDLE__->p_instance)
419 
420 /** @brief Disable the I2S DMA mode.
421  * @param __HANDLE__ Specifies the I2S Handle.
422  * @retval None
423  */
424 #define __HAL_I2S_DISABLE_DMA_MODE(__HANDLE__) ll_i2s_disable_dma_mode(__HANDLE__->p_instance)
425 
426 /** @brief Reset the I2S RX DMA request to the lowest enabled channel.
427  * @param __HANDLE__ Specifies the I2S Handle.
428  * @retval None
429  */
430 
431 #define __HAL_I2S_RESET_RXDMA(__HANDLE__) WRITE_REG((__HANDLE__)->p_instance->RST_RX_DMA, I2S_RST_RX_DMA_RST_RX_DMA)
432 
433 /** @brief Enable the specified I2S interrupts.
434  * @param __HANDLE__ Specifies the I2S Handle.
435  * @param __INTERRUPT__ Specifies the interrupt source to enable.
436  * This parameter can be one of the following values:
437  * @arg @ref I2S_IT_TXFO TX FIFO write overflow interrupt
438  * @arg @ref I2S_IT_TXFE TX FIFO empty trigger interrupt
439  * @arg @ref I2S_IT_RXFO RX FIFO receive overflow interrupt
440  * @arg @ref I2S_IT_RXDA RX FIFO data available interrupt
441  * @retval None
442  */
443 
444 #define __HAL_I2S_ENABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__))
445 
446 /** @brief Disable the specified I2S interrupts.
447  * @param __HANDLE__ Specifies the I2S handle.
448  * @param __INTERRUPT__ Specifies the interrupt source to disable.
449  * This parameter can be one of the following values:
450  * @arg @ref I2S_IT_TXFO TX FIFO write overflow interrupt
451  * @arg @ref I2S_IT_TXFE TX FIFO empty trigger interrupt
452  * @arg @ref I2S_IT_RXFO RX FIFO receive overflow interrupt
453  * @arg @ref I2S_IT_RXDA RX FIFO data available interrupt
454  * @retval None
455  */
456 
457 #define __HAL_I2S_DISABLE_IT(__HANDLE__, __INTERRUPT__) SET_BITS((__HANDLE__)->p_instance->INT_MASK, (__INTERRUPT__))
458 
459 /** @brief Check whether the specified I2S flag is set or not.
460  * @param __HANDLE__ Specifies the I2S Handle.
461  * @param __FLAG__ Specifies the flag to check.
462  * This parameter can be one of the following values:
463  * @arg @ref I2S_FLAG_TXFO TX FIFO write overflow flag
464  * @arg @ref I2S_FLAG_TXFE TX FIFO empty trigger flag
465  * @arg @ref I2S_FLAG_RXFO RX FIFO receive overflow flag
466  * @arg @ref I2S_FLAG_RXDA RX FIFO data available flag
467  * @retval The new state of __FLAG__ (TRUE or FALSE).
468  */
469 
470 #define __HAL_I2S_GET_FLAG(__HANDLE__, __FLAG__) ((READ_BITS((__HANDLE__)->p_instance->INT_STAT, (__FLAG__)) != 0) ? SET : RESET)
471 
472 /** @brief Clear the specified I2S flag.
473  * @param __HANDLE__ Specifies the I2S Handle.
474  * @param __FLAG__ Specifies the flag to check.
475  * This parameter can be one of the following values:
476  * @arg @ref I2S_FLAG_TXFO TX FIFO write overflow flag
477  * @arg @ref I2S_FLAG_RXFO RX FIFO receive overflow flag
478  * @retval None
479  */
480 
481 #define __HAL_I2S_CLEAR_FLAG(__HANDLE__, __FLAG__) do { \
482  if ((__FLAG__) & I2S_FLAG_RXFO) \
483  { \
484  READ_BITS((__HANDLE__)->p_instance->RX_OVER, I2S_RX_OVER_RX_CLR_FDO);\
485  } \
486  if ((__FLAG__) & I2S_FLAG_TXFO) \
487  { \
488  READ_BITS((__HANDLE__)->p_instance->TX_OVER, I2S_TX_OVER_TX_CLR_FDO);\
489  } \
490  } while(0);
491 
492 /** @} */
493 
494 /* Private macros ------------------------------------------------------------*/
495 /** @defgroup I2S_Private_Macro I2S Private Macros
496  * @{
497  */
498 
499 /** @brief Check if I2S Direction Mode is valid.
500  * @param __MODE__ I2S Direction Mode.
501  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
502  */
503 #define IS_I2S_DIRECTION(__MODE__) (((__MODE__) == I2S_DIRECTION_FULL_DUPLEX) || \
504  ((__MODE__) == I2S_DIRECTION_SIMPLEX_TX) || \
505  ((__MODE__) == I2S_DIRECTION_SIMPLEX_RX))
506 
507 /** @brief Check if I2S Data Size is valid.
508  * @param __DATASIZE__ I2S Data Size.
509  * @retval SET (__DATASIZE__ is valid) or RESET (__DATASIZE__ is invalid)
510  */
511 #define IS_I2S_DATASIZE(__DATASIZE__) (((__DATASIZE__) == I2S_DATASIZE_12BIT) || \
512  ((__DATASIZE__) == I2S_DATASIZE_16BIT) || \
513  ((__DATASIZE__) == I2S_DATASIZE_20BIT) || \
514  ((__DATASIZE__) == I2S_DATASIZE_24BIT) || \
515  ((__DATASIZE__) == I2S_DATASIZE_32BIT))
516 
517 /** @brief Check if I2S Clock Polarity is valid.
518  * @param __CPOL__ I2S Clock Polarity.
519  * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
520  */
521 #define IS_I2S_CPOL(__CPOL__) (((__CPOL__) == I2S_POLARITY_LOW) || \
522  ((__CPOL__) == I2S_POLARITY_HIGH))
523 
524 /** @brief Check if I2S Audio Frequency is valid.
525  * @param __FREQUENCY__ I2S Audio Frequency.
526  * @retval SET (__FREQUENCY__ is valid) or RESET (__FREQUENCY__ is invalid)
527  */
528 #define IS_I2S_AUDIO_FREQUENCY(__FREQUENCY__) (((__FREQUENCY__) > 0) && ((__FREQUENCY__) <= 1500000))
529 
530 /** @brief Check if I2S FIFO Threshold is valid.
531  * @param __THR__ I2S FIFO Threshold.
532  * @retval SET (__THR__ is valid) or RESET (__THR__ is invalid)
533  */
534 #define IS_I2S_FIFO_THRESHOLD(__THR__) (((__THR__) >= 0) && ((__THR__) <= I2S_TX_FIFO_LEVEL_MAX))
535 
536 /** @} */
537 
538 /** @} */
539 
540 /* Exported functions --------------------------------------------------------*/
541 /** @addtogroup HAL_I2S_DRIVER_FUNCTIONS Functions
542  * @{
543  */
544 
545 /** @addtogroup I2S_Exported_Functions_Group1 Initialization and de-initialization functions
546  * @brief Initialization and de-initializations functions
547  *
548 @verbatim
549  ===============================================================================
550  ##### Initialization and de-initialization functions #####
551  ===============================================================================
552  [..] This subsection provides a set of functions allowing to initialize and
553  de-initialize the I2Sx peripheral:
554 
555  (+) User must implement hal_i2s_msp_init() function in which he configures
556  all related peripherals resources (GPIO, DMA, IT and NVIC ).
557 
558  (+) Call the function hal_i2s_init() to configure the selected device with
559  the selected configuration:
560  (++) Data Size
561  (++) Clock Polarity
562  (++) Audio Frequency
563 
564  (+) Call the function hal_i2s_deinit() to restore the default configuration
565  of the selected I2Sx peripheral.
566 
567 @endverbatim
568  * @{
569  */
570 
571 /**
572  ****************************************************************************************
573  * @brief Initialize the I2S according to the specified parameters
574  * in the i2s_init_t and initialize the associated handle.
575  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
576  * @retval ::HAL_OK: Operation is OK.
577  * @retval ::HAL_ERROR: Parameter error or operation not supported.
578  * @retval ::HAL_BUSY: Driver is busy.
579  * @retval ::HAL_TIMEOUT: Timeout occurred.
580  ****************************************************************************************
581  */
583 
584 /**
585  ****************************************************************************************
586  * @brief De-initialize the I2S peripheral.
587  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
588  * @retval ::HAL_OK: Operation is OK.
589  * @retval ::HAL_ERROR: Parameter error or operation not supported.
590  * @retval ::HAL_BUSY: Driver is busy.
591  * @retval ::HAL_TIMEOUT: Timeout occurred.
592  ****************************************************************************************
593  */
595 
596 /**
597  ****************************************************************************************
598  * @brief Initialize the I2S MSP.
599  * @note This function should not be modified. When the callback is needed,
600  the hal_i2s_msp_deinit can be implemented in the user file.
601  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
602  ****************************************************************************************
603  */
605 
606 /**
607  ****************************************************************************************
608  * @brief De-initialize the I2S MSP.
609  * @note This function should not be modified. When the callback is needed,
610  the hal_i2s_msp_deinit can be implemented in the user file.
611  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
612  ****************************************************************************************
613  */
615 
616 /** @} */
617 
618 /** @defgroup I2S_Exported_Functions_Group2 IO operation functions
619  * @brief Data transfers functions
620  *
621 @verbatim
622  ==============================================================================
623  ##### IO operation functions #####
624  ===============================================================================
625  [..]
626  This subsection provides a set of functions allowing to manage the I2S
627  data transfers.
628 
629  [..] The I2S supports master and slave mode:
630 
631  (#) There are two modes of transfer:
632  (++) Blocking mode: The communication is performed in polling mode.
633  The HAL status of all data processing is returned by the same function
634  after finishing transfer.
635  (++) No-Blocking mode: The communication is performed using Interrupts
636  or DMA, These APIs return the HAL status.
637  The end of the data processing will be indicated through the
638  dedicated I2S IRQ when using Interrupt mode or the DMA IRQ when
639  using DMA mode.
640  The hal_i2s_tx_cplt_callback(), hal_i2s_rx_cplt_callback() and hal_i2s_tx_rx_cplt_callback() user callbacks
641  will be executed respectively at the end of the transmit or Receive process
642  The hal_i2s_error_callback() user callback will be executed when a communication error is detected.
643 
644  (#) APIs provided for these 2 transfer modes (Blocking mode or Non blocking mode using either Interrupt or DMA)
645  exist for 1-Line (simplex) and 2-Line (full duplex) modes.
646 
647 @endverbatim
648  * @{
649  */
650 
651 /**
652  ****************************************************************************************
653  * @brief Transmit an amount of data in blocking mode.
654  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
655  * @param[in] p_data: Pointer to data buffer
656  * @param[in] length: Amount of data to be sent in halfword, data of a channel.
657  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
658  * @param[in] timeout: Timeout duration
659  * @retval ::HAL_OK: Operation is OK.
660  * @retval ::HAL_ERROR: Parameter error or operation not supported.
661  * @retval ::HAL_BUSY: Driver is busy.
662  * @retval ::HAL_TIMEOUT: Timeout occurred.
663  ****************************************************************************************
664  */
665 hal_status_t hal_i2s_transmit(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length, uint32_t timeout);
666 
667 /**
668  ****************************************************************************************
669  * @brief Receive an amount of data in blocking mode.
670  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
671  * @param[out] p_data: Pointer to data buffer
672  * @param[in] length: Amount of data to be received in halfword, data of a channel.
673  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
674  * @param[in] timeout: Timeout duration
675  * @retval ::HAL_OK: Operation is OK.
676  * @retval ::HAL_ERROR: Parameter error or operation not supported.
677  * @retval ::HAL_BUSY: Driver is busy.
678  * @retval ::HAL_TIMEOUT: Timeout occurred.
679  ****************************************************************************************
680  */
681 hal_status_t hal_i2s_receive(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length, uint32_t timeout);
682 
683 /**
684  ****************************************************************************************
685  * @brief Transmit and Receive an amount of data in blocking mode.
686  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration information for the specified I2S module.
687  * @param[in] p_tx_data: Pointer to transmission data buffer
688  * @param[out] p_rx_data: Pointer to reception data buffer
689  * @param[in] length: Amount of data to be sent and received in bytes
690  * @param[in] timeout: Timeout duration
691  * @retval ::HAL_OK: Operation is OK.
692  * @retval ::HAL_ERROR: Parameter error or operation not supported.
693  * @retval ::HAL_BUSY: Driver is busy.
694  * @retval ::HAL_TIMEOUT: Timeout occurred.
695  ****************************************************************************************
696  */
697 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);
698 
699 /**
700  ****************************************************************************************
701  * @brief Transmit an amount of data in non-blocking mode with Interrupt.
702  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
703  * @param[in] p_data: Pointer to data buffer
704  * @param[in] length: Amount of data to be sent in halfword, data of a channel.
705  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
706  * @retval ::HAL_OK: Operation is OK.
707  * @retval ::HAL_ERROR: Parameter error or operation not supported.
708  * @retval ::HAL_BUSY: Driver is busy.
709  * @retval ::HAL_TIMEOUT: Timeout occurred.
710  ****************************************************************************************
711  */
712 hal_status_t hal_i2s_transmit_it(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length);
713 
714 /**
715  ****************************************************************************************
716  * @brief Receive an amount of data in non-blocking mode with Interrupt.
717  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
718  * @param[out] p_data: Pointer to data buffer
719  * @param[in] length: Amount of data to be sent in halfword, data of a channel.
720  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
721  * @retval ::HAL_OK: Operation is OK.
722  * @retval ::HAL_ERROR: Parameter error or operation not supported.
723  * @retval ::HAL_BUSY: Driver is busy.
724  * @retval ::HAL_TIMEOUT: Timeout occurred.
725  ****************************************************************************************
726  */
727 hal_status_t hal_i2s_receive_it(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length);
728 
729 /**
730  ****************************************************************************************
731  * @brief Transmit and Receive an amount of data in non-blocking mode with Interrupt.
732  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration information for the specified SPI module.
733  * @param[in] p_tx_data: Pointer to transmission data buffer
734  * @param[out] p_rx_data: Pointer to reception data buffer
735  * @param[in] length: Amount of data to be sent and received in bytes
736  * @retval ::HAL_OK: Operation is OK.
737  * @retval ::HAL_ERROR: Parameter error or operation not supported.
738  * @retval ::HAL_BUSY: Driver is busy.
739  * @retval ::HAL_TIMEOUT: Timeout occurred.
740  ****************************************************************************************
741  */
742 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);
743 
744 /**
745  ****************************************************************************************
746  * @brief Transmit an amount of data in non-blocking mode with DMA.
747  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
748  * @param[in] p_data: Pointer to data buffer
749  * @param[in] length: Amount of data to be sent in halfword, data of a channel, ranging between 1 and 4095.
750  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
751  * @retval ::HAL_OK: Operation is OK.
752  * @retval ::HAL_ERROR: Parameter error or operation not supported.
753  * @retval ::HAL_BUSY: Driver is busy.
754  * @retval ::HAL_TIMEOUT: Timeout occurred.
755  ****************************************************************************************
756  */
757 hal_status_t hal_i2s_transmit_dma(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length);
758 
759 /**
760  ****************************************************************************************
761  * @brief Receive an amount of data in non-blocking mode with DMA.
762  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
763  * @param[out] p_data: Pointer to data buffer
764  * @param[in] length: Amount of data to be sent in halfword, data of a channel, ranging between 1 and 4095.
765  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
766  * @retval ::HAL_OK: Operation is OK.
767  * @retval ::HAL_ERROR: Parameter error or operation not supported.
768  * @retval ::HAL_BUSY: Driver is busy.
769  * @retval ::HAL_TIMEOUT: Timeout occurred.
770  ****************************************************************************************
771  */
772 hal_status_t hal_i2s_receive_dma(i2s_handle_t *p_i2s, uint16_t *p_data, uint32_t length);
773 
774 /**
775  ****************************************************************************************
776  * @brief Transmit and Receive an amount of data in non-blocking mode with DMA.
777  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration information for the specified I2S module.
778  * @param[in] p_tx_data: Pointer to transmission data buffer
779  * @param[out] p_rx_data: Pointer to reception data buffer
780  * @param[in] length: Amount of data to be sent in bytes, ranging between 0 and 4095.
781  * @retval ::HAL_OK: Operation is OK.
782  * @retval ::HAL_ERROR: Parameter error or operation not supported.
783  * @retval ::HAL_BUSY: Driver is busy.
784  * @retval ::HAL_TIMEOUT: Timeout occurred.
785  ****************************************************************************************
786  */
787 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);
788 
789 /**
790  ****************************************************************************************
791  * @brief Transmit an amount of data in non-blocking mode with DMA.
792  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
793  * @param[in] p_data: Pointer to data buffer
794  * @param[in] length: Amount of data to be sent in halfword, data of a channel, ranging between 1 and 4095.
795  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
796  * @param[in] p_sg_llp_config: Pointer to the config of source and destination's SG and LLP.
797  * @retval ::HAL_OK: Operation is OK.
798  * @retval ::HAL_ERROR: Parameter error or operation not supported.
799  * @retval ::HAL_BUSY: Driver is busy.
800  * @retval ::HAL_TIMEOUT: Timeout occurred.
801  ****************************************************************************************
802  */
803 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);
804 
805 /**
806  ****************************************************************************************
807  * @brief Receive an amount of data in non-blocking mode with DMA.
808  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
809  * @param[out] p_data: Pointer to data buffer
810  * @param[in] length: Amount of data to be sent in halfword, data of a channel, ranging between 1 and 4095.
811  * For example, when 32 bytes of data need to be sent in each of the left and right channels, length = 16.
812  * @param[in] p_sg_llp_config: Pointer to the config of source and destination's SG and LLP.
813  * @retval ::HAL_OK: Operation is OK.
814  * @retval ::HAL_ERROR: Parameter error or operation not supported.
815  * @retval ::HAL_BUSY: Driver is busy.
816  * @retval ::HAL_TIMEOUT: Timeout occurred.
817  ****************************************************************************************
818  */
819 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);
820 
821 /**
822  ****************************************************************************************
823  * @brief Transmit and Receive an amount of data in non-blocking mode with DMA.
824  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration information for the specified I2S module.
825  * @param[in] p_tx_data: Pointer to transmission data buffer
826  * @param[out] p_rx_data: Pointer to reception data buffer
827  * @param[in] length: Amount of data to be sent in bytes, ranging between 0 and 4095.
828  * @param[in] p_sg_llp_config: Pointer to the config of source and destination's SG and LLP.
829  * @retval ::HAL_OK: Operation is OK.
830  * @retval ::HAL_ERROR: Parameter error or operation not supported.
831  * @retval ::HAL_BUSY: Driver is busy.
832  * @retval ::HAL_TIMEOUT: Timeout occurred.
833  ****************************************************************************************
834  */
836  uint16_t *p_tx_data,
837  uint16_t *p_rx_data,
838  uint32_t length,
839  dma_sg_llp_config_t *p_sg_llp_config);
840 
841 
842 /**
843  ****************************************************************************************
844  * @brief Start the I2S master clock.
845  * @note In case of SLAVE mode, this function will not take effect.
846  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
847  * @retval ::HAL_OK: Operation is OK.
848  * @retval ::HAL_ERROR: Parameter error or operation not supported.
849  * @retval ::HAL_BUSY: Driver is busy.
850  * @retval ::HAL_TIMEOUT: Timeout occurred.
851  ****************************************************************************************
852  */
854 
855 /**
856  ****************************************************************************************
857  * @brief Stop the I2S master clock.
858  * @note In case of SLAVE mode, this function will not take effect.
859  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
860  * @retval ::HAL_OK: Operation is OK.
861  * @retval ::HAL_ERROR: Parameter error or operation not supported.
862  * @retval ::HAL_BUSY: Driver is busy.
863  * @retval ::HAL_TIMEOUT: Timeout occurred.
864  ****************************************************************************************
865  */
867 
868 /**
869  ****************************************************************************************
870  * @brief Abort ongoing transfer (blocking mode).
871  * @param[in] p_i2s: I2S handle.
872  * @note This procedure could be used for aborting any ongoing transfer (TX and RX),
873  * started in Interrupt or DMA mode.
874  * This procedure performs following operations :
875  * - Disable I2S Interrupts (depending of transfer direction)
876  * - Disable the DMA transfer in the peripheral register (if enabled)
877  * - Abort DMA transfer by calling hal_dma_abort (in case of transfer in DMA mode)
878  * - Set handle State to READY
879  * @note This procedure is executed in blocking mode: When exiting function, Abort is considered as completed.
880  * @retval ::HAL_OK: Operation is OK.
881  * @retval ::HAL_ERROR: Parameter error or operation not supported.
882  * @retval ::HAL_BUSY: Driver is busy.
883  * @retval ::HAL_TIMEOUT: Timeout occurred.
884  ****************************************************************************************
885  */
887 
888 /** @} */
889 
890 /** @addtogroup I2S_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
891  * @brief IRQ Handler and Callbacks functions
892  * @{
893  */
894 
895 /**
896  ****************************************************************************************
897  * @brief Handle I2S interrupt request.
898  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
899  ****************************************************************************************
900  */
902 
903 /**
904  ****************************************************************************************
905  * @brief TX Transfer completed callback.
906  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
907  ****************************************************************************************
908  */
910 
911 /**
912  ****************************************************************************************
913  * @brief RX Transfer completed callback.
914  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
915  ****************************************************************************************
916  */
918 
919 /**
920  ****************************************************************************************
921  * @brief TX/RX Transfer completed callback.
922  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
923  ****************************************************************************************
924  */
926 
927 /**
928  ****************************************************************************************
929  * @brief I2S error callback.
930  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
931  ****************************************************************************************
932  */
934 
935 /** @} */
936 
937 /** @defgroup I2S_Exported_Functions_Group3 Peripheral State and Errors functions
938  * @brief I2S control functions
939  *
940 @verbatim
941  ===============================================================================
942  ##### Peripheral State and Errors functions #####
943  ===============================================================================
944  [..]
945  This subsection provides a set of functions allowing to control the I2S.
946  (+) hal_i2s_get_state() API can be helpful to check in run-time the state of the I2S peripheral
947  (+) hal_i2s_get_error() check in run-time Errors occurring during communication
948  (+) hal_i2s_set_timeout() set the timeout during internal process
949  (+) hal_i2s_set_tx_fifo_threshold() set the TX FIFO Threshold
950  (+) hal_i2s_set_rx_fifo_threshold() set the RX FIFO Threshold
951  (+) hal_i2s_get_tx_fifo_threshold() get the TX FIFO Threshold
952  (+) hal_i2s_get_rx_fifo_threshold() get the RX FIFO Threshold
953 @endverbatim
954  * @{
955  */
956 
957 /**
958  ****************************************************************************************
959  * @brief Return the I2S handle state.
960  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
961  * @retval ::HAL_I2S_STATE_RESET: Peripheral not initialized.
962  * @retval ::HAL_I2S_STATE_READY: Peripheral initialized and ready for use.
963  * @retval ::HAL_I2S_STATE_BUSY: An internal process is ongoing.
964  * @retval ::HAL_I2S_STATE_BUSY_TX: Data Transmii2son process is ongoing.
965  * @retval ::HAL_I2S_STATE_BUSY_RX: Data Reception process is ongoing.
966  * @retval ::HAL_I2S_STATE_ABORT: Peripheral with abort request ongoing.
967  * @retval ::HAL_I2S_STATE_ERROR: Peripheral in error.
968  ****************************************************************************************
969  */
971 
972 /**
973  ****************************************************************************************
974  * @brief Return the I2S error code.
975  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
976  * @return I2S error code in bitmap format
977  ****************************************************************************************
978  */
980 
981 /**
982  ****************************************************************************************
983  * @brief Set the TX FIFO threshold.
984  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
985  * @param[in] threshold: TX FIFO threshold value ranging bwtween 0x0U ~ 0x7U.
986  * @retval ::HAL_OK: Operation is OK.
987  * @retval ::HAL_ERROR: Parameter error or operation not supported.
988  * @retval ::HAL_BUSY: Driver is busy.
989  * @retval ::HAL_TIMEOUT: Timeout occurred.
990  ****************************************************************************************
991  */
993 
994 /**
995  ****************************************************************************************
996  * @brief Set the RX FIFO threshold.
997  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
998  * @param[in] threshold: RX FIFO threshold value ranging bwtween 0x0U ~ 0x7U.
999  * @retval ::HAL_OK: Operation is OK.
1000  * @retval ::HAL_ERROR: Parameter error or operation not supported.
1001  * @retval ::HAL_BUSY: Driver is busy.
1002  * @retval ::HAL_TIMEOUT: Timeout occurred.
1003  ****************************************************************************************
1004  */
1006 
1007 /**
1008  ****************************************************************************************
1009  * @brief Get the TX FIFO threshold.
1010  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
1011  * @return TX FIFO threshold
1012  ****************************************************************************************
1013  */
1015 
1016 /**
1017  ****************************************************************************************
1018  * @brief Get the RX FIFO threshold.
1019  * @param[in] p_i2s: Pointer to an I2S handle which contains the configuration information for the specified I2S module.
1020  * @return RX FIFO threshold
1021  ****************************************************************************************
1022  */
1024 
1025 /**
1026  ****************************************************************************************
1027  * @brief Suspend some registers related to I2S configuration before sleep.
1028  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration
1029  * information for the specified I2S module.
1030  * @retval ::HAL_OK: Operation is OK.
1031  * @retval ::HAL_ERROR: Parameter error or operation not supported.
1032  * @retval ::HAL_BUSY: Driver is busy.
1033  * @retval ::HAL_TIMEOUT: Timeout occurred.
1034  ****************************************************************************************
1035  */
1037 
1038 /**
1039  ****************************************************************************************
1040  * @brief Restore some registers related to I2S configuration after sleep.
1041  * This function must be used in conjunction with the hal_i2s_suspend_reg().
1042  * @param[in] p_i2s: Pointer to a I2S handle which contains the configuration
1043  * information for the specified I2S module.
1044  * @retval ::HAL_OK: Operation is OK.
1045  * @retval ::HAL_ERROR: Parameter error or operation not supported.
1046  * @retval ::HAL_BUSY: Driver is busy.
1047  * @retval ::HAL_TIMEOUT: Timeout occurred.
1048  ****************************************************************************************
1049  */
1051 
1052 
1053 /** @} */
1054 
1055 /** @} */
1056 
1057 #ifdef __cplusplus
1058 }
1059 #endif
1060 
1061 #endif /* __GR55xx_HAL_I2S_H__ */
1062 
1063 /** @} */
1064 
1065 /** @} */
1066 
1067 /** @} */
_i2s_init::data_size
uint32_t data_size
Definition: gr55xx_hal_i2s.h:105
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_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.
_hal_i2s_callback::i2s_tx_cplt_callback
void(* i2s_tx_cplt_callback)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:190
_hal_i2s_callback::i2s_msp_init
void(* i2s_msp_init)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:186
_hal_i2s_callback::i2s_msp_deinit
void(* i2s_msp_deinit)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:187
_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_callback::i2s_tx_rx_cplt_callback
void(* i2s_tx_rx_cplt_callback)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:191
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
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_callback::i2s_rx_cplt_callback
void(* i2s_rx_cplt_callback)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:189
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_i2s_callback
HAL_I2S Callback function definition.
Definition: gr55xx_hal_i2s.h:185
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_callback::i2s_error_callback
void(* i2s_error_callback)(i2s_handle_t *p_i2s)
Definition: gr55xx_hal_i2s.h:188
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.
hal_i2s_callback_t
struct _hal_i2s_callback hal_i2s_callback_t
HAL_I2S Callback function definition.
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.
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.