bx-cam

Dependencies:   mbed-rtos mbed

Fork of rtos_basic by mbed official

Revision:
8:025a9d74a731
Parent:
7:f990f03bc2b2
--- a/main.cpp	Fri Jul 04 14:29:56 2014 +0000
+++ b/main.cpp	Tue Jul 08 06:21:37 2014 +0000
@@ -25,8 +25,8 @@
  */
 
 
-
- OV7670 camera(PTE0,PTE1,PTD6,PTD7,PTE31,PortC,0x1983C,PTB8,PTB9,PTB10); 
+                                         //D7-D0
+ OV7670 camera(PTE0,PTE1,PTD6,PTD7,PTE31,PTC17,PTC16,PTC13,PTC12,PTC6,PTC5,PTC4,PTC3,PTB8,PTB9,PTB10); 
 
 
 
@@ -40,187 +40,37 @@
 #define QVGA    76800          //320*240
 #define QQVGA   19200          //160*120
  
-static char format = ' ';
-static int resolution = 0;
- 
+
+static int resolution =QQVGA ;
+//  char in[160][120]; 
  
-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 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)
+
+
+                     if(camera.Init('b', QQVGA) != 1)  // Set up for 160*120 pixels YUV (Only Y)
                     {
                       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;
+
+
+    
+    wait_ms(50);
+    
+    //register
+    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++) 
                     {
@@ -233,49 +83,107 @@
                         pc.printf("%02X ",data);
                     }
                     pc.printf("\r\n");
-            }
-            
-            memset(word, 0, sizeof(word));
-            
+   
+    
+    wait_ms(50);
+    
+    CameraSnap();
+    
+    
+   
+    
 }
- 
- 
+  
 void CameraSnap()
 {
         led4 = 1;
- 
+    //   pc.printf("++++++++++++++++++++++++++++++");
                 // 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++)
+      
+        char max_in=0x00;
+        char min_in=0xff;
+      
+   /*
+         for(int x = 0; x<120; x++)
+            for(int y=0;y <160;y++){
+              camera.ReadOnebyte();
+              
+              in[x][y] = camera.ReadOnebyte();
+         
+             if (  max_in <in[x][y])
+                     max_in = in[x][y];
+             
+       
+             if(min_in > in[x][y])
+                  min_in=in[x][y];
+         
+         }
+        
+        
+     */   
+     
+       
+        for(int x = 0; x<120; x++){
+            for(int y=0;y <160;y++)
         {
              
+                
+           
+                  
+                     camera.ReadOnebyte();
+                    // pc.printf("%1X " ,camera.ReadOnebyte());
+            
+               if( camera.ReadOnebyte()  > 0xe0 )
+                        pc.printf("e");
+               else if( camera.ReadOnebyte()  > 0xd0 )
+                      pc.printf("d");    
+                else if( camera.ReadOnebyte()  > 0xc0 )
+                 pc.printf("c"); 
+                 else if( camera.ReadOnebyte()  > 0xb0 )
+                 pc.printf("b"); 
+                  else if( camera.ReadOnebyte()  > 0xa0 )       
+               pc.printf("a"); 
+                   else if( camera.ReadOnebyte()  > 0x90 )
+                    pc.printf("9"); 
+                    else if( camera.ReadOnebyte()  > 0x80 )
+                     pc.printf("8"); 
+                     else if( camera.ReadOnebyte()  > 0x70 )
+                      pc.printf("7"); 
+                      else if( camera.ReadOnebyte()  > 0x60 )
+                       pc.printf("6"); 
+                       else if( camera.ReadOnebyte()  > 0x50 )
+                        pc.printf("5"); 
+                       
+                        else if( camera.ReadOnebyte()  > 0x40 )
+                         pc.printf("4"); 
+                         else if( camera.ReadOnebyte()  > 0x30 )
+                          pc.printf("3"); 
+                          else if( camera.ReadOnebyte()  > 0x20 )
+                      pc.printf("2"); 
+                          else
+                           pc.printf("1"); 
+              
+              
+               //     if( (max_in-in[x][y]) > (in[x][y]-min_in) )
+               //       pc.printf("X");
+               //      else
+               //       pc.printf(" ");     
+                
+                  
+                
                
-               // 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         
         }
-       
+        pc.printf("\r\n");
+       }
         camera.ReadStop();
-        t2 = t.read_ms(); 
-        
         camera.CaptureNext();
         while(camera.CaptureDone() == false);             
         
-        pc.printf("Snap_done\r\n");   
+        pc.printf("\r\nSnap_done\r\n");   
         led4 = 0;
 }