Test Code for OV7670 Camera module with FIFO AL422

Dependencies:   MODSERIAL mbed ov7670

Dependents:   OV7670_Test_Code

You can find more information in this page: https://mbed.org/users/edodm85/notebook/ov7670-camera-module/

Files at this revision

API Documentation at this revision

Comitter:
edodm85
Date:
Sat Mar 16 13:45:09 2013 +0000
Parent:
1:922cfb5e36ba
Child:
3:b4e0cefc37f6
Commit message:
Changed parse_cmd

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
ov7670.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Mar 10 13:20:27 2013 +0000
+++ b/main.cpp	Sat Mar 16 13:45:09 2013 +0000
@@ -6,8 +6,12 @@
 
 #include "main.h"
 
-#define QQVGA 4         //320*240
-#define QVGA 2          //160*120
+#define VGA     307200         //640*480
+#define QVGA    76800          //320*240
+#define QQVGA   19200          //160*120
+
+static char format = ' ';
+static int resolution = 0;
 
 
 void rxCallback(MODSERIAL_IRQ_INFO *q) 
@@ -45,37 +49,89 @@
 void parse_cmd(){
             new_send = false;
             
-            if(strcmp("snap_yuv", word) == 0)              
+            if(strcmp("snap", word) == 0)              
             {
-                    CameraSnap('y');
+                    CameraSnap();
                     memset(word, 0, sizeof(word));      
             }else
-            if(strcmp("snap_rgb", word) == 0)              
+            if(strcmp("init_bw_VGA", word) == 0)                  // Set up for 640*480 pixels YUV (Only Y)     
             {
-                    CameraSnap('r');
+                    pc.printf("Initializing ov7670 - Format YUV422(Y only) & VGA Mode\r\n");
+                    format = 'b';
+                    resolution = VGA;
+                    if(camera.Init('b', VGA) != 1)
+                    {
+                      pc.printf("Init Fail\r\n");
+                    }
+                    pc.printf("Initializing done\r\n");
+                    memset(word, 0, sizeof(word));
+            }else  
+            if(strcmp("init_yuv_QVGA", word) == 0)                  // Set up for 320*240 pixels YUV422   
+            {
+                    pc.printf("Initializing ov7670 - Format YUV422 & QVGA Mode\r\n");
+                    format = 'y';
+                    resolution = QVGA;
+                    if(camera.Init('b', QVGA) != 1)
+                    {
+                      pc.printf("Init Fail\r\n");
+                    }
+                    pc.printf("Initializing done\r\n");
                     memset(word, 0, sizeof(word));
-                   
-            }else        
-            if(strcmp("init_yuv", word) == 0)              
+            }else  
+            if(strcmp("init_rgb_QVGA", word) == 0)                  // Set up for 320*240 pixels RGB565   
+            {
+                    pc.printf("Initializing ov7670 - Format RGB565 & QVGA Mode\r\n");
+                    format = 'r';
+                    resolution = QVGA;
+                    if(camera.Init('r', QVGA) != 1)
+                    {
+                      pc.printf("Init Fail\r\n");
+                    }
+                    pc.printf("Initializing done\r\n");
+                    memset(word, 0, sizeof(word));
+            }else 
+            if(strcmp("init_bw_QVGA", word) == 0)                  // Set up for 320*240 pixels YUV (Only Y)         
             {
-                    // Reset camera on power up
-                    camera.Reset();
-                            // Set up for 160*120 pixels YUV (Only Y)
-                    pc.printf("Initializing ov7670 - Format YUV & QQVGA Mode\r\n");
-                    if(camera.Init('y') != 1)
+                    pc.printf("Initializing ov7670 - Format YUV422(Y only) & QVGA Mode\r\n");
+                    format = 'b';
+                    resolution = QVGA;
+                    if(camera.Init('b', QVGA) != 1)
+                    {
+                      pc.printf("Init Fail\r\n");
+                    }
+                    pc.printf("Initializing done\r\n");
+                    memset(word, 0, sizeof(word));
+            }else  
+            if(strcmp("init_yuv_QQVGA", word) == 0)                 // Set up for 160*120 pixels YUV422
+            {                            
+                    pc.printf("Initializing ov7670 - Format YUV422 & QQVGA Mode\r\n");
+                    format = 'y';
+                    resolution = QQVGA;
+                    if(camera.Init('b', QQVGA) != 1)
+                    {
+                      pc.printf("Init Fail\r\n");
+                    }
+                    pc.printf("Initializing done\r\n");
+                    memset(word, 0, sizeof(word));
+            }else   
+            if(strcmp("init_rgb_QQVGA", word) == 0)                 // Set up for 160*120 pixels RGB565
+            {                            
+                    pc.printf("Initializing ov7670 - Format RGB565 & QQVGA Mode\r\n");
+                    format = 'r';
+                    resolution = QQVGA;
+                    if(camera.Init('r', QQVGA) != 1)
                     {
                       pc.printf("Init Fail\r\n");
                     }
                     pc.printf("Initializing done\r\n");
                     memset(word, 0, sizeof(word));
             }else
-            if(strcmp("init_rgb", word) == 0)              
-            {
-                    // Reset camera on power up
-                    camera.Reset();
-                            // Set up for 160*120 pixels RGB565
-                    pc.printf("Initializing ov7670 - Format RGB & QQVGA Mode\r\n");
-                    if(camera.Init('r') != 1)
+            if(strcmp("init_bw_QQVGA", word) == 0)                 // Set up for 160*120 pixels YUV (Only Y)
+            {                        
+                    pc.printf("Initializing ov7670 - Format YUV422(Y only) & QQVGA Mode\r\n");
+                    format = 'b';
+                    resolution = QQVGA;
+                    if(camera.Init('b', QQVGA) != 1)
                     {
                       pc.printf("Init Fail\r\n");
                     }
@@ -88,68 +144,48 @@
             }else
             if(strcmp("time", word) == 0)              
             {
-                    pc.printf("Time Acq from camera: %dms - Time Send to pc: %dms - Time Tot: %dms\r\n", t2-t1, t3-t2, t3-t1);
+                    pc.printf("Tot time acq + send (mbed): %dms\r\n", t2-t1);
                     memset(word, 0, sizeof(word));
-            } 
+            }
+            
             memset(word, 0, sizeof(word));
             
 }
 
 
-
-void CameraSnap(char c){
+void CameraSnap(){
         led4 = 1;
-        int var2 = 0;
-        int var = 0;
-        t1 = t.read_ms();
-         
-                // wait until the image has been captured
+
+                // Kick things off by capturing an image
         camera.CaptureNext();
-        while(camera.CaptureDone() == false);
-       
+        while(camera.CaptureDone() == false);      
                 // Start reading in the image data from the camera hardware buffer                   
         camera.ReadStart();  
+        t1 = t.read_ms();
         
-               // Read the first half of the image
-        for (int q = 0; q < SIZE; q++) 
-        {
-                bank0[q] =  camera.ReadOnebyte();
-        }
-               // Read the Second half of the image
-        for (int q = 0; q < SIZE; q++) 
+        for(int x = 0; x<resolution; x++)
         {
-                bank1[q] =  camera.ReadOnebyte();
-        }
-        
-                // Stop reading the image
-        camera.ReadStop() ; 
-        t2 = t.read_ms();          
-        
-        if(c == 'y')
-        {
-            var = 2;                    // set YUV QQVGA
-            var2 = 1;
+               // Read in the first half of the image
+               if(format == 'b')
+               {
+                    camera.ReadOnebyte();
+               }else
+               if(format == 'y' || format == 'r')
+               {
+                    pc.putc(camera.ReadOnebyte());
+               }     
+               // Read in the Second half of the image
+               pc.putc(camera.ReadOnebyte());      // Y only         
         }
-        else{
-            var = 1;                    // set RGB565 QQVGA  
-            var2 = 0;
-        }
+       
+        camera.ReadStop();
+        t2 = t.read_ms();         
         
-        for (int i = 0; i < SIZE/var; i++) {
-            pc.putc(bank0[(i*var)+var2]);       
-        }
-        for (int i = 0; i < SIZE/var; i++) {
-            pc.putc(bank1[(i*var)+var2]);       
-        }
-     
-                 // Immediately request the next image to be captured
+                 // Immediately request the next image to be captured (takes around 45ms)
         camera.CaptureNext();                             
+                // Now wait for the image to finish being captured
         while (camera.CaptureDone() == false);
-        t3 = t.read_ms();
         
-        pc.printf("Grab done\r\n"); 
-            
+        pc.printf("Snap_done\r\n");   
         led4 = 0;
-}
-
-
+}
\ No newline at end of file
--- a/main.h	Sun Mar 10 13:20:27 2013 +0000
+++ b/main.h	Sat Mar 16 13:45:09 2013 +0000
@@ -16,10 +16,6 @@
 
 
 //Camera
-#define SIZEX (160)
-#define SIZEY (120)
-#define SIZE (SIZEX*SIZEY)
-
 OV7670 camera
 (
     p28,p27,            // SDA,SCL(I2C / SCCB)
@@ -28,19 +24,16 @@
     p26,p29,p30         // RRST,OE,RCLK
 ); 
 
-unsigned char bank0 [SIZE];
-unsigned char *bank1 = (unsigned char *)(0x2007C000);
-
 //RESET
 extern "C" void mbed_reset();
 
 //Serial
-char word[8];
+char word[25];
 int t1 = 0; 
 int t2 = 0;
 int t3 = 0;
 
 //
 void parse_cmd();
-void CameraSnap(char c);
+void CameraSnap();
 void CameraGrab();
--- a/ov7670.lib	Sun Mar 10 13:20:27 2013 +0000
+++ b/ov7670.lib	Sat Mar 16 13:45:09 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/edodm85/code/ov7670/#810d59d0b843
+http://mbed.org/users/edodm85/code/ov7670/#d82dbad9c06b