PicoCamera 0.2.0
Camera library for RP2040 with an esp32-camera compatible API
GitHub
Loading...
Searching...
No Matches
ov2640_regs.h
1/*
2 * This file is part of the PicoCamera project.
3 * https://github.com/umeiko/PicoCamera
4 *
5 * Author: umeko <umeko@stu.xmu.edu.cn>
6 * License: MIT
7 */
8
9#ifndef __OV2640_REGS_H__
10#define __OV2640_REGS_H__
11/* DSP register bank FF=0x00*/
12#define R_BYPASS 0x05
13#define QS 0x44
14#define CTRLI 0x50
15#define HSIZE 0x51
16#define VSIZE 0x52
17#define XOFFL 0x53
18#define YOFFL 0x54
19#define VHYX 0x55
20#define DPRP 0x56
21#define TEST 0x57
22#define ZMOW 0x5A
23#define ZMOH 0x5B
24#define ZMHH 0x5C
25#define BPADDR 0x7C
26#define BPDATA 0x7D
27#define CTRL2 0x86
28#define CTRL3 0x87
29#define SIZEL 0x8C
30#define HSIZE8 0xC0
31#define VSIZE8 0xC1
32#define CTRL0 0xC2
33#define CTRL1 0xC3
34#define R_DVP_SP 0xD3
35#define IMAGE_MODE 0xDA
36#define RESET 0xE0
37#define MS_SP 0xF0
38#define SS_ID 0xF7
39#define SS_CTRL 0xF7
40#define MC_BIST 0xF9
41#define MC_AL 0xFA
42#define MC_AH 0xFB
43#define MC_D 0xFC
44#define P_CMD 0xFD
45#define P_STATUS 0xFE
46#define BANK_SEL 0xFF
47
48#define CTRLI_LP_DP 0x80
49#define CTRLI_ROUND 0x40
50
51#define CTRL0_AEC_EN 0x80
52#define CTRL0_AEC_SEL 0x40
53#define CTRL0_STAT_SEL 0x20
54#define CTRL0_VFIRST 0x10
55#define CTRL0_YUV422 0x08
56#define CTRL0_YUV_EN 0x04
57#define CTRL0_RGB_EN 0x02
58#define CTRL0_RAW_EN 0x01
59
60#define CTRL2_DCW_EN 0x20
61#define CTRL2_SDE_EN 0x10
62#define CTRL2_UV_ADJ_EN 0x08
63#define CTRL2_UV_AVG_EN 0x04
64#define CTRL2_CMX_EN 0x01
65
66#define CTRL3_BPC_EN 0x80
67#define CTRL3_WPC_EN 0x40
68
69#define R_DVP_SP_DIV_YUV(x) ((x)&0x7F)
70#define R_DVP_SP_DIV_RAW(x) ((x >> 1)&0x7F)
71#define R_DVP_SP_AUTO_MODE 0x80
72
73#define R_BYPASS_DSP_EN 0x00
74#define R_BYPASS_DSP_BYPAS 0x01
75
76#define IMAGE_MODE_Y8_DVP_EN 0x40
77#define IMAGE_MODE_JPEG_EN 0x10
78#define IMAGE_MODE_YUV422 0x00
79#define IMAGE_MODE_RAW10 0x04
80#define IMAGE_MODE_RGB565 0x08
81#define IMAGE_MODE_HREF_VSYNC 0x02
82#define IMAGE_MODE_LBYTE_FIRST 0x01
83
84#define RESET_MICROC 0x40
85#define RESET_SCCB 0x20
86#define RESET_JPEG 0x10
87#define RESET_DVP 0x04
88#define RESET_IPU 0x02
89#define RESET_CIF 0x01
90
91#define MC_BIST_RESET 0x80
92#define MC_BIST_BOOT_ROM_SEL 0x40
93#define MC_BIST_12KB_SEL 0x20
94#define MC_BIST_12KB_MASK 0x30
95#define MC_BIST_512KB_SEL 0x08
96#define MC_BIST_512KB_MASK 0x0C
97#define MC_BIST_BUSY_BIT_R 0x02
98#define MC_BIST_MC_RES_ONE_SH_W 0x02
99#define MC_BIST_LAUNCH 0x01
100
101#define BANK_SEL_DSP 0x00
102#define BANK_SEL_SENSOR 0x01
103
104/* Sensor register bank FF=0x01*/
105#define GAIN 0x00
106#define COM1 0x03
107#define REG04 0x04
108#define REG08 0x08
109#define COM2 0x09
110#define REG_PID 0x0A
111#define REG_VER 0x0B
112#define COM3 0x0C
113#define COM4 0x0D
114#define AEC 0x10
115#define CLKRC 0x11
116#define COM7 0x12
117#define COM8 0x13
118#define COM9 0x14 /* AGC gain ceiling */
119#define COM10 0x15
120#define HSTART 0x17
121#define HSTOP 0x18
122#define VSTART 0x19
123#define VSTOP 0x1A
124#define REG_MIDH 0x1C
125#define REG_MIDL 0x1D
126#define AEW 0x24
127#define AEB 0x25
128#define VV 0x26
129#define REG2A 0x2A
130#define FRARL 0x2B
131#define ADDVSL 0x2D
132#define ADDVSH 0x2E
133#define YAVG 0x2F
134#define HSDY 0x30
135#define HEDY 0x31
136#define REG32 0x32
137#define ARCOM2 0x34
138#define REG45 0x45
139#define FLL 0x46
140#define FLH 0x47
141#define COM19 0x48
142#define ZOOMS 0x49
143#define COM22 0x4B
144#define COM25 0x4E
145#define BD50 0x4F
146#define BD60 0x50
147#define REG5D 0x5D
148#define REG5E 0x5E
149#define REG5F 0x5F
150#define REG60 0x60
151#define HISTO_LOW 0x61
152#define HISTO_HIGH 0x62
153
154#define REG04_DEFAULT 0x28
155#define REG04_HFLIP_IMG 0x80
156#define REG04_VFLIP_IMG 0x40
157#define REG04_VREF_EN 0x10
158#define REG04_HREF_EN 0x08
159#define REG04_SET(x) (REG04_DEFAULT|x)
160
161#define COM2_STDBY 0x10
162#define COM2_OUT_DRIVE_1x 0x00
163#define COM2_OUT_DRIVE_2x 0x01
164#define COM2_OUT_DRIVE_3x 0x02
165#define COM2_OUT_DRIVE_4x 0x03
166
167#define COM3_DEFAULT 0x38
168#define COM3_BAND_50Hz 0x04
169#define COM3_BAND_60Hz 0x00
170#define COM3_BAND_AUTO 0x02
171#define COM3_BAND_SET(x) (COM3_DEFAULT|x)
172
173#define COM7_SRST 0x80
174#define COM7_RES_UXGA 0x00 /* UXGA */
175#define COM7_RES_SVGA 0x40 /* SVGA */
176#define COM7_RES_CIF 0x20 /* CIF */
177#define COM7_ZOOM_EN 0x04 /* Enable Zoom */
178#define COM7_COLOR_BAR 0x02 /* Enable Color Bar Test */
179
180#define COM8_DEFAULT 0xC0
181#define COM8_BNDF_EN 0x20 /* Enable Banding filter */
182#define COM8_AGC_EN 0x04 /* AGC Auto/Manual control selection */
183#define COM8_AEC_EN 0x01 /* Auto/Manual Exposure control */
184#define COM8_SET(x) (COM8_DEFAULT|x)
185
186#define COM9_DEFAULT 0x08
187#define COM9_AGC_GAIN_2x 0x00 /* AGC: 2x */
188#define COM9_AGC_GAIN_4x 0x01 /* AGC: 4x */
189#define COM9_AGC_GAIN_8x 0x02 /* AGC: 8x */
190#define COM9_AGC_GAIN_16x 0x03 /* AGC: 16x */
191#define COM9_AGC_GAIN_32x 0x04 /* AGC: 32x */
192#define COM9_AGC_GAIN_64x 0x05 /* AGC: 64x */
193#define COM9_AGC_GAIN_128x 0x06 /* AGC: 128x */
194#define COM9_AGC_SET(x) (COM9_DEFAULT|(x<<5))
195
196#define COM10_HREF_EN 0x80 /* HSYNC changes to HREF */
197#define COM10_HSYNC_EN 0x40 /* HREF changes to HSYNC */
198#define COM10_PCLK_FREE 0x20 /* PCLK output option: free running PCLK */
199#define COM10_PCLK_EDGE 0x10 /* Data is updated at the rising edge of PCLK */
200#define COM10_HREF_NEG 0x08 /* HREF negative */
201#define COM10_VSYNC_NEG 0x02 /* VSYNC negative */
202#define COM10_HSYNC_NEG 0x01 /* HSYNC negative */
203
204#define CTRL1_AWB 0x08 /* Enable AWB */
205
206#define VV_AGC_TH_SET(h,l) ((h<<4)|(l&0x0F))
207
208#define REG32_UXGA 0x36
209#define REG32_SVGA 0x09
210#define REG32_CIF 0x89
211
212#define CLKRC_DIV(x) (((x) - 1)&0x1F)
213#define CLKRC_2X 0x80
214#define CLKRC_2X_UXGA (CLKRC_2X | CLKRC_DIV(12))
215#define CLKRC_2X_SVGA (CLKRC_2X | CLKRC_DIV(8))
216#define CLKRC_2X_CIF (CLKRC_2X | CLKRC_DIV(0))
217
218/* DSP contrast levels (BPADDR/BPDATA indirect access) */
219#define NUM_CONTRAST_LEVELS (5)
220static const uint8_t contrast_regs[NUM_CONTRAST_LEVELS + 1][7] = {
221 {BPADDR, BPDATA, BPADDR, BPDATA, BPDATA, BPDATA, BPDATA },
222 {0x00, 0x04, 0x07, 0x20, 0x18, 0x34, 0x06 }, /* -2 */
223 {0x00, 0x04, 0x07, 0x20, 0x1c, 0x2a, 0x06 }, /* -1 */
224 {0x00, 0x04, 0x07, 0x20, 0x20, 0x20, 0x06 }, /* 0 */
225 {0x00, 0x04, 0x07, 0x20, 0x24, 0x16, 0x06 }, /* +1 */
226 {0x00, 0x04, 0x07, 0x20, 0x28, 0x0c, 0x06 }, /* +2 */
227};
228
229/* DSP saturation levels (BPADDR/BPDATA indirect access) */
230#define NUM_SATURATION_LEVELS (5)
231static const uint8_t saturation_regs[NUM_SATURATION_LEVELS + 1][5] = {
232 {BPADDR, BPDATA, BPADDR, BPDATA, BPDATA },
233 {0x00, 0x02, 0x03, 0x28, 0x28 }, /* -2 */
234 {0x00, 0x02, 0x03, 0x38, 0x38 }, /* -1 */
235 {0x00, 0x02, 0x03, 0x48, 0x48 }, /* 0 */
236 {0x00, 0x02, 0x03, 0x58, 0x58 }, /* +1 */
237 {0x00, 0x02, 0x03, 0x68, 0x68 }, /* +2 */
238};
239
240/* DSP special effects (BPADDR/BPDATA indirect access) */
241#define NUM_SPECIAL_EFFECTS (7)
242static const uint8_t special_effects_regs[NUM_SPECIAL_EFFECTS + 1][5] = {
243 {BPADDR, BPDATA, BPADDR, BPDATA, BPDATA },
244 {0x00, 0X00, 0x05, 0X80, 0X80 }, /* no effect */
245 {0x00, 0X40, 0x05, 0X80, 0X80 }, /* negative */
246 {0x00, 0X18, 0x05, 0X80, 0X80 }, /* black and white */
247 {0x00, 0X18, 0x05, 0X40, 0XC0 }, /* reddish */
248 {0x00, 0X18, 0x05, 0X40, 0X40 }, /* greenish */
249 {0x00, 0X18, 0x05, 0XA0, 0X40 }, /* blue */
250 {0x00, 0X18, 0x05, 0X40, 0XA6 }, /* retro */
251};
252
253/* DSP white balance modes */
254#define NUM_WB_MODES (4)
255static const uint8_t wb_modes_regs[NUM_WB_MODES + 1][3] = {
256 {0XCC, 0XCD, 0XCE },
257 {0x5E, 0X41, 0x54 }, /* sunny */
258 {0x65, 0X41, 0x4F }, /* cloudy */
259 {0x52, 0X41, 0x66 }, /* office */
260 {0x42, 0X3F, 0x71 }, /* home */
261};
262
263/* Sensor AE levels */
264#define NUM_AE_LEVELS (5)
265static const uint8_t ae_levels_regs[NUM_AE_LEVELS + 1][3] = {
266 { AEW, AEB, VV },
267 {0x20, 0X18, 0x60 }, /* -2 */
268 {0x34, 0X1C, 0x00 }, /* -1 */
269 {0x3E, 0X38, 0x81 }, /* 0 */
270 {0x48, 0X40, 0x81 }, /* +1 */
271 {0x58, 0X50, 0x92 }, /* +2 */
272};
273
274#define ENDMARKER {0xff, 0xff}
275
276#endif //__OV2640_REGS_H__
中文文档