• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2   ******************************************************************************
3   * @file    stm32mp1xx_hal_sai_ex.c
4   * @author  MCD Application Team
5   * @brief   SAI Extended HAL module driver.
6   *          This file provides firmware functions to manage the following
7   *          functionality of the SAI Peripheral Controller:
8   *           + Modify PDM microphone delays.
9   *
10   ******************************************************************************
11   * @attention
12   *
13   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
14   * All rights reserved.</center></h2>
15   *
16   * This software component is licensed by ST under BSD 3-Clause license,
17   * the "License"; You may not use this file except in compliance with the
18   * License. You may obtain a copy of the License at:
19   *                        opensource.org/licenses/BSD-3-Clause
20   *
21   ******************************************************************************
22   */
23 
24 /* Includes ------------------------------------------------------------------*/
25 #include "stm32mp1xx_hal.h"
26 
27 /** @addtogroup STM32MP1xx_HAL_Driver
28   * @{
29   */
30 #ifdef HAL_SAI_MODULE_ENABLED
31 
32 /** @defgroup SAIEx SAIEx
33   * @brief SAI Extended HAL module driver
34   * @{
35   */
36 
37 /* Private types -------------------------------------------------------------*/
38 /* Private variables ---------------------------------------------------------*/
39 /* Private constants ---------------------------------------------------------*/
40 /** @defgroup SAIEx_Private_Defines SAIEx Extended Private Defines
41   * @{
42   */
43 #define SAI_PDM_DELAY_MASK          0x77U
44 #define SAI_PDM_DELAY_OFFSET        8U
45 #define SAI_PDM_RIGHT_DELAY_OFFSET  4U
46 /**
47   * @}
48   */
49 
50 /* Private macros ------------------------------------------------------------*/
51 /* Private functions ---------------------------------------------------------*/
52 /* Exported functions --------------------------------------------------------*/
53 /** @defgroup SAIEx_Exported_Functions SAIEx Extended Exported Functions
54   * @{
55   */
56 
57 /** @defgroup SAIEx_Exported_Functions_Group1 Peripheral Control functions
58   * @brief    SAIEx control functions
59   *
60 @verbatim
61  ===============================================================================
62                  ##### Extended features functions #####
63  ===============================================================================
64     [..]  This section provides functions allowing to:
65       (+) Modify PDM microphone delays
66 
67 @endverbatim
68   * @{
69   */
70 
71 /**
72   * @brief  Configure PDM microphone delays.
73   * @param  hsai SAI handle.
74   * @param  pdmMicDelay Microphone delays configuration.
75   * @retval HAL status
76   */
HAL_SAIEx_ConfigPdmMicDelay(SAI_HandleTypeDef * hsai,SAIEx_PdmMicDelayParamTypeDef * pdmMicDelay)77 HAL_StatusTypeDef HAL_SAIEx_ConfigPdmMicDelay(SAI_HandleTypeDef *hsai, SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay)
78 {
79   HAL_StatusTypeDef status = HAL_OK;
80   uint32_t offset;
81   SAI_TypeDef *SaiBaseAddress;
82 
83 #if defined(SAI4)
84   /* Get the SAI base address according to the SAI handle */
85   SaiBaseAddress = (hsai->Instance == SAI1_Block_A) ? SAI1 : \
86                    ((hsai->Instance == SAI4_Block_A) ? SAI4 : \
87                      NULL);
88 #else
89   /* Get the SAI base address according to the SAI handle */
90   SaiBaseAddress = (hsai->Instance == SAI1_Block_A) ? SAI1 : NULL;
91 #endif
92 
93   /* Check that SAI sub-block is SAI sub-block A */
94   if (SaiBaseAddress == NULL)
95   {
96     status = HAL_ERROR;
97   }
98   else
99   {
100     /* Check microphone delay parameters */
101     assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(pdmMicDelay->MicPair));
102     assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->LeftDelay));
103     assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->RightDelay));
104 
105     /* Compute offset on PDMDLY register according mic pair number */
106     offset = SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1U);
107 
108     /* Check SAI state and offset */
109     if ((hsai->State != HAL_SAI_STATE_RESET) && (offset <= 24U))
110     {
111       /* Reset current delays for specified microphone */
112       SaiBaseAddress->PDMDLY &= ~(SAI_PDM_DELAY_MASK << offset);
113 
114       /* Apply new microphone delays */
115       SaiBaseAddress->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << offset);
116     }
117     else
118     {
119       status = HAL_ERROR;
120     }
121   }
122   return status;
123 }
124 
125 /**
126   * @}
127   */
128 
129 /**
130   * @}
131   */
132 
133 /**
134   * @}
135   */
136 
137 #endif /* HAL_SAI_MODULE_ENABLED */
138 /**
139   * @}
140   */
141 
142 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
143