LCD Shield sample. 4.3inch.

Dependencies:   GR-PEACH_video mbed-rtos mbed

Fork of GR-PEACH_LCD_sample by Daiki Kato

Information

Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.

This program displays the NTSC input from NTSC1A of LCD Shield on the screen. Touch coordinates are displayed on the terminal when you touch the screen. You can touch at the same time up to 2 points.

When you connect the "GR-PEACH AUDIO CAMERA Shield", you can display an image of the CMOS Camera(MT9V111).
If you use CMOS Camera, Please change the below in the “main.cpp”.

main.cpp

#define VIDEO_INPUT_METHOD     (VIDEO_CVBS)
->
#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA)


Please refer to following link about "GR-PEACH AUDIO CAMERA Shield".
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield


このプログラムは、NTSC1AからのNTSC入力をLCDシールドの画面上に表示します。画面をタッチすると、タッチ座標がprintf表示されます。2点まで同時にタッチできます。
GR-PEACH AUDIO CAMERA Shieldを接続すると、CMOSカメラ(MT9V111)の画像を表示することができます。CMOSカメラを使用する場合は、「main.cpp」の以下を変更してください。

main.cpp

#define VIDEO_INPUT_METHOD     (VIDEO_CVBS)
->
#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA)


GR-PEACH AUDIO CAMERA Shieldについては下記を参照ください。
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

Committer:
dkato
Date:
Tue Apr 19 02:42:13 2016 +0000
Revision:
4:c1e61a1d75df
Parent:
3:b5aaf7215800
Supports IAR.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:47ea8de0be6c 1 #include "mbed.h"
dkato 0:47ea8de0be6c 2 #include "DisplayBace.h"
dkato 0:47ea8de0be6c 3 #include "rtos.h"
dkato 0:47ea8de0be6c 4
dkato 0:47ea8de0be6c 5 #define VIDEO_CVBS (0) /* Analog Video Signal */
dkato 0:47ea8de0be6c 6 #define VIDEO_CMOS_CAMERA (1) /* Digital Video Signal */
dkato 0:47ea8de0be6c 7 #define VIDEO_YCBCR422 (0)
dkato 0:47ea8de0be6c 8 #define VIDEO_RGB888 (1)
dkato 0:47ea8de0be6c 9 #define VIDEO_RGB565 (2)
dkato 0:47ea8de0be6c 10
dkato 0:47ea8de0be6c 11 /**** User Selection *********/
dkato 0:47ea8de0be6c 12 #define VIDEO_INPUT_METHOD (VIDEO_CVBS) /* Select VIDEO_CVBS or VIDEO_CMOS_CAMERA */
dkato 0:47ea8de0be6c 13 #define VIDEO_INPUT_FORMAT (VIDEO_YCBCR422) /* Select VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565 */
dkato 0:47ea8de0be6c 14 #define USE_VIDEO_CH (0) /* Select 0 or 1 If selecting VIDEO_CMOS_CAMERA, should be 0.) */
dkato 0:47ea8de0be6c 15 #define VIDEO_PAL (0) /* Select 0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */
dkato 0:47ea8de0be6c 16 /*****************************/
dkato 1:f0d5f9c28404 17
dkato 1:f0d5f9c28404 18 /**** LCD Parameter **********/
dkato 1:f0d5f9c28404 19 #define LCD_DE_MODE (0)
dkato 1:f0d5f9c28404 20 #define LCD_SYNC_MODE (1)
dkato 1:f0d5f9c28404 21
dkato 1:f0d5f9c28404 22 #define LCD_DOT_CLOCK (13.40f) // 13.4MHz
dkato 1:f0d5f9c28404 23
dkato 1:f0d5f9c28404 24 #define LCD_H_WIDTH (480u)
dkato 1:f0d5f9c28404 25 #define LCD_H_BACK_PORCH (43u)
dkato 1:f0d5f9c28404 26 #define LCD_H_FRONT_PORCH (52u)
dkato 1:f0d5f9c28404 27 #define LCD_H_SYNC_WIDTH (41u)
dkato 1:f0d5f9c28404 28
dkato 1:f0d5f9c28404 29 #define LCD_V_WIDTH (272u)
dkato 1:f0d5f9c28404 30 #define LCD_V_BACK_PORCH (12u)
dkato 1:f0d5f9c28404 31 #define LCD_V_FRONT_PORCH (2u)
dkato 1:f0d5f9c28404 32 #define LCD_V_SYNC_WIDTH (10u)
dkato 1:f0d5f9c28404 33
dkato 1:f0d5f9c28404 34 #define LCD_MODE (LCD_SYNC_MODE)
dkato 1:f0d5f9c28404 35
dkato 1:f0d5f9c28404 36 /*****************************/
dkato 1:f0d5f9c28404 37
dkato 0:47ea8de0be6c 38
dkato 0:47ea8de0be6c 39 #if USE_VIDEO_CH == (0)
dkato 0:47ea8de0be6c 40 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_0)
dkato 0:47ea8de0be6c 41 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S0_VFIELD)
dkato 0:47ea8de0be6c 42 #else
dkato 0:47ea8de0be6c 43 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_1)
dkato 0:47ea8de0be6c 44 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S1_VFIELD)
dkato 0:47ea8de0be6c 45 #endif
dkato 0:47ea8de0be6c 46
dkato 0:47ea8de0be6c 47 #if ( VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 || VIDEO_INPUT_FORMAT == VIDEO_RGB565 )
dkato 0:47ea8de0be6c 48 #define DATA_SIZE_PER_PIC (2u)
dkato 0:47ea8de0be6c 49 #else
dkato 0:47ea8de0be6c 50 #define DATA_SIZE_PER_PIC (4u)
dkato 0:47ea8de0be6c 51 #endif
dkato 0:47ea8de0be6c 52
dkato 0:47ea8de0be6c 53 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
dkato 0:47ea8de0be6c 54 in accordance with the frame buffer burst transfer mode. */
dkato 1:f0d5f9c28404 55 #define PIXEL_HW (480u) /* WQVGA */
dkato 1:f0d5f9c28404 56 #define PIXEL_VW (272u) /* WQVGA */
dkato 0:47ea8de0be6c 57
dkato 0:47ea8de0be6c 58 #define VIDEO_BUFFER_STRIDE (((PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u)
dkato 0:47ea8de0be6c 59 #define VIDEO_BUFFER_HEIGHT (PIXEL_VW)
dkato 0:47ea8de0be6c 60
dkato 0:47ea8de0be6c 61 DigitalIn button(USER_BUTTON0);
dkato 0:47ea8de0be6c 62 #if(1) //lcd
dkato 0:47ea8de0be6c 63 DigitalOut lcd_pwon(P7_15);
dkato 0:47ea8de0be6c 64 DigitalOut lcd_blon(P8_1);
dkato 3:b5aaf7215800 65 DigitalOut touch_reset(P4_0);
dkato 0:47ea8de0be6c 66 PwmOut lcd_cntrst(P8_15);
dkato 0:47ea8de0be6c 67 I2C mI2c(I2C_SDA, I2C_SCL);
dkato 0:47ea8de0be6c 68
dkato 0:47ea8de0be6c 69 typedef struct {
dkato 0:47ea8de0be6c 70 uint8_t y_h: 3,
dkato 0:47ea8de0be6c 71 reserved: 1,
dkato 0:47ea8de0be6c 72 x_h: 3,
dkato 0:47ea8de0be6c 73 valid: 1;
dkato 0:47ea8de0be6c 74 uint8_t x_l;
dkato 0:47ea8de0be6c 75 uint8_t y_l;
dkato 0:47ea8de0be6c 76 } xyz_data_t;
dkato 0:47ea8de0be6c 77
dkato 0:47ea8de0be6c 78 typedef struct {
dkato 3:b5aaf7215800 79 uint8_t fingers: 3,
dkato 3:b5aaf7215800 80 reserved: 5;
dkato 0:47ea8de0be6c 81 uint8_t keys;
dkato 0:47ea8de0be6c 82 xyz_data_t xyz_data[2];
dkato 0:47ea8de0be6c 83 } stx_report_data_t;
dkato 0:47ea8de0be6c 84
dkato 0:47ea8de0be6c 85 static int get_coordinates(uint8_t *count, uint32_t *x0, uint32_t *y0, uint32_t *x1, uint32_t *y1) {
dkato 3:b5aaf7215800 86 char buf[8];
dkato 0:47ea8de0be6c 87 stx_report_data_t *pdata;
dkato 0:47ea8de0be6c 88 int ret = -1;
dkato 0:47ea8de0be6c 89 *count = 0; // Set point detected count to 0.
dkato 0:47ea8de0be6c 90
dkato 0:47ea8de0be6c 91 if (mI2c.read((0x55 << 1), buf, sizeof(buf)) == 0) {
dkato 0:47ea8de0be6c 92 pdata = (stx_report_data_t *)buf;
dkato 0:47ea8de0be6c 93 if (pdata->fingers) {
dkato 0:47ea8de0be6c 94 if (pdata->xyz_data[0].valid) {
dkato 0:47ea8de0be6c 95 *x0 = (pdata->xyz_data[0].x_h << 8) | pdata->xyz_data[0].x_l;
dkato 0:47ea8de0be6c 96 *y0 = (pdata->xyz_data[0].y_h << 8) | pdata->xyz_data[0].y_l;
dkato 0:47ea8de0be6c 97 (*count)++;
dkato 0:47ea8de0be6c 98 }
dkato 0:47ea8de0be6c 99 }
dkato 0:47ea8de0be6c 100 if (pdata->xyz_data[1].valid) {
dkato 0:47ea8de0be6c 101 *x1 = (pdata->xyz_data[1].x_h << 8) | pdata->xyz_data[1].x_l;
dkato 0:47ea8de0be6c 102 *y1 = (pdata->xyz_data[1].y_h << 8) | pdata->xyz_data[1].y_l;
dkato 0:47ea8de0be6c 103 (*count)++;
dkato 0:47ea8de0be6c 104 }
dkato 0:47ea8de0be6c 105 ret = 0;
dkato 0:47ea8de0be6c 106 }
dkato 0:47ea8de0be6c 107
dkato 0:47ea8de0be6c 108 return ret;
dkato 0:47ea8de0be6c 109 }
dkato 0:47ea8de0be6c 110 #endif
dkato 0:47ea8de0be6c 111
dkato 4:c1e61a1d75df 112 #if defined(__ICCARM__)
dkato 4:c1e61a1d75df 113 #pragma data_alignment=16
dkato 4:c1e61a1d75df 114 static uint8_t FrameBuffer_Video[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]@ ".mirrorram"; //16 bytes aligned!;
dkato 4:c1e61a1d75df 115 #pragma data_alignment=4
dkato 4:c1e61a1d75df 116 #else
dkato 0:47ea8de0be6c 117 static uint8_t FrameBuffer_Video[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16))); //16 bytes aligned!;
dkato 4:c1e61a1d75df 118 #endif
dkato 0:47ea8de0be6c 119 static volatile int32_t vsync_count = 0;
dkato 0:47ea8de0be6c 120 static volatile int32_t vfield_count = 1;
dkato 0:47ea8de0be6c 121 static int image_change = 0;
dkato 0:47ea8de0be6c 122
dkato 0:47ea8de0be6c 123 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type)
dkato 0:47ea8de0be6c 124 {
dkato 0:47ea8de0be6c 125 //Interrupt callback function
dkato 0:47ea8de0be6c 126 if (vfield_count != 0) {
dkato 0:47ea8de0be6c 127 vfield_count = 0;
dkato 0:47ea8de0be6c 128 } else {
dkato 0:47ea8de0be6c 129 vfield_count = 1;
dkato 0:47ea8de0be6c 130 image_change = 1;
dkato 0:47ea8de0be6c 131 }
dkato 0:47ea8de0be6c 132 }
dkato 0:47ea8de0be6c 133
dkato 0:47ea8de0be6c 134 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type)
dkato 0:47ea8de0be6c 135 {
dkato 0:47ea8de0be6c 136 //Interrupt callback function for Vsync interruption
dkato 0:47ea8de0be6c 137 if (vsync_count > 0) {
dkato 0:47ea8de0be6c 138 vsync_count--;
dkato 0:47ea8de0be6c 139 }
dkato 0:47ea8de0be6c 140 }
dkato 0:47ea8de0be6c 141
dkato 0:47ea8de0be6c 142 static void WaitVsync(const int32_t wait_count)
dkato 0:47ea8de0be6c 143 {
dkato 0:47ea8de0be6c 144 //Wait for the specified number of times Vsync occurs
dkato 0:47ea8de0be6c 145 vsync_count = wait_count;
dkato 0:47ea8de0be6c 146 while (vsync_count > 0) {
dkato 0:47ea8de0be6c 147 /* Do nothing */
dkato 0:47ea8de0be6c 148 }
dkato 0:47ea8de0be6c 149 }
dkato 0:47ea8de0be6c 150
dkato 0:47ea8de0be6c 151 int main(void)
dkato 0:47ea8de0be6c 152 {
dkato 0:47ea8de0be6c 153 /* Create DisplayBase object */
dkato 0:47ea8de0be6c 154 DisplayBase Display;
dkato 0:47ea8de0be6c 155 DisplayBase::graphics_error_t error;
dkato 0:47ea8de0be6c 156
dkato 0:47ea8de0be6c 157 #if VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA
dkato 0:47ea8de0be6c 158 DisplayBase::video_ext_in_config_t ext_in_config;
dkato 0:47ea8de0be6c 159 PinName cmos_camera_pin[11] = {
dkato 0:47ea8de0be6c 160 /* data pin */
dkato 0:47ea8de0be6c 161 P2_7, P2_6, P2_5, P2_4, P2_3, P2_2, P2_1, P2_0,
dkato 0:47ea8de0be6c 162 /* control pin */
dkato 0:47ea8de0be6c 163 P10_0, /* DV0_CLK */
dkato 0:47ea8de0be6c 164 P1_0, /* DV0_Vsync */
dkato 0:47ea8de0be6c 165 P1_1 /* DV0_Hsync */
dkato 0:47ea8de0be6c 166 };
dkato 0:47ea8de0be6c 167 #endif
dkato 0:47ea8de0be6c 168 #if(1) //lcd
dkato 1:f0d5f9c28404 169 lcd_pwon = 0;
dkato 1:f0d5f9c28404 170 lcd_blon = 0;
dkato 3:b5aaf7215800 171 touch_reset = 0;
dkato 1:f0d5f9c28404 172 Thread::wait(100);
dkato 1:f0d5f9c28404 173
dkato 0:47ea8de0be6c 174 lcd_pwon = 1;
dkato 0:47ea8de0be6c 175 lcd_blon = 1;
dkato 3:b5aaf7215800 176 touch_reset = 1;
dkato 1:f0d5f9c28404 177 Thread::wait(100);
dkato 0:47ea8de0be6c 178
dkato 0:47ea8de0be6c 179 DisplayBase::lcd_config_t lcd_config;
dkato 0:47ea8de0be6c 180 PinName lvds_pin[8] = {
dkato 0:47ea8de0be6c 181 /* data pin */
dkato 0:47ea8de0be6c 182 P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0
dkato 0:47ea8de0be6c 183 };
dkato 0:47ea8de0be6c 184 DisplayBase::rect_t rect;
dkato 0:47ea8de0be6c 185
dkato 0:47ea8de0be6c 186 lcd_config.lcd_type = DisplayBase::LCD_TYPE_LVDS;
dkato 0:47ea8de0be6c 187 lcd_config.intputClock = 66.67f;
dkato 1:f0d5f9c28404 188 lcd_config.outputClock = LCD_DOT_CLOCK;
dkato 0:47ea8de0be6c 189 lcd_config.lcd_outformat = DisplayBase::LCD_OUTFORMAT_RGB888;
dkato 0:47ea8de0be6c 190 lcd_config.lcd_edge = DisplayBase::EDGE_RISING;
dkato 1:f0d5f9c28404 191 #if(LCD_MODE) //SYNC Mode
dkato 1:f0d5f9c28404 192 lcd_config.h_toatal_period = (LCD_H_BACK_PORCH + LCD_H_WIDTH + LCD_H_FRONT_PORCH);
dkato 1:f0d5f9c28404 193 lcd_config.v_toatal_period = (LCD_V_BACK_PORCH + LCD_V_WIDTH + LCD_V_FRONT_PORCH);
dkato 1:f0d5f9c28404 194
dkato 1:f0d5f9c28404 195 lcd_config.h_disp_widht = (LCD_H_WIDTH);
dkato 1:f0d5f9c28404 196 lcd_config.v_disp_widht = (LCD_V_WIDTH);
dkato 1:f0d5f9c28404 197 lcd_config.h_back_porch = (LCD_H_BACK_PORCH);
dkato 1:f0d5f9c28404 198 lcd_config.v_back_porch = (LCD_V_BACK_PORCH);
dkato 1:f0d5f9c28404 199
dkato 1:f0d5f9c28404 200 lcd_config.h_sync_port = DisplayBase::LCD_TCON_PIN_2;
dkato 1:f0d5f9c28404 201 lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_INVERTED;
dkato 1:f0d5f9c28404 202 lcd_config.h_sync_width = LCD_H_SYNC_WIDTH;
dkato 1:f0d5f9c28404 203
dkato 1:f0d5f9c28404 204 lcd_config.v_sync_port = DisplayBase::LCD_TCON_PIN_0;
dkato 1:f0d5f9c28404 205 lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_INVERTED;
dkato 1:f0d5f9c28404 206 lcd_config.v_sync_width = LCD_V_SYNC_WIDTH;
dkato 1:f0d5f9c28404 207
dkato 2:8e78c957adb5 208 lcd_config.de_port = DisplayBase::LCD_TCON_PIN_3;
dkato 1:f0d5f9c28404 209 lcd_config.de_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED;
dkato 1:f0d5f9c28404 210 #else //DE Mode
dkato 1:f0d5f9c28404 211 lcd_config.h_toatal_period = (LCD_H_WIDTH + 80u);
dkato 1:f0d5f9c28404 212 lcd_config.v_toatal_period = (LCD_V_WIDTH);
dkato 0:47ea8de0be6c 213
dkato 1:f0d5f9c28404 214 lcd_config.h_disp_widht = (LCD_H_WIDTH);
dkato 1:f0d5f9c28404 215 lcd_config.v_disp_widht = (LCD_V_WIDTH);
dkato 1:f0d5f9c28404 216 lcd_config.h_back_porch = (68u);
dkato 1:f0d5f9c28404 217 lcd_config.v_back_porch = (18u);
dkato 0:47ea8de0be6c 218
dkato 0:47ea8de0be6c 219 lcd_config.h_sync_port = DisplayBase::LCD_TCON_PIN_NON;
dkato 0:47ea8de0be6c 220 lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED;
dkato 0:47ea8de0be6c 221 lcd_config.h_sync_width = 0;
dkato 0:47ea8de0be6c 222
dkato 0:47ea8de0be6c 223 lcd_config.v_sync_port = DisplayBase::LCD_TCON_PIN_NON;
dkato 0:47ea8de0be6c 224 lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED;
dkato 0:47ea8de0be6c 225 lcd_config.v_sync_width = 0;
dkato 0:47ea8de0be6c 226
dkato 0:47ea8de0be6c 227 lcd_config.de_port = DisplayBase::LCD_TCON_PIN_3;
dkato 1:f0d5f9c28404 228 lcd_config.de_port_polarity = DisplayBase::SIG_POL_INVERTED;
dkato 1:f0d5f9c28404 229 #endif
dkato 0:47ea8de0be6c 230
dkato 0:47ea8de0be6c 231 /* Graphics initialization process */
dkato 0:47ea8de0be6c 232 error = Display.Graphics_init(&lcd_config);
dkato 0:47ea8de0be6c 233 #else
dkato 0:47ea8de0be6c 234 /* Graphics initialization process */
dkato 0:47ea8de0be6c 235 error = Display.Graphics_init(NULL);
dkato 0:47ea8de0be6c 236 #endif
dkato 0:47ea8de0be6c 237
dkato 0:47ea8de0be6c 238 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:47ea8de0be6c 239 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:47ea8de0be6c 240 while (1);
dkato 0:47ea8de0be6c 241 }
dkato 0:47ea8de0be6c 242
dkato 0:47ea8de0be6c 243 #if VIDEO_INPUT_METHOD == VIDEO_CVBS
dkato 0:47ea8de0be6c 244 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL);
dkato 0:47ea8de0be6c 245 if( error != DisplayBase::GRAPHICS_OK ) {
dkato 0:47ea8de0be6c 246 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:47ea8de0be6c 247 while(1);
dkato 0:47ea8de0be6c 248 }
dkato 0:47ea8de0be6c 249
dkato 0:47ea8de0be6c 250 #elif VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA
dkato 0:47ea8de0be6c 251 /* MT9V111 camera input config */
dkato 0:47ea8de0be6c 252 ext_in_config.inp_format = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
dkato 0:47ea8de0be6c 253 ext_in_config.inp_pxd_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing data */
dkato 0:47ea8de0be6c 254 ext_in_config.inp_vs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Vsync signals */
dkato 0:47ea8de0be6c 255 ext_in_config.inp_hs_edge = DisplayBase::EDGE_RISING; /* Clock edge select for capturing Hsync signals */
dkato 0:47ea8de0be6c 256 ext_in_config.inp_endian_on = DisplayBase::OFF; /* External input bit endian change on/off */
dkato 0:47ea8de0be6c 257 ext_in_config.inp_swap_on = DisplayBase::OFF; /* External input B/R signal swap on/off */
dkato 0:47ea8de0be6c 258 ext_in_config.inp_vs_inv = DisplayBase::SIG_POL_NOT_INVERTED; /* External input DV_VSYNC inversion control */
dkato 0:47ea8de0be6c 259 ext_in_config.inp_hs_inv = DisplayBase::SIG_POL_INVERTED; /* External input DV_HSYNC inversion control */
dkato 0:47ea8de0be6c 260 ext_in_config.inp_f525_625 = DisplayBase::EXTIN_LINE_525; /* Number of lines for BT.656 external input */
dkato 0:47ea8de0be6c 261 ext_in_config.inp_h_pos = DisplayBase::EXTIN_H_POS_CRYCBY; /* Y/Cb/Y/Cr data string start timing to Hsync reference */
dkato 0:47ea8de0be6c 262 ext_in_config.cap_vs_pos = 6; /* Capture start position from Vsync */
dkato 0:47ea8de0be6c 263 ext_in_config.cap_hs_pos = 150; /* Capture start position form Hsync */
dkato 0:47ea8de0be6c 264 ext_in_config.cap_width = 640; /* Capture width */
dkato 0:47ea8de0be6c 265 ext_in_config.cap_height = 468u; /* Capture height Max 468[line]
dkato 0:47ea8de0be6c 266 Due to CMOS(MT9V111) output signal timing and VDC5 specification */
dkato 0:47ea8de0be6c 267 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_EXT, &ext_in_config);
dkato 0:47ea8de0be6c 268 if( error != DisplayBase::GRAPHICS_OK ) {
dkato 0:47ea8de0be6c 269 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:47ea8de0be6c 270 while(1);
dkato 0:47ea8de0be6c 271 }
dkato 0:47ea8de0be6c 272
dkato 0:47ea8de0be6c 273 /* MT9V111 camera input port setting */
dkato 0:47ea8de0be6c 274 error = Display.Graphics_Dvinput_Port_Init(cmos_camera_pin, 11);
dkato 0:47ea8de0be6c 275 if( error != DisplayBase::GRAPHICS_OK ) {
dkato 0:47ea8de0be6c 276 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:47ea8de0be6c 277 while (1);
dkato 0:47ea8de0be6c 278 }
dkato 0:47ea8de0be6c 279 #endif
dkato 0:47ea8de0be6c 280
dkato 0:47ea8de0be6c 281 /* Interrupt callback function setting (Vsync signal input to scaler 0) */
dkato 0:47ea8de0be6c 282 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VI_VSYNC, 0, IntCallbackFunc_Vsync);
dkato 0:47ea8de0be6c 283 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:47ea8de0be6c 284 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:47ea8de0be6c 285 while (1);
dkato 0:47ea8de0be6c 286 }
dkato 0:47ea8de0be6c 287 /* Video capture setting (progressive form fixed) */
dkato 0:47ea8de0be6c 288 error = Display.Video_Write_Setting(
dkato 0:47ea8de0be6c 289 VIDEO_INPUT_CH,
dkato 0:47ea8de0be6c 290 #if VIDEO_PAL == 0
dkato 0:47ea8de0be6c 291 DisplayBase::COL_SYS_NTSC_358,
dkato 0:47ea8de0be6c 292 #else
dkato 0:47ea8de0be6c 293 DisplayBase::COL_SYS_PAL_443,
dkato 0:47ea8de0be6c 294 #endif
dkato 0:47ea8de0be6c 295 FrameBuffer_Video,
dkato 0:47ea8de0be6c 296 VIDEO_BUFFER_STRIDE,
dkato 0:47ea8de0be6c 297 #if VIDEO_INPUT_FORMAT == VIDEO_YCBCR422
dkato 0:47ea8de0be6c 298 DisplayBase::VIDEO_FORMAT_YCBCR422,
dkato 0:47ea8de0be6c 299 DisplayBase::WR_RD_WRSWA_NON,
dkato 0:47ea8de0be6c 300 #elif VIDEO_INPUT_FORMAT == VIDEO_RGB565
dkato 0:47ea8de0be6c 301 DisplayBase::VIDEO_FORMAT_RGB565,
dkato 0:47ea8de0be6c 302 DisplayBase::WR_RD_WRSWA_32_16BIT,
dkato 0:47ea8de0be6c 303 #else
dkato 0:47ea8de0be6c 304 DisplayBase::VIDEO_FORMAT_RGB888,
dkato 0:47ea8de0be6c 305 DisplayBase::WR_RD_WRSWA_32BIT,
dkato 0:47ea8de0be6c 306 #endif
dkato 0:47ea8de0be6c 307 PIXEL_VW,
dkato 0:47ea8de0be6c 308 PIXEL_HW
dkato 0:47ea8de0be6c 309 );
dkato 0:47ea8de0be6c 310 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:47ea8de0be6c 311 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:47ea8de0be6c 312 while (1);
dkato 0:47ea8de0be6c 313 }
dkato 0:47ea8de0be6c 314
dkato 0:47ea8de0be6c 315 /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */
dkato 0:47ea8de0be6c 316 error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield);
dkato 0:47ea8de0be6c 317 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:47ea8de0be6c 318 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:47ea8de0be6c 319 while (1);
dkato 0:47ea8de0be6c 320 }
dkato 0:47ea8de0be6c 321
dkato 0:47ea8de0be6c 322 /* Video write process start */
dkato 0:47ea8de0be6c 323 error = Display.Video_Start (VIDEO_INPUT_CH);
dkato 0:47ea8de0be6c 324 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:47ea8de0be6c 325 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:47ea8de0be6c 326 while (1);
dkato 0:47ea8de0be6c 327 }
dkato 0:47ea8de0be6c 328
dkato 0:47ea8de0be6c 329 /* Video write process stop */
dkato 0:47ea8de0be6c 330 error = Display.Video_Stop (VIDEO_INPUT_CH);
dkato 0:47ea8de0be6c 331 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:47ea8de0be6c 332 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:47ea8de0be6c 333 while (1);
dkato 0:47ea8de0be6c 334 }
dkato 0:47ea8de0be6c 335
dkato 0:47ea8de0be6c 336 /* Video write process start */
dkato 0:47ea8de0be6c 337 error = Display.Video_Start (VIDEO_INPUT_CH);
dkato 0:47ea8de0be6c 338 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:47ea8de0be6c 339 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:47ea8de0be6c 340 while (1);
dkato 0:47ea8de0be6c 341 }
dkato 0:47ea8de0be6c 342
dkato 0:47ea8de0be6c 343 /* Wait vsync to update resister */
dkato 0:47ea8de0be6c 344 WaitVsync(1);
dkato 0:47ea8de0be6c 345
dkato 0:47ea8de0be6c 346 #if(1) //lcd
dkato 0:47ea8de0be6c 347 Display.Graphics_Lvds_Port_Init(lvds_pin, 8);
dkato 0:47ea8de0be6c 348 rect.vs = 0;
dkato 0:47ea8de0be6c 349 rect.vw = PIXEL_VW;
dkato 0:47ea8de0be6c 350 rect.hs = 0;
dkato 0:47ea8de0be6c 351 rect.hw = PIXEL_HW;
dkato 0:47ea8de0be6c 352
dkato 0:47ea8de0be6c 353 Display.Graphics_Read_Setting(
dkato 0:47ea8de0be6c 354 DisplayBase::GRAPHICS_LAYER_0,
dkato 0:47ea8de0be6c 355 (void *)FrameBuffer_Video,
dkato 0:47ea8de0be6c 356 VIDEO_BUFFER_STRIDE,
dkato 0:47ea8de0be6c 357 DisplayBase::GRAPHICS_FORMAT_YCBCR422,
dkato 0:47ea8de0be6c 358 DisplayBase::WR_RD_WRSWA_NON,
dkato 0:47ea8de0be6c 359 &rect
dkato 0:47ea8de0be6c 360 );
dkato 0:47ea8de0be6c 361 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
dkato 0:47ea8de0be6c 362
dkato 0:47ea8de0be6c 363 lcd_cntrst.write(1.0);
dkato 0:47ea8de0be6c 364
dkato 0:47ea8de0be6c 365 while (1) {
dkato 0:47ea8de0be6c 366 uint8_t count;
dkato 0:47ea8de0be6c 367 uint32_t x0;
dkato 0:47ea8de0be6c 368 uint32_t y0;
dkato 0:47ea8de0be6c 369 uint32_t x1;
dkato 0:47ea8de0be6c 370 uint32_t y1;
dkato 0:47ea8de0be6c 371
dkato 0:47ea8de0be6c 372 count = 0;
dkato 0:47ea8de0be6c 373 x0 = 0;
dkato 0:47ea8de0be6c 374 y0 = 0;
dkato 0:47ea8de0be6c 375 x1 = 0;
dkato 0:47ea8de0be6c 376 y1 = 0;
dkato 0:47ea8de0be6c 377 get_coordinates(&count, &x0, &y0, &x1, &y1);
dkato 0:47ea8de0be6c 378 if (count != 0) {
dkato 0:47ea8de0be6c 379 printf("count=%d, {X=%d,Y=%d}, {X=%d,Y=%d} \n", count, x0, y0, x1, y1);
dkato 0:47ea8de0be6c 380 }
dkato 0:47ea8de0be6c 381 Thread::wait(100);
dkato 0:47ea8de0be6c 382 }
dkato 0:47ea8de0be6c 383 #endif
dkato 0:47ea8de0be6c 384 }