![](/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@3:b4e0cefc37f6, 2013-04-07 (annotated)
- Committer:
- edodm85
- Date:
- Sun Apr 07 10:52:10 2013 +0000
- Revision:
- 3:b4e0cefc37f6
- Parent:
- 2:bbd557817319
- Child:
- 4:d0d4760d32b2
Added VGA RAW
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 | 3:b4e0cefc37f6 | 3 | * Date: 07/04/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 | 2:bbd557817319 | 9 | #define VGA 307200 //640*480 |
edodm85 | 2:bbd557817319 | 10 | #define QVGA 76800 //320*240 |
edodm85 | 2:bbd557817319 | 11 | #define QQVGA 19200 //160*120 |
edodm85 | 2:bbd557817319 | 12 | |
edodm85 | 2:bbd557817319 | 13 | static char format = ' '; |
edodm85 | 2:bbd557817319 | 14 | static int resolution = 0; |
edodm85 | 0:19429e334b75 | 15 | |
edodm85 | 0:19429e334b75 | 16 | |
edodm85 | 0:19429e334b75 | 17 | void rxCallback(MODSERIAL_IRQ_INFO *q) |
edodm85 | 0:19429e334b75 | 18 | { |
edodm85 | 0:19429e334b75 | 19 | new_send = true; |
edodm85 | 0:19429e334b75 | 20 | } |
edodm85 | 0:19429e334b75 | 21 | |
edodm85 | 0:19429e334b75 | 22 | int main() |
edodm85 | 0:19429e334b75 | 23 | { |
edodm85 | 0:19429e334b75 | 24 | pc.baud(921600); |
edodm85 | 0:19429e334b75 | 25 | pc.printf("SystemCoreClock: %dMHz\r\n", SystemCoreClock/1000000); // print the clock frequency |
edodm85 | 0:19429e334b75 | 26 | led4 = 0; |
edodm85 | 0:19429e334b75 | 27 | |
edodm85 | 0:19429e334b75 | 28 | t.start(); |
edodm85 | 0:19429e334b75 | 29 | pc.attach(&rxCallback, MODSERIAL::RxIrq); |
edodm85 | 0:19429e334b75 | 30 | |
edodm85 | 0:19429e334b75 | 31 | while(1) |
edodm85 | 0:19429e334b75 | 32 | { |
edodm85 | 0:19429e334b75 | 33 | if(new_send){ |
edodm85 | 0:19429e334b75 | 34 | int i = 0; |
edodm85 | 0:19429e334b75 | 35 | |
edodm85 | 0:19429e334b75 | 36 | while(pc.readable()) |
edodm85 | 0:19429e334b75 | 37 | { |
edodm85 | 0:19429e334b75 | 38 | word[i] = pc.getc(); |
edodm85 | 0:19429e334b75 | 39 | i++; |
edodm85 | 0:19429e334b75 | 40 | } |
edodm85 | 0:19429e334b75 | 41 | parse_cmd(); |
edodm85 | 0:19429e334b75 | 42 | } |
edodm85 | 0:19429e334b75 | 43 | wait_ms(50); |
edodm85 | 0:19429e334b75 | 44 | } |
edodm85 | 0:19429e334b75 | 45 | } |
edodm85 | 0:19429e334b75 | 46 | |
edodm85 | 0:19429e334b75 | 47 | |
edodm85 | 0:19429e334b75 | 48 | |
edodm85 | 0:19429e334b75 | 49 | void parse_cmd(){ |
edodm85 | 0:19429e334b75 | 50 | new_send = false; |
edodm85 | 0:19429e334b75 | 51 | |
edodm85 | 2:bbd557817319 | 52 | if(strcmp("snap", word) == 0) |
edodm85 | 0:19429e334b75 | 53 | { |
edodm85 | 2:bbd557817319 | 54 | CameraSnap(); |
edodm85 | 0:19429e334b75 | 55 | memset(word, 0, sizeof(word)); |
edodm85 | 0:19429e334b75 | 56 | }else |
edodm85 | 3:b4e0cefc37f6 | 57 | if(strcmp("init_bw_VGA", word) == 0) // Set up for 640*480 pixels RAW |
edodm85 | 0:19429e334b75 | 58 | { |
edodm85 | 2:bbd557817319 | 59 | format = 'b'; |
edodm85 | 2:bbd557817319 | 60 | resolution = VGA; |
edodm85 | 2:bbd557817319 | 61 | if(camera.Init('b', VGA) != 1) |
edodm85 | 2:bbd557817319 | 62 | { |
edodm85 | 2:bbd557817319 | 63 | pc.printf("Init Fail\r\n"); |
edodm85 | 2:bbd557817319 | 64 | } |
edodm85 | 2:bbd557817319 | 65 | pc.printf("Initializing done\r\n"); |
edodm85 | 2:bbd557817319 | 66 | memset(word, 0, sizeof(word)); |
edodm85 | 2:bbd557817319 | 67 | }else |
edodm85 | 2:bbd557817319 | 68 | if(strcmp("init_yuv_QVGA", word) == 0) // Set up for 320*240 pixels YUV422 |
edodm85 | 2:bbd557817319 | 69 | { |
edodm85 | 2:bbd557817319 | 70 | format = 'y'; |
edodm85 | 2:bbd557817319 | 71 | resolution = QVGA; |
edodm85 | 2:bbd557817319 | 72 | if(camera.Init('b', QVGA) != 1) |
edodm85 | 2:bbd557817319 | 73 | { |
edodm85 | 2:bbd557817319 | 74 | pc.printf("Init Fail\r\n"); |
edodm85 | 2:bbd557817319 | 75 | } |
edodm85 | 2:bbd557817319 | 76 | pc.printf("Initializing done\r\n"); |
edodm85 | 0:19429e334b75 | 77 | memset(word, 0, sizeof(word)); |
edodm85 | 2:bbd557817319 | 78 | }else |
edodm85 | 2:bbd557817319 | 79 | if(strcmp("init_rgb_QVGA", word) == 0) // Set up for 320*240 pixels RGB565 |
edodm85 | 2:bbd557817319 | 80 | { |
edodm85 | 2:bbd557817319 | 81 | format = 'r'; |
edodm85 | 2:bbd557817319 | 82 | resolution = QVGA; |
edodm85 | 2:bbd557817319 | 83 | if(camera.Init('r', QVGA) != 1) |
edodm85 | 2:bbd557817319 | 84 | { |
edodm85 | 2:bbd557817319 | 85 | pc.printf("Init Fail\r\n"); |
edodm85 | 2:bbd557817319 | 86 | } |
edodm85 | 2:bbd557817319 | 87 | pc.printf("Initializing done\r\n"); |
edodm85 | 2:bbd557817319 | 88 | memset(word, 0, sizeof(word)); |
edodm85 | 2:bbd557817319 | 89 | }else |
edodm85 | 2:bbd557817319 | 90 | if(strcmp("init_bw_QVGA", word) == 0) // Set up for 320*240 pixels YUV (Only Y) |
edodm85 | 0:19429e334b75 | 91 | { |
edodm85 | 2:bbd557817319 | 92 | format = 'b'; |
edodm85 | 2:bbd557817319 | 93 | resolution = QVGA; |
edodm85 | 2:bbd557817319 | 94 | if(camera.Init('b', QVGA) != 1) |
edodm85 | 2:bbd557817319 | 95 | { |
edodm85 | 2:bbd557817319 | 96 | pc.printf("Init Fail\r\n"); |
edodm85 | 2:bbd557817319 | 97 | } |
edodm85 | 2:bbd557817319 | 98 | pc.printf("Initializing done\r\n"); |
edodm85 | 2:bbd557817319 | 99 | memset(word, 0, sizeof(word)); |
edodm85 | 2:bbd557817319 | 100 | }else |
edodm85 | 2:bbd557817319 | 101 | if(strcmp("init_yuv_QQVGA", word) == 0) // Set up for 160*120 pixels YUV422 |
edodm85 | 2:bbd557817319 | 102 | { |
edodm85 | 2:bbd557817319 | 103 | format = 'y'; |
edodm85 | 2:bbd557817319 | 104 | resolution = QQVGA; |
edodm85 | 2:bbd557817319 | 105 | if(camera.Init('b', QQVGA) != 1) |
edodm85 | 2:bbd557817319 | 106 | { |
edodm85 | 2:bbd557817319 | 107 | pc.printf("Init Fail\r\n"); |
edodm85 | 2:bbd557817319 | 108 | } |
edodm85 | 2:bbd557817319 | 109 | pc.printf("Initializing done\r\n"); |
edodm85 | 2:bbd557817319 | 110 | memset(word, 0, sizeof(word)); |
edodm85 | 2:bbd557817319 | 111 | }else |
edodm85 | 2:bbd557817319 | 112 | if(strcmp("init_rgb_QQVGA", word) == 0) // Set up for 160*120 pixels RGB565 |
edodm85 | 2:bbd557817319 | 113 | { |
edodm85 | 2:bbd557817319 | 114 | format = 'r'; |
edodm85 | 2:bbd557817319 | 115 | resolution = QQVGA; |
edodm85 | 2:bbd557817319 | 116 | if(camera.Init('r', QQVGA) != 1) |
edodm85 | 0:19429e334b75 | 117 | { |
edodm85 | 0:19429e334b75 | 118 | pc.printf("Init Fail\r\n"); |
edodm85 | 0:19429e334b75 | 119 | } |
edodm85 | 0:19429e334b75 | 120 | pc.printf("Initializing done\r\n"); |
edodm85 | 0:19429e334b75 | 121 | memset(word, 0, sizeof(word)); |
edodm85 | 0:19429e334b75 | 122 | }else |
edodm85 | 2:bbd557817319 | 123 | if(strcmp("init_bw_QQVGA", word) == 0) // Set up for 160*120 pixels YUV (Only Y) |
edodm85 | 2:bbd557817319 | 124 | { |
edodm85 | 2:bbd557817319 | 125 | format = 'b'; |
edodm85 | 2:bbd557817319 | 126 | resolution = QQVGA; |
edodm85 | 2:bbd557817319 | 127 | if(camera.Init('b', QQVGA) != 1) |
edodm85 | 0:19429e334b75 | 128 | { |
edodm85 | 0:19429e334b75 | 129 | pc.printf("Init Fail\r\n"); |
edodm85 | 0:19429e334b75 | 130 | } |
edodm85 | 0:19429e334b75 | 131 | pc.printf("Initializing done\r\n"); |
edodm85 | 0:19429e334b75 | 132 | memset(word, 0, sizeof(word)); |
edodm85 | 0:19429e334b75 | 133 | }else |
edodm85 | 0:19429e334b75 | 134 | if(strcmp("reset", word) == 0) |
edodm85 | 0:19429e334b75 | 135 | { |
edodm85 | 0:19429e334b75 | 136 | mbed_reset(); |
edodm85 | 0:19429e334b75 | 137 | }else |
edodm85 | 0:19429e334b75 | 138 | if(strcmp("time", word) == 0) |
edodm85 | 0:19429e334b75 | 139 | { |
edodm85 | 2:bbd557817319 | 140 | pc.printf("Tot time acq + send (mbed): %dms\r\n", t2-t1); |
edodm85 | 0:19429e334b75 | 141 | memset(word, 0, sizeof(word)); |
edodm85 | 2:bbd557817319 | 142 | } |
edodm85 | 2:bbd557817319 | 143 | |
edodm85 | 0:19429e334b75 | 144 | memset(word, 0, sizeof(word)); |
edodm85 | 0:19429e334b75 | 145 | |
edodm85 | 0:19429e334b75 | 146 | } |
edodm85 | 0:19429e334b75 | 147 | |
edodm85 | 0:19429e334b75 | 148 | |
edodm85 | 2:bbd557817319 | 149 | void CameraSnap(){ |
edodm85 | 0:19429e334b75 | 150 | led4 = 1; |
edodm85 | 2:bbd557817319 | 151 | |
edodm85 | 2:bbd557817319 | 152 | // Kick things off by capturing an image |
edodm85 | 0:19429e334b75 | 153 | camera.CaptureNext(); |
edodm85 | 2:bbd557817319 | 154 | while(camera.CaptureDone() == false); |
edodm85 | 0:19429e334b75 | 155 | // Start reading in the image data from the camera hardware buffer |
edodm85 | 0:19429e334b75 | 156 | camera.ReadStart(); |
edodm85 | 2:bbd557817319 | 157 | t1 = t.read_ms(); |
edodm85 | 0:19429e334b75 | 158 | |
edodm85 | 2:bbd557817319 | 159 | for(int x = 0; x<resolution; x++) |
edodm85 | 0:19429e334b75 | 160 | { |
edodm85 | 2:bbd557817319 | 161 | // Read in the first half of the image |
edodm85 | 3:b4e0cefc37f6 | 162 | if(format == 'b' && resolution != VGA) |
edodm85 | 2:bbd557817319 | 163 | { |
edodm85 | 2:bbd557817319 | 164 | camera.ReadOnebyte(); |
edodm85 | 2:bbd557817319 | 165 | }else |
edodm85 | 2:bbd557817319 | 166 | if(format == 'y' || format == 'r') |
edodm85 | 2:bbd557817319 | 167 | { |
edodm85 | 2:bbd557817319 | 168 | pc.putc(camera.ReadOnebyte()); |
edodm85 | 2:bbd557817319 | 169 | } |
edodm85 | 2:bbd557817319 | 170 | // Read in the Second half of the image |
edodm85 | 2:bbd557817319 | 171 | pc.putc(camera.ReadOnebyte()); // Y only |
edodm85 | 0:19429e334b75 | 172 | } |
edodm85 | 2:bbd557817319 | 173 | |
edodm85 | 2:bbd557817319 | 174 | camera.ReadStop(); |
edodm85 | 2:bbd557817319 | 175 | t2 = t.read_ms(); |
edodm85 | 0:19429e334b75 | 176 | |
edodm85 | 2:bbd557817319 | 177 | // Immediately request the next image to be captured (takes around 45ms) |
edodm85 | 0:19429e334b75 | 178 | camera.CaptureNext(); |
edodm85 | 2:bbd557817319 | 179 | // Now wait for the image to finish being captured |
edodm85 | 0:19429e334b75 | 180 | while (camera.CaptureDone() == false); |
edodm85 | 0:19429e334b75 | 181 | |
edodm85 | 2:bbd557817319 | 182 | pc.printf("Snap_done\r\n"); |
edodm85 | 0:19429e334b75 | 183 | led4 = 0; |
edodm85 | 2:bbd557817319 | 184 | } |