STM32L486xx HAL User Manual
stm32l4xx_hal_sai_ex.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_sai_ex.c
00004   * @author  MCD Application Team
00005   * @brief   SAI Extended HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionality of the SAI Peripheral Controller:
00008   *           + Modify PDM microphone delays.
00009   *
00010   ******************************************************************************
00011   * @attention
00012   *
00013   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00014   *
00015   * Redistribution and use in source and binary forms, with or without modification,
00016   * are permitted provided that the following conditions are met:
00017   *   1. Redistributions of source code must retain the above copyright notice,
00018   *      this list of conditions and the following disclaimer.
00019   *   2. Redistributions in binary form must reproduce the above copyright notice,
00020   *      this list of conditions and the following disclaimer in the documentation
00021   *      and/or other materials provided with the distribution.
00022   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00023   *      may be used to endorse or promote products derived from this software
00024   *      without specific prior written permission.
00025   *
00026   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00029   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00030   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00031   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00032   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00033   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00034   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036   *
00037   ******************************************************************************
00038   */
00039 
00040 /* Includes ------------------------------------------------------------------*/
00041 #include "stm32l4xx_hal.h"
00042 
00043 /** @addtogroup STM32L4xx_HAL_Driver
00044   * @{
00045   */
00046 #ifdef HAL_SAI_MODULE_ENABLED
00047 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
00048 
00049 /** @defgroup SAIEx SAIEx
00050   * @brief SAI Extended HAL module driver
00051   * @{
00052   */
00053 
00054 /* Private types -------------------------------------------------------------*/
00055 /* Private variables ---------------------------------------------------------*/
00056 /* Private constants ---------------------------------------------------------*/
00057 #define SAI_PDM_DELAY_MASK          0x77U
00058 #define SAI_PDM_DELAY_OFFSET        8U
00059 #define SAI_PDM_RIGHT_DELAY_OFFSET  4U
00060 
00061 /* Private macros ------------------------------------------------------------*/
00062 /* Private functions ---------------------------------------------------------*/
00063 /* Exported functions --------------------------------------------------------*/
00064 /** @defgroup SAIEx_Exported_Functions SAIEx Extended Exported Functions
00065   * @{
00066   */
00067 
00068 /** @defgroup SAIEx_Exported_Functions_Group1 Peripheral Control functions
00069   * @brief    SAIEx control functions
00070   *
00071 @verbatim
00072  ===============================================================================
00073                  ##### Extended features functions #####
00074  ===============================================================================
00075     [..]  This section provides functions allowing to:
00076       (+) Modify PDM microphone delays
00077 
00078 @endverbatim
00079   * @{
00080   */
00081 
00082 /**
00083   * @brief  Configure PDM microphone delays.
00084   * @param  hsai SAI handle.
00085   * @param  pdmMicDelay Microphone delays configuration.
00086   * @retval HAL status
00087   */
00088 HAL_StatusTypeDef HAL_SAIEx_ConfigPdmMicDelay(SAI_HandleTypeDef *hsai, SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay)
00089 {
00090   HAL_StatusTypeDef status = HAL_OK;
00091   uint32_t offset;
00092 
00093   /* Check that SAI sub-block is SAI1 sub-block A */
00094   if (hsai->Instance != SAI1_Block_A)
00095   {
00096     status = HAL_ERROR;
00097   }
00098   else
00099   {
00100     /* Check microphone delay parameters */
00101     assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(pdmMicDelay->MicPair));
00102     assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->LeftDelay));
00103     assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->RightDelay));
00104 
00105     /* Compute offset on PDMDLY register according mic pair number */
00106     offset = SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1U);
00107 
00108     /* Check SAI state and offset */
00109     if ((hsai->State != HAL_SAI_STATE_RESET) && (offset <= 24U))
00110     {
00111       /* Reset current delays for specified microphone */
00112       SAI1->PDMDLY &= ~(SAI_PDM_DELAY_MASK << offset);
00113 
00114       /* Apply new microphone delays */
00115       SAI1->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << offset);
00116     }
00117     else
00118     {
00119       status = HAL_ERROR;
00120     }
00121   }
00122   return status;
00123 }
00124 
00125 /**
00126   * @}
00127   */
00128 
00129 /**
00130   * @}
00131   */
00132 
00133 /**
00134   * @}
00135   */
00136 
00137 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
00138 #endif /* HAL_SAI_MODULE_ENABLED */
00139 /**
00140   * @}
00141   */
00142 
00143 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/