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
3.9 KiB

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