1 Star 0 Fork 34

石志鹏 / lv_demo_hub

forked from Flying / lv_demo_hub 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
base_main_ubuntu.h 4.02 KB
一键复制 编辑 原始数据 按行查看 历史
Flying 提交于 2022-07-14 21:47 . first commit
/*
* @Author: Flying
* @Date: 2022-02-25 22:54:00
* @LastEditors: Flying
* @LastEditTime: 2022-06-08 22:15:58
* @Description: file content
*/
/*********************
* INCLUDES
*********************/
#define _DEFAULT_SOURCE /* needed for usleep() */
#include <stdlib.h>
#include <unistd.h>
#define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/
#include "base_main.h"
#include <SDL2/SDL.h>
#include "lvgl/lvgl.h"
#include "my_drivers/display/monitor.h"
#include "my_drivers/indev/mouse.h"
#include "my_drivers/indev/keyboard.h"
#include "my_drivers/indev/mousewheel.h"
static void hal_init(void);
static int tick_thread(void *data);
int main(int argc, char **argv)
{
(void)argc; /*Unused*/
(void)argv; /*Unused*/
/*Initialize LVGL*/
lv_init();
/*Initialize the HAL (display, input devices, tick) for LVGL*/
hal_init();
my_app_init(argc, argv);
my_app_main(argc, argv);
return 0;
}
/**********************
* STATIC FUNCTIONS
**********************/
/**
* Initialize the Hardware Abstraction Layer (HAL) for the LVGL graphics
* library
*/
static void hal_init(void)
{
/* Use the 'monitor' driver which creates window on PC's monitor to simulate a display*/
monitor_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*/
static lv_disp_draw_buf_t disp_buf1;
lv_color_t *buf1_1 = (lv_color_t *)malloc(sizeof(lv_color_t) * MY_UI_W_MAX * MY_UI_H_MAX);
lv_color_t *buf1_2 = (lv_color_t *)malloc(sizeof(lv_color_t) * MY_UI_W_MAX * MY_UI_H_MAX);
lv_disp_draw_buf_init(&disp_buf1, buf1_1, buf1_2, MY_BASE_H_MAX * MY_BASE_W_MAX);
/*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 = monitor_flush;
disp_drv.hor_res = MY_UI_W_MAX;
disp_drv.ver_res = MY_UI_H_MAX;
disp_drv.antialiasing = 1;
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);
/* Add the mouse as input device
* 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 = mouse_read;
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 = keyboard_read;
lv_indev_t *kb_indev = lv_indev_drv_register(&indev_drv_2);
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 = mousewheel_read;
lv_indev_t *enc_indev = lv_indev_drv_register(&indev_drv_3);
lv_indev_set_group(enc_indev, g);
// /*Set a cursor for the mouse*/
// 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_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*/
}
/**
* A task to measure the elapsed time for LVGL
* @param data unused
* @return never return
*/
static int tick_thread(void *data)
{
(void)data;
while (1)
{
SDL_Delay(5);
lv_tick_inc(5); /*Tell LittelvGL that 5 milliseconds were elapsed*/
}
return 0;
}
1
https://gitee.com/shi_chi_peng/lv_demo_hub.git
git@gitee.com:shi_chi_peng/lv_demo_hub.git
shi_chi_peng
lv_demo_hub
lv_demo_hub
master

搜索帮助