Daiki Kato / Mbed OS GR-PEACH_Video_Display

Files at this revision

API Documentation at this revision

Comitter:
dkato
Date:
Tue Jul 24 04:05:18 2018 +0000
Parent:
8:5975dd9a8177
Child:
10:cdef6df6eac9
Commit message:
Minor change

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jul 24 03:10:14 2018 +0000
+++ b/main.cpp	Tue Jul 24 04:05:18 2018 +0000
@@ -5,21 +5,19 @@
 
 #define STRING_DISP_TEST       (1)
 
-/* Video input and LCD layer 0 output */
-#define DATA_SIZE_PER_PIC      (2u)
-
-/*! 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 VIDEO_PIXEL_HW         LCD_PIXEL_WIDTH
-#define VIDEO_PIXEL_VW         LCD_PIXEL_HEIGHT
 #if (MBED_CONF_APP_LCD_TYPE == GR_PEACH_4_3INCH_SHIELD)
 #define ASPECT_RATIO_16_9      (1)
 #endif
 
-#define FRAME_BUFFER_STRIDE    (((VIDEO_PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u)
-#define FRAME_BUFFER_HEIGHT    (VIDEO_PIXEL_VW)
+static DisplayBase Display;
 
-static DisplayBase Display;
+/************************** Camera **************************/
+#if MBED_CONF_APP_CAMERA
+/*! 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 DATA_SIZE_PER_PIC      (2u)
+#define FRAME_BUFFER_STRIDE    (((LCD_PIXEL_WIDTH * DATA_SIZE_PER_PIC) + 31u) & ~31u)
+#define FRAME_BUFFER_HEIGHT    (LCD_PIXEL_HEIGHT)
 
 #if defined(__ICCARM__)
 #pragma data_alignment=32
@@ -28,12 +26,51 @@
 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(32)));
 #endif
 
+static void Start_Video_Camera(void) {
+    DisplayBase::rect_t rect;
+
+    // Initialize the background to black
+    for (uint32_t i = 0; i < sizeof(user_frame_buffer0); i += 2) {
+        user_frame_buffer0[i + 0] = 0x00;
+        user_frame_buffer0[i + 1] = 0x80;
+    }
+
+    // Video capture setting (progressive form fixed)
+    Display.Video_Write_Setting(
+        DisplayBase::VIDEO_INPUT_CHANNEL_0,
+        DisplayBase::COL_SYS_NTSC_358,
+        (void *)user_frame_buffer0,
+        FRAME_BUFFER_STRIDE,
+        DisplayBase::VIDEO_FORMAT_YCBCR422,
+        DisplayBase::WR_RD_WRSWA_32_16BIT,
+        LCD_PIXEL_HEIGHT,
+        LCD_PIXEL_WIDTH
+    );
+    EasyAttach_CameraStart(Display, DisplayBase::VIDEO_INPUT_CHANNEL_0);
+
+    // LCD setting
+    rect.vs = 0;
+    rect.vw = LCD_PIXEL_HEIGHT;
+    rect.hs = 0;
+    rect.hw = LCD_PIXEL_WIDTH;
+    Display.Graphics_Read_Setting(
+        DisplayBase::GRAPHICS_LAYER_0,
+        (void *)user_frame_buffer0,
+        FRAME_BUFFER_STRIDE,
+        DisplayBase::GRAPHICS_FORMAT_YCBCR422,
+        DisplayBase::WR_RD_WRSWA_32_16BIT,
+        &rect
+    );
+    Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
+}
+#endif // MBED_CONF_APP_CAMERA
+
+
+/************************** Touch panel **************************/
 #if defined(TouckKey_LCD_shield)
-
 /* TOUCH BUFFER Parameter GRAPHICS_LAYER_1 */
 #define TOUCH_BUFFER_BYTE_PER_PIXEL   (2u)
 #define TOUCH_BUFFER_STRIDE           (((LCD_PIXEL_WIDTH * TOUCH_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u)
-
 /* Touch panel parameter */
 #define TOUCH_NUM                     (2u)
 #define DRAW_POINT                    (8)
@@ -152,6 +189,8 @@
 }
 #endif // TouckKey_LCD_shield
 
+
+/************************** String Disp Test **************************/
 #if STRING_DISP_TEST
 /* STRING BUFFER Parameter GRAPHICS_LAYER_2 */
 #define STRING_PIXEL_HW               (120)
@@ -170,8 +209,6 @@
     DisplayBase::rect_t rect;
     char test_cnt = 0x20;
 
-    DigitalOut  led_blue(LED_BLUE);
-
     /* The layer by which the character string is drawn */
     memset(user_frame_buffer_string, 0, sizeof(user_frame_buffer_string));
     dcache_clean(user_frame_buffer_string, sizeof(user_frame_buffer_string));
@@ -196,7 +233,6 @@
     ascii_font.DrawStr("Font:", 0, 8, 0x0000ffff, 2);
 
     while (1) {
-        led_blue = !led_blue;
         //colour: rrrrGBAR (r:Reserve G:Green B:Blue A:Alpha R:Red
         ascii_font.DrawChar(test_cnt, 84, 0, 0x0000aa9f, 3);
         if (test_cnt < 0x7e) {
@@ -210,56 +246,24 @@
 }
 #endif // STRING_DISP_TEST
 
-static void Start_Video_Camera(void) {
-    // Video capture setting (progressive form fixed)
-    Display.Video_Write_Setting(
-        DisplayBase::VIDEO_INPUT_CHANNEL_0,
-        DisplayBase::COL_SYS_NTSC_358,
-        (void *)user_frame_buffer0,
-        FRAME_BUFFER_STRIDE,
-        DisplayBase::VIDEO_FORMAT_YCBCR422,
-        DisplayBase::WR_RD_WRSWA_32_16BIT,
-        VIDEO_PIXEL_VW,
-        VIDEO_PIXEL_HW
-    );
-    EasyAttach_CameraStart(Display, DisplayBase::VIDEO_INPUT_CHANNEL_0);
-}
 
-static void Start_LCD_Display(void) {
-    DisplayBase::rect_t rect;
-
-    rect.vs = 0;
-    rect.vw = LCD_PIXEL_HEIGHT;
-    rect.hs = 0;
-    rect.hw = LCD_PIXEL_WIDTH;
-    Display.Graphics_Read_Setting(
-        DisplayBase::GRAPHICS_LAYER_0,
-        (void *)user_frame_buffer0,
-        FRAME_BUFFER_STRIDE,
-        DisplayBase::GRAPHICS_FORMAT_YCBCR422,
-        DisplayBase::WR_RD_WRSWA_32_16BIT,
-        &rect
-    );
-    Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
-
-    Thread::wait(50);
-    EasyAttach_LcdBacklight(true);
-}
-
+/************************** main **************************/
 int main(void) {
-    // Initialize the background to black
-    for (uint32_t i = 0; i < sizeof(user_frame_buffer0); i += 2) {
-        user_frame_buffer0[i + 0] = 0x00;
-        user_frame_buffer0[i + 1] = 0x80;
-    }
-
+    /* Camera and LCD setting */
 #if ASPECT_RATIO_16_9
     EasyAttach_Init(Display, 640, 360);  //aspect ratio 16:9
 #else
     EasyAttach_Init(Display);            //aspect ratio 4:3
 #endif
+
+    /* Start camera */
+#if MBED_CONF_APP_CAMERA
     Start_Video_Camera();
-    Start_LCD_Display();
+#endif // MBED_CONF_APP_CAMERA
+
+    /* LCD Backlight ON */
+    Thread::wait(50);  // After reset, wait a bit so that the power does not rise abruptly.
+    EasyAttach_LcdBacklight(true);
 
     /* Start touch panel processing */
 #if defined(TouckKey_LCD_shield)
@@ -273,10 +277,10 @@
     stringTask.start(callback(string_task));
 #endif // STRING_DISP_TEST
 
-#if defined(TouckKey_LCD_shield)
-    touchTask.join();
-#endif // TouckKey_LCD_shield
-#if STRING_DISP_TEST
-    stringTask.join();
-#endif // STRING_DISP_TEST
+    /* LED blink */
+    DigitalOut  led_blue(LED_BLUE);
+    while (1) {
+        led_blue = !led_blue;
+        Thread::wait(500);
+    }
 }