Image scroll Sample. This program uses GraphicsFramework library and Si1143 sensor.

Dependencies:   GR-PEACH_video GraphicsFramework R_BSP SI1143 mbed-rtos mbed

Fork of RGA_HelloWorld by Renesas

About Si1143

Si1143 is a gesture sensor and can be controlled by using the I2C.
This can be detected from the shortest 1cm up to 200cm.
Si1143 emits three infrared LED that is mounted on a substrate, and detects the movement by measuring the reflected light from the external object.

About wiring

VDD3.3V
SCLD15
SDAD14
GNDGND
Revision:
4:2318f8bee89c
Parent:
2:c7faef0ef374
--- a/main.cpp	Thu Jan 21 10:21:28 2016 +0000
+++ b/main.cpp	Mon May 30 04:55:35 2016 +0000
@@ -1,128 +1,62 @@
-/*
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
- 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
 #include "mbed.h"
 #include "rga_func.h"
+#include "Images/BinaryImage_RZ_A1H.h"
 #include "DisplayBace.h"
 #include "rtos.h"
-
+#include "SI1143.h"
 
-/* LCD Parameter */
-#define LCD_INPUT_CLOCK                     (66.67f)
-#define LCD_OUTPUT_CLOCK                    (33.26f)
+/**** LCD Parameter **********/
+#define LCD_DE_MODE            (0)
+#define LCD_SYNC_MODE          (1)
+
+#define LCD_DOT_CLOCK          (13.40f)     // 13.4MHz
 
-#define LCD_PIXEL_WIDTH                     (800)
-#define LCD_PIXEL_HEIGHT                    (480)
-#define LCD_H_BACK_PORCH                    (128 + 36)
-#define LCD_H_FRONT_PORCH                   (92)
-#define LCD_V_BACK_PORCH                    (35 + 5)
-#define LCD_V_FRONT_PORCH                   (5)
+#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)
+
+/*****************************/
 
 /* FRAME BUFFER Parameter */
 #define FRAME_BUFFER_BYTE_PER_PIXEL         (2)
-#define FRAME_BUFFER_STRIDE                 (((LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u)
-
-#define DRAW_RECTANGLE_CNT_MAX              (4)
+#define FRAME_BUFFER_STRIDE                 (((LCD_H_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u)
 
-typedef enum {
-    RGA_FUNC_NON,
-    RGA_FUNC_DRAW_RECTANGLE,
-    RGA_FUNC_DRAW_IMAGE,
-    RGA_FUNC_DISSOLVE,
-    RGA_FUNC_SCROLL,
-    RGA_FUNC_ZOOM,
-    RGA_FUNC_ROTATION,
-    RGA_FUNC_ACCELERATE,
-    RGA_FUNC_ANIME_EASE,
-    RGA_FUNC_ANIME_LINEAR,
-    RGA_FUNC_ANIME_EASE_IN,
-    RGA_FUNC_ANIME_EASE_OUT,
-    RGA_FUNC_ANIME_EASE_IN_OUT,
-    RGA_FUNC_RETURN,
-    RGA_FUNC_END
-}func_code_t;
+enum {
+    IMG_SETTING,
+    IMG_START,
+    IMG_RED,
+    IMG_BLUE,
+    IMG_YELLOW,
+    IMG_GREEN
+};
 
 DigitalOut  lcd_pwon(P7_15);
 DigitalOut  lcd_blon(P8_1);
+DigitalOut  touch_reset(P4_0);
 PwmOut      lcd_cntrst(P8_15);
-I2C         i2c(I2C_SDA, I2C_SCL);
 DisplayBase Display;
+SI1143      sensor(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;
-    uint8_t z;
-} xyz_data_t;
- 
-typedef struct {
-    uint8_t fingers: 4,
-    reserved: 4;
-    uint8_t keys;
-    xyz_data_t xyz_data;
-} stx_report_data_t;
+static const graphics_image_t* image_file[6] = {
+    Setting_jpg_File, Start_jpg_File, red_jpg_File, blue_jpg_File, yellow_jpg_File, green_jpg_File
+};
 
-typedef struct {
-    uint32_t pic_pos_x;             /* X position of the key picture. */
-    uint32_t pic_pos_y;             /* Y position of the key picture. */
-    uint32_t pic_width;             /* Width of the key picture. */
-    uint32_t pic_height;            /* Height of the key picture. */
-    func_code_t func_code;          /* func code of the key picture. */
-} key_pic_info_t;
-
-static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32)));  /* 32 bytes aligned */
-static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((aligned(32))); /* 32 bytes aligned */
+static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_V_WIDTH]__attribute((aligned(32)));  /* 32 bytes aligned */
+static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_V_WIDTH]__attribute((aligned(32))); /* 32 bytes aligned */
 static frame_buffer_t frame_buffer_info;
 static volatile int32_t vsync_count = 0;
-
-static const key_pic_info_t top_screen_key_tbl[] = {
-    /*   X       Y     Width   Height   Func code                 */
-    {    50,    350,    120,     52,    RGA_FUNC_DRAW_RECTANGLE    },  /* RGA Func1 */
-    {   230,    350,    120,     52,    RGA_FUNC_DRAW_IMAGE        },  /* RGA Func2 */
-    {   410,    350,    120,     52,    RGA_FUNC_DISSOLVE          },  /* RGA Func3 */
-    {    50,    420,    120,     52,    RGA_FUNC_SCROLL            },  /* RGA Func4 */
-    {   230,    420,    120,     52,    RGA_FUNC_ZOOM              },  /* RGA Func5 */
-    {   410,    420,    120,     52,    RGA_FUNC_ROTATION          },  /* RGA Func6 */
-    {   615,    420,    120,     52,    RGA_FUNC_ACCELERATE        },  /* RGA Func7 */
-    {     0,      0,      0,      0,    RGA_FUNC_END               }   /* table end */
-};
-
-static const key_pic_info_t return_key_tbl[] = {
-    /*   X       Y     Width   Height   Func code                 */
-    {   640,     10,    150,     84,    RGA_FUNC_RETURN            },  /* Return Top Screen */
-    {     0,      0,      0,      0,    RGA_FUNC_END               }   /* table end */
-};
-
-static const key_pic_info_t animetion_timing_key_tbl[] = {
-    /*   X       Y     Width   Height   Func code                 */
-    {   640,     10,    150,     84,    RGA_FUNC_RETURN            },  /* Return Top Screen */
-    {    17,    372,    136,     50,    RGA_FUNC_ANIME_EASE        },  /* ease */
-    {   173,    372,    136,     50,    RGA_FUNC_ANIME_LINEAR      },  /* linear */
-    {   330,    372,    136,     50,    RGA_FUNC_ANIME_EASE_IN     },  /* ease-in */
-    {   487,    372,    136,     50,    RGA_FUNC_ANIME_EASE_OUT    },  /* ease-out */
-    {   644,    372,    136,     50,    RGA_FUNC_ANIME_EASE_IN_OUT },  /* ease-in-out */
-    {     0,      0,      0,      0,    RGA_FUNC_END               }   /* table end */
-};
+static int sense_old[3] = {0, 0, 0};
+static int sense_new[3] = {0, 0, 0};
+static const graphics_image_t* image_old = image_file[IMG_START];
+static const graphics_image_t* image_new = image_file[IMG_START];
 
 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) {
     /* Interrupt callback function for Vsync interruption */
@@ -139,35 +73,164 @@
     }
 }
 
-static void Init_LCD_Display(uint8_t* disp_buf) {
+static int Get_Direction(void) {
+    int dire_sense[3];
+    int ret;
+    // Read each led sensor
+    sense_new[0] = sensor.get_ps1(2);
+    sense_new[1] = sensor.get_ps2(2);
+    sense_new[2] = sensor.get_ps3(2);
+
+    if ((sense_new[0] > 50) && (sense_new[1] > 50) && (sense_new[2] > 50)) {
+        for (int cnt = 0; cnt < 3; cnt++) {
+            dire_sense[cnt] = sense_new[cnt] - sense_old[cnt];
+            if (dire_sense[cnt] <= 50) {        // less than 50 or minus
+                dire_sense[cnt] = 0;
+            }
+        }
+        if (((sense_old[0] - sense_old[1]) > 50) && ((sense_old[0] - sense_old[2]) > 50)) {
+            /* sense1 to ... */
+            if ((dire_sense[1] > dire_sense[0]) && (dire_sense[1] > dire_sense[2])) {
+                ret = DIREC_UP;
+            } else if ((dire_sense[2] > dire_sense[0]) && (dire_sense[2] > dire_sense[1])) {
+                ret = DIREC_RIGHT;
+            } else {
+                ret = DIREC_NON;
+            }
+        } else if (((sense_old[1] - sense_old[0]) > 50) && ((sense_old[1] - sense_old[2]) > 50)) {
+            /* sense2 to ... */
+            if ((dire_sense[0] > dire_sense[1]) && (dire_sense[0] > dire_sense[2])) {
+                ret = DIREC_DOWN;
+            } else if ((dire_sense[2] > dire_sense[0]) && (dire_sense[2] > dire_sense[1])) {
+                ret = DIREC_DOWN;
+            } else {
+                ret = DIREC_NON;
+            }
+        } else if (((sense_old[2] - sense_old[0]) > 50) && ((sense_old[2] - sense_old[1]) > 50)) {
+            /* sense3 to ... */
+            if ((dire_sense[0] > dire_sense[1]) && (dire_sense[0] > dire_sense[2])) {
+                ret = DIREC_LEFT;
+            } else if ((dire_sense[1] > dire_sense[0]) && (dire_sense[1] > dire_sense[2])) {
+                ret = DIREC_UP;
+            } else {
+                ret = DIREC_NON;
+            }
+        } else {
+            ret = DIREC_NON;
+        }
+    } else {
+        ret = DIREC_NON;
+    }
+    sense_old[0] = sense_new[0];
+    sense_old[1] = sense_new[1];
+    sense_old[2] = sense_new[2];
+
+
+    return ret;
+}
+
+static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) {
+    if (frmbuf_info->draw_buffer_index == 1) {
+        frmbuf_info->draw_buffer_index = 0;
+    } else {
+        frmbuf_info->draw_buffer_index = 1;
+    }
+}
+
+static void Update_LCD_Display(frame_buffer_t * frmbuf_info) {
+    Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0,
+    (void *)frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]);
+    Wait_Vsync(1);
+}
+
+static void Draw_Image(int direction) {
+    int work_width_pos;
+
+    if (direction == DIREC_RIGHT) {
+        image_new = image_file[IMG_RED];
+    } else if (direction == DIREC_LEFT) {
+        image_new = image_file[IMG_BLUE];
+    } else if (direction == DIREC_UP) {
+        image_new = image_file[IMG_YELLOW];
+    } else if (direction == DIREC_DOWN) {
+        image_new = image_file[IMG_GREEN];
+    }
+    for (work_width_pos = 1; work_width_pos <= SCROLL_STEP_NUM; work_width_pos++) {
+        /* Draw screen */
+        Swap_FrameBuffer(&frame_buffer_info);
+        RGA_Func_Scroll(&frame_buffer_info, image_old, image_new, direction, (float32_t)work_width_pos / (float32_t)SCROLL_STEP_NUM);
+        Update_LCD_Display(&frame_buffer_info);
+    }
+    image_old = image_new;
+}
+
+int main(void) {
     /* Create DisplayBase object */
     DisplayBase::graphics_error_t error;
-    DisplayBase::rect_t rect;
+    int direction = 0;
+
+    memset(user_frame_buffer, 0, sizeof(user_frame_buffer));
+    memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2));
+    frame_buffer_info.buffer_address[0] = user_frame_buffer;
+    frame_buffer_info.buffer_address[1] = user_frame_buffer2;
+    frame_buffer_info.buffer_count      = 2;
+    frame_buffer_info.show_buffer_index = 0;
+    frame_buffer_info.draw_buffer_index = 0;
+    frame_buffer_info.width             = LCD_H_WIDTH;
+    frame_buffer_info.byte_per_pixel    = FRAME_BUFFER_BYTE_PER_PIXEL;
+    frame_buffer_info.stride            = LCD_H_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL;
+    frame_buffer_info.height            = LCD_V_WIDTH;
+    frame_buffer_info.pixel_format      = PIXEL_FORMAT_RGB565;
+
+    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
     };
-
-    lcd_pwon = 0;
-    lcd_blon = 0;
-    Thread::wait(100);
-    lcd_pwon = 1;
-    lcd_blon = 1;
-    Thread::wait(100);
+    DisplayBase::rect_t rect;
 
     lcd_config.lcd_type             = DisplayBase::LCD_TYPE_LVDS;
-    lcd_config.intputClock          = LCD_INPUT_CLOCK;
-    lcd_config.outputClock          = LCD_OUTPUT_CLOCK;
+    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;
-    lcd_config.h_toatal_period      = (LCD_PIXEL_WIDTH  + LCD_H_FRONT_PORCH + LCD_H_BACK_PORCH);
-    lcd_config.v_toatal_period      = (LCD_PIXEL_HEIGHT + LCD_V_FRONT_PORCH + LCD_V_BACK_PORCH);
+#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_PIXEL_WIDTH;
-    lcd_config.v_disp_widht         = LCD_PIXEL_HEIGHT;
-    lcd_config.h_back_porch         = LCD_H_BACK_PORCH;
-    lcd_config.v_back_porch         = LCD_V_BACK_PORCH;
+    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;
@@ -178,7 +241,8 @@
     lcd_config.v_sync_width         = 0;
 
     lcd_config.de_port              = DisplayBase::LCD_TCON_PIN_3;
-    lcd_config.de_port_polarity     = DisplayBase::SIG_POL_NOT_INVERTED;
+    lcd_config.de_port_polarity     = DisplayBase::SIG_POL_INVERTED;
+#endif
 
     /* Graphics initialization process */
     error = Display.Graphics_init(&lcd_config);
@@ -196,344 +260,37 @@
 
     Display.Graphics_Lvds_Port_Init(lvds_pin, 8);
     rect.vs = 0;
-    rect.vw = LCD_PIXEL_HEIGHT;
+    rect.vw = LCD_V_WIDTH;
     rect.hs = 0;
-    rect.hw = LCD_PIXEL_WIDTH;
+    rect.hw = LCD_H_WIDTH;
 
     Display.Graphics_Read_Setting(
         DisplayBase::GRAPHICS_LAYER_0,
-        (void *)disp_buf,
+        (void *)frame_buffer_info.buffer_address[0],
         FRAME_BUFFER_STRIDE,
         DisplayBase::GRAPHICS_FORMAT_RGB565,
         DisplayBase::WR_RD_WRSWA_32_16BIT,
         &rect
     );
-}
 
-static void Start_LCD_Display(void) {
+    /* Display Start */
+    Set_RGAObject(&frame_buffer_info);
     Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
-
     lcd_cntrst.write(1.0);
-}
-
-static void Update_LCD_Display(frame_buffer_t * frmbuf_info) {
-    Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0,
-     (void *)frmbuf_info->buffer_address[frmbuf_info->draw_buffer_index]);
-    Wait_Vsync(1);
-}
 
-static int Get_Coordinates(uint8_t *count, uint32_t *x0, uint32_t *y0) {
-    char buf[6];
-    stx_report_data_t *pdata;
-    int ret = -1;
-    *count = 0;                     // Set point detected count to 0
+    // Setup the baseline
+    RGA_Func_DrawTopScreen(&frame_buffer_info, image_file[IMG_SETTING]);
+    printf("SI1143 Gesture Sensor setting...\n");
+    sensor.bias(1,5);
+    Thread::wait(1000);
+    RGA_Func_DrawTopScreen(&frame_buffer_info, image_file[IMG_START]);
+    printf("SI1143 Gesture Sensor setting finished!\n");
 
-    if (i2c.read((0x55 << 1), buf, sizeof(buf)) == 0) {
-        pdata = (stx_report_data_t *)buf;
-        if (pdata->fingers) {
-            if (pdata->xyz_data.valid) {
-                *x0 = (pdata->xyz_data.x_h << 8) | pdata->xyz_data.x_l;
-                *y0 = (pdata->xyz_data.y_h << 8) | pdata->xyz_data.y_l;
-                (*count)++;
-            }
+    while (1) {
+        /* Get coordinates */
+        direction = Get_Direction();
+        if (direction != 0) {
+            Draw_Image(direction);
         }
-        ret = 0;
-    }
-
-    return ret;
-}
-
-static func_code_t Scan_Key(const key_pic_info_t * key_tbl, const uint32_t pos_x, const uint32_t pos_y) {
-    func_code_t ret = RGA_FUNC_NON;
-
-    while (ret == RGA_FUNC_NON) {
-        if (key_tbl->func_code == RGA_FUNC_END) {
-            break;
-        }
-        /* Check the range of the X position */
-        if ((pos_x >= key_tbl->pic_pos_x) && (pos_x <= (key_tbl->pic_pos_x + key_tbl->pic_width))) {
-            /* Check the range of the Y position */
-            if ((pos_y >= key_tbl->pic_pos_y) && (pos_y <= (key_tbl->pic_pos_y + key_tbl->pic_height))) {
-                /* Decide the func code. */
-                ret = key_tbl->func_code;
-            }
-        }
-        key_tbl++;
-    }
-
-    return ret;
-}
-
-static void Swap_FrameBuffer(frame_buffer_t * frmbuf_info) {
-    if (frmbuf_info->draw_buffer_index == 1) {
-        frmbuf_info->draw_buffer_index = 0;
-    } else {
-        frmbuf_info->draw_buffer_index = 1;
     }
 }
-
-static void Exe_RGA_Func(int func_name, frame_buffer_t* frmbuf_info) {
-    uint8_t touch_num = 0;
-    uint32_t pos_x0 = 0;
-    uint32_t pos_y0 = 0;
-    func_code_t func_code;
-
-    switch (func_name) {
-        case RGA_FUNC_DRAW_RECTANGLE:
-            bool key_on = false;
-            int cnt;
-            int color_cnt = 0;
-            int x_0 = 0;
-            int y_0 = 0;
-            draw_rectangle_pos_t pos_tbl[DRAW_RECTANGLE_CNT_MAX] = {0};
-
-            pos_tbl[0].style = "#FF0000";  /* red */
-            pos_tbl[1].style = "#00FF00";  /* green */
-            pos_tbl[2].style = "#0000FF";  /* blue */
-            pos_tbl[3].style = "#000000";  /* black */
-
-            while (1) {
-                /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
-                if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
-                        break;
-                    }
-                    if (key_on == false) {
-                        key_on = true;
-                        if (color_cnt == 0) {
-                            for (cnt = 0; cnt < DRAW_RECTANGLE_CNT_MAX; cnt++) {
-                                pos_tbl[cnt].x = 0;
-                                pos_tbl[cnt].y = 0;
-                                pos_tbl[cnt].w = 0;
-                                pos_tbl[cnt].h = 0;
-                            }
-                        }
-                        x_0 = pos_x0;
-                        y_0 = pos_y0;
-                    }
-                    if (x_0 < pos_x0) {
-                        pos_tbl[color_cnt].x = x_0;
-                        pos_tbl[color_cnt].w = pos_x0 - x_0;
-                    } else {
-                        pos_tbl[color_cnt].x = pos_x0;
-                        pos_tbl[color_cnt].w = x_0 - pos_x0;
-                    }
-                    if (y_0 < pos_y0) {
-                        pos_tbl[color_cnt].y = y_0;
-                        pos_tbl[color_cnt].h = pos_y0 - y_0;
-                    } else {
-                        pos_tbl[color_cnt].y = pos_y0;
-                        pos_tbl[color_cnt].h = y_0 - pos_y0;
-                    }
-                } else {
-                    if (key_on != false) {
-                        color_cnt++;
-                        if (color_cnt == DRAW_RECTANGLE_CNT_MAX) {
-                            color_cnt = 0;
-                        }
-                    }
-                    key_on = false;
-                }
-                /* Draw screen */
-                Swap_FrameBuffer(frmbuf_info);
-                RGA_Func_DrawRectangle(frmbuf_info, pos_tbl, DRAW_RECTANGLE_CNT_MAX);
-                Update_LCD_Display(frmbuf_info);
-            }
-            break;
-        case RGA_FUNC_DRAW_IMAGE:
-            int center_pos_x = 320;
-            int center_pos_y = 110;
-            while (1) {
-                /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
-                if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
-                        break;
-                    }
-                    center_pos_x = pos_x0;
-                    center_pos_y = pos_y0;
-                }
-                /* Draw screen */
-                Swap_FrameBuffer(frmbuf_info);
-                RGA_Func_DrawImage(frmbuf_info, center_pos_x, center_pos_y);
-                Update_LCD_Display(frmbuf_info);
-            }
-            break;
-        case RGA_FUNC_DISSOLVE:
-            float32_t work_alpha = 0.0f;
-            while (1) {
-                /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
-                if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
-                        break;
-                    }
-                    work_alpha = (float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH);
-                }
-                /* Draw screen */
-                Swap_FrameBuffer(frmbuf_info);
-                RGA_Func_Dissolve(frmbuf_info, work_alpha);
-                Update_LCD_Display(frmbuf_info);
-            }
-            break;
-        case RGA_FUNC_SCROLL:
-            int work_width_pos = 0;
-            while (1) {
-                /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
-                if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
-                        break;
-                    }
-                    work_width_pos = SCROLL_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH));
-                }
-                /* Draw screen */
-                Swap_FrameBuffer(frmbuf_info);
-                RGA_Func_Scroll(frmbuf_info, work_width_pos);
-                Update_LCD_Display(frmbuf_info);
-            }
-            break;
-        case RGA_FUNC_ZOOM:
-            int work_height_pos = ZOOM_MAX_NUM;
-            while (1) {
-                /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
-                if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
-                        break;
-                    }
-                    work_height_pos = ZOOM_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH));
-                }
-                /* Draw screen */
-                Swap_FrameBuffer(frmbuf_info);
-                RGA_Func_Zoom(frmbuf_info,  work_height_pos);
-                Update_LCD_Display(frmbuf_info);
-            }
-            break;
-        case RGA_FUNC_ROTATION:
-            graphics_matrix_float_t work_angle = 0;
-            while (1) {
-                /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
-                if (touch_num != 0) {
-                    if (Scan_Key(return_key_tbl, pos_x0, pos_y0) == RGA_FUNC_RETURN) {
-                        break;
-                    }
-                    work_angle = ROTATION_MAX_NUM * ((float32_t)pos_x0 / (float32_t)(LCD_PIXEL_WIDTH));
-                }
-                /* Draw screen */
-                Swap_FrameBuffer(frmbuf_info);
-                RGA_Func_Rotation(frmbuf_info, work_angle);
-                Update_LCD_Display(frmbuf_info);
-            }
-            break;
-        case RGA_FUNC_ACCELERATE:
-            int acce_frame_num = 0;
-            int animation_timing = 0;
-            float32_t work_relative_pos;
-            while (1) {
-                /* Get coordinates */
-                Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
-                if (touch_num != 0) {
-                    func_code_t func_code;
-
-                    func_code = Scan_Key(animetion_timing_key_tbl, pos_x0, pos_y0);
-                    if (func_code == RGA_FUNC_RETURN) {
-                        break;
-                    }
-                    switch (func_code) {
-                        case RGA_FUNC_ANIME_EASE:
-                            animation_timing = 0;
-                            acce_frame_num = 0;
-                            break;
-                        case RGA_FUNC_ANIME_LINEAR:
-                            animation_timing = 1;
-                            acce_frame_num = 0;
-                            break;
-                        case RGA_FUNC_ANIME_EASE_IN:
-                            animation_timing = 2;
-                            acce_frame_num = 0;
-                            break;
-                        case RGA_FUNC_ANIME_EASE_OUT:
-                            animation_timing = 3;
-                            acce_frame_num = 0;
-                            break;
-                        case RGA_FUNC_ANIME_EASE_IN_OUT:
-                            animation_timing = 4;
-                            acce_frame_num = 0;
-                            break;
-                        default:
-                            /* Do Nothing */
-                            break;
-                    }
-                }
-                work_relative_pos = acce_frame_num / (float32_t)ACCELERATE_MAX_NUM;
-                acce_frame_num++;
-                if (acce_frame_num > ACCELERATE_MAX_NUM) {
-                    acce_frame_num = 0;
-                }
-                /* Draw screen */
-                Swap_FrameBuffer(frmbuf_info);
-                RGA_Func_Accelerate(frmbuf_info, animation_timing, work_relative_pos);
-                Update_LCD_Display(frmbuf_info);
-            }
-            break;
-        default :
-            /* Do nothing */
-            break;
-    }
-}
-
-int main(void) {
-    func_code_t func_code;
-    uint8_t touch_num = 0;
-    uint32_t pos_x0 = 0;
-    uint32_t pos_y0 = 0;
-
-    memset(user_frame_buffer, 0, sizeof(user_frame_buffer));
-    memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2));
-    frame_buffer_info.buffer_address[0] = user_frame_buffer;
-    frame_buffer_info.buffer_address[1] = user_frame_buffer2;
-    frame_buffer_info.buffer_count      = 2;
-    frame_buffer_info.show_buffer_index = 0;
-    frame_buffer_info.draw_buffer_index = 0;
-    frame_buffer_info.width             = LCD_PIXEL_WIDTH;
-    frame_buffer_info.byte_per_pixel    = FRAME_BUFFER_BYTE_PER_PIXEL;
-    frame_buffer_info.stride            = LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL;
-    frame_buffer_info.height            = LCD_PIXEL_HEIGHT;
-    frame_buffer_info.pixel_format      = PIXEL_FORMAT_RGB565;
-    Init_LCD_Display(frame_buffer_info.buffer_address[0]);
-
-    /* Display Top Screen */
-    Set_RGAObject(&frame_buffer_info);
-    RGA_Func_DrawTopScreen(&frame_buffer_info);
-    Start_LCD_Display();
-
-    while (1) {
-        /* Get Coordinates */
-        Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
-        if (touch_num != 0) {
-            func_code = Scan_Key(top_screen_key_tbl, pos_x0, pos_y0);
-            if (func_code != RGA_FUNC_NON) {
-                /* Wait key off */
-                while (1) {
-                    Get_Coordinates(&touch_num, &pos_x0, &pos_y0);
-                    if (touch_num == 0) {
-                        break;
-                    }
-                    Thread::wait(50);
-                }
-
-                /* Execute RGA functions */
-                Exe_RGA_Func(func_code, &frame_buffer_info);
-
-                /* Return Top Screen */
-                Swap_FrameBuffer(&frame_buffer_info);
-                RGA_Func_DrawTopScreen(&frame_buffer_info);
-                Update_LCD_Display(&frame_buffer_info);
-            }
-        }
-        Thread::wait(100);
-    }
-}