1 /********************************** (C) COPYRIGHT  *******************************
2 * File Name          : ch32f20x_dvp.c
3 * Author             : WCH
4 * Version            : V1.0.0
5 * Date               : 2021/08/08
6 * Description        : This file provides all the DVP firmware functions.
7 *******************************************************************************/
8 #include "ch32f20x_dvp.h"
9 
10 
11 /*******************************************************************************
12 * Function Name  : DVP_INTCfg
13 * Description    : DVP interrupt configuration
14 * Input          : s: interrupt enable
15                     ENABLE
16                     DISABLE
17                    i: interrupt type
18                     RB_DVP_IE_STP_FRM
19                     RB_DVP_IE_FIFO_OV
20                     RB_DVP_IE_FRM_DONE
21                     RB_DVP_IE_ROW_DONE
22                     RB_DVP_IE_STR_FRM
23 * Return         : None
24 *******************************************************************************/
DVP_INTCfg(uint8_t s,uint8_t i)25 void DVP_INTCfg( uint8_t s,  uint8_t i )
26 {
27     if(s){
28         DVP->IER |= i;
29     }
30     else{
31         DVP->IER &= ~i;
32     }
33 }
34 
35 /*******************************************************************************
36 * Function Name  : DVP_Mode
37 * Description    : DVP mode
38 * Input          : s: data bit width
39                     RB_DVP_D8_MOD
40                     RB_DVP_D10_MOD
41                     RB_DVP_D12_MOD
42                    i: data mode
43                     Video_Mode
44                     JPEG_Mode
45 * Return         : None
46 *******************************************************************************/
DVP_Mode(uint8_t s,DVP_Data_ModeTypeDef i)47 void DVP_Mode( uint8_t s,  DVP_Data_ModeTypeDef i)
48 {
49     DVP->CR0 &= ~RB_DVP_MSK_DAT_MOD;
50 
51     if(s){
52         DVP->CR0 |= s;
53     }
54     else{
55         DVP->CR0 &= ~((uint32_t)3<<4);
56     }
57 
58     if(i){
59         DVP->CR0 |= RB_DVP_JPEG;
60     }
61     else{
62         DVP->CR0 &= ~RB_DVP_JPEG;
63     }
64 }
65 
66 /*******************************************************************************
67 * Function Name  : DVP_Cfg
68 * Description    : DVP configuration
69 * Input          : s:  DMA enable control
70                     DVP_DMA_Enable
71                     DVP_DMA_Disable
72                    i: DVP all clear
73                     DVP_FLAG_FIFO_RESET_Enable
74                     DVP_FLAG_FIFO_RESET_Disable
75                    j:  receive reset enable
76                     DVP_RX_RESET_Enable
77                     DVP_RX_RESET_Disable
78 * Return         : None
79 *******************************************************************************/
DVP_Cfg(DVP_DMATypeDef s,DVP_FLAG_FIFO_RESETTypeDef i,DVP_RX_RESETTypeDef j)80 void DVP_Cfg( DVP_DMATypeDef s,  DVP_FLAG_FIFO_RESETTypeDef i, DVP_RX_RESETTypeDef j)
81 {
82     switch( s )
83     {
84         case DVP_DMA_Enable:
85             DVP->CR1 |= RB_DVP_DMA_EN;
86             break;
87         case DVP_DMA_Disable:
88             DVP->CR1 &= ~RB_DVP_DMA_EN;
89             break;
90         default:
91             break;
92     }
93 
94     switch( i )
95     {
96         case DVP_RX_RESET_Enable:
97             DVP->CR1 |= RB_DVP_ALL_CLR;
98             break;
99         case DVP_RX_RESET_Disable:
100             DVP->CR1 &= ~RB_DVP_ALL_CLR;
101             break;
102         default:
103             break;
104     }
105 
106     switch( j )
107     {
108         case DVP_RX_RESET_Enable:
109             DVP->CR1 |= RB_DVP_RCV_CLR;
110             break;
111         case DVP_RX_RESET_Disable:
112             DVP->CR1 &= ~RB_DVP_RCV_CLR;
113             break;
114         default:
115             break;
116     }
117 
118 }
119