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