Version 3: Trying to interleave capture and read

Dependencies:   ov7670_lib Project_test

Committer:
edodm85
Date:
Sat Mar 16 13:45:09 2013 +0000
Revision:
2:bbd557817319
Parent:
0:19429e334b75
Child:
3:b4e0cefc37f6
Changed parse_cmd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edodm85 0:19429e334b75 1 /*
edodm85 0:19429e334b75 2 * Author: Edoardo De Marchi
edodm85 0:19429e334b75 3 * Date: 10/03/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
edodm85 2:bbd557817319 12
edodm85 2:bbd557817319 13 static char format = ' ';
edodm85 2:bbd557817319 14 static int resolution = 0;
edodm85 0:19429e334b75 15
edodm85 0:19429e334b75 16
edodm85 0:19429e334b75 17 void rxCallback(MODSERIAL_IRQ_INFO *q)
edodm85 0:19429e334b75 18 {
edodm85 0:19429e334b75 19 new_send = true;
edodm85 0:19429e334b75 20 }
edodm85 0:19429e334b75 21
edodm85 0:19429e334b75 22 int main()
edodm85 0:19429e334b75 23 {
edodm85 0:19429e334b75 24 pc.baud(921600);
edodm85 0:19429e334b75 25 pc.printf("SystemCoreClock: %dMHz\r\n", SystemCoreClock/1000000); // print the clock frequency
edodm85 0:19429e334b75 26 led4 = 0;
edodm85 0:19429e334b75 27
edodm85 0:19429e334b75 28 t.start();
edodm85 0:19429e334b75 29 pc.attach(&rxCallback, MODSERIAL::RxIrq);
edodm85 0:19429e334b75 30
edodm85 0:19429e334b75 31 while(1)
edodm85 0:19429e334b75 32 {
edodm85 0:19429e334b75 33 if(new_send){
edodm85 0:19429e334b75 34 int i = 0;
edodm85 0:19429e334b75 35
edodm85 0:19429e334b75 36 while(pc.readable())
edodm85 0:19429e334b75 37 {
edodm85 0:19429e334b75 38 word[i] = pc.getc();
edodm85 0:19429e334b75 39 i++;
edodm85 0:19429e334b75 40 }
edodm85 0:19429e334b75 41 parse_cmd();
edodm85 0:19429e334b75 42 }
edodm85 0:19429e334b75 43 wait_ms(50);
edodm85 0:19429e334b75 44 }
edodm85 0:19429e334b75 45 }
edodm85 0:19429e334b75 46
edodm85 0:19429e334b75 47
edodm85 0:19429e334b75 48
edodm85 0:19429e334b75 49 void parse_cmd(){
edodm85 0:19429e334b75 50 new_send = false;
edodm85 0:19429e334b75 51
edodm85 2:bbd557817319 52 if(strcmp("snap", word) == 0)
edodm85 0:19429e334b75 53 {
edodm85 2:bbd557817319 54 CameraSnap();
edodm85 0:19429e334b75 55 memset(word, 0, sizeof(word));
edodm85 0:19429e334b75 56 }else
edodm85 2:bbd557817319 57 if(strcmp("init_bw_VGA", word) == 0) // Set up for 640*480 pixels YUV (Only Y)
edodm85 0:19429e334b75 58 {
edodm85 2:bbd557817319 59 pc.printf("Initializing ov7670 - Format YUV422(Y only) & VGA Mode\r\n");
edodm85 2:bbd557817319 60 format = 'b';
edodm85 2:bbd557817319 61 resolution = VGA;
edodm85 2:bbd557817319 62 if(camera.Init('b', VGA) != 1)
edodm85 2:bbd557817319 63 {
edodm85 2:bbd557817319 64 pc.printf("Init Fail\r\n");
edodm85 2:bbd557817319 65 }
edodm85 2:bbd557817319 66 pc.printf("Initializing done\r\n");
edodm85 2:bbd557817319 67 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 68 }else
edodm85 2:bbd557817319 69 if(strcmp("init_yuv_QVGA", word) == 0) // Set up for 320*240 pixels YUV422
edodm85 2:bbd557817319 70 {
edodm85 2:bbd557817319 71 pc.printf("Initializing ov7670 - Format YUV422 & QVGA Mode\r\n");
edodm85 2:bbd557817319 72 format = 'y';
edodm85 2:bbd557817319 73 resolution = QVGA;
edodm85 2:bbd557817319 74 if(camera.Init('b', QVGA) != 1)
edodm85 2:bbd557817319 75 {
edodm85 2:bbd557817319 76 pc.printf("Init Fail\r\n");
edodm85 2:bbd557817319 77 }
edodm85 2:bbd557817319 78 pc.printf("Initializing done\r\n");
edodm85 0:19429e334b75 79 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 80 }else
edodm85 2:bbd557817319 81 if(strcmp("init_rgb_QVGA", word) == 0) // Set up for 320*240 pixels RGB565
edodm85 2:bbd557817319 82 {
edodm85 2:bbd557817319 83 pc.printf("Initializing ov7670 - Format RGB565 & QVGA Mode\r\n");
edodm85 2:bbd557817319 84 format = 'r';
edodm85 2:bbd557817319 85 resolution = QVGA;
edodm85 2:bbd557817319 86 if(camera.Init('r', QVGA) != 1)
edodm85 2:bbd557817319 87 {
edodm85 2:bbd557817319 88 pc.printf("Init Fail\r\n");
edodm85 2:bbd557817319 89 }
edodm85 2:bbd557817319 90 pc.printf("Initializing done\r\n");
edodm85 2:bbd557817319 91 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 92 }else
edodm85 2:bbd557817319 93 if(strcmp("init_bw_QVGA", word) == 0) // Set up for 320*240 pixels YUV (Only Y)
edodm85 0:19429e334b75 94 {
edodm85 2:bbd557817319 95 pc.printf("Initializing ov7670 - Format YUV422(Y only) & QVGA Mode\r\n");
edodm85 2:bbd557817319 96 format = 'b';
edodm85 2:bbd557817319 97 resolution = QVGA;
edodm85 2:bbd557817319 98 if(camera.Init('b', QVGA) != 1)
edodm85 2:bbd557817319 99 {
edodm85 2:bbd557817319 100 pc.printf("Init Fail\r\n");
edodm85 2:bbd557817319 101 }
edodm85 2:bbd557817319 102 pc.printf("Initializing done\r\n");
edodm85 2:bbd557817319 103 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 104 }else
edodm85 2:bbd557817319 105 if(strcmp("init_yuv_QQVGA", word) == 0) // Set up for 160*120 pixels YUV422
edodm85 2:bbd557817319 106 {
edodm85 2:bbd557817319 107 pc.printf("Initializing ov7670 - Format YUV422 & QQVGA Mode\r\n");
edodm85 2:bbd557817319 108 format = 'y';
edodm85 2:bbd557817319 109 resolution = QQVGA;
edodm85 2:bbd557817319 110 if(camera.Init('b', QQVGA) != 1)
edodm85 2:bbd557817319 111 {
edodm85 2:bbd557817319 112 pc.printf("Init Fail\r\n");
edodm85 2:bbd557817319 113 }
edodm85 2:bbd557817319 114 pc.printf("Initializing done\r\n");
edodm85 2:bbd557817319 115 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 116 }else
edodm85 2:bbd557817319 117 if(strcmp("init_rgb_QQVGA", word) == 0) // Set up for 160*120 pixels RGB565
edodm85 2:bbd557817319 118 {
edodm85 2:bbd557817319 119 pc.printf("Initializing ov7670 - Format RGB565 & QQVGA Mode\r\n");
edodm85 2:bbd557817319 120 format = 'r';
edodm85 2:bbd557817319 121 resolution = QQVGA;
edodm85 2:bbd557817319 122 if(camera.Init('r', QQVGA) != 1)
edodm85 0:19429e334b75 123 {
edodm85 0:19429e334b75 124 pc.printf("Init Fail\r\n");
edodm85 0:19429e334b75 125 }
edodm85 0:19429e334b75 126 pc.printf("Initializing done\r\n");
edodm85 0:19429e334b75 127 memset(word, 0, sizeof(word));
edodm85 0:19429e334b75 128 }else
edodm85 2:bbd557817319 129 if(strcmp("init_bw_QQVGA", word) == 0) // Set up for 160*120 pixels YUV (Only Y)
edodm85 2:bbd557817319 130 {
edodm85 2:bbd557817319 131 pc.printf("Initializing ov7670 - Format YUV422(Y only) & QQVGA Mode\r\n");
edodm85 2:bbd557817319 132 format = 'b';
edodm85 2:bbd557817319 133 resolution = QQVGA;
edodm85 2:bbd557817319 134 if(camera.Init('b', QQVGA) != 1)
edodm85 0:19429e334b75 135 {
edodm85 0:19429e334b75 136 pc.printf("Init Fail\r\n");
edodm85 0:19429e334b75 137 }
edodm85 0:19429e334b75 138 pc.printf("Initializing done\r\n");
edodm85 0:19429e334b75 139 memset(word, 0, sizeof(word));
edodm85 0:19429e334b75 140 }else
edodm85 0:19429e334b75 141 if(strcmp("reset", word) == 0)
edodm85 0:19429e334b75 142 {
edodm85 0:19429e334b75 143 mbed_reset();
edodm85 0:19429e334b75 144 }else
edodm85 0:19429e334b75 145 if(strcmp("time", word) == 0)
edodm85 0:19429e334b75 146 {
edodm85 2:bbd557817319 147 pc.printf("Tot time acq + send (mbed): %dms\r\n", t2-t1);
edodm85 0:19429e334b75 148 memset(word, 0, sizeof(word));
edodm85 2:bbd557817319 149 }
edodm85 2:bbd557817319 150
edodm85 0:19429e334b75 151 memset(word, 0, sizeof(word));
edodm85 0:19429e334b75 152
edodm85 0:19429e334b75 153 }
edodm85 0:19429e334b75 154
edodm85 0:19429e334b75 155
edodm85 2:bbd557817319 156 void CameraSnap(){
edodm85 0:19429e334b75 157 led4 = 1;
edodm85 2:bbd557817319 158
edodm85 2:bbd557817319 159 // Kick things off by capturing an image
edodm85 0:19429e334b75 160 camera.CaptureNext();
edodm85 2:bbd557817319 161 while(camera.CaptureDone() == false);
edodm85 0:19429e334b75 162 // Start reading in the image data from the camera hardware buffer
edodm85 0:19429e334b75 163 camera.ReadStart();
edodm85 2:bbd557817319 164 t1 = t.read_ms();
edodm85 0:19429e334b75 165
edodm85 2:bbd557817319 166 for(int x = 0; x<resolution; x++)
edodm85 0:19429e334b75 167 {
edodm85 2:bbd557817319 168 // Read in the first half of the image
edodm85 2:bbd557817319 169 if(format == 'b')
edodm85 2:bbd557817319 170 {
edodm85 2:bbd557817319 171 camera.ReadOnebyte();
edodm85 2:bbd557817319 172 }else
edodm85 2:bbd557817319 173 if(format == 'y' || format == 'r')
edodm85 2:bbd557817319 174 {
edodm85 2:bbd557817319 175 pc.putc(camera.ReadOnebyte());
edodm85 2:bbd557817319 176 }
edodm85 2:bbd557817319 177 // Read in the Second half of the image
edodm85 2:bbd557817319 178 pc.putc(camera.ReadOnebyte()); // Y only
edodm85 0:19429e334b75 179 }
edodm85 2:bbd557817319 180
edodm85 2:bbd557817319 181 camera.ReadStop();
edodm85 2:bbd557817319 182 t2 = t.read_ms();
edodm85 0:19429e334b75 183
edodm85 2:bbd557817319 184 // Immediately request the next image to be captured (takes around 45ms)
edodm85 0:19429e334b75 185 camera.CaptureNext();
edodm85 2:bbd557817319 186 // Now wait for the image to finish being captured
edodm85 0:19429e334b75 187 while (camera.CaptureDone() == false);
edodm85 0:19429e334b75 188
edodm85 2:bbd557817319 189 pc.printf("Snap_done\r\n");
edodm85 0:19429e334b75 190 led4 = 0;
edodm85 2:bbd557817319 191 }