Sample of NTSC 2ch input.

Dependencies:   GR-PEACH_video LCD_shield_config

概要

2系統のNTSC入力をLCDの左右に分けて表示するサンプルです。
ハードウエア機能を用いることで起動時にビデオ入力とLCD出力の設定した後は自動で動作し続けます。そのため、起動後のCPU負荷が少ないのが特徴です。

機能設定

下記のマクロを変更することで、一部機能を変更できます。

main.cpp

/**** User Selection *********/
/** Camera setting **/
#define VIDEO_INPUT_FORMAT     (VIDEO_YCBCR422)    /* Select  VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565        */
#define VIDEO_PAL              (0)                 /* Select  0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */
/** LCD setting **/
#define LCD_TYPE               (0)                 /* Select  0(4.3inch) or 1(7.1inch) */
/*****************************/


VIDEO_INPUT_FORMATVIDEO_YCBCR422、VIDEO_RGB888、VIDEO_RGB565から選択できます。
VIDEO_PAL0を設定するとNTSC、1を設定するとPALの設定となります。
LCD_TYPE0を設定するとGR-PEACH 4.3 inch LCD Shield、1を設定するとGR-PEACH 7.1 inch LCD Shieldの設定となります。


また、下記関数の引数を変更することで、入力画像の表示位置や大きさを変更できます。
(Output bufferの範囲を超えるような値は設定しないでください。幅は16の倍数、高さは8の倍数を設定してください。)

main.cpp main()

    /* Start of Video ch0 */
    Start_Video(
        DisplayBase::VIDEO_INPUT_CHANNEL_0,   /* Video input channe */
        user_frame_buffer0,                   /* Output buffer */
        0,                                    /* The x coordinate of the upper-left corner */
        0,                                    /* The y coordinate of the upper-left corner */
        (LCD_PIXEL_WIDTH / 2),                /* width  (A multiple of 16) */
        LCD_PIXEL_HEIGHT                      /* height (A multiple of 8) */
    );

(上記の例はNTSC1Aの入力をLCDの画面左側に表示するための設定です。入力画像の高さはLCD画面サイズと同じ、幅は画面サイズの1/2に設定しています。)

構成

GR-PEACHGR-PEACH 4.3 inch LCD Shield または GR-PEACH 7.1 inch LCD ShieldGR-PEACH AUDIO CAMERA Shield

GR-PEACH AUDIO CAMERA Shieldを使用しない場合は、NTSC1Aピン、および、NTSC1Bピンにアナログ信号を入力してください。 /media/uploads/dkato/video_display_analog.jpg
(写真はNTSC1Aピン(黄色)とGNDピン(黒)を引き出した例です。)

Committer:
dkato
Date:
Fri Nov 25 11:34:13 2016 +0000
Revision:
2:d04ef6b5cb70
Parent:
1:e59e938472ac
Supports mbed os 5.2.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:f8cb87301ad8 1 #include "mbed.h"
dkato 0:f8cb87301ad8 2 #include "DisplayBace.h"
dkato 0:f8cb87301ad8 3 #include "rtos.h"
dkato 0:f8cb87301ad8 4
dkato 0:f8cb87301ad8 5 #define VIDEO_YCBCR422 (0)
dkato 0:f8cb87301ad8 6 #define VIDEO_RGB888 (1)
dkato 0:f8cb87301ad8 7 #define VIDEO_RGB565 (2)
dkato 0:f8cb87301ad8 8
dkato 0:f8cb87301ad8 9 /**** User Selection *********/
dkato 0:f8cb87301ad8 10 /** Camera setting **/
dkato 0:f8cb87301ad8 11 #define VIDEO_INPUT_FORMAT (VIDEO_YCBCR422) /* Select VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565 */
dkato 0:f8cb87301ad8 12 #define VIDEO_PAL (0) /* Select 0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */
dkato 0:f8cb87301ad8 13 /** LCD setting **/
dkato 0:f8cb87301ad8 14 #define LCD_TYPE (0) /* Select 0(4.3inch) or 1(7.1inch) */
dkato 0:f8cb87301ad8 15 /*****************************/
dkato 0:f8cb87301ad8 16
dkato 0:f8cb87301ad8 17 /** LCD shield config **/
dkato 0:f8cb87301ad8 18 #if (LCD_TYPE == 0)
dkato 0:f8cb87301ad8 19 #include "LCD_shield_config_4_3inch.h"
dkato 0:f8cb87301ad8 20 #else
dkato 0:f8cb87301ad8 21 #include "LCD_shield_config_7_1inch.h"
dkato 0:f8cb87301ad8 22 #endif
dkato 0:f8cb87301ad8 23
dkato 0:f8cb87301ad8 24 /** Video and Grapics (GRAPHICS_LAYER_0) parameter **/
dkato 0:f8cb87301ad8 25 /* NTSC or PAL */
dkato 0:f8cb87301ad8 26 #if VIDEO_PAL == 0
dkato 0:f8cb87301ad8 27 #define COL_SYS (DisplayBase::COL_SYS_NTSC_358)
dkato 0:f8cb87301ad8 28 #else
dkato 0:f8cb87301ad8 29 #define COL_SYS (DisplayBase::COL_SYS_PAL_443)
dkato 0:f8cb87301ad8 30 #endif
dkato 0:f8cb87301ad8 31
dkato 0:f8cb87301ad8 32 /* Video input and LCD layer 0 output */
dkato 0:f8cb87301ad8 33 #if VIDEO_INPUT_FORMAT == VIDEO_YCBCR422
dkato 0:f8cb87301ad8 34 #define VIDEO_FORMAT (DisplayBase::VIDEO_FORMAT_YCBCR422)
dkato 0:f8cb87301ad8 35 #define GRAPHICS_FORMAT (DisplayBase::GRAPHICS_FORMAT_YCBCR422)
dkato 0:f8cb87301ad8 36 #define WR_RD_WRSWA (DisplayBase::WR_RD_WRSWA_NON)
dkato 0:f8cb87301ad8 37 #elif VIDEO_INPUT_FORMAT == VIDEO_RGB565
dkato 0:f8cb87301ad8 38 #define VIDEO_FORMAT (DisplayBase::VIDEO_FORMAT_RGB565)
dkato 0:f8cb87301ad8 39 #define GRAPHICS_FORMAT (DisplayBase::GRAPHICS_FORMAT_RGB565)
dkato 0:f8cb87301ad8 40 #define WR_RD_WRSWA (DisplayBase::WR_RD_WRSWA_32_16BIT)
dkato 0:f8cb87301ad8 41 #else
dkato 0:f8cb87301ad8 42 #define VIDEO_FORMAT (DisplayBase::VIDEO_FORMAT_RGB888)
dkato 0:f8cb87301ad8 43 #define GRAPHICS_FORMAT (DisplayBase::GRAPHICS_FORMAT_RGB888)
dkato 0:f8cb87301ad8 44 #define WR_RD_WRSWA (DisplayBase::WR_RD_WRSWA_32BIT)
dkato 0:f8cb87301ad8 45 #endif
dkato 0:f8cb87301ad8 46
dkato 0:f8cb87301ad8 47 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
dkato 0:f8cb87301ad8 48 in accordance with the frame buffer burst transfer mode. */
dkato 0:f8cb87301ad8 49 /* FRAME BUFFER Parameter GRAPHICS_LAYER_0 */
dkato 0:f8cb87301ad8 50 #if ( VIDEO_INPUT_FORMAT == VIDEO_YCBCR422 || VIDEO_INPUT_FORMAT == VIDEO_RGB565 )
dkato 0:f8cb87301ad8 51 #define FRAME_BUFFER_BYTE_PER_PIXEL (2u)
dkato 0:f8cb87301ad8 52 #else
dkato 0:f8cb87301ad8 53 #define FRAME_BUFFER_BYTE_PER_PIXEL (4u)
dkato 0:f8cb87301ad8 54 #endif
dkato 0:f8cb87301ad8 55 #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u)
dkato 0:f8cb87301ad8 56
dkato 0:f8cb87301ad8 57 static DisplayBase Display;
dkato 0:f8cb87301ad8 58 static DigitalOut lcd_pwon(P7_15);
dkato 0:f8cb87301ad8 59 static DigitalOut lcd_blon(P8_1);
dkato 0:f8cb87301ad8 60 static PwmOut lcd_cntrst(P8_15);
dkato 0:f8cb87301ad8 61 static DigitalOut led_blue(LED_BLUE);
dkato 0:f8cb87301ad8 62
dkato 0:f8cb87301ad8 63 #if defined(__ICCARM__)
dkato 0:f8cb87301ad8 64 /* 32 bytes aligned */
dkato 0:f8cb87301ad8 65 #pragma data_alignment=32
dkato 0:f8cb87301ad8 66 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT];
dkato 0:f8cb87301ad8 67 #pragma data_alignment=4
dkato 0:f8cb87301ad8 68 #else
dkato 0:f8cb87301ad8 69 /* 32 bytes aligned */
dkato 0:f8cb87301ad8 70 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32)));
dkato 0:f8cb87301ad8 71 #endif
dkato 0:f8cb87301ad8 72 static bool graphics_init_end = false;
dkato 0:f8cb87301ad8 73
dkato 0:f8cb87301ad8 74 /****** LCD ******/
dkato 0:f8cb87301ad8 75 static void Init_LCD_Display(void) {
dkato 0:f8cb87301ad8 76 DisplayBase::graphics_error_t error;
dkato 0:f8cb87301ad8 77 DisplayBase::lcd_config_t lcd_config;
dkato 0:f8cb87301ad8 78 PinName lvds_pin[8] = {
dkato 0:f8cb87301ad8 79 /* data pin */
dkato 0:f8cb87301ad8 80 P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0
dkato 0:f8cb87301ad8 81 };
dkato 0:f8cb87301ad8 82
dkato 0:f8cb87301ad8 83 lcd_pwon = 0;
dkato 0:f8cb87301ad8 84 lcd_blon = 0;
dkato 0:f8cb87301ad8 85 Thread::wait(100);
dkato 0:f8cb87301ad8 86 lcd_pwon = 1;
dkato 0:f8cb87301ad8 87 lcd_blon = 1;
dkato 0:f8cb87301ad8 88
dkato 0:f8cb87301ad8 89 Display.Graphics_Lvds_Port_Init(lvds_pin, 8);
dkato 0:f8cb87301ad8 90
dkato 0:f8cb87301ad8 91 /* Graphics initialization process */
dkato 0:f8cb87301ad8 92 lcd_config = LcdCfgTbl_LCD_shield;
dkato 0:f8cb87301ad8 93 error = Display.Graphics_init(&lcd_config);
dkato 0:f8cb87301ad8 94 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:f8cb87301ad8 95 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:f8cb87301ad8 96 mbed_die();
dkato 0:f8cb87301ad8 97 }
dkato 0:f8cb87301ad8 98 graphics_init_end = true;
dkato 0:f8cb87301ad8 99 }
dkato 0:f8cb87301ad8 100
dkato 0:f8cb87301ad8 101 static void Start_LCD_Display(uint8_t * p_buf) {
dkato 0:f8cb87301ad8 102 DisplayBase::rect_t rect;
dkato 0:f8cb87301ad8 103
dkato 0:f8cb87301ad8 104 rect.vs = 0;
dkato 0:f8cb87301ad8 105 rect.vw = LCD_PIXEL_HEIGHT;
dkato 0:f8cb87301ad8 106 rect.hs = 0;
dkato 0:f8cb87301ad8 107 rect.hw = LCD_PIXEL_WIDTH;
dkato 0:f8cb87301ad8 108 Display.Graphics_Read_Setting(
dkato 0:f8cb87301ad8 109 DisplayBase::GRAPHICS_LAYER_0,
dkato 0:f8cb87301ad8 110 (void *)p_buf,
dkato 0:f8cb87301ad8 111 FRAME_BUFFER_STRIDE,
dkato 0:f8cb87301ad8 112 GRAPHICS_FORMAT,
dkato 0:f8cb87301ad8 113 WR_RD_WRSWA,
dkato 0:f8cb87301ad8 114 &rect
dkato 0:f8cb87301ad8 115 );
dkato 0:f8cb87301ad8 116 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
dkato 0:f8cb87301ad8 117 }
dkato 0:f8cb87301ad8 118
dkato 0:f8cb87301ad8 119 /****** Video ******/
dkato 0:f8cb87301ad8 120 static void Init_Video(void) {
dkato 0:f8cb87301ad8 121 DisplayBase::graphics_error_t error;
dkato 0:f8cb87301ad8 122
dkato 0:f8cb87301ad8 123 /* Graphics initialization process */
dkato 0:f8cb87301ad8 124 if (graphics_init_end == false) {
dkato 0:f8cb87301ad8 125 /* When not initializing LCD, this processing is needed. */
dkato 0:f8cb87301ad8 126 error = Display.Graphics_init(NULL);
dkato 0:f8cb87301ad8 127 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:f8cb87301ad8 128 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:f8cb87301ad8 129 mbed_die();
dkato 0:f8cb87301ad8 130 }
dkato 0:f8cb87301ad8 131 graphics_init_end = true;
dkato 0:f8cb87301ad8 132 }
dkato 0:f8cb87301ad8 133
dkato 0:f8cb87301ad8 134 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL);
dkato 0:f8cb87301ad8 135 if( error != DisplayBase::GRAPHICS_OK ) {
dkato 0:f8cb87301ad8 136 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:f8cb87301ad8 137 mbed_die();
dkato 0:f8cb87301ad8 138 }
dkato 0:f8cb87301ad8 139 }
dkato 0:f8cb87301ad8 140
dkato 1:e59e938472ac 141 static void Start_Video(DisplayBase::video_input_channel_t ch, uint8_t * p_frame_buffer,
dkato 1:e59e938472ac 142 uint16_t pos_x, uint16_t pos_y, uint16_t width, uint16_t height) {
dkato 0:f8cb87301ad8 143 DisplayBase::graphics_error_t error;
dkato 1:e59e938472ac 144 uint8_t * p_buf;
dkato 1:e59e938472ac 145
dkato 1:e59e938472ac 146 p_buf = p_frame_buffer + (FRAME_BUFFER_BYTE_PER_PIXEL * pos_x) + (FRAME_BUFFER_STRIDE * pos_y);
dkato 0:f8cb87301ad8 147
dkato 0:f8cb87301ad8 148 /* Video capture setting (progressive form fixed) */
dkato 0:f8cb87301ad8 149 error = Display.Video_Write_Setting(
dkato 0:f8cb87301ad8 150 ch,
dkato 0:f8cb87301ad8 151 COL_SYS,
dkato 0:f8cb87301ad8 152 p_buf,
dkato 0:f8cb87301ad8 153 FRAME_BUFFER_STRIDE,
dkato 0:f8cb87301ad8 154 VIDEO_FORMAT,
dkato 0:f8cb87301ad8 155 WR_RD_WRSWA,
dkato 1:e59e938472ac 156 (height & ~7u), /* A multiple of 8 */
dkato 1:e59e938472ac 157 (width & ~15u) /* A multiple of 16 */
dkato 0:f8cb87301ad8 158 );
dkato 0:f8cb87301ad8 159 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:f8cb87301ad8 160 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:f8cb87301ad8 161 mbed_die();
dkato 0:f8cb87301ad8 162 }
dkato 0:f8cb87301ad8 163
dkato 0:f8cb87301ad8 164 /* Video write process start */
dkato 0:f8cb87301ad8 165 error = Display.Video_Start(ch);
dkato 0:f8cb87301ad8 166 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:f8cb87301ad8 167 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:f8cb87301ad8 168 mbed_die();
dkato 0:f8cb87301ad8 169 }
dkato 0:f8cb87301ad8 170
dkato 0:f8cb87301ad8 171 /* Video write process stop */
dkato 0:f8cb87301ad8 172 error = Display.Video_Stop(ch);
dkato 0:f8cb87301ad8 173 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:f8cb87301ad8 174 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:f8cb87301ad8 175 mbed_die();
dkato 0:f8cb87301ad8 176 }
dkato 0:f8cb87301ad8 177
dkato 0:f8cb87301ad8 178 /* Video write process start */
dkato 0:f8cb87301ad8 179 error = Display.Video_Start(ch);
dkato 0:f8cb87301ad8 180 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:f8cb87301ad8 181 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:f8cb87301ad8 182 mbed_die();
dkato 0:f8cb87301ad8 183 }
dkato 0:f8cb87301ad8 184 }
dkato 0:f8cb87301ad8 185
dkato 1:e59e938472ac 186 /****** Cache control ******/
dkato 1:e59e938472ac 187 static void dcache_clean(void * p_buf, uint32_t size){
dkato 1:e59e938472ac 188 uint32_t start_addr = (uint32_t)p_buf & 0xFFFFFFE0;
dkato 1:e59e938472ac 189 uint32_t end_addr = (uint32_t)p_buf + size;
dkato 1:e59e938472ac 190 uint32_t addr;
dkato 1:e59e938472ac 191
dkato 1:e59e938472ac 192 /* Data cache clean */
dkato 1:e59e938472ac 193 for (addr = start_addr; addr < end_addr; addr += 0x20) {
dkato 1:e59e938472ac 194 __v7_clean_dcache_mva((void *)addr);
dkato 1:e59e938472ac 195 }
dkato 1:e59e938472ac 196 }
dkato 1:e59e938472ac 197
dkato 0:f8cb87301ad8 198 /****** main ******/
dkato 0:f8cb87301ad8 199 int main(void) {
dkato 0:f8cb87301ad8 200 /* Initialization of LCD */
dkato 0:f8cb87301ad8 201 Init_LCD_Display(); /* When using LCD, please call before than Init_Video(). */
dkato 0:f8cb87301ad8 202
dkato 0:f8cb87301ad8 203 /* Initialization of Video */
dkato 0:f8cb87301ad8 204 Init_Video();
dkato 0:f8cb87301ad8 205
dkato 0:f8cb87301ad8 206 /* Initialization memory */
dkato 1:e59e938472ac 207 #if VIDEO_INPUT_FORMAT == VIDEO_YCBCR422
dkato 1:e59e938472ac 208 for (int i = 0; i < sizeof(user_frame_buffer0); i += 2) {
dkato 1:e59e938472ac 209 user_frame_buffer0[i + 0] = 0x10;
dkato 1:e59e938472ac 210 user_frame_buffer0[i + 1] = 0x80;
dkato 1:e59e938472ac 211 }
dkato 1:e59e938472ac 212 #else
dkato 1:e59e938472ac 213 memset(user_frame_buffer0, 0, sizeof(user_frame_buffer0));
dkato 1:e59e938472ac 214 #endif
dkato 1:e59e938472ac 215 dcache_clean(user_frame_buffer0, sizeof(user_frame_buffer0));
dkato 0:f8cb87301ad8 216
dkato 1:e59e938472ac 217 /* Start of Video ch0 */
dkato 1:e59e938472ac 218 Start_Video(
dkato 1:e59e938472ac 219 DisplayBase::VIDEO_INPUT_CHANNEL_0, /* Video input channe */
dkato 1:e59e938472ac 220 user_frame_buffer0, /* Output buffer */
dkato 1:e59e938472ac 221 0, /* The x coordinate of the upper-left corner */
dkato 1:e59e938472ac 222 0, /* The y coordinate of the upper-left corner */
dkato 1:e59e938472ac 223 (LCD_PIXEL_WIDTH / 2), /* width (A multiple of 16) */
dkato 1:e59e938472ac 224 LCD_PIXEL_HEIGHT /* height (A multiple of 8) */
dkato 1:e59e938472ac 225 );
dkato 1:e59e938472ac 226
dkato 1:e59e938472ac 227 /* Start of Video ch1 */
dkato 1:e59e938472ac 228 Start_Video(
dkato 1:e59e938472ac 229 DisplayBase::VIDEO_INPUT_CHANNEL_1, /* Video input channe */
dkato 1:e59e938472ac 230 user_frame_buffer0, /* Output buffer */
dkato 1:e59e938472ac 231 (LCD_PIXEL_WIDTH / 2), /* The x coordinate of the upper-left corner */
dkato 1:e59e938472ac 232 0, /* The y coordinate of the upper-left corner */
dkato 1:e59e938472ac 233 (LCD_PIXEL_WIDTH / 2), /* width (A multiple of 16) */
dkato 1:e59e938472ac 234 LCD_PIXEL_HEIGHT /* height (A multiple of 8) */
dkato 1:e59e938472ac 235 );
dkato 0:f8cb87301ad8 236
dkato 0:f8cb87301ad8 237 /* Start of LCD */
dkato 0:f8cb87301ad8 238 Start_LCD_Display(&user_frame_buffer0[0]);
dkato 0:f8cb87301ad8 239
dkato 0:f8cb87301ad8 240 /* Backlight on */
dkato 0:f8cb87301ad8 241 Thread::wait(200);
dkato 0:f8cb87301ad8 242 lcd_cntrst.write(1.0);
dkato 0:f8cb87301ad8 243
dkato 0:f8cb87301ad8 244 while (1) {
dkato 0:f8cb87301ad8 245 led_blue = !led_blue;
dkato 0:f8cb87301ad8 246 Thread::wait(1000);
dkato 0:f8cb87301ad8 247 }
dkato 0:f8cb87301ad8 248 }