Rockchip · AI & Linux Hub

表示と音声

RockchipLinux LVGLとOpenGL(ES)ギャラリー

RockchipLinux LVGLとOpenGL(ES)ギャラリー — V1.2.1

供給された中国および英国のRockchipの源に基づくArmSoMのプラットホームの参照。 実際のボード、SOC、SDK/BSP、カーネル、周辺機器を個別にマッチさせる。これは、ArmSoMボードの全てのサポートを要求しません。 ソース例と測定はArmSoMテストではありません。 コマンドやハードウェアテストは実行されません。

ビルドルートLVGL 8.4.x / 9.1.xとRockchiplv_gl拡張子をカバー。例には、意図的なソースの省略が含まれています。

V1.2.1 と、すべての 7 章、API パラメータ、バージョン-9 lv_drivers は、フットノートを保持するマージします。 ZHは13の中国源図を使用します。EN/RU/DEは13の英語資源図を使用します。 意図的にコードを省略し、コンパイル可能なプログラムが完成していないアニメーションの例。 ソースは、透明性と可視性用語を混合します。 意味/キャビアットは、コードを変更することなく注釈付けされます。

OS バージョン
ビルドルート 8.4.x
ビルドルート 9.1.x

1. . LVGLの紹介 {#1-lvgl-introduction}

LVGLは、MCU、MPU、ディスプレイタイプに最適なUIを作成するために、最も人気のフリーでオープンソースの組み込みグラフィックライブラリです。 LVGLは完全にオープンソースであり、外部の依存関係がないので、ポートングは非常にシンプルです。 あらゆる現代MCUかMPUによって働き、ePaper、モノクロ、OLEDおよびTFTの表示を運転するあらゆる(RT)OSかベア・メタルの組み立てとそしてモニター使用することができます。

2. . LVGLソースコード {#2-lvgl-source-code}

Linux SDK では、LVGL は 3 つのリポジトリ、すなわち lvgl、lv_drivers 1 および lvgl_demo を持っています。 lvglはフレームワークのソースリポジトリです。 lv_driversは、DRM、sdl、ウェイランドなどのいくつかの表示APIが含まれています。 lvgl_demoには、Rockchip開発者からいくつかのデモが含まれているので、基本的な初期化方法やLVGLからデモを呼び出す方法を紹介します。 lvglとlv_driversソースコードはgithubからダウンロードされ、Rockchip開発者からパッチを当てるので、ビルドルート/パッケージ/lvgl/lvgl/lvgl/からパッチが確認でき、root/package/lvgl/lv_drivers/ ビルドできます。 lvgl_demoソースコードは<SDK>/app/lvgl_demoにあります。

3. . LVGL の設定 {#3-lvgl-configurations}

LVGL レンダリングのバックエンドはオプションです。 現在、DRM、SDL、RKADK を直接表示するイメージをレンダリングすることを選択できます。 DRM の設定は、RK3308 などの GPU や RGA なしで一部のプラットフォームで使用されます。 SDL の設定は、RK3568 などの GPU で利用しています。 RKADK の設定は GPU または RGA のプラットフォームで使用されます。

3.1 構成ファイル {#31-configuration-files}

基本構成ファイルは、<SDK>/buildroot/configs/rockchip/gui/lvgl/に保存されます。

<SDK>/buildroot/configs/rockchip/gui/lvgl/
├── lvgl_drm.config         # symlink to V8
├── lvgl_rkadk.config       # symlink to V8
├── lvgl_sdl.config         # symlink to V8
├── music.config            # Music DEMO from LVGL team
├── rk_demo.config          # DEMO from Rockchip team
├── v8                      # configurations for LVGL V8
│   ├── base.config         # basic configurations for LVGL
│   ├── lvgl_drm.config     # DRM configurations
│   ├── lvgl_rkadk.config   # RKADK configurations
│   └── lvgl_sdl.config     # SDL configurations
├── v9                      # configurations for LVGL V9
│   ├── base.config
│   ├── lvgl_drm.config
│   ├── lvgl_rkadk.config
│   └── lvgl_sdl.config
└── widgets.config          # Widgets DEMO from LVGL team

3.2 設定ファイルの使用 {#32-configuration-files-usage}

defconfig に LVGL 設定ファイルを含める:

$ cat buildroot/configs/rockchip_rk3308_bs_32_ia_release_defconfig | grep lvgl
# select a backend
#include "gui/lvgl/lvgl_drm.config"
# select a demo
#include "gui/lvgl/rk_demo.config"

3.3 SDL の外部構成 {#33-external-configurations-for-sdl}

SDL の設定を使用する場合は、SDL のバックエンドを選択する必要があります。

BR2_PACKAGE_SDL2=y
BR2_PACKAGE_SDL2_OPENGLES=y
# Use wayland backend. Depends on your environment
BR2_PACKAGE_SDL2_WAYLAND=y

追加するOpenGL(ES) APIが必要な場合は、この設定を有効にします。

BR2_PACKAGE_LV_DRIVERS_USE_OPENGL=y

4. . LVGLコンパイラ {#4-lvgl-complie}

cd buildroot
source envsetup.sh
# choose your board defconfig
# Compile these three package in version 8
make lvgl lv_drivers lvgl_demo -j20
# Compile these two package in version 9
make lvgl lvgl_demo -j20

メニュー設定でLVGLの設定を変更した場合は、予期しないエラーを回避するために、3つのリポジトリをすべて再コンパイルすることをお勧めします。

cd buildroot
# Compile these three package in version 8
make lvgl-reconfigure lv_drivers-reconfigure lvgl_demo-reconfigure -j20
# Compile these two package in version 9
make lvgl-reconfigure lvgl_demo-reconfigure -j20

5. .. LVGL_DEMOのソースコード {#5-lvgl_demo-source-code}

パスは<SDK>/app/lvgl_demo/です。

5.1 ディレクトリ構造 {#51-directory-structure}

app/lvgl_demo/
├── cJSON   # cJSON source code
├── common  # common widgets
├── gallery # gallery application
├── lv_demo # basic demos
├── lvgl8   # API porting for V8
├── lvgl9   # API porting for V9
├── rk_demo
│   ├── asr                 # ASR function
│   ├── furniture_control
│   ├── home                # home page
│   ├── include             # head files
│   ├── intercom_homepage
│   │   ├── intercom_call
│   │   └── video_monitor
│   ├── layout              # layout widgets
│   ├── resource            # pictures, fonts
│   ├── rockit              # rockit adaptions
│   ├── setting             # system setting page
│   ├── smart_home
│   └── wifibt              # rkwifibt adaptions
├── sys     # timestamp, cpu information, soc information, etc.
└── tools   # coding style formater

5.2 lv_demoソースコード {#52-lv_demo-source-code}

パスは<SDK>/app/lvgl_demo/lv_demoです。 主に、公式 DEMO の実行方法を示すサンプルプログラムとして使用されます。 次の手順は、いくつかの関連性の高いコードをスキップし、説明のための注意が必要なコードのみを選択します。

/* <SDK>/app/lvgl_demo/lv_demo/main.c */
...
int main(int argc, char **argv)
{
    lv_port_init();

    /* DEMO UI initialization */
#if LV_USE_DEMO_WIDGETS
    lv_demo_widgets();
#elif LV_USE_DEMO_BENCHMARK
    lv_demo_benchmark();
#elif LV_USE_DEMO_MUSIC
    lv_demo_music();
#endif
    while (!quit)
    {
        /* call the task handler, all events, rendering,
         * display will be done in this function
         */
        lv_task_handler();
        usleep(100);
    }

    return 0;
}
/* <SDK>/app/lvgl_demo/lvgl8/lv_port_init.c */
/* touch screen rotation */
/* 0, 90, 180, 270 */
static int g_indev_rotation = 0;
/* display rotation */
/* 0, 90, 180, 270 */
static int g_disp_rotation = 0;

void lv_port_init(void)
{
    /* Start of any LVGL applications */
    lv_init();

    /* display initialization */
    lv_port_disp_init(0, 0, g_disp_rotation);
    /* touch screen initialization */
    lv_port_indev_init(g_indev_rotation);
}
/* <SDK>/app/lvgl_demo/lvgl9/lv_port_init.c */
/* touch screen rotation */
/* 0, 90, 180, 270 */
static int g_indev_rotation = 0;
/* display rotation */
/* 0, 90, 180, 270 */
static int g_disp_rotation = 0;
/* log level */
static int log_level = LV_LOG_LEVEL_WARN;
...
void lv_port_init(void)
{
    const char *buf;

    /* Start of any LVGL applications */
    lv_init();

    /* update log level bt getenv */
    buf = getenv("LV_DEBUG");
    if (buf)
        log_level = buf[0] - '0';
    /* setting log callback */
    lv_log_register_print_cb(print_cb);
    /* setting systick callback */
    lv_tick_set_cb(lv_systick);
    /* setting delay callback */
    lv_delay_set_cb(lv_sysdelay);

    /* display initialization */
    lv_port_disp_init(0, 0, g_disp_rotation);
    /* touch screen initialization */
    lv_port_indev_init(g_indev_rotation);
}

6. .. OpenGL(ES) API の {#6-opengles-apis}

LVGL自体はOpenGL(ES)インタフェースとSDLをサポートしていないので、3Dオブジェクトをサポートしていません。 lv_glインターフェイスは、関連する機能を使用する必要があるいくつかのアプリケーションのためにカプセル化されています。そのため、LVGLアプリケーションは元のUIアプリケーションに3D画像効果をオーバーレイすることができます。

6.1 ファイル紹介 {#61-file-introduction}

lv_drivers/sdl/gl/
├── gl.c                // APIs implementation
├── gl.h                // APIs and external structure definition
├── mat.c               // Matrix function implementation
├── mat.h               // Matrix function definition
└── shaders             // OpenGL shaders
    ├── bgra_cube.frag  // BGRA cube fragment shader
    ├── bgra.frag       // BGRA 2D picture fragment shader
    ├── common.vert     // common vertex shader
    ├── cube.vert       // cube vertex shader
    ├── default.vert    // 2D picture vertex shader
    ├── rgba_cube.frag  // RGBA cube fragment shader
    └── rgba.frag       // RGBA 2D picture fragment shader

6.2 導入事例 {#62-enumerate-introduction}

6.2.1 カラーフォーマット {#621-color-format}

LV_GL_FMT_RGBAとLV_GL_FMT_BGRAをサポートしました。

enum {
    LV_GL_FMT_ALPHA,
    LV_GL_FMT_LUMINANCE,
    LV_GL_FMT_LUMINANCE_ALPHA,
    LV_GL_FMT_INTENSITY,
    LV_GL_FMT_RGB,
    LV_GL_FMT_RGBA,
    LV_GL_FMT_BGRA,
};

6.2.2 テクスチャタイプ {#622-texture-type}

enum {
    GL_TEX_TYPE_2D,
    GL_TEX_TYPE_CUBE,
};

6.2.3 立方体 {#623-cube-sides}

画像をインポートまたはレンダリングするときにターゲット表面を選択するために使用される。

enum {
    CUBE_LEFT,
    CUBE_RIGHT,
    CUBE_TOP,
    CUBE_BOTTOM,
    CUBE_FRONT,
    CUBE_BACK,
};

OpenGL では、画面の中心はオリジン(0, 0)であり、X座標は右側に正当で、Y座標は上向きであり、Z座標はスクリーンと外側に正の垂直です。 そのため、キューブが回転せずに作成されると、ユーザの向きの方向は正(CUBE_FRONT)であり、次の図に示すように、残りの方向は同様に似ています(点線は見えない部分を示しています):

英語版のソースからの技術図

6.3 構造の紹介 {#63-structure-introduction}

主に3つの構造lv_gl_img_t、lv_gl_tex_tおよびlv_gl_obj_tに焦点を合わせる適用で使用されて。 lv_gl_img_t GPUのテクスチャオブジェクトとして外部画像をインポートするために使用します。

typedef struct {
    /* the address of image */
    const void *pixels;
    /* image format */
    int format;
    /* width */
    int w;
    /* height */
    int h;
} lv_gl_img_t;

lv_gl_tex_tはGPUのテクスチャオブジェクトと関連情報を保存します。

typedef struct {
    /* width */
    int w;
    /* height */
    int h;
} lv_gl_size_t;

typedef struct {
    /* GPU texture object */
    GLuint gl_tex;
    /* GPU Frame Buffer Object */
    GLuint FBO;
    /* Texture size. For 2D textures, only the first set of sizes is valid.
     * A cube has 6 faces and 6 sets of size information. */
    lv_gl_size_t size[6];
    /* Texture format */
    int format;
    /* Object type, 2D or CUBE */
    int type;
    /* refrence count */
    int ref_cnt;
} lv_gl_tex_t;

lv_gl_obj_tは、頂点、変換パラメータなど、GPUレンダリングオブジェクトと関連情報を保存します。

typedef struct {
    float x, y, z;
} lv_gl_vec_t;

typedef struct {
    /* width */
    int w;
    /* height */
    int h;
    /* reverse y, just keep it 0 */
    int reverse_y;
    /* bound textures */
    lv_gl_tex_t *tex;
    /* rendering rectangle */
    SDL_Rect r;
    /* viewport rectangle */
    SDL_Rect view;
    /* crop rectagnle */
    SDL_Rect crop;
    /* The viewport area needs to be updated.
     * It is used internally and can be ignored by the application.
     */
    int view_dirty;
    /* The crop area needs to be updated.
     * It is used internally and can be ignored by the application.
     */
    int crop_dirty;
    /* enable crop */
    int crop_en;
} lv_gl_base_t;

typedef struct {
    lv_gl_base_t base;
    /* GPU Vertex Array Object */
    GLuint VAO;
    /* GPU Vertex Buffer Object */
    GLuint VBO;
    /* Output type, default GL_TEXTURE_2D.
     * If you need to render on a cube,
     * specify the rendered surface through this variable.
     */
    int out_type;
    /* Manually specify the coordinates of the four vertices of
     * a 2D object. The default vertex is full screen (note that
     * it is the view size of the framebuffer, not the screen size,
     * and the two may not be equal). Then set the scale, offset
     * and other attributes to perform matrix transformation.
     * You can also freely specify vertex coordinates through this attribute.
     * However, it is not recommended to use both methods together,
     * as the transformations involved are more complicated and
     * it is difficult to estimate the final effect by manual calculation.
     * The range of x, y, and z is [-1, 1]
     */
    lv_gl_vec_t p[4];
    /* Manually specify the reference range of the texture,
     * which is used when only part of the texture slice is needed.
     */
    SDL_Rect tp;

    /* global alpha */
    float alpha;
    /*
     * The order of the following transformations is:
     * pos * offset * scale * self_rot * view_rot * perspective * move
     * Calculate from left to right.
     * The perspective is the view transformation to achieve
     * the effect of near big and far small.
     */
    /* Scaling in three axes */
    lv_gl_vec_t scale;
    /* Offset in three axes */
    lv_gl_vec_t offset;
    /* Roration in three axes */
    lv_gl_vec_t self_rot;
    /* Viewport rotation in three axes */
    lv_gl_vec_t view_rot;
    /* Movements in three axes */
    lv_gl_vec_t move;
} lv_gl_obj_t;

6.4 機能紹介 {#64-function-introduction}

void lv_gl_set_render_cb(lv_gl_render_cb_t cb);

アプリケーションレイヤーレンダリングコールバックを登録します。 オブジェクトのレンダリングはコールバックでのみ実行できます。 cb: レンダーコールバックのポインタ

void lv_gl_set_fb(lv_gl_obj_t *obj);

フレームバッファ obj の設定: NULL なら、次のレンダリングは画面にレンダリングされます。 NULL でないと、次のレンダリングはこのオブジェクトのテクスチャにレンダリングされます。

void lv_gl_read_pixels(void *ptr, SDL_Rect *r, int type);

指定したフレームバッファの領域をメモリにコピーします。 ptr: 書きたいメモリ。 r: 読み込み領域。 タイプ: 読み取りタイプ、デフォルトは GL_TEXTURE_2D です。 キューブ面を読んでみたい場合は、Cube Sideの列列の列を参照して表面を選択します。

lv_gl_tex_t *lv_gl_tex_create(int type, int w, int h, lv_gl_img_t *img);

テクスチャタイプ:テクスチャタイプ、GL_TEX_TYPE_2D、GL_TEX_TYPE_CUBE w:テクスチャ幅。 imgがNULLでないと無視されます。 h: テクスチャの高さ。 img が NULL でないと無視されます。 img: インポートされたイメージは、空の場合には、GPU の対応するスペースのみに適用され(デフォルト値は 0.0)、空でないと、対応する画像も GPU にインポートされます。 テクスチャタイプがGL_TEX_TYPE_CUBEの場合、このパラメータは少なくとも6つの項目で配列に渡す必要があります。 絞り値: lv_gl_tex_t *、テクスチャのポインタ

void lv_gl_tex_del(lv_gl_tex_t *tex);

テクスチャの削除

tex:テクスチャのポインタ

void lv_gl_tex_import_img(lv_gl_tex_t *tex, lv_gl_img_t *img);

外部画像をテクスチャオブジェクトにインポートします。 tex:テクスチャのポインタ img: インポートされたイメージ。 テクスチャタイプがGL_TEX_TYPE_CUBEの場合、このパラメータは少なくとも6つの項目で配列に渡す必要があります。

void lv_gl_tex_clear(lv_gl_tex_t *tex, float r, float g, float b, float a);

テクスチャに色を塗ります。 tex: テクスチャのポインタ: 赤いチャンネル値。 g: グリーンチャネル値。 b: ブルーチャンネル値。 a: Alpahチャンネル値。

lv_gl_obj_t *lv_gl_obj_create(int w, int h);

レンダリングオブジェクトを作成します。 オブジェクトは、テクスチャオブジェクトを結合した後にのみレンダリングできます。 w: width h: height Return value: lv_gl_obj_t *、レンダーオブジェクトのポインタ

void lv_gl_obj_del(lv_gl_obj_t *obj);

レンダリングオブジェクトをデレクトします。 obj: レンダーオブジェクトのポインタ

void lv_gl_obj_resize(lv_gl_obj_t *obj, lv_gl_obj_t *parent);

レンダリングオブジェクトのサイズを変更します。 デフォルトレンダーオブジェクトはフルスクリーンなので、このインターフェイスを使用してスケールパラメータをリセットする必要があります。 このインターフェイスは、親の幅と高さではなく、計算するobjの幅と親ビューの幅と高さを使用して計算するべきだと指摘される。 obj: オブジェクトの親をレンダリングするポインタ: レンダー対象、画面のNULL。

void lv_gl_obj_move(lv_gl_obj_t *obj, lv_gl_obj_t *parent);

レンダリング対象のターゲットに応じてレンダリング位置をリセットします。 スケールとベースの値を計算します。r と親ビューの幅と高さ。 スケールの値が使用されるので、再サイズ後にこのインターフェイスを呼び出すことをお勧めします。 スケールが手動で変更された場合、このインターフェイスを再度objに呼び出すことをお勧めします。レンダー対象の親: レンダリング対象、画面のNULLです。

void lv_gl_obj_reset_points(lv_gl_obj_t *obj);

レンダリングされたオブジェクトの頂点パラメータをリセットします。これはフルスクリーン表示objを意味します:レンダーオブジェクトのポインタ

void lv_gl_obj_reset_tex_points(lv_gl_obj_t *obj);

レンダリングされたオブジェクトのテクスチャの頂点パラメータをリセットします。つまり、フルイメージ obj を使用します。レンダーオブジェクトのポインタ

void lv_gl_obj_update_vao(lv_gl_obj_t *obj);

レンダリングオブジェクトのVAOとVBOを、現在の頂点パラメータとテクスチャの頂点パラメータに従って更新します。 そのため、頂点パラメータとテクスチャの頂点パラメータが手動で変更されている場合は、このインターフェイスは効果を取るために呼び出される必要があります。 作成されていない場合、VAO と VBO が作成されます。obj: オブジェクトをレンダリングするポインタ

void lv_gl_obj_release_vao(lv_gl_obj_t *obj);

VAO と VBO を、デフォルトパラメーターでリリースします。 obj: レンダリングオブジェクトのポインタ

void lv_gl_obj_bind_tex(lv_gl_obj_t *obj, lv_gl_tex_t *tex);

テクスチャオブジェクトがバインドされると、テクスチャオブジェクトの参照カウントは1で増加します。 レンダーオブジェクトに既にバインドしたテクスチャオブジェクトがある場合、元のテクスチャオブジェクトへの参照が小さくなり、参照が0未満または等しい場合に自動的に解放されます。 そのため、このインターフェイスはメモリリリースをトリガーする可能性があることに注意する必要があります。アプリケーションは外部の参照を回避してテクスチャオブジェクトや繰り返しリリースを避ける必要があります。 obj: レンダリングオブジェクトのポインタ tex: テクスチャオブジェクトのポインタ

void lv_gl_obj_set_crop(lv_gl_obj_t *obj, SDL_Rect *r, int en);

画面の左下隅にあるクロップ範囲を、正Y方向に上向きに、プラスX方向のobjとして右下に配置します。レンダリングオブジェクトのポインタ、画面のNULLです。 r:クロップ範囲、座標とサイズを開始します。 空のとき、開始座標はオリジンにリセットされ、サイズはレンダリングされたオブジェクトのサイズにリセットされます。 en: 1 はクロップを有効にします。 0 はクロップを無効にします

void lv_gl_obj_get_crop(lv_gl_obj_t *obj, SDL_Rect *r);

作物範囲 obj: レンダリングオブジェクトのポインタ、画面の NULL を取得します。r: 戻り値を保存するポインタ。

void lv_gl_obj_set_viewport(lv_gl_obj_t *obj, SDL_Rect *r);

ビューポート範囲を設定し、画面の左下隅を右下に移動して、正Y方向に上向きに、プラスX方向のobjとして右下で設定します。レンダリングオブジェクトのポインタ、画面用のNULLです。 r:ビューポート範囲、座標とサイズを開始します。 空のとき、開始座標はオリジンにリセットされ、サイズはレンダリングされたオブジェクトのサイズにリセットされます。

void lv_gl_obj_get_viewport(lv_gl_obj_t *obj, SDL_Rect *r);

ビューポート範囲 obj: レンダリングオブジェクトのポインタ、画面の NULL を取得します。

r: 戻り値を保存するポインタ。

void lv_gl_obj_render(lv_gl_obj_t *obj);

フレームバッファのレンダーオブジェクトをレンダリングします。 レンダリングコールバックでのみ使用できます。 obj: オブジェクトのレンダリングのポインタ

アルバムやギャラリーのアプリケーションでは、スライドイン、フェードイン、キューブ回転、キューブフリップ、キューブテキストディスプレイ、ローラーイメージプレビュー、フォトストリームなど、複数のアニメーション効果を含む新しいギャラリーDEMOが追加されています。

7.1 ディレクトリ構造 {#71-directory-structure}

gallery/
├── anims                   // animations
│   ├── cube_flip.c         // cube flip
│   ├── cube_flip.h
│   ├── cube_lyric.c        // cube lyric rendering
│   ├── cube_lyric.h
│   ├── cube_rotate.c       // cube rotate
│   ├── cube_rotate.h
│   ├── fade_out.c          // picture fade out
│   ├── fade_out.h
│   ├── fade_slide_out.c    // picture slide and fade out
│   ├── fade_slide_out.h
│   ├── fold.c              // picture fold
│   ├── fold.h
│   ├── photo_stream.c      // photo stream
│   ├── photo_stream.h
│   ├── roller.c            // picture rollering preview
│   ├── roller.h
│   ├── slide_out.c         // picture slide out
│   ├── slide_out.h
│   ├── stiker.c            // picture stiker testing
│   └── stiker.h
├── CMakeLists.txt
├── gallery.c               // UI entry
├── gallery.h
├── main.c                  // application entry
├── main.h
└── pics                    // picture resources

7.2 UI エントリー紹介 {#72-ui-entry-introduction}

main.cはlv_demoソースコードと同じなので、主にUIのエントリーを紹介します。

// gallery.c

/* Define the characters in cube lyric rendering demo, two lines for one surface */
static char *lyric[]...

/* The texture objects */
lv_gl_tex_t *tex_cube;
lv_gl_tex_t *tex_2d[6];
lv_gl_tex_t *tex_roller;
lv_gl_tex_t *tex_fb;

/* The rendering objects */
lv_gl_obj_t *obj_fb;
lv_gl_obj_t *obj_img0;
lv_gl_obj_t *obj_img1;
lv_gl_obj_t *obj_cube;
lv_gl_obj_t *obj_fold[4];
lv_gl_obj_t *obj_roller_items[6];
lv_gl_obj_t *obj_roller;
/* The lyric_row array used in cube lyric rendering demo. */
lyric_row *obj_lyrics;

/* Viewport size, equal to the screen size minus the button matrix size. */
SDL_Rect view;

/* Screen size */
SDL_Rect screen;

/* Indicates whether the current animation is playing */
int animing = 0;

/* Font imported from ttf file */
lv_ft_info_t ttf_main;

/* lvgl screen object */
lv_obj_t *scr;
/* lvgl image object */
lv_obj_t *img1;
/* lvgl image object */
lv_obj_t *img2;
/* lvgl object, animation area */
lv_obj_t *anim_area;
/* lvgl button matrix object */
lv_obj_t *btn_mat;
/* lvgl slider object */
lv_obj_t *slider;
/* lvgl object, photo stream container */
lv_obj_t *photo_box;
/* lvgl image objects for photo stream */
lv_obj_t *photos[6];

/* lvgl animations */
static lv_anim_t anims[]...

/* label texts for button matrix */
static const char *btnm_map[]...

/* event callback of button matrix */
static void event_handler(lv_event_t * e)

/* font initialization */
static void font_init(void)

/* create canvas, rendering texts to pictures */
static label_canvas *create_canvas(lv_color_t color, lv_font_t *font)

/* rendering texts to pictures and import to a GPU texture object */
static lv_gl_obj_t *utf8_to_obj(lv_gl_obj_t *parent, label_canvas *lc, char *text)

/* common animation start callback */
void common_anim_start(void)

/* texture object initialization */
static void tex_init(void)

/* UI entry */
void gallery(void)
// gallery.h
typedef struct
{
    /* Specify the text font and color */
    lv_draw_label_dsc_t label_dsc;
    /* buffer for canvas */
    lv_img_dsc_t *img_dsc;
    /* lvgl canvas object */
    lv_obj_t *canvas;
} label_canvas;

typedef struct {
    /* GPU rendering object */
    lv_gl_obj_t **objs;
    /* charactor length */
    int len;
} lyric_row;

7.3 アニメーション {#73-animations}

lv_gl はレンダーを自動トリガーできないため、アニメーションコールバックで LVGL フレームワークレンディングプロセスをトリガーする必要があります。 現在、lv_obj_invalidate(lv_layer_top()は全てのアニメーションコールバックでレンダリングをトリガーするために使用されます。 同時に、トップレイヤーは子オブジェクトを持たないため、通常のレンダリング性能には影響しません。

7.3.1 キューブフリップ {#731-cube-flip}

アニメーション説明 2枚の写真はキューブを回転させることで切り替わり、回転中にキューブが適切に減少します。

英語版のソースからの技術図

X軸を回転させることで、このアニメーションをよりよく観察できます。

英語版のソースからの技術図

コード紹介

 /* anims/cube_flip.c */
/*
 * Define three additional sub-animations.
 * The application divides the complete animation into 4 steps, each rotating 90 degrees
 * The first animation is defined in anims/cube_flip.h, from 0 degrees to 90 degrees
 * The first sub-animation rotates from 90 degrees to 180 degrees
 * The second sub-animation goes from 180 degrees to 270 degrees
 * The third sub-animation goes from 270 degrees to 360 degrees
 * Each sub-animation has act_time = -1000 set to achieve a 1s interval
 * between each action
 */
static lv_anim_t sub_anims[]...
/* Set viewport for all cube animations */
SDL_Rect cube_view;
/* Set the zoom effect according to the current animation progress */
#define ZOOM_IN ...
/* Cube animation rendering callback, for all cube animations */
void anim_cube_render(void)
/*
 * Cube animation start callback, for all cube animations
 * Modify the view to a specific value in the start callback,
 * First, take the side with smaller width and height in the default view
 * for example, if the width is smaller than the height, take the width.
 * And divide this value by 0.57 and plus 2 as the width and height of the new view
 * (the view needs to be square, otherwise subsequent transformations may be abnormal).
 * Since the distance from the center of the cube to any corner is d=sqrt(3)/2*a
 * a is the side length and is equal to 2.0 (the coordinate system is
 * [-1, -1, -1]-[1, 1, 1])
 * Therefore, in order to ensure that no matter how the cube is rotated,
 * any corner will not exceed the coordinate system, that is,
 * d should always be less than 1.0.
 * Then choose a scaling factor of 0.57. sqrt(3)/2*a*0.57=0.9873
 * plus 2 is just an empirical value, which ensures that the cube slightly exceeds the
 * screen and leaves no gaps on the left and right.
 * It can be removed according to actual application conditions
 */
void anim_cube_start(lv_anim_t *a)
/* Start callback */
void anim_cube_flip_start(lv_anim_t *a)
/* Animation callback, set the Y-axis rotation angle and scaling ratio
 * according to the current animation progress
 */
void anim_cube_flip(void *var, int32_t v)
/* End callback, determine the current animation segment according to
 * the value of a->var, and execute the next animation segment or end it
 */
void anim_cube_flip_end(lv_anim_t *a)

7.3.2 立方体回転 {#732-cube-rotation}

アニメーション 記述 すべての表面の回転およびショーのイメージ。

英語版のソースからの技術図

コード紹介

/* anims/cube_rotate.c */
/* start callback, just call anim_cube_start */
void anim_cube_rotate_start(lv_anim_t *a)
/* Animation callback, set the scale to 0.57 (see the previous section for the reason),
 * and set the rotation angle of the X and Y axes according to the animation progress */
void anim_cube_rotate(void *var, int32_t v)
/* End callback, restore animation flag, and restore progress bar */
void anim_cube_rotate_end(lv_anim_t *a)

7.3.3 キューブの歌詞レンダリング {#733-cube-lyric-rendering}

アニメーションの記述

キューブを回転させ、シーケンスの立方体の6面を表示し、現在表示されている表面に文字を描画します。 歌詞でキャラクターを交換して、音楽と組み合わせて3Dの歌詞表示を達成することができます。

英語版のソースからの技術図

コード紹介

/* anims/cube_lyric.c */
/*
 * Define two additional sub-animations. In the application, each rotation and
 * each line of text rendering is divided into sub-animations to complete.
 * The animation starts from the left, and the main animation completes the two
 * lines of drawing on the left.
 * After the main animation is completed, enable the first rotation sub-animation,
 * rotating from left to right
 * After the rotation is completed, enable the first rendering sub-animation and
 * complete the drawing of the two lines on the right surface.
 * After drawing is completed, enable the second rotation sub-animation,
 * and repeat this cycle until all 6 surfaces are drawn.
 */
static lv_anim_t sub_anims[]...
/* Indicates the number of characters in the current line being drawn. */
static int line;
static int row;
static int col;
/*
 * The rendering callback is different from the ordinary cube.
 * It has an extra step of drawing on the cube, so it has an independent callback.
 * In this callback:
 * The first step is to set the cube as a framebuffer, which means that all
 * subsequent rendering will be drawn onto the cube.
 * The second step is to draw the current character
 * The third step is to reset the framebuffer, which means that subsequent rendering
 * is directly displayed on the screen
 * The fourth step is to render the cube to the screen
 */
void anim_cube_lyric_render(void)
/*
 * The starting callback first calls the cube general starting callback and
 * sets the rendering callback to anim_cube_lyric_render
 * Then rotate the cube to the left to facilitate subsequent animation
 */
void anim_cube_lyric_start(lv_anim_t *a)
/* Draw animation callback, update character index according to current progress,
 * trigger rendering */
void anim_cube_lyric(void *var, int32_t v)
/* Rotation animation callback, rotate the cube to the appropriate face according
 * to the current progress */
void anim_cube_lyric_sub(void *var, int32_t v)
/* The rotation animation ends callback. According to the length of the next line
 * of text, the drawing animation duration is updated (calculated as 300ms per word)
 * and the drawing animation is started.*/
void anim_cube_lyric_sub_end(lv_anim_t *a)
/*
 * Callback when the animation ends. The number of lines increases by one each time
 * the animation is finished.
 * If the number of lines is an odd number, it means that there is still one line that
 * has not been displayed. According to the length of the next line of text,
 * the duration of the drawing animation is updated (calculated at 300ms per word),
 * and the drawing animation is started.
 * If the number of rows is even, it means that the current page has been drawn,
 * than start the rotation animation.
 * If all 12 lines are drawn, end the animation
 * The DEMO has 12 rows in total, 2 rows per page. If you plan for other numbers of
rows,
 * the logic will be different.
 */
void anim_cube_lyric_end(lv_anim_t *a)

7.3.4 映像の折目 {#734-picture-fold}

アニメーション 説明 最初の画像は、内側と外側に展開し、第二の画像は2つの部分に分割され、画面外から内側に移動します。

英語版のソースからの技術図

コード紹介

/* anims/fold.c */
/* Rendering callback.
 * The application divides the two images into four parts (each is divided into two
 * parts, left and right), so four rendering calls are made in the rendering callback.
*/
static void anim_fold_render(void)
/*
 * Start callback
 * 1 Set the view to 480x480 (picture size, optional, adjust according to
 *   actual situation)
 * 2 Reset the scale parameters of the 4 render objects according to the new view
 * 3 Divide the image into 4 parts, obj_fold[0] is the left half of image 1,
 *   obj_fold[1] is the right half of image 1, and so on.
 * 4 Set the render callback
 */
void anim_fold_start(lv_anim_t *a)
/*
 * Animation callbacks
 * The requirement for using rotation transformation is relatively complex,
 * because the rotation axis is constantly changing, and the rotation angle needs to be
 * inferred based on the offset value. Therefore, it is achieved by directly setting the
 * vertex coordinates. It only needs to continuously update the X-axis coordinates of
 * each vertex of the four objects in the animation callback. The two points on the
right
 * of obj_fold[0] and the two points on the left of obj_fold[1] are fixedly folded
inward
 * and unchanged. Therefore, the X coordinates of these four points do not need to be
 * changed, and only the Z coordinates need to be set to negative values (currently set
 * to 0~-0.2, adjusted according to the effect). The perspective transformation in the
 * vertex shader will automatically transform the effect of near large and far small.
 */
void anim_fold(void *var, int32_t v)
/* End callback */
void anim_fold_end(lv_anim_t *a)

7.3.5 ローラー画像プレビュー {#735-rollering-image-preview}

アニメーション 記述 6つの映像は各映像を表示するために回るバレルの形を形作ります

英語版のソースからの技術図

コード紹介

/* anims/roller.c */
/* Rendering callback, render 6 pictures in sequence */
void anim_roller_render(void)
/*
 * Start callback
 * 1 Set the view to 2000x2000. Because it involves rotation, in order to avoid the
image
 *   exceeding the coordinates and causing cropping and loss of the screen, set it to a
 *   large value.
 * 2 Recalculate the size of the rendered object according to the new view, and set
 *   the Z axis offset to 0.20785, so that the image is a certain distance from the
 *   center, thus forming a barrel shape. The Z axis calculation is a simple Pythagorean
 *   theorem, sqrt(240^2 - 120^2) / 2000 * 2.0 = 0.20785, the image width is 240 (see
the
 *   image below), and since it is a hexagon, a simple sqrt(240^2 - 120^2) can calculate
 *   the distance from each face to the center. 2000 is the view size, and the scale
 *   ratio is calculated from it, and then multiplied by the range 2.0 (coordinates
 *   -1.0~1.0) to get the offset value. If it is not a hexagon, you need to calculate
the
 *   distance in other ways, and the way to calculate the scale ratio and offset value
 *   remains unchanged.
 * 3 Set the X-axis rotation to 30 and the Z-axis rotation to 15. In order to have a
 *   tilt effect, set them as needed.
 */
void anim_roller_start(lv_anim_t *a)
/* Animation callback. Add the rotation value to the Y axis of each image.
 * The first image is 0 degrees plus the rotation value, the second image is 60 degrees
 * plus the rotation value, and so on. */
void anim_roller(void *var, int32_t v)
/* End callback */
void anim_roller_end(lv_anim_t *a)

英語版のソースからの技術図

7.3.6 撹拌機テスト {#736-stiker-test}

アニメーション 背景画像の1つの小さなグリッドを一度に動かし、一定の距離をステップし、小さな画像を貼り付けます。

英語版のソースからの技術図

コード紹介

/* anims/stiker.c */
/*
 * Rendering callback
 * 1 Set obj_fb as framebuffer
 * 2 Clear obj_fb with color(0.0, 0.0, 0.0, 1.0) because we need the alpha of framebuffer
 *   always be 1.0 before each rendering
 * 3 Rendering obj_img1 to obj_fb as a backgroud
 * 4 Rendering obj_img0 to obj_fb as a stiker
 * 5 Reset to default framebuffer, rendering obj_fb to screen
 * In actual use, the two images can be rendered directly to the screen.
 * The DEMO is just to show the rendering function and framebuffer function.
 */
static void anim_stiker_render(void)
/* Start callback. Set the coordinates of the texture to 0,0 and call lv_gl_obj_move
 * to update the parameter values.
 */
void anim_stiker_start(lv_anim_t *a)
/* Animation callback. Set the coordinates according to the current animation progress,
 * and call lv_gl_obj_move to update the parameter values.
 */
void anim_stiker(void *var, int32_t v)
/* End callback */
void anim_stiker_end(lv_anim_t *a)

7.3.7 スライドアウト {#737-slide-out}

アニメーション 説明 図に示すように、単純なスライドアウトDEMO、最初の画像は画面から左に徐々にスライドしますが、第二の画像は画面に左にスライドします

英語版のソースからの技術図

コード紹介

/* anims/slide_out.c */
/* Calls the common start callback and sets the animation area to be visible */
void anim_slide_out_start(lv_anim_t *a)
/* Animation callback, updates the X coordinates of the two images */
void anim_slide_out(void *var, int32_t v)
/* End callback */
void anim_slide_out_end(lv_anim_t *a)

7.3.8 逃げ出 {#738-fade-out}

アニメーション 説明 数字に示すように、単純なフェードインとフェードアウトDEMO、最初の画像の透明性は、画面から徐々に消え、第二の画像の透明度が増加し、徐々にスクリーンにフェードアウトします

英語版のソースからの技術図

コード紹介

/* anims/fade_out.c */
/* Calls the common start callback and sets the animation area to be visible */
void anim_fade_out_start(lv_anim_t *a)
/* Animation callback, updates the transparency of the two images */
void anim_fade_out(void *var, int32_t v)
/* End callback */
void anim_fade_out_end(lv_anim_t *a)

7.3.9 衰退し、スライドアウト {#739-fade-and-slide-out}

アニメーション 説明 2つのアニメーションを組み合わせます。 透明性を低下させながら最初のイメージがスライドし、第二の画像は画面にスライドします。

英語版のソースからの技術図

コード紹介

/* anims/fade_slide_out.c */
/* Calls the common start callback and sets the animation area to be visible */
void anim_fade_slide_out_start(lv_anim_t *a)
/* Animation callback, updates the X coordinates of the two images and the
 * transparency of first image according to the current animation progress */
void anim_fade_slide_out(void *var, int32_t v)
/* End callback */
void anim_fade_slide_out_end(lv_anim_t *a)

7.3.10 フォトストリーム {#7310-photo-stream}

アニメーション 説明 6 枚の写真をスクロールします。 一番下から下にスクロールします。 画面に触れると、アニメーションは一時停止して指で動かします。 リリースすると、アニメーションは続行します。

英語版のソースからの技術図

コード紹介

/* anims/photo_stream.c */
/* image height */
static int32_t img_h = 480;
/* image gap */
static int32_t gap_h = 20;
/*
 * Calculate the maximum Y coordinate based on the image height, image gap,
 * and number of images
 * max_y = n * img_h + (n - 1) * gap_h
 */
static int32_t max_y;
/*
 * Boundary value, used to reset to the top of the photo stream and continue
 * looping after the image reaches max_y
 * boundary = n * img_h + n * gap_h
 * Since the image needs to return to the top after the loop and needs to be
 * spaced from the first image, boundary has one more gap_h than max_y.
 */
static int32_t boundary;
/* Update image coordinates regularly */
static lv_timer_t *timer;
/* The coordinate offset increased by the timer*/
static int32_t timer_ofs = 0;
/* The coordinate offset increased by the last touch */
static int32_t touch_ofs_s = 0;
/* The coordinate offset increased by this touch */
static int32_t touch_ofs = 0;
/* Update and check the Y coordinate of the image to achieve animation effect */
static void update_y(void)
/* Timer callback */
static void lv_timer_cb(lv_timer_t *timer)
/*
 * Touch callback
 * LV_EVENT_PRESSED: Pause the timer and get the coordinates of the pressed
 * LV_EVENT_PRESSING: Get the current touch coordinates, compare with the pressed
 * coordinates, add touch_ofs_s to calculate the offset value and update the coordinates
 * LV_EVENT_RELEASED: Re-enable the timer and record the touch offset to touch_ofs_s
 * The reason for dividing into three offsets is to ensure the continuity of the
 * animation coordinates when the touch is pressed and released,
 * and to avoid coordinate shifting.
 */
static void touch_handler(lv_event_t * e)
/* Stop photo stream */
void anim_photo_stream_stop(void)
/* Initialize the photo stream, create a timer, calculate max_y, boundary, etc. */
void anim_photo_stream_start(lv_anim_t *a)
/* Animation callback
 * In fact, the photo stream is implemented using a timer and has nothing to do
 * in animation callback. The animation callback is used here just to unify the
 * interface and facilitate embedding into the DEMO framework.
 * The actual application development can just use the timer callback.
 */
void anim_photo_stream(void *var, int32_t v)
void anim_photo_stream_end(lv_anim_t *a)
  1. バージョン9では、lvglチームはlv_driversをlvglメインリポジトリに統合しました。

中国ソースからの追加説明

中国語と英語のコードコメントは、それぞれ異なる。各ソースリストは保持されます。 中国のソースは、さらに説明しています: furniture_control は、家庭用電化製品を制御します。 intercom_homepage は、ビルのインターコム、intercom_call はコールを処理します。 video_monitor は RTSP を再生します。 smart_home はスマートホームアプリケーションであり、 wifibt は rkwifibt を適応させます。 VAO は、VBO と 属性の設定を切り替える機能のキャッシュをします。VBO は座標とテクスチャの頂点を格納します。FBO は、テクスチャがフレームバッファになるときに使われます。 ギャラリーの歌詞には12行、2つのキューブフェイスがあります。 lyric_row配列は12メンバーで、それぞれその行の文字を含む。 アクションボタンは、画面下がり、上領域をアニメーション化します。1つのアニメーションは一度に終了します。 ステッカー例では、最終アルファは、宛先の背景のd.aなので、クリアカラーアルファは1.0です。それ以外の場合は、結果が透明であるか、見えないかもしれません。

中国語§1は依存症文を修飾します。ただし、一部の拡張子を除く外部の依存関係はありません。 Windows または Linux PC 環境は、繰り返しファームウェアビルドとフラッシュなしでプラットフォームに依存しない UI をデバッグできます。その後、コードを埋め込まれたデバイスにコピーし、コンパイルして実行します。 エクステンションは、対応する依存関係を要求します。

ArmSoM Docs

http://cube%20sides/

製品と開発リソース

製品資料でハードウェアのリビジョン、キャリアボード、OS イメージ、インターフェースをご確認ください。記事への掲載は、その構成での動作検証を意味しません。

以下の製品はプラットフォームの参考情報として掲載しています。サンプルを各製品へ移植済みとするものではありません。

このトピックを詳しく見る → · 学習ガイド →