Create release.yml
[betaflight.git] / lib / main / STM32F1 / Drivers / STM32F10x_StdPeriph_Driver / src / stm32f10x_cec.c
blob4dc615f032f6d1b70eebd313b55fca1294b77d9e
1 /**
2 ******************************************************************************
3 * @file stm32f10x_cec.c
4 * @author MCD Application Team
5 * @version V3.5.0
6 * @date 11-March-2011
7 * @brief This file provides all the CEC firmware functions.
8 ******************************************************************************
9 * @attention
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x_cec.h"
24 #include "stm32f10x_rcc.h"
26 /** @addtogroup STM32F10x_StdPeriph_Driver
27 * @{
30 /** @defgroup CEC
31 * @brief CEC driver modules
32 * @{
35 /** @defgroup CEC_Private_TypesDefinitions
36 * @{
39 /**
40 * @}
44 /** @defgroup CEC_Private_Defines
45 * @{
46 */
48 /* ------------ CEC registers bit address in the alias region ----------- */
49 #define CEC_OFFSET (CEC_BASE - PERIPH_BASE)
51 /* --- CFGR Register ---*/
53 /* Alias word address of PE bit */
54 #define CFGR_OFFSET (CEC_OFFSET + 0x00)
55 #define PE_BitNumber 0x00
56 #define CFGR_PE_BB (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (PE_BitNumber * 4))
58 /* Alias word address of IE bit */
59 #define IE_BitNumber 0x01
60 #define CFGR_IE_BB (PERIPH_BB_BASE + (CFGR_OFFSET * 32) + (IE_BitNumber * 4))
62 /* --- CSR Register ---*/
64 /* Alias word address of TSOM bit */
65 #define CSR_OFFSET (CEC_OFFSET + 0x10)
66 #define TSOM_BitNumber 0x00
67 #define CSR_TSOM_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TSOM_BitNumber * 4))
69 /* Alias word address of TEOM bit */
70 #define TEOM_BitNumber 0x01
71 #define CSR_TEOM_BB (PERIPH_BB_BASE + (CSR_OFFSET * 32) + (TEOM_BitNumber * 4))
73 #define CFGR_CLEAR_Mask (uint8_t)(0xF3) /* CFGR register Mask */
74 #define FLAG_Mask ((uint32_t)0x00FFFFFF) /* CEC FLAG mask */
76 /**
77 * @}
78 */
81 /** @defgroup CEC_Private_Macros
82 * @{
83 */
85 /**
86 * @}
87 */
90 /** @defgroup CEC_Private_Variables
91 * @{
92 */
94 /**
95 * @}
96 */
99 /** @defgroup CEC_Private_FunctionPrototypes
100 * @{
104 * @}
108 /** @defgroup CEC_Private_Functions
109 * @{
113 * @brief Deinitializes the CEC peripheral registers to their default reset
114 * values.
115 * @param None
116 * @retval None
118 void CEC_DeInit(void)
120 /* Enable CEC reset state */
121 RCC_APB1PeriphResetCmd(RCC_APB1Periph_CEC, ENABLE);
122 /* Release CEC from reset state */
123 RCC_APB1PeriphResetCmd(RCC_APB1Periph_CEC, DISABLE);
128 * @brief Initializes the CEC peripheral according to the specified
129 * parameters in the CEC_InitStruct.
130 * @param CEC_InitStruct: pointer to an CEC_InitTypeDef structure that
131 * contains the configuration information for the specified
132 * CEC peripheral.
133 * @retval None
135 void CEC_Init(CEC_InitTypeDef* CEC_InitStruct)
137 uint16_t tmpreg = 0;
139 /* Check the parameters */
140 assert_param(IS_CEC_BIT_TIMING_ERROR_MODE(CEC_InitStruct->CEC_BitTimingMode));
141 assert_param(IS_CEC_BIT_PERIOD_ERROR_MODE(CEC_InitStruct->CEC_BitPeriodMode));
143 /*---------------------------- CEC CFGR Configuration -----------------*/
144 /* Get the CEC CFGR value */
145 tmpreg = CEC->CFGR;
147 /* Clear BTEM and BPEM bits */
148 tmpreg &= CFGR_CLEAR_Mask;
150 /* Configure CEC: Bit Timing Error and Bit Period Error */
151 tmpreg |= (uint16_t)(CEC_InitStruct->CEC_BitTimingMode | CEC_InitStruct->CEC_BitPeriodMode);
153 /* Write to CEC CFGR register*/
154 CEC->CFGR = tmpreg;
159 * @brief Enables or disables the specified CEC peripheral.
160 * @param NewState: new state of the CEC peripheral.
161 * This parameter can be: ENABLE or DISABLE.
162 * @retval None
164 void CEC_Cmd(FunctionalState NewState)
166 /* Check the parameters */
167 assert_param(IS_FUNCTIONAL_STATE(NewState));
169 *(__IO uint32_t *) CFGR_PE_BB = (uint32_t)NewState;
171 if(NewState == DISABLE)
173 /* Wait until the PE bit is cleared by hardware (Idle Line detected) */
174 while((CEC->CFGR & CEC_CFGR_PE) != (uint32_t)RESET)
181 * @brief Enables or disables the CEC interrupt.
182 * @param NewState: new state of the CEC interrupt.
183 * This parameter can be: ENABLE or DISABLE.
184 * @retval None
186 void CEC_ITConfig(FunctionalState NewState)
188 /* Check the parameters */
189 assert_param(IS_FUNCTIONAL_STATE(NewState));
191 *(__IO uint32_t *) CFGR_IE_BB = (uint32_t)NewState;
195 * @brief Defines the Own Address of the CEC device.
196 * @param CEC_OwnAddress: The CEC own address
197 * @retval None
199 void CEC_OwnAddressConfig(uint8_t CEC_OwnAddress)
201 /* Check the parameters */
202 assert_param(IS_CEC_ADDRESS(CEC_OwnAddress));
204 /* Set the CEC own address */
205 CEC->OAR = CEC_OwnAddress;
209 * @brief Sets the CEC prescaler value.
210 * @param CEC_Prescaler: CEC prescaler new value
211 * @retval None
213 void CEC_SetPrescaler(uint16_t CEC_Prescaler)
215 /* Check the parameters */
216 assert_param(IS_CEC_PRESCALER(CEC_Prescaler));
218 /* Set the Prescaler value*/
219 CEC->PRES = CEC_Prescaler;
223 * @brief Transmits single data through the CEC peripheral.
224 * @param Data: the data to transmit.
225 * @retval None
227 void CEC_SendDataByte(uint8_t Data)
229 /* Transmit Data */
230 CEC->TXD = Data ;
235 * @brief Returns the most recent received data by the CEC peripheral.
236 * @param None
237 * @retval The received data.
239 uint8_t CEC_ReceiveDataByte(void)
241 /* Receive Data */
242 return (uint8_t)(CEC->RXD);
246 * @brief Starts a new message.
247 * @param None
248 * @retval None
250 void CEC_StartOfMessage(void)
252 /* Starts of new message */
253 *(__IO uint32_t *) CSR_TSOM_BB = (uint32_t)0x1;
257 * @brief Transmits message with or without an EOM bit.
258 * @param NewState: new state of the CEC Tx End Of Message.
259 * This parameter can be: ENABLE or DISABLE.
260 * @retval None
262 void CEC_EndOfMessageCmd(FunctionalState NewState)
264 /* Check the parameters */
265 assert_param(IS_FUNCTIONAL_STATE(NewState));
267 /* The data byte will be transmitted with or without an EOM bit*/
268 *(__IO uint32_t *) CSR_TEOM_BB = (uint32_t)NewState;
272 * @brief Gets the CEC flag status
273 * @param CEC_FLAG: specifies the CEC flag to check.
274 * This parameter can be one of the following values:
275 * @arg CEC_FLAG_BTE: Bit Timing Error
276 * @arg CEC_FLAG_BPE: Bit Period Error
277 * @arg CEC_FLAG_RBTFE: Rx Block Transfer Finished Error
278 * @arg CEC_FLAG_SBE: Start Bit Error
279 * @arg CEC_FLAG_ACKE: Block Acknowledge Error
280 * @arg CEC_FLAG_LINE: Line Error
281 * @arg CEC_FLAG_TBTFE: Tx Block Transfer Finished Error
282 * @arg CEC_FLAG_TEOM: Tx End Of Message
283 * @arg CEC_FLAG_TERR: Tx Error
284 * @arg CEC_FLAG_TBTRF: Tx Byte Transfer Request or Block Transfer Finished
285 * @arg CEC_FLAG_RSOM: Rx Start Of Message
286 * @arg CEC_FLAG_REOM: Rx End Of Message
287 * @arg CEC_FLAG_RERR: Rx Error
288 * @arg CEC_FLAG_RBTF: Rx Byte/Block Transfer Finished
289 * @retval The new state of CEC_FLAG (SET or RESET)
291 FlagStatus CEC_GetFlagStatus(uint32_t CEC_FLAG)
293 FlagStatus bitstatus = RESET;
294 uint32_t cecreg = 0, cecbase = 0;
296 /* Check the parameters */
297 assert_param(IS_CEC_GET_FLAG(CEC_FLAG));
299 /* Get the CEC peripheral base address */
300 cecbase = (uint32_t)(CEC_BASE);
302 /* Read flag register index */
303 cecreg = CEC_FLAG >> 28;
305 /* Get bit[23:0] of the flag */
306 CEC_FLAG &= FLAG_Mask;
308 if(cecreg != 0)
310 /* Flag in CEC ESR Register */
311 CEC_FLAG = (uint32_t)(CEC_FLAG >> 16);
313 /* Get the CEC ESR register address */
314 cecbase += 0xC;
316 else
318 /* Get the CEC CSR register address */
319 cecbase += 0x10;
322 if(((*(__IO uint32_t *)cecbase) & CEC_FLAG) != (uint32_t)RESET)
324 /* CEC_FLAG is set */
325 bitstatus = SET;
327 else
329 /* CEC_FLAG is reset */
330 bitstatus = RESET;
333 /* Return the CEC_FLAG status */
334 return bitstatus;
338 * @brief Clears the CEC's pending flags.
339 * @param CEC_FLAG: specifies the flag to clear.
340 * This parameter can be any combination of the following values:
341 * @arg CEC_FLAG_TERR: Tx Error
342 * @arg CEC_FLAG_TBTRF: Tx Byte Transfer Request or Block Transfer Finished
343 * @arg CEC_FLAG_RSOM: Rx Start Of Message
344 * @arg CEC_FLAG_REOM: Rx End Of Message
345 * @arg CEC_FLAG_RERR: Rx Error
346 * @arg CEC_FLAG_RBTF: Rx Byte/Block Transfer Finished
347 * @retval None
349 void CEC_ClearFlag(uint32_t CEC_FLAG)
351 uint32_t tmp = 0x0;
353 /* Check the parameters */
354 assert_param(IS_CEC_CLEAR_FLAG(CEC_FLAG));
356 tmp = CEC->CSR & 0x2;
358 /* Clear the selected CEC flags */
359 CEC->CSR &= (uint32_t)(((~(uint32_t)CEC_FLAG) & 0xFFFFFFFC) | tmp);
363 * @brief Checks whether the specified CEC interrupt has occurred or not.
364 * @param CEC_IT: specifies the CEC interrupt source to check.
365 * This parameter can be one of the following values:
366 * @arg CEC_IT_TERR: Tx Error
367 * @arg CEC_IT_TBTF: Tx Block Transfer Finished
368 * @arg CEC_IT_RERR: Rx Error
369 * @arg CEC_IT_RBTF: Rx Block Transfer Finished
370 * @retval The new state of CEC_IT (SET or RESET).
372 ITStatus CEC_GetITStatus(uint8_t CEC_IT)
374 ITStatus bitstatus = RESET;
375 uint32_t enablestatus = 0;
377 /* Check the parameters */
378 assert_param(IS_CEC_GET_IT(CEC_IT));
380 /* Get the CEC IT enable bit status */
381 enablestatus = (CEC->CFGR & (uint8_t)CEC_CFGR_IE) ;
383 /* Check the status of the specified CEC interrupt */
384 if (((CEC->CSR & CEC_IT) != (uint32_t)RESET) && enablestatus)
386 /* CEC_IT is set */
387 bitstatus = SET;
389 else
391 /* CEC_IT is reset */
392 bitstatus = RESET;
394 /* Return the CEC_IT status */
395 return bitstatus;
399 * @brief Clears the CEC's interrupt pending bits.
400 * @param CEC_IT: specifies the CEC interrupt pending bit to clear.
401 * This parameter can be any combination of the following values:
402 * @arg CEC_IT_TERR: Tx Error
403 * @arg CEC_IT_TBTF: Tx Block Transfer Finished
404 * @arg CEC_IT_RERR: Rx Error
405 * @arg CEC_IT_RBTF: Rx Block Transfer Finished
406 * @retval None
408 void CEC_ClearITPendingBit(uint16_t CEC_IT)
410 uint32_t tmp = 0x0;
412 /* Check the parameters */
413 assert_param(IS_CEC_GET_IT(CEC_IT));
415 tmp = CEC->CSR & 0x2;
417 /* Clear the selected CEC interrupt pending bits */
418 CEC->CSR &= (uint32_t)(((~(uint32_t)CEC_IT) & 0xFFFFFFFC) | tmp);
422 * @}
426 * @}
430 * @}
433 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/