ov7670 library

Dependents:   Project_test Capture_bw_portin Capture_bw_v3 Project_190659132

Committer:
sebbarpar
Date:
Mon Jun 22 11:07:23 2020 +0000
Revision:
7:2ca4f55b5ac2
Parent:
6:b1b77891bddf
ib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edodm85 0:810d59d0b843 1 #include "ov7670.h"
edodm85 0:810d59d0b843 2
edodm85 0:810d59d0b843 3
sebbarpar 6:b1b77891bddf 4 OV7670::OV7670(PinName sda, PinName scl, PinName vs, PinName hr, PinName we, /*PinName d7, PinName d6, PinName d5, PinName d4, PinName d3, PinName d2, PinName d1, PinName d0,*/PortName port, int mask, PinName rt, PinName o, PinName rc) : _i2c(sda,scl),vsync(vs),href(hr),wen(we),/*data(d0,d1,d2,d3,d4,d5,d6,d7)*/data(port,mask),rrst(rt),oe(o),rclk(rc)
edodm85 0:810d59d0b843 5 {
edodm85 0:810d59d0b843 6 _i2c.stop();
edodm85 0:810d59d0b843 7 _i2c.frequency(OV7670_I2CFREQ);
edodm85 0:810d59d0b843 8 vsync.fall(this,&OV7670::VsyncHandler); // interrupt fall edge
sebbarpar 6:b1b77891bddf 9 href.fall(this,&OV7670::HrefHandler); // interrupt fall edge
edodm85 0:810d59d0b843 10 CaptureReq = false;
edodm85 0:810d59d0b843 11 Busy = false;
edodm85 0:810d59d0b843 12 Done = false;
edodm85 0:810d59d0b843 13 LineCounter = 0;
edodm85 0:810d59d0b843 14 rrst = 1;
edodm85 0:810d59d0b843 15 oe = 1;
edodm85 0:810d59d0b843 16 rclk = 1;
edodm85 0:810d59d0b843 17 wen = 0;
edodm85 0:810d59d0b843 18 }
edodm85 0:810d59d0b843 19
sebbarpar 6:b1b77891bddf 20 int bit=0;
edodm85 0:810d59d0b843 21 OV7670::~OV7670()
edodm85 0:810d59d0b843 22 {
edodm85 3:b40a945dd672 23 }
edodm85 0:810d59d0b843 24
edodm85 0:810d59d0b843 25
edodm85 0:810d59d0b843 26 // capture request
edodm85 0:810d59d0b843 27 void OV7670::CaptureNext(void)
edodm85 0:810d59d0b843 28 {
edodm85 3:b40a945dd672 29 CaptureReq = true;
edodm85 3:b40a945dd672 30 Busy = true;
edodm85 0:810d59d0b843 31 }
edodm85 0:810d59d0b843 32
edodm85 3:b40a945dd672 33
edodm85 0:810d59d0b843 34 // capture done? (with clear)
edodm85 0:810d59d0b843 35 bool OV7670::CaptureDone(void)
edodm85 0:810d59d0b843 36 {
edodm85 3:b40a945dd672 37 bool result;
edodm85 3:b40a945dd672 38 if (Busy)
edodm85 3:b40a945dd672 39 {
edodm85 3:b40a945dd672 40 result = false;
edodm85 3:b40a945dd672 41 }else
edodm85 3:b40a945dd672 42 {
edodm85 3:b40a945dd672 43 result = Done;
edodm85 3:b40a945dd672 44 Done = false;
edodm85 0:810d59d0b843 45 }
edodm85 3:b40a945dd672 46 return result;
edodm85 0:810d59d0b843 47 }
edodm85 0:810d59d0b843 48
edodm85 3:b40a945dd672 49
edodm85 3:b40a945dd672 50 // vsync handler
edodm85 3:b40a945dd672 51 void OV7670::VsyncHandler(void)
sebbarpar 6:b1b77891bddf 52 {
edodm85 3:b40a945dd672 53 // Capture Enable
edodm85 3:b40a945dd672 54 if (CaptureReq)
edodm85 3:b40a945dd672 55 {
edodm85 3:b40a945dd672 56 wen = 1;
edodm85 3:b40a945dd672 57 Done = false;
edodm85 3:b40a945dd672 58 CaptureReq = false;
edodm85 3:b40a945dd672 59 }else
edodm85 3:b40a945dd672 60 {
edodm85 3:b40a945dd672 61 wen = 0;
edodm85 3:b40a945dd672 62 if (Busy)
edodm85 3:b40a945dd672 63 {
edodm85 3:b40a945dd672 64 Busy = false;
edodm85 3:b40a945dd672 65 Done = true;
edodm85 3:b40a945dd672 66 }
edodm85 3:b40a945dd672 67 }
edodm85 0:810d59d0b843 68 }
edodm85 0:810d59d0b843 69
sebbarpar 7:2ca4f55b5ac2 70
sebbarpar 6:b1b77891bddf 71
edodm85 3:b40a945dd672 72
edodm85 3:b40a945dd672 73 // Data Read
sebbarpar 5:46b8114bb5dd 74 int OV7670:: ReadOnebyte(void)
sebbarpar 5:46b8114bb5dd 75 {
sebbarpar 5:46b8114bb5dd 76 int result ;
sebbarpar 5:46b8114bb5dd 77 rclk = 1 ;
sebbarpar 5:46b8114bb5dd 78 // wait_us(1) ;
sebbarpar 5:46b8114bb5dd 79 result = data ;
sebbarpar 6:b1b77891bddf 80
sebbarpar 6:b1b77891bddf 81 int top= result>>4;
sebbarpar 6:b1b77891bddf 82 result=result&0x0F;
sebbarpar 6:b1b77891bddf 83 result=result+top;
sebbarpar 6:b1b77891bddf 84
sebbarpar 5:46b8114bb5dd 85 rclk = 0 ;
sebbarpar 5:46b8114bb5dd 86 return result ;
sebbarpar 5:46b8114bb5dd 87 }
edodm85 0:810d59d0b843 88
edodm85 3:b40a945dd672 89
edodm85 3:b40a945dd672 90 // Data Start read from FIFO
edodm85 3:b40a945dd672 91 void OV7670::ReadStart(void)
edodm85 3:b40a945dd672 92 {
edodm85 3:b40a945dd672 93 rrst = 0;
edodm85 3:b40a945dd672 94 oe = 0;
edodm85 3:b40a945dd672 95 wait_us(1);
edodm85 3:b40a945dd672 96 rclk = 0;
edodm85 3:b40a945dd672 97 wait_us(1);
edodm85 3:b40a945dd672 98 rclk = 1;
edodm85 3:b40a945dd672 99 wait_us(1);
edodm85 3:b40a945dd672 100 rrst = 1;
edodm85 0:810d59d0b843 101 }
edodm85 0:810d59d0b843 102
edodm85 3:b40a945dd672 103
edodm85 3:b40a945dd672 104 // Data Stop read from FIFO
edodm85 3:b40a945dd672 105 void OV7670::ReadStop(void)
edodm85 3:b40a945dd672 106 {
edodm85 3:b40a945dd672 107 oe = 1;
edodm85 3:b40a945dd672 108 ReadOnebyte();
edodm85 3:b40a945dd672 109 rclk = 1;
edodm85 3:b40a945dd672 110 }
edodm85 3:b40a945dd672 111
edodm85 3:b40a945dd672 112
edodm85 3:b40a945dd672 113 void OV7670::Reset(void)
edodm85 3:b40a945dd672 114 {
edodm85 3:b40a945dd672 115 WriteReg(0x12, 0x80); // RESET CAMERA
edodm85 3:b40a945dd672 116 wait_ms(200);
edodm85 3:b40a945dd672 117 }
edodm85 3:b40a945dd672 118
edodm85 3:b40a945dd672 119
edodm85 1:d82dbad9c06b 120 int OV7670::Init(char c, int n)
edodm85 0:810d59d0b843 121 {
edodm85 0:810d59d0b843 122
edodm85 2:354a00023f79 123 if (ReadReg(REG_PID) != 0x76) // check id camera
edodm85 0:810d59d0b843 124 {
edodm85 0:810d59d0b843 125 return 0;
edodm85 0:810d59d0b843 126 }
edodm85 0:810d59d0b843 127
edodm85 2:354a00023f79 128 Reset(); // Resets all registers to default values
edodm85 2:354a00023f79 129 Reset(); // Resets all registers to default values
edodm85 1:d82dbad9c06b 130
edodm85 2:354a00023f79 131 WriteReg(REG_RGB444, 0x00); // Disable RGB444
edodm85 3:b40a945dd672 132 WriteReg(REG_COM10, 0x02); // 0x02 VSYNC negative (http://thinksmallthings.wordpress.com/2012/03/10/cf7670c-vs-cf7670c-v2/)
edodm85 2:354a00023f79 133 WriteReg(REG_MVFP, 0x27); // mirror image
edodm85 1:d82dbad9c06b 134
edodm85 2:354a00023f79 135 WriteReg(REG_CLKRC, 0x80); // prescaler x1
edodm85 2:354a00023f79 136 WriteReg(DBLV, 0x0a); // bypass PLL
edodm85 1:d82dbad9c06b 137
edodm85 2:354a00023f79 138 WriteReg(REG_COM11, 0x0A) ;
edodm85 2:354a00023f79 139 WriteReg(REG_TSLB, 0x04); // 0D = UYVY 04 = YUYV
edodm85 2:354a00023f79 140 WriteReg(REG_COM13, 0x88); // connect to REG_TSLB
edodm85 0:810d59d0b843 141
edodm85 1:d82dbad9c06b 142
edodm85 1:d82dbad9c06b 143 if(c == 'b' || c == 'y') // YUV
edodm85 1:d82dbad9c06b 144 {
edodm85 1:d82dbad9c06b 145 WriteReg(REG_COM7, 0x00); // YUV
edodm85 1:d82dbad9c06b 146 WriteReg(REG_COM17, 0x00); // color bar disable
edodm85 1:d82dbad9c06b 147 WriteReg(REG_COM3, 0x04);
edodm85 1:d82dbad9c06b 148 WriteReg(REG_COM15, 0xC0); // Set normal rgb with Full range
edodm85 1:d82dbad9c06b 149
edodm85 1:d82dbad9c06b 150 }else
edodm85 1:d82dbad9c06b 151 if(c == 'r') // RGB565
edodm85 1:d82dbad9c06b 152 {
edodm85 1:d82dbad9c06b 153 WriteReg(REG_COM7, 0x04); // RGB + color bar disable
edodm85 1:d82dbad9c06b 154 WriteReg(REG_RGB444, 0x00); // Disable RGB444
edodm85 1:d82dbad9c06b 155 WriteReg(REG_COM15, 0x10); // Set rgb565 with Full range 0xD0
edodm85 1:d82dbad9c06b 156 WriteReg(REG_COM3, 0x04);
edodm85 2:354a00023f79 157 WriteReg(REG_CLKRC, 0x80); // prescaler x1
edodm85 1:d82dbad9c06b 158 }
edodm85 1:d82dbad9c06b 159
edodm85 1:d82dbad9c06b 160 WriteReg(0x70, 0x3A); // Scaling Xsc
edodm85 1:d82dbad9c06b 161 WriteReg(0x71, 0x35); // Scaling Ysc
edodm85 1:d82dbad9c06b 162 WriteReg(0xA2, 0x02); // pixel clock delay
edodm85 1:d82dbad9c06b 163
edodm85 1:d82dbad9c06b 164 if(n == 19200) // 160*120
edodm85 1:d82dbad9c06b 165 {
edodm85 1:d82dbad9c06b 166 WriteReg(REG_COM14, 0x1a); // divide by 4
edodm85 1:d82dbad9c06b 167 WriteReg(0x72, 0x22); // downsample by 4
edodm85 1:d82dbad9c06b 168 WriteReg(0x73, 0xf2); // divide by 4
edodm85 2:354a00023f79 169 WriteReg(REG_HREF, 0xa4);
edodm85 2:354a00023f79 170 WriteReg(REG_HSTART, 0x16);
edodm85 2:354a00023f79 171 WriteReg(REG_HSTOP, 0x04);
edodm85 2:354a00023f79 172 WriteReg(REG_VREF, 0x0a);
edodm85 2:354a00023f79 173 WriteReg(REG_VSTART, 0x02);
edodm85 2:354a00023f79 174 WriteReg(REG_VSTOP, 0x7a);
edodm85 2:354a00023f79 175
edodm85 2:354a00023f79 176 WriteReg(0x7a, 0x20);
edodm85 2:354a00023f79 177 WriteReg(0x7b, 0x1c);
edodm85 2:354a00023f79 178 WriteReg(0x7c, 0x28);
edodm85 2:354a00023f79 179 WriteReg(0x7d, 0x3c);
edodm85 2:354a00023f79 180 WriteReg(0x7e, 0x5a);
edodm85 2:354a00023f79 181 WriteReg(0x7f, 0x68);
edodm85 2:354a00023f79 182 WriteReg(0x80, 0x76);
edodm85 2:354a00023f79 183 WriteReg(0x81, 0x80);
edodm85 2:354a00023f79 184 WriteReg(0x82, 0x88);
edodm85 2:354a00023f79 185 WriteReg(0x83, 0x8f);
edodm85 2:354a00023f79 186 WriteReg(0x84, 0x96);
edodm85 2:354a00023f79 187 WriteReg(0x85, 0xa3);
edodm85 2:354a00023f79 188 WriteReg(0x86, 0xaf);
edodm85 2:354a00023f79 189 WriteReg(0x87, 0xc4);
edodm85 2:354a00023f79 190 WriteReg(0x88, 0xd7);
edodm85 2:354a00023f79 191 WriteReg(0x89, 0xe8);
edodm85 2:354a00023f79 192
edodm85 2:354a00023f79 193 WriteReg(0x13, 0xe0);
edodm85 2:354a00023f79 194 WriteReg(0x00, 0x00);
edodm85 2:354a00023f79 195 WriteReg(0x10, 0x00);
edodm85 2:354a00023f79 196 WriteReg(0x0d, 0x40);
edodm85 2:354a00023f79 197 WriteReg(0x14, 0x18);
edodm85 2:354a00023f79 198 WriteReg(0xa5, 0x05);
edodm85 2:354a00023f79 199 WriteReg(0xab, 0x07);
edodm85 2:354a00023f79 200 WriteReg(0x24, 0x95);
edodm85 2:354a00023f79 201 WriteReg(0x25, 0x33);
edodm85 2:354a00023f79 202 WriteReg(0x26, 0xe3);
edodm85 2:354a00023f79 203 WriteReg(0x9f, 0x78);
edodm85 2:354a00023f79 204 WriteReg(0xa0, 0x68);
edodm85 2:354a00023f79 205 WriteReg(0xa1, 0x03);
edodm85 2:354a00023f79 206 WriteReg(0xa6, 0xd8);
edodm85 2:354a00023f79 207 WriteReg(0xa7, 0xd8);
edodm85 2:354a00023f79 208 WriteReg(0xa8, 0xf0);
edodm85 2:354a00023f79 209 WriteReg(0xa9, 0x90);
edodm85 2:354a00023f79 210 WriteReg(0xaa, 0x94);
edodm85 2:354a00023f79 211 WriteReg(0x13, 0xe5);
edodm85 2:354a00023f79 212
edodm85 2:354a00023f79 213 WriteReg(0x0e, 0x61);
edodm85 2:354a00023f79 214 WriteReg(0x0f, 0x4b);
edodm85 2:354a00023f79 215 WriteReg(0x16, 0x02);
edodm85 2:354a00023f79 216
edodm85 2:354a00023f79 217 WriteReg(0x21, 0x02);
edodm85 2:354a00023f79 218 WriteReg(0x22, 0x91);
edodm85 2:354a00023f79 219 WriteReg(0x29, 0x07);
edodm85 2:354a00023f79 220 WriteReg(0x33, 0x0b);
edodm85 2:354a00023f79 221 WriteReg(0x35, 0x0b);
edodm85 2:354a00023f79 222 WriteReg(0x37, 0x1d);
edodm85 2:354a00023f79 223 WriteReg(0x38, 0x71);
edodm85 2:354a00023f79 224 WriteReg(0x39, 0x2a);
edodm85 2:354a00023f79 225 WriteReg(0x3c, 0x78);
edodm85 2:354a00023f79 226 WriteReg(0x4d, 0x40);
edodm85 2:354a00023f79 227 WriteReg(0x4e, 0x20);
edodm85 2:354a00023f79 228 WriteReg(0x69, 0x00);
edodm85 2:354a00023f79 229
edodm85 2:354a00023f79 230 WriteReg(0x74, 0x10);
edodm85 2:354a00023f79 231 WriteReg(0x8d, 0x4f);
edodm85 2:354a00023f79 232 WriteReg(0x8e, 0x00);
edodm85 2:354a00023f79 233 WriteReg(0x8f, 0x00);
edodm85 2:354a00023f79 234 WriteReg(0x90, 0x00);
edodm85 2:354a00023f79 235 WriteReg(0x91, 0x00);
edodm85 2:354a00023f79 236 WriteReg(0x92, 0x00);
edodm85 2:354a00023f79 237
edodm85 2:354a00023f79 238 WriteReg(0x96, 0x00);
edodm85 2:354a00023f79 239 WriteReg(0x9a, 0x80);
edodm85 2:354a00023f79 240 WriteReg(0xb0, 0x84);
edodm85 2:354a00023f79 241 WriteReg(0xb1, 0x0c);
edodm85 2:354a00023f79 242 WriteReg(0xb2, 0x0e);
edodm85 2:354a00023f79 243 WriteReg(0xb3, 0x82);
edodm85 2:354a00023f79 244 WriteReg(0xb8, 0x0a);
edodm85 2:354a00023f79 245
edodm85 2:354a00023f79 246 WriteReg(0x43, 0x0a);
edodm85 2:354a00023f79 247 WriteReg(0x44, 0xf0);
edodm85 2:354a00023f79 248 WriteReg(0x45, 0x34);
edodm85 2:354a00023f79 249 WriteReg(0x46, 0x58);
edodm85 2:354a00023f79 250 WriteReg(0x47, 0x28);
edodm85 2:354a00023f79 251 WriteReg(0x48, 0x3a);
edodm85 2:354a00023f79 252 WriteReg(0x59, 0x88);
edodm85 2:354a00023f79 253 WriteReg(0x5a, 0x88);
edodm85 2:354a00023f79 254 WriteReg(0x5b, 0x44);
edodm85 2:354a00023f79 255 WriteReg(0x5c, 0x67);
edodm85 2:354a00023f79 256 WriteReg(0x5d, 0x49);
edodm85 2:354a00023f79 257 WriteReg(0x5e, 0x0e);
edodm85 2:354a00023f79 258 WriteReg(0x64, 0x04);
edodm85 2:354a00023f79 259 WriteReg(0x65, 0x20);
edodm85 2:354a00023f79 260 WriteReg(0x66, 0x05);
edodm85 2:354a00023f79 261 WriteReg(0x94, 0x04);
edodm85 2:354a00023f79 262 WriteReg(0x95, 0x08);
edodm85 2:354a00023f79 263
edodm85 2:354a00023f79 264 WriteReg(0x6c, 0x0a);
edodm85 2:354a00023f79 265 WriteReg(0x6d, 0x55);
edodm85 2:354a00023f79 266 WriteReg(0x6e, 0x11);
edodm85 2:354a00023f79 267 WriteReg(0x6f, 0x9f);
edodm85 2:354a00023f79 268 WriteReg(0x6a, 0x40);
edodm85 2:354a00023f79 269 WriteReg(0x01, 0x40);
edodm85 2:354a00023f79 270 WriteReg(0x02, 0x40);
edodm85 2:354a00023f79 271 WriteReg(0x13, 0xe7);
edodm85 3:b40a945dd672 272 //WriteReg(0x15, 0x02);
edodm85 2:354a00023f79 273
edodm85 2:354a00023f79 274 WriteReg(0x4f, 0x80);
edodm85 2:354a00023f79 275 WriteReg(0x50, 0x80);
edodm85 2:354a00023f79 276 WriteReg(0x51, 0x00);
edodm85 2:354a00023f79 277 WriteReg(0x52, 0x22);
edodm85 2:354a00023f79 278 WriteReg(0x53, 0x5e);
edodm85 2:354a00023f79 279 WriteReg(0x54, 0x80);
edodm85 2:354a00023f79 280 WriteReg(0x58, 0x9e);
edodm85 2:354a00023f79 281
edodm85 2:354a00023f79 282 WriteReg(0x41, 0x08);
edodm85 2:354a00023f79 283 WriteReg(0x3f, 0x00);
edodm85 2:354a00023f79 284 WriteReg(0x75, 0x05);
edodm85 2:354a00023f79 285 WriteReg(0x76, 0xe1);
edodm85 2:354a00023f79 286 WriteReg(0x4c, 0x00);
edodm85 2:354a00023f79 287 WriteReg(0x77, 0x01);
edodm85 2:354a00023f79 288 WriteReg(0x3d, 0xc1);
edodm85 2:354a00023f79 289 WriteReg(0x4b, 0x09);
edodm85 2:354a00023f79 290 WriteReg(0xc9, 0x60);
edodm85 2:354a00023f79 291 WriteReg(0x41, 0x38);
edodm85 2:354a00023f79 292 WriteReg(0x56, 0x40);
edodm85 2:354a00023f79 293
edodm85 2:354a00023f79 294 WriteReg(0x34, 0x11);
edodm85 2:354a00023f79 295 WriteReg(0x3b, 0x02);
edodm85 2:354a00023f79 296 WriteReg(0xa4, 0x88);
edodm85 2:354a00023f79 297 WriteReg(0x96, 0x00);
edodm85 2:354a00023f79 298 WriteReg(0x97, 0x30);
edodm85 2:354a00023f79 299 WriteReg(0x98, 0x20);
edodm85 2:354a00023f79 300 WriteReg(0x99, 0x30);
edodm85 2:354a00023f79 301 WriteReg(0x9a, 0x84);
edodm85 2:354a00023f79 302 WriteReg(0x9b, 0x29);
edodm85 2:354a00023f79 303 WriteReg(0x9c, 0x03);
edodm85 2:354a00023f79 304 WriteReg(0x9d, 0x4c);
edodm85 2:354a00023f79 305 WriteReg(0x9e, 0x3f);
edodm85 2:354a00023f79 306 WriteReg(0x78, 0x04);
edodm85 2:354a00023f79 307
edodm85 2:354a00023f79 308 WriteReg(0x79, 0x01);
edodm85 2:354a00023f79 309 WriteReg(0xc8, 0xf0);
edodm85 2:354a00023f79 310 WriteReg(0x79, 0x0f);
edodm85 2:354a00023f79 311 WriteReg(0xc8, 0x00);
edodm85 2:354a00023f79 312 WriteReg(0x79, 0x10);
edodm85 2:354a00023f79 313 WriteReg(0xc8, 0x7e);
edodm85 2:354a00023f79 314 WriteReg(0x79, 0x0a);
edodm85 2:354a00023f79 315 WriteReg(0xc8, 0x80);
edodm85 2:354a00023f79 316 WriteReg(0x79, 0x0b);
edodm85 2:354a00023f79 317 WriteReg(0xc8, 0x01);
edodm85 2:354a00023f79 318 WriteReg(0x79, 0x0c);
edodm85 2:354a00023f79 319 WriteReg(0xc8, 0x0f);
edodm85 2:354a00023f79 320 WriteReg(0x79, 0x0d);
edodm85 2:354a00023f79 321 WriteReg(0xc8, 0x20);
edodm85 2:354a00023f79 322 WriteReg(0x79, 0x09);
edodm85 2:354a00023f79 323 WriteReg(0xc8, 0x80);
edodm85 2:354a00023f79 324 WriteReg(0x79, 0x02);
edodm85 2:354a00023f79 325 WriteReg(0xc8, 0xc0);
edodm85 2:354a00023f79 326 WriteReg(0x79, 0x03);
edodm85 2:354a00023f79 327 WriteReg(0xc8, 0x40);
edodm85 2:354a00023f79 328 WriteReg(0x79, 0x05);
edodm85 2:354a00023f79 329 WriteReg(0xc8, 0x30);
edodm85 2:354a00023f79 330 WriteReg(0x79, 0x26);
edodm85 2:354a00023f79 331 WriteReg(0x09, 0x03);
edodm85 2:354a00023f79 332 WriteReg(0x3b, 0x42);
edodm85 2:354a00023f79 333
edodm85 2:354a00023f79 334 WriteReg(0xff, 0xff); /* END MARKER */
edodm85 2:354a00023f79 335
edodm85 1:d82dbad9c06b 336 }
edodm85 1:d82dbad9c06b 337 if(n == 76800) // 320*240
edodm85 1:d82dbad9c06b 338 {
edodm85 1:d82dbad9c06b 339 WriteReg(REG_COM14, 0x19);
edodm85 1:d82dbad9c06b 340 WriteReg(0x72, 0x11);
edodm85 1:d82dbad9c06b 341 WriteReg(0x73, 0xf1);
edodm85 2:354a00023f79 342 WriteReg(REG_HREF, 0x24);
edodm85 2:354a00023f79 343 WriteReg(REG_HSTART, 0x16);
edodm85 2:354a00023f79 344 WriteReg(REG_HSTOP, 0x04);
edodm85 2:354a00023f79 345 WriteReg(REG_VREF, 0x0a);
edodm85 1:d82dbad9c06b 346 WriteReg(REG_VSTART,0x02);
edodm85 2:354a00023f79 347 WriteReg(REG_VSTOP, 0x7a);
edodm85 2:354a00023f79 348
edodm85 2:354a00023f79 349 WriteReg(0x7a, 0x20);
edodm85 2:354a00023f79 350 WriteReg(0x7b, 0x1c);
edodm85 2:354a00023f79 351 WriteReg(0x7c, 0x28);
edodm85 2:354a00023f79 352 WriteReg(0x7d, 0x3c);
edodm85 2:354a00023f79 353 WriteReg(0x7e, 0x55);
edodm85 2:354a00023f79 354 WriteReg(0x7f, 0x68);
edodm85 2:354a00023f79 355 WriteReg(0x80, 0x76);
edodm85 2:354a00023f79 356 WriteReg(0x81, 0x80);
edodm85 2:354a00023f79 357 WriteReg(0x82, 0x88);
edodm85 2:354a00023f79 358 WriteReg(0x83, 0x8f);
edodm85 2:354a00023f79 359 WriteReg(0x84, 0x96);
edodm85 2:354a00023f79 360 WriteReg(0x85, 0xa3);
edodm85 2:354a00023f79 361 WriteReg(0x86, 0xaf);
edodm85 2:354a00023f79 362 WriteReg(0x87, 0xc4);
edodm85 2:354a00023f79 363 WriteReg(0x88, 0xd7);
edodm85 2:354a00023f79 364 WriteReg(0x89, 0xe8);
edodm85 2:354a00023f79 365
edodm85 2:354a00023f79 366 WriteReg(0x13, 0xe0);
edodm85 2:354a00023f79 367 WriteReg(0x00, 0x00);
edodm85 2:354a00023f79 368 WriteReg(0x10, 0x00);
edodm85 2:354a00023f79 369 WriteReg(0x0d, 0x00);
edodm85 2:354a00023f79 370 WriteReg(0x14, 0x28);
edodm85 2:354a00023f79 371 WriteReg(0xa5, 0x05);
edodm85 2:354a00023f79 372 WriteReg(0xab, 0x07);
edodm85 2:354a00023f79 373 WriteReg(0x24, 0x75);
edodm85 2:354a00023f79 374 WriteReg(0x25, 0x63);
edodm85 2:354a00023f79 375 WriteReg(0x26, 0xA5);
edodm85 2:354a00023f79 376 WriteReg(0x9f, 0x78);
edodm85 2:354a00023f79 377 WriteReg(0xa0, 0x68);
edodm85 2:354a00023f79 378 WriteReg(0xa1, 0x03);
edodm85 2:354a00023f79 379 WriteReg(0xa6, 0xdf);
edodm85 2:354a00023f79 380 WriteReg(0xa7, 0xdf);
edodm85 2:354a00023f79 381 WriteReg(0xa8, 0xf0);
edodm85 2:354a00023f79 382 WriteReg(0xa9, 0x90);
edodm85 2:354a00023f79 383 WriteReg(0xaa, 0x94);
edodm85 2:354a00023f79 384 WriteReg(0x13, 0xe5);
edodm85 2:354a00023f79 385
edodm85 2:354a00023f79 386 WriteReg(0x0e, 0x61);
edodm85 2:354a00023f79 387 WriteReg(0x0f, 0x4b);
edodm85 2:354a00023f79 388 WriteReg(0x16, 0x02);
edodm85 2:354a00023f79 389 WriteReg(0x21, 0x02);
edodm85 2:354a00023f79 390 WriteReg(0x22, 0x91);
edodm85 2:354a00023f79 391 WriteReg(0x29, 0x07);
edodm85 2:354a00023f79 392 WriteReg(0x33, 0x0b);
edodm85 2:354a00023f79 393 WriteReg(0x35, 0x0b);
edodm85 2:354a00023f79 394 WriteReg(0x37, 0x1d);
edodm85 2:354a00023f79 395 WriteReg(0x38, 0x71);
edodm85 2:354a00023f79 396 WriteReg(0x39, 0x2a);
edodm85 2:354a00023f79 397 WriteReg(0x3c, 0x78);
edodm85 2:354a00023f79 398 WriteReg(0x4d, 0x40);
edodm85 2:354a00023f79 399 WriteReg(0x4e, 0x20);
edodm85 2:354a00023f79 400 WriteReg(0x69, 0x00);
edodm85 2:354a00023f79 401 WriteReg(0x6b, 0x00);
edodm85 2:354a00023f79 402 WriteReg(0x74, 0x19);
edodm85 2:354a00023f79 403 WriteReg(0x8d, 0x4f);
edodm85 2:354a00023f79 404 WriteReg(0x8e, 0x00);
edodm85 2:354a00023f79 405 WriteReg(0x8f, 0x00);
edodm85 2:354a00023f79 406 WriteReg(0x90, 0x00);
edodm85 2:354a00023f79 407 WriteReg(0x91, 0x00);
edodm85 2:354a00023f79 408 WriteReg(0x92, 0x00);
edodm85 2:354a00023f79 409 WriteReg(0x96, 0x00);
edodm85 2:354a00023f79 410 WriteReg(0x9a, 0x80);
edodm85 2:354a00023f79 411 WriteReg(0xb0, 0x84);
edodm85 2:354a00023f79 412 WriteReg(0xb1, 0x0c);
edodm85 2:354a00023f79 413 WriteReg(0xb2, 0x0e);
edodm85 2:354a00023f79 414 WriteReg(0xb3, 0x82);
edodm85 2:354a00023f79 415 WriteReg(0xb8, 0x0a);
edodm85 2:354a00023f79 416 WriteReg(0x43, 0x14);
edodm85 2:354a00023f79 417 WriteReg(0x44, 0xf0);
edodm85 2:354a00023f79 418 WriteReg(0x45, 0x34);
edodm85 2:354a00023f79 419 WriteReg(0x46, 0x58);
edodm85 2:354a00023f79 420 WriteReg(0x47, 0x28);
edodm85 2:354a00023f79 421 WriteReg(0x48, 0x3a);
edodm85 2:354a00023f79 422 WriteReg(0x59, 0x88);
edodm85 2:354a00023f79 423 WriteReg(0x5a, 0x88);
edodm85 2:354a00023f79 424 WriteReg(0x5b, 0x44);
edodm85 2:354a00023f79 425 WriteReg(0x5c, 0x67);
edodm85 2:354a00023f79 426 WriteReg(0x5d, 0x49);
edodm85 2:354a00023f79 427 WriteReg(0x5e, 0x0e);
edodm85 2:354a00023f79 428 WriteReg(0x64, 0x04);
edodm85 2:354a00023f79 429 WriteReg(0x65, 0x20);
edodm85 2:354a00023f79 430 WriteReg(0x66, 0x05);
edodm85 2:354a00023f79 431 WriteReg(0x94, 0x04);
edodm85 2:354a00023f79 432 WriteReg(0x95, 0x08);
edodm85 2:354a00023f79 433 WriteReg(0x6c, 0x0a);
edodm85 2:354a00023f79 434 WriteReg(0x6d, 0x55);
edodm85 2:354a00023f79 435 WriteReg(0x6e, 0x11);
edodm85 2:354a00023f79 436 WriteReg(0x6f, 0x9f);
edodm85 2:354a00023f79 437 WriteReg(0x6a, 0x40);
edodm85 2:354a00023f79 438 WriteReg(0x01, 0x40);
edodm85 2:354a00023f79 439 WriteReg(0x02, 0x40);
edodm85 2:354a00023f79 440 WriteReg(0x13, 0xe7);
edodm85 3:b40a945dd672 441 //WriteReg(0x15, 0x02);
edodm85 2:354a00023f79 442 WriteReg(0x4f, 0x80);
edodm85 2:354a00023f79 443 WriteReg(0x50, 0x80);
edodm85 2:354a00023f79 444 WriteReg(0x51, 0x00);
edodm85 2:354a00023f79 445 WriteReg(0x52, 0x22);
edodm85 2:354a00023f79 446 WriteReg(0x53, 0x5e);
edodm85 2:354a00023f79 447 WriteReg(0x54, 0x80);
edodm85 2:354a00023f79 448 WriteReg(0x58, 0x9e);
edodm85 2:354a00023f79 449 WriteReg(0x41, 0x08);
edodm85 2:354a00023f79 450 WriteReg(0x3f, 0x00);
edodm85 2:354a00023f79 451 WriteReg(0x75, 0x05);
edodm85 2:354a00023f79 452 WriteReg(0x76, 0xe1);
edodm85 2:354a00023f79 453 WriteReg(0x4c, 0x00);
edodm85 2:354a00023f79 454 WriteReg(0x77, 0x01);
edodm85 2:354a00023f79 455 WriteReg(0x3d, 0xc2);
edodm85 2:354a00023f79 456 WriteReg(0x4b, 0x09);
edodm85 2:354a00023f79 457 WriteReg(0xc9, 0x60);
edodm85 2:354a00023f79 458 WriteReg(0x41, 0x38);
edodm85 2:354a00023f79 459 WriteReg(0x56, 0x40);
edodm85 2:354a00023f79 460 WriteReg(0x34, 0x11);
edodm85 2:354a00023f79 461 WriteReg(0x3b, 0x02);
edodm85 2:354a00023f79 462 WriteReg(0xa4, 0x89);
edodm85 2:354a00023f79 463 WriteReg(0x96, 0x00);
edodm85 2:354a00023f79 464 WriteReg(0x97, 0x30);
edodm85 2:354a00023f79 465 WriteReg(0x98, 0x20);
edodm85 2:354a00023f79 466 WriteReg(0x99, 0x30);
edodm85 2:354a00023f79 467 WriteReg(0x9a, 0x84);
edodm85 2:354a00023f79 468 WriteReg(0x9b, 0x29);
edodm85 2:354a00023f79 469 WriteReg(0x9c, 0x03);
edodm85 2:354a00023f79 470 WriteReg(0x9d, 0x4c);
edodm85 2:354a00023f79 471 WriteReg(0x9e, 0x3f);
edodm85 2:354a00023f79 472 WriteReg(0x78, 0x04);
edodm85 2:354a00023f79 473 WriteReg(0x79, 0x01);
edodm85 2:354a00023f79 474 WriteReg(0xc8, 0xf0);
edodm85 2:354a00023f79 475 WriteReg(0x79, 0x0f);
edodm85 2:354a00023f79 476 WriteReg(0xc8, 0x00);
edodm85 2:354a00023f79 477 WriteReg(0x79, 0x10);
edodm85 2:354a00023f79 478 WriteReg(0xc8, 0x7e);
edodm85 2:354a00023f79 479 WriteReg(0x79, 0x0a);
edodm85 2:354a00023f79 480 WriteReg(0xc8, 0x80);
edodm85 2:354a00023f79 481 WriteReg(0x79, 0x0b);
edodm85 2:354a00023f79 482 WriteReg(0xc8, 0x01);
edodm85 2:354a00023f79 483 WriteReg(0x79, 0x0c);
edodm85 2:354a00023f79 484 WriteReg(0xc8, 0x0f);
edodm85 2:354a00023f79 485 WriteReg(0x79, 0x0d);
edodm85 2:354a00023f79 486 WriteReg(0xc8, 0x20);
edodm85 2:354a00023f79 487 WriteReg(0x79, 0x09);
edodm85 2:354a00023f79 488 WriteReg(0xc8, 0x80);
edodm85 2:354a00023f79 489 WriteReg(0x79, 0x02);
edodm85 2:354a00023f79 490 WriteReg(0xc8, 0xc0);
edodm85 2:354a00023f79 491 WriteReg(0x79, 0x03);
edodm85 2:354a00023f79 492 WriteReg(0xc8, 0x40);
edodm85 2:354a00023f79 493 WriteReg(0x79, 0x05);
edodm85 2:354a00023f79 494 WriteReg(0xc8, 0x30);
edodm85 2:354a00023f79 495 WriteReg(0x79, 0x26);
edodm85 2:354a00023f79 496 WriteReg(0x09, 0x03);
edodm85 2:354a00023f79 497 WriteReg(0x3b, 0x42);
edodm85 2:354a00023f79 498
edodm85 2:354a00023f79 499 WriteReg(0xff, 0xff); /* END MARKER */
edodm85 2:354a00023f79 500
edodm85 1:d82dbad9c06b 501 }
edodm85 1:d82dbad9c06b 502 if(n == 307200) // 640*480
edodm85 1:d82dbad9c06b 503 {
edodm85 2:354a00023f79 504 WriteReg(REG_CLKRC, 0x01);
edodm85 2:354a00023f79 505 WriteReg(REG_TSLB, 0x04);
edodm85 2:354a00023f79 506 WriteReg(REG_COM7, 0x01);
edodm85 2:354a00023f79 507 WriteReg(DBLV, 0x4a);
edodm85 2:354a00023f79 508 WriteReg(REG_COM3, 0);
edodm85 2:354a00023f79 509 WriteReg(REG_COM14, 0);
edodm85 2:354a00023f79 510
edodm85 2:354a00023f79 511 WriteReg(REG_HSTART, 0x13);
edodm85 2:354a00023f79 512 WriteReg(REG_HSTOP, 0x01);
edodm85 2:354a00023f79 513 WriteReg(REG_HREF, 0xb6);
edodm85 2:354a00023f79 514 WriteReg(REG_VSTART, 0x02);
edodm85 2:354a00023f79 515 WriteReg(REG_VSTOP, 0x7a);
edodm85 2:354a00023f79 516 WriteReg(REG_VREF, 0x0a);
edodm85 2:354a00023f79 517 WriteReg(0x72, 0x11);
edodm85 2:354a00023f79 518 WriteReg(0x73, 0xf0);
edodm85 2:354a00023f79 519
edodm85 2:354a00023f79 520 /* Gamma curve values */
edodm85 2:354a00023f79 521 WriteReg(0x7a, 0x20);
edodm85 2:354a00023f79 522 WriteReg(0x7b, 0x10);
edodm85 2:354a00023f79 523 WriteReg(0x7c, 0x1e);
edodm85 2:354a00023f79 524 WriteReg(0x7d, 0x35);
edodm85 2:354a00023f79 525 WriteReg(0x7e, 0x5a);
edodm85 2:354a00023f79 526 WriteReg(0x7f, 0x69);
edodm85 2:354a00023f79 527 WriteReg(0x80, 0x76);
edodm85 2:354a00023f79 528 WriteReg(0x81, 0x80);
edodm85 2:354a00023f79 529 WriteReg(0x82, 0x88);
edodm85 2:354a00023f79 530 WriteReg(0x83, 0x8f);
edodm85 2:354a00023f79 531 WriteReg(0x84, 0x96);
edodm85 2:354a00023f79 532 WriteReg(0x85, 0xa3);
edodm85 2:354a00023f79 533 WriteReg(0x86, 0xaf);
edodm85 2:354a00023f79 534 WriteReg(0x87, 0xc4);
edodm85 2:354a00023f79 535 WriteReg(0x88, 0xd7);
edodm85 2:354a00023f79 536 WriteReg(0x89, 0xe8);
edodm85 2:354a00023f79 537
edodm85 2:354a00023f79 538 /* AGC and AEC parameters. Note we start by disabling those features,
edodm85 2:354a00023f79 539 then turn them only after tweaking the values. */
edodm85 2:354a00023f79 540 WriteReg(0x13, COM8_FASTAEC | COM8_AECSTEP | COM8_BFILT);
edodm85 2:354a00023f79 541 WriteReg(0x00, 0);
edodm85 2:354a00023f79 542 WriteReg(0x10, 0);
edodm85 2:354a00023f79 543 WriteReg(0x0d, 0x40);
edodm85 2:354a00023f79 544 WriteReg(0x14, 0x18);
edodm85 2:354a00023f79 545 WriteReg(0xa5, 0x05);
edodm85 2:354a00023f79 546 WriteReg(0xab, 0x07);
edodm85 2:354a00023f79 547 WriteReg(0x24, 0x95);
edodm85 2:354a00023f79 548 WriteReg(0x25, 0x33);
edodm85 2:354a00023f79 549 WriteReg(0x26, 0xe3);
edodm85 2:354a00023f79 550 WriteReg(0x9f, 0x78);
edodm85 2:354a00023f79 551 WriteReg(0xa0, 0x68);
edodm85 2:354a00023f79 552 WriteReg(0xa1, 0x03);
edodm85 2:354a00023f79 553 WriteReg(0xa6, 0xd8);
edodm85 2:354a00023f79 554 WriteReg(0xa7, 0xd8);
edodm85 2:354a00023f79 555 WriteReg(0xa8, 0xf0);
edodm85 2:354a00023f79 556 WriteReg(0xa9, 0x90);
edodm85 2:354a00023f79 557 WriteReg(0xaa, 0x94);
edodm85 2:354a00023f79 558 WriteReg(0x13, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC);
edodm85 2:354a00023f79 559
edodm85 2:354a00023f79 560 /* Almost all of these are magic "reserved" values. */
edodm85 2:354a00023f79 561 WriteReg(0x0e, 0x61);
edodm85 2:354a00023f79 562 WriteReg(0x0f, 0x4b);
edodm85 2:354a00023f79 563 WriteReg(0x16, 0x02);
edodm85 2:354a00023f79 564 WriteReg(0x1e, 0x27);
edodm85 2:354a00023f79 565 WriteReg(0x21, 0x02);
edodm85 2:354a00023f79 566 WriteReg(0x22, 0x91);
edodm85 2:354a00023f79 567 WriteReg(0x29, 0x07);
edodm85 2:354a00023f79 568 WriteReg(0x33, 0x0b);
edodm85 2:354a00023f79 569 WriteReg(0x35, 0x0b);
edodm85 2:354a00023f79 570 WriteReg(0x37, 0x1d);
edodm85 2:354a00023f79 571 WriteReg(0x38, 0x71);
edodm85 2:354a00023f79 572 WriteReg(0x39, 0x2a);
edodm85 2:354a00023f79 573 WriteReg(0x3c, 0x78);
edodm85 2:354a00023f79 574 WriteReg(0x4d, 0x40);
edodm85 2:354a00023f79 575 WriteReg(0x4e, 0x20);
edodm85 2:354a00023f79 576 WriteReg(0x69, 0);
edodm85 2:354a00023f79 577 WriteReg(0x6b, 0x0a);
edodm85 2:354a00023f79 578 WriteReg(0x74, 0x10);
edodm85 2:354a00023f79 579 WriteReg(0x8d, 0x4f);
edodm85 2:354a00023f79 580 WriteReg(0x8e, 0);
edodm85 2:354a00023f79 581 WriteReg(0x8f, 0);
edodm85 2:354a00023f79 582 WriteReg(0x90, 0);
edodm85 2:354a00023f79 583 WriteReg(0x91, 0);
edodm85 2:354a00023f79 584 WriteReg(0x96, 0);
edodm85 2:354a00023f79 585 WriteReg(0x9a, 0);
edodm85 2:354a00023f79 586 WriteReg(0xb0, 0x84);
edodm85 2:354a00023f79 587 WriteReg(0xb1, 0x0c);
edodm85 2:354a00023f79 588 WriteReg(0xb2, 0x0e);
edodm85 2:354a00023f79 589 WriteReg(0xb3, 0x82);
edodm85 2:354a00023f79 590 WriteReg(0xb8, 0x0a);
edodm85 2:354a00023f79 591
edodm85 2:354a00023f79 592 /* More reserved magic, some of which tweaks white balance */
edodm85 2:354a00023f79 593 WriteReg(0x43, 0x0a);
edodm85 2:354a00023f79 594 WriteReg(0x44, 0xf0);
edodm85 2:354a00023f79 595 WriteReg(0x45, 0x34);
edodm85 2:354a00023f79 596 WriteReg(0x46, 0x58);
edodm85 2:354a00023f79 597 WriteReg(0x47, 0x28);
edodm85 2:354a00023f79 598 WriteReg(0x48, 0x3a);
edodm85 2:354a00023f79 599 WriteReg(0x59, 0x88);
edodm85 2:354a00023f79 600 WriteReg(0x5a, 0x88);
edodm85 2:354a00023f79 601 WriteReg(0x5b, 0x44);
edodm85 2:354a00023f79 602 WriteReg(0x5c, 0x67);
edodm85 2:354a00023f79 603 WriteReg(0x5d, 0x49);
edodm85 2:354a00023f79 604 WriteReg(0x5e, 0x0e);
edodm85 2:354a00023f79 605 WriteReg(0x6c, 0x0a);
edodm85 2:354a00023f79 606 WriteReg(0x6d, 0x55);
edodm85 2:354a00023f79 607 WriteReg(0x6e, 0x11);
edodm85 2:354a00023f79 608 WriteReg(0x6f, 0x9f);
edodm85 2:354a00023f79 609 WriteReg(0x6a, 0x40);
edodm85 2:354a00023f79 610 WriteReg(0x01, 0x40);
edodm85 2:354a00023f79 611 WriteReg(0x02, 0x60);
edodm85 2:354a00023f79 612 WriteReg(0x13, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC|COM8_AWB);
edodm85 2:354a00023f79 613
edodm85 2:354a00023f79 614 /* Matrix coefficients */
edodm85 2:354a00023f79 615 WriteReg(0x4f, 0x80);
edodm85 2:354a00023f79 616 WriteReg(0x50, 0x80);
edodm85 2:354a00023f79 617 WriteReg(0x51, 0);
edodm85 2:354a00023f79 618 WriteReg(0x52, 0x22);
edodm85 2:354a00023f79 619 WriteReg(0x53, 0x5e);
edodm85 2:354a00023f79 620 WriteReg(0x54, 0x80);
edodm85 2:354a00023f79 621 WriteReg(0x58, 0x9e);
edodm85 2:354a00023f79 622
edodm85 2:354a00023f79 623 WriteReg(0x41, 0x08);
edodm85 2:354a00023f79 624 WriteReg(0x3f, 0);
edodm85 2:354a00023f79 625 WriteReg(0x75, 0x05);
edodm85 2:354a00023f79 626 WriteReg(0x76, 0xe1);
edodm85 2:354a00023f79 627 WriteReg(0x4c, 0);
edodm85 2:354a00023f79 628 WriteReg(0x77, 0x01);
edodm85 2:354a00023f79 629 WriteReg(0x3d, 0xc3);
edodm85 2:354a00023f79 630 WriteReg(0x4b, 0x09);
edodm85 2:354a00023f79 631 WriteReg(0xc9, 0x60);
edodm85 2:354a00023f79 632 WriteReg(0x41, 0x38);
edodm85 2:354a00023f79 633 WriteReg(0x56, 0x40);
edodm85 2:354a00023f79 634
edodm85 2:354a00023f79 635 WriteReg(0x34, 0x11);
edodm85 2:354a00023f79 636 WriteReg(0x3b, COM11_EXP|COM11_HZAUTO);
edodm85 2:354a00023f79 637 WriteReg(0xa4, 0x88);
edodm85 2:354a00023f79 638 WriteReg(0x96, 0);
edodm85 2:354a00023f79 639 WriteReg(0x97, 0x30);
edodm85 2:354a00023f79 640 WriteReg(0x98, 0x20);
edodm85 2:354a00023f79 641 WriteReg(0x99, 0x30);
edodm85 2:354a00023f79 642 WriteReg(0x9a, 0x84);
edodm85 2:354a00023f79 643 WriteReg(0x9b, 0x29);
edodm85 2:354a00023f79 644 WriteReg(0x9c, 0x03);
edodm85 2:354a00023f79 645 WriteReg(0x9d, 0x4c);
edodm85 2:354a00023f79 646 WriteReg(0x9e, 0x3f);
edodm85 2:354a00023f79 647 WriteReg(0x78, 0x04);
edodm85 2:354a00023f79 648
edodm85 2:354a00023f79 649 /* Extra-weird stuff. Some sort of multiplexor register */
edodm85 2:354a00023f79 650 WriteReg(0x79, 0x01);
edodm85 2:354a00023f79 651 WriteReg(0xc8, 0xf0);
edodm85 2:354a00023f79 652 WriteReg(0x79, 0x0f);
edodm85 2:354a00023f79 653 WriteReg(0xc8, 0x00);
edodm85 2:354a00023f79 654 WriteReg(0x79, 0x10);
edodm85 2:354a00023f79 655 WriteReg(0xc8, 0x7e);
edodm85 2:354a00023f79 656 WriteReg(0x79, 0x0a);
edodm85 2:354a00023f79 657 WriteReg(0xc8, 0x80);
edodm85 2:354a00023f79 658 WriteReg(0x79, 0x0b);
edodm85 2:354a00023f79 659 WriteReg(0xc8, 0x01);
edodm85 2:354a00023f79 660 WriteReg(0x79, 0x0c);
edodm85 2:354a00023f79 661 WriteReg(0xc8, 0x0f);
edodm85 2:354a00023f79 662 WriteReg(0x79, 0x0d);
edodm85 2:354a00023f79 663 WriteReg(0xc8, 0x20);
edodm85 2:354a00023f79 664 WriteReg(0x79, 0x09);
edodm85 2:354a00023f79 665 WriteReg(0xc8, 0x80);
edodm85 2:354a00023f79 666 WriteReg(0x79, 0x02);
edodm85 2:354a00023f79 667 WriteReg(0xc8, 0xc0);
edodm85 2:354a00023f79 668 WriteReg(0x79, 0x03);
edodm85 2:354a00023f79 669 WriteReg(0xc8, 0x40);
edodm85 2:354a00023f79 670 WriteReg(0x79, 0x05);
edodm85 2:354a00023f79 671 WriteReg(0xc8, 0x30);
edodm85 2:354a00023f79 672 WriteReg(0x79, 0x26);
edodm85 2:354a00023f79 673
edodm85 2:354a00023f79 674 WriteReg(0xff, 0xff); /* END MARKER */
edodm85 1:d82dbad9c06b 675 }
edodm85 1:d82dbad9c06b 676
edodm85 0:810d59d0b843 677 return 1;
edodm85 0:810d59d0b843 678 }
edodm85 0:810d59d0b843 679
edodm85 3:b40a945dd672 680
edodm85 3:b40a945dd672 681
edodm85 3:b40a945dd672 682
edodm85 3:b40a945dd672 683 // write to camera
edodm85 3:b40a945dd672 684 void OV7670::WriteReg(int addr,int data)
edodm85 0:810d59d0b843 685 {
edodm85 3:b40a945dd672 686 _i2c.start();
edodm85 3:b40a945dd672 687 _i2c.write(OV7670_WRITE);
edodm85 3:b40a945dd672 688 wait_us(OV7670_WRITEWAIT);
edodm85 3:b40a945dd672 689 _i2c.write(addr);
edodm85 3:b40a945dd672 690 wait_us(OV7670_WRITEWAIT);
edodm85 3:b40a945dd672 691 _i2c.write(data);
edodm85 3:b40a945dd672 692 _i2c.stop();
edodm85 0:810d59d0b843 693 }
edodm85 0:810d59d0b843 694
edodm85 3:b40a945dd672 695 // read from camera
edodm85 3:b40a945dd672 696 int OV7670::ReadReg(int addr)
edodm85 0:810d59d0b843 697 {
edodm85 3:b40a945dd672 698 int data;
edodm85 3:b40a945dd672 699
edodm85 3:b40a945dd672 700 _i2c.start();
edodm85 3:b40a945dd672 701 _i2c.write(OV7670_WRITE);
edodm85 3:b40a945dd672 702 wait_us(OV7670_WRITEWAIT);
edodm85 3:b40a945dd672 703 _i2c.write(addr);
edodm85 3:b40a945dd672 704 _i2c.stop();
edodm85 3:b40a945dd672 705 wait_us(OV7670_WRITEWAIT);
edodm85 0:810d59d0b843 706
edodm85 3:b40a945dd672 707 _i2c.start();
edodm85 3:b40a945dd672 708 _i2c.write(OV7670_READ);
edodm85 3:b40a945dd672 709 wait_us(OV7670_WRITEWAIT);
edodm85 3:b40a945dd672 710 data = _i2c.read(OV7670_NOACK);
edodm85 3:b40a945dd672 711 _i2c.stop();
edodm85 0:810d59d0b843 712
edodm85 3:b40a945dd672 713 return data;
edodm85 0:810d59d0b843 714 }