Mike Spadaru / physcom
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ov7670.h Source File

ov7670.h

00001 #ifndef PHYSCOM_OV_H
00002 #define PHYSCOM_OV_H
00003 
00004 #pragma once 
00005 #include "mbed.h"
00006 #include "ov7670reg.h"
00007 
00008 #define OV7670_WRITE (0x42)
00009 #define OV7670_READ  (0x43)
00010 #define OV7670_WRITEWAIT (20)
00011 #define OV7670_NOACK (0)
00012 #define OV7670_REGMAX (201)
00013 #define OV7670_I2CFREQ (100000) 
00014 
00015 namespace physcom {
00016 
00017 /**
00018  * Class used to controll the OV7670 camera. 
00019  * Using the constructor:
00020  * @code
00021  * OV7670 camera (
00022  *     p28,p27,            // SDA,SCL(I2C / SCCB)
00023  *     p23,NC,p25,         // VSYNC,HREF,WEN(FIFO)  
00024  *     Port0,0x07878000,   // PortIn data        p18(P0.26),p17(P0.25),p16(P0.24),p15(P0.23),p11(P0.18),p12(P0.17),p14(P0.16),p13(P0.15)
00025  *     p26,p29,p30         // RRST,OE,RCLK
00026  * ); 
00027  * @endcode
00028  * Before snapping a piture, the camera needs to be initialized. During the 
00029  * initialization, the format and resolution are set. Possible formats:
00030  * YUV422, RGB565. Possible resolutions: VGA (640 x 480), QVGA (320 x 240), 
00031  * QQVGA (160 x 120). See Init(char c, int n).
00032  */
00033 class OV7670
00034 {
00035     public:
00036             
00037         OV7670(
00038             PinName sda,    // Camera I2C port
00039             PinName scl,    // Camera I2C port
00040             PinName vs,     // VSYNC
00041             PinName hr,     // HREF
00042             PinName we,     // WEN
00043                       
00044             PortName port,  // 8bit bus port
00045             int mask,       // 0b0000_0M65_4000_0321_L000_0000_0000_0000 = 0x07878000
00046             
00047             PinName rt,     // /RRST
00048             PinName o,      // /OE
00049             PinName rc      // RCLK      
00050             );
00051         
00052         ~OV7670();
00053         
00054         void CaptureNext(void);              // capture request
00055         bool CaptureDone(void);              // capture done? (with clear)
00056         void WriteReg(int addr,int data);    // write to camera
00057         int ReadReg(int addr);               // read from camera
00058         void Reset(void);                    // reset reg camera
00059         int Init(char c, int n);             // Old init reg
00060         int Init(char *format, int n);       // init reg    
00061         void VsyncHandler(void);             // New vsync handler
00062         void HrefHandler(void);              // href handler
00063         int ReadOnebyte(void);               // Data Read
00064         void ReadStart(void);                // Data Start
00065         void ReadStop(void);                 // Data Stop
00066        
00067         
00068     private:
00069         I2C _i2c;
00070         InterruptIn vsync,href;
00071         
00072         DigitalOut wen;
00073         PortIn data;
00074         DigitalOut rrst,oe,rclk;
00075         volatile int LineCounter;
00076         volatile int LastLines;
00077         volatile bool CaptureReq;
00078         volatile bool Busy;
00079         volatile bool Done; 
00080         char *format_temp;
00081 };
00082 
00083 } // Namespace physcom
00084 
00085 #endif