Initial commit
This commit is contained in:
commit
9f36b6f556
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
build
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "PSE-firmware"]
|
||||||
|
path = PSE-firmware
|
||||||
|
url = ssh://git@git.leserveurdansmongrenier.uk:16822/leo/PSE-firmware.git
|
23
CMakeLists.txt
Normal file
23
CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(lvgl)
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
|
||||||
|
|
||||||
|
file(GLOB_RECURSE INCLUDES "./*.h" )
|
||||||
|
|
||||||
|
SET(CMAKE_CXX_FLAGS "-O3")
|
||||||
|
|
||||||
|
find_package(SDL2 REQUIRED SDL2)
|
||||||
|
include_directories(${SDL2_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
add_subdirectory(PSE-firmware/Drivers/lvgl)
|
||||||
|
include_directories(PSE-firmware/Core/Inc)
|
||||||
|
add_executable(main main.c PSE-firmware/Core/Src/logo_mint_resize.c ${SOURCES} ${INCLUDES})
|
||||||
|
add_compile_definitions(LV_CONF_INCLUDE_SIMPLE)
|
||||||
|
target_link_libraries(main PRIVATE lvgl ${SDL2_LIBRARIES})
|
||||||
|
add_custom_target (run COMMAND ${EXECUTABLE_OUTPUT_PATH}/main)
|
||||||
|
|
||||||
|
target_compile_options(lvgl PRIVATE -Werror -Werror=float-conversion)
|
1
PSE-firmware
Submodule
1
PSE-firmware
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 6dd655d9e53d23e108c46d089ec33f753eed7aa1
|
121
main.c
Normal file
121
main.c
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <SDL2/SDL_pixels.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "lvgl.h"
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
#define BUFF_SIZE (320 * 10)
|
||||||
|
#define LCD_WIDTH 320
|
||||||
|
#define LCD_HEIGHT 240
|
||||||
|
|
||||||
|
static lv_disp_draw_buf_t disp_buf;
|
||||||
|
|
||||||
|
static lv_color_t buf_1[BUFF_SIZE];
|
||||||
|
|
||||||
|
SDL_Window* window = NULL;
|
||||||
|
|
||||||
|
SDL_Surface* screenSurface = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char** argv){
|
||||||
|
if(SDL_Init( SDL_INIT_VIDEO ) < 0){
|
||||||
|
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, LCD_WIDTH, LCD_HEIGHT, SDL_WINDOW_SHOWN );
|
||||||
|
if(window == NULL){
|
||||||
|
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
screenSurface = SDL_GetWindowSurface(window);
|
||||||
|
|
||||||
|
lv_init();
|
||||||
|
|
||||||
|
lv_disp_draw_buf_init(&disp_buf, buf_1, NULL, BUFF_SIZE);
|
||||||
|
|
||||||
|
lv_disp_drv_t disp_drv;
|
||||||
|
lv_disp_drv_init(&disp_drv);
|
||||||
|
disp_drv.draw_buf = &disp_buf;
|
||||||
|
disp_drv.hor_res = LCD_WIDTH;
|
||||||
|
disp_drv.ver_res = LCD_HEIGHT;
|
||||||
|
disp_drv.flush_cb = &my_flush_cb;
|
||||||
|
lv_disp_drv_register(&disp_drv);
|
||||||
|
|
||||||
|
lv_disp_t * disp = lv_disp_drv_register(&disp_drv);
|
||||||
|
|
||||||
|
lv_indev_drv_t indev_drv;
|
||||||
|
lv_indev_drv_init(&indev_drv);
|
||||||
|
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||||
|
indev_drv.read_cb = &touchscreen_read_callback;
|
||||||
|
lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv);
|
||||||
|
|
||||||
|
LV_IMG_DECLARE(logo_mint_resize);
|
||||||
|
lv_obj_t * logo_mint = lv_img_create(lv_scr_act());
|
||||||
|
lv_img_set_src(logo_mint, &logo_mint_resize);
|
||||||
|
|
||||||
|
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x0), LV_PART_MAIN);
|
||||||
|
|
||||||
|
lv_obj_align(logo_mint, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
lv_obj_set_size(logo_mint, 320, 240);
|
||||||
|
|
||||||
|
lv_obj_t* cursor_pos = lv_label_create(lv_scr_act());
|
||||||
|
lv_obj_t* cursor = lv_label_create(lv_scr_act());
|
||||||
|
lv_label_set_text(cursor, "A");
|
||||||
|
lv_indev_set_cursor(my_indev, cursor);
|
||||||
|
|
||||||
|
pthread_t tickThread;
|
||||||
|
pthread_create(&tickThread, NULL, tick_thread, NULL);
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
lv_timer_handler();
|
||||||
|
int x,y;
|
||||||
|
Uint32 button = SDL_GetMouseState(&x, &y);
|
||||||
|
lv_label_set_text_fmt(cursor_pos, "%d : %d", x, y);
|
||||||
|
SDL_Event e;
|
||||||
|
SDL_PollEvent(&e);
|
||||||
|
if(e.type == SDL_QUIT)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void my_flush_cb(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * buf){
|
||||||
|
int32_t x, y;
|
||||||
|
for(y = area->y1; y <= area->y2; y++) {
|
||||||
|
for(x = area->x1; x <= area->x2; x++) {
|
||||||
|
Uint32 * const target_pixel = (Uint32 *) ((Uint8 *) screenSurface->pixels + y * screenSurface->pitch + x * screenSurface->format->BytesPerPixel);
|
||||||
|
Uint16 col = *(Uint16*)buf;
|
||||||
|
*target_pixel = SDL_MapRGB(screenSurface->format, (col & 0xF800) >> 8, (col & 0x07E0) >> 3, (col & 0x001F) << 3);
|
||||||
|
buf++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SDL_UpdateWindowSurface(window);
|
||||||
|
|
||||||
|
/* IMPORTANT!!!
|
||||||
|
* Inform LVGL that you are ready with the flushing and buf is not used anymore*/
|
||||||
|
lv_disp_flush_ready(disp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void touchscreen_read_callback(lv_indev_drv_t * drv, lv_indev_data_t*data){
|
||||||
|
int x, y;
|
||||||
|
Uint32 button = SDL_GetMouseState(&x, &y);
|
||||||
|
if(SDL_BUTTON(1)) {
|
||||||
|
data->state = LV_INDEV_STATE_PRESSED;
|
||||||
|
} else {
|
||||||
|
data->state = LV_INDEV_STATE_RELEASED;
|
||||||
|
}
|
||||||
|
data->point.x = x;
|
||||||
|
data->point.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void * tick_thread (void *args){
|
||||||
|
while(1) {
|
||||||
|
usleep(5*1000); /*Sleep for 5 millisecond*/
|
||||||
|
lv_tick_inc(5); /*Tell LVGL that 5 milliseconds were elapsed*/
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user