Version 3: Trying to interleave capture and read

Dependencies:   ov7670_lib Project_test

Committer:
sebbarpar
Date:
Mon Apr 06 10:26:11 2020 +0000
Revision:
6:c7450b320c30
Parent:
5:4135ec0f88e6
Child:
7:9e4e66a8554e
ug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edodm85 0:19429e334b75 1 /*
edodm85 0:19429e334b75 2 * Author: Edoardo De Marchi
edodm85 3:b4e0cefc37f6 3 * Date: 07/04/13
edodm85 0:19429e334b75 4 * Notes: OV7670 + FIFO AL422B camera test
edodm85 0:19429e334b75 5 */
edodm85 0:19429e334b75 6
edodm85 0:19429e334b75 7 #include "main.h"
edodm85 0:19429e334b75 8
edodm85 2:bbd557817319 9 #define VGA 307200 //640*480
edodm85 2:bbd557817319 10 #define QVGA 76800 //320*240
edodm85 2:bbd557817319 11 #define QQVGA 19200 //160*120
sebbarpar 5:4135ec0f88e6 12 //FileSystem local("local");
edodm85 2:bbd557817319 13 static char format = ' ';
edodm85 2:bbd557817319 14 static int resolution = 0;
edodm85 0:19429e334b75 15
edodm85 0:19429e334b75 16
sebbarpar 5:4135ec0f88e6 17
edodm85 0:19429e334b75 18
edodm85 0:19429e334b75 19 int main()
sebbarpar 5:4135ec0f88e6 20 {
sebbarpar 5:4135ec0f88e6 21 //FILE *wrt=fopen("/local/out.txt","w");
sebbarpar 5:4135ec0f88e6 22 int pixel[QQVGA];
sebbarpar 5:4135ec0f88e6 23 int pixel2[QQVGA];
sebbarpar 5:4135ec0f88e6 24 camera.Init('y', QQVGA);
sebbarpar 5:4135ec0f88e6 25 pc.printf("Camera initiated");
sebbarpar 6:c7450b320c30 26 camera.CaptureNext();
sebbarpar 6:c7450b320c30 27 while(camera.CaptureDone() == false);
sebbarpar 5:4135ec0f88e6 28 camera.ReadStart();
sebbarpar 5:4135ec0f88e6 29 t1 = t.read_ms();
sebbarpar 5:4135ec0f88e6 30 t.start();
sebbarpar 5:4135ec0f88e6 31 for(int x = 0; x<QQVGA; x++)
sebbarpar 5:4135ec0f88e6 32 {
sebbarpar 5:4135ec0f88e6 33 pixel[x]=camera.ReadOnebyte();
sebbarpar 5:4135ec0f88e6 34 //fprintf(fp,"%i", pixel[x]);
sebbarpar 5:4135ec0f88e6 35 //pixel2[x]=camera.ReadOnebyte();
sebbarpar 5:4135ec0f88e6 36 //fprintf(fp,"%i/n", pixel2[x]);
sebbarpar 6:c7450b320c30 37 printf("%d ", camera.ReadOnebyte());
sebbarpar 5:4135ec0f88e6 38 }
sebbarpar 5:4135ec0f88e6 39
sebbarpar 5:4135ec0f88e6 40 camera.ReadStop();
sebbarpar 5:4135ec0f88e6 41 pc.printf("done in %f\r\n",t.read());
sebbarpar 5:4135ec0f88e6 42 //fclose(fp);
sebbarpar 5:4135ec0f88e6 43 /*
edodm85 0:19429e334b75 44 pc.baud(921600);
edodm85 0:19429e334b75 45 pc.printf("SystemCoreClock: %dMHz\r\n", SystemCoreClock/1000000); // print the clock frequency
edodm85 0:19429e334b75 46 led4 = 0;
edodm85 0:19429e334b75 47
edodm85 0:19429e334b75 48 t.start();
sebbarpar 5:4135ec0f88e6 49 //pc.attach(&rxCallback, MODSERIAL::RxIrq);
edodm85 0:19429e334b75 50
edodm85 0:19429e334b75 51 while(1)
edodm85 0:19429e334b75 52 {
edodm85 4:d0d4760d32b2 53 if(new_send)
edodm85 4:d0d4760d32b2 54 {
edodm85 0:19429e334b75 55 int i = 0;
edodm85 0:19429e334b75 56
edodm85 0:19429e334b75 57 while(pc.readable())
edodm85 0:19429e334b75 58 {
edodm85 0:19429e334b75 59 word[i] = pc.getc();
edodm85 0:19429e334b75 60 i++;
edodm85 0:19429e334b75 61 }
edodm85 0:19429e334b75 62 parse_cmd();
edodm85 0:19429e334b75 63 }
edodm85 0:19429e334b75 64 wait_ms(50);
edodm85 0:19429e334b75 65 }
edodm85 0:19429e334b75 66 }
edodm85 0:19429e334b75 67
edodm85 0:19429e334b75 68
edodm85 0:19429e334b75 69
edodm85 4:d0d4760d32b2 70 void parse_cmd()
edodm85 4:d0d4760d32b2 71 {
edodm85 0:19429e334b75 72 new_send = false;
edodm85 0:19429e334b75 73
edodm85 2:bbd557817319 74 if(strcmp("snap", word) == 0)
edodm85 0:19429e334b75 75 {
edodm85 2:bbd557817319 76 CameraSnap();
edodm85 0:19429e334b75 77 memset(word, 0, sizeof(word));
edodm85 0:19429e334b75 78 }else
edodm85 3:b4e0cefc37f6 79 if(strcmp("init_bw_VGA", word) == 0) // Set up for 640*480 pixels RAW
edodm85 0:19429e334b75 80 {
edodm85 2:bbd557817319 81 format = 'b';
edodm85 2:bbd557817319 82 resolution = VGA;
edodm85 2:bbd557817319 83 if(camera.Init('b', VGA) != 1)
edodm85 2:bbd557817319 84 {
edodm85 2:bbd557817319 85 pc.printf("Init Fail\r\n");
edodm85 2:bbd557817319 86 }
edodm85 2:bbd557817319 87 pc.printf("Initializing done\r\n");
edodm85 2:bbd557817319 88 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 89 }else
edodm85 2:bbd557817319 90 if(strcmp("init_yuv_QVGA", word) == 0) // Set up for 320*240 pixels YUV422
edodm85 2:bbd557817319 91 {
edodm85 2:bbd557817319 92 format = 'y';
edodm85 2:bbd557817319 93 resolution = QVGA;
edodm85 2:bbd557817319 94 if(camera.Init('b', QVGA) != 1)
edodm85 2:bbd557817319 95 {
edodm85 2:bbd557817319 96 pc.printf("Init Fail\r\n");
edodm85 2:bbd557817319 97 }
edodm85 2:bbd557817319 98 pc.printf("Initializing done\r\n");
edodm85 0:19429e334b75 99 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 100 }else
edodm85 2:bbd557817319 101 if(strcmp("init_rgb_QVGA", word) == 0) // Set up for 320*240 pixels RGB565
edodm85 2:bbd557817319 102 {
edodm85 2:bbd557817319 103 format = 'r';
edodm85 2:bbd557817319 104 resolution = QVGA;
edodm85 2:bbd557817319 105 if(camera.Init('r', QVGA) != 1)
edodm85 2:bbd557817319 106 {
edodm85 2:bbd557817319 107 pc.printf("Init Fail\r\n");
edodm85 2:bbd557817319 108 }
edodm85 2:bbd557817319 109 pc.printf("Initializing done\r\n");
edodm85 2:bbd557817319 110 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 111 }else
edodm85 2:bbd557817319 112 if(strcmp("init_bw_QVGA", word) == 0) // Set up for 320*240 pixels YUV (Only Y)
edodm85 0:19429e334b75 113 {
edodm85 2:bbd557817319 114 format = 'b';
edodm85 2:bbd557817319 115 resolution = QVGA;
edodm85 2:bbd557817319 116 if(camera.Init('b', QVGA) != 1)
edodm85 2:bbd557817319 117 {
edodm85 2:bbd557817319 118 pc.printf("Init Fail\r\n");
edodm85 2:bbd557817319 119 }
edodm85 2:bbd557817319 120 pc.printf("Initializing done\r\n");
edodm85 2:bbd557817319 121 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 122 }else
edodm85 2:bbd557817319 123 if(strcmp("init_yuv_QQVGA", word) == 0) // Set up for 160*120 pixels YUV422
edodm85 2:bbd557817319 124 {
edodm85 2:bbd557817319 125 format = 'y';
edodm85 2:bbd557817319 126 resolution = QQVGA;
edodm85 2:bbd557817319 127 if(camera.Init('b', QQVGA) != 1)
edodm85 2:bbd557817319 128 {
edodm85 2:bbd557817319 129 pc.printf("Init Fail\r\n");
edodm85 2:bbd557817319 130 }
edodm85 2:bbd557817319 131 pc.printf("Initializing done\r\n");
edodm85 2:bbd557817319 132 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 133 }else
edodm85 2:bbd557817319 134 if(strcmp("init_rgb_QQVGA", word) == 0) // Set up for 160*120 pixels RGB565
edodm85 2:bbd557817319 135 {
edodm85 2:bbd557817319 136 format = 'r';
edodm85 2:bbd557817319 137 resolution = QQVGA;
edodm85 2:bbd557817319 138 if(camera.Init('r', QQVGA) != 1)
edodm85 0:19429e334b75 139 {
edodm85 0:19429e334b75 140 pc.printf("Init Fail\r\n");
edodm85 0:19429e334b75 141 }
edodm85 0:19429e334b75 142 pc.printf("Initializing done\r\n");
edodm85 0:19429e334b75 143 memset(word, 0, sizeof(word));
edodm85 0:19429e334b75 144 }else
edodm85 2:bbd557817319 145 if(strcmp("init_bw_QQVGA", word) == 0) // Set up for 160*120 pixels YUV (Only Y)
edodm85 2:bbd557817319 146 {
edodm85 2:bbd557817319 147 format = 'b';
edodm85 2:bbd557817319 148 resolution = QQVGA;
edodm85 2:bbd557817319 149 if(camera.Init('b', QQVGA) != 1)
edodm85 0:19429e334b75 150 {
edodm85 0:19429e334b75 151 pc.printf("Init Fail\r\n");
edodm85 0:19429e334b75 152 }
edodm85 0:19429e334b75 153 pc.printf("Initializing done\r\n");
edodm85 0:19429e334b75 154 memset(word, 0, sizeof(word));
edodm85 0:19429e334b75 155 }else
edodm85 0:19429e334b75 156 if(strcmp("reset", word) == 0)
edodm85 0:19429e334b75 157 {
sebbarpar 5:4135ec0f88e6 158 //mbed_reset();
edodm85 0:19429e334b75 159 }else
edodm85 0:19429e334b75 160 if(strcmp("time", word) == 0)
edodm85 0:19429e334b75 161 {
edodm85 2:bbd557817319 162 pc.printf("Tot time acq + send (mbed): %dms\r\n", t2-t1);
edodm85 0:19429e334b75 163 memset(word, 0, sizeof(word));
edodm85 4:d0d4760d32b2 164 }else
edodm85 4:d0d4760d32b2 165 if(strcmp("reg_status", word) == 0)
edodm85 4:d0d4760d32b2 166 {
edodm85 4:d0d4760d32b2 167 int i = 0;
edodm85 4:d0d4760d32b2 168 pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F");
edodm85 4:d0d4760d32b2 169 for (i=0;i<OV7670_REGMAX;i++)
edodm85 4:d0d4760d32b2 170 {
edodm85 4:d0d4760d32b2 171 int data;
edodm85 4:d0d4760d32b2 172 data = camera.ReadReg(i); // READ REG
edodm85 4:d0d4760d32b2 173 if ((i & 0x0F) == 0)
edodm85 4:d0d4760d32b2 174 {
edodm85 4:d0d4760d32b2 175 pc.printf("\r\n%02X : ",i);
edodm85 4:d0d4760d32b2 176 }
edodm85 4:d0d4760d32b2 177 pc.printf("%02X ",data);
edodm85 4:d0d4760d32b2 178 }
edodm85 4:d0d4760d32b2 179 pc.printf("\r\n");
edodm85 2:bbd557817319 180 }
edodm85 2:bbd557817319 181
edodm85 0:19429e334b75 182 memset(word, 0, sizeof(word));
edodm85 0:19429e334b75 183
edodm85 0:19429e334b75 184 }
edodm85 0:19429e334b75 185
edodm85 0:19429e334b75 186
edodm85 4:d0d4760d32b2 187 void CameraSnap()
edodm85 4:d0d4760d32b2 188 {
edodm85 0:19429e334b75 189 led4 = 1;
edodm85 2:bbd557817319 190
edodm85 2:bbd557817319 191 // Kick things off by capturing an image
edodm85 0:19429e334b75 192 camera.CaptureNext();
edodm85 2:bbd557817319 193 while(camera.CaptureDone() == false);
edodm85 0:19429e334b75 194 // Start reading in the image data from the camera hardware buffer
edodm85 0:19429e334b75 195 camera.ReadStart();
edodm85 2:bbd557817319 196 t1 = t.read_ms();
edodm85 0:19429e334b75 197
edodm85 2:bbd557817319 198 for(int x = 0; x<resolution; x++)
edodm85 0:19429e334b75 199 {
edodm85 2:bbd557817319 200 // Read in the first half of the image
edodm85 3:b4e0cefc37f6 201 if(format == 'b' && resolution != VGA)
edodm85 2:bbd557817319 202 {
edodm85 2:bbd557817319 203 camera.ReadOnebyte();
edodm85 2:bbd557817319 204 }else
edodm85 2:bbd557817319 205 if(format == 'y' || format == 'r')
edodm85 2:bbd557817319 206 {
edodm85 2:bbd557817319 207 pc.putc(camera.ReadOnebyte());
edodm85 2:bbd557817319 208 }
edodm85 2:bbd557817319 209 // Read in the Second half of the image
edodm85 2:bbd557817319 210 pc.putc(camera.ReadOnebyte()); // Y only
edodm85 0:19429e334b75 211 }
edodm85 2:bbd557817319 212
edodm85 2:bbd557817319 213 camera.ReadStop();
edodm85 4:d0d4760d32b2 214 t2 = t.read_ms();
edodm85 0:19429e334b75 215
edodm85 4:d0d4760d32b2 216 camera.CaptureNext();
edodm85 4:d0d4760d32b2 217 while(camera.CaptureDone() == false);
edodm85 0:19429e334b75 218
edodm85 2:bbd557817319 219 pc.printf("Snap_done\r\n");
sebbarpar 5:4135ec0f88e6 220 led4 = 0;*/
edodm85 2:bbd557817319 221 }