LCD (4.3inch) Shield sample. While USER_BUTTON0 is pressed, it will save the image to the USB memory.When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Dependencies:   GR-PEACH_video GraphicsFramework R_BSP USBHost mbed

License

When you use this program, we judge you have agreed to the following contents.

本プログラムを使用する際は、以下の内容に合意した事になります。

https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Information

Japanese version is available in lower part of this page.

このページの後半に日本語版が用意されています.

What is this ?

This is a sample program that displays the image captured by the camera to the LCD by using the GR-PEACH AUDIO CAMERA Shield and GR-PEACH LCD Shield.
This program displays the NTSC input from NTSC1A on the screen of LCD shield.
When you touch on the screen of LCD Shield, the touch coordinates are displayed on the PC terminal software. You can touch the two points at the same time.
Inaddition, while you press USER_BUTTON0, th image is saved to the USB memory.

Composition

GR-PEACH, AUDIO CAMERA Shield, LCD Shield, Camera and USB memory.

Please refer to following link about Audio/Camera Shield.
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

MT9V111 is being used for a camera by this sample program. When using a camera besides MT9V111, please change the setting according to the used camera.

main.cpp (camera input config 1)

/**** User Selection *********/
#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA) /* Select  VIDEO_CVBS or VIDEO_CMOS_CAMERA                       */
#define VIDEO_INPUT_FORMAT     (VIDEO_YCBCR422)    /* Select  VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565        */
#define USE_VIDEO_CH           (0)                 /* Select  0 or 1            If selecting VIDEO_CMOS_CAMERA, should be 0.)               */
#define VIDEO_PAL              (0)                 /* Select  0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */

main.cpp (camera input config 2)

    /* MT9V111 camera input config */
    ext_in_config.inp_format     = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
    ext_in_config.inp_pxd_edge   = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing data          */
    ext_in_config.inp_vs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Vsync signals */
    ext_in_config.inp_hs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Hsync signals */
    ext_in_config.inp_endian_on  = DisplayBase::OFF;                      /* External input bit endian change on/off       */
    ext_in_config.inp_swap_on    = DisplayBase::OFF;                      /* External input B/R signal swap on/off         */
    ext_in_config.inp_vs_inv     = DisplayBase::SIG_POL_NOT_INVERTED;     /* External input DV_VSYNC inversion control     */
    ext_in_config.inp_hs_inv     = DisplayBase::SIG_POL_INVERTED;         /* External input DV_HSYNC inversion control     */
    ext_in_config.inp_f525_625   = DisplayBase::EXTIN_LINE_525;           /* Number of lines for BT.656 external input */
    ext_in_config.inp_h_pos      = DisplayBase::EXTIN_H_POS_CRYCBY;       /* Y/Cb/Y/Cr data string start timing to Hsync reference */
    ext_in_config.cap_vs_pos     = 6;                                     /* Capture start position from Vsync */
    ext_in_config.cap_hs_pos     = 150;                                   /* Capture start position form Hsync */
    ext_in_config.cap_width      = 640;                                   /* Capture width  */
    ext_in_config.cap_height     = 468u;                                  /* Capture height Max 468[line]
                                                                             Due to CMOS(MT9V111) output signal timing and VDC5 specification */


When you save a camera image to a USB memory, the image is converted along the following conversion method.

Value of "VIDEO_INPUT_FORMAT" in main.cppConversion method
VIDEO_YCBCR422JPEG
VIDEO_RGB888bitmap
VIDEO_RGB565binary (RAW data)


If you use a USB, according to the USB port to use, make the following changes and the jumper short. (define 0:USB0、define 1:USB1)

USBHost\USBHost\TARGET_RENESAS\TARGET_RZ_A1H\usb_host_setting.h

#define USB_HOST_CH                           0
↓
#define USB_HOST_CH                           1


If you use the GR-PEACH's USB connector (USB0), please close GR-PEACH's JP3.
/media/uploads/RyoheiHagimoto/usb.jpg

If you use the GR-PEACH AUDIO CAMERA Shield's USB connector (USB1), please close Audio/Camera Shield's JP1.
/media/uploads/dkato/audiocamerashield_jp1.jpg


概要

GR-PEACH AUDIO CAMERA ShieldとGR-PEACH LCD Shieldを使って、カメラで取り込んだ画像をLCDへ表示するサンプルプログラムです。
このプログラムは、NTSC1AからのNTSC入力をLCDシールドの画面上に表示します。
画面をタッチすると、タッチ座標がPCターミナルソフト上に表示されます。2点まで同時にタッチできます。
また、GR-PEACHのUSER_BOTTON0を押している間、カメラで取り込んだ画像をUSBメモリへ保存することができます。

構成

GR-PEACH、AUDIO CAMERA Shield、LCD Shield、 カメラ、USBメモリ

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

サンプルプログラムではCameraにMT9V111を使用しています。MT9V111以外のCameraを使用する際は使用するCameraにあわせて設定を変更して下さい。

main.cpp (camera input config 1)

/**** User Selection *********/
#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA) /* Select  VIDEO_CVBS or VIDEO_CMOS_CAMERA                       */
#define VIDEO_INPUT_FORMAT     (VIDEO_YCBCR422)    /* Select  VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565        */
#define USE_VIDEO_CH           (0)                 /* Select  0 or 1            If selecting VIDEO_CMOS_CAMERA, should be 0.)               */
#define VIDEO_PAL              (0)                 /* Select  0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */

main.cpp (camera input config 2)

    /* MT9V111 camera input config */
    ext_in_config.inp_format     = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
    ext_in_config.inp_pxd_edge   = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing data          */
    ext_in_config.inp_vs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Vsync signals */
    ext_in_config.inp_hs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Hsync signals */
    ext_in_config.inp_endian_on  = DisplayBase::OFF;                      /* External input bit endian change on/off       */
    ext_in_config.inp_swap_on    = DisplayBase::OFF;                      /* External input B/R signal swap on/off         */
    ext_in_config.inp_vs_inv     = DisplayBase::SIG_POL_NOT_INVERTED;     /* External input DV_VSYNC inversion control     */
    ext_in_config.inp_hs_inv     = DisplayBase::SIG_POL_INVERTED;         /* External input DV_HSYNC inversion control     */
    ext_in_config.inp_f525_625   = DisplayBase::EXTIN_LINE_525;           /* Number of lines for BT.656 external input */
    ext_in_config.inp_h_pos      = DisplayBase::EXTIN_H_POS_CRYCBY;       /* Y/Cb/Y/Cr data string start timing to Hsync reference */
    ext_in_config.cap_vs_pos     = 6;                                     /* Capture start position from Vsync */
    ext_in_config.cap_hs_pos     = 150;                                   /* Capture start position form Hsync */
    ext_in_config.cap_width      = 640;                                   /* Capture width  */
    ext_in_config.cap_height     = 468u;                                  /* Capture height Max 468[line]
                                                                             Due to CMOS(MT9V111) output signal timing and VDC5 specification */


カメラ画像をUSBメモリへ保存する際、以下の変換方法に沿って変換を行なって保存します。

main.cpp内の"VIDEO_INPUT_FORMAT"の値変換方法
VIDEO_YCBCR422JPEG
VIDEO_RGB888bitmap
VIDEO_RGB565binary (RAW data)


USBを使用する場合、使用するUSB口に合わせて、以下の変更とジャンパーショートを行なって下さい。
(define 0:USB0、define 1:USB1)

USBHost\USBHost\TARGET_RENESAS\TARGET_RZ_A1H\usb_host_setting.h

#define USB_HOST_CH                           0
↓
#define USB_HOST_CH                           1


GR-PEACH側のUSB0を使用する場合は、JP3をショートして下さい。
/media/uploads/RyoheiHagimoto/usb.jpg

GR-PEACH AUDIO CAMERA Shield側のUSB1を使用する場合は、JP1をショートして以下の変更を行なって下さい。
/media/uploads/dkato/audiocamerashield_jp1.jpg

Revision:
0:a8ad8fee330b
Child:
1:edcd6dd3a6f5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Apr 18 06:52:31 2016 +0000
@@ -0,0 +1,498 @@
+#include "mbed.h"
+#include "DisplayBace.h"
+#include "rtos.h"
+#include "JPEG_Converter.h"
+#include "USBHostMSD.h"
+#include "bitmap.h"
+#if defined(TARGET_RZ_A1H)
+#include "usb_host_setting.h"
+#else
+#define USB_HOST_CH            (0)
+#endif
+
+#define VIDEO_CVBS             (0)                 /* Analog  Video Signal */
+#define VIDEO_CMOS_CAMERA      (1)                 /* Digital Video Signal */
+#define VIDEO_YCBCR422         (0)
+#define VIDEO_RGB888           (1)
+#define VIDEO_RGB565           (2)
+
+/**** User Selection *********/
+#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA) /* Select  VIDEO_CVBS or VIDEO_CMOS_CAMERA                       */
+#define VIDEO_INPUT_FORMAT     (VIDEO_YCBCR422)    /* Select  VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565        */
+#define USE_VIDEO_CH           (0)                 /* Select  0 or 1            If selecting VIDEO_CMOS_CAMERA, should be 0.)               */
+#define VIDEO_PAL              (0)                 /* Select  0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */
+/*****************************/
+ 
+/**** LCD Parameter **********/
+#define LCD_DE_MODE            (0)
+#define LCD_SYNC_MODE          (1)
+
+#define LCD_DOT_CLOCK          (13.40f)            // 13.4MHz
+
+#define LCD_H_WIDTH            (480u)
+#define LCD_H_BACK_PORCH       (43u)
+#define LCD_H_FRONT_PORCH      (52u)
+#define LCD_H_SYNC_WIDTH       (41u)
+
+#define LCD_V_WIDTH            (272u)
+#define LCD_V_BACK_PORCH       (12u)
+#define LCD_V_FRONT_PORCH      (2u)
+#define LCD_V_SYNC_WIDTH       (10u)
+
+#define LCD_MODE               (LCD_SYNC_MODE)
+
+/*****************************/
+
+
+#if USE_VIDEO_CH == (0)
+#define VIDEO_INPUT_CH         (DisplayBase::VIDEO_INPUT_CHANNEL_0)
+#define VIDEO_INT_TYPE         (DisplayBase::INT_TYPE_S0_VFIELD)
+#else
+#define VIDEO_INPUT_CH         (DisplayBase::VIDEO_INPUT_CHANNEL_1)
+#define VIDEO_INT_TYPE         (DisplayBase::INT_TYPE_S1_VFIELD)
+#endif
+
+#if ( VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 || VIDEO_INPUT_FORMAT == VIDEO_RGB565 )
+#define DATA_SIZE_PER_PIC      (2u)
+#else
+#define DATA_SIZE_PER_PIC      (4u)
+#endif
+
+/*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
+    in accordance with the frame buffer burst transfer mode. */
+#define PIXEL_HW               (480u)  /* WQVGA */
+#define PIXEL_VW               (272u)  /* WQVGA */
+
+#define VIDEO_BUFFER_STRIDE    (((PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u)
+#define VIDEO_BUFFER_HEIGHT    (PIXEL_VW)
+
+#if (USB_HOST_CH == 1) //Audio Camera Shield USB1
+DigitalOut usb1en(P3_8);
+#endif
+DigitalOut led1(LED1);
+DigitalIn  button(USER_BUTTON0);
+#if(1) //lcd
+DigitalOut lcd_pwon(P7_15);
+DigitalOut lcd_blon(P8_1);
+DigitalOut touch_reset(P4_0);
+PwmOut     lcd_cntrst(P8_15);
+I2C        mI2c(I2C_SDA, I2C_SCL);
+
+typedef struct {
+    uint8_t y_h: 3,
+    reserved: 1,
+    x_h: 3,
+    valid: 1;
+    uint8_t x_l;
+    uint8_t y_l;
+} xyz_data_t;
+
+typedef struct {
+    uint8_t fingers: 3,
+    reserved: 5;
+    uint8_t keys;
+    xyz_data_t xyz_data[2];
+} stx_report_data_t;
+
+static int get_coordinates(uint8_t *count, uint32_t *x0, uint32_t *y0, uint32_t *x1, uint32_t *y1) {
+    char buf[8];
+    stx_report_data_t *pdata;
+    int ret = -1;
+    *count = 0; // Set point detected count to 0.
+
+    if (mI2c.read((0x55 << 1), buf, sizeof(buf)) == 0) {
+        pdata = (stx_report_data_t *)buf;
+        if (pdata->fingers) {
+            if (pdata->xyz_data[0].valid) {
+                *x0 = (pdata->xyz_data[0].x_h << 8) | pdata->xyz_data[0].x_l;
+                *y0 = (pdata->xyz_data[0].y_h << 8) | pdata->xyz_data[0].y_l;
+                (*count)++;
+            }
+        }
+        if (pdata->xyz_data[1].valid) {
+            *x1 = (pdata->xyz_data[1].x_h << 8) | pdata->xyz_data[1].x_l;
+            *y1 = (pdata->xyz_data[1].y_h << 8) | pdata->xyz_data[1].y_l;
+            (*count)++;
+        }
+        ret = 0;
+    }
+
+    return ret;
+}
+#endif
+
+static uint8_t FrameBuffer_Video_A[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16)));  //16 bytes aligned!;
+static uint8_t FrameBuffer_Video_B[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16)));  //16 bytes aligned!;
+static uint8_t JCUBuffer_OUTPUT[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(8)));  //8 bytes aligned!;
+static volatile int32_t vfield_count;
+static volatile int32_t vsync_count;
+
+static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type)
+{
+    //Interrupt callback function
+    if (vfield_count != 0) {
+        vfield_count = 0;
+    }
+}
+
+static void WaitVfield(const int32_t wait_count)
+{
+    vfield_count = wait_count;
+    while (vfield_count > 0) {
+        /* Do nothing */
+    }
+}
+ 
+static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type)
+{
+    //Interrupt callback function for Vsync interruption
+    if (vsync_count > 0) {
+        vsync_count--;
+    }
+}
+
+static void WaitVsync(const int32_t wait_count)
+{
+    //Wait for the specified number of times Vsync occurs
+    vsync_count = wait_count;
+    while (vsync_count > 0) {
+        /* Do nothing */
+    }
+}
+
+int main(void)
+{
+    /* Create DisplayBase object */
+    DisplayBase Display;
+    DisplayBase::graphics_error_t error;
+    JPEG_Converter decoder;
+    JPEG_Converter::bitmap_buff_info_t aBitmapData;
+    FILE * wr_fp = NULL;
+    size_t EncodeSize;
+    uint8_t * write_buff_addr = FrameBuffer_Video_A;
+    uint8_t * save_buff_addr  = FrameBuffer_Video_B;
+
+
+#if VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA
+    DisplayBase::video_ext_in_config_t ext_in_config;
+    PinName cmos_camera_pin[11] = {
+        /* data pin */
+        P2_7, P2_6, P2_5, P2_4, P2_3, P2_2, P2_1, P2_0,
+        /* control pin */
+        P10_0,      /* DV0_CLK   */
+        P1_0,       /* DV0_Vsync */
+        P1_1        /* DV0_Hsync */
+    };
+#endif
+#if(1) //lcd
+    lcd_pwon = 0;
+    lcd_blon = 0;
+    touch_reset = 0;
+    Thread::wait(100);
+ 
+    lcd_pwon = 1;
+    lcd_blon = 1;
+    touch_reset = 1;
+    Thread::wait(100);
+
+    DisplayBase::lcd_config_t lcd_config;
+    PinName lvds_pin[8] = {
+        /* data pin */
+        P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0
+    };
+    DisplayBase::rect_t rect;
+
+    lcd_config.lcd_type             = DisplayBase::LCD_TYPE_LVDS;
+    lcd_config.intputClock          = 66.67f;
+    lcd_config.outputClock          = LCD_DOT_CLOCK;
+    lcd_config.lcd_outformat        = DisplayBase::LCD_OUTFORMAT_RGB888;
+    lcd_config.lcd_edge             = DisplayBase::EDGE_RISING;
+#if(LCD_MODE) //SYNC Mode
+    lcd_config.h_toatal_period      = (LCD_H_BACK_PORCH + LCD_H_WIDTH + LCD_H_FRONT_PORCH);
+    lcd_config.v_toatal_period      = (LCD_V_BACK_PORCH + LCD_V_WIDTH + LCD_V_FRONT_PORCH);
+ 
+    lcd_config.h_disp_widht         = (LCD_H_WIDTH);
+    lcd_config.v_disp_widht         = (LCD_V_WIDTH);
+    lcd_config.h_back_porch         = (LCD_H_BACK_PORCH);
+    lcd_config.v_back_porch         = (LCD_V_BACK_PORCH);
+ 
+    lcd_config.h_sync_port          = DisplayBase::LCD_TCON_PIN_2;
+    lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_INVERTED;
+    lcd_config.h_sync_width         = LCD_H_SYNC_WIDTH;
+ 
+    lcd_config.v_sync_port          = DisplayBase::LCD_TCON_PIN_0;
+    lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_INVERTED;
+    lcd_config.v_sync_width         = LCD_V_SYNC_WIDTH;
+ 
+    lcd_config.de_port              = DisplayBase::LCD_TCON_PIN_3;
+    lcd_config.de_port_polarity     = DisplayBase::SIG_POL_NOT_INVERTED;
+#else  //DE Mode
+    lcd_config.h_toatal_period      = (LCD_H_WIDTH + 80u);
+    lcd_config.v_toatal_period      = (LCD_V_WIDTH);
+
+    lcd_config.h_disp_widht         = (LCD_H_WIDTH);
+    lcd_config.v_disp_widht         = (LCD_V_WIDTH);
+    lcd_config.h_back_porch         = (68u);
+    lcd_config.v_back_porch         = (18u);
+
+    lcd_config.h_sync_port          = DisplayBase::LCD_TCON_PIN_NON;
+    lcd_config.h_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED;
+    lcd_config.h_sync_width         = 0;
+
+    lcd_config.v_sync_port          = DisplayBase::LCD_TCON_PIN_NON;
+    lcd_config.v_sync_port_polarity = DisplayBase::SIG_POL_NOT_INVERTED;
+    lcd_config.v_sync_width         = 0;
+
+    lcd_config.de_port              = DisplayBase::LCD_TCON_PIN_3;
+    lcd_config.de_port_polarity     = DisplayBase::SIG_POL_INVERTED;
+#endif
+
+    /* Graphics initialization process */
+    error = Display.Graphics_init(&lcd_config);
+#else
+    /* Graphics initialization process */
+    error = Display.Graphics_init(NULL);
+#endif
+
+    if (error != DisplayBase::GRAPHICS_OK) {
+        printf("Line %d, error %d\n", __LINE__, error);
+        while (1);
+    }
+
+#if VIDEO_INPUT_METHOD == VIDEO_CVBS
+    error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL);
+    if( error != DisplayBase::GRAPHICS_OK ) {
+        printf("Line %d, error %d\n", __LINE__, error);
+        while(1);
+    }
+
+#elif VIDEO_INPUT_METHOD == VIDEO_CMOS_CAMERA
+    /* MT9V111 camera input config */
+    ext_in_config.inp_format     = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
+    ext_in_config.inp_pxd_edge   = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing data          */
+    ext_in_config.inp_vs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Vsync signals */
+    ext_in_config.inp_hs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Hsync signals */
+    ext_in_config.inp_endian_on  = DisplayBase::OFF;                      /* External input bit endian change on/off       */
+    ext_in_config.inp_swap_on    = DisplayBase::OFF;                      /* External input B/R signal swap on/off         */
+    ext_in_config.inp_vs_inv     = DisplayBase::SIG_POL_NOT_INVERTED;     /* External input DV_VSYNC inversion control     */
+    ext_in_config.inp_hs_inv     = DisplayBase::SIG_POL_INVERTED;         /* External input DV_HSYNC inversion control     */
+    ext_in_config.inp_f525_625   = DisplayBase::EXTIN_LINE_525;           /* Number of lines for BT.656 external input */
+    ext_in_config.inp_h_pos      = DisplayBase::EXTIN_H_POS_CRYCBY;       /* Y/Cb/Y/Cr data string start timing to Hsync reference */
+    ext_in_config.cap_vs_pos     = 6;                                     /* Capture start position from Vsync */
+    ext_in_config.cap_hs_pos     = 150;                                   /* Capture start position form Hsync */
+    ext_in_config.cap_width      = 640;                                   /* Capture width  */
+    ext_in_config.cap_height     = 468u;                                  /* Capture height Max 468[line]
+                                                                             Due to CMOS(MT9V111) output signal timing and VDC5 specification */
+    error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_EXT, &ext_in_config);
+    if( error != DisplayBase::GRAPHICS_OK ) {
+        printf("Line %d, error %d\n", __LINE__, error);
+        while(1);
+    }
+
+    /* MT9V111 camera input port setting */
+    error = Display.Graphics_Dvinput_Port_Init(cmos_camera_pin, 11);
+    if( error != DisplayBase::GRAPHICS_OK ) {
+        printf("Line %d, error %d\n", __LINE__, error);
+        while (1);
+    }
+#endif
+
+    /* Interrupt callback function setting (Vsync signal output from scaler 0) */
+    error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_Vsync);
+    if (error != DisplayBase::GRAPHICS_OK) {
+        printf("Line %d, error %d\n", __LINE__, error);
+        while (1);
+    }
+    /* Video capture setting (progressive form fixed) */
+    error = Display.Video_Write_Setting(
+                VIDEO_INPUT_CH,
+#if VIDEO_PAL == 0
+                DisplayBase::COL_SYS_NTSC_358,
+#else
+                DisplayBase::COL_SYS_PAL_443,
+#endif
+                write_buff_addr,
+                VIDEO_BUFFER_STRIDE,
+#if VIDEO_INPUT_FORMAT == VIDEO_YCBCR422
+                DisplayBase::VIDEO_FORMAT_YCBCR422,
+                DisplayBase::WR_RD_WRSWA_NON,
+#elif VIDEO_INPUT_FORMAT == VIDEO_RGB565
+                DisplayBase::VIDEO_FORMAT_RGB565,
+                DisplayBase::WR_RD_WRSWA_32_16BIT,
+#else
+                DisplayBase::VIDEO_FORMAT_RGB888,
+                DisplayBase::WR_RD_WRSWA_32BIT,
+#endif
+                PIXEL_VW,
+                PIXEL_HW
+            );
+    if (error != DisplayBase::GRAPHICS_OK) {
+        printf("Line %d, error %d\n", __LINE__, error);
+        while (1);
+    }
+
+    /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */
+    error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield);
+    if (error != DisplayBase::GRAPHICS_OK) {
+        printf("Line %d, error %d\n", __LINE__, error);
+        while (1);
+    }
+
+    /* Video write process start */
+    error = Display.Video_Start (VIDEO_INPUT_CH);
+    if (error != DisplayBase::GRAPHICS_OK) {
+        printf("Line %d, error %d\n", __LINE__, error);
+        while (1);
+    }
+
+    /* Video write process stop */
+    error = Display.Video_Stop (VIDEO_INPUT_CH);
+    if (error != DisplayBase::GRAPHICS_OK) {
+        printf("Line %d, error %d\n", __LINE__, error);
+        while (1);
+    }
+
+    /* Video write process start */
+    error = Display.Video_Start (VIDEO_INPUT_CH);
+    if (error != DisplayBase::GRAPHICS_OK) {
+        printf("Line %d, error %d\n", __LINE__, error);
+        while (1);
+    }
+
+    /* Wait vsync to update resister */
+    WaitVsync(1);
+ 
+    /* Wait 2 Vfield(Top or bottom field) */
+    WaitVfield(2);
+
+#if (USB_HOST_CH == 1) //Audio Shield USB1
+    //Audio Shield USB1 enable
+    usb1en = 1;        //Outputs high level
+    Thread::wait(5);
+    usb1en = 0;        //Outputs low level
+#endif
+    USBHostMSD msd("usb");
+    char file_name[32];
+    int file_name_index = 0;
+    int save_file_size;
+
+#if(1) //lcd
+    Display.Graphics_Lvds_Port_Init(lvds_pin, 8);
+    rect.vs = 0;
+    rect.vw = PIXEL_VW;
+    rect.hs = 0;
+    rect.hw = PIXEL_HW;
+
+    Display.Graphics_Read_Setting(
+        DisplayBase::GRAPHICS_LAYER_0,
+        (void *)write_buff_addr,
+        VIDEO_BUFFER_STRIDE,
+        DisplayBase::GRAPHICS_FORMAT_YCBCR422,
+        DisplayBase::WR_RD_WRSWA_NON,
+        &rect
+    );
+    Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
+
+    lcd_cntrst.write(1.0);
+
+    while (1) {
+        uint8_t count = 0;
+        uint32_t x0 = 0;
+        uint32_t y0 = 0;
+        uint32_t x1 = 0;
+        uint32_t y1 = 0;
+
+        /* button check */
+        if (button == 0) {
+            if (!msd.connect()) {
+                printf("Device disconnected\n");
+            } else {
+                led1 = 1;
+                if (write_buff_addr == FrameBuffer_Video_A) {
+                    write_buff_addr = FrameBuffer_Video_B;
+                    save_buff_addr  = FrameBuffer_Video_A;
+                } else {
+                    write_buff_addr = FrameBuffer_Video_A;
+                    save_buff_addr  = FrameBuffer_Video_B;
+                }
+    
+                /* Change write buffer */
+                error = Display.Video_Write_Change(
+                            VIDEO_INPUT_CH,
+                            write_buff_addr,
+                            VIDEO_BUFFER_STRIDE);
+                if (error != DisplayBase::GRAPHICS_OK) {
+                    printf("Line %d, error %d\n", __LINE__, error);
+                    while (1);
+                }
+                /* Wait 2 Vfield(Top or bottom field) */
+                WaitVfield(2);
+    
+                /* FrameBuffer_Video_A or FrameBuffer_Video_B capture completed */
+                printf("USB connect checking...\n");
+                while (!msd.connected()) {
+                    if (!msd.connect()) {
+                        Thread::wait(500);
+                    } else {
+                        break;
+                    }
+                }
+                printf("USB connect check OK!\n");
+    
+                /* Data save */
+#if ( VIDEO_INPUT_FORMAT == VIDEO_RGB565 )
+                /* Save ".bin" file */
+                sprintf(file_name, "/usb/video_%d.bin", file_name_index++);
+                FILE * fp = fopen(file_name, "w");
+                save_file_size = fwrite(save_buff_addr, sizeof(char), (VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT), fp);
+                fclose(fp);
+#elif ( VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 )
+                /* Save ".jpg" file */
+                sprintf(file_name, "/usb/image_%d.jpg", file_name_index++);
+                //YCbCr setting
+                aBitmapData.width           = PIXEL_HW;
+                aBitmapData.height          = PIXEL_VW;
+                aBitmapData.format          = JPEG_Converter::WR_RD_YCbCr422;   //YCbCr[0] & ARGB8888[1] is 4byte, not RGB565[2] is 2byte
+                aBitmapData.buffer_address  = save_buff_addr;
+                printf("File encode start\n");
+                // JPEG_Converter
+                if (decoder.encode(&aBitmapData, JCUBuffer_OUTPUT, &EncodeSize) == JPEG_Converter::JPEG_CONV_OK) {
+                    printf("File encode done\n");
+                    printf("File write start\n");
+                    wr_fp = fopen(file_name, "w");
+                    save_file_size = fwrite(JCUBuffer_OUTPUT, sizeof(char), EncodeSize, wr_fp);
+                    fclose(wr_fp);
+                    printf("File write done\n");
+                    led1 = 0;
+                } else {
+                    printf("Error:JCU encode error\n");
+                    led1 = 0;
+                }
+#else
+                /* Save ".bmp" file */
+                sprintf(file_name, "/usb/video_%d.bmp", file_name_index++);
+    
+                bitmap bitmapfile;
+                save_file_size = bitmapfile.Rgb888ToBmp(file_name, save_buff_addr, PIXEL_HW, PIXEL_VW);
+#endif
+                printf("file name : %s, file size : %d\n", file_name, save_file_size);
+    
+                /* Swap frame buffer */
+                Display.Graphics_Read_Change(
+                            DisplayBase::GRAPHICS_LAYER_0,
+                            write_buff_addr);
+                /* Wait vsync to update resister */
+                WaitVsync(1);
+                led1 = 0;
+            }
+        }
+
+        /* coordinates check */
+        get_coordinates(&count, &x0, &y0, &x1, &y1);
+        if (count != 0) {
+            printf("count=%d, {X=%d,Y=%d}, {X=%d,Y=%d} \n", count, x0, y0, x1, y1);
+        }
+        Thread::wait(100);
+    }
+#endif
+}