STM32L443xx HAL User Manual
|
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 * 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 "stm32l4xx_hal.h" 00025 00026 /** @addtogroup STM32L4xx_HAL_Driver 00027 * @{ 00028 */ 00029 #ifdef HAL_SAI_MODULE_ENABLED 00030 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) || \ 00031 defined(STM32L4P5xx) || defined(STM32L4Q5xx) 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(SAI_HandleTypeDef *hsai, SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay) 00079 { 00080 HAL_StatusTypeDef status = HAL_OK; 00081 uint32_t offset; 00082 00083 /* Check that SAI sub-block is SAI1 sub-block A */ 00084 if (hsai->Instance != SAI1_Block_A) 00085 { 00086 status = HAL_ERROR; 00087 } 00088 else 00089 { 00090 /* Check microphone delay parameters */ 00091 assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(pdmMicDelay->MicPair)); 00092 assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->LeftDelay)); 00093 assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->RightDelay)); 00094 00095 /* Compute offset on PDMDLY register according mic pair number */ 00096 offset = SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1U); 00097 00098 /* Check SAI state and offset */ 00099 if ((hsai->State != HAL_SAI_STATE_RESET) && (offset <= 24U)) 00100 { 00101 /* Reset current delays for specified microphone */ 00102 SAI1->PDMDLY &= ~(SAI_PDM_DELAY_MASK << offset); 00103 00104 /* Apply new microphone delays */ 00105 SAI1->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << offset); 00106 } 00107 else 00108 { 00109 status = HAL_ERROR; 00110 } 00111 } 00112 return status; 00113 } 00114 00115 /** 00116 * @} 00117 */ 00118 00119 /** 00120 * @} 00121 */ 00122 00123 /** 00124 * @} 00125 */ 00126 00127 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx || */ 00128 /* STM32L4P5xx || STM32L4Q5xx */ 00129 #endif /* HAL_SAI_MODULE_ENABLED */ 00130 /** 00131 * @} 00132 */ 00133