graphics/nxterm and configs/boardctl.c: Replace specific interfaces between boardctl and nxterm with a generalized IOCTL interface.

This commit is contained in:
Gregory Nutt 2019-05-16 11:54:38 -06:00
parent a40ef12895
commit 7a653cba7e
6 changed files with 188 additions and 127 deletions

View File

@ -512,47 +512,25 @@ int boardctl(unsigned int cmd, uintptr_t arg)
}
break;
/* CMD: BOARDIOC_NXTERM_REDRAW
* DESCRIPTION: Re-draw a portion of the NX console. This function
* should be called from the appropriate window callback
* logic.
* ARG: A reference readable instance of struct
* boardioc_nxterm_redraw_s
/* CMD: BOARDIOC_NXTERM_IOCTL
* DESCRIPTION: Create an NX terminal IOCTL command. Normal IOCTLs
* cannot be be performed in most graphics contexts since
* the depend on the task holding an open file descriptor
* ARG: A reference readable/writable instance of struct
* boardioc_nxterm_ioctl_s
* CONFIGURATION: CONFIG_NXTERM
* DEPENDENCIES: Base NX terminal logic provides nxterm_redraw()
* DEPENDENCIES: Base NX terminal logic provides nxterm_ioctl_tap()
*/
case BOARDIOC_NXTERM_REDRAW:
{
FAR struct boardioc_nxterm_redraw_s *redraw =
(FAR struct boardioc_nxterm_redraw_s *)((uintptr_t)arg);
case BOARDIOC_NXTERM_IOCTL:
{
FAR struct boardioc_nxterm_ioctl_s *nxterm =
(FAR struct boardioc_nxterm_ioctl_s *)arg;
nxterm_redraw(redraw->handle, &redraw->rect, redraw->more);
ret = OK;
}
break;
ret = nxterm_ioctl_tap(nxterm->cmd, nxterm->arg);
}
break;
/* CMD: BOARDIOC_NXTERM_KBDIN
* DESCRIPTION: Provide NxTerm keyboard input to NX.
* ARG: A reference readable instance of struct
* boardioc_nxterm_kbdin_s
* CONFIGURATION: CONFIG_NXTERM_NXKBDIN
* DEPENDENCIES: Base NX terminal logic provides nxterm_kbdin()
*/
case BOARDIOC_NXTERM_KBDIN:
{
#ifdef CONFIG_NXTERM_NXKBDIN
FAR struct boardioc_nxterm_kbdin_s *kbdin =
(FAR struct boardioc_nxterm_kbdin_s *)((uintptr_t)arg);
nxterm_kbdin(kbdin->handle, kbdin->buffer, kbdin->buflen);
ret = OK;
#else
ret = -ENOSYS;
#endif
}
break;
#endif /* CONFIG_NXTERM */
#ifdef CONFIG_BOARDCTL_TESTSET

View File

@ -210,6 +210,8 @@ FAR struct nxterm_state_s *nxterm_register(NXTERM handle,
void nxterm_unregister(FAR struct nxterm_state_s *priv);
#endif
/* Driver methods */
#ifdef CONFIG_NXTERM_NXKBDIN
ssize_t nxterm_read(FAR struct file *filep, FAR char *buffer, size_t len);
#ifndef CONFIG_DISABLE_POLL
@ -217,6 +219,14 @@ int nxterm_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup);
#endif
#endif
/* IOCTL handlers */
void nxterm_redraw(NXTERM handle, FAR const struct nxgl_rect_s *rect,
bool more);
#ifdef CONFIG_NXTERM_NXKBDIN
void nxterm_kbdin(NXTERM handle, FAR const uint8_t *buffer, uint8_t buflen);
#endif
/* VT100 Terminal emulation */
enum nxterm_vt100state_e nxterm_vt100(FAR struct nxterm_state_s *priv, char ch);

View File

@ -59,6 +59,8 @@ static int nxterm_open(FAR struct file *filep);
static int nxterm_close(FAR struct file *filep);
static ssize_t nxterm_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static int nxterm_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
static int nxterm_unlink(FAR struct inode *inode);
#endif
@ -78,7 +80,7 @@ const struct file_operations g_nxterm_drvrops =
nxterm_read, /* read */
nxterm_write, /* write */
0, /* seek */
0 /* ioctl */
nxterm_ioctl /* ioctl */
#ifndef CONFIG_DISABLE_POLL
,
nxterm_poll /* poll */
@ -98,7 +100,7 @@ const struct file_operations g_nxterm_drvrops =
0, /* read */
nxterm_write, /* write */
0, /* seek */
0 /* ioctl */
nxterm_ioctl /* ioctl */
#ifndef CONFIG_DISABLE_POLL
,
0 /* poll */
@ -315,6 +317,23 @@ static ssize_t nxterm_write(FAR struct file *filep, FAR const char *buffer,
return (ssize_t)buflen;
}
/****************************************************************************
* Name: nxterm_ioctl
****************************************************************************/
static int nxterm_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
/* NOTE: We don't need driver context here because the NXTERM handle
* provided within each of the NXTERM IOCTL command data. Mutual
* exclusion is similar managed by the IOCTL cmmand hendler.
*
* This permits the IOCTL to be called in abnormal context (such as
* from boardctl())
*/
return nxterm_ioctl_tap(cmd, arg);
}
/****************************************************************************
* Name: nxterm_unlink
****************************************************************************/
@ -362,3 +381,73 @@ static int nxterm_unlink(FAR struct inode *inode)
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxterm_ioctl_tap
*
* Description:
* Execute an NXTERM IOCTL command from an external caller.
*
* NOTE: We don't need driver context here because the NXTERM handle
* provided within each of the NXTERM IOCTL command data. Mutual
* exclusion is similar managed by the IOCTL cmmand hendler.
*
* This permits the IOCTL to be called in abnormal context (such as
* from boardctl())
*
****************************************************************************/
int nxterm_ioctl_tap(int cmd, uintptr_t arg)
{
int ret;
switch (cmd)
{
/* CMD: NXTERMIOC_NXTERM_REDRAW
* DESCRIPTION: Re-draw a portion of the NX console. This function
* should be called from the appropriate window callback
* logic.
* ARG: A reference readable instance of struct
* nxtermioc_redraw_s
* CONFIGURATION: CONFIG_NXTERM
* DEPENDENCIES: Base NX terminal logic provides nxterm_redraw()
*/
case NXTERMIOC_NXTERM_REDRAW:
{
FAR struct nxtermioc_redraw_s *redraw =
(FAR struct nxtermioc_redraw_s *)((uintptr_t)arg);
nxterm_redraw(redraw->handle, &redraw->rect, redraw->more);
ret = OK;
}
break;
/* CMD: NXTERMIOC_NXTERM_KBDIN
* DESCRIPTION: Provide NxTerm keyboard input to NX.
* ARG: A reference readable instance of struct
* nxtermioc_kbdin_s
* CONFIGURATION: CONFIG_NXTERM_NXKBDIN
* DEPENDENCIES: Base NX terminal logic provides nxterm_kbdin()
*/
case NXTERMIOC_NXTERM_KBDIN:
{
#ifdef CONFIG_NXTERM_NXKBDIN
FAR struct nxtermioc_kbdin_s *kbdin =
(FAR struct nxtermioc_kbdin_s *)((uintptr_t)arg);
nxterm_kbdin(kbdin->handle, kbdin->buffer, kbdin->buflen);
ret = OK;
#else
ret = -ENOSYS;
#endif
}
break;
default:
ret = -ENOTTY;
break;
}
return ret;
}

View File

@ -93,6 +93,7 @@
#define _MAC802154BASE (0x2600) /* 802.15.4 MAC ioctl commands */
#define _PWRBASE (0x2700) /* Power-related ioctl commands */
#define _FBIOCBASE (0x2800) /* Frame buffer character driver ioctl commands */
#define _NXTERMBASE (0x2900) /* NxTerm character driver ioctl commands */
/* boardctl() commands share the same number space */
@ -467,8 +468,13 @@
/* Frame buffer character drivers *******************************************/
#define _FBIOCVALID(c) (_IOC_TYPE(c)==_FBIOCBASE)
#define _FBIOC(nr) _IOC(_FBIOCBASE,nr)
#define _FBIOCVALID(c) (_IOC_TYPE(c)==_FBIOCBASE)
#define _FBIOC(nr) _IOC(_FBIOCBASE,nr)
/* NxTerm character drivers *************************************************/
#define _NXTERMVALID(c) (_IOC_TYPE(c)==_NXTERMBASE)
#define _NXTERMIOC(nr) _IOC(_NXTERMBASE,nr)
/* boardctl() command definitions *******************************************/

View File

@ -42,6 +42,7 @@
#include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxtk.h>
@ -192,6 +193,29 @@
# define CONFIG_NXTERM_NPOLLWAITERS 0
#endif
/* IOCTL commands ***********************************************************/
/* CMD: NXTERMIOC_NXTERM_REDRAW
* DESCRIPTION: Re-draw a portion of the NX console. This function
* should be called from the appropriate window callback
* logic.
* ARG: A reference readable instance of struct
* nxtermioc_redraw_s
* CONFIGURATION: CONFIG_NXTERM
* DEPENDENCIES: Base NX terminal logic provides nxterm_redraw()
*
* CMD: NXTERMIOC_NXTERM_KBDIN
* DESCRIPTION: Provide NxTerm keyboard input to NX.
* ARG: A reference readable instance of struct
* nxtermioc_kbdin_s
* CONFIGURATION: CONFIG_NXTERM_NXKBDIN
* DEPENDENCIES: Base NX terminal logic provides nxterm_kbdin()
*/
#define _NXTERMIOC(nr) _IOC(_NXTERMBASE,nr)
#define NXTERMIOC_NXTERM_REDRAW _NXTERMIOC(0x000c)
#define NXTERMIOC_NXTERM_KBDIN _NXTERMIOC(0x000d)
/****************************************************************************
* Public Types
****************************************************************************/
@ -213,6 +237,26 @@ struct nxterm_window_s
int fontid; /* The ID of the font to use */
};
/* Arguments passed with the NXTERMIOC_NXTERM_REDRAW command */
struct nxtermioc_redraw_s
{
NXTERM handle; /* NxTerm handle */
struct nxgl_rect_s rect; /* Rectangle to be re-drawn */
bool more; /* True: More redraw commands follow */
};
#ifdef CONFIG_NXTERM_NXKBDIN
/* Arguments passed with the NXTERMIOC_NXTERM_KBDIN command */
struct nxtermioc_kbdin_s
{
NXTERM handle; /* NxTerm handle */
FAR const uint8_t *buffer; /* Buffered keyboard data */
uint8_t buflen; /* Amount of data in buffer */
};
#endif
/****************************************************************************
* Public Data
****************************************************************************/
@ -315,64 +359,21 @@ NXTERM nxtool_register(NXTKWINDOW hfwnd, FAR struct nxterm_window_s *wndo,
int minor);
/****************************************************************************
* Name: nxterm_redraw
* Name: nxterm_ioctl_tap
*
* Description:
* Re-draw a portion of the NX console. This function should be called
* from the appropriate window callback logic.
* Execute an NXTERM IOCTL command from an external caller.
*
* This is an internal NuttX interface and should not be called directly
* from applications. Application access is supported only indirectly via
* the boardctl(BOARDIOC_REDRAW) interface.
* NOTE: We don't need driver context here because the NXTERM handle
* provided within each of the NXTERM IOCTL command data. Mutual
* exclusion is similar managed by the IOCTL cmmand hendler.
*
* Input Parameters:
* handle - A handle previously returned by nx_register, nxtk_register, or
* nxtool_register.
* rect - The rectangle that needs to be re-drawn (in window relative
* coordinates)
* more - true: More re-draw requests will follow
*
* Returned Value:
* None
* This permits the IOCTL to be called in abnormal context (such as
* from boardctl())
*
****************************************************************************/
void nxterm_redraw(NXTERM handle, FAR const struct nxgl_rect_s *rect,
bool more);
/****************************************************************************
* Name: nxterm_kbdin
*
* Description:
* This function should be driven by the window kbdin callback function
* (see nx.h). When the NxTerm is the top window and keyboard input is
* received on the top window, that window callback should be directed to
* this function. This function will buffer the keyboard data and make
* it available to the NxTerm as stdin.
*
* If CONFIG_NXTERM_NXKBDIN is not selected, then the NxTerm will
* receive its input from stdin (/dev/console). This works great but
* cannot be shared between different windows. Chaos will ensue if you
* try to support multiple NxTerm windows without CONFIG_NXTERM_NXKBDIN
*
* This is an internal NuttX interface and should not be called directly
* from applications. Application access is supported only indirectly via
* the boardctl(BOARDIOC_KBDIN) interface.
*
* Input Parameters:
* handle - A handle previously returned by nx_register, nxtk_register, or
* nxtool_register.
* buffer - The array of characters
* buflen - The number of characters that are available in buffer[]
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NXTERM_NXKBDIN
void nxterm_kbdin(NXTERM handle, FAR const uint8_t *buffer, uint8_t buflen);
#endif
int nxterm_ioctl_tap(int cmd, uintptr_t arg);
#undef EXTERN
#if defined(__cplusplus)

View File

@ -138,21 +138,14 @@
* DEPENDENCIES: Base NX terminal logic provides nx_register() and
* nxtk_register()
*
* CMD: BOARDIOC_NXTERM_REDRAW
* DESCRIPTION: Re-draw a portion of the NX console. This function
* should be called from the appropriate window callback
* logic.
* ARG: A reference readable instance of struct
* boardioc_nxterm_redraw_s
* CMD: BOARDIOC_NXTERM_IOCTL
* DESCRIPTION: Create an NX terminal IOCTL command. Normal IOCTLs
* cannot be be performed in most graphics contexts since
* the depend on the task holding an open file descriptor
* ARG: A reference readable/writable instance of struct
* boardioc_nxterm_ioctl_s
* CONFIGURATION: CONFIG_NXTERM
* DEPENDENCIES: Base NX terminal logic provides nxterm_redraw()
*
* CMD: BOARDIOC_NXTERM_KBDIN
* DESCRIPTION: Provide NxTerm keyboard input to NX.
* ARG: A reference readable instance of struct
* boardioc_nxterm_kbdin_s
* CONFIGURATION: CONFIG_NXTERM_NXKBDIN
* DEPENDENCIES: Base NX terminal logic provides nxterm_kbdin()
* DEPENDENCIES: Base NX terminal logic provides nxterm_ioctl_tap()
*
* CMD: BOARDIOC_TESTSET
* DESCRIPTION: Access architecture-specific up_testset() operation
@ -174,9 +167,8 @@
#define BOARDIOC_NX_START _BOARDIOC(0x0009)
#define BOARDIOC_VNC_START _BOARDIOC(0x000a)
#define BOARDIOC_NXTERM _BOARDIOC(0x000b)
#define BOARDIOC_NXTERM_REDRAW _BOARDIOC(0x000c)
#define BOARDIOC_NXTERM_KBDIN _BOARDIOC(0x000d)
#define BOARDIOC_TESTSET _BOARDIOC(0x000e)
#define BOARDIOC_NXTERM_IOCTL _BOARDIOC(0x000c)
#define BOARDIOC_TESTSET _BOARDIOC(0x000d)
/* If CONFIG_BOARDCTL_IOCTL=y, then board-specific commands will be support.
* In this case, all commands not recognized by boardctl() will be forwarded
@ -185,7 +177,7 @@
* User defined board commands may begin with this value:
*/
#define BOARDIOC_USER _BOARDIOC(0x000f)
#define BOARDIOC_USER _BOARDIOC(0x000e)
/****************************************************************************
* Public Type Definitions
@ -295,26 +287,11 @@ struct boardioc_nxterm_create_s
* /dev/nxtermN. 0 <= N <= 255 */
};
/* Arguments passed with the BOARDIOC_NXTERM_REDRAW command */
struct boardioc_nxterm_redraw_s
struct boardioc_nxterm_ioctl_s
{
NXTERM handle; /* NxTerm handle */
struct nxgl_rect_s rect; /* Rectangle to be re-drawn */
bool more; /* True: More redraw commands follow */
int cmd; /* IOCTL command */
uintptr_t arg; /* IOCTL argument */
};
#ifdef CONFIG_NXTERM_NXKBDIN
/* Arguments passed with the BOARDIOC_NXTERM_KBDIN command */
struct boardioc_nxterm_kbdin_s
{
NXTERM handle; /* NxTerm handle */
FAR const uint8_t *buffer; /* Buffered keyboard data */
uint8_t buflen; /* Amount of data in buffer */
};
#endif
#endif /* CONFIG_NXTERM */
/****************************************************************************