kevin eccli
/
AcquisitionCamera2
Test Acquis Cam2D
main.cpp@0:05d03cca2089, 2015-02-07 (annotated)
- Committer:
- singularity
- Date:
- Sat Feb 07 17:21:20 2015 +0000
- Revision:
- 0:05d03cca2089
Bruckner
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
singularity | 0:05d03cca2089 | 1 | #include "mbed.h" |
singularity | 0:05d03cca2089 | 2 | #include "ov7670.h" |
singularity | 0:05d03cca2089 | 3 | |
singularity | 0:05d03cca2089 | 4 | |
singularity | 0:05d03cca2089 | 5 | #define I2C_D D15 |
singularity | 0:05d03cca2089 | 6 | #define I2C_CLK D14 |
singularity | 0:05d03cca2089 | 7 | #define VSYNC PTD5 |
singularity | 0:05d03cca2089 | 8 | #define HREF PTD6 |
singularity | 0:05d03cca2089 | 9 | #define WEN PTD7 |
singularity | 0:05d03cca2089 | 10 | #define RRST PTC6 |
singularity | 0:05d03cca2089 | 11 | #define OE PTC3 |
singularity | 0:05d03cca2089 | 12 | #define RCLK PTA4 |
singularity | 0:05d03cca2089 | 13 | #define D0 PTC5 |
singularity | 0:05d03cca2089 | 14 | #define D1 PTC10 |
singularity | 0:05d03cca2089 | 15 | #define D2 PTC7 |
singularity | 0:05d03cca2089 | 16 | #define D3 PTC9 |
singularity | 0:05d03cca2089 | 17 | #define D4 PTC8 |
singularity | 0:05d03cca2089 | 18 | #define D5 PTA12 |
singularity | 0:05d03cca2089 | 19 | #define D6 PTA13 |
singularity | 0:05d03cca2089 | 20 | #define D7 PTA5 |
singularity | 0:05d03cca2089 | 21 | |
singularity | 0:05d03cca2089 | 22 | #define SIZEX (160) |
singularity | 0:05d03cca2089 | 23 | #define SIZEY (120) |
singularity | 0:05d03cca2089 | 24 | |
singularity | 0:05d03cca2089 | 25 | |
singularity | 0:05d03cca2089 | 26 | DigitalOut led_red(LED_RED); |
singularity | 0:05d03cca2089 | 27 | OV7670 camera(I2C_D,I2C_CLK,VSYNC,HREF,WEN,D0,D1,D2,D3,D4,D5,D6,D7,RRST,OE,RCLK); |
singularity | 0:05d03cca2089 | 28 | Serial pc(USBTX,USBRX); |
singularity | 0:05d03cca2089 | 29 | |
singularity | 0:05d03cca2089 | 30 | int main() |
singularity | 0:05d03cca2089 | 31 | { |
singularity | 0:05d03cca2089 | 32 | int i ; |
singularity | 0:05d03cca2089 | 33 | |
singularity | 0:05d03cca2089 | 34 | pc.printf("Camera resetting..\r\n") ; |
singularity | 0:05d03cca2089 | 35 | camera.Reset() ; |
singularity | 0:05d03cca2089 | 36 | |
singularity | 0:05d03cca2089 | 37 | pc.printf("Before Init...\r\n") ; |
singularity | 0:05d03cca2089 | 38 | pc.printf("Lecture Registres...\r\n") ; |
singularity | 0:05d03cca2089 | 39 | pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F") ; |
singularity | 0:05d03cca2089 | 40 | for (i=0;i<OV7670_REGMAX;i++) { |
singularity | 0:05d03cca2089 | 41 | int data ; |
singularity | 0:05d03cca2089 | 42 | data = camera.ReadReg(i) ; // READ REG |
singularity | 0:05d03cca2089 | 43 | if ((i & 0x0F) == 0) { |
singularity | 0:05d03cca2089 | 44 | pc.printf("\r\n%02X : ",i) ; |
singularity | 0:05d03cca2089 | 45 | } |
singularity | 0:05d03cca2089 | 46 | pc.printf("%02X ",data) ; |
singularity | 0:05d03cca2089 | 47 | } |
singularity | 0:05d03cca2089 | 48 | |
singularity | 0:05d03cca2089 | 49 | |
singularity | 0:05d03cca2089 | 50 | pc.printf("\r\n") ; |
singularity | 0:05d03cca2089 | 51 | camera.InitQQVGA() ; |
singularity | 0:05d03cca2089 | 52 | |
singularity | 0:05d03cca2089 | 53 | pc.printf("After Init...\r\n") ; |
singularity | 0:05d03cca2089 | 54 | pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F") ; |
singularity | 0:05d03cca2089 | 55 | for (i=0;i<OV7670_REGMAX;i++) { |
singularity | 0:05d03cca2089 | 56 | int data ; |
singularity | 0:05d03cca2089 | 57 | data = camera.ReadReg(i) ; // READ REG |
singularity | 0:05d03cca2089 | 58 | if ((i & 0x0F) == 0) { |
singularity | 0:05d03cca2089 | 59 | pc.printf("\r\n%02X : ",i) ; |
singularity | 0:05d03cca2089 | 60 | } |
singularity | 0:05d03cca2089 | 61 | pc.printf("%02X ",data) ; |
singularity | 0:05d03cca2089 | 62 | } |
singularity | 0:05d03cca2089 | 63 | pc.printf("\r\n") ; |
singularity | 0:05d03cca2089 | 64 | |
singularity | 0:05d03cca2089 | 65 | |
singularity | 0:05d03cca2089 | 66 | // CAPTURE and SEND LOOP |
singularity | 0:05d03cca2089 | 67 | while(1) |
singularity | 0:05d03cca2089 | 68 | { |
singularity | 0:05d03cca2089 | 69 | pc.printf("Hit Any Key to send RGBx160x120 Capture Data.\r\n") ; |
singularity | 0:05d03cca2089 | 70 | while(!pc.readable()) ; |
singularity | 0:05d03cca2089 | 71 | pc.getc() ; |
singularity | 0:05d03cca2089 | 72 | camera.CaptureNext() ; |
singularity | 0:05d03cca2089 | 73 | while(camera.CaptureDone() == false) ; |
singularity | 0:05d03cca2089 | 74 | pc.printf("*\r\n") ; |
singularity | 0:05d03cca2089 | 75 | camera.ReadStart() ; |
singularity | 0:05d03cca2089 | 76 | i = 0 ; |
singularity | 0:05d03cca2089 | 77 | for (int y = 0;y < SIZEY;y++) { |
singularity | 0:05d03cca2089 | 78 | int r,g,b,d1,d2 ; |
singularity | 0:05d03cca2089 | 79 | for (int x = 0;x < SIZEX;x++) { |
singularity | 0:05d03cca2089 | 80 | d1 = camera.ReadOneByte() ; // upper nibble is XXX , lower nibble is B |
singularity | 0:05d03cca2089 | 81 | d2 = camera.ReadOneByte() ; // upper nibble is G , lower nibble is R |
singularity | 0:05d03cca2089 | 82 | b = (d1 & 0x0F) ; |
singularity | 0:05d03cca2089 | 83 | g = (d2 & 0xF0) >> 4 ; |
singularity | 0:05d03cca2089 | 84 | r = (d2 & 0x0F) ; |
singularity | 0:05d03cca2089 | 85 | pc.printf ("%1X%1X%1X",r,g,b) ; |
singularity | 0:05d03cca2089 | 86 | } |
singularity | 0:05d03cca2089 | 87 | pc.printf("\r\n") ; |
singularity | 0:05d03cca2089 | 88 | } |
singularity | 0:05d03cca2089 | 89 | camera.ReadStop() ; |
singularity | 0:05d03cca2089 | 90 | } |
singularity | 0:05d03cca2089 | 91 | } |