Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2 | Rev 3 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /** |
1 | /** |
| 2 | ****************************************************************************** |
2 | ****************************************************************************** |
| 3 | * @file stm32f1xx_hal_cec.c |
3 | * @file stm32f1xx_hal_cec.c |
| 4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
| 5 | * @brief CEC HAL module driver. |
5 | * @brief CEC HAL module driver. |
| 6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
| 7 | * functionalities of the High Definition Multimedia Interface |
7 | * functionalities of the High Definition Multimedia Interface |
| 8 | * Consumer Electronics Control Peripheral (CEC). |
8 | * Consumer Electronics Control Peripheral (CEC). |
| 9 | * + Initialization and de-initialization function |
9 | * + Initialization and de-initialization function |
| 10 | * + IO operation function |
10 | * + IO operation function |
| 11 | * + Peripheral Control function |
11 | * + Peripheral Control function |
| 12 | * |
12 | * |
| 13 | * |
13 | * |
| 14 | @verbatim |
14 | ****************************************************************************** |
| 15 | =============================================================================== |
15 | * @attention |
| 16 | ##### How to use this driver ##### |
16 | * |
| 17 | =============================================================================== |
17 | * Copyright (c) 2016 STMicroelectronics. |
| 18 | [..] |
18 | * All rights reserved. |
| 19 | The CEC HAL driver can be used as follow: |
19 | * |
| 20 | |
20 | * This software is licensed under terms that can be found in the LICENSE file |
| 21 | (#) Declare a CEC_HandleTypeDef handle structure. |
21 | * in the root directory of this software component. |
| 22 | (#) Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API: |
22 | * If no LICENSE file comes with this software, it is provided AS-IS. |
| 23 | (##) Enable the CEC interface clock. |
23 | * |
| 24 | (##) CEC pins configuration: |
24 | ****************************************************************************** |
| 25 | (+++) Enable the clock for the CEC GPIOs. |
25 | @verbatim |
| 26 | (+++) Configure these CEC pins as alternate function pull-up. |
26 | =============================================================================== |
| 27 | (##) NVIC configuration if you need to use interrupt process (HAL_CEC_Transmit_IT() |
27 | ##### How to use this driver ##### |
| 28 | and HAL_CEC_Receive_IT() APIs): |
28 | =============================================================================== |
| 29 | (+++) Configure the CEC interrupt priority. |
29 | [..] |
| 30 | (+++) Enable the NVIC CEC IRQ handle. |
30 | The CEC HAL driver can be used as follow: |
| 31 | (+++) The specific CEC interrupts (Transmission complete interrupt, |
31 | |
| 32 | RXNE interrupt and Error Interrupts) will be managed using the macros |
32 | (#) Declare a CEC_HandleTypeDef handle structure. |
| 33 | __HAL_CEC_ENABLE_IT() and __HAL_CEC_DISABLE_IT() inside the transmit |
33 | (#) Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API: |
| 34 | and receive process. |
34 | (##) Enable the CEC interface clock. |
| 35 | 35 | (##) CEC pins configuration: |
|
| 36 | (#) Program the Bit Timing Error Mode and the Bit Period Error Mode in the hcec Init structure. |
36 | (+++) Enable the clock for the CEC GPIOs. |
| 37 | 37 | (+++) Configure these CEC pins as alternate function pull-up. |
|
| 38 | (#) Initialize the CEC registers by calling the HAL_CEC_Init() API. |
38 | (##) NVIC configuration if you need to use interrupt process (HAL_CEC_Transmit_IT() |
| 39 | 39 | and HAL_CEC_Receive_IT() APIs): |
|
| 40 | [..] |
40 | (+++) Configure the CEC interrupt priority. |
| 41 | (@) This API (HAL_CEC_Init()) configures also the low level Hardware (GPIO, CLOCK, CORTEX...etc) |
41 | (+++) Enable the NVIC CEC IRQ handle. |
| 42 | by calling the customed HAL_CEC_MspInit() API. |
42 | (+++) The specific CEC interrupts (Transmission complete interrupt, |
| 43 | *** Callback registration *** |
43 | RXNE interrupt and Error Interrupts) will be managed using the macros |
| 44 | ============================================= |
44 | __HAL_CEC_ENABLE_IT() and __HAL_CEC_DISABLE_IT() inside the transmit |
| 45 | The compilation define USE_HAL_CEC_REGISTER_CALLBACKS when set to 1 |
45 | and receive process. |
| 46 | allows the user to configure dynamically the driver callbacks. |
46 | |
| 47 | Use Functions @ref HAL_CEC_RegisterCallback() or HAL_CEC_RegisterXXXCallback() |
47 | (#) Program the Bit Timing Error Mode and the Bit Period Error Mode in the hcec Init structure. |
| 48 | to register an interrupt callback. |
48 | |
| 49 | 49 | (#) Initialize the CEC registers by calling the HAL_CEC_Init() API. |
|
| 50 | Function @ref HAL_CEC_RegisterCallback() allows to register following callbacks: |
50 | |
| 51 | (+) TxCpltCallback : Tx Transfer completed callback. |
51 | [..] |
| 52 | (+) ErrorCallback : callback for error detection. |
52 | (@) This API (HAL_CEC_Init()) configures also the low level Hardware (GPIO, CLOCK, CORTEX...etc) |
| 53 | (+) MspInitCallback : CEC MspInit. |
53 | by calling the customed HAL_CEC_MspInit() API. |
| 54 | (+) MspDeInitCallback : CEC MspDeInit. |
54 | *** Callback registration *** |
| 55 | This function takes as parameters the HAL peripheral handle, the Callback ID |
55 | ============================================= |
| 56 | and a pointer to the user callback function. |
56 | |
| 57 | 57 | The compilation define USE_HAL_CEC_REGISTER_CALLBACKS when set to 1 |
|
| 58 | For specific callback HAL_CEC_RxCpltCallback use dedicated register callbacks |
58 | allows the user to configure dynamically the driver callbacks. |
| 59 | @ref HAL_CEC_RegisterRxCpltCallback(). |
59 | Use Functions HAL_CEC_RegisterCallback() or HAL_CEC_RegisterXXXCallback() |
| 60 | 60 | to register an interrupt callback. |
|
| 61 | Use function @ref HAL_CEC_UnRegisterCallback() to reset a callback to the default |
61 | |
| 62 | weak function. |
62 | Function HAL_CEC_RegisterCallback() allows to register following callbacks: |
| 63 | @ref HAL_CEC_UnRegisterCallback() takes as parameters the HAL peripheral handle, |
63 | (+) TxCpltCallback : Tx Transfer completed callback. |
| 64 | and the Callback ID. |
64 | (+) ErrorCallback : callback for error detection. |
| 65 | This function allows to reset following callbacks: |
65 | (+) MspInitCallback : CEC MspInit. |
| 66 | (+) TxCpltCallback : Tx Transfer completed callback. |
66 | (+) MspDeInitCallback : CEC MspDeInit. |
| 67 | (+) ErrorCallback : callback for error detection. |
67 | This function takes as parameters the HAL peripheral handle, the Callback ID |
| 68 | (+) MspInitCallback : CEC MspInit. |
68 | and a pointer to the user callback function. |
| 69 | (+) MspDeInitCallback : CEC MspDeInit. |
69 | |
| 70 | 70 | For specific callback HAL_CEC_RxCpltCallback use dedicated register callbacks |
|
| 71 | For callback HAL_CEC_RxCpltCallback use dedicated unregister callback : |
71 | HAL_CEC_RegisterRxCpltCallback(). |
| 72 | @ref HAL_CEC_UnRegisterRxCpltCallback(). |
72 | |
| 73 | 73 | Use function HAL_CEC_UnRegisterCallback() to reset a callback to the default |
|
| 74 | By default, after the @ref HAL_CEC_Init() and when the state is HAL_CEC_STATE_RESET |
74 | weak function. |
| 75 | all callbacks are set to the corresponding weak functions : |
75 | HAL_CEC_UnRegisterCallback() takes as parameters the HAL peripheral handle, |
| 76 | examples @ref HAL_CEC_TxCpltCallback() , @ref HAL_CEC_RxCpltCallback(). |
76 | and the Callback ID. |
| 77 | Exception done for MspInit and MspDeInit functions that are |
77 | This function allows to reset following callbacks: |
| 78 | reset to the legacy weak function in the @ref HAL_CEC_Init()/ @ref HAL_CEC_DeInit() only when |
78 | (+) TxCpltCallback : Tx Transfer completed callback. |
| 79 | these callbacks are null (not registered beforehand). |
79 | (+) ErrorCallback : callback for error detection. |
| 80 | if not, MspInit or MspDeInit are not null, the @ref HAL_CEC_Init() / @ref HAL_CEC_DeInit() |
80 | (+) MspInitCallback : CEC MspInit. |
| 81 | keep and use the user MspInit/MspDeInit functions (registered beforehand) |
81 | (+) MspDeInitCallback : CEC MspDeInit. |
| 82 | 82 | ||
| 83 | Callbacks can be registered/unregistered in HAL_CEC_STATE_READY state only. |
83 | For callback HAL_CEC_RxCpltCallback use dedicated unregister callback : |
| 84 | Exception done MspInit/MspDeInit callbacks that can be registered/unregistered |
84 | HAL_CEC_UnRegisterRxCpltCallback(). |
| 85 | in HAL_CEC_STATE_READY or HAL_CEC_STATE_RESET state, |
85 | |
| 86 | thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. |
86 | By default, after the HAL_CEC_Init() and when the state is HAL_CEC_STATE_RESET |
| 87 | In that case first register the MspInit/MspDeInit user callbacks |
87 | all callbacks are set to the corresponding weak functions : |
| 88 | using @ref HAL_CEC_RegisterCallback() before calling @ref HAL_CEC_DeInit() |
88 | examples HAL_CEC_TxCpltCallback() , HAL_CEC_RxCpltCallback(). |
| 89 | or @ref HAL_CEC_Init() function. |
89 | Exception done for MspInit and MspDeInit functions that are |
| 90 | 90 | reset to the legacy weak function in the HAL_CEC_Init()/ HAL_CEC_DeInit() only when |
|
| 91 | When the compilation define USE_HAL_CEC_REGISTER_CALLBACKS is set to 0 or |
91 | these callbacks are null (not registered beforehand). |
| 92 | not defined, the callback registration feature is not available and all callbacks |
92 | if not, MspInit or MspDeInit are not null, the HAL_CEC_Init() / HAL_CEC_DeInit() |
| 93 | are set to the corresponding weak functions. |
93 | keep and use the user MspInit/MspDeInit functions (registered beforehand) |
| 94 | @endverbatim |
94 | |
| 95 | ****************************************************************************** |
95 | Callbacks can be registered/unregistered in HAL_CEC_STATE_READY state only. |
| 96 | * @attention |
96 | Exception done MspInit/MspDeInit callbacks that can be registered/unregistered |
| 97 | * |
97 | in HAL_CEC_STATE_READY or HAL_CEC_STATE_RESET state, |
| 98 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
98 | thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit. |
| 99 | * All rights reserved.</center></h2> |
99 | In that case first register the MspInit/MspDeInit user callbacks |
| 100 | * |
100 | using HAL_CEC_RegisterCallback() before calling HAL_CEC_DeInit() |
| 101 | * This software component is licensed by ST under BSD 3-Clause license, |
101 | or HAL_CEC_Init() function. |
| 102 | * the "License"; You may not use this file except in compliance with the |
102 | |
| 103 | * License. You may obtain a copy of the License at: |
103 | When the compilation define USE_HAL_CEC_REGISTER_CALLBACKS is set to 0 or |
| 104 | * opensource.org/licenses/BSD-3-Clause |
104 | not defined, the callback registration feature is not available and all callbacks |
| 105 | * |
105 | are set to the corresponding weak functions. |
| 106 | ****************************************************************************** |
106 | @endverbatim |
| 107 | */ |
107 | ****************************************************************************** |
| 108 | 108 | */ |
|
| 109 | /* Includes ------------------------------------------------------------------*/ |
109 | |
| 110 | #include "stm32f1xx_hal.h" |
110 | /* Includes ------------------------------------------------------------------*/ |
| 111 | 111 | #include "stm32f1xx_hal.h" |
|
| 112 | #ifdef HAL_CEC_MODULE_ENABLED |
112 | |
| 113 | 113 | #ifdef HAL_CEC_MODULE_ENABLED |
|
| 114 | #if defined (CEC) |
114 | |
| 115 | 115 | #if defined (CEC) |
|
| 116 | /** @addtogroup STM32F1xx_HAL_Driver |
116 | |
| 117 | * @{ |
117 | /** @addtogroup STM32F1xx_HAL_Driver |
| 118 | */ |
118 | * @{ |
| 119 | 119 | */ |
|
| 120 | /** @defgroup CEC CEC |
120 | |
| 121 | * @brief HAL CEC module driver |
121 | /** @defgroup CEC CEC |
| 122 | * @{ |
122 | * @brief HAL CEC module driver |
| 123 | */ |
123 | * @{ |
| 124 | 124 | */ |
|
| 125 | /* Private typedef -----------------------------------------------------------*/ |
125 | |
| 126 | /* Private define ------------------------------------------------------------*/ |
126 | /* Private typedef -----------------------------------------------------------*/ |
| 127 | /** @defgroup CEC_Private_Constants CEC Private Constants |
127 | /* Private define ------------------------------------------------------------*/ |
| 128 | * @{ |
128 | /** @defgroup CEC_Private_Constants CEC Private Constants |
| 129 | */ |
129 | * @{ |
| 130 | #define CEC_CFGR_FIELDS (CEC_CFGR_BTEM | CEC_CFGR_BPEM ) |
130 | */ |
| 131 | #define CEC_FLAG_TRANSMIT_MASK (CEC_FLAG_TSOM|CEC_FLAG_TEOM|CEC_FLAG_TBTRF) |
131 | #define CEC_CFGR_FIELDS (CEC_CFGR_BTEM | CEC_CFGR_BPEM ) |
| 132 | #define CEC_FLAG_RECEIVE_MASK (CEC_FLAG_RSOM|CEC_FLAG_REOM|CEC_FLAG_RBTF) |
132 | #define CEC_FLAG_TRANSMIT_MASK (CEC_FLAG_TSOM|CEC_FLAG_TEOM|CEC_FLAG_TBTRF) |
| 133 | #define CEC_ESR_ALL_ERROR (CEC_ESR_BTE|CEC_ESR_BPE|CEC_ESR_RBTFE|CEC_ESR_SBE|CEC_ESR_ACKE|CEC_ESR_LINE|CEC_ESR_TBTFE) |
133 | #define CEC_FLAG_RECEIVE_MASK (CEC_FLAG_RSOM|CEC_FLAG_REOM|CEC_FLAG_RBTF) |
| 134 | #define CEC_RXXFERSIZE_INITIALIZE 0xFFFF /*!< Value used to initialise the RxXferSize of the handle */ |
134 | #define CEC_ESR_ALL_ERROR (CEC_ESR_BTE|CEC_ESR_BPE|CEC_ESR_RBTFE|CEC_ESR_SBE|CEC_ESR_ACKE|CEC_ESR_LINE|CEC_ESR_TBTFE) |
| 135 | /** |
135 | #define CEC_RXXFERSIZE_INITIALIZE 0xFFFF /*!< Value used to initialise the RxXferSize of the handle */ |
| 136 | * @} |
136 | /** |
| 137 | */ |
137 | * @} |
| 138 | 138 | */ |
|
| 139 | /* Private macro -------------------------------------------------------------*/ |
139 | |
| 140 | /* Private variables ---------------------------------------------------------*/ |
140 | /* Private macro -------------------------------------------------------------*/ |
| 141 | /* Private function prototypes -----------------------------------------------*/ |
141 | /* Private variables ---------------------------------------------------------*/ |
| 142 | /** @defgroup CEC_Private_Functions CEC Private Functions |
142 | /* Private function prototypes -----------------------------------------------*/ |
| 143 | * @{ |
143 | /** @defgroup CEC_Private_Functions CEC Private Functions |
| 144 | */ |
144 | * @{ |
| 145 | static HAL_StatusTypeDef CEC_Transmit_IT(CEC_HandleTypeDef *hcec); |
145 | */ |
| 146 | static HAL_StatusTypeDef CEC_Receive_IT(CEC_HandleTypeDef *hcec); |
146 | static HAL_StatusTypeDef CEC_Transmit_IT(CEC_HandleTypeDef *hcec); |
| 147 | /** |
147 | static HAL_StatusTypeDef CEC_Receive_IT(CEC_HandleTypeDef *hcec); |
| 148 | * @} |
148 | /** |
| 149 | */ |
149 | * @} |
| 150 | 150 | */ |
|
| 151 | /* Exported functions ---------------------------------------------------------*/ |
151 | |
| 152 | 152 | /* Exported functions ---------------------------------------------------------*/ |
|
| 153 | /** @defgroup CEC_Exported_Functions CEC Exported Functions |
153 | |
| 154 | * @{ |
154 | /** @defgroup CEC_Exported_Functions CEC Exported Functions |
| 155 | */ |
155 | * @{ |
| 156 | 156 | */ |
|
| 157 | /** @defgroup CEC_Exported_Functions_Group1 Initialization and de-initialization functions |
157 | |
| 158 | * @brief Initialization and Configuration functions |
158 | /** @defgroup CEC_Exported_Functions_Group1 Initialization and de-initialization functions |
| 159 | * |
159 | * @brief Initialization and Configuration functions |
| 160 | @verbatim |
160 | * |
| 161 | =============================================================================== |
161 | @verbatim |
| 162 | ##### Initialization and Configuration functions ##### |
162 | =============================================================================== |
| 163 | =============================================================================== |
163 | ##### Initialization and Configuration functions ##### |
| 164 | [..] |
164 | =============================================================================== |
| 165 | This subsection provides a set of functions allowing to initialize the CEC |
165 | [..] |
| 166 | (+) The following parameters need to be configured: |
166 | This subsection provides a set of functions allowing to initialize the CEC |
| 167 | (++) TimingErrorFree |
167 | (+) The following parameters need to be configured: |
| 168 | (++) PeriodErrorFree |
168 | (++) TimingErrorFree |
| 169 | (++) InitiatorAddress |
169 | (++) PeriodErrorFree |
| 170 | 170 | (++) InitiatorAddress |
|
| 171 | @endverbatim |
171 | |
| 172 | * @{ |
172 | @endverbatim |
| 173 | */ |
173 | * @{ |
| 174 | 174 | */ |
|
| 175 | /** |
175 | |
| 176 | * @brief Initializes the CEC mode according to the specified |
176 | /** |
| 177 | * parameters in the CEC_InitTypeDef and creates the associated handle . |
177 | * @brief Initializes the CEC mode according to the specified |
| 178 | * @param hcec: CEC handle |
178 | * parameters in the CEC_InitTypeDef and creates the associated handle . |
| 179 | * @retval HAL status |
179 | * @param hcec CEC handle |
| 180 | */ |
180 | * @retval HAL status |
| 181 | HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec) |
181 | */ |
| 182 | { |
182 | HAL_StatusTypeDef HAL_CEC_Init(CEC_HandleTypeDef *hcec) |
| 183 | /* Check the CEC handle allocation */ |
183 | { |
| 184 | if((hcec == NULL) ||(hcec->Init.RxBuffer == NULL)) |
184 | /* Check the CEC handle allocation */ |
| 185 | { |
185 | if ((hcec == NULL) || (hcec->Init.RxBuffer == NULL)) |
| 186 | return HAL_ERROR; |
186 | { |
| 187 | } |
187 | return HAL_ERROR; |
| 188 | 188 | } |
|
| 189 | /* Check the parameters */ |
189 | |
| 190 | assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance)); |
190 | /* Check the parameters */ |
| 191 | assert_param(IS_CEC_BIT_TIMING_ERROR_MODE(hcec->Init.TimingErrorFree)); |
191 | assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance)); |
| 192 | assert_param(IS_CEC_BIT_PERIOD_ERROR_MODE(hcec->Init.PeriodErrorFree)); |
192 | assert_param(IS_CEC_BIT_TIMING_ERROR_MODE(hcec->Init.TimingErrorFree)); |
| 193 | assert_param(IS_CEC_ADDRESS(hcec->Init.OwnAddress)); |
193 | assert_param(IS_CEC_BIT_PERIOD_ERROR_MODE(hcec->Init.PeriodErrorFree)); |
| 194 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
194 | assert_param(IS_CEC_ADDRESS(hcec->Init.OwnAddress)); |
| 195 | if(hcec->gState == HAL_CEC_STATE_RESET) |
195 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
| 196 | { |
196 | if (hcec->gState == HAL_CEC_STATE_RESET) |
| 197 | /* Allocate lock resource and initialize it */ |
197 | { |
| 198 | hcec->Lock = HAL_UNLOCKED; |
198 | /* Allocate lock resource and initialize it */ |
| 199 | 199 | hcec->Lock = HAL_UNLOCKED; |
|
| 200 | hcec->TxCpltCallback = HAL_CEC_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
200 | |
| 201 | hcec->RxCpltCallback = HAL_CEC_RxCpltCallback; /* Legacy weak RxCpltCallback */ |
201 | hcec->TxCpltCallback = HAL_CEC_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
| 202 | hcec->ErrorCallback = HAL_CEC_ErrorCallback; /* Legacy weak ErrorCallback */ |
202 | hcec->RxCpltCallback = HAL_CEC_RxCpltCallback; /* Legacy weak RxCpltCallback */ |
| 203 | 203 | hcec->ErrorCallback = HAL_CEC_ErrorCallback; /* Legacy weak ErrorCallback */ |
|
| 204 | if(hcec->MspInitCallback == NULL) |
204 | |
| 205 | { |
205 | if (hcec->MspInitCallback == NULL) |
| 206 | hcec->MspInitCallback = HAL_CEC_MspInit; /* Legacy weak MspInit */ |
206 | { |
| 207 | } |
207 | hcec->MspInitCallback = HAL_CEC_MspInit; /* Legacy weak MspInit */ |
| 208 | 208 | } |
|
| 209 | /* Init the low level hardware */ |
209 | |
| 210 | hcec->MspInitCallback(hcec); |
210 | /* Init the low level hardware */ |
| 211 | } |
211 | hcec->MspInitCallback(hcec); |
| 212 | #else |
212 | } |
| 213 | if(hcec->gState == HAL_CEC_STATE_RESET) |
213 | #else |
| 214 | { |
214 | if (hcec->gState == HAL_CEC_STATE_RESET) |
| 215 | /* Allocate lock resource and initialize it */ |
215 | { |
| 216 | hcec->Lock = HAL_UNLOCKED; |
216 | /* Allocate lock resource and initialize it */ |
| 217 | /* Init the low level hardware : GPIO, CLOCK */ |
217 | hcec->Lock = HAL_UNLOCKED; |
| 218 | HAL_CEC_MspInit(hcec); |
218 | /* Init the low level hardware : GPIO, CLOCK */ |
| 219 | } |
219 | HAL_CEC_MspInit(hcec); |
| 220 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
220 | } |
| 221 | 221 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
|
| 222 | hcec->gState = HAL_CEC_STATE_BUSY; |
222 | |
| 223 | 223 | hcec->gState = HAL_CEC_STATE_BUSY; |
|
| 224 | /* Disable the Peripheral */ |
224 | |
| 225 | __HAL_CEC_DISABLE(hcec); |
225 | /* Disable the Peripheral */ |
| 226 | 226 | __HAL_CEC_DISABLE(hcec); |
|
| 227 | /* Write to CEC Control Register */ |
227 | |
| 228 | MODIFY_REG(hcec->Instance->CFGR, CEC_CFGR_FIELDS, hcec->Init.TimingErrorFree | hcec->Init.PeriodErrorFree); |
228 | /* Write to CEC Control Register */ |
| 229 | 229 | MODIFY_REG(hcec->Instance->CFGR, CEC_CFGR_FIELDS, hcec->Init.TimingErrorFree | hcec->Init.PeriodErrorFree); |
|
| 230 | /* Write to CEC Own Address Register */ |
230 | |
| 231 | MODIFY_REG(hcec->Instance->OAR, CEC_OAR_OA, hcec->Init.OwnAddress); |
231 | /* Write to CEC Own Address Register */ |
| 232 | 232 | MODIFY_REG(hcec->Instance->OAR, CEC_OAR_OA, hcec->Init.OwnAddress); |
|
| 233 | /* Configure the prescaler to generate the required 50 microseconds time base.*/ |
233 | |
| 234 | MODIFY_REG(hcec->Instance->PRES, CEC_PRES_PRES, 50U * (HAL_RCC_GetPCLK1Freq()/1000000U) - 1U); |
234 | /* Configure the prescaler to generate the required 50 microseconds time base.*/ |
| 235 | 235 | MODIFY_REG(hcec->Instance->PRES, CEC_PRES_PRES, 50U * (HAL_RCC_GetPCLK1Freq() / 1000000U) - 1U); |
|
| 236 | /* Enable the following CEC Interrupt */ |
236 | |
| 237 | __HAL_CEC_ENABLE_IT(hcec, CEC_IT_IE); |
237 | /* Enable the following CEC Interrupt */ |
| 238 | 238 | __HAL_CEC_ENABLE_IT(hcec, CEC_IT_IE); |
|
| 239 | /* Enable the CEC Peripheral */ |
239 | |
| 240 | __HAL_CEC_ENABLE(hcec); |
240 | /* Enable the CEC Peripheral */ |
| 241 | 241 | __HAL_CEC_ENABLE(hcec); |
|
| 242 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
242 | |
| 243 | hcec->gState = HAL_CEC_STATE_READY; |
243 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
| 244 | hcec->RxState = HAL_CEC_STATE_READY; |
244 | hcec->gState = HAL_CEC_STATE_READY; |
| 245 | 245 | hcec->RxState = HAL_CEC_STATE_READY; |
|
| 246 | return HAL_OK; |
246 | |
| 247 | } |
247 | return HAL_OK; |
| 248 | 248 | } |
|
| 249 | /** |
249 | |
| 250 | * @brief DeInitializes the CEC peripheral |
250 | /** |
| 251 | * @param hcec: CEC handle |
251 | * @brief DeInitializes the CEC peripheral |
| 252 | * @retval HAL status |
252 | * @param hcec CEC handle |
| 253 | */ |
253 | * @retval HAL status |
| 254 | HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec) |
254 | */ |
| 255 | { |
255 | HAL_StatusTypeDef HAL_CEC_DeInit(CEC_HandleTypeDef *hcec) |
| 256 | /* Check the CEC handle allocation */ |
256 | { |
| 257 | if(hcec == NULL) |
257 | /* Check the CEC handle allocation */ |
| 258 | { |
258 | if (hcec == NULL) |
| 259 | return HAL_ERROR; |
259 | { |
| 260 | } |
260 | return HAL_ERROR; |
| 261 | 261 | } |
|
| 262 | /* Check the parameters */ |
262 | |
| 263 | assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance)); |
263 | /* Check the parameters */ |
| 264 | 264 | assert_param(IS_CEC_ALL_INSTANCE(hcec->Instance)); |
|
| 265 | hcec->gState = HAL_CEC_STATE_BUSY; |
265 | |
| 266 | 266 | hcec->gState = HAL_CEC_STATE_BUSY; |
|
| 267 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
267 | |
| 268 | if(hcec->MspDeInitCallback == NULL) |
268 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
| 269 | { |
269 | if (hcec->MspDeInitCallback == NULL) |
| 270 | hcec->MspDeInitCallback = HAL_CEC_MspDeInit; /* Legacy weak MspDeInit */ |
270 | { |
| 271 | } |
271 | hcec->MspDeInitCallback = HAL_CEC_MspDeInit; /* Legacy weak MspDeInit */ |
| 272 | 272 | } |
|
| 273 | /* DeInit the low level hardware */ |
273 | |
| 274 | hcec->MspDeInitCallback(hcec); |
274 | /* DeInit the low level hardware */ |
| 275 | 275 | hcec->MspDeInitCallback(hcec); |
|
| 276 | #else |
276 | |
| 277 | /* DeInit the low level hardware */ |
277 | #else |
| 278 | HAL_CEC_MspDeInit(hcec); |
278 | /* DeInit the low level hardware */ |
| 279 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
279 | HAL_CEC_MspDeInit(hcec); |
| 280 | 280 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
|
| 281 | __HAL_RCC_CEC_FORCE_RESET(); |
281 | |
| 282 | __HAL_RCC_CEC_RELEASE_RESET(); |
282 | __HAL_RCC_CEC_FORCE_RESET(); |
| 283 | 283 | __HAL_RCC_CEC_RELEASE_RESET(); |
|
| 284 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
284 | |
| 285 | hcec->gState = HAL_CEC_STATE_RESET; |
285 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
| 286 | hcec->RxState = HAL_CEC_STATE_RESET; |
286 | hcec->gState = HAL_CEC_STATE_RESET; |
| 287 | 287 | hcec->RxState = HAL_CEC_STATE_RESET; |
|
| 288 | /* Process Unlock */ |
288 | |
| 289 | __HAL_UNLOCK(hcec); |
289 | /* Process Unlock */ |
| 290 | 290 | __HAL_UNLOCK(hcec); |
|
| 291 | return HAL_OK; |
291 | |
| 292 | } |
292 | return HAL_OK; |
| 293 | 293 | } |
|
| 294 | /** |
294 | |
| 295 | * @brief Initializes the Own Address of the CEC device |
295 | /** |
| 296 | * @param hcec: CEC handle |
296 | * @brief Initializes the Own Address of the CEC device |
| 297 | * @param CEC_OwnAddress: The CEC own address. |
297 | * @param hcec CEC handle |
| 298 | * @retval HAL status |
298 | * @param CEC_OwnAddress The CEC own address. |
| 299 | */ |
299 | * @retval HAL status |
| 300 | HAL_StatusTypeDef HAL_CEC_SetDeviceAddress(CEC_HandleTypeDef *hcec, uint16_t CEC_OwnAddress) |
300 | */ |
| 301 | { |
301 | HAL_StatusTypeDef HAL_CEC_SetDeviceAddress(CEC_HandleTypeDef *hcec, uint16_t CEC_OwnAddress) |
| 302 | /* Check the parameters */ |
302 | { |
| 303 | assert_param(IS_CEC_OWN_ADDRESS(CEC_OwnAddress)); |
303 | /* Check the parameters */ |
| 304 | 304 | assert_param(IS_CEC_OWN_ADDRESS(CEC_OwnAddress)); |
|
| 305 | if ((hcec->gState == HAL_CEC_STATE_READY) && (hcec->RxState == HAL_CEC_STATE_READY)) |
305 | |
| 306 | { |
306 | if ((hcec->gState == HAL_CEC_STATE_READY) && (hcec->RxState == HAL_CEC_STATE_READY)) |
| 307 | /* Process Locked */ |
307 | { |
| 308 | __HAL_LOCK(hcec); |
308 | /* Process Locked */ |
| 309 | 309 | __HAL_LOCK(hcec); |
|
| 310 | hcec->gState = HAL_CEC_STATE_BUSY; |
310 | |
| 311 | 311 | hcec->gState = HAL_CEC_STATE_BUSY; |
|
| 312 | /* Disable the Peripheral */ |
312 | |
| 313 | __HAL_CEC_DISABLE(hcec); |
313 | /* Disable the Peripheral */ |
| 314 | 314 | __HAL_CEC_DISABLE(hcec); |
|
| 315 | if(CEC_OwnAddress != CEC_OWN_ADDRESS_NONE) |
315 | |
| 316 | { |
316 | if (CEC_OwnAddress != CEC_OWN_ADDRESS_NONE) |
| 317 | MODIFY_REG(hcec->Instance->OAR, CEC_OAR_OA, hcec->Init.OwnAddress); |
317 | { |
| 318 | } |
318 | MODIFY_REG(hcec->Instance->OAR, CEC_OAR_OA, hcec->Init.OwnAddress); |
| 319 | else |
319 | } |
| 320 | { |
320 | else |
| 321 | CLEAR_BIT(hcec->Instance->OAR, CEC_OAR_OA); |
321 | { |
| 322 | } |
322 | CLEAR_BIT(hcec->Instance->OAR, CEC_OAR_OA); |
| 323 | 323 | } |
|
| 324 | hcec->gState = HAL_CEC_STATE_READY; |
324 | |
| 325 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
325 | hcec->gState = HAL_CEC_STATE_READY; |
| 326 | 326 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
|
| 327 | /* Process Unlocked */ |
327 | |
| 328 | __HAL_UNLOCK(hcec); |
328 | /* Process Unlocked */ |
| 329 | 329 | __HAL_UNLOCK(hcec); |
|
| 330 | /* Enable the Peripheral */ |
330 | |
| 331 | __HAL_CEC_ENABLE(hcec); |
331 | /* Enable the Peripheral */ |
| 332 | 332 | __HAL_CEC_ENABLE(hcec); |
|
| 333 | return HAL_OK; |
333 | |
| 334 | } |
334 | return HAL_OK; |
| 335 | else |
335 | } |
| 336 | { |
336 | else |
| 337 | return HAL_BUSY; |
337 | { |
| 338 | } |
338 | return HAL_BUSY; |
| 339 | } |
339 | } |
| 340 | 340 | } |
|
| 341 | /** |
341 | |
| 342 | * @brief CEC MSP Init |
342 | /** |
| 343 | * @param hcec: CEC handle |
343 | * @brief CEC MSP Init |
| 344 | * @retval None |
344 | * @param hcec CEC handle |
| 345 | */ |
345 | * @retval None |
| 346 | __weak void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec) |
346 | */ |
| 347 | { |
347 | __weak void HAL_CEC_MspInit(CEC_HandleTypeDef *hcec) |
| 348 | /* Prevent unused argument(s) compilation warning */ |
348 | { |
| 349 | UNUSED(hcec); |
349 | /* Prevent unused argument(s) compilation warning */ |
| 350 | /* NOTE : This function should not be modified, when the callback is needed, |
350 | UNUSED(hcec); |
| 351 | the HAL_CEC_MspInit can be implemented in the user file |
351 | /* NOTE : This function should not be modified, when the callback is needed, |
| 352 | */ |
352 | the HAL_CEC_MspInit can be implemented in the user file |
| 353 | } |
353 | */ |
| 354 | 354 | } |
|
| 355 | /** |
355 | |
| 356 | * @brief CEC MSP DeInit |
356 | /** |
| 357 | * @param hcec: CEC handle |
357 | * @brief CEC MSP DeInit |
| 358 | * @retval None |
358 | * @param hcec CEC handle |
| 359 | */ |
359 | * @retval None |
| 360 | __weak void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec) |
360 | */ |
| 361 | { |
361 | __weak void HAL_CEC_MspDeInit(CEC_HandleTypeDef *hcec) |
| 362 | /* Prevent unused argument(s) compilation warning */ |
362 | { |
| 363 | UNUSED(hcec); |
363 | /* Prevent unused argument(s) compilation warning */ |
| 364 | /* NOTE : This function should not be modified, when the callback is needed, |
364 | UNUSED(hcec); |
| 365 | the HAL_CEC_MspDeInit can be implemented in the user file |
365 | /* NOTE : This function should not be modified, when the callback is needed, |
| 366 | */ |
366 | the HAL_CEC_MspDeInit can be implemented in the user file |
| 367 | } |
367 | */ |
| 368 | 368 | } |
|
| 369 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
369 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
| 370 | /** |
370 | /** |
| 371 | * @brief Register a User CEC Callback |
371 | * @brief Register a User CEC Callback |
| 372 | * To be used instead of the weak predefined callback |
372 | * To be used instead of the weak predefined callback |
| 373 | * @param hcec CEC handle |
373 | * @param hcec CEC handle |
| 374 | * @param CallbackID ID of the callback to be registered |
374 | * @param CallbackID ID of the callback to be registered |
| 375 | * This parameter can be one of the following values: |
375 | * This parameter can be one of the following values: |
| 376 | * @arg @ref HAL_CEC_TX_CPLT_CB_ID Tx Complete callback ID |
376 | * @arg @ref HAL_CEC_TX_CPLT_CB_ID Tx Complete callback ID |
| 377 | * @arg @ref HAL_CEC_ERROR_CB_ID Error callback ID |
377 | * @arg @ref HAL_CEC_ERROR_CB_ID Error callback ID |
| 378 | * @arg @ref HAL_CEC_MSPINIT_CB_ID MspInit callback ID |
378 | * @arg @ref HAL_CEC_MSPINIT_CB_ID MspInit callback ID |
| 379 | * @arg @ref HAL_CEC_MSPDEINIT_CB_ID MspDeInit callback ID |
379 | * @arg @ref HAL_CEC_MSPDEINIT_CB_ID MspDeInit callback ID |
| 380 | * @param pCallback pointer to the Callback function |
380 | * @param pCallback pointer to the Callback function |
| 381 | * @retval HAL status |
381 | * @retval HAL status |
| 382 | */ |
382 | */ |
| 383 | HAL_StatusTypeDef HAL_CEC_RegisterCallback(CEC_HandleTypeDef *hcec, HAL_CEC_CallbackIDTypeDef CallbackID, pCEC_CallbackTypeDef pCallback) |
383 | HAL_StatusTypeDef HAL_CEC_RegisterCallback(CEC_HandleTypeDef *hcec, HAL_CEC_CallbackIDTypeDef CallbackID, |
| 384 | { |
384 | pCEC_CallbackTypeDef pCallback) |
| 385 | HAL_StatusTypeDef status = HAL_OK; |
385 | { |
| 386 | 386 | HAL_StatusTypeDef status = HAL_OK; |
|
| 387 | if(pCallback == NULL) |
387 | |
| 388 | { |
388 | if (pCallback == NULL) |
| 389 | /* Update the error code */ |
389 | { |
| 390 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
390 | /* Update the error code */ |
| 391 | return HAL_ERROR; |
391 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
| 392 | } |
392 | return HAL_ERROR; |
| 393 | /* Process locked */ |
393 | } |
| 394 | __HAL_LOCK(hcec); |
394 | /* Process locked */ |
| 395 | 395 | __HAL_LOCK(hcec); |
|
| 396 | if(hcec->gState == HAL_CEC_STATE_READY) |
396 | |
| 397 | { |
397 | if (hcec->gState == HAL_CEC_STATE_READY) |
| 398 | switch (CallbackID) |
398 | { |
| 399 | { |
399 | switch (CallbackID) |
| 400 | case HAL_CEC_TX_CPLT_CB_ID : |
400 | { |
| 401 | hcec->TxCpltCallback = pCallback; |
401 | case HAL_CEC_TX_CPLT_CB_ID : |
| 402 | break; |
402 | hcec->TxCpltCallback = pCallback; |
| 403 | 403 | break; |
|
| 404 | case HAL_CEC_ERROR_CB_ID : |
404 | |
| 405 | hcec->ErrorCallback = pCallback; |
405 | case HAL_CEC_ERROR_CB_ID : |
| 406 | break; |
406 | hcec->ErrorCallback = pCallback; |
| 407 | 407 | break; |
|
| 408 | case HAL_CEC_MSPINIT_CB_ID : |
408 | |
| 409 | hcec->MspInitCallback = pCallback; |
409 | case HAL_CEC_MSPINIT_CB_ID : |
| 410 | break; |
410 | hcec->MspInitCallback = pCallback; |
| 411 | 411 | break; |
|
| 412 | case HAL_CEC_MSPDEINIT_CB_ID : |
412 | |
| 413 | hcec->MspDeInitCallback = pCallback; |
413 | case HAL_CEC_MSPDEINIT_CB_ID : |
| 414 | break; |
414 | hcec->MspDeInitCallback = pCallback; |
| 415 | 415 | break; |
|
| 416 | default : |
416 | |
| 417 | /* Update the error code */ |
417 | default : |
| 418 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
418 | /* Update the error code */ |
| 419 | /* Return error status */ |
419 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
| 420 | status = HAL_ERROR; |
420 | /* Return error status */ |
| 421 | break; |
421 | status = HAL_ERROR; |
| 422 | } |
422 | break; |
| 423 | } |
423 | } |
| 424 | else if(hcec->gState == HAL_CEC_STATE_RESET) |
424 | } |
| 425 | { |
425 | else if (hcec->gState == HAL_CEC_STATE_RESET) |
| 426 | switch (CallbackID) |
426 | { |
| 427 | { |
427 | switch (CallbackID) |
| 428 | case HAL_CEC_MSPINIT_CB_ID : |
428 | { |
| 429 | hcec->MspInitCallback = pCallback; |
429 | case HAL_CEC_MSPINIT_CB_ID : |
| 430 | break; |
430 | hcec->MspInitCallback = pCallback; |
| 431 | 431 | break; |
|
| 432 | case HAL_CEC_MSPDEINIT_CB_ID : |
432 | |
| 433 | hcec->MspDeInitCallback = pCallback; |
433 | case HAL_CEC_MSPDEINIT_CB_ID : |
| 434 | break; |
434 | hcec->MspDeInitCallback = pCallback; |
| 435 | 435 | break; |
|
| 436 | default : |
436 | |
| 437 | /* Update the error code */ |
437 | default : |
| 438 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
438 | /* Update the error code */ |
| 439 | /* Return error status */ |
439 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
| 440 | status = HAL_ERROR; |
440 | /* Return error status */ |
| 441 | break; |
441 | status = HAL_ERROR; |
| 442 | } |
442 | break; |
| 443 | } |
443 | } |
| 444 | else |
444 | } |
| 445 | { |
445 | else |
| 446 | /* Update the error code */ |
446 | { |
| 447 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
447 | /* Update the error code */ |
| 448 | /* Return error status */ |
448 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
| 449 | status = HAL_ERROR; |
449 | /* Return error status */ |
| 450 | } |
450 | status = HAL_ERROR; |
| 451 | 451 | } |
|
| 452 | /* Release Lock */ |
452 | |
| 453 | __HAL_UNLOCK(hcec); |
453 | /* Release Lock */ |
| 454 | 454 | __HAL_UNLOCK(hcec); |
|
| 455 | return status; |
455 | |
| 456 | } |
456 | return status; |
| 457 | 457 | } |
|
| 458 | /** |
458 | |
| 459 | * @brief Unregister an CEC Callback |
459 | /** |
| 460 | * CEC callabck is redirected to the weak predefined callback |
460 | * @brief Unregister an CEC Callback |
| 461 | * @param hcec uart handle |
461 | * CEC callback is redirected to the weak predefined callback |
| 462 | * @param CallbackID ID of the callback to be unregistered |
462 | * @param hcec uart handle |
| 463 | * This parameter can be one of the following values: |
463 | * @param CallbackID ID of the callback to be unregistered |
| 464 | * @arg @ref HAL_CEC_TX_CPLT_CB_ID Tx Complete callback IDD |
464 | * This parameter can be one of the following values: |
| 465 | * @arg @ref HAL_CEC_ERROR_CB_ID Error callback ID |
465 | * @arg @ref HAL_CEC_TX_CPLT_CB_ID Tx Complete callback ID |
| 466 | * @arg @ref HAL_CEC_MSPINIT_CB_ID MspInit callback ID |
466 | * @arg @ref HAL_CEC_ERROR_CB_ID Error callback ID |
| 467 | * @arg @ref HAL_CEC_MSPDEINIT_CB_ID MspDeInit callback ID |
467 | * @arg @ref HAL_CEC_MSPINIT_CB_ID MspInit callback ID |
| 468 | * @retval status |
468 | * @arg @ref HAL_CEC_MSPDEINIT_CB_ID MspDeInit callback ID |
| 469 | */ |
469 | * @retval status |
| 470 | HAL_StatusTypeDef HAL_CEC_UnRegisterCallback(CEC_HandleTypeDef *hcec, HAL_CEC_CallbackIDTypeDef CallbackID) |
470 | */ |
| 471 | { |
471 | HAL_StatusTypeDef HAL_CEC_UnRegisterCallback(CEC_HandleTypeDef *hcec, HAL_CEC_CallbackIDTypeDef CallbackID) |
| 472 | HAL_StatusTypeDef status = HAL_OK; |
472 | { |
| 473 | 473 | HAL_StatusTypeDef status = HAL_OK; |
|
| 474 | /* Process locked */ |
474 | |
| 475 | __HAL_LOCK(hcec); |
475 | /* Process locked */ |
| 476 | 476 | __HAL_LOCK(hcec); |
|
| 477 | if(hcec->gState == HAL_CEC_STATE_READY) |
477 | |
| 478 | { |
478 | if (hcec->gState == HAL_CEC_STATE_READY) |
| 479 | switch (CallbackID) |
479 | { |
| 480 | { |
480 | switch (CallbackID) |
| 481 | case HAL_CEC_TX_CPLT_CB_ID : |
481 | { |
| 482 | hcec->TxCpltCallback = HAL_CEC_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
482 | case HAL_CEC_TX_CPLT_CB_ID : |
| 483 | break; |
483 | hcec->TxCpltCallback = HAL_CEC_TxCpltCallback; /* Legacy weak TxCpltCallback */ |
| 484 | 484 | break; |
|
| 485 | case HAL_CEC_ERROR_CB_ID : |
485 | |
| 486 | hcec->ErrorCallback = HAL_CEC_ErrorCallback; /* Legacy weak ErrorCallback */ |
486 | case HAL_CEC_ERROR_CB_ID : |
| 487 | break; |
487 | hcec->ErrorCallback = HAL_CEC_ErrorCallback; /* Legacy weak ErrorCallback */ |
| 488 | 488 | break; |
|
| 489 | case HAL_CEC_MSPINIT_CB_ID : |
489 | |
| 490 | hcec->MspInitCallback = HAL_CEC_MspInit; |
490 | case HAL_CEC_MSPINIT_CB_ID : |
| 491 | break; |
491 | hcec->MspInitCallback = HAL_CEC_MspInit; |
| 492 | 492 | break; |
|
| 493 | case HAL_CEC_MSPDEINIT_CB_ID : |
493 | |
| 494 | hcec->MspDeInitCallback = HAL_CEC_MspDeInit; |
494 | case HAL_CEC_MSPDEINIT_CB_ID : |
| 495 | break; |
495 | hcec->MspDeInitCallback = HAL_CEC_MspDeInit; |
| 496 | 496 | break; |
|
| 497 | default : |
497 | |
| 498 | /* Update the error code */ |
498 | default : |
| 499 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
499 | /* Update the error code */ |
| 500 | /* Return error status */ |
500 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
| 501 | status = HAL_ERROR; |
501 | /* Return error status */ |
| 502 | break; |
502 | status = HAL_ERROR; |
| 503 | } |
503 | break; |
| 504 | } |
504 | } |
| 505 | else if(hcec->gState == HAL_CEC_STATE_RESET) |
505 | } |
| 506 | { |
506 | else if (hcec->gState == HAL_CEC_STATE_RESET) |
| 507 | switch (CallbackID) |
507 | { |
| 508 | { |
508 | switch (CallbackID) |
| 509 | case HAL_CEC_MSPINIT_CB_ID : |
509 | { |
| 510 | hcec->MspInitCallback = HAL_CEC_MspInit; |
510 | case HAL_CEC_MSPINIT_CB_ID : |
| 511 | break; |
511 | hcec->MspInitCallback = HAL_CEC_MspInit; |
| 512 | 512 | break; |
|
| 513 | case HAL_CEC_MSPDEINIT_CB_ID : |
513 | |
| 514 | hcec->MspDeInitCallback = HAL_CEC_MspDeInit; |
514 | case HAL_CEC_MSPDEINIT_CB_ID : |
| 515 | break; |
515 | hcec->MspDeInitCallback = HAL_CEC_MspDeInit; |
| 516 | 516 | break; |
|
| 517 | default : |
517 | |
| 518 | /* Update the error code */ |
518 | default : |
| 519 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
519 | /* Update the error code */ |
| 520 | /* Return error status */ |
520 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
| 521 | status = HAL_ERROR; |
521 | /* Return error status */ |
| 522 | break; |
522 | status = HAL_ERROR; |
| 523 | } |
523 | break; |
| 524 | } |
524 | } |
| 525 | else |
525 | } |
| 526 | { |
526 | else |
| 527 | /* Update the error code */ |
527 | { |
| 528 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
528 | /* Update the error code */ |
| 529 | /* Return error status */ |
529 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
| 530 | status = HAL_ERROR; |
530 | /* Return error status */ |
| 531 | } |
531 | status = HAL_ERROR; |
| 532 | 532 | } |
|
| 533 | /* Release Lock */ |
533 | |
| 534 | __HAL_UNLOCK(hcec); |
534 | /* Release Lock */ |
| 535 | 535 | __HAL_UNLOCK(hcec); |
|
| 536 | return status; |
536 | |
| 537 | } |
537 | return status; |
| 538 | 538 | } |
|
| 539 | /** |
539 | |
| 540 | * @brief Register CEC RX complete Callback |
540 | /** |
| 541 | * To be used instead of the weak HAL_CEC_RxCpltCallback() predefined callback |
541 | * @brief Register CEC RX complete Callback |
| 542 | * @param hcec CEC handle |
542 | * To be used instead of the weak HAL_CEC_RxCpltCallback() predefined callback |
| 543 | * @param pCallback pointer to the Rx transfer compelete Callback function |
543 | * @param hcec CEC handle |
| 544 | * @retval HAL status |
544 | * @param pCallback pointer to the Rx transfer compelete Callback function |
| 545 | */ |
545 | * @retval HAL status |
| 546 | HAL_StatusTypeDef HAL_CEC_RegisterRxCpltCallback(CEC_HandleTypeDef *hcec, pCEC_RxCallbackTypeDef pCallback) |
546 | */ |
| 547 | { |
547 | HAL_StatusTypeDef HAL_CEC_RegisterRxCpltCallback(CEC_HandleTypeDef *hcec, pCEC_RxCallbackTypeDef pCallback) |
| 548 | HAL_StatusTypeDef status = HAL_OK; |
548 | { |
| 549 | 549 | HAL_StatusTypeDef status = HAL_OK; |
|
| 550 | if(pCallback == NULL) |
550 | |
| 551 | { |
551 | if (pCallback == NULL) |
| 552 | /* Update the error code */ |
552 | { |
| 553 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
553 | /* Update the error code */ |
| 554 | return HAL_ERROR; |
554 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
| 555 | } |
555 | return HAL_ERROR; |
| 556 | /* Process locked */ |
556 | } |
| 557 | __HAL_LOCK(hcec); |
557 | /* Process locked */ |
| 558 | 558 | __HAL_LOCK(hcec); |
|
| 559 | if(HAL_CEC_STATE_READY == hcec->RxState) |
559 | |
| 560 | { |
560 | if (HAL_CEC_STATE_READY == hcec->RxState) |
| 561 | hcec->RxCpltCallback = pCallback; |
561 | { |
| 562 | } |
562 | hcec->RxCpltCallback = pCallback; |
| 563 | else |
563 | } |
| 564 | { |
564 | else |
| 565 | /* Update the error code */ |
565 | { |
| 566 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
566 | /* Update the error code */ |
| 567 | /* Return error status */ |
567 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
| 568 | status = HAL_ERROR; |
568 | /* Return error status */ |
| 569 | } |
569 | status = HAL_ERROR; |
| 570 | 570 | } |
|
| 571 | /* Release Lock */ |
571 | |
| 572 | __HAL_UNLOCK(hcec); |
572 | /* Release Lock */ |
| 573 | return status; |
573 | __HAL_UNLOCK(hcec); |
| 574 | } |
574 | return status; |
| 575 | 575 | } |
|
| 576 | /** |
576 | |
| 577 | * @brief UnRegister CEC RX complete Callback |
577 | /** |
| 578 | * CEC RX complete Callback is redirected to the weak HAL_CEC_RxCpltCallback() predefined callback |
578 | * @brief UnRegister CEC RX complete Callback |
| 579 | * @param hcec CEC handle |
579 | * CEC RX complete Callback is redirected to the weak HAL_CEC_RxCpltCallback() predefined callback |
| 580 | * @retval HAL status |
580 | * @param hcec CEC handle |
| 581 | */ |
581 | * @retval HAL status |
| 582 | HAL_StatusTypeDef HAL_CEC_UnRegisterRxCpltCallback(CEC_HandleTypeDef *hcec) |
582 | */ |
| 583 | { |
583 | HAL_StatusTypeDef HAL_CEC_UnRegisterRxCpltCallback(CEC_HandleTypeDef *hcec) |
| 584 | HAL_StatusTypeDef status = HAL_OK; |
584 | { |
| 585 | 585 | HAL_StatusTypeDef status = HAL_OK; |
|
| 586 | /* Process locked */ |
586 | |
| 587 | __HAL_LOCK(hcec); |
587 | /* Process locked */ |
| 588 | 588 | __HAL_LOCK(hcec); |
|
| 589 | if(HAL_CEC_STATE_READY == hcec->RxState) |
589 | |
| 590 | { |
590 | if (HAL_CEC_STATE_READY == hcec->RxState) |
| 591 | hcec->RxCpltCallback = HAL_CEC_RxCpltCallback; /* Legacy weak CEC RxCpltCallback */ |
591 | { |
| 592 | } |
592 | hcec->RxCpltCallback = HAL_CEC_RxCpltCallback; /* Legacy weak CEC RxCpltCallback */ |
| 593 | else |
593 | } |
| 594 | { |
594 | else |
| 595 | /* Update the error code */ |
595 | { |
| 596 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
596 | /* Update the error code */ |
| 597 | /* Return error status */ |
597 | hcec->ErrorCode |= HAL_CEC_ERROR_INVALID_CALLBACK; |
| 598 | status = HAL_ERROR; |
598 | /* Return error status */ |
| 599 | } |
599 | status = HAL_ERROR; |
| 600 | 600 | } |
|
| 601 | /* Release Lock */ |
601 | |
| 602 | __HAL_UNLOCK(hcec); |
602 | /* Release Lock */ |
| 603 | return status; |
603 | __HAL_UNLOCK(hcec); |
| 604 | } |
604 | return status; |
| 605 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
605 | } |
| 606 | 606 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
|
| 607 | /** |
607 | |
| 608 | * @} |
608 | /** |
| 609 | */ |
609 | * @} |
| 610 | 610 | */ |
|
| 611 | /** @defgroup CEC_Exported_Functions_Group2 Input and Output operation functions |
611 | |
| 612 | * @brief CEC Transmit/Receive functions |
612 | /** @defgroup CEC_Exported_Functions_Group2 Input and Output operation functions |
| 613 | * |
613 | * @brief CEC Transmit/Receive functions |
| 614 | @verbatim |
614 | * |
| 615 | =============================================================================== |
615 | @verbatim |
| 616 | ##### IO operation functions ##### |
616 | =============================================================================== |
| 617 | =============================================================================== |
617 | ##### IO operation functions ##### |
| 618 | [..] |
618 | =============================================================================== |
| 619 | This subsection provides a set of functions allowing to manage the CEC data transfers. |
619 | This subsection provides a set of functions allowing to manage the CEC data transfers. |
| 620 | |
620 | |
| 621 | (#) The CEC handle must contain the initiator (TX side) and the destination (RX side) |
621 | (#) The CEC handle must contain the initiator (TX side) and the destination (RX side) |
| 622 | logical addresses (4-bit long addresses, 0xF for broadcast messages destination) |
622 | logical addresses (4-bit long addresses, 0xF for broadcast messages destination) |
| 623 | |
623 | |
| 624 | (#) The communication is performed using Interrupts. |
624 | (#) The communication is performed using Interrupts. |
| 625 | These API's return the HAL status. |
625 | These API's return the HAL status. |
| 626 | The end of the data processing will be indicated through the |
626 | The end of the data processing will be indicated through the |
| 627 | dedicated CEC IRQ when using Interrupt mode. |
627 | dedicated CEC IRQ when using Interrupt mode. |
| 628 | The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user callbacks |
628 | The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user callbacks |
| 629 | will be executed respectively at the end of the transmit or Receive process |
629 | will be executed respectively at the end of the transmit or Receive process |
| 630 | The HAL_CEC_ErrorCallback() user callback will be executed when a communication |
630 | The HAL_CEC_ErrorCallback() user callback will be executed when a communication |
| 631 | error is detected |
631 | error is detected |
| 632 | |
632 | |
| 633 | (#) API's with Interrupt are : |
633 | (#) API's with Interrupt are : |
| 634 | (+) HAL_CEC_Transmit_IT() |
634 | (+) HAL_CEC_Transmit_IT() |
| 635 | (+) HAL_CEC_IRQHandler() |
635 | (+) HAL_CEC_IRQHandler() |
| 636 | 636 | ||
| 637 | (#) A set of User Callbacks are provided: |
637 | (#) A set of User Callbacks are provided: |
| 638 | (+) HAL_CEC_TxCpltCallback() |
638 | (+) HAL_CEC_TxCpltCallback() |
| 639 | (+) HAL_CEC_RxCpltCallback() |
639 | (+) HAL_CEC_RxCpltCallback() |
| 640 | (+) HAL_CEC_ErrorCallback() |
640 | (+) HAL_CEC_ErrorCallback() |
| 641 | |
641 | |
| 642 | @endverbatim |
642 | @endverbatim |
| 643 | * @{ |
643 | * @{ |
| 644 | */ |
644 | */ |
| 645 | 645 | ||
| 646 | /** |
646 | /** |
| 647 | * @brief Send data in interrupt mode |
647 | * @brief Send data in interrupt mode |
| 648 | * @param hcec: CEC handle |
648 | * @param hcec CEC handle |
| 649 | * @param InitiatorAddress: Initiator address |
649 | * @param InitiatorAddress Initiator address |
| 650 | * @param DestinationAddress: destination logical address |
650 | * @param DestinationAddress destination logical address |
| 651 | * @param pData: pointer to input byte data buffer |
651 | * @param pData pointer to input byte data buffer |
| 652 | * @param Size: amount of data to be sent in bytes (without counting the header). |
652 | * @param Size amount of data to be sent in bytes (without counting the header). |
| 653 | * 0 means only the header is sent (ping operation). |
653 | * 0 means only the header is sent (ping operation). |
| 654 | * Maximum TX size is 15 bytes (1 opcode and up to 14 operands). |
654 | * Maximum TX size is 15 bytes (1 opcode and up to 14 operands). |
| 655 | * @retval HAL status |
655 | * @retval HAL status |
| 656 | */ |
656 | */ |
| 657 | HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t InitiatorAddress,uint8_t DestinationAddress, uint8_t *pData, uint32_t Size) |
657 | HAL_StatusTypeDef HAL_CEC_Transmit_IT(CEC_HandleTypeDef *hcec, uint8_t InitiatorAddress, uint8_t DestinationAddress, |
| 658 | { |
658 | const uint8_t *pData, uint32_t Size) |
| 659 | /* if the IP isn't already busy and if there is no previous transmission |
659 | { |
| 660 | already pending due to arbitration lost */ |
660 | /* if the peripheral isn't already busy and if there is no previous transmission |
| 661 | if(hcec->gState == HAL_CEC_STATE_READY) |
661 | already pending due to arbitration lost */ |
| 662 | { |
662 | if (hcec->gState == HAL_CEC_STATE_READY) |
| 663 | if((pData == NULL ) && (Size > 0U)) |
663 | { |
| 664 | { |
664 | if ((pData == NULL) && (Size > 0U)) |
| 665 | return HAL_ERROR; |
665 | { |
| 666 | } |
666 | return HAL_ERROR; |
| 667 | 667 | } |
|
| 668 | assert_param(IS_CEC_ADDRESS(DestinationAddress)); |
668 | |
| 669 | assert_param(IS_CEC_ADDRESS(InitiatorAddress)); |
669 | assert_param(IS_CEC_ADDRESS(DestinationAddress)); |
| 670 | assert_param(IS_CEC_MSGSIZE(Size)); |
670 | assert_param(IS_CEC_ADDRESS(InitiatorAddress)); |
| 671 | 671 | assert_param(IS_CEC_MSGSIZE(Size)); |
|
| 672 | /* Process Locked */ |
672 | |
| 673 | __HAL_LOCK(hcec); |
673 | /* Process Locked */ |
| 674 | hcec->pTxBuffPtr = pData; |
674 | __HAL_LOCK(hcec); |
| 675 | hcec->gState = HAL_CEC_STATE_BUSY_TX; |
675 | hcec->pTxBuffPtr = pData; |
| 676 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
676 | hcec->gState = HAL_CEC_STATE_BUSY_TX; |
| 677 | 677 | hcec->ErrorCode = HAL_CEC_ERROR_NONE; |
|
| 678 | /* initialize the number of bytes to send, |
678 | |
| 679 | * 0 means only one header is sent (ping operation) */ |
679 | /* initialize the number of bytes to send, |
| 680 | hcec->TxXferCount = Size; |
680 | * 0 means only one header is sent (ping operation) */ |
| 681 | 681 | hcec->TxXferCount = Size; |
|
| 682 | /* send header block */ |
682 | |
| 683 | hcec->Instance->TXD = (uint8_t)((uint32_t)InitiatorAddress << CEC_INITIATOR_LSB_POS) | DestinationAddress; |
683 | /* send header block */ |
| 684 | 684 | hcec->Instance->TXD = (uint8_t)((uint32_t)InitiatorAddress << CEC_INITIATOR_LSB_POS) | DestinationAddress; |
|
| 685 | /* Process Unlocked */ |
685 | |
| 686 | __HAL_UNLOCK(hcec); |
686 | /* Process Unlocked */ |
| 687 | 687 | __HAL_UNLOCK(hcec); |
|
| 688 | /* case no data to be sent, sender is only pinging the system */ |
688 | |
| 689 | if (Size != 0) |
689 | /* case no data to be sent, sender is only pinging the system */ |
| 690 | { |
690 | if (Size != 0) |
| 691 | /* Set TX Start of Message (TXSOM) bit */ |
691 | { |
| 692 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TSOM); |
692 | /* Set TX Start of Message (TXSOM) bit */ |
| 693 | } |
693 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TSOM); |
| 694 | else |
694 | } |
| 695 | { |
695 | else |
| 696 | /* Send a ping command */ |
696 | { |
| 697 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TEOM|CEC_FLAG_TSOM); |
697 | /* Send a ping command */ |
| 698 | } |
698 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TEOM | CEC_FLAG_TSOM); |
| 699 | return HAL_OK; |
699 | } |
| 700 | 700 | return HAL_OK; |
|
| 701 | } |
701 | |
| 702 | else |
702 | } |
| 703 | { |
703 | else |
| 704 | return HAL_BUSY; |
704 | { |
| 705 | } |
705 | return HAL_BUSY; |
| 706 | } |
706 | } |
| 707 | 707 | } |
|
| 708 | /** |
708 | |
| 709 | * @brief Get size of the received frame. |
709 | /** |
| 710 | * @param hcec: CEC handle |
710 | * @brief Get size of the received frame. |
| 711 | * @retval Frame size |
711 | * @param hcec CEC handle |
| 712 | */ |
712 | * @retval Frame size |
| 713 | uint32_t HAL_CEC_GetLastReceivedFrameSize(CEC_HandleTypeDef *hcec) |
713 | */ |
| 714 | { |
714 | uint32_t HAL_CEC_GetLastReceivedFrameSize(const CEC_HandleTypeDef *hcec) |
| 715 | return hcec->RxXferSize; |
715 | { |
| 716 | } |
716 | return hcec->RxXferSize; |
| 717 | 717 | } |
|
| 718 | /** |
718 | |
| 719 | * @brief Change Rx Buffer. |
719 | /** |
| 720 | * @param hcec: CEC handle |
720 | * @brief Change Rx Buffer. |
| 721 | * @param Rxbuffer: Rx Buffer |
721 | * @param hcec CEC handle |
| 722 | * @note This function can be called only inside the HAL_CEC_RxCpltCallback() |
722 | * @param Rxbuffer Rx Buffer |
| 723 | * @retval Frame size |
723 | * @note This function can be called only inside the HAL_CEC_RxCpltCallback() |
| 724 | */ |
724 | * @retval Frame size |
| 725 | void HAL_CEC_ChangeRxBuffer(CEC_HandleTypeDef *hcec, uint8_t* Rxbuffer) |
725 | */ |
| 726 | { |
726 | void HAL_CEC_ChangeRxBuffer(CEC_HandleTypeDef *hcec, uint8_t *Rxbuffer) |
| 727 | hcec->Init.RxBuffer = Rxbuffer; |
727 | { |
| 728 | } |
728 | hcec->Init.RxBuffer = Rxbuffer; |
| 729 | 729 | } |
|
| 730 | /** |
730 | |
| 731 | * @brief This function handles CEC interrupt requests. |
731 | /** |
| 732 | * @param hcec: CEC handle |
732 | * @brief This function handles CEC interrupt requests. |
| 733 | * @retval None |
733 | * @param hcec CEC handle |
| 734 | */ |
734 | * @retval None |
| 735 | void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec) |
735 | */ |
| 736 | { |
736 | void HAL_CEC_IRQHandler(CEC_HandleTypeDef *hcec) |
| 737 | /* Save error status register for further error handling purposes */ |
737 | { |
| 738 | hcec->ErrorCode = READ_BIT(hcec->Instance->ESR, CEC_ESR_ALL_ERROR); |
738 | |
| 739 | 739 | /* save interrupts register for further error or interrupts handling purposes */ |
|
| 740 | /* Transmit error */ |
740 | uint32_t itflag; |
| 741 | if(__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TERR) != RESET) |
741 | itflag = hcec->Instance->CSR; |
| 742 | { |
742 | |
| 743 | /* Acknowledgement of the error */ |
743 | /* Save error status register for further error handling purposes */ |
| 744 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TERR); |
744 | hcec->ErrorCode = READ_BIT(hcec->Instance->ESR, CEC_ESR_ALL_ERROR); |
| 745 | 745 | ||
| 746 | hcec->gState = HAL_CEC_STATE_READY; |
746 | /* Transmit error */ |
| 747 | } |
747 | if (HAL_IS_BIT_SET(itflag, CEC_FLAG_TERR)) |
| 748 | 748 | { |
|
| 749 | /* Receive error */ |
749 | /* Acknowledgement of the error */ |
| 750 | if(__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_RERR) != RESET) |
750 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_TERR); |
| 751 | { |
751 | |
| 752 | /* Acknowledgement of the error */ |
752 | hcec->gState = HAL_CEC_STATE_READY; |
| 753 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RERR); |
753 | } |
| 754 | hcec->Init.RxBuffer-=hcec->RxXferSize; |
754 | |
| 755 | hcec->RxXferSize = 0U; |
755 | /* Receive error */ |
| 756 | hcec->RxState = HAL_CEC_STATE_READY; |
756 | if (HAL_IS_BIT_SET(itflag, CEC_FLAG_RERR)) |
| 757 | } |
757 | { |
| 758 | 758 | /* Acknowledgement of the error */ |
|
| 759 | if((hcec->ErrorCode & CEC_ESR_ALL_ERROR) != 0U) |
759 | __HAL_CEC_CLEAR_FLAG(hcec, CEC_FLAG_RERR); |
| 760 | { |
760 | hcec->Init.RxBuffer -= hcec->RxXferSize; |
| 761 | /* Error Call Back */ |
761 | hcec->RxXferSize = 0U; |
| 762 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
762 | hcec->RxState = HAL_CEC_STATE_READY; |
| 763 | hcec->ErrorCallback(hcec); |
763 | } |
| 764 | #else |
764 | |
| 765 | HAL_CEC_ErrorCallback(hcec); |
765 | if ((hcec->ErrorCode & CEC_ESR_ALL_ERROR) != 0U) |
| 766 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
766 | { |
| 767 | } |
767 | /* Error Call Back */ |
| 768 | 768 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
|
| 769 | /* Transmit byte request or block transfer finished */ |
769 | hcec->ErrorCallback(hcec); |
| 770 | if(__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_TBTRF) != RESET) |
770 | #else |
| 771 | { |
771 | HAL_CEC_ErrorCallback(hcec); |
| 772 | CEC_Transmit_IT(hcec); |
772 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
| 773 | } |
773 | } |
| 774 | 774 | ||
| 775 | /* Receive byte or block transfer finished */ |
775 | /* Transmit byte request or block transfer finished */ |
| 776 | if(__HAL_CEC_GET_FLAG(hcec, CEC_FLAG_RBTF) != RESET) |
776 | if (HAL_IS_BIT_SET(itflag, CEC_FLAG_TBTRF)) |
| 777 | { |
777 | { |
| 778 | if(hcec->RxXferSize == 0U) |
778 | CEC_Transmit_IT(hcec); |
| 779 | { |
779 | } |
| 780 | /* reception is starting */ |
780 | |
| 781 | hcec->RxState = HAL_CEC_STATE_BUSY_RX; |
781 | /* Receive byte or block transfer finished */ |
| 782 | } |
782 | if (HAL_IS_BIT_SET(itflag, CEC_FLAG_RBTF)) |
| 783 | CEC_Receive_IT(hcec); |
783 | { |
| 784 | } |
784 | if (hcec->RxXferSize == 0U) |
| 785 | } |
785 | { |
| 786 | 786 | /* reception is starting */ |
|
| 787 | 787 | hcec->RxState = HAL_CEC_STATE_BUSY_RX; |
|
| 788 | /** |
788 | } |
| 789 | * @brief Tx Transfer completed callback |
789 | CEC_Receive_IT(hcec); |
| 790 | * @param hcec: CEC handle |
790 | } |
| 791 | * @retval None |
791 | } |
| 792 | */ |
792 | |
| 793 | __weak void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec) |
793 | /** |
| 794 | { |
794 | * @brief Tx Transfer completed callback |
| 795 | /* Prevent unused argument(s) compilation warning */ |
795 | * @param hcec CEC handle |
| 796 | UNUSED(hcec); |
796 | * @retval None |
| 797 | /* NOTE : This function should not be modified, when the callback is needed, |
797 | */ |
| 798 | the HAL_CEC_TxCpltCallback can be implemented in the user file |
798 | __weak void HAL_CEC_TxCpltCallback(CEC_HandleTypeDef *hcec) |
| 799 | */ |
799 | { |
| 800 | } |
800 | /* Prevent unused argument(s) compilation warning */ |
| 801 | 801 | UNUSED(hcec); |
|
| 802 | /** |
802 | /* NOTE : This function should not be modified, when the callback is needed, |
| 803 | * @brief Rx Transfer completed callback |
803 | the HAL_CEC_TxCpltCallback can be implemented in the user file |
| 804 | * @param hcec: CEC handle |
804 | */ |
| 805 | * @param RxFrameSize: Size of frame |
805 | } |
| 806 | * @retval None |
806 | |
| 807 | */ |
807 | /** |
| 808 | __weak void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec, uint32_t RxFrameSize) |
808 | * @brief Rx Transfer completed callback |
| 809 | { |
809 | * @param hcec CEC handle |
| 810 | /* Prevent unused argument(s) compilation warning */ |
810 | * @param RxFrameSize Size of frame |
| 811 | UNUSED(hcec); |
811 | * @retval None |
| 812 | UNUSED(RxFrameSize); |
812 | */ |
| 813 | /* NOTE : This function should not be modified, when the callback is needed, |
813 | __weak void HAL_CEC_RxCpltCallback(CEC_HandleTypeDef *hcec, uint32_t RxFrameSize) |
| 814 | the HAL_CEC_RxCpltCallback can be implemented in the user file |
814 | { |
| 815 | */ |
815 | /* Prevent unused argument(s) compilation warning */ |
| 816 | } |
816 | UNUSED(hcec); |
| 817 | 817 | UNUSED(RxFrameSize); |
|
| 818 | /** |
818 | /* NOTE : This function should not be modified, when the callback is needed, |
| 819 | * @brief CEC error callbacks |
819 | the HAL_CEC_RxCpltCallback can be implemented in the user file |
| 820 | * @param hcec: CEC handle |
820 | */ |
| 821 | * @retval None |
821 | } |
| 822 | */ |
822 | |
| 823 | __weak void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec) |
823 | /** |
| 824 | { |
824 | * @brief CEC error callbacks |
| 825 | /* Prevent unused argument(s) compilation warning */ |
825 | * @param hcec CEC handle |
| 826 | UNUSED(hcec); |
826 | * @retval None |
| 827 | /* NOTE : This function should not be modified, when the callback is needed, |
827 | */ |
| 828 | the HAL_CEC_ErrorCallback can be implemented in the user file |
828 | __weak void HAL_CEC_ErrorCallback(CEC_HandleTypeDef *hcec) |
| 829 | */ |
829 | { |
| 830 | } |
830 | /* Prevent unused argument(s) compilation warning */ |
| 831 | /** |
831 | UNUSED(hcec); |
| 832 | * @} |
832 | /* NOTE : This function should not be modified, when the callback is needed, |
| 833 | */ |
833 | the HAL_CEC_ErrorCallback can be implemented in the user file |
| 834 | 834 | */ |
|
| 835 | /** @defgroup CEC_Exported_Functions_Group3 Peripheral Control functions |
835 | } |
| 836 | * @brief CEC control functions |
836 | /** |
| 837 | * |
837 | * @} |
| 838 | @verbatim |
838 | */ |
| 839 | =============================================================================== |
839 | |
| 840 | ##### Peripheral Control function ##### |
840 | /** @defgroup CEC_Exported_Functions_Group3 Peripheral Control functions |
| 841 | =============================================================================== |
841 | * @brief CEC control functions |
| 842 | [..] |
842 | * |
| 843 | This subsection provides a set of functions allowing to control the CEC. |
843 | @verbatim |
| 844 | (+) HAL_CEC_GetState() API can be helpful to check in run-time the state of the CEC peripheral. |
844 | =============================================================================== |
| 845 | (+) HAL_CEC_GetError() API can be helpful to check in run-time the error of the CEC peripheral. |
845 | ##### Peripheral Control function ##### |
| 846 | @endverbatim |
846 | =============================================================================== |
| 847 | * @{ |
847 | [..] |
| 848 | */ |
848 | This subsection provides a set of functions allowing to control the CEC. |
| 849 | /** |
849 | (+) HAL_CEC_GetState() API can be helpful to check in run-time the state of the CEC peripheral. |
| 850 | * @brief return the CEC state |
850 | (+) HAL_CEC_GetError() API can be helpful to check in run-time the error of the CEC peripheral. |
| 851 | * @param hcec: pointer to a CEC_HandleTypeDef structure that contains |
851 | @endverbatim |
| 852 | * the configuration information for the specified CEC module. |
852 | * @{ |
| 853 | * @retval HAL state |
853 | */ |
| 854 | */ |
854 | /** |
| 855 | HAL_CEC_StateTypeDef HAL_CEC_GetState(CEC_HandleTypeDef *hcec) |
855 | * @brief return the CEC state |
| 856 | { |
856 | * @param hcec pointer to a CEC_HandleTypeDef structure that contains |
| 857 | uint32_t temp1= 0x00U, temp2 = 0x00U; |
857 | * the configuration information for the specified CEC module. |
| 858 | temp1 = hcec->gState; |
858 | * @retval HAL state |
| 859 | temp2 = hcec->RxState; |
859 | */ |
| 860 | 860 | HAL_CEC_StateTypeDef HAL_CEC_GetState(const CEC_HandleTypeDef *hcec) |
|
| 861 | return (HAL_CEC_StateTypeDef)(temp1 | temp2); |
861 | { |
| 862 | } |
862 | uint32_t temp1; |
| 863 | 863 | uint32_t temp2; |
|
| 864 | /** |
864 | temp1 = hcec->gState; |
| 865 | * @brief Return the CEC error code |
865 | temp2 = hcec->RxState; |
| 866 | * @param hcec : pointer to a CEC_HandleTypeDef structure that contains |
866 | |
| 867 | * the configuration information for the specified CEC. |
867 | return (HAL_CEC_StateTypeDef)(temp1 | temp2); |
| 868 | * @retval CEC Error Code |
868 | } |
| 869 | */ |
869 | |
| 870 | uint32_t HAL_CEC_GetError(CEC_HandleTypeDef *hcec) |
870 | /** |
| 871 | { |
871 | * @brief Return the CEC error code |
| 872 | return hcec->ErrorCode; |
872 | * @param hcec pointer to a CEC_HandleTypeDef structure that contains |
| 873 | } |
873 | * the configuration information for the specified CEC. |
| 874 | 874 | * @retval CEC Error Code |
|
| 875 | /** |
875 | */ |
| 876 | * @} |
876 | uint32_t HAL_CEC_GetError(const CEC_HandleTypeDef *hcec) |
| 877 | */ |
877 | { |
| 878 | 878 | return hcec->ErrorCode; |
|
| 879 | /** |
879 | } |
| 880 | * @} |
880 | |
| 881 | */ |
881 | /** |
| 882 | 882 | * @} |
|
| 883 | /** @addtogroup CEC_Private_Functions |
883 | */ |
| 884 | * @{ |
884 | |
| 885 | */ |
885 | /** |
| 886 | 886 | * @} |
|
| 887 | /** |
887 | */ |
| 888 | * @brief Send data in interrupt mode |
888 | |
| 889 | * @param hcec: CEC handle. |
889 | /** @addtogroup CEC_Private_Functions |
| 890 | * Function called under interruption only, once |
890 | * @{ |
| 891 | * interruptions have been enabled by HAL_CEC_Transmit_IT() |
891 | */ |
| 892 | * @retval HAL status |
892 | |
| 893 | */ |
893 | /** |
| 894 | static HAL_StatusTypeDef CEC_Transmit_IT(CEC_HandleTypeDef *hcec) |
894 | * @brief Send data in interrupt mode |
| 895 | { |
895 | * @param hcec CEC handle. |
| 896 | /* if the IP is already busy or if there is a previous transmission |
896 | * Function called under interruption only, once |
| 897 | already pending due to arbitration loss */ |
897 | * interruptions have been enabled by HAL_CEC_Transmit_IT() |
| 898 | if((hcec->gState == HAL_CEC_STATE_BUSY_TX) || (__HAL_CEC_GET_TRANSMISSION_START_FLAG(hcec) != RESET)) |
898 | * @retval HAL status |
| 899 | { |
899 | */ |
| 900 | /* if all data have been sent */ |
900 | static HAL_StatusTypeDef CEC_Transmit_IT(CEC_HandleTypeDef *hcec) |
| 901 | if(hcec->TxXferCount == 0U) |
901 | { |
| 902 | { |
902 | /* if the peripheral is already busy or if there is a previous transmission |
| 903 | /* Acknowledge successful completion by writing 0x00 */ |
903 | already pending due to arbitration loss */ |
| 904 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, 0x00U); |
904 | if ((hcec->gState == HAL_CEC_STATE_BUSY_TX) || (__HAL_CEC_GET_TRANSMISSION_START_FLAG(hcec) != RESET)) |
| 905 | 905 | { |
|
| 906 | hcec->gState = HAL_CEC_STATE_READY; |
906 | /* if all data have been sent */ |
| 907 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
907 | if (hcec->TxXferCount == 0U) |
| 908 | hcec->TxCpltCallback(hcec); |
908 | { |
| 909 | #else |
909 | /* Acknowledge successful completion by writing 0x00 */ |
| 910 | HAL_CEC_TxCpltCallback(hcec); |
910 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, 0x00U); |
| 911 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
911 | |
| 912 | 912 | hcec->gState = HAL_CEC_STATE_READY; |
|
| 913 | return HAL_OK; |
913 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
| 914 | } |
914 | hcec->TxCpltCallback(hcec); |
| 915 | else |
915 | #else |
| 916 | { |
916 | HAL_CEC_TxCpltCallback(hcec); |
| 917 | /* Reduce the number of bytes to transfer by one */ |
917 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
| 918 | hcec->TxXferCount--; |
918 | |
| 919 | 919 | return HAL_OK; |
|
| 920 | /* Write data to TX buffer*/ |
920 | } |
| 921 | hcec->Instance->TXD = *hcec->pTxBuffPtr++; |
921 | else |
| 922 | 922 | { |
|
| 923 | /* If this is the last byte of the ongoing transmission */ |
923 | /* Reduce the number of bytes to transfer by one */ |
| 924 | if(hcec->TxXferCount == 0U) |
924 | hcec->TxXferCount--; |
| 925 | { |
925 | |
| 926 | /* Acknowledge byte request and signal end of message */ |
926 | /* Write data to TX buffer*/ |
| 927 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TEOM); |
927 | hcec->Instance->TXD = (uint8_t)*hcec->pTxBuffPtr++; |
| 928 | } |
928 | |
| 929 | else |
929 | /* If this is the last byte of the ongoing transmission */ |
| 930 | { |
930 | if (hcec->TxXferCount == 0U) |
| 931 | /* Acknowledge byte request by writing 0x00 */ |
931 | { |
| 932 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, 0x00U); |
932 | /* Acknowledge byte request and signal end of message */ |
| 933 | } |
933 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, CEC_FLAG_TEOM); |
| 934 | 934 | } |
|
| 935 | return HAL_OK; |
935 | else |
| 936 | } |
936 | { |
| 937 | } |
937 | /* Acknowledge byte request by writing 0x00 */ |
| 938 | else |
938 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_TRANSMIT_MASK, 0x00U); |
| 939 | { |
939 | } |
| 940 | return HAL_BUSY; |
940 | |
| 941 | } |
941 | return HAL_OK; |
| 942 | } |
942 | } |
| 943 | 943 | } |
|
| 944 | /** |
944 | else |
| 945 | * @brief Receive data in interrupt mode. |
945 | { |
| 946 | * @param hcec: CEC handle. |
946 | return HAL_BUSY; |
| 947 | * Function called under interruption only, once |
947 | } |
| 948 | * interruptions have been enabled by HAL_CEC_Receive_IT() |
948 | } |
| 949 | * @retval HAL status |
949 | |
| 950 | */ |
950 | /** |
| 951 | static HAL_StatusTypeDef CEC_Receive_IT(CEC_HandleTypeDef *hcec) |
951 | * @brief Receive data in interrupt mode. |
| 952 | { |
952 | * @param hcec CEC handle. |
| 953 | static uint32_t temp; |
953 | * Function called under interruption only, once |
| 954 | 954 | * interruptions have been enabled by HAL_CEC_Receive_IT() |
|
| 955 | if(hcec->RxState == HAL_CEC_STATE_BUSY_RX) |
955 | * @retval HAL status |
| 956 | { |
956 | */ |
| 957 | temp = hcec->Instance->CSR; |
957 | static HAL_StatusTypeDef CEC_Receive_IT(CEC_HandleTypeDef *hcec) |
| 958 | 958 | { |
|
| 959 | /* Store received data */ |
959 | static uint32_t temp; |
| 960 | hcec->RxXferSize++; |
960 | |
| 961 | *hcec->Init.RxBuffer++ = hcec->Instance->RXD; |
961 | if (hcec->RxState == HAL_CEC_STATE_BUSY_RX) |
| 962 | 962 | { |
|
| 963 | /* Acknowledge received byte by writing 0x00 */ |
963 | temp = hcec->Instance->CSR; |
| 964 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_RECEIVE_MASK, 0x00U); |
964 | |
| 965 | 965 | /* Store received data */ |
|
| 966 | /* If the End Of Message is reached */ |
966 | hcec->RxXferSize++; |
| 967 | if(HAL_IS_BIT_SET(temp, CEC_FLAG_REOM)) |
967 | *hcec->Init.RxBuffer++ = hcec->Instance->RXD; |
| 968 | { |
968 | |
| 969 | /* Interrupts are not disabled due to transmission still ongoing */ |
969 | /* Acknowledge received byte by writing 0x00 */ |
| 970 | hcec->RxState = HAL_CEC_STATE_READY; |
970 | MODIFY_REG(hcec->Instance->CSR, CEC_FLAG_RECEIVE_MASK, 0x00U); |
| 971 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
971 | |
| 972 | hcec->RxCpltCallback(hcec, hcec->RxXferSize); |
972 | /* If the End Of Message is reached */ |
| 973 | #else |
973 | if (HAL_IS_BIT_SET(temp, CEC_FLAG_REOM)) |
| 974 | HAL_CEC_RxCpltCallback(hcec, hcec->RxXferSize); |
974 | { |
| 975 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
975 | /* Interrupts are not disabled due to transmission still ongoing */ |
| 976 | 976 | hcec->RxState = HAL_CEC_STATE_READY; |
|
| 977 | return HAL_OK; |
977 | #if (USE_HAL_CEC_REGISTER_CALLBACKS == 1) |
| 978 | } |
978 | hcec->RxCpltCallback(hcec, hcec->RxXferSize); |
| 979 | else |
979 | #else |
| 980 | { |
980 | HAL_CEC_RxCpltCallback(hcec, hcec->RxXferSize); |
| 981 | return HAL_BUSY; |
981 | #endif /* USE_HAL_CEC_REGISTER_CALLBACKS */ |
| 982 | } |
982 | |
| 983 | } |
983 | return HAL_OK; |
| 984 | else |
984 | } |
| 985 | { |
985 | else |
| 986 | return HAL_BUSY; |
986 | { |
| 987 | } |
987 | return HAL_BUSY; |
| 988 | } |
988 | } |
| 989 | 989 | } |
|
| 990 | /** |
990 | else |
| 991 | * @} |
991 | { |
| 992 | */ |
992 | return HAL_BUSY; |
| 993 | 993 | } |
|
| 994 | /** |
994 | } |
| 995 | * @} |
995 | |
| 996 | */ |
996 | /** |
| 997 | 997 | * @} |
|
| 998 | #endif /* CEC */ |
998 | */ |
| 999 | 999 | ||
| 1000 | #endif /* HAL_CEC_MODULE_ENABLED */ |
1000 | /** |
| 1001 | /** |
1001 | * @} |
| 1002 | * @} |
1002 | */ |
| 1003 | */ |
1003 | |
| 1004 | 1004 | #endif /* CEC */ |
|
| 1005 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
1005 | |
| - | 1006 | #endif /* HAL_CEC_MODULE_ENABLED */ |
|
| - | 1007 | /** |
|
| - | 1008 | * @} |
|
| - | 1009 | */ |
|