mirror of
https://gitee.com/dlmu-cone/tronone-h7-scaffold
synced 2026-07-24 11:37:44 +08:00
tft lvgl test ok
This commit is contained in:
109
User_Code/module/software/prts/port/prts_lvgl_port.c
Normal file
109
User_Code/module/software/prts/port/prts_lvgl_port.c
Normal file
@@ -0,0 +1,109 @@
|
||||
#include "prts_lvgl_port.h"
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "lv_draw_sw_utils.h"
|
||||
#include "main.h"
|
||||
#include "tft.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define PRTS_LVGL_BUF_LINES 40U
|
||||
#define PRTS_DMA_BUFFER_ATTR __attribute__((section(".dma_buffer"), aligned(32)))
|
||||
|
||||
static lv_display_t *prts_display = NULL;
|
||||
static uint8_t prts_lvgl_buf[TFT_LCD_W * PRTS_LVGL_BUF_LINES * 2U] PRTS_DMA_BUFFER_ATTR;
|
||||
|
||||
static uint32_t prts_lvgl_tick_get(void)
|
||||
{
|
||||
return HAL_GetTick();
|
||||
}
|
||||
|
||||
static void prts_lvgl_flush(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map)
|
||||
{
|
||||
int32_t area_width;
|
||||
int32_t area_height;
|
||||
int32_t x1;
|
||||
int32_t y1;
|
||||
int32_t x2;
|
||||
int32_t y2;
|
||||
uint32_t pixel_count;
|
||||
|
||||
if (area->x2 < 0 || area->y2 < 0 || area->x1 >= (int32_t) TFT_LCD_W || area->y1 >= (int32_t) TFT_LCD_H)
|
||||
{
|
||||
lv_display_flush_ready(disp);
|
||||
return;
|
||||
}
|
||||
|
||||
area_width = lv_area_get_width(area);
|
||||
area_height = lv_area_get_height(area);
|
||||
if (area_width <= 0 || area_height <= 0)
|
||||
{
|
||||
lv_display_flush_ready(disp);
|
||||
return;
|
||||
}
|
||||
|
||||
pixel_count = (uint32_t) area_width * (uint32_t) area_height;
|
||||
lv_draw_sw_rgb565_swap(px_map, pixel_count);
|
||||
|
||||
x1 = LV_MAX(area->x1, 0);
|
||||
y1 = LV_MAX(area->y1, 0);
|
||||
x2 = LV_MIN(area->x2, (int32_t) TFT_LCD_W - 1);
|
||||
y2 = LV_MIN(area->y2, (int32_t) TFT_LCD_H - 1);
|
||||
|
||||
if (x1 == area->x1 && y1 == area->y1 && x2 == area->x2 && y2 == area->y2)
|
||||
{
|
||||
LCD_Address_Set((uint16_t) x1, (uint16_t) y1, (uint16_t) x2, (uint16_t) y2);
|
||||
TFT_WriteColorData(px_map, pixel_count * 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t visible_width = (uint32_t) (x2 - x1 + 1);
|
||||
uint32_t row_stride = (uint32_t) area_width * 2U;
|
||||
uint32_t row_bytes = visible_width * 2U;
|
||||
uint8_t *row = px_map + (((uint32_t) (y1 - area->y1) * (uint32_t) area_width +
|
||||
(uint32_t) (x1 - area->x1)) * 2U);
|
||||
|
||||
while (y1 <= y2)
|
||||
{
|
||||
LCD_Address_Set((uint16_t) x1, (uint16_t) y1, (uint16_t) x2, (uint16_t) y1);
|
||||
TFT_WriteColorData(row, row_bytes);
|
||||
row += row_stride;
|
||||
y1++;
|
||||
}
|
||||
}
|
||||
|
||||
lv_display_flush_ready(disp);
|
||||
}
|
||||
|
||||
bool PRTS_LVGLPortInit(void)
|
||||
{
|
||||
if (prts_display != NULL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
TFT_Init();
|
||||
if (!TFT_IsReady())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
lv_tick_set_cb(prts_lvgl_tick_get);
|
||||
|
||||
prts_display = lv_display_create((int32_t) TFT_LCD_W, (int32_t) TFT_LCD_H);
|
||||
if (prts_display == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
lv_display_set_flush_cb(prts_display, prts_lvgl_flush);
|
||||
lv_display_set_color_format(prts_display, LV_COLOR_FORMAT_RGB565);
|
||||
lv_display_set_buffers(prts_display,
|
||||
prts_lvgl_buf,
|
||||
NULL,
|
||||
sizeof(prts_lvgl_buf),
|
||||
LV_DISPLAY_RENDER_MODE_PARTIAL);
|
||||
lv_display_set_default(prts_display);
|
||||
|
||||
return true;
|
||||
}
|
||||
16
User_Code/module/software/prts/port/prts_lvgl_port.h
Normal file
16
User_Code/module/software/prts/port/prts_lvgl_port.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef PRTS_LVGL_PORT_H
|
||||
#define PRTS_LVGL_PORT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool PRTS_LVGLPortInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user