summaryrefslogtreecommitdiff
path: root/bsp/apm32/libraries/APM32F4xx_Library/APM32F4xx_StdPeriphDriver/src/apm32f4xx_dci.c
blob: a31858295ae6dee976897b846d97faf11b9b7b0f (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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*!
 * @file        apm32f4xx_dci.c
 *
 * @brief       This file provides all the DCI firmware functions
 *
 * @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.
 */

#include "apm32f4xx_dci.h"
#include "apm32f4xx_rcm.h"

/** @addtogroup APM32F4xx_StdPeriphDriver
  @{
*/

/** @defgroup DCI_Driver
  * @brief DCI driver modules
  @{
*/

/** @defgroup DCI_Functions
  @{
*/

/*!
 * @brief     Reast the DCI registers to their default reset values.
 *
 * @param     None
 *
 * @retval    None
 */
void DCI_Rest(void)
{
    DCI->CTRL      = 0x00;
    DCI->INTEN     = 0x00;
    DCI->INTCLR    = 0x1F;
    DCI->ESYNCC    = 0x00;
    DCI->ESYNCUM   = 0x00;
    DCI->CROPWSTAT = 0x00;
    DCI->CROPWSIZE = 0x00;
}

/*!
 * @brief     Configure DCI by configuring the structure
 *
 * @param     dciConfig: pointer to a DCI_Config_T structure
 *
 * @retval    None
 */
void DCI_Config(DCI_Config_T *dciConfig)
{
    DCI->CTRL_B.CMODE    = dciConfig->captureMode;
    DCI->CTRL_B.ESYNCSEL = dciConfig->synchroMode;
    DCI->CTRL_B.PXCLKPOL = dciConfig->pckPolarity;
    DCI->CTRL_B.VSYNCPOL = dciConfig->vsyncPolarity;
    DCI->CTRL_B.HSYNCPOL = dciConfig->hsyncPolarity;
    DCI->CTRL_B.FCRCFG   = dciConfig->capturerate;
    DCI->CTRL_B.EXDMOD   = dciConfig->extendedDataMode;
}

/*!
 * @brief     Fills each DCI InitStruct member with its default value.
 *
 * @param     dciConfig : pointer to a DCI_Config_T structure
 *
 * @retval    None
 */
void DCI_ConfigStructInit(DCI_Config_T *dciConfig)
{
    dciConfig->captureMode      = DCI_CAPTURE_MODE_CONTINUOUS;
    dciConfig->synchroMode      = DCI_SYNCHRO_MODE_HARDWARE;
    dciConfig->pckPolarity      = DCI_PCK_POL_FALLING;
    dciConfig->vsyncPolarity    = DCI_VSYNC_POL_LOW;
    dciConfig->hsyncPolarity    = DCI_HSYNC_POL_LOW;
    dciConfig->capturerate      = DCI_CAPTURE_RATE_ALL_FRAME;
    dciConfig->extendedDataMode = DCI_EXTENDED_DATA_MODE_8B;
}

/*!
 * @brief       Configure DCI CROP mode by configuring the structure
 *
 * @param       cropConfig:  pointer to a DCI_CropConfig_T structure
 *
 * @retval      None
 */
void DCI_ConfigCROP(DCI_CropConfig_T *cropConfig)
{
    DCI->CROPWSTAT_B.HOFSCNT   = (uint16_t)cropConfig->horizontalOffsetCount;
    DCI->CROPWSTAT_B.VSLINECNT = (uint16_t)cropConfig->verticalStartLine;

    DCI->CROPWSIZE_B.CCNT     = (uint16_t)cropConfig->captureCount;
    DCI->CROPWSIZE_B.VLINECNT = (uint16_t)cropConfig->verticalLineCount;
}

/*!
 * @brief     Enable the DCI Crop.
 *
 * @param     None
 *
 * @retval    None
 */
void DCI_EnableCROP(void)
{
    DCI->CTRL_B.CROPF = SET;
}

/*!
 * @brief     Disable the DCI Crop.
 *
 * @param     None
 *
 * @retval    None
 */
void DCI_DisableCROP(void)
{
    DCI->CTRL_B.CROPF = RESET;
}

/*!
 * @brief     Sets the embedded synchronization codes
 *
 * @param     CodeConfig: pointer to a DCI_CodeConfig_T structure
 *
 * @retval    None
 */
void DCI_ConfigSynchroCode(DCI_CodeConfig_T *codeConfig)
{
    DCI->ESYNCC_B.FSDC = (uint8_t)codeConfig->frameStartCode;
    DCI->ESYNCC_B.LSDC = (uint8_t)codeConfig->lineStartCode;
    DCI->ESYNCC_B.LEDC = (uint8_t)codeConfig->lineEndCode;
    DCI->ESYNCC_B.FEDC = (uint8_t)codeConfig->frameEndCode;
}

/*!
 * @brief     Enable the DCI JPEG.
 *
 * @param     None
 *
 * @retval    None
 */
void  DCI_EnableJPEG(void)
{
    DCI->CTRL_B.JPGFM = SET;
}

/*!
 * @brief     Disable the DCI JPEG.
 *
 * @param     None
 *
 * @retval    None
 */
void  DCI_DisableJPEG(void)
{

    DCI->CTRL_B.JPGFM = RESET;
}

/*!
* @brief     Enable the DCI interface.
*
* @param     None
*
* @retval    None
*/
void  DCI_Enable(void)
{
    DCI->CTRL_B.DCIEN = SET;
}

/*!
 * @brief     Disable the DCI interface.
 *
 * @param     None
 *
 * @retval    None
 */
void  DCI_Disable(void)
{
    DCI->CTRL_B.DCIEN = RESET;
}

/*!
 * @brief     Enable the DCI Capture.
 *
 * @param     None
 *
 * @retval    None
 */
void  DCI_EnableCapture(void)
{
    DCI->CTRL_B.CEN = SET;
}

/*!
 * @brief     Disable the DCI Capture.
 *
 * @param     None
 *
 * @retval    None
 */
void  DCI_DisableCapture(void)
{
    DCI->CTRL_B.CEN = RESET;
}

/*!
 * @brief     Read the data stored in the DATA register.
 *
 * @param     None
 *
 * @retval    Data register value
 */
uint32_t DCI_ReadData(void)
{
    return DCI->DATA;
}

/*!
 * @brief     Enable the DCI interface interrupts.
 *
 * @param     interrupt: specifies the DCI interrupt sources
 *            This parameter can be any combination of the following values:
 *              @arg DCI_INT_CC:    Frame capture complete interrupt mask
 *              @arg DCI_INT_OVR:   Overflow interrupt mask
 *              @arg DCI_INT_ERR:   Synchronization error interrupt mask
 *              @arg DCI_INT_VSYNC: VSYNC interrupt mask
 *              @arg DCI_INT_LINE:  Line interrupt mask
 *
 * @retval    None
 */
void DCI_EnableInterrupt(uint32_t interrupt)
{
    DCI->INTEN |= (uint32_t)interrupt;
}

/*!
 * @brief     Disable the DCI interface interrupts.
 *
 * @param     interrupt: specifies the DCI interrupt sources
 *            This parameter can be any combination of the following values:
 *              @arg DCI_INT_CC:    Frame capture complete interrupt mask
 *              @arg DCI_INT_OVR:   Overflow interrupt mask
 *              @arg DCI_INT_ERR:   Synchronization error interrupt mask
 *              @arg DCI_INT_VSYNC: VSYNC interrupt mask
 *              @arg DCI_INT_LINE:  Line interrupt mask
 *
 * @retval    None
 */
void DCI_DisableInterrupt(uint32_t interrupt)
{
    DCI->INTEN &= ~(uint32_t)interrupt;
}

/*!
 * @brief     Reads the DCI flag.
 *
 * @param     flag: specifies the flag to check.
 *            This parameter can be one of the following values:
 *              @arg DCI_FLAG_CCI:     Frame capture complete Raw flag mask
 *              @arg DCI_FLAG_OVRI:    Overflow Raw flag mask
 *              @arg DCI_FLAG_ERRI:    Synchronization error Raw flag mask
 *              @arg DCI_FLAG_VSYNCI:  VSYNC Raw flag mask
 *              @arg DCI_FLAG_LINEI:   Line Raw flag mask
 *              @arg DCI_FLAG_CCMI:    Frame capture complete Masked flag mask
 *              @arg DCI_FLAG_OVRMI:   Overflow Masked flag mask
 *              @arg DCI_FLAG_ERRMI:   Synchronization error Masked flag mask
 *              @arg DCI_FLAG_VSYNCMI: VSYNC Masked flag mask
 *              @arg DCI_FLAG_LINEMI:  Line Masked flag mask
 *              @arg DCI_FLAG_HSYNC:   HSYNC flag mask
 *              @arg DCI_FLAG_VSYNC:   VSYNC flag mask
 *              @arg DCI_FLAG_FNE:     Fifo not empty flag mask
 *
 * @retval    SET or RESET.
 */
uint16_t DCI_ReadStatusFlag(DCI_FLAG_T flag)
{
    uint32_t offset, temp = 0;
    offset = (flag >> 12);

    if (offset == 0x00)
    {
        temp = DCI->RINTSTS;
    }
    else if (offset == 0x01)
    {
        temp = DCI->MINTSTS;
    }
    else
    {
        temp = DCI->STS;
    }
    return (temp & flag) ? SET : RESET;
}

/*!
 * @brief     Clears the DCI flag.
 *
 * @param     flag: specifies the flag to clear.
 *            This parameter can be any combination of the following values:
 *              @arg DCI_FLAG_CCI:     Frame capture complete Raw flag mask
 *              @arg DCI_FLAG_OVRI:    Overflow Raw flag mask
 *              @arg DCI_FLAG_ERRI:    Synchronization error Raw flag mask
 *              @arg DCI_FLAG_VSYNCI:  VSYNC Raw flag mask
 *              @arg DCI_FLAG_LINEI:   Line Raw flag mask

 * @retval    None
 */
void DCI_ClearStatusFlag(uint16_t flag)
{
    DCI->INTCLR = (uint16_t)flag;
}

/*!
 * @brief     Read the DCI interrupt flag.
 *
 * @param     flag: specifies the DCI interrupt source to check.
 *            This parameter can be one of the following values:
 *              @arg DCI_INT_CC:    Frame capture complete interrupt mask
 *              @arg DCI_INT_OVR:   Overflow interrupt mask
 *              @arg DCI_INT_ERR:   Synchronization error interrupt mask
 *              @arg DCI_INT_VSYNC: VSYNC interrupt mask
 *              @arg DCI_INT_LINE:  Line interrupt mask
 *
 * @retval    None
 */
uint16_t DCI_ReadIntFlag(DCI_INT_T flag)
{
    return (DCI->MINTSTS & flag) ? SET : RESET;
}

/*!
 * @brief     Clear the DCI interrupt flag.
 *
 * @param     flag: specifies the DCI interrupt pending bit to clear.
 *            This parameter can be any combination of the following values:
 *              @arg DCI_INT_CC:    Frame capture complete interrupt mask
 *              @arg DCI_INT_OVR:   Overflow interrupt mask
 *              @arg DCI_INT_ERR:   Synchronization error interrupt mask
 *              @arg DCI_INT_VSYNC: VSYNC interrupt mask
 *              @arg DCI_INT_LINE:  Line interrupt mask
 *
 * @retval    None
 */
void DCI_ClearIntFlag(uint16_t flag)
{
    DCI->INTCLR = (uint16_t)flag;
}

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