Hello World for RGA(Renesas Graphics Architecture) for the GR-PEACH 4.3 inch LCD Shield. RGA is the Graphics Library of RZ/A1. 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 LCD_shield_config R_BSP

Fork of RGA_HelloWorld by Renesas

Note

For a sample program of with GR-PEACH 7.1 inch LCD Shield, please refer to RGA_HelloWorld.

GR-PEACH 7.1 inch LCD Shield用のサンプルプログラムについては、 RGA_HelloWorldを参照ください。

License

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

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

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

Trouble shooting

There is a problem with Exporter currently, the compilation fails if you export to DS-5 or e2 studio.
The compilation successes if you export with GCC (ARM Embedded) or import it with mbed CLI.
Please refer to the below link for workaround.
Compilation fails after Export to DS-5 or e2 studio


現在Exporterで問題があり、DS-5又はe2 studioにExportするとコンパイルが失敗します。
GCC(ARM Embedded)でExportするか、mbed CLIでimportすればコンパイルは成功します。
回避策は以下のリンクを参照下さい。
Compilation fails after Export to DS-5 or e2 studio

Information

Japanese version is available in lower part of this page.

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

What is this ?

RGA(Renesas Graphics Architecture) sample program using GR-PEACH.
The following lists features of the RGA.

  • Allows high-speed drawing using the hardware acceleration.
  • The API created based on the W3C standard HTML Canvas 2D Context achieves easy learning.
    In addition, the RGA provides C++API that is operable as an interface that is backward compatible with HTML Canvas 2D Context.
  • The memory area was defined by the application is available as a drawing destination or for input images.
  • Allows drawing of translucent images and translucent drawing using an alpha mask.

Please refer to the following link about RGA.
https://www.renesas.com/en-us/software/D3018075.html
This sample program draws in the frame buffer by using the buffer drawing mode of RGA.
In addition, supporting compiler is ARMCC, GCC ARM and IAR.

Composition

GR-PEACH and 4.3 inch LCD Shield.

/media/uploads/dkato/peach_and_4.3inch.jpg

How to use

  1. Please connect GR-PEACH and LCD Shield. Then turn on the power to GR-PEACH.
  2. Please press the reset button of GR-PEACH.
  3. The top screen which "RGA Library Sample" is drawn is displayed on the LCD.
    /media/uploads/1050186/rga_sample_top.jpg
  4. There are seven touch buttons at the bottom of the top screen.When you press each button, the function of RGA that have been linked to the panel is executed, and the output image will be displayed on the LCD.
    Please refer to the "Drawing using the RGA" below about the function of RGA that have been linked to the panel.
  5. When RGA of the execution is completed, "Return Top Screen" button displaies at the top right of the screen. When you press it, the top screen is displayed.

Drawing using the RGA

Touch ButtonDiscriptions
Drawing of RectangleDrawing the rectangle.
The sample program draws a rectangle in the range that you swaipe on the LCD.
/media/uploads/1050186/drawing_of_rectangle3.jpg
Drawing of ImageDraw the image.
The sample program draws by overlapping the two images(flower and crystal image).
In addition, the sample program draws a picture of Crystal to the swipe position on the LCD.
/media/uploads/1050186/drawing_of_image.jpg
DissolutionDissolve by carry out the fade-in and the fade-out at the same time.
The sample program draws by overlapping the two images. And the sample program draws while changing the transparency of the two images by the swipe operation of sideways on the LCD.
/media/uploads/1050186/dissolution4.jpg
ScrollScroll the image.
The sample program draws while shifting the position of cutting out of the rendering source by the swipe operation of sideways on the LCD while fixing the display position of the drawing destination.
/media/uploads/1050186/scroll3.jpg
ZoomZoom the image.
The sample program draws while changing the size of cutting out of the rendering source by the swipe operation of sideways on the LCD while fixing the display position of the drawing destination.
/media/uploads/1050186/zoom3.jpg
RotationRotate the image.
The sample draws the image while changing the tilt by the swipe operation of sideways on the LCD.
/media/uploads/1050186/rotation4.jpg
AccelerationMovement of the image along with the acceleration.
The sample program draws while moving the image from right to left along with the acceleration.
You can select the type of the following acceleration in LCD touch operation.
- ease ...... Move smoothly the start and the end (default)
- linear ...... Move constant speed
- ease-in ...... Move slowly the start
- ease-out ...... Move slowly the end
- ease-in-out ...... Move slowly the start and the end
/media/uploads/1050186/acceleration3.jpg

About image to be drawn

Image files that are used in the sample program is easily possible replacement by using the "Convert Image to Binary Table" tool below.
This tool generates "BinaryImage_RZ_A1H.c" and "BinaryImage_RZ_A1H.h" in the Images folder and converts each image file to binary. Then, this tool outputs the data to "RGA_Sample_BinaryImage" table of "BinaryImage_RZ_A1H.c" and defines the macro name indicating the offset position in the table to "BinaryImage_RZ_A1H.h".
The sample program executes with reference to this macro name for offset.

Convert Image to Binary Table

File Description

Folder and FileDiscriptions
Images folder
BinaryImage_RZ_A1H.c[Output File]
Source file which binary table is generated
BinaryImage_RZ_A1H.h[Output File]Header file which macro name for the offset is defined
BinaryImageConfigRGAH.image.xmlSetting file
*.jpg, *.png, *.bmp[Input File]
Image files for drawing
scriptlib folder
Files omittedCommand files called from a script
RGA_Tools.vbsScript file
BinaryImageMakeRGAH.batExecute file

How to use

  1. Please download the "Convert Image to Binary Table" tool and unzip it.
  2. Please put the image file to the Images folder and edit "BinaryImageConfigRGAH.image.xml".
  3. Please execute "BinaryImageMakeRGAH.bat". Then, "BinaryImage_RZ_A1H.c" and "BinaryImage_RZ_A1H.h" is generated.
  4. Please replace "BinaryImage_RZ_A1H.c" and "BinaryImage_RZ_A1H.h" in your program to the generated files.
  5. If necessary, please change macro name for the offset that is referenced in your program.
  6. Please build your program


概要

GR-PEACHを使ったRGA(ルネサスグラフィックスライブラリ)サンプルプログラムです。
RGAの特徴は以下の通りです。

  • ハードウェア アクセラレーションを使って高速に描画
  • W3C 標準である HTML Canvas 2D Context をベースに作成した API のため、学習が容易。
    また HTML Canvas 2D Context の下位互換として動作できる C++API を提供
  • アプリケーション側で用意したメモリー領域を描画先、または、入力画像として使用可能
  • 半透明な画像の描画と、アルファマスクを使った任意の形状の描画

RGAの詳細については、以下を参照下さい。
https://www.renesas.com/ja-jp/software/D3018074.html
本サンプルプログラムでは、RGAのバッファー描画モードを使ってフレームバッファに描画しています。
なお、対応するコンパイラはARMCC、GCC ARM、IARです。

構成

GR-PEACH、4.3 inch LCDシールド
/media/uploads/dkato/peach_and_4.3inch.jpg

使い方

  1. GR-PEACHとLCDシールドを接続し、GR-PEACHに電源を入れます。
  2. GR-PEACHのリセットボタンを押します。
  3. "RGA Library Sample"というトップ画面がLCDに表示されます。
    /media/uploads/1050186/rga_sample_top.jpg
  4. 画面下に7個のタッチボタンがあり、それぞれを押すと、各パネルに紐付けられたRGAの機能が実行され、その出力画像がLCDに表示されます。
    パネルに紐付けられたRGAの機能については、下記"RGAを使った描画"を参照下さい。
  5. RGA機能の実行が終わると、画面右上に"Return Top Screen"のボタンが表示されますので、押すとトップ画面に戻ります。

RGAを使った描画

タッチボタン説明
Drawing of Rectangle四角形の描画を行ないます。
サンプルでは、LCD上をスワイプさせた範囲に四角形を描画します。
/media/uploads/1050186/drawing_of_rectangle3.jpg
Drawing of Image画像を描画を行ないます。
サンプルでは、2つの画像(花とクリスタルの画像)を重ねて描画します。
LCD上をスワイプした位置にクリスタルの画像を描画します。
/media/uploads/1050186/drawing_of_image.jpg
Dissolutionフェードインとフェードアウトを同時に行うことでディゾルブを行ないます。
サンプルでは、2つの画像を重ねて表示して、LCD上の横方向のスワイプ操作によって2つの画像の透明度を変化させながら描画します。
/media/uploads/1050186/dissolution4.jpg
Scroll画像のスクロールを行ないます。
サンプルでは、描画先の表示位置は固定のまま、LCD上の横方向のスワイプ操作によって描画元の取り出す位置をずらしながら描画します。
/media/uploads/1050186/scroll3.jpg
Zoom画像のズームを行ないます。
サンプルでは、描画先の表示位置は固定のまま、LCD上の横方向のスワイプ操作によって描画元の取り出すサイズを変化させながら描画します。
/media/uploads/1050186/zoom3.jpg
Rotation画像の回転を行ないます。
サンプルでは、LCD上の横方向のスワイプ操作によって傾きを変化させながら画像を描画します。
/media/uploads/1050186/rotation4.jpg
Acceleration加速を伴って画像の移動を行ないます。
サンプルでは、加速を伴って、画像を右から左に移動させながら描画します。
LCDのタッチ操作で以下の加速の種類を選択できます。
- ease …… 開始と終了が滑らかに動く(デフォルト)
- linear …… 一定の速度
- ease-in …… 開始がゆっくり動く
- ease-out …… 終了がゆっくり動く
- ease-in-out …… 開始と終了がゆっくり動く
/media/uploads/1050186/acceleration3.jpg

描画する画像について

サンプルプログラムで使用している画像ファイルは、下記の"Convert Image to Binary Table"ツールを利用する事で、簡単に差し替えが可能です。
このツールは、Imagesフォルダ内にBinaryImage_RZ_A1H.c ファイルと BinaryImage_RZ_A1H.h ファイルを生成し、各画像ファイルをバイナリ変換します。そして、そのデータをBinaryImage_RZ_A1H.c ファイルのRGA_Sample_BinaryImageテーブルに出力し、BinaryImage_RZ_A1H.h ファイルにテーブル内のオフセット位置を示すマクロ名を定義します。
サンプルプログラムでは、オフセット用のマクロ名を参照して動作します。

Convert Image to Binary Table

ファイル説明

フォルダ、ファイル説明
Imagesフォルダ
BinaryImage_RZ_A1H.c[出力ファイル]
バイナリテーブルが生成されるソースファイル
BinaryImage_RZ_A1H.h[出力ファイル]
オフセット用のマクロ名が定義されるヘッダファイル
BinaryImageConfigRGAH.image.xml設定ファイル
*.jpg, *.png, *.bmp[入力ファイル]
描画用の画像ファイル
scriptlibフォルダ
・・・ファイル省略・・・スクリプトから呼ばれるコマンドファイル
RGA_Tools.vbsスクリプトファイル
BinaryImageMakeRGAH.bat実行ファイル

使い方

  1. "Convert Image to Binary Table"ツールをダウンロードして解凍します
  2. Imagesフォルダ内に画像ファイルを入れ、BinaryImageConfigRGAH.image.xmlを編集します
  3. BinaryImageMakeRGAH.batを実行し、BinaryImage_RZ_A1H.cとBinaryImage_RZ_A1H.hを生成します
  4. 生成されたファイルをプログラム内のBinaryImage_RZ_A1H.cとBinaryImage_RZ_A1H.hと置き換えます
  5. 必要であれば、プログラム内で参照しているオフセット用のマクロ名を変更します
  6. プログラムをビルドします

main.cpp

Committer:
1050186
Date:
2016-11-10
Revision:
6:608c35ed73bb
Parent:
5:a7bb6e1d6e13
Child:
7:170f8b6e0421

File content as of revision 6:608c35ed73bb:

/*
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 "DisplayBace.h"
#include "rtos.h"
#include "LCD_shield_config_4_3inch.h"

#define GRAPHICS_FORMAT                     (DisplayBase::GRAPHICS_FORMAT_RGB565)
#define WR_RD_WRSWA                         (DisplayBase::WR_RD_WRSWA_32_16BIT)
#define TOUCH_NUM                           (1u)

/* 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)

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;

DigitalOut  lcd_pwon(P7_15);
DigitalOut  lcd_blon(P8_1);
PwmOut      lcd_cntrst(P8_15);
DisplayBase Display;

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;

#if defined(__ICCARM__)
#pragma data_alignment=32
static uint8_t user_frame_buffer1[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT];
static uint8_t user_frame_buffer2[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT];
#pragma data_alignment=4
#else
static uint8_t user_frame_buffer1[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 */
#endif
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                 */
    {    30,    194,     72,     31,    RGA_FUNC_DRAW_RECTANGLE    },  /* RGA Func1 */
    {   138,    194,     72,     31,    RGA_FUNC_DRAW_IMAGE        },  /* RGA Func2 */
    {   246,    194,     72,     31,    RGA_FUNC_DISSOLVE          },  /* RGA Func3 */
    {    30,    236,     72,     31,    RGA_FUNC_SCROLL            },  /* RGA Func4 */
    {   138,    236,     72,     31,    RGA_FUNC_ZOOM              },  /* RGA Func5 */
    {   246,    236,     72,     31,    RGA_FUNC_ROTATION          },  /* RGA Func6 */
    {   369,    236,     72,     31,    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                 */
    {   384,      6,     90,     50,    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                 */
    {   384,      6,     90,     50,    RGA_FUNC_RETURN            },  /* Return Top Screen */
    {    10,    207,     81,     30,    RGA_FUNC_ANIME_EASE        },  /* ease */
    {   103,    207,     81,     30,    RGA_FUNC_ANIME_LINEAR      },  /* linear */
    {   198,    207,     81,     30,    RGA_FUNC_ANIME_EASE_IN     },  /* ease-in */
    {   292,    207,     81,     30,    RGA_FUNC_ANIME_EASE_OUT    },  /* ease-out */
    {   386,    207,     81,     30,    RGA_FUNC_ANIME_EASE_IN_OUT },  /* ease-in-out */
    {     0,      0,      0,      0,    RGA_FUNC_END               }   /* table end */
};

/****** LCD ******/
static void IntCallbackFunc_LoVsync(DisplayBase::int_type_t int_type) {
    /* Interrupt callback function for Vsync interruption */
    if (vsync_count > 0) {
        vsync_count--;
    }
}

static void Wait_Vsync(const int32_t wait_count) {
    /* Wait for the specified number of times Vsync occurs */
    vsync_count = wait_count;
    while (vsync_count > 0) {
        /* Do nothing */
    }
}

static void Init_LCD_Display(void) {
    DisplayBase::graphics_error_t error;
    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;

    Display.Graphics_Lvds_Port_Init(lvds_pin, 8);

    /* Graphics initialization process */
    lcd_config = LcdCfgTbl_LCD_shield;
    error = Display.Graphics_init(&lcd_config);
    if (error != DisplayBase::GRAPHICS_OK) {
        printf("Line %d, error %d\n", __LINE__, error);
        mbed_die();
    }

    /* Interrupt callback function setting (Vsync signal output from scaler 0) */
    error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_LoVsync);
    if (error != DisplayBase::GRAPHICS_OK) {
        printf("Line %d, error %d\n", __LINE__, error);
        mbed_die();
    }
}

static void Start_LCD_Display(uint8_t * p_buf) {
    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 *)p_buf,
        FRAME_BUFFER_STRIDE,
        GRAPHICS_FORMAT,
        WR_RD_WRSWA,
        &rect
    );
    Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_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 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;
    }
}

/****** Touch ******/
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;
}

/****** Efect ******/
static void Exe_RGA_Func(func_code_t func_name, frame_buffer_t* frmbuf_info, TouckKey_LCD_shield * p_touch) {
    uint8_t touch_num = 0;
    TouchKey::touch_pos_t touch_pos[TOUCH_NUM];

    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 */
                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                if (touch_num != 0) {
                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == 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 = touch_pos[0].x;
                        y_0 = touch_pos[0].y;
                    }
                    if (x_0 < touch_pos[0].x) {
                        pos_tbl[color_cnt].x = x_0;
                        pos_tbl[color_cnt].w = touch_pos[0].x - x_0;
                    } else {
                        pos_tbl[color_cnt].x = touch_pos[0].x;
                        pos_tbl[color_cnt].w = x_0 - touch_pos[0].x;
                    }
                    if (y_0 < touch_pos[0].y) {
                        pos_tbl[color_cnt].y = y_0;
                        pos_tbl[color_cnt].h = touch_pos[0].y - y_0;
                    } else {
                        pos_tbl[color_cnt].y = touch_pos[0].y;
                        pos_tbl[color_cnt].h = y_0 - touch_pos[0].y;
                    }
                } 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 */
                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                if (touch_num != 0) {
                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                        break;
                    }
                    center_pos_x = touch_pos[0].x;
                    center_pos_y = touch_pos[0].y;
                }
                /* 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 */
                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                if (touch_num != 0) {
                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                        break;
                    }
                    work_alpha = (float32_t)touch_pos[0].x / (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 */
                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                if (touch_num != 0) {
                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                        break;
                    }
                    work_width_pos = SCROLL_MAX_NUM * ((float32_t)touch_pos[0].x / (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 */
                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                if (touch_num != 0) {
                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                        break;
                    }
                    work_height_pos = ZOOM_MAX_NUM * ((float32_t)touch_pos[0].x / (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 */
                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                if (touch_num != 0) {
                    if (Scan_Key(return_key_tbl, touch_pos[0].x, touch_pos[0].y) == RGA_FUNC_RETURN) {
                        break;
                    }
                    work_angle = ROTATION_MAX_NUM * ((float32_t)touch_pos[0].x / (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 */
                touch_num = p_touch->GetCoordinates(TOUCH_NUM, touch_pos);
                if (touch_num != 0) {
                    func_code_t func_code;

                    func_code = Scan_Key(animetion_timing_key_tbl, touch_pos[0].x, touch_pos[0].y);
                    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;
    TouchKey::touch_pos_t touch_pos[TOUCH_NUM];

    /* Initialization of LCD */
    Init_LCD_Display();    /* When using LCD, please call before than Init_Video(). */

    memset(user_frame_buffer1, 0, sizeof(user_frame_buffer1));
    memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2));
    frame_buffer_info.buffer_address[0] = user_frame_buffer1;
    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;

    /* Display Top Screen */
    Set_RGAObject(&frame_buffer_info);
    RGA_Func_DrawTopScreen(&frame_buffer_info);

    /* Start of LCD */
    Start_LCD_Display(frame_buffer_info.buffer_address[0]);

    /* Backlight on */
    Thread::wait(200);
    lcd_cntrst.write(1.0);

    /* Reset touch IC */
    TouckKey_LCD_shield touch(P4_0, P2_13, I2C_SDA, I2C_SCL);
    touch.Reset();

    while (1) {
        /* Get Coordinates */
        touch_num = touch.GetCoordinates(TOUCH_NUM, touch_pos);
        if (touch_num != 0) {
            func_code = Scan_Key(top_screen_key_tbl, touch_pos[0].x, touch_pos[0].y);
            if (func_code != RGA_FUNC_NON) {
                /* Wait key off */
                while (1) {
                    touch_num = touch.GetCoordinates(TOUCH_NUM, touch_pos);
                    if (touch_num == 0) {
                        break;
                    }
                    Thread::wait(20);
                }

                /* Execute RGA functions */
                Exe_RGA_Func(func_code, &frame_buffer_info, &touch);

                /* Return Top Screen */
                Swap_FrameBuffer(&frame_buffer_info);
                RGA_Func_DrawTopScreen(&frame_buffer_info);
                Update_LCD_Display(&frame_buffer_info);
            }
        }
        Thread::wait(20);
    }
}