![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Test Code for OV7670 Camera module with FIFO AL422
Dependencies: MODSERIAL mbed ov7670
You can find more information in this page: https://mbed.org/users/edodm85/notebook/ov7670-camera-module/
main.cpp@0:19429e334b75, 2013-03-10 (annotated)
- Committer:
- edodm85
- Date:
- Sun Mar 10 13:03:52 2013 +0000
- Revision:
- 0:19429e334b75
- Child:
- 2:bbd557817319
First Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
edodm85 | 0:19429e334b75 | 1 | /* |
edodm85 | 0:19429e334b75 | 2 | * Author: Edoardo De Marchi |
edodm85 | 0:19429e334b75 | 3 | * Date: 10/03/13 |
edodm85 | 0:19429e334b75 | 4 | * Notes: OV7670 + FIFO AL422B camera test |
edodm85 | 0:19429e334b75 | 5 | */ |
edodm85 | 0:19429e334b75 | 6 | |
edodm85 | 0:19429e334b75 | 7 | #include "main.h" |
edodm85 | 0:19429e334b75 | 8 | |
edodm85 | 0:19429e334b75 | 9 | #define QQVGA 4 //320*240 |
edodm85 | 0:19429e334b75 | 10 | #define QVGA 2 //160*120 |
edodm85 | 0:19429e334b75 | 11 | |
edodm85 | 0:19429e334b75 | 12 | |
edodm85 | 0:19429e334b75 | 13 | void rxCallback(MODSERIAL_IRQ_INFO *q) |
edodm85 | 0:19429e334b75 | 14 | { |
edodm85 | 0:19429e334b75 | 15 | new_send = true; |
edodm85 | 0:19429e334b75 | 16 | } |
edodm85 | 0:19429e334b75 | 17 | |
edodm85 | 0:19429e334b75 | 18 | int main() |
edodm85 | 0:19429e334b75 | 19 | { |
edodm85 | 0:19429e334b75 | 20 | pc.baud(921600); |
edodm85 | 0:19429e334b75 | 21 | pc.printf("SystemCoreClock: %dMHz\r\n", SystemCoreClock/1000000); // print the clock frequency |
edodm85 | 0:19429e334b75 | 22 | led4 = 0; |
edodm85 | 0:19429e334b75 | 23 | |
edodm85 | 0:19429e334b75 | 24 | t.start(); |
edodm85 | 0:19429e334b75 | 25 | pc.attach(&rxCallback, MODSERIAL::RxIrq); |
edodm85 | 0:19429e334b75 | 26 | |
edodm85 | 0:19429e334b75 | 27 | while(1) |
edodm85 | 0:19429e334b75 | 28 | { |
edodm85 | 0:19429e334b75 | 29 | if(new_send){ |
edodm85 | 0:19429e334b75 | 30 | int i = 0; |
edodm85 | 0:19429e334b75 | 31 | |
edodm85 | 0:19429e334b75 | 32 | while(pc.readable()) |
edodm85 | 0:19429e334b75 | 33 | { |
edodm85 | 0:19429e334b75 | 34 | word[i] = pc.getc(); |
edodm85 | 0:19429e334b75 | 35 | i++; |
edodm85 | 0:19429e334b75 | 36 | } |
edodm85 | 0:19429e334b75 | 37 | parse_cmd(); |
edodm85 | 0:19429e334b75 | 38 | } |
edodm85 | 0:19429e334b75 | 39 | wait_ms(50); |
edodm85 | 0:19429e334b75 | 40 | } |
edodm85 | 0:19429e334b75 | 41 | } |
edodm85 | 0:19429e334b75 | 42 | |
edodm85 | 0:19429e334b75 | 43 | |
edodm85 | 0:19429e334b75 | 44 | |
edodm85 | 0:19429e334b75 | 45 | void parse_cmd(){ |
edodm85 | 0:19429e334b75 | 46 | new_send = false; |
edodm85 | 0:19429e334b75 | 47 | |
edodm85 | 0:19429e334b75 | 48 | if(strcmp("snap_yuv", word) == 0) |
edodm85 | 0:19429e334b75 | 49 | { |
edodm85 | 0:19429e334b75 | 50 | CameraSnap('y'); |
edodm85 | 0:19429e334b75 | 51 | memset(word, 0, sizeof(word)); |
edodm85 | 0:19429e334b75 | 52 | }else |
edodm85 | 0:19429e334b75 | 53 | if(strcmp("snap_rgb", word) == 0) |
edodm85 | 0:19429e334b75 | 54 | { |
edodm85 | 0:19429e334b75 | 55 | CameraSnap('r'); |
edodm85 | 0:19429e334b75 | 56 | memset(word, 0, sizeof(word)); |
edodm85 | 0:19429e334b75 | 57 | |
edodm85 | 0:19429e334b75 | 58 | }else |
edodm85 | 0:19429e334b75 | 59 | if(strcmp("init_yuv", word) == 0) |
edodm85 | 0:19429e334b75 | 60 | { |
edodm85 | 0:19429e334b75 | 61 | // Reset camera on power up |
edodm85 | 0:19429e334b75 | 62 | camera.Reset(); |
edodm85 | 0:19429e334b75 | 63 | // Set up for 160*120 pixels YUV (Only Y) |
edodm85 | 0:19429e334b75 | 64 | pc.printf("Initializing ov7670 - Format YUV & QQVGA Mode\r\n"); |
edodm85 | 0:19429e334b75 | 65 | if(camera.Init('y') != 1) |
edodm85 | 0:19429e334b75 | 66 | { |
edodm85 | 0:19429e334b75 | 67 | pc.printf("Init Fail\r\n"); |
edodm85 | 0:19429e334b75 | 68 | } |
edodm85 | 0:19429e334b75 | 69 | pc.printf("Initializing done\r\n"); |
edodm85 | 0:19429e334b75 | 70 | memset(word, 0, sizeof(word)); |
edodm85 | 0:19429e334b75 | 71 | }else |
edodm85 | 0:19429e334b75 | 72 | if(strcmp("init_rgb", word) == 0) |
edodm85 | 0:19429e334b75 | 73 | { |
edodm85 | 0:19429e334b75 | 74 | // Reset camera on power up |
edodm85 | 0:19429e334b75 | 75 | camera.Reset(); |
edodm85 | 0:19429e334b75 | 76 | // Set up for 160*120 pixels RGB565 |
edodm85 | 0:19429e334b75 | 77 | pc.printf("Initializing ov7670 - Format RGB & QQVGA Mode\r\n"); |
edodm85 | 0:19429e334b75 | 78 | if(camera.Init('r') != 1) |
edodm85 | 0:19429e334b75 | 79 | { |
edodm85 | 0:19429e334b75 | 80 | pc.printf("Init Fail\r\n"); |
edodm85 | 0:19429e334b75 | 81 | } |
edodm85 | 0:19429e334b75 | 82 | pc.printf("Initializing done\r\n"); |
edodm85 | 0:19429e334b75 | 83 | memset(word, 0, sizeof(word)); |
edodm85 | 0:19429e334b75 | 84 | }else |
edodm85 | 0:19429e334b75 | 85 | if(strcmp("reset", word) == 0) |
edodm85 | 0:19429e334b75 | 86 | { |
edodm85 | 0:19429e334b75 | 87 | mbed_reset(); |
edodm85 | 0:19429e334b75 | 88 | }else |
edodm85 | 0:19429e334b75 | 89 | if(strcmp("time", word) == 0) |
edodm85 | 0:19429e334b75 | 90 | { |
edodm85 | 0:19429e334b75 | 91 | pc.printf("Time Acq from camera: %dms - Time Send to pc: %dms - Time Tot: %dms\r\n", t2-t1, t3-t2, t3-t1); |
edodm85 | 0:19429e334b75 | 92 | memset(word, 0, sizeof(word)); |
edodm85 | 0:19429e334b75 | 93 | } |
edodm85 | 0:19429e334b75 | 94 | memset(word, 0, sizeof(word)); |
edodm85 | 0:19429e334b75 | 95 | |
edodm85 | 0:19429e334b75 | 96 | } |
edodm85 | 0:19429e334b75 | 97 | |
edodm85 | 0:19429e334b75 | 98 | |
edodm85 | 0:19429e334b75 | 99 | |
edodm85 | 0:19429e334b75 | 100 | void CameraSnap(char c){ |
edodm85 | 0:19429e334b75 | 101 | led4 = 1; |
edodm85 | 0:19429e334b75 | 102 | int var2 = 0; |
edodm85 | 0:19429e334b75 | 103 | int var = 0; |
edodm85 | 0:19429e334b75 | 104 | t1 = t.read_ms(); |
edodm85 | 0:19429e334b75 | 105 | |
edodm85 | 0:19429e334b75 | 106 | // wait until the image has been captured |
edodm85 | 0:19429e334b75 | 107 | camera.CaptureNext(); |
edodm85 | 0:19429e334b75 | 108 | while(camera.CaptureDone() == false); |
edodm85 | 0:19429e334b75 | 109 | |
edodm85 | 0:19429e334b75 | 110 | // Start reading in the image data from the camera hardware buffer |
edodm85 | 0:19429e334b75 | 111 | camera.ReadStart(); |
edodm85 | 0:19429e334b75 | 112 | |
edodm85 | 0:19429e334b75 | 113 | // Read the first half of the image |
edodm85 | 0:19429e334b75 | 114 | for (int q = 0; q < SIZE; q++) |
edodm85 | 0:19429e334b75 | 115 | { |
edodm85 | 0:19429e334b75 | 116 | bank0[q] = camera.ReadOnebyte(); |
edodm85 | 0:19429e334b75 | 117 | } |
edodm85 | 0:19429e334b75 | 118 | // Read the Second half of the image |
edodm85 | 0:19429e334b75 | 119 | for (int q = 0; q < SIZE; q++) |
edodm85 | 0:19429e334b75 | 120 | { |
edodm85 | 0:19429e334b75 | 121 | bank1[q] = camera.ReadOnebyte(); |
edodm85 | 0:19429e334b75 | 122 | } |
edodm85 | 0:19429e334b75 | 123 | |
edodm85 | 0:19429e334b75 | 124 | // Stop reading the image |
edodm85 | 0:19429e334b75 | 125 | camera.ReadStop() ; |
edodm85 | 0:19429e334b75 | 126 | t2 = t.read_ms(); |
edodm85 | 0:19429e334b75 | 127 | |
edodm85 | 0:19429e334b75 | 128 | if(c == 'y') |
edodm85 | 0:19429e334b75 | 129 | { |
edodm85 | 0:19429e334b75 | 130 | var = 2; // set YUV QQVGA |
edodm85 | 0:19429e334b75 | 131 | var2 = 1; |
edodm85 | 0:19429e334b75 | 132 | } |
edodm85 | 0:19429e334b75 | 133 | else{ |
edodm85 | 0:19429e334b75 | 134 | var = 1; // set RGB565 QQVGA |
edodm85 | 0:19429e334b75 | 135 | var2 = 0; |
edodm85 | 0:19429e334b75 | 136 | } |
edodm85 | 0:19429e334b75 | 137 | |
edodm85 | 0:19429e334b75 | 138 | for (int i = 0; i < SIZE/var; i++) { |
edodm85 | 0:19429e334b75 | 139 | pc.putc(bank0[(i*var)+var2]); |
edodm85 | 0:19429e334b75 | 140 | } |
edodm85 | 0:19429e334b75 | 141 | for (int i = 0; i < SIZE/var; i++) { |
edodm85 | 0:19429e334b75 | 142 | pc.putc(bank1[(i*var)+var2]); |
edodm85 | 0:19429e334b75 | 143 | } |
edodm85 | 0:19429e334b75 | 144 | |
edodm85 | 0:19429e334b75 | 145 | // Immediately request the next image to be captured |
edodm85 | 0:19429e334b75 | 146 | camera.CaptureNext(); |
edodm85 | 0:19429e334b75 | 147 | while (camera.CaptureDone() == false); |
edodm85 | 0:19429e334b75 | 148 | t3 = t.read_ms(); |
edodm85 | 0:19429e334b75 | 149 | |
edodm85 | 0:19429e334b75 | 150 | pc.printf("Grab done\r\n"); |
edodm85 | 0:19429e334b75 | 151 | |
edodm85 | 0:19429e334b75 | 152 | led4 = 0; |
edodm85 | 0:19429e334b75 | 153 | } |
edodm85 | 0:19429e334b75 | 154 | |
edodm85 | 0:19429e334b75 | 155 |