embox
66 строк · 1.8 Кб
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#include "lvgl.h"15
16extern uint8_t *lv_fbp;17extern struct fb_var_screeninfo lv_vinfo;18extern struct fb_fix_screeninfo lv_finfo;19
20void lvgl_port_fbdev_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area,21lv_color_t *color_p) {22int32_t act_x1, act_y1, act_x2, act_y2;23long int location = 0;24lv_coord_t w;25
26if (lv_fbp == NULL ||27area->x2 < 0 ||28area->y2 < 0 ||29area->x1 > (int32_t)lv_vinfo.xres - 1 ||30area->y1 > (int32_t)lv_vinfo.yres - 1) {31lv_disp_flush_ready(disp_drv);32return;33}34
35/* Truncate the area to the screen */36act_x1 = area->x1 < 0 ? 0 : area->x1;37act_y1 = area->y1 < 0 ? 0 : area->y1;38act_x2 = area->x2 > (int32_t)lv_vinfo.xres - 1 ? (int32_t)lv_vinfo.xres - 1 : area->x2;39act_y2 = area->y2 > (int32_t)lv_vinfo.yres - 1 ? (int32_t)lv_vinfo.yres - 1 : area->y2;40
41w = (act_x2 - act_x1 + 1);42
43if (lv_vinfo.bits_per_pixel == 32 || lv_vinfo.bits_per_pixel == 24) {44uint32_t * lv_fbp32 = (uint32_t *)lv_fbp;45int32_t y;46
47for(y = act_y1; y <= act_y2; y++) {48location = (act_x1 + lv_vinfo.xoffset) + (y + lv_vinfo.yoffset) * lv_finfo.line_length / 4;49memcpy(&lv_fbp32[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 4);50color_p += w;51}52} else if (lv_vinfo.bits_per_pixel == 16) {53uint16_t * lv_fbp16 = (uint16_t *)lv_fbp;54int32_t y;55
56for(y = act_y1; y <= act_y2; y++) {57location = (act_x1 + lv_vinfo.xoffset) + (y + lv_vinfo.yoffset) * lv_finfo.line_length / 2;58memcpy(&lv_fbp16[location], (uint32_t *)color_p, (act_x2 - act_x1 + 1) * 2);59color_p += w;60}61} else {62log_error("Unsupported bits_per_pixel=%d", lv_vinfo.bits_per_pixel);63}64
65lv_disp_flush_ready(disp_drv);66}
67