89 lines
2.4 KiB
C
89 lines
2.4 KiB
C
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
#include "lvgl.h"
|
|
|
|
#include "user_lvgl_impl.h"
|
|
|
|
#include "user_tasks.h"
|
|
|
|
osThreadId_t g_user_lvgl_tick_handle;
|
|
osThreadAttr_t g_user_lvgl_tick_attributes = {
|
|
.name = "LV_TICK",
|
|
.stack_size = 128 * 4,
|
|
.priority = (osPriority_t) osPriorityAboveNormal
|
|
};
|
|
|
|
osThreadId_t g_user_lvgl_task_handle;
|
|
osThreadAttr_t g_user_lvgl_task_attributes = {
|
|
.name = "LV_TASK",
|
|
.stack_size = 384 * 4,
|
|
.priority = (osPriority_t) osPriorityBelowNormal
|
|
};
|
|
|
|
osMutexId_t g_user_lvgl_mutex_handle;
|
|
osMutexAttr_t g_user_lvgl_mutex_attributes = {
|
|
.name = "LV_MUTX",
|
|
.attr_bits = osMutexRecursive | osMutexPrioInherit,
|
|
.cb_mem = NULL,
|
|
.cb_size = 0U
|
|
};
|
|
|
|
osEventFlagsId_t g_user_lvgl_event_handle;
|
|
|
|
lv_disp_buf_t g_user_lvgl_disp_buf;
|
|
lv_disp_t *g_user_lvgl_disp;
|
|
|
|
void user_lvgl_tick(void *argument) {
|
|
for(;;) {
|
|
if(osMutexAcquire(g_user_lvgl_mutex_handle, 1000) == osOK) {
|
|
lv_tick_inc(27);
|
|
osMutexRelease(g_user_lvgl_mutex_handle);
|
|
} else {
|
|
LV_LOG_INFO("Lock mutex failed.");
|
|
}
|
|
osDelay(27);
|
|
}
|
|
}
|
|
|
|
void user_lvgl_task(void *argument) {
|
|
|
|
g_user_lvgl_mutex_handle = osMutexNew(&g_user_lvgl_mutex_attributes);
|
|
if(g_user_lvgl_mutex_handle == NULL) {
|
|
osThreadExit();
|
|
}
|
|
|
|
lv_init();
|
|
lv_log_register_print_cb(user_lvgl_impl_log_cb);
|
|
|
|
lv_disp_buf_init(&g_user_lvgl_disp_buf, (void *)0xD0100000, (void *)0xD0300000, 800 * 480);
|
|
|
|
lv_disp_drv_t disp_drv;
|
|
lv_disp_drv_init(&disp_drv);
|
|
disp_drv.buffer = &g_user_lvgl_disp_buf;
|
|
disp_drv.flush_cb = user_lvgl_impl_flush_cb;
|
|
disp_drv.clean_dcache_cb = user_lvgl_impl_clean_dcache_cb;
|
|
|
|
g_user_lvgl_disp = lv_disp_drv_register(&disp_drv);
|
|
|
|
g_user_lvgl_tick_handle = osThreadNew(user_lvgl_tick, NULL, &g_user_lvgl_tick_attributes);
|
|
if(g_user_lvgl_tick_handle == NULL) {
|
|
LV_LOG_ERROR("Failed to create tick thread.");
|
|
osThreadExit();
|
|
}
|
|
|
|
LV_LOG_INFO("LVGL initialized at %ld, stack avail: %ldbytes.", osKernelGetTickCount(), osThreadGetStackSpace(g_user_lvgl_task_handle));
|
|
|
|
osEventFlagsSet(g_user_lvgl_event_handle, USER_LVGL_EVENT_FLAG_READY);
|
|
|
|
for(;;) {
|
|
if(osMutexAcquire(g_user_lvgl_mutex_handle, 1000) == osOK) {
|
|
lv_task_handler();
|
|
osMutexRelease(g_user_lvgl_mutex_handle);
|
|
} else {
|
|
LV_LOG_INFO("Lock mutex failed.");
|
|
}
|
|
osDelay(25);
|
|
}
|
|
} |