ov7670 no fifo

Dependents:   OV7670_Nucleo

Revision:
1:e216fd4e8d9c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OV6620.cpp	Mon Nov 21 10:04:38 2016 +0000
@@ -0,0 +1,179 @@
+#include "mbed.h"
+#include "OV6620reg.h"
+#include "OV6620.h"
+
+    void OV6620::CaptureNext(void) {
+        CaptureReq = true ;
+        Busy = true ;
+    }
+
+    bool OV6620::CaptureDone(void) {
+        bool result ;
+        if (Busy) {
+            result = false ;
+        } else {
+            result = Done ;
+            Done = false ;
+        }
+        return result ;
+    }
+
+    void OV6620::WriteReg(int addr,int data) {
+        camera.start();
+        //camera.write(CAMERA_I2C_WRITE_ADDR);
+        camera.write(addr);
+        camera.write(data);
+        camera.stop();
+        wait_us(50);
+    }
+
+    int OV6620::ReadReg(int addr) {
+        int data ;
+        camera.start() ;
+        camera.write(OV6620_WRITE) ;
+        wait_us(OV6620_WRITEWAIT);
+        camera.write(addr) ;
+        camera.stop() ;
+        wait_us(OV6620_WRITEWAIT);
+        camera.start() ;
+        camera.write(OV6620_READ) ;
+        wait_us(OV6620_WRITEWAIT);
+        data = camera.read(OV6620_NOACK) ;
+        camera.stop() ;
+        return data ;
+    }
+
+    int OV6620::Rreg(int addr) {
+        int data ;
+        camera.start() ;
+        camera.write(OV6620_WRITE) ;
+        wait_us(OV6620_WRITEWAIT);
+        camera.write(addr) ;
+        camera.stop() ;
+        wait_us(OV6620_WRITEWAIT);
+        camera.start() ;
+        camera.write(OV6620_READ) ;
+        wait_us(OV6620_WRITEWAIT);
+        data = camera.read(OV6620_NOACK) ;
+        camera.stop() ;
+        return data ;
+    }
+
+    void OV6620::Reset(void) {
+        WriteReg(0x12,0xa4) ; // RESET CAMERA
+        wait_ms(200) ;
+    }
+
+    void OV6620::Wreg (int addr,int data) {
+        camera.start();
+        camera.write(CAMERA_I2C_WRITE_ADDR);
+        camera.write(addr);
+        camera.write(data);
+        camera.stop();
+        wait_us(50);
+    }
+
+    void OV6620::InitQQVGA(void) {
+
+        xclk..period(1/24000000.0);
+        xclk.write(.5);
+
+        Reset();
+        Reset();
+        WriteReg(CLKRC,0x00);
+        WriteReg(COM_A,0x24);
+        WriteReg(COM_C,0x20);
+
+        wait(0.1);
+    }
+
+    // vsync handler
+    void OV6620::VsyncHandler(void) {
+FrameCounter++;
+    }
+
+    // href handler
+    void OV6620::HrefHandler(void) {
+        LineCounter++ ;
+    }
+
+    // pclk handler
+    void OV6620::PclkHandler(void) {
+        PixCounter++ ;
+    }
+
+    void OV6620::wait_posedge(InterruptIn pin) {
+        while(pin);
+        while(!pin);
+    }
+
+    void OV6620::wait_negedge(InterruptIn pin) {
+        while(!pin);
+        while(pin) ;
+    }
+
+    // Data Read
+    int OV6620::ReadOneByte(void) {
+        int result = (((dataP&0x07800000)>>19)|((dataP&0x078000)>>15));
+        return result ;
+    }
+
+
+    void OV6620::shot(void) {
+     uint8_t b1,b2;
+        int x = 0,pix=0; // col
+        int y = 0,line=0; // row
+        int n = 0; //  px number
+        int r,g,b;
+    
+        while(vsync); 
+       while(!vsync); //   pc.printf("!vsync 1  %d  %d  %d\r\n", vsync& 0x1,href& 0x1,pclk& 0x1);
+          while(vsync); 
+       while(!vsync);
+       while(vsync);
+       
+       for ( y=0; y<SIZEY; y++){
+        while (!href);
+        for ( x=0; x<SIZEX; x++){
+           
+            while(!pclk);
+            if (line>0){
+               b1=dataP;
+             result=dataP.read();
+            }
+            while (pclk);
+        
+         while(!pclk);
+            if (line>0){
+               b2=dataP;
+             result=dataP.read();
+            }
+            while (pclk);
+               
+               r=((bank1 & 0x1f)) ;
+            g= ((bank1&0xe0)>>5 ) | ((bank0&0x7)<<3);
+                 b=((bank0 & 0xf8)>>3 );
+                 colour = (((r<<11)&0xF800)|((g<<5)&0x7E0)| (b&0x1f));
+          TFT.pixel(x,y,colour);
+        }
+        while(href);
+    }
+        
+        printf("x , y =  %d , %d      n= %d\r\n", x,y,FrameCounter);
+        printf("frame\n");
+        n=0;
+        y=0;
+        x=0;
+        /*
+        for(y=0; y<SIZEY; y++) {
+            for(x=0; x<SIZEX; x++) {
+//         pc.printf("%d %d\n",n,byt[n]);
+              //   pc.printf("%u\n",b1[n]);
+                //TFT.pixel(x,y,b1[n]);
+                n++;
+            }
+        }
+        */
+        printf("enddddddddd frame\n");
+    }// SHOT
+}
\ No newline at end of file