@@ -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+
253267static 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 }
0 commit comments