OV7670 Library

Dependents:   OV7670_make

Committer:
edodm85
Date:
Sat Feb 15 15:00:37 2014 +0000
Revision:
3:b40a945dd672
Parent:
2:354a00023f79
Child:
4:119b4c04a4ed
Removed href

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