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