OV7670 Library

Dependents:   OV7670_make

Committer:
kangmingyo
Date:
Wed Jul 31 13:09:52 2019 +0000
Revision:
7:6c66c7f5676d
Parent:
6:8dac6edf2496
190731

Who changed what in which revision?

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