1 Star 0 Fork 2

SimonLian/smc_lv_project

forked from Flying/smc_lv_project 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
base_main_linuxarm.h 3.61 KB
一键复制 编辑 原始数据 按行查看 历史
flying 提交于 2022-04-12 20:54 . first commit
/*
* @Author: Flying
* @Date: 2022-02-25 22:54:32
* @LastEditors: Flying
* @LastEditTime: 2022-03-10 23:21:53
* @Description: file content
*/
#include "lvgl/lvgl.h"
#include "my_drivers/display/fbdev.h"
#include "my_drivers/indev/evdev.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/epoll.h>
#include <sys/timerfd.h>
#include <alloca.h>
#include "base_main.h"
#define DISP_BUF_SIZE (MY_UI_W_MAX * MY_UI_H_MAX)
#define EPOLL_LISTEN_CNT 256
#define EPOLL_LISTEN_TIMEOUT 500
static int g_epollfd = -1;
static int g_timerfd = -1;
static int epoll_add_fd(int fd)
{
int ret;
struct epoll_event event;
memset(&event, 0, sizeof(event));
event.data.fd = fd;
event.events = EPOLLIN | EPOLLET;
ret = epoll_ctl(g_epollfd, EPOLL_CTL_ADD, fd, &event);
if (ret < 0)
{
return -1;
}
return 0;
}
static int epollfd_init()
{
int epfd;
/* create epoll fd */
epfd = epoll_create(EPOLL_LISTEN_CNT);
if (epfd < 0)
{
return -1;
}
g_epollfd = epfd;
return epfd;
}
static int timerfd_init()
{
int tmfd;
int ret;
struct itimerspec new_value;
new_value.it_value.tv_sec = 0;
new_value.it_value.tv_nsec = 10 * 1000 * 1000;
new_value.it_interval.tv_sec = 0;
new_value.it_interval.tv_nsec = 10 * 1000 * 1000;
tmfd = timerfd_create(CLOCK_MONOTONIC, 0);
if (tmfd < 0)
{
return -1;
}
ret = timerfd_settime(tmfd, 0, &new_value, NULL);
if (ret < 0)
{
close(tmfd);
return -1;
}
if (epoll_add_fd(tmfd))
{
close(tmfd);
return -1;
}
g_timerfd = tmfd;
return 0;
}
int main(int argc, char *argv[])
{
/*LittlevGL init*/
lv_init();
epollfd_init();
timerfd_init();
/*Linux frame buffer device init*/
fbdev_init();
wm_app_init(argc, argv);
/*A small buffer for LittlevGL to draw the screen's content*/
lv_color_t *buf_1 = (lv_color_t *)alloca(sizeof(lv_color_t) * DISP_BUF_SIZE);
lv_color_t *buf_2 = (lv_color_t *)alloca(sizeof(lv_color_t) * DISP_BUF_SIZE);
/*Initialize a descriptor for the buffer*/
static lv_disp_draw_buf_t disp_buf;
lv_disp_draw_buf_init(&disp_buf, buf_1, buf_2, DISP_BUF_SIZE);
/*Initialize and register a display driver*/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &disp_buf;
disp_drv.flush_cb = fbdev_flush;
disp_drv.hor_res = MY_UI_W_MAX;
disp_drv.ver_res = MY_UI_H_MAX;
lv_disp_drv_register(&disp_drv);
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
evdev_init();
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = (void (*)(struct _lv_indev_drv_t *, lv_indev_data_t *))evdev_read; // defined in lv_drivers/indev/evdev.h
indev_drv.feedback_cb = wm_touch_feedback;
lv_indev_t *lv_indev = lv_indev_drv_register(&indev_drv);
if (!lv_indev)
{
printf("lv_indev rregister error %d \r\n", __LINE__);
return 0;
}
// app
wm_app_main(argc, argv);
return 0;
}
/*Set in lv_conf.h as `LV_TICK_CUSTOM_SYS_TIME_EXPR`*/
uint32_t custom_tick_get(void)
{
static uint64_t start_ms = 0;
if (start_ms == 0)
{
struct timeval tv_start;
gettimeofday(&tv_start, NULL);
start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
}
struct timeval tv_now;
gettimeofday(&tv_now, NULL);
uint64_t now_ms;
now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;
uint32_t time_ms = now_ms - start_ms;
return time_ms;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/simonlian/smc_lv_project.git
git@gitee.com:simonlian/smc_lv_project.git
simonlian
smc_lv_project
smc_lv_project
master

搜索帮助