STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_sai_ex.c
Go to the documentation of this file.
1 
24 /* Includes ------------------------------------------------------------------*/
25 #include "stm32l4xx_hal.h"
26 
30 #ifdef HAL_SAI_MODULE_ENABLED
31 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
32 
38 /* Private types -------------------------------------------------------------*/
39 /* Private variables ---------------------------------------------------------*/
40 /* Private constants ---------------------------------------------------------*/
44 #define SAI_PDM_DELAY_MASK 0x77U
45 #define SAI_PDM_DELAY_OFFSET 8U
46 #define SAI_PDM_RIGHT_DELAY_OFFSET 4U
47 
51 /* Private macros ------------------------------------------------------------*/
52 /* Private functions ---------------------------------------------------------*/
53 /* Exported functions --------------------------------------------------------*/
79 {
80  HAL_StatusTypeDef status = HAL_OK;
81  uint32_t offset;
82 
83  /* Check that SAI sub-block is SAI1 sub-block A */
84  if (hsai->Instance != SAI1_Block_A)
85  {
86  status = HAL_ERROR;
87  }
88  else
89  {
90  /* Check microphone delay parameters */
91  assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(pdmMicDelay->MicPair));
92  assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->LeftDelay));
93  assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->RightDelay));
94 
95  /* Compute offset on PDMDLY register according mic pair number */
96  offset = SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1U);
97 
98  /* Check SAI state and offset */
99  if ((hsai->State != HAL_SAI_STATE_RESET) && (offset <= 24U))
100  {
101  /* Reset current delays for specified microphone */
102  SAI1->PDMDLY &= ~(SAI_PDM_DELAY_MASK << offset);
103 
104  /* Apply new microphone delays */
105  SAI1->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << offset);
106  }
107  else
108  {
109  status = HAL_ERROR;
110  }
111  }
112  return status;
113 }
114 
127 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
128 #endif /* HAL_SAI_MODULE_ENABLED */
129 
133 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_SAIEx_ConfigPdmMicDelay(SAI_HandleTypeDef *hsai, SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay)
Configure PDM microphone delays.
This file contains all the functions prototypes for the HAL module driver.
SAI_Block_TypeDef * Instance
__IO HAL_SAI_StateTypeDef State
return HAL_OK
PDM microphone delay structure definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))