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: GR-PEACH_video mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "DisplayBace.h" 00003 #include "rtos.h" 00004 00005 #define VIDEO_CVBS (0) /* Analog Video Signal */ 00006 #define VIDEO_CMOS_CAMERA (1) /* Digital Video Signal */ 00007 #define VIDEO_YCBCR422 (0) 00008 #define VIDEO_RGB888 (1) 00009 #define VIDEO_RGB565 (2) 00010 00011 /**** User Selection *********/ 00012 #define VIDEO_INPUT_METHOD (VIDEO_CVBS) /* Select VIDEO_CVBS or VIDEO_CMOS_CAMERA */ 00013 #define VIDEO_INPUT_FORMAT (VIDEO_YCBCR422) /* Select VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565 */ 00014 #define USE_VIDEO_CH (0) /* Select 0 or 1 If selecting VIDEO_CMOS_CAMERA, should be 0.) */ 00015 #define VIDEO_PAL (0) /* Select 0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */ 00016 /*****************************/ 00017 00018 #if USE_VIDEO_CH == (0) 00019 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_0) 00020 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S0_VFIELD) 00021 #else 00022 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_1) 00023 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S1_VFIELD) 00024 #endif 00025 00026 #if ( VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 || VIDEO_INPUT_FORMAT == VIDEO_RGB565 ) 00027 #define DATA_SIZE_PER_PIC (2u) 00028 #else 00029 #define DATA_SIZE_PER_PIC (4u) 00030 #endif 00031 00032 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128 00033 in accordance with the frame buffer burst transfer mode. */ 00034 #if VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA 00035 #define PIXEL_HW (640u) /* Camera */ 00036 #define PIXEL_VW (468u) /* Camera */ 00037 #else 00038 #define PIXEL_HW (800u) /* NTSC */ 00039 #define PIXEL_VW (480u) /* NTSC */ 00040 #endif 00041 00042 #define VIDEO_BUFFER_STRIDE (((PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u) 00043 #define VIDEO_BUFFER_HEIGHT (PIXEL_VW) 00044 00045 DigitalIn button(USER_BUTTON0); 00046 #if(1) //lcd 00047 DigitalOut lcd_pwon(P7_15); 00048 DigitalOut lcd_blon(P8_1); 00049 PwmOut lcd_cntrst(P8_15); 00050 I2C mI2c(I2C_SDA, I2C_SCL); 00051 00052 typedef struct { 00053 uint8_t y_h: 3, 00054 reserved: 1, 00055 x_h: 3, 00056 valid: 1; 00057 uint8_t x_l; 00058 uint8_t y_l; 00059 uint8_t z; 00060 } xyz_data_t; 00061 00062 typedef struct { 00063 uint8_t fingers: 4, 00064 reserved: 4; 00065 uint8_t keys; 00066 xyz_data_t xyz_data[2]; 00067 } stx_report_data_t; 00068 00069 static int get_coordinates(uint8_t *count, uint32_t *x0, uint32_t *y0, uint32_t *x1, uint32_t *y1) { 00070 char buf[10]; 00071 stx_report_data_t *pdata; 00072 int ret = -1; 00073 *count = 0; // Set point detected count to 0. 00074 00075 if (mI2c.read((0x55 << 1), buf, sizeof(buf)) == 0) { 00076 pdata = (stx_report_data_t *)buf; 00077 if (pdata->fingers) { 00078 if (pdata->xyz_data[0].valid) { 00079 *x0 = (pdata->xyz_data[0].x_h << 8) | pdata->xyz_data[0].x_l; 00080 *y0 = (pdata->xyz_data[0].y_h << 8) | pdata->xyz_data[0].y_l; 00081 (*count)++; 00082 } 00083 } 00084 if (pdata->xyz_data[1].valid) { 00085 *x1 = (pdata->xyz_data[1].x_h << 8) | pdata->xyz_data[1].x_l; 00086 *y1 = (pdata->xyz_data[1].y_h << 8) | pdata->xyz_data[1].y_l; 00087 (*count)++; 00088 } 00089 ret = 0; 00090 } 00091 00092 return ret; 00093 } 00094 #endif 00095 00096 #if defined(__ICCARM__) 00097 #pragma data_alignment=16 00098 static uint8_t FrameBuffer_Video[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]@ ".mirrorram"; //16 bytes aligned!; 00099 #pragma data_alignment=4 00100 #else 00101 static uint8_t FrameBuffer_Video[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16))); //16 bytes aligned!; 00102 #endif 00103 static volatile int32_t vsync_count = 0; 00104 static volatile int32_t vfield_count = 1; 00105 static int image_change = 0; 00106 00107 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type) 00108 { 00109 //Interrupt callback function 00110 if (vfield_count != 0) { 00111 vfield_count = 0; 00112 } else { 00113 vfield_count = 1; 00114 image_change = 1; 00115 } 00116 } 00117 00118 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) 00119 { 00120 //Interrupt callback function for Vsync interruption 00121 if (vsync_count > 0) { 00122 vsync_count--; 00123 } 00124 } 00125 00126 static void WaitVsync(const int32_t wait_count) 00127 { 00128 //Wait for the specified number of times Vsync occurs 00129 vsync_count = wait_count; 00130 while (vsync_count > 0) { 00131 /* Do nothing */ 00132 } 00133 } 00134 00135 int main(void) 00136 { 00137 /* Create DisplayBase object */ 00138 DisplayBase Display; 00139 DisplayBase::graphics_error_t error; 00140 00141 #if VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA 00142 DisplayBase::video_ext_in_config_t ext_in_config; 00143 PinName cmos_camera_pin[11] = { 00144 /* data pin */ 00145 P2_7, P2_6, P2_5, P2_4, P2_3, P2_2, P2_1, P2_0, 00146 /* control pin */ 00147 P10_0, /* DV0_CLK */ 00148 P1_0, /* DV0_Vsync */ 00149 P1_1 /* DV0_Hsync */ 00150 }; 00151 #endif 00152 #if(1) //lcd 00153 Thread::wait(500); 00154 00155 lcd_pwon = 1; 00156 lcd_blon = 1; 00157 00158 DisplayBase::lcd_config_t lcd_config; 00159 PinName lvds_pin[8] = { 00160 /* data pin */ 00161 P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0 00162 }; 00163 DisplayBase::rect_t rect; 00164 00165 lcd_config.lcd_type = DisplayBase::LCD_TYPE_LVDS; 00166 lcd_config.intputClock = 66.67f; 00167 lcd_config.outputClock = 33.26f; 00168 lcd_config.lcd_outformat = DisplayBase::LCD_OUTFORMAT_RGB888; 00169 lcd_config.lcd_edge = DisplayBase::EDGE_RISING; 00170 lcd_config.h_toatal_period = (800 + 92 + 128 + 36); 00171 lcd_config.v_toatal_period = (480 + 5 + 35 + 5); 00172 00173 lcd_config.h_disp_widht = 800; 00174 lcd_config.v_disp_widht = 480; 00175 lcd_config.h_back_porch = (128 + 36); 00176 lcd_config.v_back_porch = (35 + 5); 00177 00178 lcd_config.h_sync_port = DisplayBase::LCD_TCON_PIN_NON; 00179 lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; 00180 lcd_config.h_sync_width = 0; 00181 00182 lcd_config.v_sync_port = DisplayBase::LCD_TCON_PIN_NON; 00183 lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; 00184 lcd_config.v_sync_width = 0; 00185 00186 lcd_config.de_port = DisplayBase::LCD_TCON_PIN_3; 00187 lcd_config.de_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED; 00188 00189 /* Graphics initialization process */ 00190 error = Display.Graphics_init(&lcd_config); 00191 #else 00192 /* Graphics initialization process */ 00193 error = Display.Graphics_init(NULL); 00194 #endif 00195 00196 if (error != DisplayBase::GRAPHICS_OK) { 00197 printf("Line %d, error %d\n", __LINE__, error); 00198 while (1); 00199 } 00200 00201 #if VIDEO_INPUT_METHOD == VIDEO_CVBS 00202 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL); 00203 if( error != DisplayBase::GRAPHICS_OK ) { 00204 printf("Line %d, error %d\n", __LINE__, error); 00205 while(1); 00206 } 00207 00208 #elif VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA 00209 /* MT9V111 camera input config */ 00210 ext_in_config.inp_format = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */ 00211 ext_in_config.inp_pxd_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing data */ 00212 ext_in_config.inp_vs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Vsync signals */ 00213 ext_in_config.inp_hs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Hsync signals */ 00214 ext_in_config.inp_endian_on = DisplayBase::OFF; /* External input bit endian change on/off */ 00215 ext_in_config.inp_swap_on = DisplayBase::OFF; /* External input B/R signal swap on/off */ 00216 ext_in_config.inp_vs_inv = DisplayBase::SIG_POL_NOT_INVERTED; /* External input DV_VSYNC inversion control */ 00217 ext_in_config.inp_hs_inv = DisplayBase::SIG_POL_INVERTED; /* External input DV_HSYNC inversion control */ 00218 ext_in_config.inp_f525_625 = DisplayBase::EXTIN_LINE_525; /* Number of lines for BT.656 external input */ 00219 ext_in_config.inp_h_pos = DisplayBase::EXTIN_H_POS_CRYCBY; /* Y/Cb/Y/Cr data string start timing to Hsync reference */ 00220 ext_in_config.cap_vs_pos = 6; /* Capture start position from Vsync */ 00221 ext_in_config.cap_hs_pos = 150; /* Capture start position form Hsync */ 00222 ext_in_config.cap_width = 640; /* Capture width */ 00223 ext_in_config.cap_height = 468u; /* Capture height Max 468[line] 00224 Due to CMOS(MT9V111) output signal timing and VDC5 specification */ 00225 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_EXT, &ext_in_config); 00226 if( error != DisplayBase::GRAPHICS_OK ) { 00227 printf("Line %d, error %d\n", __LINE__, error); 00228 while(1); 00229 } 00230 00231 /* MT9V111 camera input port setting */ 00232 error = Display.Graphics_Dvinput_Port_Init(cmos_camera_pin, 11); 00233 if( error != DisplayBase::GRAPHICS_OK ) { 00234 printf("Line %d, error %d\n", __LINE__, error); 00235 while (1); 00236 } 00237 #endif 00238 00239 /* Interrupt callback function setting (Vsync signal input to scaler 0) */ 00240 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VI_VSYNC, 0, IntCallbackFunc_Vsync); 00241 if (error != DisplayBase::GRAPHICS_OK) { 00242 printf("Line %d, error %d\n", __LINE__, error); 00243 while (1); 00244 } 00245 /* Video capture setting (progressive form fixed) */ 00246 error = Display.Video_Write_Setting( 00247 VIDEO_INPUT_CH, 00248 #if VIDEO_PAL == 0 00249 DisplayBase::COL_SYS_NTSC_358, 00250 #else 00251 DisplayBase::COL_SYS_PAL_443, 00252 #endif 00253 FrameBuffer_Video, 00254 VIDEO_BUFFER_STRIDE, 00255 #if VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 00256 DisplayBase::VIDEO_FORMAT_YCBCR422, 00257 DisplayBase::WR_RD_WRSWA_NON, 00258 #elif VIDEO_INPUT_FORMAT == VIDEO_RGB565 00259 DisplayBase::VIDEO_FORMAT_RGB565, 00260 DisplayBase::WR_RD_WRSWA_32_16BIT, 00261 #else 00262 DisplayBase::VIDEO_FORMAT_RGB888, 00263 DisplayBase::WR_RD_WRSWA_32BIT, 00264 #endif 00265 PIXEL_VW, 00266 PIXEL_HW 00267 ); 00268 if (error != DisplayBase::GRAPHICS_OK) { 00269 printf("Line %d, error %d\n", __LINE__, error); 00270 while (1); 00271 } 00272 00273 /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */ 00274 error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield); 00275 if (error != DisplayBase::GRAPHICS_OK) { 00276 printf("Line %d, error %d\n", __LINE__, error); 00277 while (1); 00278 } 00279 00280 /* Video write process start */ 00281 error = Display.Video_Start (VIDEO_INPUT_CH); 00282 if (error != DisplayBase::GRAPHICS_OK) { 00283 printf("Line %d, error %d\n", __LINE__, error); 00284 while (1); 00285 } 00286 00287 /* Video write process stop */ 00288 error = Display.Video_Stop (VIDEO_INPUT_CH); 00289 if (error != DisplayBase::GRAPHICS_OK) { 00290 printf("Line %d, error %d\n", __LINE__, error); 00291 while (1); 00292 } 00293 00294 /* Video write process start */ 00295 error = Display.Video_Start (VIDEO_INPUT_CH); 00296 if (error != DisplayBase::GRAPHICS_OK) { 00297 printf("Line %d, error %d\n", __LINE__, error); 00298 while (1); 00299 } 00300 00301 /* Wait vsync to update resister */ 00302 WaitVsync(1); 00303 00304 #if(1) //lcd 00305 Display.Graphics_Lvds_Port_Init(lvds_pin, 8); 00306 rect.vs = 0; 00307 rect.vw = PIXEL_VW; 00308 rect.hs = 0; 00309 rect.hw = PIXEL_HW; 00310 00311 Display.Graphics_Read_Setting( 00312 DisplayBase::GRAPHICS_LAYER_0, 00313 (void *)FrameBuffer_Video, 00314 VIDEO_BUFFER_STRIDE, 00315 DisplayBase::GRAPHICS_FORMAT_YCBCR422, 00316 DisplayBase::WR_RD_WRSWA_NON, 00317 &rect 00318 ); 00319 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0); 00320 00321 lcd_cntrst.write(1.0); 00322 00323 while (1) { 00324 uint8_t count; 00325 uint32_t x0; 00326 uint32_t y0; 00327 uint32_t x1; 00328 uint32_t y1; 00329 00330 count = 0; 00331 x0 = 0; 00332 y0 = 0; 00333 x1 = 0; 00334 y1 = 0; 00335 get_coordinates(&count, &x0, &y0, &x1, &y1); 00336 if (count != 0) { 00337 printf("count=%d, {X=%d,Y=%d}, {X=%d,Y=%d} \n", count, x0, y0, x1, y1); 00338 } 00339 Thread::wait(100); 00340 } 00341 #endif 00342 }
Generated on Tue Jul 12 2022 17:04:30 by
1.7.2