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.
 
 
 

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