Edoardo De Marchi / Mbed 2 deprecated OV7670_Test_Code

Dependencies:   MODSERIAL mbed ov7670

Dependents:   OV7670_Test_Code

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  * Author: Edoardo De Marchi
00003  * Date: 07/04/13
00004  * Notes: OV7670 + FIFO AL422B camera test
00005 */
00006 
00007 #include "main.h"
00008 
00009 #define VGA     307200         //640*480
00010 #define QVGA    76800          //320*240
00011 #define QQVGA   19200          //160*120
00012 
00013 static char format = ' ';
00014 static int resolution = 0;
00015 
00016 
00017 void rxCallback(MODSERIAL_IRQ_INFO *q) 
00018 {
00019      new_send = true;
00020 }
00021 
00022 int main() 
00023 {  
00024     pc.baud(921600);       
00025     pc.printf("SystemCoreClock: %dMHz\r\n", SystemCoreClock/1000000);       // print the clock frequency
00026     led4 = 0;
00027   
00028     t.start();
00029     pc.attach(&rxCallback, MODSERIAL::RxIrq);
00030 
00031     while(1) 
00032     { 
00033         if(new_send)
00034         {
00035             int i = 0;
00036        
00037             while(pc.readable())
00038             {
00039                 word[i] = pc.getc();
00040                 i++;
00041             }
00042             parse_cmd(); 
00043         }            
00044         wait_ms(50);
00045     }
00046 }
00047 
00048 
00049 
00050 void parse_cmd()
00051 {
00052             new_send = false;
00053             
00054             if(strcmp("snap", word) == 0)              
00055             {
00056                     CameraSnap();
00057                     memset(word, 0, sizeof(word));      
00058             }else
00059             if(strcmp("init_bw_VGA", word) == 0)                    // Set up for 640*480 pixels RAW    
00060             {
00061                     format = 'b';
00062                     resolution = VGA;
00063                     if(camera.Init('b', VGA) != 1)
00064                     {
00065                       pc.printf("Init Fail\r\n");
00066                     }
00067                     pc.printf("Initializing done\r\n");
00068                     memset(word, 0, sizeof(word));
00069             }else  
00070             if(strcmp("init_yuv_QVGA", word) == 0)                  // Set up for 320*240 pixels YUV422   
00071             {
00072                     format = 'y';
00073                     resolution = QVGA;
00074                     if(camera.Init('b', QVGA) != 1)
00075                     {
00076                       pc.printf("Init Fail\r\n");
00077                     }
00078                     pc.printf("Initializing done\r\n");
00079                     memset(word, 0, sizeof(word));
00080             }else  
00081             if(strcmp("init_rgb_QVGA", word) == 0)                  // Set up for 320*240 pixels RGB565   
00082             {
00083                     format = 'r';
00084                     resolution = QVGA;
00085                     if(camera.Init('r', QVGA) != 1)
00086                     {
00087                       pc.printf("Init Fail\r\n");
00088                     }
00089                     pc.printf("Initializing done\r\n");
00090                     memset(word, 0, sizeof(word));
00091             }else 
00092             if(strcmp("init_bw_QVGA", word) == 0)                  // Set up for 320*240 pixels YUV (Only Y)         
00093             {
00094                     format = 'b';
00095                     resolution = QVGA;
00096                     if(camera.Init('b', QVGA) != 1)
00097                     {
00098                       pc.printf("Init Fail\r\n");
00099                     }
00100                     pc.printf("Initializing done\r\n");
00101                     memset(word, 0, sizeof(word));
00102             }else  
00103             if(strcmp("init_yuv_QQVGA", word) == 0)                 // Set up for 160*120 pixels YUV422
00104             {                            
00105                     format = 'y';
00106                     resolution = QQVGA;
00107                     if(camera.Init('b', QQVGA) != 1)
00108                     {
00109                       pc.printf("Init Fail\r\n");
00110                     }
00111                     pc.printf("Initializing done\r\n");
00112                     memset(word, 0, sizeof(word));
00113             }else   
00114             if(strcmp("init_rgb_QQVGA", word) == 0)                 // Set up for 160*120 pixels RGB565
00115             {                            
00116                     format = 'r';
00117                     resolution = QQVGA;
00118                     if(camera.Init('r', QQVGA) != 1)
00119                     {
00120                       pc.printf("Init Fail\r\n");
00121                     }
00122                     pc.printf("Initializing done\r\n");
00123                     memset(word, 0, sizeof(word));
00124             }else
00125             if(strcmp("init_bw_QQVGA", word) == 0)                 // Set up for 160*120 pixels YUV (Only Y)
00126             {                        
00127                     format = 'b';
00128                     resolution = QQVGA;
00129                     if(camera.Init('b', QQVGA) != 1)
00130                     {
00131                       pc.printf("Init Fail\r\n");
00132                     }
00133                     pc.printf("Initializing done\r\n");
00134                     memset(word, 0, sizeof(word));
00135             }else
00136             if(strcmp("reset", word) == 0)              
00137             {
00138                     mbed_reset();        
00139             }else
00140             if(strcmp("time", word) == 0)              
00141             {
00142                     pc.printf("Tot time acq + send (mbed): %dms\r\n", t2-t1);
00143                     memset(word, 0, sizeof(word));
00144             }else
00145             if(strcmp("reg_status", word) == 0)              
00146             {  
00147                     int i = 0;
00148                     pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F");
00149                     for (i=0;i<OV7670_REGMAX;i++) 
00150                     {
00151                         int data;
00152                         data = camera.ReadReg(i); // READ REG
00153                         if ((i & 0x0F) == 0) 
00154                         {
00155                             pc.printf("\r\n%02X : ",i);
00156                         }
00157                         pc.printf("%02X ",data);
00158                     }
00159                     pc.printf("\r\n");
00160             }
00161             
00162             memset(word, 0, sizeof(word));
00163             
00164 }
00165 
00166 
00167 void CameraSnap()
00168 {
00169         led4 = 1;
00170 
00171                 // Kick things off by capturing an image
00172         camera.CaptureNext();
00173         while(camera.CaptureDone() == false);      
00174                 // Start reading in the image data from the camera hardware buffer                   
00175         camera.ReadStart();  
00176         t1 = t.read_ms();
00177         
00178         for(int x = 0; x<resolution; x++)
00179         {
00180                // Read in the first half of the image
00181                if(format == 'b' && resolution != VGA)
00182                {
00183                     camera.ReadOnebyte();
00184                }else
00185                if(format == 'y' || format == 'r')
00186                {
00187                     pc.putc(camera.ReadOnebyte());
00188                }     
00189                // Read in the Second half of the image
00190                pc.putc(camera.ReadOnebyte());      // Y only         
00191         }
00192        
00193         camera.ReadStop();
00194         t2 = t.read_ms(); 
00195         
00196         camera.CaptureNext();
00197         while(camera.CaptureDone() == false);             
00198         
00199         pc.printf("Snap_done\r\n");   
00200         led4 = 0;
00201 }