1 /*!
2  * @file        apm32f0xx_cec.h
3  *
4  * @brief       This file contains all the functions prototypes for the CEC firmware library
5  *
6  * @version     V1.0.3
7  *
8  * @date        2022-09-20
9  *
10  * @attention
11  *
12  *  Copyright (C) 2020-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be useful and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 /* Define to prevent recursive inclusion */
27 #ifndef __APM32F0XX_CEC_H
28 #define __APM32F0XX_CEC_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* Includes */
35 #include "apm32f0xx.h"
36 
37 /** @addtogroup APM32F0xx_StdPeriphDriver
38   @{
39 */
40 
41 /** @addtogroup CEC_Driver
42   @{
43 */
44 
45 /** @defgroup CEC_Macros Macros
46   @{
47 */
48 
49 /**@} end of group CEC_Macros */
50 
51 /** @defgroup CEC_Enumerations Enumerations
52   @{
53 */
54 
55 /**
56  * @brief    CEC_Signal_Free_Time
57  */
58 typedef enum
59 {
60     CEC_SINGANL_FREETIME_STANDARD = 0x00, /*!< none nominal data bit periods */
61     CEC_SINGANL_FREETIME_1T       = 0x01, /*!< 0.5 nominal data bit periods */
62     CEC_SINGANL_FREETIME_2T       = 0x02, /*!< 1.5 nominal data bit periods */
63     CEC_SINGANL_FREETIME_3T       = 0x03, /*!< 2.5 nominal data bit periods */
64     CEC_SINGANL_FREETIME_4T       = 0x04, /*!< 3.5 nominal data bit periods */
65     CEC_SINGANL_FREETIME_5T       = 0x05, /*!< 4.5 nominal data bit periods */
66     CEC_SINGANL_FREETIME_6T       = 0x06, /*!< 5.5 nominal data bit periods */
67     CEC_SINGANL_FREETIME_7T       = 0x07, /*!< 6.5 nominal data bit periods */
68 } CEC_SIGNAL_FREETIME_T;
69 
70 /**
71  * @brief    CEC_RxTolerance
72  */
73 typedef enum
74 {
75     CEC_RX_TOLERANCE_STANDARD  =  0x00,   /*!< Standard tolerance margin */
76     CEC_RX_TOLERANCE_EXTENDED  =  0x01    /*!< Extended Tolerance */
77 } CEC_RX_TOLERANCE_T;
78 
79 /**
80  * @brief    CEC_Stop_Reception
81  */
82 typedef enum
83 {
84     CEC_STOP_RECEPTION_OFF,           /*!< CEC Stop Reception Off */
85     CEC_STOP_RECEPTION_ON             /*!< CEC Stop Reception On */
86 } CEC_STOP_RECEPTION_T;
87 
88 /**
89  * @brief     CEC_Bit_Rising_Error_Generation
90  */
91 typedef enum
92 {
93     CEC_BIT_RISING_ERR_OFF,           /*!< BRE detection does not generate an Error-Bit on the CEC line */
94     CEC_BIT_RISING_ERR_ON             /*!< BRE detection generates an Error-Bit on the CEC line (if BRESTP is set) */
95 } CEC_BIT_RISING_ERR_T;
96 
97 /**
98  * @brief     CEC_Long_Bit_Error_Generation
99  */
100 typedef enum
101 {
102     CEC_LONG_PERIOD_ERR_OFF,         /*!< LBPE detection does not generate an Error-Bit on the CEC line */
103     CEC_LONG_PERIOD_ERR_ON           /*!< LBPE detection generates an Error-Bit on the CEC line */
104 } CEC_LONG_PERIOD_ERR_T;
105 
106 /**
107  * @brief     CEC_BDR_No_Gen
108  */
109 typedef enum
110 {
111     CEC_BROADCAST_NO_ERR_OFF,         /*!< Broadcast Bit Rising Error generation turned Off */
112     CEC_BROADCAST_NO_ERR_ON           /*!< Broadcast Bit Rising Error generation turned On */
113 } CEC_BROADCAST_NO_ERR_T;
114 
115 /**
116  * @brief     CEC_SFT_Option
117  */
118 typedef enum
119 {
120     CEC_SIGNAL_FREETIME_OPTION_OFF,   /*!< SFTCFG timer starts when TXSOM is set by software */
121     CEC_SIGNAL_FREETIME_OPTION_ON     /*!< SFTCFG timer starts automatically at the end of message transmission/reception */
122 } CEC_SIGNAL_FREETIME_OPTION_T;
123 
124 /**
125  * @brief    CEC_Interrupt_Configuration_definition
126  */
127 typedef enum
128 {
129     CEC_INT_RXBR   = ((uint32_t)0x00000001), /*!< Rx-Byte Received Interrupt */
130     CEC_INT_RXEND  = ((uint32_t)0x00000002), /*!< End Of Reception Interrupt */
131     CEC_INT_RXOVR  = ((uint32_t)0x00000004), /*!< Rx-Buffer Overrun Interrupt */
132     CEC_INT_BRE    = ((uint32_t)0x00000008), /*!< Bit Rising Error Interrupt */
133     CEC_INT_SBPE   = ((uint32_t)0x00000010), /*!< Short Bit Period Error Interrupt */
134     CEC_INT_LBPE   = ((uint32_t)0x00000020), /*!< Long Bit Period Error Interrupt */
135     CEC_INT_RXACKE = ((uint32_t)0x00000040), /*!< Rx-Missing Acknowledge Error Interrupt */
136     CEC_INT_ARBLST = ((uint32_t)0x00000080), /*!< Arbitration Lost Interrupt */
137     CEC_INT_TXBR   = ((uint32_t)0x00000100), /*!< Tx-Byte Request Interrupt */
138     CEC_INT_TXEND  = ((uint32_t)0x00000200), /*!< Tx-End Of Message Interrupt */
139     CEC_INT_TXUDR  = ((uint32_t)0x00000400), /*!< Tx-Underrun Interrupt */
140     CEC_INT_TXERR  = ((uint32_t)0x00000800), /*!< Tx-Error Interrupt */
141     CEC_INT_TXACKE = ((uint32_t)0x00001000), /*!< Tx-Missing Acknowledge Error Interrupt */
142 } CEC_INT_T;
143 
144 /**
145  * @brief   CEC_STS_register_flags_definition
146  */
147 typedef enum
148 {
149     CEC_FLAG_RXBR   = ((uint32_t)0x00000001),  /*!< Rx-Byte Received Flag */
150     CEC_FLAG_RXEND  = ((uint32_t)0x00000002),  /*!< End Of Reception Flag */
151     CEC_FLAG_RXOVR  = ((uint32_t)0x00000004),  /*!< Rx-Buffer Overrun Flag */
152     CEC_FLAG_BRE    = ((uint32_t)0x00000008),  /*!< Bit Rising Error Flag */
153     CEC_FLAG_SBPE   = ((uint32_t)0x00000010),  /*!< Short Bit Period Error Flag */
154     CEC_FLAG_LBPE   = ((uint32_t)0x00000020),  /*!< Long Bit Period Error Flag */
155     CEC_FLAG_RXACKE = ((uint32_t)0x00000040),  /*!< Rx-Missing Acknowledge Error Flag */
156     CEC_FLAG_ARBLST = ((uint32_t)0x00000080),  /*!< Arbitration Lost Flag */
157     CEC_FLAG_TXBR   = ((uint32_t)0x00000100),  /*!< Tx-Byte Request Flag */
158     CEC_FLAG_TXEND  = ((uint32_t)0x00000200),  /*!< Tx-End Of Message Flag */
159     CEC_FLAG_TXUDR  = ((uint32_t)0x00000400),  /*!< Tx-Underrun Flag */
160     CEC_FLAG_TXERR  = ((uint32_t)0x00000800),  /*!< Tx-Error Flag */
161     CEC_FLAG_TXACKE = ((uint32_t)0x00001000),  /*!< Tx-Missing Acknowledge Error Flag */
162 } CEC_FLAG_T;
163 
164 /**@} end of group CEC_Enumerations */
165 
166 /** @defgroup CEC_Structures Structures
167   @{
168 */
169 
170 /**
171   * @brief CEC Init structure definition
172   */
173 typedef struct
174 {
175     CEC_SIGNAL_FREETIME_T  signalFreeTime;     /*!< Signal Free Time */
176     CEC_RX_TOLERANCE_T     RxTolerance;        /*!< Rx-Tolerance */
177     CEC_STOP_RECEPTION_T   stopReception;      /*!< Rx-Stop on Bit Rising Error */
178     CEC_BIT_RISING_ERR_T   bitRisingError;     /*!< Generate Error-Bit on Bit Rising Error */
179     CEC_LONG_PERIOD_ERR_T  longPeriodError;    /*!< Generate Error-Bit on Long Bit Period Error */
180     CEC_BROADCAST_NO_ERR_T broadcastrNoGen;    /*!< Avoid Error-Bit Generation in Broadcast */
181     CEC_SIGNAL_FREETIME_OPTION_T signalFreeTimeOption;/*!< Signal Free Time optional */
182 } CEC_Config_T;
183 
184 /**@} end of group CEC_Structures */
185 
186 /** @defgroup CEC_Variables Variables
187   @{
188 */
189 
190 /**@} end of group CEC_Variables */
191 
192 /** @defgroup CEC_Functions Functions
193   @{
194 */
195 
196 /* CEC reset and configuration */
197 void CEC_Reset(void);
198 void CEC_Config(CEC_Config_T* cecConfig);
199 void CEC_ConfigStructInit(CEC_Config_T* cecConfig);
200 void CEC_Enable(void);
201 void CEC_Disable(void);
202 void CEC_EnableListenMode(void);
203 void CEC_DisableListenMode(void);
204 void CEC_ConfigOwnAddress(uint8_t ownAddress);
205 void CEC_ClearQwnAddress(void);
206 
207 /* Transmit and receive */
208 void CEC_TxData(uint8_t Data);
209 uint8_t CEC_RxData(void);
210 
211 /* Config Message */
212 void CEC_StartNewMessage(void);
213 void CEC_CompleteMessage(void);
214 
215 /* Interrupt and Flag*/
216 void CEC_EnableInterrupt(uint32_t interrupt);
217 void CEC_DisableInterrupt(uint32_t interrupt);
218 uint8_t CEC_ReadStatusFlag(uint32_t flag);
219 void CEC_ClearStatusFlag(uint32_t flag);
220 uint8_t CEC_ReadIntFlag(uint16_t flag);
221 void CEC_ClearIntFlag(uint16_t flag);
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #endif /* __APM32F0XX_CEC_H */
228 
229 /**@} end of group CEC_Functions */
230 /**@} end of group CEC_Driver */
231 /**@} end of group APM32F0xx_StdPeriphDriver */
232