How to use SDL dirver?

Description

How to use lvgl with SDL?

What MCU/Processor/Board and compiler are you using?

For now UBUNTU on intel

What do you want to achieve?

To use SDL driver

What have you tried so far?

Wyaland and windows driver

Code to reproduce

So the sdl driver is as this for my hal_init:

#if USE_SDL

#include <lvgl.h>
#include <sdl/sdl.h>

bool hal_init(void)
{
    sdl_init();
    /*Create a display buffer*/
    static lv_disp_draw_buf_t disp_buf1;
    static lv_color_t buf1_1[SDL_HOR_RES * 100];
    lv_disp_draw_buf_init(&disp_buf1, buf1_1, NULL, SDL_HOR_RES * 100);

    /*Create a display*/
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv); /*Basic initialization*/
    disp_drv.draw_buf = &disp_buf1;
    disp_drv.flush_cb = sdl_display_flush;
    disp_drv.hor_res = SDL_HOR_RES;
    disp_drv.ver_res = SDL_VER_RES;

    lv_disp_t * disp = lv_disp_drv_register(&disp_drv);
    lv_theme_t * th = lv_theme_default_init(disp, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), LV_THEME_DEFAULT_DARK, LV_FONT_DEFAULT);
    lv_disp_set_theme(disp, th);

    lv_group_t * g = lv_group_create();
    lv_group_set_default(g);
    LV_LOG_USER("SDL driver set.");
    return true;
}
#endif

The lvgl is crashing here:

It seems disp_refr is not well initialized. What am I doing wrong?

I would also like to try drm driver, is there any example on how to use this?

Thank you!

Ok, never mind.

I changed the code to the following and now it’s working:

#if USE_SDL

#include <lvgl.h>
#include <sdl/sdl.h>

bool hal_init(void)
{
    sdl_init();

    /*Create a display buffer*/
    static lv_disp_draw_buf_t disp_buf1;

    void * buf1 = lv_mem_alloc(SDL_HOR_RES * SDL_VER_RES * sizeof(lv_color_t));
    lv_disp_draw_buf_init(&disp_buf1, buf1, NULL, SDL_HOR_RES * SDL_VER_RES);

    /*Create a display*/
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv); /*Basic initialization*/
    disp_drv.draw_buf = &disp_buf1;
    disp_drv.flush_cb = sdl_display_flush;
    disp_drv.hor_res = SDL_HOR_RES;
    disp_drv.ver_res = SDL_VER_RES;

    lv_disp_t * disp = lv_disp_drv_register(&disp_drv);

    /* Register input */
    static lv_indev_drv_t lv_indev_drv_pointer;
    lv_indev_drv_pointer.type = LV_INDEV_TYPE_POINTER;
    lv_indev_drv_pointer.read_cb = sdl_mouse_read;
    lv_indev_t *mouse_indev = lv_indev_drv_register(&lv_indev_drv_pointer);


    lv_theme_t * th = lv_theme_default_init(disp,
                                            lv_palette_main(LV_PALETTE_BLUE),
                                            lv_palette_main(LV_PALETTE_RED),
                                            LV_THEME_DEFAULT_DARK,
                                            LV_FONT_DEFAULT);
    lv_disp_set_theme(disp, th);

    lv_group_t * g = lv_group_create();
    lv_group_set_default(g);
    LV_LOG_USER("SDL driver set.");
    return true;
}
#endif

I haven’t tried yet on my hardware, but does this SDL driver support touch events?
Thanks

I think SDL support touch events. You should check if your hardware environment has correct device tree and SDL lib firstly.
Try ls /dev/input/

Thank you. The sdl_mouse_read callback did the trick. It was enough to have touch events.