summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-03-27 16:59:15 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-03-27 16:59:15 +0000
commit5d3e1ee2e876b618f11a16753ca1d992260089be (patch)
treece0fbf634a4a79157ec8554a02933bf935f5ce72 /apps
parent2a4b0b1d5da5d20a1145f5bcdd845c3b49cae7bd (diff)
downloadnuttx-5d3e1ee2e876b618f11a16753ca1d992260089be.tar.gz
nuttx-5d3e1ee2e876b618f11a16753ca1d992260089be.tar.bz2
nuttx-5d3e1ee2e876b618f11a16753ca1d992260089be.zip
Add a test for the NX console device
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4528 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps')
-rwxr-xr-xapps/ChangeLog.txt1
-rw-r--r--apps/examples/Makefile8
-rw-r--r--apps/examples/README.txt65
-rw-r--r--apps/examples/nxconsole/Makefile109
-rw-r--r--apps/examples/nxconsole/nxcon_internal.h239
-rw-r--r--apps/examples/nxconsole/nxcon_main.c506
-rw-r--r--apps/examples/nxconsole/nxcon_server.c193
-rw-r--r--apps/examples/nxconsole/nxcon_toolbar.c162
-rw-r--r--apps/examples/nxconsole/nxcon_wndo.c194
9 files changed, 1473 insertions, 4 deletions
diff --git a/apps/ChangeLog.txt b/apps/ChangeLog.txt
index 1fd91b3a2..feb80dcb4 100755
--- a/apps/ChangeLog.txt
+++ b/apps/ChangeLog.txt
@@ -212,3 +212,4 @@
built-int functions.
* vsn/hello: Removed. The modified apps/examples/hello is enough "Hello,
World!"
+ * apps/examples/nxconsole: Add a test of the NX console device.
diff --git a/apps/examples/Makefile b/apps/examples/Makefile
index 4cf2a700d..c1da00628 100644
--- a/apps/examples/Makefile
+++ b/apps/examples/Makefile
@@ -38,9 +38,9 @@
# Sub-directories
SUBDIRS = adc buttons can cdcacm composite dhcpd ftpc ftpd hello helloxx \
- hidkbd igmp lcdrw mm mount nettest nsh null nx nxffs nxflat nxhello \
- nximage nxlines nxtext ostest pashello pipe poll pwm qencoder rgmp \
- romfs serloop telnetd thttpd tiff touchscreen udp uip usbserial \
+ hidkbd igmp lcdrw mm mount nettest nsh null nx nxconsole nxffs nxflat \
+ nxhello nximage nxlines nxtext ostest pashello pipe poll pwm qencoder \
+ rgmp romfs serloop telnetd thttpd tiff touchscreen udp uip usbserial \
sendmail usbstorage usbterm wget wlan
# Sub-directories that might need context setup. Directories may need
@@ -56,7 +56,7 @@ SUBDIRS = adc buttons can cdcacm composite dhcpd ftpc ftpd hello helloxx \
CNTXTDIRS = pwm
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
-CNTXTDIRS += adc can cdcacm composite ftpd dhcpd nettest qencoder telnetd
+CNTXTDIRS += adc can cdcacm composite ftpd dhcpd nettest nxconsole qencoder telnetd
endif
ifeq ($(CONFIG_EXAMPLES_HELLO_BUILTIN),y)
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index b037b9501..f7b6d74e7 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -614,6 +614,71 @@ examples/nx
CONFIG_DISABLE_PTHREAD=n
CONFIG_NX_BLOCKING=y
+examples/nxconsole
+^^^^^^^^^^^^^^^^^^
+
+ This directory contains a simple test of the NX console device defined in
+ include/nuttx/nx/nxconsole.h. The following configuration options
+ can be selected:
+
+ CONFIG_NSH_BUILTIN_APPS -- Build the NX example as a "built-in"
+ that can be executed from the NSH command line
+ CONFIG_EXAMPLES_NXCON_VPLANE -- The plane to select from the frame-
+ buffer driver for use in the test. Default: 0
+ CONFIG_EXAMPLES_NXCON_DEVNO - The LCD device to select from the LCD
+ driver for use in the test: Default: 0
+ CONFIG_EXAMPLES_NXCON_BGCOLOR -- The color of the background. Default depends on
+ CONFIG_EXAMPLES_NXCON_BPP.
+ CONFIG_EXAMPLES_NXCON_WCOLOR -- The color of the window. Default depends on
+ CONFIG_EXAMPLES_NXCON_BPP.
+ CONFIG_EXAMPLES_NXCON_FONTID - Selects the font (see font ID numbers in
+ include/nuttx/nx/nxfonts.h)
+ CONFIG_EXAMPLES_NXCON_FONTCOLOR -- The color of the fonts. Default depends on
+ CONFIG_EXAMPLES_NXCON_BPP.
+ CONFIG_EXAMPLES_NXCON_BPP -- Pixels per pixel to use. Valid options
+ include 2, 4, 8, 16, 24, and 32. Default is 32.
+ CONFIG_EXAMPLES_NXCON_TOOLBAR_HEIGHT -- The height of the toolbar.
+ Default: 16
+ CONFIG_EXAMPLES_NXCON_EXTERNINIT - The driver for the graphics device on
+ this platform requires some unusual initialization. This is the
+ for, for example, SPI LCD/OLED devices. If this configuration is
+ selected, then the platform code must provide an LCD initialization
+ function with a prototype like:
+
+ #ifdef CONFIG_NX_LCDDRIVER
+ FAR struct lcd_dev_s *up_nxdrvinit(unsigned int devno);
+ #else
+ FAR struct fb_vtable_s *up_nxdrvinit(unsigned int devno);
+ #endif
+
+ CONFIG_EXAMPLES_NXCON_MINOR -- The NX console device minor number.
+ Default is 0 corresponding to /dev/nxcon0
+ CONFIG_EXAMPLES_NXCON_DEVNAME -- The quoated, full path to the
+ NX console device corresponding to CONFIG_EXAMPLES_NXCON_MINOR.
+ Default: "/dev/nxcon0"
+
+ This test can be performed with either the single-user version of
+ NX or with the multiple user version of NX selected with CONFIG_NX_MULTIUSER.
+ If CONFIG_NX_MULTIUSER is defined, then the following configuration
+ options also apply:
+
+ CONFIG_EXAMPLES_NXCON_STACKSIZE -- The stacksize to use when creating
+ the NX server. Default 2048
+ CONFIG_EXAMPLES_NXCON_CLIENTPRIO -- The client priority. Default: 100
+ CONFIG_EXAMPLES_NXCON_SERVERPRIO -- The server priority. Default: 120
+ CONFIG_EXAMPLES_NXCON_LISTENERPRIO -- The priority of the event listener
+ thread. Default 80.
+ CONFIG_EXAMPLES_NXCON_NOTIFYSIGNO -- The signal number to use with
+ nx_eventnotify(). Default: 4
+
+ If CONFIG_NX_MULTIUSER is defined, then the example also expects the
+ following settings and will generate an error if they are not as expected:
+
+ CONFIG_DISABLE_MQUEUE=n
+ CONFIG_DISABLE_SIGNALS=n
+ CONFIG_DISABLE_PTHREAD=n
+ CONFIG_NX_BLOCKING=y
+
examples/nxffs
^^^^^^^^^^^^^^
diff --git a/apps/examples/nxconsole/Makefile b/apps/examples/nxconsole/Makefile
new file mode 100644
index 000000000..0816fc96e
--- /dev/null
+++ b/apps/examples/nxconsole/Makefile
@@ -0,0 +1,109 @@
+############################################################################
+# apps/examples/nxconsole/Makefile
+#
+# Copyright (C) 2011 Gregory Nutt. All rights reserved.
+# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+#
+# 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.
+#
+############################################################################
+
+-include $(TOPDIR)/.config
+-include $(TOPDIR)/Make.defs
+include $(APPDIR)/Make.defs
+
+# NuttX NX Console Example.
+
+ASRCS =
+CSRCS = nxcon_main.c nxcon_toolbar.c nxcon_wndo.c
+
+ifeq ($(CONFIG_NX_MULTIUSER),y)
+CSRCS += nxcon_server.c
+endif
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+
+ifeq ($(WINTOOL),y)
+ BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+else
+ BIN = "$(APPDIR)/libapps$(LIBEXT)"
+endif
+
+ROOTDEPPATH = --dep-path .
+
+# NxConsole built-in application info
+
+APPNAME = nxcon
+PRIORITY = SCHED_PRIORITY_DEFAULT
+STACKSIZE = 2048
+
+# Common build
+
+VPATH =
+
+all: .built
+.PHONY: context clean depend distclean
+
+$(AOBJS): %$(OBJEXT): %.S
+ $(call ASSEMBLE, $<, $@)
+
+$(COBJS): %$(OBJEXT): %.c
+ $(call COMPILE, $<, $@)
+
+.built: $(OBJS)
+ @( for obj in $(OBJS) ; do \
+ $(call ARCHIVE, $(BIN), $${obj}); \
+ done ; )
+ @touch .built
+
+.context:
+ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
+ $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
+ @touch $@
+endif
+
+context: .context
+
+.depend: Makefile $(SRCS)
+ @$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @touch $@
+
+depend: .depend
+
+clean:
+ @rm -f *.o *~ .*.swp .built
+ $(call CLEAN)
+
+distclean: clean
+ @rm -f Make.dep .depend
+
+-include Make.dep
diff --git a/apps/examples/nxconsole/nxcon_internal.h b/apps/examples/nxconsole/nxcon_internal.h
new file mode 100644
index 000000000..a4bcd851b
--- /dev/null
+++ b/apps/examples/nxconsole/nxcon_internal.h
@@ -0,0 +1,239 @@
+/****************************************************************************
+ * examples/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 __EXAMPLES_NXCONSOLE_NXCON_INTERNAL_H
+#define __EXAMPLES_NXCONSOLE_NXCON_INTERNAL_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <semaphore.h>
+
+#include <nuttx/nx/nx.h>
+#include <nuttx/nx/nxglib.h>
+#include <nuttx/nx/nxtk.h>
+#include <nuttx/nx/nxconsole.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* Configuration ************************************************************/
+
+#ifndef CONFIG_NX
+# error "NX is not enabled (CONFIG_NX)"
+#endif
+
+/* If not specified, assume that the hardware supports one video plane */
+
+#if CONFIG_NX_NPLANES != 1
+# error "Only CONFIG_NX_NPLANES==1 supported"
+#endif
+
+#ifndef CONFIG_EXAMPLES_NXCON_VPLANE
+# define CONFIG_EXAMPLES_NXCON_VPLANE 0
+#endif
+
+#ifndef CONFIG_EXAMPLES_NXCON_BPP
+# define CONFIG_EXAMPLES_NXCON_BPP 32
+#endif
+
+/* Background color */
+
+#ifndef CONFIG_EXAMPLES_NXCON_BGCOLOR
+# if CONFIG_EXAMPLES_NXCON_BPP == 24 || CONFIG_EXAMPLES_NXCON_BPP == 32
+# define CONFIG_EXAMPLES_NXCON_BGCOLOR 0x007b68ee
+# elif CONFIG_EXAMPLES_NXCON_BPP == 16
+# define CONFIG_EXAMPLES_NXCON_BGCOLOR 0x7b5d
+# else
+# define CONFIG_EXAMPLES_NXCON_BGCOLOR ' '
+# endif
+#endif
+
+/* Window color */
+
+#ifndef CONFIG_EXAMPLES_NXCON_WCOLOR
+# if CONFIG_EXAMPLES_NXCON_BPP == 24 || CONFIG_EXAMPLES_NXCON_BPP == 32
+# define CONFIG_EXAMPLES_NXCON_WCOLOR 0x007b68ee
+# elif CONFIG_EXAMPLES_NXCON_BPP == 16
+# define CONFIG_EXAMPLES_NXCON_WCOLOR 0x7b5d
+# else
+# define CONFIG_EXAMPLES_NXCON_WCOLOR ' '
+# endif
+#endif
+
+/* Font ID */
+
+#ifndef CONFIG_EXAMPLES_NXCON_FONTID
+# define CONFIG_EXAMPLES_NXCON_FONTID NXFONT_DEFAULT
+#endif
+
+/* Font color */
+
+#ifndef CONFIG_EXAMPLES_NXCON_FONTCOLOR
+# if CONFIG_EXAMPLES_NXCON_BPP == 24 || CONFIG_EXAMPLES_NXCON_BPP == 32
+# define CONFIG_EXAMPLES_NXCON_FONTCOLOR 0x00000000
+# elif CONFIG_EXAMPLES_NXCON_BPP == 16
+# define CONFIG_EXAMPLES_NXCON_FONTCOLOR 0x0000
+# else
+# define CONFIG_EXAMPLES_NXCON_FONTCOLOR 'F'
+# endif
+#endif
+
+/* Height of the toolbar */
+
+#ifndef CONFIG_EXAMPLES_NXCON_TOOLBAR_HEIGHT
+# define CONFIG_EXAMPLES_NXCON_TOOLBAR_HEIGHT 16
+#endif
+
+/* Multi-user NX support */
+
+#ifdef CONFIG_NX_MULTIUSER
+# ifdef CONFIG_DISABLE_MQUEUE
+# error "The multi-threaded example requires MQ support (CONFIG_DISABLE_MQUEUE=n)"
+# endif
+# ifdef CONFIG_DISABLE_SIGNALS
+# error "This example requires signal support (CONFIG_DISABLE_SIGNALS=n)"
+# endif
+# ifdef CONFIG_DISABLE_PTHREAD
+# error "This example requires pthread support (CONFIG_DISABLE_PTHREAD=n)"
+# endif
+# ifndef CONFIG_NX_BLOCKING
+# error "This example depends on CONFIG_NX_BLOCKING"
+# endif
+# ifndef CONFIG_EXAMPLES_NXCON_STACKSIZE
+# define CONFIG_EXAMPLES_NXCON_STACKSIZE 2048
+# endif
+# ifndef CONFIG_EXAMPLES_NXCON_LISTENERPRIO
+# define CONFIG_EXAMPLES_NXCON_LISTENERPRIO 100
+# endif
+# ifndef CONFIG_EXAMPLES_NXCON_CLIENTPRIO
+# define CONFIG_EXAMPLES_NXCON_CLIENTPRIO 100
+# endif
+# ifndef CONFIG_EXAMPLES_NXCON_SERVERPRIO
+# define CONFIG_EXAMPLES_NXCON_SERVERPRIO 120
+# endif
+# ifndef CONFIG_EXAMPLES_NXCON_NOTIFYSIGNO
+# define CONFIG_EXAMPLES_NXCON_NOTIFYSIGNO 4
+# endif
+#endif
+
+/* NX Console Device */
+
+#ifndef CONFIG_EXAMPLES_NXCON_MINOR
+# define CONFIG_EXAMPLES_NXCON_MINOR 0
+#endif
+
+#ifndef CONFIG_EXAMPLES_NXCON_DEVNAME
+# define CONFIG_EXAMPLES_NXCON_DEVNAME "/dev/nxcon0"
+#endif
+
+/* Debug ********************************************************************/
+
+#ifdef CONFIG_CPP_HAVE_VARARGS
+# ifdef CONFIG_DEBUG
+# define message(...) lib_lowprintf(__VA_ARGS__)
+# define msgflush()
+# else
+# define message(...) printf(__VA_ARGS__)
+# define msgflush() fflush(stdout)
+# endif
+#else
+# ifdef CONFIG_DEBUG
+# define message lib_lowprintf
+# define msgflush()
+# else
+# define message printf
+# define msgflush() fflush(stdout)
+# endif
+#endif
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* All example global variables are retained in a structure to minimize
+ * the chance of name collisions.
+ */
+
+struct nxcon_state_s
+{
+ volatile bool haveres; /* True: Have screen resolution */
+#ifdef CONFIG_NX_MULTIUSER
+ bool connected; /* True: Connected to server */
+#endif
+ sem_t eventsem; /* Control waiting for display events */
+ NXHANDLE hnx; /* The connection handler */
+ NXTKWINDOW hwnd; /* The window */
+ NXCONSOLE hdrvr; /* The console driver */
+ FAR struct nxcon_window_s wndo; /* Describes the window */
+ nxgl_coord_t xres; /* Screen X resolution */
+ nxgl_coord_t yres; /* Screen Y resolution */
+ struct nxgl_size_s wsize; /* Window size */
+ struct nxgl_point_s wpos; /* Window position */
+};
+
+/****************************************************************************
+ * Public Variables
+ ****************************************************************************/
+/* All example global variables are retained in a structure to minimize
+ * the chance of name collisions.
+ */
+
+extern struct nxcon_state_s g_nxcon_vars;
+
+/* NX callback vtables */
+
+extern const struct nx_callback_s g_nxconcb;
+extern const struct nx_callback_s g_nxtoolcb;
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef CONFIG_EXAMPLES_NXCON_EXTERNINIT
+extern FAR NX_DRIVERTYPE *up_nxdrvinit(unsigned int devno);
+#endif
+#if defined(CONFIG_NX) && defined(CONFIG_NX_MULTIUSER)
+extern int nxcon_server(int argc, char *argv[]);
+extern FAR void *nxcon_listener(FAR void *arg);
+#endif
+
+#endif /* __EXAMPLES_NXCONSOLE_NXCON_INTERNAL_H */
diff --git a/apps/examples/nxconsole/nxcon_main.c b/apps/examples/nxconsole/nxcon_main.c
new file mode 100644
index 000000000..cc83aac16
--- /dev/null
+++ b/apps/examples/nxconsole/nxcon_main.c
@@ -0,0 +1,506 @@
+/****************************************************************************
+ * examples/nxconsole/nxcon_main.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 <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <debug.h>
+
+#ifdef CONFIG_NX_LCDDRIVER
+# include <nuttx/lcd/lcd.h>
+#else
+# include <nuttx/fb.h>
+#endif
+
+#include <nuttx/arch.h>
+#include <nuttx/nx/nx.h>
+#include <nuttx/nx/nxglib.h>
+#include <nuttx/nx/nxfonts.h>
+#include <nuttx/nx/nxconsole.h>
+
+#include "nxcon_internal.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define NCON_MSG_NLINES 24
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_NX_KBD
+static const uint8_t g_pumsg[] = "Pop-Up!";
+static const char *g_nxcon_msg[NCON_MSG_NLINES] =
+{
+ "\nJULIET\n", /* Line 1 */
+ "Wilt thou be gone?\n", /* Line 2 */
+ " It is not yet near day:\n", /* Line 3 */
+ "It was the nightingale,\n", /* Line 4 */
+ " and not the lark,\n", /* Line 5 */
+ "That pierced the fearful hollow\n", /* Line 6 */
+ " of thine ear;\n", /* Line 7 */
+ "Nightly she sings\n", /* Line 8 */
+ " on yon pomegranate-tree:\n", /* Line 9 */
+ "Believe me, love,\n", /* Line 10 */
+ " it was the nightingale.\n", /* Line 11 */
+ "\nROMEO\n", /* Line 12 */
+ "It was the lark,\n", /* Line 13 */
+ " the herald of the morn,\n", /* Line 14 */
+ "No nightingale:\n", /* Line 15 */
+ " look, love, what envious streaks\n", /* Line 16 */
+ "Do lace the severing clouds\n", /* Line 17 */
+ " in yonder east:\n", /* Line 18 */
+ "Night's candles are burnt out,\n", /* Line 19 */
+ " and jocund day\n", /* Line 20 */
+ "Stands tiptoe\n", /* Line 21 */
+ " on the misty mountain tops.\n", /* Line 22 */
+ "I must be gone and live,\n", /* Line 23 */
+ " or stay and die.\n" /* Line 24 */
+};
+#endif
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* All example global variables are retained in a structure to minimize
+ * the chance of name collisions.
+ */
+
+struct nxcon_state_s g_nxcon_vars;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxcon_suinitialize
+ ****************************************************************************/
+
+#ifndef CONFIG_NX_MULTIUSER
+static inline int nxcon_suinitialize(void)
+{
+ FAR NX_DRIVERTYPE *dev;
+
+#if defined(CONFIG_EXAMPLES_NXCON_EXTERNINIT)
+ /* Use external graphics driver initialization */
+
+ message("nxcon_initialize: Initializing external graphics device\n");
+ dev = up_nxdrvinit(CONFIG_EXAMPLES_NXCON_DEVNO);
+ if (!dev)
+ {
+ message("nxcon_initialize: up_nxdrvinit failed, devno=%d\n", CONFIG_EXAMPLES_NXCON_DEVNO);
+ return ERROR;
+ }
+
+#elif defined(CONFIG_NX_LCDDRIVER)
+ int ret;
+
+ /* Initialize the LCD device */
+
+ message("nxcon_initialize: Initializing LCD\n");
+ ret = up_lcdinitialize();
+ if (ret < 0)
+ {
+ message("nxcon_initialize: up_lcdinitialize failed: %d\n", -ret);
+ return ERROR;
+ }
+
+ /* Get the device instance */
+
+ dev = up_lcdgetdev(CONFIG_EXAMPLES_NXCON_DEVNO);
+ if (!dev)
+ {
+ message("nxcon_initialize: up_lcdgetdev failed, devno=%d\n",
+ CONFIG_EXAMPLES_NXCON_DEVNO);
+ return ERROR;
+ }
+
+ /* Turn the LCD on at 75% power */
+
+ (void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
+#else
+ int ret;
+
+ /* Initialize the frame buffer device */
+
+ message("nxcon_initialize: Initializing framebuffer\n");
+ ret = up_fbinitialize();
+ if (ret < 0)
+ {
+ message("nxcon_initialize: up_fbinitialize failed: %d\n", -ret);
+ return ERROR;
+ }
+
+ dev = up_fbgetvplane(CONFIG_EXAMPLES_NXCON_VPLANE);
+ if (!dev)
+ {
+ message("nxcon_initialize: up_fbgetvplane failed, vplane=%d\n", CONFIG_EXAMPLES_NXCON_VPLANE);
+ return ERROR;
+ }
+#endif
+
+ /* Then open NX */
+
+ message("nxcon_initialize: Open NX\n");
+ g_nxcon_vars.hnx = nx_open(dev);
+ if (!g_nxcon_vars.hnx)
+ {
+ message("nxcon_initialize: nx_open failed: %d\n", errno);
+ return ERROR;
+ }
+ return OK;
+}
+#endif
+
+/****************************************************************************
+ * Name: nxcon_initialize
+ ****************************************************************************/
+
+#ifdef CONFIG_NX_MULTIUSER
+static inline int nxcon_muinitialize(void)
+{
+ struct sched_param param;
+ pthread_t thread;
+ pid_t servrid;
+ int ret;
+
+ /* Set the client task priority */
+
+ param.sched_priority = CONFIG_EXAMPLES_NXCON_CLIENTPRIO;
+ ret = sched_setparam(0, &param);
+ if (ret < 0)
+ {
+ message("nxcon_initialize: sched_setparam failed: %d\n" , ret);
+ return ERROR;
+ }
+
+ /* Start the server task */
+
+ message("nxcon_initialize: Starting nxcon_server task\n");
+ servrid = task_create("NX Server", CONFIG_EXAMPLES_NXCON_SERVERPRIO,
+ CONFIG_EXAMPLES_NXCON_STACKSIZE, nxcon_server, NULL);
+ if (servrid < 0)
+ {
+ message("nxcon_initialize: Failed to create nxcon_server task: %d\n", errno);
+ return ERROR;
+ }
+
+ /* Wait a bit to let the server get started */
+
+ sleep(1);
+
+ /* Connect to the server */
+
+ g_nxcon_vars.hnx = nx_connect();
+ if (g_nxcon_vars.hnx)
+ {
+ pthread_attr_t attr;
+
+ /* Start a separate thread to listen for server events. This is probably
+ * the least efficient way to do this, but it makes this example flow more
+ * smoothly.
+ */
+
+ (void)pthread_attr_init(&attr);
+ param.sched_priority = CONFIG_EXAMPLES_NXCON_LISTENERPRIO;
+ (void)pthread_attr_setschedparam(&attr, &param);
+ (void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NXCON_STACKSIZE);
+
+ ret = pthread_create(&thread, &attr, nxcon_listener, NULL);
+ if (ret != 0)
+ {
+ printf("nxcon_initialize: pthread_create failed: %d\n", ret);
+ return ERROR;
+ }
+
+ /* Don't return until we are connected to the server */
+
+ while (!g_nxcon_vars.connected)
+ {
+ /* Wait for the listener thread to wake us up when we really
+ * are connected.
+ */
+
+ (void)sem_wait(&g_nxcon_vars.eventsem);
+ }
+ }
+ else
+ {
+ message("nxcon_initialize: nx_connect failed: %d\n", errno);
+ return ERROR;
+ }
+ return OK;
+}
+#endif
+
+/****************************************************************************
+ * Name: nxcon_initialize
+ ****************************************************************************/
+
+static int nxcon_initialize(void)
+{
+#ifdef CONFIG_NX_MULTIUSER
+ return nxcon_muinitialize();
+#else
+ return nxcon_suinitialize();
+#endif
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: user_start/nxcon_main
+ ****************************************************************************/
+
+#ifdef CONFIG_NSH_BUILTIN_APPS
+# define MAIN_NAME nxcon_main
+# define MAIN_NAME_STRING "nxcon_main"
+#else
+# define MAIN_NAME user_start
+# define MAIN_NAME_STRING "user_start"
+#endif
+
+int MAIN_NAME(int argc, char **argv)
+{
+ int exitcode = EXIT_FAILURE;
+ nxgl_mxpixel_t color;
+ int ndx;
+ int ret;
+ int fd;
+
+ /* Reset all global data */
+
+ memset(&g_nxcon_vars, 0, sizeof(struct nxcon_state_s));
+
+ /* NX Initialization ******************************************************/
+ /* Initialize NX */
+
+ ret = nxcon_initialize();
+ message(MAIN_NAME_STRING ": NX handle=%p\n", g_nxcon_vars.hnx);
+ if (!g_nxcon_vars.hnx || ret < 0)
+ {
+ message(MAIN_NAME_STRING ": Failed to get NX handle: %d\n", errno);
+ goto errout;
+ }
+
+ /* Set the background to the configured background color */
+
+ message(MAIN_NAME_STRING ": Set background color=%d\n", CONFIG_EXAMPLES_NXCON_BGCOLOR);
+ color = CONFIG_EXAMPLES_NXCON_BGCOLOR;
+ ret = nx_setbgcolor(g_nxcon_vars.hnx, &color);
+ if (ret < 0)
+ {
+ message(MAIN_NAME_STRING ": nx_setbgcolor failed: %d\n", errno);
+ goto errout_with_nx;
+ }
+
+ /* Window Configuration ***************************************************/
+ /* Create a window */
+
+ message(MAIN_NAME_STRING ": Create window\n");
+ g_nxcon_vars.hwnd = nxtk_openwindow(&g_nxcon_vars.hnx, &g_nxconcb, NULL);
+ if (!g_nxcon_vars.hwnd)
+ {
+ message(MAIN_NAME_STRING ": nxtk_openwindow failed: %d\n", errno);
+ goto errout_with_nx;
+ }
+ message(MAIN_NAME_STRING ": hwnd=%p\n", g_nxcon_vars.hwnd);
+
+ /* Wait until we have the screen resolution. We'll have this immediately
+ * unless we are dealing with the NX server.
+ */
+
+ while (!g_nxcon_vars.haveres)
+ {
+ (void)sem_wait(&g_nxcon_vars.eventsem);
+ }
+ message(MAIN_NAME_STRING ": Screen resolution (%d,%d)\n", g_nxcon_vars.xres, g_nxcon_vars.yres);
+
+ /* Determine the size and position of the window */
+
+ g_nxcon_vars.wndo.wsize.w = g_nxcon_vars.xres / 2 + g_nxcon_vars.xres / 4;
+ g_nxcon_vars.wndo.wsize.h = g_nxcon_vars.yres / 2 + g_nxcon_vars.yres / 4;
+
+ g_nxcon_vars.wpos.x = g_nxcon_vars.xres / 8;
+ g_nxcon_vars.wpos.y = g_nxcon_vars.yres / 8;
+
+ /* Set the window position */
+
+ message(MAIN_NAME_STRING ": Set window position to (%d,%d)\n",
+ g_nxcon_vars.wpos.x, g_nxcon_vars.wpos.y);
+
+ ret = nxtk_setposition(g_nxcon_vars.hwnd, &g_nxcon_vars.wpos);
+ if (ret < 0)
+ {
+ message(MAIN_NAME_STRING ": nxtk_setposition failed: %d\n", errno);
+ goto errout_with_hwnd;
+ }
+
+ /* Set the window size */
+
+ message(MAIN_NAME_STRING ": Set window size to (%d,%d)\n",
+ g_nxcon_vars.wndo.wsize.w, g_nxcon_vars.wndo.wsize.h);
+
+ ret = nxtk_setsize(g_nxcon_vars.hwnd, &g_nxcon_vars.wndo.wsize);
+ if (ret < 0)
+ {
+ message(MAIN_NAME_STRING ": nxtk_setsize failed: %d\n", errno);
+ goto errout_with_hwnd;
+ }
+
+ /* Open the toolbar */
+
+ message(MAIN_NAME_STRING ": Add toolbar to window\n");
+ ret = nxtk_opentoolbar(g_nxcon_vars.hwnd, CONFIG_EXAMPLES_NXCON_TOOLBAR_HEIGHT, &g_nxtoolcb, NULL);
+ if (ret < 0)
+ {
+ message(MAIN_NAME_STRING ": nxtk_opentoolbar failed: %d\n", errno);
+ goto errout_with_hwnd;
+ }
+
+ /* NxConsole Configuration ************************************************/
+ /* Use the window to create an NX console */
+
+ g_nxcon_vars.wndo.wcolor[0] = CONFIG_EXAMPLES_NXCON_WCOLOR;
+ g_nxcon_vars.wndo.fcolor[0] = CONFIG_EXAMPLES_NXCON_FONTCOLOR;
+ g_nxcon_vars.wndo.fontid = CONFIG_EXAMPLES_NXCON_FONTID;
+
+ g_nxcon_vars.hdrvr = nxtk_register(g_nxcon_vars.hwnd, &g_nxcon_vars.wndo, CONFIG_EXAMPLES_NXCON_MINOR);
+ if (!g_nxcon_vars.hdrvr)
+ {
+ message(MAIN_NAME_STRING ": nxtk_register failed: %d\n", errno);
+ goto errout_with_hwnd;
+ }
+
+ /* Open the driver */
+
+ fd = open(CONFIG_EXAMPLES_NXCON_DEVNAME, O_RDONLY);
+ if (fd < 0)
+ {
+ message(MAIN_NAME_STRING ": open %d read-only failed: %d\n",
+ CONFIG_EXAMPLES_NXCON_DEVNAME, errno);
+ goto errout_with_driver;
+ }
+
+ /* Now re-direct stdout and stderr so that they use the NX console driver */
+
+ (void)dup2(fd, 1);
+ (void)dup2(fd, 2);
+
+ /* And we can close our original driver fd */
+
+ close(fd);
+
+ /* Test Loop **************************************************************/
+ /* Now loop, adding text to the NX console */
+
+ ndx = 0;
+ for (;;)
+ {
+ /* Sleep for one second */
+
+ sleep(1);
+
+ /* Give another line of text to the NX console.*/
+
+ printf(g_nxcon_msg[ndx]);
+ if (++ndx >= NCON_MSG_NLINES)
+ {
+#ifdef CONFIG_NSH_BUILTIN_APPS
+ /* If this is an NSH built-in apps, then just return after all
+ * of the lines have been presented.
+ */
+
+ break;
+#else
+ /* Otherwise, just reset the index to the first line and continue */
+
+ ndx = 0;
+#endif
+ }
+ }
+ exitcode = EXIT_SUCCESS;
+
+ /* Clean-up and Error Exits ***********************************************/
+
+errout_with_driver:
+ message(MAIN_NAME_STRING ": Unregister the NX console device\n");
+ (void)nxcon_unregister(g_nxcon_vars.hdrvr);
+
+errout_with_hwnd:
+ message(MAIN_NAME_STRING ": Close the window\n");
+ (void)nxtk_closewindow(g_nxcon_vars.hwnd);
+
+errout_with_nx:
+#ifdef CONFIG_NX_MULTIUSER
+ /* Disconnect from the server */
+
+ message(MAIN_NAME_STRING ": Disconnect from the server\n");
+ nx_disconnect(g_nxcon_vars.hnx);
+#else
+ /* Close the server */
+
+ message(MAIN_NAME_STRING ": Close NX\n");
+ nx_close(g_nxcon_vars.hnx);
+#endif
+errout:
+ return exitcode;
+}
diff --git a/apps/examples/nxconsole/nxcon_server.c b/apps/examples/nxconsole/nxcon_server.c
new file mode 100644
index 000000000..661479a4a
--- /dev/null
+++ b/apps/examples/nxconsole/nxcon_server.c
@@ -0,0 +1,193 @@
+/****************************************************************************
+ * examples/nxconsole/nxcon_server.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 <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sched.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/nx/nx.h>
+
+#ifdef CONFIG_NX_LCDDRIVER
+# include <nuttx/lcd/lcd.h>
+#else
+# include <nuttx/fb.h>
+#endif
+
+#include "nxcon_internal.h"
+
+#ifdef CONFIG_NX_MULTIUSER
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxcon_server
+ ****************************************************************************/
+
+int nxcon_server(int argc, char *argv[])
+{
+ FAR NX_DRIVERTYPE *dev;
+ int ret;
+
+#if defined(CONFIG_EXAMPLES_NXCON_EXTERNINIT)
+ /* Use external graphics driver initialization */
+
+ message("nxcon_server: Initializing external graphics device\n");
+ dev = up_nxdrvinit(CONFIG_EXAMPLES_NXCON_DEVNO);
+ if (!dev)
+ {
+ message("nxcon_server: up_nxdrvinit failed, devno=%d\n", CONFIG_EXAMPLES_NXCON_DEVNO);
+ return ERROR;
+ }
+
+#elif defined(CONFIG_NX_LCDDRIVER)
+ /* Initialize the LCD device */
+
+ message("nxcon_server: Initializing LCD\n");
+ ret = up_lcdinitialize();
+ if (ret < 0)
+ {
+ message("nxcon_server: up_lcdinitialize failed: %d\n", -ret);
+ return 1;
+ }
+
+ /* Get the device instance */
+
+ dev = up_lcdgetdev(CONFIG_EXAMPLES_NXCON_DEVNO);
+ if (!dev)
+ {
+ message("nxcon_server: up_lcdgetdev failed, devno=%d\n", CONFIG_EXAMPLES_NXCON_DEVNO);
+ return 2;
+ }
+
+ /* Turn the LCD on at 75% power */
+
+ (void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
+#else
+ /* Initialize the frame buffer device */
+
+ message("nxcon_server: Initializing framebuffer\n");
+ ret = up_fbinitialize();
+ if (ret < 0)
+ {
+ message("nxcon_server: up_fbinitialize failed: %d\n", -ret);
+ return 1;
+ }
+
+ dev = up_fbgetvplane(CONFIG_EXAMPLES_NXCON_VPLANE);
+ if (!dev)
+ {
+ message("nxcon_server: up_fbgetvplane failed, vplane=%d\n", CONFIG_EXAMPLES_NXCON_VPLANE);
+ return 2;
+ }
+#endif
+
+ /* Then start the server */
+
+ ret = nx_run(dev);
+ gvdbg("nx_run returned: %d\n", errno);
+ return 3;
+}
+
+/****************************************************************************
+ * Name: nxcon_listener
+ ****************************************************************************/
+
+FAR void *nxcon_listener(FAR void *arg)
+{
+ int ret;
+
+ /* Process events forever */
+
+ for (;;)
+ {
+ /* Handle the next event. If we were configured blocking, then
+ * we will stay right here until the next event is received. Since
+ * we have dedicated a while thread to servicing events, it would
+ * be most natural to also select CONFIG_NX_BLOCKING -- if not, the
+ * following would be a tight infinite loop (unless we added addition
+ * logic with nx_eventnotify and sigwait to pace it).
+ */
+
+ ret = nx_eventhandler(g_nxcon_vars.hnx);
+ if (ret < 0)
+ {
+ /* An error occurred... assume that we have lost connection with
+ * the server.
+ */
+
+ message("nxcon_listener: Lost server connection: %d\n", errno);
+ exit(NXEXIT_LOSTSERVERCONN);
+ }
+
+ /* If we received a message, we must be connected */
+
+ if (!g_nxcon_vars.connected)
+ {
+ g_nxcon_vars.connected = true;
+ sem_post(&g_nxcon_vars.eventsem);
+ message("nxcon_listener: Connected\n");
+ }
+ }
+}
+
+#endif /* CONFIG_NX_MULTIUSER */
diff --git a/apps/examples/nxconsole/nxcon_toolbar.c b/apps/examples/nxconsole/nxcon_toolbar.c
new file mode 100644
index 000000000..38b5c1ee3
--- /dev/null
+++ b/apps/examples/nxconsole/nxcon_toolbar.c
@@ -0,0 +1,162 @@
+/****************************************************************************
+ * examples/nxconsole/nxcon_toolbar.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 <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <semaphore.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/nx/nx.h>
+#include <nuttx/nx/nxfonts.h>
+
+#include "nxcon_internal.h"
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static void nxtool_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
+ bool morem, FAR void *arg);
+static void nxtool_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
+ FAR const struct nxgl_point_s *pos,
+ FAR const struct nxgl_rect_s *bounds,
+ FAR void *arg);
+#ifdef CONFIG_NX_MOUSE
+static void nxtool_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
+ uint8_t buttons, FAR void *arg);
+#endif
+
+#ifdef CONFIG_NX_KBD
+static void nxtool_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
+ FAR void *arg);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* Background window call table */
+
+const struct nx_callback_s g_nxtoolcb =
+{
+ nxtool_redraw, /* redraw */
+ nxtool_position /* position */
+#ifdef CONFIG_NX_MOUSE
+ , nxtool_mousein /* mousein */
+#endif
+#ifdef CONFIG_NX_KBD
+ , nxtool_kbdin /* my kbdin */
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxtool_redraw
+ ****************************************************************************/
+
+static void nxtool_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
+ bool more, FAR void *arg)
+{
+ gvdbg("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
+ hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
+ more ? "true" : "false");
+}
+
+/****************************************************************************
+ * Name: nxtool_position
+ ****************************************************************************/
+
+static void nxtool_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
+ FAR const struct nxgl_point_s *pos,
+ FAR const struct nxgl_rect_s *bounds,
+ FAR void *arg)
+{
+ gvdbg("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
+ hwnd, size->w, size->h, pos->x, pos->y,
+ bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
+}
+
+/****************************************************************************
+ * Name: nxtool_mousein
+ ****************************************************************************/
+
+#ifdef CONFIG_NX_MOUSE
+static void nxtool_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
+ uint8_t buttons, FAR void *arg)
+{
+ gvdbg("hwnd=%p pos=(%d,%d) button=%02x\n", hwnd, pos->x, pos->y, buttons);
+}
+#endif
+
+/****************************************************************************
+ * Name: nxtool_kbdin
+ ****************************************************************************/
+
+#ifdef CONFIG_NX_KBD
+static void nxtool_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
+ FAR void *arg)
+{
+ gvdbg("hwnd=%p nch=%d\n", hwnd, nch);
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
diff --git a/apps/examples/nxconsole/nxcon_wndo.c b/apps/examples/nxconsole/nxcon_wndo.c
new file mode 100644
index 000000000..b052af0d2
--- /dev/null
+++ b/apps/examples/nxconsole/nxcon_wndo.c
@@ -0,0 +1,194 @@
+/****************************************************************************
+ * examples/nxconsole/nxcon_wndo.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 <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <semaphore.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/nx/nx.h>
+#include <nuttx/nx/nxfonts.h>
+
+#include "nxcon_internal.h"
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
+ bool morem, FAR void *arg);
+static void nxwndo_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
+ FAR const struct nxgl_point_s *pos,
+ FAR const struct nxgl_rect_s *bounds,
+ FAR void *arg);
+#ifdef CONFIG_NX_MOUSE
+static void nxwndo_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
+ uint8_t buttons, FAR void *arg);
+#endif
+
+#ifdef CONFIG_NX_KBD
+static void nxwndo_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
+ FAR void *arg);
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* Background window call table */
+
+const struct nx_callback_s g_nxconcb =
+{
+ nxwndo_redraw, /* redraw */
+ nxwndo_position /* position */
+#ifdef CONFIG_NX_MOUSE
+ , nxwndo_mousein /* mousein */
+#endif
+#ifdef CONFIG_NX_KBD
+ , nxwndo_kbdin /* my kbdin */
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxwndo_redraw
+ ****************************************************************************/
+
+static void nxwndo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
+ bool more, FAR void *arg)
+{
+ gvdbg("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
+ hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
+ more ? "true" : "false");
+
+ /* Inform the NX console of the redraw request */
+
+ nxcon_redraw(g_nxcon_vars.hdrvr, rect, more);
+}
+
+/****************************************************************************
+ * Name: nxwndo_position
+ ****************************************************************************/
+
+static void nxwndo_position(NXWINDOW hwnd, FAR const struct nxgl_size_s *size,
+ FAR const struct nxgl_point_s *pos,
+ FAR const struct nxgl_rect_s *bounds,
+ FAR void *arg)
+{
+ /* Report the position */
+
+ gvdbg("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
+ hwnd, size->w, size->h, pos->x, pos->y,
+ bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
+
+ /* Have we picked off the window bounds yet? */
+
+ if (!g_nxcon_vars.haveres)
+ {
+ /* Save the background window handle */
+
+ g_nxcon_vars.hwnd = hwnd;
+
+ /* Save the background window size */
+
+ g_nxcon_vars.wndo.wsize.w = size->w;
+ g_nxcon_vars.wndo.wsize.h = size->h;
+
+ /* Save the window limits (these should be the same for all places and all windows */
+
+ g_nxcon_vars.xres = bounds->pt2.x + 1;
+ g_nxcon_vars.yres = bounds->pt2.y + 1;
+
+ g_nxcon_vars.haveres = true;
+ sem_post(&g_nxcon_vars.eventsem);
+ gvdbg("Have xres=%d yres=%d\n", g_nxcon_vars.xres, g_nxcon_vars.yres);
+ }
+}
+
+/****************************************************************************
+ * Name: nxwndo_mousein
+ ****************************************************************************/
+
+#ifdef CONFIG_NX_MOUSE
+static void nxwndo_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
+ uint8_t buttons, FAR void *arg)
+{
+ gvdbg("hwnd=%p pos=(%d,%d) button=%02x\n",
+ hwnd, pos->x, pos->y, buttons);
+}
+#endif
+
+/****************************************************************************
+ * Name: nxwndo_kbdin
+ ****************************************************************************/
+
+#ifdef CONFIG_NX_KBD
+static void nxwndo_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
+ FAR void *arg)
+{
+ gvdbg("hwnd=%p nch=%d\n", hwnd, nch);
+ (void)write(1, ch, nch);
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/