Mouse code for the MacroRat
mbed-dev/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_cec.c@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /** |
sahilmgandhi | 18:6a4db94011d3 | 2 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @file stm32f4xx_hal_cec.c |
sahilmgandhi | 18:6a4db94011d3 | 4 | * @author MCD Application Team |
sahilmgandhi | 18:6a4db94011d3 | 5 | * @version V1.5.0 |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @date 06-May-2016 |
sahilmgandhi | 18:6a4db94011d3 | 7 | * @brief CEC HAL module driver. |
sahilmgandhi | 18:6a4db94011d3 | 8 | * This file provides firmware functions to manage the following |
sahilmgandhi | 18:6a4db94011d3 | 9 | * functionalities of the High Definition Multimedia Interface |
sahilmgandhi | 18:6a4db94011d3 | 10 | * Consumer Electronics Control Peripheral (CEC). |
sahilmgandhi | 18:6a4db94011d3 | 11 | * + Initialization and de-initialization functions |
sahilmgandhi | 18:6a4db94011d3 | 12 | * + IO operation functions |
sahilmgandhi | 18:6a4db94011d3 | 13 | * + Peripheral Control functions |
sahilmgandhi | 18:6a4db94011d3 | 14 | * |
sahilmgandhi | 18:6a4db94011d3 | 15 | * |
sahilmgandhi | 18:6a4db94011d3 | 16 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 17 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 18 | ##### How to use this driver ##### |
sahilmgandhi | 18:6a4db94011d3 | 19 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 20 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 21 | The CEC HAL driver can be used as follow: |
sahilmgandhi | 18:6a4db94011d3 | 22 | |
sahilmgandhi | 18:6a4db94011d3 | 23 | (#) Declare a CEC_HandleTypeDef handle structure. |
sahilmgandhi | 18:6a4db94011d3 | 24 | (#) Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API: |
sahilmgandhi | 18:6a4db94011d3 | 25 | (##) Enable the CEC interface clock. |
sahilmgandhi | 18:6a4db94011d3 | 26 | (##) CEC pins configuration: |
sahilmgandhi | 18:6a4db94011d3 | 27 | (+) Enable the clock for the CEC GPIOs. |
sahilmgandhi | 18:6a4db94011d3 | 28 | (+) Configure these CEC pins as alternate function pull-up. |
sahilmgandhi | 18:6a4db94011d3 | 29 | (##) NVIC configuration if you need to use interrupt process (HAL_CEC_Transmit_IT() |
sahilmgandhi | 18:6a4db94011d3 | 30 | and HAL_CEC_Receive_IT() APIs): |
sahilmgandhi | 18:6a4db94011d3 | 31 | (+) Configure the CEC interrupt priority. |
sahilmgandhi | 18:6a4db94011d3 | 32 | (+) Enable the NVIC CEC IRQ handle. |
sahilmgandhi | 18:6a4db94011d3 | 33 | (@) The specific CEC interrupts (Transmission complete interrupt, |
sahilmgandhi | 18:6a4db94011d3 | 34 | RXNE interrupt and Error Interrupts) will be managed using the macros |
sahilmgandhi | 18:6a4db94011d3 | 35 | __HAL_CEC_ENABLE_IT() and __HAL_CEC_DISABLE_IT() inside the transmit |
sahilmgandhi | 18:6a4db94011d3 | 36 | and receive process. |
sahilmgandhi | 18:6a4db94011d3 | 37 | |
sahilmgandhi | 18:6a4db94011d3 | 38 | (#) Program the Signal Free Time (SFT) and SFT option, Tolerance, reception stop in |
sahilmgandhi | 18:6a4db94011d3 | 39 | in case of Bit Rising Error, Error-Bit generation conditions, device logical |
sahilmgandhi | 18:6a4db94011d3 | 40 | address and Listen mode in the hcec Init structure. |
sahilmgandhi | 18:6a4db94011d3 | 41 | |
sahilmgandhi | 18:6a4db94011d3 | 42 | (#) Initialize the CEC registers by calling the HAL_CEC_Init() API. |
sahilmgandhi | 18:6a4db94011d3 | 43 | |
sahilmgandhi | 18:6a4db94011d3 | 44 | (@) This API (HAL_CEC_Init()) configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) |
sahilmgandhi | 18:6a4db94011d3 | 45 | by calling the customed HAL_CEC_MspInit() API. |
sahilmgandhi | 18:6a4db94011d3 | 46 | |
sahilmgandhi | 18:6a4db94011d3 | 47 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 48 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 49 | * @attention |
sahilmgandhi | 18:6a4db94011d3 | 50 | * |
sahilmgandhi | 18:6a4db94011d3 | 51 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
sahilmgandhi | 18:6a4db94011d3 | 52 | * |
sahilmgandhi | 18:6a4db94011d3 | 53 | * Redistribution and use in source and binary forms, with or without modification, |
sahilmgandhi | 18:6a4db94011d3 | 54 | * are permitted provided that the following conditions are met: |
sahilmgandhi | 18:6a4db94011d3 | 55 | * 1. Redistributions of source code must retain the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 56 | * this list of conditions and the following disclaimer. |
sahilmgandhi | 18:6a4db94011d3 | 57 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 58 | * this list of conditions and the following disclaimer in the documentation |
sahilmgandhi | 18:6a4db94011d3 | 59 | * and/or other materials provided with the distribution. |
sahilmgandhi | 18:6a4db94011d3 | 60 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
sahilmgandhi | 18:6a4db94011d3 | 61 | * may be used to endorse or promote products derived from this software |
sahilmgandhi | 18:6a4db94011d3 | 62 | * without specific prior written permission. |
sahilmgandhi | 18:6a4db94011d3 | 63 | * |
sahilmgandhi | 18:6a4db94011d3 | 64 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
sahilmgandhi | 18:6a4db94011d3 | 65 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
sahilmgandhi | 18:6a4db94011d3 | 66 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
sahilmgandhi | 18:6a4db94011d3 | 67 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
sahilmgandhi | 18:6a4db94011d3 | 68 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
sahilmgandhi | 18:6a4db94011d3 | 69 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
sahilmgandhi | 18:6a4db94011d3 | 70 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
sahilmgandhi | 18:6a4db94011d3 | 71 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
sahilmgandhi | 18:6a4db94011d3 | 72 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
sahilmgandhi | 18:6a4db94011d3 | 73 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
sahilmgandhi | 18:6a4db94011d3 | 74 | * |
sahilmgandhi | 18:6a4db94011d3 | 75 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 76 | */ |
sahilmgandhi | 18:6a4db94011d3 | 77 | |
sahilmgandhi | 18:6a4db94011d3 | 78 | /* Includes ------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 79 | #include "stm32f4xx_hal.h" |
sahilmgandhi | 18:6a4db94011d3 | 80 | |
sahilmgandhi | 18:6a4db94011d3 | 81 | /** @addtogroup STM32F4xx_HAL_Driver |
sahilmgandhi | 18:6a4db94011d3 | 82 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 83 | */ |
sahilmgandhi | 18:6a4db94011d3 | 84 | |
sahilmgandhi | 18:6a4db94011d3 | 85 | /** @defgroup CEC CEC |
sahilmgandhi | 18:6a4db94011d3 | 86 | * @brief HAL CEC module driver |
sahilmgandhi | 18:6a4db94011d3 | 87 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 88 | */ |
sahilmgandhi | 18:6a4db94011d3 | 89 | #ifdef HAL_CEC_MODULE_ENABLED |
sahilmgandhi | 18:6a4db94011d3 | 90 | |
sahilmgandhi | 18:6a4db94011d3 | 91 | #if defined(STM32F446xx) |
sahilmgandhi | 18:6a4db94011d3 | 92 | |
sahilmgandhi | 18:6a4db94011d3 | 93 | /* Private typedef -----------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 94 | /* Private define ------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 95 | /** @defgroup CEC_Private_Constants CEC Private Constants |
sahilmgandhi | 18:6a4db94011d3 | 96 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 97 | */ |
sahilmgandhi | 18:6a4db94011d3 | 98 | /** |
sahilmgandhi | 18:6a4db94011d3 | 99 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 100 | */ |
sahilmgandhi | 18:6a4db94011d3 | 101 | |
sahilmgandhi | 18:6a4db94011d3 | 102 | /* Private macro -------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 103 | /* Private variables ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 104 | /* Private function prototypes -----------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 105 | /** @defgroup CEC_Private_Functions CEC Private Functions |
sahilmgandhi | 18:6a4db94011d3 | 106 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 107 | */ |
sahilmgandhi | 18:6a4db94011d3 | 108 | /** |
sahilmgandhi | 18:6a4db94011d3 | 109 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 110 | */ |
sahilmgandhi | 18:6a4db94011d3 | 111 | |
sahilmgandhi | 18:6a4db94011d3 | 112 | /* Exported functions ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 113 | |
sahilmgandhi | 18:6a4db94011d3 | 114 | /** @defgroup CEC_Exported_Functions CEC Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 115 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 116 | */ |
sahilmgandhi | 18:6a4db94011d3 | 117 | |
sahilmgandhi | 18:6a4db94011d3 | 118 | /** @defgroup CEC_Exported_Functions_Group1 Initialization and de-initialization functions |
sahilmgandhi | 18:6a4db94011d3 | 119 | * @brief Initialization and Configuration functions |
sahilmgandhi | 18:6a4db94011d3 | 120 | * |
sahilmgandhi | 18:6a4db94011d3 | 121 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 122 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 123 | ##### Initialization and Configuration functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 124 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 125 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 126 | This subsection provides a set of functions allowing to initialize the CEC |
sahilmgandhi | 18:6a4db94011d3 | 127 | (+) The following parameters need to be configured: |
sahilmgandhi | 18:6a4db94011d3 | 128 | (++) SignalFreeTime |
sahilmgandhi | 18:6a4db94011d3 | 129 | (++) Tolerance |
sahilmgandhi | 18:6a4db94011d3 | 130 | (++) BRERxStop (RX stopped or not upon Bit Rising Error) |
sahilmgandhi | 18:6a4db94011d3 | 131 | (++) BREErrorBitGen (Error-Bit generation in case of Bit Rising Error) |
sahilmgandhi | 18:6a4db94011d3 | 132 | (++) LBPEErrorBitGen (Error-Bit generation in case of Long Bit Period Error) |
sahilmgandhi | 18:6a4db94011d3 | 133 | (++) BroadcastMsgNoErrorBitGen (Error-bit generation in case of broadcast message error) |
sahilmgandhi | 18:6a4db94011d3 | 134 | (++) SignalFreeTimeOption (SFT Timer start definition) |
sahilmgandhi | 18:6a4db94011d3 | 135 | (++) OwnAddress (CEC device address) |
sahilmgandhi | 18:6a4db94011d3 | 136 | (++) ListenMode |
sahilmgandhi | 18:6a4db94011d3 | 137 | |
sahilmgandhi | 18:6a4db94011d3 | 138 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 139 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 140 | */ |
sahilmgandhi | 18:6a4db94011d3 | 141 | |
sahilmgandhi | 18:6a4db94011d3 | 142 | /** |
sahilmgandhi | 18:6a4db94011d3 | 143 | * @brief Initializes the CEC mode according to the specified |
sahilmgandhi | 18:6a4db94011d3 | 144 | * parameters in the CEC_InitTypeDef and creates the associated handle . |
sahilmgandhi | 18:6a4db94011d3 | 145 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 146 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 147 | */ |
sahilmgandhi | 18:6a4db94011d3 | 148 | HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec) |
sahilmgandhi | 18:6a4db94011d3 | 149 | { |
sahilmgandhi | 18:6a4db94011d3 | 150 | /* Check the CEC handle allocation */ |
sahilmgandhi | 18:6a4db94011d3 | 151 | if((hcec == NULL) ||(hcec->Init.RxBuffer == NULL)) |
sahilmgandhi | 18:6a4db94011d3 | 152 | { |
sahilmgandhi | 18:6a4db94011d3 | 153 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 154 | } |
sahilmgandhi | 18:6a4db94011d3 | 155 | |
sahilmgandhi | 18:6a4db94011d3 | 156 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 157 | assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance)); |
sahilmgandhi | 18:6a4db94011d3 | 158 | assert_param(IS_CEC_SIGNALFREETIME(hcec->Init.SignalFreeTime)); |
sahilmgandhi | 18:6a4db94011d3 | 159 | assert_param(IS_CEC_TOLERANCE(hcec->Init.Tolerance)); |
sahilmgandhi | 18:6a4db94011d3 | 160 | assert_param(IS_CEC_BRERXSTOP(hcec->Init.BRERxStop)); |
sahilmgandhi | 18:6a4db94011d3 | 161 | assert_param(IS_CEC_BREERRORBITGEN(hcec->Init.BREErrorBitGen)); |
sahilmgandhi | 18:6a4db94011d3 | 162 | assert_param(IS_CEC_LBPEERRORBITGEN(hcec->Init.LBPEErrorBitGen)); |
sahilmgandhi | 18:6a4db94011d3 | 163 | assert_param(IS_CEC_BROADCASTERROR_NO_ERRORBIT_GENERATION(hcec->Init.BroadcastMsgNoErrorBitGen)); |
sahilmgandhi | 18:6a4db94011d3 | 164 | assert_param(IS_CEC_SFTOP(hcec->Init.SignalFreeTimeOption)); |
sahilmgandhi | 18:6a4db94011d3 | 165 | assert_param(IS_CEC_LISTENING_MODE(hcec->Init.ListenMode)); |
sahilmgandhi | 18:6a4db94011d3 | 166 | assert_param(IS_CEC_OWN_ADDRESS(hcec->Init.OwnAddress)); |
sahilmgandhi | 18:6a4db94011d3 | 167 | |
sahilmgandhi | 18:6a4db94011d3 | 168 | if(hcec->gState == HAL_CEC_STATE_RESET) |
sahilmgandhi | 18:6a4db94011d3 | 169 | { |
sahilmgandhi | 18:6a4db94011d3 | 170 | /* Allocate lock resource and initialize it */ |
sahilmgandhi | 18:6a4db94011d3 | 171 | hcec->Lock = HAL_UNLOCKED; |
sahilmgandhi | 18:6a4db94011d3 | 172 | /* Init the low level hardware : GPIO, CLOCK */ |
sahilmgandhi | 18:6a4db94011d3 | 173 | HAL_CEC_MspInit(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 174 | } |
sahilmgandhi | 18:6a4db94011d3 | 175 | hcec->gState = HAL_CEC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 176 | |
sahilmgandhi | 18:6a4db94011d3 | 177 | /* Disable the Peripheral */ |
sahilmgandhi | 18:6a4db94011d3 | 178 | __HAL_CEC_DISABLE(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 179 | |
sahilmgandhi | 18:6a4db94011d3 | 180 | /* Write to CEC Control Register */ |
sahilmgandhi | 18:6a4db94011d3 | 181 | hcec->Instance->CFGR = hcec->Init.SignalFreeTime | hcec->Init.Tolerance | hcec->Init.BRERxStop|\ |
sahilmgandhi | 18:6a4db94011d3 | 182 | hcec->Init.BREErrorBitGen | hcec->Init.LBPEErrorBitGen | hcec->Init.BroadcastMsgNoErrorBitGen |\ |
sahilmgandhi | 18:6a4db94011d3 | 183 | hcec->Init.SignalFreeTimeOption |((uint32_t)(hcec->Init.OwnAddress)<<16U) |\ |
sahilmgandhi | 18:6a4db94011d3 | 184 | hcec->Init.ListenMode; |
sahilmgandhi | 18:6a4db94011d3 | 185 | |
sahilmgandhi | 18:6a4db94011d3 | 186 | /* Enable the following CEC Transmission/Reception interrupts as |
sahilmgandhi | 18:6a4db94011d3 | 187 | * well as the following CEC Transmission/Reception Errors interrupts |
sahilmgandhi | 18:6a4db94011d3 | 188 | * Rx Byte Received IT |
sahilmgandhi | 18:6a4db94011d3 | 189 | * End of Reception IT |
sahilmgandhi | 18:6a4db94011d3 | 190 | * Rx overrun |
sahilmgandhi | 18:6a4db94011d3 | 191 | * Rx bit rising error |
sahilmgandhi | 18:6a4db94011d3 | 192 | * Rx short bit period error |
sahilmgandhi | 18:6a4db94011d3 | 193 | * Rx long bit period error |
sahilmgandhi | 18:6a4db94011d3 | 194 | * Rx missing acknowledge |
sahilmgandhi | 18:6a4db94011d3 | 195 | * Tx Byte Request IT |
sahilmgandhi | 18:6a4db94011d3 | 196 | * End of Transmission IT |
sahilmgandhi | 18:6a4db94011d3 | 197 | * Tx Missing Acknowledge IT |
sahilmgandhi | 18:6a4db94011d3 | 198 | * Tx-Error IT |
sahilmgandhi | 18:6a4db94011d3 | 199 | * Tx-Buffer Underrun IT |
sahilmgandhi | 18:6a4db94011d3 | 200 | * Tx arbitration lost */ |
sahilmgandhi | 18:6a4db94011d3 | 201 | __HAL_CEC_ENABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND|CEC_IER_RX_ALL_ERR|CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR); |
sahilmgandhi | 18:6a4db94011d3 | 202 | |
sahilmgandhi | 18:6a4db94011d3 | 203 | /* Enable the CEC Peripheral */ |
sahilmgandhi | 18:6a4db94011d3 | 204 | __HAL_CEC_ENABLE(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 205 | |
sahilmgandhi | 18:6a4db94011d3 | 206 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
sahilmgandhi | 18:6a4db94011d3 | 207 | hcec->gState = HAL_CEC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 208 | hcec->RxState = HAL_CEC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 209 | |
sahilmgandhi | 18:6a4db94011d3 | 210 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 211 | } |
sahilmgandhi | 18:6a4db94011d3 | 212 | |
sahilmgandhi | 18:6a4db94011d3 | 213 | /** |
sahilmgandhi | 18:6a4db94011d3 | 214 | * @brief DeInitializes the CEC peripheral |
sahilmgandhi | 18:6a4db94011d3 | 215 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 216 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 217 | */ |
sahilmgandhi | 18:6a4db94011d3 | 218 | HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec) |
sahilmgandhi | 18:6a4db94011d3 | 219 | { |
sahilmgandhi | 18:6a4db94011d3 | 220 | /* Check the CEC handle allocation */ |
sahilmgandhi | 18:6a4db94011d3 | 221 | if(hcec == NULL) |
sahilmgandhi | 18:6a4db94011d3 | 222 | { |
sahilmgandhi | 18:6a4db94011d3 | 223 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 224 | } |
sahilmgandhi | 18:6a4db94011d3 | 225 | |
sahilmgandhi | 18:6a4db94011d3 | 226 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 227 | assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance)); |
sahilmgandhi | 18:6a4db94011d3 | 228 | |
sahilmgandhi | 18:6a4db94011d3 | 229 | hcec->gState = HAL_CEC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 230 | |
sahilmgandhi | 18:6a4db94011d3 | 231 | /* DeInit the low level hardware */ |
sahilmgandhi | 18:6a4db94011d3 | 232 | HAL_CEC_MspDeInit(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 233 | /* Disable the Peripheral */ |
sahilmgandhi | 18:6a4db94011d3 | 234 | __HAL_CEC_DISABLE(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 235 | |
sahilmgandhi | 18:6a4db94011d3 | 236 | /* Clear Flags */ |
sahilmgandhi | 18:6a4db94011d3 | 237 | __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXEND|CEC_FLAG_TXBR|CEC_FLAG_RXBR|CEC_FLAG_RXEND|CEC_ISR_ALL_ERROR); |
sahilmgandhi | 18:6a4db94011d3 | 238 | |
sahilmgandhi | 18:6a4db94011d3 | 239 | /* Disable the following CEC Transmission/Reception interrupts as |
sahilmgandhi | 18:6a4db94011d3 | 240 | * well as the following CEC Transmission/Reception Errors interrupts |
sahilmgandhi | 18:6a4db94011d3 | 241 | * Rx Byte Received IT |
sahilmgandhi | 18:6a4db94011d3 | 242 | * End of Reception IT |
sahilmgandhi | 18:6a4db94011d3 | 243 | * Rx overrun |
sahilmgandhi | 18:6a4db94011d3 | 244 | * Rx bit rising error |
sahilmgandhi | 18:6a4db94011d3 | 245 | * Rx short bit period error |
sahilmgandhi | 18:6a4db94011d3 | 246 | * Rx long bit period error |
sahilmgandhi | 18:6a4db94011d3 | 247 | * Rx missing acknowledge |
sahilmgandhi | 18:6a4db94011d3 | 248 | * Tx Byte Request IT |
sahilmgandhi | 18:6a4db94011d3 | 249 | * End of Transmission IT |
sahilmgandhi | 18:6a4db94011d3 | 250 | * Tx Missing Acknowledge IT |
sahilmgandhi | 18:6a4db94011d3 | 251 | * Tx-Error IT |
sahilmgandhi | 18:6a4db94011d3 | 252 | * Tx-Buffer Underrun IT |
sahilmgandhi | 18:6a4db94011d3 | 253 | * Tx arbitration lost */ |
sahilmgandhi | 18:6a4db94011d3 | 254 | __HAL_CEC_DISABLE_IT(hcec, CEC_IT_RXBR|CEC_IT_RXEND|CEC_IER_RX_ALL_ERR|CEC_IT_TXBR|CEC_IT_TXEND|CEC_IER_TX_ALL_ERR); |
sahilmgandhi | 18:6a4db94011d3 | 255 | |
sahilmgandhi | 18:6a4db94011d3 | 256 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
sahilmgandhi | 18:6a4db94011d3 | 257 | hcec->gState = HAL_CEC_STATE_RESET; |
sahilmgandhi | 18:6a4db94011d3 | 258 | hcec->RxState = HAL_CEC_STATE_RESET; |
sahilmgandhi | 18:6a4db94011d3 | 259 | |
sahilmgandhi | 18:6a4db94011d3 | 260 | /* Process Unlock */ |
sahilmgandhi | 18:6a4db94011d3 | 261 | __HAL_UNLOCK(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 262 | |
sahilmgandhi | 18:6a4db94011d3 | 263 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 264 | } |
sahilmgandhi | 18:6a4db94011d3 | 265 | |
sahilmgandhi | 18:6a4db94011d3 | 266 | /** |
sahilmgandhi | 18:6a4db94011d3 | 267 | * @brief Initializes the Own Address of the CEC device |
sahilmgandhi | 18:6a4db94011d3 | 268 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 269 | * @param CEC_OwnAddress: The CEC own address. |
sahilmgandhi | 18:6a4db94011d3 | 270 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 271 | */ |
sahilmgandhi | 18:6a4db94011d3 | 272 | HAL_StatusTypeDef HAL_CEC_SetDeviceAddress(CEC_HandleTypeDef *hcec, uint16_t CEC_OwnAddress) |
sahilmgandhi | 18:6a4db94011d3 | 273 | { |
sahilmgandhi | 18:6a4db94011d3 | 274 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 275 | assert_param(IS_CEC_OWN_ADDRESS(CEC_OwnAddress)); |
sahilmgandhi | 18:6a4db94011d3 | 276 | |
sahilmgandhi | 18:6a4db94011d3 | 277 | if ((hcec->gState == HAL_CEC_STATE_READY) && (hcec->RxState == HAL_CEC_STATE_READY)) |
sahilmgandhi | 18:6a4db94011d3 | 278 | { |
sahilmgandhi | 18:6a4db94011d3 | 279 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 280 | __HAL_LOCK(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 281 | |
sahilmgandhi | 18:6a4db94011d3 | 282 | hcec->gState = HAL_CEC_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 283 | |
sahilmgandhi | 18:6a4db94011d3 | 284 | /* Disable the Peripheral */ |
sahilmgandhi | 18:6a4db94011d3 | 285 | __HAL_CEC_DISABLE(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 286 | |
sahilmgandhi | 18:6a4db94011d3 | 287 | if(CEC_OwnAddress != CEC_OWN_ADDRESS_NONE) |
sahilmgandhi | 18:6a4db94011d3 | 288 | { |
sahilmgandhi | 18:6a4db94011d3 | 289 | hcec->Instance->CFGR |= ((uint32_t)CEC_OwnAddress<<16); |
sahilmgandhi | 18:6a4db94011d3 | 290 | } |
sahilmgandhi | 18:6a4db94011d3 | 291 | else |
sahilmgandhi | 18:6a4db94011d3 | 292 | { |
sahilmgandhi | 18:6a4db94011d3 | 293 | hcec->Instance->CFGR &= ~(CEC_CFGR_OAR); |
sahilmgandhi | 18:6a4db94011d3 | 294 | } |
sahilmgandhi | 18:6a4db94011d3 | 295 | |
sahilmgandhi | 18:6a4db94011d3 | 296 | hcec->gState = HAL_CEC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 297 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
sahilmgandhi | 18:6a4db94011d3 | 298 | |
sahilmgandhi | 18:6a4db94011d3 | 299 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 300 | __HAL_UNLOCK(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 301 | |
sahilmgandhi | 18:6a4db94011d3 | 302 | /* Enable the Peripheral */ |
sahilmgandhi | 18:6a4db94011d3 | 303 | __HAL_CEC_ENABLE(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 304 | |
sahilmgandhi | 18:6a4db94011d3 | 305 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 306 | } |
sahilmgandhi | 18:6a4db94011d3 | 307 | else |
sahilmgandhi | 18:6a4db94011d3 | 308 | { |
sahilmgandhi | 18:6a4db94011d3 | 309 | return HAL_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 310 | } |
sahilmgandhi | 18:6a4db94011d3 | 311 | } |
sahilmgandhi | 18:6a4db94011d3 | 312 | |
sahilmgandhi | 18:6a4db94011d3 | 313 | /** |
sahilmgandhi | 18:6a4db94011d3 | 314 | * @brief CEC MSP Init |
sahilmgandhi | 18:6a4db94011d3 | 315 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 316 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 317 | */ |
sahilmgandhi | 18:6a4db94011d3 | 318 | __weak void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec) |
sahilmgandhi | 18:6a4db94011d3 | 319 | { |
sahilmgandhi | 18:6a4db94011d3 | 320 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 321 | UNUSED(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 322 | /* NOTE : This function should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 323 | the HAL_CEC_MspInit can be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 324 | */ |
sahilmgandhi | 18:6a4db94011d3 | 325 | } |
sahilmgandhi | 18:6a4db94011d3 | 326 | |
sahilmgandhi | 18:6a4db94011d3 | 327 | /** |
sahilmgandhi | 18:6a4db94011d3 | 328 | * @brief CEC MSP DeInit |
sahilmgandhi | 18:6a4db94011d3 | 329 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 330 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 331 | */ |
sahilmgandhi | 18:6a4db94011d3 | 332 | __weak void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec) |
sahilmgandhi | 18:6a4db94011d3 | 333 | { |
sahilmgandhi | 18:6a4db94011d3 | 334 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 335 | UNUSED(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 336 | /* NOTE : This function should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 337 | the HAL_CEC_MspDeInit can be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 338 | */ |
sahilmgandhi | 18:6a4db94011d3 | 339 | } |
sahilmgandhi | 18:6a4db94011d3 | 340 | |
sahilmgandhi | 18:6a4db94011d3 | 341 | /** |
sahilmgandhi | 18:6a4db94011d3 | 342 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 343 | */ |
sahilmgandhi | 18:6a4db94011d3 | 344 | |
sahilmgandhi | 18:6a4db94011d3 | 345 | /** @defgroup CEC_Exported_Functions_Group2 Input and Output operation functions |
sahilmgandhi | 18:6a4db94011d3 | 346 | * @brief CEC Transmit/Receive functions |
sahilmgandhi | 18:6a4db94011d3 | 347 | * |
sahilmgandhi | 18:6a4db94011d3 | 348 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 349 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 350 | ##### IO operation functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 351 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 352 | This subsection provides a set of functions allowing to manage the CEC data transfers. |
sahilmgandhi | 18:6a4db94011d3 | 353 | |
sahilmgandhi | 18:6a4db94011d3 | 354 | (#) The CEC handle must contain the initiator (TX side) and the destination (RX side) |
sahilmgandhi | 18:6a4db94011d3 | 355 | logical addresses (4-bit long addresses, 0x0F for broadcast messages destination) |
sahilmgandhi | 18:6a4db94011d3 | 356 | |
sahilmgandhi | 18:6a4db94011d3 | 357 | (#) The communication is performed using Interrupts. |
sahilmgandhi | 18:6a4db94011d3 | 358 | These API's return the HAL status. |
sahilmgandhi | 18:6a4db94011d3 | 359 | The end of the data processing will be indicated through the |
sahilmgandhi | 18:6a4db94011d3 | 360 | dedicated CEC IRQ when using Interrupt mode. |
sahilmgandhi | 18:6a4db94011d3 | 361 | The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user callbacks |
sahilmgandhi | 18:6a4db94011d3 | 362 | will be executed respectivelly at the end of the transmit or Receive process |
sahilmgandhi | 18:6a4db94011d3 | 363 | The HAL_CEC_ErrorCallback()user callback will be executed when a communication |
sahilmgandhi | 18:6a4db94011d3 | 364 | error is detected |
sahilmgandhi | 18:6a4db94011d3 | 365 | |
sahilmgandhi | 18:6a4db94011d3 | 366 | (#) API's with Interrupt are : |
sahilmgandhi | 18:6a4db94011d3 | 367 | (+) HAL_CEC_Transmit_IT() |
sahilmgandhi | 18:6a4db94011d3 | 368 | (+) HAL_CEC_IRQHandler() |
sahilmgandhi | 18:6a4db94011d3 | 369 | |
sahilmgandhi | 18:6a4db94011d3 | 370 | (#) A set of User Callbacks are provided: |
sahilmgandhi | 18:6a4db94011d3 | 371 | (+) HAL_CEC_TxCpltCallback() |
sahilmgandhi | 18:6a4db94011d3 | 372 | (+) HAL_CEC_RxCpltCallback() |
sahilmgandhi | 18:6a4db94011d3 | 373 | (+) HAL_CEC_ErrorCallback() |
sahilmgandhi | 18:6a4db94011d3 | 374 | |
sahilmgandhi | 18:6a4db94011d3 | 375 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 376 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 377 | */ |
sahilmgandhi | 18:6a4db94011d3 | 378 | |
sahilmgandhi | 18:6a4db94011d3 | 379 | /** |
sahilmgandhi | 18:6a4db94011d3 | 380 | * @brief Send data in interrupt mode |
sahilmgandhi | 18:6a4db94011d3 | 381 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 382 | * @param DestinationAddress: destination logical address |
sahilmgandhi | 18:6a4db94011d3 | 383 | * @param pData: pointer to input byte data buffer |
sahilmgandhi | 18:6a4db94011d3 | 384 | * @param Size: amount of data to be sent in bytes (without counting the header). |
sahilmgandhi | 18:6a4db94011d3 | 385 | * 0 means only the header is sent (ping operation). |
sahilmgandhi | 18:6a4db94011d3 | 386 | * Maximum TX size is 15 bytes (1 opcode and up to 14 operands). |
sahilmgandhi | 18:6a4db94011d3 | 387 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 388 | */ |
sahilmgandhi | 18:6a4db94011d3 | 389 | HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t InitiatorAddress, uint8_t DestinationAddress, uint8_t *pData, uint32_t Size) |
sahilmgandhi | 18:6a4db94011d3 | 390 | { |
sahilmgandhi | 18:6a4db94011d3 | 391 | /* if the IP isn't already busy and if there is no previous transmission |
sahilmgandhi | 18:6a4db94011d3 | 392 | already pending due to arbitration lost */ |
sahilmgandhi | 18:6a4db94011d3 | 393 | if (hcec->gState == HAL_CEC_STATE_READY) |
sahilmgandhi | 18:6a4db94011d3 | 394 | { |
sahilmgandhi | 18:6a4db94011d3 | 395 | if((pData == NULL ) && (Size > 0U)) |
sahilmgandhi | 18:6a4db94011d3 | 396 | { |
sahilmgandhi | 18:6a4db94011d3 | 397 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 398 | } |
sahilmgandhi | 18:6a4db94011d3 | 399 | |
sahilmgandhi | 18:6a4db94011d3 | 400 | assert_param(IS_CEC_ADDRESS(DestinationAddress)); |
sahilmgandhi | 18:6a4db94011d3 | 401 | assert_param(IS_CEC_ADDRESS(InitiatorAddress)); |
sahilmgandhi | 18:6a4db94011d3 | 402 | assert_param(IS_CEC_MSGSIZE(Size)); |
sahilmgandhi | 18:6a4db94011d3 | 403 | |
sahilmgandhi | 18:6a4db94011d3 | 404 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 405 | __HAL_LOCK(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 406 | hcec->pTxBuffPtr = pData; |
sahilmgandhi | 18:6a4db94011d3 | 407 | hcec->gState = HAL_CEC_STATE_BUSY_TX; |
sahilmgandhi | 18:6a4db94011d3 | 408 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
sahilmgandhi | 18:6a4db94011d3 | 409 | |
sahilmgandhi | 18:6a4db94011d3 | 410 | /* initialize the number of bytes to send, |
sahilmgandhi | 18:6a4db94011d3 | 411 | * 0 means only one header is sent (ping operation) */ |
sahilmgandhi | 18:6a4db94011d3 | 412 | hcec->TxXferCount = Size; |
sahilmgandhi | 18:6a4db94011d3 | 413 | |
sahilmgandhi | 18:6a4db94011d3 | 414 | /* in case of no payload (Size = 0), sender is only pinging the system; |
sahilmgandhi | 18:6a4db94011d3 | 415 | Set TX End of Message (TXEOM) bit, must be set before writing data to TXDR */ |
sahilmgandhi | 18:6a4db94011d3 | 416 | if (Size == 0U) |
sahilmgandhi | 18:6a4db94011d3 | 417 | { |
sahilmgandhi | 18:6a4db94011d3 | 418 | __HAL_CEC_LAST_BYTE_TX_SET(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 419 | } |
sahilmgandhi | 18:6a4db94011d3 | 420 | |
sahilmgandhi | 18:6a4db94011d3 | 421 | /* send header block */ |
sahilmgandhi | 18:6a4db94011d3 | 422 | hcec->Instance->TXDR = ((uint8_t)(InitiatorAddress << CEC_INITIATOR_LSB_POS) |(uint8_t) DestinationAddress); |
sahilmgandhi | 18:6a4db94011d3 | 423 | /* Set TX Start of Message (TXSOM) bit */ |
sahilmgandhi | 18:6a4db94011d3 | 424 | __HAL_CEC_FIRST_BYTE_TX_SET(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 425 | |
sahilmgandhi | 18:6a4db94011d3 | 426 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 427 | __HAL_UNLOCK(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 428 | |
sahilmgandhi | 18:6a4db94011d3 | 429 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 430 | |
sahilmgandhi | 18:6a4db94011d3 | 431 | } |
sahilmgandhi | 18:6a4db94011d3 | 432 | else |
sahilmgandhi | 18:6a4db94011d3 | 433 | { |
sahilmgandhi | 18:6a4db94011d3 | 434 | return HAL_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 435 | } |
sahilmgandhi | 18:6a4db94011d3 | 436 | } |
sahilmgandhi | 18:6a4db94011d3 | 437 | |
sahilmgandhi | 18:6a4db94011d3 | 438 | /** |
sahilmgandhi | 18:6a4db94011d3 | 439 | * @brief Get size of the received frame. |
sahilmgandhi | 18:6a4db94011d3 | 440 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 441 | * @retval Frame size |
sahilmgandhi | 18:6a4db94011d3 | 442 | */ |
sahilmgandhi | 18:6a4db94011d3 | 443 | uint32_t HAL_CEC_GetLastReceivedFrameSize(CEC_HandleTypeDef *hcec) |
sahilmgandhi | 18:6a4db94011d3 | 444 | { |
sahilmgandhi | 18:6a4db94011d3 | 445 | return hcec->RxXferSize; |
sahilmgandhi | 18:6a4db94011d3 | 446 | } |
sahilmgandhi | 18:6a4db94011d3 | 447 | |
sahilmgandhi | 18:6a4db94011d3 | 448 | /** |
sahilmgandhi | 18:6a4db94011d3 | 449 | * @brief Change Rx Buffer. |
sahilmgandhi | 18:6a4db94011d3 | 450 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 451 | * @note This function can be called only inside the HAL_CEC_RxCpltCallback() |
sahilmgandhi | 18:6a4db94011d3 | 452 | * @retval Frame size |
sahilmgandhi | 18:6a4db94011d3 | 453 | */ |
sahilmgandhi | 18:6a4db94011d3 | 454 | void HAL_CEC_ChangeRxBuffer(CEC_HandleTypeDef *hcec, uint8_t* Rxbuffer) |
sahilmgandhi | 18:6a4db94011d3 | 455 | { |
sahilmgandhi | 18:6a4db94011d3 | 456 | hcec->Init.RxBuffer = Rxbuffer; |
sahilmgandhi | 18:6a4db94011d3 | 457 | } |
sahilmgandhi | 18:6a4db94011d3 | 458 | |
sahilmgandhi | 18:6a4db94011d3 | 459 | /** |
sahilmgandhi | 18:6a4db94011d3 | 460 | * @brief This function handles CEC interrupt requests. |
sahilmgandhi | 18:6a4db94011d3 | 461 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 462 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 463 | */ |
sahilmgandhi | 18:6a4db94011d3 | 464 | void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec) |
sahilmgandhi | 18:6a4db94011d3 | 465 | { |
sahilmgandhi | 18:6a4db94011d3 | 466 | |
sahilmgandhi | 18:6a4db94011d3 | 467 | /* save interrupts register for further error or interrupts handling purposes */ |
sahilmgandhi | 18:6a4db94011d3 | 468 | uint32_t reg = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 469 | reg = hcec->Instance->ISR; |
sahilmgandhi | 18:6a4db94011d3 | 470 | |
sahilmgandhi | 18:6a4db94011d3 | 471 | |
sahilmgandhi | 18:6a4db94011d3 | 472 | /* ----------------------------Arbitration Lost Management----------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 473 | /* CEC TX arbitration error interrupt occurred --------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 474 | if((reg & CEC_FLAG_ARBLST) != RESET) |
sahilmgandhi | 18:6a4db94011d3 | 475 | { |
sahilmgandhi | 18:6a4db94011d3 | 476 | hcec->ErrorCode = HAL_CEC_ERROR_ARBLST; |
sahilmgandhi | 18:6a4db94011d3 | 477 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_ARBLST); |
sahilmgandhi | 18:6a4db94011d3 | 478 | } |
sahilmgandhi | 18:6a4db94011d3 | 479 | |
sahilmgandhi | 18:6a4db94011d3 | 480 | /* ----------------------------Rx Management----------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 481 | /* CEC RX byte received interrupt ---------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 482 | if((reg & CEC_FLAG_RXBR) != RESET) |
sahilmgandhi | 18:6a4db94011d3 | 483 | { |
sahilmgandhi | 18:6a4db94011d3 | 484 | /* reception is starting */ |
sahilmgandhi | 18:6a4db94011d3 | 485 | hcec->RxState = HAL_CEC_STATE_BUSY_RX; |
sahilmgandhi | 18:6a4db94011d3 | 486 | hcec->RxXferSize++; |
sahilmgandhi | 18:6a4db94011d3 | 487 | /* read received byte */ |
sahilmgandhi | 18:6a4db94011d3 | 488 | *hcec->Init.RxBuffer++ = hcec->Instance->RXDR; |
sahilmgandhi | 18:6a4db94011d3 | 489 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXBR); |
sahilmgandhi | 18:6a4db94011d3 | 490 | } |
sahilmgandhi | 18:6a4db94011d3 | 491 | |
sahilmgandhi | 18:6a4db94011d3 | 492 | /* CEC RX end received interrupt ---------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 493 | if((reg & CEC_FLAG_RXEND) != RESET) |
sahilmgandhi | 18:6a4db94011d3 | 494 | { |
sahilmgandhi | 18:6a4db94011d3 | 495 | /* clear IT */ |
sahilmgandhi | 18:6a4db94011d3 | 496 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RXEND); |
sahilmgandhi | 18:6a4db94011d3 | 497 | |
sahilmgandhi | 18:6a4db94011d3 | 498 | /* Rx process is completed, restore hcec->RxState to Ready */ |
sahilmgandhi | 18:6a4db94011d3 | 499 | hcec->RxState = HAL_CEC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 500 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
sahilmgandhi | 18:6a4db94011d3 | 501 | hcec->Init.RxBuffer -= hcec->RxXferSize; |
sahilmgandhi | 18:6a4db94011d3 | 502 | HAL_CEC_RxCpltCallback(hcec, hcec->RxXferSize); |
sahilmgandhi | 18:6a4db94011d3 | 503 | hcec->RxXferSize = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 504 | } |
sahilmgandhi | 18:6a4db94011d3 | 505 | |
sahilmgandhi | 18:6a4db94011d3 | 506 | /* ----------------------------Tx Management----------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 507 | /* CEC TX byte request interrupt ------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 508 | if((reg & CEC_FLAG_TXBR) != RESET) |
sahilmgandhi | 18:6a4db94011d3 | 509 | { |
sahilmgandhi | 18:6a4db94011d3 | 510 | if (hcec->TxXferCount == 0U) |
sahilmgandhi | 18:6a4db94011d3 | 511 | { |
sahilmgandhi | 18:6a4db94011d3 | 512 | /* if this is the last byte transmission, set TX End of Message (TXEOM) bit */ |
sahilmgandhi | 18:6a4db94011d3 | 513 | __HAL_CEC_LAST_BYTE_TX_SET(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 514 | hcec->Instance->TXDR = *hcec->pTxBuffPtr++; |
sahilmgandhi | 18:6a4db94011d3 | 515 | } |
sahilmgandhi | 18:6a4db94011d3 | 516 | else |
sahilmgandhi | 18:6a4db94011d3 | 517 | { |
sahilmgandhi | 18:6a4db94011d3 | 518 | hcec->Instance->TXDR = *hcec->pTxBuffPtr++; |
sahilmgandhi | 18:6a4db94011d3 | 519 | hcec->TxXferCount--; |
sahilmgandhi | 18:6a4db94011d3 | 520 | } |
sahilmgandhi | 18:6a4db94011d3 | 521 | /* clear Tx-Byte request flag */ |
sahilmgandhi | 18:6a4db94011d3 | 522 | __HAL_CEC_CLEAR_FLAG(hcec,CEC_FLAG_TXBR); |
sahilmgandhi | 18:6a4db94011d3 | 523 | } |
sahilmgandhi | 18:6a4db94011d3 | 524 | |
sahilmgandhi | 18:6a4db94011d3 | 525 | /* CEC TX end interrupt ------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 526 | if((reg & CEC_FLAG_TXEND) != RESET) |
sahilmgandhi | 18:6a4db94011d3 | 527 | { |
sahilmgandhi | 18:6a4db94011d3 | 528 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TXEND); |
sahilmgandhi | 18:6a4db94011d3 | 529 | |
sahilmgandhi | 18:6a4db94011d3 | 530 | /* Tx process is ended, restore hcec->gState to Ready */ |
sahilmgandhi | 18:6a4db94011d3 | 531 | hcec->gState = HAL_CEC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 532 | /* Call the Process Unlocked before calling the Tx call back API to give the possibility to |
sahilmgandhi | 18:6a4db94011d3 | 533 | start again the Transmission under the Tx call back API */ |
sahilmgandhi | 18:6a4db94011d3 | 534 | __HAL_UNLOCK(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 535 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
sahilmgandhi | 18:6a4db94011d3 | 536 | HAL_CEC_TxCpltCallback(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 537 | } |
sahilmgandhi | 18:6a4db94011d3 | 538 | |
sahilmgandhi | 18:6a4db94011d3 | 539 | /* ----------------------------Rx/Tx Error Management----------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 540 | if ((reg & (CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE|CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)) != 0U) |
sahilmgandhi | 18:6a4db94011d3 | 541 | { |
sahilmgandhi | 18:6a4db94011d3 | 542 | hcec->ErrorCode = reg; |
sahilmgandhi | 18:6a4db94011d3 | 543 | __HAL_CEC_CLEAR_FLAG(hcec, HAL_CEC_ERROR_RXOVR|HAL_CEC_ERROR_BRE|CEC_FLAG_LBPE|CEC_FLAG_SBPE|HAL_CEC_ERROR_RXACKE|HAL_CEC_ERROR_TXUDR|HAL_CEC_ERROR_TXERR|HAL_CEC_ERROR_TXACKE); |
sahilmgandhi | 18:6a4db94011d3 | 544 | |
sahilmgandhi | 18:6a4db94011d3 | 545 | |
sahilmgandhi | 18:6a4db94011d3 | 546 | if((reg & (CEC_ISR_RXOVR|CEC_ISR_BRE|CEC_ISR_SBPE|CEC_ISR_LBPE|CEC_ISR_RXACKE)) != RESET) |
sahilmgandhi | 18:6a4db94011d3 | 547 | { |
sahilmgandhi | 18:6a4db94011d3 | 548 | hcec->Init.RxBuffer-=hcec->RxXferSize; |
sahilmgandhi | 18:6a4db94011d3 | 549 | hcec->RxXferSize = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 550 | hcec->RxState = HAL_CEC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 551 | } |
sahilmgandhi | 18:6a4db94011d3 | 552 | else if (((reg & (CEC_ISR_TXUDR|CEC_ISR_TXERR|CEC_ISR_TXACKE)) != RESET) && ((reg & CEC_ISR_ARBLST) == RESET)) |
sahilmgandhi | 18:6a4db94011d3 | 553 | { |
sahilmgandhi | 18:6a4db94011d3 | 554 | /* Set the CEC state ready to be able to start again the process */ |
sahilmgandhi | 18:6a4db94011d3 | 555 | hcec->gState = HAL_CEC_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 556 | } |
sahilmgandhi | 18:6a4db94011d3 | 557 | |
sahilmgandhi | 18:6a4db94011d3 | 558 | /* Error Call Back */ |
sahilmgandhi | 18:6a4db94011d3 | 559 | HAL_CEC_ErrorCallback(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 560 | } |
sahilmgandhi | 18:6a4db94011d3 | 561 | |
sahilmgandhi | 18:6a4db94011d3 | 562 | } |
sahilmgandhi | 18:6a4db94011d3 | 563 | |
sahilmgandhi | 18:6a4db94011d3 | 564 | /** |
sahilmgandhi | 18:6a4db94011d3 | 565 | * @brief Tx Transfer completed callback |
sahilmgandhi | 18:6a4db94011d3 | 566 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 567 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 568 | */ |
sahilmgandhi | 18:6a4db94011d3 | 569 | __weak void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec) |
sahilmgandhi | 18:6a4db94011d3 | 570 | { |
sahilmgandhi | 18:6a4db94011d3 | 571 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 572 | UNUSED(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 573 | /* NOTE : This function should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 574 | the HAL_CEC_TxCpltCallback can be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 575 | */ |
sahilmgandhi | 18:6a4db94011d3 | 576 | } |
sahilmgandhi | 18:6a4db94011d3 | 577 | |
sahilmgandhi | 18:6a4db94011d3 | 578 | /** |
sahilmgandhi | 18:6a4db94011d3 | 579 | * @brief Rx Transfer completed callback |
sahilmgandhi | 18:6a4db94011d3 | 580 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 581 | * @param RxFrameSize: Size of frame |
sahilmgandhi | 18:6a4db94011d3 | 582 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 583 | */ |
sahilmgandhi | 18:6a4db94011d3 | 584 | __weak void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec, uint32_t RxFrameSize) |
sahilmgandhi | 18:6a4db94011d3 | 585 | { |
sahilmgandhi | 18:6a4db94011d3 | 586 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 587 | UNUSED(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 588 | UNUSED(RxFrameSize); |
sahilmgandhi | 18:6a4db94011d3 | 589 | /* NOTE : This function should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 590 | the HAL_CEC_RxCpltCallback can be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 591 | */ |
sahilmgandhi | 18:6a4db94011d3 | 592 | } |
sahilmgandhi | 18:6a4db94011d3 | 593 | |
sahilmgandhi | 18:6a4db94011d3 | 594 | /** |
sahilmgandhi | 18:6a4db94011d3 | 595 | * @brief CEC error callbacks |
sahilmgandhi | 18:6a4db94011d3 | 596 | * @param hcec: CEC handle |
sahilmgandhi | 18:6a4db94011d3 | 597 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 598 | */ |
sahilmgandhi | 18:6a4db94011d3 | 599 | __weak void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec) |
sahilmgandhi | 18:6a4db94011d3 | 600 | { |
sahilmgandhi | 18:6a4db94011d3 | 601 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 602 | UNUSED(hcec); |
sahilmgandhi | 18:6a4db94011d3 | 603 | /* NOTE : This function should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 604 | the HAL_CEC_ErrorCallback can be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 605 | */ |
sahilmgandhi | 18:6a4db94011d3 | 606 | } |
sahilmgandhi | 18:6a4db94011d3 | 607 | /** |
sahilmgandhi | 18:6a4db94011d3 | 608 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 609 | */ |
sahilmgandhi | 18:6a4db94011d3 | 610 | |
sahilmgandhi | 18:6a4db94011d3 | 611 | /** @defgroup CEC_Exported_Functions_Group3 Peripheral Control function |
sahilmgandhi | 18:6a4db94011d3 | 612 | * @brief CEC control functions |
sahilmgandhi | 18:6a4db94011d3 | 613 | * |
sahilmgandhi | 18:6a4db94011d3 | 614 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 615 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 616 | ##### Peripheral Control function ##### |
sahilmgandhi | 18:6a4db94011d3 | 617 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 618 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 619 | This subsection provides a set of functions allowing to control the CEC. |
sahilmgandhi | 18:6a4db94011d3 | 620 | (+) HAL_CEC_GetState() API can be helpful to check in run-time the state of the CEC peripheral. |
sahilmgandhi | 18:6a4db94011d3 | 621 | (+) HAL_CEC_GetError() API can be helpful to check in run-time the error of the CEC peripheral. |
sahilmgandhi | 18:6a4db94011d3 | 622 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 623 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 624 | */ |
sahilmgandhi | 18:6a4db94011d3 | 625 | /** |
sahilmgandhi | 18:6a4db94011d3 | 626 | * @brief return the CEC state |
sahilmgandhi | 18:6a4db94011d3 | 627 | * @param hcec: pointer to a CEC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 628 | * the configuration information for the specified CEC module. |
sahilmgandhi | 18:6a4db94011d3 | 629 | * @retval HAL state |
sahilmgandhi | 18:6a4db94011d3 | 630 | */ |
sahilmgandhi | 18:6a4db94011d3 | 631 | HAL_CEC_StateTypeDef HAL_CEC_GetState(CEC_HandleTypeDef *hcec) |
sahilmgandhi | 18:6a4db94011d3 | 632 | { |
sahilmgandhi | 18:6a4db94011d3 | 633 | uint32_t temp1 = 0x00U, temp2 = 0x00U; |
sahilmgandhi | 18:6a4db94011d3 | 634 | temp1 = hcec->gState; |
sahilmgandhi | 18:6a4db94011d3 | 635 | temp2 = hcec->RxState; |
sahilmgandhi | 18:6a4db94011d3 | 636 | |
sahilmgandhi | 18:6a4db94011d3 | 637 | return (HAL_CEC_StateTypeDef)(temp1 | temp2); |
sahilmgandhi | 18:6a4db94011d3 | 638 | } |
sahilmgandhi | 18:6a4db94011d3 | 639 | |
sahilmgandhi | 18:6a4db94011d3 | 640 | /** |
sahilmgandhi | 18:6a4db94011d3 | 641 | * @brief Return the CEC error code |
sahilmgandhi | 18:6a4db94011d3 | 642 | * @param hcec : pointer to a CEC_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 643 | * the configuration information for the specified CEC. |
sahilmgandhi | 18:6a4db94011d3 | 644 | * @retval CEC Error Code |
sahilmgandhi | 18:6a4db94011d3 | 645 | */ |
sahilmgandhi | 18:6a4db94011d3 | 646 | uint32_t HAL_CEC_GetError(CEC_HandleTypeDef *hcec) |
sahilmgandhi | 18:6a4db94011d3 | 647 | { |
sahilmgandhi | 18:6a4db94011d3 | 648 | return hcec->ErrorCode; |
sahilmgandhi | 18:6a4db94011d3 | 649 | } |
sahilmgandhi | 18:6a4db94011d3 | 650 | |
sahilmgandhi | 18:6a4db94011d3 | 651 | /** |
sahilmgandhi | 18:6a4db94011d3 | 652 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 653 | */ |
sahilmgandhi | 18:6a4db94011d3 | 654 | |
sahilmgandhi | 18:6a4db94011d3 | 655 | /** |
sahilmgandhi | 18:6a4db94011d3 | 656 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 657 | */ |
sahilmgandhi | 18:6a4db94011d3 | 658 | |
sahilmgandhi | 18:6a4db94011d3 | 659 | #endif /* STM32F446xx */ |
sahilmgandhi | 18:6a4db94011d3 | 660 | |
sahilmgandhi | 18:6a4db94011d3 | 661 | #endif /* HAL_CEC_MODULE_ENABLED */ |
sahilmgandhi | 18:6a4db94011d3 | 662 | /** |
sahilmgandhi | 18:6a4db94011d3 | 663 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 664 | */ |
sahilmgandhi | 18:6a4db94011d3 | 665 | |
sahilmgandhi | 18:6a4db94011d3 | 666 | /** |
sahilmgandhi | 18:6a4db94011d3 | 667 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 668 | */ |
sahilmgandhi | 18:6a4db94011d3 | 669 | |
sahilmgandhi | 18:6a4db94011d3 | 670 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |