stm32l4xx_hal_sai_ex.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_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. * Copyright (c) 2017 STMicroelectronics.
  14. * All rights reserved.
  15. *
  16. * This software is licensed under terms that can be found in the LICENSE file
  17. * in the root directory of this software component.
  18. * If no LICENSE file comes with this software, it is provided AS-IS.
  19. *
  20. ******************************************************************************
  21. */
  22. /* Includes ------------------------------------------------------------------*/
  23. #include "stm32l4xx_hal.h"
  24. /** @addtogroup STM32L4xx_HAL_Driver
  25. * @{
  26. */
  27. #ifdef HAL_SAI_MODULE_ENABLED
  28. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) || \
  29. defined(STM32L4P5xx) || defined(STM32L4Q5xx)
  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(const SAI_HandleTypeDef *hsai,
  71. const SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay)
  72. {
  73. HAL_StatusTypeDef status = HAL_OK;
  74. uint32_t offset;
  75. /* Check that SAI sub-block is SAI1 sub-block A */
  76. if (hsai->Instance != SAI1_Block_A)
  77. {
  78. status = HAL_ERROR;
  79. }
  80. else
  81. {
  82. /* Check microphone delay parameters */
  83. assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(pdmMicDelay->MicPair));
  84. assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->LeftDelay));
  85. assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->RightDelay));
  86. /* Compute offset on PDMDLY register according mic pair number */
  87. offset = SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1U);
  88. /* Check SAI state and offset */
  89. if ((hsai->State != HAL_SAI_STATE_RESET) && (offset <= 24U))
  90. {
  91. /* Reset current delays for specified microphone */
  92. SAI1->PDMDLY &= ~(SAI_PDM_DELAY_MASK << offset);
  93. /* Apply new microphone delays */
  94. SAI1->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << offset);
  95. }
  96. else
  97. {
  98. status = HAL_ERROR;
  99. }
  100. }
  101. return status;
  102. }
  103. /**
  104. * @}
  105. */
  106. /**
  107. * @}
  108. */
  109. /**
  110. * @}
  111. */
  112. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx || */
  113. /* STM32L4P5xx || STM32L4Q5xx */
  114. #endif /* HAL_SAI_MODULE_ENABLED */
  115. /**
  116. * @}
  117. */