📌

LVGL V9をWio Terminalで動かしてみる

に公開

Wio Terminalを買った

使い道はかんがえてないが、Wio Terminalを買ってきた。
とりあえずM5StackのようにLVGL V9を動かしてみる。

ArduinoIDEの準備

このとおり
https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/

LovyanGFXをインストール

TFT_eSPIを使っても良いけれども、M5StackでLovyanGFXを使っているので、今回もLovyanGFXを使います。

ライブラリマネージャーで「LovyanGFX」を検索して、インストールする。

LVGL v9をインストール

ライブラリマネージャーで「LVGL」を検索して、インストールする。

lv_conf_template.hをコピーする

「基本設定」-> 「スケッチブックの場所」をエクスプローラーで開く。
その中にある「libraries」 -> 「lvgl」フォルダにあるlv_conf_template.hをコピーして
「libraries」フォルダに戻って ペーストする。
(つまりlibrariesフォルダにファイルコピーする)
コピーしたlv_conf_template.hをlv_conf.hにリネームする。

lv.conf.hを編集する

好きなエディタでlv_conf.hファイルを編集する。

15行目の"#if 0"を"#if 1"に書き換えて保存する。

新規スケッチ

ArduinoIDEで新規スケッチを開いて、exampleのLVGL_Arduino.inoを参考にして書く。

今回TFT_eSPIは使わないのでその部分は削除してLovyanGFXを使うように書き換える。

/*Using LVGL with Arduino requires some extra steps:
 *Be sure to read the docs here: https://docs.lvgl.io/master/integration/framework/arduino.html  */

#include <lvgl.h>

#define LGFX_AUTODETECT
#include <LovyanGFX.hpp>

static LGFX lcd;

/*To use the built-in examples and demos of LVGL uncomment the includes below respectively.
 *You also need to copy `lvgl/examples` to `lvgl/src/examples`. Similarly for the demos `lvgl/demos` to `lvgl/src/demos`.
 *Note that the `lv_examples` library is for LVGL v7 and you shouldn't install it for this version (since LVGL v8)
 *as the examples and demos are now part of the main LVGL library. */

//#include <examples/lv_examples.h>
//#include <demos/lv_demos.h>

/*Set to your screen resolution and rotation*/
#define TFT_HOR_RES   320
#define TFT_VER_RES   240
#define TFT_ROTATION  LV_DISPLAY_ROTATION_0

/*LVGL draw into this buffer, 1/10 screen size usually works well. The size is in bytes*/
#define DRAW_BUF_SIZE (TFT_HOR_RES * TFT_VER_RES / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4];

#if LV_USE_LOG != 0
void my_print( lv_log_level_t level, const char * buf )
{
    LV_UNUSED(level);
    Serial.println(buf);
    Serial.flush();
}
#endif

/* LVGL calls it when a rendered image needs to copied to the display*/
void my_disp_flush( lv_display_t *disp, const lv_area_t *area, uint8_t * px_map)
{
    /*Copy `px map` to the `area`*/
    uint32_t width = (area->x2 - area->x1 + 1);
    uint32_t height = (area->y2 - area->y1 + 1);
    if(!lcd.getSwapBytes()) {
        lv_draw_sw_rgb565_swap(px_map, width*height);   // LGFXでバイト順変換をする場合は不要になる
    }
    lcd.pushImageDMA<uint16_t>(area->x1, area->y1, width, height, (uint16_t *)px_map);
    /*Call it to tell LVGL you are ready*/
    lv_display_flush_ready(disp);
}

/*Read the touchpad*/
void my_touchpad_read( lv_indev_t * indev, lv_indev_data_t * data )
{
    /*For example  ("my_..." functions needs to be implemented by you)
    int32_t x, y;
    bool touched = my_get_touch( &x, &y );

    if(!touched) {
        data->state = LV_INDEV_STATE_RELEASED;
    } else {
        data->state = LV_INDEV_STATE_PRESSED;

        data->point.x = x;
        data->point.y = y;
    }
     */
}

/*use Arduinos millis() as tick source*/
static uint32_t my_tick(void)
{
    return millis();
}

void setup()
{
    lcd.init();             // 最初に初期化関数を呼び出します。
    lcd.setColorDepth(16);  // RGB565の16ビットに設定
    lcd.setSwapBytes(true); // バイト順変換を有効にする。

    String LVGL_Arduino = "Hello Arduino! ";
    LVGL_Arduino += String('V') + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();

    Serial.begin( 115200 );
    for (auto t0 = millis(); (millis() - t0 < 2000) && !Serial;) {
        /* シリアル初期化完了待ち */
    }
    Serial.println( LVGL_Arduino );

    lv_init();

    /*Set a tick source so that LVGL will know how much time elapsed. */
    lv_tick_set_cb(my_tick);

    /* register print function for debugging */
#if LV_USE_LOG != 0
    lv_log_register_print_cb( my_print );
#endif

    lv_display_t * disp;
    disp = lv_display_create(TFT_HOR_RES, TFT_VER_RES);
    lv_display_set_flush_cb(disp, my_disp_flush);
    lv_display_set_buffers(disp, draw_buf, NULL, sizeof(draw_buf), LV_DISPLAY_RENDER_MODE_PARTIAL);

    /*Initialize the (dummy) input device driver*/
    lv_indev_t * indev = lv_indev_create();
    lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER); /*Touchpad should have POINTER type*/
    lv_indev_set_read_cb(indev, my_touchpad_read);

    /* Create a simple label
     * ---------------------
     lv_obj_t *label = lv_label_create( lv_screen_active() );
     lv_label_set_text( label, "Hello Arduino, I'm LVGL!" );
     lv_obj_align( label, LV_ALIGN_CENTER, 0, 0 );

     * Try an example. See all the examples
     *  - Online: https://docs.lvgl.io/master/examples.html
     *  - Source codes: https://github.com/lvgl/lvgl/tree/master/examples
     * ----------------------------------------------------------------

     lv_example_btn_1();

     * Or try out a demo. Don't forget to enable the demos in lv_conf.h. E.g. LV_USE_DEMO_WIDGETS
     * -------------------------------------------------------------------------------------------

     lv_demo_widgets();
     */

    lv_obj_t *label = lv_label_create( lv_screen_active() );
    lv_label_set_text( label, "Hello Arduino, I'm LVGL!" );
    lv_obj_align( label, LV_ALIGN_CENTER, 0, 0 );

    Serial.println( "Setup done" );
}

void loop()
{
    lv_timer_handler(); /* let the GUI do its work */
    delay(5); /* let this time pass */
}

コンパイル

コンパイルするとリンクエラーが発生する。

c:/users/aki/appdata/local/arduino15/packages/seeeduino/tools/arm-none-eabi-gcc/7-2017q4/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: error: C:\Users\aki\AppData\Local\arduino\sketches\29D69E51D22E74D7754D10FDEC164EF3\libraries\lvgl\draw\sw\blend\helium\objs.a(lv_blend_helium.S.o): Conflicting CPU architectures 13/0
c:/users/aki/appdata/local/arduino15/packages/seeeduino/tools/arm-none-eabi-gcc/7-2017q4/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file C:\Users\aki\AppData\Local\arduino\sketches\29D69E51D22E74D7754D10FDEC164EF3\libraries\lvgl\draw\sw\blend\helium\objs.a(lv_blend_helium.S.o)
c:/users/aki/appdata/local/arduino15/packages/seeeduino/tools/arm-none-eabi-gcc/7-2017q4/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: error: C:\Users\aki\AppData\Local\arduino\sketches\29D69E51D22E74D7754D10FDEC164EF3\libraries\lvgl\draw\sw\blend\neon\objs.a(lv_blend_neon.S.o): Conflicting CPU architectures 13/0
c:/users/aki/appdata/local/arduino15/packages/seeeduino/tools/arm-none-eabi-gcc/7-2017q4/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file C:\Users\aki\AppData\Local\arduino\sketches\29D69E51D22E74D7754D10FDEC164EF3\libraries\lvgl\draw\sw\blend\neon\objs.a(lv_blend_neon.S.o)
collect2.exe: error: ld returned 1 exit status
exit status 1

Compilation error: exit status 1

この2ファイルのオブジェクトファイルでリンクエラーを起こす。

リンクエラーの対処

lv_conf.hのLV_USE_DRAW_SW_ASMが LV_DRAW_SW_ASM_NONE(つまり 0) で設定しているので、このアセンブリは使っていないのにオブジェクトコードが出力されている。

オプション設定で何とかなりそうなんだけど、わからなかったので強引に対処する。

  • Arduino\libraries\lvgl\src\draw\sw\blend\heliumフォルダ
  • Arduino\libraries\lvgl\src\draw\sw\blend\neonフォルダ
    この2つを削除する。

ビルド&書き込み

やりかたが強引だったけどなんとかなった。

GitHubリポジトリ

GitHubにおきました。
https://github.com/ak1211/LVGL_wio_terminal

Discussion