30 #ifndef __STM32F4xx_SAI_H
31 #define __STM32F4xx_SAI_H
156 #define IS_SAI_PERIPH(PERIPH) ((PERIPH) == SAI1)
158 #define IS_SAI_BLOCK_PERIPH(PERIPH) (((PERIPH) == SAI1_Block_A) || \
159 ((PERIPH) == SAI1_Block_B))
165 #define SAI_Mode_MasterTx ((uint32_t)0x00000000)
166 #define SAI_Mode_MasterRx ((uint32_t)0x00000001)
167 #define SAI_Mode_SlaveTx ((uint32_t)0x00000002)
168 #define SAI_Mode_SlaveRx ((uint32_t)0x00000003)
169 #define IS_SAI_BLOCK_MODE(MODE) (((MODE) == SAI_Mode_MasterTx) || \
170 ((MODE) == SAI_Mode_MasterRx) || \
171 ((MODE) == SAI_Mode_SlaveTx) || \
172 ((MODE) == SAI_Mode_SlaveRx))
181 #define SAI_Free_Protocol ((uint32_t)0x00000000)
182 #define SAI_SPDIF_Protocol ((uint32_t)SAI_xCR1_PRTCFG_0)
183 #define SAI_AC97_Protocol ((uint32_t)SAI_xCR1_PRTCFG_1)
184 #define IS_SAI_BLOCK_PROTOCOL(PROTOCOL) (((PROTOCOL) == SAI_Free_Protocol) || \
185 ((PROTOCOL) == SAI_SPDIF_Protocol) || \
186 ((PROTOCOL) == SAI_AC97_Protocol))
195 #define SAI_DataSize_8b ((uint32_t)0x00000040)
196 #define SAI_DataSize_10b ((uint32_t)0x00000060)
197 #define SAI_DataSize_16b ((uint32_t)0x00000080)
198 #define SAI_DataSize_20b ((uint32_t)0x000000A0)
199 #define SAI_DataSize_24b ((uint32_t)0x000000C0)
200 #define SAI_DataSize_32b ((uint32_t)0x000000E0)
201 #define IS_SAI_BLOCK_DATASIZE(DATASIZE) (((DATASIZE) == SAI_DataSize_8b) || \
202 ((DATASIZE) == SAI_DataSize_10b) || \
203 ((DATASIZE) == SAI_DataSize_16b) || \
204 ((DATASIZE) == SAI_DataSize_20b) || \
205 ((DATASIZE) == SAI_DataSize_24b) || \
206 ((DATASIZE) == SAI_DataSize_32b))
215 #define SAI_FirstBit_MSB ((uint32_t)0x00000000)
216 #define SAI_FirstBit_LSB ((uint32_t)SAI_xCR1_LSBFIRST)
217 #define IS_SAI_BLOCK_FIRST_BIT(BIT) (((BIT) == SAI_FirstBit_MSB) || \
218 ((BIT) == SAI_FirstBit_LSB))
227 #define SAI_ClockStrobing_FallingEdge ((uint32_t)0x00000000)
228 #define SAI_ClockStrobing_RisingEdge ((uint32_t)SAI_xCR1_CKSTR)
229 #define IS_SAI_BLOCK_CLOCK_STROBING(CLOCK) (((CLOCK) == SAI_ClockStrobing_FallingEdge) || \
230 ((CLOCK) == SAI_ClockStrobing_RisingEdge))
239 #define SAI_Asynchronous ((uint32_t)0x00000000)
240 #define SAI_Synchronous ((uint32_t)SAI_xCR1_SYNCEN_0)
241 #define IS_SAI_BLOCK_SYNCHRO(SYNCHRO) (((SYNCHRO) == SAI_Synchronous) || \
242 ((SYNCHRO) == SAI_Asynchronous))
251 #define SAI_OutputDrive_Disabled ((uint32_t)0x00000000)
252 #define SAI_OutputDrive_Enabled ((uint32_t)SAI_xCR1_OUTDRIV)
253 #define IS_SAI_BLOCK_OUTPUT_DRIVE(DRIVE) (((DRIVE) == SAI_OutputDrive_Disabled) || \
254 ((DRIVE) == SAI_OutputDrive_Enabled))
265 #define SAI_MasterDivider_Enabled ((uint32_t)0x00000000)
266 #define SAI_MasterDivider_Disabled ((uint32_t)SAI_xCR1_NODIV)
267 #define IS_SAI_BLOCK_NODIVIDER(NODIVIDER) (((NODIVIDER) == SAI_MasterDivider_Enabled) || \
268 ((NODIVIDER) == SAI_MasterDivider_Disabled))
277 #define IS_SAI_BLOCK_MASTER_DIVIDER(DIVIDER) ((DIVIDER) <= 15)
286 #define IS_SAI_BLOCK_FRAME_LENGTH(LENGTH) ((8 <= (LENGTH)) && ((LENGTH) <= 256))
295 #define IS_SAI_BLOCK_ACTIVE_FRAME(LENGTH) ((1 <= (LENGTH)) && ((LENGTH) <= 128))
305 #define SAI_FS_StartFrame ((uint32_t)0x00000000)
306 #define I2S_FS_ChannelIdentification ((uint32_t)SAI_xFRCR_FSDEF)
307 #define IS_SAI_BLOCK_FS_DEFINITION(DEFINITION) (((DEFINITION) == SAI_FS_StartFrame) || \
308 ((DEFINITION) == I2S_FS_ChannelIdentification))
317 #define SAI_FS_ActiveLow ((uint32_t)0x00000000)
318 #define SAI_FS_ActiveHigh ((uint32_t)SAI_xFRCR_FSPO)
319 #define IS_SAI_BLOCK_FS_POLARITY(POLARITY) (((POLARITY) == SAI_FS_ActiveLow) || \
320 ((POLARITY) == SAI_FS_ActiveHigh))
329 #define SAI_FS_FirstBit ((uint32_t)0x00000000)
330 #define SAI_FS_BeforeFirstBit ((uint32_t)SAI_xFRCR_FSOFF)
331 #define IS_SAI_BLOCK_FS_OFFSET(OFFSET) (((OFFSET) == SAI_FS_FirstBit) || \
332 ((OFFSET) == SAI_FS_BeforeFirstBit))
340 #define IS_SAI_BLOCK_FIRSTBIT_OFFSET(OFFSET) ((OFFSET) <= 24)
349 #define SAI_SlotSize_DataSize ((uint32_t)0x00000000)
350 #define SAI_SlotSize_16b ((uint32_t)SAI_xSLOTR_SLOTSZ_0)
351 #define SAI_SlotSize_32b ((uint32_t)SAI_xSLOTR_SLOTSZ_1)
352 #define IS_SAI_BLOCK_SLOT_SIZE(SIZE) (((SIZE) == SAI_SlotSize_DataSize) || \
353 ((SIZE) == SAI_SlotSize_16b) || \
354 ((SIZE) == SAI_SlotSize_32b))
363 #define IS_SAI_BLOCK_SLOT_NUMBER(NUMBER) ((1 <= (NUMBER)) && ((NUMBER) <= 16))
372 #define SAI_Slot_NotActive ((uint32_t)0x00000000)
373 #define SAI_SlotActive_0 ((uint32_t)0x00010000)
374 #define SAI_SlotActive_1 ((uint32_t)0x00020000)
375 #define SAI_SlotActive_2 ((uint32_t)0x00040000)
376 #define SAI_SlotActive_3 ((uint32_t)0x00080000)
377 #define SAI_SlotActive_4 ((uint32_t)0x00100000)
378 #define SAI_SlotActive_5 ((uint32_t)0x00200000)
379 #define SAI_SlotActive_6 ((uint32_t)0x00400000)
380 #define SAI_SlotActive_7 ((uint32_t)0x00800000)
381 #define SAI_SlotActive_8 ((uint32_t)0x01000000)
382 #define SAI_SlotActive_9 ((uint32_t)0x02000000)
383 #define SAI_SlotActive_10 ((uint32_t)0x04000000)
384 #define SAI_SlotActive_11 ((uint32_t)0x08000000)
385 #define SAI_SlotActive_12 ((uint32_t)0x10000000)
386 #define SAI_SlotActive_13 ((uint32_t)0x20000000)
387 #define SAI_SlotActive_14 ((uint32_t)0x40000000)
388 #define SAI_SlotActive_15 ((uint32_t)0x80000000)
389 #define SAI_SlotActive_ALL ((uint32_t)0xFFFF0000)
391 #define IS_SAI_SLOT_ACTIVE(ACTIVE) ((ACTIVE) != 0)
401 #define SAI_MonoMode ((uint32_t)SAI_xCR1_MONO)
402 #define SAI_StreoMode ((uint32_t)0x00000000)
403 #define IS_SAI_BLOCK_MONO_STREO_MODE(MODE) (((MODE) == SAI_MonoMode) ||\
404 ((MODE) == SAI_StreoMode))
413 #define SAI_Output_NotReleased ((uint32_t)0x00000000)
414 #define SAI_Output_Released ((uint32_t)SAI_xCR2_TRIS)
415 #define IS_SAI_BLOCK_TRISTATE_MANAGEMENT(STATE) (((STATE) == SAI_Output_NotReleased) ||\
416 ((STATE) == SAI_Output_Released))
425 #define SAI_Threshold_FIFOEmpty ((uint32_t)0x00000000)
426 #define SAI_FIFOThreshold_1QuarterFull ((uint32_t)0x00000001)
427 #define SAI_FIFOThreshold_HalfFull ((uint32_t)0x00000002)
428 #define SAI_FIFOThreshold_3QuartersFull ((uint32_t)0x00000003)
429 #define SAI_FIFOThreshold_Full ((uint32_t)0x00000004)
430 #define IS_SAI_BLOCK_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == SAI_Threshold_FIFOEmpty) || \
431 ((THRESHOLD) == SAI_FIFOThreshold_1QuarterFull) || \
432 ((THRESHOLD) == SAI_FIFOThreshold_HalfFull) || \
433 ((THRESHOLD) == SAI_FIFOThreshold_3QuartersFull) || \
434 ((THRESHOLD) == SAI_FIFOThreshold_Full))
443 #define SAI_NoCompanding ((uint32_t)0x00000000)
444 #define SAI_ULaw_1CPL_Companding ((uint32_t)0x00008000)
445 #define SAI_ALaw_1CPL_Companding ((uint32_t)0x0000C000)
446 #define SAI_ULaw_2CPL_Companding ((uint32_t)0x0000A000)
447 #define SAI_ALaw_2CPL_Companding ((uint32_t)0x0000E000)
448 #define IS_SAI_BLOCK_COMPANDING_MODE(MODE) (((MODE) == SAI_NoCompanding) || \
449 ((MODE) == SAI_ULaw_1CPL_Companding) || \
450 ((MODE) == SAI_ALaw_1CPL_Companding) || \
451 ((MODE) == SAI_ULaw_2CPL_Companding) || \
452 ((MODE) == SAI_ALaw_2CPL_Companding))
461 #define SAI_ZeroValue ((uint32_t)0x00000000)
462 #define SAI_LastSentValue ((uint32_t)SAI_xCR2_MUTEVAL)
463 #define IS_SAI_BLOCK_MUTE_VALUE(VALUE) (((VALUE) == SAI_ZeroValue) || \
464 ((VALUE) == SAI_LastSentValue))
473 #define IS_SAI_BLOCK_MUTE_COUNTER(COUNTER) ((COUNTER) <= 63)
483 #define SAI_IT_OVRUDR ((uint32_t)SAI_xIMR_OVRUDRIE)
484 #define SAI_IT_MUTEDET ((uint32_t)SAI_xIMR_MUTEDETIE)
485 #define SAI_IT_WCKCFG ((uint32_t)SAI_xIMR_WCKCFGIE)
486 #define SAI_IT_FREQ ((uint32_t)SAI_xIMR_FREQIE)
487 #define SAI_IT_CNRDY ((uint32_t)SAI_xIMR_CNRDYIE)
488 #define SAI_IT_AFSDET ((uint32_t)SAI_xIMR_AFSDETIE)
489 #define SAI_IT_LFSDET ((uint32_t)SAI_xIMR_LFSDETIE)
491 #define IS_SAI_BLOCK_CONFIG_IT(IT) (((IT) == SAI_IT_OVRUDR) || \
492 ((IT) == SAI_IT_MUTEDET) || \
493 ((IT) == SAI_IT_WCKCFG) || \
494 ((IT) == SAI_IT_FREQ) || \
495 ((IT) == SAI_IT_CNRDY) || \
496 ((IT) == SAI_IT_AFSDET) || \
497 ((IT) == SAI_IT_LFSDET))
506 #define SAI_FLAG_OVRUDR ((uint32_t)SAI_xSR_OVRUDR)
507 #define SAI_FLAG_MUTEDET ((uint32_t)SAI_xSR_MUTEDET)
508 #define SAI_FLAG_WCKCFG ((uint32_t)SAI_xSR_WCKCFG)
509 #define SAI_FLAG_FREQ ((uint32_t)SAI_xSR_FREQ)
510 #define SAI_FLAG_CNRDY ((uint32_t)SAI_xSR_CNRDY)
511 #define SAI_FLAG_AFSDET ((uint32_t)SAI_xSR_AFSDET)
512 #define SAI_FLAG_LFSDET ((uint32_t)SAI_xSR_LFSDET)
514 #define IS_SAI_BLOCK_GET_FLAG(FLAG) (((FLAG) == SAI_FLAG_OVRUDR) || \
515 ((FLAG) == SAI_FLAG_MUTEDET) || \
516 ((FLAG) == SAI_FLAG_WCKCFG) || \
517 ((FLAG) == SAI_FLAG_FREQ) || \
518 ((FLAG) == SAI_FLAG_CNRDY) || \
519 ((FLAG) == SAI_FLAG_AFSDET) || \
520 ((FLAG) == SAI_FLAG_LFSDET))
522 #define IS_SAI_BLOCK_CLEAR_FLAG(FLAG) (((FLAG) == SAI_FLAG_OVRUDR) || \
523 ((FLAG) == SAI_FLAG_MUTEDET) || \
524 ((FLAG) == SAI_FLAG_WCKCFG) || \
525 ((FLAG) == SAI_FLAG_FREQ) || \
526 ((FLAG) == SAI_FLAG_CNRDY) || \
527 ((FLAG) == SAI_FLAG_AFSDET) || \
528 ((FLAG) == SAI_FLAG_LFSDET))
536 #define SAI_FIFOStatus_Empty ((uint32_t)0x00000000)
537 #define SAI_FIFOStatus_Less1QuarterFull ((uint32_t)0x00010000)
538 #define SAI_FIFOStatus_1QuarterFull ((uint32_t)0x00020000)
539 #define SAI_FIFOStatus_HalfFull ((uint32_t)0x00030000)
540 #define SAI_FIFOStatus_3QuartersFull ((uint32_t)0x00040000)
541 #define SAI_FIFOStatus_Full ((uint32_t)0x00050000)
543 #define IS_SAI_BLOCK_FIFO_STATUS(STATUS) (((STATUS) == SAI_FIFOStatus_Less1QuarterFull ) || \
544 ((STATUS) == SAI_FIFOStatus_HalfFull) || \
545 ((STATUS) == SAI_FIFOStatus_1QuarterFull) || \
546 ((STATUS) == SAI_FIFOStatus_3QuartersFull) || \
547 ((STATUS) == SAI_FIFOStatus_Full) || \
548 ((STATUS) == SAI_FIFOStatus_Empty))
uint32_t SAI_FirstBitOffset
Definition: stm32f4xx_sai.h:133
uint32_t SAI_SlotNumber
Definition: stm32f4xx_sai.h:141
void SAI_SendData(SAI_Block_TypeDef *SAI_Block_x, uint32_t Data)
Transmits a Data through the SAI block x peripheral.
Definition: stm32f4xx_sai.c:670
void SAI_ClearFlag(SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_FLAG)
Clears the specified SAI Block x flag.
Definition: stm32f4xx_sai.c:922
ITStatus SAI_GetITStatus(SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_IT)
Checks whether the specified SAI Block x interrupt has occurred or not.
Definition: stm32f4xx_sai.c:947
uint32_t SAI_ReceiveData(SAI_Block_TypeDef *SAI_Block_x)
Returns the most recent received data by the SAI block x peripheral.
Definition: stm32f4xx_sai.c:654
void SAI_FlushFIFO(SAI_Block_TypeDef *SAI_Block_x)
Reinitialize the FIFO pointer.
Definition: stm32f4xx_sai.c:612
SAI Block Frame Init structure definition.
Definition: stm32f4xx_sai.h:96
void SAI_MuteModeCmd(SAI_Block_TypeDef *SAI_Block_x, FunctionalState NewState)
Enables or disables the Mute mode for the selected SAI block.
Definition: stm32f4xx_sai.c:536
void SAI_Cmd(SAI_Block_TypeDef *SAI_Block_x, FunctionalState NewState)
Enables or disables the specified SAI Block peripheral.
Definition: stm32f4xx_sai.c:432
uint32_t SAI_FSDefinition
Definition: stm32f4xx_sai.h:113
void SAI_DeInit(SAI_TypeDef *SAIx)
Deinitialize the SAIx peripheral registers to their default reset values.
Definition: stm32f4xx_sai.c:182
uint32_t SAI_AudioMode
Definition: stm32f4xx_sai.h:56
uint32_t SAI_GetFIFOStatus(SAI_Block_TypeDef *SAI_Block_x)
Returns the current SAI Block x FIFO filled level.
Definition: stm32f4xx_sai.c:1049
void SAI_StructInit(SAI_InitTypeDef *SAI_InitStruct)
Fills each SAI_InitStruct member with its default value.
Definition: stm32f4xx_sai.c:359
void SAI_SlotStructInit(SAI_SlotInitTypeDef *SAI_SlotInitStruct)
Fills each SAI_SlotInitStruct member with its default value.
Definition: stm32f4xx_sai.c:411
CMSIS Cortex-M4 Device Peripheral Access Layer Header File. This file contains all the peripheral reg...
FlagStatus SAI_GetFlagStatus(SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_FLAG)
Checks whether the specified SAI block x flag is set or not.
Definition: stm32f4xx_sai.c:879
uint32_t SAI_ActiveFrameLength
Definition: stm32f4xx_sai.h:107
uint32_t SAI_FIFOThreshold
Definition: stm32f4xx_sai.h:88
void SAI_MonoModeConfig(SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_Mono_StreoMode)
Configures the mono mode for the selected SAI block.
Definition: stm32f4xx_sai.c:461
void SAI_ClearITPendingBit(SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_IT)
Clears the SAI Block x interrupt pending bit.
Definition: stm32f4xx_sai.c:994
uint32_t SAI_SlotActive
Definition: stm32f4xx_sai.h:145
SAI Block Init structure definition.
Definition: stm32f4xx_sai.h:54
uint32_t SAI_DataSize
Definition: stm32f4xx_sai.h:62
void SAI_Init(SAI_Block_TypeDef *SAI_Block_x, SAI_InitTypeDef *SAI_InitStruct)
Initializes the SAI Block x peripheral according to the specified parameters in the SAI_InitStruct...
Definition: stm32f4xx_sai.c:205
Serial Audio Interface.
Definition: stm32f4xx.h:1208
FunctionalState SAI_GetCmdStatus(SAI_Block_TypeDef *SAI_Block_x)
Returns the status of EN bit for the specified SAI Block x.
Definition: stm32f4xx_sai.c:1016
uint32_t SAI_MasterDivider
Definition: stm32f4xx_sai.h:84
uint32_t SAI_Synchro
Definition: stm32f4xx_sai.h:73
uint32_t SAI_NoDivider
Definition: stm32f4xx_sai.h:81
void SAI_MuteValueConfig(SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_MuteValue)
Configure the mute value for the selected SAI block.
Definition: stm32f4xx_sai.c:567
uint32_t SAI_FirstBit
Definition: stm32f4xx_sai.h:66
void SAI_FrameStructInit(SAI_FrameInitTypeDef *SAI_FrameInitStruct)
Fills each SAI_FrameInitStruct member with its default value.
Definition: stm32f4xx_sai.c:390
void SAI_CompandingModeConfig(SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_CompandingMode)
Configures the companding mode for the selected SAI block.
Definition: stm32f4xx_sai.c:512
uint32_t SAI_FSPolarity
Definition: stm32f4xx_sai.h:117
uint32_t SAI_SlotSize
Definition: stm32f4xx_sai.h:137
void SAI_MuteFrameCounterConfig(SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_MuteCounter)
Enables or disables the Mute mode for the selected SAI block.
Definition: stm32f4xx_sai.c:589
void SAI_TRIStateConfig(SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_TRIState)
Configures the TRIState managment on data line for the selected SAI block.
Definition: stm32f4xx_sai.c:484
uint32_t SAI_FSOffset
Definition: stm32f4xx_sai.h:121
uint32_t SAI_OUTDRIV
Definition: stm32f4xx_sai.h:76
SAI Block Slot Init Structure definition.
Definition: stm32f4xx_sai.h:131
void SAI_FrameInit(SAI_Block_TypeDef *SAI_Block_x, SAI_FrameInitTypeDef *SAI_FrameInitStruct)
Initializes the SAI Block Audio frame according to the specified parameters in the SAI_FrameInitStruc...
Definition: stm32f4xx_sai.c:272
void SAI_DMACmd(SAI_Block_TypeDef *SAI_Block_x, FunctionalState NewState)
Enables or disables the SAI Block x DMA interface.
Definition: stm32f4xx_sai.c:702
void SAI_SlotInit(SAI_Block_TypeDef *SAI_Block_x, SAI_SlotInitTypeDef *SAI_SlotInitStruct)
Initializes the SAI Block audio Slot according to the specified parameters in the SAI_SlotInitStruct...
Definition: stm32f4xx_sai.c:320
Definition: stm32f4xx.h:1213
uint32_t SAI_Protocol
Definition: stm32f4xx_sai.h:59
void SAI_ITConfig(SAI_Block_TypeDef *SAI_Block_x, uint32_t SAI_IT, FunctionalState NewState)
Enables or disables the specified SAI Block interrupts.
Definition: stm32f4xx_sai.c:846
uint32_t SAI_FrameLength
Definition: stm32f4xx_sai.h:99
uint32_t SAI_ClockStrobing
Definition: stm32f4xx_sai.h:70