stm32h7xx_hal_sai_ex.c
Go to the documentation of this file.
1 
24 /* Includes ------------------------------------------------------------------*/
25 #include "stm32h7xx_hal.h"
26 
30 #ifdef HAL_SAI_MODULE_ENABLED
31 
37 /* Private types -------------------------------------------------------------*/
38 /* Private variables ---------------------------------------------------------*/
39 /* Private constants ---------------------------------------------------------*/
40 #define SAI_PDM_DELAY_MASK 0x77U
41 #define SAI_PDM_DELAY_OFFSET 8U
42 #define SAI_PDM_RIGHT_DELAY_OFFSET 4U
43 
44 /* Private macros ------------------------------------------------------------*/
45 /* Private functions ---------------------------------------------------------*/
46 /* Exported functions --------------------------------------------------------*/
72 {
73  HAL_StatusTypeDef status = HAL_OK;
74  uint32_t offset;
75  SAI_TypeDef *SaiBaseAddress;
76 
77  /* Get the SAI base address according to the SAI handle */
78 #if defined(SAI4)
79  SaiBaseAddress = ((hsai->Instance == SAI1_Block_A) ? SAI1 : \
80  (hsai->Instance == SAI4_Block_A) ? SAI4 : \
81  NULL);
82 #else
83  SaiBaseAddress = ((hsai->Instance == SAI1_Block_A) ? SAI1 : NULL);
84 #endif /* SAI4 */
85 
86  /* Check that SAI sub-block is SAI sub-block A */
87  if (SaiBaseAddress == NULL)
88  {
89  status = HAL_ERROR;
90  }
91  else
92  {
93  /* Check microphone delay parameters */
97 
98  /* Compute offset on PDMDLY register according mic pair number */
99  offset = SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1U);
100 
101  /* Check SAI state and offset */
102  if ((hsai->State != HAL_SAI_STATE_RESET) && (offset <= 24U))
103  {
104  /* Reset current delays for specified microphone */
105  SaiBaseAddress->PDMDLY &= ~(SAI_PDM_DELAY_MASK << offset);
106 
107  /* Apply new microphone delays */
108  SaiBaseAddress->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << offset);
109  }
110  else
111  {
112  status = HAL_ERROR;
113  }
114  }
115  return status;
116 }
117 
130 #endif /* HAL_SAI_MODULE_ENABLED */
131 
135 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
assert_param
#define assert_param(expr)
Include module's header file.
Definition: stm32f407/stm32f407g-disc1/Inc/stm32f4xx_hal_conf.h:353
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:40
SAI4_Block_A
#define SAI4_Block_A
Definition: stm32h735xx.h:2614
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
HAL_SAIEx_ConfigPdmMicDelay
HAL_StatusTypeDef HAL_SAIEx_ConfigPdmMicDelay(SAI_HandleTypeDef *hsai, SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay)
IS_SAI_PDM_MIC_DELAY
#define IS_SAI_PDM_MIC_DELAY(VALUE)
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_sai_ex.h:86
SAIEx_PdmMicDelayParamTypeDef::RightDelay
uint32_t RightDelay
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_sai_ex.h:55
HAL_ERROR
@ HAL_ERROR
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:43
__SAI_HandleTypeDef::State
__IO HAL_SAI_StateTypeDef State
Definition: stm32f7xx_hal_sai.h:217
SAIEx_PdmMicDelayParamTypeDef
PDM microphone delay structure definition.
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_sai_ex.h:47
IS_SAI_PDM_MIC_PAIRS_NUMBER
#define IS_SAI_PDM_MIC_PAIRS_NUMBER(VALUE)
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_sai.h:858
__SAI_HandleTypeDef::Instance
SAI_Block_TypeDef * Instance
Definition: stm32f7xx_hal_sai.h:193
SAI1_Block_A
#define SAI1_Block_A
Definition: stm32f469xx.h:1334
HAL_OK
@ HAL_OK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:42
SAI1
#define SAI1
Definition: MIMXRT1052.h:20666
SAI4
#define SAI4
Definition: stm32h735xx.h:2613
__SAI_HandleTypeDef
Definition: stm32f7xx_hal_sai.h:191
SAI_TypeDef::PDMDLY
__IO uint32_t PDMDLY
Definition: stm32h735xx.h:1376
SAIEx_PdmMicDelayParamTypeDef::MicPair
uint32_t MicPair
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_sai_ex.h:49
HAL_SAI_STATE_RESET
@ HAL_SAI_STATE_RESET
Definition: stm32f7xx_hal_sai.h:50
SAIEx_PdmMicDelayParamTypeDef::LeftDelay
uint32_t LeftDelay
Definition: stm32h735/stm32h735g-dk/Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_sai_ex.h:52
SAI_TypeDef
Serial Audio Interface.
Definition: stm32f469xx.h:843


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:55