mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed Sep 30 17:00:09 2015 +0100
Revision:
636:a11c0372f0ba
Parent:
631:825f75ca301e
Synchronized with git revision d29c98dae61be0946ddf3a3c641c7726056f9452

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

Added support for SAMW25

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 340:28d1f895c6fe 1 /**
mbed_official 340:28d1f895c6fe 2 ******************************************************************************
mbed_official 340:28d1f895c6fe 3 * @file stm32f0xx_hal_irda.c
mbed_official 340:28d1f895c6fe 4 * @author MCD Application Team
mbed_official 631:825f75ca301e 5 * @version V1.3.0
mbed_official 631:825f75ca301e 6 * @date 26-June-2015
mbed_official 340:28d1f895c6fe 7 * @brief IRDA HAL module driver.
mbed_official 631:825f75ca301e 8 * This file provides firmware functions to manage the following
mbed_official 631:825f75ca301e 9 * functionalities of the IrDA (Infrared Data Association) Peripheral
mbed_official 340:28d1f895c6fe 10 * (IRDA)
mbed_official 631:825f75ca301e 11 * + Initialization and de-initialization functions
mbed_official 631:825f75ca301e 12 * + IO operation functions
mbed_official 631:825f75ca301e 13 * + Peripheral State and Errors functions
mbed_official 631:825f75ca301e 14 * + Peripheral Control functions
mbed_official 340:28d1f895c6fe 15 *
mbed_official 631:825f75ca301e 16 @verbatim
mbed_official 631:825f75ca301e 17 ==============================================================================
mbed_official 340:28d1f895c6fe 18 ##### How to use this driver #####
mbed_official 631:825f75ca301e 19 ==============================================================================
mbed_official 631:825f75ca301e 20 [..]
mbed_official 340:28d1f895c6fe 21 The IRDA HAL driver can be used as follows:
mbed_official 631:825f75ca301e 22
mbed_official 631:825f75ca301e 23 (#) Declare a IRDA_HandleTypeDef handle structure (eg. IRDA_HandleTypeDef hirda).
mbed_official 631:825f75ca301e 24 (#) Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API
mbed_official 631:825f75ca301e 25 in setting the associated USART or UART in IRDA mode:
mbed_official 631:825f75ca301e 26 (++) Enable the USARTx/UARTx interface clock.
mbed_official 631:825f75ca301e 27 (++) USARTx/UARTx pins configuration:
mbed_official 631:825f75ca301e 28 (+++) Enable the clock for the USARTx/UARTx GPIOs.
mbed_official 631:825f75ca301e 29 (+++) Configure these USARTx/UARTx pins (TX as alternate function pull-up, RX as alternate function Input).
mbed_official 631:825f75ca301e 30 (++) NVIC configuration if you need to use interrupt process (HAL_IRDA_Transmit_IT()
mbed_official 631:825f75ca301e 31 and HAL_IRDA_Receive_IT() APIs):
mbed_official 631:825f75ca301e 32 (+++) Configure the USARTx/UARTx interrupt priority.
mbed_official 631:825f75ca301e 33 (+++) Enable the NVIC USARTx/UARTx IRQ handle.
mbed_official 631:825f75ca301e 34 (+++) The specific IRDA interrupts (Transmission complete interrupt,
mbed_official 631:825f75ca301e 35 RXNE interrupt and Error Interrupts) will be managed using the macros
mbed_official 631:825f75ca301e 36 __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.
mbed_official 631:825f75ca301e 37
mbed_official 631:825f75ca301e 38 (++) DMA Configuration if you need to use DMA process (HAL_IRDA_Transmit_DMA()
mbed_official 340:28d1f895c6fe 39 and HAL_IRDA_Receive_DMA() APIs):
mbed_official 340:28d1f895c6fe 40 (+++) Declare a DMA handle structure for the Tx/Rx channel.
mbed_official 340:28d1f895c6fe 41 (+++) Enable the DMAx interface clock.
mbed_official 631:825f75ca301e 42 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
mbed_official 340:28d1f895c6fe 43 (+++) Configure the DMA Tx/Rx channel.
mbed_official 631:825f75ca301e 44 (+++) Associate the initialized DMA handle to the IRDA DMA Tx/Rx handle.
mbed_official 340:28d1f895c6fe 45 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel.
mbed_official 340:28d1f895c6fe 46
mbed_official 340:28d1f895c6fe 47 (#) Program the Baud Rate, Word Length and Parity and Mode(Receiver/Transmitter),
mbed_official 631:825f75ca301e 48 the normal or low power mode and the clock prescaler in the hirda handle Init structure.
mbed_official 340:28d1f895c6fe 49
mbed_official 340:28d1f895c6fe 50 (#) Initialize the IRDA registers by calling the HAL_IRDA_Init() API:
mbed_official 631:825f75ca301e 51 (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
mbed_official 631:825f75ca301e 52 by calling the customized HAL_IRDA_MspInit() API.
mbed_official 631:825f75ca301e 53
mbed_official 631:825f75ca301e 54 -@@- The specific IRDA interrupts (Transmission complete interrupt,
mbed_official 340:28d1f895c6fe 55 RXNE interrupt and Error Interrupts) will be managed using the macros
mbed_official 340:28d1f895c6fe 56 __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process.
mbed_official 340:28d1f895c6fe 57
mbed_official 340:28d1f895c6fe 58 (#) Three operation modes are available within this driver :
mbed_official 631:825f75ca301e 59
mbed_official 340:28d1f895c6fe 60 *** Polling mode IO operation ***
mbed_official 340:28d1f895c6fe 61 =================================
mbed_official 631:825f75ca301e 62 [..]
mbed_official 631:825f75ca301e 63 (+) Send an amount of data in blocking mode using HAL_IRDA_Transmit()
mbed_official 340:28d1f895c6fe 64 (+) Receive an amount of data in blocking mode using HAL_IRDA_Receive()
mbed_official 631:825f75ca301e 65
mbed_official 631:825f75ca301e 66 *** Interrupt mode IO operation ***
mbed_official 340:28d1f895c6fe 67 ===================================
mbed_official 631:825f75ca301e 68 [..]
mbed_official 631:825f75ca301e 69 (+) Send an amount of data in non-blocking mode using HAL_IRDA_Transmit_IT()
mbed_official 631:825f75ca301e 70 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback() is executed and user can
mbed_official 631:825f75ca301e 71 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback()
mbed_official 631:825f75ca301e 72 (+) Receive an amount of data in non-blocking mode using HAL_IRDA_Receive_IT()
mbed_official 631:825f75ca301e 73 (+) At reception end of transfer HAL_IRDA_RxCpltCallback() is executed and user can
mbed_official 631:825f75ca301e 74 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback()
mbed_official 631:825f75ca301e 75 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
mbed_official 631:825f75ca301e 76 add his own code by customization of function pointer HAL_IRDA_ErrorCallback()
mbed_official 340:28d1f895c6fe 77
mbed_official 631:825f75ca301e 78 *** DMA mode IO operation ***
mbed_official 340:28d1f895c6fe 79 ==============================
mbed_official 631:825f75ca301e 80 [..]
mbed_official 631:825f75ca301e 81 (+) Send an amount of data in non-blocking mode (DMA) using HAL_IRDA_Transmit_DMA()
mbed_official 631:825f75ca301e 82 (+) At transmission half of transfer HAL_IRDA_TxHalfCpltCallback() is executed and user can
mbed_official 631:825f75ca301e 83 add his own code by customization of function pointer HAL_IRDA_TxHalfCpltCallback()
mbed_official 631:825f75ca301e 84 (+) At transmission end of transfer HAL_IRDA_TxCpltCallback() is executed and user can
mbed_official 631:825f75ca301e 85 add his own code by customization of function pointer HAL_IRDA_TxCpltCallback()
mbed_official 631:825f75ca301e 86 (+) Receive an amount of data in non-blocking mode (DMA) using HAL_IRDA_Receive_DMA()
mbed_official 631:825f75ca301e 87 (+) At reception half of transfer HAL_IRDA_RxHalfCpltCallback() is executed and user can
mbed_official 631:825f75ca301e 88 add his own code by customization of function pointer HAL_IRDA_RxHalfCpltCallback()
mbed_official 631:825f75ca301e 89 (+) At reception end of transfer HAL_IRDA_RxCpltCallback() is executed and user can
mbed_official 631:825f75ca301e 90 add his own code by customization of function pointer HAL_IRDA_RxCpltCallback()
mbed_official 631:825f75ca301e 91 (+) In case of transfer Error, HAL_IRDA_ErrorCallback() function is executed and user can
mbed_official 631:825f75ca301e 92 add his own code by customization of function pointer HAL_IRDA_ErrorCallback()
mbed_official 340:28d1f895c6fe 93
mbed_official 340:28d1f895c6fe 94 *** IRDA HAL driver macros list ***
mbed_official 340:28d1f895c6fe 95 ====================================
mbed_official 340:28d1f895c6fe 96 [..]
mbed_official 340:28d1f895c6fe 97 Below the list of most used macros in IRDA HAL driver.
mbed_official 631:825f75ca301e 98
mbed_official 631:825f75ca301e 99 (+) __HAL_IRDA_ENABLE: Enable the IRDA peripheral
mbed_official 631:825f75ca301e 100 (+) __HAL_IRDA_DISABLE: Disable the IRDA peripheral
mbed_official 340:28d1f895c6fe 101 (+) __HAL_IRDA_GET_FLAG : Check whether the specified IRDA flag is set or not
mbed_official 340:28d1f895c6fe 102 (+) __HAL_IRDA_CLEAR_FLAG : Clear the specified IRDA pending flag
mbed_official 340:28d1f895c6fe 103 (+) __HAL_IRDA_ENABLE_IT: Enable the specified IRDA interrupt
mbed_official 340:28d1f895c6fe 104 (+) __HAL_IRDA_DISABLE_IT: Disable the specified IRDA interrupt
mbed_official 631:825f75ca301e 105 (+) __HAL_IRDA_GET_IT_SOURCE: Check whether or not the specified IRDA interrupt is enabled
mbed_official 631:825f75ca301e 106
mbed_official 631:825f75ca301e 107 [..]
mbed_official 340:28d1f895c6fe 108 (@) You can refer to the IRDA HAL driver header file for more useful macros
mbed_official 340:28d1f895c6fe 109
mbed_official 340:28d1f895c6fe 110 @endverbatim
mbed_official 340:28d1f895c6fe 111 ******************************************************************************
mbed_official 340:28d1f895c6fe 112 * @attention
mbed_official 340:28d1f895c6fe 113 *
mbed_official 631:825f75ca301e 114 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 340:28d1f895c6fe 115 *
mbed_official 340:28d1f895c6fe 116 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 340:28d1f895c6fe 117 * are permitted provided that the following conditions are met:
mbed_official 340:28d1f895c6fe 118 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 340:28d1f895c6fe 119 * this list of conditions and the following disclaimer.
mbed_official 340:28d1f895c6fe 120 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 340:28d1f895c6fe 121 * this list of conditions and the following disclaimer in the documentation
mbed_official 340:28d1f895c6fe 122 * and/or other materials provided with the distribution.
mbed_official 340:28d1f895c6fe 123 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 340:28d1f895c6fe 124 * may be used to endorse or promote products derived from this software
mbed_official 340:28d1f895c6fe 125 * without specific prior written permission.
mbed_official 340:28d1f895c6fe 126 *
mbed_official 340:28d1f895c6fe 127 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 340:28d1f895c6fe 128 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 340:28d1f895c6fe 129 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 340:28d1f895c6fe 130 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 340:28d1f895c6fe 131 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 340:28d1f895c6fe 132 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 340:28d1f895c6fe 133 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 340:28d1f895c6fe 134 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 340:28d1f895c6fe 135 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 340:28d1f895c6fe 136 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 340:28d1f895c6fe 137 *
mbed_official 631:825f75ca301e 138 ******************************************************************************
mbed_official 340:28d1f895c6fe 139 */
mbed_official 340:28d1f895c6fe 140
mbed_official 340:28d1f895c6fe 141 /* Includes ------------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 142 #include "stm32f0xx_hal.h"
mbed_official 340:28d1f895c6fe 143
mbed_official 442:d2c15dda23c1 144 #ifdef HAL_IRDA_MODULE_ENABLED
mbed_official 442:d2c15dda23c1 145
mbed_official 631:825f75ca301e 146 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
mbed_official 442:d2c15dda23c1 147
mbed_official 340:28d1f895c6fe 148 /** @addtogroup STM32F0xx_HAL_Driver
mbed_official 340:28d1f895c6fe 149 * @{
mbed_official 340:28d1f895c6fe 150 */
mbed_official 340:28d1f895c6fe 151
mbed_official 631:825f75ca301e 152 /** @defgroup IRDA IRDA
mbed_official 340:28d1f895c6fe 153 * @brief HAL IRDA module driver
mbed_official 340:28d1f895c6fe 154 * @{
mbed_official 340:28d1f895c6fe 155 */
mbed_official 340:28d1f895c6fe 156
mbed_official 340:28d1f895c6fe 157 /* Private typedef -----------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 158 /* Private define ------------------------------------------------------------*/
mbed_official 631:825f75ca301e 159 /** @defgroup IRDA_Private_Constants IRDA Private Constants
mbed_official 340:28d1f895c6fe 160 * @{
mbed_official 340:28d1f895c6fe 161 */
mbed_official 631:825f75ca301e 162 #define IRDA_TEACK_REACK_TIMEOUT 1000 /*!< IRDA TX or RX enable acknowledge time-out value */
mbed_official 340:28d1f895c6fe 163 #define IRDA_TXDMA_TIMEOUTVALUE 22000
mbed_official 340:28d1f895c6fe 164 #define IRDA_TIMEOUT_VALUE 22000
mbed_official 340:28d1f895c6fe 165 #define IRDA_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE \
mbed_official 631:825f75ca301e 166 | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE)) /*!< UART or USART CR1 fields of parameters set by IRDA_SetConfig API */
mbed_official 340:28d1f895c6fe 167 /**
mbed_official 340:28d1f895c6fe 168 * @}
mbed_official 340:28d1f895c6fe 169 */
mbed_official 340:28d1f895c6fe 170
mbed_official 631:825f75ca301e 171 /* Private macros ------------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 172 /* Private variables ---------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 173 /* Private function prototypes -----------------------------------------------*/
mbed_official 631:825f75ca301e 174 /** @addtogroup IRDA_Private_Functions IRDA Private Functions
mbed_official 340:28d1f895c6fe 175 * @{
mbed_official 340:28d1f895c6fe 176 */
mbed_official 340:28d1f895c6fe 177 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda);
mbed_official 340:28d1f895c6fe 178 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda);
mbed_official 340:28d1f895c6fe 179 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda);
mbed_official 631:825f75ca301e 180 static HAL_StatusTypeDef IRDA_SetConfig(IRDA_HandleTypeDef *hirda);
mbed_official 631:825f75ca301e 181 static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda);
mbed_official 631:825f75ca301e 182 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma);
mbed_official 631:825f75ca301e 183 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma);
mbed_official 631:825f75ca301e 184 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
mbed_official 631:825f75ca301e 185 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma);
mbed_official 631:825f75ca301e 186 static void IRDA_DMAError(DMA_HandleTypeDef *hdma);
mbed_official 631:825f75ca301e 187 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
mbed_official 340:28d1f895c6fe 188 /**
mbed_official 340:28d1f895c6fe 189 * @}
mbed_official 340:28d1f895c6fe 190 */
mbed_official 631:825f75ca301e 191
mbed_official 631:825f75ca301e 192 /* Exported functions --------------------------------------------------------*/
mbed_official 340:28d1f895c6fe 193
mbed_official 340:28d1f895c6fe 194 /** @defgroup IRDA_Exported_Functions IRDA Exported Functions
mbed_official 340:28d1f895c6fe 195 * @{
mbed_official 340:28d1f895c6fe 196 */
mbed_official 340:28d1f895c6fe 197
mbed_official 631:825f75ca301e 198 /** @defgroup IRDA_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 631:825f75ca301e 199 * @brief Initialization and Configuration functions
mbed_official 340:28d1f895c6fe 200 *
mbed_official 631:825f75ca301e 201 @verbatim
mbed_official 340:28d1f895c6fe 202 ==============================================================================
mbed_official 631:825f75ca301e 203 ##### Initialization and Configuration functions #####
mbed_official 340:28d1f895c6fe 204 ==============================================================================
mbed_official 631:825f75ca301e 205 [..]
mbed_official 631:825f75ca301e 206 This subsection provides a set of functions allowing to initialize the USARTx
mbed_official 631:825f75ca301e 207 in asynchronous IRDA mode.
mbed_official 631:825f75ca301e 208 (+) For the asynchronous mode only these parameters can be configured:
mbed_official 631:825f75ca301e 209 (++) Baud Rate
mbed_official 631:825f75ca301e 210 (++) Word Length
mbed_official 631:825f75ca301e 211 (++) Parity: If the parity is enabled, then the MSB bit of the data written
mbed_official 631:825f75ca301e 212 in the data register is transmitted but is changed by the parity bit.
mbed_official 631:825f75ca301e 213 According to device capability (support or not of 7-bit word length),
mbed_official 631:825f75ca301e 214 frame length is either defined by the M bit (8-bits or 9-bits)
mbed_official 631:825f75ca301e 215 or by the M1 and M0 bits (7-bit, 8-bit or 9-bit).
mbed_official 631:825f75ca301e 216 Possible IRDA frame formats are as listed in the following table:
mbed_official 631:825f75ca301e 217
mbed_official 631:825f75ca301e 218 (+++) Table 1. IRDA frame format.
mbed_official 631:825f75ca301e 219 (+++) +-----------------------------------------------------------------------+
mbed_official 631:825f75ca301e 220 (+++) | M bit | PCE bit | IRDA frame |
mbed_official 631:825f75ca301e 221 (+++) |-------------------|-----------|---------------------------------------|
mbed_official 631:825f75ca301e 222 (+++) | 0 | 0 | | SB | 8-bit data | STB | |
mbed_official 631:825f75ca301e 223 (+++) |-------------------|-----------|---------------------------------------|
mbed_official 631:825f75ca301e 224 (+++) | 0 | 1 | | SB | 7-bit data | PB | STB | |
mbed_official 631:825f75ca301e 225 (+++) |-------------------|-----------|---------------------------------------|
mbed_official 631:825f75ca301e 226 (+++) | 1 | 0 | | SB | 9-bit data | STB | |
mbed_official 631:825f75ca301e 227 (+++) |-------------------|-----------|---------------------------------------|
mbed_official 631:825f75ca301e 228 (+++) | 1 | 1 | | SB | 8-bit data | PB | STB | |
mbed_official 631:825f75ca301e 229 (+++) +-----------------------------------------------------------------------+
mbed_official 631:825f75ca301e 230 (+++) | M1 bit | M0 bit | PCE bit | IRDA frame |
mbed_official 631:825f75ca301e 231 (+++) |---------|---------|-----------|---------------------------------------|
mbed_official 631:825f75ca301e 232 (+++) | 0 | 0 | 0 | | SB | 8 bit data | STB | |
mbed_official 631:825f75ca301e 233 (+++) |---------|---------|-----------|---------------------------------------|
mbed_official 631:825f75ca301e 234 (+++) | 0 | 0 | 1 | | SB | 7 bit data | PB | STB | |
mbed_official 631:825f75ca301e 235 (+++) |---------|---------|-----------|---------------------------------------|
mbed_official 631:825f75ca301e 236 (+++) | 0 | 1 | 0 | | SB | 9 bit data | STB | |
mbed_official 631:825f75ca301e 237 (+++) |---------|---------|-----------|---------------------------------------|
mbed_official 631:825f75ca301e 238 (+++) | 0 | 1 | 1 | | SB | 8 bit data | PB | STB | |
mbed_official 631:825f75ca301e 239 (+++) |---------|---------|-----------|---------------------------------------|
mbed_official 631:825f75ca301e 240 (+++) | 1 | 0 | 0 | | SB | 7 bit data | STB | |
mbed_official 631:825f75ca301e 241 (+++) |---------|---------|-----------|---------------------------------------|
mbed_official 631:825f75ca301e 242 (+++) | 1 | 0 | 1 | | SB | 6 bit data | PB | STB | |
mbed_official 631:825f75ca301e 243 (+++) +-----------------------------------------------------------------------+
mbed_official 631:825f75ca301e 244
mbed_official 340:28d1f895c6fe 245 (++) Power mode
mbed_official 631:825f75ca301e 246 (++) Prescaler setting
mbed_official 340:28d1f895c6fe 247 (++) Receiver/transmitter modes
mbed_official 340:28d1f895c6fe 248
mbed_official 631:825f75ca301e 249 [..]
mbed_official 631:825f75ca301e 250 The HAL_IRDA_Init() API follows the USART asynchronous configuration procedures
mbed_official 631:825f75ca301e 251 (details for the procedures are available in reference manual).
mbed_official 340:28d1f895c6fe 252
mbed_official 340:28d1f895c6fe 253 @endverbatim
mbed_official 340:28d1f895c6fe 254 * @{
mbed_official 340:28d1f895c6fe 255 */
mbed_official 340:28d1f895c6fe 256
mbed_official 340:28d1f895c6fe 257 /**
mbed_official 631:825f75ca301e 258 * @brief Initialize the IRDA mode according to the specified
mbed_official 631:825f75ca301e 259 * parameters in the IRDA_InitTypeDef and initialize the associated handle.
mbed_official 631:825f75ca301e 260 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 261 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 262 * @retval HAL status
mbed_official 340:28d1f895c6fe 263 */
mbed_official 340:28d1f895c6fe 264 HAL_StatusTypeDef HAL_IRDA_Init(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 265 {
mbed_official 340:28d1f895c6fe 266 /* Check the IRDA handle allocation */
mbed_official 442:d2c15dda23c1 267 if(hirda == NULL)
mbed_official 340:28d1f895c6fe 268 {
mbed_official 340:28d1f895c6fe 269 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 270 }
mbed_official 631:825f75ca301e 271
mbed_official 340:28d1f895c6fe 272 /* Check the USART/UART associated to the IRDA handle */
mbed_official 340:28d1f895c6fe 273 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
mbed_official 631:825f75ca301e 274
mbed_official 340:28d1f895c6fe 275 if(hirda->State == HAL_IRDA_STATE_RESET)
mbed_official 631:825f75ca301e 276 {
mbed_official 631:825f75ca301e 277 /* Allocate lock resource and initialize it */
mbed_official 631:825f75ca301e 278 hirda->Lock = HAL_UNLOCKED;
mbed_official 631:825f75ca301e 279
mbed_official 340:28d1f895c6fe 280 /* Init the low level hardware : GPIO, CLOCK */
mbed_official 340:28d1f895c6fe 281 HAL_IRDA_MspInit(hirda);
mbed_official 340:28d1f895c6fe 282 }
mbed_official 631:825f75ca301e 283
mbed_official 340:28d1f895c6fe 284 hirda->State = HAL_IRDA_STATE_BUSY;
mbed_official 631:825f75ca301e 285
mbed_official 340:28d1f895c6fe 286 /* Disable the Peripheral to update the configuration registers */
mbed_official 340:28d1f895c6fe 287 __HAL_IRDA_DISABLE(hirda);
mbed_official 631:825f75ca301e 288
mbed_official 340:28d1f895c6fe 289 /* Set the IRDA Communication parameters */
mbed_official 340:28d1f895c6fe 290 if (IRDA_SetConfig(hirda) == HAL_ERROR)
mbed_official 340:28d1f895c6fe 291 {
mbed_official 340:28d1f895c6fe 292 return HAL_ERROR;
mbed_official 631:825f75ca301e 293 }
mbed_official 631:825f75ca301e 294
mbed_official 631:825f75ca301e 295 /* In IRDA mode, the following bits must be kept cleared:
mbed_official 340:28d1f895c6fe 296 - LINEN, STOP and CLKEN bits in the USART_CR2 register,
mbed_official 340:28d1f895c6fe 297 - SCEN and HDSEL bits in the USART_CR3 register.*/
mbed_official 631:825f75ca301e 298 hirda->Instance->CR2 &= ~(USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP);
mbed_official 631:825f75ca301e 299 hirda->Instance->CR3 &= ~(USART_CR3_SCEN | USART_CR3_HDSEL);
mbed_official 631:825f75ca301e 300
mbed_official 340:28d1f895c6fe 301 /* set the UART/USART in IRDA mode */
mbed_official 631:825f75ca301e 302 hirda->Instance->CR3 |= USART_CR3_IREN;
mbed_official 631:825f75ca301e 303
mbed_official 340:28d1f895c6fe 304 /* Enable the Peripheral */
mbed_official 340:28d1f895c6fe 305 __HAL_IRDA_ENABLE(hirda);
mbed_official 631:825f75ca301e 306
mbed_official 340:28d1f895c6fe 307 /* TEACK and/or REACK to check before moving hirda->State to Ready */
mbed_official 340:28d1f895c6fe 308 return (IRDA_CheckIdleState(hirda));
mbed_official 340:28d1f895c6fe 309 }
mbed_official 340:28d1f895c6fe 310
mbed_official 340:28d1f895c6fe 311 /**
mbed_official 631:825f75ca301e 312 * @brief DeInitialize the IRDA peripheral.
mbed_official 631:825f75ca301e 313 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 314 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 315 * @retval HAL status
mbed_official 340:28d1f895c6fe 316 */
mbed_official 340:28d1f895c6fe 317 HAL_StatusTypeDef HAL_IRDA_DeInit(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 318 {
mbed_official 340:28d1f895c6fe 319 /* Check the IRDA handle allocation */
mbed_official 442:d2c15dda23c1 320 if(hirda == NULL)
mbed_official 340:28d1f895c6fe 321 {
mbed_official 340:28d1f895c6fe 322 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 323 }
mbed_official 631:825f75ca301e 324
mbed_official 340:28d1f895c6fe 325 /* Check the USART/UART associated to the IRDA handle */
mbed_official 340:28d1f895c6fe 326 assert_param(IS_IRDA_INSTANCE(hirda->Instance));
mbed_official 340:28d1f895c6fe 327
mbed_official 340:28d1f895c6fe 328 hirda->State = HAL_IRDA_STATE_BUSY;
mbed_official 631:825f75ca301e 329
mbed_official 340:28d1f895c6fe 330 /* DeInit the low level hardware */
mbed_official 340:28d1f895c6fe 331 HAL_IRDA_MspDeInit(hirda);
mbed_official 340:28d1f895c6fe 332 /* Disable the Peripheral */
mbed_official 340:28d1f895c6fe 333 __HAL_IRDA_DISABLE(hirda);
mbed_official 631:825f75ca301e 334
mbed_official 340:28d1f895c6fe 335 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 340:28d1f895c6fe 336 hirda->State = HAL_IRDA_STATE_RESET;
mbed_official 631:825f75ca301e 337
mbed_official 340:28d1f895c6fe 338 /* Process Unlock */
mbed_official 340:28d1f895c6fe 339 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 340
mbed_official 340:28d1f895c6fe 341 return HAL_OK;
mbed_official 340:28d1f895c6fe 342 }
mbed_official 340:28d1f895c6fe 343
mbed_official 340:28d1f895c6fe 344 /**
mbed_official 631:825f75ca301e 345 * @brief Initialize the IRDA MSP.
mbed_official 631:825f75ca301e 346 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 347 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 348 * @retval None
mbed_official 340:28d1f895c6fe 349 */
mbed_official 340:28d1f895c6fe 350 __weak void HAL_IRDA_MspInit(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 351 {
mbed_official 631:825f75ca301e 352 /* NOTE: This function should not be modified, when the callback is needed,
mbed_official 631:825f75ca301e 353 the HAL_IRDA_MspInit can be implemented in the user file
mbed_official 631:825f75ca301e 354 */
mbed_official 340:28d1f895c6fe 355 }
mbed_official 340:28d1f895c6fe 356
mbed_official 340:28d1f895c6fe 357 /**
mbed_official 631:825f75ca301e 358 * @brief DeInitialize the IRDA MSP.
mbed_official 631:825f75ca301e 359 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 360 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 361 * @retval None
mbed_official 340:28d1f895c6fe 362 */
mbed_official 340:28d1f895c6fe 363 __weak void HAL_IRDA_MspDeInit(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 364 {
mbed_official 631:825f75ca301e 365 /* NOTE: This function should not be modified, when the callback is needed,
mbed_official 631:825f75ca301e 366 the HAL_IRDA_MspDeInit can be implemented in the user file
mbed_official 631:825f75ca301e 367 */
mbed_official 340:28d1f895c6fe 368 }
mbed_official 340:28d1f895c6fe 369
mbed_official 340:28d1f895c6fe 370 /**
mbed_official 340:28d1f895c6fe 371 * @}
mbed_official 340:28d1f895c6fe 372 */
mbed_official 340:28d1f895c6fe 373
mbed_official 631:825f75ca301e 374 /** @defgroup IRDA_Exported_Functions_Group2 IO operation functions
mbed_official 631:825f75ca301e 375 * @brief IRDA Transmit and Receive functions
mbed_official 340:28d1f895c6fe 376 *
mbed_official 631:825f75ca301e 377 @verbatim
mbed_official 631:825f75ca301e 378 ==============================================================================
mbed_official 631:825f75ca301e 379 ##### IO operation functions #####
mbed_official 631:825f75ca301e 380 ==============================================================================
mbed_official 340:28d1f895c6fe 381 [..]
mbed_official 340:28d1f895c6fe 382 This subsection provides a set of functions allowing to manage the IRDA data transfers.
mbed_official 340:28d1f895c6fe 383
mbed_official 340:28d1f895c6fe 384 [..]
mbed_official 340:28d1f895c6fe 385 IrDA is a half duplex communication protocol. If the Transmitter is busy, any data
mbed_official 631:825f75ca301e 386 on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver
mbed_official 340:28d1f895c6fe 387 is busy, data on the TX from the USART to IrDA will not be encoded by IrDA.
mbed_official 340:28d1f895c6fe 388 While receiving data, transmission should be avoided as the data to be transmitted
mbed_official 340:28d1f895c6fe 389 could be corrupted.
mbed_official 340:28d1f895c6fe 390
mbed_official 340:28d1f895c6fe 391 (#) There are two modes of transfer:
mbed_official 631:825f75ca301e 392 (++) Blocking mode: the communication is performed in polling mode.
mbed_official 631:825f75ca301e 393 The HAL status of all data processing is returned by the same function
mbed_official 631:825f75ca301e 394 after finishing transfer.
mbed_official 631:825f75ca301e 395 (++) No-Blocking mode: the communication is performed using Interrupts
mbed_official 631:825f75ca301e 396 or DMA, these API's return the HAL status.
mbed_official 631:825f75ca301e 397 The end of the data processing will be indicated through the
mbed_official 631:825f75ca301e 398 dedicated IRDA IRQ when using Interrupt mode or the DMA IRQ when
mbed_official 631:825f75ca301e 399 using DMA mode.
mbed_official 631:825f75ca301e 400 The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks
mbed_official 631:825f75ca301e 401 will be executed respectively at the end of the Transmit or Receive process
mbed_official 631:825f75ca301e 402 The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected
mbed_official 340:28d1f895c6fe 403
mbed_official 631:825f75ca301e 404 (#) Blocking mode APIs are :
mbed_official 340:28d1f895c6fe 405 (++) HAL_IRDA_Transmit()
mbed_official 631:825f75ca301e 406 (++) HAL_IRDA_Receive()
mbed_official 631:825f75ca301e 407
mbed_official 631:825f75ca301e 408 (#) Non Blocking mode APIs with Interrupt are :
mbed_official 340:28d1f895c6fe 409 (++) HAL_IRDA_Transmit_IT()
mbed_official 340:28d1f895c6fe 410 (++) HAL_IRDA_Receive_IT()
mbed_official 340:28d1f895c6fe 411 (++) HAL_IRDA_IRQHandler()
mbed_official 340:28d1f895c6fe 412
mbed_official 340:28d1f895c6fe 413 (#) Non Blocking mode functions with DMA are :
mbed_official 340:28d1f895c6fe 414 (++) HAL_IRDA_Transmit_DMA()
mbed_official 340:28d1f895c6fe 415 (++) HAL_IRDA_Receive_DMA()
mbed_official 631:825f75ca301e 416 (++) HAL_IRDA_DMAPause()
mbed_official 631:825f75ca301e 417 (++) HAL_IRDA_DMAResume()
mbed_official 631:825f75ca301e 418 (++) HAL_IRDA_DMAStop()
mbed_official 340:28d1f895c6fe 419
mbed_official 340:28d1f895c6fe 420 (#) A set of Transfer Complete Callbacks are provided in Non Blocking mode:
mbed_official 631:825f75ca301e 421 (++) HAL_IRDA_TxHalfCpltCallback()
mbed_official 340:28d1f895c6fe 422 (++) HAL_IRDA_TxCpltCallback()
mbed_official 631:825f75ca301e 423 (++) HAL_IRDA_RxHalfCpltCallback()
mbed_official 340:28d1f895c6fe 424 (++) HAL_IRDA_RxCpltCallback()
mbed_official 340:28d1f895c6fe 425 (++) HAL_IRDA_ErrorCallback()
mbed_official 631:825f75ca301e 426
mbed_official 340:28d1f895c6fe 427 @endverbatim
mbed_official 340:28d1f895c6fe 428 * @{
mbed_official 340:28d1f895c6fe 429 */
mbed_official 340:28d1f895c6fe 430
mbed_official 340:28d1f895c6fe 431 /**
mbed_official 631:825f75ca301e 432 * @brief Send an amount of data in blocking mode.
mbed_official 631:825f75ca301e 433 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 434 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 435 * @param pData: Pointer to data buffer.
mbed_official 631:825f75ca301e 436 * @param Size: Amount of data to be sent.
mbed_official 631:825f75ca301e 437 * @param Timeout: Specify timeout value.
mbed_official 340:28d1f895c6fe 438 * @retval HAL status
mbed_official 340:28d1f895c6fe 439 */
mbed_official 340:28d1f895c6fe 440 HAL_StatusTypeDef HAL_IRDA_Transmit(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
mbed_official 340:28d1f895c6fe 441 {
mbed_official 631:825f75ca301e 442 uint16_t* tmp;
mbed_official 631:825f75ca301e 443
mbed_official 631:825f75ca301e 444 if((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
mbed_official 340:28d1f895c6fe 445 {
mbed_official 631:825f75ca301e 446 if((pData == NULL) || (Size == 0))
mbed_official 340:28d1f895c6fe 447 {
mbed_official 631:825f75ca301e 448 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 449 }
mbed_official 631:825f75ca301e 450
mbed_official 340:28d1f895c6fe 451 /* Process Locked */
mbed_official 340:28d1f895c6fe 452 __HAL_LOCK(hirda);
mbed_official 631:825f75ca301e 453
mbed_official 340:28d1f895c6fe 454 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 340:28d1f895c6fe 455
mbed_official 631:825f75ca301e 456 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
mbed_official 340:28d1f895c6fe 457 {
mbed_official 340:28d1f895c6fe 458 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 340:28d1f895c6fe 459 }
mbed_official 340:28d1f895c6fe 460 else
mbed_official 340:28d1f895c6fe 461 {
mbed_official 340:28d1f895c6fe 462 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 631:825f75ca301e 463 }
mbed_official 631:825f75ca301e 464
mbed_official 340:28d1f895c6fe 465 hirda->TxXferSize = Size;
mbed_official 340:28d1f895c6fe 466 hirda->TxXferCount = Size;
mbed_official 340:28d1f895c6fe 467 while(hirda->TxXferCount > 0)
mbed_official 340:28d1f895c6fe 468 {
mbed_official 340:28d1f895c6fe 469 hirda->TxXferCount--;
mbed_official 340:28d1f895c6fe 470
mbed_official 340:28d1f895c6fe 471 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TXE, RESET, Timeout) != HAL_OK)
mbed_official 340:28d1f895c6fe 472 {
mbed_official 340:28d1f895c6fe 473 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 474 }
mbed_official 340:28d1f895c6fe 475 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
mbed_official 340:28d1f895c6fe 476 {
mbed_official 340:28d1f895c6fe 477 tmp = (uint16_t*) pData;
mbed_official 631:825f75ca301e 478 hirda->Instance->TDR = (*tmp & (uint16_t)0x01FF);
mbed_official 631:825f75ca301e 479 pData +=2;
mbed_official 340:28d1f895c6fe 480 }
mbed_official 340:28d1f895c6fe 481 else
mbed_official 340:28d1f895c6fe 482 {
mbed_official 631:825f75ca301e 483 hirda->Instance->TDR = (*pData++ & (uint8_t)0xFF);
mbed_official 340:28d1f895c6fe 484 }
mbed_official 340:28d1f895c6fe 485 }
mbed_official 340:28d1f895c6fe 486
mbed_official 340:28d1f895c6fe 487 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_TC, RESET, Timeout) != HAL_OK)
mbed_official 631:825f75ca301e 488 {
mbed_official 340:28d1f895c6fe 489 return HAL_TIMEOUT;
mbed_official 631:825f75ca301e 490 }
mbed_official 340:28d1f895c6fe 491
mbed_official 631:825f75ca301e 492 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 340:28d1f895c6fe 493 {
mbed_official 340:28d1f895c6fe 494 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 340:28d1f895c6fe 495 }
mbed_official 340:28d1f895c6fe 496 else
mbed_official 340:28d1f895c6fe 497 {
mbed_official 340:28d1f895c6fe 498 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 631:825f75ca301e 499 }
mbed_official 631:825f75ca301e 500
mbed_official 340:28d1f895c6fe 501 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 502 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 503
mbed_official 340:28d1f895c6fe 504 return HAL_OK;
mbed_official 340:28d1f895c6fe 505 }
mbed_official 340:28d1f895c6fe 506 else
mbed_official 340:28d1f895c6fe 507 {
mbed_official 631:825f75ca301e 508 return HAL_BUSY;
mbed_official 340:28d1f895c6fe 509 }
mbed_official 340:28d1f895c6fe 510 }
mbed_official 340:28d1f895c6fe 511
mbed_official 340:28d1f895c6fe 512 /**
mbed_official 631:825f75ca301e 513 * @brief Receive an amount of data in blocking mode.
mbed_official 631:825f75ca301e 514 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 515 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 516 * @param pData: Pointer to data buffer.
mbed_official 631:825f75ca301e 517 * @param Size: Amount of data to be received.
mbed_official 631:825f75ca301e 518 * @param Timeout: Specify timeout value.
mbed_official 340:28d1f895c6fe 519 * @retval HAL status
mbed_official 340:28d1f895c6fe 520 */
mbed_official 340:28d1f895c6fe 521 HAL_StatusTypeDef HAL_IRDA_Receive(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size, uint32_t Timeout)
mbed_official 631:825f75ca301e 522 {
mbed_official 340:28d1f895c6fe 523 uint16_t* tmp;
mbed_official 340:28d1f895c6fe 524 uint16_t uhMask;
mbed_official 631:825f75ca301e 525
mbed_official 631:825f75ca301e 526 if((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
mbed_official 631:825f75ca301e 527 {
mbed_official 631:825f75ca301e 528 if((pData == NULL) || (Size == 0))
mbed_official 340:28d1f895c6fe 529 {
mbed_official 631:825f75ca301e 530 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 531 }
mbed_official 631:825f75ca301e 532
mbed_official 340:28d1f895c6fe 533 /* Process Locked */
mbed_official 340:28d1f895c6fe 534 __HAL_LOCK(hirda);
mbed_official 631:825f75ca301e 535
mbed_official 340:28d1f895c6fe 536 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 340:28d1f895c6fe 537
mbed_official 631:825f75ca301e 538 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
mbed_official 340:28d1f895c6fe 539 {
mbed_official 340:28d1f895c6fe 540 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 340:28d1f895c6fe 541 }
mbed_official 340:28d1f895c6fe 542 else
mbed_official 340:28d1f895c6fe 543 {
mbed_official 340:28d1f895c6fe 544 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 631:825f75ca301e 545 }
mbed_official 631:825f75ca301e 546
mbed_official 631:825f75ca301e 547 hirda->RxXferSize = Size;
mbed_official 340:28d1f895c6fe 548 hirda->RxXferCount = Size;
mbed_official 340:28d1f895c6fe 549
mbed_official 631:825f75ca301e 550 /* Computation of the mask to apply to the RDR register
mbed_official 340:28d1f895c6fe 551 of the UART associated to the IRDA */
mbed_official 631:825f75ca301e 552 IRDA_MASK_COMPUTATION(hirda);
mbed_official 340:28d1f895c6fe 553 uhMask = hirda->Mask;
mbed_official 340:28d1f895c6fe 554
mbed_official 340:28d1f895c6fe 555 /* Check data remaining to be received */
mbed_official 340:28d1f895c6fe 556 while(hirda->RxXferCount > 0)
mbed_official 340:28d1f895c6fe 557 {
mbed_official 340:28d1f895c6fe 558 hirda->RxXferCount--;
mbed_official 340:28d1f895c6fe 559
mbed_official 340:28d1f895c6fe 560 if(IRDA_WaitOnFlagUntilTimeout(hirda, IRDA_FLAG_RXNE, RESET, Timeout) != HAL_OK)
mbed_official 631:825f75ca301e 561 {
mbed_official 340:28d1f895c6fe 562 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 563 }
mbed_official 340:28d1f895c6fe 564 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
mbed_official 340:28d1f895c6fe 565 {
mbed_official 340:28d1f895c6fe 566 tmp = (uint16_t*) pData ;
mbed_official 340:28d1f895c6fe 567 *tmp = (uint16_t)(hirda->Instance->RDR & uhMask);
mbed_official 340:28d1f895c6fe 568 pData +=2;
mbed_official 340:28d1f895c6fe 569 }
mbed_official 340:28d1f895c6fe 570 else
mbed_official 340:28d1f895c6fe 571 {
mbed_official 631:825f75ca301e 572 *pData++ = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask);
mbed_official 340:28d1f895c6fe 573 }
mbed_official 340:28d1f895c6fe 574 }
mbed_official 340:28d1f895c6fe 575
mbed_official 631:825f75ca301e 576 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 340:28d1f895c6fe 577 {
mbed_official 340:28d1f895c6fe 578 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 340:28d1f895c6fe 579 }
mbed_official 340:28d1f895c6fe 580 else
mbed_official 340:28d1f895c6fe 581 {
mbed_official 340:28d1f895c6fe 582 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 340:28d1f895c6fe 583 }
mbed_official 631:825f75ca301e 584
mbed_official 340:28d1f895c6fe 585 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 586 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 587
mbed_official 340:28d1f895c6fe 588 return HAL_OK;
mbed_official 340:28d1f895c6fe 589 }
mbed_official 340:28d1f895c6fe 590 else
mbed_official 340:28d1f895c6fe 591 {
mbed_official 631:825f75ca301e 592 return HAL_BUSY;
mbed_official 340:28d1f895c6fe 593 }
mbed_official 340:28d1f895c6fe 594 }
mbed_official 340:28d1f895c6fe 595
mbed_official 340:28d1f895c6fe 596 /**
mbed_official 631:825f75ca301e 597 * @brief Send an amount of data in interrupt mode.
mbed_official 631:825f75ca301e 598 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 599 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 600 * @param pData: Pointer to data buffer.
mbed_official 631:825f75ca301e 601 * @param Size: Amount of data to be sent.
mbed_official 340:28d1f895c6fe 602 * @retval HAL status
mbed_official 340:28d1f895c6fe 603 */
mbed_official 340:28d1f895c6fe 604 HAL_StatusTypeDef HAL_IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
mbed_official 340:28d1f895c6fe 605 {
mbed_official 631:825f75ca301e 606 if((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
mbed_official 340:28d1f895c6fe 607 {
mbed_official 631:825f75ca301e 608 if((pData == NULL) || (Size == 0))
mbed_official 340:28d1f895c6fe 609 {
mbed_official 631:825f75ca301e 610 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 611 }
mbed_official 631:825f75ca301e 612
mbed_official 340:28d1f895c6fe 613 /* Process Locked */
mbed_official 340:28d1f895c6fe 614 __HAL_LOCK(hirda);
mbed_official 631:825f75ca301e 615
mbed_official 340:28d1f895c6fe 616 hirda->pTxBuffPtr = pData;
mbed_official 340:28d1f895c6fe 617 hirda->TxXferSize = Size;
mbed_official 340:28d1f895c6fe 618 hirda->TxXferCount = Size;
mbed_official 340:28d1f895c6fe 619
mbed_official 340:28d1f895c6fe 620 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 631:825f75ca301e 621
mbed_official 631:825f75ca301e 622 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
mbed_official 631:825f75ca301e 623 {
mbed_official 631:825f75ca301e 624 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 631:825f75ca301e 625 }
mbed_official 631:825f75ca301e 626 else
mbed_official 631:825f75ca301e 627 {
mbed_official 631:825f75ca301e 628 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 631:825f75ca301e 629 }
mbed_official 631:825f75ca301e 630
mbed_official 631:825f75ca301e 631 /* Process Unlocked */
mbed_official 631:825f75ca301e 632 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 633
mbed_official 631:825f75ca301e 634 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 631:825f75ca301e 635 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 631:825f75ca301e 636 /* Enable the IRDA Transmit Data Register Empty Interrupt */
mbed_official 631:825f75ca301e 637 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TXE);
mbed_official 631:825f75ca301e 638
mbed_official 631:825f75ca301e 639 return HAL_OK;
mbed_official 631:825f75ca301e 640 }
mbed_official 631:825f75ca301e 641 else
mbed_official 631:825f75ca301e 642 {
mbed_official 631:825f75ca301e 643 return HAL_BUSY;
mbed_official 631:825f75ca301e 644 }
mbed_official 631:825f75ca301e 645 }
mbed_official 631:825f75ca301e 646
mbed_official 631:825f75ca301e 647 /**
mbed_official 631:825f75ca301e 648 * @brief Receive an amount of data in interrupt mode.
mbed_official 631:825f75ca301e 649 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 650 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 651 * @param pData: Pointer to data buffer.
mbed_official 631:825f75ca301e 652 * @param Size: Amount of data to be received.
mbed_official 631:825f75ca301e 653 * @retval HAL status
mbed_official 631:825f75ca301e 654 */
mbed_official 631:825f75ca301e 655 HAL_StatusTypeDef HAL_IRDA_Receive_IT(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
mbed_official 631:825f75ca301e 656 {
mbed_official 631:825f75ca301e 657 if((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
mbed_official 631:825f75ca301e 658 {
mbed_official 631:825f75ca301e 659 if((pData == NULL) || (Size == 0))
mbed_official 631:825f75ca301e 660 {
mbed_official 631:825f75ca301e 661 return HAL_ERROR;
mbed_official 631:825f75ca301e 662 }
mbed_official 631:825f75ca301e 663
mbed_official 631:825f75ca301e 664 /* Process Locked */
mbed_official 631:825f75ca301e 665 __HAL_LOCK(hirda);
mbed_official 631:825f75ca301e 666
mbed_official 631:825f75ca301e 667 hirda->pRxBuffPtr = pData;
mbed_official 631:825f75ca301e 668 hirda->RxXferSize = Size;
mbed_official 631:825f75ca301e 669 hirda->RxXferCount = Size;
mbed_official 631:825f75ca301e 670
mbed_official 631:825f75ca301e 671 /* Computation of the mask to apply to the RDR register
mbed_official 631:825f75ca301e 672 of the UART associated to the IRDA */
mbed_official 631:825f75ca301e 673 IRDA_MASK_COMPUTATION(hirda);
mbed_official 631:825f75ca301e 674
mbed_official 631:825f75ca301e 675 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 631:825f75ca301e 676
mbed_official 631:825f75ca301e 677 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
mbed_official 631:825f75ca301e 678 {
mbed_official 631:825f75ca301e 679 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 631:825f75ca301e 680 }
mbed_official 631:825f75ca301e 681 else
mbed_official 631:825f75ca301e 682 {
mbed_official 631:825f75ca301e 683 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 631:825f75ca301e 684 }
mbed_official 631:825f75ca301e 685
mbed_official 631:825f75ca301e 686 /* Process Unlocked */
mbed_official 631:825f75ca301e 687 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 688
mbed_official 631:825f75ca301e 689 /* Enable the IRDA Data Register not empty Interrupt */
mbed_official 631:825f75ca301e 690 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_RXNE);
mbed_official 631:825f75ca301e 691
mbed_official 631:825f75ca301e 692 /* Enable the IRDA Parity Error Interrupt */
mbed_official 631:825f75ca301e 693 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_PE);
mbed_official 631:825f75ca301e 694
mbed_official 631:825f75ca301e 695 /* Enable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 631:825f75ca301e 696 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 631:825f75ca301e 697
mbed_official 631:825f75ca301e 698 return HAL_OK;
mbed_official 631:825f75ca301e 699 }
mbed_official 631:825f75ca301e 700 else
mbed_official 631:825f75ca301e 701 {
mbed_official 631:825f75ca301e 702 return HAL_BUSY;
mbed_official 631:825f75ca301e 703 }
mbed_official 631:825f75ca301e 704 }
mbed_official 631:825f75ca301e 705
mbed_official 631:825f75ca301e 706 /**
mbed_official 631:825f75ca301e 707 * @brief Send an amount of data in DMA mode.
mbed_official 631:825f75ca301e 708 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 709 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 710 * @param pData: pointer to data buffer.
mbed_official 631:825f75ca301e 711 * @param Size: amount of data to be sent.
mbed_official 631:825f75ca301e 712 * @retval HAL status
mbed_official 631:825f75ca301e 713 */
mbed_official 631:825f75ca301e 714 HAL_StatusTypeDef HAL_IRDA_Transmit_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
mbed_official 631:825f75ca301e 715 {
mbed_official 631:825f75ca301e 716 uint32_t *tmp;
mbed_official 631:825f75ca301e 717
mbed_official 631:825f75ca301e 718 if((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_RX))
mbed_official 631:825f75ca301e 719 {
mbed_official 631:825f75ca301e 720 if((pData == NULL) || (Size == 0))
mbed_official 631:825f75ca301e 721 {
mbed_official 631:825f75ca301e 722 return HAL_ERROR;
mbed_official 631:825f75ca301e 723 }
mbed_official 631:825f75ca301e 724
mbed_official 631:825f75ca301e 725 /* Process Locked */
mbed_official 631:825f75ca301e 726 __HAL_LOCK(hirda);
mbed_official 631:825f75ca301e 727
mbed_official 631:825f75ca301e 728 hirda->pTxBuffPtr = pData;
mbed_official 631:825f75ca301e 729 hirda->TxXferSize = Size;
mbed_official 631:825f75ca301e 730 hirda->TxXferCount = Size;
mbed_official 631:825f75ca301e 731
mbed_official 631:825f75ca301e 732 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 631:825f75ca301e 733
mbed_official 631:825f75ca301e 734 if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
mbed_official 340:28d1f895c6fe 735 {
mbed_official 340:28d1f895c6fe 736 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 340:28d1f895c6fe 737 }
mbed_official 340:28d1f895c6fe 738 else
mbed_official 340:28d1f895c6fe 739 {
mbed_official 340:28d1f895c6fe 740 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 340:28d1f895c6fe 741 }
mbed_official 340:28d1f895c6fe 742
mbed_official 631:825f75ca301e 743 /* Set the IRDA DMA transfer complete callback */
mbed_official 631:825f75ca301e 744 hirda->hdmatx->XferCpltCallback = IRDA_DMATransmitCplt;
mbed_official 631:825f75ca301e 745
mbed_official 631:825f75ca301e 746 /* Set the IRDA DMA half transfer complete callback */
mbed_official 631:825f75ca301e 747 hirda->hdmatx->XferHalfCpltCallback = IRDA_DMATransmitHalfCplt;
mbed_official 631:825f75ca301e 748
mbed_official 631:825f75ca301e 749 /* Set the DMA error callback */
mbed_official 631:825f75ca301e 750 hirda->hdmatx->XferErrorCallback = IRDA_DMAError;
mbed_official 631:825f75ca301e 751
mbed_official 631:825f75ca301e 752 /* Enable the IRDA transmit DMA channel */
mbed_official 631:825f75ca301e 753 tmp = (uint32_t*)&pData;
mbed_official 631:825f75ca301e 754 HAL_DMA_Start_IT(hirda->hdmatx, *(uint32_t*)tmp, (uint32_t)&hirda->Instance->TDR, Size);
mbed_official 631:825f75ca301e 755
mbed_official 631:825f75ca301e 756 /* Clear the TC flag in the ICR register */
mbed_official 631:825f75ca301e 757 __HAL_IRDA_CLEAR_FLAG(hirda, IRDA_CLEAR_TCF);
mbed_official 631:825f75ca301e 758
mbed_official 631:825f75ca301e 759 /* Enable the DMA transfer for transmit request by setting the DMAT bit
mbed_official 631:825f75ca301e 760 in the USART CR3 register */
mbed_official 631:825f75ca301e 761 hirda->Instance->CR3 |= USART_CR3_DMAT;
mbed_official 631:825f75ca301e 762
mbed_official 340:28d1f895c6fe 763 /* Process Unlocked */
mbed_official 631:825f75ca301e 764 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 765
mbed_official 340:28d1f895c6fe 766 return HAL_OK;
mbed_official 340:28d1f895c6fe 767 }
mbed_official 340:28d1f895c6fe 768 else
mbed_official 340:28d1f895c6fe 769 {
mbed_official 631:825f75ca301e 770 return HAL_BUSY;
mbed_official 340:28d1f895c6fe 771 }
mbed_official 340:28d1f895c6fe 772 }
mbed_official 340:28d1f895c6fe 773
mbed_official 340:28d1f895c6fe 774 /**
mbed_official 631:825f75ca301e 775 * @brief Receive an amount of data in DMA mode.
mbed_official 631:825f75ca301e 776 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 777 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 778 * @param pData: Pointer to data buffer.
mbed_official 631:825f75ca301e 779 * @param Size: Amount of data to be received.
mbed_official 631:825f75ca301e 780 * @note When the IRDA parity is enabled (PCE = 1) the received data contains
mbed_official 631:825f75ca301e 781 * the parity bit (MSB position).
mbed_official 340:28d1f895c6fe 782 * @retval HAL status
mbed_official 340:28d1f895c6fe 783 */
mbed_official 631:825f75ca301e 784 HAL_StatusTypeDef HAL_IRDA_Receive_DMA(IRDA_HandleTypeDef *hirda, uint8_t *pData, uint16_t Size)
mbed_official 631:825f75ca301e 785 {
mbed_official 631:825f75ca301e 786 uint32_t *tmp;
mbed_official 631:825f75ca301e 787
mbed_official 631:825f75ca301e 788 if((hirda->State == HAL_IRDA_STATE_READY) || (hirda->State == HAL_IRDA_STATE_BUSY_TX))
mbed_official 340:28d1f895c6fe 789 {
mbed_official 631:825f75ca301e 790 if((pData == NULL) || (Size == 0))
mbed_official 340:28d1f895c6fe 791 {
mbed_official 631:825f75ca301e 792 return HAL_ERROR;
mbed_official 340:28d1f895c6fe 793 }
mbed_official 631:825f75ca301e 794
mbed_official 340:28d1f895c6fe 795 /* Process Locked */
mbed_official 631:825f75ca301e 796 __HAL_LOCK(hirda);
mbed_official 631:825f75ca301e 797
mbed_official 340:28d1f895c6fe 798 hirda->pRxBuffPtr = pData;
mbed_official 340:28d1f895c6fe 799 hirda->RxXferSize = Size;
mbed_official 340:28d1f895c6fe 800
mbed_official 631:825f75ca301e 801 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 631:825f75ca301e 802
mbed_official 631:825f75ca301e 803 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
mbed_official 340:28d1f895c6fe 804 {
mbed_official 340:28d1f895c6fe 805 hirda->State = HAL_IRDA_STATE_BUSY_TX_RX;
mbed_official 340:28d1f895c6fe 806 }
mbed_official 340:28d1f895c6fe 807 else
mbed_official 340:28d1f895c6fe 808 {
mbed_official 340:28d1f895c6fe 809 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 340:28d1f895c6fe 810 }
mbed_official 340:28d1f895c6fe 811
mbed_official 340:28d1f895c6fe 812 /* Set the IRDA DMA transfer complete callback */
mbed_official 340:28d1f895c6fe 813 hirda->hdmarx->XferCpltCallback = IRDA_DMAReceiveCplt;
mbed_official 631:825f75ca301e 814
mbed_official 631:825f75ca301e 815 /* Set the IRDA DMA half transfer complete callback */
mbed_official 631:825f75ca301e 816 hirda->hdmarx->XferHalfCpltCallback = IRDA_DMAReceiveHalfCplt;
mbed_official 631:825f75ca301e 817
mbed_official 340:28d1f895c6fe 818 /* Set the DMA error callback */
mbed_official 340:28d1f895c6fe 819 hirda->hdmarx->XferErrorCallback = IRDA_DMAError;
mbed_official 340:28d1f895c6fe 820
mbed_official 340:28d1f895c6fe 821 /* Enable the DMA channel */
mbed_official 340:28d1f895c6fe 822 tmp = (uint32_t*)&pData;
mbed_official 340:28d1f895c6fe 823 HAL_DMA_Start_IT(hirda->hdmarx, (uint32_t)&hirda->Instance->RDR, *(uint32_t*)tmp, Size);
mbed_official 340:28d1f895c6fe 824
mbed_official 631:825f75ca301e 825 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
mbed_official 631:825f75ca301e 826 in the USART CR3 register */
mbed_official 340:28d1f895c6fe 827 hirda->Instance->CR3 |= USART_CR3_DMAR;
mbed_official 631:825f75ca301e 828
mbed_official 340:28d1f895c6fe 829 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 830 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 831
mbed_official 340:28d1f895c6fe 832 return HAL_OK;
mbed_official 340:28d1f895c6fe 833 }
mbed_official 340:28d1f895c6fe 834 else
mbed_official 340:28d1f895c6fe 835 {
mbed_official 631:825f75ca301e 836 return HAL_BUSY;
mbed_official 340:28d1f895c6fe 837 }
mbed_official 340:28d1f895c6fe 838 }
mbed_official 631:825f75ca301e 839
mbed_official 631:825f75ca301e 840
mbed_official 631:825f75ca301e 841 /**
mbed_official 631:825f75ca301e 842 * @brief Pause the DMA Transfer.
mbed_official 631:825f75ca301e 843 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 844 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 845 * @retval HAL status
mbed_official 631:825f75ca301e 846 */
mbed_official 631:825f75ca301e 847 HAL_StatusTypeDef HAL_IRDA_DMAPause(IRDA_HandleTypeDef *hirda)
mbed_official 631:825f75ca301e 848 {
mbed_official 631:825f75ca301e 849 /* Process Locked */
mbed_official 631:825f75ca301e 850 __HAL_LOCK(hirda);
mbed_official 631:825f75ca301e 851
mbed_official 631:825f75ca301e 852 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
mbed_official 631:825f75ca301e 853 {
mbed_official 631:825f75ca301e 854 /* Disable the IRDA DMA Tx request */
mbed_official 631:825f75ca301e 855 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
mbed_official 631:825f75ca301e 856 }
mbed_official 631:825f75ca301e 857 else if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
mbed_official 631:825f75ca301e 858 {
mbed_official 631:825f75ca301e 859 /* Disable the IRDA DMA Rx request */
mbed_official 631:825f75ca301e 860 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
mbed_official 631:825f75ca301e 861 }
mbed_official 631:825f75ca301e 862 else if (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 631:825f75ca301e 863 {
mbed_official 631:825f75ca301e 864 /* Disable the IRDA DMA Tx & Rx requests */
mbed_official 631:825f75ca301e 865 CLEAR_BIT(hirda->Instance->CR3, (USART_CR3_DMAT | USART_CR3_DMAR));
mbed_official 631:825f75ca301e 866 }
mbed_official 631:825f75ca301e 867 else
mbed_official 631:825f75ca301e 868 {
mbed_official 631:825f75ca301e 869 /* Process Unlocked */
mbed_official 631:825f75ca301e 870 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 871
mbed_official 631:825f75ca301e 872 return HAL_ERROR;
mbed_official 631:825f75ca301e 873 }
mbed_official 631:825f75ca301e 874
mbed_official 631:825f75ca301e 875 /* Process Unlocked */
mbed_official 631:825f75ca301e 876 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 877
mbed_official 631:825f75ca301e 878 return HAL_OK;
mbed_official 631:825f75ca301e 879 }
mbed_official 631:825f75ca301e 880
mbed_official 340:28d1f895c6fe 881 /**
mbed_official 631:825f75ca301e 882 * @brief Resume the DMA Transfer.
mbed_official 631:825f75ca301e 883 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 884 * the configuration information for the specified UART module.
mbed_official 631:825f75ca301e 885 * @retval HAL status
mbed_official 631:825f75ca301e 886 */
mbed_official 631:825f75ca301e 887 HAL_StatusTypeDef HAL_IRDA_DMAResume(IRDA_HandleTypeDef *hirda)
mbed_official 631:825f75ca301e 888 {
mbed_official 631:825f75ca301e 889 /* Process Locked */
mbed_official 631:825f75ca301e 890 __HAL_LOCK(hirda);
mbed_official 631:825f75ca301e 891
mbed_official 631:825f75ca301e 892 if(hirda->State == HAL_IRDA_STATE_BUSY_TX)
mbed_official 631:825f75ca301e 893 {
mbed_official 631:825f75ca301e 894 /* Enable the IRDA DMA Tx request */
mbed_official 631:825f75ca301e 895 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
mbed_official 631:825f75ca301e 896 }
mbed_official 631:825f75ca301e 897 else if(hirda->State == HAL_IRDA_STATE_BUSY_RX)
mbed_official 631:825f75ca301e 898 {
mbed_official 631:825f75ca301e 899 /* Clear the Overrun flag before resuming the Rx transfer*/
mbed_official 631:825f75ca301e 900 __HAL_IRDA_CLEAR_OREFLAG(hirda);
mbed_official 631:825f75ca301e 901 /* Enable the IRDA DMA Rx request */
mbed_official 631:825f75ca301e 902 SET_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
mbed_official 631:825f75ca301e 903 }
mbed_official 631:825f75ca301e 904 else if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 631:825f75ca301e 905 {
mbed_official 631:825f75ca301e 906 /* Clear the Overrun flag before resuming the Rx transfer*/
mbed_official 631:825f75ca301e 907 __HAL_IRDA_CLEAR_OREFLAG(hirda);
mbed_official 631:825f75ca301e 908 /* Enable the IRDA DMA Tx & Rx request */
mbed_official 631:825f75ca301e 909 SET_BIT(hirda->Instance->CR3, (USART_CR3_DMAT | USART_CR3_DMAR));
mbed_official 631:825f75ca301e 910 }
mbed_official 631:825f75ca301e 911 else
mbed_official 631:825f75ca301e 912 {
mbed_official 631:825f75ca301e 913 /* Process Unlocked */
mbed_official 631:825f75ca301e 914 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 915
mbed_official 631:825f75ca301e 916 return HAL_ERROR;
mbed_official 631:825f75ca301e 917 }
mbed_official 631:825f75ca301e 918
mbed_official 631:825f75ca301e 919 /* Process Unlocked */
mbed_official 631:825f75ca301e 920 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 921
mbed_official 631:825f75ca301e 922 return HAL_OK;
mbed_official 631:825f75ca301e 923 }
mbed_official 631:825f75ca301e 924
mbed_official 631:825f75ca301e 925 /**
mbed_official 631:825f75ca301e 926 * @brief Stop the DMA Transfer.
mbed_official 631:825f75ca301e 927 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 928 * the configuration information for the specified UART module.
mbed_official 631:825f75ca301e 929 * @retval HAL status
mbed_official 631:825f75ca301e 930 */
mbed_official 631:825f75ca301e 931 HAL_StatusTypeDef HAL_IRDA_DMAStop(IRDA_HandleTypeDef *hirda)
mbed_official 631:825f75ca301e 932 {
mbed_official 631:825f75ca301e 933 /* The Lock is not implemented on this API to allow the user application
mbed_official 631:825f75ca301e 934 to call the HAL IRDA API under callbacks HAL_IRDA_TxCpltCallback() / HAL_IRDA_RxCpltCallback() /
mbed_official 631:825f75ca301e 935 HAL_IRDA_TxHalfCpltCallback() / HAL_IRDA_RxHalfCpltCallback():
mbed_official 631:825f75ca301e 936 indeed, when HAL_DMA_Abort() API is called, the DMA TX/RX Transfer or Half Transfer complete interrupt is
mbed_official 631:825f75ca301e 937 generated if the DMA transfer interruption occurs at the middle or at the end of the stream
mbed_official 631:825f75ca301e 938 and the corresponding call back is executed.
mbed_official 631:825f75ca301e 939 */
mbed_official 631:825f75ca301e 940
mbed_official 631:825f75ca301e 941 /* Disable the IRDA Tx/Rx DMA requests */
mbed_official 631:825f75ca301e 942 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAT);
mbed_official 631:825f75ca301e 943 CLEAR_BIT(hirda->Instance->CR3, USART_CR3_DMAR);
mbed_official 631:825f75ca301e 944
mbed_official 631:825f75ca301e 945 /* Abort the IRDA DMA tx channel */
mbed_official 631:825f75ca301e 946 if(hirda->hdmatx != NULL)
mbed_official 631:825f75ca301e 947 {
mbed_official 631:825f75ca301e 948 HAL_DMA_Abort(hirda->hdmatx);
mbed_official 631:825f75ca301e 949 }
mbed_official 631:825f75ca301e 950 /* Abort the IRDA DMA rx channel */
mbed_official 631:825f75ca301e 951 if(hirda->hdmarx != NULL)
mbed_official 631:825f75ca301e 952 {
mbed_official 631:825f75ca301e 953 HAL_DMA_Abort(hirda->hdmarx);
mbed_official 631:825f75ca301e 954 }
mbed_official 631:825f75ca301e 955
mbed_official 631:825f75ca301e 956 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 631:825f75ca301e 957
mbed_official 631:825f75ca301e 958 return HAL_OK;
mbed_official 631:825f75ca301e 959 }
mbed_official 631:825f75ca301e 960
mbed_official 631:825f75ca301e 961
mbed_official 631:825f75ca301e 962 /**
mbed_official 631:825f75ca301e 963 * @brief Handle IRDA interrupt request.
mbed_official 631:825f75ca301e 964 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 965 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 966 * @retval None
mbed_official 340:28d1f895c6fe 967 */
mbed_official 340:28d1f895c6fe 968 void HAL_IRDA_IRQHandler(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 969 {
mbed_official 340:28d1f895c6fe 970 /* IRDA parity error interrupt occurred -------------------------------------*/
mbed_official 340:28d1f895c6fe 971 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_PE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_PE) != RESET))
mbed_official 631:825f75ca301e 972 {
mbed_official 340:28d1f895c6fe 973 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_PEF);
mbed_official 340:28d1f895c6fe 974
mbed_official 340:28d1f895c6fe 975 hirda->ErrorCode |= HAL_IRDA_ERROR_PE;
mbed_official 340:28d1f895c6fe 976 /* Set the IRDA state ready to be able to start again the process */
mbed_official 340:28d1f895c6fe 977 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 340:28d1f895c6fe 978 }
mbed_official 631:825f75ca301e 979
mbed_official 631:825f75ca301e 980 /* IRDA frame error interrupt occurred --------------------------------------*/
mbed_official 340:28d1f895c6fe 981 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_FE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
mbed_official 631:825f75ca301e 982 {
mbed_official 340:28d1f895c6fe 983 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_FEF);
mbed_official 340:28d1f895c6fe 984
mbed_official 340:28d1f895c6fe 985 hirda->ErrorCode |= HAL_IRDA_ERROR_FE;
mbed_official 340:28d1f895c6fe 986 /* Set the IRDA state ready to be able to start again the process */
mbed_official 340:28d1f895c6fe 987 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 340:28d1f895c6fe 988 }
mbed_official 631:825f75ca301e 989
mbed_official 631:825f75ca301e 990 /* IRDA noise error interrupt occurred --------------------------------------*/
mbed_official 340:28d1f895c6fe 991 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_NE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
mbed_official 631:825f75ca301e 992 {
mbed_official 340:28d1f895c6fe 993 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_NEF);
mbed_official 340:28d1f895c6fe 994
mbed_official 631:825f75ca301e 995 hirda->ErrorCode |= HAL_IRDA_ERROR_NE;
mbed_official 340:28d1f895c6fe 996 /* Set the IRDA state ready to be able to start again the process */
mbed_official 340:28d1f895c6fe 997 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 340:28d1f895c6fe 998 }
mbed_official 631:825f75ca301e 999
mbed_official 631:825f75ca301e 1000 /* IRDA Over-Run interrupt occurred -----------------------------------------*/
mbed_official 340:28d1f895c6fe 1001 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_ORE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_ERR) != RESET))
mbed_official 631:825f75ca301e 1002 {
mbed_official 340:28d1f895c6fe 1003 __HAL_IRDA_CLEAR_IT(hirda, IRDA_CLEAR_OREF);
mbed_official 340:28d1f895c6fe 1004
mbed_official 631:825f75ca301e 1005 hirda->ErrorCode |= HAL_IRDA_ERROR_ORE;
mbed_official 340:28d1f895c6fe 1006 /* Set the IRDA state ready to be able to start again the process */
mbed_official 340:28d1f895c6fe 1007 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 340:28d1f895c6fe 1008 }
mbed_official 631:825f75ca301e 1009
mbed_official 340:28d1f895c6fe 1010 /* Call IRDA Error Call back function if need be --------------------------*/
mbed_official 340:28d1f895c6fe 1011 if(hirda->ErrorCode != HAL_IRDA_ERROR_NONE)
mbed_official 340:28d1f895c6fe 1012 {
mbed_official 340:28d1f895c6fe 1013 HAL_IRDA_ErrorCallback(hirda);
mbed_official 631:825f75ca301e 1014 }
mbed_official 340:28d1f895c6fe 1015
mbed_official 340:28d1f895c6fe 1016 /* IRDA in mode Receiver ---------------------------------------------------*/
mbed_official 340:28d1f895c6fe 1017 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_RXNE) != RESET) && (__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_RXNE) != RESET))
mbed_official 631:825f75ca301e 1018 {
mbed_official 340:28d1f895c6fe 1019 IRDA_Receive_IT(hirda);
mbed_official 340:28d1f895c6fe 1020 /* Clear RXNE interrupt flag */
mbed_official 340:28d1f895c6fe 1021 __HAL_IRDA_SEND_REQ(hirda, IRDA_RXDATA_FLUSH_REQUEST);
mbed_official 340:28d1f895c6fe 1022 }
mbed_official 631:825f75ca301e 1023
mbed_official 340:28d1f895c6fe 1024
mbed_official 340:28d1f895c6fe 1025 /* IRDA in mode Transmitter ------------------------------------------------*/
mbed_official 340:28d1f895c6fe 1026 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_TXE) != RESET) &&(__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TXE) != RESET))
mbed_official 340:28d1f895c6fe 1027 {
mbed_official 340:28d1f895c6fe 1028 IRDA_Transmit_IT(hirda);
mbed_official 631:825f75ca301e 1029 }
mbed_official 631:825f75ca301e 1030
mbed_official 340:28d1f895c6fe 1031 /* IRDA in mode Transmitter (transmission end) -----------------------------*/
mbed_official 340:28d1f895c6fe 1032 if((__HAL_IRDA_GET_IT(hirda, IRDA_IT_TC) != RESET) &&(__HAL_IRDA_GET_IT_SOURCE(hirda, IRDA_IT_TC) != RESET))
mbed_official 340:28d1f895c6fe 1033 {
mbed_official 340:28d1f895c6fe 1034 IRDA_EndTransmit_IT(hirda);
mbed_official 631:825f75ca301e 1035 }
mbed_official 340:28d1f895c6fe 1036
mbed_official 340:28d1f895c6fe 1037 }
mbed_official 340:28d1f895c6fe 1038
mbed_official 340:28d1f895c6fe 1039 /**
mbed_official 631:825f75ca301e 1040 * @brief Tx Transfer completed callback.
mbed_official 631:825f75ca301e 1041 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1042 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 1043 * @retval None
mbed_official 340:28d1f895c6fe 1044 */
mbed_official 340:28d1f895c6fe 1045 __weak void HAL_IRDA_TxCpltCallback(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 1046 {
mbed_official 631:825f75ca301e 1047 /* NOTE: This function should not be modified, when the callback is needed,
mbed_official 631:825f75ca301e 1048 the HAL_IRDA_TxCpltCallback can be implemented in the user file.
mbed_official 631:825f75ca301e 1049 */
mbed_official 340:28d1f895c6fe 1050 }
mbed_official 340:28d1f895c6fe 1051
mbed_official 340:28d1f895c6fe 1052 /**
mbed_official 631:825f75ca301e 1053 * @brief Tx Half Transfer completed callback.
mbed_official 631:825f75ca301e 1054 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1055 * the configuration information for the specified USART module.
mbed_official 631:825f75ca301e 1056 * @retval None
mbed_official 631:825f75ca301e 1057 */
mbed_official 631:825f75ca301e 1058 __weak void HAL_IRDA_TxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
mbed_official 631:825f75ca301e 1059 {
mbed_official 631:825f75ca301e 1060 /* NOTE: This function should not be modified, when the callback is needed,
mbed_official 631:825f75ca301e 1061 the HAL_IRDA_TxHalfCpltCallback can be implemented in the user file.
mbed_official 631:825f75ca301e 1062 */
mbed_official 631:825f75ca301e 1063 }
mbed_official 631:825f75ca301e 1064
mbed_official 631:825f75ca301e 1065 /**
mbed_official 631:825f75ca301e 1066 * @brief Rx Transfer completed callback.
mbed_official 631:825f75ca301e 1067 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1068 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 1069 * @retval None
mbed_official 340:28d1f895c6fe 1070 */
mbed_official 340:28d1f895c6fe 1071 __weak void HAL_IRDA_RxCpltCallback(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 1072 {
mbed_official 631:825f75ca301e 1073 /* NOTE: This function should not be modified, when the callback is needed,
mbed_official 631:825f75ca301e 1074 the HAL_IRDA_RxCpltCallback can be implemented in the user file.
mbed_official 340:28d1f895c6fe 1075 */
mbed_official 340:28d1f895c6fe 1076 }
mbed_official 340:28d1f895c6fe 1077
mbed_official 340:28d1f895c6fe 1078 /**
mbed_official 631:825f75ca301e 1079 * @brief Rx Half Transfer complete callback.
mbed_official 631:825f75ca301e 1080 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1081 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 1082 * @retval None
mbed_official 631:825f75ca301e 1083 */
mbed_official 631:825f75ca301e 1084 __weak void HAL_IRDA_RxHalfCpltCallback(IRDA_HandleTypeDef *hirda)
mbed_official 631:825f75ca301e 1085 {
mbed_official 631:825f75ca301e 1086 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 631:825f75ca301e 1087 the HAL_IRDA_RxHalfCpltCallback can be implemented in the user file.
mbed_official 631:825f75ca301e 1088 */
mbed_official 631:825f75ca301e 1089 }
mbed_official 631:825f75ca301e 1090
mbed_official 631:825f75ca301e 1091 /**
mbed_official 631:825f75ca301e 1092 * @brief IRDA error callback.
mbed_official 631:825f75ca301e 1093 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1094 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 1095 * @retval None
mbed_official 340:28d1f895c6fe 1096 */
mbed_official 340:28d1f895c6fe 1097 __weak void HAL_IRDA_ErrorCallback(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 1098 {
mbed_official 631:825f75ca301e 1099 /* NOTE: This function should not be modified, when the callback is needed,
mbed_official 631:825f75ca301e 1100 the HAL_IRDA_ErrorCallback can be implemented in the user file.
mbed_official 631:825f75ca301e 1101 */
mbed_official 340:28d1f895c6fe 1102 }
mbed_official 340:28d1f895c6fe 1103
mbed_official 340:28d1f895c6fe 1104 /**
mbed_official 340:28d1f895c6fe 1105 * @}
mbed_official 340:28d1f895c6fe 1106 */
mbed_official 340:28d1f895c6fe 1107
mbed_official 631:825f75ca301e 1108 /** @defgroup IRDA_Exported_Functions_Group3 Peripheral State and Error functions
mbed_official 631:825f75ca301e 1109 * @brief IRDA State and Errors functions
mbed_official 631:825f75ca301e 1110 *
mbed_official 631:825f75ca301e 1111 @verbatim
mbed_official 631:825f75ca301e 1112 ==============================================================================
mbed_official 631:825f75ca301e 1113 ##### Peripheral State and Errors functions #####
mbed_official 631:825f75ca301e 1114 ==============================================================================
mbed_official 631:825f75ca301e 1115 [..]
mbed_official 631:825f75ca301e 1116 This subsection provides a set of functions allowing to return the State of IrDA
mbed_official 631:825f75ca301e 1117 communication process and also return Peripheral Errors occurred during communication process
mbed_official 631:825f75ca301e 1118 (+) HAL_IRDA_GetState() API can be helpful to check in run-time the state
mbed_official 631:825f75ca301e 1119 of the IRDA peripheral handle.
mbed_official 631:825f75ca301e 1120 (+) HAL_IRDA_GetError() checks in run-time errors that could occur during
mbed_official 631:825f75ca301e 1121 communication.
mbed_official 340:28d1f895c6fe 1122
mbed_official 340:28d1f895c6fe 1123 @endverbatim
mbed_official 340:28d1f895c6fe 1124 * @{
mbed_official 340:28d1f895c6fe 1125 */
mbed_official 340:28d1f895c6fe 1126
mbed_official 340:28d1f895c6fe 1127 /**
mbed_official 631:825f75ca301e 1128 * @brief Return the IRDA handle state.
mbed_official 631:825f75ca301e 1129 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1130 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 1131 * @retval HAL state
mbed_official 340:28d1f895c6fe 1132 */
mbed_official 340:28d1f895c6fe 1133 HAL_IRDA_StateTypeDef HAL_IRDA_GetState(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 1134 {
mbed_official 631:825f75ca301e 1135 /* Return IRDA handle state */
mbed_official 340:28d1f895c6fe 1136 return hirda->State;
mbed_official 340:28d1f895c6fe 1137 }
mbed_official 340:28d1f895c6fe 1138
mbed_official 340:28d1f895c6fe 1139 /**
mbed_official 631:825f75ca301e 1140 * @brief Return the IRDA handle error code.
mbed_official 631:825f75ca301e 1141 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1142 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 1143 * @retval IRDA Error Code
mbed_official 631:825f75ca301e 1144 */
mbed_official 340:28d1f895c6fe 1145 uint32_t HAL_IRDA_GetError(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 1146 {
mbed_official 340:28d1f895c6fe 1147 return hirda->ErrorCode;
mbed_official 340:28d1f895c6fe 1148 }
mbed_official 340:28d1f895c6fe 1149
mbed_official 340:28d1f895c6fe 1150 /**
mbed_official 340:28d1f895c6fe 1151 * @}
mbed_official 340:28d1f895c6fe 1152 */
mbed_official 340:28d1f895c6fe 1153
mbed_official 340:28d1f895c6fe 1154 /**
mbed_official 340:28d1f895c6fe 1155 * @}
mbed_official 631:825f75ca301e 1156 */
mbed_official 340:28d1f895c6fe 1157
mbed_official 340:28d1f895c6fe 1158 /** @addtogroup IRDA_Private_Functions IRDA Private Functions
mbed_official 340:28d1f895c6fe 1159 * @{
mbed_official 340:28d1f895c6fe 1160 */
mbed_official 631:825f75ca301e 1161
mbed_official 631:825f75ca301e 1162
mbed_official 340:28d1f895c6fe 1163 /**
mbed_official 631:825f75ca301e 1164 * @brief Configure the IRDA peripheral.
mbed_official 631:825f75ca301e 1165 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1166 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 1167 * @retval None
mbed_official 340:28d1f895c6fe 1168 */
mbed_official 340:28d1f895c6fe 1169 static HAL_StatusTypeDef IRDA_SetConfig(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 1170 {
mbed_official 340:28d1f895c6fe 1171 uint32_t tmpreg = 0x00000000;
mbed_official 340:28d1f895c6fe 1172 IRDA_ClockSourceTypeDef clocksource = IRDA_CLOCKSOURCE_UNDEFINED;
mbed_official 631:825f75ca301e 1173 HAL_StatusTypeDef ret = HAL_OK;
mbed_official 631:825f75ca301e 1174
mbed_official 631:825f75ca301e 1175 /* Check the communication parameters */
mbed_official 631:825f75ca301e 1176 assert_param(IS_IRDA_BAUDRATE(hirda->Init.BaudRate));
mbed_official 340:28d1f895c6fe 1177 assert_param(IS_IRDA_WORD_LENGTH(hirda->Init.WordLength));
mbed_official 340:28d1f895c6fe 1178 assert_param(IS_IRDA_PARITY(hirda->Init.Parity));
mbed_official 340:28d1f895c6fe 1179 assert_param(IS_IRDA_TX_RX_MODE(hirda->Init.Mode));
mbed_official 631:825f75ca301e 1180 assert_param(IS_IRDA_PRESCALER(hirda->Init.Prescaler));
mbed_official 631:825f75ca301e 1181 assert_param(IS_IRDA_POWERMODE(hirda->Init.PowerMode));
mbed_official 340:28d1f895c6fe 1182
mbed_official 631:825f75ca301e 1183 /*-------------------------- USART CR1 Configuration -----------------------*/
mbed_official 631:825f75ca301e 1184 /* Configure the IRDA Word Length, Parity and transfer Mode:
mbed_official 631:825f75ca301e 1185 Set the M bits according to hirda->Init.WordLength value
mbed_official 340:28d1f895c6fe 1186 Set PCE and PS bits according to hirda->Init.Parity value
mbed_official 340:28d1f895c6fe 1187 Set TE and RE bits according to hirda->Init.Mode value */
mbed_official 340:28d1f895c6fe 1188 tmpreg = (uint32_t)hirda->Init.WordLength | hirda->Init.Parity | hirda->Init.Mode ;
mbed_official 631:825f75ca301e 1189
mbed_official 340:28d1f895c6fe 1190 MODIFY_REG(hirda->Instance->CR1, IRDA_CR1_FIELDS, tmpreg);
mbed_official 631:825f75ca301e 1191
mbed_official 340:28d1f895c6fe 1192 /*-------------------------- USART CR3 Configuration -----------------------*/
mbed_official 340:28d1f895c6fe 1193 MODIFY_REG(hirda->Instance->CR3, USART_CR3_IRLP, hirda->Init.PowerMode);
mbed_official 631:825f75ca301e 1194
mbed_official 631:825f75ca301e 1195 /*-------------------------- USART GTPR Configuration ----------------------*/
mbed_official 340:28d1f895c6fe 1196 MODIFY_REG(hirda->Instance->GTPR, USART_GTPR_PSC, hirda->Init.Prescaler);
mbed_official 631:825f75ca301e 1197
mbed_official 631:825f75ca301e 1198 /*-------------------------- USART BRR Configuration -----------------------*/
mbed_official 631:825f75ca301e 1199 IRDA_GETCLOCKSOURCE(hirda, clocksource);
mbed_official 340:28d1f895c6fe 1200 switch (clocksource)
mbed_official 340:28d1f895c6fe 1201 {
mbed_official 631:825f75ca301e 1202 case IRDA_CLOCKSOURCE_PCLK1:
mbed_official 340:28d1f895c6fe 1203 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetPCLK1Freq() / hirda->Init.BaudRate);
mbed_official 340:28d1f895c6fe 1204 break;
mbed_official 631:825f75ca301e 1205 case IRDA_CLOCKSOURCE_HSI:
mbed_official 631:825f75ca301e 1206 hirda->Instance->BRR = (uint16_t)(HSI_VALUE / hirda->Init.BaudRate);
mbed_official 631:825f75ca301e 1207 break;
mbed_official 631:825f75ca301e 1208 case IRDA_CLOCKSOURCE_SYSCLK:
mbed_official 340:28d1f895c6fe 1209 hirda->Instance->BRR = (uint16_t)(HAL_RCC_GetSysClockFreq() / hirda->Init.BaudRate);
mbed_official 631:825f75ca301e 1210 break;
mbed_official 631:825f75ca301e 1211 case IRDA_CLOCKSOURCE_LSE:
mbed_official 631:825f75ca301e 1212 hirda->Instance->BRR = (uint16_t)(LSE_VALUE / hirda->Init.BaudRate);
mbed_official 340:28d1f895c6fe 1213 break;
mbed_official 631:825f75ca301e 1214 case IRDA_CLOCKSOURCE_UNDEFINED:
mbed_official 631:825f75ca301e 1215 default:
mbed_official 631:825f75ca301e 1216 ret = HAL_ERROR;
mbed_official 631:825f75ca301e 1217 break;
mbed_official 340:28d1f895c6fe 1218 }
mbed_official 631:825f75ca301e 1219
mbed_official 631:825f75ca301e 1220 return ret;
mbed_official 340:28d1f895c6fe 1221 }
mbed_official 340:28d1f895c6fe 1222
mbed_official 340:28d1f895c6fe 1223 /**
mbed_official 631:825f75ca301e 1224 * @brief Check the IRDA Idle State.
mbed_official 631:825f75ca301e 1225 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1226 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 1227 * @retval HAL status
mbed_official 340:28d1f895c6fe 1228 */
mbed_official 340:28d1f895c6fe 1229 static HAL_StatusTypeDef IRDA_CheckIdleState(IRDA_HandleTypeDef *hirda)
mbed_official 340:28d1f895c6fe 1230 {
mbed_official 340:28d1f895c6fe 1231
mbed_official 340:28d1f895c6fe 1232 /* Initialize the IRDA ErrorCode */
mbed_official 340:28d1f895c6fe 1233 hirda->ErrorCode = HAL_IRDA_ERROR_NONE;
mbed_official 340:28d1f895c6fe 1234
mbed_official 631:825f75ca301e 1235 /* TEACK and REACK bits in ISR are checked only when available (not available on all F0 devices).
mbed_official 631:825f75ca301e 1236 Bits are defined for some specific devices, and are available only for UART instances supporting WakeUp from Stop Mode feature.
mbed_official 631:825f75ca301e 1237 */
mbed_official 631:825f75ca301e 1238 #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
mbed_official 631:825f75ca301e 1239 if (IS_UART_WAKEUP_INSTANCE(hirda->Instance))
mbed_official 340:28d1f895c6fe 1240 {
mbed_official 631:825f75ca301e 1241 /* Check if the Transmitter is enabled */
mbed_official 631:825f75ca301e 1242 if((hirda->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
mbed_official 631:825f75ca301e 1243 {
mbed_official 631:825f75ca301e 1244 /* Wait until TEACK flag is set */
mbed_official 631:825f75ca301e 1245 if(IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_TEACK, RESET, IRDA_TEACK_REACK_TIMEOUT) != HAL_OK)
mbed_official 631:825f75ca301e 1246 {
mbed_official 631:825f75ca301e 1247 /* Timeout occurred */
mbed_official 631:825f75ca301e 1248 return HAL_TIMEOUT;
mbed_official 631:825f75ca301e 1249 }
mbed_official 631:825f75ca301e 1250 }
mbed_official 631:825f75ca301e 1251
mbed_official 340:28d1f895c6fe 1252 /* Check if the Receiver is enabled */
mbed_official 631:825f75ca301e 1253 if((hirda->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
mbed_official 631:825f75ca301e 1254 {
mbed_official 631:825f75ca301e 1255 /* Wait until REACK flag is set */
mbed_official 631:825f75ca301e 1256 if(IRDA_WaitOnFlagUntilTimeout(hirda, USART_ISR_REACK, RESET, IRDA_TEACK_REACK_TIMEOUT) != HAL_OK)
mbed_official 631:825f75ca301e 1257 {
mbed_official 631:825f75ca301e 1258 /* Timeout occurred */
mbed_official 631:825f75ca301e 1259 return HAL_TIMEOUT;
mbed_official 631:825f75ca301e 1260 }
mbed_official 631:825f75ca301e 1261 }
mbed_official 340:28d1f895c6fe 1262 }
mbed_official 631:825f75ca301e 1263 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
mbed_official 631:825f75ca301e 1264
mbed_official 340:28d1f895c6fe 1265 /* Initialize the IRDA state*/
mbed_official 631:825f75ca301e 1266 hirda->State= HAL_IRDA_STATE_READY;
mbed_official 631:825f75ca301e 1267
mbed_official 340:28d1f895c6fe 1268 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1269 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 1270
mbed_official 340:28d1f895c6fe 1271 return HAL_OK;
mbed_official 340:28d1f895c6fe 1272 }
mbed_official 340:28d1f895c6fe 1273
mbed_official 340:28d1f895c6fe 1274 /**
mbed_official 340:28d1f895c6fe 1275 * @brief Handle IRDA Communication Timeout.
mbed_official 631:825f75ca301e 1276 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1277 * the configuration information for the specified IRDA module.
mbed_official 340:28d1f895c6fe 1278 * @param Flag: specifies the IRDA flag to check.
mbed_official 631:825f75ca301e 1279 * @param Status: the new flag status (SET or RESET). The function is locked in a while loop as long as the flag remains set to Status.
mbed_official 340:28d1f895c6fe 1280 * @param Timeout: Timeout duration
mbed_official 340:28d1f895c6fe 1281 * @retval HAL status
mbed_official 340:28d1f895c6fe 1282 */
mbed_official 631:825f75ca301e 1283 static HAL_StatusTypeDef IRDA_WaitOnFlagUntilTimeout(IRDA_HandleTypeDef *hirda, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
mbed_official 340:28d1f895c6fe 1284 {
mbed_official 340:28d1f895c6fe 1285 uint32_t tickstart = HAL_GetTick();
mbed_official 631:825f75ca301e 1286
mbed_official 340:28d1f895c6fe 1287 /* Wait until flag is set */
mbed_official 340:28d1f895c6fe 1288 if(Status == RESET)
mbed_official 631:825f75ca301e 1289 {
mbed_official 340:28d1f895c6fe 1290 while(__HAL_IRDA_GET_FLAG(hirda, Flag) == RESET)
mbed_official 340:28d1f895c6fe 1291 {
mbed_official 340:28d1f895c6fe 1292 /* Check for the Timeout */
mbed_official 340:28d1f895c6fe 1293 if(Timeout != HAL_MAX_DELAY)
mbed_official 340:28d1f895c6fe 1294 {
mbed_official 631:825f75ca301e 1295 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
mbed_official 340:28d1f895c6fe 1296 {
mbed_official 340:28d1f895c6fe 1297 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
mbed_official 340:28d1f895c6fe 1298 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
mbed_official 340:28d1f895c6fe 1299 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
mbed_official 340:28d1f895c6fe 1300 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
mbed_official 340:28d1f895c6fe 1301 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 631:825f75ca301e 1302
mbed_official 442:d2c15dda23c1 1303 hirda->State= HAL_IRDA_STATE_READY;
mbed_official 631:825f75ca301e 1304
mbed_official 340:28d1f895c6fe 1305 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1306 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 1307
mbed_official 340:28d1f895c6fe 1308 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 1309 }
mbed_official 340:28d1f895c6fe 1310 }
mbed_official 340:28d1f895c6fe 1311 }
mbed_official 340:28d1f895c6fe 1312 }
mbed_official 340:28d1f895c6fe 1313 else
mbed_official 340:28d1f895c6fe 1314 {
mbed_official 340:28d1f895c6fe 1315 while(__HAL_IRDA_GET_FLAG(hirda, Flag) != RESET)
mbed_official 340:28d1f895c6fe 1316 {
mbed_official 340:28d1f895c6fe 1317 /* Check for the Timeout */
mbed_official 340:28d1f895c6fe 1318 if(Timeout != HAL_MAX_DELAY)
mbed_official 631:825f75ca301e 1319 {
mbed_official 631:825f75ca301e 1320 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
mbed_official 340:28d1f895c6fe 1321 {
mbed_official 340:28d1f895c6fe 1322 /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
mbed_official 340:28d1f895c6fe 1323 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
mbed_official 340:28d1f895c6fe 1324 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
mbed_official 340:28d1f895c6fe 1325 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
mbed_official 340:28d1f895c6fe 1326 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 631:825f75ca301e 1327
mbed_official 442:d2c15dda23c1 1328 hirda->State= HAL_IRDA_STATE_READY;
mbed_official 631:825f75ca301e 1329
mbed_official 340:28d1f895c6fe 1330 /* Process Unlocked */
mbed_official 340:28d1f895c6fe 1331 __HAL_UNLOCK(hirda);
mbed_official 631:825f75ca301e 1332
mbed_official 340:28d1f895c6fe 1333 return HAL_TIMEOUT;
mbed_official 340:28d1f895c6fe 1334 }
mbed_official 340:28d1f895c6fe 1335 }
mbed_official 340:28d1f895c6fe 1336 }
mbed_official 340:28d1f895c6fe 1337 }
mbed_official 631:825f75ca301e 1338 return HAL_OK;
mbed_official 631:825f75ca301e 1339 }
mbed_official 631:825f75ca301e 1340
mbed_official 631:825f75ca301e 1341 /**
mbed_official 631:825f75ca301e 1342 * @brief DMA IRDA transmit process complete callback.
mbed_official 631:825f75ca301e 1343 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1344 * the configuration information for the specified DMA module.
mbed_official 631:825f75ca301e 1345 * @retval None
mbed_official 631:825f75ca301e 1346 */
mbed_official 631:825f75ca301e 1347 static void IRDA_DMATransmitCplt(DMA_HandleTypeDef *hdma)
mbed_official 631:825f75ca301e 1348 {
mbed_official 631:825f75ca301e 1349 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 631:825f75ca301e 1350
mbed_official 631:825f75ca301e 1351 /* DMA Normal mode */
mbed_official 631:825f75ca301e 1352 if ( HAL_IS_BIT_CLR(hdma->Instance->CCR, DMA_CCR_CIRC) )
mbed_official 631:825f75ca301e 1353 {
mbed_official 631:825f75ca301e 1354 hirda->TxXferCount = 0;
mbed_official 631:825f75ca301e 1355
mbed_official 631:825f75ca301e 1356 /* Disable the DMA transfer for transmit request by resetting the DMAT bit
mbed_official 631:825f75ca301e 1357 in the IRDA CR3 register */
mbed_official 631:825f75ca301e 1358 hirda->Instance->CR3 &= ~(USART_CR3_DMAT);
mbed_official 631:825f75ca301e 1359
mbed_official 631:825f75ca301e 1360 /* Enable the IRDA Transmit Complete Interrupt */
mbed_official 631:825f75ca301e 1361 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TC);
mbed_official 631:825f75ca301e 1362 }
mbed_official 631:825f75ca301e 1363 /* DMA Circular mode */
mbed_official 631:825f75ca301e 1364 else
mbed_official 631:825f75ca301e 1365 {
mbed_official 631:825f75ca301e 1366 HAL_IRDA_TxCpltCallback(hirda);
mbed_official 631:825f75ca301e 1367 }
mbed_official 631:825f75ca301e 1368 }
mbed_official 631:825f75ca301e 1369
mbed_official 631:825f75ca301e 1370 /**
mbed_official 631:825f75ca301e 1371 * @brief DMA IRDA transmit process half complete callback.
mbed_official 631:825f75ca301e 1372 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1373 * the configuration information for the specified DMA module.
mbed_official 631:825f75ca301e 1374 * @retval None
mbed_official 631:825f75ca301e 1375 */
mbed_official 631:825f75ca301e 1376 static void IRDA_DMATransmitHalfCplt(DMA_HandleTypeDef *hdma)
mbed_official 631:825f75ca301e 1377 {
mbed_official 631:825f75ca301e 1378 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 631:825f75ca301e 1379
mbed_official 631:825f75ca301e 1380 HAL_IRDA_TxHalfCpltCallback(hirda);
mbed_official 631:825f75ca301e 1381 }
mbed_official 631:825f75ca301e 1382
mbed_official 631:825f75ca301e 1383 /**
mbed_official 631:825f75ca301e 1384 * @brief DMA IRDA receive process complete callback.
mbed_official 631:825f75ca301e 1385 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1386 * the configuration information for the specified DMA module.
mbed_official 631:825f75ca301e 1387 * @retval None
mbed_official 631:825f75ca301e 1388 */
mbed_official 631:825f75ca301e 1389 static void IRDA_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
mbed_official 631:825f75ca301e 1390 {
mbed_official 631:825f75ca301e 1391 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 631:825f75ca301e 1392
mbed_official 631:825f75ca301e 1393 /* DMA Normal mode */
mbed_official 631:825f75ca301e 1394 if ( HAL_IS_BIT_CLR(hdma->Instance->CCR, DMA_CCR_CIRC) )
mbed_official 631:825f75ca301e 1395 {
mbed_official 631:825f75ca301e 1396 hirda->RxXferCount = 0;
mbed_official 631:825f75ca301e 1397
mbed_official 631:825f75ca301e 1398 /* Disable the DMA transfer for the receiver request by resetting the DMAR bit
mbed_official 631:825f75ca301e 1399 in the IRDA CR3 register */
mbed_official 631:825f75ca301e 1400 hirda->Instance->CR3 &= ~(USART_CR3_DMAR);
mbed_official 631:825f75ca301e 1401
mbed_official 631:825f75ca301e 1402 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 631:825f75ca301e 1403 {
mbed_official 631:825f75ca301e 1404 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 631:825f75ca301e 1405 }
mbed_official 631:825f75ca301e 1406 else
mbed_official 631:825f75ca301e 1407 {
mbed_official 631:825f75ca301e 1408 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 631:825f75ca301e 1409 }
mbed_official 631:825f75ca301e 1410 }
mbed_official 631:825f75ca301e 1411
mbed_official 631:825f75ca301e 1412 HAL_IRDA_RxCpltCallback(hirda);
mbed_official 631:825f75ca301e 1413 }
mbed_official 631:825f75ca301e 1414
mbed_official 631:825f75ca301e 1415 /**
mbed_official 631:825f75ca301e 1416 * @brief DMA IRDA receive process half complete callback.
mbed_official 631:825f75ca301e 1417 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1418 * the configuration information for the specified DMA module.
mbed_official 631:825f75ca301e 1419 * @retval None
mbed_official 631:825f75ca301e 1420 */
mbed_official 631:825f75ca301e 1421 static void IRDA_DMAReceiveHalfCplt(DMA_HandleTypeDef *hdma)
mbed_official 631:825f75ca301e 1422 {
mbed_official 631:825f75ca301e 1423 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 631:825f75ca301e 1424
mbed_official 631:825f75ca301e 1425 HAL_IRDA_RxHalfCpltCallback(hirda);
mbed_official 631:825f75ca301e 1426 }
mbed_official 631:825f75ca301e 1427
mbed_official 631:825f75ca301e 1428 /**
mbed_official 631:825f75ca301e 1429 * @brief DMA IRDA communication error callback.
mbed_official 631:825f75ca301e 1430 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1431 * the configuration information for the specified DMA module.
mbed_official 631:825f75ca301e 1432 * @retval None
mbed_official 631:825f75ca301e 1433 */
mbed_official 631:825f75ca301e 1434 static void IRDA_DMAError(DMA_HandleTypeDef *hdma)
mbed_official 631:825f75ca301e 1435 {
mbed_official 631:825f75ca301e 1436 IRDA_HandleTypeDef* hirda = ( IRDA_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
mbed_official 631:825f75ca301e 1437
mbed_official 631:825f75ca301e 1438 hirda->RxXferCount = 0;
mbed_official 631:825f75ca301e 1439 hirda->TxXferCount = 0;
mbed_official 631:825f75ca301e 1440 hirda->ErrorCode |= HAL_IRDA_ERROR_DMA;
mbed_official 631:825f75ca301e 1441 hirda->State= HAL_IRDA_STATE_READY;
mbed_official 631:825f75ca301e 1442
mbed_official 631:825f75ca301e 1443 HAL_IRDA_ErrorCallback(hirda);
mbed_official 631:825f75ca301e 1444 }
mbed_official 631:825f75ca301e 1445
mbed_official 631:825f75ca301e 1446
mbed_official 631:825f75ca301e 1447 /**
mbed_official 631:825f75ca301e 1448 * @brief Send an amount of data in non-blocking mode.
mbed_official 631:825f75ca301e 1449 * @note Function is called under interruption only, once
mbed_official 631:825f75ca301e 1450 * interruptions have been enabled by HAL_IRDA_Transmit_IT().
mbed_official 631:825f75ca301e 1451 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1452 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 1453 * @retval HAL status
mbed_official 631:825f75ca301e 1454 */
mbed_official 631:825f75ca301e 1455 static HAL_StatusTypeDef IRDA_Transmit_IT(IRDA_HandleTypeDef *hirda)
mbed_official 631:825f75ca301e 1456 {
mbed_official 631:825f75ca301e 1457 uint16_t* tmp;
mbed_official 631:825f75ca301e 1458
mbed_official 631:825f75ca301e 1459 if((hirda->State == HAL_IRDA_STATE_BUSY_TX) || (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX))
mbed_official 631:825f75ca301e 1460 {
mbed_official 631:825f75ca301e 1461 if(hirda->TxXferCount == 0)
mbed_official 631:825f75ca301e 1462 {
mbed_official 631:825f75ca301e 1463 /* Disable the IRDA Transmit Data Register Empty Interrupt */
mbed_official 631:825f75ca301e 1464 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TXE);
mbed_official 631:825f75ca301e 1465
mbed_official 631:825f75ca301e 1466 /* Enable the IRDA Transmit Complete Interrupt */
mbed_official 631:825f75ca301e 1467 __HAL_IRDA_ENABLE_IT(hirda, IRDA_IT_TC);
mbed_official 631:825f75ca301e 1468
mbed_official 631:825f75ca301e 1469 return HAL_OK;
mbed_official 631:825f75ca301e 1470 }
mbed_official 631:825f75ca301e 1471 else
mbed_official 631:825f75ca301e 1472 {
mbed_official 631:825f75ca301e 1473 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
mbed_official 631:825f75ca301e 1474 {
mbed_official 631:825f75ca301e 1475 tmp = (uint16_t*) hirda->pTxBuffPtr;
mbed_official 631:825f75ca301e 1476 hirda->Instance->TDR = (*tmp & (uint16_t)0x01FF);
mbed_official 631:825f75ca301e 1477 hirda->pTxBuffPtr += 2;
mbed_official 631:825f75ca301e 1478 }
mbed_official 631:825f75ca301e 1479 else
mbed_official 631:825f75ca301e 1480 {
mbed_official 631:825f75ca301e 1481 hirda->Instance->TDR = (uint8_t)(*hirda->pTxBuffPtr++ & (uint8_t)0xFF);
mbed_official 631:825f75ca301e 1482 }
mbed_official 631:825f75ca301e 1483 hirda->TxXferCount--;
mbed_official 631:825f75ca301e 1484
mbed_official 631:825f75ca301e 1485 return HAL_OK;
mbed_official 631:825f75ca301e 1486 }
mbed_official 631:825f75ca301e 1487 }
mbed_official 631:825f75ca301e 1488 else
mbed_official 631:825f75ca301e 1489 {
mbed_official 631:825f75ca301e 1490 return HAL_BUSY;
mbed_official 631:825f75ca301e 1491 }
mbed_official 631:825f75ca301e 1492 }
mbed_official 631:825f75ca301e 1493
mbed_official 631:825f75ca301e 1494 /**
mbed_official 631:825f75ca301e 1495 * @brief Wrap up transmission in non-blocking mode.
mbed_official 631:825f75ca301e 1496 * @param hirda: pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1497 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 1498 * @retval HAL status
mbed_official 631:825f75ca301e 1499 */
mbed_official 631:825f75ca301e 1500 static HAL_StatusTypeDef IRDA_EndTransmit_IT(IRDA_HandleTypeDef *hirda)
mbed_official 631:825f75ca301e 1501 {
mbed_official 631:825f75ca301e 1502 /* Disable the IRDA Transmit Complete Interrupt */
mbed_official 631:825f75ca301e 1503 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_TC);
mbed_official 631:825f75ca301e 1504
mbed_official 631:825f75ca301e 1505 /* Check if a receive process is ongoing or not */
mbed_official 631:825f75ca301e 1506 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 631:825f75ca301e 1507 {
mbed_official 631:825f75ca301e 1508 hirda->State = HAL_IRDA_STATE_BUSY_RX;
mbed_official 631:825f75ca301e 1509 }
mbed_official 631:825f75ca301e 1510 else
mbed_official 631:825f75ca301e 1511 {
mbed_official 631:825f75ca301e 1512 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 631:825f75ca301e 1513 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 631:825f75ca301e 1514
mbed_official 631:825f75ca301e 1515 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 631:825f75ca301e 1516 }
mbed_official 631:825f75ca301e 1517
mbed_official 631:825f75ca301e 1518 HAL_IRDA_TxCpltCallback(hirda);
mbed_official 631:825f75ca301e 1519
mbed_official 631:825f75ca301e 1520 return HAL_OK;
mbed_official 631:825f75ca301e 1521 }
mbed_official 631:825f75ca301e 1522
mbed_official 631:825f75ca301e 1523
mbed_official 631:825f75ca301e 1524 /**
mbed_official 631:825f75ca301e 1525 * @brief Receive an amount of data in non-blocking mode.
mbed_official 631:825f75ca301e 1526 * Function is called under interruption only, once
mbed_official 631:825f75ca301e 1527 * interruptions have been enabled by HAL_IRDA_Receive_IT().
mbed_official 631:825f75ca301e 1528 * @param hirda: Pointer to a IRDA_HandleTypeDef structure that contains
mbed_official 631:825f75ca301e 1529 * the configuration information for the specified IRDA module.
mbed_official 631:825f75ca301e 1530 * @retval HAL status
mbed_official 631:825f75ca301e 1531 */
mbed_official 631:825f75ca301e 1532 static HAL_StatusTypeDef IRDA_Receive_IT(IRDA_HandleTypeDef *hirda)
mbed_official 631:825f75ca301e 1533 {
mbed_official 631:825f75ca301e 1534 uint16_t* tmp;
mbed_official 631:825f75ca301e 1535 uint16_t uhMask = hirda->Mask;
mbed_official 631:825f75ca301e 1536
mbed_official 631:825f75ca301e 1537 if ((hirda->State == HAL_IRDA_STATE_BUSY_RX) || (hirda->State == HAL_IRDA_STATE_BUSY_TX_RX))
mbed_official 631:825f75ca301e 1538 {
mbed_official 631:825f75ca301e 1539
mbed_official 631:825f75ca301e 1540 if ((hirda->Init.WordLength == IRDA_WORDLENGTH_9B) && (hirda->Init.Parity == IRDA_PARITY_NONE))
mbed_official 631:825f75ca301e 1541 {
mbed_official 631:825f75ca301e 1542 tmp = (uint16_t*) hirda->pRxBuffPtr ;
mbed_official 631:825f75ca301e 1543 *tmp = (uint16_t)(hirda->Instance->RDR & uhMask);
mbed_official 631:825f75ca301e 1544 hirda->pRxBuffPtr +=2;
mbed_official 631:825f75ca301e 1545 }
mbed_official 631:825f75ca301e 1546 else
mbed_official 631:825f75ca301e 1547 {
mbed_official 631:825f75ca301e 1548 *hirda->pRxBuffPtr++ = (uint8_t)(hirda->Instance->RDR & (uint8_t)uhMask);
mbed_official 631:825f75ca301e 1549 }
mbed_official 631:825f75ca301e 1550
mbed_official 631:825f75ca301e 1551 if(--hirda->RxXferCount == 0)
mbed_official 631:825f75ca301e 1552 {
mbed_official 631:825f75ca301e 1553 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_RXNE);
mbed_official 631:825f75ca301e 1554
mbed_official 631:825f75ca301e 1555 if(hirda->State == HAL_IRDA_STATE_BUSY_TX_RX)
mbed_official 631:825f75ca301e 1556 {
mbed_official 631:825f75ca301e 1557 hirda->State = HAL_IRDA_STATE_BUSY_TX;
mbed_official 631:825f75ca301e 1558 }
mbed_official 631:825f75ca301e 1559 else
mbed_official 631:825f75ca301e 1560 {
mbed_official 631:825f75ca301e 1561 /* Disable the IRDA Parity Error Interrupt */
mbed_official 631:825f75ca301e 1562 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_PE);
mbed_official 631:825f75ca301e 1563
mbed_official 631:825f75ca301e 1564 /* Disable the IRDA Error Interrupt: (Frame error, noise error, overrun error) */
mbed_official 631:825f75ca301e 1565 __HAL_IRDA_DISABLE_IT(hirda, IRDA_IT_ERR);
mbed_official 631:825f75ca301e 1566
mbed_official 631:825f75ca301e 1567 hirda->State = HAL_IRDA_STATE_READY;
mbed_official 631:825f75ca301e 1568 }
mbed_official 631:825f75ca301e 1569
mbed_official 631:825f75ca301e 1570 HAL_IRDA_RxCpltCallback(hirda);
mbed_official 631:825f75ca301e 1571
mbed_official 631:825f75ca301e 1572 return HAL_OK;
mbed_official 631:825f75ca301e 1573 }
mbed_official 631:825f75ca301e 1574
mbed_official 631:825f75ca301e 1575 return HAL_OK;
mbed_official 631:825f75ca301e 1576 }
mbed_official 631:825f75ca301e 1577 else
mbed_official 631:825f75ca301e 1578 {
mbed_official 631:825f75ca301e 1579 return HAL_BUSY;
mbed_official 631:825f75ca301e 1580 }
mbed_official 340:28d1f895c6fe 1581 }
mbed_official 340:28d1f895c6fe 1582
mbed_official 340:28d1f895c6fe 1583 /**
mbed_official 340:28d1f895c6fe 1584 * @}
mbed_official 340:28d1f895c6fe 1585 */
mbed_official 340:28d1f895c6fe 1586
mbed_official 340:28d1f895c6fe 1587 /**
mbed_official 340:28d1f895c6fe 1588 * @}
mbed_official 340:28d1f895c6fe 1589 */
mbed_official 340:28d1f895c6fe 1590
mbed_official 340:28d1f895c6fe 1591 /**
mbed_official 340:28d1f895c6fe 1592 * @}
mbed_official 340:28d1f895c6fe 1593 */
mbed_official 340:28d1f895c6fe 1594
mbed_official 631:825f75ca301e 1595 #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
mbed_official 442:d2c15dda23c1 1596
mbed_official 442:d2c15dda23c1 1597 #endif /* HAL_IRDA_MODULE_ENABLED */
mbed_official 442:d2c15dda23c1 1598
mbed_official 340:28d1f895c6fe 1599 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/