Samuel Pullman / Mbed 2 deprecated CameraTest

Dependencies:   FastPWM MODSERIAL mbed

Revision:
1:6e4d2cff76e8
Parent:
0:f309a2b2f27b
--- a/OC7670.cpp	Mon Jul 22 23:55:34 2013 +0000
+++ b/OC7670.cpp	Tue Jul 23 06:33:27 2013 +0000
@@ -11,15 +11,13 @@
     PortName port, // 8bit bus port
     int mask // 0000 0111 4000 0111 1000 0000 0000 0000 = 0x07878000
     
-    ) : camera(sda,scl), data(port, mask), inPort(Port2, 0x0000001C)
+    ) : camera(sda,scl), data(port, mask), inPort(Port2, 0x0000001C),  spi(p5, p6, p7), ram(spi, p8)
 {
     camera.stop();
     camera.frequency(OV7670_I2CFREQ);
-    CaptureReq = false;
-    Busy = false;
-    Done = false;
-    LineCounter = 0;
     xclkPin = xclk;
+    spi.frequency(16000000);
+    size = 0;
 }
 
 void OV7670::Init() {
@@ -114,6 +112,7 @@
     WriteReg(0x6f,0x9f);
 
     WriteReg(0xb0,0x84);
+    size = 160 * 120 * 2;
 }
 
 void OV7670::scopeTest(Serial *host) {
@@ -135,10 +134,12 @@
     //printf("Avg on, off = %d, %d\n\r", t1.read_us()/100, t2.read_us()/100);
 }
 
-int OV7670::captureImage(unsigned char *arr1, unsigned char* arr2) {
+int OV7670::captureImage() {
     int d, i=0;
     int byte = 0;
     Timer t1;
+    // Prepare SRAM output
+    ram.startWriteSequence();
     // Read in the first half of the image
     while(inPort & 0x00000008) {};    // Wait for VSYNC low
     while(!(inPort & 0x00000008)) {}; // Wait for VSYNC high
@@ -154,17 +155,38 @@
             d = data;
             byte  = (d & 0x07800000) >> 19; // bit26 to bit7
             byte |= (d & 0x00078000) >> 15; // bit18 to bit3
-            arr1[i] = byte;
+            //arr1[i] = byte;
+            ram.writeSequence1(byte);
             while(inPort & 0x00000010) {};        // Wait for PCLK low
             while(!(inPort & 0x00000010)) {};  // Wait for PCLK high
             d = data;
             byte  = (d & 0x07800000) >> 19; // bit26 to bit7
             byte |= (d & 0x00078000) >> 15; // bit18 to bit3
-            arr2[i++] = byte;
+            ram.writeSequence1(byte);
+            //arr2[i++] = byte;
             while(inPort & 0x00000010) {}; 
+            i++;
         }
     }
+    //t1.stop();
+    ram.stopSequence();
     //printf("Image read: %d\n\r", t1.read_us());
     return i*2;
 }
+
+
+void OV7670::sendImage(Serial *dest, int numBytes) {
+    Timer t;
+    Serial host = *dest;
+    // Write the image to the serial host
+    ram.startReadSequence();
+    t.start();
+    for (int i = 0; i < numBytes; i++) {
+        while(!(host.writeable())) {}
+        host.putc(ram.readSequence1());
+    }
+    t.stop();
+    printf("BT time: %d\n\r", t.read_us());
+    ram.stopSequence();
+}
     
\ No newline at end of file