summaryrefslogtreecommitdiff
path: root/NxWidgets/libnxwidgets
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-05-01 20:36:19 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-05-01 20:36:19 +0000
commitfd4dd86fe8de2ddda1e8723973e8b5774528ebb7 (patch)
tree076f03852cb6bcd7a34d313558f7529143337e6d /NxWidgets/libnxwidgets
parent990276740afafeb69f64b01050a99f113bb89fa6 (diff)
downloadnuttx-fd4dd86fe8de2ddda1e8723973e8b5774528ebb7.tar.gz
nuttx-fd4dd86fe8de2ddda1e8723973e8b5774528ebb7.tar.bz2
nuttx-fd4dd86fe8de2ddda1e8723973e8b5774528ebb7.zip
More NxWM support
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4682 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'NxWidgets/libnxwidgets')
-rw-r--r--NxWidgets/libnxwidgets/include/cnxserver.hxx20
-rw-r--r--NxWidgets/libnxwidgets/include/nxconfig.hxx44
-rw-r--r--NxWidgets/libnxwidgets/src/cnxserver.cxx89
3 files changed, 128 insertions, 25 deletions
diff --git a/NxWidgets/libnxwidgets/include/cnxserver.hxx b/NxWidgets/libnxwidgets/include/cnxserver.hxx
index 3043fd9e0..c6ca21bfc 100644
--- a/NxWidgets/libnxwidgets/include/cnxserver.hxx
+++ b/NxWidgets/libnxwidgets/include/cnxserver.hxx
@@ -44,6 +44,7 @@
#include <stdint.h>
#include <stdbool.h>
+#include <semaphore.h>
#include <nuttx/nx/nx.h>
@@ -79,21 +80,28 @@ namespace NXWidgets
class CNxServer
{
private:
-#ifndef CONFIG_NX_MULTIUSER
FAR NX_DRIVERTYPE *m_hDevice; /**< LCD/Framebuffer device handle */
-#endif
NXHANDLE m_hNxServer; /**< NX server handle */
#ifdef CONFIG_NX_MULTIUSER
- voilatile bool m_running; /**< True: The listener thread is running */
- voilatile bool m_connected; /**< True: Connected to the server */
+ volatile bool m_running; /**< True: The listener thread is running */
+ volatile bool m_connected; /**< True: Connected to the server */
volatile bool m_stop; /**< True: Waiting for the listener thread to stop */
sem_t m_connsem; /**< Wait for server connection */
#endif
static uint8_t m_nServers; /**< The number of NX server instances */
/**
- * This is the entry point of a thread that listeners for and dispatches
- * events from the NX server.
+ * NX server thread. This is the entry point into the server thread that
+ * serializes the multi-threaded accesses to the display.
+ */
+
+#ifdef CONFIG_NX_MULTIUSER
+ static int server(int argc, char *argv[]);
+#endif
+
+ /**
+ * NX listener thread. This is the entry point of a thread that listeners for and
+ * dispatches events from the NX server.
*/
#ifdef CONFIG_NX_MULTIUSER
diff --git a/NxWidgets/libnxwidgets/include/nxconfig.hxx b/NxWidgets/libnxwidgets/include/nxconfig.hxx
index 2f38c7c26..682eadb82 100644
--- a/NxWidgets/libnxwidgets/include/nxconfig.hxx
+++ b/NxWidgets/libnxwidgets/include/nxconfig.hxx
@@ -52,13 +52,20 @@
* Pre-Processor Definitions
****************************************************************************/
/* NX Configuration *********************************************************/
+/**
+ * C++ support is required
+ */
+
+#ifndef CONFIG_HAVE_CXX
+# error "C++ support is required (CONFIG_HAVE_CXX)"
+#endif
/**
* Required to enabled NX graphics support
*/
#ifndef CONFIG_NX
-# error "NX mouse/touchscreen support is required (CONFIG_NX_MOUSE)"
+# error "NX graphics support is required (CONFIG_NX)"
#endif
/**
@@ -112,7 +119,19 @@
*/
#ifndef CONFIG_NXWIDGETS_SERVERPRIO
-# define CONFIG_NXWIDGETS_SERVERPRIO 50
+# define CONFIG_NXWIDGETS_SERVERPRIO SCHED_PRIORITY_DEFAULT
+#endif
+
+#ifndef CONFIG_NXWIDGETS_CLIENTPRIO
+# define CONFIG_NXWIDGETS_CLIENTPRIO SCHED_PRIORITY_DEFAULT
+#endif
+
+/**
+ * NX server thread stack size (in multi-user mode)
+ */
+
+#ifndef CONFIG_NXWIDGETS_SERVERSTACK
+# define CONFIG_NXWIDGETS_SERVERSTACK 2048
#endif
/**
@@ -120,30 +139,35 @@
*/
#ifndef CONFIG_NXWIDGETS_LISTENERPRIO
-# define CONFIG_NXWIDGETS_LISTENERPRIO 50
+# define CONFIG_NXWIDGETS_LISTENERPRIO SCHED_PRIORITY_DEFAULT
#endif
/**
- * NX server/listener thread stack size (in multi-user mode)
+ * NX listener thread stack size (in multi-user mode)
*/
-#ifndef CONFIG_NXWIDGETS_STACKSIZE
-# define CONFIG_NXWIDGETS_STACKSIZE 4096
+#ifndef CONFIG_NXWIDGETS_LISTENERSTACK
+# define CONFIG_NXWIDGETS_LISTENERSTACK 2048
#endif
/* NXWidget Configuration ***************************************************/
-/* NX Server/Device Configuration
+/**
+ * NX Server/Device Configuration
*
* CONFIG_NXWIDGETS_DEVNO - LCD device number (in case there are more than
* one LCDs connected. Default: 0
* CONFIG_NXWIDGETS_VPLANE - Only a single video plane is supported. Default: 0
* CONFIG_NXWIDGETS_SERVERPRIO - Priority of the NX server (in multi-user mode).
* Default: 50
- * CONFIG_NXWIDGETS_SERVERPRIO
+ * CONFIG_NXWIDGETS_CLIENTPRIO
* CONFIG_NXWIDGETS_LISTENERPRIO - Priority of the NX event listener thread (in
* multi-user mode). Default: 50
- * CONFIG_NXWIDGETS_STACKSIZE - Priority of the NX server/listener thread
- * stack size (in multi-user mode). Default: 4096
+ * CONFIG_NXWIDGETS_EXTERNINIT - Define to support external display
+ * initialization.
+ * CONFIG_NXWIDGETS_SERVERSTACK - NX server thread stack size (in multi-user
+ * mode). Default 2048
+ * CONFIG_NXWIDGETS_LISTENERSTACK - NX listener thread stack size (in multi-user
+ * mode). Default 2048
*
* NXWidget Configuration
*
diff --git a/NxWidgets/libnxwidgets/src/cnxserver.cxx b/NxWidgets/libnxwidgets/src/cnxserver.cxx
index ef71deb44..69b1c5c4e 100644
--- a/NxWidgets/libnxwidgets/src/cnxserver.cxx
+++ b/NxWidgets/libnxwidgets/src/cnxserver.cxx
@@ -42,6 +42,8 @@
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
+#include <unistd.h>
+#include <cstdlib>
#include <cerrno>
#include <debug.h>
@@ -212,12 +214,12 @@ bool CNxServer::connect(void)
// Start the server task
- message("NxServer::connect: Starting nx_servertask task\n");
+ gvdbg("NxServer::connect: Starting server task\n");
serverId = task_create("NX Server", CONFIG_NXWIDGETS_SERVERPRIO,
- CONFIG_NXWIDGETS_STACKSIZE, nx_servertask, NULL);
+ CONFIG_NXWIDGETS_SERVERSTACK, server, (FAR const char **)0);
if (serverId < 0)
{
- message("NxServer::connect: Failed to create nx_servertask task: %d\n", errno);
+ gdbg("NxServer::connect: Failed to create nx_servertask task: %d\n", errno);
return false;
}
@@ -239,7 +241,7 @@ bool CNxServer::connect(void)
(void)pthread_attr_init(&attr);
param.sched_priority = CONFIG_NXWIDGETS_LISTENERPRIO;
(void)pthread_attr_setschedparam(&attr, &param);
- (void)pthread_attr_setstacksize(&attr, CONFIG_NXWIDGETS_STACKSIZE);
+ (void)pthread_attr_setstacksize(&attr, CONFIG_NXWIDGETS_LISTENERSTACK);
m_stop = false;
m_running = true;
@@ -247,7 +249,7 @@ bool CNxServer::connect(void)
ret = pthread_create(&thread, &attr, listener, (FAR void *)this);
if (ret != 0)
{
- printf("NxServer::connect: pthread_create failed: %d\n", ret);
+ gdbg("NxServer::connect: pthread_create failed: %d\n", ret);
m_running = false;
disconnect();
return false;
@@ -266,7 +268,7 @@ bool CNxServer::connect(void)
// In the successful case, the listener is still running (m_running)
// and the server is connected (m_connected). Anything else is a failure.
- if (!m_connected !! !m_running)
+ if (!m_connected || !m_running)
{
disconnect();
return false;
@@ -333,6 +335,75 @@ void CNxServer::disconnect(void)
#endif
/**
+ * NX server thread. This is the entry point into the server thread that
+ * serializes the multi-threaded accesses to the display.
+ */
+
+#ifdef CONFIG_NX_MULTIUSER
+int CNxServer::server(int argc, char *argv[])
+{
+ FAR NX_DRIVERTYPE *dev;
+ int ret;
+
+#if defined(CONFIG_NXWIDGETS_EXTERNINIT)
+ /* Use external graphics driver initialization */
+
+ dev = up_nxdrvinit(CONFIG_NXWIDGETS_DEVNO);
+ if (!dev)
+ {
+ gdbg("up_nxdrvinit failed, devno=%d\n", CONFIG_NXWIDGETS_DEVNO);
+ return EXIT_FAILURE;
+ }
+
+#elif defined(CONFIG_NX_LCDDRIVER)
+ /* Initialize the LCD device */
+
+ ret = up_lcdinitialize();
+ if (ret < 0)
+ {
+ gdbg("up_lcdinitialize failed: %d\n", -ret);
+ return EXIT_FAILURE;
+ }
+
+ /* Get the device instance */
+
+ dev = up_lcdgetdev(CONFIG_NXWIDGETS_DEVNO);
+ if (!dev)
+ {
+ gdbg("up_lcdgetdev failed, devno=%d\n", CONFIG_NXWIDGETS_DEVNO);
+ return EXIT_FAILURE;
+ }
+
+ /* Turn the LCD on at 75% power */
+
+ (void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
+#else
+ /* Initialize the frame buffer device */
+
+ ret = up_fbinitialize();
+ if (ret < 0)
+ {
+ gdbg("nxcon_server: up_fbinitialize failed: %d\n", -ret);
+ return EXIT_FAILURE;
+ }
+
+ dev = up_fbgetvplane(CONFIG_NXWIDGETS_VPLANE);
+ if (!dev)
+ {
+ gdbg("up_fbgetvplane failed, vplane=%d\n", CONFIG_NXWIDGETS_VPLANE);
+ return 2;
+ }
+#endif
+
+ /* Then start the server */
+
+ ret = nx_run(dev);
+ gvdbg("nx_run returned: %d\n", errno);
+ return EXIT_FAILURE;
+}
+#endif
+
+/**
* This is the entry point of a thread that listeners for and dispatches
* events from the NX server.
*/
@@ -342,7 +413,7 @@ FAR void *CNxServer::listener(FAR void *arg)
{
// The argument must be the CNxServer instance
- CNxServer *This = (CNxServer*)pvArg;
+ CNxServer *This = (CNxServer*)arg;
// Process events forever
@@ -361,7 +432,7 @@ FAR void *CNxServer::listener(FAR void *arg)
// An error occurred... assume that we have lost connection with
// the server.
- gdbg("CNxServer::listener: Lost server connection: %d\n", errno);
+ gdbg("Lost server connection: %d\n", errno);
break;
}
@@ -371,7 +442,7 @@ FAR void *CNxServer::listener(FAR void *arg)
{
This->m_connected = true;
sem_post(&This->m_connsem);
- gdbg("CNxServer::listener: Connected\n");
+ gvdbg("Connected\n");
}
}