v2

Dependencies:   ov7670 FastPWM

Committer:
kangmingyo
Date:
Tue Jul 30 09:05:12 2019 +0000
Revision:
0:520e7ccaa52d
Child:
1:792b922ca3b9
v2;

Who changed what in which revision?

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