added x11 support for lowlevel display support
the x11 driver has been added to the lv_library repository. Now both variants (SDL/X11) can be selected in the Makefile. Additional fixes here have been applied. select X11 by default
This commit is contained in:
parent
465cbdd3fe
commit
7a83e60683
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +1,6 @@
|
|||||||
|
[submodule "lv_drivers"]
|
||||||
|
path = lv_drivers
|
||||||
|
url = https://github.com/gcopoix/lv_drivers.git
|
||||||
[submodule "lvgl"]
|
[submodule "lvgl"]
|
||||||
path = lvgl
|
path = lvgl
|
||||||
url = https://github.com/lvgl/lvgl.git
|
url = https://github.com/lvgl/lvgl.git
|
||||||
|
|||||||
23
.vscode/c_cpp_properties.json
vendored
23
.vscode/c_cpp_properties.json
vendored
@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Linux",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**"
|
|
||||||
],
|
|
||||||
"defines": [],
|
|
||||||
"intelliSenseMode": "gcc-x64",
|
|
||||||
"browse": {
|
|
||||||
"path": [
|
|
||||||
"${workspaceFolder}/**"
|
|
||||||
],
|
|
||||||
"limitSymbolsToIncludedHeaders": true,
|
|
||||||
"databaseFilename": ""
|
|
||||||
},
|
|
||||||
"compilerPath": "/usr/bin/gcc",
|
|
||||||
"cStandard": "c11",
|
|
||||||
"cppStandard": "c++17"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
3
.vscode/extensions.json
vendored
3
.vscode/extensions.json
vendored
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"recommendations": ["ms-vscode.cpptools"]
|
|
||||||
}
|
|
||||||
25
.vscode/launch.json
vendored
25
.vscode/launch.json
vendored
@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "g++ build and debug active file",
|
|
||||||
"type": "cppdbg",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceFolder}/build/bin/demo",
|
|
||||||
"args": [],
|
|
||||||
"stopAtEntry": false,
|
|
||||||
"cwd": "${workspaceFolder}",
|
|
||||||
"environment": [],
|
|
||||||
"externalConsole": false,
|
|
||||||
"MIMode": "gdb",
|
|
||||||
"setupCommands": [
|
|
||||||
{
|
|
||||||
"description": "Enable pretty-printing for gdb",
|
|
||||||
"text": "-enable-pretty-printing",
|
|
||||||
"ignoreFailures": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"preLaunchTask": "Build"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
38
.vscode/tasks.json
vendored
38
.vscode/tasks.json
vendored
@ -1,38 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "2.0.0",
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"type": "shell",
|
|
||||||
"label": "Build",
|
|
||||||
"command": "make",
|
|
||||||
"options": {
|
|
||||||
"cwd": "${workspaceFolder}"
|
|
||||||
},
|
|
||||||
"presentation": {
|
|
||||||
"echo": true,
|
|
||||||
"reveal": "always",
|
|
||||||
"focus": false,
|
|
||||||
"panel": "shared"
|
|
||||||
},
|
|
||||||
"problemMatcher": {
|
|
||||||
"owner": "cpp",
|
|
||||||
"fileLocation": [
|
|
||||||
"relative",
|
|
||||||
"${workspaceFolder}"
|
|
||||||
],
|
|
||||||
"pattern": {
|
|
||||||
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
|
|
||||||
"file": 1,
|
|
||||||
"line": 2,
|
|
||||||
"column": 3,
|
|
||||||
"severity": 4,
|
|
||||||
"message": 5
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"group": {
|
|
||||||
"kind": "build",
|
|
||||||
"isDefault": true
|
|
||||||
},
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
26
Makefile
26
Makefile
@ -3,7 +3,12 @@
|
|||||||
# WARNING: relies on invocation setting current working directory to Makefile location
|
# WARNING: relies on invocation setting current working directory to Makefile location
|
||||||
# This is done in .vscode/task.json
|
# This is done in .vscode/task.json
|
||||||
#
|
#
|
||||||
PROJECT ?= lvgl-sdl
|
|
||||||
|
# select underlaying LCGL display driver (SDL2 || X11)
|
||||||
|
LV_DRIVER := X11
|
||||||
|
#LV_DRIVER := SDL2
|
||||||
|
|
||||||
|
PROJECT ?= lvgl-demo
|
||||||
MAKEFLAGS := -j $(shell nproc)
|
MAKEFLAGS := -j $(shell nproc)
|
||||||
SRC_EXT := c
|
SRC_EXT := c
|
||||||
OBJ_EXT := o
|
OBJ_EXT := o
|
||||||
@ -25,12 +30,19 @@ WARNINGS := -Wall -Wextra \
|
|||||||
|
|
||||||
CFLAGS := -O0 -g $(WARNINGS)
|
CFLAGS := -O0 -g $(WARNINGS)
|
||||||
|
|
||||||
# Add simulator define to allow modification of source
|
# simulator library define
|
||||||
DEFINES := -D SIMULATOR=1 -D LV_BUILD_TEST=0
|
ifeq "$(LV_DRIVER)" "SDL2"
|
||||||
|
LV_DRIVER_USE := USE_SDL
|
||||||
|
else
|
||||||
|
LV_DRIVER_USE := USE_$(LV_DRIVER)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Add simulator defines to allow modification of source
|
||||||
|
DEFINES := -D SIMULATOR=1 -D LV_BUILD_TEST=0 -D $(LV_DRIVER_USE)
|
||||||
|
|
||||||
# Include simulator inc folder first so lv_conf.h from custom UI can be used instead
|
# Include simulator inc folder first so lv_conf.h from custom UI can be used instead
|
||||||
INC := -I./ui/simulator/inc/ -I./ -I./lvgl/ #-I/usr/include/freetype2 -L/usr/local/lib
|
INC := -I./ui/simulator/inc/ -I./ -I./lvgl/ #-I/usr/include/freetype2 -L/usr/local/lib
|
||||||
LDLIBS := -lSDL2 -lm #-lfreetype -lavformat -lavcodec -lavutil -lswscale -lm -lz -lpthread
|
LDLIBS := -l$(LV_DRIVER) -lpthread -lm #-lfreetype -lavformat -lavcodec -lavutil -lswscale -lm -lz
|
||||||
BIN := $(BIN_DIR)/demo
|
BIN := $(BIN_DIR)/demo
|
||||||
|
|
||||||
COMPILE = $(CC) $(CFLAGS) $(INC) $(DEFINES)
|
COMPILE = $(CC) $(CFLAGS) $(INC) $(DEFINES)
|
||||||
@ -39,14 +51,14 @@ COMPILE = $(CC) $(CFLAGS) $(INC) $(DEFINES)
|
|||||||
SRCS := $(shell find $(SRC_DIR) -type f -name '*.c' -not -path '*/\.*')
|
SRCS := $(shell find $(SRC_DIR) -type f -name '*.c' -not -path '*/\.*')
|
||||||
OBJECTS := $(patsubst $(SRC_DIR)%,$(BUILD_DIR)/%,$(SRCS:.$(SRC_EXT)=.$(OBJ_EXT)))
|
OBJECTS := $(patsubst $(SRC_DIR)%,$(BUILD_DIR)/%,$(SRCS:.$(SRC_EXT)=.$(OBJ_EXT)))
|
||||||
|
|
||||||
all: default
|
all: $(BIN)
|
||||||
|
|
||||||
$(BUILD_DIR)/%.$(OBJ_EXT): $(SRC_DIR)/%.$(SRC_EXT)
|
$(BUILD_DIR)/%.$(OBJ_EXT): $(SRC_DIR)/%.$(SRC_EXT) lv_demo_conf.h lv_conf.h Makefile
|
||||||
@echo 'Building project file: $<'
|
@echo 'Building project file: $<'
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
@$(COMPILE) -c -o "$@" "$<"
|
@$(COMPILE) -c -o "$@" "$<"
|
||||||
|
|
||||||
default: $(OBJECTS)
|
$(BIN): $(OBJECTS)
|
||||||
@mkdir -p $(BIN_DIR)
|
@mkdir -p $(BIN_DIR)
|
||||||
$(CC) -o $(BIN) $(OBJECTS) $(LDFLAGS) ${LDLIBS}
|
$(CC) -o $(BIN) $(OBJECTS) $(LDFLAGS) ${LDLIBS}
|
||||||
|
|
||||||
|
|||||||
31
README.md
31
README.md
@ -9,11 +9,12 @@ Using a PC simulator instead of an embedded hardware has several advantages:
|
|||||||
* **Developer friendly** because much easier and faster to debug on PC
|
* **Developer friendly** because much easier and faster to debug on PC
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
This project is configured for VSCode and only tested on Linux, although this may work on OSx or WSL. It requires a working version of GCC, GDB and make in your path.
|
This project is configured for [VSCode](https://code.visualstudio.com) and only tested on Linux, although this may work on OSx or WSL. It requires a working version of GCC, GDB and make in your path.
|
||||||
|
|
||||||
To allow debugging inside VSCode you will also require a GDB [extension](https://marketplace.visualstudio.com/items?itemName=webfreak.debug) or other suitable debugger.
|
To allow debugging inside VSCode you will also require a GDB [extension](https://marketplace.visualstudio.com/items?itemName=webfreak.debug) or other suitable debugger. All the requirements have been pre-configured in the [.workspace](simulator.code-workspace) file (simply open the project by doubleclick on this file).
|
||||||
|
|
||||||
* **SDL** a low level driver library to use graphics, handle mouse, keyboard etc.
|
The project can use **SDL** or **X11** as LVGL display driver for lowlevel graphics/mouse/keyboard support. This can be defined in the [Makefile](Makefile#L8).
|
||||||
|
Please make sure the selected library is installed in the system (check [Install graphics driver](#install-graphics-driver)).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -25,7 +26,11 @@ Clone the PC project and the related sub modules:
|
|||||||
git clone --recursive https://github.com/lvgl/lv_port_pc_vscode
|
git clone --recursive https://github.com/lvgl/lv_port_pc_vscode
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install SDL
|
### Install graphics driver
|
||||||
|
The project can use **SDL** or **X11** as LVGL display driver. This can be selected in the [Makefile](Makefile#L8).
|
||||||
|
Please make sure the used library is installed in the system:
|
||||||
|
|
||||||
|
#### Install SDL
|
||||||
You can download SDL from https://www.libsdl.org/
|
You can download SDL from https://www.libsdl.org/
|
||||||
|
|
||||||
On on Linux you can install it via terminal:
|
On on Linux you can install it via terminal:
|
||||||
@ -33,6 +38,12 @@ On on Linux you can install it via terminal:
|
|||||||
sudo apt-get update && sudo apt-get install -y build-essential libsdl2-dev
|
sudo apt-get update && sudo apt-get install -y build-essential libsdl2-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Install X11
|
||||||
|
On on Linux you can install it via terminal:
|
||||||
|
```bash
|
||||||
|
sudo apt-get update && sudo apt-get install -y libx11-dev
|
||||||
|
```
|
||||||
|
|
||||||
### Optional library
|
### Optional library
|
||||||
There are also FreeType and FFmpeg support. You can install FreeType support with:
|
There are also FreeType and FFmpeg support. You can install FreeType support with:
|
||||||
```bash
|
```bash
|
||||||
@ -55,10 +66,16 @@ make
|
|||||||
sudo make install
|
sudo make install
|
||||||
```
|
```
|
||||||
|
|
||||||
And then remove all the comments in the `Makefile` on `INC` and `LDLIBS` lines. They should be:
|
And then remove all the comments in the `Makefile` on `INC` and `LDLIBS` lines. \
|
||||||
|
They should be for **SDL**:
|
||||||
```Makefile
|
```Makefile
|
||||||
INC := -I./ui/simulator/inc/ -I./ -I./lvgl/ -I/usr/include/freetype2 -L/usr/local/lib
|
INC := -I./ui/simulator/inc/ -I./ -I./lvgl/ -I/usr/include/freetype2 -L/usr/local/lib
|
||||||
LDLIBS := -lSDL2 -lm -lfreetype -lavformat -lavcodec -lavutil -lswscale -lm -lz -lpthread
|
LDLIBS := -lSDL2 -lm -lfreetype -lavformat -lavcodec -lavutil -lswscale -lm -lz -lpthread
|
||||||
|
```
|
||||||
|
They should be for **X11**:
|
||||||
|
```Makefile
|
||||||
|
INC := -I./ui/simulator/inc/ -I./ -I./lvgl/ -I/usr/include/freetype2 -L/usr/local/lib
|
||||||
|
LDLIBS := -lX11 -lm -lfreetype -lavformat -lavcodec -lavutil -lswscale -lm -lz -lpthread
|
||||||
```
|
```
|
||||||
|
|
||||||
### Setup
|
### Setup
|
||||||
|
|||||||
@ -12,6 +12,11 @@
|
|||||||
#ifndef LV_EX_CONF_H
|
#ifndef LV_EX_CONF_H
|
||||||
#define LV_EX_CONF_H
|
#define LV_EX_CONF_H
|
||||||
|
|
||||||
|
/*====================
|
||||||
|
SIMULATION SETTINGS
|
||||||
|
*====================*/
|
||||||
|
#define DISP_HOR_RES 800
|
||||||
|
#define DISP_VER_RES 600
|
||||||
|
|
||||||
/*******************
|
/*******************
|
||||||
* GENERAL SETTING
|
* GENERAL SETTING
|
||||||
@ -53,4 +58,3 @@
|
|||||||
#endif /*LV_EX_CONF_H*/
|
#endif /*LV_EX_CONF_H*/
|
||||||
|
|
||||||
#endif /*End of "Content enable"*/
|
#endif /*End of "Content enable"*/
|
||||||
|
|
||||||
|
|||||||
1
lv_drivers
Submodule
1
lv_drivers
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 60887240447d061d0d84c95f0ce8dd810b706456
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @file lv_drv_conf.h
|
* @file lv_drv_conf.h
|
||||||
* Configuration file for v8.3.0
|
* Configuration file for v9.0.0-dev
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -86,7 +86,7 @@
|
|||||||
|
|
||||||
/* SDL based drivers for display, mouse, mousewheel and keyboard*/
|
/* SDL based drivers for display, mouse, mousewheel and keyboard*/
|
||||||
#ifndef USE_SDL
|
#ifndef USE_SDL
|
||||||
# define USE_SDL 1
|
# define USE_SDL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Hardware accelerated SDL driver */
|
/* Hardware accelerated SDL driver */
|
||||||
@ -113,6 +113,9 @@
|
|||||||
|
|
||||||
/*Open two windows to test multi display support*/
|
/*Open two windows to test multi display support*/
|
||||||
# define SDL_DUAL_DISPLAY 0
|
# define SDL_DUAL_DISPLAY 0
|
||||||
|
|
||||||
|
/* Window Title */
|
||||||
|
# define SDL_WINDOW_TITLE "TFT Simulator"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-------------------
|
/*-------------------
|
||||||
@ -195,6 +198,23 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*----------------------------------------
|
||||||
|
* X11 drivers (monitor, mouse, keyboard)
|
||||||
|
*---------------------------------------*/
|
||||||
|
#ifndef USE_X11
|
||||||
|
# define USE_X11 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if USE_X11
|
||||||
|
/* Simulated screen resolution */
|
||||||
|
#ifndef DISP_HOR_RES
|
||||||
|
#define DISP_HOR_RES 480
|
||||||
|
#endif
|
||||||
|
#ifndef DISP_VER_RES
|
||||||
|
#define DISP_VER_RES 320
|
||||||
|
#endif
|
||||||
|
#endif // USE_X11
|
||||||
|
|
||||||
/*----------------
|
/*----------------
|
||||||
* SSD1963
|
* SSD1963
|
||||||
*--------------*/
|
*--------------*/
|
||||||
@ -323,8 +343,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if USE_FBDEV
|
#if USE_FBDEV
|
||||||
# define FBDEV_PATH "/dev/fb0"
|
# define FBDEV_PATH "/dev/fb0"
|
||||||
# define FBDEV_DISPLAY_POWER_ON 1 /* 1 to force display power during initialization */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------
|
/*-----------------------------------------
|
||||||
@ -335,8 +354,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if USE_BSD_FBDEV
|
#if USE_BSD_FBDEV
|
||||||
# define FBDEV_PATH "/dev/fb0"
|
# define FBDEV_PATH "/dev/fb0"
|
||||||
# define FBDEV_DISPLAY_POWER_ON 1 /* 1 to force display power during initialization */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-----------------------------------------
|
/*-----------------------------------------
|
||||||
|
|||||||
143
main/src/main.c
143
main/src/main.c
@ -10,12 +10,18 @@
|
|||||||
#define _DEFAULT_SOURCE /* needed for usleep() */
|
#define _DEFAULT_SOURCE /* needed for usleep() */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
|
#include <pthread.h>
|
||||||
#include <SDL2/SDL.h>
|
#include "lv_drv_conf.h"
|
||||||
#include "lvgl/lvgl.h"
|
#include "lvgl/lvgl.h"
|
||||||
#include "lvgl/examples/lv_examples.h"
|
#include "lvgl/examples/lv_examples.h"
|
||||||
#include "lvgl/demos/lv_demos.h"
|
#include "lvgl/demos/lv_demos.h"
|
||||||
#include "lv_drivers/sdl/sdl.h"
|
#if USE_SDL
|
||||||
|
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include "lv_drivers/sdl/sdl.h"
|
||||||
|
#elif USE_X11
|
||||||
|
#include "lv_drivers/x11/x11.h"
|
||||||
|
#endif
|
||||||
// #include "lv_drivers/display/monitor.h"
|
// #include "lv_drivers/display/monitor.h"
|
||||||
// #include "lv_drivers/indev/mouse.h"
|
// #include "lv_drivers/indev/mouse.h"
|
||||||
// #include "lv_drivers/indev/keyboard.h"
|
// #include "lv_drivers/indev/keyboard.h"
|
||||||
@ -33,11 +39,14 @@
|
|||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
static void hal_init(void);
|
static void hal_init(void);
|
||||||
static int tick_thread(void *data);
|
static void hal_deinit(void);
|
||||||
|
static void* tick_thread(void *data);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
|
static pthread_t thr_tick; /* thread */
|
||||||
|
static bool end_tick = false; /* flag to terminate thread */
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
@ -197,6 +206,7 @@ int main(int argc, char **argv)
|
|||||||
usleep(5 * 1000);
|
usleep(5 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hal_deinit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,12 +220,29 @@ int main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
static void hal_init(void)
|
static void hal_init(void)
|
||||||
{
|
{
|
||||||
|
/* mouse input device */
|
||||||
|
static lv_indev_drv_t indev_drv_1;
|
||||||
|
lv_indev_drv_init(&indev_drv_1);
|
||||||
|
indev_drv_1.type = LV_INDEV_TYPE_POINTER;
|
||||||
|
|
||||||
|
/* keyboard input device */
|
||||||
|
static lv_indev_drv_t indev_drv_2;
|
||||||
|
lv_indev_drv_init(&indev_drv_2);
|
||||||
|
indev_drv_2.type = LV_INDEV_TYPE_KEYPAD;
|
||||||
|
|
||||||
|
/* mouse scroll wheel input device */
|
||||||
|
static lv_indev_drv_t indev_drv_3;
|
||||||
|
lv_indev_drv_init(&indev_drv_3);
|
||||||
|
indev_drv_3.type = LV_INDEV_TYPE_ENCODER;
|
||||||
|
|
||||||
|
lv_group_t *g = lv_group_create();
|
||||||
|
lv_group_set_default(g);
|
||||||
|
|
||||||
|
lv_disp_t *disp = NULL;
|
||||||
|
|
||||||
|
#if USE_SDL
|
||||||
/* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/
|
/* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/
|
||||||
sdl_init();
|
sdl_init();
|
||||||
/* Tick init.
|
|
||||||
* You have to call 'lv_tick_inc()' in periodically to inform LittelvGL about
|
|
||||||
* how much time were elapsed Create an SDL thread to do this*/
|
|
||||||
SDL_CreateThread(tick_thread, "tick", NULL);
|
|
||||||
|
|
||||||
/*Create a display buffer*/
|
/*Create a display buffer*/
|
||||||
static lv_disp_draw_buf_t disp_buf1;
|
static lv_disp_draw_buf_t disp_buf1;
|
||||||
@ -232,46 +259,78 @@ static void hal_init(void)
|
|||||||
disp_drv.ver_res = MONITOR_VER_RES;
|
disp_drv.ver_res = MONITOR_VER_RES;
|
||||||
disp_drv.antialiasing = 1;
|
disp_drv.antialiasing = 1;
|
||||||
|
|
||||||
lv_disp_t * disp = lv_disp_drv_register(&disp_drv);
|
disp = lv_disp_drv_register(&disp_drv);
|
||||||
|
|
||||||
|
/* Add the input device driver */
|
||||||
|
// mouse_init();
|
||||||
|
indev_drv_1.read_cb = sdl_mouse_read;
|
||||||
|
|
||||||
|
// keyboard_init();
|
||||||
|
indev_drv_2.read_cb = sdl_keyboard_read;
|
||||||
|
|
||||||
|
// mousewheel_init();
|
||||||
|
indev_drv_3.read_cb = sdl_mousewheel_read;
|
||||||
|
|
||||||
|
#elif USE_X11
|
||||||
|
lv_x11_init("LVGL Simulator Demo", DISP_HOR_RES, DISP_VER_RES);
|
||||||
|
|
||||||
|
/*Create a display buffer*/
|
||||||
|
static lv_disp_draw_buf_t disp_buf1;
|
||||||
|
static lv_color_t buf1_1[DISP_HOR_RES * 100];
|
||||||
|
static lv_color_t buf1_2[DISP_HOR_RES * 100];
|
||||||
|
lv_disp_draw_buf_init(&disp_buf1, buf1_1, buf1_2, DISP_HOR_RES * 100);
|
||||||
|
|
||||||
|
/*Create a display*/
|
||||||
|
static lv_disp_drv_t disp_drv;
|
||||||
|
lv_disp_drv_init(&disp_drv);
|
||||||
|
disp_drv.draw_buf = &disp_buf1;
|
||||||
|
disp_drv.flush_cb = lv_x11_flush;
|
||||||
|
disp_drv.hor_res = DISP_HOR_RES;
|
||||||
|
disp_drv.ver_res = DISP_VER_RES;
|
||||||
|
disp_drv.antialiasing = 1;
|
||||||
|
|
||||||
|
disp = lv_disp_drv_register(&disp_drv);
|
||||||
|
|
||||||
|
/* Add the input device driver */
|
||||||
|
indev_drv_1.read_cb = lv_x11_get_pointer;
|
||||||
|
indev_drv_2.read_cb = lv_x11_get_keyboard;
|
||||||
|
indev_drv_3.read_cb = lv_x11_get_mousewheel;
|
||||||
|
#endif
|
||||||
|
/* Set diplay theme */
|
||||||
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_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_disp_set_theme(disp, th);
|
||||||
|
|
||||||
lv_group_t * g = lv_group_create();
|
/* Tick init */
|
||||||
lv_group_set_default(g);
|
end_tick = false;
|
||||||
|
pthread_create(&thr_tick, NULL, tick_thread, NULL);
|
||||||
|
|
||||||
/* Add the mouse as input device
|
/* register input devices */
|
||||||
* Use the 'mouse' driver which reads the PC's mouse*/
|
|
||||||
// mouse_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 = sdl_mouse_read;
|
|
||||||
lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv_1);
|
lv_indev_t *mouse_indev = lv_indev_drv_register(&indev_drv_1);
|
||||||
|
|
||||||
// keyboard_init();
|
|
||||||
static lv_indev_drv_t indev_drv_2;
|
|
||||||
lv_indev_drv_init(&indev_drv_2); /*Basic initialization*/
|
|
||||||
indev_drv_2.type = LV_INDEV_TYPE_KEYPAD;
|
|
||||||
indev_drv_2.read_cb = sdl_keyboard_read;
|
|
||||||
lv_indev_t *kb_indev = lv_indev_drv_register(&indev_drv_2);
|
lv_indev_t *kb_indev = lv_indev_drv_register(&indev_drv_2);
|
||||||
|
lv_indev_t *enc_indev = lv_indev_drv_register(&indev_drv_3);
|
||||||
lv_indev_set_group(kb_indev, g);
|
lv_indev_set_group(kb_indev, g);
|
||||||
// mousewheel_init();
|
|
||||||
static lv_indev_drv_t indev_drv_3;
|
|
||||||
lv_indev_drv_init(&indev_drv_3); /*Basic initialization*/
|
|
||||||
indev_drv_3.type = LV_INDEV_TYPE_ENCODER;
|
|
||||||
indev_drv_3.read_cb = sdl_mousewheel_read;
|
|
||||||
|
|
||||||
lv_indev_t * enc_indev = lv_indev_drv_register(&indev_drv_3);
|
|
||||||
lv_indev_set_group(enc_indev, g);
|
lv_indev_set_group(enc_indev, g);
|
||||||
|
|
||||||
/*Set a cursor for the mouse*/
|
/* Set a cursor for the mouse */
|
||||||
LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
|
LV_IMG_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
|
||||||
lv_obj_t * cursor_obj = lv_img_create(lv_scr_act()); /*Create an image object for the cursor */
|
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_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*/
|
lv_indev_set_cursor(mouse_indev, cursor_obj); /*Connect the image object to the driver*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases the Hardware Abstraction Layer (HAL) for the LVGL graphics library
|
||||||
|
*/
|
||||||
|
static void hal_deinit(void)
|
||||||
|
{
|
||||||
|
end_tick = true;
|
||||||
|
pthread_join(thr_tick, NULL);
|
||||||
|
|
||||||
|
#if USE_SDL
|
||||||
|
// nop
|
||||||
|
#elif USE_X11
|
||||||
|
lv_x11_deinit();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -279,13 +338,13 @@ static void hal_init(void)
|
|||||||
* @param data unused
|
* @param data unused
|
||||||
* @return never return
|
* @return never return
|
||||||
*/
|
*/
|
||||||
static int tick_thread(void *data) {
|
static void* tick_thread(void *data) {
|
||||||
(void)data;
|
(void)data;
|
||||||
|
|
||||||
while(1) {
|
while(!end_tick) {
|
||||||
SDL_Delay(5);
|
usleep(5000);
|
||||||
lv_tick_inc(5); /*Tell LittelvGL that 5 milliseconds were elapsed*/
|
lv_tick_inc(5); /*Tell LittelvGL that 5 milliseconds were elapsed*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,75 @@
|
|||||||
{
|
{
|
||||||
|
// https://code.visualstudio.com/docs/editor/workspaces
|
||||||
|
// https://code.visualstudio.com/docs/editor/multi-root-workspaces
|
||||||
|
// https://code.visualstudio.com/docs/editor/variables-reference
|
||||||
|
|
||||||
"folders": [
|
"folders": [
|
||||||
{
|
{
|
||||||
"path": "./"
|
"path": "."
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
|
// extensions.json section
|
||||||
|
"extensions": {
|
||||||
|
"recommendations": [
|
||||||
|
"ms-vscode.cpptools", // common C/C++ support
|
||||||
|
"ms-vscode.cpptools-themes", // general C/C++ theme
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
]
|
||||||
|
},
|
||||||
|
// settings.json section
|
||||||
"settings": {
|
"settings": {
|
||||||
|
"files.trimTrailingWhitespace": true,
|
||||||
|
"files.insertFinalNewline": true,
|
||||||
|
"files.trimFinalNewlines": true,
|
||||||
|
"cmake.configureOnOpen": false,
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"cstdio": "cpp",
|
"lv_demos.h": "c",
|
||||||
"cstdarg": "cpp"
|
"lvgl.h": "c",
|
||||||
|
"lv_drv_conf.h": "c",
|
||||||
|
"stdlib.h": "c"
|
||||||
},
|
},
|
||||||
"search.exclude": {
|
},
|
||||||
"**/.*": true,
|
// tasks.json section
|
||||||
"build": true
|
"tasks": {
|
||||||
},
|
"version": "2.0.0",
|
||||||
"search.useIgnoreFiles": false
|
"tasks": [
|
||||||
}
|
{
|
||||||
|
"label": "Build",
|
||||||
|
"command": "make",
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"problemMatcher": {
|
||||||
|
"owner": "cpp",
|
||||||
|
"fileLocation": ["relative", "${workspaceFolder}"],
|
||||||
|
"pattern": {
|
||||||
|
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"severity": 4,
|
||||||
|
"message": 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
// launch.json section
|
||||||
|
"launch": {
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Debug LVGL demo with gdb",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/build/bin/demo",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${fileDirname}",
|
||||||
|
"preLaunchTask": "Build",
|
||||||
|
"stopAtEntry": false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user