Skip to content

Commit fa8f828

Browse files
committed
display/fb: support non-mmappable frame buffers
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
1 parent 7f07a12 commit fa8f828

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,11 @@ menu "LVGL configuration"
16831683
depends on LV_USE_LINUX_FBDEV && LV_LINUX_FBDEV_CUSTOM_BUFFER
16841684
default 60
16851685

1686+
config LV_LINUX_FBDEV_MMAP
1687+
bool "Framebuffer device supports mmap"
1688+
depends on LV_USE_LINUX_FBDEV
1689+
default y
1690+
16861691
config LV_USE_NUTTX
16871692
bool "Use Nuttx to open window and handle touchscreen"
16881693
default n

lv_conf_template.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@
997997
#define LV_LINUX_FBDEV_RENDER_MODE LV_DISPLAY_RENDER_MODE_PARTIAL
998998
#define LV_LINUX_FBDEV_BUFFER_COUNT 0
999999
#define LV_LINUX_FBDEV_BUFFER_SIZE 60
1000+
#define LV_LINUX_FBDEV_MMAP 1
10001001
#endif
10011002

10021003
/*Use Nuttx to open window and handle touchscreen*/

src/drivers/display/fb/lv_linux_fbdev.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ typedef struct {
5959
struct fb_var_screeninfo vinfo;
6060
struct fb_fix_screeninfo finfo;
6161
#endif /* LV_LINUX_FBDEV_BSD */
62+
#if LV_LINUX_FBDEV_MMAP
6263
char * fbp;
64+
#endif
6365
uint8_t * rotated_buf;
6466
size_t rotated_buf_size;
6567
long int screensize;
@@ -183,12 +185,14 @@ void lv_linux_fbdev_set_file(lv_display_t * disp, const char * file)
183185
/* Figure out the size of the screen in bytes*/
184186
dsc->screensize = dsc->finfo.smem_len;/*finfo.line_length * vinfo.yres;*/
185187

188+
#if LV_LINUX_FBDEV_MMAP
186189
/* Map the device to memory*/
187190
dsc->fbp = (char *)mmap(0, dsc->screensize, PROT_READ | PROT_WRITE, MAP_SHARED, dsc->fbfd, 0);
188191
if((intptr_t)dsc->fbp == -1) {
189192
perror("Error: failed to map framebuffer device to memory");
190193
return;
191194
}
195+
#endif
192196

193197
/* Don't initialise the memory to retain what's currently displayed / avoid clearing the screen.
194198
* This is important for applications that only draw to a subsection of the full framebuffer.*/
@@ -250,14 +254,26 @@ void lv_linux_fbdev_set_force_refresh(lv_display_t * disp, bool enabled)
250254
* STATIC FUNCTIONS
251255
**********************/
252256

257+
static void write_to_fb(lv_linux_fb_t * dsc, uint32_t fb_pos, const void *data, size_t sz)
258+
{
259+
#if LV_LINUX_FBDEV_MMAP
260+
uint8_t * fbp = (uint8_t *)dsc->fbp;
261+
lv_memcpy(&fbp[fb_pos], data, sz);
262+
#else
263+
pwrite(dsc->fbfd, data, sz, fb_pos);
264+
#endif
265+
}
266+
253267
static void flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * color_p)
254268
{
255269
lv_linux_fb_t * dsc = lv_display_get_driver_data(disp);
256270

271+
#if LV_LINUX_FBDEV_MMAP
257272
if(dsc->fbp == NULL) {
258273
lv_display_flush_ready(disp);
259274
return;
260275
}
276+
#endif
261277

262278
int32_t w = lv_area_get_width(area);
263279
int32_t h = lv_area_get_height(area);
@@ -316,23 +332,22 @@ static void flush_cb(lv_display_t * disp, const lv_area_t * area, uint8_t * colo
316332
(area->x1 + dsc->vinfo.xoffset) * px_size +
317333
(area->y1 + dsc->vinfo.yoffset) * dsc->finfo.line_length;
318334

319-
uint8_t * fbp = (uint8_t *)dsc->fbp;
320335
int32_t y;
321336
if(LV_LINUX_FBDEV_RENDER_MODE == LV_DISPLAY_RENDER_MODE_DIRECT) {
322337
uint32_t color_pos =
323338
area->x1 * px_size +
324339
area->y1 * disp->hor_res * px_size;
325340

326341
for(y = area->y1; y <= area->y2; y++) {
327-
lv_memcpy(&fbp[fb_pos], &color_p[color_pos], w * px_size);
342+
write_to_fb(dsc, fb_pos, &color_p[color_pos], w * px_size);
328343
fb_pos += dsc->finfo.line_length;
329344
color_pos += disp->hor_res * px_size;
330345
}
331346
}
332347
else {
333348
w = lv_area_get_width(area);
334349
for(y = area->y1; y <= area->y2; y++) {
335-
lv_memcpy(&fbp[fb_pos], color_p, w * px_size);
350+
write_to_fb(dsc, fb_pos, color_p, w * px_size);
336351
fb_pos += dsc->finfo.line_length;
337352
color_p += w * px_size;
338353
}

src/lv_conf_internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,6 +3292,13 @@
32923292
#define LV_LINUX_FBDEV_BUFFER_SIZE 60
32933293
#endif
32943294
#endif
3295+
#ifndef LV_LINUX_FBDEV_MMAP
3296+
#ifdef CONFIG_LV_LINUX_FBDEV_MMAP
3297+
#define LV_LINUX_FBDEV_MMAP CONFIG_LV_LINUX_FBDEV_MMAP
3298+
#else
3299+
#define LV_LINUX_FBDEV_MMAP 1
3300+
#endif
3301+
#endif
32953302
#endif
32963303

32973304
/*Use Nuttx to open window and handle touchscreen*/

0 commit comments

Comments
 (0)