38
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * @file stm32f4xx_hal_sai.h
|
|
4 * @author MCD Application Team
|
|
5 * @version V1.2.0
|
|
6 * @date 26-December-2014
|
|
7 * @brief Header file of SAI HAL module.
|
|
8 ******************************************************************************
|
|
9 * @attention
|
|
10 *
|
|
11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
|
|
12 *
|
|
13 * Redistribution and use in source and binary forms, with or without modification,
|
|
14 * are permitted provided that the following conditions are met:
|
|
15 * 1. Redistributions of source code must retain the above copyright notice,
|
|
16 * this list of conditions and the following disclaimer.
|
|
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
18 * this list of conditions and the following disclaimer in the documentation
|
|
19 * and/or other materials provided with the distribution.
|
|
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
21 * may be used to endorse or promote products derived from this software
|
|
22 * without 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 ARE
|
|
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
34 *
|
|
35 ******************************************************************************
|
|
36 */
|
|
37
|
|
38 /* Define to prevent recursive inclusion -------------------------------------*/
|
|
39 #ifndef __STM32F4xx_HAL_SAI_H
|
|
40 #define __STM32F4xx_HAL_SAI_H
|
|
41
|
|
42 #ifdef __cplusplus
|
|
43 extern "C" {
|
|
44 #endif
|
|
45
|
|
46 /* Includes ------------------------------------------------------------------*/
|
|
47 #include "stm32f4xx_hal_def.h"
|
|
48
|
|
49 /** @addtogroup STM32F4xx_HAL_Driver
|
|
50 * @{
|
|
51 */
|
|
52 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
|
|
53
|
|
54 /** @addtogroup SAI
|
|
55 * @{
|
|
56 */
|
|
57
|
|
58 /* Exported types ------------------------------------------------------------*/
|
|
59 /** @defgroup SAI_Exported_Types SAI Exported Types
|
|
60 * @{
|
|
61 */
|
|
62
|
|
63 /**
|
|
64 * @brief HAL State structures definition
|
|
65 */
|
|
66 typedef enum
|
|
67 {
|
|
68 HAL_SAI_STATE_RESET = 0x00, /*!< SAI not yet initialized or disabled */
|
|
69 HAL_SAI_STATE_READY = 0x01, /*!< SAI initialized and ready for use */
|
|
70 HAL_SAI_STATE_BUSY = 0x02, /*!< SAI internal process is ongoing */
|
|
71 HAL_SAI_STATE_BUSY_TX = 0x12, /*!< Data transmission process is ongoing */
|
|
72 HAL_SAI_STATE_BUSY_RX = 0x22, /*!< Data reception process is ongoing */
|
|
73 HAL_SAI_STATE_TIMEOUT = 0x03, /*!< SAI timeout state */
|
|
74 HAL_SAI_STATE_ERROR = 0x04 /*!< SAI error state */
|
|
75
|
|
76 }HAL_SAI_StateTypeDef;
|
|
77
|
|
78 /**
|
|
79 * @brief SAI Init Structure definition
|
|
80 */
|
|
81 typedef struct
|
|
82 {
|
|
83 uint32_t Protocol; /*!< Specifies the SAI Block protocol.
|
|
84 This parameter can be a value of @ref SAI_Block_Protocol */
|
|
85
|
|
86 uint32_t AudioMode; /*!< Specifies the SAI Block audio Mode.
|
|
87 This parameter can be a value of @ref SAI_Block_Mode */
|
|
88
|
|
89 uint32_t DataSize; /*!< Specifies the SAI Block data size.
|
|
90 This parameter can be a value of @ref SAI_Block_Data_Size */
|
|
91
|
|
92 uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
|
|
93 This parameter can be a value of @ref SAI_Block_MSB_LSB_transmission */
|
|
94
|
|
95 uint32_t ClockStrobing; /*!< Specifies the SAI Block clock strobing edge sensitivity.
|
|
96 This parameter can be a value of @ref SAI_Block_Clock_Strobing */
|
|
97
|
|
98 uint32_t Synchro; /*!< Specifies SAI Block synchronization
|
|
99 This parameter can be a value of @ref SAI_Block_Synchronization */
|
|
100
|
|
101 uint32_t OutputDrive; /*!< Specifies when SAI Block outputs are driven.
|
|
102 This parameter can be a value of @ref SAI_Block_Output_Drive
|
|
103 @note this value has to be set before enabling the audio block
|
|
104 but after the audio block configuration. */
|
|
105
|
|
106 uint32_t NoDivider; /*!< Specifies whether master clock will be divided or not.
|
|
107 This parameter can be a value of @ref SAI_Block_NoDivider
|
|
108 @note: If bit NODIV in the SAI_xCR1 register is cleared, the frame length
|
|
109 should be aligned to a number equal to a power of 2, from 8 to 256.
|
|
110 If bit NODIV in the SAI_xCR1 register is set, the frame length can
|
|
111 take any of the values without constraint since the input clock of
|
|
112 the audio block should be equal to the bit clock.
|
|
113 There is no MCLK_x clock which can be output. */
|
|
114
|
|
115 uint32_t FIFOThreshold; /*!< Specifies SAI Block FIFO threshold.
|
|
116 This parameter can be a value of @ref SAI_Block_Fifo_Threshold */
|
|
117
|
|
118 uint32_t ClockSource; /*!< Specifies the SAI Block x Clock source.
|
|
119 This parameter can be a value of @ref SAI_Clock_Source
|
|
120 @note: If ClockSource is equal to SAI_CLKSource_Ext, the PLLI2S
|
|
121 and PLLSAI divisions factors will be ignored. */
|
|
122
|
|
123 uint32_t AudioFrequency; /*!< Specifies the audio frequency sampling.
|
|
124 This parameter can be a value of @ref SAI_Audio_Frequency */
|
|
125
|
|
126 }SAI_InitTypeDef;
|
|
127
|
|
128 /**
|
|
129 * @brief SAI Block Frame Init structure definition
|
|
130 */
|
|
131
|
|
132 typedef struct
|
|
133 {
|
|
134
|
|
135 uint32_t FrameLength; /*!< Specifies the Frame length, the number of SCK clocks for each audio frame.
|
|
136 This parameter must be a number between Min_Data = 8 and Max_Data = 256.
|
|
137 @note: If master clock MCLK_x pin is declared as an output, the frame length
|
|
138 should be aligned to a number equal to power of 2 in order to keep
|
|
139 in an audio frame, an integer number of MCLK pulses by bit Clock. */
|
|
140
|
|
141 uint32_t ActiveFrameLength; /*!< Specifies the Frame synchronization active level length.
|
|
142 This Parameter specifies the length in number of bit clock (SCK + 1)
|
|
143 of the active level of FS signal in audio frame.
|
|
144 This parameter must be a number between Min_Data = 1 and Max_Data = 128 */
|
|
145
|
|
146 uint32_t FSDefinition; /*!< Specifies the Frame synchronization definition.
|
|
147 This parameter can be a value of @ref SAI_Block_FS_Definition */
|
|
148
|
|
149 uint32_t FSPolarity; /*!< Specifies the Frame synchronization Polarity.
|
|
150 This parameter can be a value of @ref SAI_Block_FS_Polarity */
|
|
151
|
|
152 uint32_t FSOffset; /*!< Specifies the Frame synchronization Offset.
|
|
153 This parameter can be a value of @ref SAI_Block_FS_Offset */
|
|
154
|
|
155 }SAI_FrameInitTypeDef;
|
|
156
|
|
157 /**
|
|
158 * @brief SAI Block Slot Init Structure definition
|
|
159 */
|
|
160
|
|
161 typedef struct
|
|
162 {
|
|
163 uint32_t FirstBitOffset; /*!< Specifies the position of first data transfer bit in the slot.
|
|
164 This parameter must be a number between Min_Data = 0 and Max_Data = 24 */
|
|
165
|
|
166 uint32_t SlotSize; /*!< Specifies the Slot Size.
|
|
167 This parameter can be a value of @ref SAI_Block_Slot_Size */
|
|
168
|
|
169 uint32_t SlotNumber; /*!< Specifies the number of slot in the audio frame.
|
|
170 This parameter must be a number between Min_Data = 1 and Max_Data = 16 */
|
|
171
|
|
172 uint32_t SlotActive; /*!< Specifies the slots in audio frame that will be activated.
|
|
173 This parameter can be a value of @ref SAI_Block_Slot_Active */
|
|
174 }SAI_SlotInitTypeDef;
|
|
175
|
|
176 /**
|
|
177 * @brief SAI handle Structure definition
|
|
178 */
|
|
179 typedef struct
|
|
180 {
|
|
181 SAI_Block_TypeDef *Instance; /*!< SAI Blockx registers base address */
|
|
182
|
|
183 SAI_InitTypeDef Init; /*!< SAI communication parameters */
|
|
184
|
|
185 SAI_FrameInitTypeDef FrameInit; /*!< SAI Frame configuration parameters */
|
|
186
|
|
187 SAI_SlotInitTypeDef SlotInit; /*!< SAI Slot configuration parameters */
|
|
188
|
|
189 uint16_t *pTxBuffPtr; /*!< Pointer to SAI Tx transfer Buffer */
|
|
190
|
|
191 uint16_t TxXferSize; /*!< SAI Tx transfer size */
|
|
192
|
|
193 uint16_t TxXferCount; /*!< SAI Tx transfer counter */
|
|
194
|
|
195 uint16_t *pRxBuffPtr; /*!< Pointer to SAI Rx transfer buffer */
|
|
196
|
|
197 uint16_t RxXferSize; /*!< SAI Rx transfer size */
|
|
198
|
|
199 uint16_t RxXferCount; /*!< SAI Rx transfer counter */
|
|
200
|
|
201 DMA_HandleTypeDef *hdmatx; /*!< SAI Tx DMA handle parameters */
|
|
202
|
|
203 DMA_HandleTypeDef *hdmarx; /*!< SAI Rx DMA handle parameters */
|
|
204
|
|
205 HAL_LockTypeDef Lock; /*!< SAI locking object */
|
|
206
|
|
207 __IO HAL_SAI_StateTypeDef State; /*!< SAI communication state */
|
|
208
|
|
209 __IO uint32_t ErrorCode; /*!< SAI Error code */
|
|
210 }SAI_HandleTypeDef;
|
|
211
|
|
212 /**
|
|
213 * @}
|
|
214 */
|
|
215
|
|
216 /* Exported constants --------------------------------------------------------*/
|
|
217
|
|
218 /** @defgroup SAI_Exported_Constants SAI Exported Constants
|
|
219 * @{
|
|
220 */
|
|
221
|
|
222 /** @defgroup SAI_Error_Code SAI Error Code
|
|
223 * @{
|
|
224 */
|
|
225 #define HAL_SAI_ERROR_NONE ((uint32_t)0x00000000) /*!< No error */
|
|
226 #define HAL_SAI_ERROR_OVR ((uint32_t)0x00000001) /*!< Overrun Error */
|
|
227 #define HAL_SAI_ERROR_UDR ((uint32_t)0x00000002) /*!< Underrun error */
|
|
228 #define HAL_SAI_ERROR_TIMEOUT ((uint32_t)0x00000020) /*!< Timeout error */
|
|
229 /**
|
|
230 * @}
|
|
231 */
|
|
232
|
|
233 /** @defgroup SAI_Clock_Source SAI Clock Source
|
|
234 * @{
|
|
235 */
|
|
236 #define SAI_CLKSOURCE_PLLSAI ((uint32_t)RCC_SAIACLKSOURCE_PLLSAI)
|
|
237 #define SAI_CLKSOURCE_PLLI2S ((uint32_t)RCC_SAIACLKSOURCE_PLLI2S)
|
|
238 #define SAI_CLKSOURCE_EXT ((uint32_t)RCC_SAIACLKSOURCE_EXT)
|
|
239
|
|
240 /**
|
|
241 * @}
|
|
242 */
|
|
243
|
|
244 /** @defgroup SAI_Audio_Frequency SAI Audio Frequency
|
|
245 * @{
|
|
246 */
|
|
247 #define SAI_AUDIO_FREQUENCY_192K ((uint32_t)192000)
|
|
248 #define SAI_AUDIO_FREQUENCY_96K ((uint32_t)96000)
|
|
249 #define SAI_AUDIO_FREQUENCY_48K ((uint32_t)48000)
|
|
250 #define SAI_AUDIO_FREQUENCY_44K ((uint32_t)44100)
|
|
251 #define SAI_AUDIO_FREQUENCY_32K ((uint32_t)32000)
|
|
252 #define SAI_AUDIO_FREQUENCY_22K ((uint32_t)22050)
|
|
253 #define SAI_AUDIO_FREQUENCY_16K ((uint32_t)16000)
|
|
254 #define SAI_AUDIO_FREQUENCY_11K ((uint32_t)11025)
|
|
255 #define SAI_AUDIO_FREQUENCY_8K ((uint32_t)8000)
|
|
256
|
|
257 /**
|
|
258 * @}
|
|
259 */
|
|
260
|
|
261 /** @defgroup SAI_Block_Mode SAI Block Mode
|
|
262 * @{
|
|
263 */
|
|
264 #define SAI_MODEMASTER_TX ((uint32_t)0x00000000)
|
|
265 #define SAI_MODEMASTER_RX ((uint32_t)0x00000001)
|
|
266 #define SAI_MODESLAVE_TX ((uint32_t)0x00000002)
|
|
267 #define SAI_MODESLAVE_RX ((uint32_t)0x00000003)
|
|
268
|
|
269 /**
|
|
270 * @}
|
|
271 */
|
|
272
|
|
273 /** @defgroup SAI_Block_Protocol SAI Block Protocol
|
|
274 * @{
|
|
275 */
|
|
276 #define SAI_FREE_PROTOCOL ((uint32_t)0x00000000)
|
|
277 #define SAI_AC97_PROTOCOL ((uint32_t)SAI_xCR1_PRTCFG_1)
|
|
278
|
|
279 /**
|
|
280 * @}
|
|
281 */
|
|
282
|
|
283 /** @defgroup SAI_Block_Data_Size SAI Block Data Size
|
|
284 * @{
|
|
285 */
|
|
286 #define SAI_DATASIZE_8 ((uint32_t)0x00000040)
|
|
287 #define SAI_DATASIZE_10 ((uint32_t)0x00000060)
|
|
288 #define SAI_DATASIZE_16 ((uint32_t)0x00000080)
|
|
289 #define SAI_DATASIZE_20 ((uint32_t)0x000000A0)
|
|
290 #define SAI_DATASIZE_24 ((uint32_t)0x000000C0)
|
|
291 #define SAI_DATASIZE_32 ((uint32_t)0x000000E0)
|
|
292
|
|
293 /**
|
|
294 * @}
|
|
295 */
|
|
296
|
|
297 /** @defgroup SAI_Block_MSB_LSB_transmission SAI Block MSB LSB transmission
|
|
298 * @{
|
|
299 */
|
|
300 #define SAI_FIRSTBIT_MSB ((uint32_t)0x00000000)
|
|
301 #define SAI_FIRSTBIT_LSB ((uint32_t)SAI_xCR1_LSBFIRST)
|
|
302
|
|
303 /**
|
|
304 * @}
|
|
305 */
|
|
306
|
|
307 /** @defgroup SAI_Block_Clock_Strobing SAI Block Clock Strobing
|
|
308 * @{
|
|
309 */
|
|
310 #define SAI_CLOCKSTROBING_FALLINGEDGE ((uint32_t)0x00000000)
|
|
311 #define SAI_CLOCKSTROBING_RISINGEDGE ((uint32_t)SAI_xCR1_CKSTR)
|
|
312
|
|
313 /**
|
|
314 * @}
|
|
315 */
|
|
316
|
|
317 /** @defgroup SAI_Block_Synchronization SAI Block Synchronization
|
|
318 * @{
|
|
319 */
|
|
320 #define SAI_ASYNCHRONOUS ((uint32_t)0x00000000)
|
|
321 #define SAI_SYNCHRONOUS ((uint32_t)SAI_xCR1_SYNCEN_0)
|
|
322
|
|
323 /**
|
|
324 * @}
|
|
325 */
|
|
326
|
|
327 /** @defgroup SAI_Block_Output_Drive SAI Block Output Drive
|
|
328 * @{
|
|
329 */
|
|
330 #define SAI_OUTPUTDRIVE_DISABLE ((uint32_t)0x00000000)
|
|
331 #define SAI_OUTPUTDRIVE_ENABLE ((uint32_t)SAI_xCR1_OUTDRIV)
|
|
332
|
|
333 /**
|
|
334 * @}
|
|
335 */
|
|
336
|
|
337 /** @defgroup SAI_Block_NoDivider SAI Block NoDivider
|
|
338 * @{
|
|
339 */
|
|
340 #define SAI_MASTERDIVIDER_ENABLE ((uint32_t)0x00000000)
|
|
341 #define SAI_MASTERDIVIDER_DISABLE ((uint32_t)SAI_xCR1_NODIV)
|
|
342
|
|
343 /**
|
|
344 * @}
|
|
345 */
|
|
346
|
|
347
|
|
348 /** @defgroup SAI_Block_FS_Definition SAI Block FS Definition
|
|
349 * @{
|
|
350 */
|
|
351 #define SAI_FS_STARTFRAME ((uint32_t)0x00000000)
|
|
352 #define SAI_FS_CHANNEL_IDENTIFICATION ((uint32_t)SAI_xFRCR_FSDEF)
|
|
353
|
|
354 /**
|
|
355 * @}
|
|
356 */
|
|
357
|
|
358 /** @defgroup SAI_Block_FS_Polarity SAI Block FS Polarity
|
|
359 * @{
|
|
360 */
|
|
361 #define SAI_FS_ACTIVE_LOW ((uint32_t)0x00000000)
|
|
362 #define SAI_FS_ACTIVE_HIGH ((uint32_t)SAI_xFRCR_FSPO)
|
|
363
|
|
364 /**
|
|
365 * @}
|
|
366 */
|
|
367
|
|
368 /** @defgroup SAI_Block_FS_Offset SAI Block FS Offset
|
|
369 * @{
|
|
370 */
|
|
371 #define SAI_FS_FIRSTBIT ((uint32_t)0x00000000)
|
|
372 #define SAI_FS_BEFOREFIRSTBIT ((uint32_t)SAI_xFRCR_FSOFF)
|
|
373
|
|
374 /**
|
|
375 * @}
|
|
376 */
|
|
377
|
|
378
|
|
379 /** @defgroup SAI_Block_Slot_Size SAI Block Slot Size
|
|
380 * @{
|
|
381 */
|
|
382 #define SAI_SLOTSIZE_DATASIZE ((uint32_t)0x00000000)
|
|
383 #define SAI_SLOTSIZE_16B ((uint32_t)SAI_xSLOTR_SLOTSZ_0)
|
|
384 #define SAI_SLOTSIZE_32B ((uint32_t)SAI_xSLOTR_SLOTSZ_1)
|
|
385 /**
|
|
386 * @}
|
|
387 */
|
|
388
|
|
389 /** @defgroup SAI_Block_Slot_Active SAI Block Slot Active
|
|
390 * @{
|
|
391 */
|
|
392 #define SAI_SLOT_NOTACTIVE ((uint32_t)0x00000000)
|
|
393 #define SAI_SLOTACTIVE_0 ((uint32_t)0x00010000)
|
|
394 #define SAI_SLOTACTIVE_1 ((uint32_t)0x00020000)
|
|
395 #define SAI_SLOTACTIVE_2 ((uint32_t)0x00040000)
|
|
396 #define SAI_SLOTACTIVE_3 ((uint32_t)0x00080000)
|
|
397 #define SAI_SLOTACTIVE_4 ((uint32_t)0x00100000)
|
|
398 #define SAI_SLOTACTIVE_5 ((uint32_t)0x00200000)
|
|
399 #define SAI_SLOTACTIVE_6 ((uint32_t)0x00400000)
|
|
400 #define SAI_SLOTACTIVE_7 ((uint32_t)0x00800000)
|
|
401 #define SAI_SLOTACTIVE_8 ((uint32_t)0x01000000)
|
|
402 #define SAI_SLOTACTIVE_9 ((uint32_t)0x02000000)
|
|
403 #define SAI_SLOTACTIVE_10 ((uint32_t)0x04000000)
|
|
404 #define SAI_SLOTACTIVE_11 ((uint32_t)0x08000000)
|
|
405 #define SAI_SLOTACTIVE_12 ((uint32_t)0x10000000)
|
|
406 #define SAI_SLOTACTIVE_13 ((uint32_t)0x20000000)
|
|
407 #define SAI_SLOTACTIVE_14 ((uint32_t)0x40000000)
|
|
408 #define SAI_SLOTACTIVE_15 ((uint32_t)0x80000000)
|
|
409 #define SAI_SLOTACTIVE_ALL ((uint32_t)0xFFFF0000)
|
|
410
|
|
411 /**
|
|
412 * @}
|
|
413 */
|
|
414
|
|
415 /** @defgroup SAI_Mono_Stereo_Mode SAI Mono Stereo Mode
|
|
416 * @{
|
|
417 */
|
|
418 #define SAI_MONOMODE ((uint32_t)SAI_xCR1_MONO)
|
|
419 #define SAI_STEREOMODE ((uint32_t)0x00000000)
|
|
420
|
|
421 /**
|
|
422 * @}
|
|
423 */
|
|
424
|
|
425 /** @defgroup SAI_TRIState_Management SAI TRIState Management
|
|
426 * @{
|
|
427 */
|
|
428 #define SAI_OUTPUT_NOTRELEASED ((uint32_t)0x00000000)
|
|
429 #define SAI_OUTPUT_RELEASED ((uint32_t)SAI_xCR2_TRIS)
|
|
430
|
|
431 /**
|
|
432 * @}
|
|
433 */
|
|
434
|
|
435 /** @defgroup SAI_Block_Fifo_Threshold SAI Block Fifo Threshold
|
|
436 * @{
|
|
437 */
|
|
438 #define SAI_FIFOTHRESHOLD_EMPTY ((uint32_t)0x00000000)
|
|
439 #define SAI_FIFOTHRESHOLD_1QF ((uint32_t)0x00000001)
|
|
440 #define SAI_FIFOTHRESHOLD_HF ((uint32_t)0x00000002)
|
|
441 #define SAI_FIFOTHRESHOLD_3QF ((uint32_t)0x00000003)
|
|
442 #define SAI_FIFOTHRESHOLD_FULL ((uint32_t)0x00000004)
|
|
443
|
|
444 /**
|
|
445 * @}
|
|
446 */
|
|
447
|
|
448 /** @defgroup SAI_Block_Companding_Mode SAI Block Companding Mode
|
|
449 * @{
|
|
450 */
|
|
451 #define SAI_NOCOMPANDING ((uint32_t)0x00000000)
|
|
452 #define SAI_ULAW_1CPL_COMPANDING ((uint32_t)0x00008000)
|
|
453 #define SAI_ALAW_1CPL_COMPANDING ((uint32_t)0x0000C000)
|
|
454 #define SAI_ULAW_2CPL_COMPANDING ((uint32_t)0x0000A000)
|
|
455 #define SAI_ALAW_2CPL_COMPANDING ((uint32_t)0x0000E000)
|
|
456
|
|
457 /**
|
|
458 * @}
|
|
459 */
|
|
460
|
|
461 /** @defgroup SAI_Block_Mute_Value SAI Block Mute Value
|
|
462 * @{
|
|
463 */
|
|
464 #define SAI_ZERO_VALUE ((uint32_t)0x00000000)
|
|
465 #define SAI_LAST_SENT_VALUE ((uint32_t)SAI_xCR2_MUTEVAL)
|
|
466
|
|
467 /**
|
|
468 * @}
|
|
469 */
|
|
470
|
|
471
|
|
472 /** @defgroup SAI_Block_Interrupts_Definition SAI Block Interrupts Definition
|
|
473 * @{
|
|
474 */
|
|
475 #define SAI_IT_OVRUDR ((uint32_t)SAI_xIMR_OVRUDRIE)
|
|
476 #define SAI_IT_MUTEDET ((uint32_t)SAI_xIMR_MUTEDETIE)
|
|
477 #define SAI_IT_WCKCFG ((uint32_t)SAI_xIMR_WCKCFGIE)
|
|
478 #define SAI_IT_FREQ ((uint32_t)SAI_xIMR_FREQIE)
|
|
479 #define SAI_IT_CNRDY ((uint32_t)SAI_xIMR_CNRDYIE)
|
|
480 #define SAI_IT_AFSDET ((uint32_t)SAI_xIMR_AFSDETIE)
|
|
481 #define SAI_IT_LFSDET ((uint32_t)SAI_xIMR_LFSDETIE)
|
|
482
|
|
483 /**
|
|
484 * @}
|
|
485 */
|
|
486
|
|
487 /** @defgroup SAI_Block_Flags_Definition SAI Block Flags Definition
|
|
488 * @{
|
|
489 */
|
|
490 #define SAI_FLAG_OVRUDR ((uint32_t)SAI_xSR_OVRUDR)
|
|
491 #define SAI_FLAG_MUTEDET ((uint32_t)SAI_xSR_MUTEDET)
|
|
492 #define SAI_FLAG_WCKCFG ((uint32_t)SAI_xSR_WCKCFG)
|
|
493 #define SAI_FLAG_FREQ ((uint32_t)SAI_xSR_FREQ)
|
|
494 #define SAI_FLAG_CNRDY ((uint32_t)SAI_xSR_CNRDY)
|
|
495 #define SAI_FLAG_AFSDET ((uint32_t)SAI_xSR_AFSDET)
|
|
496 #define SAI_FLAG_LFSDET ((uint32_t)SAI_xSR_LFSDET)
|
|
497
|
|
498 /**
|
|
499 * @}
|
|
500 */
|
|
501
|
|
502 /** @defgroup SAI_Block_Fifo_Status_Level SAI Block Fifo Status Level
|
|
503 * @{
|
|
504 */
|
|
505 #define SAI_FIFOSTATUS_EMPTY ((uint32_t)0x00000000)
|
|
506 #define SAI_FIFOSTATUS_LESS1QUARTERFULL ((uint32_t)0x00010000)
|
|
507 #define SAI_FIFOSTATUS_1QUARTERFULL ((uint32_t)0x00020000)
|
|
508 #define SAI_FIFOSTATUS_HALFFULL ((uint32_t)0x00030000)
|
|
509 #define SAI_FIFOSTATUS_3QUARTERFULL ((uint32_t)0x00040000)
|
|
510 #define SAI_FIFOSTATUS_FULL ((uint32_t)0x00050000)
|
|
511
|
|
512 /**
|
|
513 * @}
|
|
514 */
|
|
515
|
|
516 /**
|
|
517 * @}
|
|
518 */
|
|
519
|
|
520 /* Exported macro ------------------------------------------------------------*/
|
|
521
|
|
522 /** @defgroup SAI_Exported_Macros SAI Exported Macros
|
|
523 * @brief macros to handle interrupts and specific configurations
|
|
524 * @{
|
|
525 */
|
|
526
|
|
527 /** @brief Reset SAI handle state
|
|
528 * @param __HANDLE__: specifies the SAI Handle.
|
|
529 * @retval None
|
|
530 */
|
|
531 #define __HAL_SAI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SAI_STATE_RESET)
|
|
532
|
|
533 /** @brief Enable or disable the specified SAI interrupts.
|
|
534 * @param __HANDLE__: specifies the SAI Handle.
|
|
535 * @param __INTERRUPT__: specifies the interrupt source to enable or disable.
|
|
536 * This parameter can be one of the following values:
|
|
537 * @arg SAI_IT_OVRUDR: Overrun underrun interrupt enable
|
|
538 * @arg SAI_IT_MUTEDET: Mute detection interrupt enable
|
|
539 * @arg SAI_IT_WCKCFG: Wrong Clock Configuration interrupt enable
|
|
540 * @arg SAI_IT_FREQ: FIFO request interrupt enable
|
|
541 * @arg SAI_IT_CNRDY: Codec not ready interrupt enable
|
|
542 * @arg SAI_IT_AFSDET: Anticipated frame synchronization detection interrupt enable
|
|
543 * @arg SAI_IT_LFSDET: Late frame synchronization detection interrupt enable
|
|
544 * @retval None
|
|
545 */
|
|
546
|
|
547 #define __HAL_SAI_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR |= (__INTERRUPT__))
|
|
548 #define __HAL_SAI_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->IMR &= (~(__INTERRUPT__)))
|
|
549
|
|
550 /** @brief Check if the specified SAI interrupt source is enabled or disabled.
|
|
551 * @param __HANDLE__: specifies the SAI Handle.
|
|
552 * This parameter can be SAI where x: 1, 2, or 3 to select the SAI peripheral.
|
|
553 * @param __INTERRUPT__: specifies the SAI interrupt source to check.
|
|
554 * This parameter can be one of the following values:
|
|
555 * @arg SAI_IT_TXE: Tx buffer empty interrupt enable.
|
|
556 * @arg SAI_IT_RXNE: Rx buffer not empty interrupt enable.
|
|
557 * @arg SAI_IT_ERR: Error interrupt enable.
|
|
558 * @retval The new state of __INTERRUPT__ (TRUE or FALSE).
|
|
559 */
|
|
560 #define __HAL_SAI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->IMR & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
|
|
561
|
|
562 /** @brief Check whether the specified SAI flag is set or not.
|
|
563 * @param __HANDLE__: specifies the SAI Handle.
|
|
564 * @param __FLAG__: specifies the flag to check.
|
|
565 * This parameter can be one of the following values:
|
|
566 * @arg SAI_FLAG_OVRUDR: Overrun underrun flag.
|
|
567 * @arg SAI_FLAG_MUTEDET: Mute detection flag.
|
|
568 * @arg SAI_FLAG_WCKCFG: Wrong Clock Configuration flag.
|
|
569 * @arg SAI_FLAG_FREQ: FIFO request flag.
|
|
570 * @arg SAI_FLAG_CNRDY: Codec not ready flag.
|
|
571 * @arg SAI_FLAG_AFSDET: Anticipated frame synchronization detection flag.
|
|
572 * @arg SAI_FLAG_LFSDET: Late frame synchronization detection flag.
|
|
573 * @retval The new state of __FLAG__ (TRUE or FALSE).
|
|
574 */
|
|
575 #define __HAL_SAI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
|
|
576
|
|
577 /** @brief Clears the specified SAI pending flag.
|
|
578 * @param __HANDLE__: specifies the SAI Handle.
|
|
579 * @param __FLAG__: specifies the flag to check.
|
|
580 * This parameter can be any combination of the following values:
|
|
581 * @arg SAI_FLAG_OVRUDR: Clear Overrun underrun
|
|
582 * @arg SAI_FLAG_MUTEDET: Clear Mute detection
|
|
583 * @arg SAI_FLAG_WCKCFG: Clear Wrong Clock Configuration
|
|
584 * @arg SAI_FLAG_FREQ: Clear FIFO request
|
|
585 * @arg SAI_FLAG_CNRDY: Clear Codec not ready
|
|
586 * @arg SAI_FLAG_AFSDET: Clear Anticipated frame synchronization detection
|
|
587 * @arg SAI_FLAG_LFSDET: Clear Late frame synchronization detection
|
|
588 *
|
|
589 * @retval None
|
|
590 */
|
|
591 #define __HAL_SAI_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->CLRFR = (__FLAG__))
|
|
592
|
|
593 #define __HAL_SAI_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= SAI_xCR1_SAIEN)
|
|
594 #define __HAL_SAI_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~SAI_xCR1_SAIEN)
|
|
595
|
|
596 /**
|
|
597 * @}
|
|
598 */
|
|
599
|
|
600 /* Exported functions --------------------------------------------------------*/
|
|
601
|
|
602 /** @addtogroup SAI_Exported_Functions
|
|
603 * @{
|
|
604 */
|
|
605
|
|
606 /* Initialization/de-initialization functions **********************************/
|
|
607 /** @addtogroup SAI_Exported_Functions_Group1
|
|
608 * @{
|
|
609 */
|
|
610 HAL_StatusTypeDef HAL_SAI_Init(SAI_HandleTypeDef *hsai);
|
|
611 HAL_StatusTypeDef HAL_SAI_DeInit (SAI_HandleTypeDef *hsai);
|
|
612 void HAL_SAI_MspInit(SAI_HandleTypeDef *hsai);
|
|
613 void HAL_SAI_MspDeInit(SAI_HandleTypeDef *hsai);
|
|
614
|
|
615 /**
|
|
616 * @}
|
|
617 */
|
|
618
|
|
619 /* I/O operation functions *****************************************************/
|
|
620 /** @addtogroup SAI_Exported_Functions_Group2
|
|
621 * @{
|
|
622 */
|
|
623 /* Blocking mode: Polling */
|
|
624 HAL_StatusTypeDef HAL_SAI_Transmit(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size, uint32_t Timeout);
|
|
625 HAL_StatusTypeDef HAL_SAI_Receive(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size, uint32_t Timeout);
|
|
626
|
|
627 /* Non-Blocking mode: Interrupt */
|
|
628 HAL_StatusTypeDef HAL_SAI_Transmit_IT(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size);
|
|
629 HAL_StatusTypeDef HAL_SAI_Receive_IT(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size);
|
|
630
|
|
631 /* Non-Blocking mode: DMA */
|
|
632 HAL_StatusTypeDef HAL_SAI_Transmit_DMA(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size);
|
|
633 HAL_StatusTypeDef HAL_SAI_Receive_DMA(SAI_HandleTypeDef *hsai, uint16_t *pData, uint16_t Size);
|
|
634 HAL_StatusTypeDef HAL_SAI_DMAPause(SAI_HandleTypeDef *hsai);
|
|
635 HAL_StatusTypeDef HAL_SAI_DMAResume(SAI_HandleTypeDef *hsai);
|
|
636 HAL_StatusTypeDef HAL_SAI_DMAStop(SAI_HandleTypeDef *hsai);
|
|
637
|
|
638 /* SAI IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */
|
|
639 void HAL_SAI_IRQHandler(SAI_HandleTypeDef *hsai);
|
|
640 void HAL_SAI_TxHalfCpltCallback(SAI_HandleTypeDef *hsai);
|
|
641 void HAL_SAI_TxCpltCallback(SAI_HandleTypeDef *hsai);
|
|
642 void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai);
|
|
643 void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai);
|
|
644 void HAL_SAI_ErrorCallback(SAI_HandleTypeDef *hsai);
|
|
645 /**
|
|
646 * @}
|
|
647 */
|
|
648
|
|
649 /** @addtogroup SAI_Exported_Functions_Group3
|
|
650 * @{
|
|
651 */
|
|
652 /* Peripheral State functions **************************************************/
|
|
653 HAL_SAI_StateTypeDef HAL_SAI_GetState(SAI_HandleTypeDef *hsai);
|
|
654 uint32_t HAL_SAI_GetError(SAI_HandleTypeDef *hsai);
|
|
655 /**
|
|
656 * @}
|
|
657 */
|
|
658
|
|
659 /**
|
|
660 * @}
|
|
661 */
|
|
662
|
|
663 /* Private types -------------------------------------------------------------*/
|
|
664 /** @defgroup SAI_Private_Types SAI Private Types
|
|
665 * @{
|
|
666 */
|
|
667
|
|
668 /**
|
|
669 * @}
|
|
670 */
|
|
671
|
|
672 /* Private variables ---------------------------------------------------------*/
|
|
673 /** @defgroup SAI_Private_Variables SAI Private Variables
|
|
674 * @{
|
|
675 */
|
|
676
|
|
677 /**
|
|
678 * @}
|
|
679 */
|
|
680
|
|
681 /* Private constants ---------------------------------------------------------*/
|
|
682 /** @defgroup SAI_Private_Constants SAI Private Constants
|
|
683 * @{
|
|
684 */
|
|
685
|
|
686 /**
|
|
687 * @}
|
|
688 */
|
|
689
|
|
690 /* Private macros ------------------------------------------------------------*/
|
|
691 /** @addtogroup SAI_Private_Macros
|
|
692 * @{
|
|
693 */
|
|
694 #define IS_SAI_CLK_SOURCE(SOURCE) (((SOURCE) == SAI_CLKSOURCE_PLLSAI) ||\
|
|
695 ((SOURCE) == SAI_CLKSOURCE_PLLI2S) ||\
|
|
696 ((SOURCE) == SAI_CLKSOURCE_EXT))
|
|
697
|
|
698 #define IS_SAI_AUDIO_FREQUENCY(AUDIO) (((AUDIO) == SAI_AUDIO_FREQUENCY_192K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_96K) || \
|
|
699 ((AUDIO) == SAI_AUDIO_FREQUENCY_48K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_44K) || \
|
|
700 ((AUDIO) == SAI_AUDIO_FREQUENCY_32K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_22K) || \
|
|
701 ((AUDIO) == SAI_AUDIO_FREQUENCY_16K) || ((AUDIO) == SAI_AUDIO_FREQUENCY_11K) || \
|
|
702 ((AUDIO) == SAI_AUDIO_FREQUENCY_8K))
|
|
703
|
|
704 #define IS_SAI_BLOCK_MODE(MODE) (((MODE) == SAI_MODEMASTER_TX) || \
|
|
705 ((MODE) == SAI_MODEMASTER_RX) || \
|
|
706 ((MODE) == SAI_MODESLAVE_TX) || \
|
|
707 ((MODE) == SAI_MODESLAVE_RX))
|
|
708
|
|
709 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_FREE_PROTOCOL) || \
|
|
710 ((PROTOCOL) == SAI_AC97_PROTOCOL))
|
|
711
|
|
712 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DATASIZE_8) || \
|
|
713 ((DATASIZE) == SAI_DATASIZE_10) || \
|
|
714 ((DATASIZE) == SAI_DATASIZE_16) || \
|
|
715 ((DATASIZE) == SAI_DATASIZE_20) || \
|
|
716 ((DATASIZE) == SAI_DATASIZE_24) || \
|
|
717 ((DATASIZE) == SAI_DATASIZE_32))
|
|
718
|
|
719 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FIRSTBIT_MSB) || \
|
|
720 ((BIT) == SAI_FIRSTBIT_LSB))
|
|
721
|
|
722 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_CLOCKSTROBING_FALLINGEDGE) || \
|
|
723 ((CLOCK) == SAI_CLOCKSTROBING_RISINGEDGE))
|
|
724
|
|
725 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_ASYNCHRONOUS) || \
|
|
726 ((SYNCHRO) == SAI_SYNCHRONOUS))
|
|
727
|
|
728 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OUTPUTDRIVE_DISABLE) || \
|
|
729 ((DRIVE) == SAI_OUTPUTDRIVE_ENABLE))
|
|
730
|
|
731 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MASTERDIVIDER_ENABLE) || \
|
|
732 ((NODIVIDER) == SAI_MASTERDIVIDER_DISABLE))
|
|
733
|
|
734 #define IS_SAI_BLOCK_FIFO_STATUS(STATUS) (((STATUS) == SAI_FIFOSTATUS_LESS1QUARTERFULL ) || \
|
|
735 ((STATUS) == SAI_FIFOSTATUS_HALFFULL) || \
|
|
736 ((STATUS) == SAI_FIFOSTATUS_1QUARTERFULL) || \
|
|
737 ((STATUS) == SAI_FIFOSTATUS_3QUARTERFULL) || \
|
|
738 ((STATUS) == SAI_FIFOSTATUS_FULL) || \
|
|
739 ((STATUS) == SAI_FIFOSTATUS_EMPTY))
|
|
740
|
|
741 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63)
|
|
742
|
|
743 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE) (((VALUE) == SAI_ZERO_VALUE) || \
|
|
744 ((VALUE) == SAI_LAST_SENT_VALUE))
|
|
745
|
|
746 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE) (((MODE) == SAI_NOCOMPANDING) || \
|
|
747 ((MODE) == SAI_ULAW_1CPL_COMPANDING) || \
|
|
748 ((MODE) == SAI_ALAW_1CPL_COMPANDING) || \
|
|
749 ((MODE) == SAI_ULAW_2CPL_COMPANDING) || \
|
|
750 ((MODE) == SAI_ALAW_2CPL_COMPANDING))
|
|
751
|
|
752 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_FIFOTHRESHOLD_EMPTY) || \
|
|
753 ((THRESHOLD) == SAI_FIFOTHRESHOLD_1QF) || \
|
|
754 ((THRESHOLD) == SAI_FIFOTHRESHOLD_HF) || \
|
|
755 ((THRESHOLD) == SAI_FIFOTHRESHOLD_3QF) || \
|
|
756 ((THRESHOLD) == SAI_FIFOTHRESHOLD_FULL))
|
|
757
|
|
758 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_OUTPUT_NOTRELEASED) ||\
|
|
759 ((STATE) == SAI_OUTPUT_RELEASED))
|
|
760
|
|
761 #define IS_SAI_BLOCK_MONO_STEREO_MODE(MODE) (((MODE) == SAI_MONOMODE) ||\
|
|
762 ((MODE) == SAI_STEREOMODE))
|
|
763
|
|
764 #define IS_SAI_SLOT_ACTIVE(ACTIVE) ((ACTIVE) != 0)
|
|
765
|
|
766 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1 <= (NUMBER)) && ((NUMBER) <= 16))
|
|
767
|
|
768 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SLOTSIZE_DATASIZE) || \
|
|
769 ((SIZE) == SAI_SLOTSIZE_16B) || \
|
|
770 ((SIZE) == SAI_SLOTSIZE_32B))
|
|
771
|
|
772 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24)
|
|
773
|
|
774 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FIRSTBIT) || \
|
|
775 ((OFFSET) == SAI_FS_BEFOREFIRSTBIT))
|
|
776
|
|
777 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ACTIVE_LOW) || \
|
|
778 ((POLARITY) == SAI_FS_ACTIVE_HIGH))
|
|
779
|
|
780 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_STARTFRAME) || \
|
|
781 ((DEFINITION) == SAI_FS_CHANNEL_IDENTIFICATION))
|
|
782
|
|
783 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15)
|
|
784
|
|
785 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8 <= (LENGTH)) && ((LENGTH) <= 256))
|
|
786
|
|
787 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1 <= (LENGTH)) && ((LENGTH) <= 128))
|
|
788
|
|
789 /**
|
|
790 * @}
|
|
791 */
|
|
792
|
|
793 /* Private functions ---------------------------------------------------------*/
|
|
794 /** @defgroup SAI_Private_Functions SAI Private Functions
|
|
795 * @{
|
|
796 */
|
|
797
|
|
798 /**
|
|
799 * @}
|
|
800 */
|
|
801
|
|
802 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
|
|
803 /**
|
|
804 * @}
|
|
805 */
|
|
806
|
|
807 /**
|
|
808 * @}
|
|
809 */
|
|
810
|
|
811 #ifdef __cplusplus
|
|
812 }
|
|
813 #endif
|
|
814
|
|
815 #endif /* __STM32F4xx_HAL_SAI_H */
|
|
816
|
|
817 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|