stm32l4xx_hal_sai_ex.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  14. *
  15. * Redistribution and use in source and binary forms, with or without modification,
  16. * are permitted provided that the following conditions are met:
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ******************************************************************************
  38. */
  39. /* Includes ------------------------------------------------------------------*/
  40. #include "stm32l4xx_hal.h"
  41. /** @addtogroup STM32L4xx_HAL_Driver
  42. * @{
  43. */
  44. #ifdef HAL_SAI_MODULE_ENABLED
  45. #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
  46. /** @defgroup SAIEx SAIEx
  47. * @brief SAI Extended HAL module driver
  48. * @{
  49. */
  50. /* Private types -------------------------------------------------------------*/
  51. /* Private variables ---------------------------------------------------------*/
  52. /* Private constants ---------------------------------------------------------*/
  53. #define SAI_PDM_DELAY_MASK 0x77U
  54. #define SAI_PDM_DELAY_OFFSET 8U
  55. #define SAI_PDM_RIGHT_DELAY_OFFSET 4U
  56. /* Private macros ------------------------------------------------------------*/
  57. /* Private functions ---------------------------------------------------------*/
  58. /* Exported functions --------------------------------------------------------*/
  59. /** @defgroup SAIEx_Exported_Functions SAIEx Extended Exported Functions
  60. * @{
  61. */
  62. /** @defgroup SAIEx_Exported_Functions_Group1 Peripheral Control functions
  63. * @brief SAIEx control functions
  64. *
  65. @verbatim
  66. ===============================================================================
  67. ##### Extended features functions #####
  68. ===============================================================================
  69. [..] This section provides functions allowing to:
  70. (+) Modify PDM microphone delays
  71. @endverbatim
  72. * @{
  73. */
  74. /**
  75. * @brief Configure PDM microphone delays.
  76. * @param hsai SAI handle.
  77. * @param pdmMicDelay Microphone delays configuration.
  78. * @retval HAL status
  79. */
  80. HAL_StatusTypeDef HAL_SAIEx_ConfigPdmMicDelay(SAI_HandleTypeDef *hsai, SAIEx_PdmMicDelayParamTypeDef *pdmMicDelay)
  81. {
  82. HAL_StatusTypeDef status = HAL_OK;
  83. /* Check that SAI sub-block is SAI1 sub-block A */
  84. if(hsai->Instance != SAI1_Block_A)
  85. {
  86. status = HAL_ERROR;
  87. }
  88. else
  89. {
  90. /* Check microphone delay parameters */
  91. assert_param(IS_SAI_PDM_MIC_PAIRS_NUMBER(pdmMicDelay->MicPair));
  92. assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->LeftDelay));
  93. assert_param(IS_SAI_PDM_MIC_DELAY(pdmMicDelay->RightDelay));
  94. /* Check SAI state */
  95. if(hsai->State != HAL_SAI_STATE_RESET)
  96. {
  97. /* Reset current delays for specified microphone */
  98. SAI1->PDMDLY &= ~(SAI_PDM_DELAY_MASK << (SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1)));
  99. /* Apply new microphone delays */
  100. SAI1->PDMDLY |= (((pdmMicDelay->RightDelay << SAI_PDM_RIGHT_DELAY_OFFSET) | pdmMicDelay->LeftDelay) << \
  101. (SAI_PDM_DELAY_OFFSET * (pdmMicDelay->MicPair - 1)));
  102. }
  103. else
  104. {
  105. status = HAL_ERROR;
  106. }
  107. }
  108. return status;
  109. }
  110. /**
  111. * @}
  112. */
  113. /**
  114. * @}
  115. */
  116. /**
  117. * @}
  118. */
  119. #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
  120. #endif /* HAL_SAI_MODULE_ENABLED */
  121. /**
  122. * @}
  123. */
  124. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/