STM32G474xx HAL用户手册
stm32g4xx_hal_sai_ex.c
转到该文件的文档。
00001 /**
00002   ******************************************************************************
00003   * @file    stm32g4xx_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   * Copyright (c) 2019 STMicroelectronics.
00014   * All rights reserved.
00015   *
00016   * This software is licensed under terms that can be found in the LICENSE file
00017   * in the root directory of this software component.
00018   * If no LICENSE file comes with this software, it is provided AS-IS.
00019   *
00020   ******************************************************************************
00021   */
00022 
00023 /* Includes ------------------------------------------------------------------*/
00024 #include "stm32g4xx_hal.h"
00025 
00026 /** @addtogroup STM32G4xx_HAL_Driver
00027   * @{
00028   */
00029 
00030 #if defined(SAI1)
00031 #ifdef HAL_SAI_MODULE_ENABLED
00032 
00033 /** @defgroup SAIEx SAIEx
00034   * @brief SAI Extended HAL module driver
00035   * @{
00036   */
00037 
00038 /* Private types -------------------------------------------------------------*/
00039 /* Private variables ---------------------------------------------------------*/
00040 /* Private constants ---------------------------------------------------------*/
00041 /** @defgroup SAIEx_Private_Defines SAIEx Extended Private Defines
00042   * @{
00043   */
00044 #define SAI_PDM_DELAY_MASK          0x77U
00045 #define SAI_PDM_DELAY_OFFSET        8U
00046 #define SAI_PDM_RIGHT_DELAY_OFFSET  4U
00047 /**
00048   * @}
00049   */
00050 
00051 /* Private macros ------------------------------------------------------------*/
00052 /* Private functions ---------------------------------------------------------*/
00053 /* Exported functions --------------------------------------------------------*/
00054 /** @defgroup SAIEx_Exported_Functions SAIEx Extended Exported Functions
00055   * @{
00056   */
00057 
00058 /** @defgroup SAIEx_Exported_Functions_Group1 Peripheral Control functions
00059   * @brief    SAIEx control functions
00060   *
00061 @verbatim
00062  ===============================================================================
00063                  ##### Extended features functions #####
00064  ===============================================================================
00065     [..]  This section provides functions allowing to:
00066       (+) Modify PDM microphone delays
00067 
00068 @endverbatim
00069   * @{
00070   */
00071 
00072 /**
00073   * @brief  Configure PDM microphone delays.
00074   * @param  hsai SAI handle.
00075   * @param  pdmMicDelay Microphone delays configuration.
00076   * @retval HAL status
00077   */
00078 HAL_StatusTypeDef HAL_SAIEx_ConfigPdmMicDelay(const SAI_HandleTypeDef *hsai,
00079                                               const SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay)
00080 {
00081   HAL_StatusTypeDef status = HAL_OK;
00082   uint32_t offset;
00083 
00084 /* Check that SAI sub-block is SAI1 sub-block A */
00085 if (hsai->Instance != SAI1_Block_A)
00086   {
00087     status = HAL_ERROR;
00088   }
00089 else
00090   {
00091 /* Check microphone delay parameters */
00092     assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(pdmMicDelay->MicPair));
00093     assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->LeftDelay));
00094     assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->RightDelay));
00095 
00096 /* Compute offset on PDMDLY register according mic pair number */
00097     offset = SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1U);
00098 
00099 /* Check SAI state and offset */
00100     if ((hsai->State != HAL_SAI_STATE_RESET) && (offset <= 24U))
00100     {
00102 /* Reset current delays for specified microphone */
00103       SAI1->PDMDLY &= ~(SAI_PDM_DELAY_MASK << offset);
00104 
00105 /* Apply new microphone delays */
00106       SAI1->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << offset);
00107     }
00108     else
00109     {
00110       status = HAL_ERROR;
00111     }
00112   }
00113   return status;
00114 }
00115 
00116 /**
00117   * @}
00118   */
00119 
00120 /**
00121   * @}
00122   */
00123 
00124 /**
00125   * @}
00126   */
00127 
00128 #endif /* HAL_SAI_MODULE_ENABLED */
00129 #endif /* SAI1 */
00130 
00131 /**
00132   * @}
00133   */