1 /*!
2  * @file        apm32f4xx_dci.h
3  *
4  * @brief       This file contains all the functions prototypes for the DCI firmware library
5  *
6  * @version     V1.0.2
7  *
8  * @date        2022-06-23
9  *
10  * @attention
11  *
12  *  Copyright (C) 2021-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 usefull 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 __APM32F4XX_DCI_H
28 #define __APM32F4XX_DCI_H
29 
30 #ifdef __cplusplus
31   extern "C" {
32 #endif
33 
34 /* Includes */
35 #include "apm32f4xx.h"
36 
37 /** @addtogroup APM32F4xx_StdPeriphDriver
38   @{
39 */
40 
41 /** @addtogroup DCI_Driver
42   @{
43 */
44 
45 /** @defgroup DCI_Enumerations
46   @{
47 */
48 
49 /**
50  * @brief DCI Capture Mode
51  */
52 typedef enum
53 {
54     DCI_CAPTURE_MODE_CONTINUOUS,    /*!< Continuous capture mode    */
55     DCI_CAPTURE_MODE_SNAPSHOT       /*!< Snapshot mode */
56 } DCI_CAPTURE_MODE_T;
57 
58 /**
59  * @brief DCI Synchronization Mode
60  */
61 typedef enum
62 {
63     DCI_SYNCHRO_MODE_HARDWARE,  /*!< Hardware synchronization */
64     DCI_SYNCHRO_MODE_EMBEDDED   /*!< Embedded code synchronization */
65 } DCI_SYNCHRO_MODEVAL_T;
66 
67 /**
68  * @brief DCI Pixel Clock Polarity
69  */
70 typedef enum
71 {
72     DCI_PCK_POL_FALLING,        /*!< Falling edge capture */
73     DCI_PCK_POL_RISING          /*!< Rising edge capture */
74 } DCI_PCK_POL_T;
75 
76 /**
77  * @brief DCI VSYNC Polarity
78  */
79 typedef enum
80 {
81     DCI_VSYNC_POL_LOW,  /*!< VSYNC low-level valid */
82     DCI_VSYNC_POL_HIGH  /*!< VSYNC high-level valid */
83 } DCI_VSYNC_POL_T;
84 
85 /**
86  * @brief DCI HSYNC Polarity
87  */
88 typedef enum
89 {
90     DCI_HSYNC_POL_LOW,  /*!< HSYNC low-level valid */
91     DCI_HSYNC_POL_HIGH  /*!< HSYNC high-level valid */
92 } DCI_HSYNC_POL_T;
93 
94 /**
95  * @brief DCI Capture Rate
96  */
97 typedef enum
98 {
99     DCI_CAPTURE_RATE_ALL_FRAME,     /*!< Capture all frame */
100     DCI_CAPTURE_RATE_1OF2_FRAME,    /*!< Capture every other frame */
101     DCI_CAPTURE_RATE_1OF4_FRAME     /*!< Capture every three frame */
102 } DCI_CAPTURE_RATE_T;
103 
104 /**
105  * @brief DCI Extended Data Mode
106  */
107 typedef enum
108 {
109     DCI_EXTENDED_DATA_MODE_8B,      /*!< Extended 8-bit data mode */
110     DCI_EXTENDED_DATA_MODE_10B,     /*!< Extended 10-bit data mode */
111     DCI_EXTENDED_DATA_MODE_12B,     /*!< Extended 12-bit data mode */
112     DCI_EXTENDED_DATA_MODE_14B      /*!< Extended 14-bit data mode */
113 } DCI_EXTENDED_DATA_MODE_T;
114 
115 /**
116  * @brief DCI interrupt sources
117  */
118 typedef enum
119 {
120     DCI_INT_CC    =((uint16_t)0x0001),  /*!< Frame capture complete interrupt mask */
121     DCI_INT_OVR   =((uint16_t)0x0002),  /*!< Overflow interrupt mask */
122     DCI_INT_ERR   =((uint16_t)0x0004),  /*!< Synchronization error interrupt mask */
123     DCI_INT_VSYNC =((uint16_t)0x0008),  /*!< VSYNC interrupt mask */
124     DCI_INT_LINE  =((uint16_t)0x0010),  /*!< Line interrupt mask */
125 } DCI_INT_T;
126 
127 /**
128  * @brief DCI flags
129  */
130 typedef enum
131 {
132     /* DCI RINTSTS register */
133     DCI_FLAG_CCI        =((uint16_t)0x0001),    /*!< Frame capture complete Raw flag mask */
134     DCI_FLAG_OVRI       =((uint16_t)0x0002),    /*!< Overflow Raw flag mask */
135     DCI_FLAG_ERRI       =((uint16_t)0x0004),    /*!< Synchronization error Raw flag mask */
136     DCI_FLAG_VSYNCI     =((uint16_t)0x0008),    /*!< VSYNC Raw flag mask */
137     DCI_FLAG_LINEI      =((uint16_t)0x0010),    /*!< Line Raw flag mask */
138     /* DCI MINTSTS register */
139     DCI_FLAG_CCMI       =((uint16_t)0x1001),    /*!< Frame capture complete Masked flag mask */
140     DCI_FLAG_OVRMI      =((uint16_t)0x1002),    /*!< Overflow Masked flag mask */
141     DCI_FLAG_ERRMI      =((uint16_t)0x1004),    /*!< Synchronization error Masked flag mask */
142     DCI_FLAG_VSYNCMI    =((uint16_t)0x1008),    /*!< VSYNC Masked flag mask */
143     DCI_FLAG_LINEMI     =((uint16_t)0x1010),    /*!< Line Masked flag mask */
144     /* DCI STS register */
145     DCI_FLAG_HSYNC      =((uint16_t)0x2001),    /*!< HSYNC flag mask */
146     DCI_FLAG_VSYNC      =((uint16_t)0x2002),    /*!< VSYNC flag mask */
147     DCI_FLAG_FNE        =((uint16_t)0x2004),    /*!< Fifo not empty flag mask */
148 } DCI_FLAG_T;
149 
150 /**@} end of group DCI_Enumerations*/
151 
152 /** @addtogroup DCI_Structure Data Structure
153   @{
154 */
155 
156 /**
157  * @brief DCI Config structure definition
158  */
159 typedef struct
160 {
161     DCI_CAPTURE_MODE_T        captureMode;      /*!< Specifies the Capture Mode: Continuous or Snapshot */
162 
163     DCI_SYNCHRO_MODEVAL_T     synchroMode;      /*!< Specifies the Synchronization Mode: Hardware or Embedded */
164 
165     DCI_PCK_POL_T             pckPolarity;      /*!< Specifies the Pixel clock polarity: Falling or Rising */
166 
167     DCI_VSYNC_POL_T           vsyncPolarity;    /*!< Specifies the Vertical synchronization polarity: High or Low */
168 
169     DCI_HSYNC_POL_T           hsyncPolarity;    /*!< Specifies the Horizontal synchronization polarity: High or Low */
170 
171     DCI_CAPTURE_RATE_T        capturerate;      /*!< Specifies the frequency of frame capture: All, 1/2 or 1/4 */
172 
173     DCI_EXTENDED_DATA_MODE_T  extendedDataMode; /*!< Specifies the data width: 8-bit, 10-bit, 12-bit or 14-bit */
174 } DCI_Config_T;
175 
176 /**
177  * @brief DCI CROP Init structure definition
178  */
179 typedef struct
180 {
181     uint16_t    verticalStartLine;      /*!< Vertical start line count from which the image capture(between 0x00 and 0x1FFF) */
182 
183     uint16_t    horizontalOffsetCount;  /*!< number of pixel clocks to count before starting a capture(between 0x00 and 0x3FFF) */
184 
185     uint16_t    verticalLineCount;      /*!< number of lines to be captured from the starting point(between 0x00 and 0x3FFF) */
186 
187     uint16_t    captureCount;           /*!< number of pixel clocks to be captured from the starting(between 0x00 and 0x3FFF) */
188 } DCI_CropConfig_T;
189 
190 /**
191   * @brief   DCI Embedded Synchronisation CODE Init structure definition
192   */
193 typedef struct
194 {
195     uint8_t     frameStartCode;      /*!< Specifies the code of the frame start delimiter */
196     uint8_t     lineStartCode;       /*!< Specifies the code of the line start delimiter */
197     uint8_t     lineEndCode;         /*!< Specifies the code of the line end delimiter */
198     uint8_t     frameEndCode;        /*!< Specifies the code of the frame end delimiter */
199 } DCI_CodeConfig_T;
200 
201 /**@} end of group DCI_Structure*/
202 
203 /** @defgroup DCI_Functions
204   @{
205 */
206 
207 /** DCI Configuration */
208 void DCI_Rest(void);
209 void DCI_Config(DCI_Config_T* dciConfig);
210 void DCI_ConfigStructInit(DCI_Config_T* dciConfig);
211 void DCI_ConfigCROP(DCI_CropConfig_T* cropConfig);
212 void DCI_EnableCROP(void);
213 void DCI_DisableCROP(void);
214 void DCI_ConfigSynchroCode(DCI_CodeConfig_T* codeConfig);
215 void DCI_EnableJPEG(void);
216 void DCI_DisableJPEG(void);
217 
218 /** DCI Image capture */
219 void DCI_Enable(void);
220 void DCI_Disable(void);
221 void DCI_EnableCapture(void);
222 void DCI_DisableCapture(void);
223 uint32_t DCI_ReadData(void);
224 
225 /** Interrupts and flags */
226 void DCI_EnableInterrupt(uint32_t interrupt);
227 void DCI_DisableInterrupt(uint32_t interrupt);
228 uint16_t DCI_ReadStatusFlag(DCI_FLAG_T flag);
229 void DCI_ClearStatusFlag(uint16_t flag);
230 uint16_t DCI_ReadIntFlag(DCI_INT_T flag);
231 void DCI_ClearIntFlag(uint16_t flag);
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 
237 #endif /* __APM32F4XX_DCI_H */
238 
239 /**@} end of group DCI_Enumerations */
240 /**@} end of group DCI_Driver */
241 /**@} end of group APM32F4xx_StdPeriphDriver */
242