lvgl / lv_drivers

TFT and touch pad drivers for LVGL embedded GUI library
https://docs.lvgl.io/master/porting/index.html
MIT License
318 stars 313 forks source link

lv_drivers/display/drm.c.o Undefined reference to #239

Closed SwordofMorning closed 2 years ago

SwordofMorning commented 2 years ago

I tried to use DRM as the display interface of the project, but I encountered some problems when compiling:

lv_drivers/display/drm.c:132: undefined reference to `drmModeObjectGetProperties'
lv_drivers/display/drm.c:141: undefined reference to `drmModeGetProperty'
........

I use CMake to build my project, my cc tool chain is arm-linux-gnueabihf- whic is produced by Buildroot. Here is my project tree:

.
├── CMakeLists.txt    // 1
├── src
│   ├── lv_conf.h
│   ├── lv_drv_conf.h
│   ├── lvgl
│   │   ├── CMakeLists.txt    // 3
│   ├── CMakeLists.txt    // 2
│   ├── lv_drivers
│   │   ├── CMakeLists.txt    // 4
│   └── main.c
└── build

CMakeLists 1:

PROJECT(RV1126)

CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

SET(CMAKE_C_COMPILER "/home/xjt/SF6_RV1126/RV1126/buildroot/output/rockchip_rv1126_rv1109_dcir/host/bin/arm-linux-gnueabihf-gcc")

ADD_SUBDIRECTORY(src bin)

CMakeLists 2:

FILE(GLOB_RECURSE SRC_LIST ./*.c)

ADD_SUBDIRECTORY(./lvgl)
ADD_SUBDIRECTORY(./lv_drivers)

LINK_DIRECTORIES(./lvgl)
INCLUDE_DIRECTORIES(./lvgl)

SET(
    LIB_LIST
    lvgl_lib
)

SET(
    ${LIB_LIST}
    lv_drv_lib
)

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR/bin})

ADD_EXECUTABLE(demo ${SRC_LIST})

TARGET_LINK_LIBRARIES(demo ${LIB_LIST})

CMakeLists 3 & 4 are similar :

AUX_SOURCE_DIRECTORY(./src/core DIR_LVGL_SRC)
AUX_SOURCE_DIRECTORY(./src/draw DIR_LVGL_SRC)
AUX_SOURCE_DIRECTORY(./src/extra DIR_LVGL_SRC)
AUX_SOURCE_DIRECTORY(./src/font DIR_LVGL_SRC)
AUX_SOURCE_DIRECTORY(./src/hal DIR_LVGL_SRC)
AUX_SOURCE_DIRECTORY(./src/misc DIR_LVGL_SRC)
AUX_SOURCE_DIRECTORY(./src/widgets DIR_LVGL_SRC)

ADD_LIBRARY(lvgl_lib ${DIR_LVGL_SRC})

But when i use fb instead of drm, it compiles fine. Here is my main.c:

#include "lvgl/lvgl.h"
#include <libdrm/drm.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include "lv_drivers/display/drm.h"
#include "lv_drivers/indev/evdev.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>

#define DISP_BUF_SIZE (1280 * 800)

int main(void)
{

    /*LittlevGL init*/
    lv_init();

    /*Linux frame buffer device init*/
    drm_init();

    /*A small buffer for LittlevGL to draw the screen's content*/
    static lv_color_t buf[DISP_BUF_SIZE], buf1[DISP_BUF_SIZE];

    /*Initialize a descriptor for the buffer*/
    static lv_disp_draw_buf_t disp_buf;
    // lv_disp_draw_buf_init(&disp_buf, buf, NULL, DISP_BUF_SIZE);
    lv_disp_draw_buf_init(&disp_buf, buf, buf1, DISP_BUF_SIZE);

    /*Initialize and register a display driver*/
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    disp_drv.draw_buf   = &disp_buf;
    disp_drv.flush_cb   = drm_flush;
    disp_drv.hor_res    = 800;
    disp_drv.ver_res    = 1280;
    lv_disp_drv_register(&disp_drv);

    // evdev_init();
    // static lv_indev_drv_t indev_drv_1;
    // lv_indev_drv_init(&indev_drv_1); /*Basic initialization*/
    // indev_drv_1.type = LV_INDEV_TYPE_POINTER;

    /*This function will be called periodically (by the library) to get the mouse position and state*/
    // indev_drv_1.read_cb = evdev_read;
    // lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv_1);

#if 0

    /*Set a cursor for the mouse*/
    LV_IMG_DECLARE(mouse_cursor_icon)
    lv_obj_t * cursor_obj = lv_img_create(lv_scr_act()); /*Create an image object for the cursor */
    lv_img_set_src(cursor_obj, &mouse_cursor_icon);           /*Set the image source*/
    lv_indev_set_cursor(mouse_indev, cursor_obj);             /*Connect the image  object to the driver*/

#endif

    // lv_example_get_started_1();

    /*Handle LitlevGL tasks (tickless mode)*/
    while(1) {
        lv_timer_handler();
        usleep(5000);
    }

    return 0;
}

/*Set in lv_conf.h as `LV_TICK_CUSTOM_SYS_TIME_EXPR`*/
uint32_t custom_tick_get(void)
{
    static uint64_t start_ms = 0;
    if(start_ms == 0) {
        struct timeval tv_start;
        gettimeofday(&tv_start, NULL);
        start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
    }

    struct timeval tv_now;
    gettimeofday(&tv_now, NULL);
    uint64_t now_ms;
    now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;

    uint32_t time_ms = now_ms - start_ms;
    return time_ms;
}
SwordofMorning commented 2 years ago

It's a linking problem, in CML2, add:

LINK_LIBRARIES("/home/xjt/SF6_RV1126/RV1126/buildroot/output/rockchip_rv1126_rv1109_dcir/host/arm-linux-gnueabihf/sysroot/usr/lib/libdrm.so")

TARGET_LINK_LIBRARIES(demo libdrm.so)