mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jul 02 16:30:08 2015 +0100
Revision:
581:39197bcd20f2
Parent:
532:fe11edbda85c
Child:
613:bc40b8d2aec4
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724

Full URL: https://github.com/mbedmicro/mbed/commit/ae2d3cdffe70184eb8736d94f76c45c93f4b7724/

Make it possible to build the core mbed library with yotta

Who changed what in which revision?

UserRevisionLine numberNew 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 532:fe11edbda85c 5 * @version V1.3.0
mbed_official 532:fe11edbda85c 6 * @date 09-March-2015
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 532:fe11edbda85c 36 (+++) Associate the initialized 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 532:fe11edbda85c 112 * <h2><center>&copy; COPYRIGHT(c) 2015 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 532:fe11edbda85c 146 /** @defgroup I2S 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 532:fe11edbda85c 158 /** @addtogroup I2S_Private_Functions
mbed_official 235:685d5f11838f 159 * @{
mbed_official 235:685d5f11838f 160 */
mbed_official 235:685d5f11838f 161
mbed_official 532:fe11edbda85c 162 /**
mbed_official 532:fe11edbda85c 163 * @}
mbed_official 532:fe11edbda85c 164 */
mbed_official 532:fe11edbda85c 165
mbed_official 532:fe11edbda85c 166 /* Exported functions --------------------------------------------------------*/
mbed_official 532:fe11edbda85c 167 /** @defgroup I2S_Exported_Functions I2S Exported Functions
mbed_official 532:fe11edbda85c 168 * @{
mbed_official 532:fe11edbda85c 169 */
mbed_official 532:fe11edbda85c 170
mbed_official 532:fe11edbda85c 171 /** @defgroup I2S_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 532:fe11edbda85c 172 * @brief Initialization and Configuration functions
mbed_official 532:fe11edbda85c 173 *
mbed_official 532:fe11edbda85c 174 @verbatim
mbed_official 235:685d5f11838f 175 ===============================================================================
mbed_official 235:685d5f11838f 176 ##### Initialization and de-initialization functions #####
mbed_official 235:685d5f11838f 177 ===============================================================================
mbed_official 235:685d5f11838f 178 [..] This subsection provides a set of functions allowing to initialize and
mbed_official 532:fe11edbda85c 179 de-initialize the I2Sx peripheral in simplex mode:
mbed_official 235:685d5f11838f 180
mbed_official 235:685d5f11838f 181 (+) User must Implement HAL_I2S_MspInit() function in which he configures
mbed_official 235:685d5f11838f 182 all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
mbed_official 235:685d5f11838f 183
mbed_official 235:685d5f11838f 184 (+) Call the function HAL_I2S_Init() to configure the selected device with
mbed_official 235:685d5f11838f 185 the selected configuration:
mbed_official 235:685d5f11838f 186 (++) Mode
mbed_official 235:685d5f11838f 187 (++) Standard
mbed_official 235:685d5f11838f 188 (++) Data Format
mbed_official 235:685d5f11838f 189 (++) MCLK Output
mbed_official 235:685d5f11838f 190 (++) Audio frequency
mbed_official 235:685d5f11838f 191 (++) Polarity
mbed_official 235:685d5f11838f 192
mbed_official 235:685d5f11838f 193 (+) Call the function HAL_I2S_DeInit() to restore the default configuration
mbed_official 532:fe11edbda85c 194 of the selected I2Sx peripheral.
mbed_official 235:685d5f11838f 195 @endverbatim
mbed_official 235:685d5f11838f 196 * @{
mbed_official 235:685d5f11838f 197 */
mbed_official 235:685d5f11838f 198
mbed_official 235:685d5f11838f 199 /**
mbed_official 235:685d5f11838f 200 * @brief Initializes the I2S according to the specified parameters
mbed_official 235:685d5f11838f 201 * in the I2S_InitTypeDef and create the associated handle.
mbed_official 235:685d5f11838f 202 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 203 * the configuration information for I2S module
mbed_official 235:685d5f11838f 204 * @retval HAL status
mbed_official 235:685d5f11838f 205 */
mbed_official 532:fe11edbda85c 206 __weak HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 207 {
mbed_official 235:685d5f11838f 208 uint32_t tmpreg = 0, i2sdiv = 2, i2sodd = 0, packetlength = 1;
mbed_official 235:685d5f11838f 209 uint32_t tmp = 0, i2sclk = 0;
mbed_official 235:685d5f11838f 210
mbed_official 235:685d5f11838f 211 /* Check the I2S handle allocation */
mbed_official 352:95e80f5e68f6 212 if(hi2s == HAL_NULL)
mbed_official 235:685d5f11838f 213 {
mbed_official 235:685d5f11838f 214 return HAL_ERROR;
mbed_official 235:685d5f11838f 215 }
mbed_official 235:685d5f11838f 216
mbed_official 235:685d5f11838f 217 /* Check the I2S parameters */
mbed_official 532:fe11edbda85c 218 assert_param(IS_I2S_ALL_INSTANCE(hi2s->Instance));
mbed_official 235:685d5f11838f 219 assert_param(IS_I2S_MODE(hi2s->Init.Mode));
mbed_official 235:685d5f11838f 220 assert_param(IS_I2S_STANDARD(hi2s->Init.Standard));
mbed_official 235:685d5f11838f 221 assert_param(IS_I2S_DATA_FORMAT(hi2s->Init.DataFormat));
mbed_official 235:685d5f11838f 222 assert_param(IS_I2S_MCLK_OUTPUT(hi2s->Init.MCLKOutput));
mbed_official 235:685d5f11838f 223 assert_param(IS_I2S_AUDIO_FREQ(hi2s->Init.AudioFreq));
mbed_official 235:685d5f11838f 224 assert_param(IS_I2S_CPOL(hi2s->Init.CPOL));
mbed_official 235:685d5f11838f 225 assert_param(IS_I2S_CLOCKSOURCE(hi2s->Init.ClockSource));
mbed_official 235:685d5f11838f 226
mbed_official 235:685d5f11838f 227 if(hi2s->State == HAL_I2S_STATE_RESET)
mbed_official 235:685d5f11838f 228 {
mbed_official 532:fe11edbda85c 229 /* Allocate lock resource and initialize it */
mbed_official 532:fe11edbda85c 230 hi2s->Lock = HAL_UNLOCKED;
mbed_official 235:685d5f11838f 231 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
mbed_official 235:685d5f11838f 232 HAL_I2S_MspInit(hi2s);
mbed_official 235:685d5f11838f 233 }
mbed_official 235:685d5f11838f 234
mbed_official 235:685d5f11838f 235 hi2s->State = HAL_I2S_STATE_BUSY;
mbed_official 235:685d5f11838f 236
mbed_official 235:685d5f11838f 237 /*----------------------- SPIx I2SCFGR & I2SPR Configuration ---------------*/
mbed_official 235:685d5f11838f 238 /* Clear I2SMOD, I2SE, I2SCFG, PCMSYNC, I2SSTD, CKPOL, DATLEN and CHLEN bits */
mbed_official 235:685d5f11838f 239 hi2s->Instance->I2SCFGR &= ~(SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CKPOL | \
mbed_official 235:685d5f11838f 240 SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC | SPI_I2SCFGR_I2SCFG | \
mbed_official 235:685d5f11838f 241 SPI_I2SCFGR_I2SE | SPI_I2SCFGR_I2SMOD);
mbed_official 235:685d5f11838f 242 hi2s->Instance->I2SPR = 0x0002;
mbed_official 235:685d5f11838f 243
mbed_official 235:685d5f11838f 244 /* Get the I2SCFGR register value */
mbed_official 235:685d5f11838f 245 tmpreg = hi2s->Instance->I2SCFGR;
mbed_official 235:685d5f11838f 246
mbed_official 235:685d5f11838f 247 /* If the default frequency value has to be written, reinitialize i2sdiv and i2sodd */
mbed_official 235:685d5f11838f 248 /* If the requested audio frequency is not the default, compute the prescaler */
mbed_official 235:685d5f11838f 249 if(hi2s->Init.AudioFreq != I2S_AUDIOFREQ_DEFAULT)
mbed_official 235:685d5f11838f 250 {
mbed_official 235:685d5f11838f 251 /* Check the frame length (For the Prescaler computing) *******************/
mbed_official 235:685d5f11838f 252 if(hi2s->Init.DataFormat != I2S_DATAFORMAT_16B)
mbed_official 235:685d5f11838f 253 {
mbed_official 235:685d5f11838f 254 /* Packet length is 32 bits */
mbed_official 235:685d5f11838f 255 packetlength = 2;
mbed_official 235:685d5f11838f 256 }
mbed_official 235:685d5f11838f 257
mbed_official 235:685d5f11838f 258 /* Get I2S source Clock frequency ****************************************/
mbed_official 235:685d5f11838f 259 /* If an external I2S clock has to be used, the specific define should be set
mbed_official 235:685d5f11838f 260 in the project configuration or in the stm32f4xx_conf.h file */
mbed_official 532:fe11edbda85c 261 i2sclk = I2S_GetInputClock(hi2s);
mbed_official 235:685d5f11838f 262
mbed_official 235:685d5f11838f 263 /* Compute the Real divider depending on the MCLK output state, with a floating point */
mbed_official 235:685d5f11838f 264 if(hi2s->Init.MCLKOutput == I2S_MCLKOUTPUT_ENABLE)
mbed_official 235:685d5f11838f 265 {
mbed_official 235:685d5f11838f 266 /* MCLK output is enabled */
mbed_official 235:685d5f11838f 267 tmp = (uint32_t)(((((i2sclk / 256) * 10) / hi2s->Init.AudioFreq)) + 5);
mbed_official 235:685d5f11838f 268 }
mbed_official 235:685d5f11838f 269 else
mbed_official 235:685d5f11838f 270 {
mbed_official 235:685d5f11838f 271 /* MCLK output is disabled */
mbed_official 235:685d5f11838f 272 tmp = (uint32_t)(((((i2sclk / (32 * packetlength)) *10 ) / hi2s->Init.AudioFreq)) + 5);
mbed_official 235:685d5f11838f 273 }
mbed_official 235:685d5f11838f 274
mbed_official 235:685d5f11838f 275 /* Remove the flatting point */
mbed_official 235:685d5f11838f 276 tmp = tmp / 10;
mbed_official 235:685d5f11838f 277
mbed_official 235:685d5f11838f 278 /* Check the parity of the divider */
mbed_official 235:685d5f11838f 279 i2sodd = (uint32_t)(tmp & (uint32_t)1);
mbed_official 235:685d5f11838f 280
mbed_official 235:685d5f11838f 281 /* Compute the i2sdiv prescaler */
mbed_official 235:685d5f11838f 282 i2sdiv = (uint32_t)((tmp - i2sodd) / 2);
mbed_official 235:685d5f11838f 283
mbed_official 235:685d5f11838f 284 /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */
mbed_official 235:685d5f11838f 285 i2sodd = (uint32_t) (i2sodd << 8);
mbed_official 235:685d5f11838f 286 }
mbed_official 235:685d5f11838f 287
mbed_official 235:685d5f11838f 288 /* Test if the divider is 1 or 0 or greater than 0xFF */
mbed_official 235:685d5f11838f 289 if((i2sdiv < 2) || (i2sdiv > 0xFF))
mbed_official 235:685d5f11838f 290 {
mbed_official 235:685d5f11838f 291 /* Set the default values */
mbed_official 235:685d5f11838f 292 i2sdiv = 2;
mbed_official 235:685d5f11838f 293 i2sodd = 0;
mbed_official 235:685d5f11838f 294 }
mbed_official 235:685d5f11838f 295
mbed_official 235:685d5f11838f 296 /* Write to SPIx I2SPR register the computed value */
mbed_official 235:685d5f11838f 297 hi2s->Instance->I2SPR = (uint32_t)((uint32_t)i2sdiv | (uint32_t)(i2sodd | (uint32_t)hi2s->Init.MCLKOutput));
mbed_official 235:685d5f11838f 298
mbed_official 235:685d5f11838f 299 /* Configure the I2S with the I2S_InitStruct values */
mbed_official 235:685d5f11838f 300 tmpreg |= (uint32_t)(SPI_I2SCFGR_I2SMOD | hi2s->Init.Mode | hi2s->Init.Standard | hi2s->Init.DataFormat | hi2s->Init.CPOL);
mbed_official 235:685d5f11838f 301
mbed_official 532:fe11edbda85c 302 #if defined(SPI_I2SCFGR_ASTRTEN)
mbed_official 532:fe11edbda85c 303 if (hi2s->Init.Standard == I2S_STANDARD_PCM_SHORT)
mbed_official 532:fe11edbda85c 304 {
mbed_official 532:fe11edbda85c 305 /* Write to SPIx I2SCFGR */
mbed_official 532:fe11edbda85c 306 hi2s->Instance->I2SCFGR = tmpreg | SPI_I2SCFGR_ASTRTEN;
mbed_official 532:fe11edbda85c 307 }
mbed_official 532:fe11edbda85c 308 else
mbed_official 532:fe11edbda85c 309 {
mbed_official 532:fe11edbda85c 310 /* Write to SPIx I2SCFGR */
mbed_official 532:fe11edbda85c 311 hi2s->Instance->I2SCFGR = tmpreg;
mbed_official 532:fe11edbda85c 312 }
mbed_official 532:fe11edbda85c 313 #else
mbed_official 235:685d5f11838f 314 /* Write to SPIx I2SCFGR */
mbed_official 235:685d5f11838f 315 hi2s->Instance->I2SCFGR = tmpreg;
mbed_official 532:fe11edbda85c 316 #endif
mbed_official 235:685d5f11838f 317
mbed_official 235:685d5f11838f 318 hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
mbed_official 235:685d5f11838f 319 hi2s->State= HAL_I2S_STATE_READY;
mbed_official 235:685d5f11838f 320
mbed_official 235:685d5f11838f 321 return HAL_OK;
mbed_official 235:685d5f11838f 322 }
mbed_official 235:685d5f11838f 323
mbed_official 235:685d5f11838f 324 /**
mbed_official 235:685d5f11838f 325 * @brief DeInitializes the I2S peripheral
mbed_official 235:685d5f11838f 326 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 327 * the configuration information for I2S module
mbed_official 235:685d5f11838f 328 * @retval HAL status
mbed_official 235:685d5f11838f 329 */
mbed_official 235:685d5f11838f 330 HAL_StatusTypeDef HAL_I2S_DeInit(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 331 {
mbed_official 235:685d5f11838f 332 /* Check the I2S handle allocation */
mbed_official 352:95e80f5e68f6 333 if(hi2s == HAL_NULL)
mbed_official 235:685d5f11838f 334 {
mbed_official 235:685d5f11838f 335 return HAL_ERROR;
mbed_official 235:685d5f11838f 336 }
mbed_official 235:685d5f11838f 337
mbed_official 235:685d5f11838f 338 hi2s->State = HAL_I2S_STATE_BUSY;
mbed_official 235:685d5f11838f 339
mbed_official 235:685d5f11838f 340 /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */
mbed_official 235:685d5f11838f 341 HAL_I2S_MspDeInit(hi2s);
mbed_official 235:685d5f11838f 342
mbed_official 235:685d5f11838f 343 hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
mbed_official 235:685d5f11838f 344 hi2s->State = HAL_I2S_STATE_RESET;
mbed_official 235:685d5f11838f 345
mbed_official 235:685d5f11838f 346 /* Release Lock */
mbed_official 235:685d5f11838f 347 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 348
mbed_official 235:685d5f11838f 349 return HAL_OK;
mbed_official 235:685d5f11838f 350 }
mbed_official 235:685d5f11838f 351
mbed_official 235:685d5f11838f 352 /**
mbed_official 235:685d5f11838f 353 * @brief I2S MSP Init
mbed_official 235:685d5f11838f 354 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 355 * the configuration information for I2S module
mbed_official 235:685d5f11838f 356 * @retval None
mbed_official 235:685d5f11838f 357 */
mbed_official 235:685d5f11838f 358 __weak void HAL_I2S_MspInit(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 359 {
mbed_official 235:685d5f11838f 360 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 361 the HAL_I2S_MspInit could be implemented in the user file
mbed_official 235:685d5f11838f 362 */
mbed_official 235:685d5f11838f 363 }
mbed_official 235:685d5f11838f 364
mbed_official 235:685d5f11838f 365 /**
mbed_official 235:685d5f11838f 366 * @brief I2S MSP DeInit
mbed_official 235:685d5f11838f 367 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 368 * the configuration information for I2S module
mbed_official 235:685d5f11838f 369 * @retval None
mbed_official 235:685d5f11838f 370 */
mbed_official 235:685d5f11838f 371 __weak void HAL_I2S_MspDeInit(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 372 {
mbed_official 235:685d5f11838f 373 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 374 the HAL_I2S_MspDeInit could be implemented in the user file
mbed_official 235:685d5f11838f 375 */
mbed_official 235:685d5f11838f 376 }
mbed_official 235:685d5f11838f 377 /**
mbed_official 235:685d5f11838f 378 * @}
mbed_official 235:685d5f11838f 379 */
mbed_official 235:685d5f11838f 380
mbed_official 532:fe11edbda85c 381 /** @defgroup I2S_Exported_Functions_Group2 IO operation functions
mbed_official 532:fe11edbda85c 382 * @brief Data transfers functions
mbed_official 532:fe11edbda85c 383 *
mbed_official 235:685d5f11838f 384 @verbatim
mbed_official 235:685d5f11838f 385 ===============================================================================
mbed_official 235:685d5f11838f 386 ##### IO operation functions #####
mbed_official 235:685d5f11838f 387 ===============================================================================
mbed_official 235:685d5f11838f 388 [..]
mbed_official 235:685d5f11838f 389 This subsection provides a set of functions allowing to manage the I2S data
mbed_official 235:685d5f11838f 390 transfers.
mbed_official 235:685d5f11838f 391
mbed_official 235:685d5f11838f 392 (#) There are two modes of transfer:
mbed_official 235:685d5f11838f 393 (++) Blocking mode : The communication is performed in the polling mode.
mbed_official 235:685d5f11838f 394 The status of all data processing is returned by the same function
mbed_official 235:685d5f11838f 395 after finishing transfer.
mbed_official 235:685d5f11838f 396 (++) No-Blocking mode : The communication is performed using Interrupts
mbed_official 235:685d5f11838f 397 or DMA. These functions return the status of the transfer startup.
mbed_official 235:685d5f11838f 398 The end of the data processing will be indicated through the
mbed_official 235:685d5f11838f 399 dedicated I2S IRQ when using Interrupt mode or the DMA IRQ when
mbed_official 235:685d5f11838f 400 using DMA mode.
mbed_official 235:685d5f11838f 401
mbed_official 235:685d5f11838f 402 (#) Blocking mode functions are :
mbed_official 235:685d5f11838f 403 (++) HAL_I2S_Transmit()
mbed_official 235:685d5f11838f 404 (++) HAL_I2S_Receive()
mbed_official 235:685d5f11838f 405
mbed_official 235:685d5f11838f 406 (#) No-Blocking mode functions with Interrupt are :
mbed_official 235:685d5f11838f 407 (++) HAL_I2S_Transmit_IT()
mbed_official 235:685d5f11838f 408 (++) HAL_I2S_Receive_IT()
mbed_official 235:685d5f11838f 409
mbed_official 235:685d5f11838f 410 (#) No-Blocking mode functions with DMA are :
mbed_official 235:685d5f11838f 411 (++) HAL_I2S_Transmit_DMA()
mbed_official 235:685d5f11838f 412 (++) HAL_I2S_Receive_DMA()
mbed_official 235:685d5f11838f 413
mbed_official 235:685d5f11838f 414 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
mbed_official 235:685d5f11838f 415 (++) HAL_I2S_TxCpltCallback()
mbed_official 235:685d5f11838f 416 (++) HAL_I2S_RxCpltCallback()
mbed_official 235:685d5f11838f 417 (++) HAL_I2S_ErrorCallback()
mbed_official 235:685d5f11838f 418
mbed_official 235:685d5f11838f 419 @endverbatim
mbed_official 235:685d5f11838f 420 * @{
mbed_official 235:685d5f11838f 421 */
mbed_official 235:685d5f11838f 422
mbed_official 235:685d5f11838f 423 /**
mbed_official 235:685d5f11838f 424 * @brief Transmit an amount of data in blocking mode
mbed_official 235:685d5f11838f 425 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 426 * the configuration information for I2S module
mbed_official 235:685d5f11838f 427 * @param pData: a 16-bit pointer to data buffer.
mbed_official 235:685d5f11838f 428 * @param Size: number of data sample to be sent:
mbed_official 235:685d5f11838f 429 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
mbed_official 235:685d5f11838f 430 * configuration phase, the Size parameter means the number of 16-bit data length
mbed_official 235:685d5f11838f 431 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
mbed_official 235:685d5f11838f 432 * the Size parameter means the number of 16-bit data length.
mbed_official 235:685d5f11838f 433 * @param Timeout: Timeout duration
mbed_official 235:685d5f11838f 434 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
mbed_official 235:685d5f11838f 435 * between Master and Slave(example: audio streaming).
mbed_official 235:685d5f11838f 436 * @retval HAL status
mbed_official 235:685d5f11838f 437 */
mbed_official 235:685d5f11838f 438 HAL_StatusTypeDef HAL_I2S_Transmit(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout)
mbed_official 235:685d5f11838f 439 {
mbed_official 235:685d5f11838f 440 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 352:95e80f5e68f6 441 if((pData == HAL_NULL ) || (Size == 0))
mbed_official 235:685d5f11838f 442 {
mbed_official 235:685d5f11838f 443 return HAL_ERROR;
mbed_official 235:685d5f11838f 444 }
mbed_official 235:685d5f11838f 445
mbed_official 235:685d5f11838f 446 if(hi2s->State == HAL_I2S_STATE_READY)
mbed_official 235:685d5f11838f 447 {
mbed_official 235:685d5f11838f 448 tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 449 tmp2 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 450 if((tmp1 == I2S_DATAFORMAT_24B)|| \
mbed_official 235:685d5f11838f 451 (tmp2 == I2S_DATAFORMAT_32B))
mbed_official 235:685d5f11838f 452 {
mbed_official 235:685d5f11838f 453 hi2s->TxXferSize = Size*2;
mbed_official 235:685d5f11838f 454 hi2s->TxXferCount = Size*2;
mbed_official 235:685d5f11838f 455 }
mbed_official 235:685d5f11838f 456 else
mbed_official 235:685d5f11838f 457 {
mbed_official 235:685d5f11838f 458 hi2s->TxXferSize = Size;
mbed_official 235:685d5f11838f 459 hi2s->TxXferCount = Size;
mbed_official 235:685d5f11838f 460 }
mbed_official 235:685d5f11838f 461
mbed_official 235:685d5f11838f 462 /* Process Locked */
mbed_official 235:685d5f11838f 463 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 464
mbed_official 235:685d5f11838f 465 hi2s->State = HAL_I2S_STATE_BUSY_TX;
mbed_official 235:685d5f11838f 466
mbed_official 235:685d5f11838f 467 /* Check if the I2S is already enabled */
mbed_official 235:685d5f11838f 468 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 235:685d5f11838f 469 {
mbed_official 235:685d5f11838f 470 /* Enable I2S peripheral */
mbed_official 235:685d5f11838f 471 __HAL_I2S_ENABLE(hi2s);
mbed_official 235:685d5f11838f 472 }
mbed_official 235:685d5f11838f 473
mbed_official 235:685d5f11838f 474 while(hi2s->TxXferCount > 0)
mbed_official 235:685d5f11838f 475 {
mbed_official 235:685d5f11838f 476 hi2s->Instance->DR = (*pData++);
mbed_official 235:685d5f11838f 477 hi2s->TxXferCount--;
mbed_official 235:685d5f11838f 478 /* Wait until TXE flag is set */
mbed_official 235:685d5f11838f 479 if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_TXE, RESET, Timeout) != HAL_OK)
mbed_official 235:685d5f11838f 480 {
mbed_official 235:685d5f11838f 481 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 482 }
mbed_official 235:685d5f11838f 483 }
mbed_official 235:685d5f11838f 484 /* Wait until Busy flag is reset */
mbed_official 235:685d5f11838f 485 if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_BSY, SET, Timeout) != HAL_OK)
mbed_official 235:685d5f11838f 486 {
mbed_official 235:685d5f11838f 487 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 488 }
mbed_official 235:685d5f11838f 489
mbed_official 235:685d5f11838f 490 hi2s->State = HAL_I2S_STATE_READY;
mbed_official 235:685d5f11838f 491
mbed_official 235:685d5f11838f 492 /* Process Unlocked */
mbed_official 235:685d5f11838f 493 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 494
mbed_official 235:685d5f11838f 495 return HAL_OK;
mbed_official 235:685d5f11838f 496 }
mbed_official 235:685d5f11838f 497 else
mbed_official 235:685d5f11838f 498 {
mbed_official 235:685d5f11838f 499 return HAL_BUSY;
mbed_official 235:685d5f11838f 500 }
mbed_official 235:685d5f11838f 501 }
mbed_official 235:685d5f11838f 502
mbed_official 235:685d5f11838f 503 /**
mbed_official 235:685d5f11838f 504 * @brief Receive an amount of data in blocking mode
mbed_official 235:685d5f11838f 505 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 506 * the configuration information for I2S module
mbed_official 235:685d5f11838f 507 * @param pData: a 16-bit pointer to data buffer.
mbed_official 235:685d5f11838f 508 * @param Size: number of data sample to be sent:
mbed_official 235:685d5f11838f 509 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
mbed_official 235:685d5f11838f 510 * configuration phase, the Size parameter means the number of 16-bit data length
mbed_official 235:685d5f11838f 511 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
mbed_official 235:685d5f11838f 512 * the Size parameter means the number of 16-bit data length.
mbed_official 235:685d5f11838f 513 * @param Timeout: Timeout duration
mbed_official 235:685d5f11838f 514 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
mbed_official 235:685d5f11838f 515 * between Master and Slave(example: audio streaming).
mbed_official 235:685d5f11838f 516 * @note In I2S Master Receiver mode, just after enabling the peripheral the clock will be generate
mbed_official 532:fe11edbda85c 517 * in continuous way and as the I2S is not disabled at the end of the I2S transaction.
mbed_official 235:685d5f11838f 518 * @retval HAL status
mbed_official 235:685d5f11838f 519 */
mbed_official 235:685d5f11838f 520 HAL_StatusTypeDef HAL_I2S_Receive(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size, uint32_t Timeout)
mbed_official 235:685d5f11838f 521 {
mbed_official 235:685d5f11838f 522 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 352:95e80f5e68f6 523 if((pData == HAL_NULL ) || (Size == 0))
mbed_official 235:685d5f11838f 524 {
mbed_official 235:685d5f11838f 525 return HAL_ERROR;
mbed_official 235:685d5f11838f 526 }
mbed_official 235:685d5f11838f 527
mbed_official 235:685d5f11838f 528 if(hi2s->State == HAL_I2S_STATE_READY)
mbed_official 235:685d5f11838f 529 {
mbed_official 235:685d5f11838f 530 tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 531 tmp2 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 532 if((tmp1 == I2S_DATAFORMAT_24B)|| \
mbed_official 235:685d5f11838f 533 (tmp2 == I2S_DATAFORMAT_32B))
mbed_official 235:685d5f11838f 534 {
mbed_official 235:685d5f11838f 535 hi2s->RxXferSize = Size*2;
mbed_official 235:685d5f11838f 536 hi2s->RxXferCount = Size*2;
mbed_official 235:685d5f11838f 537 }
mbed_official 235:685d5f11838f 538 else
mbed_official 235:685d5f11838f 539 {
mbed_official 235:685d5f11838f 540 hi2s->RxXferSize = Size;
mbed_official 235:685d5f11838f 541 hi2s->RxXferCount = Size;
mbed_official 235:685d5f11838f 542 }
mbed_official 235:685d5f11838f 543 /* Process Locked */
mbed_official 235:685d5f11838f 544 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 545
mbed_official 235:685d5f11838f 546 hi2s->State = HAL_I2S_STATE_BUSY_RX;
mbed_official 235:685d5f11838f 547
mbed_official 235:685d5f11838f 548 /* Check if the I2S is already enabled */
mbed_official 235:685d5f11838f 549 if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 235:685d5f11838f 550 {
mbed_official 235:685d5f11838f 551 /* Enable I2S peripheral */
mbed_official 235:685d5f11838f 552 __HAL_I2S_ENABLE(hi2s);
mbed_official 235:685d5f11838f 553 }
mbed_official 235:685d5f11838f 554
mbed_official 235:685d5f11838f 555 /* Check if Master Receiver mode is selected */
mbed_official 235:685d5f11838f 556 if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX)
mbed_official 235:685d5f11838f 557 {
mbed_official 235:685d5f11838f 558 /* Clear the Overrun Flag by a read operation on the SPI_DR register followed by a read
mbed_official 235:685d5f11838f 559 access to the SPI_SR register. */
mbed_official 235:685d5f11838f 560 __HAL_I2S_CLEAR_OVRFLAG(hi2s);
mbed_official 235:685d5f11838f 561 }
mbed_official 235:685d5f11838f 562
mbed_official 235:685d5f11838f 563 /* Receive data */
mbed_official 235:685d5f11838f 564 while(hi2s->RxXferCount > 0)
mbed_official 235:685d5f11838f 565 {
mbed_official 235:685d5f11838f 566 /* Wait until RXNE flag is set */
mbed_official 235:685d5f11838f 567 if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_RXNE, RESET, Timeout) != HAL_OK)
mbed_official 235:685d5f11838f 568 {
mbed_official 235:685d5f11838f 569 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 570 }
mbed_official 235:685d5f11838f 571
mbed_official 235:685d5f11838f 572 (*pData++) = hi2s->Instance->DR;
mbed_official 235:685d5f11838f 573 hi2s->RxXferCount--;
mbed_official 235:685d5f11838f 574 }
mbed_official 235:685d5f11838f 575
mbed_official 235:685d5f11838f 576 hi2s->State = HAL_I2S_STATE_READY;
mbed_official 235:685d5f11838f 577
mbed_official 235:685d5f11838f 578 /* Process Unlocked */
mbed_official 235:685d5f11838f 579 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 580
mbed_official 235:685d5f11838f 581 return HAL_OK;
mbed_official 235:685d5f11838f 582 }
mbed_official 235:685d5f11838f 583 else
mbed_official 235:685d5f11838f 584 {
mbed_official 235:685d5f11838f 585 return HAL_BUSY;
mbed_official 235:685d5f11838f 586 }
mbed_official 235:685d5f11838f 587 }
mbed_official 235:685d5f11838f 588
mbed_official 235:685d5f11838f 589 /**
mbed_official 235:685d5f11838f 590 * @brief Transmit an amount of data in non-blocking mode with Interrupt
mbed_official 235:685d5f11838f 591 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 592 * the configuration information for I2S module
mbed_official 235:685d5f11838f 593 * @param pData: a 16-bit pointer to data buffer.
mbed_official 235:685d5f11838f 594 * @param Size: number of data sample to be sent:
mbed_official 235:685d5f11838f 595 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
mbed_official 235:685d5f11838f 596 * configuration phase, the Size parameter means the number of 16-bit data length
mbed_official 235:685d5f11838f 597 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
mbed_official 235:685d5f11838f 598 * the Size parameter means the number of 16-bit data length.
mbed_official 235:685d5f11838f 599 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
mbed_official 235:685d5f11838f 600 * between Master and Slave(example: audio streaming).
mbed_official 235:685d5f11838f 601 * @retval HAL status
mbed_official 235:685d5f11838f 602 */
mbed_official 235:685d5f11838f 603 HAL_StatusTypeDef HAL_I2S_Transmit_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size)
mbed_official 235:685d5f11838f 604 {
mbed_official 235:685d5f11838f 605 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 235:685d5f11838f 606 if(hi2s->State == HAL_I2S_STATE_READY)
mbed_official 235:685d5f11838f 607 {
mbed_official 352:95e80f5e68f6 608 if((pData == HAL_NULL) || (Size == 0))
mbed_official 235:685d5f11838f 609 {
mbed_official 235:685d5f11838f 610 return HAL_ERROR;
mbed_official 235:685d5f11838f 611 }
mbed_official 235:685d5f11838f 612
mbed_official 235:685d5f11838f 613 hi2s->pTxBuffPtr = pData;
mbed_official 235:685d5f11838f 614 tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 615 tmp2 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 616 if((tmp1 == I2S_DATAFORMAT_24B)|| \
mbed_official 235:685d5f11838f 617 (tmp2 == I2S_DATAFORMAT_32B))
mbed_official 235:685d5f11838f 618 {
mbed_official 235:685d5f11838f 619 hi2s->TxXferSize = Size*2;
mbed_official 235:685d5f11838f 620 hi2s->TxXferCount = Size*2;
mbed_official 235:685d5f11838f 621 }
mbed_official 235:685d5f11838f 622 else
mbed_official 235:685d5f11838f 623 {
mbed_official 235:685d5f11838f 624 hi2s->TxXferSize = Size;
mbed_official 235:685d5f11838f 625 hi2s->TxXferCount = Size;
mbed_official 235:685d5f11838f 626 }
mbed_official 235:685d5f11838f 627
mbed_official 235:685d5f11838f 628 /* Process Locked */
mbed_official 235:685d5f11838f 629 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 630
mbed_official 235:685d5f11838f 631 hi2s->State = HAL_I2S_STATE_BUSY_TX;
mbed_official 235:685d5f11838f 632 hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
mbed_official 235:685d5f11838f 633
mbed_official 235:685d5f11838f 634 /* Enable TXE and ERR interrupt */
mbed_official 235:685d5f11838f 635 __HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_ERR));
mbed_official 235:685d5f11838f 636
mbed_official 235:685d5f11838f 637 /* Check if the I2S is already enabled */
mbed_official 235:685d5f11838f 638 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 235:685d5f11838f 639 {
mbed_official 235:685d5f11838f 640 /* Enable I2S peripheral */
mbed_official 235:685d5f11838f 641 __HAL_I2S_ENABLE(hi2s);
mbed_official 235:685d5f11838f 642 }
mbed_official 235:685d5f11838f 643
mbed_official 235:685d5f11838f 644 /* Process Unlocked */
mbed_official 235:685d5f11838f 645 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 646
mbed_official 235:685d5f11838f 647 return HAL_OK;
mbed_official 235:685d5f11838f 648 }
mbed_official 235:685d5f11838f 649 else
mbed_official 235:685d5f11838f 650 {
mbed_official 235:685d5f11838f 651 return HAL_BUSY;
mbed_official 235:685d5f11838f 652 }
mbed_official 235:685d5f11838f 653 }
mbed_official 235:685d5f11838f 654
mbed_official 235:685d5f11838f 655 /**
mbed_official 235:685d5f11838f 656 * @brief Receive an amount of data in non-blocking mode with Interrupt
mbed_official 235:685d5f11838f 657 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 658 * the configuration information for I2S module
mbed_official 235:685d5f11838f 659 * @param pData: a 16-bit pointer to the Receive data buffer.
mbed_official 235:685d5f11838f 660 * @param Size: number of data sample to be sent:
mbed_official 235:685d5f11838f 661 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
mbed_official 235:685d5f11838f 662 * configuration phase, the Size parameter means the number of 16-bit data length
mbed_official 235:685d5f11838f 663 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
mbed_official 235:685d5f11838f 664 * the Size parameter means the number of 16-bit data length.
mbed_official 235:685d5f11838f 665 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
mbed_official 235:685d5f11838f 666 * between Master and Slave(example: audio streaming).
mbed_official 235:685d5f11838f 667 * @note It is recommended to use DMA for the I2S receiver to avoid de-synchronisation
mbed_official 235:685d5f11838f 668 * between Master and Slave otherwise the I2S interrupt should be optimized.
mbed_official 235:685d5f11838f 669 * @retval HAL status
mbed_official 235:685d5f11838f 670 */
mbed_official 235:685d5f11838f 671 HAL_StatusTypeDef HAL_I2S_Receive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size)
mbed_official 235:685d5f11838f 672 {
mbed_official 235:685d5f11838f 673 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 235:685d5f11838f 674 if(hi2s->State == HAL_I2S_STATE_READY)
mbed_official 235:685d5f11838f 675 {
mbed_official 352:95e80f5e68f6 676 if((pData == HAL_NULL) || (Size == 0))
mbed_official 235:685d5f11838f 677 {
mbed_official 235:685d5f11838f 678 return HAL_ERROR;
mbed_official 235:685d5f11838f 679 }
mbed_official 235:685d5f11838f 680
mbed_official 235:685d5f11838f 681 hi2s->pRxBuffPtr = pData;
mbed_official 235:685d5f11838f 682 tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 683 tmp2 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 684 if((tmp1 == I2S_DATAFORMAT_24B)||\
mbed_official 235:685d5f11838f 685 (tmp2 == I2S_DATAFORMAT_32B))
mbed_official 235:685d5f11838f 686 {
mbed_official 235:685d5f11838f 687 hi2s->RxXferSize = Size*2;
mbed_official 235:685d5f11838f 688 hi2s->RxXferCount = Size*2;
mbed_official 235:685d5f11838f 689 }
mbed_official 235:685d5f11838f 690 else
mbed_official 235:685d5f11838f 691 {
mbed_official 235:685d5f11838f 692 hi2s->RxXferSize = Size;
mbed_official 235:685d5f11838f 693 hi2s->RxXferCount = Size;
mbed_official 235:685d5f11838f 694 }
mbed_official 235:685d5f11838f 695 /* Process Locked */
mbed_official 235:685d5f11838f 696 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 697
mbed_official 235:685d5f11838f 698 hi2s->State = HAL_I2S_STATE_BUSY_RX;
mbed_official 235:685d5f11838f 699 hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
mbed_official 235:685d5f11838f 700
mbed_official 235:685d5f11838f 701 /* Enable TXE and ERR interrupt */
mbed_official 235:685d5f11838f 702 __HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_ERR));
mbed_official 235:685d5f11838f 703
mbed_official 235:685d5f11838f 704 /* Check if the I2S is already enabled */
mbed_official 235:685d5f11838f 705 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 235:685d5f11838f 706 {
mbed_official 235:685d5f11838f 707 /* Enable I2S peripheral */
mbed_official 235:685d5f11838f 708 __HAL_I2S_ENABLE(hi2s);
mbed_official 235:685d5f11838f 709 }
mbed_official 235:685d5f11838f 710
mbed_official 235:685d5f11838f 711 /* Process Unlocked */
mbed_official 235:685d5f11838f 712 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 713
mbed_official 235:685d5f11838f 714 return HAL_OK;
mbed_official 235:685d5f11838f 715 }
mbed_official 235:685d5f11838f 716
mbed_official 235:685d5f11838f 717 else
mbed_official 235:685d5f11838f 718 {
mbed_official 235:685d5f11838f 719 return HAL_BUSY;
mbed_official 235:685d5f11838f 720 }
mbed_official 235:685d5f11838f 721 }
mbed_official 235:685d5f11838f 722
mbed_official 235:685d5f11838f 723 /**
mbed_official 235:685d5f11838f 724 * @brief Transmit an amount of data in non-blocking mode with DMA
mbed_official 235:685d5f11838f 725 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 726 * the configuration information for I2S module
mbed_official 235:685d5f11838f 727 * @param pData: a 16-bit pointer to the Transmit data buffer.
mbed_official 235:685d5f11838f 728 * @param Size: number of data sample to be sent:
mbed_official 235:685d5f11838f 729 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
mbed_official 235:685d5f11838f 730 * configuration phase, the Size parameter means the number of 16-bit data length
mbed_official 235:685d5f11838f 731 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
mbed_official 235:685d5f11838f 732 * the Size parameter means the number of 16-bit data length.
mbed_official 235:685d5f11838f 733 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
mbed_official 235:685d5f11838f 734 * between Master and Slave(example: audio streaming).
mbed_official 235:685d5f11838f 735 * @retval HAL status
mbed_official 235:685d5f11838f 736 */
mbed_official 235:685d5f11838f 737 HAL_StatusTypeDef HAL_I2S_Transmit_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size)
mbed_official 235:685d5f11838f 738 {
mbed_official 235:685d5f11838f 739 uint32_t *tmp;
mbed_official 235:685d5f11838f 740 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 235:685d5f11838f 741
mbed_official 352:95e80f5e68f6 742 if((pData == HAL_NULL) || (Size == 0))
mbed_official 235:685d5f11838f 743 {
mbed_official 235:685d5f11838f 744 return HAL_ERROR;
mbed_official 235:685d5f11838f 745 }
mbed_official 235:685d5f11838f 746
mbed_official 235:685d5f11838f 747 if(hi2s->State == HAL_I2S_STATE_READY)
mbed_official 235:685d5f11838f 748 {
mbed_official 235:685d5f11838f 749 hi2s->pTxBuffPtr = pData;
mbed_official 235:685d5f11838f 750 tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 751 tmp2 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 752 if((tmp1 == I2S_DATAFORMAT_24B)|| \
mbed_official 235:685d5f11838f 753 (tmp2 == I2S_DATAFORMAT_32B))
mbed_official 235:685d5f11838f 754 {
mbed_official 235:685d5f11838f 755 hi2s->TxXferSize = Size*2;
mbed_official 235:685d5f11838f 756 hi2s->TxXferCount = Size*2;
mbed_official 235:685d5f11838f 757 }
mbed_official 235:685d5f11838f 758 else
mbed_official 235:685d5f11838f 759 {
mbed_official 235:685d5f11838f 760 hi2s->TxXferSize = Size;
mbed_official 235:685d5f11838f 761 hi2s->TxXferCount = Size;
mbed_official 235:685d5f11838f 762 }
mbed_official 235:685d5f11838f 763
mbed_official 235:685d5f11838f 764 /* Process Locked */
mbed_official 235:685d5f11838f 765 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 766
mbed_official 235:685d5f11838f 767 hi2s->State = HAL_I2S_STATE_BUSY_TX;
mbed_official 235:685d5f11838f 768 hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
mbed_official 235:685d5f11838f 769
mbed_official 532:fe11edbda85c 770 /* Set the I2S Tx DMA Half transfer complete callback */
mbed_official 235:685d5f11838f 771 hi2s->hdmatx->XferHalfCpltCallback = I2S_DMATxHalfCplt;
mbed_official 235:685d5f11838f 772
mbed_official 532:fe11edbda85c 773 /* Set the I2S Tx DMA transfer complete callback */
mbed_official 235:685d5f11838f 774 hi2s->hdmatx->XferCpltCallback = I2S_DMATxCplt;
mbed_official 235:685d5f11838f 775
mbed_official 235:685d5f11838f 776 /* Set the DMA error callback */
mbed_official 235:685d5f11838f 777 hi2s->hdmatx->XferErrorCallback = I2S_DMAError;
mbed_official 235:685d5f11838f 778
mbed_official 235:685d5f11838f 779 /* Enable the Tx DMA Stream */
mbed_official 235:685d5f11838f 780 tmp = (uint32_t*)&pData;
mbed_official 235:685d5f11838f 781 HAL_DMA_Start_IT(hi2s->hdmatx, *(uint32_t*)tmp, (uint32_t)&hi2s->Instance->DR, hi2s->TxXferSize);
mbed_official 235:685d5f11838f 782
mbed_official 235:685d5f11838f 783 /* Check if the I2S is already enabled */
mbed_official 235:685d5f11838f 784 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 235:685d5f11838f 785 {
mbed_official 235:685d5f11838f 786 /* Enable I2S peripheral */
mbed_official 235:685d5f11838f 787 __HAL_I2S_ENABLE(hi2s);
mbed_official 235:685d5f11838f 788 }
mbed_official 235:685d5f11838f 789
mbed_official 235:685d5f11838f 790 /* Check if the I2S Tx request is already enabled */
mbed_official 235:685d5f11838f 791 if((hi2s->Instance->CR2 & SPI_CR2_TXDMAEN) != SPI_CR2_TXDMAEN)
mbed_official 235:685d5f11838f 792 {
mbed_official 235:685d5f11838f 793 /* Enable Tx DMA Request */
mbed_official 235:685d5f11838f 794 hi2s->Instance->CR2 |= SPI_CR2_TXDMAEN;
mbed_official 235:685d5f11838f 795 }
mbed_official 235:685d5f11838f 796
mbed_official 235:685d5f11838f 797 /* Process Unlocked */
mbed_official 235:685d5f11838f 798 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 799
mbed_official 235:685d5f11838f 800 return HAL_OK;
mbed_official 235:685d5f11838f 801 }
mbed_official 235:685d5f11838f 802 else
mbed_official 235:685d5f11838f 803 {
mbed_official 235:685d5f11838f 804 return HAL_BUSY;
mbed_official 235:685d5f11838f 805 }
mbed_official 235:685d5f11838f 806 }
mbed_official 235:685d5f11838f 807
mbed_official 235:685d5f11838f 808 /**
mbed_official 235:685d5f11838f 809 * @brief Receive an amount of data in non-blocking mode with DMA
mbed_official 235:685d5f11838f 810 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 811 * the configuration information for I2S module
mbed_official 235:685d5f11838f 812 * @param pData: a 16-bit pointer to the Receive data buffer.
mbed_official 235:685d5f11838f 813 * @param Size: number of data sample to be sent:
mbed_official 235:685d5f11838f 814 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
mbed_official 235:685d5f11838f 815 * configuration phase, the Size parameter means the number of 16-bit data length
mbed_official 235:685d5f11838f 816 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
mbed_official 235:685d5f11838f 817 * the Size parameter means the number of 16-bit data length.
mbed_official 235:685d5f11838f 818 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
mbed_official 235:685d5f11838f 819 * between Master and Slave(example: audio streaming).
mbed_official 235:685d5f11838f 820 * @retval HAL status
mbed_official 235:685d5f11838f 821 */
mbed_official 235:685d5f11838f 822 HAL_StatusTypeDef HAL_I2S_Receive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size)
mbed_official 235:685d5f11838f 823 {
mbed_official 235:685d5f11838f 824 uint32_t *tmp;
mbed_official 235:685d5f11838f 825 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 235:685d5f11838f 826
mbed_official 352:95e80f5e68f6 827 if((pData == HAL_NULL) || (Size == 0))
mbed_official 235:685d5f11838f 828 {
mbed_official 235:685d5f11838f 829 return HAL_ERROR;
mbed_official 235:685d5f11838f 830 }
mbed_official 235:685d5f11838f 831
mbed_official 235:685d5f11838f 832 if(hi2s->State == HAL_I2S_STATE_READY)
mbed_official 235:685d5f11838f 833 {
mbed_official 235:685d5f11838f 834 hi2s->pRxBuffPtr = pData;
mbed_official 235:685d5f11838f 835 tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 836 tmp2 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
mbed_official 235:685d5f11838f 837 if((tmp1 == I2S_DATAFORMAT_24B)|| \
mbed_official 235:685d5f11838f 838 (tmp2 == I2S_DATAFORMAT_32B))
mbed_official 235:685d5f11838f 839 {
mbed_official 235:685d5f11838f 840 hi2s->RxXferSize = Size*2;
mbed_official 235:685d5f11838f 841 hi2s->RxXferCount = Size*2;
mbed_official 235:685d5f11838f 842 }
mbed_official 235:685d5f11838f 843 else
mbed_official 235:685d5f11838f 844 {
mbed_official 235:685d5f11838f 845 hi2s->RxXferSize = Size;
mbed_official 235:685d5f11838f 846 hi2s->RxXferCount = Size;
mbed_official 235:685d5f11838f 847 }
mbed_official 235:685d5f11838f 848 /* Process Locked */
mbed_official 235:685d5f11838f 849 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 850
mbed_official 235:685d5f11838f 851 hi2s->State = HAL_I2S_STATE_BUSY_RX;
mbed_official 235:685d5f11838f 852 hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
mbed_official 235:685d5f11838f 853
mbed_official 532:fe11edbda85c 854 /* Set the I2S Rx DMA Half transfer complete callback */
mbed_official 235:685d5f11838f 855 hi2s->hdmarx->XferHalfCpltCallback = I2S_DMARxHalfCplt;
mbed_official 235:685d5f11838f 856
mbed_official 532:fe11edbda85c 857 /* Set the I2S Rx DMA transfer complete callback */
mbed_official 235:685d5f11838f 858 hi2s->hdmarx->XferCpltCallback = I2S_DMARxCplt;
mbed_official 235:685d5f11838f 859
mbed_official 235:685d5f11838f 860 /* Set the DMA error callback */
mbed_official 235:685d5f11838f 861 hi2s->hdmarx->XferErrorCallback = I2S_DMAError;
mbed_official 235:685d5f11838f 862
mbed_official 235:685d5f11838f 863 /* Check if Master Receiver mode is selected */
mbed_official 235:685d5f11838f 864 if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX)
mbed_official 235:685d5f11838f 865 {
mbed_official 235:685d5f11838f 866 /* Clear the Overrun Flag by a read operation to the SPI_DR register followed by a read
mbed_official 235:685d5f11838f 867 access to the SPI_SR register. */
mbed_official 235:685d5f11838f 868 __HAL_I2S_CLEAR_OVRFLAG(hi2s);
mbed_official 235:685d5f11838f 869 }
mbed_official 235:685d5f11838f 870
mbed_official 235:685d5f11838f 871 /* Enable the Rx DMA Stream */
mbed_official 235:685d5f11838f 872 tmp = (uint32_t*)&pData;
mbed_official 235:685d5f11838f 873 HAL_DMA_Start_IT(hi2s->hdmarx, (uint32_t)&hi2s->Instance->DR, *(uint32_t*)tmp, hi2s->RxXferSize);
mbed_official 235:685d5f11838f 874
mbed_official 235:685d5f11838f 875 /* Check if the I2S is already enabled */
mbed_official 235:685d5f11838f 876 if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
mbed_official 235:685d5f11838f 877 {
mbed_official 235:685d5f11838f 878 /* Enable I2S peripheral */
mbed_official 235:685d5f11838f 879 __HAL_I2S_ENABLE(hi2s);
mbed_official 235:685d5f11838f 880 }
mbed_official 235:685d5f11838f 881
mbed_official 235:685d5f11838f 882 /* Check if the I2S Rx request is already enabled */
mbed_official 235:685d5f11838f 883 if((hi2s->Instance->CR2 &SPI_CR2_RXDMAEN) != SPI_CR2_RXDMAEN)
mbed_official 235:685d5f11838f 884 {
mbed_official 235:685d5f11838f 885 /* Enable Rx DMA Request */
mbed_official 235:685d5f11838f 886 hi2s->Instance->CR2 |= SPI_CR2_RXDMAEN;
mbed_official 235:685d5f11838f 887 }
mbed_official 235:685d5f11838f 888
mbed_official 235:685d5f11838f 889 /* Process Unlocked */
mbed_official 235:685d5f11838f 890 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 891
mbed_official 235:685d5f11838f 892 return HAL_OK;
mbed_official 235:685d5f11838f 893 }
mbed_official 235:685d5f11838f 894 else
mbed_official 235:685d5f11838f 895 {
mbed_official 235:685d5f11838f 896 return HAL_BUSY;
mbed_official 235:685d5f11838f 897 }
mbed_official 235:685d5f11838f 898 }
mbed_official 235:685d5f11838f 899
mbed_official 235:685d5f11838f 900 /**
mbed_official 235:685d5f11838f 901 * @brief Pauses the audio stream playing from the Media.
mbed_official 235:685d5f11838f 902 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 903 * the configuration information for I2S module
mbed_official 235:685d5f11838f 904 * @retval HAL status
mbed_official 235:685d5f11838f 905 */
mbed_official 532:fe11edbda85c 906 __weak HAL_StatusTypeDef HAL_I2S_DMAPause(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 907 {
mbed_official 235:685d5f11838f 908 /* Process Locked */
mbed_official 235:685d5f11838f 909 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 910
mbed_official 235:685d5f11838f 911 if(hi2s->State == HAL_I2S_STATE_BUSY_TX)
mbed_official 235:685d5f11838f 912 {
mbed_official 235:685d5f11838f 913 /* Disable the I2S DMA Tx request */
mbed_official 235:685d5f11838f 914 hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_TXDMAEN);
mbed_official 235:685d5f11838f 915 }
mbed_official 235:685d5f11838f 916 else if(hi2s->State == HAL_I2S_STATE_BUSY_RX)
mbed_official 235:685d5f11838f 917 {
mbed_official 235:685d5f11838f 918 /* Disable the I2S DMA Rx request */
mbed_official 235:685d5f11838f 919 hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_RXDMAEN);
mbed_official 235:685d5f11838f 920 }
mbed_official 235:685d5f11838f 921 else if(hi2s->State == HAL_I2S_STATE_BUSY_TX_RX)
mbed_official 235:685d5f11838f 922 {
mbed_official 235:685d5f11838f 923 if((hi2s->Init.Mode == I2S_MODE_SLAVE_TX)||(hi2s->Init.Mode == I2S_MODE_MASTER_TX))
mbed_official 235:685d5f11838f 924 {
mbed_official 235:685d5f11838f 925 /* Disable the I2S DMA Tx request */
mbed_official 235:685d5f11838f 926 hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_TXDMAEN);
mbed_official 235:685d5f11838f 927 }
mbed_official 235:685d5f11838f 928 else
mbed_official 235:685d5f11838f 929 {
mbed_official 235:685d5f11838f 930 /* Disable the I2S DMA Rx request */
mbed_official 235:685d5f11838f 931 hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_RXDMAEN);
mbed_official 235:685d5f11838f 932 }
mbed_official 235:685d5f11838f 933 }
mbed_official 235:685d5f11838f 934
mbed_official 235:685d5f11838f 935 /* Process Unlocked */
mbed_official 235:685d5f11838f 936 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 937
mbed_official 235:685d5f11838f 938 return HAL_OK;
mbed_official 235:685d5f11838f 939 }
mbed_official 235:685d5f11838f 940
mbed_official 235:685d5f11838f 941 /**
mbed_official 235:685d5f11838f 942 * @brief Resumes the audio stream playing from the Media.
mbed_official 235:685d5f11838f 943 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 944 * the configuration information for I2S module
mbed_official 235:685d5f11838f 945 * @retval HAL status
mbed_official 235:685d5f11838f 946 */
mbed_official 532:fe11edbda85c 947 __weak HAL_StatusTypeDef HAL_I2S_DMAResume(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 948 {
mbed_official 235:685d5f11838f 949 /* Process Locked */
mbed_official 235:685d5f11838f 950 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 951
mbed_official 235:685d5f11838f 952 if(hi2s->State == HAL_I2S_STATE_BUSY_TX)
mbed_official 235:685d5f11838f 953 {
mbed_official 235:685d5f11838f 954 /* Enable the I2S DMA Tx request */
mbed_official 235:685d5f11838f 955 hi2s->Instance->CR2 |= SPI_CR2_TXDMAEN;
mbed_official 235:685d5f11838f 956 }
mbed_official 235:685d5f11838f 957 else if(hi2s->State == HAL_I2S_STATE_BUSY_RX)
mbed_official 235:685d5f11838f 958 {
mbed_official 235:685d5f11838f 959 /* Enable the I2S DMA Rx request */
mbed_official 235:685d5f11838f 960 hi2s->Instance->CR2 |= SPI_CR2_RXDMAEN;
mbed_official 235:685d5f11838f 961 }
mbed_official 235:685d5f11838f 962 else if(hi2s->State == HAL_I2S_STATE_BUSY_TX_RX)
mbed_official 235:685d5f11838f 963 {
mbed_official 235:685d5f11838f 964 if((hi2s->Init.Mode == I2S_MODE_SLAVE_TX)||(hi2s->Init.Mode == I2S_MODE_MASTER_TX))
mbed_official 235:685d5f11838f 965 {
mbed_official 235:685d5f11838f 966 /* Enable the I2S DMA Tx request */
mbed_official 235:685d5f11838f 967 hi2s->Instance->CR2 |= SPI_CR2_TXDMAEN;
mbed_official 235:685d5f11838f 968 }
mbed_official 235:685d5f11838f 969 else
mbed_official 235:685d5f11838f 970 {
mbed_official 235:685d5f11838f 971 /* Enable the I2S DMA Rx request */
mbed_official 235:685d5f11838f 972 hi2s->Instance->CR2 |= SPI_CR2_RXDMAEN;
mbed_official 235:685d5f11838f 973 }
mbed_official 235:685d5f11838f 974 }
mbed_official 235:685d5f11838f 975
mbed_official 235:685d5f11838f 976 /* If the I2S peripheral is still not enabled, enable it */
mbed_official 235:685d5f11838f 977 if ((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SE) == 0)
mbed_official 235:685d5f11838f 978 {
mbed_official 235:685d5f11838f 979 /* Enable I2S peripheral */
mbed_official 235:685d5f11838f 980 __HAL_I2S_ENABLE(hi2s);
mbed_official 235:685d5f11838f 981 }
mbed_official 235:685d5f11838f 982
mbed_official 235:685d5f11838f 983 /* Process Unlocked */
mbed_official 235:685d5f11838f 984 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 985
mbed_official 235:685d5f11838f 986 return HAL_OK;
mbed_official 235:685d5f11838f 987 }
mbed_official 235:685d5f11838f 988
mbed_official 235:685d5f11838f 989 /**
mbed_official 235:685d5f11838f 990 * @brief Resumes the audio stream playing from the Media.
mbed_official 235:685d5f11838f 991 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 992 * the configuration information for I2S module
mbed_official 235:685d5f11838f 993 * @retval HAL status
mbed_official 235:685d5f11838f 994 */
mbed_official 532:fe11edbda85c 995 __weak HAL_StatusTypeDef HAL_I2S_DMAStop(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 996 {
mbed_official 235:685d5f11838f 997 /* Process Locked */
mbed_official 235:685d5f11838f 998 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 999
mbed_official 235:685d5f11838f 1000 /* Disable the I2S Tx/Rx DMA requests */
mbed_official 235:685d5f11838f 1001 hi2s->Instance->CR2 &= ~SPI_CR2_TXDMAEN;
mbed_official 235:685d5f11838f 1002 hi2s->Instance->CR2 &= ~SPI_CR2_RXDMAEN;
mbed_official 532:fe11edbda85c 1003
mbed_official 235:685d5f11838f 1004 /* Abort the I2S DMA Stream tx */
mbed_official 352:95e80f5e68f6 1005 if(hi2s->hdmatx != HAL_NULL)
mbed_official 235:685d5f11838f 1006 {
mbed_official 235:685d5f11838f 1007 HAL_DMA_Abort(hi2s->hdmatx);
mbed_official 235:685d5f11838f 1008 }
mbed_official 235:685d5f11838f 1009 /* Abort the I2S DMA Stream rx */
mbed_official 352:95e80f5e68f6 1010 if(hi2s->hdmarx != HAL_NULL)
mbed_official 235:685d5f11838f 1011 {
mbed_official 235:685d5f11838f 1012 HAL_DMA_Abort(hi2s->hdmarx);
mbed_official 235:685d5f11838f 1013 }
mbed_official 235:685d5f11838f 1014
mbed_official 235:685d5f11838f 1015 /* Disable I2S peripheral */
mbed_official 235:685d5f11838f 1016 __HAL_I2S_DISABLE(hi2s);
mbed_official 235:685d5f11838f 1017
mbed_official 235:685d5f11838f 1018 hi2s->State = HAL_I2S_STATE_READY;
mbed_official 235:685d5f11838f 1019
mbed_official 235:685d5f11838f 1020 /* Process Unlocked */
mbed_official 235:685d5f11838f 1021 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 1022
mbed_official 235:685d5f11838f 1023 return HAL_OK;
mbed_official 235:685d5f11838f 1024 }
mbed_official 235:685d5f11838f 1025
mbed_official 235:685d5f11838f 1026 /**
mbed_official 235:685d5f11838f 1027 * @brief This function handles I2S interrupt request.
mbed_official 235:685d5f11838f 1028 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1029 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1030 * @retval None
mbed_official 235:685d5f11838f 1031 */
mbed_official 532:fe11edbda85c 1032 __weak void HAL_I2S_IRQHandler(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 1033 {
mbed_official 532:fe11edbda85c 1034 uint32_t tmp1 = 0, tmp2 = 0;
mbed_official 532:fe11edbda85c 1035
mbed_official 235:685d5f11838f 1036 if(hi2s->State == HAL_I2S_STATE_BUSY_RX)
mbed_official 235:685d5f11838f 1037 {
mbed_official 235:685d5f11838f 1038 tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_RXNE);
mbed_official 235:685d5f11838f 1039 tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_RXNE);
mbed_official 235:685d5f11838f 1040 /* I2S in mode Receiver ------------------------------------------------*/
mbed_official 235:685d5f11838f 1041 if((tmp1 != RESET) && (tmp2 != RESET))
mbed_official 235:685d5f11838f 1042 {
mbed_official 235:685d5f11838f 1043 I2S_Receive_IT(hi2s);
mbed_official 235:685d5f11838f 1044 }
mbed_official 235:685d5f11838f 1045
mbed_official 235:685d5f11838f 1046 tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_OVR);
mbed_official 235:685d5f11838f 1047 tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR);
mbed_official 235:685d5f11838f 1048 /* I2S Overrun error interrupt occurred ---------------------------------*/
mbed_official 235:685d5f11838f 1049 if((tmp1 != RESET) && (tmp2 != RESET))
mbed_official 235:685d5f11838f 1050 {
mbed_official 235:685d5f11838f 1051 __HAL_I2S_CLEAR_OVRFLAG(hi2s);
mbed_official 235:685d5f11838f 1052 hi2s->ErrorCode |= HAL_I2S_ERROR_OVR;
mbed_official 235:685d5f11838f 1053 }
mbed_official 235:685d5f11838f 1054 }
mbed_official 235:685d5f11838f 1055
mbed_official 235:685d5f11838f 1056 if(hi2s->State == HAL_I2S_STATE_BUSY_TX)
mbed_official 235:685d5f11838f 1057 {
mbed_official 235:685d5f11838f 1058 tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_TXE);
mbed_official 235:685d5f11838f 1059 tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_TXE);
mbed_official 532:fe11edbda85c 1060 /* I2S in mode Transmitter -----------------------------------------------*/
mbed_official 235:685d5f11838f 1061 if((tmp1 != RESET) && (tmp2 != RESET))
mbed_official 235:685d5f11838f 1062 {
mbed_official 235:685d5f11838f 1063 I2S_Transmit_IT(hi2s);
mbed_official 235:685d5f11838f 1064 }
mbed_official 235:685d5f11838f 1065
mbed_official 235:685d5f11838f 1066 tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_UDR);
mbed_official 235:685d5f11838f 1067 tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR);
mbed_official 235:685d5f11838f 1068 /* I2S Underrun error interrupt occurred --------------------------------*/
mbed_official 235:685d5f11838f 1069 if((tmp1 != RESET) && (tmp2 != RESET))
mbed_official 235:685d5f11838f 1070 {
mbed_official 235:685d5f11838f 1071 __HAL_I2S_CLEAR_UDRFLAG(hi2s);
mbed_official 235:685d5f11838f 1072 hi2s->ErrorCode |= HAL_I2S_ERROR_UDR;
mbed_official 235:685d5f11838f 1073 }
mbed_official 235:685d5f11838f 1074 }
mbed_official 235:685d5f11838f 1075
mbed_official 235:685d5f11838f 1076 /* Call the Error call Back in case of Errors */
mbed_official 235:685d5f11838f 1077 if(hi2s->ErrorCode != HAL_I2S_ERROR_NONE)
mbed_official 235:685d5f11838f 1078 {
mbed_official 235:685d5f11838f 1079 /* Set the I2S state ready to be able to start again the process */
mbed_official 235:685d5f11838f 1080 hi2s->State= HAL_I2S_STATE_READY;
mbed_official 235:685d5f11838f 1081 HAL_I2S_ErrorCallback(hi2s);
mbed_official 235:685d5f11838f 1082 }
mbed_official 235:685d5f11838f 1083 }
mbed_official 235:685d5f11838f 1084
mbed_official 235:685d5f11838f 1085 /**
mbed_official 235:685d5f11838f 1086 * @brief Tx Transfer Half completed callbacks
mbed_official 235:685d5f11838f 1087 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1088 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1089 * @retval None
mbed_official 235:685d5f11838f 1090 */
mbed_official 235:685d5f11838f 1091 __weak void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 1092 {
mbed_official 235:685d5f11838f 1093 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 1094 the HAL_I2S_TxHalfCpltCallback could be implemented in the user file
mbed_official 235:685d5f11838f 1095 */
mbed_official 235:685d5f11838f 1096 }
mbed_official 235:685d5f11838f 1097
mbed_official 235:685d5f11838f 1098 /**
mbed_official 235:685d5f11838f 1099 * @brief Tx Transfer completed callbacks
mbed_official 235:685d5f11838f 1100 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1101 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1102 * @retval None
mbed_official 235:685d5f11838f 1103 */
mbed_official 235:685d5f11838f 1104 __weak void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 1105 {
mbed_official 235:685d5f11838f 1106 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 1107 the HAL_I2S_TxCpltCallback could be implemented in the user file
mbed_official 235:685d5f11838f 1108 */
mbed_official 235:685d5f11838f 1109 }
mbed_official 235:685d5f11838f 1110
mbed_official 235:685d5f11838f 1111 /**
mbed_official 235:685d5f11838f 1112 * @brief Rx Transfer half completed callbacks
mbed_official 235:685d5f11838f 1113 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1114 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1115 * @retval None
mbed_official 235:685d5f11838f 1116 */
mbed_official 235:685d5f11838f 1117 __weak void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 1118 {
mbed_official 235:685d5f11838f 1119 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 1120 the HAL_I2S_RxCpltCallback could be implemented in the user file
mbed_official 235:685d5f11838f 1121 */
mbed_official 235:685d5f11838f 1122 }
mbed_official 235:685d5f11838f 1123
mbed_official 235:685d5f11838f 1124 /**
mbed_official 235:685d5f11838f 1125 * @brief Rx Transfer completed callbacks
mbed_official 235:685d5f11838f 1126 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1127 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1128 * @retval None
mbed_official 235:685d5f11838f 1129 */
mbed_official 235:685d5f11838f 1130 __weak void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 1131 {
mbed_official 235:685d5f11838f 1132 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 1133 the HAL_I2S_RxCpltCallback could be implemented in the user file
mbed_official 235:685d5f11838f 1134 */
mbed_official 235:685d5f11838f 1135 }
mbed_official 235:685d5f11838f 1136
mbed_official 235:685d5f11838f 1137 /**
mbed_official 235:685d5f11838f 1138 * @brief I2S error callbacks
mbed_official 235:685d5f11838f 1139 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1140 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1141 * @retval None
mbed_official 235:685d5f11838f 1142 */
mbed_official 235:685d5f11838f 1143 __weak void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 1144 {
mbed_official 235:685d5f11838f 1145 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 1146 the HAL_I2S_ErrorCallback could be implemented in the user file
mbed_official 235:685d5f11838f 1147 */
mbed_official 235:685d5f11838f 1148 }
mbed_official 235:685d5f11838f 1149
mbed_official 235:685d5f11838f 1150 /**
mbed_official 235:685d5f11838f 1151 * @}
mbed_official 235:685d5f11838f 1152 */
mbed_official 235:685d5f11838f 1153
mbed_official 532:fe11edbda85c 1154 /** @defgroup I2S_Exported_Functions_Group3 Peripheral State and Errors functions
mbed_official 532:fe11edbda85c 1155 * @brief Peripheral State functions
mbed_official 235:685d5f11838f 1156 @verbatim
mbed_official 235:685d5f11838f 1157 ===============================================================================
mbed_official 235:685d5f11838f 1158 ##### Peripheral State and Errors functions #####
mbed_official 235:685d5f11838f 1159 ===============================================================================
mbed_official 235:685d5f11838f 1160 [..]
mbed_official 235:685d5f11838f 1161 This subsection permits to get in run-time the status of the peripheral
mbed_official 235:685d5f11838f 1162 and the data flow.
mbed_official 235:685d5f11838f 1163
mbed_official 235:685d5f11838f 1164 @endverbatim
mbed_official 235:685d5f11838f 1165 * @{
mbed_official 235:685d5f11838f 1166 */
mbed_official 235:685d5f11838f 1167
mbed_official 235:685d5f11838f 1168 /**
mbed_official 235:685d5f11838f 1169 * @brief Return the I2S state
mbed_official 235:685d5f11838f 1170 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1171 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1172 * @retval HAL state
mbed_official 235:685d5f11838f 1173 */
mbed_official 235:685d5f11838f 1174 HAL_I2S_StateTypeDef HAL_I2S_GetState(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 1175 {
mbed_official 235:685d5f11838f 1176 return hi2s->State;
mbed_official 235:685d5f11838f 1177 }
mbed_official 235:685d5f11838f 1178
mbed_official 235:685d5f11838f 1179 /**
mbed_official 235:685d5f11838f 1180 * @brief Return the I2S error code
mbed_official 235:685d5f11838f 1181 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1182 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1183 * @retval I2S Error Code
mbed_official 235:685d5f11838f 1184 */
mbed_official 532:fe11edbda85c 1185 uint32_t HAL_I2S_GetError(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 1186 {
mbed_official 235:685d5f11838f 1187 return hi2s->ErrorCode;
mbed_official 235:685d5f11838f 1188 }
mbed_official 235:685d5f11838f 1189 /**
mbed_official 235:685d5f11838f 1190 * @}
mbed_official 235:685d5f11838f 1191 */
mbed_official 235:685d5f11838f 1192
mbed_official 235:685d5f11838f 1193 /**
mbed_official 235:685d5f11838f 1194 * @brief DMA I2S transmit process half complete callback
mbed_official 235:685d5f11838f 1195 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1196 * the configuration information for the specified DMA module.
mbed_official 235:685d5f11838f 1197 * @retval None
mbed_official 235:685d5f11838f 1198 */
mbed_official 532:fe11edbda85c 1199 void I2S_DMATxHalfCplt(DMA_HandleTypeDef *hdma)
mbed_official 235:685d5f11838f 1200 {
mbed_official 235:685d5f11838f 1201 I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
mbed_official 235:685d5f11838f 1202
mbed_official 235:685d5f11838f 1203 HAL_I2S_TxHalfCpltCallback(hi2s);
mbed_official 235:685d5f11838f 1204 }
mbed_official 235:685d5f11838f 1205
mbed_official 235:685d5f11838f 1206 /**
mbed_official 235:685d5f11838f 1207 * @brief DMA I2S receive process half complete callback
mbed_official 235:685d5f11838f 1208 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1209 * the configuration information for the specified DMA module.
mbed_official 235:685d5f11838f 1210 * @retval None
mbed_official 235:685d5f11838f 1211 */
mbed_official 235:685d5f11838f 1212 void I2S_DMARxHalfCplt(DMA_HandleTypeDef *hdma)
mbed_official 235:685d5f11838f 1213 {
mbed_official 235:685d5f11838f 1214 I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
mbed_official 235:685d5f11838f 1215
mbed_official 235:685d5f11838f 1216 HAL_I2S_RxHalfCpltCallback(hi2s);
mbed_official 235:685d5f11838f 1217 }
mbed_official 235:685d5f11838f 1218
mbed_official 235:685d5f11838f 1219 /**
mbed_official 235:685d5f11838f 1220 * @brief DMA I2S communication error callback
mbed_official 235:685d5f11838f 1221 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1222 * the configuration information for the specified DMA module.
mbed_official 235:685d5f11838f 1223 * @retval None
mbed_official 235:685d5f11838f 1224 */
mbed_official 235:685d5f11838f 1225 void I2S_DMAError(DMA_HandleTypeDef *hdma)
mbed_official 235:685d5f11838f 1226 {
mbed_official 235:685d5f11838f 1227 I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
mbed_official 235:685d5f11838f 1228
mbed_official 235:685d5f11838f 1229 hi2s->TxXferCount = 0;
mbed_official 235:685d5f11838f 1230 hi2s->RxXferCount = 0;
mbed_official 235:685d5f11838f 1231
mbed_official 235:685d5f11838f 1232 hi2s->State= HAL_I2S_STATE_READY;
mbed_official 235:685d5f11838f 1233
mbed_official 235:685d5f11838f 1234 hi2s->ErrorCode |= HAL_I2S_ERROR_DMA;
mbed_official 235:685d5f11838f 1235 HAL_I2S_ErrorCallback(hi2s);
mbed_official 235:685d5f11838f 1236 }
mbed_official 235:685d5f11838f 1237
mbed_official 235:685d5f11838f 1238 /**
mbed_official 235:685d5f11838f 1239 * @brief Transmit an amount of data in non-blocking mode with Interrupt
mbed_official 235:685d5f11838f 1240 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1241 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1242 * @retval HAL status
mbed_official 235:685d5f11838f 1243 */
mbed_official 532:fe11edbda85c 1244 HAL_StatusTypeDef I2S_Transmit_IT(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 1245 {
mbed_official 235:685d5f11838f 1246 if(hi2s->State == HAL_I2S_STATE_BUSY_TX)
mbed_official 235:685d5f11838f 1247 {
mbed_official 235:685d5f11838f 1248 /* Process Locked */
mbed_official 235:685d5f11838f 1249 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 1250
mbed_official 235:685d5f11838f 1251 /* Transmit data */
mbed_official 235:685d5f11838f 1252 hi2s->Instance->DR = (*hi2s->pTxBuffPtr++);
mbed_official 235:685d5f11838f 1253
mbed_official 235:685d5f11838f 1254 hi2s->TxXferCount--;
mbed_official 235:685d5f11838f 1255
mbed_official 235:685d5f11838f 1256 if(hi2s->TxXferCount == 0)
mbed_official 235:685d5f11838f 1257 {
mbed_official 235:685d5f11838f 1258 /* Disable TXE and ERR interrupt */
mbed_official 235:685d5f11838f 1259 __HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_ERR));
mbed_official 235:685d5f11838f 1260
mbed_official 235:685d5f11838f 1261 hi2s->State = HAL_I2S_STATE_READY;
mbed_official 235:685d5f11838f 1262
mbed_official 235:685d5f11838f 1263 /* Process Unlocked */
mbed_official 235:685d5f11838f 1264 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 1265 HAL_I2S_TxCpltCallback(hi2s);
mbed_official 235:685d5f11838f 1266 }
mbed_official 235:685d5f11838f 1267 else
mbed_official 235:685d5f11838f 1268 {
mbed_official 235:685d5f11838f 1269 /* Process Unlocked */
mbed_official 235:685d5f11838f 1270 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 1271 }
mbed_official 235:685d5f11838f 1272
mbed_official 235:685d5f11838f 1273 return HAL_OK;
mbed_official 235:685d5f11838f 1274 }
mbed_official 235:685d5f11838f 1275
mbed_official 235:685d5f11838f 1276 else
mbed_official 235:685d5f11838f 1277 {
mbed_official 235:685d5f11838f 1278 return HAL_BUSY;
mbed_official 235:685d5f11838f 1279 }
mbed_official 235:685d5f11838f 1280 }
mbed_official 235:685d5f11838f 1281
mbed_official 235:685d5f11838f 1282 /**
mbed_official 235:685d5f11838f 1283 * @brief Receive an amount of data in non-blocking mode with Interrupt
mbed_official 235:685d5f11838f 1284 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1285 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1286 * @retval HAL status
mbed_official 235:685d5f11838f 1287 */
mbed_official 532:fe11edbda85c 1288 HAL_StatusTypeDef I2S_Receive_IT(I2S_HandleTypeDef *hi2s)
mbed_official 235:685d5f11838f 1289 {
mbed_official 235:685d5f11838f 1290 if(hi2s->State == HAL_I2S_STATE_BUSY_RX)
mbed_official 235:685d5f11838f 1291 {
mbed_official 235:685d5f11838f 1292 /* Process Locked */
mbed_official 235:685d5f11838f 1293 __HAL_LOCK(hi2s);
mbed_official 235:685d5f11838f 1294
mbed_official 235:685d5f11838f 1295 /* Receive data */
mbed_official 235:685d5f11838f 1296 (*hi2s->pRxBuffPtr++) = hi2s->Instance->DR;
mbed_official 235:685d5f11838f 1297
mbed_official 235:685d5f11838f 1298 hi2s->RxXferCount--;
mbed_official 235:685d5f11838f 1299
mbed_official 235:685d5f11838f 1300 /* Check if Master Receiver mode is selected */
mbed_official 235:685d5f11838f 1301 if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX)
mbed_official 235:685d5f11838f 1302 {
mbed_official 235:685d5f11838f 1303 /* Clear the Overrun Flag by a read operation on the SPI_DR register followed by a read
mbed_official 235:685d5f11838f 1304 access to the SPI_SR register. */
mbed_official 235:685d5f11838f 1305 __HAL_I2S_CLEAR_OVRFLAG(hi2s);
mbed_official 235:685d5f11838f 1306 }
mbed_official 235:685d5f11838f 1307
mbed_official 235:685d5f11838f 1308 if(hi2s->RxXferCount == 0)
mbed_official 235:685d5f11838f 1309 {
mbed_official 235:685d5f11838f 1310 /* Disable RXNE and ERR interrupt */
mbed_official 235:685d5f11838f 1311 __HAL_I2S_DISABLE_IT(hi2s, I2S_IT_RXNE | I2S_IT_ERR);
mbed_official 235:685d5f11838f 1312
mbed_official 235:685d5f11838f 1313 hi2s->State = HAL_I2S_STATE_READY;
mbed_official 235:685d5f11838f 1314
mbed_official 235:685d5f11838f 1315 /* Process Unlocked */
mbed_official 235:685d5f11838f 1316 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 1317
mbed_official 235:685d5f11838f 1318 HAL_I2S_RxCpltCallback(hi2s);
mbed_official 235:685d5f11838f 1319 }
mbed_official 235:685d5f11838f 1320 else
mbed_official 235:685d5f11838f 1321 {
mbed_official 235:685d5f11838f 1322 /* Process Unlocked */
mbed_official 235:685d5f11838f 1323 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 1324 }
mbed_official 235:685d5f11838f 1325
mbed_official 235:685d5f11838f 1326 return HAL_OK;
mbed_official 235:685d5f11838f 1327 }
mbed_official 235:685d5f11838f 1328 else
mbed_official 235:685d5f11838f 1329 {
mbed_official 235:685d5f11838f 1330 return HAL_BUSY;
mbed_official 235:685d5f11838f 1331 }
mbed_official 235:685d5f11838f 1332 }
mbed_official 235:685d5f11838f 1333
mbed_official 235:685d5f11838f 1334 /**
mbed_official 235:685d5f11838f 1335 * @brief This function handles I2S Communication Timeout.
mbed_official 235:685d5f11838f 1336 * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
mbed_official 235:685d5f11838f 1337 * the configuration information for I2S module
mbed_official 235:685d5f11838f 1338 * @param Flag: Flag checked
mbed_official 532:fe11edbda85c 1339 * @param Status: Value of the flag expected
mbed_official 235:685d5f11838f 1340 * @param Timeout: Duration of the timeout
mbed_official 235:685d5f11838f 1341 * @retval HAL status
mbed_official 235:685d5f11838f 1342 */
mbed_official 235:685d5f11838f 1343 HAL_StatusTypeDef I2S_WaitFlagStateUntilTimeout(I2S_HandleTypeDef *hi2s, uint32_t Flag, uint32_t Status, uint32_t Timeout)
mbed_official 235:685d5f11838f 1344 {
mbed_official 235:685d5f11838f 1345 uint32_t tickstart = 0;
mbed_official 235:685d5f11838f 1346
mbed_official 235:685d5f11838f 1347 /* Get tick */
mbed_official 235:685d5f11838f 1348 tickstart = HAL_GetTick();
mbed_official 235:685d5f11838f 1349
mbed_official 235:685d5f11838f 1350 /* Wait until flag is set */
mbed_official 235:685d5f11838f 1351 if(Status == RESET)
mbed_official 235:685d5f11838f 1352 {
mbed_official 235:685d5f11838f 1353 while(__HAL_I2S_GET_FLAG(hi2s, Flag) == RESET)
mbed_official 235:685d5f11838f 1354 {
mbed_official 235:685d5f11838f 1355 if(Timeout != HAL_MAX_DELAY)
mbed_official 235:685d5f11838f 1356 {
mbed_official 235:685d5f11838f 1357 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 235:685d5f11838f 1358 {
mbed_official 235:685d5f11838f 1359 /* Set the I2S State ready */
mbed_official 235:685d5f11838f 1360 hi2s->State= HAL_I2S_STATE_READY;
mbed_official 235:685d5f11838f 1361
mbed_official 235:685d5f11838f 1362 /* Process Unlocked */
mbed_official 235:685d5f11838f 1363 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 1364
mbed_official 235:685d5f11838f 1365 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1366 }
mbed_official 235:685d5f11838f 1367 }
mbed_official 235:685d5f11838f 1368 }
mbed_official 235:685d5f11838f 1369 }
mbed_official 235:685d5f11838f 1370 else
mbed_official 235:685d5f11838f 1371 {
mbed_official 235:685d5f11838f 1372 while(__HAL_I2S_GET_FLAG(hi2s, Flag) != RESET)
mbed_official 235:685d5f11838f 1373 {
mbed_official 235:685d5f11838f 1374 if(Timeout != HAL_MAX_DELAY)
mbed_official 235:685d5f11838f 1375 {
mbed_official 235:685d5f11838f 1376 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
mbed_official 235:685d5f11838f 1377 {
mbed_official 235:685d5f11838f 1378 /* Set the I2S State ready */
mbed_official 235:685d5f11838f 1379 hi2s->State= HAL_I2S_STATE_READY;
mbed_official 235:685d5f11838f 1380
mbed_official 235:685d5f11838f 1381 /* Process Unlocked */
mbed_official 235:685d5f11838f 1382 __HAL_UNLOCK(hi2s);
mbed_official 235:685d5f11838f 1383
mbed_official 235:685d5f11838f 1384 return HAL_TIMEOUT;
mbed_official 235:685d5f11838f 1385 }
mbed_official 235:685d5f11838f 1386 }
mbed_official 235:685d5f11838f 1387 }
mbed_official 235:685d5f11838f 1388 }
mbed_official 235:685d5f11838f 1389 return HAL_OK;
mbed_official 235:685d5f11838f 1390 }
mbed_official 235:685d5f11838f 1391
mbed_official 235:685d5f11838f 1392 /**
mbed_official 235:685d5f11838f 1393 * @}
mbed_official 235:685d5f11838f 1394 */
mbed_official 235:685d5f11838f 1395
mbed_official 235:685d5f11838f 1396 #endif /* HAL_I2S_MODULE_ENABLED */
mbed_official 235:685d5f11838f 1397 /**
mbed_official 235:685d5f11838f 1398 * @}
mbed_official 235:685d5f11838f 1399 */
mbed_official 235:685d5f11838f 1400
mbed_official 235:685d5f11838f 1401 /**
mbed_official 235:685d5f11838f 1402 * @}
mbed_official 235:685d5f11838f 1403 */
mbed_official 235:685d5f11838f 1404
mbed_official 235:685d5f11838f 1405 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/