2018-01-16 22:35:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/examples/lvgldemo/fbdev.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gábor Kiss-Vámosi <kisvegabor@gmail.com>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "fbdev.h"
|
|
|
|
|
2021-04-05 15:13:30 +02:00
|
|
|
#include <nuttx/compiler.h>
|
2018-01-16 22:35:55 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2021-04-05 15:13:30 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
#endif
|
|
|
|
|
2018-01-16 22:35:55 +01:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
2021-02-15 10:05:04 +01:00
|
|
|
#include <debug.h>
|
2018-01-16 22:35:55 +01:00
|
|
|
|
|
|
|
#include <nuttx/video/fb.h>
|
|
|
|
#include <nuttx/video/rgbcolors.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef FBDEV_PATH
|
|
|
|
# define FBDEV_PATH "/dev/fb0"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct fb_state_s
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
struct fb_videoinfo_s vinfo;
|
|
|
|
struct fb_planeinfo_s pinfo;
|
|
|
|
FAR void *fbmem;
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct fb_state_s state;
|
|
|
|
|
2021-04-05 15:13:30 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
|
|
|
static pthread_t fb_write_thread;
|
|
|
|
static sem_t flush_sem;
|
|
|
|
static sem_t wait_sem;
|
|
|
|
|
|
|
|
static lv_area_t lv_area;
|
|
|
|
static lv_color_t *lv_color_p;
|
|
|
|
#endif
|
|
|
|
|
2018-01-16 22:35:55 +01:00
|
|
|
/****************************************************************************
|
2021-04-05 15:13:30 +02:00
|
|
|
* Private Functions
|
2018-01-16 22:35:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2021-04-05 15:13:30 +02:00
|
|
|
* Name: fbdev_wait
|
2018-01-16 22:35:55 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2021-04-05 15:13:30 +02:00
|
|
|
* Wait for the flushing operation conclusion to notify LVGL.
|
2018-01-16 22:35:55 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2021-04-05 15:13:30 +02:00
|
|
|
* disp_drv - LVGL driver interface
|
2018-01-16 22:35:55 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-04-05 15:13:30 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
|
|
|
|
|
|
|
static void fbdev_wait(lv_disp_drv_t *disp_drv)
|
|
|
|
{
|
|
|
|
sem_wait(&wait_sem);
|
|
|
|
|
|
|
|
/* Tell the flushing is ready */
|
|
|
|
|
|
|
|
lv_disp_flush_ready(disp_drv);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fbdev_flush_internal
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Write the buffer to Framebuffer interface.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* area - Area of the screen to be flushed
|
|
|
|
* color_p - A n array of colors
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int fbdev_flush_internal(const lv_area_t *area, lv_color_t *color_p)
|
2018-01-16 22:35:55 +01:00
|
|
|
{
|
2020-07-23 06:27:14 +02:00
|
|
|
#ifdef CONFIG_FB_UPDATE
|
2021-02-15 10:05:04 +01:00
|
|
|
struct fb_area_s fb_area;
|
2018-01-16 22:35:55 +01:00
|
|
|
#endif
|
2020-04-07 03:00:56 +02:00
|
|
|
int32_t x1 = area->x1;
|
|
|
|
int32_t y1 = area->y1;
|
|
|
|
int32_t x2 = area->x2;
|
|
|
|
int32_t y2 = area->y2;
|
2018-01-16 22:35:55 +01:00
|
|
|
int32_t act_x1;
|
|
|
|
int32_t act_y1;
|
|
|
|
int32_t act_x2;
|
|
|
|
int32_t act_y2;
|
|
|
|
long int location = 0;
|
|
|
|
|
|
|
|
if (state.fbmem == NULL)
|
|
|
|
{
|
2021-04-05 15:13:30 +02:00
|
|
|
return ERROR;
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return if the area is out the screen */
|
|
|
|
|
|
|
|
if (x2 < 0)
|
|
|
|
{
|
2021-04-05 15:13:30 +02:00
|
|
|
return ERROR;
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (y2 < 0)
|
|
|
|
{
|
2021-04-05 15:13:30 +02:00
|
|
|
return ERROR;
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (x1 > state.vinfo.xres - 1)
|
|
|
|
{
|
2021-04-05 15:13:30 +02:00
|
|
|
return ERROR;
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (y1 > state.vinfo.yres - 1)
|
|
|
|
{
|
2021-04-05 15:13:30 +02:00
|
|
|
return ERROR;
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Truncate the area to the screen */
|
|
|
|
|
|
|
|
act_x1 = x1 < 0 ? 0 : x1;
|
|
|
|
act_y1 = y1 < 0 ? 0 : y1;
|
|
|
|
act_x2 = x2 > state.vinfo.xres - 1 ? state.vinfo.xres - 1 : x2;
|
|
|
|
act_y2 = y2 > state.vinfo.yres - 1 ? state.vinfo.yres - 1 : y2;
|
|
|
|
|
|
|
|
if (state.pinfo.bpp == 8)
|
|
|
|
{
|
2020-04-07 03:00:56 +02:00
|
|
|
uint8_t *fbp8 = (uint8_t *)state.fbmem;
|
2018-01-16 22:35:55 +01:00
|
|
|
uint32_t x;
|
|
|
|
uint32_t y;
|
|
|
|
|
|
|
|
for (y = act_y1; y <= act_y2; y++)
|
|
|
|
{
|
|
|
|
for (x = act_x1; x <= act_x2; x++)
|
|
|
|
{
|
|
|
|
location = x + (y * state.vinfo.xres);
|
|
|
|
fbp8[location] = color_p->full;
|
|
|
|
color_p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
color_p += x2 - act_x2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.pinfo.bpp == 16)
|
|
|
|
{
|
2020-04-07 03:00:56 +02:00
|
|
|
uint16_t *fbp16 = (uint16_t *)state.fbmem;
|
2018-01-16 22:35:55 +01:00
|
|
|
uint32_t x;
|
|
|
|
uint32_t y;
|
|
|
|
|
|
|
|
for (y = act_y1; y <= act_y2; y++)
|
|
|
|
{
|
|
|
|
for (x = act_x1; x <= act_x2; x++)
|
|
|
|
{
|
|
|
|
location = x + (y * state.vinfo.xres);
|
|
|
|
fbp16[location] = color_p->full;
|
|
|
|
color_p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
color_p += x2 - act_x2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.pinfo.bpp == 24 || state.pinfo.bpp == 32)
|
|
|
|
{
|
2020-04-07 03:00:56 +02:00
|
|
|
uint32_t *fbp32 = (uint32_t *)state.fbmem;
|
2018-01-16 22:35:55 +01:00
|
|
|
uint32_t x;
|
|
|
|
uint32_t y;
|
|
|
|
|
|
|
|
for (y = act_y1; y <= act_y2; y++)
|
|
|
|
{
|
|
|
|
for (x = act_x1; x <= act_x2; x++)
|
|
|
|
{
|
|
|
|
location = x + (y * state.vinfo.xres);
|
|
|
|
fbp32[location] = color_p->full;
|
|
|
|
color_p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
color_p += x2 - act_x2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 06:27:14 +02:00
|
|
|
#ifdef CONFIG_FB_UPDATE
|
2021-02-15 10:05:04 +01:00
|
|
|
fb_area.x = act_x1;
|
|
|
|
fb_area.y = act_y1;
|
|
|
|
fb_area.w = act_x2 - act_x1 + 1;
|
|
|
|
fb_area.h = act_y2 - act_y1 + 1;
|
|
|
|
ioctl(state.fd, FBIO_UPDATE, (unsigned long)((uintptr_t)&fb_area));
|
2018-01-16 22:35:55 +01:00
|
|
|
#endif
|
|
|
|
|
2021-04-05 15:13:30 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fbdev_async_flush
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Flush a buffer to the marked area asynchronously.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* disp_drv - LVGL driver interface
|
|
|
|
* area - Area of the screen to be flushed
|
|
|
|
* color_p - A n array of colors
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
|
|
|
|
|
|
|
static void fbdev_async_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area,
|
|
|
|
lv_color_t *color_p)
|
|
|
|
{
|
|
|
|
UNUSED(disp_drv);
|
|
|
|
|
|
|
|
lv_area.y1 = area->y1;
|
|
|
|
lv_area.y2 = area->y2;
|
|
|
|
lv_area.x1 = area->x1;
|
|
|
|
lv_area.x2 = area->x2;
|
|
|
|
|
|
|
|
lv_color_p = color_p;
|
|
|
|
|
|
|
|
sem_post(&flush_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fbdev_sync_flush
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Flush a buffer to the marked area synchronously.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* disp_drv - LVGL driver interface
|
|
|
|
* area - Area of the screen to be flushed
|
|
|
|
* color_p - A n array of colors
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
|
|
|
|
|
|
|
static void fbdev_sync_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area,
|
|
|
|
lv_color_t *color_p)
|
|
|
|
{
|
|
|
|
fbdev_flush_internal(area, color_p);
|
|
|
|
|
2018-01-16 22:35:55 +01:00
|
|
|
/* Tell the flushing is ready */
|
|
|
|
|
2020-04-07 03:00:56 +02:00
|
|
|
lv_disp_flush_ready(disp_drv);
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
|
|
|
|
2021-04-05 15:13:30 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fbdev_write
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Thread for writing the buffer to Framebuffer interface.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* arg - Context data from the parent thread
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Context data to the parent thread
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
|
|
|
|
|
|
|
static pthread_addr_t fbdev_write(pthread_addr_t arg)
|
|
|
|
{
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
|
|
while (ret == OK)
|
|
|
|
{
|
|
|
|
sem_wait(&flush_sem);
|
|
|
|
|
|
|
|
ret = fbdev_flush_internal(&lv_area, lv_color_p);
|
|
|
|
|
|
|
|
sem_post(&wait_sem);
|
|
|
|
}
|
|
|
|
|
|
|
|
gerr("Failed to write buffer contents to display device\n");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-01-16 22:35:55 +01:00
|
|
|
/****************************************************************************
|
2021-02-15 10:05:04 +01:00
|
|
|
* Public Functions
|
2018-01-16 22:35:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2021-02-15 10:05:04 +01:00
|
|
|
* Name: fbdev_init
|
2018-01-16 22:35:55 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2021-02-15 10:05:04 +01:00
|
|
|
* lv_drvr -- LVGL driver interface
|
2018-01-16 22:35:55 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
int fbdev_init(lv_disp_drv_t *lv_drvr)
|
2018-01-16 22:35:55 +01:00
|
|
|
{
|
2021-02-15 10:05:04 +01:00
|
|
|
FAR const char *fbdev = "/dev/fb0";
|
|
|
|
int ret;
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
/* Open the framebuffer driver */
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
state.fd = open(fbdev, O_RDWR);
|
|
|
|
if (state.fd < 0)
|
2018-01-16 22:35:55 +01:00
|
|
|
{
|
2021-02-15 10:05:04 +01:00
|
|
|
int errcode = errno;
|
2021-04-05 15:13:30 +02:00
|
|
|
gerr("Failed to open %s: %d\n", fbdev, errcode);
|
2021-02-15 10:05:04 +01:00
|
|
|
return EXIT_FAILURE;
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
/* Get the characteristics of the framebuffer */
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
ret = ioctl(state.fd, FBIOGET_VIDEOINFO,
|
|
|
|
(unsigned long)((uintptr_t)&state.vinfo));
|
|
|
|
if (ret < 0)
|
2018-01-16 22:35:55 +01:00
|
|
|
{
|
2021-02-15 10:05:04 +01:00
|
|
|
int errcode = errno;
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2021-04-05 15:13:30 +02:00
|
|
|
gerr("ioctl(FBIOGET_VIDEOINFO) failed: %d\n", errcode);
|
2021-02-15 10:05:04 +01:00
|
|
|
close(state.fd);
|
|
|
|
state.fd = -1;
|
|
|
|
return EXIT_FAILURE;
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
ginfo("VideoInfo:\n\tfmt: %u\n\txres: %u\n\tyres: %u\n\tnplanes: %u\n",
|
|
|
|
state.vinfo.fmt, state.vinfo.xres, state.vinfo.yres,
|
|
|
|
state.vinfo.nplanes);
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
ret = ioctl(state.fd, FBIOGET_PLANEINFO,
|
|
|
|
(unsigned long)((uintptr_t)&state.pinfo));
|
|
|
|
if (ret < 0)
|
2018-01-16 22:35:55 +01:00
|
|
|
{
|
2021-02-15 10:05:04 +01:00
|
|
|
int errcode = errno;
|
2021-04-05 15:13:30 +02:00
|
|
|
gerr("ioctl(FBIOGET_PLANEINFO) failed: %d\n", errcode);
|
2021-02-15 10:05:04 +01:00
|
|
|
close(state.fd);
|
|
|
|
state.fd = -1;
|
|
|
|
return EXIT_FAILURE;
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
ginfo("PlaneInfo (plane 0):\n"
|
|
|
|
"\tfbmem: %p\n\tfblen: %l\n\tstride: %u\n"
|
|
|
|
"\tdisplay: %u\n\tbpp: %u\n\t",
|
|
|
|
state.pinfo.fbmem, (unsigned long)state.pinfo.fblen,
|
|
|
|
state.pinfo.stride, state.pinfo.display, state.pinfo.bpp);
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
lv_drvr->hor_res = state.vinfo.xres;
|
|
|
|
lv_drvr->ver_res = state.vinfo.yres;
|
2021-04-05 15:13:30 +02:00
|
|
|
#ifndef CONFIG_EXAMPLES_LVGLDEMO_ASYNC_FLUSH
|
|
|
|
lv_drvr->flush_cb = fbdev_sync_flush;
|
|
|
|
#else
|
|
|
|
lv_drvr->flush_cb = fbdev_async_flush;
|
|
|
|
lv_drvr->wait_cb = fbdev_wait;
|
|
|
|
|
|
|
|
/* Initialize the mutexes for buffer flushing synchronization */
|
|
|
|
|
|
|
|
sem_init(&flush_sem, 0, 0);
|
|
|
|
sem_init(&wait_sem, 0, 0);
|
|
|
|
|
|
|
|
/* Initialize the buffer flushing thread */
|
|
|
|
|
|
|
|
pthread_create(&fb_write_thread, NULL, fbdev_write, NULL);
|
|
|
|
#endif
|
2020-04-07 03:00:56 +02:00
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
/* Only these pixel depths are supported. viinfo.fmt is ignored, only
|
|
|
|
* certain color formats are supported.
|
|
|
|
*/
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
if (state.pinfo.bpp != 32 && state.pinfo.bpp != 16 &&
|
|
|
|
state.pinfo.bpp != 8 && state.pinfo.bpp != 1)
|
2018-01-16 22:35:55 +01:00
|
|
|
{
|
2021-04-05 15:13:30 +02:00
|
|
|
gerr("bpp=%u not supported\n", state.pinfo.bpp);
|
2021-02-15 10:05:04 +01:00
|
|
|
close(state.fd);
|
|
|
|
state.fd = -1;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2018-01-16 22:35:55 +01:00
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
/* mmap() the framebuffer.
|
|
|
|
*
|
|
|
|
* NOTE: In the FLAT build the frame buffer address returned by the
|
|
|
|
* FBIOGET_PLANEINFO IOCTL command will be the same as the framebuffer
|
|
|
|
* address. mmap(), however, is the preferred way to get the framebuffer
|
|
|
|
* address because in the KERNEL build, it will perform the necessary
|
|
|
|
* address mapping to make the memory accessible to the application.
|
|
|
|
*/
|
2020-04-07 03:00:56 +02:00
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
state.fbmem = mmap(NULL, state.pinfo.fblen, PROT_READ | PROT_WRITE,
|
|
|
|
MAP_SHARED | MAP_FILE, state.fd, 0);
|
|
|
|
if (state.fbmem == MAP_FAILED)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
2021-04-05 15:13:30 +02:00
|
|
|
gerr("ioctl(FBIOGET_PLANEINFO) failed: %d\n", errcode);
|
2021-02-15 10:05:04 +01:00
|
|
|
close(state.fd);
|
|
|
|
state.fd = -1;
|
|
|
|
return EXIT_FAILURE;
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|
|
|
|
|
2021-02-15 10:05:04 +01:00
|
|
|
ginfo("Mapped FB: %p\n", state.fbmem);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2018-01-16 22:35:55 +01:00
|
|
|
}
|