Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ov7670.cpp
- Revision:
- 3:b40a945dd672
- Parent:
- 2:354a00023f79
- Child:
- 4:119b4c04a4ed
- Child:
- 5:46b8114bb5dd
--- a/ov7670.cpp Sun Apr 07 10:47:47 2013 +0000
+++ b/ov7670.cpp Sat Feb 15 15:00:37 2014 +0000
@@ -6,7 +6,6 @@
_i2c.stop();
_i2c.frequency(OV7670_I2CFREQ);
vsync.fall(this,&OV7670::VsyncHandler); // interrupt fall edge
- href.rise(this,&OV7670::HrefHandler); // interrupt rise edge
CaptureReq = false;
Busy = false;
Done = false;
@@ -17,69 +16,98 @@
wen = 0;
}
+
OV7670::~OV7670()
{
+}
-}
// capture request
void OV7670::CaptureNext(void)
{
- CaptureReq = true ;
- Busy = true ;
+ CaptureReq = true;
+ Busy = true;
}
+
// capture done? (with clear)
bool OV7670::CaptureDone(void)
{
- bool result ;
- if (Busy) {
- result = false ;
- } else {
- result = Done ;
- Done = false ;
+ bool result;
+ if (Busy)
+ {
+ result = false;
+ }else
+ {
+ result = Done;
+ Done = false;
}
- return result ;
+ return result;
}
-// write to camera
-void OV7670::WriteReg(int addr,int data)
-{
- _i2c.start() ;
- _i2c.write(OV7670_WRITE) ;
- wait_us(OV7670_WRITEWAIT);
- _i2c.write(addr) ;
- wait_us(OV7670_WRITEWAIT);
- _i2c.write(data) ;
- _i2c.stop() ;
+
+// vsync handler
+void OV7670::VsyncHandler(void)
+{
+ // Capture Enable
+ if (CaptureReq)
+ {
+ wen = 1;
+ Done = false;
+ CaptureReq = false;
+ }else
+ {
+ wen = 0;
+ if (Busy)
+ {
+ Busy = false;
+ Done = true;
+ }
+ }
}
-// read from camera
-int OV7670::ReadReg(int addr)
+
+// Data Read
+int OV7670::ReadOnebyte(void)
{
- int data ;
-
- _i2c.start() ;
- _i2c.write(OV7670_WRITE) ;
- wait_us(OV7670_WRITEWAIT);
- _i2c.write(addr) ;
- _i2c.stop() ;
- wait_us(OV7670_WRITEWAIT);
-
- _i2c.start() ;
- _i2c.write(OV7670_READ) ;
- wait_us(OV7670_WRITEWAIT);
- data = _i2c.read(OV7670_NOACK) ;
- _i2c.stop() ;
-
- return data ;
+ int B1;
+ rclk = 1;
+ B1 = (((data&0x07800000)>>19)|((data&0x078000)>>15));
+ rclk = 0;
+ return B1;
}
-void OV7670::Reset(void) {
- WriteReg(0x12, 0x80) ; // RESET CAMERA
- wait_ms(200) ;
+
+// Data Start read from FIFO
+void OV7670::ReadStart(void)
+{
+ rrst = 0;
+ oe = 0;
+ wait_us(1);
+ rclk = 0;
+ wait_us(1);
+ rclk = 1;
+ wait_us(1);
+ rrst = 1;
}
+
+// Data Stop read from FIFO
+void OV7670::ReadStop(void)
+{
+ oe = 1;
+ ReadOnebyte();
+ rclk = 1;
+}
+
+
+void OV7670::Reset(void)
+{
+ WriteReg(0x12, 0x80); // RESET CAMERA
+ wait_ms(200);
+}
+
+
int OV7670::Init(char c, int n)
{
@@ -92,7 +120,7 @@
Reset(); // Resets all registers to default values
WriteReg(REG_RGB444, 0x00); // Disable RGB444
- WriteReg(REG_COM10, 0x02); // 0x02 VSYNC negative (http://nasulica.homelinux.org/?p=959)
+ WriteReg(REG_COM10, 0x02); // 0x02 VSYNC negative (http://thinksmallthings.wordpress.com/2012/03/10/cf7670c-vs-cf7670c-v2/)
WriteReg(REG_MVFP, 0x27); // mirror image
WriteReg(REG_CLKRC, 0x80); // prescaler x1
@@ -232,7 +260,7 @@
WriteReg(0x01, 0x40);
WriteReg(0x02, 0x40);
WriteReg(0x13, 0xe7);
- WriteReg(0x15, 0x02);
+ //WriteReg(0x15, 0x02);
WriteReg(0x4f, 0x80);
WriteReg(0x50, 0x80);
@@ -401,7 +429,7 @@
WriteReg(0x01, 0x40);
WriteReg(0x02, 0x40);
WriteReg(0x13, 0xe7);
- WriteReg(0x15, 0x02);
+ //WriteReg(0x15, 0x02);
WriteReg(0x4f, 0x80);
WriteReg(0x50, 0x80);
WriteReg(0x51, 0x00);
@@ -640,61 +668,38 @@
return 1;
}
-// vsync handler
-void OV7670::VsyncHandler(void)
+
+
+
+// write to camera
+void OV7670::WriteReg(int addr,int data)
{
-
- // Capture Enable
- if (CaptureReq) {
- wen = 1 ;
- Done = false ;
- CaptureReq = false ;
- } else {
- wen = 0 ;
- if (Busy) {
- Busy = false ;
- Done = true ;
- }
- }
-
- // Hline Counter
- LastLines = LineCounter ;
- LineCounter = 0 ;
-}
-
-// href handler
-void OV7670::HrefHandler(void)
-{
- LineCounter++ ;
+ _i2c.start();
+ _i2c.write(OV7670_WRITE);
+ wait_us(OV7670_WRITEWAIT);
+ _i2c.write(addr);
+ wait_us(OV7670_WRITEWAIT);
+ _i2c.write(data);
+ _i2c.stop();
}
-// Data Read
-int OV7670::ReadOnebyte(void)
+// read from camera
+int OV7670::ReadReg(int addr)
{
- int B1;
- rclk = 1;
- B1 = (((data&0x07800000)>>19)|((data&0x078000)>>15));
- rclk = 0;
- return B1;
-}
+ int data;
+
+ _i2c.start();
+ _i2c.write(OV7670_WRITE);
+ wait_us(OV7670_WRITEWAIT);
+ _i2c.write(addr);
+ _i2c.stop();
+ wait_us(OV7670_WRITEWAIT);
-// Data Start read from FIFO
-void OV7670::ReadStart(void)
-{
- rrst = 0 ;
- oe = 0 ;
- wait_us(1) ;
- rclk = 0 ;
- wait_us(1) ;
- rclk = 1 ;
- wait_us(1) ;
- rrst = 1 ;
-}
+ _i2c.start();
+ _i2c.write(OV7670_READ);
+ wait_us(OV7670_WRITEWAIT);
+ data = _i2c.read(OV7670_NOACK);
+ _i2c.stop();
-// Data Stop read from FIFO
-void OV7670::ReadStop(void)
-{
- oe = 1 ;
- ReadOnebyte() ;
- rclk = 1 ;
+ return data;
}
\ No newline at end of file