You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

136 lines
4.1 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_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) 2017 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. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32h7xx_hal.h"
  25. /** @addtogroup STM32H7xx_HAL_Driver
  26. * @{
  27. */
  28. #ifdef HAL_SAI_MODULE_ENABLED
  29. /** @defgroup SAIEx SAIEx
  30. * @brief SAI Extended HAL module driver
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. #define SAI_PDM_DELAY_MASK 0x77U
  37. #define SAI_PDM_DELAY_OFFSET 8U
  38. #define SAI_PDM_RIGHT_DELAY_OFFSET 4U
  39. /* Private macros ------------------------------------------------------------*/
  40. /* Private functions ---------------------------------------------------------*/
  41. /* Exported functions --------------------------------------------------------*/
  42. /** @defgroup SAIEx_Exported_Functions SAIEx Extended Exported Functions
  43. * @{
  44. */
  45. /** @defgroup SAIEx_Exported_Functions_Group1 Peripheral Control functions
  46. * @brief SAIEx control functions
  47. *
  48. @verbatim
  49. ===============================================================================
  50. ##### Extended features functions #####
  51. ===============================================================================
  52. [..] This section provides functions allowing to:
  53. (+) Modify PDM microphone delays
  54. @endverbatim
  55. * @{
  56. */
  57. /**
  58. * @brief Configure PDM microphone delays.
  59. * @param hsai SAI handle.
  60. * @param pdmMicDelay Microphone delays configuration.
  61. * @retval HAL status
  62. */
  63. HAL_StatusTypeDef HAL_SAIEx_ConfigPdmMicDelay(SAI_HandleTypeDef *hsai, SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay)
  64. {
  65. HAL_StatusTypeDef status = HAL_OK;
  66. uint32_t offset;
  67. SAI_TypeDef *SaiBaseAddress;
  68. /* Get the SAI base address according to the SAI handle */
  69. #if defined(SAI4)
  70. SaiBaseAddress = ((hsai->Instance == SAI1_Block_A) ? SAI1 : \
  71. (hsai->Instance == SAI4_Block_A) ? SAI4 : \
  72. NULL);
  73. #else
  74. SaiBaseAddress = ((hsai->Instance == SAI1_Block_A) ? SAI1 : NULL);
  75. #endif /* SAI4 */
  76. /* Check that SAI sub-block is SAI sub-block A */
  77. if (SaiBaseAddress == NULL)
  78. {
  79. status = HAL_ERROR;
  80. }
  81. else
  82. {
  83. /* Check microphone delay parameters */
  84. assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(pdmMicDelay->MicPair));
  85. assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->LeftDelay));
  86. assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->RightDelay));
  87. /* Compute offset on PDMDLY register according mic pair number */
  88. offset = SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1U);
  89. /* Check SAI state and offset */
  90. if ((hsai->State != HAL_SAI_STATE_RESET) && (offset <= 24U))
  91. {
  92. /* Reset current delays for specified microphone */
  93. SaiBaseAddress->PDMDLY &= ~(SAI_PDM_DELAY_MASK << offset);
  94. /* Apply new microphone delays */
  95. SaiBaseAddress->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << offset);
  96. }
  97. else
  98. {
  99. status = HAL_ERROR;
  100. }
  101. }
  102. return status;
  103. }
  104. /**
  105. * @}
  106. */
  107. /**
  108. * @}
  109. */
  110. /**
  111. * @}
  112. */
  113. #endif /* HAL_SAI_MODULE_ENABLED */
  114. /**
  115. * @}
  116. */
  117. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/