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