Add NX kbd input support to NxConsole
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4753 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
1d5e3bbc75
commit
d2a564f8c8
@ -2781,3 +2781,12 @@
|
||||
things happen.
|
||||
|
||||
6.19 2012-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* graphics/nxconsole/nxcon_kbdin.c: If selected, the NxConsole will take
|
||||
input from the NX keyboard input callback. If this option is set, then
|
||||
the interface nxcon_kdbin() is enabled. That interface may be driven by
|
||||
window callback functions so that keyboard input *only* goes to the top
|
||||
window. If CONFIG_NXCONSOLE_NXKBDIN is not selected, then the NxConsole
|
||||
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 NxConsole windows without CONFIG_NXCONSOLE_NXKBDIN
|
||||
|
@ -3358,10 +3358,17 @@ int nxf_convert_32bpp(FAR uint32_t *dest, uint16_t height,
|
||||
|
||||
<h2>B.7 <a name="nxconsoleconfig">NxConsole Configuration Settings</a></h2>
|
||||
|
||||
<p>General NxConsole settings.</p>
|
||||
<ul>
|
||||
<dl>
|
||||
<dt><code>CONFIG_NXCONSOLE</code>:
|
||||
<dd>Enables building of the NxConsole driver.
|
||||
</dl>
|
||||
</ul>
|
||||
|
||||
<p>NxConsole output text/graphics options:</p>
|
||||
<ul>
|
||||
<dl>
|
||||
<dt><code>CONFIG_NXCONSOLE_BPP</code>:
|
||||
<dd>Currently, NxConsole supports only a single pixel depth.
|
||||
This configuration setting must be provided to support that single pixel depth.
|
||||
@ -3399,6 +3406,23 @@ int nxf_convert_32bpp(FAR uint32_t *dest, uint16_t height,
|
||||
</dl>
|
||||
</ul>
|
||||
|
||||
<p>NxConsole input options:</p>
|
||||
<ul>
|
||||
<dl>
|
||||
<dt><code>CONFIG_NXCONSOLE_NXKBDIN</code>:
|
||||
<dd>Take input from the NX keyboard input callback.
|
||||
By default, keyboard input is taken from stdin (<code>/dev/console</code>).
|
||||
If this option is set, then the interface<code>nxcon_kdbin()</code> is enabled.
|
||||
That interface may be driven by window callback functions so that keyboard input <i>only</i> goes to the top window.
|
||||
<dt><code>CONFIG__NXCONSOLE_KBDBUFSIZE</code>:
|
||||
<dd>If <code>CONFIG_NXCONSOLE_NXKBDIN</code> is enabled, then this value may be used to
|
||||
define the size of the per-window keyboar input buffer. Default: 16
|
||||
<dt><code>CONFIG_NXCONSOLE_NPOLLWAITERS</code>:
|
||||
<dd>The number of threads that can be waiting for read data available.
|
||||
Default: 4
|
||||
</dl>
|
||||
</ul>
|
||||
|
||||
<table width ="100%">
|
||||
<tr bgcolor="#e4e4e4">
|
||||
<td>
|
||||
|
@ -1,8 +1,8 @@
|
||||
############################################################################
|
||||
# graphics/Makefile
|
||||
#
|
||||
# Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
# Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
|
@ -232,6 +232,9 @@ Installing New Fonts
|
||||
Configuration Settings
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
General NX Settings
|
||||
-------------------
|
||||
|
||||
CONFIG_NX
|
||||
Enables overall support for graphics library and NX
|
||||
CONFIG_NX_MULTIUSER
|
||||
@ -273,6 +276,9 @@ CONFIG_NXFONTS_CHARBITS
|
||||
The number of bits in the character set. Current options are only 7 and 8.
|
||||
The default is 7.
|
||||
|
||||
Font Selections
|
||||
---------------
|
||||
|
||||
CONFIG_NXFONT_SANS17X22
|
||||
This option enables support for a tiny, 17x22 san serif font
|
||||
(font ID FONTID_SANS17X22 == 14).
|
||||
@ -325,10 +331,14 @@ CONFIG_NXFONT_SERIF38X49B
|
||||
This option enables support for a large, 38x49 bold font (with serifs)
|
||||
(font ID FONTID_SERIF38X49B == 13).
|
||||
|
||||
NxConsole Configuration Settings:
|
||||
NxConsole Configuration Settings
|
||||
--------------------------------
|
||||
|
||||
CONFIG_NXCONSOLE
|
||||
Enables building of the NxConsole driver.
|
||||
|
||||
NxConsole output text/graphics options:
|
||||
|
||||
CONFIG_NXCONSOLE_BPP
|
||||
Currently, NxConsole supports only a single pixel depth. This
|
||||
configuration setting must be provided to support that single pixel depth.
|
||||
@ -361,7 +371,23 @@ CONFIG_NXCONSOLE_NOWRAP
|
||||
of the window. This setting can be defining to change this behavior so
|
||||
that the text is simply truncated until a new line is encountered.
|
||||
|
||||
NX Multi-user only options:
|
||||
NxConsole Input options
|
||||
|
||||
CONFIG_NXCONSOLE_NXKBDIN
|
||||
Take input from the NX keyboard input callback. By default, keyboard
|
||||
input is taken from stdin (/dev/console). If this option is set, then
|
||||
the interface nxcon_kdbin() is enabled. That interface may be driven
|
||||
by window callback functions so that keyboard input *only* goes to the
|
||||
top window.
|
||||
CONFIG__NXCONSOLE_KBDBUFSIZE
|
||||
If CONFIG_NXCONSOLE_NXKBDIN is enabled, then this value may be used to
|
||||
define the size of the per-window keyboard input buffer. Default: 16
|
||||
CONFIG_NXCONSOLE_NPOLLWAITERS
|
||||
The number of threads that can be waiting for read data available.
|
||||
Default: 4
|
||||
|
||||
NX Multi-user only options
|
||||
--------------------------
|
||||
|
||||
CONFIG_NX_BLOCKING
|
||||
Open the client message queues in blocking mode. In this case,
|
||||
|
@ -39,6 +39,10 @@ NXCON_CSRCS += nxcon_redraw.c nxcon_register.c nxcon_scroll.c
|
||||
NXCON_CSRCS += nxcon_vt100.c nxcon_unregister.c nxtk_register.c
|
||||
NXCON_CSRCS += nxtool_register.c
|
||||
|
||||
ifeq ($(CONFIG_NXCONSOLE_NXKBDIN),y)
|
||||
NXCON_CSRCS += nxcon_kbdin.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DEBUG),y)
|
||||
NXCON_CSRCS += nxcon_sem.c
|
||||
endif
|
||||
|
@ -64,6 +64,24 @@ static ssize_t nxcon_write(FAR struct file *filep, FAR const char *buffer,
|
||||
****************************************************************************/
|
||||
/* This is the common NX driver file operations */
|
||||
|
||||
#ifdef CONFIG_NXCONSOLE_NXKBDIN
|
||||
|
||||
const struct file_operations g_nxcon_drvrops =
|
||||
{
|
||||
nxcon_open, /* open */
|
||||
0, /* close */
|
||||
nxcon_read, /* read */
|
||||
nxcon_write, /* write */
|
||||
0, /* seek */
|
||||
0 /* ioctl */
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
,
|
||||
nxcon_poll /* poll */
|
||||
#endif
|
||||
};
|
||||
|
||||
#else /* CONFIG_NXCONSOLE_NXKBDIN */
|
||||
|
||||
const struct file_operations g_nxcon_drvrops =
|
||||
{
|
||||
nxcon_open, /* open */
|
||||
@ -73,10 +91,13 @@ const struct file_operations g_nxcon_drvrops =
|
||||
0, /* seek */
|
||||
0 /* ioctl */
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
, 0 /* poll */
|
||||
,
|
||||
0 /* poll */
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* CONFIG_NXCONSOLE_NXKBDIN */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
@ -104,11 +125,13 @@ static int nxcon_open(FAR struct file *filep)
|
||||
|
||||
/* Verify that the driver is opened for write-only access */
|
||||
|
||||
#ifndef CONFIG_NXCONSOLE_NXKBDIN
|
||||
if ((filep->f_oflags & O_RDOK) != 0)
|
||||
{
|
||||
gdbg("Attempted open with read access\n");
|
||||
return -EACCES;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Assign the driver structure to the file */
|
||||
|
||||
|
@ -144,6 +144,9 @@ struct nxcon_state_s
|
||||
#ifdef CONFIG_DEBUG
|
||||
pid_t holder; /* Deadlock avoidance */
|
||||
#endif
|
||||
|
||||
/* Text output support */
|
||||
|
||||
struct nxgl_point_s fpos; /* Next display position */
|
||||
|
||||
uint16_t maxchars; /* Size of the bm[] array */
|
||||
@ -168,6 +171,26 @@ struct nxcon_state_s
|
||||
/* Glyph cache data storage */
|
||||
|
||||
struct nxcon_glyph_s glyph[CONFIG_NXCONSOLE_CACHESIZE];
|
||||
|
||||
/* Keyboard input support */
|
||||
|
||||
#ifdef CONFIG_NXCONSOLE_NXKBDIN
|
||||
sem_t waitsem; /* Supports waiting for input data */
|
||||
uint8_t nwaiters; /* Number of threads waiting for data */
|
||||
uint8_t head; /* rxbuffer head/input index */
|
||||
uint8_t tail; /* rxbuffer tail/output index */
|
||||
|
||||
uint8_t rxbuffer[CONFIG_NXCONSOLE_KBDBUFSIZE];
|
||||
|
||||
/* The following is a list if poll structures of threads waiting for
|
||||
* driver events. The 'struct pollfd' reference for each open is also
|
||||
* retained in the f_priv field of the 'struct file'.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
struct pollfd *fds[CONFIG_RAMLOG_NPOLLWAITERS];
|
||||
#endif
|
||||
#endif /* CONFIG_NXCONSOLE_NXKBDIN */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@ -197,6 +220,13 @@ FAR struct nxcon_state_s *nxcon_register(NXCONSOLE handle,
|
||||
FAR struct nxcon_window_s *wndo, FAR const struct nxcon_operations_s *ops,
|
||||
int minor);
|
||||
|
||||
#ifdef CONFIG_NXCONSOLE_NXKBDIN
|
||||
ssize_t nxcon_read(FAR struct file *filep, FAR char *buffer, size_t len);
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
int nxcon_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* VT100 Terminal emulation */
|
||||
|
||||
enum nxcon_vt100state_e nxcon_vt100(FAR struct nxcon_state_s *priv, char ch);
|
||||
|
470
graphics/nxconsole/nxcon_kbdin.c
Normal file
470
graphics/nxconsole/nxcon_kbdin.c
Normal file
@ -0,0 +1,470 @@
|
||||
/****************************************************************************
|
||||
* nuttx/graphics/nxconsole/nxcon_kbdin.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sched.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include "nxcon_internal.h"
|
||||
|
||||
#ifdef CONFIG_NXCONSOLE_NXKBDIN
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxcon_pollnotify
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
static void nxcon_pollnotify(FAR struct nxcon_state_s *priv, pollevent_t eventset)
|
||||
{
|
||||
FAR struct pollfd *fds;
|
||||
irqstate_t flags;
|
||||
int i;
|
||||
|
||||
/* This function may be called from an interrupt handler */
|
||||
|
||||
for (i = 0; i < CONFIG_NXCONSOLE_NPOLLWAITERS; i++)
|
||||
{
|
||||
flags = irqsave();
|
||||
fds = priv->fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= (fds->events & eventset);
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
sem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
irqrestore(flags);
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define nxcon_pollnotify(priv,event)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxcon_read
|
||||
*
|
||||
* Description:
|
||||
* The optional NxConsole read method
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t nxcon_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
||||
{
|
||||
FAR struct nxcon_state_s *priv;
|
||||
ssize_t nread;
|
||||
char ch;
|
||||
int ret;
|
||||
|
||||
/* Recover our private state structure */
|
||||
|
||||
DEBUGASSERT(filep && filep->f_priv);
|
||||
priv = (FAR struct nxcon_state_s *)filep->f_priv;
|
||||
|
||||
/* Get exclusive access to the driver structure */
|
||||
|
||||
ret = nxcon_semwait(priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Loop until something is read */
|
||||
|
||||
for (nread = 0; nread < len; )
|
||||
{
|
||||
/* Get the next byte from the buffer */
|
||||
|
||||
if (priv->head == priv->tail)
|
||||
{
|
||||
/* The circular buffer is empty. Did we read anything? */
|
||||
|
||||
if (nread > 0)
|
||||
{
|
||||
/* Yes.. break out to return what we have. */
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
/* If the driver was opened with O_NONBLOCK option, then don't wait.
|
||||
* Just return EGAIN.
|
||||
*/
|
||||
|
||||
if (filep->f_oflags & O_NONBLOCK)
|
||||
{
|
||||
nread = -EAGAIN;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Otherwise, wait for something to be written to the circular
|
||||
* buffer. Increment the number of waiters so that the nxcon_write()
|
||||
* will not that it needs to post the semaphore to wake us up.
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
priv->nwaiters++;
|
||||
nxcon_sempost(priv);
|
||||
|
||||
/* We may now be pre-empted! But that should be okay because we
|
||||
* have already incremented nwaiters. Pre-emption is disabled
|
||||
* but will be re-enabled while we are waiting.
|
||||
*/
|
||||
|
||||
ret = sem_wait(&priv->waitsem);
|
||||
|
||||
/* Pre-emption will be disabled when we return. So the decrementing
|
||||
* nwaiters here is safe.
|
||||
*/
|
||||
|
||||
priv->nwaiters--;
|
||||
sched_unlock();
|
||||
|
||||
/* Did we successfully get the waitsem? */
|
||||
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* Yes... then retake the mutual exclusion semaphore */
|
||||
|
||||
ret = nxcon_semwait(priv);
|
||||
}
|
||||
|
||||
/* Was the semaphore wait successful? Did we successful re-take the
|
||||
* mutual exclusion semaphore?
|
||||
*/
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
/* No.. One of the two sem_wait's failed. */
|
||||
|
||||
int errval = errno;
|
||||
|
||||
/* Were we awakened by a signal? Did we read anything before
|
||||
* we received the signal?
|
||||
*/
|
||||
|
||||
if (errval != EINTR || nread >= 0)
|
||||
{
|
||||
/* Yes.. return the error. */
|
||||
|
||||
nread = -errval;
|
||||
}
|
||||
|
||||
/* Break out to return what we have. Note, we can't exactly
|
||||
* "break" out because whichever error occurred, we do not hold
|
||||
* the exclusion semaphore.
|
||||
*/
|
||||
|
||||
goto errout_without_sem;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The circular buffer is not empty, get the next byte from the
|
||||
* tail index.
|
||||
*/
|
||||
|
||||
ch = priv->rxbuffer[priv->tail];
|
||||
|
||||
/* Increment the tail index and re-enable interrupts */
|
||||
|
||||
if (++priv->tail >= CONFIG_NXCONSOLE_KBDBUFSIZE)
|
||||
{
|
||||
priv->tail = 0;
|
||||
}
|
||||
|
||||
/* Add the character to the user buffer */
|
||||
|
||||
buffer[nread] = ch;
|
||||
nread++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Relinquish the mutual exclusion semaphore */
|
||||
|
||||
sem_post(&priv->exclsem);
|
||||
|
||||
/* Notify all poll/select waiters that they can write to the FIFO */
|
||||
|
||||
errout_without_sem:
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
if (nread > 0)
|
||||
{
|
||||
nxcon_pollnotify(priv, POLLOUT);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Return the number of characters actually read */
|
||||
|
||||
return nread;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxcon_poll
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
int nxcon_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct nxcon_state_s *priv;
|
||||
pollevent_t eventset;
|
||||
int ndx;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Some sanity checking */
|
||||
|
||||
DEBUGASSERT(inode && inode->i_private);
|
||||
priv = inode->i_private;
|
||||
|
||||
/* Get exclusive access to the driver structure */
|
||||
|
||||
ret = nxcon_semwait(priv);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Are we setting up the poll? Or tearing it down? */
|
||||
|
||||
if (setup)
|
||||
{
|
||||
/* This is a request to set up the poll. Find an available
|
||||
* slot for the poll structure reference
|
||||
*/
|
||||
|
||||
for (i = 0; i < CONFIG_NXCONSOLE_NPOLLWAITERS; i++)
|
||||
{
|
||||
/* Find an available slot */
|
||||
|
||||
if (!priv->fds[i])
|
||||
{
|
||||
/* Bind the poll structure and this slot */
|
||||
|
||||
priv->fds[i] = fds;
|
||||
fds->priv = &priv->fds[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= CONFIG_NXCONSOLE_NPOLLWAITERS)
|
||||
{
|
||||
fds->priv = NULL;
|
||||
ret = -EBUSY;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Should immediately notify on any of the requested events?
|
||||
* This driver is always available for transmission.
|
||||
*/
|
||||
|
||||
eventset = POLLOUT;
|
||||
|
||||
/* Check if the receive buffer is empty */
|
||||
|
||||
if (priv->head != priv->tail)
|
||||
{
|
||||
eventset |= POLLIN;
|
||||
}
|
||||
|
||||
if (eventset)
|
||||
{
|
||||
nxcon_pollnotify(priv, eventset);
|
||||
}
|
||||
|
||||
}
|
||||
else if (fds->priv)
|
||||
{
|
||||
/* This is a request to tear down the poll. */
|
||||
|
||||
struct pollfd **slot = (struct pollfd **)fds->priv;
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!slot)
|
||||
{
|
||||
ret = -EIO;
|
||||
goto errout;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Remove all memory of the poll setup */
|
||||
|
||||
*slot = NULL;
|
||||
fds->priv = NULL;
|
||||
}
|
||||
|
||||
errout:
|
||||
nxcon_sempost(priv);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxcon_kdbin
|
||||
*
|
||||
* Description:
|
||||
* This function should be driven by the window kbdin callback function
|
||||
* (see nx.h). When the NxConsole 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 may
|
||||
* it available to the NxConsole as stdin.
|
||||
*
|
||||
* If CONFIG_NXCONSOLE_NXKBDIN is not selected, then the NxConsole 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 NxConsole windows without CONFIG_NXCONSOLE_NXKBDIN
|
||||
*
|
||||
* 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
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void nxcon_kdbin(NXCONSOLE handle, FAR const uint8_t *buffer, uint8_t buflen)
|
||||
{
|
||||
FAR struct nxcon_state_s *priv;
|
||||
ssize_t nwritten;
|
||||
int nexthead;
|
||||
char ch;
|
||||
|
||||
DEBUGASSERT(handle);
|
||||
|
||||
/* Get the reference to the driver structure from the handle */
|
||||
|
||||
priv = (FAR struct nxcon_state_s *)handle;
|
||||
|
||||
/* Loop until all of the bytes have been written. This function may be
|
||||
* called from an interrupt handler! Semaphores cannot be used!
|
||||
*
|
||||
* The write logic only needs to modify the head index. Therefore,
|
||||
* there is a difference in the way that head and tail are protected:
|
||||
* tail is protected with a semaphore; tail is protected by disabling
|
||||
* interrupts.
|
||||
*/
|
||||
|
||||
for (nwritten = 0; nwritten < buflen; nwritten++)
|
||||
{
|
||||
/* Add the next character */
|
||||
|
||||
ch = buffer[nwritten];
|
||||
|
||||
/* Calculate the write index AFTER the next byte is add to the ring
|
||||
* buffer
|
||||
*/
|
||||
|
||||
nexthead = priv->head + 1;
|
||||
if (nexthead >= CONFIG_NXCONSOLE_KBDBUFSIZE)
|
||||
{
|
||||
nexthead = 0;
|
||||
}
|
||||
|
||||
/* Would the next write overflow the circular buffer? */
|
||||
|
||||
if (nexthead == priv->tail)
|
||||
{
|
||||
/* Yes... Return an indication that nothing was saved in the buffer. */
|
||||
|
||||
gdbg("ERROR: Keyboard data overrun\n");
|
||||
break;
|
||||
}
|
||||
|
||||
/* No... copy the byte */
|
||||
|
||||
priv->rxbuffer[priv->head] = ch;
|
||||
priv->head = nexthead;
|
||||
}
|
||||
|
||||
/* Was anything written? */
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
if (nwritten > 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Are there threads waiting for read data? */
|
||||
|
||||
sched_lock();
|
||||
for (i = 0; i < priv->nwaiters; i++)
|
||||
{
|
||||
/* Yes.. Notify all of the waiting readers that more data is available */
|
||||
|
||||
sem_post(&priv->waitsem);
|
||||
}
|
||||
|
||||
/* Notify all poll/select waiters that they can write to the FIFO */
|
||||
|
||||
nxcon_pollnotify(priv, POLLIN);
|
||||
sched_unlock();
|
||||
}
|
||||
#endif
|
||||
|
||||
nxcon_sempost(priv);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NXCONSOLE_NXKBDIN */
|
@ -99,6 +99,9 @@ FAR struct nxcon_state_s *
|
||||
memcpy(&priv->wndo, wndo, sizeof( struct nxcon_window_s));
|
||||
|
||||
sem_init(&priv->exclsem, 0, 1);
|
||||
#ifdef CONFIG_NXCONSOLE_NXKBDIN
|
||||
sem_init(&priv->waitsem, 0, 0);
|
||||
#endif
|
||||
|
||||
/* Select the font */
|
||||
|
||||
|
@ -97,6 +97,9 @@ void nxcon_unregister(NXCONSOLE handle)
|
||||
|
||||
priv = (FAR struct nxcon_state_s *)handle;
|
||||
sem_destroy(&priv->exclsem);
|
||||
#ifdef CONFIG_NXCONSOLE_NXKBDIN
|
||||
sem_destroy(&priv->waitsem);
|
||||
#endif
|
||||
|
||||
/* Free all allocated glyph bitmap */
|
||||
|
||||
|
@ -65,6 +65,9 @@
|
||||
*
|
||||
* CONFIG_NXCONSOLE
|
||||
* Enables building of the NxConsole driver.
|
||||
*
|
||||
* Output text/graphics options:
|
||||
*
|
||||
* CONFIG_NXCONSOLE_BPP
|
||||
* Currently, NxConsole supports only a single pixel depth. This
|
||||
* configuration setting must be provided to support that single pixel depth.
|
||||
@ -91,6 +94,21 @@
|
||||
* By default, lines will wrap when the test reaches the right hand side
|
||||
* of the window. This setting can be defining to change this behavior so
|
||||
* that the text is simply truncated until a new line is encountered.
|
||||
*
|
||||
* Input options:
|
||||
*
|
||||
* CONFIG_NXCONSOLE_NXKBDIN
|
||||
* Take input from the NX keyboard input callback. By default, keyboard
|
||||
* input is taken from stdin (/dev/console). If this option is set, then
|
||||
* the interface nxcon_kdbin() is enabled. That interface may be driven
|
||||
* by window callback functions so that keyboard input *only* goes to the
|
||||
* top window.
|
||||
* CONFIG_NXCONSOLE_KBDBUFSIZE
|
||||
* If CONFIG_NXCONSOLE_NXKBDIN is enabled, then this value may be used to
|
||||
* define the size of the per-window keyboard input buffer. Default: 16
|
||||
* CONFIG_NXCONSOLE_NPOLLWAITERS
|
||||
* The number of threads that can be waiting for read data available.
|
||||
* Default: 4
|
||||
*/
|
||||
|
||||
/* Cursor character */
|
||||
@ -141,6 +159,30 @@
|
||||
# define CONFIG_NXCONSOLE_LINESEPARATION 0
|
||||
#endif
|
||||
|
||||
/* Input options */
|
||||
|
||||
#ifndef CONFIG_NX_KBD
|
||||
# undef CONFIG_NXCONSOLE_NXKBDIN
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NXCONSOLE_NXKBDIN
|
||||
|
||||
# ifndef CONFIG_NXCONSOLE_KBDBUFSIZE
|
||||
# define CONFIG_NXCONSOLE_KBDBUFSIZE 16
|
||||
# elif (CONFIG_NXCONSOLE_KBDBUFSIZE < 1) || (CONFIG_NXCONSOLE_KBDBUFSIZE > 255)
|
||||
# error "CONFIG_NXCONSOLE_KBDBUFSIZE is out of range (1-255)"
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_NXCONSOLE_NPOLLWAITERS
|
||||
# define CONFIG_NXCONSOLE_NPOLLWAITERS 4
|
||||
# endif
|
||||
|
||||
#else
|
||||
# undef CONFIG_NXCONSOLE_KBDBUFSIZE
|
||||
# define CONFIG_NXCONSOLE_KBDBUFSIZE 0
|
||||
# define CONFIG_NXCONSOLE_NPOLLWAITERS 0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@ -285,6 +327,37 @@ EXTERN void nxcon_unregister(NXCONSOLE handle);
|
||||
EXTERN void nxcon_redraw(NXCONSOLE handle, FAR const struct nxgl_rect_s *rect,
|
||||
bool more);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxcon_kdbin
|
||||
*
|
||||
* Description:
|
||||
* This function should be driven by the window kbdin callback function
|
||||
* (see nx.h). When the NxConsole 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 may
|
||||
* it available to the NxConsole as stdin.
|
||||
*
|
||||
* If CONFIG_NXCONSOLE_NXKBDIN is not selected, then the NxConsole 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 NxConsole windows without CONFIG_NXCONSOLE_NXKBDIN
|
||||
*
|
||||
* 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_NXCONSOLE_NXKBDIN
|
||||
EXTERN void nxcon_kdbin(NXCONSOLE handle, FAR const uint8_t *buffer,
|
||||
uint8_t buflen);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user