Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F429ZI LCD_DISCO_F429ZI mbed levkov_ov7670
main.cpp
00001 /*#include "mbed.h" 00002 #include "LCD_DISCO_F429ZI.h" 00003 #include "ov7670.h" 00004 00005 LCD_DISCO_F429ZI lcd; 00006 00007 DigitalOut led1(LED1); 00008 00009 OV7670 camera( 00010 PB_9,PB_8, // SDA,SCL(I2C / SCCB) 00011 PB_7,PF_8,PA_10, // VSYNC,HREF,WEN(FIFO) 00012 //PortD,0xFF000000, 00013 PE_6,PE_5,PB_6,PE_4,PC_9,PC_8,PC_7,PC_6, 00014 PF_9,PF_7,PA_9) ; // RRST,OE,RCLK 00015 00016 Serial pc(USBTX,USBRX); 00017 00018 #define SIZEX (160) 00019 #define SIZEY (120) 00020 #define SIZE 19200 00021 #define VGA 307200 //640*480 00022 #define QVGA 76800 //320*240 00023 #define QQVGA 19200 //160*120 00024 00025 unsigned char bank0 [SIZE]; 00026 unsigned char *bank1 = (unsigned char *)(0x2007C000); 00027 00028 int main() 00029 { 00030 led1 = 1; 00031 00032 BSP_LCD_SetFont(&Font20); 00033 lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE); 00034 wait(1); 00035 00036 lcd.Clear(LCD_COLOR_BLUE); 00037 lcd.SetBackColor(LCD_COLOR_BLUE); 00038 lcd.SetTextColor(LCD_COLOR_WHITE); 00039 wait(0.3); 00040 lcd.DisplayStringAt(0, LINE(4), (uint8_t *)"DISCOVERY", CENTER_MODE); 00041 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"STM32F429ZI", CENTER_MODE); 00042 wait(1); 00043 00044 lcd.Clear(LCD_COLOR_GREEN); 00045 00046 lcd.SetTextColor(LCD_COLOR_BLUE); 00047 lcd.FillRect(10, 20, 50, 50); 00048 wait(0.1); 00049 lcd.SetTextColor(LCD_COLOR_BROWN); 00050 lcd.FillCircle(80, 80, 50); 00051 wait(0.1); 00052 lcd.SetTextColor(LCD_COLOR_YELLOW); 00053 lcd.FillEllipse(150, 150, 50, 100); 00054 wait(0.1); 00055 lcd.SetTextColor(LCD_COLOR_RED); 00056 lcd.FillCircle(200, 200, 40); 00057 wait(1); 00058 00059 lcd.SetBackColor(LCD_COLOR_ORANGE); 00060 lcd.SetTextColor(LCD_COLOR_CYAN); 00061 BSP_LCD_SetFont(&Font24); 00062 lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"HAVE FUN !!!", CENTER_MODE); 00063 wait(1); 00064 00065 led1 = !led1; 00066 wait(0.5); 00067 lcd.Clear(LCD_COLOR_WHITE); 00068 lcd.SetBackColor(LCD_COLOR_WHITE); 00069 lcd.SetTextColor(LCD_COLOR_WHITE);*/ 00070 // Reset camera on power up 00071 /* camera.Reset() ; 00072 00073 // Set up for 160*120 pixels RGB565 00074 camera.Init('r', QQVGA); 00075 00076 // Print message to screen 00077 pc.printf("Hit Any Key to stop RGBx160x120 Capture Data.\r\n"); 00078 00079 // Kick things off by capturing an image 00080 camera.CaptureNext() ; 00081 while (camera.CaptureDone() == false) ; 00082 00083 // Now enter the main loop 00084 while (!pc.readable()) { 00085 00086 // Start reading in the image data from the camera hardware buffer 00087 camera.ReadStart(); 00088 00089 // Read in the first half of the image 00090 for (int i = 0; i < SIZE; i++) { 00091 bank0[i] = camera.ReadOnebyte(); 00092 } 00093 00094 // Read in the second half of the image 00095 for (int i = 0; i < SIZE ; i++) { 00096 bank1[i] = camera.ReadOnebyte(); 00097 } 00098 00099 // Stop reading the image 00100 camera.ReadStop() ; 00101 00102 // Immediately request the next image to be captured (takes around 45ms) 00103 camera.CaptureNext() ; 00104 00105 // Use this time to display the image on the screen 00106 // Display the top half 00107 lcd.DrawBitmap(0, 0, bank0); 00108 lcd.DrawBitmap(0, 60, bank1); 00109 // TFT.Bitmap(0,0,160,60,bank1); 00110 // Display the bottom half 00111 // TFT.Bitmap(0,60,160,60,bank0); 00112 00113 00114 00115 // Now wait for the image to finish being captured 00116 while (camera.CaptureDone() == false) ; 00117 } 00118 pc.printf("Capture Stop.\r\n");*/ 00119 00120 //} 00121 /* 00122 OV7670 camera( 00123 p28,p27, // SDA,SCL(I2C / SCCB) 00124 p21,p22,p20, // VSYNC,HREF,WEN(FIFO) 00125 Port0,0x07800033, 00126 p23,p24,p25) ; // RRST,OE,RCLK 00127 00128 // the TFT is connected to SPI pin 5-7 00129 SPI_TFT TFT(p5, p6, p7, p8, p14,"TFT"); // mosi, miso, sclk, cs, reset 00130 00131 Serial pc(USBTX,USBRX); 00132 00133 #define SIZEX (160) 00134 #define SIZEY (120) 00135 #define SIZE 19200 00136 00137 unsigned char bank0 [SIZE]; 00138 unsigned char *bank1 = (unsigned char *)(0x2007C000); 00139 00140 int main() { 00141 00142 // Set up the TFT 00143 TFT.claim(stdout); // Send stdout to the TFT display 00144 TFT.background(Black); // Set background to black 00145 TFT.foreground(White); // Set chars to white 00146 TFT.cls(); // Clear the screen 00147 TFT.set_font((unsigned char*) Arial12x12); // Select the font 00148 TFT.set_orientation(3); // Select orientation 00149 00150 // Reset camera on power up 00151 camera.Reset() ; 00152 00153 // Set up for 160*120 pixels RGB565 00154 camera.InitQQVGA() ; 00155 00156 // Print message to screen 00157 pc.printf("Hit Any Key to stop RGBx160x120 Capture Data.\r\n"); 00158 00159 // Kick things off by capturing an image 00160 camera.CaptureNext() ; 00161 while (camera.CaptureDone() == false) ; 00162 00163 // Now enter the main loop 00164 while (!pc.readable()) { 00165 00166 // Start reading in the image data from the camera hardware buffer 00167 camera.ReadStart(); 00168 00169 // Read in the first half of the image 00170 for (int i = 0; i < SIZE; i++) { 00171 bank0[i] = camera.ReadOneByte(); 00172 } 00173 00174 // Read in the second half of the image 00175 for (int i = 0; i < SIZE ; i++) { 00176 bank1[i] = camera.ReadOneByte(); 00177 } 00178 00179 // Stop reading the image 00180 camera.ReadStop() ; 00181 00182 // Immediately request the next image to be captured (takes around 45ms) 00183 camera.CaptureNext() ; 00184 00185 // Use this time to display the image on the screen 00186 // Display the top half 00187 TFT.Bitmap(0,0,160,60,bank1); 00188 // Display the bottom half 00189 TFT.Bitmap(0,60,160,60,bank0); 00190 00191 00192 00193 // Now wait for the image to finish being captured 00194 while (camera.CaptureDone() == false) ; 00195 } 00196 } 00197 */ 00198 00199 00200 00201 #include "mbed.h" 00202 #include "ov7670.h" 00203 #include "LCD_DISCO_F429ZI.h" 00204 #include "string" 00205 #include <stdlib.h> 00206 #include <stdio.h> 00207 #include <stdint.h> 00208 #include <inttypes.h> 00209 00210 00211 //Timer t; 00212 bool new_send = false; 00213 00214 DigitalOut led1(LED1); 00215 DigitalOut led2(LED2); 00216 DigitalOut led3(LED3); 00217 DigitalOut led4(LED4); 00218 Serial pc(USBTX,USBRX); 00219 LCD_DISCO_F429ZI lcd; 00220 //Camera 00221 OV7670 camera( 00222 PC_9,PA_8, // SDA,SCL(I2C / SCCB) 00223 PB_3,PF_6,PG_9, // VSYNC,HREF,WEN(FIFO) 00224 //PortD,0xFF000000, 00225 PB_7,PE_3,PE_5,PE_6,PB_2,PE_4,PA_5,PE_2, 00226 PC_3,PA_0,PB_4) ; // RRST,OE,RCLK 00227 00228 void parse_cmd(); 00229 void CameraSnap(); 00230 void CameraGrab(); 00231 00232 #define SIZEX (160) 00233 #define SIZEY (120) 00234 #define SIZE 19200 00235 00236 unsigned char bank0 [SIZE]; 00237 unsigned char *bank1 = (unsigned char *)(0x2007C000); 00238 //RESET 00239 //extern "C" void mbed_reset(); 00240 00241 //Serial 00242 00243 int t1 = 0; 00244 int t2 = 0; 00245 int t3 = 0; 00246 char word[25]; 00247 int snap = 0; 00248 // 00249 00250 00251 #define VGA 307200 //640*480 00252 #define QVGA 76800 //320*240 00253 #define QQVGA 19200 //160*120 00254 00255 static char format = ' '; 00256 static int resolution = 0; 00257 00258 void rxCallback() { 00259 char l; 00260 00261 while ((l= pc.getc())!=-1){ 00262 //read 1 character 00263 // wor[i] = l; 00264 // i++; 00265 // arr += l; 00266 pc.printf("%c", l); 00267 } 00268 pc.printf("c"); 00269 /*if(strcmp("hello",wor) == 0) 00270 { 00271 pc.printf("HELLO\r\n"); 00272 }*/ 00273 //pc.printf("\r\n");*/ 00274 //pc.scanf("%s\n", &word); 00275 //pc.printf("HELLO\r\n"); 00276 } 00277 00278 void periodicCallback(void){ 00279 00280 pc.printf("Snap_done %d\r\n", snap); 00281 } 00282 00283 int main() 00284 { 00285 // pc.format(8, Serial::None, 1); 00286 pc.baud(250000); 00287 //pc.attach(&rxCallback); 00288 Ticker ticker; 00289 ticker.attach(periodicCallback, 10); 00290 00291 BSP_LCD_SetFont(&Font20); 00292 lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"MBED EXAMPLE", CENTER_MODE); 00293 wait(1); 00294 00295 lcd.Clear(LCD_COLOR_BLUE); 00296 lcd.SetBackColor(LCD_COLOR_BLUE); 00297 lcd.SetTextColor(LCD_COLOR_WHITE); 00298 wait(0.3); 00299 lcd.DisplayStringAt(0, LINE(4), (uint8_t *)"DISCOVERY", CENTER_MODE); 00300 lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"STM32F429ZI", CENTER_MODE); 00301 wait(1); 00302 00303 lcd.Clear(LCD_COLOR_WHITE); 00304 lcd.SetBackColor(LCD_COLOR_WHITE); 00305 lcd.SetTextColor(LCD_COLOR_WHITE); 00306 00307 pc.printf("SystemCoreClock: %dMHz\r\n", SystemCoreClock/1000000); // print the clock frequency 00308 00309 00310 format = 'b'; 00311 resolution = QQVGA; 00312 if(camera.Init('b', QQVGA) != 1) 00313 { 00314 pc.printf("Init Fail\r\n"); 00315 } 00316 pc.printf("Initializing done\r\n"); 00317 00318 00319 00320 while(1) 00321 { 00322 CameraSnap(); 00323 } 00324 } 00325 00326 00327 00328 void parse_cmd() 00329 { 00330 new_send = false; 00331 00332 if(strcmp("hello", word) == 0) 00333 { 00334 pc.printf("HELLO\r\n"); 00335 }else 00336 if(strcmp("snap", word) == 0) 00337 { 00338 CameraSnap(); 00339 memset(word, 0, sizeof(word)); 00340 }else 00341 if(strcmp("init_bw_VGA", word) == 0) // Set up for 640*480 pixels RAW 00342 { 00343 format = 'b'; 00344 resolution = VGA; 00345 if(camera.Init('b', VGA) != 1) 00346 { 00347 pc.printf("Init Fail\r\n"); 00348 } 00349 pc.printf("Initializing done\r\n"); 00350 memset(word, 0, sizeof(word)); 00351 }else 00352 if(strcmp("init_yuv_QVGA", word) == 0) // Set up for 320*240 pixels YUV422 00353 { 00354 format = 'y'; 00355 resolution = QVGA; 00356 if(camera.Init('b', QVGA) != 1) 00357 { 00358 pc.printf("Init Fail\r\n"); 00359 } 00360 pc.printf("Initializing done\r\n"); 00361 memset(word, 0, sizeof(word)); 00362 }else 00363 if(strcmp("init_rgb_QVGA", word) == 0) // Set up for 320*240 pixels RGB565 00364 { 00365 format = 'r'; 00366 resolution = QVGA; 00367 if(camera.Init('r', QVGA) != 1) 00368 { 00369 pc.printf("Init Fail\r\n"); 00370 } 00371 pc.printf("Initializing done\r\n"); 00372 memset(word, 0, sizeof(word)); 00373 }else 00374 if(strcmp("init_bw_QVGA", word) == 0) // Set up for 320*240 pixels YUV (Only Y) 00375 { 00376 format = 'b'; 00377 resolution = QVGA; 00378 if(camera.Init('b', QVGA) != 1) 00379 { 00380 pc.printf("Init Fail\r\n"); 00381 } 00382 pc.printf("Initializing done\r\n"); 00383 memset(word, 0, sizeof(word)); 00384 }else 00385 if(strcmp("init_yuv_QQVGA", word) == 0) // Set up for 160*120 pixels YUV422 00386 { 00387 format = 'y'; 00388 resolution = QQVGA; 00389 if(camera.Init('b', QQVGA) != 1) 00390 { 00391 pc.printf("Init Fail\r\n"); 00392 } 00393 pc.printf("Initializing done\r\n"); 00394 memset(word, 0, sizeof(word)); 00395 }else 00396 if(strcmp("init_rgb_QQVGA", word) == 0) // Set up for 160*120 pixels RGB565 00397 { 00398 format = 'r'; 00399 resolution = QQVGA; 00400 if(camera.Init('r', QQVGA) != 1) 00401 { 00402 pc.printf("Init Fail\r\n"); 00403 } 00404 pc.printf("Initializing done\r\n"); 00405 memset(word, 0, sizeof(word)); 00406 }else 00407 if(strcmp("init_bw_QQVGA", word) == 0) // Set up for 160*120 pixels YUV (Only Y) 00408 { 00409 format = 'b'; 00410 resolution = QQVGA; 00411 if(camera.Init('b', QQVGA) != 1) 00412 { 00413 pc.printf("Init Fail\r\n"); 00414 } 00415 pc.printf("Initializing done\r\n"); 00416 memset(word, 0, sizeof(word)); 00417 }else 00418 /*if(strcmp("reset", word) == 0) 00419 { 00420 mbed_reset(); 00421 }else*/ 00422 if(strcmp("time", word) == 0) 00423 { 00424 pc.printf("Tot time acq + send (mbed): %dms\r\n", t2-t1); 00425 memset(word, 0, sizeof(word)); 00426 }else 00427 if(strcmp("reg_status", word) == 0) 00428 { 00429 int i = 0; 00430 pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F"); 00431 for (i=0;i<OV7670_REGMAX;i++) 00432 { 00433 int data; 00434 data = camera.ReadReg(i); // READ REG 00435 if ((i & 0x0F) == 0) 00436 { 00437 pc.printf("\r\n%02X : ",i); 00438 } 00439 pc.printf("%02X ",data); 00440 } 00441 pc.printf("\r\n"); 00442 } 00443 00444 memset(word, 0, sizeof(word)); 00445 00446 } 00447 00448 uint32_t createRGB(int z, int r, int g, int b) 00449 { 00450 return ((z & 0xff) << 24)+((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff); 00451 } 00452 00453 00454 void CameraSnap() 00455 { 00456 00457 camera.CaptureNext(); 00458 while(camera.CaptureDone() == false); 00459 camera.ReadStart(); 00460 int xx = 0; 00461 int yy = 0; 00462 for(int x = 0; x<resolution; x++) 00463 { 00464 // Read in the first half of the image 00465 /* if(format == 'b' && resolution != VGA) 00466 { 00467 camera.ReadOnebyte(); 00468 }else 00469 if(format == 'y' || format == 'r') 00470 { 00471 pc.putc(camera.ReadOnebyte()); 00472 } */ 00473 // Read in the Second half of the image 00474 //pc.putc(camera.ReadOnebyte()); // Y only 00475 00476 camera.ReadOnebyte(); 00477 int l = camera.ReadOnebyte(); 00478 uint32_t k = createRGB(255, l, l, l); 00479 lcd.DrawPixel(xx+10, yy+10, k); 00480 xx++; 00481 if (xx >= 160) { 00482 yy++; 00483 xx =0; 00484 } 00485 00486 } 00487 camera.ReadStop(); 00488 snap++; 00489 }
Generated on Thu Jul 14 2022 14:58:49 by
1.7.2