bx-cam

Dependencies:   mbed-rtos mbed

Fork of rtos_basic by mbed official

Revision:
7:f990f03bc2b2
Parent:
3:c92e21f305d8
Child:
8:025a9d74a731
--- a/main.cpp	Tue Jun 04 16:01:32 2013 +0100
+++ b/main.cpp	Fri Jul 04 14:29:56 2014 +0000
@@ -1,21 +1,283 @@
 #include "mbed.h"
 #include "rtos.h"
+#include "main.h"
+#include "ov7670.h"
  
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
+
+ 
+ /*
+  OV7670(
+            PinName sda,    // Camera I2C port
+            PinName scl,    // Camera I2C port
+            PinName vs, l8 aa    // VS YNC
+            PinName hr,     // HREF
+            PinName we,     // WEN
+                      
+            PortName port,  // 8bit bus port
+            int mask,       // 0b0000_0M65_4000_0321_L000_0000_0000_0000 = 0x07878000
+            
+            PinName rt,     // /RRST
+            PinName o,      // /OE
+            PinName rc      // RCLK      
+            );
+ 
+ 
+ */
+
+
+
+ OV7670 camera(PTE0,PTE1,PTD6,PTD7,PTE31,PortC,0x1983C,PTB8,PTB9,PTB10); 
+
+
+
+
+
+
+
+
+
+#define VGA     307200         //640*480
+#define QVGA    76800          //320*240
+#define QQVGA   19200          //160*120
+ 
+static char format = ' ';
+static int resolution = 0;
+ 
+ 
+void rxCallback()  
+{     
+     pc.putc( pc.getc() );
+     new_send = true;
+}
+
+I2C i2c(PTE0, PTE1);
+ 
+ /*
+int main() {
+  
+    while (1) {
+      
+        i2c.write('l');
+ 
+        wait(0.5);
+ 
+      
+ 
+    }
+}*/
+
+
+ 
+int main() 
+{  
+    pc.baud(115200);       
+    pc.printf("SystemCoreClock: %dMHz\r\n", SystemCoreClock/1000000);       // print the clock frequency
+    led4 = 0;
+
+  
+  
+    t.start();
+    //pc.attach(&rxCallback);
+    
+    strcpy(word,"init_yuv_QQVGA");
+    parse_cmd();
+    
+    
+    wait_ms(50);
+    
+    strcpy(word,"snap");
+    parse_cmd();
+    
+    
+    
+    
+    /*while(1) 
+    {   
+    
+        if(new_send)
+        {
+            int i = 0;
+            
+     
+           
+     
+            while(pc.readable())
+            {
+                word[i] = pc.getc();
+                i++;
+            }
+            parse_cmd();
+            i=0;
+        }
+        
+        wait_ms(50);
+    }*/
+    
+}
+
+
  
-void led2_thread(void const *args) {
-    while (true) {
-        led2 = !led2;
-        Thread::wait(1000);
-    }
+void parse_cmd()
+{
+            new_send = false;
+            
+            if(strcmp("snap", word) == 0)              
+            {
+                    CameraSnap();
+                    memset(word, 0, sizeof(word));      
+            }else
+            if(strcmp("init_bw_VGA", word) == 0)                    // Set up for 640*480 pixels RAW    
+            {       
+            
+                    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   
+            {
+                    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_rgb_QVGA", word) == 0)                  // Set up for 320*240 pixels RGB565   
+            {
+                    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)         
+            {
+                    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   ////////
+            {                            
+                  
+                    format = 'y';
+                    resolution = QQVGA;
+                    
+                    //pc.printf("ReadReg = %o\r\n",camera.Init('b', 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
+            {                            
+                    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_bw_QQVGA", word) == 0)                 // Set up for 160*120 pixels YUV (Only Y)
+            {                        
+                    format = 'b';
+                    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("reset", word) == 0)              
+            {
+                    mbed_reset();        
+            }else
+            if(strcmp("time", word) == 0)              
+            {
+                    pc.printf("Tot time acq + send (mbed): %dms\r\n", t2-t1);
+                    memset(word, 0, sizeof(word));
+            }else
+            if(strcmp("reg_status", word) == 0)              
+            {  
+                    int i = 0;
+                    pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F");
+                    for (i=0;i<OV7670_REGMAX;i++) 
+                    {
+                        int data;
+                        data = camera.ReadReg(i); // READ REG
+                        if ((i & 0x0F) == 0) 
+                        {
+                            pc.printf("\r\n%02X : ",i);
+                        }
+                        pc.printf("%02X ",data);
+                    }
+                    pc.printf("\r\n");
+            }
+            
+            memset(word, 0, sizeof(word));
+            
 }
  
-int main() {
-    Thread thread(led2_thread);
-    
-    while (true) {
-        led1 = !led1;
-        Thread::wait(500);
-    }
+ 
+void CameraSnap()
+{
+        led4 = 1;
+ 
+                // Kick things off by capturing an image
+        camera.CaptureNext();
+        while(camera.CaptureDone() == false);      
+                // Start reading in the image data from the camera hardware buffer                   
+        camera.ReadStart();  
+        t1 = t.read_ms();
+          pc.printf("re: %d",resolution);
+        for(int x = 0; x<resolution; x++)
+        {
+             
+               
+               // Read in the first half of the image
+               if(format == 'b' && resolution != VGA)
+               {
+                    camera.ReadOnebyte();
+               }else
+               if(format == 'y' || format == 'r')
+               {    
+                   // pc.printf("XDDDD");
+                    pc.putc(camera.ReadOnebyte());
+               }     
+               // Read in the Second half of the image
+               pc.putc(camera.ReadOnebyte());      // Y only         
+        }
+       
+        camera.ReadStop();
+        t2 = t.read_ms(); 
+        
+        camera.CaptureNext();
+        while(camera.CaptureDone() == false);             
+        
+        pc.printf("Snap_done\r\n");   
+        led4 = 0;
 }
+
+
+