Dependents:   OV7670_make

Files at this revision

API Documentation at this revision

Comitter:
kangmingyo
Date:
Wed Jul 31 13:09:52 2019 +0000
Parent:
6:8dac6edf2496
Commit message:
190731

Changed in this revision

ov7670.cpp Show annotated file Show diff for this revision Revisions of this file
ov7670.h Show annotated file Show diff for this revision Revisions of this file
diff -r 8dac6edf2496 -r 6c66c7f5676d ov7670.cpp
--- a/ov7670.cpp	Tue Jul 30 09:04:01 2019 +0000
+++ b/ov7670.cpp	Wed Jul 31 13:09:52 2019 +0000
@@ -8,11 +8,12 @@
     _i2c.frequency(OV7670_I2CFREQ);
     vsync.fall(this,&OV7670::VsyncHandler2);
     vsync.rise(this,&OV7670::VsyncHandler);
-    pclk.rise(this,&OV7670::pclkHandler); // interrupt fall edge
+   pclk.rise(this,&OV7670::pclkHandler); // interrupt fall edge
     vsync.disable_irq();  
     pclk.disable_irq(); 
     _x=0;
-    _y=0; 
+    _y=0;
+
  //   href.enable_irq();
 
 
@@ -74,25 +75,58 @@
 //        }
 //    }
 //}
+//
+//void OV7670::pclkHandler(void){
+//    
+//    while(vsync) {
+// //       _y++;
+//        if(href==1) {
+//            while(!pclk);
+//           // printf("Doing!\r\n");
+//            _x++;
+//            while(pclk);
+//        }
+//    }
+//    if(_x){
+//     printf("_x=%d _y=%d\r\n",_x,_y);
+//    }
+//    _x=0;
+//}
+//
+//void OV7670::VsyncHandler2(void)
+//{  
+//     flag=0;
+////     pclk.disable_irq();
+//     printf("_x=%d _y=%d\r\n",_x,_y);
+//     _x=0;
+//}
+//
+//void OV7670::VsyncHandler(void)
+//{  
+//    while(!vsync);      
+//    _y++;
+//    flag=1;
+//    pclkHandler();
+//     while(vsync);   
+//}
 
+ 
 void OV7670::pclkHandler(void){
     if(href==1){
-       printf("%x",data.read());
-    
-}
+     _x++;
+    }
 }
-
+ 
 void OV7670::VsyncHandler2(void)
-{  
+{   
+    printf("x: %d\r\n",_x);
      pclk.disable_irq();
 }
-
+ 
 void OV7670::VsyncHandler(void)
-{  
+{  _x=0;
     pclk.enable_irq(); 
 }
-
-
 // Data Read
 //int OV7670::ReadOnebyte(void)
 //{
@@ -165,7 +199,8 @@
     WriteReg(REG_COM10, 0x02);               // 0x02   VSYNC negative (http://nasulica.homelinux.org/?p=959)
     WriteReg(REG_MVFP, 0x27);                // mirror image 
 
-    WriteReg(REG_CLKRC, 0x80);               // prescaler x1     
+//     WriteReg(REG_CLKRC, 0x80);
+    WriteReg(REG_CLKRC, 0x92);               // prescaler x1     
     WriteReg(DBLV, 0x3A);                    // bypass PLL 
         
     WriteReg(REG_COM11, 0x0A) ;
@@ -177,7 +212,13 @@
     {
         WriteReg(REG_COM7, 0x00);           // YUV
         WriteReg(REG_COM17, 0x00);          // color bar disable
-        WriteReg(REG_COM3, 0x04);
+        WriteReg(REG_COM3, 0x0C);
+        WriteReg(0x12, 0x00);//COM7
+        WriteReg(0x8C, 0x00);//RGB444
+        WriteReg(0x04, 0x00);//COM1
+        WriteReg(0x40, 0xC0);//COM15
+        WriteReg(0x14, 0x1A);//COM9
+        WriteReg(0x3D, 0x40);//COM13
         WriteReg(REG_COM15, 0xC0);          // Set normal rgb with Full range
 
     }
@@ -187,7 +228,8 @@
         WriteReg(REG_COM7, 0x04);           // RGB + color bar disable 
         WriteReg(REG_RGB444, 0x00);         // Disable RGB444
         WriteReg(REG_COM15, 0x10);          // Set rgb565 with Full range    0xD0
-        WriteReg(REG_COM3, 0x4);
+        WriteReg(REG_COM3, 0x4); 
+
 //        WriteReg(REG_CLKRC, 0x80);          // prescaler x1 
     }
       
@@ -371,10 +413,12 @@
     if(n == 76800)              // 320*240
     {
 //        WriteReg(REG_COM14, 0x19);
+     WriteReg(REG_COM7, 0x10);
         WriteReg(REG_COM14, 0x00);           
         WriteReg(0x72, 0x11);
         WriteReg(0x73, 0xf1);
-        WriteReg(REG_HREF, 0x24); 
+//        WriteReg(REG_HREF, 0x24);
+        WriteReg(REG_HREF, 0xA4);  
         WriteReg(REG_HSTART, 0x16);
         WriteReg(REG_HSTOP, 0x04);
         WriteReg(REG_VREF, 0x0a);           
@@ -540,7 +584,7 @@
         WriteReg(REG_TSLB,  0x04);    
         WriteReg(REG_COM7, 0x01);        
         WriteReg(DBLV, 0x4a); 
-        WriteReg(REG_COM3, 0);        
+        WriteReg(REG_COM3, 0x00);        
         WriteReg(REG_COM14, 0);
         
         WriteReg(REG_HSTART, 0x13);   
diff -r 8dac6edf2496 -r 6c66c7f5676d ov7670.h
--- a/ov7670.h	Tue Jul 30 09:04:01 2019 +0000
+++ b/ov7670.h	Wed Jul 31 13:09:52 2019 +0000
@@ -50,10 +50,9 @@
         int ReadOnebyte(void);               // Data Read
         void ReadStart(void);                // Data Start
         void ReadStop(void);                 // Data Stop
-//        char ram_data[640][480];
-        InterruptIn vsync;
-        InterruptIn pclk;
-       
+//        char ram_data[640][480]; 
+        InterruptIn vsync,pclk;
+ //       uint8_t data_message[76800 ];
         
     private:
         int _x,_y;
@@ -71,4 +70,5 @@
         volatile bool Done; 
         long cnt;
         char *format_temp;
+        volatile int flag;
 };