app_i2s.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file app_i2s.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of I2S app 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 APP_DRIVER APP DRIVER
43  * @{
44  */
45 
46 /** @defgroup APP_I2S I2S
47  * @brief I2S APP module driver.
48  * @{
49  */
50 
51 
52 #ifndef _APP_I2S_H_
53 #define _APP_I2S_H_
54 
55 #include <stdbool.h>
56 #include "grx_hal.h"
57 #include "app_io.h"
58 #include "app_dma.h"
59 #include "app_drv_error.h"
60 #include "app_drv_config.h"
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 #ifdef HAL_I2S_MODULE_ENABLED
67 
68 /** @addtogroup APP_I2S_ENUM Enumerations
69  * @{
70  */
71 
72 /**
73  * @brief I2S module Enumerations definition
74  */
75 typedef enum
76 {
77  APP_I2S_ID_SLAVE, /**< I2S slave module. */
78  APP_I2S_ID_MASTER, /**< I2S master module. */
79  APP_I2S_ID_MAX /**< Only for check parameter, not used as input parameters. */
81 
82 /**
83  * @brief I2S event Enumerations definition
84  */
85 typedef enum
86 {
87  APP_I2S_EVT_ERROR, /**< Error reported by UART peripheral. */
88  APP_I2S_EVT_TX_CPLT, /**< Requested TX transfer completed. */
89  APP_I2S_EVT_RX_DATA, /**< Requested RX transfer completed. */
90  APP_I2S_EVT_TX_RX, /**< Requested TX/RX transfer completed. */
92 /** @} */
93 
94 
95 /** @addtogroup APP_I2S_STRUCTURES Structures
96  * @{
97  */
98 
99 /**
100  * @brief I2S pins Structures
101  */
102 typedef struct
103 {
104  app_io_type_t type; /**< Specifies the type of I2S IO. */
105  app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
106  uint32_t pin; /**< Specifies the IO pins to be configured.
107  This parameter can be any value of @ref GR5xxx_pins. */
108  app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
109 } app_i2s_pin_t;
110 
111 /**
112  * @brief I2S pins config Structures
113  */
114 typedef struct
115 {
116  app_i2s_pin_t ws; /**< Set the configuration of I2S WS pin. */
117  app_i2s_pin_t sdo; /**< Set the configuration of I2S SDO pin. */
118  app_i2s_pin_t sdi; /**< Set the configuration of I2S SDI pin. */
119  app_i2s_pin_t sclk; /**< Set the configuration of I2S SCLK pin. */
121 
122 /**
123  * @brief I2S operate mode Enumerations definition
124  */
125 typedef struct
126 {
127  dma_regs_t *tx_dma_instance;/**< Specifies the TX DMA instance.*/
128  dma_regs_t *rx_dma_instance;/**< Specifies the RX DMA instance.*/
129  dma_channel_t tx_dma_channel; /**< Specifies the dma channel of I2S TX. */
130  dma_channel_t rx_dma_channel; /**< Specifies the dma channel of I2S RX. */
132 
133 /**
134  * @brief I2S event structure definition
135  */
136 typedef struct
137 {
138  app_i2s_evt_type_t type; /**< Type of event. */
139  union
140  {
141  uint32_t error_code; /**< I2S Error code . */
142  uint16_t size; /**< I2S transmitted/received counter. */
143  } data; /**< Data of event. */
144 } app_i2s_evt_t;
145 
146 /** @} */
147 
148 /** @addtogroup APP_I2S_ENUM Enumerations
149  * @{
150  */
151 /**@brief App i2s state types. */
152 typedef enum
153 {
156 #ifdef APP_DRIVER_WAKEUP_CALL_FUN
157  APP_I2S_SLEEP,
158 #endif
160 
161 
162 /**@brief App i2s dma state types. */
163 typedef enum
164 {
168 
169 /** @} */
170 
171 /** @addtogroup APP_I2S_TYPEDEFS Type definitions
172  * @{
173  */
174 /**
175  * @brief I2S event callback definition
176  */
177 typedef void (*app_i2s_evt_handler_t)(app_i2s_evt_t *p_evt);
178 
179 /** @} */
180 
181 /** @addtogroup APP_I2S_STRUCTURES Structures
182  * @{
183  */
184 /**
185  * @brief I2S device structure definition
186  */
187 typedef struct
188 {
189  app_i2s_evt_handler_t evt_handler; /**< I2S event callback definition. */
190  i2s_handle_t handle; /**< I2S handle definition. */
191  app_i2s_pin_cfg_t *p_pin_cfg; /**< I2S pins config Structures. */
192  dma_id_t dma_id[2]; /**< DMA id definition. */
193  app_i2s_state_t i2s_state; /**< I2S state types. */
194  app_i2s_dma_state_t i2s_dma_state; /**< I2S dma state types. */
195  bool start_flag; /**< Start flag definition. */
196 } i2s_env_t;
197 
198 /**
199  * @brief I2S parameters structure definition
200  */
201 typedef struct
202 {
203  app_i2s_id_t id; /**< specified I2S module ID. */
204  app_i2s_pin_cfg_t pin_cfg; /**< the pin configuration information for the specified I2S module. */
205  app_i2s_dma_cfg_t dma_cfg; /**< I2S operate mode Enumerations definition. */
206  i2s_init_t init; /**< I2S communication parameters. */
207  i2s_env_t i2s_env; /**< I2S device structure definition. */
209 
210 /** @} */
211 
212 /* Exported functions --------------------------------------------------------*/
213 /** @addtogroup HAL_APP_I2S_DRIVER_FUNCTIONS Functions
214  * @{
215  */
216 
217 /**
218  ****************************************************************************************
219  * @brief Initialize the APP I2S DRIVER according to the specified parameters
220  * in the app_i2s_params_t and app_i2s_evt_handler_t.
221  * @note If interrupt mode is set, you can use blocking mode. Conversely, if blocking mode
222  * is set, you can't use interrupt mode.
223  *
224  * @param[in] p_params: Pointer to app_i2s_params_t parameter which contains the
225  * configuration information for the specified I2S module.
226  * @param[in] evt_handler: I2S user callback function.
227  *
228  * @return Result of initialization.
229  ****************************************************************************************
230  */
231 uint16_t app_i2s_init(app_i2s_params_t *p_params, app_i2s_evt_handler_t evt_handler);
232 
233 /**
234  ****************************************************************************************
235  * @brief De-initialize the APP I2S DRIVER peripheral.
236  *
237  * @param[in] id: De-initialize for a specific ID.
238  *
239  * @return Result of De-initialization.
240  ****************************************************************************************
241  */
243 
244 /**
245  ****************************************************************************************
246  * @brief Receive in master or slave mode an amount of data in blocking mode.
247  *
248  * @param[in] id: which I2S module want to receive.
249  * @param[in] p_data: Pointer to data buffer
250  * @param[in] size: Amount of data to be sent
251  * @param[in] timeout: Timeout duration
252  *
253  * @return Result of operation.
254  ****************************************************************************************
255  */
256 uint16_t app_i2s_receive_sync(app_i2s_id_t id, uint16_t *p_data, uint16_t size, uint32_t timeout);
257 
258 /**
259  ****************************************************************************************
260  * @brief Receive in master or slave mode an amount of data in non-blocking mode with Interrupt
261  *
262  * @param[in] id: which I2S module want to receive.
263  * @param[in] p_data: Pointer to data buffer
264  * @param[in] size: Amount of data to be sent
265  *
266  * @return Result of operation.
267  ****************************************************************************************
268  */
269 uint16_t app_i2s_receive_async(app_i2s_id_t id, uint16_t *p_data, uint16_t size);
270 
271 /**
272  ****************************************************************************************
273  * @brief Transmits in master or slave mode an amount of data in blocking mode.
274  *
275  * @param[in] id: which I2S module want to transmit.
276  * @param[in] p_data: Pointer to data buffer
277  * @param[in] size: Amount of data to be sent
278  * @param[in] timeout: Timeout duration
279  *
280  * @return Result of operation.
281  ****************************************************************************************
282  */
283 uint16_t app_i2s_transmit_sync(app_i2s_id_t id, uint16_t *p_data, uint16_t size, uint32_t timeout);
284 
285 /**
286  ****************************************************************************************
287  * @brief Transmits in master or slave mode an amount of data in non-blocking mode with Interrupt
288  *
289  * @param[in] id: which I2S module want to transmit.
290  * @param[in] p_data: Pointer to data buffer
291  * @param[in] size: Amount of data to be sent
292  *
293  * @return Result of operation.
294  ****************************************************************************************
295  */
296 uint16_t app_i2s_transmit_async(app_i2s_id_t id, uint16_t *p_data, uint16_t size);
297 
298 /**
299  ****************************************************************************************
300  * @brief Enable the I2S module.
301  *
302  * @param[in] id: The I2S module id.
303  *
304  * @return Result of operation.
305  ****************************************************************************************
306  */
307 
309 
310 /**
311  ****************************************************************************************
312  * @brief Disable the I2S module.
313  *
314  * @param[in] id: The I2S module id.
315  *
316  * @return Result of operation.
317  ****************************************************************************************
318  */
320 
321 /**
322  ****************************************************************************************
323  * @brief Enable the master I2S clock.
324  *
325  * @param[in] id: The I2S master module id.
326  *
327  * @return Result of operation.
328  ****************************************************************************************
329  */
331 
332 /**
333  ****************************************************************************************
334  * @brief Disable the master I2S clock.
335  *
336  * @param[in] id: The I2S master module id.
337  *
338  * @return Result of operation.
339  ****************************************************************************************
340  */
342 
343 /**
344  ****************************************************************************************
345  * @brief Flush the I2S transmitter FIFO.
346  *
347  * @param[in] id: which I2S module want to flush.
348  *
349  * @return Result of operation.
350  ****************************************************************************************
351  */
353 
354 /**
355  ****************************************************************************************
356  * @brief Flush the I2S receiver FIFO.
357  *
358  * @param[in] id: which I2S module want to flush.
359  *
360  * @return Result of operation.
361  ****************************************************************************************
362  */
364 
365 /**
366  ****************************************************************************************
367  * @brief Return the I2S handle.
368  *
369  * @param[in] id: I2S Channel ID.
370  *
371  * @return Pointer to the specified ID's I2S handle.
372  ****************************************************************************************
373  */
375 
376 /**
377  ****************************************************************************************
378  * @brief Abort ongoing transfer (blocking mode).
379  * @param id I2S ID
380  * @note This procedure is executed in blocking mode: When exiting
381  * function, Abort is considered as completed.
382  * @retval ::APP_DRV_SUCCESS: Operation is OK.
383  * @retval ::HAL_ERROR: Parameter error or operation not supported.
384  * @retval ::HAL_BUSY: Driver is busy.
385  * @retval ::HAL_TIMEOUT: Timeout occurred.
386  * @retval ::APP_DRV_ERR_INVALID_PARAM: Parameter error.
387  ****************************************************************************************
388  */
390 
391 /**
392  ****************************************************************************************
393  * @brief Transmit and Receive an amount of data in blocking mode.
394  * @param id I2S ID
395  * @param p_tx_data Pointer to transmission data buffer
396  * @param[out] p_rx_data: Pointer to reception data buffer
397  * @param[in] length: Amount of data to be sent and received in bytes
398  * @param[in] timeout: Timeout duration
399  * @retval ::APP_DRV_SUCCESS: Operation is OK.
400  * @retval ::HAL_ERROR: Parameter error or operation not supported.
401  * @retval ::HAL_BUSY: Driver is busy.
402  * @retval ::HAL_TIMEOUT: Timeout occurred.
403  * @retval ::APP_DRV_ERR_INVALID_PARAM: Parameter error.
404  * @retval ::APP_DRV_ERR_BUSY: Driver is busy.
405  ****************************************************************************************
406  */
408  uint16_t *p_tx_data,
409  uint16_t *p_rx_data,
410  uint32_t length,
411  uint32_t timeout);
412 /**
413  ****************************************************************************************
414  * @brief Transmit and Receive an amount of data in non-blocking mode with Interrupt.
415  * @param[in] id: I2S ID
416  * @param[in] p_tx_data: Pointer to transmission data buffer
417  * @param[out] p_rx_data: Pointer to reception data buffer
418  * @param[in] length: Amount of data to be sent and received in bytes
419  * @retval ::APP_DRV_SUCCESS: Operation is OK.
420  * @retval ::HAL_ERROR: Parameter error or operation not supported.
421  * @retval ::HAL_BUSY: Driver is busy.
422  * @retval ::HAL_TIMEOUT: Timeout occurred.
423  * @retval ::APP_DRV_ERR_INVALID_PARAM: Parameter error.
424  * @retval ::APP_DRV_ERR_BUSY: Driver is busy.
425  ****************************************************************************************
426  */
428  uint16_t *p_tx_data,
429  uint16_t *p_rx_data,
430  uint32_t length);
431 
432 /** @} */
433 
434 #endif
435 
436 #ifdef __cplusplus
437 }
438 #endif
439 
440 #endif
441 
442 /** @} */
443 /** @} */
444 /** @} */
445 
446 
i2s_env_t::handle
i2s_handle_t handle
Definition: app_i2s.h:190
app_i2s_params_t::id
app_i2s_id_t id
Definition: app_i2s.h:203
app_i2s_pin_t::mux
app_io_mux_t mux
Definition: app_i2s.h:105
app_i2s_transmit_sync
uint16_t app_i2s_transmit_sync(app_i2s_id_t id, uint16_t *p_data, uint16_t size, uint32_t timeout)
Transmits in master or slave mode an amount of data in blocking mode.
i2s_env_t::start_flag
bool start_flag
Definition: app_i2s.h:195
APP_I2S_DMA_ACTIVITY
@ APP_I2S_DMA_ACTIVITY
Definition: app_i2s.h:166
app_i2s_pin_cfg_t
I2S pins config Structures.
Definition: app_i2s.h:115
app_i2s_enable_clock
uint16_t app_i2s_enable_clock(app_i2s_id_t id)
Enable the master I2S clock.
app_i2s_flush_tx_fifo
uint16_t app_i2s_flush_tx_fifo(app_i2s_id_t id)
Flush the I2S transmitter FIFO.
app_i2s_params_t
I2S parameters structure definition.
Definition: app_i2s.h:202
APP_I2S_ID_MAX
@ APP_I2S_ID_MAX
Definition: app_i2s.h:79
APP_I2S_DMA_INVALID
@ APP_I2S_DMA_INVALID
Definition: app_i2s.h:165
app_i2s_evt_t::error_code
uint32_t error_code
Definition: app_i2s.h:141
app_i2s_pin_cfg_t::sdi
app_i2s_pin_t sdi
Definition: app_i2s.h:118
app_i2s_evt_type_t
app_i2s_evt_type_t
I2S event Enumerations definition.
Definition: app_i2s.h:86
app_i2s_evt_t::size
uint16_t size
Definition: app_i2s.h:142
app_i2s_evt_handler_t
void(* app_i2s_evt_handler_t)(app_i2s_evt_t *p_evt)
I2S event callback definition.
Definition: app_i2s.h:177
i2s_env_t
I2S device structure definition.
Definition: app_i2s.h:188
app_io_pull_t
app_io_pull_t
GPIO pull Enumerations definition.
Definition: app_io.h:183
app_io_type_t
app_io_type_t
GPIO type Enumerations definition.
Definition: app_io.h:147
app_i2s_deinit
uint16_t app_i2s_deinit(app_i2s_id_t id)
De-initialize the APP I2S DRIVER peripheral.
app_i2s_pin_cfg_t::sdo
app_i2s_pin_t sdo
Definition: app_i2s.h:117
app_i2s_params_t::i2s_env
i2s_env_t i2s_env
Definition: app_i2s.h:207
app_i2s_dma_cfg_t::rx_dma_channel
dma_channel_t rx_dma_channel
Definition: app_i2s.h:130
app_i2s_disable
uint16_t app_i2s_disable(app_i2s_id_t id)
Disable the I2S module.
app_i2s_flush_rx_fifo
uint16_t app_i2s_flush_rx_fifo(app_i2s_id_t id)
Flush the I2S receiver FIFO.
APP_I2S_ID_SLAVE
@ APP_I2S_ID_SLAVE
Definition: app_i2s.h:77
APP_I2S_ID_MASTER
@ APP_I2S_ID_MASTER
Definition: app_i2s.h:78
app_i2s_receive_sync
uint16_t app_i2s_receive_sync(app_i2s_id_t id, uint16_t *p_data, uint16_t size, uint32_t timeout)
Receive in master or slave mode an amount of data in blocking mode.
app_i2s_state_t
app_i2s_state_t
App i2s state types.
Definition: app_i2s.h:153
app_i2s_dma_state_t
app_i2s_dma_state_t
App i2s dma state types.
Definition: app_i2s.h:164
APP_I2S_EVT_RX_DATA
@ APP_I2S_EVT_RX_DATA
Definition: app_i2s.h:89
app_io.h
Header file containing functions prototypes of GPIO app library.
app_i2s_transmit_async
uint16_t app_i2s_transmit_async(app_i2s_id_t id, uint16_t *p_data, uint16_t size)
Transmits in master or slave mode an amount of data in non-blocking mode with Interrupt.
app_i2s_pin_t::pin
uint32_t pin
Definition: app_i2s.h:106
app_i2s_evt_t::type
app_i2s_evt_type_t type
Definition: app_i2s.h:138
app_i2s_abort
uint16_t app_i2s_abort(app_i2s_id_t id)
Abort ongoing transfer (blocking mode).
app_i2s_id_t
app_i2s_id_t
I2S module Enumerations definition.
Definition: app_i2s.h:76
app_i2s_params_t::pin_cfg
app_i2s_pin_cfg_t pin_cfg
Definition: app_i2s.h:204
i2s_env_t::evt_handler
app_i2s_evt_handler_t evt_handler
Definition: app_i2s.h:189
app_i2s_pin_t::pull
app_io_pull_t pull
Definition: app_i2s.h:108
app_i2s_evt_t
I2S event structure definition.
Definition: app_i2s.h:137
app_i2s_dma_cfg_t
I2S operate mode Enumerations definition.
Definition: app_i2s.h:126
i2s_env_t::i2s_state
app_i2s_state_t i2s_state
Definition: app_i2s.h:193
app_i2s_pin_cfg_t::ws
app_i2s_pin_t ws
Definition: app_i2s.h:116
_i2s_handle
I2S handle Structure definition.
Definition: gr55xx_hal_i2s.h:133
app_i2s_params_t::dma_cfg
app_i2s_dma_cfg_t dma_cfg
Definition: app_i2s.h:205
grx_hal.h
This file contains all the functions prototypes for the HAL module driver.
app_i2s_pin_t::type
app_io_type_t type
Definition: app_i2s.h:104
app_i2s_pin_t
I2S pins Structures.
Definition: app_i2s.h:103
app_i2s_dma_cfg_t::tx_dma_channel
dma_channel_t tx_dma_channel
Definition: app_i2s.h:129
APP_I2S_EVT_TX_CPLT
@ APP_I2S_EVT_TX_CPLT
Definition: app_i2s.h:88
app_i2s_pin_cfg_t::sclk
app_i2s_pin_t sclk
Definition: app_i2s.h:119
app_i2s_init
uint16_t app_i2s_init(app_i2s_params_t *p_params, app_i2s_evt_handler_t evt_handler)
Initialize the APP I2S DRIVER according to the specified parameters in the app_i2s_params_t and app_i...
app_i2s_dma_cfg_t::rx_dma_instance
dma_regs_t * rx_dma_instance
Definition: app_i2s.h:128
app_i2s_params_t::init
i2s_init_t init
Definition: app_i2s.h:206
i2s_env_t::i2s_dma_state
app_i2s_dma_state_t i2s_dma_state
Definition: app_i2s.h:194
_i2s_init
I2S init Structure definition.
Definition: gr55xx_hal_i2s.h:104
i2s_env_t::p_pin_cfg
app_i2s_pin_cfg_t * p_pin_cfg
Definition: app_i2s.h:191
app_dma.h
Header file containing functions prototypes of DMA app library.
app_i2s_enable
uint16_t app_i2s_enable(app_i2s_id_t id)
Enable the I2S module.
app_i2s_get_handle
i2s_handle_t * app_i2s_get_handle(app_i2s_id_t id)
Return the I2S handle.
APP_I2S_EVT_TX_RX
@ APP_I2S_EVT_TX_RX
Definition: app_i2s.h:90
app_i2s_disable_clock
uint16_t app_i2s_disable_clock(app_i2s_id_t id)
Disable the master I2S clock.
APP_I2S_INVALID
@ APP_I2S_INVALID
Definition: app_i2s.h:154
app_io_mux_t
app_io_mux_t
GPIO mux Enumerations definition.
Definition: app_io.h:255
APP_I2S_EVT_ERROR
@ APP_I2S_EVT_ERROR
Definition: app_i2s.h:87
APP_I2S_ACTIVITY
@ APP_I2S_ACTIVITY
Definition: app_i2s.h:155
app_drv_error.h
Header file of app driver error code.
app_drv_config.h
Header file of app driver config code.
app_i2s_transmit_receive_sync
uint16_t app_i2s_transmit_receive_sync(app_i2s_id_t id, 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.
dma_id_t
int16_t dma_id_t
DMA id definition.
Definition: app_dma.h:98
app_i2s_transmit_receive_async
uint16_t app_i2s_transmit_receive_async(app_i2s_id_t id, 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.
app_i2s_dma_cfg_t::tx_dma_instance
dma_regs_t * tx_dma_instance
Definition: app_i2s.h:127
app_i2s_receive_async
uint16_t app_i2s_receive_async(app_i2s_id_t id, uint16_t *p_data, uint16_t size)
Receive in master or slave mode an amount of data in non-blocking mode with Interrupt.
dma_channel_t
dma_channel_t
HAL DMA Channel Enumerations definition.
Definition: gr55xx_hal_dma.h:94