123 lines
2.8 KiB
C
123 lines
2.8 KiB
C
|
|
/* FreeRTOS */
|
|
#include "FreeRTOS.h"
|
|
#include "semphr.h"
|
|
#include "task.h"
|
|
|
|
/* LVGL */
|
|
#include "lv_demos.h"
|
|
#include "lvgl.h"
|
|
|
|
/* LCD */
|
|
#include "epd-spi/panel/lcd_h189s001.h"
|
|
|
|
/* App */
|
|
#include "app_impl_lcd.h"
|
|
#include "app_lvgl.h"
|
|
|
|
static lcd_gc9b71_t s_lcd = {
|
|
.cb =
|
|
{
|
|
.write_command_cb = app_lcd_impl_write_command,
|
|
.write_data_cb = app_lcd_impl_write_data,
|
|
.delay_cb = app_lcd_impl_delay,
|
|
|
|
},
|
|
.user_data = NULL,
|
|
};
|
|
|
|
static SemaphoreHandle_t s_lvgl_semphr = NULL;
|
|
|
|
static uint16_t s_lcd_buffer[320 * 40];
|
|
|
|
static uint32_t app_lvgl_get_tick_cb(void);
|
|
static void app_lvgl_lcd_flush_cb(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map);
|
|
static void app_lvgl_task(void *arguments);
|
|
|
|
int app_lvgl_init(void) {
|
|
s_lvgl_semphr = xSemaphoreCreateBinary();
|
|
if (s_lvgl_semphr == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
xSemaphoreGive(s_lvgl_semphr);
|
|
|
|
app_lcd_impl_init(NULL);
|
|
|
|
lcd_gc9b71_init(&s_lcd, &lcd_h189s001_panel_config);
|
|
lcd_gc9b71_set_pixel_format(&s_lcd, LCD_GC9B71_RGB565);
|
|
lcd_gc9b71_enable_display(&s_lcd, true);
|
|
lv_init();
|
|
|
|
lv_tick_set_cb(app_lvgl_get_tick_cb);
|
|
|
|
uint16_t hor_res = s_lcd.panel_config->size_x;
|
|
uint16_t ver_res = s_lcd.panel_config->size_y;
|
|
|
|
lv_display_t *display = lv_display_create(hor_res, ver_res);
|
|
if (display == NULL) {
|
|
goto deinit_lv_exit;
|
|
}
|
|
|
|
lv_display_set_flush_cb(display, app_lvgl_lcd_flush_cb);
|
|
lv_display_set_buffers(display, s_lcd_buffer, NULL, sizeof(s_lcd_buffer), LV_DISPLAY_RENDER_MODE_PARTIAL);
|
|
|
|
lv_demo_music();
|
|
|
|
if (xTaskCreate(app_lvgl_task, "LVGL", 2048, NULL, 3, NULL) != pdPASS) {
|
|
goto destroy_display_exit;
|
|
}
|
|
|
|
return 0;
|
|
|
|
destroy_display_exit:
|
|
lv_display_delete(display);
|
|
|
|
deinit_lv_exit:
|
|
lv_deinit();
|
|
vSemaphoreDelete(s_lvgl_semphr);
|
|
|
|
return -1;
|
|
}
|
|
|
|
bool app_lvgl_lock(uint32_t timeout_ms) {
|
|
if (xSemaphoreTake(s_lvgl_semphr, pdMS_TO_TICKS(timeout_ms)) != pdPASS) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void app_lvgl_unlock(void) {
|
|
xSemaphoreGive(s_lvgl_semphr);
|
|
}
|
|
|
|
static uint32_t app_lvgl_get_tick_cb(void) {
|
|
return xTaskGetTickCount();
|
|
}
|
|
|
|
static void app_lvgl_lcd_flush_cb(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map) {
|
|
epd_coord_t coord = {
|
|
.x_start = area->x1,
|
|
.x_end = area->x2,
|
|
.y_start = area->y1,
|
|
.y_end = area->y2,
|
|
};
|
|
|
|
lv_draw_sw_rgb565_swap(px_map, (area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1));
|
|
|
|
lcd_gc9b71_load(&s_lcd, &coord, px_map);
|
|
|
|
lv_display_flush_ready(disp);
|
|
}
|
|
|
|
static void app_lvgl_task(void *arguments) {
|
|
for (;;) {
|
|
if (app_lvgl_lock(portMAX_DELAY)) {
|
|
lv_task_handler();
|
|
app_lvgl_unlock();
|
|
}
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(5));
|
|
}
|
|
} |