annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_i2s.c @ 45:219943ef9dc0

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