OV7670 + 23LC1024 + Bluetooth

Dependencies:   FastPWM MODSERIAL mbed

Revision:
0:f309a2b2f27b
Child:
1:6e4d2cff76e8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 22 23:55:34 2013 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+#include "OV7670.h"
+#include "FastPWM.h"
+
+#define SIZEX (160)
+#define SIZEY (120)
+#define SIZE 19200
+
+OV7670 camera(
+    p28, p27,           // SDA,SCL(I2C / SCCB)
+    p21, p22, p23, p24, // XCLK, PCLK, VSYNC, HREF
+    Port0, 0x07878000); // D0-D7 -> P11-p18
+    
+Serial host(USBTX, USBRX);
+DigitalOut status(p20);
+
+unsigned char bank0[SIZE];
+unsigned char *bank1 = (unsigned char *)(0x2007C000);
+
+int hexToInt(int i) {
+    if(i >= '0' && i <= '9') return i - '0';
+    else if(i >= 'A' && i <= 'F') return i - 55;
+    else return 0;
+}
+
+int getHexWord(Serial *ser) {
+    int b1 = ser->getc();
+    int b2 = ser->getc();
+    return (hexToInt(b1) << 4) | hexToInt(b2);
+}
+
+void sendImage() {
+    // Write the image to the serial host
+    for (int i = 0; i < SIZE; i++) {
+        while(!(host.writeable())) {}
+        host.putc(bank0[i]);
+        while(!(host.writeable())) {}
+        host.putc(bank1[i]);
+    }
+}
+
+int main() {
+    host.baud(115200);
+    
+    // Initialize a 12Mhz XCLK for the camera
+    camera.Init();
+    
+    // Reset camera on power up
+    camera.Reset();
+    
+    // Set up for 160*120 pixels RGB565
+    camera.InitQQVGA();
+
+    char c;
+    while(1) {
+        if(host.readable()) {
+            c = host.getc();
+        } else {
+            continue;
+        }
+        if(c == 'r') {
+            int reg = getHexWord(&host);
+            host.printf("%d\n\r", camera.ReadReg(reg));
+        } else if(c == 'w') {
+            int reg = getHexWord(&host);
+            int val = getHexWord(&host);
+            camera.WriteReg(reg, val);
+            host.printf("%d\n\r", camera.ReadReg(reg));
+        } else if(c == 't') {
+            camera.scopeTest(&host);
+        } else if(c == 'c') {
+            status = 1;
+            int bytes = camera.captureImage(bank0, bank1);
+            //host.printf("%d\n", bytes);
+            sendImage();
+            status = 0;
+        }
+    }
+}
+