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