summaryrefslogtreecommitdiffstats
path: root/nuttx/graphics/nxconsole
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-03-26 22:10:21 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-03-26 22:10:21 +0000
commit5f606f01b37bcde9b1a1d1bd9f7b9b99d285db18 (patch)
tree944155d15d445099ed9a21737b66dbd8b747eed8 /nuttx/graphics/nxconsole
parentea6f2252102e999dbf2d9ca8ba87ba86158deb9c (diff)
Add beginnings of an NX console driver
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4524 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/graphics/nxconsole')
-rw-r--r--nuttx/graphics/nxconsole/Make.defs38
-rw-r--r--nuttx/graphics/nxconsole/nx_register.c193
-rw-r--r--nuttx/graphics/nxconsole/nxcon_internal.h170
-rw-r--r--nuttx/graphics/nxconsole/nxcon_register.c123
-rw-r--r--nuttx/graphics/nxconsole/nxcon_unregister.c101
-rw-r--r--nuttx/graphics/nxconsole/nxtk_register.c192
-rw-r--r--nuttx/graphics/nxconsole/nxtool_register.c195
7 files changed, 1012 insertions, 0 deletions
diff --git a/nuttx/graphics/nxconsole/Make.defs b/nuttx/graphics/nxconsole/Make.defs
new file mode 100644
index 0000000000..95b4ff49e4
--- /dev/null
+++ b/nuttx/graphics/nxconsole/Make.defs
@@ -0,0 +1,38 @@
+############################################################################
+# graphics/nxconsole/Make.defs
+#
+# 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.
+#
+############################################################################
+
+NXCON_ASRCS =
+NXCON_CSRCS = nx_register.c nxcon_register.c nxcon_unregister.c
+NXCON_CSRCS += nxtk_register.c nxtool_register.c
diff --git a/nuttx/graphics/nxconsole/nx_register.c b/nuttx/graphics/nxconsole/nx_register.c
new file mode 100644
index 0000000000..c009720347
--- /dev/null
+++ b/nuttx/graphics/nxconsole/nx_register.c
@@ -0,0 +1,193 @@
+/****************************************************************************
+ * nuttx/graphics/nxconsole/nx_register.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 <nuttx/nx/nx.h>
+#include <nuttx/nx/nxconsole.h>
+
+#include "nxcon_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int nxcon_fill(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES]);
+#ifndef CONFIG_NXCONSOLE_NOGETRUN
+static int nxcon_move(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ FAR const struct nxgl_point_s *offset);
+#endif
+static int nxcon_bitmap(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const void *src[CONFIG_NX_NPLANES],
+ FAR const struct nxgl_point_s *origin,
+ unsigned int stride);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct nxcon_operations_s g_nxops =
+{
+ nxcon_fill,
+#ifndef CONFIG_NXCONSOLE_NOGETRUN
+ nxcon_move,
+#endif
+ nxcon_bitmap
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxcon_fill
+ *
+ * Description:
+ * Fill the specified rectangle in the window with the specified color
+ *
+ * Input Parameters:
+ * priv - The driver state structure.
+ * rect - The location to be filled
+ * color - The color to use in the fill
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+static int nxcon_fill(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES])
+{
+ return nx_fill((NXWINDOW)priv->handle, rect, wcolor);
+}
+
+/****************************************************************************
+ * Name: nxcon_move
+ *
+ * Description:
+ * Move a rectangular region within the window
+ *
+ * Input Parameters:
+ * priv - The driver state structure.
+ * rect - Describes the rectangular region to move
+ * offset - The offset to move the region. The rectangular region will be
+ * moved so that the origin is translated by this amount.
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_NXCONSOLE_NOGETRUN
+static int nxcon_move(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ FAR const struct nxgl_point_s *offset)
+{
+ return nx_move((NXWINDOW)priv->handle, rect, offset);
+}
+#endif
+
+/****************************************************************************
+ * Name: nxcon_bitmap
+ *
+ * Description:
+ * Copy a rectangular region of a larger image into the rectangle in the
+ * specified window.
+ *
+ * Input Parameters:
+ * priv - The driver state structure.
+ * dest - Describes the rectangular region on the display that will
+ * receive the bit map.
+ * src - The start of the source image. This is an array source
+ * images of size CONFIG_NX_NPLANES.
+ * origin - The origin of the upper, left-most corner of the full bitmap.
+ * Both dest and origin are in window coordinates, however, origin
+ * may lie outside of the display.
+ * stride - The width of the full source image in bytes.
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+static int nxcon_bitmap(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const void *src[CONFIG_NX_NPLANES],
+ FAR const struct nxgl_point_s *origin,
+ unsigned int stride)
+{
+ return nx_bitmap((NXWINDOW)priv->handle, dest, src, origin, stride);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nx_register
+ *
+ * Description:
+ * Register a console device on a raw NX window. The device will be
+ * registered at /dev/nxconN where N is the provided minor number.
+ *
+ * Input Parameters:
+ * hwnd - A handle that will be used to access the window. The window must
+ * persist and this handle must be valid for the life of the NX console.
+ * wndo - Describes the window and font to be used
+ * minor - The device minor number
+ *
+ * Return:
+ * A non-NULL handle is returned on success.
+ *
+ ****************************************************************************/
+
+NXCONSOLE nx_register(NXWINDOW hwnd, FAR struct nxcon_window_s *wndo, int minor)
+{
+ return nxcon_register((NXCONSOLE)hwnd, wndo, &g_nxops, minor);
+}
+
diff --git a/nuttx/graphics/nxconsole/nxcon_internal.h b/nuttx/graphics/nxconsole/nxcon_internal.h
new file mode 100644
index 0000000000..d0e332ba49
--- /dev/null
+++ b/nuttx/graphics/nxconsole/nxcon_internal.h
@@ -0,0 +1,170 @@
+/****************************************************************************
+ * nuttx/graphics/nxconsole/nxcon_internal.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __GRAPHICS_NXCONSOLE_NXCON_INTERNAL_H
+#define __GRAPHICS_NXCONSOLE_NXCON_INTERNAL_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+#include <nuttx/fs/fs.h>
+
+#include <nuttx/nx/nx.h>
+#include <nuttx/nx/nxtk.h>
+#include <nuttx/nx/nxfonts.h>
+#include <nuttx/nx/nxconsole.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+/* Bitmap flags */
+
+#define BMFLAGS_NOGLYPH (1 << 0) /* No glyph available, use space */
+
+#define BM_ISSPACE(bm) (((bm)->flags & BMFLAGS_NOGLYPH) != 0)
+
+/* Sizes and maximums */
+
+#define MAX_USECNT 255 /* Limit to range of a uint8_t */
+#define LINE_SEPARATION 2 /* Space (in rows) between lines */
+
+/* Device path formats */
+
+#define NX_DEVNAME_FORMAT "/dev/nxcon%d"
+#define NX_DEVNAME_SIZE 16
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Describes on set of console window callbacks */
+
+struct nxcon_state_s;
+struct nxcon_operations_s
+{
+ int (*fill)(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES]);
+#ifndef CONFIG_NXCONSOLE_NOGETRUN
+ int (*move)(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ FAR const struct nxgl_point_s *offset);
+#endif
+ int (*bitmap)(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const void *src[CONFIG_NX_NPLANES],
+ FAR const struct nxgl_point_s *origin,
+ unsigned int stride);
+};
+
+/* Describes one cached glyph bitmap */
+
+struct nxcon_glyph_s
+{
+ uint8_t code; /* Character code */
+ uint8_t height; /* Height of this glyph (in rows) */
+ uint8_t width; /* Width of this glyph (in pixels) */
+ uint8_t stride; /* Width of the glyph row (in bytes) */
+ uint8_t usecnt; /* Use count */
+ FAR uint8_t *bitmap; /* Allocated bitmap memory */
+};
+
+/* Describes on character on the display */
+
+struct nxcon_bitmap_s
+{
+ uint8_t code; /* Character code */
+ uint8_t flags; /* See BMFLAGS_* */
+ struct nxgl_point_s pos; /* Character position */
+};
+
+/* Describes the state of one NX console driver*/
+
+struct nxcon_state_s
+{
+ FAR const struct nxcon_operations_s *ops; /* Window operations */
+ FAR void *handle; /* The window handle */
+ uint8_t minor; /* Device minor number */
+ FAR struct nxcon_window_s wndo; /* Describes the window and font */
+
+ /* These characterize the font in use */
+
+ NXHANDLE font; /* The current font handle */
+ uint8_t fheight; /* Max height of a font in pixels */
+ uint8_t fwidth; /* Max width of a font in pixels */
+ uint8_t spwidth; /* The width of a space */
+ struct nxgl_point_s fpos; /* Next display position */
+
+ /* These describe all text already added to the display */
+
+ uint8_t maxglyphs; /* Size of the glyph[] array */
+ uint16_t maxchars; /* Size of the bm[] array */
+ uint16_t nchars; /* Number of chars in the bm[] array */
+
+ FAR struct nxcon_bitmap_s *bm; /* List of characters on the display */
+ FAR struct nxcon_glyph_s *glyph; /* Cache of rendered fonts in use */
+};
+
+/****************************************************************************
+ * Public Variables
+ ****************************************************************************/
+
+/* This is the common NX driver file operations */
+
+extern const struct file_operations g_nxcondrvrops;
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+/* Common device registration */
+
+FAR struct nxcon_state_s *nxcon_register(NXCONSOLE handle,
+ FAR struct nxcon_window_s *wndo, FAR const struct nxcon_operations_s *ops,
+ int minor);
+
+/* Generic text helpers */
+
+void nxcon_home(FAR struct nxcon_state_s *priv);
+void nxcon_newline(FAR struct nxcon_state_s *priv);
+void nxcon_putc(FAR struct nxcon_state_s *priv, NXHANDLE hfont, uint8_t ch);
+void nxcon_fillchar(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect, FAR const struct nxcon_bitmap_s *bm);
+
+#endif /* __GRAPHICS_NXCONSOLE_NXCON_INTERNAL_H */
diff --git a/nuttx/graphics/nxconsole/nxcon_register.c b/nuttx/graphics/nxconsole/nxcon_register.c
new file mode 100644
index 0000000000..d85b5ffc36
--- /dev/null
+++ b/nuttx/graphics/nxconsole/nxcon_register.c
@@ -0,0 +1,123 @@
+/****************************************************************************
+ * nuttx/graphics/nxconsole/nxcon_register.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 <sys/types.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+
+#include "nxcon_internal.h"
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxcon_allocate
+ ****************************************************************************/
+
+FAR struct nxcon_state_s *
+ nxcon_register(NXCONSOLE handle, FAR struct nxcon_window_s *wndo,
+ FAR const struct nxcon_operations_s *ops, int minor)
+{
+ FAR struct nxcon_state_s *priv;
+ char devname[NX_DEVNAME_SIZE];
+ int ret;
+
+ DEBUGASSERT(handle && wndo && ops && (unsigned)minor < 256);
+
+ /* Allocate the driver structure */
+
+ priv = (FAR struct nxcon_state_s *)kzalloc(sizeof(struct nxcon_state_s));
+ if (!priv)
+ {
+ gdbg("Failed to allocate the NX driver structure\n");
+ return NULL;
+ }
+
+ /* Initialize the driver structure */
+
+ priv->ops = ops;
+ priv->handle = handle;
+ priv->minor = minor;
+ memcpy(&priv->wndo, wndo, sizeof( struct nxcon_window_s));
+
+ /* Select the font */
+
+ priv->font = nxf_getfonthandle(wndo->fontid);
+ if (!priv->font)
+ {
+ gdbg("Failed to get font ID %d: %d\n", wndo->fontid, errno);
+ goto errout;
+ }
+
+ /* Register the driver */
+
+ snprintf(devname, NX_DEVNAME_SIZE, NX_DEVNAME_FORMAT, minor);
+ ret = register_driver(devname, &g_nxcondrvrops, 0666, priv);
+ if (ret < 0)
+ {
+ gdbg("Failed to register %s\n", devname);
+ }
+ return (NXCONSOLE)priv;
+
+errout:
+ kfree(priv);
+ return NULL;
+}
diff --git a/nuttx/graphics/nxconsole/nxcon_unregister.c b/nuttx/graphics/nxconsole/nxcon_unregister.c
new file mode 100644
index 0000000000..1b92649cd3
--- /dev/null
+++ b/nuttx/graphics/nxconsole/nxcon_unregister.c
@@ -0,0 +1,101 @@
+/****************************************************************************
+ * nuttx/graphics/nxconsole/nxcon_unregister.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 <sys/types.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/nx/nxconsole.h>
+
+#include "nxcon_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxcon_unregister
+ *
+ * Description:
+ * Un-register to NX console device.
+ *
+ * Input Parameters:
+ * handle - A handle previously returned by nx_register, nxtk_register, or
+ * nxtool_register.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void nxcon_unregister(NXCONSOLE handle)
+{
+ FAR struct nxcon_state_s *priv;
+ char devname[NX_DEVNAME_SIZE];
+
+ /* Unregister the driver */
+
+ snprintf(devname, NX_DEVNAME_SIZE, NX_DEVNAME_FORMAT, priv->minor);
+ (void)unregister_driver(devname);
+
+ /* Free the private data structure */
+
+ kfree(handle);
+}
diff --git a/nuttx/graphics/nxconsole/nxtk_register.c b/nuttx/graphics/nxconsole/nxtk_register.c
new file mode 100644
index 0000000000..6ea239d742
--- /dev/null
+++ b/nuttx/graphics/nxconsole/nxtk_register.c
@@ -0,0 +1,192 @@
+/****************************************************************************
+ * nuttx/graphics/nxconsole/nxtk_register.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 <nuttx/nx/nxtk.h>
+#include <nuttx/nx/nxconsole.h>
+
+#include "nxcon_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int nxtkcon_fill(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES]);
+#ifndef CONFIG_NXCONSOLE_NOGETRUN
+static int nxtkcon_move(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ FAR const struct nxgl_point_s *offset);
+#endif
+static int nxtkcon_bitmap(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const void *src[CONFIG_NX_NPLANES],
+ FAR const struct nxgl_point_s *origin,
+ unsigned int stride);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct nxcon_operations_s g_nxtkops =
+{
+ nxtkcon_fill,
+#ifndef CONFIG_NXCONSOLE_NOGETRUN
+ nxtkcon_move,
+#endif
+ nxtkcon_bitmap
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxtkcon_fill
+ *
+ * Description:
+ * Fill the specified rectangle in the window with the specified color
+ *
+ * Input Parameters:
+ * priv - The driver state structure.
+ * rect - The location to be filled
+ * color - The color to use in the fill
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+static int nxtkcon_fill(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES])
+{
+ return nxtk_fillwindow((NXTKWINDOW)priv->handle, rect, wcolor);
+}
+
+/****************************************************************************
+ * Name: nxtkcon_move
+ *
+ * Description:
+ * Move a rectangular region within the window
+ *
+ * Input Parameters:
+ * priv - The driver state structure.
+ * rect - Describes the rectangular region to move
+ * offset - The offset to move the region. The rectangular region will be
+ * moved so that the origin is translated by this amount.
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_NXCONSOLE_NOGETRUN
+static int nxtkcon_move(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ FAR const struct nxgl_point_s *offset)
+{
+ return nxtk_movewindow((NXTKWINDOW)priv->handle, rect, offset);
+}
+#endif
+
+/****************************************************************************
+ * Name: nxtkcon_bitmap
+ *
+ * Description:
+ * Copy a rectangular region of a larger image into the rectangle in the
+ * specified window.
+ *
+ * Input Parameters:
+ * priv - The driver state structure.
+ * dest - Describes the rectangular region on the display that will
+ * receive the bit map.
+ * src - The start of the source image. This is an array source
+ * images of size CONFIG_NX_NPLANES.
+ * origin - The origin of the upper, left-most corner of the full bitmap.
+ * Both dest and origin are in window coordinates, however, origin
+ * may lie outside of the display.
+ * stride - The width of the full source image in bytes.
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+static int nxtkcon_bitmap(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const void *src[CONFIG_NX_NPLANES],
+ FAR const struct nxgl_point_s *origin,
+ unsigned int stride)
+{
+ return nxtk_bitmapwindow((NXTKWINDOW)priv->handle, dest, src, origin, stride);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxtk_register
+ *
+ * Description:
+ * Register a console device on a framed NX window. The device will be
+ * registered at /dev/nxtkN where N is the provided minor number.
+ *
+ * Input Parameters:
+ * hfwnd - A handle that will be used to access the window. The window must
+ * persist and this handle must be valid for the life of the NX console.
+ * wndo - Describes the window and font to be used
+ * minor - The device minor number
+ *
+ * Return:
+ * A non-NULL handle is returned on success.
+ *
+ ****************************************************************************/
+
+NXCONSOLE nxtk_register(NXTKWINDOW hfwnd, FAR struct nxcon_window_s *wndo, int minor)
+{
+ return nxcon_register((NXCONSOLE)hfwnd, wndo, &g_nxtkops, minor);
+}
diff --git a/nuttx/graphics/nxconsole/nxtool_register.c b/nuttx/graphics/nxconsole/nxtool_register.c
new file mode 100644
index 0000000000..c5273d5f68
--- /dev/null
+++ b/nuttx/graphics/nxconsole/nxtool_register.c
@@ -0,0 +1,195 @@
+/****************************************************************************
+ * nuttx/graphics/nxconsole/nxtool_register.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 <nuttx/nx/nxtk.h>
+#include <nuttx/nx/nxconsole.h>
+
+#include "nxcon_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int nxtool_fill(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES]);
+#ifndef CONFIG_NXCONSOLE_NOGETRUN
+static int nxtool_move(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ FAR const struct nxgl_point_s *offset);
+#endif
+static int nxtool_bitmap(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const void *src[CONFIG_NX_NPLANES],
+ FAR const struct nxgl_point_s *origin,
+ unsigned int stride);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct nxcon_operations_s g_nxtoolops =
+{
+ nxtool_fill,
+#ifndef CONFIG_NXCONSOLE_NOGETRUN
+ nxtool_move,
+#endif
+ nxtool_bitmap
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxtool_fill
+ *
+ * Description:
+ * Fill the specified rectangle in the window with the specified color
+ *
+ * Input Parameters:
+ * priv - The driver state structure.
+ * rect - The location to be filled
+ * color - The color to use in the fill
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+static int nxtool_fill(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES])
+{
+ return nxtk_filltoolbar((NXTKWINDOW)priv->handle, rect, wcolor);
+}
+
+/****************************************************************************
+ * Name: nxtool_move
+ *
+ * Description:
+ * Move a rectangular region within the window
+ *
+ * Input Parameters:
+ * priv - The driver state structure.
+ * rect - Describes the rectangular region to move
+ * offset - The offset to move the region. The rectangular region will be
+ * moved so that the origin is translated by this amount.
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_NXCONSOLE_NOGETRUN
+static int nxtool_move(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *rect,
+ FAR const struct nxgl_point_s *offset)
+{
+ return nxtk_movetoolbar((NXTKWINDOW)priv->handle, rect, offset);
+}
+#endif
+
+/****************************************************************************
+ * Name: nxtool_bitmap
+ *
+ * Description:
+ * Copy a rectangular region of a larger image into the rectangle in the
+ * specified window.
+ *
+ * Input Parameters:
+ * priv - The driver state structure.
+ * dest - Describes the rectangular region on the display that will
+ * receive the bit map.
+ * src - The start of the source image. This is an array source
+ * images of size CONFIG_NX_NPLANES.
+ * origin - The origin of the upper, left-most corner of the full bitmap.
+ * Both dest and origin are in window coordinates, however, origin
+ * may lie outside of the display.
+ * stride - The width of the full source image in bytes.
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+static int nxtool_bitmap(FAR struct nxcon_state_s *priv,
+ FAR const struct nxgl_rect_s *dest,
+ FAR const void *src[CONFIG_NX_NPLANES],
+ FAR const struct nxgl_point_s *origin,
+ unsigned int stride)
+{
+ return nxtk_bitmaptoolbar((NXTKWINDOW)priv->handle, dest, src, origin, stride);
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxtool_register
+ *
+ * Description:
+ * Register a console device on a toolbar of a framed NX window. The
+ * device will be registered at /dev/nxtoolN where N is the provided minor
+ * number.
+ *
+ * Input Parameters:
+ * hfwnd - A handle that will be used to access the toolbar. The toolbar
+ * must persist and this handle must be valid for the life of the NX
+ * console.
+ * wndo - Describes the window and font to be used
+ * minor - The device minor number
+ *
+ * Return:
+ * A non-NULL handle is returned on success.
+ *
+ ****************************************************************************/
+
+NXCONSOLE nxtool_register(NXTKWINDOW hfwnd, FAR struct nxcon_window_s *wndo, int minor)
+{
+ return nxcon_register((NXCONSOLE)hfwnd, wndo, &g_nxtoolops, minor);
+}
+