mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F072RB/stm32f0xx_hal_i2s.c@310:6188e0254baa, 2014-09-16 (annotated)
- Committer:
- janekm
- Date:
- Tue Sep 16 22:42:01 2014 +0000
- Revision:
- 310:6188e0254baa
- Parent:
- 218:44081b78fdc2
N/A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 205:c41fc65bcfb4 | 1 | /** |
mbed_official | 205:c41fc65bcfb4 | 2 | ****************************************************************************** |
mbed_official | 205:c41fc65bcfb4 | 3 | * @file stm32f0xx_hal_i2s.c |
mbed_official | 205:c41fc65bcfb4 | 4 | * @author MCD Application Team |
mbed_official | 205:c41fc65bcfb4 | 5 | * @version V1.0.0 |
mbed_official | 218:44081b78fdc2 | 6 | * @date 28-May-2014 |
mbed_official | 205:c41fc65bcfb4 | 7 | * @brief I2S HAL module driver. |
mbed_official | 205:c41fc65bcfb4 | 8 | * |
mbed_official | 205:c41fc65bcfb4 | 9 | * This file provides firmware functions to manage the following |
mbed_official | 205:c41fc65bcfb4 | 10 | * functionalities of the Integrated Interchip Sound (I2S) peripheral: |
mbed_official | 205:c41fc65bcfb4 | 11 | * + Initialization and de-initialization functions |
mbed_official | 205:c41fc65bcfb4 | 12 | * + IO operation functions |
mbed_official | 205:c41fc65bcfb4 | 13 | * + Peripheral State and Errors functions |
mbed_official | 205:c41fc65bcfb4 | 14 | @verbatim |
mbed_official | 205:c41fc65bcfb4 | 15 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 16 | ##### How to use this driver ##### |
mbed_official | 205:c41fc65bcfb4 | 17 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 18 | [..] |
mbed_official | 205:c41fc65bcfb4 | 19 | The I2S HAL driver can be used as follows: |
mbed_official | 205:c41fc65bcfb4 | 20 | |
mbed_official | 205:c41fc65bcfb4 | 21 | (#) Declare a I2S_HandleTypeDef handle structure. |
mbed_official | 205:c41fc65bcfb4 | 22 | (#) Initialize the I2S low level resources by implement the HAL_I2S_MspInit() API: |
mbed_official | 205:c41fc65bcfb4 | 23 | (##) Enable the SPIx interface clock. |
mbed_official | 205:c41fc65bcfb4 | 24 | (##) I2S pins configuration: |
mbed_official | 205:c41fc65bcfb4 | 25 | (+++) Enable the clock for the I2S GPIOs. |
mbed_official | 205:c41fc65bcfb4 | 26 | (+++) Configure these I2S pins as alternate function pull-up. |
mbed_official | 205:c41fc65bcfb4 | 27 | (##) NVIC configuration if you need to use interrupt process (HAL_I2S_Transmit_IT() |
mbed_official | 205:c41fc65bcfb4 | 28 | and HAL_I2S_Receive_IT() APIs). |
mbed_official | 205:c41fc65bcfb4 | 29 | (+++) Configure the I2Sx interrupt priority. |
mbed_official | 205:c41fc65bcfb4 | 30 | (+++) Enable the NVIC I2S IRQ handle. |
mbed_official | 205:c41fc65bcfb4 | 31 | (##) DMA Configuration if you need to use DMA process (HAL_I2S_Transmit_DMA() |
mbed_official | 205:c41fc65bcfb4 | 32 | and HAL_I2S_Receive_DMA() APIs: |
mbed_official | 205:c41fc65bcfb4 | 33 | (+++) Declare a DMA handle structure for the Tx/Rx stream. |
mbed_official | 205:c41fc65bcfb4 | 34 | (+++) Enable the DMAx interface clock. |
mbed_official | 205:c41fc65bcfb4 | 35 | (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
mbed_official | 205:c41fc65bcfb4 | 36 | (+++) Configure the DMA Tx/Rx Channel. |
mbed_official | 205:c41fc65bcfb4 | 37 | (+++) Associate the initilalized DMA handle to the I2S DMA Tx/Rx handle. |
mbed_official | 205:c41fc65bcfb4 | 38 | (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the |
mbed_official | 205:c41fc65bcfb4 | 39 | DMA Tx/Rx Channel. |
mbed_official | 205:c41fc65bcfb4 | 40 | |
mbed_official | 205:c41fc65bcfb4 | 41 | (#) Program the Mode, Standard, Data Format, MCLK Output, Audio frequency and Polarity |
mbed_official | 205:c41fc65bcfb4 | 42 | using HAL_I2S_Init() function. |
mbed_official | 205:c41fc65bcfb4 | 43 | |
mbed_official | 205:c41fc65bcfb4 | 44 | -@- The specific I2S interrupts (Transmission complete interrupt, |
mbed_official | 205:c41fc65bcfb4 | 45 | RXNE interrupt and Error Interrupts) will be managed using the macros |
mbed_official | 205:c41fc65bcfb4 | 46 | __I2S_ENABLE_IT() and __I2S_DISABLE_IT() inside the transmit and receive process. |
mbed_official | 205:c41fc65bcfb4 | 47 | -@- Make sure that either: |
mbed_official | 205:c41fc65bcfb4 | 48 | (+@) External clock source is configured after setting correctly |
mbed_official | 205:c41fc65bcfb4 | 49 | the define constant EXTERNAL_CLOCK_VALUE in the stm32f0xx_hal_conf.h file. |
mbed_official | 205:c41fc65bcfb4 | 50 | |
mbed_official | 205:c41fc65bcfb4 | 51 | (#) Three mode of operations are available within this driver : |
mbed_official | 205:c41fc65bcfb4 | 52 | |
mbed_official | 205:c41fc65bcfb4 | 53 | *** Polling mode IO operation *** |
mbed_official | 205:c41fc65bcfb4 | 54 | ================================= |
mbed_official | 205:c41fc65bcfb4 | 55 | [..] |
mbed_official | 205:c41fc65bcfb4 | 56 | (+) Send an amount of data in blocking mode using HAL_I2S_Transmit() |
mbed_official | 205:c41fc65bcfb4 | 57 | (+) Receive an amount of data in blocking mode using HAL_I2S_Receive() |
mbed_official | 205:c41fc65bcfb4 | 58 | |
mbed_official | 205:c41fc65bcfb4 | 59 | *** Interrupt mode IO operation *** |
mbed_official | 205:c41fc65bcfb4 | 60 | =================================== |
mbed_official | 205:c41fc65bcfb4 | 61 | [..] |
mbed_official | 205:c41fc65bcfb4 | 62 | (+) Send an amount of data in non blocking mode using HAL_I2S_Transmit_IT() |
mbed_official | 205:c41fc65bcfb4 | 63 | (+) At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can |
mbed_official | 205:c41fc65bcfb4 | 64 | add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback |
mbed_official | 205:c41fc65bcfb4 | 65 | (+) At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can |
mbed_official | 205:c41fc65bcfb4 | 66 | add his own code by customization of function pointer HAL_I2S_TxCpltCallback |
mbed_official | 205:c41fc65bcfb4 | 67 | (+) Receive an amount of data in non blocking mode using HAL_I2S_Receive_IT() |
mbed_official | 205:c41fc65bcfb4 | 68 | (+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can |
mbed_official | 205:c41fc65bcfb4 | 69 | add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback |
mbed_official | 205:c41fc65bcfb4 | 70 | (+) At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can |
mbed_official | 205:c41fc65bcfb4 | 71 | add his own code by customization of function pointer HAL_I2S_RxCpltCallback |
mbed_official | 205:c41fc65bcfb4 | 72 | (+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can |
mbed_official | 205:c41fc65bcfb4 | 73 | add his own code by customization of function pointer HAL_I2S_ErrorCallback |
mbed_official | 205:c41fc65bcfb4 | 74 | |
mbed_official | 205:c41fc65bcfb4 | 75 | *** DMA mode IO operation *** |
mbed_official | 205:c41fc65bcfb4 | 76 | ============================== |
mbed_official | 205:c41fc65bcfb4 | 77 | [..] |
mbed_official | 205:c41fc65bcfb4 | 78 | (+) Send an amount of data in non blocking mode (DMA) using HAL_I2S_Transmit_DMA() |
mbed_official | 205:c41fc65bcfb4 | 79 | (+) At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can |
mbed_official | 205:c41fc65bcfb4 | 80 | add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback |
mbed_official | 205:c41fc65bcfb4 | 81 | (+) At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can |
mbed_official | 205:c41fc65bcfb4 | 82 | add his own code by customization of function pointer HAL_I2S_TxCpltCallback |
mbed_official | 205:c41fc65bcfb4 | 83 | (+) Receive an amount of data in non blocking mode (DMA) using HAL_I2S_Receive_DMA() |
mbed_official | 205:c41fc65bcfb4 | 84 | (+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can |
mbed_official | 205:c41fc65bcfb4 | 85 | add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback |
mbed_official | 205:c41fc65bcfb4 | 86 | (+) At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can |
mbed_official | 205:c41fc65bcfb4 | 87 | add his own code by customization of function pointer HAL_I2S_RxCpltCallback |
mbed_official | 205:c41fc65bcfb4 | 88 | (+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can |
mbed_official | 205:c41fc65bcfb4 | 89 | add his own code by customization of function pointer HAL_I2S_ErrorCallback |
mbed_official | 205:c41fc65bcfb4 | 90 | (+) Pause the DMA Transfer using HAL_I2S_DMAPause() |
mbed_official | 205:c41fc65bcfb4 | 91 | (+) Resume the DMA Transfer using HAL_I2S_DMAResume() |
mbed_official | 205:c41fc65bcfb4 | 92 | (+) Stop the DMA Transfer using HAL_I2S_DMAStop() |
mbed_official | 205:c41fc65bcfb4 | 93 | |
mbed_official | 205:c41fc65bcfb4 | 94 | *** I2S HAL driver macros list *** |
mbed_official | 205:c41fc65bcfb4 | 95 | ============================================= |
mbed_official | 205:c41fc65bcfb4 | 96 | [..] |
mbed_official | 205:c41fc65bcfb4 | 97 | Below the list of most used macros in USART HAL driver. |
mbed_official | 205:c41fc65bcfb4 | 98 | |
mbed_official | 205:c41fc65bcfb4 | 99 | (+) __HAL_I2S_ENABLE: Enable the specified SPI peripheral (in I2S mode) |
mbed_official | 205:c41fc65bcfb4 | 100 | (+) __HAL_I2S_DISABLE: Disable the specified SPI peripheral (in I2S mode) |
mbed_official | 205:c41fc65bcfb4 | 101 | (+) __HAL_I2S_ENABLE_IT : Enable the specified I2S interrupts |
mbed_official | 205:c41fc65bcfb4 | 102 | (+) __HAL_I2S_DISABLE_IT : Disable the specified I2S interrupts |
mbed_official | 205:c41fc65bcfb4 | 103 | (+) __HAL_I2S_GET_FLAG: Check whether the specified I2S flag is set or not |
mbed_official | 205:c41fc65bcfb4 | 104 | |
mbed_official | 205:c41fc65bcfb4 | 105 | [..] |
mbed_official | 205:c41fc65bcfb4 | 106 | (@) You can refer to the I2S HAL driver header file for more useful macros |
mbed_official | 205:c41fc65bcfb4 | 107 | |
mbed_official | 205:c41fc65bcfb4 | 108 | @endverbatim |
mbed_official | 205:c41fc65bcfb4 | 109 | ****************************************************************************** |
mbed_official | 205:c41fc65bcfb4 | 110 | * @attention |
mbed_official | 205:c41fc65bcfb4 | 111 | * |
mbed_official | 205:c41fc65bcfb4 | 112 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 205:c41fc65bcfb4 | 113 | * |
mbed_official | 205:c41fc65bcfb4 | 114 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 205:c41fc65bcfb4 | 115 | * are permitted provided that the following conditions are met: |
mbed_official | 205:c41fc65bcfb4 | 116 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 205:c41fc65bcfb4 | 117 | * this list of conditions and the following disclaimer. |
mbed_official | 205:c41fc65bcfb4 | 118 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 205:c41fc65bcfb4 | 119 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 205:c41fc65bcfb4 | 120 | * and/or other materials provided with the distribution. |
mbed_official | 205:c41fc65bcfb4 | 121 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 205:c41fc65bcfb4 | 122 | * may be used to endorse or promote products derived from this software |
mbed_official | 205:c41fc65bcfb4 | 123 | * without specific prior written permission. |
mbed_official | 205:c41fc65bcfb4 | 124 | * |
mbed_official | 205:c41fc65bcfb4 | 125 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 205:c41fc65bcfb4 | 126 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 205:c41fc65bcfb4 | 127 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 205:c41fc65bcfb4 | 128 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 205:c41fc65bcfb4 | 129 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 205:c41fc65bcfb4 | 130 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 205:c41fc65bcfb4 | 131 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 205:c41fc65bcfb4 | 132 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 205:c41fc65bcfb4 | 133 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 205:c41fc65bcfb4 | 134 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 205:c41fc65bcfb4 | 135 | * |
mbed_official | 205:c41fc65bcfb4 | 136 | ****************************************************************************** |
mbed_official | 205:c41fc65bcfb4 | 137 | */ |
mbed_official | 205:c41fc65bcfb4 | 138 | |
mbed_official | 205:c41fc65bcfb4 | 139 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 140 | #include "stm32f0xx_hal.h" |
mbed_official | 205:c41fc65bcfb4 | 141 | |
mbed_official | 205:c41fc65bcfb4 | 142 | /** @addtogroup STM32F0xx_HAL_Driver |
mbed_official | 205:c41fc65bcfb4 | 143 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 144 | */ |
mbed_official | 205:c41fc65bcfb4 | 145 | |
mbed_official | 205:c41fc65bcfb4 | 146 | /** @defgroup I2S |
mbed_official | 205:c41fc65bcfb4 | 147 | * @brief I2S HAL module driver |
mbed_official | 205:c41fc65bcfb4 | 148 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 149 | */ |
mbed_official | 205:c41fc65bcfb4 | 150 | |
mbed_official | 205:c41fc65bcfb4 | 151 | #ifdef HAL_I2S_MODULE_ENABLED |
mbed_official | 205:c41fc65bcfb4 | 152 | |
mbed_official | 205:c41fc65bcfb4 | 153 | #if defined(STM32F031x6) || defined(STM32F038xx) || \ |
mbed_official | 205:c41fc65bcfb4 | 154 | defined(STM32F051x8) || defined(STM32F058xx) || \ |
mbed_official | 205:c41fc65bcfb4 | 155 | defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || \ |
mbed_official | 205:c41fc65bcfb4 | 156 | defined(STM32F042x6) || defined(STM32F048xx) |
mbed_official | 205:c41fc65bcfb4 | 157 | |
mbed_official | 205:c41fc65bcfb4 | 158 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 159 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 160 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 161 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 162 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 163 | static void I2S_DMATxCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 205:c41fc65bcfb4 | 164 | static void I2S_DMATxHalfCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 205:c41fc65bcfb4 | 165 | static void I2S_DMARxCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 205:c41fc65bcfb4 | 166 | static void I2S_DMARxHalfCplt(DMA_HandleTypeDef *hdma); |
mbed_official | 205:c41fc65bcfb4 | 167 | static void I2S_DMAError(DMA_HandleTypeDef *hdma); |
mbed_official | 205:c41fc65bcfb4 | 168 | static void I2S_Transmit_IT(I2S_HandleTypeDef *hi2s); |
mbed_official | 205:c41fc65bcfb4 | 169 | static void I2S_Receive_IT(I2S_HandleTypeDef *hi2s); |
mbed_official | 205:c41fc65bcfb4 | 170 | static HAL_StatusTypeDef I2S_WaitFlagStateUntilTimeout(I2S_HandleTypeDef *hi2s, uint32_t Flag, uint32_t State, uint32_t Timeout); |
mbed_official | 205:c41fc65bcfb4 | 171 | |
mbed_official | 205:c41fc65bcfb4 | 172 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 173 | |
mbed_official | 205:c41fc65bcfb4 | 174 | /** @defgroup I2S_Private_Functions |
mbed_official | 205:c41fc65bcfb4 | 175 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 176 | */ |
mbed_official | 205:c41fc65bcfb4 | 177 | |
mbed_official | 205:c41fc65bcfb4 | 178 | /** @defgroup I2S_Group1 Initialization and de-initialization functions |
mbed_official | 205:c41fc65bcfb4 | 179 | * @brief Initialization and Configuration functions |
mbed_official | 205:c41fc65bcfb4 | 180 | * |
mbed_official | 205:c41fc65bcfb4 | 181 | @verbatim |
mbed_official | 205:c41fc65bcfb4 | 182 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 183 | ##### Initialization and de-initialization functions ##### |
mbed_official | 205:c41fc65bcfb4 | 184 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 185 | [..] This subsection provides a set of functions allowing to initialize and |
mbed_official | 205:c41fc65bcfb4 | 186 | de-initialiaze the I2Sx peripheral in simplex mode: |
mbed_official | 205:c41fc65bcfb4 | 187 | |
mbed_official | 205:c41fc65bcfb4 | 188 | (+) User must Implement HAL_I2S_MspInit() function in which he configures |
mbed_official | 205:c41fc65bcfb4 | 189 | all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ). |
mbed_official | 205:c41fc65bcfb4 | 190 | |
mbed_official | 205:c41fc65bcfb4 | 191 | (+) Call the function HAL_I2S_Init() to configure the selected device with |
mbed_official | 205:c41fc65bcfb4 | 192 | the selected configuration: |
mbed_official | 205:c41fc65bcfb4 | 193 | (++) Mode |
mbed_official | 205:c41fc65bcfb4 | 194 | (++) Standard |
mbed_official | 205:c41fc65bcfb4 | 195 | (++) Data Format |
mbed_official | 205:c41fc65bcfb4 | 196 | (++) MCLK Output |
mbed_official | 205:c41fc65bcfb4 | 197 | (++) Audio frequency |
mbed_official | 205:c41fc65bcfb4 | 198 | (++) Polarity |
mbed_official | 205:c41fc65bcfb4 | 199 | |
mbed_official | 205:c41fc65bcfb4 | 200 | (+) Call the function HAL_I2S_DeInit() to restore the default configuration |
mbed_official | 205:c41fc65bcfb4 | 201 | of the selected I2Sx periperal. |
mbed_official | 205:c41fc65bcfb4 | 202 | @endverbatim |
mbed_official | 205:c41fc65bcfb4 | 203 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 204 | */ |
mbed_official | 205:c41fc65bcfb4 | 205 | |
mbed_official | 205:c41fc65bcfb4 | 206 | /** |
mbed_official | 205:c41fc65bcfb4 | 207 | * @brief Initializes the I2S according to the specified parameters |
mbed_official | 205:c41fc65bcfb4 | 208 | * in the I2S_InitTypeDef and create the associated handle. |
mbed_official | 205:c41fc65bcfb4 | 209 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 210 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 211 | */ |
mbed_official | 205:c41fc65bcfb4 | 212 | HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 213 | { |
mbed_official | 205:c41fc65bcfb4 | 214 | uint32_t tmpreg = 0, i2sdiv = 2, i2sodd = 0, packetlength = 1; |
mbed_official | 205:c41fc65bcfb4 | 215 | uint32_t tmp = 0, i2sclk = 0; |
mbed_official | 205:c41fc65bcfb4 | 216 | |
mbed_official | 205:c41fc65bcfb4 | 217 | /* Check the I2S handle allocation */ |
mbed_official | 205:c41fc65bcfb4 | 218 | if(hi2s == NULL) |
mbed_official | 205:c41fc65bcfb4 | 219 | { |
mbed_official | 205:c41fc65bcfb4 | 220 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 221 | } |
mbed_official | 205:c41fc65bcfb4 | 222 | |
mbed_official | 205:c41fc65bcfb4 | 223 | /* Check the I2S parameters */ |
mbed_official | 205:c41fc65bcfb4 | 224 | assert_param(IS_I2S_MODE(hi2s->Init.Mode)); |
mbed_official | 205:c41fc65bcfb4 | 225 | assert_param(IS_I2S_STANDARD(hi2s->Init.Standard)); |
mbed_official | 205:c41fc65bcfb4 | 226 | assert_param(IS_I2S_DATA_FORMAT(hi2s->Init.DataFormat)); |
mbed_official | 205:c41fc65bcfb4 | 227 | assert_param(IS_I2S_MCLK_OUTPUT(hi2s->Init.MCLKOutput)); |
mbed_official | 205:c41fc65bcfb4 | 228 | assert_param(IS_I2S_AUDIO_FREQ(hi2s->Init.AudioFreq)); |
mbed_official | 205:c41fc65bcfb4 | 229 | assert_param(IS_I2S_CPOL(hi2s->Init.CPOL)); |
mbed_official | 205:c41fc65bcfb4 | 230 | assert_param(IS_I2S_CLOCKSOURCE(hi2s->Init.ClockSource)); |
mbed_official | 205:c41fc65bcfb4 | 231 | |
mbed_official | 205:c41fc65bcfb4 | 232 | if(hi2s->State == HAL_I2S_STATE_RESET) |
mbed_official | 205:c41fc65bcfb4 | 233 | { |
mbed_official | 205:c41fc65bcfb4 | 234 | /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */ |
mbed_official | 205:c41fc65bcfb4 | 235 | HAL_I2S_MspInit(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 236 | } |
mbed_official | 205:c41fc65bcfb4 | 237 | |
mbed_official | 205:c41fc65bcfb4 | 238 | hi2s->State = HAL_I2S_STATE_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 239 | |
mbed_official | 205:c41fc65bcfb4 | 240 | /*----------------------- SPIx I2SCFGR & I2SPR Configuration ---------------*/ |
mbed_official | 205:c41fc65bcfb4 | 241 | /* Clear I2SMOD, I2SE, I2SCFG, PCMSYNC, I2SSTD, CKPOL, DATLEN and CHLEN bits */ |
mbed_official | 205:c41fc65bcfb4 | 242 | hi2s->Instance->I2SCFGR &= (uint16_t)(~(SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CKPOL | \ |
mbed_official | 205:c41fc65bcfb4 | 243 | SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC | SPI_I2SCFGR_I2SCFG | \ |
mbed_official | 205:c41fc65bcfb4 | 244 | SPI_I2SCFGR_I2SE | SPI_I2SCFGR_I2SMOD)); |
mbed_official | 205:c41fc65bcfb4 | 245 | hi2s->Instance->I2SPR = 0x0002; |
mbed_official | 205:c41fc65bcfb4 | 246 | |
mbed_official | 205:c41fc65bcfb4 | 247 | /* Get the I2SCFGR register value */ |
mbed_official | 205:c41fc65bcfb4 | 248 | tmpreg = hi2s->Instance->I2SCFGR; |
mbed_official | 205:c41fc65bcfb4 | 249 | |
mbed_official | 205:c41fc65bcfb4 | 250 | /* If the default value has to be written, reinitialize i2sdiv and i2sodd*/ |
mbed_official | 205:c41fc65bcfb4 | 251 | if(hi2s->Init.AudioFreq == I2S_AUDIOFREQ_DEFAULT) |
mbed_official | 205:c41fc65bcfb4 | 252 | { |
mbed_official | 205:c41fc65bcfb4 | 253 | i2sodd = (uint16_t)0; |
mbed_official | 205:c41fc65bcfb4 | 254 | i2sdiv = (uint16_t)2; |
mbed_official | 205:c41fc65bcfb4 | 255 | } |
mbed_official | 205:c41fc65bcfb4 | 256 | /* If the requested audio frequency is not the default, compute the prescaler */ |
mbed_official | 205:c41fc65bcfb4 | 257 | else |
mbed_official | 205:c41fc65bcfb4 | 258 | { |
mbed_official | 205:c41fc65bcfb4 | 259 | /* Check the frame length (For the Prescaler computing) *******************/ |
mbed_official | 205:c41fc65bcfb4 | 260 | if(hi2s->Init.DataFormat == I2S_DATAFORMAT_16B) |
mbed_official | 205:c41fc65bcfb4 | 261 | { |
mbed_official | 205:c41fc65bcfb4 | 262 | /* Packet length is 16 bits */ |
mbed_official | 205:c41fc65bcfb4 | 263 | packetlength = 1; |
mbed_official | 205:c41fc65bcfb4 | 264 | } |
mbed_official | 205:c41fc65bcfb4 | 265 | else |
mbed_official | 205:c41fc65bcfb4 | 266 | { |
mbed_official | 205:c41fc65bcfb4 | 267 | /* Packet length is 32 bits */ |
mbed_official | 205:c41fc65bcfb4 | 268 | packetlength = 2; |
mbed_official | 205:c41fc65bcfb4 | 269 | } |
mbed_official | 205:c41fc65bcfb4 | 270 | |
mbed_official | 205:c41fc65bcfb4 | 271 | /* Get I2S source Clock frequency ****************************************/ |
mbed_official | 205:c41fc65bcfb4 | 272 | i2sclk = HAL_RCC_GetSysClockFreq(); |
mbed_official | 205:c41fc65bcfb4 | 273 | |
mbed_official | 205:c41fc65bcfb4 | 274 | /* Compute the Real divider depending on the MCLK output state, with a floating point */ |
mbed_official | 205:c41fc65bcfb4 | 275 | if(hi2s->Init.MCLKOutput == I2S_MCLKOUTPUT_ENABLE) |
mbed_official | 205:c41fc65bcfb4 | 276 | { |
mbed_official | 205:c41fc65bcfb4 | 277 | /* MCLK output is enabled */ |
mbed_official | 205:c41fc65bcfb4 | 278 | tmp = (uint32_t)(((((i2sclk / 256) * 10) / hi2s->Init.AudioFreq)) + 5); |
mbed_official | 205:c41fc65bcfb4 | 279 | } |
mbed_official | 205:c41fc65bcfb4 | 280 | else |
mbed_official | 205:c41fc65bcfb4 | 281 | { |
mbed_official | 205:c41fc65bcfb4 | 282 | /* MCLK output is disabled */ |
mbed_official | 205:c41fc65bcfb4 | 283 | tmp = (uint32_t)(((((i2sclk / (32 * packetlength)) *10 ) / hi2s->Init.AudioFreq)) + 5); |
mbed_official | 205:c41fc65bcfb4 | 284 | } |
mbed_official | 205:c41fc65bcfb4 | 285 | |
mbed_official | 205:c41fc65bcfb4 | 286 | /* Remove the flatting point */ |
mbed_official | 205:c41fc65bcfb4 | 287 | tmp = tmp / 10; |
mbed_official | 205:c41fc65bcfb4 | 288 | |
mbed_official | 205:c41fc65bcfb4 | 289 | /* Check the parity of the divider */ |
mbed_official | 205:c41fc65bcfb4 | 290 | i2sodd = (uint32_t)(tmp & (uint32_t)1); |
mbed_official | 205:c41fc65bcfb4 | 291 | |
mbed_official | 205:c41fc65bcfb4 | 292 | /* Compute the i2sdiv prescaler */ |
mbed_official | 205:c41fc65bcfb4 | 293 | i2sdiv = (uint32_t)((tmp - i2sodd) / 2); |
mbed_official | 205:c41fc65bcfb4 | 294 | |
mbed_official | 205:c41fc65bcfb4 | 295 | /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */ |
mbed_official | 205:c41fc65bcfb4 | 296 | i2sodd = (uint32_t) (i2sodd << 8); |
mbed_official | 205:c41fc65bcfb4 | 297 | } |
mbed_official | 205:c41fc65bcfb4 | 298 | |
mbed_official | 205:c41fc65bcfb4 | 299 | /* Test if the divider is 1 or 0 or greater than 0xFF */ |
mbed_official | 205:c41fc65bcfb4 | 300 | if((i2sdiv < 2) || (i2sdiv > 0xFF)) |
mbed_official | 205:c41fc65bcfb4 | 301 | { |
mbed_official | 205:c41fc65bcfb4 | 302 | /* Set the default values */ |
mbed_official | 205:c41fc65bcfb4 | 303 | i2sdiv = 2; |
mbed_official | 205:c41fc65bcfb4 | 304 | i2sodd = 0; |
mbed_official | 205:c41fc65bcfb4 | 305 | } |
mbed_official | 205:c41fc65bcfb4 | 306 | |
mbed_official | 205:c41fc65bcfb4 | 307 | /* Write to SPIx I2SPR register the computed value */ |
mbed_official | 205:c41fc65bcfb4 | 308 | hi2s->Instance->I2SPR = (uint32_t)((uint32_t)i2sdiv | (uint32_t)(i2sodd | (uint32_t)hi2s->Init.MCLKOutput)); |
mbed_official | 205:c41fc65bcfb4 | 309 | |
mbed_official | 205:c41fc65bcfb4 | 310 | /* Configure the I2S with the I2S_InitStruct values */ |
mbed_official | 205:c41fc65bcfb4 | 311 | tmpreg |= (uint32_t)(SPI_I2SCFGR_I2SMOD | hi2s->Init.Mode | hi2s->Init.Standard | hi2s->Init.DataFormat | hi2s->Init.CPOL); |
mbed_official | 205:c41fc65bcfb4 | 312 | |
mbed_official | 205:c41fc65bcfb4 | 313 | /* Write to SPIx I2SCFGR */ |
mbed_official | 205:c41fc65bcfb4 | 314 | hi2s->Instance->I2SCFGR = tmpreg; |
mbed_official | 205:c41fc65bcfb4 | 315 | |
mbed_official | 205:c41fc65bcfb4 | 316 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 205:c41fc65bcfb4 | 317 | hi2s->State= HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 318 | |
mbed_official | 205:c41fc65bcfb4 | 319 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 320 | } |
mbed_official | 205:c41fc65bcfb4 | 321 | |
mbed_official | 205:c41fc65bcfb4 | 322 | /** |
mbed_official | 205:c41fc65bcfb4 | 323 | * @brief DeInitializes the I2S peripheral |
mbed_official | 205:c41fc65bcfb4 | 324 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 325 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 326 | */ |
mbed_official | 205:c41fc65bcfb4 | 327 | HAL_StatusTypeDef HAL_I2S_DeInit(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 328 | { |
mbed_official | 205:c41fc65bcfb4 | 329 | /* Check the I2S handle allocation */ |
mbed_official | 205:c41fc65bcfb4 | 330 | if(hi2s == NULL) |
mbed_official | 205:c41fc65bcfb4 | 331 | { |
mbed_official | 205:c41fc65bcfb4 | 332 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 333 | } |
mbed_official | 205:c41fc65bcfb4 | 334 | |
mbed_official | 205:c41fc65bcfb4 | 335 | /* Check the parameters */ |
mbed_official | 205:c41fc65bcfb4 | 336 | assert_param(IS_I2S_ALL_INSTANCE(hi2s->Instance)); |
mbed_official | 205:c41fc65bcfb4 | 337 | |
mbed_official | 205:c41fc65bcfb4 | 338 | hi2s->State = HAL_I2S_STATE_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 339 | |
mbed_official | 205:c41fc65bcfb4 | 340 | /* Disable the I2S Peripheral Clock */ |
mbed_official | 205:c41fc65bcfb4 | 341 | __HAL_I2S_DISABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 342 | |
mbed_official | 205:c41fc65bcfb4 | 343 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */ |
mbed_official | 205:c41fc65bcfb4 | 344 | HAL_I2S_MspDeInit(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 345 | |
mbed_official | 205:c41fc65bcfb4 | 346 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 205:c41fc65bcfb4 | 347 | hi2s->State = HAL_I2S_STATE_RESET; |
mbed_official | 205:c41fc65bcfb4 | 348 | |
mbed_official | 205:c41fc65bcfb4 | 349 | /* Release Lock */ |
mbed_official | 205:c41fc65bcfb4 | 350 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 351 | |
mbed_official | 205:c41fc65bcfb4 | 352 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 353 | } |
mbed_official | 205:c41fc65bcfb4 | 354 | |
mbed_official | 205:c41fc65bcfb4 | 355 | /** |
mbed_official | 205:c41fc65bcfb4 | 356 | * @brief I2S MSP Init |
mbed_official | 205:c41fc65bcfb4 | 357 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 358 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 359 | */ |
mbed_official | 205:c41fc65bcfb4 | 360 | __weak void HAL_I2S_MspInit(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 361 | { |
mbed_official | 205:c41fc65bcfb4 | 362 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 205:c41fc65bcfb4 | 363 | the HAL_I2S_MspInit could be implemented in the user file |
mbed_official | 205:c41fc65bcfb4 | 364 | */ |
mbed_official | 205:c41fc65bcfb4 | 365 | } |
mbed_official | 205:c41fc65bcfb4 | 366 | |
mbed_official | 205:c41fc65bcfb4 | 367 | /** |
mbed_official | 205:c41fc65bcfb4 | 368 | * @brief I2S MSP DeInit |
mbed_official | 205:c41fc65bcfb4 | 369 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 370 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 371 | */ |
mbed_official | 205:c41fc65bcfb4 | 372 | __weak void HAL_I2S_MspDeInit(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 373 | { |
mbed_official | 205:c41fc65bcfb4 | 374 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 205:c41fc65bcfb4 | 375 | the HAL_I2S_MspDeInit could be implemented in the user file |
mbed_official | 205:c41fc65bcfb4 | 376 | */ |
mbed_official | 205:c41fc65bcfb4 | 377 | } |
mbed_official | 205:c41fc65bcfb4 | 378 | |
mbed_official | 205:c41fc65bcfb4 | 379 | /** |
mbed_official | 205:c41fc65bcfb4 | 380 | * @} |
mbed_official | 205:c41fc65bcfb4 | 381 | */ |
mbed_official | 205:c41fc65bcfb4 | 382 | |
mbed_official | 205:c41fc65bcfb4 | 383 | /** @defgroup I2S_Group2 IO operation functions |
mbed_official | 205:c41fc65bcfb4 | 384 | * @brief Data transfers functions |
mbed_official | 205:c41fc65bcfb4 | 385 | * |
mbed_official | 205:c41fc65bcfb4 | 386 | @verbatim |
mbed_official | 205:c41fc65bcfb4 | 387 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 388 | ##### IO operation functions ##### |
mbed_official | 205:c41fc65bcfb4 | 389 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 390 | [..] |
mbed_official | 205:c41fc65bcfb4 | 391 | This subsection provides a set of functions allowing to manage the I2S data |
mbed_official | 205:c41fc65bcfb4 | 392 | transfers. |
mbed_official | 205:c41fc65bcfb4 | 393 | |
mbed_official | 205:c41fc65bcfb4 | 394 | (#) There is two mode of transfer: |
mbed_official | 205:c41fc65bcfb4 | 395 | (++) Blocking mode : The communication is performed in the polling mode. |
mbed_official | 205:c41fc65bcfb4 | 396 | The status of all data processing is returned by the same function |
mbed_official | 205:c41fc65bcfb4 | 397 | after finishing transfer. |
mbed_official | 205:c41fc65bcfb4 | 398 | (++) No-Blocking mode : The communication is performed using Interrupts |
mbed_official | 205:c41fc65bcfb4 | 399 | or DMA. These functions return the status of the transfer startup. |
mbed_official | 205:c41fc65bcfb4 | 400 | The end of the data processing will be indicated through the |
mbed_official | 205:c41fc65bcfb4 | 401 | dedicated I2S IRQ when using Interrupt mode or the DMA IRQ when |
mbed_official | 205:c41fc65bcfb4 | 402 | using DMA mode. |
mbed_official | 205:c41fc65bcfb4 | 403 | |
mbed_official | 205:c41fc65bcfb4 | 404 | (#) Blocking mode functions are : |
mbed_official | 205:c41fc65bcfb4 | 405 | (++) HAL_I2S_Transmit() |
mbed_official | 205:c41fc65bcfb4 | 406 | (++) HAL_I2S_Receive() |
mbed_official | 205:c41fc65bcfb4 | 407 | |
mbed_official | 205:c41fc65bcfb4 | 408 | (#) No-Blocking mode functions with Interrupt are : |
mbed_official | 205:c41fc65bcfb4 | 409 | (++) HAL_I2S_Transmit_IT() |
mbed_official | 205:c41fc65bcfb4 | 410 | (++) HAL_I2S_Receive_IT() |
mbed_official | 205:c41fc65bcfb4 | 411 | |
mbed_official | 205:c41fc65bcfb4 | 412 | (#) No-Blocking mode functions with DMA are : |
mbed_official | 205:c41fc65bcfb4 | 413 | (++) HAL_I2S_Transmit_DMA() |
mbed_official | 205:c41fc65bcfb4 | 414 | (++) HAL_I2S_Receive_DMA() |
mbed_official | 205:c41fc65bcfb4 | 415 | |
mbed_official | 205:c41fc65bcfb4 | 416 | (#) A set of Transfer Complete Callbacks are provided in No_Blocking mode: |
mbed_official | 205:c41fc65bcfb4 | 417 | (++) HAL_I2S_TxCpltCallback() |
mbed_official | 205:c41fc65bcfb4 | 418 | (++) HAL_I2S_RxCpltCallback() |
mbed_official | 205:c41fc65bcfb4 | 419 | (++) HAL_I2S_ErrorCallback() |
mbed_official | 205:c41fc65bcfb4 | 420 | |
mbed_official | 205:c41fc65bcfb4 | 421 | @endverbatim |
mbed_official | 205:c41fc65bcfb4 | 422 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 423 | */ |
mbed_official | 205:c41fc65bcfb4 | 424 | |
mbed_official | 205:c41fc65bcfb4 | 425 | /** |
mbed_official | 205:c41fc65bcfb4 | 426 | * @brief Transmit an amount of data in blocking mode |
mbed_official | 205:c41fc65bcfb4 | 427 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 428 | * @param pData: a 16-bit pointer to data buffer. |
mbed_official | 205:c41fc65bcfb4 | 429 | * @param Size: number of data sample to be sent: |
mbed_official | 205:c41fc65bcfb4 | 430 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 205:c41fc65bcfb4 | 431 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 205:c41fc65bcfb4 | 432 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 205:c41fc65bcfb4 | 433 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 205:c41fc65bcfb4 | 434 | * @param Timeout: Timeout duration |
mbed_official | 205:c41fc65bcfb4 | 435 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 205:c41fc65bcfb4 | 436 | * between Master and Slave(example: audio streaming). |
mbed_official | 205:c41fc65bcfb4 | 437 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 438 | */ |
mbed_official | 205:c41fc65bcfb4 | 439 | HAL_StatusTypeDef HAL_I2S_Transmit(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 205:c41fc65bcfb4 | 440 | { |
mbed_official | 205:c41fc65bcfb4 | 441 | if((pData == NULL ) || (Size == 0)) |
mbed_official | 205:c41fc65bcfb4 | 442 | { |
mbed_official | 205:c41fc65bcfb4 | 443 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 444 | } |
mbed_official | 205:c41fc65bcfb4 | 445 | |
mbed_official | 205:c41fc65bcfb4 | 446 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 205:c41fc65bcfb4 | 447 | { |
mbed_official | 205:c41fc65bcfb4 | 448 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 205:c41fc65bcfb4 | 449 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 205:c41fc65bcfb4 | 450 | { |
mbed_official | 205:c41fc65bcfb4 | 451 | hi2s->TxXferSize = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 452 | hi2s->TxXferCount = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 453 | } |
mbed_official | 205:c41fc65bcfb4 | 454 | else |
mbed_official | 205:c41fc65bcfb4 | 455 | { |
mbed_official | 205:c41fc65bcfb4 | 456 | hi2s->TxXferSize = Size; |
mbed_official | 205:c41fc65bcfb4 | 457 | hi2s->TxXferCount = Size; |
mbed_official | 205:c41fc65bcfb4 | 458 | } |
mbed_official | 205:c41fc65bcfb4 | 459 | |
mbed_official | 205:c41fc65bcfb4 | 460 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 461 | __HAL_LOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 462 | |
mbed_official | 205:c41fc65bcfb4 | 463 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 205:c41fc65bcfb4 | 464 | hi2s->State = HAL_I2S_STATE_BUSY_TX; |
mbed_official | 205:c41fc65bcfb4 | 465 | |
mbed_official | 205:c41fc65bcfb4 | 466 | /* Check if the I2S is already enabled */ |
mbed_official | 205:c41fc65bcfb4 | 467 | if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 205:c41fc65bcfb4 | 468 | { |
mbed_official | 205:c41fc65bcfb4 | 469 | /* Enable I2S peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 470 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 471 | } |
mbed_official | 205:c41fc65bcfb4 | 472 | |
mbed_official | 205:c41fc65bcfb4 | 473 | |
mbed_official | 205:c41fc65bcfb4 | 474 | /* Wait until TXE flag is set */ |
mbed_official | 205:c41fc65bcfb4 | 475 | if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_TXE, RESET, Timeout) != HAL_OK) |
mbed_official | 205:c41fc65bcfb4 | 476 | { |
mbed_official | 205:c41fc65bcfb4 | 477 | /* Set the error code and execute error callback*/ |
mbed_official | 205:c41fc65bcfb4 | 478 | hi2s->ErrorCode |= HAL_I2S_ERROR_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 479 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 480 | return HAL_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 481 | } |
mbed_official | 205:c41fc65bcfb4 | 482 | |
mbed_official | 205:c41fc65bcfb4 | 483 | while(hi2s->TxXferCount > 0) |
mbed_official | 205:c41fc65bcfb4 | 484 | { |
mbed_official | 205:c41fc65bcfb4 | 485 | hi2s->Instance->DR = (*pData++); |
mbed_official | 205:c41fc65bcfb4 | 486 | hi2s->TxXferCount--; |
mbed_official | 205:c41fc65bcfb4 | 487 | |
mbed_official | 205:c41fc65bcfb4 | 488 | /* Wait until TXE flag is set */ |
mbed_official | 205:c41fc65bcfb4 | 489 | if(I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_TXE, RESET, Timeout) != HAL_OK) |
mbed_official | 205:c41fc65bcfb4 | 490 | { |
mbed_official | 205:c41fc65bcfb4 | 491 | /* Set the error code and execute error callback*/ |
mbed_official | 205:c41fc65bcfb4 | 492 | hi2s->ErrorCode |= HAL_I2S_ERROR_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 493 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 494 | return HAL_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 495 | } |
mbed_official | 205:c41fc65bcfb4 | 496 | } |
mbed_official | 205:c41fc65bcfb4 | 497 | |
mbed_official | 205:c41fc65bcfb4 | 498 | /* Wait until Busy flag is reset */ |
mbed_official | 205:c41fc65bcfb4 | 499 | if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_BSY, SET, Timeout) != HAL_OK) |
mbed_official | 205:c41fc65bcfb4 | 500 | { |
mbed_official | 205:c41fc65bcfb4 | 501 | /* Set the error code and execute error callback*/ |
mbed_official | 205:c41fc65bcfb4 | 502 | hi2s->ErrorCode |= HAL_I2S_ERROR_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 503 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 504 | return HAL_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 505 | } |
mbed_official | 205:c41fc65bcfb4 | 506 | |
mbed_official | 205:c41fc65bcfb4 | 507 | /* Disable I2S peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 508 | __HAL_I2S_DISABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 509 | |
mbed_official | 205:c41fc65bcfb4 | 510 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 511 | |
mbed_official | 205:c41fc65bcfb4 | 512 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 513 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 514 | |
mbed_official | 205:c41fc65bcfb4 | 515 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 516 | } |
mbed_official | 205:c41fc65bcfb4 | 517 | else |
mbed_official | 205:c41fc65bcfb4 | 518 | { |
mbed_official | 205:c41fc65bcfb4 | 519 | return HAL_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 520 | } |
mbed_official | 205:c41fc65bcfb4 | 521 | } |
mbed_official | 205:c41fc65bcfb4 | 522 | |
mbed_official | 205:c41fc65bcfb4 | 523 | /** |
mbed_official | 205:c41fc65bcfb4 | 524 | * @brief Receive an amount of data in blocking mode |
mbed_official | 205:c41fc65bcfb4 | 525 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 526 | * @param pData: a 16-bit pointer to data buffer. |
mbed_official | 205:c41fc65bcfb4 | 527 | * @param Size: number of data sample to be sent: |
mbed_official | 205:c41fc65bcfb4 | 528 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 205:c41fc65bcfb4 | 529 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 205:c41fc65bcfb4 | 530 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 205:c41fc65bcfb4 | 531 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 205:c41fc65bcfb4 | 532 | * @param Timeout: Timeout duration |
mbed_official | 205:c41fc65bcfb4 | 533 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 205:c41fc65bcfb4 | 534 | * between Master and Slave(example: audio streaming). |
mbed_official | 205:c41fc65bcfb4 | 535 | * @note In I2S Master Receiver mode, just after enabling the peripheral the clock will be generate |
mbed_official | 205:c41fc65bcfb4 | 536 | * in continouse way and as the I2S is not disabled at the end of the I2S transaction. |
mbed_official | 205:c41fc65bcfb4 | 537 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 538 | */ |
mbed_official | 205:c41fc65bcfb4 | 539 | HAL_StatusTypeDef HAL_I2S_Receive(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout) |
mbed_official | 205:c41fc65bcfb4 | 540 | { |
mbed_official | 205:c41fc65bcfb4 | 541 | if((pData == NULL ) || (Size == 0)) |
mbed_official | 205:c41fc65bcfb4 | 542 | { |
mbed_official | 205:c41fc65bcfb4 | 543 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 544 | } |
mbed_official | 205:c41fc65bcfb4 | 545 | |
mbed_official | 205:c41fc65bcfb4 | 546 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 205:c41fc65bcfb4 | 547 | { |
mbed_official | 205:c41fc65bcfb4 | 548 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 205:c41fc65bcfb4 | 549 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 205:c41fc65bcfb4 | 550 | { |
mbed_official | 205:c41fc65bcfb4 | 551 | hi2s->RxXferSize = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 552 | hi2s->RxXferCount = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 553 | } |
mbed_official | 205:c41fc65bcfb4 | 554 | else |
mbed_official | 205:c41fc65bcfb4 | 555 | { |
mbed_official | 205:c41fc65bcfb4 | 556 | hi2s->RxXferSize = Size; |
mbed_official | 205:c41fc65bcfb4 | 557 | hi2s->RxXferCount = Size; |
mbed_official | 205:c41fc65bcfb4 | 558 | } |
mbed_official | 205:c41fc65bcfb4 | 559 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 560 | __HAL_LOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 561 | |
mbed_official | 205:c41fc65bcfb4 | 562 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 205:c41fc65bcfb4 | 563 | hi2s->State = HAL_I2S_STATE_BUSY_RX; |
mbed_official | 205:c41fc65bcfb4 | 564 | |
mbed_official | 205:c41fc65bcfb4 | 565 | /* Check if the I2S is already enabled */ |
mbed_official | 205:c41fc65bcfb4 | 566 | if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 205:c41fc65bcfb4 | 567 | { |
mbed_official | 205:c41fc65bcfb4 | 568 | /* Enable I2S peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 569 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 570 | } |
mbed_official | 205:c41fc65bcfb4 | 571 | |
mbed_official | 205:c41fc65bcfb4 | 572 | /* Check if Master Receiver mode is selected */ |
mbed_official | 205:c41fc65bcfb4 | 573 | if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX) |
mbed_official | 205:c41fc65bcfb4 | 574 | { |
mbed_official | 205:c41fc65bcfb4 | 575 | /* Clear the Overrun Flag by a read operation on the SPI_DR register followed by a read |
mbed_official | 205:c41fc65bcfb4 | 576 | access to the SPI_SR register. */ |
mbed_official | 205:c41fc65bcfb4 | 577 | __HAL_I2S_CLEAR_OVRFLAG(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 578 | } |
mbed_official | 205:c41fc65bcfb4 | 579 | |
mbed_official | 205:c41fc65bcfb4 | 580 | /* Receive data */ |
mbed_official | 205:c41fc65bcfb4 | 581 | while(hi2s->RxXferCount > 0) |
mbed_official | 205:c41fc65bcfb4 | 582 | { |
mbed_official | 205:c41fc65bcfb4 | 583 | /* Wait until RXNE flag is set */ |
mbed_official | 205:c41fc65bcfb4 | 584 | if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_RXNE, RESET, Timeout) != HAL_OK) |
mbed_official | 205:c41fc65bcfb4 | 585 | { |
mbed_official | 205:c41fc65bcfb4 | 586 | /* Set the error code and execute error callback*/ |
mbed_official | 205:c41fc65bcfb4 | 587 | hi2s->ErrorCode |= HAL_I2S_ERROR_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 588 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 589 | return HAL_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 590 | } |
mbed_official | 205:c41fc65bcfb4 | 591 | |
mbed_official | 205:c41fc65bcfb4 | 592 | (*pData++) = hi2s->Instance->DR; |
mbed_official | 205:c41fc65bcfb4 | 593 | hi2s->RxXferCount--; |
mbed_official | 205:c41fc65bcfb4 | 594 | |
mbed_official | 205:c41fc65bcfb4 | 595 | /* Check if an overrun occurs */ |
mbed_official | 205:c41fc65bcfb4 | 596 | if(__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_OVR) == SET) |
mbed_official | 205:c41fc65bcfb4 | 597 | { |
mbed_official | 205:c41fc65bcfb4 | 598 | /* Set the I2S State ready */ |
mbed_official | 205:c41fc65bcfb4 | 599 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 600 | |
mbed_official | 205:c41fc65bcfb4 | 601 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 602 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 603 | |
mbed_official | 205:c41fc65bcfb4 | 604 | /* Set the error code and execute error callback*/ |
mbed_official | 205:c41fc65bcfb4 | 605 | hi2s->ErrorCode |= HAL_I2S_ERROR_OVR; |
mbed_official | 205:c41fc65bcfb4 | 606 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 607 | |
mbed_official | 205:c41fc65bcfb4 | 608 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 609 | } |
mbed_official | 205:c41fc65bcfb4 | 610 | } |
mbed_official | 205:c41fc65bcfb4 | 611 | |
mbed_official | 205:c41fc65bcfb4 | 612 | /* Disable the I2S Peripheral Clock */ |
mbed_official | 205:c41fc65bcfb4 | 613 | __HAL_I2S_DISABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 614 | |
mbed_official | 205:c41fc65bcfb4 | 615 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 616 | |
mbed_official | 205:c41fc65bcfb4 | 617 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 618 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 619 | |
mbed_official | 205:c41fc65bcfb4 | 620 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 621 | } |
mbed_official | 205:c41fc65bcfb4 | 622 | else |
mbed_official | 205:c41fc65bcfb4 | 623 | { |
mbed_official | 205:c41fc65bcfb4 | 624 | return HAL_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 625 | } |
mbed_official | 205:c41fc65bcfb4 | 626 | } |
mbed_official | 205:c41fc65bcfb4 | 627 | |
mbed_official | 205:c41fc65bcfb4 | 628 | /** |
mbed_official | 205:c41fc65bcfb4 | 629 | * @brief Transmit an amount of data in non-blocking mode with Interrupt |
mbed_official | 205:c41fc65bcfb4 | 630 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 631 | * @param pData: a 16-bit pointer to data buffer. |
mbed_official | 205:c41fc65bcfb4 | 632 | * @param Size: number of data sample to be sent: |
mbed_official | 205:c41fc65bcfb4 | 633 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 205:c41fc65bcfb4 | 634 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 205:c41fc65bcfb4 | 635 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 205:c41fc65bcfb4 | 636 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 205:c41fc65bcfb4 | 637 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 205:c41fc65bcfb4 | 638 | * between Master and Slave(example: audio streaming). |
mbed_official | 205:c41fc65bcfb4 | 639 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 640 | */ |
mbed_official | 205:c41fc65bcfb4 | 641 | HAL_StatusTypeDef HAL_I2S_Transmit_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size) |
mbed_official | 205:c41fc65bcfb4 | 642 | { |
mbed_official | 205:c41fc65bcfb4 | 643 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 205:c41fc65bcfb4 | 644 | { |
mbed_official | 205:c41fc65bcfb4 | 645 | if((pData == NULL) || (Size == 0)) |
mbed_official | 205:c41fc65bcfb4 | 646 | { |
mbed_official | 205:c41fc65bcfb4 | 647 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 648 | } |
mbed_official | 205:c41fc65bcfb4 | 649 | |
mbed_official | 205:c41fc65bcfb4 | 650 | hi2s->pTxBuffPtr = pData; |
mbed_official | 205:c41fc65bcfb4 | 651 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 205:c41fc65bcfb4 | 652 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 205:c41fc65bcfb4 | 653 | { |
mbed_official | 205:c41fc65bcfb4 | 654 | hi2s->TxXferSize = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 655 | hi2s->TxXferCount = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 656 | } |
mbed_official | 205:c41fc65bcfb4 | 657 | else |
mbed_official | 205:c41fc65bcfb4 | 658 | { |
mbed_official | 205:c41fc65bcfb4 | 659 | hi2s->TxXferSize = Size; |
mbed_official | 205:c41fc65bcfb4 | 660 | hi2s->TxXferCount = Size; |
mbed_official | 205:c41fc65bcfb4 | 661 | } |
mbed_official | 205:c41fc65bcfb4 | 662 | |
mbed_official | 205:c41fc65bcfb4 | 663 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 664 | __HAL_LOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 665 | |
mbed_official | 205:c41fc65bcfb4 | 666 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 205:c41fc65bcfb4 | 667 | hi2s->State = HAL_I2S_STATE_BUSY_TX; |
mbed_official | 205:c41fc65bcfb4 | 668 | |
mbed_official | 205:c41fc65bcfb4 | 669 | /* Enable TXE and ERR interrupt */ |
mbed_official | 205:c41fc65bcfb4 | 670 | __HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_ERR)); |
mbed_official | 205:c41fc65bcfb4 | 671 | |
mbed_official | 205:c41fc65bcfb4 | 672 | /* Check if the I2S is already enabled */ |
mbed_official | 205:c41fc65bcfb4 | 673 | if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 205:c41fc65bcfb4 | 674 | { |
mbed_official | 205:c41fc65bcfb4 | 675 | /* Enable I2S peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 676 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 677 | } |
mbed_official | 205:c41fc65bcfb4 | 678 | |
mbed_official | 205:c41fc65bcfb4 | 679 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 680 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 681 | |
mbed_official | 205:c41fc65bcfb4 | 682 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 683 | } |
mbed_official | 205:c41fc65bcfb4 | 684 | else |
mbed_official | 205:c41fc65bcfb4 | 685 | { |
mbed_official | 205:c41fc65bcfb4 | 686 | return HAL_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 687 | } |
mbed_official | 205:c41fc65bcfb4 | 688 | } |
mbed_official | 205:c41fc65bcfb4 | 689 | |
mbed_official | 205:c41fc65bcfb4 | 690 | /** |
mbed_official | 205:c41fc65bcfb4 | 691 | * @brief Receive an amount of data in non-blocking mode with Interrupt |
mbed_official | 205:c41fc65bcfb4 | 692 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 693 | * @param pData: a 16-bit pointer to the Receive data buffer. |
mbed_official | 205:c41fc65bcfb4 | 694 | * @param Size: number of data sample to be sent: |
mbed_official | 205:c41fc65bcfb4 | 695 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 205:c41fc65bcfb4 | 696 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 205:c41fc65bcfb4 | 697 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 205:c41fc65bcfb4 | 698 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 205:c41fc65bcfb4 | 699 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 205:c41fc65bcfb4 | 700 | * between Master and Slave(example: audio streaming). |
mbed_official | 205:c41fc65bcfb4 | 701 | * @note It is recommended to use DMA for the I2S receiver to avoid de-synchronisation |
mbed_official | 205:c41fc65bcfb4 | 702 | * between Master and Slave otherwise the I2S interrupt should be optimized. |
mbed_official | 205:c41fc65bcfb4 | 703 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 704 | */ |
mbed_official | 205:c41fc65bcfb4 | 705 | HAL_StatusTypeDef HAL_I2S_Receive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size) |
mbed_official | 205:c41fc65bcfb4 | 706 | { |
mbed_official | 205:c41fc65bcfb4 | 707 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 205:c41fc65bcfb4 | 708 | { |
mbed_official | 205:c41fc65bcfb4 | 709 | if((pData == NULL) || (Size == 0)) |
mbed_official | 205:c41fc65bcfb4 | 710 | { |
mbed_official | 205:c41fc65bcfb4 | 711 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 712 | } |
mbed_official | 205:c41fc65bcfb4 | 713 | |
mbed_official | 205:c41fc65bcfb4 | 714 | hi2s->pRxBuffPtr = pData; |
mbed_official | 205:c41fc65bcfb4 | 715 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 205:c41fc65bcfb4 | 716 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 205:c41fc65bcfb4 | 717 | { |
mbed_official | 205:c41fc65bcfb4 | 718 | hi2s->RxXferSize = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 719 | hi2s->RxXferCount = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 720 | } |
mbed_official | 205:c41fc65bcfb4 | 721 | else |
mbed_official | 205:c41fc65bcfb4 | 722 | { |
mbed_official | 205:c41fc65bcfb4 | 723 | hi2s->RxXferSize = Size; |
mbed_official | 205:c41fc65bcfb4 | 724 | hi2s->RxXferCount = Size; |
mbed_official | 205:c41fc65bcfb4 | 725 | } |
mbed_official | 205:c41fc65bcfb4 | 726 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 727 | __HAL_LOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 728 | |
mbed_official | 205:c41fc65bcfb4 | 729 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 205:c41fc65bcfb4 | 730 | hi2s->State = HAL_I2S_STATE_BUSY_RX; |
mbed_official | 205:c41fc65bcfb4 | 731 | |
mbed_official | 205:c41fc65bcfb4 | 732 | /* Enable TXE and ERR interrupt */ |
mbed_official | 205:c41fc65bcfb4 | 733 | __HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_ERR)); |
mbed_official | 205:c41fc65bcfb4 | 734 | |
mbed_official | 205:c41fc65bcfb4 | 735 | /* Check if the I2S is already enabled */ |
mbed_official | 205:c41fc65bcfb4 | 736 | if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 205:c41fc65bcfb4 | 737 | { |
mbed_official | 205:c41fc65bcfb4 | 738 | /* Enable I2S peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 739 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 740 | } |
mbed_official | 205:c41fc65bcfb4 | 741 | |
mbed_official | 205:c41fc65bcfb4 | 742 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 743 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 744 | |
mbed_official | 205:c41fc65bcfb4 | 745 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 746 | } |
mbed_official | 205:c41fc65bcfb4 | 747 | else |
mbed_official | 205:c41fc65bcfb4 | 748 | { |
mbed_official | 205:c41fc65bcfb4 | 749 | return HAL_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 750 | } |
mbed_official | 205:c41fc65bcfb4 | 751 | } |
mbed_official | 205:c41fc65bcfb4 | 752 | |
mbed_official | 205:c41fc65bcfb4 | 753 | /** |
mbed_official | 205:c41fc65bcfb4 | 754 | * @brief Transmit an amount of data in non-blocking mode with DMA |
mbed_official | 205:c41fc65bcfb4 | 755 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 756 | * @param pData: a 16-bit pointer to the Transmit data buffer. |
mbed_official | 205:c41fc65bcfb4 | 757 | * @param Size: number of data sample to be sent: |
mbed_official | 205:c41fc65bcfb4 | 758 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 205:c41fc65bcfb4 | 759 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 205:c41fc65bcfb4 | 760 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 205:c41fc65bcfb4 | 761 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 205:c41fc65bcfb4 | 762 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 205:c41fc65bcfb4 | 763 | * between Master and Slave(example: audio streaming). |
mbed_official | 205:c41fc65bcfb4 | 764 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 765 | */ |
mbed_official | 205:c41fc65bcfb4 | 766 | HAL_StatusTypeDef HAL_I2S_Transmit_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size) |
mbed_official | 205:c41fc65bcfb4 | 767 | { |
mbed_official | 205:c41fc65bcfb4 | 768 | uint32_t *tmp; |
mbed_official | 205:c41fc65bcfb4 | 769 | |
mbed_official | 205:c41fc65bcfb4 | 770 | if((pData == NULL) || (Size == 0)) |
mbed_official | 205:c41fc65bcfb4 | 771 | { |
mbed_official | 205:c41fc65bcfb4 | 772 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 773 | } |
mbed_official | 205:c41fc65bcfb4 | 774 | |
mbed_official | 205:c41fc65bcfb4 | 775 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 205:c41fc65bcfb4 | 776 | { |
mbed_official | 205:c41fc65bcfb4 | 777 | hi2s->pTxBuffPtr = pData; |
mbed_official | 205:c41fc65bcfb4 | 778 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 205:c41fc65bcfb4 | 779 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 205:c41fc65bcfb4 | 780 | { |
mbed_official | 205:c41fc65bcfb4 | 781 | hi2s->TxXferSize = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 782 | hi2s->TxXferCount = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 783 | } |
mbed_official | 205:c41fc65bcfb4 | 784 | else |
mbed_official | 205:c41fc65bcfb4 | 785 | { |
mbed_official | 205:c41fc65bcfb4 | 786 | hi2s->TxXferSize = Size; |
mbed_official | 205:c41fc65bcfb4 | 787 | hi2s->TxXferCount = Size; |
mbed_official | 205:c41fc65bcfb4 | 788 | } |
mbed_official | 205:c41fc65bcfb4 | 789 | |
mbed_official | 205:c41fc65bcfb4 | 790 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 791 | __HAL_LOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 792 | |
mbed_official | 205:c41fc65bcfb4 | 793 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 205:c41fc65bcfb4 | 794 | hi2s->State = HAL_I2S_STATE_BUSY_TX; |
mbed_official | 205:c41fc65bcfb4 | 795 | |
mbed_official | 205:c41fc65bcfb4 | 796 | /* Set the I2S Tx DMA Half transfert complete callback */ |
mbed_official | 205:c41fc65bcfb4 | 797 | hi2s->hdmatx->XferHalfCpltCallback = I2S_DMATxHalfCplt; |
mbed_official | 205:c41fc65bcfb4 | 798 | |
mbed_official | 205:c41fc65bcfb4 | 799 | /* Set the I2S TxDMA transfert complete callback */ |
mbed_official | 205:c41fc65bcfb4 | 800 | hi2s->hdmatx->XferCpltCallback = I2S_DMATxCplt; |
mbed_official | 205:c41fc65bcfb4 | 801 | |
mbed_official | 205:c41fc65bcfb4 | 802 | /* Set the DMA error callback */ |
mbed_official | 205:c41fc65bcfb4 | 803 | hi2s->hdmatx->XferErrorCallback = I2S_DMAError; |
mbed_official | 205:c41fc65bcfb4 | 804 | |
mbed_official | 205:c41fc65bcfb4 | 805 | /* Enable the Tx DMA Channel */ |
mbed_official | 205:c41fc65bcfb4 | 806 | tmp = (uint32_t*)&pData; |
mbed_official | 205:c41fc65bcfb4 | 807 | HAL_DMA_Start_IT(hi2s->hdmatx, *(uint32_t*)tmp, (uint32_t)&hi2s->Instance->DR, hi2s->TxXferSize); |
mbed_official | 205:c41fc65bcfb4 | 808 | |
mbed_official | 205:c41fc65bcfb4 | 809 | /* Check if the I2S is already enabled */ |
mbed_official | 205:c41fc65bcfb4 | 810 | if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 205:c41fc65bcfb4 | 811 | { |
mbed_official | 205:c41fc65bcfb4 | 812 | /* Enable I2S peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 813 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 814 | } |
mbed_official | 205:c41fc65bcfb4 | 815 | |
mbed_official | 205:c41fc65bcfb4 | 816 | /* Enable Tx DMA Request */ |
mbed_official | 205:c41fc65bcfb4 | 817 | hi2s->Instance->CR2 |= SPI_CR2_TXDMAEN; |
mbed_official | 205:c41fc65bcfb4 | 818 | |
mbed_official | 205:c41fc65bcfb4 | 819 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 820 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 821 | |
mbed_official | 205:c41fc65bcfb4 | 822 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 823 | } |
mbed_official | 205:c41fc65bcfb4 | 824 | else |
mbed_official | 205:c41fc65bcfb4 | 825 | { |
mbed_official | 205:c41fc65bcfb4 | 826 | return HAL_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 827 | } |
mbed_official | 205:c41fc65bcfb4 | 828 | } |
mbed_official | 205:c41fc65bcfb4 | 829 | |
mbed_official | 205:c41fc65bcfb4 | 830 | /** |
mbed_official | 205:c41fc65bcfb4 | 831 | * @brief Receive an amount of data in non-blocking mode with DMA |
mbed_official | 205:c41fc65bcfb4 | 832 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 833 | * @param pData: a 16-bit pointer to the Receive data buffer. |
mbed_official | 205:c41fc65bcfb4 | 834 | * @param Size: number of data sample to be sent: |
mbed_official | 205:c41fc65bcfb4 | 835 | * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S |
mbed_official | 205:c41fc65bcfb4 | 836 | * configuration phase, the Size parameter means the number of 16-bit data length |
mbed_official | 205:c41fc65bcfb4 | 837 | * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected |
mbed_official | 205:c41fc65bcfb4 | 838 | * the Size parameter means the number of 16-bit data length. |
mbed_official | 205:c41fc65bcfb4 | 839 | * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization |
mbed_official | 205:c41fc65bcfb4 | 840 | * between Master and Slave(example: audio streaming). |
mbed_official | 205:c41fc65bcfb4 | 841 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 842 | */ |
mbed_official | 205:c41fc65bcfb4 | 843 | HAL_StatusTypeDef HAL_I2S_Receive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size) |
mbed_official | 205:c41fc65bcfb4 | 844 | { |
mbed_official | 205:c41fc65bcfb4 | 845 | uint32_t *tmp; |
mbed_official | 205:c41fc65bcfb4 | 846 | |
mbed_official | 205:c41fc65bcfb4 | 847 | if((pData == NULL) || (Size == 0)) |
mbed_official | 205:c41fc65bcfb4 | 848 | { |
mbed_official | 205:c41fc65bcfb4 | 849 | return HAL_ERROR; |
mbed_official | 205:c41fc65bcfb4 | 850 | } |
mbed_official | 205:c41fc65bcfb4 | 851 | |
mbed_official | 205:c41fc65bcfb4 | 852 | if(hi2s->State == HAL_I2S_STATE_READY) |
mbed_official | 205:c41fc65bcfb4 | 853 | { |
mbed_official | 205:c41fc65bcfb4 | 854 | hi2s->pRxBuffPtr = pData; |
mbed_official | 205:c41fc65bcfb4 | 855 | if(((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_24B)||\ |
mbed_official | 205:c41fc65bcfb4 | 856 | ((hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)) == I2S_DATAFORMAT_32B)) |
mbed_official | 205:c41fc65bcfb4 | 857 | { |
mbed_official | 205:c41fc65bcfb4 | 858 | hi2s->RxXferSize = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 859 | hi2s->RxXferCount = (Size << 1); |
mbed_official | 205:c41fc65bcfb4 | 860 | } |
mbed_official | 205:c41fc65bcfb4 | 861 | else |
mbed_official | 205:c41fc65bcfb4 | 862 | { |
mbed_official | 205:c41fc65bcfb4 | 863 | hi2s->RxXferSize = Size; |
mbed_official | 205:c41fc65bcfb4 | 864 | hi2s->RxXferCount = Size; |
mbed_official | 205:c41fc65bcfb4 | 865 | } |
mbed_official | 205:c41fc65bcfb4 | 866 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 867 | __HAL_LOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 868 | |
mbed_official | 205:c41fc65bcfb4 | 869 | hi2s->ErrorCode = HAL_I2S_ERROR_NONE; |
mbed_official | 205:c41fc65bcfb4 | 870 | hi2s->State = HAL_I2S_STATE_BUSY_RX; |
mbed_official | 205:c41fc65bcfb4 | 871 | |
mbed_official | 205:c41fc65bcfb4 | 872 | /* Set the I2S Rx DMA Half transfert complete callback */ |
mbed_official | 205:c41fc65bcfb4 | 873 | hi2s->hdmarx->XferHalfCpltCallback = I2S_DMARxHalfCplt; |
mbed_official | 205:c41fc65bcfb4 | 874 | |
mbed_official | 205:c41fc65bcfb4 | 875 | /* Set the I2S Rx DMA transfert complete callback */ |
mbed_official | 205:c41fc65bcfb4 | 876 | hi2s->hdmarx->XferCpltCallback = I2S_DMARxCplt; |
mbed_official | 205:c41fc65bcfb4 | 877 | |
mbed_official | 205:c41fc65bcfb4 | 878 | /* Set the DMA error callback */ |
mbed_official | 205:c41fc65bcfb4 | 879 | hi2s->hdmarx->XferErrorCallback = I2S_DMAError; |
mbed_official | 205:c41fc65bcfb4 | 880 | |
mbed_official | 205:c41fc65bcfb4 | 881 | /* Check if Master Receiver mode is selected */ |
mbed_official | 205:c41fc65bcfb4 | 882 | if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX) |
mbed_official | 205:c41fc65bcfb4 | 883 | { |
mbed_official | 205:c41fc65bcfb4 | 884 | /* Clear the Overrun Flag by a read operation to the SPI_DR register followed by a read |
mbed_official | 205:c41fc65bcfb4 | 885 | access to the SPI_SR register. */ |
mbed_official | 205:c41fc65bcfb4 | 886 | __HAL_I2S_CLEAR_OVRFLAG(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 887 | } |
mbed_official | 205:c41fc65bcfb4 | 888 | |
mbed_official | 205:c41fc65bcfb4 | 889 | /* Enable the Rx DMA Channel */ |
mbed_official | 205:c41fc65bcfb4 | 890 | tmp = (uint32_t*)&pData; |
mbed_official | 205:c41fc65bcfb4 | 891 | HAL_DMA_Start_IT(hi2s->hdmarx, (uint32_t)&hi2s->Instance->DR, *(uint32_t*)tmp, hi2s->RxXferSize); |
mbed_official | 205:c41fc65bcfb4 | 892 | |
mbed_official | 205:c41fc65bcfb4 | 893 | /* Check if the I2S is already enabled */ |
mbed_official | 205:c41fc65bcfb4 | 894 | if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE) |
mbed_official | 205:c41fc65bcfb4 | 895 | { |
mbed_official | 205:c41fc65bcfb4 | 896 | /* Enable I2S peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 897 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 898 | } |
mbed_official | 205:c41fc65bcfb4 | 899 | |
mbed_official | 205:c41fc65bcfb4 | 900 | /* Enable Rx DMA Request */ |
mbed_official | 205:c41fc65bcfb4 | 901 | hi2s->Instance->CR2 |= SPI_CR2_RXDMAEN; |
mbed_official | 205:c41fc65bcfb4 | 902 | |
mbed_official | 205:c41fc65bcfb4 | 903 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 904 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 905 | |
mbed_official | 205:c41fc65bcfb4 | 906 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 907 | } |
mbed_official | 205:c41fc65bcfb4 | 908 | else |
mbed_official | 205:c41fc65bcfb4 | 909 | { |
mbed_official | 205:c41fc65bcfb4 | 910 | return HAL_BUSY; |
mbed_official | 205:c41fc65bcfb4 | 911 | } |
mbed_official | 205:c41fc65bcfb4 | 912 | } |
mbed_official | 205:c41fc65bcfb4 | 913 | |
mbed_official | 205:c41fc65bcfb4 | 914 | /** |
mbed_official | 205:c41fc65bcfb4 | 915 | * @brief Pauses the audio stream playing from the Media. |
mbed_official | 205:c41fc65bcfb4 | 916 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 917 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 918 | */ |
mbed_official | 205:c41fc65bcfb4 | 919 | HAL_StatusTypeDef HAL_I2S_DMAPause(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 920 | { |
mbed_official | 205:c41fc65bcfb4 | 921 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 922 | __HAL_LOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 923 | |
mbed_official | 205:c41fc65bcfb4 | 924 | if(hi2s->State == HAL_I2S_STATE_BUSY_TX) |
mbed_official | 205:c41fc65bcfb4 | 925 | { |
mbed_official | 205:c41fc65bcfb4 | 926 | /* Disable the I2S DMA Tx request */ |
mbed_official | 205:c41fc65bcfb4 | 927 | hi2s->Instance->CR2 &= (uint16_t)(~SPI_CR2_TXDMAEN); |
mbed_official | 205:c41fc65bcfb4 | 928 | } |
mbed_official | 205:c41fc65bcfb4 | 929 | else if(hi2s->State == HAL_I2S_STATE_BUSY_RX) |
mbed_official | 205:c41fc65bcfb4 | 930 | { |
mbed_official | 205:c41fc65bcfb4 | 931 | /* Disable the I2S DMA Rx request */ |
mbed_official | 205:c41fc65bcfb4 | 932 | hi2s->Instance->CR2 &= (uint16_t)(~SPI_CR2_RXDMAEN); |
mbed_official | 205:c41fc65bcfb4 | 933 | } |
mbed_official | 205:c41fc65bcfb4 | 934 | |
mbed_official | 205:c41fc65bcfb4 | 935 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 936 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 937 | |
mbed_official | 205:c41fc65bcfb4 | 938 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 939 | } |
mbed_official | 205:c41fc65bcfb4 | 940 | |
mbed_official | 205:c41fc65bcfb4 | 941 | /** |
mbed_official | 205:c41fc65bcfb4 | 942 | * @brief Resumes the audio stream playing from the Media. |
mbed_official | 205:c41fc65bcfb4 | 943 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 944 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 945 | */ |
mbed_official | 205:c41fc65bcfb4 | 946 | HAL_StatusTypeDef HAL_I2S_DMAResume(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 947 | { |
mbed_official | 205:c41fc65bcfb4 | 948 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 949 | __HAL_LOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 950 | |
mbed_official | 205:c41fc65bcfb4 | 951 | if(hi2s->State == HAL_I2S_STATE_BUSY_TX) |
mbed_official | 205:c41fc65bcfb4 | 952 | { |
mbed_official | 205:c41fc65bcfb4 | 953 | /* Enable the I2S DMA Tx request */ |
mbed_official | 205:c41fc65bcfb4 | 954 | hi2s->Instance->CR2 |= SPI_CR2_TXDMAEN; |
mbed_official | 205:c41fc65bcfb4 | 955 | } |
mbed_official | 205:c41fc65bcfb4 | 956 | else if(hi2s->State == HAL_I2S_STATE_BUSY_RX) |
mbed_official | 205:c41fc65bcfb4 | 957 | { |
mbed_official | 205:c41fc65bcfb4 | 958 | /* Enable the I2S DMA Rx request */ |
mbed_official | 205:c41fc65bcfb4 | 959 | hi2s->Instance->CR2 |= SPI_CR2_RXDMAEN; |
mbed_official | 205:c41fc65bcfb4 | 960 | } |
mbed_official | 205:c41fc65bcfb4 | 961 | |
mbed_official | 205:c41fc65bcfb4 | 962 | /* If the I2S peripheral is still not enabled, enable it */ |
mbed_official | 205:c41fc65bcfb4 | 963 | if ((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SE) == 0) |
mbed_official | 205:c41fc65bcfb4 | 964 | { |
mbed_official | 205:c41fc65bcfb4 | 965 | /* Enable I2S peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 966 | __HAL_I2S_ENABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 967 | } |
mbed_official | 205:c41fc65bcfb4 | 968 | |
mbed_official | 205:c41fc65bcfb4 | 969 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 970 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 971 | |
mbed_official | 205:c41fc65bcfb4 | 972 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 973 | } |
mbed_official | 205:c41fc65bcfb4 | 974 | |
mbed_official | 205:c41fc65bcfb4 | 975 | /** |
mbed_official | 205:c41fc65bcfb4 | 976 | * @brief Resumes the audio stream playing from the Media. |
mbed_official | 205:c41fc65bcfb4 | 977 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 978 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 979 | */ |
mbed_official | 205:c41fc65bcfb4 | 980 | HAL_StatusTypeDef HAL_I2S_DMAStop(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 981 | { |
mbed_official | 205:c41fc65bcfb4 | 982 | /* Process Locked */ |
mbed_official | 205:c41fc65bcfb4 | 983 | __HAL_LOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 984 | |
mbed_official | 205:c41fc65bcfb4 | 985 | /* Disable the I2S Tx/Rx DMA requests */ |
mbed_official | 205:c41fc65bcfb4 | 986 | hi2s->Instance->CR2 &= (uint16_t)(~SPI_CR2_TXDMAEN); |
mbed_official | 205:c41fc65bcfb4 | 987 | hi2s->Instance->CR2 &= (uint16_t)(~SPI_CR2_RXDMAEN); |
mbed_official | 205:c41fc65bcfb4 | 988 | |
mbed_official | 205:c41fc65bcfb4 | 989 | /* Disable the I2S DMA channel */ |
mbed_official | 205:c41fc65bcfb4 | 990 | __HAL_DMA_DISABLE(hi2s->hdmatx); |
mbed_official | 205:c41fc65bcfb4 | 991 | __HAL_DMA_DISABLE(hi2s->hdmarx); |
mbed_official | 205:c41fc65bcfb4 | 992 | |
mbed_official | 205:c41fc65bcfb4 | 993 | /* Disable I2S peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 994 | __HAL_I2S_DISABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 995 | |
mbed_official | 205:c41fc65bcfb4 | 996 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 997 | |
mbed_official | 205:c41fc65bcfb4 | 998 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 999 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1000 | |
mbed_official | 205:c41fc65bcfb4 | 1001 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 1002 | } |
mbed_official | 205:c41fc65bcfb4 | 1003 | |
mbed_official | 205:c41fc65bcfb4 | 1004 | /** |
mbed_official | 205:c41fc65bcfb4 | 1005 | * @brief This function handles I2S interrupt request. |
mbed_official | 205:c41fc65bcfb4 | 1006 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1007 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 1008 | */ |
mbed_official | 205:c41fc65bcfb4 | 1009 | void HAL_I2S_IRQHandler(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 1010 | { |
mbed_official | 205:c41fc65bcfb4 | 1011 | /* I2S in mode Receiver ------------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 1012 | if((__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_RXNE) != RESET) && (__HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_RXNE) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 1013 | { |
mbed_official | 205:c41fc65bcfb4 | 1014 | I2S_Receive_IT(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1015 | return; |
mbed_official | 205:c41fc65bcfb4 | 1016 | } |
mbed_official | 205:c41fc65bcfb4 | 1017 | |
mbed_official | 205:c41fc65bcfb4 | 1018 | /* I2S in mode Tramitter -----------------------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 1019 | if((__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_TXE) != RESET) && (__HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_TXE) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 1020 | { |
mbed_official | 205:c41fc65bcfb4 | 1021 | I2S_Transmit_IT(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1022 | return; |
mbed_official | 205:c41fc65bcfb4 | 1023 | } |
mbed_official | 205:c41fc65bcfb4 | 1024 | |
mbed_official | 205:c41fc65bcfb4 | 1025 | /* I2S Overrun error interrupt occured ---------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 1026 | if((__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_OVR) != RESET) && (__HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 1027 | { |
mbed_official | 205:c41fc65bcfb4 | 1028 | /* Disable RXNE and ERR interrupt */ |
mbed_official | 205:c41fc65bcfb4 | 1029 | __HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_ERR)); |
mbed_official | 205:c41fc65bcfb4 | 1030 | |
mbed_official | 205:c41fc65bcfb4 | 1031 | /* Set the I2S State ready */ |
mbed_official | 205:c41fc65bcfb4 | 1032 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 1033 | |
mbed_official | 205:c41fc65bcfb4 | 1034 | /* Set the error code and execute error callback*/ |
mbed_official | 205:c41fc65bcfb4 | 1035 | hi2s->ErrorCode |= HAL_I2S_ERROR_OVR; |
mbed_official | 205:c41fc65bcfb4 | 1036 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1037 | } |
mbed_official | 205:c41fc65bcfb4 | 1038 | |
mbed_official | 205:c41fc65bcfb4 | 1039 | /* I2S Underrun error interrupt occured --------------------------------*/ |
mbed_official | 205:c41fc65bcfb4 | 1040 | if((__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_UDR) != RESET) && (__HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 1041 | { |
mbed_official | 205:c41fc65bcfb4 | 1042 | /* Disable TXE and ERR interrupt */ |
mbed_official | 205:c41fc65bcfb4 | 1043 | __HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_ERR)); |
mbed_official | 205:c41fc65bcfb4 | 1044 | |
mbed_official | 205:c41fc65bcfb4 | 1045 | /* Set the I2S State ready */ |
mbed_official | 205:c41fc65bcfb4 | 1046 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 1047 | |
mbed_official | 205:c41fc65bcfb4 | 1048 | /* Set the error code and execute error callback*/ |
mbed_official | 205:c41fc65bcfb4 | 1049 | hi2s->ErrorCode |= HAL_I2S_ERROR_UDR; |
mbed_official | 205:c41fc65bcfb4 | 1050 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1051 | } |
mbed_official | 205:c41fc65bcfb4 | 1052 | } |
mbed_official | 205:c41fc65bcfb4 | 1053 | |
mbed_official | 205:c41fc65bcfb4 | 1054 | /** |
mbed_official | 205:c41fc65bcfb4 | 1055 | * @brief Tx Transfer Half completed callbacks |
mbed_official | 205:c41fc65bcfb4 | 1056 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1057 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1058 | */ |
mbed_official | 205:c41fc65bcfb4 | 1059 | __weak void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 1060 | { |
mbed_official | 205:c41fc65bcfb4 | 1061 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 205:c41fc65bcfb4 | 1062 | the HAL_I2S_TxHalfCpltCallback could be implemented in the user file |
mbed_official | 205:c41fc65bcfb4 | 1063 | */ |
mbed_official | 205:c41fc65bcfb4 | 1064 | } |
mbed_official | 205:c41fc65bcfb4 | 1065 | |
mbed_official | 205:c41fc65bcfb4 | 1066 | /** |
mbed_official | 205:c41fc65bcfb4 | 1067 | * @brief Tx Transfer completed callbacks |
mbed_official | 205:c41fc65bcfb4 | 1068 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1069 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1070 | */ |
mbed_official | 205:c41fc65bcfb4 | 1071 | __weak void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 1072 | { |
mbed_official | 205:c41fc65bcfb4 | 1073 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 205:c41fc65bcfb4 | 1074 | the HAL_I2S_TxCpltCallback could be implemented in the user file |
mbed_official | 205:c41fc65bcfb4 | 1075 | */ |
mbed_official | 205:c41fc65bcfb4 | 1076 | } |
mbed_official | 205:c41fc65bcfb4 | 1077 | |
mbed_official | 205:c41fc65bcfb4 | 1078 | /** |
mbed_official | 205:c41fc65bcfb4 | 1079 | * @brief Rx Transfer half completed callbacks |
mbed_official | 205:c41fc65bcfb4 | 1080 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1081 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1082 | */ |
mbed_official | 205:c41fc65bcfb4 | 1083 | __weak void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 1084 | { |
mbed_official | 205:c41fc65bcfb4 | 1085 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 205:c41fc65bcfb4 | 1086 | the HAL_I2S_RxCpltCallback could be implemented in the user file |
mbed_official | 205:c41fc65bcfb4 | 1087 | */ |
mbed_official | 205:c41fc65bcfb4 | 1088 | } |
mbed_official | 205:c41fc65bcfb4 | 1089 | |
mbed_official | 205:c41fc65bcfb4 | 1090 | /** |
mbed_official | 205:c41fc65bcfb4 | 1091 | * @brief Rx Transfer completed callbacks |
mbed_official | 205:c41fc65bcfb4 | 1092 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1093 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1094 | */ |
mbed_official | 205:c41fc65bcfb4 | 1095 | __weak void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 1096 | { |
mbed_official | 205:c41fc65bcfb4 | 1097 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 205:c41fc65bcfb4 | 1098 | the HAL_I2S_RxCpltCallback could be implemented in the user file |
mbed_official | 205:c41fc65bcfb4 | 1099 | */ |
mbed_official | 205:c41fc65bcfb4 | 1100 | } |
mbed_official | 205:c41fc65bcfb4 | 1101 | |
mbed_official | 205:c41fc65bcfb4 | 1102 | /** |
mbed_official | 205:c41fc65bcfb4 | 1103 | * @brief I2S error callbacks |
mbed_official | 205:c41fc65bcfb4 | 1104 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1105 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1106 | */ |
mbed_official | 205:c41fc65bcfb4 | 1107 | __weak void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 1108 | { |
mbed_official | 205:c41fc65bcfb4 | 1109 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 205:c41fc65bcfb4 | 1110 | the HAL_I2S_ErrorCallback could be implemented in the user file |
mbed_official | 205:c41fc65bcfb4 | 1111 | */ |
mbed_official | 205:c41fc65bcfb4 | 1112 | } |
mbed_official | 205:c41fc65bcfb4 | 1113 | |
mbed_official | 205:c41fc65bcfb4 | 1114 | /** |
mbed_official | 205:c41fc65bcfb4 | 1115 | * @} |
mbed_official | 205:c41fc65bcfb4 | 1116 | */ |
mbed_official | 205:c41fc65bcfb4 | 1117 | |
mbed_official | 205:c41fc65bcfb4 | 1118 | /** @defgroup I2S_Group3 Peripheral State and Errors functions |
mbed_official | 205:c41fc65bcfb4 | 1119 | * @brief Peripheral State functions |
mbed_official | 205:c41fc65bcfb4 | 1120 | * |
mbed_official | 205:c41fc65bcfb4 | 1121 | @verbatim |
mbed_official | 205:c41fc65bcfb4 | 1122 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 1123 | ##### Peripheral State and Errors functions ##### |
mbed_official | 205:c41fc65bcfb4 | 1124 | =============================================================================== |
mbed_official | 205:c41fc65bcfb4 | 1125 | [..] |
mbed_official | 205:c41fc65bcfb4 | 1126 | This subsection permit to get in run-time the status of the peripheral |
mbed_official | 205:c41fc65bcfb4 | 1127 | and the data flow. |
mbed_official | 205:c41fc65bcfb4 | 1128 | |
mbed_official | 205:c41fc65bcfb4 | 1129 | @endverbatim |
mbed_official | 205:c41fc65bcfb4 | 1130 | * @{ |
mbed_official | 205:c41fc65bcfb4 | 1131 | */ |
mbed_official | 205:c41fc65bcfb4 | 1132 | |
mbed_official | 205:c41fc65bcfb4 | 1133 | /** |
mbed_official | 205:c41fc65bcfb4 | 1134 | * @brief Return the I2S state |
mbed_official | 205:c41fc65bcfb4 | 1135 | * @param hi2s : I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1136 | * @retval HAL state |
mbed_official | 205:c41fc65bcfb4 | 1137 | */ |
mbed_official | 205:c41fc65bcfb4 | 1138 | HAL_I2S_StateTypeDef HAL_I2S_GetState(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 1139 | { |
mbed_official | 205:c41fc65bcfb4 | 1140 | return hi2s->State; |
mbed_official | 205:c41fc65bcfb4 | 1141 | } |
mbed_official | 205:c41fc65bcfb4 | 1142 | |
mbed_official | 205:c41fc65bcfb4 | 1143 | /** |
mbed_official | 205:c41fc65bcfb4 | 1144 | * @brief Return the I2S error code |
mbed_official | 205:c41fc65bcfb4 | 1145 | * @param hi2s : I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1146 | * @retval I2S Error Code |
mbed_official | 205:c41fc65bcfb4 | 1147 | */ |
mbed_official | 205:c41fc65bcfb4 | 1148 | HAL_I2S_ErrorTypeDef HAL_I2S_GetError(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 1149 | { |
mbed_official | 205:c41fc65bcfb4 | 1150 | return hi2s->ErrorCode; |
mbed_official | 205:c41fc65bcfb4 | 1151 | } |
mbed_official | 205:c41fc65bcfb4 | 1152 | |
mbed_official | 205:c41fc65bcfb4 | 1153 | /** |
mbed_official | 205:c41fc65bcfb4 | 1154 | * @} |
mbed_official | 205:c41fc65bcfb4 | 1155 | */ |
mbed_official | 205:c41fc65bcfb4 | 1156 | |
mbed_official | 205:c41fc65bcfb4 | 1157 | /** |
mbed_official | 205:c41fc65bcfb4 | 1158 | * @brief DMA I2S transmit process complete callback |
mbed_official | 205:c41fc65bcfb4 | 1159 | * @param hdma : DMA handle |
mbed_official | 205:c41fc65bcfb4 | 1160 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1161 | */ |
mbed_official | 205:c41fc65bcfb4 | 1162 | static void I2S_DMATxCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 205:c41fc65bcfb4 | 1163 | { |
mbed_official | 205:c41fc65bcfb4 | 1164 | I2S_HandleTypeDef* hi2s = ( I2S_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 205:c41fc65bcfb4 | 1165 | |
mbed_official | 205:c41fc65bcfb4 | 1166 | /* Disable Tx DMA Request */ |
mbed_official | 205:c41fc65bcfb4 | 1167 | hi2s->Instance->CR2 &= (uint16_t)(~SPI_CR2_TXDMAEN); |
mbed_official | 205:c41fc65bcfb4 | 1168 | |
mbed_official | 205:c41fc65bcfb4 | 1169 | hi2s->TxXferCount = 0; |
mbed_official | 205:c41fc65bcfb4 | 1170 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 1171 | |
mbed_official | 205:c41fc65bcfb4 | 1172 | HAL_I2S_TxCpltCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1173 | } |
mbed_official | 205:c41fc65bcfb4 | 1174 | |
mbed_official | 205:c41fc65bcfb4 | 1175 | /** |
mbed_official | 205:c41fc65bcfb4 | 1176 | * @brief DMA I2S transmit process half complete callback |
mbed_official | 205:c41fc65bcfb4 | 1177 | * @param hdma : DMA handle |
mbed_official | 205:c41fc65bcfb4 | 1178 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1179 | */ |
mbed_official | 205:c41fc65bcfb4 | 1180 | static void I2S_DMATxHalfCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 205:c41fc65bcfb4 | 1181 | { |
mbed_official | 205:c41fc65bcfb4 | 1182 | I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 205:c41fc65bcfb4 | 1183 | |
mbed_official | 205:c41fc65bcfb4 | 1184 | HAL_I2S_TxHalfCpltCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1185 | } |
mbed_official | 205:c41fc65bcfb4 | 1186 | |
mbed_official | 205:c41fc65bcfb4 | 1187 | /** |
mbed_official | 205:c41fc65bcfb4 | 1188 | * @brief DMA I2S receive process complete callback |
mbed_official | 205:c41fc65bcfb4 | 1189 | * @param hdma : DMA handle |
mbed_official | 205:c41fc65bcfb4 | 1190 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1191 | */ |
mbed_official | 205:c41fc65bcfb4 | 1192 | static void I2S_DMARxCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 205:c41fc65bcfb4 | 1193 | { |
mbed_official | 205:c41fc65bcfb4 | 1194 | I2S_HandleTypeDef* hi2s = ( I2S_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 205:c41fc65bcfb4 | 1195 | |
mbed_official | 205:c41fc65bcfb4 | 1196 | /* Disable Rx DMA Request */ |
mbed_official | 205:c41fc65bcfb4 | 1197 | hi2s->Instance->CR2 &= (uint16_t)(~SPI_CR2_RXDMAEN); |
mbed_official | 205:c41fc65bcfb4 | 1198 | hi2s->RxXferCount = 0; |
mbed_official | 205:c41fc65bcfb4 | 1199 | |
mbed_official | 205:c41fc65bcfb4 | 1200 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 1201 | HAL_I2S_RxCpltCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1202 | } |
mbed_official | 205:c41fc65bcfb4 | 1203 | |
mbed_official | 205:c41fc65bcfb4 | 1204 | /** |
mbed_official | 205:c41fc65bcfb4 | 1205 | * @brief DMA I2S receive process half complete callback |
mbed_official | 205:c41fc65bcfb4 | 1206 | * @param hdma : DMA handle |
mbed_official | 205:c41fc65bcfb4 | 1207 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1208 | */ |
mbed_official | 205:c41fc65bcfb4 | 1209 | static void I2S_DMARxHalfCplt(DMA_HandleTypeDef *hdma) |
mbed_official | 205:c41fc65bcfb4 | 1210 | { |
mbed_official | 205:c41fc65bcfb4 | 1211 | I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; |
mbed_official | 205:c41fc65bcfb4 | 1212 | |
mbed_official | 205:c41fc65bcfb4 | 1213 | HAL_I2S_RxHalfCpltCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1214 | } |
mbed_official | 205:c41fc65bcfb4 | 1215 | |
mbed_official | 205:c41fc65bcfb4 | 1216 | /** |
mbed_official | 205:c41fc65bcfb4 | 1217 | * @brief DMA I2S communication error callback |
mbed_official | 205:c41fc65bcfb4 | 1218 | * @param hdma : DMA handle |
mbed_official | 205:c41fc65bcfb4 | 1219 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1220 | */ |
mbed_official | 205:c41fc65bcfb4 | 1221 | static void I2S_DMAError(DMA_HandleTypeDef *hdma) |
mbed_official | 205:c41fc65bcfb4 | 1222 | { |
mbed_official | 205:c41fc65bcfb4 | 1223 | I2S_HandleTypeDef* hi2s = ( I2S_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
mbed_official | 205:c41fc65bcfb4 | 1224 | |
mbed_official | 205:c41fc65bcfb4 | 1225 | /* Disable Rx and Tx DMA Request */ |
mbed_official | 205:c41fc65bcfb4 | 1226 | hi2s->Instance->CR2 &= (uint16_t)(~(SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN)); |
mbed_official | 205:c41fc65bcfb4 | 1227 | hi2s->TxXferCount = 0; |
mbed_official | 205:c41fc65bcfb4 | 1228 | hi2s->RxXferCount = 0; |
mbed_official | 205:c41fc65bcfb4 | 1229 | |
mbed_official | 205:c41fc65bcfb4 | 1230 | hi2s->State= HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 1231 | |
mbed_official | 205:c41fc65bcfb4 | 1232 | /* Set the error code and execute error callback*/ |
mbed_official | 205:c41fc65bcfb4 | 1233 | hi2s->ErrorCode |= HAL_I2S_ERROR_DMA; |
mbed_official | 205:c41fc65bcfb4 | 1234 | HAL_I2S_ErrorCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1235 | } |
mbed_official | 205:c41fc65bcfb4 | 1236 | |
mbed_official | 205:c41fc65bcfb4 | 1237 | /** |
mbed_official | 205:c41fc65bcfb4 | 1238 | * @brief Transmit an amount of data in non-blocking mode with Interrupt |
mbed_official | 205:c41fc65bcfb4 | 1239 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1240 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1241 | */ |
mbed_official | 205:c41fc65bcfb4 | 1242 | static void I2S_Transmit_IT(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 1243 | { |
mbed_official | 205:c41fc65bcfb4 | 1244 | /* Transmit data */ |
mbed_official | 205:c41fc65bcfb4 | 1245 | hi2s->Instance->DR = (*hi2s->pTxBuffPtr++); |
mbed_official | 205:c41fc65bcfb4 | 1246 | hi2s->TxXferCount--; |
mbed_official | 205:c41fc65bcfb4 | 1247 | |
mbed_official | 205:c41fc65bcfb4 | 1248 | if(hi2s->TxXferCount == 0) |
mbed_official | 205:c41fc65bcfb4 | 1249 | { |
mbed_official | 205:c41fc65bcfb4 | 1250 | /* Disable TXE and ERR interrupt */ |
mbed_official | 205:c41fc65bcfb4 | 1251 | __HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_ERR)); |
mbed_official | 205:c41fc65bcfb4 | 1252 | |
mbed_official | 205:c41fc65bcfb4 | 1253 | while(__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_TXE) == RESET) {}; |
mbed_official | 205:c41fc65bcfb4 | 1254 | |
mbed_official | 205:c41fc65bcfb4 | 1255 | while(__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_BSY) != RESET) {}; |
mbed_official | 205:c41fc65bcfb4 | 1256 | |
mbed_official | 205:c41fc65bcfb4 | 1257 | /* Disable I2S peripheral */ |
mbed_official | 205:c41fc65bcfb4 | 1258 | __HAL_I2S_DISABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1259 | |
mbed_official | 205:c41fc65bcfb4 | 1260 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 1261 | HAL_I2S_TxCpltCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1262 | } |
mbed_official | 205:c41fc65bcfb4 | 1263 | } |
mbed_official | 205:c41fc65bcfb4 | 1264 | |
mbed_official | 205:c41fc65bcfb4 | 1265 | /** |
mbed_official | 205:c41fc65bcfb4 | 1266 | * @brief Receive an amount of data in non-blocking mode with Interrupt |
mbed_official | 205:c41fc65bcfb4 | 1267 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1268 | * @retval None |
mbed_official | 205:c41fc65bcfb4 | 1269 | */ |
mbed_official | 205:c41fc65bcfb4 | 1270 | static void I2S_Receive_IT(I2S_HandleTypeDef *hi2s) |
mbed_official | 205:c41fc65bcfb4 | 1271 | { |
mbed_official | 205:c41fc65bcfb4 | 1272 | /* Receive data */ |
mbed_official | 205:c41fc65bcfb4 | 1273 | (*hi2s->pRxBuffPtr++) = hi2s->Instance->DR; |
mbed_official | 205:c41fc65bcfb4 | 1274 | hi2s->RxXferCount--; |
mbed_official | 205:c41fc65bcfb4 | 1275 | |
mbed_official | 205:c41fc65bcfb4 | 1276 | /* Check if Master Receiver mode is selected */ |
mbed_official | 205:c41fc65bcfb4 | 1277 | if((hi2s->Init.Mode == I2S_MODE_MASTER_RX) && \ |
mbed_official | 205:c41fc65bcfb4 | 1278 | (__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_OVR) != RESET)) |
mbed_official | 205:c41fc65bcfb4 | 1279 | { |
mbed_official | 205:c41fc65bcfb4 | 1280 | /* Clear the Overrun Flag by a read operation on the SPI_DR register followed by a read |
mbed_official | 205:c41fc65bcfb4 | 1281 | access to the SPI_SR register. */ |
mbed_official | 205:c41fc65bcfb4 | 1282 | __HAL_I2S_CLEAR_OVRFLAG(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1283 | } |
mbed_official | 205:c41fc65bcfb4 | 1284 | |
mbed_official | 205:c41fc65bcfb4 | 1285 | |
mbed_official | 205:c41fc65bcfb4 | 1286 | if(hi2s->RxXferCount == 0) |
mbed_official | 205:c41fc65bcfb4 | 1287 | { |
mbed_official | 205:c41fc65bcfb4 | 1288 | /* Disable the I2S Peripheral Clock */ |
mbed_official | 205:c41fc65bcfb4 | 1289 | __HAL_I2S_DISABLE(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1290 | |
mbed_official | 205:c41fc65bcfb4 | 1291 | /* Disable RXNE and ERR interrupt */ |
mbed_official | 205:c41fc65bcfb4 | 1292 | __HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_ERR)); |
mbed_official | 205:c41fc65bcfb4 | 1293 | hi2s->State = HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 1294 | HAL_I2S_RxCpltCallback(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1295 | } |
mbed_official | 205:c41fc65bcfb4 | 1296 | } |
mbed_official | 205:c41fc65bcfb4 | 1297 | |
mbed_official | 205:c41fc65bcfb4 | 1298 | |
mbed_official | 205:c41fc65bcfb4 | 1299 | /** |
mbed_official | 205:c41fc65bcfb4 | 1300 | * @brief This function handles I2S Communication Timeout. |
mbed_official | 205:c41fc65bcfb4 | 1301 | * @param hi2s: I2S handle |
mbed_official | 205:c41fc65bcfb4 | 1302 | * @param Flag: Flag checked |
mbed_official | 205:c41fc65bcfb4 | 1303 | * @param State: Value of the flag expected |
mbed_official | 205:c41fc65bcfb4 | 1304 | * @param Timeout: Duration of the timeout |
mbed_official | 205:c41fc65bcfb4 | 1305 | * @retval HAL status |
mbed_official | 205:c41fc65bcfb4 | 1306 | */ |
mbed_official | 205:c41fc65bcfb4 | 1307 | static HAL_StatusTypeDef I2S_WaitFlagStateUntilTimeout(I2S_HandleTypeDef *hi2s, uint32_t Flag, uint32_t State, uint32_t Timeout) |
mbed_official | 205:c41fc65bcfb4 | 1308 | { |
mbed_official | 205:c41fc65bcfb4 | 1309 | uint32_t tickstart = HAL_GetTick(); |
mbed_official | 205:c41fc65bcfb4 | 1310 | |
mbed_official | 205:c41fc65bcfb4 | 1311 | /* Wait until flag is set */ |
mbed_official | 205:c41fc65bcfb4 | 1312 | if(State == RESET) |
mbed_official | 205:c41fc65bcfb4 | 1313 | { |
mbed_official | 205:c41fc65bcfb4 | 1314 | while(__HAL_I2S_GET_FLAG(hi2s, Flag) == RESET) |
mbed_official | 205:c41fc65bcfb4 | 1315 | { |
mbed_official | 205:c41fc65bcfb4 | 1316 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 205:c41fc65bcfb4 | 1317 | { |
mbed_official | 205:c41fc65bcfb4 | 1318 | if((HAL_GetTick() - tickstart) > Timeout) |
mbed_official | 205:c41fc65bcfb4 | 1319 | { |
mbed_official | 205:c41fc65bcfb4 | 1320 | /* Set the I2S State ready */ |
mbed_official | 205:c41fc65bcfb4 | 1321 | hi2s->State= HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 1322 | |
mbed_official | 205:c41fc65bcfb4 | 1323 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 1324 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1325 | |
mbed_official | 205:c41fc65bcfb4 | 1326 | return HAL_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 1327 | } |
mbed_official | 205:c41fc65bcfb4 | 1328 | } |
mbed_official | 205:c41fc65bcfb4 | 1329 | } |
mbed_official | 205:c41fc65bcfb4 | 1330 | } |
mbed_official | 205:c41fc65bcfb4 | 1331 | else |
mbed_official | 205:c41fc65bcfb4 | 1332 | { |
mbed_official | 205:c41fc65bcfb4 | 1333 | while(__HAL_I2S_GET_FLAG(hi2s, Flag) != RESET) |
mbed_official | 205:c41fc65bcfb4 | 1334 | { |
mbed_official | 205:c41fc65bcfb4 | 1335 | if(Timeout != HAL_MAX_DELAY) |
mbed_official | 205:c41fc65bcfb4 | 1336 | { |
mbed_official | 205:c41fc65bcfb4 | 1337 | if((HAL_GetTick() - tickstart) > Timeout) |
mbed_official | 205:c41fc65bcfb4 | 1338 | { |
mbed_official | 205:c41fc65bcfb4 | 1339 | /* Set the I2S State ready */ |
mbed_official | 205:c41fc65bcfb4 | 1340 | hi2s->State= HAL_I2S_STATE_READY; |
mbed_official | 205:c41fc65bcfb4 | 1341 | |
mbed_official | 205:c41fc65bcfb4 | 1342 | /* Process Unlocked */ |
mbed_official | 205:c41fc65bcfb4 | 1343 | __HAL_UNLOCK(hi2s); |
mbed_official | 205:c41fc65bcfb4 | 1344 | |
mbed_official | 205:c41fc65bcfb4 | 1345 | return HAL_TIMEOUT; |
mbed_official | 205:c41fc65bcfb4 | 1346 | } |
mbed_official | 205:c41fc65bcfb4 | 1347 | } |
mbed_official | 205:c41fc65bcfb4 | 1348 | } |
mbed_official | 205:c41fc65bcfb4 | 1349 | } |
mbed_official | 205:c41fc65bcfb4 | 1350 | return HAL_OK; |
mbed_official | 205:c41fc65bcfb4 | 1351 | } |
mbed_official | 205:c41fc65bcfb4 | 1352 | |
mbed_official | 205:c41fc65bcfb4 | 1353 | /** |
mbed_official | 205:c41fc65bcfb4 | 1354 | * @} |
mbed_official | 205:c41fc65bcfb4 | 1355 | */ |
mbed_official | 205:c41fc65bcfb4 | 1356 | |
mbed_official | 205:c41fc65bcfb4 | 1357 | #endif /* defined(STM32F031x6) || defined(STM32F038xx) || */ |
mbed_official | 205:c41fc65bcfb4 | 1358 | /* defined(STM32F051x8) || defined(STM32F058xx) || */ |
mbed_official | 205:c41fc65bcfb4 | 1359 | /* defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx) || */ |
mbed_official | 205:c41fc65bcfb4 | 1360 | /* defined(STM32F042x6) || defined(STM32F048xx) */ |
mbed_official | 205:c41fc65bcfb4 | 1361 | |
mbed_official | 205:c41fc65bcfb4 | 1362 | #endif /* HAL_I2S_MODULE_ENABLED */ |
mbed_official | 205:c41fc65bcfb4 | 1363 | /** |
mbed_official | 205:c41fc65bcfb4 | 1364 | * @} |
mbed_official | 205:c41fc65bcfb4 | 1365 | */ |
mbed_official | 205:c41fc65bcfb4 | 1366 | |
mbed_official | 205:c41fc65bcfb4 | 1367 | /** |
mbed_official | 205:c41fc65bcfb4 | 1368 | * @} |
mbed_official | 205:c41fc65bcfb4 | 1369 | */ |
mbed_official | 205:c41fc65bcfb4 | 1370 | |
mbed_official | 205:c41fc65bcfb4 | 1371 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |