drivers/video/fb: add poll support

Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
FASTSHIFT 2022-11-29 22:00:43 +08:00 committed by Xiang Xiao
parent b1b2a7cc0b
commit 0ae242aa8d
2 changed files with 88 additions and 1 deletions

View File

@ -33,6 +33,7 @@
#include <assert.h>
#include <debug.h>
#include <errno.h>
#include <poll.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
@ -53,6 +54,7 @@ struct fb_chardev_s
{
FAR struct fb_vtable_s *vtable; /* Framebuffer interface */
FAR void *fbmem; /* Start of frame buffer memory */
FAR struct pollfd *fds; /* Polling structure of waiting thread */
size_t fblen; /* Size of the framebuffer */
uint8_t plane; /* Video plan number */
uint8_t bpp; /* Bits per pixel */
@ -68,6 +70,8 @@ static ssize_t fb_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
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);
static int fb_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup);
/****************************************************************************
* Private Data
@ -81,7 +85,7 @@ static const struct file_operations fb_fops =
fb_write, /* write */
fb_seek, /* seek */
fb_ioctl, /* ioctl */
NULL /* poll */
fb_poll /* poll */
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
, NULL /* unlink */
#endif
@ -544,6 +548,70 @@ static int fb_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
return ret;
}
/****************************************************************************
* 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;
/* Get the framebuffer instance */
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
inode = filep->f_inode;
fb = (FAR struct fb_chardev_s *)inode->i_private;
if (setup)
{
if (fb->fds == NULL)
{
fb->fds = fds;
fds->priv = &fb->fds;
}
else
{
return -EBUSY;
}
}
else if (fds->priv)
{
fb->fds = NULL;
fds->priv = NULL;
}
return OK;
}
/****************************************************************************
* Name: fb_pollnotify
*
* Description:
* Notify the waiting thread that the framebuffer can be written.
*
* Input Parameters:
* vtable - Pointer to framebuffer's virtual table.
*
****************************************************************************/
void fb_pollnotify(FAR struct fb_vtable_s *vtable)
{
FAR struct fb_chardev_s *fb;
DEBUGASSERT(vtable != NULL);
fb = vtable->priv;
/* Notify framebuffer is writable. */
poll_notify(&fb->fds, 1, POLLOUT);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -611,6 +679,8 @@ int fb_register(int display, int plane)
goto errout_with_fb;
}
fb->vtable->priv = fb;
/* Initialize the frame buffer instance. */
DEBUGASSERT(fb->vtable->getvideoinfo != NULL);

View File

@ -613,6 +613,10 @@ struct fb_vtable_s
/* Enable/disable panel power (0: full off). */
int (*setpower)(FAR struct fb_vtable_s *vtable, int power);
/* Pointer to framebuffer device private data. */
FAR void *priv;
};
/****************************************************************************
@ -696,6 +700,19 @@ FAR struct fb_vtable_s *up_fbgetvplane(int display, int vplane);
void up_fbuninitialize(int display);
/****************************************************************************
* Name: fb_pollnotify
*
* Description:
* Notify the waiting thread that the framebuffer can be written.
*
* Input Parameters:
* vtable - Pointer to framebuffer's virtual table.
*
****************************************************************************/
void fb_pollnotify(FAR struct fb_vtable_s *vtable);
/****************************************************************************
* Name: fb_register
*