linuxOS_D21X/source/artinchip/lvgl-ui/main.c

91 lines
1.7 KiB
C
Raw Normal View History

2024-11-29 08:23:11 +00:00
/*
2024-11-29 08:33:21 +00:00
* Copyright (C) 2022-2024 ArtInChip Technology Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
2024-11-29 08:23:11 +00:00
* Authors: Ning Fang <ning.fang@artinchip.com>
*/
2024-11-29 08:13:19 +00:00
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <sys/time.h>
#include <sched.h>
#include <assert.h>
#include "lvgl/lvgl.h"
#include "lv_port_disp.h"
#include "lv_port_indev.h"
#include "aic_ui.h"
2024-11-29 08:33:21 +00:00
uint32_t custom_tick_get(void)
{
static uint64_t start_ms = 0;
if (start_ms == 0) {
struct timespec tv_start;
clock_gettime(CLOCK_MONOTONIC, &tv_start);
start_ms = tv_start.tv_sec * 1000 + tv_start.tv_nsec / 1000000;
}
struct timespec tv_now;
clock_gettime(CLOCK_MONOTONIC, &tv_now);
uint64_t now_ms;
now_ms = tv_now.tv_sec * 1000 + tv_now.tv_nsec / 1000000;
uint32_t time_ms = (uint32_t)(now_ms - start_ms);
return time_ms;
}
2024-11-29 08:23:11 +00:00
#if LV_USE_LOG
2024-11-29 08:33:21 +00:00
#if LVGL_VERSION_MAJOR == 8
2024-11-29 08:23:11 +00:00
static void lv_user_log(const char *buf)
{
printf("%s\n", buf);
}
2024-11-29 08:33:21 +00:00
#else
static void lv_user_log(lv_log_level_t level, const char *buf)
{
(void)level;
printf("%s\n", buf);
}
#endif
2024-11-29 08:23:11 +00:00
#endif /* LV_USE_LOG */
2024-11-29 08:13:19 +00:00
int main(void)
{
2024-11-29 08:23:11 +00:00
#if LV_USE_LOG
lv_log_register_print_cb(lv_user_log);
#endif /* LV_USE_LOG */
2024-11-29 08:13:19 +00:00
/*LittlevGL init*/
lv_init();
lv_port_disp_init();
lv_port_indev_init();
2024-11-29 08:33:21 +00:00
#if LV_IMG_CACHE_DEF_SIZE == 1
lv_img_cache_set_size(LV_CACHE_IMG_NUM);
#endif
2024-11-29 08:13:19 +00:00
/*Create a Demo*/
2024-11-29 08:23:11 +00:00
#if LV_USE_DEMO_MUSIC == 1
void lv_demo_music(void);
lv_demo_music();
2024-11-29 08:33:21 +00:00
#else
2024-11-29 08:23:11 +00:00
void ui_init(void);
ui_init();
2024-11-29 08:33:21 +00:00
#endif
#if LVGL_VERSION_MAJOR == 9
lv_tick_set_cb(&custom_tick_get);
2024-11-29 08:23:11 +00:00
#endif
2024-11-29 08:13:19 +00:00
/*Handle LitlevGL tasks (tickless mode)*/
while (1) {
lv_timer_handler();
usleep(1000);
}
return 0;
}