Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split backends #63

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ set(CMAKE_CXX_STANDARD 17) #C17
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
add_subdirectory(lvgl)
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR})

target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/src)

file(GLOB SIM_SRC src/*.c)

if (LV_USE_LINUX_DRM)

find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBDRM REQUIRED libdrm)

target_include_directories(lvgl PUBLIC ${LIBDRM_INCLUDE_DIRS})
add_executable(lvglsim main.c mouse_cursor_icon.c)
add_executable(lvglsim ${SIM_SRC} src/backends/drm.c)
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg ${LIBDRM_LIBRARIES} m pthread)

elseif (LV_USE_SDL)
Expand All @@ -33,7 +36,7 @@ elseif (LV_USE_SDL)

target_include_directories(lvgl PRIVATE ${SDL2_INCLUDE_DIRS})
target_include_directories(lvgl PRIVATE ${SDL2_IMAGE_INCLUDE_DIRS})
add_executable(lvglsim main.c mouse_cursor_icon.c)
add_executable(lvglsim ${SIM_SRC} src/backends/sdl.c)
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} m pthread)

elseif (LV_USE_WAYLAND)
Expand All @@ -51,17 +54,17 @@ elseif (LV_USE_WAYLAND)

target_include_directories(lvgl PRIVATE ${PROJECT_SOURCE_DIR}
"${PROJECT_SOURCE_DIR}/wl_protocols")
add_executable(lvglsim main.c ${WAYLAND_PROTOCOLS_SRC}
mouse_cursor_icon.c backends/wayland.c)
add_executable(lvglsim ${SIM_SRC} ${WAYLAND_PROTOCOLS_SRC} src/backends/wayland.c)
target_compile_definitions(lvglsim PRIVATE LV_CONF_INCLUDE_SIMPLE)
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg m
wayland-client wayland-cursor xkbcommon)

else()
elseif (LV_USE_LINUX_FBDEV)

# No specific build steps required for FBDEV
add_executable(lvglsim main.c mouse_cursor_icon.c)
add_executable(lvglsim ${SIM_SRC} src/backends/fbdev.c)
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg m pthread)

endif()

add_custom_target (run COMMAND ${EXECUTABLE_OUTPUT_PATH}/lvglsim DEPENDS lvglsim)
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ WARNINGS := -Wall -Wshadow -Wundef -Wmissing-prototypes -Wno-discarded-qualifie
-Wsizeof-pointer-memaccess -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default -Wreturn-type -Wmultichar -Wformat-security \
-Wno-ignored-qualifiers -Wno-error=pedantic -Wno-sign-compare -Wno-error=missing-prototypes -Wdouble-promotion -Wclobbered -Wdeprecated -Wempty-body \
-Wshift-negative-value -Wstack-usage=2048 -Wno-unused-value -std=gnu99
CFLAGS ?= -O3 -g0 -I$(LVGL_DIR)/ $(WARNINGS)
CFLAGS ?= -O3 -g0 -I$(LVGL_DIR) -I$(LVGL_DIR)/src -I${LVGL_DIR}/src/backend $(WARNINGS)
LDFLAGS ?= -lm
BIN = main
BUILD_DIR = ./build
Expand All @@ -21,11 +21,11 @@ prefix ?= /usr
bindir ?= $(prefix)/bin

#Collect the files to compile
MAINSRC = ./main.c
MAINSRC = ./src/main.c

include $(LVGL_DIR)/lvgl/lvgl.mk

CSRCS +=$(LVGL_DIR)/mouse_cursor_icon.c
CSRCS +=$(LVGL_DIR)/src/mouse_cursor_icon.c ${LVGL_DIR}/src/util.c ${LVGL_DIR}/src/backends/fbdev.c

OBJEXT ?= .o

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ To use wayland, adjust `lv_conf.h` as follows:
#define LV_USE_WAYLAND 1
```


### cmake

```
Expand Down
11 changes: 0 additions & 11 deletions backends/settings.h

This file was deleted.

37 changes: 37 additions & 0 deletions src/backends/drm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file drm.c
*
* The libdrm backend
*
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>

#include "lvgl/lvgl.h"
#include "settings.h"
#include "util.h"

void lv_linux_disp_init(void)
{
const char *device = getenv_default("LV_LINUX_DRM_CARD", "/dev/dri/card0");
lv_display_t * disp = lv_linux_drm_create();

if (disp == NULL) {
die("Failed to initialize DRM backend\n");
}

lv_linux_drm_set_file(disp, device, -1);
}

void lv_linux_run_loop(void)
{
uint32_t idle_time;

/* Handle LVGL tasks */
while (true) {

idle_time = lv_timer_handler(); /* Returns the time to the next timer execution */
usleep(idle_time * 1000);
}
}
37 changes: 37 additions & 0 deletions src/backends/fbdev.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file fbdev.c
*
* The backend for the legacy framebuffer device
*
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>

#include "lvgl/lvgl.h"
#include "settings.h"
#include "util.h"

void lv_linux_disp_init(void)
{
const char *device = getenv_default("LV_LINUX_FBDEV_DEVICE", "/dev/fb0");
lv_display_t * disp = lv_linux_fbdev_create();

if (disp == NULL) {
die("Failed to initialize FBDEV backend\n");
}

lv_linux_fbdev_set_file(disp, device);
}

void lv_linux_run_loop(void)
{
uint32_t idle_time;

/* Handle LVGL tasks */
while (true) {

idle_time = lv_timer_handler(); /* Returns the time to the next timer execution */
usleep(idle_time * 1000);
}
}
7 changes: 7 additions & 0 deletions backends/interface.h → src/backends/interface.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* @file interface.h
*
* Declares the functions that a backend
* has to implement
*
*/

/* Enters the run loop of the selected backend */
void lv_linux_run_loop(void);
Expand Down
35 changes: 35 additions & 0 deletions src/backends/sdl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file sdl.c
*
* The SDL backend
*
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>

#include "lvgl/lvgl.h"
#include "settings.h"

void lv_linux_disp_init(void)
{
lv_display_t *disp;

disp = lv_sdl_window_create(window_width, window_height);

if (disp == NULL) {
die("Failed to initialize the SDL backend\n");
}
}

void lv_linux_run_loop(void)
{
uint32_t idle_time;

/* Handle LVGL tasks */
while (true) {

idle_time = lv_timer_handler(); /* Returns the time to the next timer execution */
usleep(idle_time * 1000);
}
}
30 changes: 30 additions & 0 deletions src/backends/settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @file settings.h
*
* Must be included in each backend files
* Declares variables that are defined in the main file
* Those variables contain simulator settings, such as screen size etc
*/

#include <stdbool.h>
#include <stdint.h>

/* Catch configuration errors at compile time */
#if LV_USE_SDL == 0 && \
LV_USE_WAYLAND == 0 && \
LV_USE_LINUX_DRM == 0 && \
LV_USE_LINUX_FBDEV == 0

#error Unsupported configuration - Please select at least one backend in lv_conf.h

#endif

/* Settings defined in main.c */

extern uint16_t window_width;
extern uint16_t window_height;

extern bool fullscreen;
extern bool maximize;


15 changes: 14 additions & 1 deletion backends/wayland.c → src/backends/wayland.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
/**
* @file wayland.c
*
* The wayland backend
*
*/
#include <unistd.h>
#include <stdbool.h>
#include <stdlib.h>

#include "lvgl/lvgl.h"
#include "settings.h"
#include "util.h"

/* Currently, the wayland driver calls lv_timer_handler internaly */
/* The wayland driver needs to be re-written to match the other backends */
void lv_linux_run_loop(void)
{

bool completed;

/* Handle LVGL tasks */
while (1) {
while (true) {

completed = lv_wayland_timer_handler();

Expand All @@ -36,6 +45,10 @@ void lv_linux_disp_init(void)
disp = lv_wayland_window_create(window_width, window_height,
"LVGL Simulator", NULL);

if (disp == NULL) {
die("Failed to initialize Wayland backend\n");
}

if (fullscreen) {
lv_wayland_window_set_fullscreen(disp, fullscreen);
} else if (maximize) {
Expand Down
Loading
Loading