ov7670 library

Dependents:   Project_test Capture_bw_portin Capture_bw_v3 Project_190659132

Committer:
sebbarpar
Date:
Sat Jun 20 11:07:03 2020 +0000
Revision:
6:b1b77891bddf
Parent:
5:46b8114bb5dd
Child:
8:39ad588f56e5
uh

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edodm85 0:810d59d0b843 1 //
edodm85 0:810d59d0b843 2 // OV7670 library
edodm85 0:810d59d0b843 3 //
edodm85 0:810d59d0b843 4
edodm85 0:810d59d0b843 5 #pragma once
edodm85 0:810d59d0b843 6 #include "mbed.h"
edodm85 0:810d59d0b843 7 #include "ov7670reg.h"
edodm85 0:810d59d0b843 8
edodm85 0:810d59d0b843 9 #define OV7670_WRITE (0x42)
edodm85 0:810d59d0b843 10 #define OV7670_READ (0x43)
edodm85 0:810d59d0b843 11 #define OV7670_WRITEWAIT (20)
edodm85 0:810d59d0b843 12 #define OV7670_NOACK (0)
edodm85 0:810d59d0b843 13 #define OV7670_REGMAX (201)
edodm85 0:810d59d0b843 14 #define OV7670_I2CFREQ (100000)
edodm85 0:810d59d0b843 15
edodm85 0:810d59d0b843 16
edodm85 0:810d59d0b843 17 class OV7670
edodm85 0:810d59d0b843 18 {
edodm85 0:810d59d0b843 19 public:
sebbarpar 6:b1b77891bddf 20 PortIn data;
edodm85 0:810d59d0b843 21 OV7670(
edodm85 0:810d59d0b843 22 PinName sda, // Camera I2C port
edodm85 0:810d59d0b843 23 PinName scl, // Camera I2C port
edodm85 0:810d59d0b843 24 PinName vs, // VSYNC
edodm85 0:810d59d0b843 25 PinName hr, // HREF
edodm85 0:810d59d0b843 26 PinName we, // WEN
sebbarpar 6:b1b77891bddf 27 /*
sebbarpar 5:46b8114bb5dd 28 PinName d7, // D7
sebbarpar 5:46b8114bb5dd 29 PinName d6, // D6
sebbarpar 5:46b8114bb5dd 30 PinName d5, // D5
sebbarpar 5:46b8114bb5dd 31 PinName d4, // D4
sebbarpar 5:46b8114bb5dd 32 PinName d3, // D3
sebbarpar 5:46b8114bb5dd 33 PinName d2, // D2
sebbarpar 5:46b8114bb5dd 34 PinName d1, // D1
sebbarpar 5:46b8114bb5dd 35 PinName d0, // D0
sebbarpar 6:b1b77891bddf 36 */
sebbarpar 6:b1b77891bddf 37 PortName port,
sebbarpar 6:b1b77891bddf 38 int mask,
edodm85 0:810d59d0b843 39 PinName rt, // /RRST
edodm85 0:810d59d0b843 40 PinName o, // /OE
edodm85 0:810d59d0b843 41 PinName rc // RCLK
edodm85 0:810d59d0b843 42 );
edodm85 0:810d59d0b843 43
edodm85 0:810d59d0b843 44 ~OV7670();
edodm85 0:810d59d0b843 45
edodm85 0:810d59d0b843 46 void CaptureNext(void); // capture request
edodm85 0:810d59d0b843 47 bool CaptureDone(void); // capture done? (with clear)
edodm85 0:810d59d0b843 48 void WriteReg(int addr,int data); // write to camera
edodm85 0:810d59d0b843 49 int ReadReg(int addr); // read from camera
edodm85 0:810d59d0b843 50 void Reset(void); // reset reg camera
edodm85 1:d82dbad9c06b 51 int Init(char c, int n); // init reg
edodm85 0:810d59d0b843 52 void VsyncHandler(void); // vsync handler
edodm85 0:810d59d0b843 53 void HrefHandler(void); // href handler
edodm85 0:810d59d0b843 54 int ReadOnebyte(void); // Data Read
edodm85 0:810d59d0b843 55 void ReadStart(void); // Data Start
edodm85 0:810d59d0b843 56 void ReadStop(void); // Data Stop
edodm85 0:810d59d0b843 57
edodm85 0:810d59d0b843 58
edodm85 0:810d59d0b843 59 private:
edodm85 0:810d59d0b843 60 I2C _i2c;
edodm85 0:810d59d0b843 61 InterruptIn vsync,href;
sebbarpar 6:b1b77891bddf 62 //BusIn data;
sebbarpar 6:b1b77891bddf 63
edodm85 0:810d59d0b843 64 DigitalOut wen;
sebbarpar 5:46b8114bb5dd 65 /*
sebbarpar 5:46b8114bb5dd 66 DigitalIn da7;
sebbarpar 5:46b8114bb5dd 67 DigitalIn da6;
sebbarpar 5:46b8114bb5dd 68 DigitalIn da5;
sebbarpar 5:46b8114bb5dd 69 DigitalIn da4;
sebbarpar 5:46b8114bb5dd 70 DigitalIn da3;
sebbarpar 5:46b8114bb5dd 71 DigitalIn da2;
sebbarpar 5:46b8114bb5dd 72 DigitalIn da1;
sebbarpar 5:46b8114bb5dd 73 DigitalIn da0;
sebbarpar 5:46b8114bb5dd 74 */
edodm85 0:810d59d0b843 75 DigitalOut rrst,oe,rclk;
edodm85 0:810d59d0b843 76 volatile int LineCounter;
edodm85 0:810d59d0b843 77 volatile int LastLines;
edodm85 0:810d59d0b843 78 volatile bool CaptureReq;
edodm85 0:810d59d0b843 79 volatile bool Busy;
edodm85 0:810d59d0b843 80 volatile bool Done;
edodm85 0:810d59d0b843 81 };