![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ov7670 FIFO data taking program
Dependencies: OV7670 with FIFO ST7735_TFT mbed
Fork of OV7670_Testing by
main.cpp@1:c98598814170, 2012-03-31 (annotated)
- Committer:
- ms523
- Date:
- Sat Mar 31 10:05:59 2012 +0000
- Revision:
- 1:c98598814170
- Parent:
- 0:aabbf2286bf2
- Child:
- 2:4ebec58ffaca
Working at 15fps for 160*120 RGB565 video
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ms523 | 0:aabbf2286bf2 | 1 | // |
ms523 | 0:aabbf2286bf2 | 2 | // OV7670 + FIFO AL422B camera board test |
ms523 | 0:aabbf2286bf2 | 3 | // |
ms523 | 0:aabbf2286bf2 | 4 | #include "mbed.h" |
ms523 | 0:aabbf2286bf2 | 5 | #include "ov7670.h" |
ms523 | 0:aabbf2286bf2 | 6 | #include "stdio.h" |
ms523 | 0:aabbf2286bf2 | 7 | #include "SPI_TFT.h" |
ms523 | 0:aabbf2286bf2 | 8 | #include "string" |
ms523 | 0:aabbf2286bf2 | 9 | #include "Arial12x12.h" |
ms523 | 0:aabbf2286bf2 | 10 | #include "Arial24x23.h" |
ms523 | 0:aabbf2286bf2 | 11 | #include "Arial28x28.h" |
ms523 | 0:aabbf2286bf2 | 12 | #include "font_big.h" |
ms523 | 0:aabbf2286bf2 | 13 | |
ms523 | 0:aabbf2286bf2 | 14 | OV7670 camera( |
ms523 | 0:aabbf2286bf2 | 15 | p28,p27, // SDA,SCL(I2C / SCCB) |
ms523 | 0:aabbf2286bf2 | 16 | p21,p22,p20, // VSYNC,HREF,WEN(FIFO) |
ms523 | 1:c98598814170 | 17 | Port0,0x07800033, |
ms523 | 0:aabbf2286bf2 | 18 | p23,p24,p25) ; // RRST,OE,RCLK |
ms523 | 0:aabbf2286bf2 | 19 | |
ms523 | 0:aabbf2286bf2 | 20 | // the TFT is connected to SPI pin 5-7 |
ms523 | 1:c98598814170 | 21 | SPI_TFT TFT(p5, p6, p7, p8, p14,"TFT"); // mosi, miso, sclk, cs, reset |
ms523 | 0:aabbf2286bf2 | 22 | |
ms523 | 0:aabbf2286bf2 | 23 | Serial pc(USBTX,USBRX); |
ms523 | 0:aabbf2286bf2 | 24 | |
ms523 | 0:aabbf2286bf2 | 25 | #define SIZEX (160) |
ms523 | 0:aabbf2286bf2 | 26 | #define SIZEY (120) |
ms523 | 1:c98598814170 | 27 | #define SIZE 19200 |
ms523 | 1:c98598814170 | 28 | |
ms523 | 1:c98598814170 | 29 | unsigned char bank0 [SIZE]; |
ms523 | 1:c98598814170 | 30 | unsigned char *bank1 = (unsigned char *)(0x2007C000); |
ms523 | 0:aabbf2286bf2 | 31 | |
ms523 | 0:aabbf2286bf2 | 32 | int main() { |
ms523 | 0:aabbf2286bf2 | 33 | |
ms523 | 0:aabbf2286bf2 | 34 | // Set up the TFT |
ms523 | 0:aabbf2286bf2 | 35 | TFT.claim(stdout); // Send stdout to the TFT display |
ms523 | 0:aabbf2286bf2 | 36 | TFT.background(Black); // Set background to black |
ms523 | 0:aabbf2286bf2 | 37 | TFT.foreground(White); // Set chars to white |
ms523 | 0:aabbf2286bf2 | 38 | TFT.cls(); // Clear the screen |
ms523 | 0:aabbf2286bf2 | 39 | TFT.set_font((unsigned char*) Arial12x12); // Select the font |
ms523 | 0:aabbf2286bf2 | 40 | TFT.set_orientation(3); // Select orientation |
ms523 | 0:aabbf2286bf2 | 41 | |
ms523 | 1:c98598814170 | 42 | // Reset camera on power up |
ms523 | 0:aabbf2286bf2 | 43 | camera.Reset() ; |
ms523 | 0:aabbf2286bf2 | 44 | |
ms523 | 1:c98598814170 | 45 | // Set up for 160*120 pixels RGB565 |
ms523 | 0:aabbf2286bf2 | 46 | camera.InitQQVGA() ; |
ms523 | 1:c98598814170 | 47 | |
ms523 | 1:c98598814170 | 48 | // Print message to screen |
ms523 | 1:c98598814170 | 49 | pc.printf("Hit Any Key to stop RGBx160x120 Capture Data.\r\n"); |
ms523 | 1:c98598814170 | 50 | |
ms523 | 1:c98598814170 | 51 | // Kick things off by capturing an image |
ms523 | 1:c98598814170 | 52 | camera.CaptureNext() ; |
ms523 | 1:c98598814170 | 53 | while (camera.CaptureDone() == false) ; |
ms523 | 0:aabbf2286bf2 | 54 | |
ms523 | 1:c98598814170 | 55 | // Now enter the main loop |
ms523 | 1:c98598814170 | 56 | while (!pc.readable()) { |
ms523 | 1:c98598814170 | 57 | |
ms523 | 1:c98598814170 | 58 | // Start reading in the image data from the camera hardware buffer |
ms523 | 1:c98598814170 | 59 | camera.ReadStart(); |
ms523 | 1:c98598814170 | 60 | |
ms523 | 1:c98598814170 | 61 | // Read in the first half of the image |
ms523 | 1:c98598814170 | 62 | for (int i = 0; i < SIZE; i++) { |
ms523 | 1:c98598814170 | 63 | bank0[i] = camera.ReadOneByte(); |
ms523 | 0:aabbf2286bf2 | 64 | } |
ms523 | 0:aabbf2286bf2 | 65 | |
ms523 | 1:c98598814170 | 66 | // Read in the second half of the image |
ms523 | 1:c98598814170 | 67 | for (int i = 0; i < SIZE ; i++) { |
ms523 | 1:c98598814170 | 68 | bank1[i] = camera.ReadOneByte(); |
ms523 | 1:c98598814170 | 69 | } |
ms523 | 1:c98598814170 | 70 | |
ms523 | 1:c98598814170 | 71 | // Stop reading the image |
ms523 | 1:c98598814170 | 72 | camera.ReadStop() ; |
ms523 | 1:c98598814170 | 73 | |
ms523 | 1:c98598814170 | 74 | // Immediately request the next image to be captured (takes around 45ms) |
ms523 | 0:aabbf2286bf2 | 75 | camera.CaptureNext() ; |
ms523 | 0:aabbf2286bf2 | 76 | |
ms523 | 1:c98598814170 | 77 | // Use this time to display the image on the screen |
ms523 | 1:c98598814170 | 78 | // Display the top half |
ms523 | 1:c98598814170 | 79 | TFT.Bitmap(0,0,160,60,bank1); |
ms523 | 1:c98598814170 | 80 | // Display the bottom half |
ms523 | 1:c98598814170 | 81 | TFT.Bitmap(0,60,160,60,bank0); |
ms523 | 1:c98598814170 | 82 | |
ms523 | 1:c98598814170 | 83 | /* Note: we still have around 15ms left here to do other stuff */ |
ms523 | 1:c98598814170 | 84 | |
ms523 | 1:c98598814170 | 85 | // Now wait for the image to finish being captured |
ms523 | 1:c98598814170 | 86 | while (camera.CaptureDone() == false) ; |
ms523 | 0:aabbf2286bf2 | 87 | } |
ms523 | 0:aabbf2286bf2 | 88 | } |