#include "cmsis_os.h" #include "main.h" #include "fatfs.h" #include "lvgl.h" #include "otm8009a_lcd.h" #include "otm_lcd_impl.h" #include "otm8009a_lcd_lvgl_impl.h" #include "user_tasks.h" #define DISP_BUF_SIZE (800 * 10) osThreadId_t lvgl_tick_thread_handle; const osThreadAttr_t lvgl_tick_thread_attributes = { .name = "LVTICK", .priority = (osPriority_t) osPriorityNormal, .stack_size = 128 * 4 }; osThreadId_t lvgl_task_thread_handle; const osThreadAttr_t lvgl_task_thread_attributes = { .name = "LVTASK", .priority = (osPriority_t) osPriorityBelowNormal, .stack_size = 512 * 4 }; osSemaphoreId_t g_lvgl_semaphore; lv_disp_buf_t g_disp_buf; lv_color_t g_disp_buf_array[DISP_BUF_SIZE]; _otm_impl_t g_lcd_impl; otm_t g_lcd = { .cb = { .delay_cb = _otm_impl_delay, .write_data_cb = _otm_impl_write_data, .write_reg_cb = _otm_impl_write_reg, .backlight_cb = _otm_impl_backlight }, .user_data = &g_lcd_impl }; void lvgl_tick_thread(void *parameters); void lvgl_task_thread(void *parameters); void user_task_lvgl_init(void) { HAL_GPIO_WritePin(LCD_BL_GPIO_Port, LCD_BL_Pin, GPIO_PIN_SET); lv_init(); otm_lcd_init(&g_lcd); otm_lcd_color_format(&g_lcd, OTM_RGB888); otm_lcd_direction(&g_lcd, OTM_HORIZONTAL_INV); lv_disp_buf_init(&g_disp_buf, &g_disp_buf_array, NULL, DISP_BUF_SIZE); lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); disp_drv.buffer = &g_disp_buf; disp_drv.flush_cb = _otm_lcd_flush_cb; disp_drv.rounder_cb = _otm_lcd_rounder_cb; if(g_lcd.color_format == OTM_RGB888) { disp_drv.set_px_cb = _otm_lcd_set_px_cb; } disp_drv.user_data = &g_lcd; lv_disp_drv_register(&disp_drv); g_lvgl_semaphore = osSemaphoreNew(1, 1, NULL); lvgl_tick_thread_handle = osThreadNew(lvgl_tick_thread, NULL, &lvgl_tick_thread_attributes); lvgl_task_thread_handle = osThreadNew(lvgl_task_thread, NULL, &lvgl_task_thread_attributes); } void lvgl_tick_thread(void *parameters) { for(;;) { osSemaphoreAcquire(g_lvgl_semaphore, osWaitForever); lv_tick_inc(30); osSemaphoreRelease(g_lvgl_semaphore); osDelay(30); } } void lvgl_task_thread(void *parameters) { for(;;) { osSemaphoreAcquire(g_lvgl_semaphore, osWaitForever); lv_task_handler(); osSemaphoreRelease(g_lvgl_semaphore); osDelay(31); } }