Lcd companion boards support (VKLCD50RTA & VKLCD70RT)
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* 00002 Permission is hereby granted, free of charge, to any person obtaining a copy 00003 of this software and associated documentation files (the "Software"), to deal 00004 in the Software without restriction, including without limitation the rights 00005 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00006 copies of the Software, and to permit persons to whom the Software is 00007 furnished to do so, subject to the following conditions: 00008 00009 The above copyright notice and this permission notice shall be included in 00010 all copies or substantial portions of the Software. 00011 00012 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00013 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00014 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00015 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00016 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00018 THE SOFTWARE. 00019 */ 00020 00021 00022 #define __SOFT_JPEG__ 00023 00024 #include "mbed.h" 00025 #include "rga_func.h" 00026 #include "DisplayBace.h" 00027 #include "rtos.h" 00028 #include "LcdCfg.h" 00029 #include "Touch.h" 00030 #include "rza_io_regrw.h" 00031 #include "USBHostCam.h" 00032 //#include "JPEG_Converter.h" 00033 00034 #include "Images/BinaryImage_RZ_A1H.h" 00035 00036 #ifdef __SOFT_JPEG__ 00037 #include "jpeglib.h" 00038 #include <setjmp.h> 00039 #endif 00040 00041 #define VIDEO_CVBS (0) /* Analog Video Signal */ 00042 #define VIDEO_CMOS_CAMERA (1) /* Digital Video Signal */ 00043 00044 #define VIDEO_YCBCR422 (0) 00045 #define VIDEO_RGB888 (1) 00046 #define VIDEO_RGB565 (2) 00047 00048 /**** User Selection *********/ 00049 #define VIDEO_INPUT_METHOD (VIDEO_CVBS) /* Select VIDEO_CVBS or VIDEO_CMOS_CAMERA */ 00050 #define VIDEO_INPUT_FORMAT (VIDEO_RGB565) /* Select VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565 */ 00051 #define USE_VIDEO_CH (0) /* Select 0 or 1 If selecting VIDEO_CMOS_CAMERA, should be 0.) */ 00052 #define VIDEO_PAL (1) /* Select 0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */ 00053 /*****************************/ 00054 00055 #if USE_VIDEO_CH == (0) 00056 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_0) 00057 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S0_VFIELD) 00058 #else 00059 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_1) 00060 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S1_VFIELD) 00061 #endif 00062 00063 /** Video and Grapics (GRAPHICS_LAYER_0) parameter **/ 00064 /* NTSC or PAL */ 00065 #if VIDEO_PAL == 0 00066 #define COL_SYS (DisplayBase::COL_SYS_NTSC_358) 00067 #else 00068 #define COL_SYS (DisplayBase::COL_SYS_PAL_443) 00069 #endif 00070 00071 /* Video input and LCD layer 0 output */ 00072 #if VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 00073 #define VIDEO_FORMAT (DisplayBase::VIDEO_FORMAT_YCBCR422) 00074 #define GRAPHICS_FORMAT (DisplayBase::GRAPHICS_FORMAT_YCBCR422) 00075 #define WR_RD_WRSWA (DisplayBase::WR_RD_WRSWA_NON) 00076 #elif VIDEO_INPUT_FORMAT == VIDEO_RGB565 00077 #define VIDEO_FORMAT (DisplayBase::VIDEO_FORMAT_RGB565) 00078 #define GRAPHICS_FORMAT (DisplayBase::GRAPHICS_FORMAT_RGB565) 00079 #define WR_RD_WRSWA (DisplayBase::WR_RD_WRSWA_32_16BIT) 00080 #else 00081 #define VIDEO_FORMAT (DisplayBase::VIDEO_FORMAT_RGB888) 00082 #define GRAPHICS_FORMAT (DisplayBase::GRAPHICS_FORMAT_RGB888) 00083 #define WR_RD_WRSWA (DisplayBase::WR_RD_WRSWA_32BIT) 00084 #endif 00085 00086 /* NOSIGNAL bit position */ 00087 #define NOSIGNAL (11u) 00088 #define MASK(n) (1<<(n)) 00089 00090 #define MAX_TRY 3 00091 00092 /* FRAME BUFFER Parameter */ 00093 #if ( VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 || VIDEO_INPUT_FORMAT == VIDEO_RGB565 ) 00094 #define FRAME_BUFFER_BYTE_PER_PIXEL (2u) 00095 #else 00096 #define FRAME_BUFFER_BYTE_PER_PIXEL (4u) 00097 #endif 00098 #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u) 00099 #define FASTR_RENDER user_video_buffer 00100 00101 #define DRAW_RECTANGLE_CNT_MAX (4) 00102 #define TOUCH_NUM (1u) 00103 #define ROTRNDR_SIZE ((uint8_t*)Board_wide_jpg_File - (uint8_t *)Board_jpg_File) 00104 #define SCRRNDR_SIZE ((uint8_t*)TopScrn_jpg_File - (uint8_t *)Board_wide_jpg_File) 00105 00106 #define VID_X 0 00107 #define VID_Y 0 00108 #define VID_W LCD_PIXEL_WIDTH-SLIDE_WIDTH 00109 #define VID_H SLIDE_WIDTH 00110 00111 #define RVID_X SLIDE_WIDTH 00112 #define RVID_Y LCD_PIXEL_HEIGHT-SLIDE_WIDTH 00113 #define RVID_W LCD_PIXEL_WIDTH-SLIDE_WIDTH 00114 #define RVID_H SLIDE_WIDTH 00115 00116 00117 #define CAM_X LCD_PIXEL_WIDTH-SLIDE_WIDTH 00118 #define CAM_Y 0 00119 #define CAM_W SLIDE_WIDTH 00120 #define CAM_H LCD_PIXEL_HEIGHT 00121 00122 #define RCAM_X 0 00123 #define RCAM_Y 0 00124 #define RCAM_W SLIDE_WIDTH 00125 #define RCAM_H LCD_PIXEL_HEIGHT 00126 00127 00128 typedef enum { 00129 RGA_FUNC_NON, 00130 RGA_FUNC_DRAW_RECTANGLE, 00131 RGA_FUNC_DRAW_IMAGE, 00132 RGA_FUNC_DISSOLVE, 00133 RGA_FUNC_SCROLL, 00134 RGA_FUNC_ZOOM, 00135 RGA_FUNC_ROTATION, 00136 RGA_FUNC_ACCELERATE, 00137 RGA_FUNC_ANIME_EASE, 00138 RGA_FUNC_ANIME_LINEAR, 00139 RGA_FUNC_ANIME_EASE_IN, 00140 RGA_FUNC_ANIME_EASE_OUT, 00141 RGA_FUNC_ANIME_EASE_IN_OUT, 00142 RGA_FUNC_RETURN, 00143 RGA_FUNC_AUTO_MANUAL, 00144 RGA_FUNC_VIDEO, 00145 RGA_FUNC_USBCAM, 00146 RGA_FUNC_END 00147 } func_code_t; 00148 00149 DigitalOut test_point(LED1); 00150 PwmOut lcd_cntrst(P8_15); 00151 DisplayBase Display; 00152 Touch STMPE811; 00153 USBHostCam Cam(_432x240); 00154 interact_t Interaction_mode; 00155 00156 typedef struct { 00157 uint32_t x; /**< The position of the x-coordinate. */ 00158 uint32_t y; /**< The position of the y-coordinate. */ 00159 bool touch_down; /**< IS stylus still down */ 00160 } touch_pos_t; 00161 00162 typedef struct { 00163 uint32_t pic_pos_x; /* X position of the key picture. */ 00164 uint32_t pic_pos_y; /* Y position of the key picture. */ 00165 uint32_t pic_width; /* Width of the key picture. */ 00166 uint32_t pic_height; /* Height of the key picture. */ 00167 func_code_t func_code; /* func code of the key picture. */ 00168 } key_pic_info_t; 00169 00170 #ifdef __SOFT_JPEG__ 00171 struct my_error_mgr { 00172 struct jpeg_error_mgr pub; /* "public" fields */ 00173 00174 jmp_buf setjmp_buffer; /* for return to caller */ 00175 }; 00176 00177 typedef struct my_error_mgr * my_error_ptr; 00178 #endif 00179 00180 #if defined(__ICCARM__) 00181 #pragma data_alignment=32 00182 static uint8_t user_frame_buffer1[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]; 00183 static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]; 00184 static uint8_t user_video_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]; 00185 #pragma data_alignment=4 00186 #else 00187 static uint8_t user_frame_buffer1[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ 00188 static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ 00189 static uint8_t user_video_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */ 00190 static uint8_t shot_buffer[100 * 1024]__attribute((aligned(32))); /* 32 bytes aligned */ 00191 //static uint8_t shot_buffer[200*1024]__attribute((section("NC_BSS"),aligned(32))); /* 32 bytes aligned */ 00192 #endif 00193 static frame_buffer_t frame_buffer_info; 00194 static volatile int32_t vsync_count = 0; 00195 //static volatile int32_t vfield_count_0 = 1; 00196 static volatile bool usb_plug = false; 00197 static volatile bool video_signal = false; 00198 static volatile bool try_cam_connect = false; 00199 static volatile DisplayBase::slide_t slide_screen = DisplayBase::SLIDE_NONE ; 00200 static bool graphics_init_end = false; 00201 00202 00203 #if (LCD_VDC5_CH0_PANEL == LCD_CH0_PANEL_VKLCD70RT) 00204 static const key_pic_info_t top_screen_key_tbl[] = { 00205 /* X Y Width Height Func code */ 00206 { 40, 468, 102, 106, RGA_FUNC_DRAW_RECTANGLE }, /* RGA Func1 */ 00207 { 180, 468, 102, 106, RGA_FUNC_DRAW_IMAGE }, /* RGA Func2 */ 00208 { 322, 468, 102, 106, RGA_FUNC_DISSOLVE }, /* RGA Func3 */ 00209 { 462, 468, 102, 106, RGA_FUNC_SCROLL }, /* RGA Func4 */ 00210 { 884, 468, 102, 106, RGA_FUNC_ZOOM }, /* RGA Func5 */ 00211 { 604, 468, 102, 106, RGA_FUNC_ROTATION }, /* RGA Func6 */ 00212 { 744, 468, 102, 106, RGA_FUNC_ACCELERATE }, /* RGA Func7 */ 00213 { VID_X, VID_Y, VID_W, VID_H, RGA_FUNC_VIDEO }, /* RGA FuncN */ 00214 { CAM_X, CAM_Y, CAM_W, CAM_H, RGA_FUNC_USBCAM }, 00215 { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ 00216 }; 00217 00218 static const key_pic_info_t return_key_tbl[] = { 00219 /* X Y Width Height Func code */ 00220 { 792, 6, 226, 93, RGA_FUNC_RETURN }, /* Return Top Screen */ 00221 { 849, 230, 117, 124, RGA_FUNC_AUTO_MANUAL }, /* Interaction_Mode */ 00222 { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ 00223 }; 00224 00225 static const key_pic_info_t animetion_timing_key_tbl[] = { 00226 /* X Y Width Height Func code */ 00227 { 792, 6, 226, 93, RGA_FUNC_RETURN }, /* Return Top Screen */ 00228 { 21, 501, 173, 66, RGA_FUNC_ANIME_EASE }, /* ease */ 00229 { 220, 501, 173, 66, RGA_FUNC_ANIME_LINEAR }, /* linear */ 00230 { 422, 501, 173, 66, RGA_FUNC_ANIME_EASE_IN }, /* ease-in */ 00231 { 623, 501, 173, 66, RGA_FUNC_ANIME_EASE_OUT }, /* ease-out */ 00232 { 823, 501, 173, 66, RGA_FUNC_ANIME_EASE_IN_OUT }, /* ease-in-out */ 00233 { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ 00234 }; 00235 #else 00236 static const key_pic_info_t top_screen_key_tbl[] = { 00237 /* X Y Width Height Func code */ 00238 { 18, 216, 50, 50, RGA_FUNC_DRAW_RECTANGLE }, /* RGA Func1 */ 00239 { 84, 216, 50, 50, RGA_FUNC_DRAW_IMAGE }, /* RGA Func2 */ 00240 { 150, 216, 50, 50, RGA_FUNC_DISSOLVE }, /* RGA Func3 */ 00241 { 216, 216, 50, 50, RGA_FUNC_SCROLL }, /* RGA Func4 */ 00242 { 414, 216, 50, 50, RGA_FUNC_ZOOM }, /* RGA Func5 */ 00243 { 282, 216, 50, 50, RGA_FUNC_ROTATION }, /* RGA Func6 */ 00244 { 348, 216, 50, 50, RGA_FUNC_ACCELERATE }, /* RGA Func7 */ 00245 { VID_X, VID_Y, VID_W, VID_H, RGA_FUNC_VIDEO }, /* RGA FuncN */ 00246 { CAM_X, CAM_Y, CAM_W, CAM_H, RGA_FUNC_USBCAM }, 00247 { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ 00248 }; 00249 00250 static const key_pic_info_t return_key_tbl[] = { 00251 /* X Y Width Height Func code */ 00252 { 372, 6, 104, 40, RGA_FUNC_RETURN }, /* Return Top Screen */ 00253 { 398, 104, 55, 56, RGA_FUNC_AUTO_MANUAL }, /* Interaction_Mode */ 00254 { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ 00255 }; 00256 00257 static const key_pic_info_t animetion_timing_key_tbl[] = { 00258 /* X Y Width Height Func code */ 00259 { 372, 6, 104, 40, RGA_FUNC_RETURN }, /* Return Top Screen */ 00260 { 10, 227, 81, 30, RGA_FUNC_ANIME_EASE }, /* ease */ 00261 { 103, 227, 81, 30, RGA_FUNC_ANIME_LINEAR }, /* linear */ 00262 { 198, 227, 81, 30, RGA_FUNC_ANIME_EASE_IN }, /* ease-in */ 00263 { 292, 227, 81, 30, RGA_FUNC_ANIME_EASE_OUT }, /* ease-out */ 00264 { 386, 227, 81, 30, RGA_FUNC_ANIME_EASE_IN_OUT }, /* ease-in-out */ 00265 { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ 00266 }; 00267 #endif 00268 00269 static const key_pic_info_t video_screen_key_tbl[] = { 00270 /* X Y Width Height Func code */ 00271 {RVID_X, RVID_Y, RVID_W, RVID_H, RGA_FUNC_RETURN }, /* Return Top Screen */ 00272 { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ 00273 }; 00274 00275 static const key_pic_info_t cam_screen_key_tbl[] = { 00276 /* X Y Width Height Func code */ 00277 {RCAM_X, RCAM_Y, RCAM_W, RCAM_H, RGA_FUNC_RETURN }, /* Return Top Screen */ 00278 { 0, 0, 0, 0, RGA_FUNC_END } /* table end */ 00279 }; 00280 00281 #ifdef __SOFT_JPEG__ 00282 METHODDEF(void) 00283 my_error_exit (j_common_ptr cinfo) 00284 { 00285 /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ 00286 my_error_ptr myerr = (my_error_ptr) cinfo->err; 00287 00288 /* Always display the message. */ 00289 /* We could postpone this until after returning, if we chose. */ 00290 (*cinfo->err->output_message) (cinfo); 00291 00292 /* Return control to the setjmp point */ 00293 longjmp(myerr->setjmp_buffer, 1); 00294 } 00295 #endif 00296 00297 00298 /****** LCD ******/ 00299 static void IntCallbackFunc_LoVsync(DisplayBase::int_type_t int_type) { 00300 bool plug = Cam.plugged(); 00301 /* Interrupt callback function for Vsync interruption */ 00302 if (vsync_count > 0) { 00303 vsync_count--; 00304 } 00305 00306 if(slide_screen != DisplayBase::SLIDE_NONE ) 00307 { 00308 Display.Graphics_Read_Change_More(DisplayBase::GRAPHICS_LAYER_2 , 00309 (void *)frame_buffer_info.buffer_address[frame_buffer_info.draw_buffer_index], FRAME_BUFFER_STRIDE, (DisplayBase::slide_t *)&slide_screen); 00310 } 00311 00312 /* Read NOSIGNAL bit */ 00313 video_signal = (RZA_IO_RegRead_16(&DVDEC0.VSYNCSR, NOSIGNAL, MASK(NOSIGNAL)))? false : true; 00314 /* Read USB ATTCH DTTCH signals */ 00315 if(plug ^ usb_plug) 00316 { 00317 try_cam_connect = plug; 00318 usb_plug = plug; 00319 } 00320 } 00321 00322 static void Wait_Vsync(const int32_t wait_count) { 00323 /* Wait for the specified number of times Vsync occurs */ 00324 vsync_count = wait_count; 00325 while (vsync_count > 0) { 00326 /* Do nothing */ 00327 } 00328 } 00329 00330 static void IntCallbackFunc_Vfield_0(DisplayBase::int_type_t int_type) { 00331 /*DisplayBase::graphics_error_t error; 00332 00333 // Interrupt callback function 00334 if (vfield_count_0 == 0) { 00335 vfield_count_0 = 1; 00336 error = Display.Video_Stop( DisplayBase::VIDEO_INPUT_CHANNEL_0 ); 00337 if (error != DisplayBase::GRAPHICS_OK) { 00338 printf("Line %d, error %d\n", __LINE__, error); 00339 mbed_die(); 00340 } 00341 } else { 00342 ; 00343 }*/ 00344 } 00345 00346 static void Init_LCD_Display(void) { 00347 DisplayBase::graphics_error_t error; 00348 DisplayBase::lcd_config_t lcd_config; 00349 00350 #if (LCD_VDC5_CH0_PANEL == LCD_CH0_PANEL_VKLCD70RT) 00351 PinName lvds_pin[] = {P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0}; 00352 Display.Graphics_Lvds_Port_Init(lvds_pin, sizeof(lvds_pin)/sizeof(lvds_pin[0])); 00353 #else /* D15, D14, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0, DE, CLK */ 00354 PinName lcd_pin[] = {P4_7, P4_6, P4_5, P4_4, P4_3, P4_2, P4_1, P4_0, P3_15, P3_14, P3_13, P3_12, P3_11, P3_10, P3_9, P3_8, P3_1, P3_0}; 00355 Display.Graphics_Lcd_Port_Init(lcd_pin, sizeof(lcd_pin)/sizeof(lcd_pin[0])); 00356 #endif 00357 00358 00359 /* Graphics initialization process */ 00360 lcd_config = LcdCfgTbl; 00361 error = Display.Graphics_init(&lcd_config); 00362 if (error != DisplayBase::GRAPHICS_OK ) { 00363 printf("Line %d, error %d\n", __LINE__, error); 00364 mbed_die(); 00365 } 00366 00367 /* Interrupt callback function setting (Vsync signal output from scaler 0) */ 00368 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC , 0, IntCallbackFunc_LoVsync); 00369 if (error != DisplayBase::GRAPHICS_OK ) { 00370 printf("Line %d, error %d\n", __LINE__, error); 00371 mbed_die(); 00372 } 00373 00374 graphics_init_end = true; 00375 } 00376 00377 /****** Video ******/ 00378 static void Init_Video(void) { 00379 DisplayBase::graphics_error_t error; 00380 00381 /* Graphics initialization process */ 00382 if (graphics_init_end == false) { 00383 /* When not initializing LCD, this processing is needed. */ 00384 error = Display.Graphics_init(NULL); 00385 if (error != DisplayBase::GRAPHICS_OK ) { 00386 printf("Line %d, error %d\n", __LINE__, error); 00387 mbed_die(); 00388 } 00389 graphics_init_end = true; 00390 } 00391 00392 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC , NULL); 00393 if( error != DisplayBase::GRAPHICS_OK ) { 00394 printf("Line %d, error %d\n", __LINE__, error); 00395 mbed_die(); 00396 } 00397 00398 /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */ 00399 error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield_0); 00400 if (error != DisplayBase::GRAPHICS_OK ) { 00401 printf("Line %d, error %d\n", __LINE__, error); 00402 mbed_die(); 00403 } 00404 } 00405 00406 static void Start_Video(DisplayBase::video_input_channel_t ch, uint8_t * p_frame_buffer, 00407 uint16_t pos_x, uint16_t pos_y, uint16_t width, uint16_t height) { 00408 DisplayBase::graphics_error_t error; 00409 //uint8_t * p_buf; 00410 00411 //p_buf = p_frame_buffer + (FRAME_BUFFER_BYTE_PER_PIXEL * pos_x) + (FRAME_BUFFER_STRIDE * pos_y); 00412 00413 /* Video capture setting (progressive form fixed) */ 00414 error = Display.Video_Write_Setting( 00415 ch, 00416 COL_SYS, 00417 p_frame_buffer, //p_buf, 00418 FRAME_BUFFER_STRIDE, 00419 VIDEO_FORMAT, 00420 WR_RD_WRSWA, 00421 height, //(height & ~7u), /* A multiple of 8 */ 00422 width //(width & ~15u) /* A multiple of 16 */ 00423 ); 00424 if (error != DisplayBase::GRAPHICS_OK ) { 00425 printf("Line %d, error %d\n", __LINE__, error); 00426 mbed_die(); 00427 } 00428 00429 /* Video write process start */ 00430 error = Display.Video_Start(ch); 00431 if (error != DisplayBase::GRAPHICS_OK ) { 00432 printf("Line %d, error %d\n", __LINE__, error); 00433 mbed_die(); 00434 } 00435 00436 error = Display.Video_Stop( DisplayBase::VIDEO_INPUT_CHANNEL_0 ); 00437 if (error != DisplayBase::GRAPHICS_OK ) { 00438 printf("Line %d, error %d\n", __LINE__, error); 00439 mbed_die(); 00440 } 00441 } 00442 00443 static void Start_LCD_Display(uint8_t * p_buf) { 00444 DisplayBase::rect_t rect; 00445 00446 rect.vs = 0; 00447 rect.vw = LCD_PIXEL_HEIGHT; 00448 rect.hs = 0; 00449 rect.hw = LCD_PIXEL_WIDTH; 00450 Display.Graphics_Read_Setting( 00451 DisplayBase::GRAPHICS_LAYER_0 , 00452 (void *)user_video_buffer, 00453 FRAME_BUFFER_STRIDE, 00454 GRAPHICS_FORMAT, 00455 WR_RD_WRSWA, 00456 &rect 00457 ); 00458 00459 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0 ); 00460 00461 rect.vs = 0; 00462 rect.vw = LCD_PIXEL_HEIGHT; 00463 rect.hs = 0; 00464 rect.hw = LCD_PIXEL_WIDTH; 00465 Display.Graphics_Read_Setting( 00466 DisplayBase::GRAPHICS_LAYER_2 , 00467 (void *)p_buf, 00468 FRAME_BUFFER_STRIDE, 00469 GRAPHICS_FORMAT, 00470 WR_RD_WRSWA, 00471 &rect 00472 ); 00473 00474 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_2 ); 00475 } 00476 00477 static void Update_LCD_Display(frame_buffer_t * frmbuf_info) { 00478 Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_2 , 00479 (void *)frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]); 00480 Wait_Vsync(1); 00481 } 00482 00483 static void Update_VIDEO_Display(frame_buffer_t * frmbuf_info) { 00484 Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0 , 00485 (void *)frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]); 00486 Wait_Vsync(1); 00487 } 00488 00489 static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) { 00490 if (frmbuf_info->draw_buffer_index == 1) { 00491 frmbuf_info->draw_buffer_index = 0; 00492 } else { 00493 frmbuf_info->draw_buffer_index = 1; 00494 } 00495 } 00496 00497 00498 /****** Touch ******/ 00499 static func_code_t Scan_Key(const key_pic_info_t * key_tbl, const uint32_t pos_x, const uint32_t pos_y) { 00500 func_code_t ret = RGA_FUNC_NON; 00501 00502 while (ret == RGA_FUNC_NON) { 00503 if (key_tbl->func_code == RGA_FUNC_END) { 00504 break; 00505 } 00506 /* Check the range of the X position */ 00507 if ((pos_x >= key_tbl->pic_pos_x) && (pos_x <= (key_tbl->pic_pos_x + key_tbl->pic_width))) { 00508 /* Check the range of the Y position */ 00509 if ((pos_y >= key_tbl->pic_pos_y) && (pos_y <= (key_tbl->pic_pos_y + key_tbl->pic_height))) { 00510 /* Decide the func code. */ 00511 ret = key_tbl->func_code; 00512 } 00513 } 00514 key_tbl++; 00515 } 00516 00517 return ret; 00518 } 00519 00520 static int GetCoordinates(touch_pos_t * p_touch) { 00521 touch_pos_t * wk_touch; 00522 int count = 0; 00523 int i; 00524 00525 if (p_touch != NULL) 00526 { 00527 wk_touch = p_touch; 00528 wk_touch->x = 0; 00529 wk_touch->y = 0; 00530 wk_touch->touch_down = false; 00531 00532 wk_touch->touch_down = STMPE811.Handle_touch((uint8_t*)&count); 00533 if(count) 00534 { 00535 wk_touch->x = STMPE811.x; 00536 wk_touch->y = STMPE811.y; 00537 } 00538 } 00539 00540 return count; 00541 } 00542 00543 /****** Efect ******/ 00544 static void Exe_RGA_Func(func_code_t func_name, frame_buffer_t* frmbuf_info) { 00545 uint8_t touch_num = 0; 00546 touch_pos_t touch_pos[TOUCH_NUM]; 00547 00548 switch (func_name) { 00549 case RGA_FUNC_DRAW_RECTANGLE: 00550 bool key_on = false; 00551 bool first = false; 00552 bool second = false; 00553 int cnt = 0; 00554 int color_cnt = 0; 00555 int x_0 = 0; 00556 int y_0 = 0; 00557 draw_rectangle_pos_t pos_tbl[DRAW_RECTANGLE_CNT_MAX] = {0}; 00558 00559 pos_tbl[0].style = "#FF0000"; /* red */ 00560 pos_tbl[1].style = "#00FF00"; /* green */ 00561 pos_tbl[2].style = "#0000FF"; /* blue */ 00562 pos_tbl[3].style = "#000000"; /* black */ 00563 00564 while (1) { 00565 /* Get coordinates */ 00566 touch_num = GetCoordinates(touch_pos); 00567 if (touch_num != 0) 00568 { 00569 if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) { 00570 break; 00571 } 00572 if(touch_pos[0].touch_down) { 00573 if(!key_on) { 00574 pos_tbl[cnt].x = x_0 = touch_pos[0].x; 00575 pos_tbl[cnt].y = y_0 = touch_pos[0].y; 00576 pos_tbl[cnt].w = 0; 00577 pos_tbl[cnt].h = 0; 00578 if(cnt == 0) { 00579 for (color_cnt = 1; color_cnt < DRAW_RECTANGLE_CNT_MAX; color_cnt++) { 00580 pos_tbl[color_cnt].x = 0; 00581 pos_tbl[color_cnt].y = 0; 00582 pos_tbl[color_cnt].w = 0; 00583 pos_tbl[color_cnt].h = 0; 00584 } 00585 } 00586 key_on = true; 00587 } 00588 else { 00589 if(touch_pos[0].x >= x_0) { 00590 pos_tbl[cnt].x = x_0; 00591 pos_tbl[cnt].w = touch_pos[0].x - pos_tbl[cnt].x; 00592 } 00593 else { 00594 pos_tbl[cnt].x = touch_pos[0].x; 00595 pos_tbl[cnt].w = x_0 - touch_pos[0].x; 00596 } 00597 00598 if(touch_pos[0].y >= y_0) { 00599 pos_tbl[cnt].y = y_0; 00600 pos_tbl[cnt].h = touch_pos[0].y - pos_tbl[cnt].y; 00601 } 00602 else { 00603 pos_tbl[cnt].y = touch_pos[0].y; 00604 pos_tbl[cnt].h = y_0 - touch_pos[0].y; 00605 } 00606 } 00607 00608 } 00609 else { 00610 if(key_on) { 00611 if(touch_pos[0].x >= x_0) { 00612 pos_tbl[cnt].x = x_0; 00613 pos_tbl[cnt].w = touch_pos[0].x - pos_tbl[cnt].x; 00614 } 00615 else { 00616 pos_tbl[cnt].x = touch_pos[0].x; 00617 pos_tbl[cnt].w = x_0 - touch_pos[0].x; 00618 } 00619 00620 if(touch_pos[0].y >= y_0) { 00621 pos_tbl[cnt].y = y_0; 00622 pos_tbl[cnt].h = touch_pos[0].y - pos_tbl[cnt].y; 00623 } 00624 else { 00625 pos_tbl[cnt].y = touch_pos[0].y; 00626 pos_tbl[cnt].h = y_0 - touch_pos[0].y; 00627 } 00628 00629 cnt++; 00630 if (cnt == DRAW_RECTANGLE_CNT_MAX) 00631 cnt = 0; 00632 key_on = false; 00633 } 00634 else 00635 { 00636 00637 } 00638 } 00639 } 00640 /* Draw screen */ 00641 Swap_FrameBuffer(frmbuf_info); 00642 RGA_Func_DrawRectangle(frmbuf_info, pos_tbl, DRAW_RECTANGLE_CNT_MAX); 00643 Update_LCD_Display(frmbuf_info); 00644 } 00645 break; 00646 case RGA_FUNC_DRAW_IMAGE: 00647 int center_pos_x = 320; 00648 int center_pos_y = 110; 00649 while (1) { 00650 /* Get coordinates */ 00651 touch_num = GetCoordinates(touch_pos); 00652 if (touch_num != 0) { 00653 if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) { 00654 break; 00655 } 00656 center_pos_x = touch_pos[0].x; 00657 center_pos_y = touch_pos[0].y; 00658 } 00659 /* Draw screen */ 00660 Swap_FrameBuffer(frmbuf_info); 00661 RGA_Func_DrawImage(frmbuf_info, center_pos_x, center_pos_y); 00662 Update_LCD_Display(frmbuf_info); 00663 } 00664 break; 00665 case RGA_FUNC_DISSOLVE: 00666 float32_t work_alpha = 0.0f; 00667 uint16_t xa = LCD_PIXEL_WIDTH; 00668 00669 RGA_Func_Dissolve(frmbuf_info, 0.0f, Interaction_mode); 00670 Swap_FrameBuffer(frmbuf_info); 00671 RGA_Func_Dissolve(frmbuf_info, 0.0f, Interaction_mode); 00672 Update_LCD_Display(frmbuf_info); 00673 memcpy(FASTR_RENDER, (uint8_t*)Board_jpg_File, ROTRNDR_SIZE); 00674 while (1) { 00675 /* Get coordinates */ 00676 touch_num = GetCoordinates(touch_pos); 00677 if (touch_num != 0) { 00678 func_code_t func_code; 00679 00680 func_code = Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y); 00681 if (func_code == RGA_FUNC_RETURN) { 00682 break; 00683 } 00684 00685 if(!touch_pos[0].touch_down && (func_code == RGA_FUNC_AUTO_MANUAL)) 00686 Interaction_mode = (Interaction_mode == AUTO_INTERACT)? MANUAL_INTERACT : AUTO_INTERACT; 00687 else 00688 work_alpha = (float32_t)touch_pos[0].x / (float32_t)(LCD_PIXEL_WIDTH); 00689 } 00690 if(Interaction_mode == AUTO_INTERACT) 00691 { 00692 xa= (xa >= LCD_PIXEL_WIDTH)? 0: (xa+1); 00693 work_alpha = (float32_t)xa / (float32_t)(LCD_PIXEL_WIDTH); 00694 } 00695 /* Draw screen */ 00696 Swap_FrameBuffer(frmbuf_info); 00697 RGA_Func_Diss(frmbuf_info, work_alpha, Interaction_mode, (graphics_image_t*)FASTR_RENDER); 00698 Update_LCD_Display(frmbuf_info); 00699 } 00700 break; 00701 case RGA_FUNC_SCROLL: 00702 int work_width_pos = 0; 00703 uint16_t xs = LCD_PIXEL_WIDTH; 00704 00705 RGA_Func_Scroll(frmbuf_info, 0, Interaction_mode); 00706 Swap_FrameBuffer(frmbuf_info); 00707 RGA_Func_Scroll(frmbuf_info, 0, Interaction_mode); 00708 Update_LCD_Display(frmbuf_info); 00709 memcpy(FASTR_RENDER, (uint8_t*)Board_wide_jpg_File, SCRRNDR_SIZE); 00710 while (1) { 00711 /* Get coordinates */ 00712 touch_num = GetCoordinates(touch_pos); 00713 if (touch_num != 0) { 00714 func_code_t func_code; 00715 00716 func_code = Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y); 00717 if (func_code == RGA_FUNC_RETURN) { 00718 break; 00719 } 00720 00721 if(!touch_pos[0].touch_down && (func_code == RGA_FUNC_AUTO_MANUAL)) 00722 Interaction_mode = (Interaction_mode == AUTO_INTERACT)? MANUAL_INTERACT : AUTO_INTERACT; 00723 else 00724 work_width_pos = SCROLL_MAX_NUM * ((float32_t)touch_pos[0].x / (float32_t)(LCD_PIXEL_WIDTH)); 00725 } 00726 if(Interaction_mode == AUTO_INTERACT) 00727 { 00728 xs= (xs >= LCD_PIXEL_WIDTH)? 0: (xs+1); 00729 work_width_pos = SCROLL_MAX_NUM * ((float32_t)xs / (float32_t)(LCD_PIXEL_WIDTH)); 00730 } 00731 /* Draw screen */ 00732 Swap_FrameBuffer(frmbuf_info); 00733 RGA_Func_Scr(frmbuf_info, work_width_pos, Interaction_mode, (graphics_image_t*)FASTR_RENDER); 00734 Update_LCD_Display(frmbuf_info); 00735 } 00736 break; 00737 case RGA_FUNC_ZOOM: 00738 int work_height_pos = ZOOM_MAX_NUM; 00739 uint16_t xz = LCD_PIXEL_WIDTH; 00740 00741 RGA_Func_Zoom(frmbuf_info, 0, Interaction_mode); 00742 Swap_FrameBuffer(frmbuf_info); 00743 RGA_Func_Zoom(frmbuf_info, 0, Interaction_mode); 00744 Update_LCD_Display(frmbuf_info); 00745 memcpy(FASTR_RENDER, (uint8_t*)Board_jpg_File, ROTRNDR_SIZE); 00746 while (1) { 00747 /* Get coordinates */ 00748 touch_num = GetCoordinates(touch_pos); 00749 if (touch_num != 0) { 00750 func_code_t func_code; 00751 00752 func_code = Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y); 00753 if (func_code == RGA_FUNC_RETURN) { 00754 break; 00755 } 00756 00757 if(!touch_pos[0].touch_down && (func_code == RGA_FUNC_AUTO_MANUAL)) 00758 Interaction_mode = (Interaction_mode == AUTO_INTERACT)? MANUAL_INTERACT : AUTO_INTERACT; 00759 else 00760 work_height_pos = ZOOM_MAX_NUM * ((float32_t)touch_pos[0].x / (float32_t)(LCD_PIXEL_WIDTH)); 00761 } 00762 if(Interaction_mode == AUTO_INTERACT) 00763 { 00764 xz= (xz >= LCD_PIXEL_WIDTH)? 0: (xz+1); 00765 work_height_pos = ZOOM_MAX_NUM * ((float32_t)xz / (float32_t)(LCD_PIXEL_WIDTH)); 00766 } 00767 /* Draw screen */ 00768 Swap_FrameBuffer(frmbuf_info); 00769 RGA_Func_Zo(frmbuf_info, work_height_pos, Interaction_mode, (graphics_image_t*)FASTR_RENDER); 00770 Update_LCD_Display(frmbuf_info); 00771 } 00772 break; 00773 case RGA_FUNC_ROTATION: 00774 graphics_matrix_float_t work_angle = 0; 00775 uint16_t xr = LCD_PIXEL_WIDTH; 00776 00777 RGA_Func_Rotation(frmbuf_info, 0, Interaction_mode); 00778 Swap_FrameBuffer(frmbuf_info); 00779 RGA_Func_Rotation(frmbuf_info, 0, Interaction_mode); 00780 Update_LCD_Display(frmbuf_info); 00781 memcpy(FASTR_RENDER, (uint8_t*)Board_jpg_File, ROTRNDR_SIZE); 00782 while (1) { 00783 /* Get coordinates */ 00784 touch_num = GetCoordinates(touch_pos); 00785 if (touch_num != 0) { 00786 func_code_t func_code; 00787 00788 func_code = Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y); 00789 if (func_code == RGA_FUNC_RETURN) { 00790 break; 00791 } 00792 00793 if(!touch_pos[0].touch_down && (func_code == RGA_FUNC_AUTO_MANUAL)) 00794 Interaction_mode = (Interaction_mode == AUTO_INTERACT)? MANUAL_INTERACT : AUTO_INTERACT; 00795 else 00796 work_angle = ROTATION_MAX_NUM * ((float32_t)touch_pos[0].x / (float32_t)(LCD_PIXEL_WIDTH)); 00797 } 00798 if(Interaction_mode == AUTO_INTERACT) 00799 { 00800 xr= (xr >= LCD_PIXEL_WIDTH)? 0: (xr+1); 00801 work_angle = ROTATION_MAX_NUM * ((float32_t)xr / (float32_t)(LCD_PIXEL_WIDTH)); 00802 } 00803 /* Draw screen */ 00804 Swap_FrameBuffer(frmbuf_info); 00805 RGA_Func_Rotor(frmbuf_info, work_angle, Interaction_mode, (graphics_image_t*)FASTR_RENDER); 00806 Update_LCD_Display(frmbuf_info); 00807 } 00808 break; 00809 case RGA_FUNC_ACCELERATE: 00810 int acce_frame_num = 0; 00811 int animation_timing = 0; 00812 float32_t work_relative_pos; 00813 00814 RGA_Func_Accelerate(frmbuf_info, 0, 0); 00815 Swap_FrameBuffer(frmbuf_info); 00816 RGA_Func_Accelerate(frmbuf_info, 0, 0); 00817 Update_LCD_Display(frmbuf_info); 00818 memcpy(FASTR_RENDER, (uint8_t*)Board_jpg_File, ROTRNDR_SIZE); 00819 while (1) { 00820 /* Get coordinates */ 00821 touch_num = GetCoordinates(touch_pos); 00822 if (touch_num != 0) { 00823 func_code_t func_code; 00824 00825 func_code = Scan_Key(animetion_timing_key_tbl, touch_pos[0].x, touch_pos[0].y); 00826 if (func_code == RGA_FUNC_RETURN) { 00827 break; 00828 } 00829 switch (func_code) { 00830 case RGA_FUNC_ANIME_EASE: 00831 animation_timing = 0; 00832 acce_frame_num = 0; 00833 break; 00834 case RGA_FUNC_ANIME_LINEAR: 00835 animation_timing = 1; 00836 acce_frame_num = 0; 00837 break; 00838 case RGA_FUNC_ANIME_EASE_IN: 00839 animation_timing = 2; 00840 acce_frame_num = 0; 00841 break; 00842 case RGA_FUNC_ANIME_EASE_OUT: 00843 animation_timing = 3; 00844 acce_frame_num = 0; 00845 break; 00846 case RGA_FUNC_ANIME_EASE_IN_OUT: 00847 animation_timing = 4; 00848 acce_frame_num = 0; 00849 break; 00850 default: 00851 /* Do Nothing */ 00852 break; 00853 } 00854 } 00855 work_relative_pos = acce_frame_num / (float32_t)ACCELERATE_MAX_NUM; 00856 acce_frame_num++; 00857 if (acce_frame_num > ACCELERATE_MAX_NUM) { 00858 acce_frame_num = 0; 00859 } 00860 /* Draw screen */ 00861 Swap_FrameBuffer(frmbuf_info); 00862 RGA_Func_Axel(frmbuf_info, animation_timing, work_relative_pos, (graphics_image_t*)FASTR_RENDER); 00863 Update_LCD_Display(frmbuf_info); 00864 } 00865 break; 00866 00867 case RGA_FUNC_VIDEO: 00868 static bool old_signal; 00869 00870 if(video_signal) 00871 { /* Video write process start */ 00872 if (Display.Video_Start(DisplayBase::VIDEO_INPUT_CHANNEL_0 ) != DisplayBase::GRAPHICS_OK ) { 00873 printf("Line %d, error %d\n", __LINE__, error); 00874 mbed_die(); 00875 } 00876 } 00877 else 00878 { 00879 frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index] = user_video_buffer; 00880 RGA_Func_DrawFullScreen(frmbuf_info, TstScrn_jpg_File); 00881 frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index] = (frmbuf_info->draw_buffer_index)? user_frame_buffer2 : user_frame_buffer1; 00882 } 00883 00884 old_signal = video_signal; 00885 slide_screen = DisplayBase::SLIDE_OUT_BOTTOM ; 00886 while(slide_screen !=DisplayBase::SLIDE_NONE ); 00887 frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index] = user_video_buffer; 00888 00889 while (1) { 00890 /* Get coordinates */ 00891 touch_num = GetCoordinates(touch_pos); 00892 if (touch_num != 0) { 00893 if (Scan_Key(video_screen_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) { 00894 if(video_signal) 00895 { 00896 if (Display.Video_Stop(DisplayBase::VIDEO_INPUT_CHANNEL_0 ) != DisplayBase::GRAPHICS_OK ) { 00897 printf("Line %d, error %d\n", __LINE__, error); 00898 mbed_die(); 00899 } 00900 } 00901 frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index] = (frmbuf_info->draw_buffer_index)? user_frame_buffer2 : user_frame_buffer1; 00902 slide_screen = DisplayBase::SLIDE_IN_BOTTOM ; 00903 break; 00904 } 00905 } 00906 00907 if(video_signal ^ old_signal) 00908 { 00909 if(video_signal) 00910 { 00911 if (Display.Video_Start(DisplayBase::VIDEO_INPUT_CHANNEL_0 ) != DisplayBase::GRAPHICS_OK ) { 00912 printf("Line %d, error %d\n", __LINE__, error); 00913 mbed_die(); 00914 } 00915 } 00916 else 00917 { 00918 if (Display.Video_Stop(DisplayBase::VIDEO_INPUT_CHANNEL_0 ) != DisplayBase::GRAPHICS_OK ) { 00919 printf("Line %d, error %d\n", __LINE__, error); 00920 mbed_die(); 00921 } 00922 Wait_Vsync(3); 00923 RGA_Func_DrawFullScreen(frmbuf_info, TstScrn_jpg_File); 00924 } 00925 old_signal = video_signal; 00926 } 00927 } 00928 break; 00929 00930 case RGA_FUNC_USBCAM: 00931 static int swaped_idx; 00932 static bool old_usbplug; 00933 static int try_recognize; 00934 int shot_size; 00935 00936 try_recognize = 0; 00937 swaped_idx = frmbuf_info->draw_buffer_index; 00938 frmbuf_info->buffer_address[(swaped_idx)? 0 : 1] = user_video_buffer; 00939 frmbuf_info->buffer_address[swaped_idx] = (swaped_idx)? user_frame_buffer1 : user_frame_buffer2; 00940 00941 RGA_Func_DrawFullScreen(frmbuf_info, CamScrn_jpg_File); 00942 if(!Cam.connected()) 00943 RGA_Func_DrawPNG(frmbuf_info, NoDevice_png_ARGB4444, NO_DEV_X, NO_DEV_Y); 00944 Swap_FrameBuffer(frmbuf_info); 00945 RGA_Func_DrawFullScreen(frmbuf_info, CamScrn_jpg_File); 00946 if(!Cam.connected()) 00947 RGA_Func_DrawPNG(frmbuf_info, NoDevice_png_ARGB4444, NO_DEV_X, NO_DEV_Y); 00948 Swap_FrameBuffer(frmbuf_info); 00949 00950 frmbuf_info->buffer_address[swaped_idx] = (swaped_idx)? user_frame_buffer2 : user_frame_buffer1; 00951 old_usbplug = usb_plug; 00952 slide_screen = DisplayBase::SLIDE_OUT_LEFT ; 00953 while(slide_screen !=DisplayBase::SLIDE_NONE ); 00954 frmbuf_info->buffer_address[swaped_idx] = (swaped_idx)? user_frame_buffer1 : user_frame_buffer2; 00955 00956 if(Cam.connected()) 00957 { 00958 RGA_Func_DrawFullScreen(frmbuf_info, NULL); 00959 Swap_FrameBuffer(frmbuf_info); 00960 RGA_Func_DrawFullScreen(frmbuf_info, NULL); 00961 } 00962 00963 00964 #ifdef __SOFT_JPEG__ 00965 // decompression with libJPEG 00966 //1: Allocate and initialize a JPEG decompression object 00967 //2: Specify the source of the compressed data (eg, a file) 00968 //3: Call jpeg_read_header() to obtain image info 00969 //4: Set parameters for decompression 00970 //5: jpeg_start_decompress(...); 00971 //6: while (scan lines remain to be read) 00972 // jpeg_read_scanlines(...); 00973 //7: jpeg_finish_decompress(...); 00974 //8: Release the JPEG decompression object 00975 00976 struct jpeg_decompress_struct cinfo; 00977 struct my_error_mgr jerr; 00978 JSAMPARRAY buffer; /* Output row buffer */ 00979 int row_stride; /* physical row width in output buffer */ 00980 //... 00981 cinfo.err = jpeg_std_error(&jerr.pub); /* We set up the normal JPEG error routines */ 00982 jerr.pub.error_exit = my_error_exit; /* then override error_exit. */ 00983 00984 /* Establish the setjmp return context for my_error_exit to use. */ 00985 if (setjmp(jerr.setjmp_buffer)) { 00986 /* If we get here, the JPEG code has signaled an error. 00987 * We need to clean up the JPEG object, close the input file, and return. 00988 */ 00989 jpeg_destroy_decompress(&cinfo); 00990 } 00991 00992 //1: 00993 jpeg_create_decompress(&cinfo); 00994 #endif 00995 00996 while (1) { 00997 /* Get coordinates */ 00998 touch_num = GetCoordinates(touch_pos); 00999 if (touch_num != 0) { 01000 if (Scan_Key(cam_screen_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) { 01001 frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index] = user_video_buffer; 01002 Update_VIDEO_Display(frmbuf_info); 01003 frmbuf_info->buffer_address[0] = user_frame_buffer1; 01004 frmbuf_info->buffer_address[1] = user_frame_buffer2; 01005 slide_screen = DisplayBase::SLIDE_IN_LEFT ; 01006 break; 01007 } 01008 } 01009 01010 if(Cam.connected()) 01011 { 01012 shot_size = Cam.readJPEG(shot_buffer, sizeof(shot_buffer)); 01013 //printf("JPEG size: %d\r\n", shot_size); 01014 //test_point = !test_point; 01015 01016 Swap_FrameBuffer(frmbuf_info); 01017 01018 #ifdef __SOFT_JPEG__ 01019 //2: 01020 jpeg_mem_src(&cinfo, shot_buffer ,shot_size); 01021 01022 //3: 01023 jpeg_read_header(&cinfo, TRUE); 01024 //4: 01025 // Default decompression parameters 01026 //5: 01027 jpeg_start_decompress(&cinfo); 01028 01029 //6: 01030 row_stride = cinfo.output_width * cinfo.output_components; 01031 buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1); 01032 while (cinfo.output_scanline < cinfo.output_height) { 01033 jpeg_read_scanlines(&cinfo, buffer, 1); 01034 01035 for(int i=0; i<cinfo.output_width; i++) 01036 { 01037 uint16_t _565; 01038 01039 _565 = (uint16_t)(0xF8 & buffer[0][(i*3)+2])>>3; 01040 _565 |= (uint16_t)(0xFC & buffer[0][(i*3)+1])<<3; 01041 _565 |= (uint16_t)(0xF8 & buffer[0][i*3])<<8; 01042 01043 ((uint16_t*)(frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]))[((cinfo.output_scanline-1)*LCD_PIXEL_WIDTH)+i] = _565; 01044 } 01045 } 01046 //7: 01047 jpeg_finish_decompress(&cinfo); 01048 01049 RGA_Func_DrawCamScreen(NULL); 01050 #else 01051 RGA_Func_DrawCamScreen(shot_buffer); 01052 #endif 01053 01054 Update_VIDEO_Display(frmbuf_info); 01055 01056 Cam.poll(); 01057 } 01058 01059 if(usb_plug ^ old_usbplug) 01060 { 01061 if(usb_plug) 01062 { 01063 //Swap_FrameBuffer(frmbuf_info); 01064 //RGA_Func_DrawFullScreen(frmbuf_info, CamScrn_jpg_File); 01065 //Update_VIDEO_Display(frmbuf_info); 01066 } 01067 else 01068 { 01069 Swap_FrameBuffer(frmbuf_info); 01070 RGA_Func_DrawFullScreen(frmbuf_info, CamScrn_jpg_File); 01071 RGA_Func_DrawPNG(frmbuf_info, NoDevice_png_ARGB4444, NO_DEV_X, NO_DEV_Y); 01072 Update_VIDEO_Display(frmbuf_info); 01073 } 01074 old_usbplug = usb_plug; 01075 } 01076 01077 if(try_cam_connect) 01078 { 01079 if(!Cam.connected()) 01080 { 01081 Cam.connect(); 01082 Thread::wait(500); 01083 if(try_recognize == 0) 01084 { 01085 Swap_FrameBuffer(frmbuf_info); 01086 RGA_Func_DrawFullScreen(frmbuf_info, CamScrn_jpg_File); 01087 Update_VIDEO_Display(frmbuf_info); 01088 } 01089 01090 try_recognize++; 01091 if(try_recognize > MAX_TRY) 01092 { 01093 try_cam_connect = false; 01094 Swap_FrameBuffer(frmbuf_info); 01095 RGA_Func_DrawFullScreen(frmbuf_info, CamScrn_jpg_File); 01096 RGA_Func_DrawPNG(frmbuf_info, NoDevice_png_ARGB4444, NO_DEV_X, NO_DEV_Y); 01097 Update_VIDEO_Display(frmbuf_info); 01098 } 01099 } 01100 else 01101 { 01102 try_cam_connect = false; 01103 RGA_Func_DrawFullScreen(frmbuf_info, NULL); 01104 Swap_FrameBuffer(frmbuf_info); 01105 RGA_Func_DrawFullScreen(frmbuf_info, NULL); 01106 Swap_FrameBuffer(frmbuf_info); 01107 } 01108 } 01109 else 01110 try_recognize = 0; 01111 } 01112 01113 #ifdef __SOFT_JPEG__ 01114 //8: 01115 jpeg_destroy_decompress(&cinfo); 01116 #endif 01117 break; 01118 01119 default : 01120 /* Do nothing */ 01121 break; 01122 } 01123 } 01124 01125 01126 //void test(int x) 01127 //{ 01128 // test_point=x; 01129 //} 01130 01131 int main(void) { 01132 func_code_t func_code; 01133 uint8_t touch_num = 0; 01134 touch_pos_t touch_pos[TOUCH_NUM]; 01135 01136 /* Initialization of LCD */ 01137 Init_LCD_Display(); /* When using LCD, please call before than Init_Video(). */ 01138 01139 /* Initialization of Video */ 01140 Init_Video(); 01141 01142 /* Start of Video ch0 */ 01143 Start_Video( 01144 DisplayBase::VIDEO_INPUT_CHANNEL_0 , /* Video input channe */ 01145 user_video_buffer, /* Output buffer */ 01146 0, /* The x coordinate of the upper-left corner */ 01147 0, /* The y coordinate of the upper-left corner */ 01148 LCD_PIXEL_WIDTH, /* width (A multiple of 16) */ 01149 LCD_PIXEL_HEIGHT /* height (A multiple of 8) */ 01150 ); 01151 01152 memset(user_frame_buffer1, 0, sizeof(user_frame_buffer1)); 01153 memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2)); 01154 frame_buffer_info.buffer_address[0] = user_frame_buffer1; 01155 frame_buffer_info.buffer_address[1] = user_frame_buffer2; 01156 frame_buffer_info.buffer_count = 2; 01157 frame_buffer_info.show_buffer_index = 0; 01158 frame_buffer_info.draw_buffer_index = 0; 01159 frame_buffer_info.width = LCD_PIXEL_WIDTH; 01160 frame_buffer_info.byte_per_pixel = FRAME_BUFFER_BYTE_PER_PIXEL; 01161 frame_buffer_info.stride = LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL; 01162 frame_buffer_info.height = LCD_PIXEL_HEIGHT; 01163 frame_buffer_info.pixel_format = PIXEL_FORMAT_RGB565; 01164 01165 /* Display Top Screen */ 01166 Set_RGAObject(&frame_buffer_info); 01167 RGA_Func_DrawFullScreen(&frame_buffer_info, TopScrn_jpg_File); 01168 01169 Swap_FrameBuffer(&frame_buffer_info); 01170 RGA_Func_DrawFullScreen(&frame_buffer_info, TopScrn_jpg_File); 01171 Swap_FrameBuffer(&frame_buffer_info); 01172 01173 /* Start of LCD */ 01174 Start_LCD_Display(frame_buffer_info.buffer_address[0]); 01175 01176 /* Backlight on */ 01177 Thread::wait(200); 01178 lcd_cntrst.period_us(100); 01179 lcd_cntrst.write(((float)LCD_CH0_INITIAL_DC)/100.0f); // 01180 01181 /* Reset touch IC */ 01182 STMPE811.Init(); 01183 01184 Interaction_mode = MANUAL_INTERACT; 01185 01186 while (1) { 01187 /* Get Coordinates */ 01188 touch_num = GetCoordinates(touch_pos); 01189 if (touch_num != 0) { 01190 func_code = Scan_Key(top_screen_key_tbl, touch_pos[0].x, touch_pos[0].y); 01191 if (func_code != RGA_FUNC_NON) { 01192 /* Wait key off */ 01193 while (1) { 01194 touch_num = GetCoordinates(touch_pos); 01195 if (touch_num == 0) { 01196 break; 01197 } 01198 Thread::wait(20); 01199 } 01200 01201 /* Execute RGA functions */ 01202 Exe_RGA_Func(func_code, &frame_buffer_info); 01203 01204 /* Return Top Screen */ 01205 touch_num = 0; 01206 touch_num = (RGA_Func_CheckPorts(&frame_buffer_info, false, false))? 1 : 0; 01207 touch_num = (RGA_Func_CheckPorts(&frame_buffer_info, video_signal, usb_plug))? 1 : 0; 01208 if(touch_num == 0) 01209 { 01210 Swap_FrameBuffer(&frame_buffer_info); 01211 RGA_Func_DrawFullScreen(&frame_buffer_info, TopScrn_jpg_File); 01212 } 01213 Update_LCD_Display(&frame_buffer_info); 01214 } 01215 } 01216 else 01217 if(RGA_Func_CheckPorts(&frame_buffer_info, video_signal, usb_plug)) 01218 Update_LCD_Display(&frame_buffer_info); 01219 Thread::wait(20); 01220 } 01221 } 01222 01223
Generated on Tue Jul 12 2022 14:32:43 by
1.7.2