STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_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) 2017 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 "stm32h7xx_hal.h" 00025 00026 /** @addtogroup STM32H7xx_HAL_Driver 00027 * @{ 00028 */ 00029 #ifdef HAL_SAI_MODULE_ENABLED 00030 00031 /** @defgroup SAIEx SAIEx 00032 * @brief SAI Extended HAL module driver 00033 * @{ 00034 */ 00035 00036 /* Private types -------------------------------------------------------------*/ 00037 /* Private variables ---------------------------------------------------------*/ 00038 /* Private constants ---------------------------------------------------------*/ 00039 #define SAI_PDM_DELAY_MASK 0x77U 00040 #define SAI_PDM_DELAY_OFFSET 8U 00041 #define SAI_PDM_RIGHT_DELAY_OFFSET 4U 00042 00043 /* Private macros ------------------------------------------------------------*/ 00044 /* Private functions ---------------------------------------------------------*/ 00045 /* Exported functions --------------------------------------------------------*/ 00046 /** @defgroup SAIEx_Exported_Functions SAIEx Extended Exported Functions 00047 * @{ 00048 */ 00049 00050 /** @defgroup SAIEx_Exported_Functions_Group1 Peripheral Control functions 00051 * @brief SAIEx control functions 00052 * 00053 @verbatim 00054 =============================================================================== 00055 ##### Extended features functions ##### 00056 =============================================================================== 00057 [..] This section provides functions allowing to: 00058 (+) Modify PDM microphone delays 00059 00060 @endverbatim 00061 * @{ 00062 */ 00063 00064 /** 00065 * @brief Configure PDM microphone delays. 00066 * @param hsai SAI handle. 00067 * @param pdmMicDelay Microphone delays configuration. 00068 * @retval HAL status 00069 */ 00070 HAL_StatusTypeDef HAL_SAIEx_ConfigPdmMicDelay(SAI_HandleTypeDef *hsai, SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay) 00071 { 00072 HAL_StatusTypeDef status = HAL_OK; 00073 uint32_t offset; 00074 SAI_TypeDef *SaiBaseAddress; 00075 00076 /* Get the SAI base address according to the SAI handle */ 00077 #if defined(SAI4) 00078 SaiBaseAddress = ((hsai->Instance == SAI1_Block_A) ? SAI1 : \ 00079 (hsai->Instance == SAI4_Block_A) ? SAI4 : \ 00080 NULL); 00081 #else 00082 SaiBaseAddress = ((hsai->Instance == SAI1_Block_A) ? SAI1 : NULL); 00083 #endif /* SAI4 */ 00084 00085 /* Check that SAI sub-block is SAI sub-block A */ 00086 if (SaiBaseAddress == NULL) 00087 { 00088 status = HAL_ERROR; 00089 } 00090 else 00091 { 00092 /* Check microphone delay parameters */ 00093 assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(pdmMicDelay->MicPair)); 00094 assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->LeftDelay)); 00095 assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->RightDelay)); 00096 00097 /* Compute offset on PDMDLY register according mic pair number */ 00098 offset = SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1U); 00099 00100 /* Check SAI state and offset */ 00101 if ((hsai->State != HAL_SAI_STATE_RESET) && (offset <= 24U)) 00102 { 00103 /* Reset current delays for specified microphone */ 00104 SaiBaseAddress->PDMDLY &= ~(SAI_PDM_DELAY_MASK << offset); 00105 00106 /* Apply new microphone delays */ 00107 SaiBaseAddress->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << offset); 00108 } 00109 else 00110 { 00111 status = HAL_ERROR; 00112 } 00113 } 00114 return status; 00115 } 00116 00117 /** 00118 * @} 00119 */ 00120 00121 /** 00122 * @} 00123 */ 00124 00125 /** 00126 * @} 00127 */ 00128 00129 #endif /* HAL_SAI_MODULE_ENABLED */ 00130 /** 00131 * @} 00132 */ 00133