embox
78 строк · 2.1 Кб
1/**
2* @file
3* @brief LVGL display interface port
4* @defails Based on lv_drivers/display/fbdev.c
5*
6* @date 15.02.2021
7* @author Alexander Kalmuk
8*/
9
10#include <unistd.h>
11#include <util/log.h>
12#include <drivers/video/fb.h>
13
14#if defined STM32F746xx || defined STM32F769xx
15#include <stm32f7xx_hal.h>
16#elif defined STM32H745xx
17#include <stm32h7xx_hal.h>
18#elif defined (STM32F429xx)
19#include <stm32f4xx_hal.h>
20#endif
21
22#include "lvgl.h"
23
24extern uint8_t *lv_fbp;
25extern struct fb_var_screeninfo lv_vinfo;
26extern struct fb_fix_screeninfo lv_finfo;
27
28void lvgl_port_fbdev_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area,
29lv_color_t *color_p) {
30int32_t act_x1, act_y1, act_x2, act_y2;
31long int location = 0;
32lv_coord_t w;
33
34if (lv_fbp == NULL ||
35area->x2 < 0 ||
36area->y2 < 0 ||
37area->x1 > (int32_t)lv_vinfo.xres - 1 ||
38area->y1 > (int32_t)lv_vinfo.yres - 1) {
39lv_disp_flush_ready(disp_drv);
40return;
41}
42
43/* Truncate the area to the screen */
44act_x1 = area->x1 < 0 ? 0 : area->x1;
45act_y1 = area->y1 < 0 ? 0 : area->y1;
46act_x2 = area->x2 > (int32_t)lv_vinfo.xres - 1 ? (int32_t)lv_vinfo.xres - 1 : area->x2;
47act_y2 = area->y2 > (int32_t)lv_vinfo.yres - 1 ? (int32_t)lv_vinfo.yres - 1 : area->y2;
48
49w = (act_x2 - act_x1 + 1);
50
51if (lv_vinfo.bits_per_pixel == 32 || lv_vinfo.bits_per_pixel == 24) {
52uint32_t * lv_fbp32 = (uint32_t *)lv_fbp;
53int32_t y;
54
55for(y = act_y1; y <= act_y2; y++) {
56location = (act_x1 + lv_vinfo.xoffset) + (y + lv_vinfo.yoffset) * lv_finfo.line_length / 4;
57memcpy(&lv_fbp32[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 4);
58color_p += w;
59}
60} else if (lv_vinfo.bits_per_pixel == 16) {
61uint16_t * lv_fbp16 = (uint16_t *)lv_fbp;
62int32_t y;
63
64for(y = act_y1; y <= act_y2; y++) {
65location = (act_x1 + lv_vinfo.xoffset) + (y + lv_vinfo.yoffset) * lv_finfo.line_length / 2;
66memcpy(&lv_fbp16[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 2);
67color_p += w;
68}
69} else {
70log_error("Unsupported bits_per_pixel=%d", lv_vinfo.bits_per_pixel);
71}
72
73#if defined STM32F746xx || defined STM32F769xx || defined STM32H745xx
74SCB_CleanDCache();
75#endif
76
77lv_disp_flush_ready(disp_drv);
78}
79