Battery

Dependencies:   mbed PowerControl SDFileSystem

Fork of HeptaBattery by 智也 大野

Committer:
tomoya123
Date:
Tue Dec 13 06:37:27 2016 +0000
Revision:
1:166ddf929155
Parent:
0:d53e9c6fc771
HeptaBattery

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tomoya123 0:d53e9c6fc771 1 #include "HeptaCamera.h"
tomoya123 0:d53e9c6fc771 2 #include "mbed.h"
tomoya123 0:d53e9c6fc771 3
tomoya123 0:d53e9c6fc771 4 int sizex = 0;
tomoya123 0:d53e9c6fc771 5 int sizey = 0;
tomoya123 0:d53e9c6fc771 6
tomoya123 0:d53e9c6fc771 7 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE)
tomoya123 0:d53e9c6fc771 8
tomoya123 0:d53e9c6fc771 9 #define FILEHEADERSIZE 14 //ファイルヘッダのサイズ
tomoya123 0:d53e9c6fc771 10 #define INFOHEADERSIZE 40 //情報ヘッダのサイズ
tomoya123 0:d53e9c6fc771 11 #define HEADERSIZE (FILEHEADERSIZE+INFOHEADERSIZE)
tomoya123 0:d53e9c6fc771 12
tomoya123 0:d53e9c6fc771 13 int create_header(FILE *fp, int width, int height) {
tomoya123 0:d53e9c6fc771 14 int real_width;
tomoya123 0:d53e9c6fc771 15 unsigned char header_buf[HEADERSIZE]; //ヘッダを格納する
tomoya123 0:d53e9c6fc771 16 unsigned int file_size;
tomoya123 0:d53e9c6fc771 17 unsigned int offset_to_data;
tomoya123 0:d53e9c6fc771 18 unsigned long info_header_size;
tomoya123 0:d53e9c6fc771 19 unsigned int planes;
tomoya123 0:d53e9c6fc771 20 unsigned int color;
tomoya123 0:d53e9c6fc771 21 unsigned long compress;
tomoya123 0:d53e9c6fc771 22 unsigned long data_size;
tomoya123 0:d53e9c6fc771 23 long xppm;
tomoya123 0:d53e9c6fc771 24 long yppm;
tomoya123 0:d53e9c6fc771 25
tomoya123 0:d53e9c6fc771 26 real_width = width*3 + width%4;
tomoya123 0:d53e9c6fc771 27
tomoya123 0:d53e9c6fc771 28 //ここからヘッダ作成
tomoya123 0:d53e9c6fc771 29 file_size = height * real_width + HEADERSIZE;
tomoya123 0:d53e9c6fc771 30 offset_to_data = HEADERSIZE;
tomoya123 0:d53e9c6fc771 31 info_header_size = INFOHEADERSIZE;
tomoya123 0:d53e9c6fc771 32 planes = 1;
tomoya123 0:d53e9c6fc771 33 color = 24;
tomoya123 0:d53e9c6fc771 34 compress = 0;
tomoya123 0:d53e9c6fc771 35 data_size = height * real_width;
tomoya123 0:d53e9c6fc771 36 xppm = 1;
tomoya123 0:d53e9c6fc771 37 yppm = 1;
tomoya123 0:d53e9c6fc771 38
tomoya123 0:d53e9c6fc771 39 header_buf[0] = 'B';
tomoya123 0:d53e9c6fc771 40 header_buf[1] = 'M';
tomoya123 0:d53e9c6fc771 41 memcpy(header_buf + 2, &file_size, sizeof(file_size));
tomoya123 0:d53e9c6fc771 42 header_buf[6] = 0;
tomoya123 0:d53e9c6fc771 43 header_buf[7] = 0;
tomoya123 0:d53e9c6fc771 44 header_buf[8] = 0;
tomoya123 0:d53e9c6fc771 45 header_buf[9] = 0;
tomoya123 0:d53e9c6fc771 46 memcpy(header_buf + 10, &offset_to_data, sizeof(offset_to_data));
tomoya123 0:d53e9c6fc771 47 memcpy(header_buf + 14, &info_header_size, sizeof(info_header_size));
tomoya123 0:d53e9c6fc771 48 memcpy(header_buf + 18, &width, sizeof(width));
tomoya123 0:d53e9c6fc771 49 height = height * -1; // データ格納順が逆なので、高さをマイナスとしている
tomoya123 0:d53e9c6fc771 50 memcpy(header_buf + 22, &height, sizeof(height));
tomoya123 0:d53e9c6fc771 51 memcpy(header_buf + 26, &planes, sizeof(planes));
tomoya123 0:d53e9c6fc771 52 memcpy(header_buf + 28, &color, sizeof(color));
tomoya123 0:d53e9c6fc771 53 memcpy(header_buf + 30, &compress, sizeof(compress));
tomoya123 0:d53e9c6fc771 54 memcpy(header_buf + 34, &data_size, sizeof(data_size));
tomoya123 0:d53e9c6fc771 55 memcpy(header_buf + 38, &xppm, sizeof(xppm));
tomoya123 0:d53e9c6fc771 56 memcpy(header_buf + 42, &yppm, sizeof(yppm));
tomoya123 0:d53e9c6fc771 57 header_buf[46] = 0;
tomoya123 0:d53e9c6fc771 58 header_buf[47] = 0;
tomoya123 0:d53e9c6fc771 59 header_buf[48] = 0;
tomoya123 0:d53e9c6fc771 60 header_buf[49] = 0;
tomoya123 0:d53e9c6fc771 61 header_buf[50] = 0;
tomoya123 0:d53e9c6fc771 62 header_buf[51] = 0;
tomoya123 0:d53e9c6fc771 63 header_buf[52] = 0;
tomoya123 0:d53e9c6fc771 64 header_buf[53] = 0;
tomoya123 0:d53e9c6fc771 65
tomoya123 0:d53e9c6fc771 66 //ヘッダの書き込み
tomoya123 0:d53e9c6fc771 67 fwrite(header_buf, sizeof(unsigned char), HEADERSIZE, fp);
tomoya123 0:d53e9c6fc771 68
tomoya123 0:d53e9c6fc771 69 return 0;
tomoya123 0:d53e9c6fc771 70 }
tomoya123 0:d53e9c6fc771 71 #endif
tomoya123 0:d53e9c6fc771 72
tomoya123 0:d53e9c6fc771 73 HeptaCamera::HeptaCamera(PinName sda, PinName scl, PinName vs, PinName hr,PinName we, PinName d7, PinName d6, PinName d5, PinName d4,
tomoya123 0:d53e9c6fc771 74 PinName d3, PinName d2, PinName d1, PinName d0, PinName rt, PinName o, PinName rc ) : camera(sda,scl),vsync(vs),href(hr),wen(we),data(d0,d1,d2,d3,d4,d5,d6,d7),rrst(rt),oe(o),rclk(rc)
tomoya123 0:d53e9c6fc771 75 {
tomoya123 0:d53e9c6fc771 76 camera.stop();
tomoya123 0:d53e9c6fc771 77 camera.frequency(OV7670_I2CFREQ);
tomoya123 0:d53e9c6fc771 78 vsync.fall(this,&HeptaCamera::VsyncHandler);
tomoya123 0:d53e9c6fc771 79 href.rise(this,&HeptaCamera::HrefHandler);
tomoya123 0:d53e9c6fc771 80 CaptureReq = false;
tomoya123 0:d53e9c6fc771 81 Busy = false;
tomoya123 0:d53e9c6fc771 82 Done = false;
tomoya123 0:d53e9c6fc771 83 LineCounter = 0;
tomoya123 0:d53e9c6fc771 84 rrst = 1;
tomoya123 0:d53e9c6fc771 85 oe = 1;
tomoya123 0:d53e9c6fc771 86 rclk = 1;
tomoya123 0:d53e9c6fc771 87 wen = 0;
tomoya123 0:d53e9c6fc771 88 }
tomoya123 0:d53e9c6fc771 89 // capture request
tomoya123 0:d53e9c6fc771 90 void HeptaCamera::CaptureNext(void)
tomoya123 0:d53e9c6fc771 91 {
tomoya123 0:d53e9c6fc771 92 CaptureReq = true;
tomoya123 0:d53e9c6fc771 93 Busy = true;
tomoya123 0:d53e9c6fc771 94 }
tomoya123 0:d53e9c6fc771 95
tomoya123 0:d53e9c6fc771 96 // capture done? (with clear)
tomoya123 0:d53e9c6fc771 97 bool HeptaCamera::CaptureDone(void)
tomoya123 0:d53e9c6fc771 98 {
tomoya123 0:d53e9c6fc771 99 bool result;
tomoya123 0:d53e9c6fc771 100 if (Busy) {
tomoya123 0:d53e9c6fc771 101 result = false;
tomoya123 0:d53e9c6fc771 102 } else {
tomoya123 0:d53e9c6fc771 103 result = Done;
tomoya123 0:d53e9c6fc771 104 Done = false;
tomoya123 0:d53e9c6fc771 105 }
tomoya123 0:d53e9c6fc771 106 return result;
tomoya123 0:d53e9c6fc771 107 }
tomoya123 0:d53e9c6fc771 108
tomoya123 0:d53e9c6fc771 109 // write to camera
tomoya123 0:d53e9c6fc771 110 void HeptaCamera::WriteReg(int addr,int data)
tomoya123 0:d53e9c6fc771 111 {
tomoya123 0:d53e9c6fc771 112 // WRITE 0x42,ADDR,DATA
tomoya123 0:d53e9c6fc771 113 camera.start();
tomoya123 0:d53e9c6fc771 114 camera.write(OV7670_WRITE);
tomoya123 0:d53e9c6fc771 115 wait_us(OV7670_WRITEWAIT);
tomoya123 0:d53e9c6fc771 116 camera.write(addr);
tomoya123 0:d53e9c6fc771 117 wait_us(OV7670_WRITEWAIT);
tomoya123 0:d53e9c6fc771 118 camera.write(data);
tomoya123 0:d53e9c6fc771 119 camera.stop();
tomoya123 0:d53e9c6fc771 120 }
tomoya123 0:d53e9c6fc771 121
tomoya123 0:d53e9c6fc771 122 // read from camera
tomoya123 0:d53e9c6fc771 123 int HeptaCamera::ReadReg(int addr)
tomoya123 0:d53e9c6fc771 124 {
tomoya123 0:d53e9c6fc771 125 int data;
tomoya123 0:d53e9c6fc771 126
tomoya123 0:d53e9c6fc771 127 // WRITE 0x42,ADDR
tomoya123 0:d53e9c6fc771 128 camera.start();
tomoya123 0:d53e9c6fc771 129 camera.write(OV7670_WRITE);
tomoya123 0:d53e9c6fc771 130 wait_us(OV7670_WRITEWAIT);
tomoya123 0:d53e9c6fc771 131 camera.write(addr);
tomoya123 0:d53e9c6fc771 132 camera.stop();
tomoya123 0:d53e9c6fc771 133 wait_us(OV7670_WRITEWAIT);
tomoya123 0:d53e9c6fc771 134
tomoya123 0:d53e9c6fc771 135 // WRITE 0x43,READ
tomoya123 0:d53e9c6fc771 136 camera.start();
tomoya123 0:d53e9c6fc771 137 camera.write(OV7670_READ);
tomoya123 0:d53e9c6fc771 138 wait_us(OV7670_WRITEWAIT);
tomoya123 0:d53e9c6fc771 139 data = camera.read(OV7670_NOACK);
tomoya123 0:d53e9c6fc771 140 camera.stop();
tomoya123 0:d53e9c6fc771 141
tomoya123 0:d53e9c6fc771 142 return data;
tomoya123 0:d53e9c6fc771 143 }
tomoya123 0:d53e9c6fc771 144
tomoya123 0:d53e9c6fc771 145 // print register
tomoya123 0:d53e9c6fc771 146 void HeptaCamera::PrintRegister(void) {
tomoya123 0:d53e9c6fc771 147 printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F");
tomoya123 0:d53e9c6fc771 148 for (int i=0;i<OV7670_REGMAX;i++) {
tomoya123 0:d53e9c6fc771 149 int data;
tomoya123 0:d53e9c6fc771 150 data = ReadReg(i); // READ REG
tomoya123 0:d53e9c6fc771 151 if ((i & 0x0F) == 0) {
tomoya123 0:d53e9c6fc771 152 printf("\r\n%02X : ",i);
tomoya123 0:d53e9c6fc771 153 }
tomoya123 0:d53e9c6fc771 154 printf("%02X ",data);
tomoya123 0:d53e9c6fc771 155 }
tomoya123 0:d53e9c6fc771 156 printf("\r\n");
tomoya123 0:d53e9c6fc771 157 }
tomoya123 0:d53e9c6fc771 158
tomoya123 0:d53e9c6fc771 159 void HeptaCamera::Reset(void) {
tomoya123 0:d53e9c6fc771 160 WriteReg(REG_COM7,COM7_RESET); // RESET CAMERA
tomoya123 0:d53e9c6fc771 161 wait_ms(200);
tomoya123 0:d53e9c6fc771 162 }
tomoya123 0:d53e9c6fc771 163
tomoya123 0:d53e9c6fc771 164 void HeptaCamera::InitForFIFOWriteReset(void) {
tomoya123 0:d53e9c6fc771 165 WriteReg(REG_COM10, COM10_VS_NEG);
tomoya123 0:d53e9c6fc771 166 }
tomoya123 0:d53e9c6fc771 167
tomoya123 0:d53e9c6fc771 168 void HeptaCamera::InitSetColorbar(void) {
tomoya123 0:d53e9c6fc771 169 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 170 // color bar
tomoya123 0:d53e9c6fc771 171 WriteReg(REG_COM17, reg_com7|COM17_CBAR);
tomoya123 0:d53e9c6fc771 172 }
tomoya123 0:d53e9c6fc771 173
tomoya123 0:d53e9c6fc771 174 void HeptaCamera::InitDefaultReg(void) {
tomoya123 0:d53e9c6fc771 175 // Gamma curve values
tomoya123 0:d53e9c6fc771 176 WriteReg(0x7a, 0x20);
tomoya123 0:d53e9c6fc771 177 WriteReg(0x7b, 0x10);
tomoya123 0:d53e9c6fc771 178 WriteReg(0x7c, 0x1e);
tomoya123 0:d53e9c6fc771 179 WriteReg(0x7d, 0x35);
tomoya123 0:d53e9c6fc771 180 WriteReg(0x7e, 0x5a);
tomoya123 0:d53e9c6fc771 181 WriteReg(0x7f, 0x69);
tomoya123 0:d53e9c6fc771 182 WriteReg(0x80, 0x76);
tomoya123 0:d53e9c6fc771 183 WriteReg(0x81, 0x80);
tomoya123 0:d53e9c6fc771 184 WriteReg(0x82, 0x88);
tomoya123 0:d53e9c6fc771 185 WriteReg(0x83, 0x8f);
tomoya123 0:d53e9c6fc771 186 WriteReg(0x84, 0x96);
tomoya123 0:d53e9c6fc771 187 WriteReg(0x85, 0xa3);
tomoya123 0:d53e9c6fc771 188 WriteReg(0x86, 0xaf);
tomoya123 0:d53e9c6fc771 189 WriteReg(0x87, 0xc4);
tomoya123 0:d53e9c6fc771 190 WriteReg(0x88, 0xd7);
tomoya123 0:d53e9c6fc771 191 WriteReg(0x89, 0xe8);
tomoya123 0:d53e9c6fc771 192
tomoya123 0:d53e9c6fc771 193 // AGC and AEC parameters. Note we start by disabling those features,
tomoya123 0:d53e9c6fc771 194 //then turn them only after tweaking the values.
tomoya123 0:d53e9c6fc771 195 WriteReg(REG_COM8, COM8_FASTAEC | COM8_AECSTEP | COM8_BFILT);
tomoya123 0:d53e9c6fc771 196 WriteReg(REG_GAIN, 0);
tomoya123 0:d53e9c6fc771 197 WriteReg(REG_AECH, 0);
tomoya123 0:d53e9c6fc771 198 WriteReg(REG_COM4, 0x40);
tomoya123 0:d53e9c6fc771 199 // magic reserved bit
tomoya123 0:d53e9c6fc771 200 WriteReg(REG_COM9, 0x18);
tomoya123 0:d53e9c6fc771 201 // 4x gain + magic rsvd bit
tomoya123 0:d53e9c6fc771 202 WriteReg(REG_BD50MAX, 0x05);
tomoya123 0:d53e9c6fc771 203 WriteReg(REG_BD60MAX, 0x07);
tomoya123 0:d53e9c6fc771 204 WriteReg(REG_AEW, 0x95);
tomoya123 0:d53e9c6fc771 205 WriteReg(REG_AEB, 0x33);
tomoya123 0:d53e9c6fc771 206 WriteReg(REG_VPT, 0xe3);
tomoya123 0:d53e9c6fc771 207 WriteReg(REG_HAECC1, 0x78);
tomoya123 0:d53e9c6fc771 208 WriteReg(REG_HAECC2, 0x68);
tomoya123 0:d53e9c6fc771 209 WriteReg(0xa1, 0x03);
tomoya123 0:d53e9c6fc771 210 // magic
tomoya123 0:d53e9c6fc771 211 WriteReg(REG_HAECC3, 0xd8);
tomoya123 0:d53e9c6fc771 212 WriteReg(REG_HAECC4, 0xd8);
tomoya123 0:d53e9c6fc771 213 WriteReg(REG_HAECC5, 0xf0);
tomoya123 0:d53e9c6fc771 214 WriteReg(REG_HAECC6, 0x90);
tomoya123 0:d53e9c6fc771 215 WriteReg(REG_HAECC7, 0x94);
tomoya123 0:d53e9c6fc771 216 WriteReg(REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC);
tomoya123 0:d53e9c6fc771 217
tomoya123 0:d53e9c6fc771 218 // Almost all of these are magic "reserved" values.
tomoya123 0:d53e9c6fc771 219 WriteReg(REG_COM5, 0x61);
tomoya123 0:d53e9c6fc771 220 WriteReg(REG_COM6, 0x4b);
tomoya123 0:d53e9c6fc771 221 WriteReg(0x16, 0x02);
tomoya123 0:d53e9c6fc771 222 WriteReg(REG_MVFP, 0x07);
tomoya123 0:d53e9c6fc771 223 WriteReg(0x21, 0x02);
tomoya123 0:d53e9c6fc771 224 WriteReg(0x22, 0x91);
tomoya123 0:d53e9c6fc771 225 WriteReg(0x29, 0x07);
tomoya123 0:d53e9c6fc771 226 WriteReg(0x33, 0x0b);
tomoya123 0:d53e9c6fc771 227 WriteReg(0x35, 0x0b);
tomoya123 0:d53e9c6fc771 228 WriteReg(0x37, 0x1d);
tomoya123 0:d53e9c6fc771 229 WriteReg(0x38, 0x71);
tomoya123 0:d53e9c6fc771 230 WriteReg(0x39, 0x2a);
tomoya123 0:d53e9c6fc771 231 WriteReg(REG_COM12, 0x78);
tomoya123 0:d53e9c6fc771 232 WriteReg(0x4d, 0x40);
tomoya123 0:d53e9c6fc771 233 WriteReg(0x4e, 0x20);
tomoya123 0:d53e9c6fc771 234 WriteReg(REG_GFIX, 0);
tomoya123 0:d53e9c6fc771 235 WriteReg(0x6b, 0x0a);
tomoya123 0:d53e9c6fc771 236 WriteReg(0x74, 0x10);
tomoya123 0:d53e9c6fc771 237 WriteReg(0x8d, 0x4f);
tomoya123 0:d53e9c6fc771 238 WriteReg(0x8e, 0);
tomoya123 0:d53e9c6fc771 239 WriteReg(0x8f, 0);
tomoya123 0:d53e9c6fc771 240 WriteReg(0x90, 0);
tomoya123 0:d53e9c6fc771 241 WriteReg(0x91, 0);
tomoya123 0:d53e9c6fc771 242 WriteReg(0x96, 0);
tomoya123 0:d53e9c6fc771 243 WriteReg(0x9a, 0);
tomoya123 0:d53e9c6fc771 244 WriteReg(0xb0, 0x84);
tomoya123 0:d53e9c6fc771 245 WriteReg(0xb1, 0x0c);
tomoya123 0:d53e9c6fc771 246 WriteReg(0xb2, 0x0e);
tomoya123 0:d53e9c6fc771 247 WriteReg(0xb3, 0x82);
tomoya123 0:d53e9c6fc771 248 WriteReg(0xb8, 0x0a);
tomoya123 0:d53e9c6fc771 249
tomoya123 0:d53e9c6fc771 250 // More reserved magic, some of which tweaks white balance
tomoya123 0:d53e9c6fc771 251 WriteReg(0x43, 0x0a);
tomoya123 0:d53e9c6fc771 252 WriteReg(0x44, 0xf0);
tomoya123 0:d53e9c6fc771 253 WriteReg(0x45, 0x34);
tomoya123 0:d53e9c6fc771 254 WriteReg(0x46, 0x58);
tomoya123 0:d53e9c6fc771 255 WriteReg(0x47, 0x28);
tomoya123 0:d53e9c6fc771 256 WriteReg(0x48, 0x3a);
tomoya123 0:d53e9c6fc771 257 WriteReg(0x59, 0x88);
tomoya123 0:d53e9c6fc771 258 WriteReg(0x5a, 0x88);
tomoya123 0:d53e9c6fc771 259 WriteReg(0x5b, 0x44);
tomoya123 0:d53e9c6fc771 260 WriteReg(0x5c, 0x67);
tomoya123 0:d53e9c6fc771 261 WriteReg(0x5d, 0x49);
tomoya123 0:d53e9c6fc771 262 WriteReg(0x5e, 0x0e);
tomoya123 0:d53e9c6fc771 263 WriteReg(0x6c, 0x0a);
tomoya123 0:d53e9c6fc771 264 WriteReg(0x6d, 0x55);
tomoya123 0:d53e9c6fc771 265 WriteReg(0x6e, 0x11);
tomoya123 0:d53e9c6fc771 266 WriteReg(0x6f, 0x9f);
tomoya123 0:d53e9c6fc771 267 // "9e for advance AWB"
tomoya123 0:d53e9c6fc771 268 WriteReg(0x6a, 0x40);
tomoya123 0:d53e9c6fc771 269 WriteReg(REG_BLUE, 0x40);
tomoya123 0:d53e9c6fc771 270 WriteReg(REG_RED, 0x60);
tomoya123 0:d53e9c6fc771 271 WriteReg(REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC|COM8_AWB);
tomoya123 0:d53e9c6fc771 272
tomoya123 0:d53e9c6fc771 273 // Matrix coefficients
tomoya123 0:d53e9c6fc771 274 WriteReg(0x4f, 0x80);
tomoya123 0:d53e9c6fc771 275 WriteReg(0x50, 0x80);
tomoya123 0:d53e9c6fc771 276 WriteReg(0x51, 0);
tomoya123 0:d53e9c6fc771 277 WriteReg(0x52, 0x22);
tomoya123 0:d53e9c6fc771 278 WriteReg(0x53, 0x5e);
tomoya123 0:d53e9c6fc771 279 WriteReg(0x54, 0x80);
tomoya123 0:d53e9c6fc771 280 WriteReg(0x58, 0x9e);
tomoya123 0:d53e9c6fc771 281
tomoya123 0:d53e9c6fc771 282 WriteReg(REG_COM16, COM16_AWBGAIN);
tomoya123 0:d53e9c6fc771 283 WriteReg(REG_EDGE, 0);
tomoya123 0:d53e9c6fc771 284 WriteReg(0x75, 0x05);
tomoya123 0:d53e9c6fc771 285 WriteReg(0x76, 0xe1);
tomoya123 0:d53e9c6fc771 286 WriteReg(0x4c, 0);
tomoya123 0:d53e9c6fc771 287 WriteReg(0x77, 0x01);
tomoya123 0:d53e9c6fc771 288 WriteReg(0x4b, 0x09);
tomoya123 0:d53e9c6fc771 289 WriteReg(0xc9, 0x60);
tomoya123 0:d53e9c6fc771 290 WriteReg(REG_COM16, 0x38);
tomoya123 0:d53e9c6fc771 291 WriteReg(0x56, 0x40);
tomoya123 0:d53e9c6fc771 292
tomoya123 0:d53e9c6fc771 293 WriteReg(0x34, 0x11);
tomoya123 0:d53e9c6fc771 294 WriteReg(REG_COM11, COM11_EXP|COM11_HZAUTO_ON);
tomoya123 0:d53e9c6fc771 295 WriteReg(0xa4, 0x88);
tomoya123 0:d53e9c6fc771 296 WriteReg(0x96, 0);
tomoya123 0:d53e9c6fc771 297 WriteReg(0x97, 0x30);
tomoya123 0:d53e9c6fc771 298 WriteReg(0x98, 0x20);
tomoya123 0:d53e9c6fc771 299 WriteReg(0x99, 0x30);
tomoya123 0:d53e9c6fc771 300 WriteReg(0x9a, 0x84);
tomoya123 0:d53e9c6fc771 301 WriteReg(0x9b, 0x29);
tomoya123 0:d53e9c6fc771 302 WriteReg(0x9c, 0x03);
tomoya123 0:d53e9c6fc771 303 WriteReg(0x9d, 0x4c);
tomoya123 0:d53e9c6fc771 304 WriteReg(0x9e, 0x3f);
tomoya123 0:d53e9c6fc771 305 WriteReg(0x78, 0x04);
tomoya123 0:d53e9c6fc771 306
tomoya123 0:d53e9c6fc771 307 // Extra-weird stuff. Some sort of multiplexor register
tomoya123 0:d53e9c6fc771 308 WriteReg(0x79, 0x01);
tomoya123 0:d53e9c6fc771 309 WriteReg(0xc8, 0xf0);
tomoya123 0:d53e9c6fc771 310 WriteReg(0x79, 0x0f);
tomoya123 0:d53e9c6fc771 311 WriteReg(0xc8, 0x00);
tomoya123 0:d53e9c6fc771 312 WriteReg(0x79, 0x10);
tomoya123 0:d53e9c6fc771 313 WriteReg(0xc8, 0x7e);
tomoya123 0:d53e9c6fc771 314 WriteReg(0x79, 0x0a);
tomoya123 0:d53e9c6fc771 315 WriteReg(0xc8, 0x80);
tomoya123 0:d53e9c6fc771 316 WriteReg(0x79, 0x0b);
tomoya123 0:d53e9c6fc771 317 WriteReg(0xc8, 0x01);
tomoya123 0:d53e9c6fc771 318 WriteReg(0x79, 0x0c);
tomoya123 0:d53e9c6fc771 319 WriteReg(0xc8, 0x0f);
tomoya123 0:d53e9c6fc771 320 WriteReg(0x79, 0x0d);
tomoya123 0:d53e9c6fc771 321 WriteReg(0xc8, 0x20);
tomoya123 0:d53e9c6fc771 322 WriteReg(0x79, 0x09);
tomoya123 0:d53e9c6fc771 323 WriteReg(0xc8, 0x80);
tomoya123 0:d53e9c6fc771 324 WriteReg(0x79, 0x02);
tomoya123 0:d53e9c6fc771 325 WriteReg(0xc8, 0xc0);
tomoya123 0:d53e9c6fc771 326 WriteReg(0x79, 0x03);
tomoya123 0:d53e9c6fc771 327 WriteReg(0xc8, 0x40);
tomoya123 0:d53e9c6fc771 328 WriteReg(0x79, 0x05);
tomoya123 0:d53e9c6fc771 329 WriteReg(0xc8, 0x30);
tomoya123 0:d53e9c6fc771 330 WriteReg(0x79, 0x26);
tomoya123 0:d53e9c6fc771 331 }
tomoya123 0:d53e9c6fc771 332
tomoya123 0:d53e9c6fc771 333 void HeptaCamera::InitRGB444(void){
tomoya123 0:d53e9c6fc771 334 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 335
tomoya123 0:d53e9c6fc771 336 WriteReg(REG_COM7, reg_com7|COM7_RGB);
tomoya123 0:d53e9c6fc771 337 WriteReg(REG_RGB444, RGB444_ENABLE|RGB444_XBGR);
tomoya123 0:d53e9c6fc771 338 WriteReg(REG_COM15, COM15_R01FE|COM15_RGB444);
tomoya123 0:d53e9c6fc771 339
tomoya123 0:d53e9c6fc771 340 WriteReg(REG_COM1, 0x40); // Magic reserved bit
tomoya123 0:d53e9c6fc771 341 WriteReg(REG_COM9, 0x38); // 16x gain ceiling; 0x8 is reserved bit
tomoya123 0:d53e9c6fc771 342 WriteReg(0x4f, 0xb3); // "matrix coefficient 1"
tomoya123 0:d53e9c6fc771 343 WriteReg(0x50, 0xb3); // "matrix coefficient 2"
tomoya123 0:d53e9c6fc771 344 WriteReg(0x51, 0x00); // vb
tomoya123 0:d53e9c6fc771 345 WriteReg(0x52, 0x3d); // "matrix coefficient 4"
tomoya123 0:d53e9c6fc771 346 WriteReg(0x53, 0xa7); // "matrix coefficient 5"
tomoya123 0:d53e9c6fc771 347 WriteReg(0x54, 0xe4); // "matrix coefficient 6"
tomoya123 0:d53e9c6fc771 348 WriteReg(REG_COM13, COM13_GAMMA|COM13_UVSAT|0x2); // Magic rsvd bit
tomoya123 0:d53e9c6fc771 349
tomoya123 0:d53e9c6fc771 350 WriteReg(REG_TSLB, 0x04);
tomoya123 0:d53e9c6fc771 351 }
tomoya123 0:d53e9c6fc771 352
tomoya123 0:d53e9c6fc771 353 void HeptaCamera::InitRGB555(void){
tomoya123 0:d53e9c6fc771 354 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 355
tomoya123 0:d53e9c6fc771 356 WriteReg(REG_COM7, reg_com7|COM7_RGB);
tomoya123 0:d53e9c6fc771 357 WriteReg(REG_RGB444, RGB444_DISABLE);
tomoya123 0:d53e9c6fc771 358 WriteReg(REG_COM15, COM15_RGB555|COM15_R00FF);
tomoya123 0:d53e9c6fc771 359
tomoya123 0:d53e9c6fc771 360 WriteReg(REG_TSLB, 0x04);
tomoya123 0:d53e9c6fc771 361
tomoya123 0:d53e9c6fc771 362 WriteReg(REG_COM1, 0x00);
tomoya123 0:d53e9c6fc771 363 WriteReg(REG_COM9, 0x38); // 16x gain ceiling; 0x8 is reserved bit
tomoya123 0:d53e9c6fc771 364 WriteReg(0x4f, 0xb3); // "matrix coefficient 1"
tomoya123 0:d53e9c6fc771 365 WriteReg(0x50, 0xb3); // "matrix coefficient 2"
tomoya123 0:d53e9c6fc771 366 WriteReg(0x51, 0x00); // vb
tomoya123 0:d53e9c6fc771 367 WriteReg(0x52, 0x3d); // "matrix coefficient 4"
tomoya123 0:d53e9c6fc771 368 WriteReg(0x53, 0xa7); // "matrix coefficient 5"
tomoya123 0:d53e9c6fc771 369 WriteReg(0x54, 0xe4); // "matrix coefficient 6"
tomoya123 0:d53e9c6fc771 370 WriteReg(REG_COM13, COM13_GAMMA|COM13_UVSAT);
tomoya123 0:d53e9c6fc771 371 }
tomoya123 0:d53e9c6fc771 372
tomoya123 0:d53e9c6fc771 373 void HeptaCamera::InitRGB565(void){
tomoya123 0:d53e9c6fc771 374 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 375
tomoya123 0:d53e9c6fc771 376 WriteReg(REG_COM7, reg_com7|COM7_RGB);
tomoya123 0:d53e9c6fc771 377 WriteReg(REG_RGB444, RGB444_DISABLE);
tomoya123 0:d53e9c6fc771 378 WriteReg(REG_COM15, COM15_R00FF|COM15_RGB565);
tomoya123 0:d53e9c6fc771 379
tomoya123 0:d53e9c6fc771 380 WriteReg(REG_TSLB, 0x04);
tomoya123 0:d53e9c6fc771 381
tomoya123 0:d53e9c6fc771 382 WriteReg(REG_COM1, 0x00);
tomoya123 0:d53e9c6fc771 383 WriteReg(REG_COM9, 0x38); // 16x gain ceiling; 0x8 is reserved bit
tomoya123 0:d53e9c6fc771 384 WriteReg(0x4f, 0xb3); // "matrix coefficient 1"
tomoya123 0:d53e9c6fc771 385 WriteReg(0x50, 0xb3); // "matrix coefficient 2"
tomoya123 0:d53e9c6fc771 386 WriteReg(0x51, 0x00); // vb
tomoya123 0:d53e9c6fc771 387 WriteReg(0x52, 0x3d); // "matrix coefficient 4"
tomoya123 0:d53e9c6fc771 388 WriteReg(0x53, 0xa7); // "matrix coefficient 5"
tomoya123 0:d53e9c6fc771 389 WriteReg(0x54, 0xe4); // "matrix coefficient 6"
tomoya123 0:d53e9c6fc771 390 WriteReg(REG_COM13, COM13_GAMMA|COM13_UVSAT);
tomoya123 0:d53e9c6fc771 391 }
tomoya123 0:d53e9c6fc771 392
tomoya123 0:d53e9c6fc771 393 void HeptaCamera::InitYUV(void){
tomoya123 0:d53e9c6fc771 394 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 395
tomoya123 0:d53e9c6fc771 396 WriteReg(REG_COM7, reg_com7|COM7_YUV);
tomoya123 0:d53e9c6fc771 397 WriteReg(REG_RGB444, RGB444_DISABLE);
tomoya123 0:d53e9c6fc771 398 WriteReg(REG_COM15, COM15_R00FF);
tomoya123 0:d53e9c6fc771 399
tomoya123 0:d53e9c6fc771 400 WriteReg(REG_TSLB, 0x04);
tomoya123 0:d53e9c6fc771 401 // WriteReg(REG_TSLB, 0x14);
tomoya123 0:d53e9c6fc771 402 // WriteReg(REG_MANU, 0x00);
tomoya123 0:d53e9c6fc771 403 // WriteReg(REG_MANV, 0x00);
tomoya123 0:d53e9c6fc771 404
tomoya123 0:d53e9c6fc771 405 WriteReg(REG_COM1, 0x00);
tomoya123 0:d53e9c6fc771 406 WriteReg(REG_COM9, 0x18); // 4x gain ceiling; 0x8 is reserved bit
tomoya123 0:d53e9c6fc771 407 WriteReg(0x4f, 0x80); // "matrix coefficient 1"
tomoya123 0:d53e9c6fc771 408 WriteReg(0x50, 0x80); // "matrix coefficient 2"
tomoya123 0:d53e9c6fc771 409 WriteReg(0x51, 0x00); // vb
tomoya123 0:d53e9c6fc771 410 WriteReg(0x52, 0x22); // "matrix coefficient 4"
tomoya123 0:d53e9c6fc771 411 WriteReg(0x53, 0x5e); // "matrix coefficient 5"
tomoya123 0:d53e9c6fc771 412 WriteReg(0x54, 0x80); // "matrix coefficient 6"
tomoya123 0:d53e9c6fc771 413 WriteReg(REG_COM13, COM13_GAMMA|COM13_UVSAT|COM13_UVSWAP);
tomoya123 0:d53e9c6fc771 414 }
tomoya123 0:d53e9c6fc771 415
tomoya123 0:d53e9c6fc771 416 void HeptaCamera::InitBayerRGB(void){
tomoya123 0:d53e9c6fc771 417 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 418
tomoya123 0:d53e9c6fc771 419 // odd line BGBG... even line GRGR...
tomoya123 0:d53e9c6fc771 420 WriteReg(REG_COM7, reg_com7|COM7_BAYER);
tomoya123 0:d53e9c6fc771 421 // odd line GBGB... even line RGRG...
tomoya123 0:d53e9c6fc771 422 //WriteReg(REG_COM7, reg_com7|COM7_PBAYER);
tomoya123 0:d53e9c6fc771 423
tomoya123 0:d53e9c6fc771 424 WriteReg(REG_RGB444, RGB444_DISABLE);
tomoya123 0:d53e9c6fc771 425 WriteReg(REG_COM15, COM15_R00FF);
tomoya123 0:d53e9c6fc771 426
tomoya123 0:d53e9c6fc771 427 WriteReg(REG_COM13, 0x08); /* No gamma, magic rsvd bit */
tomoya123 0:d53e9c6fc771 428 WriteReg(REG_COM16, 0x3d); /* Edge enhancement, denoise */
tomoya123 0:d53e9c6fc771 429 WriteReg(REG_REG76, 0xe1); /* Pix correction, magic rsvd */
tomoya123 0:d53e9c6fc771 430
tomoya123 0:d53e9c6fc771 431 WriteReg(REG_TSLB, 0x04);
tomoya123 0:d53e9c6fc771 432 }
tomoya123 0:d53e9c6fc771 433
tomoya123 0:d53e9c6fc771 434 void HeptaCamera::InitVGA(void) {
tomoya123 0:d53e9c6fc771 435 // VGA
tomoya123 0:d53e9c6fc771 436 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 437
tomoya123 0:d53e9c6fc771 438 WriteReg(REG_COM7,reg_com7|COM7_VGA);
tomoya123 0:d53e9c6fc771 439
tomoya123 0:d53e9c6fc771 440 WriteReg(REG_HSTART,HSTART_VGA);
tomoya123 0:d53e9c6fc771 441 WriteReg(REG_HSTOP,HSTOP_VGA);
tomoya123 0:d53e9c6fc771 442 WriteReg(REG_HREF,HREF_VGA);
tomoya123 0:d53e9c6fc771 443 WriteReg(REG_VSTART,VSTART_VGA);
tomoya123 0:d53e9c6fc771 444 WriteReg(REG_VSTOP,VSTOP_VGA);
tomoya123 0:d53e9c6fc771 445 WriteReg(REG_VREF,VREF_VGA);
tomoya123 0:d53e9c6fc771 446 WriteReg(REG_COM3, COM3_VGA);
tomoya123 0:d53e9c6fc771 447 WriteReg(REG_COM14, COM14_VGA);
tomoya123 0:d53e9c6fc771 448 WriteReg(REG_SCALING_XSC, SCALING_XSC_VGA);
tomoya123 0:d53e9c6fc771 449 WriteReg(REG_SCALING_YSC, SCALING_YSC_VGA);
tomoya123 0:d53e9c6fc771 450 WriteReg(REG_SCALING_DCWCTR, SCALING_DCWCTR_VGA);
tomoya123 0:d53e9c6fc771 451 WriteReg(REG_SCALING_PCLK_DIV, SCALING_PCLK_DIV_VGA);
tomoya123 0:d53e9c6fc771 452 WriteReg(REG_SCALING_PCLK_DELAY, SCALING_PCLK_DELAY_VGA);
tomoya123 0:d53e9c6fc771 453 }
tomoya123 0:d53e9c6fc771 454
tomoya123 0:d53e9c6fc771 455 void HeptaCamera::InitFIFO_2bytes_color_nealy_limit_size(void) {
tomoya123 0:d53e9c6fc771 456 // nealy FIFO limit 544x360
tomoya123 0:d53e9c6fc771 457 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 458
tomoya123 0:d53e9c6fc771 459 WriteReg(REG_COM7,reg_com7|COM7_VGA);
tomoya123 0:d53e9c6fc771 460
tomoya123 0:d53e9c6fc771 461 WriteReg(REG_HSTART,HSTART_VGA);
tomoya123 0:d53e9c6fc771 462 WriteReg(REG_HSTOP,HSTOP_VGA);
tomoya123 0:d53e9c6fc771 463 WriteReg(REG_HREF,HREF_VGA);
tomoya123 0:d53e9c6fc771 464 WriteReg(REG_VSTART,VSTART_VGA);
tomoya123 0:d53e9c6fc771 465 WriteReg(REG_VSTOP,VSTOP_VGA);
tomoya123 0:d53e9c6fc771 466 WriteReg(REG_VREF,VREF_VGA);
tomoya123 0:d53e9c6fc771 467 WriteReg(REG_COM3, COM3_VGA);
tomoya123 0:d53e9c6fc771 468 WriteReg(REG_COM14, COM14_VGA);
tomoya123 0:d53e9c6fc771 469 WriteReg(REG_SCALING_XSC, SCALING_XSC_VGA);
tomoya123 0:d53e9c6fc771 470 WriteReg(REG_SCALING_YSC, SCALING_YSC_VGA);
tomoya123 0:d53e9c6fc771 471 WriteReg(REG_SCALING_DCWCTR, SCALING_DCWCTR_VGA);
tomoya123 0:d53e9c6fc771 472 WriteReg(REG_SCALING_PCLK_DIV, SCALING_PCLK_DIV_VGA);
tomoya123 0:d53e9c6fc771 473 WriteReg(REG_SCALING_PCLK_DELAY, SCALING_PCLK_DELAY_VGA);
tomoya123 0:d53e9c6fc771 474
tomoya123 0:d53e9c6fc771 475 WriteReg(REG_HSTART, 0x17);
tomoya123 0:d53e9c6fc771 476 WriteReg(REG_HSTOP, 0x5b);
tomoya123 0:d53e9c6fc771 477 WriteReg(REG_VSTART, 0x12);
tomoya123 0:d53e9c6fc771 478 WriteReg(REG_VSTOP, 0x6c);
tomoya123 0:d53e9c6fc771 479 }
tomoya123 0:d53e9c6fc771 480
tomoya123 0:d53e9c6fc771 481 void HeptaCamera::InitVGA_3_4(void) {
tomoya123 0:d53e9c6fc771 482 // VGA 3/4 -> 480x360
tomoya123 0:d53e9c6fc771 483 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 484
tomoya123 0:d53e9c6fc771 485 WriteReg(REG_COM7,reg_com7|COM7_VGA);
tomoya123 0:d53e9c6fc771 486
tomoya123 0:d53e9c6fc771 487 WriteReg(REG_HSTART,HSTART_VGA);
tomoya123 0:d53e9c6fc771 488 WriteReg(REG_HSTOP,HSTOP_VGA);
tomoya123 0:d53e9c6fc771 489 WriteReg(REG_HREF,HREF_VGA);
tomoya123 0:d53e9c6fc771 490 WriteReg(REG_VSTART,VSTART_VGA);
tomoya123 0:d53e9c6fc771 491 WriteReg(REG_VSTOP,VSTOP_VGA);
tomoya123 0:d53e9c6fc771 492 WriteReg(REG_VREF,VREF_VGA);
tomoya123 0:d53e9c6fc771 493 WriteReg(REG_COM3, COM3_VGA);
tomoya123 0:d53e9c6fc771 494 WriteReg(REG_COM14, COM14_VGA);
tomoya123 0:d53e9c6fc771 495 WriteReg(REG_SCALING_XSC, SCALING_XSC_VGA);
tomoya123 0:d53e9c6fc771 496 WriteReg(REG_SCALING_YSC, SCALING_YSC_VGA);
tomoya123 0:d53e9c6fc771 497 WriteReg(REG_SCALING_DCWCTR, SCALING_DCWCTR_VGA);
tomoya123 0:d53e9c6fc771 498 WriteReg(REG_SCALING_PCLK_DIV, SCALING_PCLK_DIV_VGA);
tomoya123 0:d53e9c6fc771 499 WriteReg(REG_SCALING_PCLK_DELAY, SCALING_PCLK_DELAY_VGA);
tomoya123 0:d53e9c6fc771 500
tomoya123 0:d53e9c6fc771 501 WriteReg(REG_HSTART, 0x1b);
tomoya123 0:d53e9c6fc771 502 WriteReg(REG_HSTOP, 0x57);
tomoya123 0:d53e9c6fc771 503 WriteReg(REG_VSTART, 0x12);
tomoya123 0:d53e9c6fc771 504 WriteReg(REG_VSTOP, 0x6c);
tomoya123 0:d53e9c6fc771 505 }
tomoya123 0:d53e9c6fc771 506
tomoya123 0:d53e9c6fc771 507 void HeptaCamera::InitQVGA(void) {
tomoya123 0:d53e9c6fc771 508 // QQVGA
tomoya123 0:d53e9c6fc771 509 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 510
tomoya123 0:d53e9c6fc771 511 WriteReg(REG_COM7,reg_com7|COM7_QVGA);
tomoya123 0:d53e9c6fc771 512
tomoya123 0:d53e9c6fc771 513 WriteReg(REG_HSTART,HSTART_QVGA);
tomoya123 0:d53e9c6fc771 514 WriteReg(REG_HSTOP,HSTOP_QVGA);
tomoya123 0:d53e9c6fc771 515 WriteReg(REG_HREF,HREF_QVGA);
tomoya123 0:d53e9c6fc771 516 WriteReg(REG_VSTART,VSTART_QVGA);
tomoya123 0:d53e9c6fc771 517 WriteReg(REG_VSTOP,VSTOP_QVGA);
tomoya123 0:d53e9c6fc771 518 WriteReg(REG_VREF,VREF_QVGA);
tomoya123 0:d53e9c6fc771 519 WriteReg(REG_COM3, COM3_QVGA);
tomoya123 0:d53e9c6fc771 520 WriteReg(REG_COM14, COM14_QVGA);
tomoya123 0:d53e9c6fc771 521 WriteReg(REG_SCALING_XSC, SCALING_XSC_QVGA);
tomoya123 0:d53e9c6fc771 522 WriteReg(REG_SCALING_YSC, SCALING_YSC_QVGA);
tomoya123 0:d53e9c6fc771 523 WriteReg(REG_SCALING_DCWCTR, SCALING_DCWCTR_QVGA);
tomoya123 0:d53e9c6fc771 524 WriteReg(REG_SCALING_PCLK_DIV, SCALING_PCLK_DIV_QVGA);
tomoya123 0:d53e9c6fc771 525 WriteReg(REG_SCALING_PCLK_DELAY, SCALING_PCLK_DELAY_QVGA);
tomoya123 0:d53e9c6fc771 526 }
tomoya123 0:d53e9c6fc771 527
tomoya123 0:d53e9c6fc771 528 void HeptaCamera::InitQQVGA(void) {
tomoya123 0:d53e9c6fc771 529 // QQVGA
tomoya123 0:d53e9c6fc771 530 int reg_com7 = ReadReg(REG_COM7);
tomoya123 0:d53e9c6fc771 531
tomoya123 0:d53e9c6fc771 532 WriteReg(REG_COM7,reg_com7|COM7_QQVGA);
tomoya123 0:d53e9c6fc771 533
tomoya123 0:d53e9c6fc771 534 WriteReg(REG_HSTART,HSTART_QQVGA);
tomoya123 0:d53e9c6fc771 535 WriteReg(REG_HSTOP,HSTOP_QQVGA);
tomoya123 0:d53e9c6fc771 536 WriteReg(REG_HREF,HREF_QQVGA);
tomoya123 0:d53e9c6fc771 537 WriteReg(REG_VSTART,VSTART_QQVGA);
tomoya123 0:d53e9c6fc771 538 WriteReg(REG_VSTOP,VSTOP_QQVGA);
tomoya123 0:d53e9c6fc771 539 WriteReg(REG_VREF,VREF_QQVGA);
tomoya123 0:d53e9c6fc771 540 WriteReg(REG_COM3, COM3_QQVGA);
tomoya123 0:d53e9c6fc771 541 WriteReg(REG_COM14, COM14_QQVGA);
tomoya123 0:d53e9c6fc771 542 WriteReg(REG_SCALING_XSC, SCALING_XSC_QQVGA);
tomoya123 0:d53e9c6fc771 543 WriteReg(REG_SCALING_YSC, SCALING_YSC_QQVGA);
tomoya123 0:d53e9c6fc771 544 WriteReg(REG_SCALING_DCWCTR, SCALING_DCWCTR_QQVGA);
tomoya123 0:d53e9c6fc771 545 WriteReg(REG_SCALING_PCLK_DIV, SCALING_PCLK_DIV_QQVGA);
tomoya123 0:d53e9c6fc771 546 WriteReg(REG_SCALING_PCLK_DELAY, SCALING_PCLK_DELAY_QQVGA);
tomoya123 0:d53e9c6fc771 547 }
tomoya123 0:d53e9c6fc771 548
tomoya123 0:d53e9c6fc771 549 // vsync handler
tomoya123 0:d53e9c6fc771 550 void HeptaCamera::VsyncHandler(void)
tomoya123 0:d53e9c6fc771 551 {
tomoya123 0:d53e9c6fc771 552 // Capture Enable
tomoya123 0:d53e9c6fc771 553 if (CaptureReq) {
tomoya123 0:d53e9c6fc771 554 wen = 1;
tomoya123 0:d53e9c6fc771 555 Done = false;
tomoya123 0:d53e9c6fc771 556 CaptureReq = false;
tomoya123 0:d53e9c6fc771 557 } else {
tomoya123 0:d53e9c6fc771 558 wen = 0;
tomoya123 0:d53e9c6fc771 559 if (Busy) {
tomoya123 0:d53e9c6fc771 560 Busy = false;
tomoya123 0:d53e9c6fc771 561 Done = true;
tomoya123 0:d53e9c6fc771 562 }
tomoya123 0:d53e9c6fc771 563 }
tomoya123 0:d53e9c6fc771 564
tomoya123 0:d53e9c6fc771 565 // Hline Counter
tomoya123 0:d53e9c6fc771 566 LastLines = LineCounter;
tomoya123 0:d53e9c6fc771 567 LineCounter = 0;
tomoya123 0:d53e9c6fc771 568 }
tomoya123 0:d53e9c6fc771 569
tomoya123 0:d53e9c6fc771 570 // href handler
tomoya123 0:d53e9c6fc771 571 void HeptaCamera::HrefHandler(void)
tomoya123 0:d53e9c6fc771 572 {
tomoya123 0:d53e9c6fc771 573 LineCounter++;
tomoya123 0:d53e9c6fc771 574 }
tomoya123 0:d53e9c6fc771 575
tomoya123 0:d53e9c6fc771 576 // Data Read
tomoya123 0:d53e9c6fc771 577 int HeptaCamera::ReadOneByte(void)
tomoya123 0:d53e9c6fc771 578 {
tomoya123 0:d53e9c6fc771 579 int result;
tomoya123 0:d53e9c6fc771 580 rclk = 1;
tomoya123 0:d53e9c6fc771 581 // wait_us(1);
tomoya123 0:d53e9c6fc771 582 result = data;
tomoya123 0:d53e9c6fc771 583 rclk = 0;
tomoya123 0:d53e9c6fc771 584 return result;
tomoya123 0:d53e9c6fc771 585 }
tomoya123 0:d53e9c6fc771 586
tomoya123 0:d53e9c6fc771 587 // Data Start
tomoya123 0:d53e9c6fc771 588 void HeptaCamera::ReadStart(void)
tomoya123 0:d53e9c6fc771 589 {
tomoya123 0:d53e9c6fc771 590 rrst = 0;
tomoya123 0:d53e9c6fc771 591 oe = 0;
tomoya123 0:d53e9c6fc771 592 wait_us(1);
tomoya123 0:d53e9c6fc771 593 rclk = 0;
tomoya123 0:d53e9c6fc771 594 wait_us(1);
tomoya123 0:d53e9c6fc771 595 rclk = 1;
tomoya123 0:d53e9c6fc771 596 wait_us(1);
tomoya123 0:d53e9c6fc771 597 rrst = 1;
tomoya123 0:d53e9c6fc771 598 }
tomoya123 0:d53e9c6fc771 599
tomoya123 0:d53e9c6fc771 600 // Data Stop
tomoya123 0:d53e9c6fc771 601 void HeptaCamera::ReadStop(void)
tomoya123 0:d53e9c6fc771 602 {
tomoya123 0:d53e9c6fc771 603 oe = 1;
tomoya123 0:d53e9c6fc771 604 ReadOneByte();
tomoya123 0:d53e9c6fc771 605 rclk = 1;
tomoya123 0:d53e9c6fc771 606 }
tomoya123 0:d53e9c6fc771 607
tomoya123 0:d53e9c6fc771 608 void HeptaCamera::shoot()
tomoya123 0:d53e9c6fc771 609 {
tomoya123 0:d53e9c6fc771 610 //pc.baud(115200);
tomoya123 0:d53e9c6fc771 611
tomoya123 0:d53e9c6fc771 612 //pc.printf("Camera resetting..\r\n");
tomoya123 0:d53e9c6fc771 613 HeptaCamera::Reset();
tomoya123 0:d53e9c6fc771 614
tomoya123 0:d53e9c6fc771 615 //pc.printf("Before Init...\r\n");
tomoya123 0:d53e9c6fc771 616 HeptaCamera::PrintRegister();
tomoya123 0:d53e9c6fc771 617 char color_format = '1';
tomoya123 0:d53e9c6fc771 618 /*pc.printf("Select color format.\r\n") ;
tomoya123 0:d53e9c6fc771 619 pc.printf("1: RGB444.\r\n");
tomoya123 0:d53e9c6fc771 620 pc.printf("2: RGB555.\r\n");
tomoya123 0:d53e9c6fc771 621 pc.printf("3: RGB565.\r\n");
tomoya123 0:d53e9c6fc771 622 pc.printf("4: YUV(UYVY).\r\n");
tomoya123 0:d53e9c6fc771 623 pc.printf("5: Bayer RGB(BGBG... GRGR...).\r\n");*/
tomoya123 0:d53e9c6fc771 624
tomoya123 0:d53e9c6fc771 625 /*while(!pc.readable());
tomoya123 0:d53e9c6fc771 626 char color_format = pc.getc();
tomoya123 0:d53e9c6fc771 627 switch (color_format) {
tomoya123 0:d53e9c6fc771 628 case '1':
tomoya123 0:d53e9c6fc771 629 camera.InitRGB444();
tomoya123 0:d53e9c6fc771 630 break;
tomoya123 0:d53e9c6fc771 631 case '2':
tomoya123 0:d53e9c6fc771 632 camera.InitRGB555();
tomoya123 0:d53e9c6fc771 633 break;
tomoya123 0:d53e9c6fc771 634 case '3':
tomoya123 0:d53e9c6fc771 635 camera.InitRGB565();
tomoya123 0:d53e9c6fc771 636 break;
tomoya123 0:d53e9c6fc771 637 case '4':
tomoya123 0:d53e9c6fc771 638 camera.InitYUV();
tomoya123 0:d53e9c6fc771 639 break;
tomoya123 0:d53e9c6fc771 640 case '5':
tomoya123 0:d53e9c6fc771 641 camera.InitBayerRGB();
tomoya123 0:d53e9c6fc771 642 break;
tomoya123 0:d53e9c6fc771 643 }
tomoya123 0:d53e9c6fc771 644 pc.printf("select %c\r\n", color_format);
tomoya123 0:d53e9c6fc771 645
tomoya123 0:d53e9c6fc771 646 pc.printf("Select screen size.\r\n") ;
tomoya123 0:d53e9c6fc771 647 switch (color_format) {
tomoya123 0:d53e9c6fc771 648 case '5':
tomoya123 0:d53e9c6fc771 649 pc.printf("1: VGA(640x480).\r\n");
tomoya123 0:d53e9c6fc771 650 case '1':
tomoya123 0:d53e9c6fc771 651 case '2':
tomoya123 0:d53e9c6fc771 652 case '3':
tomoya123 0:d53e9c6fc771 653 case '4':
tomoya123 0:d53e9c6fc771 654 pc.printf("2: FIFO nealy limit(544x360).\r\n");
tomoya123 0:d53e9c6fc771 655 pc.printf("3: VGA*3/4(480x360).\r\n");
tomoya123 0:d53e9c6fc771 656 pc.printf("4: QVGA(320x240).\r\n");
tomoya123 0:d53e9c6fc771 657 pc.printf("5: QQVGA(160x120).\r\n");
tomoya123 0:d53e9c6fc771 658 break;
tomoya123 0:d53e9c6fc771 659 }
tomoya123 0:d53e9c6fc771 660 char screen_size = 4;
tomoya123 0:d53e9c6fc771 661 while(!pc.readable());
tomoya123 0:d53e9c6fc771 662 char screen_size = pc.getc() ;
tomoya123 0:d53e9c6fc771 663 switch (screen_size) {
tomoya123 0:d53e9c6fc771 664 case '1':
tomoya123 0:d53e9c6fc771 665 sizex = 640;
tomoya123 0:d53e9c6fc771 666 sizey = 480;
tomoya123 0:d53e9c6fc771 667 camera.InitVGA();
tomoya123 0:d53e9c6fc771 668 break;
tomoya123 0:d53e9c6fc771 669 case '2':
tomoya123 0:d53e9c6fc771 670 sizex = 544;
tomoya123 0:d53e9c6fc771 671 sizey = 360;
tomoya123 0:d53e9c6fc771 672 camera.InitFIFO_2bytes_color_nealy_limit_size();
tomoya123 0:d53e9c6fc771 673 break;
tomoya123 0:d53e9c6fc771 674 case '3':
tomoya123 0:d53e9c6fc771 675 sizex = 480;
tomoya123 0:d53e9c6fc771 676 sizey = 360;
tomoya123 0:d53e9c6fc771 677 camera.InitVGA_3_4();
tomoya123 0:d53e9c6fc771 678 break;
tomoya123 0:d53e9c6fc771 679 case '4':
tomoya123 0:d53e9c6fc771 680 sizex = 320;
tomoya123 0:d53e9c6fc771 681 sizey = 240;
tomoya123 0:d53e9c6fc771 682 camera.InitQVGA();
tomoya123 0:d53e9c6fc771 683 break;
tomoya123 0:d53e9c6fc771 684 case '5':
tomoya123 0:d53e9c6fc771 685 sizex = 160;
tomoya123 0:d53e9c6fc771 686 sizey = 120;
tomoya123 0:d53e9c6fc771 687 camera.InitQQVGA();
tomoya123 0:d53e9c6fc771 688 break;
tomoya123 0:d53e9c6fc771 689 }
tomoya123 0:d53e9c6fc771 690 pc.printf("select %c\r\n", screen_size);*/
tomoya123 0:d53e9c6fc771 691 char screen_size = '4';
tomoya123 0:d53e9c6fc771 692 HeptaCamera::InitRGB444();
tomoya123 0:d53e9c6fc771 693 sizex = 320;
tomoya123 0:d53e9c6fc771 694 sizey = 240;
tomoya123 0:d53e9c6fc771 695 HeptaCamera::InitQVGA();
tomoya123 0:d53e9c6fc771 696 HeptaCamera::InitForFIFOWriteReset();
tomoya123 0:d53e9c6fc771 697 HeptaCamera::InitDefaultReg();
tomoya123 0:d53e9c6fc771 698
tomoya123 0:d53e9c6fc771 699 #ifdef COLORBAR
tomoya123 0:d53e9c6fc771 700 HeptaCamera::InitSetColorbar();
tomoya123 0:d53e9c6fc771 701 #endif
tomoya123 0:d53e9c6fc771 702
tomoya123 0:d53e9c6fc771 703 //pc.printf("After Init...\r\n");
tomoya123 0:d53e9c6fc771 704 HeptaCamera::PrintRegister();
tomoya123 0:d53e9c6fc771 705
tomoya123 0:d53e9c6fc771 706 // CAPTURE and SEND LOOP
tomoya123 0:d53e9c6fc771 707
tomoya123 0:d53e9c6fc771 708 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE) || defined(HEXFILE)
tomoya123 0:d53e9c6fc771 709 //pc.printf("Hit Any Key %dx%d Capture Data.\r\n", sizex, sizey) ;
tomoya123 0:d53e9c6fc771 710 //while(!pc.readable());
tomoya123 0:d53e9c6fc771 711 //pc.printf("*\r\n");
tomoya123 0:d53e9c6fc771 712 //pc.getc();
tomoya123 0:d53e9c6fc771 713
tomoya123 0:d53e9c6fc771 714 int real_width = sizex*3 + sizey%4;
tomoya123 0:d53e9c6fc771 715
tomoya123 0:d53e9c6fc771 716 unsigned char *bmp_line_data; //画像1行分のRGB情報を格納する
tomoya123 0:d53e9c6fc771 717 if((bmp_line_data = (unsigned char *)malloc(sizeof(unsigned char)*real_width)) == NULL){
tomoya123 0:d53e9c6fc771 718 fprintf(stderr, "Error: Allocation error.\n");
tomoya123 0:d53e9c6fc771 719 //return 1;
tomoya123 0:d53e9c6fc771 720 }
tomoya123 0:d53e9c6fc771 721
tomoya123 0:d53e9c6fc771 722 //RGB情報を4バイトの倍数に合わせている
tomoya123 0:d53e9c6fc771 723 for(int i=sizex*3; i<real_width; i++){
tomoya123 0:d53e9c6fc771 724 bmp_line_data[i] = 0;
tomoya123 0:d53e9c6fc771 725 }
tomoya123 0:d53e9c6fc771 726 #endif
tomoya123 0:d53e9c6fc771 727 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE)
tomoya123 0:d53e9c6fc771 728 FILE *fp;
tomoya123 0:d53e9c6fc771 729 char *filename = "/local/test.bmp";
tomoya123 0:d53e9c6fc771 730 if((fp = fopen(filename, "wb")) == NULL){
tomoya123 0:d53e9c6fc771 731 //pc.printf("Error: %s could not open.", filename);
tomoya123 0:d53e9c6fc771 732 //return 1;
tomoya123 0:d53e9c6fc771 733 }
tomoya123 0:d53e9c6fc771 734
tomoya123 0:d53e9c6fc771 735 create_header(fp, sizex, sizey);
tomoya123 0:d53e9c6fc771 736 #endif
tomoya123 0:d53e9c6fc771 737 #ifdef HEXFILE
tomoya123 0:d53e9c6fc771 738 FILE *fp2;
tomoya123 0:d53e9c6fc771 739 char *filename2 = "/local/test.txt";
tomoya123 0:d53e9c6fc771 740 if((fp2 = fopen(filename2, "w")) == NULL){
tomoya123 0:d53e9c6fc771 741 pc.printf("Error: %s could not open.", filename2);
tomoya123 0:d53e9c6fc771 742 return 1;
tomoya123 0:d53e9c6fc771 743 }
tomoya123 0:d53e9c6fc771 744 #endif
tomoya123 0:d53e9c6fc771 745
tomoya123 0:d53e9c6fc771 746 HeptaCamera::CaptureNext();
tomoya123 0:d53e9c6fc771 747 while(HeptaCamera::CaptureDone() == false);
tomoya123 0:d53e9c6fc771 748 HeptaCamera::ReadStart();
tomoya123 0:d53e9c6fc771 749
tomoya123 0:d53e9c6fc771 750 int r=0, g=0, b=0, d1, d2;
tomoya123 0:d53e9c6fc771 751
tomoya123 0:d53e9c6fc771 752 switch (color_format) {
tomoya123 0:d53e9c6fc771 753 case '1':
tomoya123 0:d53e9c6fc771 754 case '2':
tomoya123 0:d53e9c6fc771 755 case '3':
tomoya123 0:d53e9c6fc771 756
tomoya123 0:d53e9c6fc771 757 for (int y=0; y<sizey; y++) {
tomoya123 0:d53e9c6fc771 758 for (int x=0; x<sizex; x++) {
tomoya123 0:d53e9c6fc771 759 d1 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 760 d2 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 761
tomoya123 0:d53e9c6fc771 762 switch (color_format) {
tomoya123 0:d53e9c6fc771 763 case '1':
tomoya123 0:d53e9c6fc771 764 // RGB444 to RGB888
tomoya123 0:d53e9c6fc771 765 b = (d1 & 0x0F) << 4;
tomoya123 0:d53e9c6fc771 766 g = (d2 & 0xF0);
tomoya123 0:d53e9c6fc771 767 r = (d2 & 0x0F) << 4;
tomoya123 0:d53e9c6fc771 768 break;
tomoya123 0:d53e9c6fc771 769 case '2':
tomoya123 0:d53e9c6fc771 770 // RGB555 to RGB888
tomoya123 0:d53e9c6fc771 771 b = (d1 & 0x1F) << 3;
tomoya123 0:d53e9c6fc771 772 g = (((d1 & 0xE0) >> 2) | ((d2 & 0x03) << 6));
tomoya123 0:d53e9c6fc771 773 r = (d2 & 0x7c) << 1;
tomoya123 0:d53e9c6fc771 774 break;
tomoya123 0:d53e9c6fc771 775 case '3':
tomoya123 0:d53e9c6fc771 776 // RGB565 to RGB888
tomoya123 0:d53e9c6fc771 777 b = (d1 & 0x1F) << 3;
tomoya123 0:d53e9c6fc771 778 g = (((d1 & 0xE0) >> 3) | ((d2 & 0x07) << 5));
tomoya123 0:d53e9c6fc771 779 r = (d2 & 0xF8);
tomoya123 0:d53e9c6fc771 780 break;
tomoya123 0:d53e9c6fc771 781 }
tomoya123 0:d53e9c6fc771 782 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:d53e9c6fc771 783 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:d53e9c6fc771 784 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:d53e9c6fc771 785 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:d53e9c6fc771 786 #endif
tomoya123 0:d53e9c6fc771 787 /*
tomoya123 0:d53e9c6fc771 788 // RGB
tomoya123 0:d53e9c6fc771 789 pc.printf ("%2X%2X%2X", r, g, b) ;
tomoya123 0:d53e9c6fc771 790 */
tomoya123 0:d53e9c6fc771 791 }
tomoya123 0:d53e9c6fc771 792 #ifdef BITMAPFILE
tomoya123 0:d53e9c6fc771 793 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 794 #endif
tomoya123 0:d53e9c6fc771 795 #ifdef HEXFILE
tomoya123 0:d53e9c6fc771 796 for(int i=0; i<sizex*3; i++){
tomoya123 0:d53e9c6fc771 797 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:d53e9c6fc771 798 }
tomoya123 0:d53e9c6fc771 799 #endif
tomoya123 0:d53e9c6fc771 800 // pc.printf("\r\n") ;
tomoya123 0:d53e9c6fc771 801 }
tomoya123 0:d53e9c6fc771 802 break;
tomoya123 0:d53e9c6fc771 803
tomoya123 0:d53e9c6fc771 804 case '4':
tomoya123 0:d53e9c6fc771 805 int index = 0;
tomoya123 0:d53e9c6fc771 806 for (int y=0; y<sizey; y++) {
tomoya123 0:d53e9c6fc771 807 int U0=0, Y0=0, V0=0, Y1=0;
tomoya123 0:d53e9c6fc771 808 for (int x=0; x<sizex; x++) {
tomoya123 0:d53e9c6fc771 809 if(index%2 == 0) {
tomoya123 0:d53e9c6fc771 810 U0 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 811 Y0 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 812 V0 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 813 Y1 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 814
tomoya123 0:d53e9c6fc771 815 b = Y0 + 1.77200 * (U0 - 128);
tomoya123 0:d53e9c6fc771 816 g = Y0 - 0.34414 * (U0 - 128) - 0.71414 * (V0 - 128);
tomoya123 0:d53e9c6fc771 817 r = Y0 + 1.40200 * (V0 - 128);
tomoya123 0:d53e9c6fc771 818 } else {
tomoya123 0:d53e9c6fc771 819 b = Y1 + 1.77200 * (U0 - 128);
tomoya123 0:d53e9c6fc771 820 g = Y1 - 0.34414 * (U0 - 128) - 0.71414 * (V0 - 128);
tomoya123 0:d53e9c6fc771 821 r = Y1 + 1.40200 * (V0 - 128);
tomoya123 0:d53e9c6fc771 822 }
tomoya123 0:d53e9c6fc771 823
tomoya123 0:d53e9c6fc771 824 b = min(max(b, 0), 255);
tomoya123 0:d53e9c6fc771 825 g = min(max(g, 0), 255);
tomoya123 0:d53e9c6fc771 826 r = min(max(r, 0), 255);
tomoya123 0:d53e9c6fc771 827
tomoya123 0:d53e9c6fc771 828 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:d53e9c6fc771 829 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:d53e9c6fc771 830 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:d53e9c6fc771 831 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:d53e9c6fc771 832 #endif
tomoya123 0:d53e9c6fc771 833 /*
tomoya123 0:d53e9c6fc771 834 // RGB
tomoya123 0:d53e9c6fc771 835 pc.printf ("%2X%2X%2X", r, g, b) ;
tomoya123 0:d53e9c6fc771 836 */
tomoya123 0:d53e9c6fc771 837 index++;
tomoya123 0:d53e9c6fc771 838 }
tomoya123 0:d53e9c6fc771 839 #ifdef BITMAPFILE
tomoya123 0:d53e9c6fc771 840 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 841 #endif
tomoya123 0:d53e9c6fc771 842 #ifdef HEXFILE
tomoya123 0:d53e9c6fc771 843 for(int i=0; i<sizex*3; i++){
tomoya123 0:d53e9c6fc771 844 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:d53e9c6fc771 845 }
tomoya123 0:d53e9c6fc771 846 #endif
tomoya123 0:d53e9c6fc771 847 // pc.printf("\r\n") ;
tomoya123 0:d53e9c6fc771 848 }
tomoya123 0:d53e9c6fc771 849 break;
tomoya123 0:d53e9c6fc771 850
tomoya123 0:d53e9c6fc771 851 case '5':
tomoya123 0:d53e9c6fc771 852 unsigned char *bayer_line[2];
tomoya123 0:d53e9c6fc771 853 unsigned char *bayer_line_data[2]; //画像1行分のRGB情報を格納する2行分
tomoya123 0:d53e9c6fc771 854 for(int i=0; i<2; i++) {
tomoya123 0:d53e9c6fc771 855 if((bayer_line_data[i] = (unsigned char *)malloc(sizeof(unsigned char)*sizex)) == NULL){
tomoya123 0:d53e9c6fc771 856 fprintf(stderr, "Error: Allocation error.\n");
tomoya123 0:d53e9c6fc771 857 //return 1;
tomoya123 0:d53e9c6fc771 858 }
tomoya123 0:d53e9c6fc771 859 }
tomoya123 0:d53e9c6fc771 860
tomoya123 0:d53e9c6fc771 861 for (int x=0; x<sizex; x++) {
tomoya123 0:d53e9c6fc771 862 // odd line BGBG... even line GRGR...
tomoya123 0:d53e9c6fc771 863 bayer_line_data[0][x] = (unsigned char)HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 864 #ifdef BAYERBITMAPFILE
tomoya123 0:d53e9c6fc771 865 bmp_line_data[x*3] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:d53e9c6fc771 866 bmp_line_data[x*3 + 1] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:d53e9c6fc771 867 bmp_line_data[x*3 + 2] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:d53e9c6fc771 868 #endif
tomoya123 0:d53e9c6fc771 869 }
tomoya123 0:d53e9c6fc771 870 #ifdef BAYERBITMAPFILE
tomoya123 0:d53e9c6fc771 871 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 872 #endif
tomoya123 0:d53e9c6fc771 873 bayer_line[1] = bayer_line_data[0];
tomoya123 0:d53e9c6fc771 874
tomoya123 0:d53e9c6fc771 875 for (int y=1; y<sizey; y++) {
tomoya123 0:d53e9c6fc771 876 int line = y%2;
tomoya123 0:d53e9c6fc771 877
tomoya123 0:d53e9c6fc771 878 for (int x=0; x<sizex; x++) {
tomoya123 0:d53e9c6fc771 879 // odd line BGBG... even line GRGR...
tomoya123 0:d53e9c6fc771 880 bayer_line_data[line][x] = (unsigned char)HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 881 #ifdef BAYERBITMAPFILE
tomoya123 0:d53e9c6fc771 882 bmp_line_data[x*3] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:d53e9c6fc771 883 bmp_line_data[x*3 + 1] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:d53e9c6fc771 884 bmp_line_data[x*3 + 2] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:d53e9c6fc771 885 #endif
tomoya123 0:d53e9c6fc771 886 }
tomoya123 0:d53e9c6fc771 887 #ifdef BAYERBITMAPFILE
tomoya123 0:d53e9c6fc771 888 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 889 #endif
tomoya123 0:d53e9c6fc771 890 bayer_line[0] = bayer_line[1];
tomoya123 0:d53e9c6fc771 891 bayer_line[1] = bayer_line_data[line];
tomoya123 0:d53e9c6fc771 892
tomoya123 0:d53e9c6fc771 893 for (int x=0; x<sizex - 1; x++) {
tomoya123 0:d53e9c6fc771 894 if(y%2==1) {
tomoya123 0:d53e9c6fc771 895 if(x%2==0) {
tomoya123 0:d53e9c6fc771 896 // BG
tomoya123 0:d53e9c6fc771 897 // GR
tomoya123 0:d53e9c6fc771 898 b = bayer_line[0][x];
tomoya123 0:d53e9c6fc771 899 g = ((int)bayer_line[0][x+1] + bayer_line[1][x])>>1;
tomoya123 0:d53e9c6fc771 900 r = bayer_line[1][x+1];
tomoya123 0:d53e9c6fc771 901 } else {
tomoya123 0:d53e9c6fc771 902 // GB
tomoya123 0:d53e9c6fc771 903 // RG
tomoya123 0:d53e9c6fc771 904 b = bayer_line[0][x+1];
tomoya123 0:d53e9c6fc771 905 g = ((int)bayer_line[0][x] + bayer_line[1][x+1])>>1;
tomoya123 0:d53e9c6fc771 906 r = bayer_line[1][x];
tomoya123 0:d53e9c6fc771 907 }
tomoya123 0:d53e9c6fc771 908 } else {
tomoya123 0:d53e9c6fc771 909 if(x%2==0) {
tomoya123 0:d53e9c6fc771 910 // GR
tomoya123 0:d53e9c6fc771 911 // BG
tomoya123 0:d53e9c6fc771 912 b = bayer_line[1][x];
tomoya123 0:d53e9c6fc771 913 g = ((int)bayer_line[0][x] + bayer_line[1][x+1])>>1;
tomoya123 0:d53e9c6fc771 914 r = bayer_line[0][x+1];
tomoya123 0:d53e9c6fc771 915 } else {
tomoya123 0:d53e9c6fc771 916 // RG
tomoya123 0:d53e9c6fc771 917 // GB
tomoya123 0:d53e9c6fc771 918 b = bayer_line[1][x+1];
tomoya123 0:d53e9c6fc771 919 g = ((int)bayer_line[0][x+1] + bayer_line[1][x])>>1;
tomoya123 0:d53e9c6fc771 920 r = bayer_line[0][x];
tomoya123 0:d53e9c6fc771 921 }
tomoya123 0:d53e9c6fc771 922 }
tomoya123 0:d53e9c6fc771 923 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:d53e9c6fc771 924 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:d53e9c6fc771 925 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:d53e9c6fc771 926 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:d53e9c6fc771 927 #endif
tomoya123 0:d53e9c6fc771 928 }
tomoya123 0:d53e9c6fc771 929
tomoya123 0:d53e9c6fc771 930 #ifdef BITMAPFILE
tomoya123 0:d53e9c6fc771 931 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 932 #endif
tomoya123 0:d53e9c6fc771 933
tomoya123 0:d53e9c6fc771 934 #ifdef HEXFILE
tomoya123 0:d53e9c6fc771 935 for(int i=0; i<sizex*3; i++){
tomoya123 0:d53e9c6fc771 936 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:d53e9c6fc771 937 }
tomoya123 0:d53e9c6fc771 938 #endif
tomoya123 0:d53e9c6fc771 939 }
tomoya123 0:d53e9c6fc771 940
tomoya123 0:d53e9c6fc771 941 for(int i=0; i<2; i++) {
tomoya123 0:d53e9c6fc771 942 free(bayer_line_data[i]);
tomoya123 0:d53e9c6fc771 943 }
tomoya123 0:d53e9c6fc771 944 #ifdef BITMAPFILE
tomoya123 0:d53e9c6fc771 945 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 946 #endif
tomoya123 0:d53e9c6fc771 947 break;
tomoya123 0:d53e9c6fc771 948 }
tomoya123 0:d53e9c6fc771 949 HeptaCamera::ReadStop();
tomoya123 0:d53e9c6fc771 950
tomoya123 0:d53e9c6fc771 951 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE)
tomoya123 0:d53e9c6fc771 952 free(bmp_line_data);
tomoya123 0:d53e9c6fc771 953 fclose(fp);
tomoya123 0:d53e9c6fc771 954 #endif
tomoya123 0:d53e9c6fc771 955 #ifdef HEXFILE
tomoya123 0:d53e9c6fc771 956 fclose(fp2);
tomoya123 0:d53e9c6fc771 957 #endif
tomoya123 0:d53e9c6fc771 958
tomoya123 0:d53e9c6fc771 959 }
tomoya123 0:d53e9c6fc771 960
tomoya123 0:d53e9c6fc771 961 void HeptaCamera::shoot2()
tomoya123 0:d53e9c6fc771 962 {
tomoya123 0:d53e9c6fc771 963 //pc.baud(115200);
tomoya123 0:d53e9c6fc771 964
tomoya123 0:d53e9c6fc771 965 //pc.printf("Camera resetting..\r\n");
tomoya123 0:d53e9c6fc771 966 HeptaCamera::Reset();
tomoya123 0:d53e9c6fc771 967
tomoya123 0:d53e9c6fc771 968 //pc.printf("Before Init...\r\n");
tomoya123 0:d53e9c6fc771 969 HeptaCamera::PrintRegister();
tomoya123 0:d53e9c6fc771 970 char color_format = '1';
tomoya123 0:d53e9c6fc771 971 /*pc.printf("Select color format.\r\n") ;
tomoya123 0:d53e9c6fc771 972 pc.printf("1: RGB444.\r\n");
tomoya123 0:d53e9c6fc771 973 pc.printf("2: RGB555.\r\n");
tomoya123 0:d53e9c6fc771 974 pc.printf("3: RGB565.\r\n");
tomoya123 0:d53e9c6fc771 975 pc.printf("4: YUV(UYVY).\r\n");
tomoya123 0:d53e9c6fc771 976 pc.printf("5: Bayer RGB(BGBG... GRGR...).\r\n");*/
tomoya123 0:d53e9c6fc771 977
tomoya123 0:d53e9c6fc771 978 /*while(!pc.readable());
tomoya123 0:d53e9c6fc771 979 char color_format = pc.getc();
tomoya123 0:d53e9c6fc771 980 switch (color_format) {
tomoya123 0:d53e9c6fc771 981 case '1':
tomoya123 0:d53e9c6fc771 982 camera.InitRGB444();
tomoya123 0:d53e9c6fc771 983 break;
tomoya123 0:d53e9c6fc771 984 case '2':
tomoya123 0:d53e9c6fc771 985 camera.InitRGB555();
tomoya123 0:d53e9c6fc771 986 break;
tomoya123 0:d53e9c6fc771 987 case '3':
tomoya123 0:d53e9c6fc771 988 camera.InitRGB565();
tomoya123 0:d53e9c6fc771 989 break;
tomoya123 0:d53e9c6fc771 990 case '4':
tomoya123 0:d53e9c6fc771 991 camera.InitYUV();
tomoya123 0:d53e9c6fc771 992 break;
tomoya123 0:d53e9c6fc771 993 case '5':
tomoya123 0:d53e9c6fc771 994 camera.InitBayerRGB();
tomoya123 0:d53e9c6fc771 995 break;
tomoya123 0:d53e9c6fc771 996 }
tomoya123 0:d53e9c6fc771 997 pc.printf("select %c\r\n", color_format);
tomoya123 0:d53e9c6fc771 998
tomoya123 0:d53e9c6fc771 999 pc.printf("Select screen size.\r\n") ;
tomoya123 0:d53e9c6fc771 1000 switch (color_format) {
tomoya123 0:d53e9c6fc771 1001 case '5':
tomoya123 0:d53e9c6fc771 1002 pc.printf("1: VGA(640x480).\r\n");
tomoya123 0:d53e9c6fc771 1003 case '1':
tomoya123 0:d53e9c6fc771 1004 case '2':
tomoya123 0:d53e9c6fc771 1005 case '3':
tomoya123 0:d53e9c6fc771 1006 case '4':
tomoya123 0:d53e9c6fc771 1007 pc.printf("2: FIFO nealy limit(544x360).\r\n");
tomoya123 0:d53e9c6fc771 1008 pc.printf("3: VGA*3/4(480x360).\r\n");
tomoya123 0:d53e9c6fc771 1009 pc.printf("4: QVGA(320x240).\r\n");
tomoya123 0:d53e9c6fc771 1010 pc.printf("5: QQVGA(160x120).\r\n");
tomoya123 0:d53e9c6fc771 1011 break;
tomoya123 0:d53e9c6fc771 1012 }
tomoya123 0:d53e9c6fc771 1013 char screen_size = 4;
tomoya123 0:d53e9c6fc771 1014 while(!pc.readable());
tomoya123 0:d53e9c6fc771 1015 char screen_size = pc.getc() ;
tomoya123 0:d53e9c6fc771 1016 switch (screen_size) {
tomoya123 0:d53e9c6fc771 1017 case '1':
tomoya123 0:d53e9c6fc771 1018 sizex = 640;
tomoya123 0:d53e9c6fc771 1019 sizey = 480;
tomoya123 0:d53e9c6fc771 1020 camera.InitVGA();
tomoya123 0:d53e9c6fc771 1021 break;
tomoya123 0:d53e9c6fc771 1022 case '2':
tomoya123 0:d53e9c6fc771 1023 sizex = 544;
tomoya123 0:d53e9c6fc771 1024 sizey = 360;
tomoya123 0:d53e9c6fc771 1025 camera.InitFIFO_2bytes_color_nealy_limit_size();
tomoya123 0:d53e9c6fc771 1026 break;
tomoya123 0:d53e9c6fc771 1027 case '3':
tomoya123 0:d53e9c6fc771 1028 sizex = 480;
tomoya123 0:d53e9c6fc771 1029 sizey = 360;
tomoya123 0:d53e9c6fc771 1030 camera.InitVGA_3_4();
tomoya123 0:d53e9c6fc771 1031 break;
tomoya123 0:d53e9c6fc771 1032 case '4':
tomoya123 0:d53e9c6fc771 1033 sizex = 320;
tomoya123 0:d53e9c6fc771 1034 sizey = 240;
tomoya123 0:d53e9c6fc771 1035 camera.InitQVGA();
tomoya123 0:d53e9c6fc771 1036 break;
tomoya123 0:d53e9c6fc771 1037 case '5':
tomoya123 0:d53e9c6fc771 1038 sizex = 160;
tomoya123 0:d53e9c6fc771 1039 sizey = 120;
tomoya123 0:d53e9c6fc771 1040 camera.InitQQVGA();
tomoya123 0:d53e9c6fc771 1041 break;
tomoya123 0:d53e9c6fc771 1042 }
tomoya123 0:d53e9c6fc771 1043 pc.printf("select %c\r\n", screen_size);*/
tomoya123 0:d53e9c6fc771 1044 char screen_size = '4';
tomoya123 0:d53e9c6fc771 1045 HeptaCamera::InitRGB444();
tomoya123 0:d53e9c6fc771 1046 sizex = 320;
tomoya123 0:d53e9c6fc771 1047 sizey = 240;
tomoya123 0:d53e9c6fc771 1048 HeptaCamera::InitQVGA();
tomoya123 0:d53e9c6fc771 1049 HeptaCamera::InitForFIFOWriteReset();
tomoya123 0:d53e9c6fc771 1050 HeptaCamera::InitDefaultReg();
tomoya123 0:d53e9c6fc771 1051
tomoya123 0:d53e9c6fc771 1052 #ifdef COLORBAR
tomoya123 0:d53e9c6fc771 1053 HeptaCamera::InitSetColorbar();
tomoya123 0:d53e9c6fc771 1054 #endif
tomoya123 0:d53e9c6fc771 1055
tomoya123 0:d53e9c6fc771 1056 //pc.printf("After Init...\r\n");
tomoya123 0:d53e9c6fc771 1057 HeptaCamera::PrintRegister();
tomoya123 0:d53e9c6fc771 1058
tomoya123 0:d53e9c6fc771 1059 // CAPTURE and SEND LOOP
tomoya123 0:d53e9c6fc771 1060
tomoya123 0:d53e9c6fc771 1061 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE) || defined(HEXFILE)
tomoya123 0:d53e9c6fc771 1062 //pc.printf("Hit Any Key %dx%d Capture Data.\r\n", sizex, sizey) ;
tomoya123 0:d53e9c6fc771 1063 //while(!pc.readable());
tomoya123 0:d53e9c6fc771 1064 //pc.printf("*\r\n");
tomoya123 0:d53e9c6fc771 1065 //pc.getc();
tomoya123 0:d53e9c6fc771 1066
tomoya123 0:d53e9c6fc771 1067 int real_width = sizex*3 + sizey%4;
tomoya123 0:d53e9c6fc771 1068
tomoya123 0:d53e9c6fc771 1069 unsigned char *bmp_line_data; //画像1行分のRGB情報を格納する
tomoya123 0:d53e9c6fc771 1070 if((bmp_line_data = (unsigned char *)malloc(sizeof(unsigned char)*real_width)) == NULL){
tomoya123 0:d53e9c6fc771 1071 fprintf(stderr, "Error: Allocation error.\n");
tomoya123 0:d53e9c6fc771 1072 //return 1;
tomoya123 0:d53e9c6fc771 1073 }
tomoya123 0:d53e9c6fc771 1074
tomoya123 0:d53e9c6fc771 1075 //RGB情報を4バイトの倍数に合わせている
tomoya123 0:d53e9c6fc771 1076 for(int i=sizex*3; i<real_width; i++){
tomoya123 0:d53e9c6fc771 1077 bmp_line_data[i] = 0;
tomoya123 0:d53e9c6fc771 1078 }
tomoya123 0:d53e9c6fc771 1079 #endif
tomoya123 0:d53e9c6fc771 1080 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE)
tomoya123 0:d53e9c6fc771 1081 mkdir("/sd/mydir", 0777);
tomoya123 0:d53e9c6fc771 1082 FILE *fp = fopen("/sd/mydir/picture.bmp","w");
tomoya123 0:d53e9c6fc771 1083 if(fp == NULL) {
tomoya123 0:d53e9c6fc771 1084 error("Could not open file for write\r\n");
tomoya123 0:d53e9c6fc771 1085 }
tomoya123 0:d53e9c6fc771 1086
tomoya123 0:d53e9c6fc771 1087 create_header(fp, sizex, sizey);
tomoya123 0:d53e9c6fc771 1088 #endif
tomoya123 0:d53e9c6fc771 1089 #ifdef HEXFILE
tomoya123 0:d53e9c6fc771 1090 FILE *fp2;
tomoya123 0:d53e9c6fc771 1091 char *filename2 = "/local/test.txt";
tomoya123 0:d53e9c6fc771 1092 if((fp2 = fopen(filename2, "w")) == NULL){
tomoya123 0:d53e9c6fc771 1093 pc.printf("Error: %s could not open.", filename2);
tomoya123 0:d53e9c6fc771 1094 return 1;
tomoya123 0:d53e9c6fc771 1095 }
tomoya123 0:d53e9c6fc771 1096 #endif
tomoya123 0:d53e9c6fc771 1097
tomoya123 0:d53e9c6fc771 1098 HeptaCamera::CaptureNext();
tomoya123 0:d53e9c6fc771 1099 while(HeptaCamera::CaptureDone() == false);
tomoya123 0:d53e9c6fc771 1100 HeptaCamera::ReadStart();
tomoya123 0:d53e9c6fc771 1101
tomoya123 0:d53e9c6fc771 1102 int r=0, g=0, b=0, d1, d2;
tomoya123 0:d53e9c6fc771 1103
tomoya123 0:d53e9c6fc771 1104 switch (color_format) {
tomoya123 0:d53e9c6fc771 1105 case '1':
tomoya123 0:d53e9c6fc771 1106 case '2':
tomoya123 0:d53e9c6fc771 1107 case '3':
tomoya123 0:d53e9c6fc771 1108
tomoya123 0:d53e9c6fc771 1109 for (int y=0; y<sizey; y++) {
tomoya123 0:d53e9c6fc771 1110 for (int x=0; x<sizex; x++) {
tomoya123 0:d53e9c6fc771 1111 d1 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 1112 d2 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 1113
tomoya123 0:d53e9c6fc771 1114 switch (color_format) {
tomoya123 0:d53e9c6fc771 1115 case '1':
tomoya123 0:d53e9c6fc771 1116 // RGB444 to RGB888
tomoya123 0:d53e9c6fc771 1117 b = (d1 & 0x0F) << 4;
tomoya123 0:d53e9c6fc771 1118 g = (d2 & 0xF0);
tomoya123 0:d53e9c6fc771 1119 r = (d2 & 0x0F) << 4;
tomoya123 0:d53e9c6fc771 1120 break;
tomoya123 0:d53e9c6fc771 1121 case '2':
tomoya123 0:d53e9c6fc771 1122 // RGB555 to RGB888
tomoya123 0:d53e9c6fc771 1123 b = (d1 & 0x1F) << 3;
tomoya123 0:d53e9c6fc771 1124 g = (((d1 & 0xE0) >> 2) | ((d2 & 0x03) << 6));
tomoya123 0:d53e9c6fc771 1125 r = (d2 & 0x7c) << 1;
tomoya123 0:d53e9c6fc771 1126 break;
tomoya123 0:d53e9c6fc771 1127 case '3':
tomoya123 0:d53e9c6fc771 1128 // RGB565 to RGB888
tomoya123 0:d53e9c6fc771 1129 b = (d1 & 0x1F) << 3;
tomoya123 0:d53e9c6fc771 1130 g = (((d1 & 0xE0) >> 3) | ((d2 & 0x07) << 5));
tomoya123 0:d53e9c6fc771 1131 r = (d2 & 0xF8);
tomoya123 0:d53e9c6fc771 1132 break;
tomoya123 0:d53e9c6fc771 1133 }
tomoya123 0:d53e9c6fc771 1134 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:d53e9c6fc771 1135 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:d53e9c6fc771 1136 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:d53e9c6fc771 1137 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:d53e9c6fc771 1138 #endif
tomoya123 0:d53e9c6fc771 1139 /*
tomoya123 0:d53e9c6fc771 1140 // RGB
tomoya123 0:d53e9c6fc771 1141 pc.printf ("%2X%2X%2X", r, g, b) ;
tomoya123 0:d53e9c6fc771 1142 */
tomoya123 0:d53e9c6fc771 1143 }
tomoya123 0:d53e9c6fc771 1144 #ifdef BITMAPFILE
tomoya123 0:d53e9c6fc771 1145 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 1146 #endif
tomoya123 0:d53e9c6fc771 1147 #ifdef HEXFILE
tomoya123 0:d53e9c6fc771 1148 for(int i=0; i<sizex*3; i++){
tomoya123 0:d53e9c6fc771 1149 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:d53e9c6fc771 1150 }
tomoya123 0:d53e9c6fc771 1151 #endif
tomoya123 0:d53e9c6fc771 1152 // pc.printf("\r\n") ;
tomoya123 0:d53e9c6fc771 1153 }
tomoya123 0:d53e9c6fc771 1154 break;
tomoya123 0:d53e9c6fc771 1155
tomoya123 0:d53e9c6fc771 1156 case '4':
tomoya123 0:d53e9c6fc771 1157 int index = 0;
tomoya123 0:d53e9c6fc771 1158 for (int y=0; y<sizey; y++) {
tomoya123 0:d53e9c6fc771 1159 int U0=0, Y0=0, V0=0, Y1=0;
tomoya123 0:d53e9c6fc771 1160 for (int x=0; x<sizex; x++) {
tomoya123 0:d53e9c6fc771 1161 if(index%2 == 0) {
tomoya123 0:d53e9c6fc771 1162 U0 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 1163 Y0 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 1164 V0 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 1165 Y1 = HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 1166
tomoya123 0:d53e9c6fc771 1167 b = Y0 + 1.77200 * (U0 - 128);
tomoya123 0:d53e9c6fc771 1168 g = Y0 - 0.34414 * (U0 - 128) - 0.71414 * (V0 - 128);
tomoya123 0:d53e9c6fc771 1169 r = Y0 + 1.40200 * (V0 - 128);
tomoya123 0:d53e9c6fc771 1170 } else {
tomoya123 0:d53e9c6fc771 1171 b = Y1 + 1.77200 * (U0 - 128);
tomoya123 0:d53e9c6fc771 1172 g = Y1 - 0.34414 * (U0 - 128) - 0.71414 * (V0 - 128);
tomoya123 0:d53e9c6fc771 1173 r = Y1 + 1.40200 * (V0 - 128);
tomoya123 0:d53e9c6fc771 1174 }
tomoya123 0:d53e9c6fc771 1175
tomoya123 0:d53e9c6fc771 1176 b = min(max(b, 0), 255);
tomoya123 0:d53e9c6fc771 1177 g = min(max(g, 0), 255);
tomoya123 0:d53e9c6fc771 1178 r = min(max(r, 0), 255);
tomoya123 0:d53e9c6fc771 1179
tomoya123 0:d53e9c6fc771 1180 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:d53e9c6fc771 1181 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:d53e9c6fc771 1182 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:d53e9c6fc771 1183 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:d53e9c6fc771 1184 #endif
tomoya123 0:d53e9c6fc771 1185 /*
tomoya123 0:d53e9c6fc771 1186 // RGB
tomoya123 0:d53e9c6fc771 1187 pc.printf ("%2X%2X%2X", r, g, b) ;
tomoya123 0:d53e9c6fc771 1188 */
tomoya123 0:d53e9c6fc771 1189 index++;
tomoya123 0:d53e9c6fc771 1190 }
tomoya123 0:d53e9c6fc771 1191 #ifdef BITMAPFILE
tomoya123 0:d53e9c6fc771 1192 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 1193 #endif
tomoya123 0:d53e9c6fc771 1194 #ifdef HEXFILE
tomoya123 0:d53e9c6fc771 1195 for(int i=0; i<sizex*3; i++){
tomoya123 0:d53e9c6fc771 1196 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:d53e9c6fc771 1197 }
tomoya123 0:d53e9c6fc771 1198 #endif
tomoya123 0:d53e9c6fc771 1199 // pc.printf("\r\n") ;
tomoya123 0:d53e9c6fc771 1200 }
tomoya123 0:d53e9c6fc771 1201 break;
tomoya123 0:d53e9c6fc771 1202
tomoya123 0:d53e9c6fc771 1203 case '5':
tomoya123 0:d53e9c6fc771 1204 unsigned char *bayer_line[2];
tomoya123 0:d53e9c6fc771 1205 unsigned char *bayer_line_data[2]; //画像1行分のRGB情報を格納する2行分
tomoya123 0:d53e9c6fc771 1206 for(int i=0; i<2; i++) {
tomoya123 0:d53e9c6fc771 1207 if((bayer_line_data[i] = (unsigned char *)malloc(sizeof(unsigned char)*sizex)) == NULL){
tomoya123 0:d53e9c6fc771 1208 fprintf(stderr, "Error: Allocation error.\n");
tomoya123 0:d53e9c6fc771 1209 //return 1;
tomoya123 0:d53e9c6fc771 1210 }
tomoya123 0:d53e9c6fc771 1211 }
tomoya123 0:d53e9c6fc771 1212
tomoya123 0:d53e9c6fc771 1213 for (int x=0; x<sizex; x++) {
tomoya123 0:d53e9c6fc771 1214 // odd line BGBG... even line GRGR...
tomoya123 0:d53e9c6fc771 1215 bayer_line_data[0][x] = (unsigned char)HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 1216 #ifdef BAYERBITMAPFILE
tomoya123 0:d53e9c6fc771 1217 bmp_line_data[x*3] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:d53e9c6fc771 1218 bmp_line_data[x*3 + 1] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:d53e9c6fc771 1219 bmp_line_data[x*3 + 2] = (unsigned char)bayer_line_data[0][x];
tomoya123 0:d53e9c6fc771 1220 #endif
tomoya123 0:d53e9c6fc771 1221 }
tomoya123 0:d53e9c6fc771 1222 #ifdef BAYERBITMAPFILE
tomoya123 0:d53e9c6fc771 1223 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 1224 #endif
tomoya123 0:d53e9c6fc771 1225 bayer_line[1] = bayer_line_data[0];
tomoya123 0:d53e9c6fc771 1226
tomoya123 0:d53e9c6fc771 1227 for (int y=1; y<sizey; y++) {
tomoya123 0:d53e9c6fc771 1228 int line = y%2;
tomoya123 0:d53e9c6fc771 1229
tomoya123 0:d53e9c6fc771 1230 for (int x=0; x<sizex; x++) {
tomoya123 0:d53e9c6fc771 1231 // odd line BGBG... even line GRGR...
tomoya123 0:d53e9c6fc771 1232 bayer_line_data[line][x] = (unsigned char)HeptaCamera::ReadOneByte();
tomoya123 0:d53e9c6fc771 1233 #ifdef BAYERBITMAPFILE
tomoya123 0:d53e9c6fc771 1234 bmp_line_data[x*3] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:d53e9c6fc771 1235 bmp_line_data[x*3 + 1] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:d53e9c6fc771 1236 bmp_line_data[x*3 + 2] = (unsigned char)bayer_line_data[line][x];
tomoya123 0:d53e9c6fc771 1237 #endif
tomoya123 0:d53e9c6fc771 1238 }
tomoya123 0:d53e9c6fc771 1239 #ifdef BAYERBITMAPFILE
tomoya123 0:d53e9c6fc771 1240 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 1241 #endif
tomoya123 0:d53e9c6fc771 1242 bayer_line[0] = bayer_line[1];
tomoya123 0:d53e9c6fc771 1243 bayer_line[1] = bayer_line_data[line];
tomoya123 0:d53e9c6fc771 1244
tomoya123 0:d53e9c6fc771 1245 for (int x=0; x<sizex - 1; x++) {
tomoya123 0:d53e9c6fc771 1246 if(y%2==1) {
tomoya123 0:d53e9c6fc771 1247 if(x%2==0) {
tomoya123 0:d53e9c6fc771 1248 // BG
tomoya123 0:d53e9c6fc771 1249 // GR
tomoya123 0:d53e9c6fc771 1250 b = bayer_line[0][x];
tomoya123 0:d53e9c6fc771 1251 g = ((int)bayer_line[0][x+1] + bayer_line[1][x])>>1;
tomoya123 0:d53e9c6fc771 1252 r = bayer_line[1][x+1];
tomoya123 0:d53e9c6fc771 1253 } else {
tomoya123 0:d53e9c6fc771 1254 // GB
tomoya123 0:d53e9c6fc771 1255 // RG
tomoya123 0:d53e9c6fc771 1256 b = bayer_line[0][x+1];
tomoya123 0:d53e9c6fc771 1257 g = ((int)bayer_line[0][x] + bayer_line[1][x+1])>>1;
tomoya123 0:d53e9c6fc771 1258 r = bayer_line[1][x];
tomoya123 0:d53e9c6fc771 1259 }
tomoya123 0:d53e9c6fc771 1260 } else {
tomoya123 0:d53e9c6fc771 1261 if(x%2==0) {
tomoya123 0:d53e9c6fc771 1262 // GR
tomoya123 0:d53e9c6fc771 1263 // BG
tomoya123 0:d53e9c6fc771 1264 b = bayer_line[1][x];
tomoya123 0:d53e9c6fc771 1265 g = ((int)bayer_line[0][x] + bayer_line[1][x+1])>>1;
tomoya123 0:d53e9c6fc771 1266 r = bayer_line[0][x+1];
tomoya123 0:d53e9c6fc771 1267 } else {
tomoya123 0:d53e9c6fc771 1268 // RG
tomoya123 0:d53e9c6fc771 1269 // GB
tomoya123 0:d53e9c6fc771 1270 b = bayer_line[1][x+1];
tomoya123 0:d53e9c6fc771 1271 g = ((int)bayer_line[0][x+1] + bayer_line[1][x])>>1;
tomoya123 0:d53e9c6fc771 1272 r = bayer_line[0][x];
tomoya123 0:d53e9c6fc771 1273 }
tomoya123 0:d53e9c6fc771 1274 }
tomoya123 0:d53e9c6fc771 1275 #if defined(BITMAPFILE) || defined(HEXFILE)
tomoya123 0:d53e9c6fc771 1276 bmp_line_data[x*3] = (unsigned char)b;
tomoya123 0:d53e9c6fc771 1277 bmp_line_data[x*3 + 1] = (unsigned char)g;
tomoya123 0:d53e9c6fc771 1278 bmp_line_data[x*3 + 2] = (unsigned char)r;
tomoya123 0:d53e9c6fc771 1279 #endif
tomoya123 0:d53e9c6fc771 1280 }
tomoya123 0:d53e9c6fc771 1281
tomoya123 0:d53e9c6fc771 1282 #ifdef BITMAPFILE
tomoya123 0:d53e9c6fc771 1283 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 1284 #endif
tomoya123 0:d53e9c6fc771 1285
tomoya123 0:d53e9c6fc771 1286 #ifdef HEXFILE
tomoya123 0:d53e9c6fc771 1287 for(int i=0; i<sizex*3; i++){
tomoya123 0:d53e9c6fc771 1288 fprintf(fp2, "%02X", bmp_line_data[i]);
tomoya123 0:d53e9c6fc771 1289 }
tomoya123 0:d53e9c6fc771 1290 #endif
tomoya123 0:d53e9c6fc771 1291 }
tomoya123 0:d53e9c6fc771 1292
tomoya123 0:d53e9c6fc771 1293 for(int i=0; i<2; i++) {
tomoya123 0:d53e9c6fc771 1294 free(bayer_line_data[i]);
tomoya123 0:d53e9c6fc771 1295 }
tomoya123 0:d53e9c6fc771 1296 #ifdef BITMAPFILE
tomoya123 0:d53e9c6fc771 1297 fwrite(bmp_line_data, sizeof(unsigned char), real_width, fp);
tomoya123 0:d53e9c6fc771 1298 #endif
tomoya123 0:d53e9c6fc771 1299 break;
tomoya123 0:d53e9c6fc771 1300 }
tomoya123 0:d53e9c6fc771 1301 HeptaCamera::ReadStop();
tomoya123 0:d53e9c6fc771 1302
tomoya123 0:d53e9c6fc771 1303 #if defined(BITMAPFILE) || defined(BAYERBITMAPFILE)
tomoya123 0:d53e9c6fc771 1304 free(bmp_line_data);
tomoya123 0:d53e9c6fc771 1305 fclose(fp);
tomoya123 0:d53e9c6fc771 1306 #endif
tomoya123 0:d53e9c6fc771 1307 #ifdef HEXFILE
tomoya123 0:d53e9c6fc771 1308 fclose(fp2);
tomoya123 0:d53e9c6fc771 1309 #endif
tomoya123 0:d53e9c6fc771 1310
tomoya123 0:d53e9c6fc771 1311 }