Rockchip · AI & Linux Hub

Affichage et audio

Rockchip Linux LVGL et OpenGL(ES) Galerie

Rockchip Linux LVGL et OpenGL(ES) Gallery — V1.2.1

Référence de la plateforme ArmSoM basée sur les sources de Rockchip fournies en chinois et anglais. Correspondez individuellement au tableau, SoC, SDK/BSP, noyau et périphériques ; cela ne réclame pas de support pour chaque tableau ArmSoM. Les exemples de sources et les mesures ne sont pas des tests ArmSoM. Aucune commande ni aucun test matériel n’ont été exécutés.

Couvertures Buildroot LVGL 8.4.x / 9.1.x et Rockchip lv_gl extensions; exemples incluent des omissions intentionnelles de source.

V1.2.1; les 7 chapitres, les paramètres de l’API et la version-9 lv_drivers fusionnent la note de bas de page conservée. ZH utilise 13 chiffres de source chinoise; EN/RU/DE utilise 13 chiffres de source anglaise. Des exemples d’animation omettent intentionnellement le code et ne sont pas des programmes complets compilables. La source mélange transparence et visibilité; la signification/caveats est annotée sans changer de code.

OS Version
Construire la racine 8.4.x
Construire la racine 9.1.x

1. LVGL Introduction {#1-lvgl-introduction}

LVGL est la bibliothèque graphique intégrée la plus populaire, gratuite et ouverte, pour créer de beaux UI pour n’importe quel type de MCU, MPU et d’affichage. LVGL est entièrement open-source et n’a aucune dépendance externe qui rend son portage incroyablement simple. Il fonctionne avec n’importe quel MCU ou MPU moderne et peut être utilisé avec n’importe quelle configuration (RT)OS ou métal nu pour piloter ePaper, monochrome, OLED, ou TFT des écrans, et même des moniteurs.

2. Code source LVGL {#2-lvgl-source-code}

Dans Linux SDK, LVGL a trois dépôts, à savoir lvgl, lv_drivers 1 et lvgl_demo. Le lvgl est le dépôt source framework. Le lv_drivers comprend certaines API d’affichage telles que drm, sdl, wayland, etc. Le lvgl_demo comprend quelques démos de développeurs Rockchip, montrant comment faire une initialisation de base, et comment appeler les démos de LVGL. Le code source lvgl et lv_drivers sont téléchargés depuis le github, et ont appliqué des correctifs de développeurs Rockchip, vous pouvez trouver les correctifs de buildroot/package/lvgl/lvgl/ et buildroot/package/lvgl/lv_drivers/ . Le code source lvgl_demo est en <SDK>/app/lvgl_demo .

3. Configurations LVGL {#3-lvgl-configurations}

Le moteur de rendu LVGL est optionnel. Actuellement, vous pouvez choisir de rendre l’image directement à l’affichage via DRM, SDL ou RKADK. La configuration DRM est utilisée sur certaines plateformes sans GPU ou RGA, comme RK3308. La configuration SDL est utilisée sur certaines plateformes avec GPU, comme RK3568. La configuration RKADK est utilisée sur certaines plates-formes avec GPU ou RGA.

3.1 Fichiers de configuration {#31-configuration-files}

Les fichiers de configuration de base sont stockés dans <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 Utilisation des fichiers de configuration {#32-configuration-files-usage}

Inclure les fichiers de configuration LVGL dans votre fichier defconfig:

$ 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 Configurations externes pour SDL {#33-external-configurations-for-sdl}

Si vous utilisez des configurations SDL, vous devez sélectionner le moteur de SDL:

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

Si vous avez besoin d’APIs OpenGL(ES) supplémentaires, activez cette configuration :

BR2_PACKAGE_LV_DRIVERS_USE_OPENGL=y

4. LVGL Complie {#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

Veuillez noter que si vous modifiez la configuration de LVGL via menuconfig, nous vous recommandons de recompiler les trois dépôts pour éviter les erreurs inattendues:

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. Code source LVGL_DEMO {#5-lvgl_demo-source-code}

Le chemin est <SDK>/app/lvgl_demo/ .

5.1 Structure du répertoire {#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 Code source lv_demo {#52-lv_demo-source-code}

Le chemin est <SDK>/app/lvgl_demo/lv_demo . Ce programme est principalement utilisé comme exemple pour démontrer comment exécuter le DEMO officiel. Les instructions suivantes ne tiennent pas compte de certains codes et ne choisissent que les codes qui nécessitent une attention particulière pour des explications:

/* <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. API OpenGL(ES) {#6-opengles-apis}

Comme LVGL ne supporte pas l’interface OpenGL (ES) et que SDL ne supporte pas les objets 3D, un ensemble d’interfaces lv_gl est encapsulé pour certaines applications qui doivent utiliser des fonctions connexes, de sorte que les applications LVGL peuvent directement superposer les effets d’image 3D sur les applications d’interface utilisateur originales.

6.1 Introduction du dossier {#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 énumérer {#62-enumerate-introduction}

6.2.1 Format de couleur {#621-color-format}

Maintenant, prenez en charge LV_GL_FMT_RGBA et 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 Type de texture {#622-texture-type}

enum {
    GL_TEX_TYPE_2D,
    GL_TEX_TYPE_CUBE,
};

6.2.3 Côtés cubes {#623-cube-sides}

Utilisé pour sélectionner la surface cible lors de l’importation ou du rendu d’image.

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

Dans les coordonnées OpenGL, le centre de l’écran est l’origine (0, 0), la coordonnée X est positive à droite, la coordonnée Y est positive vers le haut, et la coordonnée Z est positive perpendiculaire à l’écran et vers l’extérieur. Par conséquent, lorsqu’un cube est créé sans rotation, la direction vers laquelle l’utilisateur se trouve est positive (CUBE_FRONT), et le reste des directions sont similaires, comme le montre la figure suivante (la ligne pointillée indique la partie invisible):

Chiffre technique d'origine anglaise

6.3 Présentation de la structure {#63-structure-introduction}

Utilisé dans les applications, principalement en se concentrant sur les trois structures lv_gl_img_t, lv_gl_tex_t et lv_gl_obj_t. lv_gl_img_t Utilisé pour importer des images externes comme objets de texture 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 Store Objets de texture GPU et informations connexes.

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 stocke les objets de rendu GPU et les informations connexes, comme les sommets, les paramètres de transformation, etc.

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 Présentation de la fonction {#64-function-introduction}

void lv_gl_set_render_cb(lv_gl_render_cb_t cb);

Enregistrer le callback de rendu de calque d’application. Le rendu des objets ne peut être fait que dans le callback. cb: le pointeur du callback de rendu

void lv_gl_set_fb(lv_gl_obj_t *obj);

Définir framebuffer obj : Si c’est NULL, le prochain rendu sera rendu à l’écran. Si ce n’est pas NULL, le prochain rendu sera rendu à la texture de cet objet.

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

Copier la zone spécifiée de la mémoire courante du tampon de cadre. ptr : La mémoire que vous voulez écrire. r : Zone de lecture. type : Type de lecture, par défaut GL_TEXTURE_2D. Si vous voulez lire une surface cube, référez-vous à l’énumération dans Cube Sides pour sélectionner la surface.

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

Créer un type de texture : Type de texture, GL_TEX_TYPE_2D ou GL_TEX_TYPE_CUBE w : Largeur de texture. Ignoré si l’img n’est pas NULL. h: Hauteur de texture. Ignoré si l’img n’est pas NULL. img : L’image importée, si vide, ne s’appliquera que pour l’espace correspondant dans le GPU (la valeur par défaut est tout 0.0), si elle n’est pas vide, l’image correspondante sera également importée dans le GPU. Si le type de texture est GL_TEX_TYPE_CUBE, ce paramètre doit passer dans un tableau avec au moins 6 éléments. Valeur de la reture : lv_gl_tex_t *, le pointeur de la texture

void lv_gl_tex_del(lv_gl_tex_t *tex);

Supprimer une texture

tex: le pointeur de la texture

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

Importer des images externes dans un objet de texture. tex: le pointeur de texture img: L’image importée. Si le type de texture est GL_TEX_TYPE_CUBE, ce paramètre doit passer dans un tableau avec au moins 6 éléments.

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

Remplir la couleur d’une texture. tex: le pointeur de texture r: Valeur du canal rouge. g: Valeur du canal vert. b: Valeur du canal bleu. a: Valeur du canal Alpah.

lv_gl_obj_t *lv_gl_obj_create(int w, int h);

Créer un objet de rendu. L’objet ne peut être rendu qu’après avoir lié un objet de texture. w: width h: hight Valeur de retour : lv_gl_obj_t *, le pointeur de l’objet de rendu

void lv_gl_obj_del(lv_gl_obj_t *obj);

Délecter un objet de rendu. obj: le pointeur de rendu d’objet

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

Redimensionner l’objet de rendu. L’objet de rendu par défaut est plein écran, vous devez donc utiliser cette interface pour réinitialiser le paramètre échelle. Il est à noter que cette interface utilise la largeur et la hauteur de l’obj et la largeur et la hauteur de la vue parent pour calculer, plutôt que la largeur et la hauteur du parent. obj: le pointeur de rendu parent objet: objectif de rendu, NULL pour écran.

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

Réinitialisez la position de rendu en fonction de la cible de rendu. Calculer en fonction des valeurs de l’échelle et de la base.r et de la largeur et de la hauteur de la vue parent. Comme la valeur de l’échelle est utilisée, il est recommandé d’appeler cette interface après redimensionnement. Si l’échelle est modifiée manuellement, il est recommandé d’appeler cette interface à nouveau obj : le pointeur du parent de rendu de l’objet : cible de rendu, NULL pour écran.

void lv_gl_obj_reset_points(lv_gl_obj_t *obj);

Réinitialiser les paramètres vertex de l’objet rendu, ce qui signifie affichage en plein écran obj: le pointeur de rendu de l’objet

void lv_gl_obj_reset_tex_points(lv_gl_obj_t *obj);

Réinitialiser les paramètres de texture vertex de l’objet rendu, ce qui signifie utiliser l’image obj complète: le pointeur de l’objet rendu

void lv_gl_obj_update_vao(lv_gl_obj_t *obj);

Mettre à jour les VAO et VBO de l’objet de rendu en fonction des paramètres actuels du vertex et des paramètres de texture du vertex. Par conséquent, si les paramètres de vertex et de texture vertex sont modifiés manuellement, cette interface doit être appelée pour prendre effet. S’ils n’ont pas été créés, de nouveaux VAO et VBO seront créés. obj: le pointeur de rendu d’objet

void lv_gl_obj_release_vao(lv_gl_obj_t *obj);

Release VAO et VBO, en utilisant les paramètres par défaut. obj: le pointeur de l’objet de rendu

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

Lorsqu’un objet de texture est lié, le nombre de références d’objets de texture augmente de 1. Si l’objet rendu a déjà un objet de texture lié, la référence à l’objet de texture original sera réduite et elle sera automatiquement libérée lorsque la référence est inférieure ou égale à 0. Il est donc à noter que cette interface peut déclencher la libération de mémoire, et l’application doit éviter les références externes aux objets texture et les versions répétées. obj: le pointeur de rendu objet tex: le pointeur de l’objet texture

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

Définissez la plage de crop, avec le coin inférieur gauche de l’écran comme coordonnées d’origine, vers le haut comme direction Y positive, et vers la droite comme direction X positive obj: le pointeur de l’objet de rendu, NULL pour écran. r: Plage de crop, coordonnées de départ et taille. Lorsque vide, les coordonnées de départ sont réinitialisées à l’origine et la taille est réinitialisée à la taille de l’objet rendu. fr: 1 active crop, 0 désactive crop

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

Obtenez la plage de crop obj : le pointeur de l’objet de rendu, NULL pour l’écran. r : Le pointeur pour stocker la valeur de retour.

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

Réglez la plage de port de vue, avec le coin inférieur gauche de l’écran comme coordonnées d’origine, vers le haut comme direction Y positive, et vers la droite comme direction X positive obj: le pointeur de l’objet de rendu, NULL pour écran. r: plage de port de vue, coordonnées de départ et taille. Lorsque vide, les coordonnées de départ sont réinitialisées à l’origine et la taille est réinitialisée à la taille de l’objet rendu.

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

Obtenez la plage de port de vue obj: le pointeur de rendu objet, NULL pour écran.

r: Le pointeur pour stocker la valeur de retour.

void lv_gl_obj_render(lv_gl_obj_t *obj);

Renvoyez l’objet rendu sur le tampon de trame. Ne peut être utilisé que pour le rendu callback. obj: le pointeur de rendu objet

Pour les applications d’album et de galerie, une nouvelle Galerie DEMO est ajoutée, qui comprend plusieurs effets d’animation, tels que la diapositive, la décoloration, la rotation cube, le flip cube, l’affichage de texte cube, l’aperçu d’image à rouleaux, le flux photo, etc.

7.1 Structure du répertoire {#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 Introduction à l’entrée dans l’assurance-chômage {#72-ui-entry-introduction}

Le main.c est le même que le code source lv_demo, nous introduisons donc ici principalement l’entrée 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 Animations {#73-animations}

Puisque lv_gl ne peut pas déclencher automatiquement le rendu, il est nécessaire de déclencher le processus de rendu du cadre LVGL dans le callback d’animation. Actuellement, lv_obj_invalidate(lv_layer_top()) est utilisé dans tous les callbacks d’animation pour déclencher le rendu. En même temps, puisque la couche supérieure n’a pas d’objets enfants, elle n’affectera pas les performances de rendu normales.

7.3.1 Dépliage en cube {#731-cube-flip}

Animation Description Les deux photos sont commutées en tournant le cube, et le cube est correctement réduit pendant la rotation.

Chiffre technique d'origine anglaise

En tournant l’axe des X à 15 degrés, vous pouvez mieux observer cette animation

Chiffre technique d'origine anglaise

Code Introduction

 /* 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 Rotation du cube {#732-cube-rotation}

Animation Description Rotation et présentation de l’image de toutes les surfaces.

Chiffre technique d'origine anglaise

Code Introduction

/* 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 Cube rendu lyrique {#733-cube-lyric-rendering}

Description de l’animation

Faites tourner le cube et montrez les six surfaces du cube en séquence, dessinez les caractères sur la surface actuellement affichée. Vous pouvez remplacer les personnages par des paroles pour obtenir l’affichage des paroles 3D en conjonction avec la musique.

Chiffre technique d'origine anglaise

Code Introduction

/* 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 Pliage de l’image {#734-picture-fold}

Animation Description La première image se replie vers l’intérieur et sort, tandis que la seconde image est divisée en deux parties et se déplace vers l’intérieur de l’extérieur de l’écran.

Chiffre technique d'origine anglaise

Code Introduction

/* 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 Aperçu de l’image enrouleur {#735-rollering-image-preview}

Description de l’animation Six images forment une forme de baril, tournant pour afficher chaque image

Chiffre technique d'origine anglaise

Code Introduction

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

Chiffre technique d'origine anglaise

7.3.6 Essai de piquage {#736-stiker-test}

Animation Description Sur l’image de fond, déplacez une petite grille à la fois, marchez une certaine distance et collez une petite image.

Chiffre technique d'origine anglaise

Code Introduction

/* 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 Sortie de la diapositive {#737-slide-out}

Animation Description Une simple diapo-out DEMO, comme le montre la figure, la première image glisse progressivement de l’écran vers la gauche, tandis que la deuxième image glisse vers la gauche

Chiffre technique d'origine anglaise

Code Introduction

/* 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 Défaut {#738-fade-out}

Animation Description Un simple décoloration et décoloration DEMO, comme le montre la figure, la transparence de la première image diminue et s’efface progressivement hors de l’écran, tandis que la transparence de la deuxième image augmente et s’efface progressivement dans l’écran

Chiffre technique d'origine anglaise

Code Introduction

/* 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 Fade et glisse {#739-fade-and-slide-out}

Animation Description Combinez les deux animations. La première image glisse en réduisant sa transparence, tandis que la seconde image glisse dans l’écran.

Chiffre technique d'origine anglaise

Code Introduction

/* 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 Volet photo {#7310-photo-stream}

Animation Description 6 images défilent de haut en bas. Lorsque vous touchez l’écran, l’animation s’arrêtera et se déplacera avec le doigt. Lorsque vous la relâchez, l’animation se poursuivra.

Chiffre technique d'origine anglaise

Code Introduction

/* 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. Dans la version 9, l’équipe lvgl a fusionné lv_drivers dans le dépôt principal lvgl.

Explications supplémentaires de la source chinoise

Les commentaires des codes chinois et anglais diffèrent en détail; chaque liste de sources est conservée. La source chinoise explique en outre : furniture_control contrôle les appareils ménagers ; intercom_homepage est l’interphone de construction, intercom_call gère les appels, video_monitor joue RTSP, smart_home est l’application Smart-home, et wifibt adapte rkwifibt. VAO cache la configuration VBO et l’attribut pour le changement; VBO stocke les coordonnées et les sommets de texture; FBO est utilisé lorsqu’une texture devient le tampon de trame. Les paroles de la galerie ont 12 lignes, deux par face cube; le tableau lyric_row a 12 membres, chacun contenant les caractères de cette ligne. Les boutons d’interaction occupent l’écran inférieur et l’animation la région supérieure; une animation se termine à la fois. Dans l’exemple d’autocollant, l’alpha final est le d.a de la destination, donc l’alpha clair est 1,0; sinon le résultat peut être transparent ou invisible.

Chinois §1 qualifie la déclaration de dépendance: aucune dépendance externe sauf pour certaines extensions. Un environnement Windows ou Linux PC peut déboguer l’interface utilisateur indépendante de la plate-forme sans créer et clignoter de firmware répété; puis copier le code sur le périphérique intégré, compiler et exécuter. Les extensions nécessitent toujours leurs dépendances correspondantes.

ArmSoM Docs

http://cube%20sides/

Produits et ressources de développement

Vérifiez la révision matérielle, la carte porteuse, l’image système et les interfaces dans la documentation produit. Une association à cet article ne prouve pas que cette configuration a été testée.

Ces modèles sont proposés pour approfondir le choix de plateforme. Les exemples ne sont pas présentés comme ayant été portés sur ces produits.

Explorer ce sujet → · Parcours →