2017-09-12 00:26:18 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* drivers/video/fb.c
|
2017-09-12 00:26:18 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-09-12 00:26:18 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-09-12 00:26:18 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-09-12 00:26:18 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-04 07:10:42 +01:00
|
|
|
/* Framebuffer character driver */
|
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2021-05-18 08:59:14 +02:00
|
|
|
#include <assert.h>
|
2021-05-14 04:45:57 +02:00
|
|
|
#include <debug.h>
|
2017-09-12 00:26:18 +02:00
|
|
|
#include <errno.h>
|
2022-11-29 15:00:43 +01:00
|
|
|
#include <poll.h>
|
2017-09-12 00:26:18 +02:00
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/fs/fs.h>
|
|
|
|
#include <nuttx/fs/ioctl.h>
|
|
|
|
#include <nuttx/video/fb.h>
|
2023-03-27 08:09:59 +02:00
|
|
|
#include <nuttx/clock.h>
|
|
|
|
#include <nuttx/wdog.h>
|
2023-07-19 15:11:07 +02:00
|
|
|
#include <nuttx/mm/circbuf.h>
|
2017-09-12 00:26:18 +02:00
|
|
|
|
2023-03-30 09:07:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
struct fb_priv_s
|
|
|
|
{
|
2023-09-11 04:40:20 +02:00
|
|
|
/* Supports a singly linked list */
|
|
|
|
|
|
|
|
FAR struct fb_priv_s *flink;
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
int overlay; /* Overlay number */
|
2023-09-11 04:40:20 +02:00
|
|
|
|
|
|
|
/* Polling fds of waiting threads */
|
|
|
|
|
|
|
|
FAR struct pollfd *fds[CONFIG_VIDEO_FB_NPOLLWAITERS];
|
|
|
|
|
|
|
|
#ifdef CONFIG_FB_SYNC
|
|
|
|
sem_t wait;
|
|
|
|
#endif
|
2023-07-19 15:11:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fb_paninfo_s
|
|
|
|
{
|
|
|
|
FAR struct circbuf_s buf; /* Pan buffer queued list */
|
|
|
|
|
2023-09-28 10:31:55 +02:00
|
|
|
struct wdog_s wdog; /* VSync offset timer */
|
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
FAR struct fb_chardev_s *dev;
|
2023-07-19 15:11:07 +02:00
|
|
|
};
|
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
/* This structure defines one framebuffer device. Note that which is
|
|
|
|
* everything in this structure is constant data set up and initialization
|
|
|
|
* time. Therefore, no there is requirement for serialized access to this
|
|
|
|
* structure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct fb_chardev_s
|
|
|
|
{
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_vtable_s *vtable; /* Framebuffer interface */
|
|
|
|
uint8_t plane; /* Video plan number */
|
|
|
|
clock_t vsyncoffset; /* VSync offset ticks */
|
2023-09-11 04:40:20 +02:00
|
|
|
FAR struct fb_priv_s *head;
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_paninfo_s *paninfo; /* Pan info array */
|
|
|
|
size_t paninfo_count; /* Pan info count */
|
2023-03-30 09:07:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct fb_panelinfo_s
|
|
|
|
{
|
|
|
|
FAR void *fbmem; /* Start of frame buffer memory */
|
|
|
|
size_t fblen; /* Size of the framebuffer */
|
2023-07-19 15:11:07 +02:00
|
|
|
uint8_t fbcount; /* Count of frame buffer */
|
2023-03-30 09:07:42 +02:00
|
|
|
uint8_t bpp; /* Bits per pixel */
|
2017-09-12 00:26:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
static FAR struct circbuf_s *fb_get_panbuf(FAR struct fb_chardev_s *fb,
|
|
|
|
int overlay);
|
2023-09-11 04:40:20 +02:00
|
|
|
static int fb_add_paninfo(FAR struct fb_chardev_s *fb,
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR const union fb_paninfo_u *info,
|
|
|
|
int overlay);
|
2024-08-08 09:51:09 +02:00
|
|
|
static int fb_clear_paninfo(FAR struct fb_chardev_s *fb,
|
|
|
|
int overlay);
|
2023-05-06 12:05:08 +02:00
|
|
|
static int fb_open(FAR struct file *filep);
|
|
|
|
static int fb_close(FAR struct file *filep);
|
2017-09-12 00:26:18 +02:00
|
|
|
static ssize_t fb_read(FAR struct file *filep, FAR char *buffer,
|
2022-04-12 12:16:13 +02:00
|
|
|
size_t buflen);
|
2017-09-12 00:26:18 +02:00
|
|
|
static ssize_t fb_write(FAR struct file *filep, FAR const char *buffer,
|
2022-04-12 12:16:13 +02:00
|
|
|
size_t buflen);
|
2017-09-12 00:26:18 +02:00
|
|
|
static off_t fb_seek(FAR struct file *filep, off_t offset, int whence);
|
|
|
|
static int fb_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
2023-01-02 14:02:51 +01:00
|
|
|
static int fb_mmap(FAR struct file *filep,
|
|
|
|
FAR struct mm_map_entry_s *map);
|
2022-11-29 15:00:43 +01:00
|
|
|
static int fb_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|
|
|
bool setup);
|
2023-03-30 09:07:42 +02:00
|
|
|
static int fb_get_panelinfo(FAR struct fb_chardev_s *fb,
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_panelinfo_s *panelinfo,
|
|
|
|
int overlay);
|
2023-07-21 10:33:48 +02:00
|
|
|
static int fb_get_planeinfo(FAR struct fb_chardev_s *fb,
|
|
|
|
FAR struct fb_planeinfo_s *pinfo,
|
|
|
|
uint8_t display);
|
2023-09-11 04:40:20 +02:00
|
|
|
#ifdef CONFIG_FB_SYNC
|
|
|
|
static int fb_sem_wait(FAR struct fb_chardev_s *fb,
|
|
|
|
FAR struct fb_priv_s *priv,
|
|
|
|
int overlay);
|
|
|
|
static void fb_sem_post(FAR struct fb_chardev_s *fb, int overlay);
|
|
|
|
#endif
|
2017-09-12 00:26:18 +02:00
|
|
|
|
2024-05-05 02:04:47 +02:00
|
|
|
#ifdef CONFIG_BUILD_KERNEL
|
|
|
|
static int fb_munmap(FAR struct task_group_s *group,
|
|
|
|
FAR struct mm_map_entry_s *entry,
|
|
|
|
FAR void *start, size_t length);
|
|
|
|
#endif
|
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-04-22 16:43:07 +02:00
|
|
|
static const struct file_operations g_fb_fops =
|
2017-09-12 00:26:18 +02:00
|
|
|
{
|
2023-05-06 12:05:08 +02:00
|
|
|
fb_open, /* open */
|
|
|
|
fb_close, /* close */
|
2017-09-12 00:26:18 +02:00
|
|
|
fb_read, /* read */
|
|
|
|
fb_write, /* write */
|
|
|
|
fb_seek, /* seek */
|
2019-05-22 02:57:54 +02:00
|
|
|
fb_ioctl, /* ioctl */
|
2023-01-02 14:02:51 +01:00
|
|
|
fb_mmap, /* mmap */
|
2023-01-02 18:06:12 +01:00
|
|
|
NULL, /* truncate */
|
2022-11-29 15:00:43 +01:00
|
|
|
fb_poll /* poll */
|
2017-09-12 00:26:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_get_panbuf
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static FAR struct circbuf_s *fb_get_panbuf(FAR struct fb_chardev_s *fb,
|
|
|
|
int overlay)
|
|
|
|
{
|
|
|
|
int id = overlay + 1;
|
|
|
|
|
|
|
|
DEBUGASSERT(id >= 0 && id < fb->paninfo_count);
|
|
|
|
|
|
|
|
return &(fb->paninfo[id].buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_add_paninfo
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
static int fb_add_paninfo(FAR struct fb_chardev_s *fb,
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR const union fb_paninfo_u *info,
|
|
|
|
int overlay)
|
|
|
|
{
|
|
|
|
FAR struct circbuf_s *panbuf;
|
|
|
|
irqstate_t flags;
|
|
|
|
ssize_t ret;
|
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
DEBUGASSERT(fb != NULL);
|
2023-07-19 15:11:07 +02:00
|
|
|
|
|
|
|
panbuf = fb_get_panbuf(fb, overlay);
|
|
|
|
if (panbuf == NULL)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable the interrupt when writing to the queue to
|
|
|
|
* prevent it from being modified by the interrupted
|
|
|
|
* thread during the writing process.
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
/* Write planeinfo information to the queue. */
|
|
|
|
|
|
|
|
ret = circbuf_write(panbuf, info, sizeof(union fb_paninfo_u));
|
2024-01-09 07:35:22 +01:00
|
|
|
if (ret != sizeof(union fb_paninfo_u))
|
|
|
|
{
|
|
|
|
gwarn("WARNING: circbuf_write(panbuf) failed\n");
|
|
|
|
}
|
2023-07-19 15:11:07 +02:00
|
|
|
|
|
|
|
/* Re-enable interrupts */
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return ret <= 0 ? -ENOSPC : OK;
|
|
|
|
}
|
|
|
|
|
2024-08-08 09:51:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_clear_paninfo
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int fb_clear_paninfo(FAR struct fb_chardev_s *fb,
|
|
|
|
int overlay)
|
|
|
|
{
|
|
|
|
FAR struct circbuf_s *panbuf;
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
DEBUGASSERT(fb != NULL);
|
|
|
|
|
|
|
|
panbuf = fb_get_panbuf(fb, overlay);
|
|
|
|
if (panbuf == NULL)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable the interrupt when writing to the queue to
|
|
|
|
* prevent it from being modified by the interrupted
|
|
|
|
* thread during the writing process.
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
circbuf_reset(panbuf);
|
|
|
|
|
|
|
|
/* Re-enable interrupts */
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2023-05-06 12:05:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_open
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int fb_open(FAR struct file *filep)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_priv_s *priv;
|
2023-09-11 04:40:20 +02:00
|
|
|
irqstate_t flags;
|
2023-05-06 12:05:08 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
inode = filep->f_inode;
|
|
|
|
fb = inode->i_private;
|
|
|
|
|
|
|
|
DEBUGASSERT(fb->vtable != NULL);
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
priv = kmm_zalloc(sizeof(*priv));
|
|
|
|
if (priv == NULL)
|
|
|
|
{
|
2023-09-11 04:40:20 +02:00
|
|
|
return -ENOMEM;
|
2023-07-19 15:11:07 +02:00
|
|
|
}
|
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
if (fb->head == NULL)
|
2023-05-06 12:05:08 +02:00
|
|
|
{
|
2023-07-19 15:11:07 +02:00
|
|
|
if (fb->vtable->open != NULL &&
|
|
|
|
(ret = fb->vtable->open(fb->vtable)) < 0)
|
2023-05-06 12:05:08 +02:00
|
|
|
{
|
2023-07-19 15:11:07 +02:00
|
|
|
goto err_fb;
|
2023-05-06 12:05:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
priv->overlay = FB_NO_OVERLAY;
|
2023-09-11 04:40:20 +02:00
|
|
|
#ifdef CONFIG_FB_SYNC
|
|
|
|
nxsem_init(&priv->wait, 0, 0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Attach the open structure to the device */
|
|
|
|
|
|
|
|
priv->flink = fb->head;
|
|
|
|
fb->head = priv;
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
filep->f_priv = priv;
|
2023-05-06 12:05:08 +02:00
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
leave_critical_section(flags);
|
2023-07-19 15:11:07 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_fb:
|
2023-09-11 04:40:20 +02:00
|
|
|
leave_critical_section(flags);
|
2023-07-19 15:11:07 +02:00
|
|
|
kmm_free(priv);
|
2023-05-06 12:05:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_close
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int fb_close(FAR struct file *filep)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_priv_s *priv;
|
2023-09-11 04:40:20 +02:00
|
|
|
FAR struct fb_priv_s *curr;
|
|
|
|
FAR struct fb_priv_s *prev;
|
|
|
|
irqstate_t flags;
|
2023-05-06 12:05:08 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
inode = filep->f_inode;
|
|
|
|
fb = inode->i_private;
|
2023-07-19 15:11:07 +02:00
|
|
|
priv = filep->f_priv;
|
2023-05-06 12:05:08 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
DEBUGASSERT(fb->vtable != NULL && priv != NULL);
|
2023-05-06 12:05:08 +02:00
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
flags = enter_critical_section();
|
2023-05-06 12:05:08 +02:00
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
DEBUGASSERT(fb->head);
|
|
|
|
if (fb->head->flink == NULL)
|
2023-05-06 12:05:08 +02:00
|
|
|
{
|
|
|
|
if (fb->vtable->close != NULL)
|
|
|
|
{
|
|
|
|
ret = fb->vtable->close(fb->vtable);
|
2023-09-11 04:40:20 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return ret;
|
|
|
|
}
|
2023-05-06 12:05:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
/* Find the open structure in the list of
|
|
|
|
* open structures for the device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (prev = NULL, curr = fb->head;
|
|
|
|
curr && curr != priv;
|
|
|
|
prev = curr, curr = curr->flink);
|
|
|
|
|
|
|
|
DEBUGASSERT(curr);
|
|
|
|
|
|
|
|
/* Remove the structure from the device */
|
|
|
|
|
|
|
|
if (prev)
|
2023-05-06 12:05:08 +02:00
|
|
|
{
|
2023-09-11 04:40:20 +02:00
|
|
|
prev->flink = priv->flink;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fb->head = priv->flink;
|
2023-05-06 12:05:08 +02:00
|
|
|
}
|
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
|
|
|
|
#ifdef CONFIG_FB_SYNC
|
|
|
|
nxsem_destroy(&priv->wait);
|
|
|
|
#endif
|
|
|
|
kmm_free(priv);
|
|
|
|
|
|
|
|
return OK;
|
2023-05-06 12:05:08 +02:00
|
|
|
}
|
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_read
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t fb_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_priv_s *priv;
|
2023-03-30 09:07:42 +02:00
|
|
|
struct fb_panelinfo_s panelinfo;
|
2017-09-12 00:26:18 +02:00
|
|
|
size_t start;
|
|
|
|
size_t end;
|
|
|
|
size_t size;
|
2023-03-30 09:07:42 +02:00
|
|
|
int ret;
|
2017-09-12 00:26:18 +02:00
|
|
|
|
|
|
|
ginfo("len: %u\n", (unsigned int)len);
|
|
|
|
|
|
|
|
/* Get the framebuffer instance */
|
|
|
|
|
|
|
|
inode = filep->f_inode;
|
2023-08-29 06:16:49 +02:00
|
|
|
fb = inode->i_private;
|
2023-07-19 15:11:07 +02:00
|
|
|
priv = filep->f_priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(fb->vtable != NULL && priv != NULL);
|
2017-09-12 00:26:18 +02:00
|
|
|
|
2023-03-30 09:07:42 +02:00
|
|
|
/* Get panel info */
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
ret = fb_get_panelinfo(fb, &panelinfo, priv->overlay);
|
2023-03-30 09:07:42 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
/* Get the start and size of the transfer */
|
|
|
|
|
2017-09-14 16:43:41 +02:00
|
|
|
start = filep->f_pos;
|
2023-03-30 09:07:42 +02:00
|
|
|
if (start >= panelinfo.fblen)
|
2017-09-12 00:26:18 +02:00
|
|
|
{
|
|
|
|
return 0; /* Return end-of-file */
|
|
|
|
}
|
|
|
|
|
|
|
|
end = start + len;
|
2023-03-30 09:07:42 +02:00
|
|
|
if (end >= panelinfo.fblen)
|
2017-09-12 00:26:18 +02:00
|
|
|
{
|
2023-03-30 09:07:42 +02:00
|
|
|
end = panelinfo.fblen;
|
2017-09-12 00:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size = end - start;
|
|
|
|
|
|
|
|
/* And transfer the data from the frame buffer */
|
|
|
|
|
2023-03-30 09:07:42 +02:00
|
|
|
memcpy(buffer, panelinfo.fbmem + start, size);
|
2017-09-12 00:26:18 +02:00
|
|
|
filep->f_pos += size;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_write
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-09-17 18:38:34 +02:00
|
|
|
static ssize_t fb_write(FAR struct file *filep, FAR const char *buffer,
|
|
|
|
size_t len)
|
2017-09-12 00:26:18 +02:00
|
|
|
{
|
|
|
|
FAR struct inode *inode;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_priv_s *priv;
|
2023-03-30 09:07:42 +02:00
|
|
|
struct fb_panelinfo_s panelinfo;
|
2017-09-12 00:26:18 +02:00
|
|
|
size_t start;
|
|
|
|
size_t end;
|
|
|
|
size_t size;
|
2023-03-30 09:07:42 +02:00
|
|
|
int ret;
|
2017-09-12 00:26:18 +02:00
|
|
|
|
|
|
|
ginfo("len: %u\n", (unsigned int)len);
|
|
|
|
|
|
|
|
/* Get the framebuffer instance */
|
|
|
|
|
|
|
|
inode = filep->f_inode;
|
2023-08-29 06:16:49 +02:00
|
|
|
fb = inode->i_private;
|
2023-07-19 15:11:07 +02:00
|
|
|
priv = filep->f_priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(fb->vtable != NULL && priv != NULL);
|
2017-09-12 00:26:18 +02:00
|
|
|
|
2023-03-30 09:07:42 +02:00
|
|
|
/* Get panel info */
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
ret = fb_get_panelinfo(fb, &panelinfo, priv->overlay);
|
2023-03-30 09:07:42 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
/* Get the start and size of the transfer */
|
|
|
|
|
2017-09-14 16:43:41 +02:00
|
|
|
start = filep->f_pos;
|
2023-03-30 09:07:42 +02:00
|
|
|
if (start >= panelinfo.fblen)
|
2017-09-12 00:26:18 +02:00
|
|
|
{
|
|
|
|
return -EFBIG; /* Cannot extend the framebuffer */
|
|
|
|
}
|
|
|
|
|
|
|
|
end = start + len;
|
2023-03-30 09:07:42 +02:00
|
|
|
if (end >= panelinfo.fblen)
|
2017-09-12 00:26:18 +02:00
|
|
|
{
|
2023-03-30 09:07:42 +02:00
|
|
|
end = panelinfo.fblen;
|
2017-09-12 00:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size = end - start;
|
|
|
|
|
|
|
|
/* And transfer the data into the frame buffer */
|
|
|
|
|
2023-03-30 09:07:42 +02:00
|
|
|
memcpy(panelinfo.fbmem + start, buffer, size);
|
2017-09-12 00:26:18 +02:00
|
|
|
filep->f_pos += size;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_seek
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Seek the logical file pointer to the specified position. The offset
|
|
|
|
* is in units of pixels, with offset zero being the beginning of the
|
|
|
|
* framebuffer.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static off_t fb_seek(FAR struct file *filep, off_t offset, int whence)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_priv_s *priv;
|
2023-03-30 09:07:42 +02:00
|
|
|
struct fb_panelinfo_s panelinfo;
|
2017-09-12 00:26:18 +02:00
|
|
|
off_t newpos;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ginfo("offset: %u whence: %d\n", (unsigned int)offset, whence);
|
|
|
|
|
|
|
|
/* Get the framebuffer instance */
|
|
|
|
|
|
|
|
inode = filep->f_inode;
|
2023-08-29 06:16:49 +02:00
|
|
|
fb = inode->i_private;
|
2023-07-19 15:11:07 +02:00
|
|
|
priv = filep->f_priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(fb->vtable != NULL && priv != NULL);
|
2017-09-12 00:26:18 +02:00
|
|
|
|
|
|
|
/* Determine the new, requested file position */
|
|
|
|
|
|
|
|
switch (whence)
|
|
|
|
{
|
|
|
|
case SEEK_CUR:
|
|
|
|
newpos = filep->f_pos + offset;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEEK_SET:
|
|
|
|
newpos = offset;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SEEK_END:
|
2023-03-30 09:07:42 +02:00
|
|
|
|
|
|
|
/* Get panel info */
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
ret = fb_get_panelinfo(fb, &panelinfo, priv->overlay);
|
2023-03-30 09:07:42 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
newpos = panelinfo.fblen + offset;
|
2017-09-12 00:26:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-07-22 12:11:01 +02:00
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
/* Return EINVAL if the whence argument is invalid */
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Opengroup.org:
|
|
|
|
*
|
2020-07-22 12:11:01 +02:00
|
|
|
* "The lseek() function shall allow the file offset to be set beyond the
|
|
|
|
* end of the existing data in the file. If data is later written at this
|
|
|
|
* point, subsequent reads of data in the gap shall return bytes with the
|
|
|
|
* value 0 until data is actually written into the gap."
|
2017-09-12 00:26:18 +02:00
|
|
|
*
|
2020-07-22 12:11:01 +02:00
|
|
|
* We can conform to the first part, but not the second. Return EINVAL if
|
|
|
|
* "...the resulting file offset would be negative for a regular file,
|
|
|
|
* block special file, or directory."
|
2017-09-12 00:26:18 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (newpos >= 0)
|
|
|
|
{
|
|
|
|
filep->f_pos = newpos;
|
|
|
|
ret = newpos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The standard ioctl method.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int fb_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
2024-04-03 09:08:16 +02:00
|
|
|
int ret = OK;
|
2017-09-12 00:26:18 +02:00
|
|
|
|
|
|
|
ginfo("cmd: %d arg: %ld\n", cmd, arg);
|
|
|
|
|
|
|
|
/* Get the framebuffer instance */
|
|
|
|
|
|
|
|
inode = filep->f_inode;
|
2023-08-29 06:16:49 +02:00
|
|
|
fb = inode->i_private;
|
2017-09-12 00:26:18 +02:00
|
|
|
|
|
|
|
/* Process the IOCTL command */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case FBIOGET_VIDEOINFO: /* Get color plane info */
|
|
|
|
{
|
|
|
|
FAR struct fb_videoinfo_s *vinfo =
|
|
|
|
(FAR struct fb_videoinfo_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(vinfo != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->getvideoinfo != NULL);
|
|
|
|
ret = fb->vtable->getvideoinfo(fb->vtable, vinfo);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOGET_PLANEINFO: /* Get video plane info */
|
|
|
|
{
|
|
|
|
FAR struct fb_planeinfo_s *pinfo =
|
|
|
|
(FAR struct fb_planeinfo_s *)((uintptr_t)arg);
|
|
|
|
|
2023-07-21 10:33:48 +02:00
|
|
|
DEBUGASSERT(pinfo != 0);
|
|
|
|
ret = fb_get_planeinfo(fb, pinfo, pinfo->display);
|
2017-09-12 00:26:18 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef CONFIG_FB_CMAP
|
|
|
|
case FBIOGET_CMAP: /* Get RGB color mapping */
|
|
|
|
{
|
|
|
|
FAR struct fb_cmap_s *cmap =
|
|
|
|
(FAR struct fb_cmap_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(cmap != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->getcmap != NULL);
|
|
|
|
ret = fb->vtable->getcmap(fb->vtable, cmap);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOPUT_CMAP: /* Put RGB color mapping */
|
|
|
|
{
|
|
|
|
FAR const struct fb_cmap_s *cmap =
|
|
|
|
(FAR struct fb_cmap_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(cmap != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->putcmap != NULL);
|
|
|
|
ret = fb->vtable->putcmap(fb->vtable, cmap);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_FB_HWCURSOR
|
|
|
|
case FBIOGET_CURSOR: /* Get cursor attributes */
|
|
|
|
{
|
|
|
|
FAR struct fb_cursorattrib_s *attrib =
|
|
|
|
(FAR struct fb_cursorattrib_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(attrib != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->getcursor != NULL);
|
|
|
|
ret = fb->vtable->getcursor(fb->vtable, attrib);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
case FBIOPUT_CURSOR: /* Set cursor attributes */
|
2017-09-12 00:26:18 +02:00
|
|
|
{
|
|
|
|
FAR struct fb_setcursor_s *cursor =
|
|
|
|
(FAR struct fb_setcursor_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(cursor != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->setcursor != NULL);
|
|
|
|
ret = fb->vtable->setcursor(fb->vtable, cursor);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2020-06-04 04:35:50 +02:00
|
|
|
#ifdef CONFIG_FB_UPDATE
|
|
|
|
case FBIO_UPDATE: /* Update the modified framebuffer data */
|
2017-09-12 00:43:12 +02:00
|
|
|
{
|
2020-06-04 04:35:50 +02:00
|
|
|
struct fb_area_s *area = (FAR struct fb_area_s *)((uintptr_t)arg);
|
2017-09-12 00:43:12 +02:00
|
|
|
|
2020-06-04 04:35:50 +02:00
|
|
|
DEBUGASSERT(fb->vtable != NULL && fb->vtable->updatearea != NULL);
|
|
|
|
ret = fb->vtable->updatearea(fb->vtable, area);
|
2017-09-12 00:43:12 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2018-05-18 00:11:09 +02:00
|
|
|
#ifdef CONFIG_FB_SYNC
|
|
|
|
case FBIO_WAITFORVSYNC: /* Wait upon vertical sync */
|
|
|
|
{
|
2023-09-11 04:40:20 +02:00
|
|
|
FAR struct fb_priv_s *priv = (FAR struct fb_priv_s *)filep->f_priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(fb->vtable != NULL);
|
|
|
|
if (fb->vtable->waitforvsync != NULL)
|
|
|
|
{
|
|
|
|
ret = fb->vtable->waitforvsync(fb->vtable);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = fb_sem_wait(fb, priv, priv->overlay);
|
2018-05-18 00:11:09 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_FB_OVERLAY
|
|
|
|
case FBIO_SELECT_OVERLAY: /* Select video overlay */
|
|
|
|
{
|
|
|
|
struct fb_overlayinfo_s oinfo;
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_priv_s *priv = filep->f_priv;
|
2018-05-18 00:11:09 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
DEBUGASSERT(priv != NULL && fb->vtable != NULL &&
|
2020-07-22 12:11:01 +02:00
|
|
|
fb->vtable->getoverlayinfo != NULL);
|
2024-04-03 09:08:16 +02:00
|
|
|
if (arg != FB_NO_OVERLAY)
|
|
|
|
{
|
|
|
|
memset(&oinfo, 0, sizeof(oinfo));
|
|
|
|
ret = fb->vtable->getoverlayinfo(fb->vtable, arg, &oinfo);
|
|
|
|
}
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
if (ret >= 0)
|
2018-05-18 00:11:09 +02:00
|
|
|
{
|
2023-07-19 15:11:07 +02:00
|
|
|
priv->overlay = arg;
|
2018-05-18 00:11:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOGET_OVERLAYINFO: /* Get video overlay info */
|
|
|
|
{
|
|
|
|
FAR struct fb_overlayinfo_s *oinfo =
|
|
|
|
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(oinfo != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->getoverlayinfo != NULL);
|
2020-07-22 12:11:01 +02:00
|
|
|
ret = fb->vtable->getoverlayinfo(fb->vtable,
|
|
|
|
oinfo->overlay, oinfo);
|
2018-05-18 00:11:09 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOSET_TRANSP: /* Set video overlay transparency */
|
|
|
|
{
|
|
|
|
FAR struct fb_overlayinfo_s *oinfo =
|
|
|
|
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(oinfo != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->settransp != NULL);
|
|
|
|
ret = fb->vtable->settransp(fb->vtable, oinfo);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOSET_CHROMAKEY: /* Set video overlay chroma key */
|
|
|
|
{
|
|
|
|
FAR struct fb_overlayinfo_s *oinfo =
|
|
|
|
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(oinfo != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->setchromakey != NULL);
|
|
|
|
ret = fb->vtable->setchromakey(fb->vtable, oinfo);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOSET_COLOR: /* Set video overlay color */
|
|
|
|
{
|
|
|
|
FAR struct fb_overlayinfo_s *oinfo =
|
|
|
|
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(oinfo != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->setcolor != NULL);
|
|
|
|
ret = fb->vtable->setcolor(fb->vtable, oinfo);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOSET_BLANK: /* Blank or unblank video overlay */
|
|
|
|
{
|
|
|
|
FAR struct fb_overlayinfo_s *oinfo =
|
|
|
|
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(oinfo != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->setblank != NULL);
|
|
|
|
ret = fb->vtable->setblank(fb->vtable, oinfo);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOSET_AREA: /* Set active video overlay area */
|
|
|
|
{
|
|
|
|
FAR struct fb_overlayinfo_s *oinfo =
|
|
|
|
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(oinfo != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->setarea != NULL);
|
|
|
|
ret = fb->vtable->setarea(fb->vtable, oinfo);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-06-20 12:02:29 +02:00
|
|
|
case FBIOSET_DESTAREA: /* Set destination area on the primary FB */
|
|
|
|
{
|
|
|
|
FAR struct fb_overlayinfo_s *oinfo =
|
|
|
|
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(oinfo != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->setdestarea != NULL);
|
|
|
|
ret = fb->vtable->setdestarea(fb->vtable, oinfo);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-05-18 00:11:09 +02:00
|
|
|
#ifdef CONFIG_FB_OVERLAY_BLIT
|
|
|
|
case FBIOSET_BLIT: /* Blit operation between video overlays */
|
|
|
|
{
|
|
|
|
FAR struct fb_overlayblit_s *blit =
|
|
|
|
(FAR struct fb_overlayblit_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(blit != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->blit != NULL);
|
|
|
|
ret = fb->vtable->blit(fb->vtable, blit);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOSET_BLEND: /* Blend operation between video overlays */
|
|
|
|
{
|
|
|
|
FAR struct fb_overlayblend_s *blend =
|
|
|
|
(FAR struct fb_overlayblend_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(blend != 0 && fb->vtable != NULL &&
|
|
|
|
fb->vtable->blend != NULL);
|
|
|
|
ret = fb->vtable->blend(fb->vtable, blend);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2023-06-20 12:02:29 +02:00
|
|
|
|
|
|
|
case FBIOPAN_OVERLAY:
|
|
|
|
{
|
|
|
|
FAR struct fb_overlayinfo_s *oinfo =
|
|
|
|
(FAR struct fb_overlayinfo_s *)((uintptr_t)arg);
|
2023-07-19 15:11:07 +02:00
|
|
|
union fb_paninfo_u paninfo;
|
2023-06-20 12:02:29 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
DEBUGASSERT(oinfo != 0 && fb->vtable != NULL);
|
|
|
|
|
|
|
|
memcpy(&paninfo, oinfo, sizeof(*oinfo));
|
|
|
|
|
|
|
|
if (fb->vtable->panoverlay != NULL)
|
|
|
|
{
|
|
|
|
fb->vtable->panoverlay(fb->vtable, oinfo);
|
|
|
|
}
|
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
ret = fb_add_paninfo(fb, &paninfo, oinfo->overlay);
|
2023-06-20 12:02:29 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-05-18 00:11:09 +02:00
|
|
|
#endif /* CONFIG_FB_OVERLAY */
|
|
|
|
|
2021-09-04 09:34:31 +02:00
|
|
|
case FBIOSET_POWER:
|
|
|
|
{
|
|
|
|
DEBUGASSERT(fb->vtable != NULL &&
|
|
|
|
fb->vtable->setpower != NULL);
|
|
|
|
ret = fb->vtable->setpower(fb->vtable, (int)arg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOGET_POWER:
|
|
|
|
{
|
|
|
|
FAR int *power = (FAR int *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(power != NULL && fb->vtable != NULL &&
|
|
|
|
fb->vtable->getpower != NULL);
|
|
|
|
*(power) = fb->vtable->getpower(fb->vtable);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOGET_FRAMERATE:
|
|
|
|
{
|
|
|
|
FAR int *rate = (FAR int *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(rate != NULL && fb->vtable != NULL &&
|
|
|
|
fb->vtable->getframerate != NULL);
|
|
|
|
*(rate) = fb->vtable->getframerate(fb->vtable);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOSET_FRAMERATE:
|
|
|
|
{
|
|
|
|
DEBUGASSERT(fb->vtable != NULL &&
|
|
|
|
fb->vtable->setframerate != NULL);
|
|
|
|
ret = fb->vtable->setframerate(fb->vtable, (int)arg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-09-30 07:47:00 +02:00
|
|
|
case FBIOPAN_DISPLAY:
|
|
|
|
{
|
|
|
|
FAR struct fb_planeinfo_s *pinfo =
|
|
|
|
(FAR struct fb_planeinfo_s *)((uintptr_t)arg);
|
2023-07-19 15:11:07 +02:00
|
|
|
union fb_paninfo_u paninfo;
|
|
|
|
|
|
|
|
DEBUGASSERT(pinfo != NULL && fb->vtable != NULL);
|
2021-09-30 07:47:00 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
memcpy(&paninfo, pinfo, sizeof(*pinfo));
|
2023-02-24 10:21:25 +01:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
if (fb->vtable->pandisplay != NULL)
|
|
|
|
{
|
|
|
|
fb->vtable->pandisplay(fb->vtable, pinfo);
|
|
|
|
}
|
2023-07-13 06:23:54 +02:00
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
ret = fb_add_paninfo(fb, &paninfo, FB_NO_OVERLAY);
|
2021-09-30 07:47:00 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2024-08-08 09:51:09 +02:00
|
|
|
case FBIOPAN_CLEAR:
|
|
|
|
{
|
|
|
|
ret = fb_clear_paninfo(fb, (int)arg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2023-03-27 08:09:59 +02:00
|
|
|
case FBIOSET_VSYNCOFFSET:
|
|
|
|
{
|
|
|
|
fb->vsyncoffset = USEC2TICK(arg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-12-13 09:42:12 +01:00
|
|
|
case FBIOGET_VSCREENINFO:
|
|
|
|
{
|
|
|
|
struct fb_videoinfo_s vinfo;
|
|
|
|
struct fb_planeinfo_s pinfo;
|
|
|
|
FAR struct fb_var_screeninfo *varinfo =
|
|
|
|
(FAR struct fb_var_screeninfo *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(varinfo != 0 && fb->vtable != NULL &&
|
2023-07-21 10:33:48 +02:00
|
|
|
fb->vtable->getvideoinfo != NULL);
|
2022-12-13 09:42:12 +01:00
|
|
|
ret = fb->vtable->getvideoinfo(fb->vtable, &vinfo);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-07-21 10:33:48 +02:00
|
|
|
ret = fb_get_planeinfo(fb, &pinfo, 0);
|
2022-12-13 09:42:12 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(varinfo, 0, sizeof(struct fb_var_screeninfo));
|
|
|
|
varinfo->xres = vinfo.xres;
|
|
|
|
varinfo->yres = vinfo.yres;
|
|
|
|
varinfo->xres_virtual = pinfo.xres_virtual;
|
|
|
|
varinfo->yres_virtual = pinfo.yres_virtual;
|
|
|
|
varinfo->xoffset = pinfo.xoffset;
|
|
|
|
varinfo->yoffset = pinfo.yoffset;
|
|
|
|
varinfo->bits_per_pixel = pinfo.bpp;
|
|
|
|
varinfo->grayscale = FB_ISMONO(vinfo.fmt);
|
|
|
|
switch (vinfo.fmt)
|
|
|
|
{
|
|
|
|
case FB_FMT_Y1:
|
|
|
|
varinfo->red.offset = 0;
|
|
|
|
varinfo->green.offset = 0;
|
|
|
|
varinfo->blue.offset = 0;
|
|
|
|
varinfo->red.length = 1;
|
|
|
|
varinfo->green.length = 1;
|
|
|
|
varinfo->blue.length = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FB_FMT_Y8:
|
|
|
|
varinfo->red.offset = 0;
|
|
|
|
varinfo->green.offset = 0;
|
|
|
|
varinfo->blue.offset = 0;
|
|
|
|
varinfo->red.length = 8;
|
|
|
|
varinfo->green.length = 8;
|
|
|
|
varinfo->blue.length = 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FB_FMT_RGB16_555:
|
|
|
|
varinfo->red.offset = 10;
|
|
|
|
varinfo->green.offset = 5;
|
|
|
|
varinfo->blue.offset = 0;
|
|
|
|
varinfo->red.length = 5;
|
|
|
|
varinfo->green.length = 5;
|
|
|
|
varinfo->blue.length = 5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FB_FMT_RGB16_565:
|
|
|
|
varinfo->red.offset = 11;
|
|
|
|
varinfo->green.offset = 5;
|
|
|
|
varinfo->blue.offset = 0;
|
|
|
|
varinfo->red.length = 5;
|
|
|
|
varinfo->green.length = 6;
|
|
|
|
varinfo->blue.length = 5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FB_FMT_RGB24:
|
|
|
|
case FB_FMT_RGB32:
|
|
|
|
varinfo->red.offset = 16;
|
|
|
|
varinfo->green.offset = 8;
|
|
|
|
varinfo->blue.offset = 0;
|
|
|
|
varinfo->red.length = 8;
|
|
|
|
varinfo->green.length = 8;
|
|
|
|
varinfo->blue.length = 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FB_FMT_RGBA32:
|
|
|
|
varinfo->red.offset = 16;
|
|
|
|
varinfo->green.offset = 8;
|
|
|
|
varinfo->blue.offset = 0;
|
|
|
|
varinfo->transp.offset = 24;
|
|
|
|
varinfo->red.length = 8;
|
|
|
|
varinfo->green.length = 8;
|
|
|
|
varinfo->blue.length = 8;
|
|
|
|
varinfo->transp.length = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FBIOGET_FSCREENINFO:
|
|
|
|
{
|
|
|
|
struct fb_videoinfo_s vinfo;
|
|
|
|
struct fb_planeinfo_s pinfo;
|
|
|
|
FAR struct fb_fix_screeninfo *fixinfo =
|
|
|
|
(FAR struct fb_fix_screeninfo *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
DEBUGASSERT(fixinfo != 0 && fb->vtable != NULL &&
|
2023-07-21 10:33:48 +02:00
|
|
|
fb->vtable->getvideoinfo != NULL);
|
2022-12-13 09:42:12 +01:00
|
|
|
ret = fb->vtable->getvideoinfo(fb->vtable, &vinfo);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-07-21 10:33:48 +02:00
|
|
|
ret = fb_get_planeinfo(fb, &pinfo, 0);
|
2022-12-13 09:42:12 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(fixinfo, 0, sizeof(struct fb_fix_screeninfo));
|
|
|
|
#ifdef CONFIG_FB_MODULEINFO
|
|
|
|
strlcpy(fixinfo->id, (FAR const char *)vinfo.moduleinfo,
|
|
|
|
sizeof(fixinfo->id));
|
|
|
|
#endif
|
|
|
|
fixinfo->smem_start = (unsigned long)pinfo.fbmem;
|
|
|
|
fixinfo->smem_len = pinfo.fblen;
|
|
|
|
fixinfo->type = FB_ISYUVPLANAR(vinfo.fmt) ?
|
|
|
|
FB_TYPE_INTERLEAVED_PLANES :
|
|
|
|
FB_TYPE_PACKED_PIXELS;
|
|
|
|
fixinfo->visual = FB_ISMONO(vinfo.fmt) ?
|
|
|
|
FB_VISUAL_MONO10 : FB_VISUAL_TRUECOLOR;
|
|
|
|
fixinfo->line_length = pinfo.stride;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
default:
|
2023-02-10 11:39:23 +01:00
|
|
|
if (fb->vtable->ioctl != NULL)
|
|
|
|
{
|
|
|
|
ret = fb->vtable->ioctl(fb->vtable, cmd, arg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gerr("ERROR: Unsupported IOCTL command: %d\n", cmd);
|
|
|
|
ret = -ENOTTY;
|
|
|
|
}
|
2017-09-12 00:26:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-05-05 02:04:47 +02:00
|
|
|
#ifdef CONFIG_BUILD_KERNEL
|
|
|
|
static int fb_munmap(FAR struct task_group_s *group,
|
|
|
|
FAR struct mm_map_entry_s *entry,
|
|
|
|
FAR void *start, size_t length)
|
|
|
|
{
|
|
|
|
if (group && entry)
|
|
|
|
{
|
|
|
|
ginfo("%p, len=%zu\n", entry->vaddr, entry->length);
|
|
|
|
vm_unmap_region(entry->vaddr, entry->length);
|
|
|
|
mm_map_remove(get_current_mm(), entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-02 14:02:51 +01:00
|
|
|
static int fb_mmap(FAR struct file *filep, FAR struct mm_map_entry_s *map)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_priv_s *priv;
|
2023-03-30 09:07:42 +02:00
|
|
|
struct fb_panelinfo_s panelinfo;
|
|
|
|
int ret;
|
2023-01-02 14:02:51 +01:00
|
|
|
|
|
|
|
/* Get the framebuffer instance */
|
|
|
|
|
|
|
|
inode = filep->f_inode;
|
2023-08-29 06:16:49 +02:00
|
|
|
fb = inode->i_private;
|
2023-07-19 15:11:07 +02:00
|
|
|
priv = filep->f_priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(fb->vtable != NULL && priv != NULL);
|
2023-01-02 14:02:51 +01:00
|
|
|
|
2023-03-30 09:07:42 +02:00
|
|
|
/* Get panel info */
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
ret = fb_get_panelinfo(fb, &panelinfo, priv->overlay);
|
2023-03-30 09:07:42 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-01-02 14:02:51 +01:00
|
|
|
/* Return the address corresponding to the start of frame buffer. */
|
|
|
|
|
2023-03-30 09:07:42 +02:00
|
|
|
if (map->offset >= 0 && map->offset < panelinfo.fblen &&
|
|
|
|
map->length && map->offset + map->length <= panelinfo.fblen)
|
2023-01-02 14:02:51 +01:00
|
|
|
{
|
video/fb: kernel build framebuffer support
This supports running fb demo app in kernel build with new
config `rv-virt/kfb64`. The demo shows colored rectangles
in graphic window with the following console logs:
```
nsh> cat /proc/version
NuttX version 12.4.0 1ea10ddacc-dirty May 3 2024 07:03:59 rv-virt/kfb64
nsh> fb
VideoInfo:
fmt: 13
xres: 640
yres: 480
nplanes: 1
PlaneInfo (plane 0):
fbmem: 0x80218010
fblen: 1228800
stride: 2560
display: 0
bpp: 32
Mapped FB: 0xc2000010
0: ( 0, 0) (640,480)
1: ( 58, 43) (524,394)
2: (116, 86) (408,308)
3: (174,129) (292,222)
4: (232,172) (176,136)
5: (290,215) ( 60, 50)
Test finished
```
Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-05-03 01:11:55 +02:00
|
|
|
#ifdef CONFIG_BUILD_KERNEL
|
|
|
|
map->vaddr = vm_map_region((uintptr_t)panelinfo.fbmem + map->offset,
|
|
|
|
panelinfo.fblen);
|
2024-05-05 02:04:47 +02:00
|
|
|
map->length = panelinfo.fblen;
|
|
|
|
map->munmap = fb_munmap;
|
|
|
|
mm_map_add(get_current_mm(), map);
|
video/fb: kernel build framebuffer support
This supports running fb demo app in kernel build with new
config `rv-virt/kfb64`. The demo shows colored rectangles
in graphic window with the following console logs:
```
nsh> cat /proc/version
NuttX version 12.4.0 1ea10ddacc-dirty May 3 2024 07:03:59 rv-virt/kfb64
nsh> fb
VideoInfo:
fmt: 13
xres: 640
yres: 480
nplanes: 1
PlaneInfo (plane 0):
fbmem: 0x80218010
fblen: 1228800
stride: 2560
display: 0
bpp: 32
Mapped FB: 0xc2000010
0: ( 0, 0) (640,480)
1: ( 58, 43) (524,394)
2: (116, 86) (408,308)
3: (174,129) (292,222)
4: (232,172) (176,136)
5: (290,215) ( 60, 50)
Test finished
```
Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-05-03 01:11:55 +02:00
|
|
|
#else
|
2023-03-30 09:07:42 +02:00
|
|
|
map->vaddr = (FAR char *)panelinfo.fbmem + map->offset;
|
video/fb: kernel build framebuffer support
This supports running fb demo app in kernel build with new
config `rv-virt/kfb64`. The demo shows colored rectangles
in graphic window with the following console logs:
```
nsh> cat /proc/version
NuttX version 12.4.0 1ea10ddacc-dirty May 3 2024 07:03:59 rv-virt/kfb64
nsh> fb
VideoInfo:
fmt: 13
xres: 640
yres: 480
nplanes: 1
PlaneInfo (plane 0):
fbmem: 0x80218010
fblen: 1228800
stride: 2560
display: 0
bpp: 32
Mapped FB: 0xc2000010
0: ( 0, 0) (640,480)
1: ( 58, 43) (524,394)
2: (116, 86) (408,308)
3: (174,129) (292,222)
4: (232,172) (176,136)
5: (290,215) ( 60, 50)
Test finished
```
Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-05-03 01:11:55 +02:00
|
|
|
#endif
|
2023-03-30 09:07:42 +02:00
|
|
|
return OK;
|
2023-01-02 14:02:51 +01:00
|
|
|
}
|
|
|
|
|
2023-03-30 09:07:42 +02:00
|
|
|
return -EINVAL;
|
2023-01-02 14:02:51 +01:00
|
|
|
}
|
|
|
|
|
2022-11-29 15:00:43 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_poll
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Wait for framebuffer to be writable.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int fb_poll(FAR struct file *filep, struct pollfd *fds, bool setup)
|
|
|
|
{
|
|
|
|
FAR struct inode *inode;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_priv_s *priv;
|
|
|
|
FAR struct circbuf_s *panbuf;
|
2023-09-11 04:40:20 +02:00
|
|
|
FAR struct pollfd **pollfds = NULL;
|
2023-07-19 15:11:07 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
int ret = OK;
|
2023-09-11 04:40:20 +02:00
|
|
|
int i;
|
2022-11-29 15:00:43 +01:00
|
|
|
|
|
|
|
/* Get the framebuffer instance */
|
|
|
|
|
|
|
|
inode = filep->f_inode;
|
2023-08-29 06:16:49 +02:00
|
|
|
fb = inode->i_private;
|
2023-07-19 15:11:07 +02:00
|
|
|
priv = filep->f_priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(fb->vtable != NULL && priv != NULL);
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
2022-11-29 15:00:43 +01:00
|
|
|
|
|
|
|
if (setup)
|
|
|
|
{
|
2023-09-11 04:40:20 +02:00
|
|
|
for (i = 0; i < CONFIG_VIDEO_FB_NPOLLWAITERS; ++i)
|
|
|
|
{
|
|
|
|
if (!priv->fds[i])
|
|
|
|
{
|
|
|
|
pollfds = &priv->fds[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
if (pollfds == NULL)
|
2022-11-29 15:00:43 +01:00
|
|
|
{
|
2023-07-19 15:11:07 +02:00
|
|
|
ret = -EBUSY;
|
|
|
|
goto errout;
|
2022-11-29 15:00:43 +01:00
|
|
|
}
|
2023-02-24 10:21:25 +01:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
*pollfds = fds;
|
|
|
|
fds->priv = pollfds;
|
|
|
|
|
|
|
|
panbuf = fb_get_panbuf(fb, priv->overlay);
|
|
|
|
if (!circbuf_is_full(panbuf))
|
2023-02-24 10:21:25 +01:00
|
|
|
{
|
2023-11-19 12:19:53 +01:00
|
|
|
poll_notify(&fds, 1, POLLOUT);
|
2023-02-24 10:21:25 +01:00
|
|
|
}
|
2022-11-29 15:00:43 +01:00
|
|
|
}
|
2023-07-19 15:11:07 +02:00
|
|
|
else if (fds->priv != NULL)
|
2022-11-29 15:00:43 +01:00
|
|
|
{
|
2023-07-19 15:11:07 +02:00
|
|
|
/* This is a request to tear down the poll. */
|
|
|
|
|
|
|
|
FAR struct pollfd **slot = (FAR struct pollfd **)fds->priv;
|
|
|
|
*slot = NULL;
|
2022-11-29 15:00:43 +01:00
|
|
|
fds->priv = NULL;
|
|
|
|
}
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
errout:
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return ret;
|
2022-11-29 15:00:43 +01:00
|
|
|
}
|
|
|
|
|
2023-03-30 09:07:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_get_panelinfo
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int fb_get_panelinfo(FAR struct fb_chardev_s *fb,
|
2023-07-19 15:11:07 +02:00
|
|
|
FAR struct fb_panelinfo_s *panelinfo,
|
|
|
|
int overlay)
|
2023-03-30 09:07:42 +02:00
|
|
|
{
|
|
|
|
struct fb_planeinfo_s pinfo;
|
2023-07-19 15:11:07 +02:00
|
|
|
struct fb_videoinfo_s vinfo;
|
2023-03-30 09:07:42 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
#ifdef CONFIG_FB_OVERLAY
|
2023-07-19 15:11:07 +02:00
|
|
|
if (overlay != FB_NO_OVERLAY)
|
2023-03-30 09:07:42 +02:00
|
|
|
{
|
|
|
|
struct fb_overlayinfo_s oinfo;
|
|
|
|
DEBUGASSERT(fb->vtable->getoverlayinfo != NULL);
|
|
|
|
memset(&oinfo, 0, sizeof(oinfo));
|
2023-07-19 15:11:07 +02:00
|
|
|
ret = fb->vtable->getoverlayinfo(fb->vtable, overlay, &oinfo);
|
2023-03-30 09:07:42 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
gerr("ERROR: getoverlayinfo() failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
panelinfo->fbmem = oinfo.fbmem;
|
|
|
|
panelinfo->fblen = oinfo.fblen;
|
|
|
|
panelinfo->fbcount = oinfo.yres_virtual == 0 ?
|
|
|
|
1 : (oinfo.yres_virtual / oinfo.yres);
|
|
|
|
panelinfo->bpp = oinfo.bpp;
|
2023-03-30 09:07:42 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-07-21 10:33:48 +02:00
|
|
|
ret = fb_get_planeinfo(fb, &pinfo, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
ret = fb->vtable->getvideoinfo(fb->vtable, &vinfo);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
gerr("ERROR: getvideoinfo() failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
panelinfo->fbmem = pinfo.fbmem;
|
|
|
|
panelinfo->fblen = pinfo.fblen;
|
|
|
|
panelinfo->fbcount = pinfo.yres_virtual == 0 ?
|
|
|
|
1 : (pinfo.yres_virtual / vinfo.yres);
|
|
|
|
panelinfo->bpp = pinfo.bpp;
|
2023-07-21 10:33:48 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_get_planeinfo
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int fb_get_planeinfo(FAR struct fb_chardev_s *fb,
|
|
|
|
FAR struct fb_planeinfo_s *pinfo,
|
|
|
|
uint8_t display)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2023-03-30 09:07:42 +02:00
|
|
|
DEBUGASSERT(fb->vtable != NULL);
|
|
|
|
DEBUGASSERT(fb->vtable->getplaneinfo != NULL);
|
|
|
|
|
2023-07-21 10:33:48 +02:00
|
|
|
memset(pinfo, 0, sizeof(struct fb_planeinfo_s));
|
|
|
|
pinfo->display = display;
|
|
|
|
|
|
|
|
ret = fb->vtable->getplaneinfo(fb->vtable, fb->plane, pinfo);
|
2023-03-30 09:07:42 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
gerr("ERROR: getplaneinfo() failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2023-03-27 08:09:59 +02:00
|
|
|
/****************************************************************************
|
2023-12-08 08:18:25 +01:00
|
|
|
* Name: fb_do_pollnotify
|
2023-03-27 08:09:59 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2023-12-08 08:18:25 +01:00
|
|
|
static void fb_do_pollnotify(wdparm_t arg)
|
2023-03-27 08:09:59 +02:00
|
|
|
{
|
2023-12-08 08:18:25 +01:00
|
|
|
FAR struct fb_paninfo_s *paninfo = (FAR struct fb_paninfo_s *)arg;
|
2023-09-11 04:40:20 +02:00
|
|
|
FAR struct fb_priv_s * priv;
|
|
|
|
irqstate_t flags;
|
2023-12-08 08:18:25 +01:00
|
|
|
int overlay;
|
|
|
|
|
|
|
|
overlay = paninfo - paninfo->dev->paninfo - 1;
|
2023-09-11 04:40:20 +02:00
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
for (priv = paninfo->dev->head; priv; priv = priv->flink)
|
|
|
|
{
|
|
|
|
if (priv->overlay != overlay)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify framebuffer is writable. */
|
|
|
|
|
2023-12-08 08:18:25 +01:00
|
|
|
poll_notify(priv->fds, CONFIG_VIDEO_FB_NPOLLWAITERS, POLLOUT);
|
2023-09-11 04:40:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_FB_SYNC
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_sem_wait
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int fb_sem_wait(FAR struct fb_chardev_s *fb,
|
|
|
|
FAR struct fb_priv_s *priv,
|
|
|
|
int overlay)
|
|
|
|
{
|
|
|
|
struct fb_panelinfo_s panelinfo;
|
|
|
|
irqstate_t flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = fb_get_panelinfo(fb, &panelinfo, overlay);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
if (fb_paninfo_count(fb->vtable, overlay) == panelinfo.fbcount)
|
|
|
|
{
|
|
|
|
ret = nxsem_wait(&priv->wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_sem_post
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void fb_sem_post(FAR struct fb_chardev_s *fb, int overlay)
|
|
|
|
{
|
|
|
|
FAR struct fb_priv_s * priv;
|
2023-07-19 15:11:07 +02:00
|
|
|
irqstate_t flags;
|
2023-03-27 08:09:59 +02:00
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
DEBUGASSERT(fb != NULL);
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
flags = enter_critical_section();
|
2023-03-27 08:09:59 +02:00
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
for (priv = fb->head; priv; priv = priv->flink)
|
|
|
|
{
|
|
|
|
if (priv->overlay != overlay)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; ; )
|
|
|
|
{
|
|
|
|
int semcount = 0;
|
|
|
|
|
|
|
|
sem_getvalue(&priv->wait, &semcount);
|
|
|
|
if (semcount >= 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wakeup all waiters. */
|
2023-03-27 08:09:59 +02:00
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
nxsem_post(&priv->wait);
|
|
|
|
}
|
|
|
|
}
|
2023-03-27 08:09:59 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
2023-09-11 04:40:20 +02:00
|
|
|
#endif
|
2023-03-30 09:07:42 +02:00
|
|
|
|
2022-11-29 15:00:43 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_pollnotify
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Notify the waiting thread that the framebuffer can be written.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* vtable - Pointer to framebuffer's virtual table.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
static void fb_pollnotify(FAR struct fb_chardev_s *fb, int overlay)
|
2022-11-29 15:00:43 +01:00
|
|
|
{
|
2023-07-19 15:11:07 +02:00
|
|
|
int id = overlay + 1;
|
2022-11-29 15:00:43 +01:00
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
DEBUGASSERT(fb != NULL);
|
2023-04-26 07:22:49 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
DEBUGASSERT(id >= 0 && id < fb->paninfo_count);
|
|
|
|
|
2023-03-27 08:09:59 +02:00
|
|
|
if (fb->vsyncoffset > 0)
|
|
|
|
{
|
2023-09-28 10:31:55 +02:00
|
|
|
wd_start(&fb->paninfo[id].wdog, fb->vsyncoffset, fb_do_pollnotify,
|
2023-07-19 15:11:07 +02:00
|
|
|
(wdparm_t)(&fb->paninfo[id]));
|
2023-03-27 08:09:59 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-19 15:11:07 +02:00
|
|
|
fb_do_pollnotify((wdparm_t)(&fb->paninfo[id]));
|
2023-03-27 08:09:59 +02:00
|
|
|
}
|
2022-11-29 15:00:43 +01:00
|
|
|
}
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-11-21 08:26:49 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_notify_vsync
|
|
|
|
* Description:
|
|
|
|
* notify that the vsync comes.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* vtable - Pointer to framebuffer's virtual table.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-12-08 08:18:25 +01:00
|
|
|
void fb_notify_vsync(FAR struct fb_vtable_s *vtable)
|
2023-11-21 08:26:49 +01:00
|
|
|
{
|
|
|
|
FAR struct fb_chardev_s *fb;
|
2023-12-08 08:18:25 +01:00
|
|
|
FAR struct fb_priv_s * priv;
|
|
|
|
irqstate_t flags;
|
2023-11-21 08:26:49 +01:00
|
|
|
|
|
|
|
fb = vtable->priv;
|
|
|
|
if (fb != NULL)
|
|
|
|
{
|
2023-12-08 08:18:25 +01:00
|
|
|
flags = enter_critical_section();
|
|
|
|
for (priv = fb->head; priv; priv = priv->flink)
|
|
|
|
{
|
|
|
|
/* Notify that the vsync comes. */
|
|
|
|
|
|
|
|
poll_notify(priv->fds, CONFIG_VIDEO_FB_NPOLLWAITERS, POLLPRI);
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
2023-11-21 08:26:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_peek_paninfo
|
|
|
|
* Description:
|
|
|
|
* Peek a frame from pan info queue of the specified overlay.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* vtable - Pointer to framebuffer's virtual table.
|
|
|
|
* info - Pointer to pan info.
|
|
|
|
* overlay - Overlay index.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success; a negated errno value is returned on any
|
|
|
|
* failure.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int fb_peek_paninfo(FAR struct fb_vtable_s *vtable,
|
|
|
|
FAR union fb_paninfo_u *info,
|
|
|
|
int overlay)
|
|
|
|
{
|
|
|
|
FAR struct circbuf_s *panbuf;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
|
|
|
irqstate_t flags;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
/* Prevent calling before getting the vtable. */
|
|
|
|
|
|
|
|
fb = vtable->priv;
|
|
|
|
if (fb == NULL)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
panbuf = fb_get_panbuf(fb, overlay);
|
|
|
|
if (panbuf == NULL)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
/* Attempt to peek a frame from the vsync queue. */
|
|
|
|
|
|
|
|
ret = circbuf_peek(panbuf, info, sizeof(union fb_paninfo_u));
|
|
|
|
DEBUGASSERT(ret <= 0 || ret == sizeof(union fb_paninfo_u));
|
|
|
|
|
|
|
|
/* Re-enable interrupts */
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return ret <= 0 ? -ENOSPC : OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_remove_paninfo
|
|
|
|
* Description:
|
|
|
|
* Remove a frame from pan info queue of the specified overlay.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* vtable - Pointer to framebuffer's virtual table.
|
|
|
|
* overlay - Overlay index.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success; a negated errno value is returned on any
|
|
|
|
* failure.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int fb_remove_paninfo(FAR struct fb_vtable_s *vtable, int overlay)
|
|
|
|
{
|
|
|
|
FAR struct circbuf_s *panbuf;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
|
|
|
irqstate_t flags;
|
|
|
|
ssize_t ret;
|
2023-09-11 04:40:20 +02:00
|
|
|
bool full;
|
2023-07-19 15:11:07 +02:00
|
|
|
|
|
|
|
fb = vtable->priv;
|
|
|
|
if (fb == NULL)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
panbuf = fb_get_panbuf(fb, overlay);
|
|
|
|
if (panbuf == NULL)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
full = (circbuf_space(panbuf) == 0);
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
/* Attempt to take a frame from the pan info. */
|
|
|
|
|
|
|
|
ret = circbuf_skip(panbuf, sizeof(union fb_paninfo_u));
|
|
|
|
DEBUGASSERT(ret <= 0 || ret == sizeof(union fb_paninfo_u));
|
|
|
|
|
|
|
|
/* Re-enable interrupts */
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
|
|
|
|
if (ret == sizeof(union fb_paninfo_u))
|
|
|
|
{
|
2023-09-11 04:40:20 +02:00
|
|
|
fb_pollnotify(fb, overlay);
|
|
|
|
if (full)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_FB_SYNC
|
|
|
|
fb_sem_post(fb, overlay);
|
|
|
|
#endif
|
|
|
|
}
|
2023-07-19 15:11:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret <= 0 ? -ENOSPC : OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: fb_paninfo_count
|
|
|
|
* Description:
|
|
|
|
* Get pan info count of specified overlay pan info queue.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* vtable - Pointer to framebuffer's virtual table.
|
|
|
|
* overlay - Overlay index.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* a non-negative value is returned on success; a negated errno value is
|
|
|
|
* returned on any failure.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int fb_paninfo_count(FAR struct fb_vtable_s *vtable, int overlay)
|
|
|
|
{
|
|
|
|
FAR struct circbuf_s *panbuf;
|
|
|
|
FAR struct fb_chardev_s *fb;
|
|
|
|
irqstate_t flags;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
/* Prevent calling before getting the vtable. */
|
|
|
|
|
|
|
|
fb = vtable->priv;
|
|
|
|
if (fb == NULL)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
panbuf = fb_get_panbuf(fb, overlay);
|
|
|
|
if (panbuf == NULL)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
ret = circbuf_used(panbuf) / sizeof(union fb_paninfo_u);
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
/****************************************************************************
|
2023-10-08 19:14:32 +02:00
|
|
|
* Name: fb_register_device
|
2017-09-12 00:26:18 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-09-12 17:48:47 +02:00
|
|
|
* Register the framebuffer character device at /dev/fbN where N is the
|
|
|
|
* display number if the devices supports only a single plane. If the
|
2017-09-18 17:03:26 +02:00
|
|
|
* hardware supports multiple color planes, then the device will be
|
2017-11-29 14:05:20 +01:00
|
|
|
* registered at /dev/fbN.M where N is the again display number but M
|
2017-09-18 17:03:26 +02:00
|
|
|
* is the display plane.
|
2017-09-12 17:48:47 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* display - The display number for the case of boards supporting multiple
|
2017-09-18 17:03:26 +02:00
|
|
|
* displays or for hardware that supports multiple
|
2017-09-12 17:48:47 +02:00
|
|
|
* layers (each layer is consider a display). Typically zero.
|
|
|
|
* plane - Identifies the color plane on hardware that supports separate
|
|
|
|
* framebuffer "planes" for each color component.
|
2023-10-08 19:14:32 +02:00
|
|
|
* vtable - Pointer to framebuffer's virtual table.
|
2017-09-12 00:26:18 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned success; a negated errno value is returned on any
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-10-08 19:14:32 +02:00
|
|
|
int fb_register_device(int display, int plane,
|
|
|
|
FAR struct fb_vtable_s *vtable)
|
2017-09-12 00:26:18 +02:00
|
|
|
{
|
|
|
|
FAR struct fb_chardev_s *fb;
|
2023-03-30 09:07:42 +02:00
|
|
|
struct fb_panelinfo_s panelinfo;
|
2017-09-12 17:48:47 +02:00
|
|
|
struct fb_videoinfo_s vinfo;
|
2017-09-12 00:26:18 +02:00
|
|
|
char devname[16];
|
2017-09-12 17:48:47 +02:00
|
|
|
int nplanes;
|
2017-09-12 00:26:18 +02:00
|
|
|
int ret;
|
2023-07-19 15:11:07 +02:00
|
|
|
size_t i;
|
2017-09-12 00:26:18 +02:00
|
|
|
|
|
|
|
/* Allocate a framebuffer state instance */
|
|
|
|
|
2023-08-28 09:39:47 +02:00
|
|
|
fb = kmm_zalloc(sizeof(struct fb_chardev_s));
|
2017-09-12 00:26:18 +02:00
|
|
|
if (fb == NULL)
|
|
|
|
{
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGASSERT((unsigned)plane <= UINT8_MAX);
|
2023-10-08 19:14:32 +02:00
|
|
|
DEBUGASSERT(vtable != NULL);
|
2017-09-12 00:26:18 +02:00
|
|
|
fb->plane = plane;
|
2023-10-08 19:14:32 +02:00
|
|
|
fb->vtable = vtable;
|
2017-09-12 00:26:18 +02:00
|
|
|
|
|
|
|
/* Initialize the frame buffer instance. */
|
|
|
|
|
2023-10-08 19:14:32 +02:00
|
|
|
DEBUGASSERT(vtable->getvideoinfo != NULL);
|
|
|
|
ret = vtable->getvideoinfo(vtable, &vinfo);
|
2017-09-12 17:48:47 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
gerr("ERROR: getvideoinfo() failed: %d\n", ret);
|
|
|
|
goto errout_with_fb;
|
|
|
|
}
|
|
|
|
|
|
|
|
nplanes = vinfo.nplanes;
|
|
|
|
DEBUGASSERT(vinfo.nplanes > 0 && (unsigned)plane < vinfo.nplanes);
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
#ifdef CONFIG_FB_OVERLAY
|
|
|
|
fb->paninfo_count = vinfo.noverlays;
|
|
|
|
#endif
|
2023-07-13 06:23:54 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
/* Add the primary framebuffer */
|
2023-07-13 06:23:54 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
fb->paninfo_count += 1;
|
|
|
|
fb->paninfo = kmm_zalloc(sizeof(struct fb_paninfo_s) * fb->paninfo_count);
|
2023-07-13 06:23:54 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
if (fb->paninfo == NULL)
|
2023-07-13 06:23:54 +02:00
|
|
|
{
|
2023-07-19 15:11:07 +02:00
|
|
|
gerr("ERROR: alloc panbuf failed\n");
|
|
|
|
goto errout_with_fb;
|
2023-07-13 06:23:54 +02:00
|
|
|
}
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
for (i = 0; i < fb->paninfo_count; i++)
|
2017-09-12 00:26:18 +02:00
|
|
|
{
|
2023-07-19 15:11:07 +02:00
|
|
|
ret = fb_get_panelinfo(fb, &panelinfo, i - 1);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_paninfo;
|
|
|
|
}
|
2017-09-12 00:26:18 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
ret = circbuf_init(&(fb->paninfo[i].buf), NULL, panelinfo.fbcount
|
|
|
|
* sizeof(union fb_paninfo_u));
|
2017-09-16 20:49:16 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
DEBUGASSERT(ret == 0);
|
2017-09-16 20:49:16 +02:00
|
|
|
|
2023-09-11 04:40:20 +02:00
|
|
|
fb->paninfo[i].dev = fb;
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
/* Clear the framebuffer memory */
|
2018-05-18 00:11:09 +02:00
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
memset(panelinfo.fbmem, 0, panelinfo.fblen);
|
2018-05-18 00:11:09 +02:00
|
|
|
}
|
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
/* Register the framebuffer device */
|
|
|
|
|
2017-09-12 17:48:47 +02:00
|
|
|
if (nplanes < 2)
|
|
|
|
{
|
2024-08-24 18:54:12 +02:00
|
|
|
snprintf(devname, sizeof(devname), "/dev/fb%d", display);
|
2017-09-12 17:48:47 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-24 18:54:12 +02:00
|
|
|
snprintf(devname, sizeof(devname), "/dev/fb%d.%d", display, plane);
|
2017-09-12 17:48:47 +02:00
|
|
|
}
|
|
|
|
|
2023-10-08 19:14:32 +02:00
|
|
|
ret = register_driver(devname, &g_fb_fops, 0666, fb);
|
2023-09-11 04:40:20 +02:00
|
|
|
|
2017-09-12 00:26:18 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
gerr("ERROR: register_driver() failed: %d\n", ret);
|
2023-09-11 04:40:20 +02:00
|
|
|
goto errout_with_paninfo;
|
2017-09-12 00:26:18 +02:00
|
|
|
}
|
|
|
|
|
2023-10-08 19:14:32 +02:00
|
|
|
vtable->priv = fb;
|
2017-09-12 00:26:18 +02:00
|
|
|
return OK;
|
|
|
|
|
2023-07-19 15:11:07 +02:00
|
|
|
errout_with_paninfo:
|
|
|
|
while (i-- > 0)
|
|
|
|
{
|
|
|
|
circbuf_uninit(&(fb->paninfo[i].buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
kmm_free(fb->paninfo);
|
|
|
|
errout_with_fb:
|
2017-09-12 00:26:18 +02:00
|
|
|
kmm_free(fb);
|
|
|
|
return ret;
|
|
|
|
}
|