summaryrefslogtreecommitdiff
path: root/bsp/apm32/libraries/APM32F4xx_Library/APM32F4xx_StdPeriphDriver/inc/apm32f4xx_dci.h
blob: d6eebb404d2f3b08775112b83a876dc10aa97dd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*!
 * @file        apm32f4xx_dci.h
 *
 * @brief       This file contains all the functions prototypes for the DCI firmware library
 *
 * @version     V1.0.2
 *
 * @date        2022-06-23
 *
 * @attention
 *
 *  Copyright (C) 2021-2022 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be usefull and instructional for customers to develop
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
 */

/* Define to prevent recursive inclusion */
#ifndef __APM32F4XX_DCI_H
#define __APM32F4XX_DCI_H

#ifdef __cplusplus
  extern "C" {
#endif

/* Includes */
#include "apm32f4xx.h"

/** @addtogroup APM32F4xx_StdPeriphDriver
  @{
*/

/** @addtogroup DCI_Driver
  @{
*/

/** @defgroup DCI_Enumerations
  @{
*/

/**
 * @brief DCI Capture Mode
 */
typedef enum
{
    DCI_CAPTURE_MODE_CONTINUOUS,    /*!< Continuous capture mode    */
    DCI_CAPTURE_MODE_SNAPSHOT       /*!< Snapshot mode */
} DCI_CAPTURE_MODE_T;

/**
 * @brief DCI Synchronization Mode
 */
typedef enum
{
    DCI_SYNCHRO_MODE_HARDWARE,  /*!< Hardware synchronization */
    DCI_SYNCHRO_MODE_EMBEDDED   /*!< Embedded code synchronization */
} DCI_SYNCHRO_MODEVAL_T;

/**
 * @brief DCI Pixel Clock Polarity
 */
typedef enum
{
    DCI_PCK_POL_FALLING,        /*!< Falling edge capture */
    DCI_PCK_POL_RISING          /*!< Rising edge capture */
} DCI_PCK_POL_T;

/**
 * @brief DCI VSYNC Polarity
 */
typedef enum
{
    DCI_VSYNC_POL_LOW,  /*!< VSYNC low-level valid */
    DCI_VSYNC_POL_HIGH  /*!< VSYNC high-level valid */
} DCI_VSYNC_POL_T;

/**
 * @brief DCI HSYNC Polarity
 */
typedef enum
{
    DCI_HSYNC_POL_LOW,  /*!< HSYNC low-level valid */
    DCI_HSYNC_POL_HIGH  /*!< HSYNC high-level valid */
} DCI_HSYNC_POL_T;

/**
 * @brief DCI Capture Rate
 */
typedef enum
{
    DCI_CAPTURE_RATE_ALL_FRAME,     /*!< Capture all frame */
    DCI_CAPTURE_RATE_1OF2_FRAME,    /*!< Capture every other frame */
    DCI_CAPTURE_RATE_1OF4_FRAME     /*!< Capture every three frame */
} DCI_CAPTURE_RATE_T;

/**
 * @brief DCI Extended Data Mode
 */
typedef enum
{
    DCI_EXTENDED_DATA_MODE_8B,      /*!< Extended 8-bit data mode */
    DCI_EXTENDED_DATA_MODE_10B,     /*!< Extended 10-bit data mode */
    DCI_EXTENDED_DATA_MODE_12B,     /*!< Extended 12-bit data mode */
    DCI_EXTENDED_DATA_MODE_14B      /*!< Extended 14-bit data mode */
} DCI_EXTENDED_DATA_MODE_T;

/**
 * @brief DCI interrupt sources
 */
typedef enum
{
    DCI_INT_CC    =((uint16_t)0x0001),  /*!< Frame capture complete interrupt mask */
    DCI_INT_OVR   =((uint16_t)0x0002),  /*!< Overflow interrupt mask */
    DCI_INT_ERR   =((uint16_t)0x0004),  /*!< Synchronization error interrupt mask */
    DCI_INT_VSYNC =((uint16_t)0x0008),  /*!< VSYNC interrupt mask */
    DCI_INT_LINE  =((uint16_t)0x0010),  /*!< Line interrupt mask */
} DCI_INT_T;

/**
 * @brief DCI flags
 */
typedef enum
{
    /* DCI RINTSTS register */
    DCI_FLAG_CCI        =((uint16_t)0x0001),    /*!< Frame capture complete Raw flag mask */
    DCI_FLAG_OVRI       =((uint16_t)0x0002),    /*!< Overflow Raw flag mask */
    DCI_FLAG_ERRI       =((uint16_t)0x0004),    /*!< Synchronization error Raw flag mask */
    DCI_FLAG_VSYNCI     =((uint16_t)0x0008),    /*!< VSYNC Raw flag mask */
    DCI_FLAG_LINEI      =((uint16_t)0x0010),    /*!< Line Raw flag mask */
    /* DCI MINTSTS register */
    DCI_FLAG_CCMI       =((uint16_t)0x1001),    /*!< Frame capture complete Masked flag mask */
    DCI_FLAG_OVRMI      =((uint16_t)0x1002),    /*!< Overflow Masked flag mask */
    DCI_FLAG_ERRMI      =((uint16_t)0x1004),    /*!< Synchronization error Masked flag mask */
    DCI_FLAG_VSYNCMI    =((uint16_t)0x1008),    /*!< VSYNC Masked flag mask */
    DCI_FLAG_LINEMI     =((uint16_t)0x1010),    /*!< Line Masked flag mask */
    /* DCI STS register */
    DCI_FLAG_HSYNC      =((uint16_t)0x2001),    /*!< HSYNC flag mask */
    DCI_FLAG_VSYNC      =((uint16_t)0x2002),    /*!< VSYNC flag mask */
    DCI_FLAG_FNE        =((uint16_t)0x2004),    /*!< Fifo not empty flag mask */
} DCI_FLAG_T;

/**@} end of group DCI_Enumerations*/

/** @addtogroup DCI_Structure Data Structure
  @{
*/

/**
 * @brief DCI Config structure definition
 */
typedef struct
{
    DCI_CAPTURE_MODE_T        captureMode;      /*!< Specifies the Capture Mode: Continuous or Snapshot */

    DCI_SYNCHRO_MODEVAL_T     synchroMode;      /*!< Specifies the Synchronization Mode: Hardware or Embedded */

    DCI_PCK_POL_T             pckPolarity;      /*!< Specifies the Pixel clock polarity: Falling or Rising */

    DCI_VSYNC_POL_T           vsyncPolarity;    /*!< Specifies the Vertical synchronization polarity: High or Low */

    DCI_HSYNC_POL_T           hsyncPolarity;    /*!< Specifies the Horizontal synchronization polarity: High or Low */

    DCI_CAPTURE_RATE_T        capturerate;      /*!< Specifies the frequency of frame capture: All, 1/2 or 1/4 */

    DCI_EXTENDED_DATA_MODE_T  extendedDataMode; /*!< Specifies the data width: 8-bit, 10-bit, 12-bit or 14-bit */
} DCI_Config_T;

/**
 * @brief DCI CROP Init structure definition
 */
typedef struct
{
    uint16_t    verticalStartLine;      /*!< Vertical start line count from which the image capture(between 0x00 and 0x1FFF) */

    uint16_t    horizontalOffsetCount;  /*!< number of pixel clocks to count before starting a capture(between 0x00 and 0x3FFF) */

    uint16_t    verticalLineCount;      /*!< number of lines to be captured from the starting point(between 0x00 and 0x3FFF) */

    uint16_t    captureCount;           /*!< number of pixel clocks to be captured from the starting(between 0x00 and 0x3FFF) */
} DCI_CropConfig_T;

/**
  * @brief   DCI Embedded Synchronisation CODE Init structure definition
  */
typedef struct
{
    uint8_t     frameStartCode;      /*!< Specifies the code of the frame start delimiter */
    uint8_t     lineStartCode;       /*!< Specifies the code of the line start delimiter */
    uint8_t     lineEndCode;         /*!< Specifies the code of the line end delimiter */
    uint8_t     frameEndCode;        /*!< Specifies the code of the frame end delimiter */
} DCI_CodeConfig_T;

/**@} end of group DCI_Structure*/

/** @defgroup DCI_Functions
  @{
*/

/** DCI Configuration */
void DCI_Rest(void);
void DCI_Config(DCI_Config_T* dciConfig);
void DCI_ConfigStructInit(DCI_Config_T* dciConfig);
void DCI_ConfigCROP(DCI_CropConfig_T* cropConfig);
void DCI_EnableCROP(void);
void DCI_DisableCROP(void);
void DCI_ConfigSynchroCode(DCI_CodeConfig_T* codeConfig);
void DCI_EnableJPEG(void);
void DCI_DisableJPEG(void);

/** DCI Image capture */
void DCI_Enable(void);
void DCI_Disable(void);
void DCI_EnableCapture(void);
void DCI_DisableCapture(void);
uint32_t DCI_ReadData(void);

/** Interrupts and flags */
void DCI_EnableInterrupt(uint32_t interrupt);
void DCI_DisableInterrupt(uint32_t interrupt);
uint16_t DCI_ReadStatusFlag(DCI_FLAG_T flag);
void DCI_ClearStatusFlag(uint16_t flag);
uint16_t DCI_ReadIntFlag(DCI_INT_T flag);
void DCI_ClearIntFlag(uint16_t flag);

#ifdef __cplusplus
}
#endif

#endif /* __APM32F4XX_DCI_H */

/**@} end of group DCI_Enumerations */
/**@} end of group DCI_Driver */
/**@} end of group APM32F4xx_StdPeriphDriver */