diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-12-01 14:04:33 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-12-03 16:48:05 -0600 |
commit | bd6542081652705e24162921d16d433ce0d05012 (patch) | |
tree | 8e048bfb5518e43733c941b6c59b06a665599f44 /apps | |
parent | 1edc1dfd51438e8f0d1fa4e91a02b912b52eb7fe (diff) | |
download | nuttx-bd6542081652705e24162921d16d433ce0d05012.tar.gz nuttx-bd6542081652705e24162921d16d433ce0d05012.tar.bz2 nuttx-bd6542081652705e24162921d16d433ce0d05012.zip |
Add graphic device initialize logic (incomplete)
Diffstat (limited to 'apps')
-rw-r--r-- | apps/examples/nxtext/nxtext_main.c | 2 | ||||
-rw-r--r-- | apps/examples/nxtext/nxtext_server.c | 2 | ||||
-rw-r--r-- | apps/graphics/traveler/Kconfig | 16 | ||||
-rw-r--r-- | apps/graphics/traveler/Makefile | 9 | ||||
-rw-r--r-- | apps/graphics/traveler/include/trv_color.h | 2 | ||||
-rw-r--r-- | apps/graphics/traveler/include/trv_debug.h | 8 | ||||
-rw-r--r-- | apps/graphics/traveler/include/trv_graphics.h | 77 | ||||
-rw-r--r-- | apps/graphics/traveler/include/trv_main.h | 2 | ||||
-rw-r--r-- | apps/graphics/traveler/include/trv_mem.h | 52 | ||||
-rw-r--r-- | apps/graphics/traveler/include/trv_raycntl.h | 8 | ||||
-rw-r--r-- | apps/graphics/traveler/include/trv_types.h | 7 | ||||
-rw-r--r-- | apps/graphics/traveler/include/trv_world.h | 10 | ||||
-rwxr-xr-x | apps/graphics/traveler/src/trv_graphics.c | 572 | ||||
-rwxr-xr-x | apps/graphics/traveler/src/trv_main.c | 62 | ||||
-rwxr-xr-x | apps/graphics/traveler/src/trv_mem.c | 85 | ||||
-rw-r--r-- | apps/graphics/traveler/src/trv_nxbkgd.c | 175 | ||||
-rw-r--r-- | apps/graphics/traveler/src/trv_nxserver.c | 114 |
17 files changed, 1123 insertions, 80 deletions
diff --git a/apps/examples/nxtext/nxtext_main.c b/apps/examples/nxtext/nxtext_main.c index bee9e90db..b1a795484 100644 --- a/apps/examples/nxtext/nxtext_main.c +++ b/apps/examples/nxtext/nxtext_main.c @@ -406,7 +406,7 @@ int nxtext_main(int argc, char **argv) ret = nx_requestbkgd(g_hnx, &g_nxtextcb, bgstate); if (ret < 0) { - printf("nxtext_main: nx_setbgcolor failed: %d\n", errno); + printf("nxtext_main: nx_requestbkgd failed: %d\n", errno); g_exitcode = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } diff --git a/apps/examples/nxtext/nxtext_server.c b/apps/examples/nxtext/nxtext_server.c index 6b5f7145d..ff3041a69 100644 --- a/apps/examples/nxtext/nxtext_server.c +++ b/apps/examples/nxtext/nxtext_server.c @@ -60,7 +60,7 @@ #ifdef CONFIG_NX_MULTIUSER /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** diff --git a/apps/graphics/traveler/Kconfig b/apps/graphics/traveler/Kconfig index e938ec742..851ab4ca7 100644 --- a/apps/graphics/traveler/Kconfig +++ b/apps/graphics/traveler/Kconfig @@ -5,10 +5,22 @@ if GRAPHICS_TRAVELER +choice + prompt "Color format" + default GRAPHICS_TRAVELER_RGB16_565 + +config GRAPHICS_TRAVELER_RGB16_565 + bool "RGB16 565" + +config GRAPHICS_TRAVELER_RGB32_888 + bool "RGB32 888 (no transparency)" + +endchoice # Color format + config GRAPHICS_TRAVELER_PERFMON - bool "Performance monitor game" + bool "Performance monitor" default y - depends on NX && FS_READABLE && !NX_LCDDRIVER + depends on FS_READABLE ---help--- Enable or disable performance monitoring instrumentation and output. diff --git a/apps/graphics/traveler/Makefile b/apps/graphics/traveler/Makefile index 75d48566f..e04bf51c3 100644 --- a/apps/graphics/traveler/Makefile +++ b/apps/graphics/traveler/Makefile @@ -46,9 +46,16 @@ STACKSIZE = 2048 # Hello, World! Example ASRCS = -CSRCS = +CSRCS = trv_mem.c trv_graphics.c MAINSRC = trv_main.c +ifeq ($(CONFIG_NX),y) +CSRCS += trv_nxbkgd.c +ifeq ($(CONFIG_NX),y) +CSRCS += trv_nxserver.c +endif +endif + AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) MAINOBJ = $(MAINSRC:.c=$(OBJEXT)) diff --git a/apps/graphics/traveler/include/trv_color.h b/apps/graphics/traveler/include/trv_color.h index 04e9d1523..0a2cf78bb 100644 --- a/apps/graphics/traveler/include/trv_color.h +++ b/apps/graphics/traveler/include/trv_color.h @@ -71,7 +71,7 @@ struct trv_color_lum_s ****************************************************************************/ bool trv_color_allocate(FAR struct trv_palette_s *pinfo); -void trv_color_endmapping(void); +void trv_color_free(FAR struct trv_palette_s *pinfo); trv_pixel_t trv_color_rgb2pixel(FAR struct trv_color_rgb_s *pixel); void trv_color_pixel2lum(trv_pixel_t pixel, FAR struct trv_color_lum_s *lum); trv_pixel_t trv_color_lum2pixel(FAR struct trv_color_lum_s *lum); diff --git a/apps/graphics/traveler/include/trv_debug.h b/apps/graphics/traveler/include/trv_debug.h index d54b1eb13..08b4c2d3b 100644 --- a/apps/graphics/traveler/include/trv_debug.h +++ b/apps/graphics/traveler/include/trv_debug.h @@ -93,13 +93,13 @@ printf(EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__) # else -# define vdbg(x...) +# define trv_vdebug(x...) # endif # else -# define dbg(x...) -# define vdbg(x...) +# define trv_debug(x...) +# define trv_vdebug(x...) # endif #else @@ -132,7 +132,7 @@ * arguments, then this additional interface will be built. */ -#ifndef CONFIG_CPP_HAVE_VARARGS && (CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL > 0) +#if !defined(CONFIG_CPP_HAVE_VARARGS) && CONFIG_GRAPHICS_TRAVELER_DEBUG_LEVEL > 0 int trv_debug(FAR const char *format, ...); #endif diff --git a/apps/graphics/traveler/include/trv_graphics.h b/apps/graphics/traveler/include/trv_graphics.h index 5364c8bc7..69790e627 100644 --- a/apps/graphics/traveler/include/trv_graphics.h +++ b/apps/graphics/traveler/include/trv_graphics.h @@ -42,41 +42,88 @@ #include "trv_types.h" +#include <nuttx/video/fb.h> +#ifdef CONFIG_NX +# include <nuttx/nx/nx.h> +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if defined(CONFIG_GRAPHICS_TRAVELER_RGB16_565) +# define TRV_BPP 16 +# define TRV_COLOR_FMT FB_FMT_RGB16_565 +#elif defined(CONFIG_GRAPHICS_TRAVELER_RGB32_888) +# define TRV_BPP 32 +# define TRV_COLOR_FMT FB_FMT_RGB32 +#else +# error No color format defined +#endif + +#define MAX_REND_WIDTH 480 +#define MAX_REND_HEIGHT 240 + /**************************************************************************** * Public Types ****************************************************************************/ +#if TRV_BPP == 16 +typedef uint16_t dev_pixel_t; /* Width of one hardware pixel */ +#elif TRV_BPP == 32 +typedef uint32_t dev_pixel_t; /* Width of one hardware pixel */ +#endif + struct trv_palette_s { int ncolors; /* Number of colors in the look-up table */ - FAR nxgl_mxpixel_t *lut; /* Color lookup table */ + FAR dev_pixel_t *lut; /* Color lookup table */ }; struct trv_graphics_info_s { - nxgl_coord_t width; /* Image width */ - nxgl_coord_t height; /* Image height */ +#ifdef CONFIG_NX + NXHANDLE hnx; /* The connection handle */ + NXHANDLE bgwnd; /* Background window handle */ +#else + trv_coord_t stride; /* Length of a line in bytes */ +#endif + trv_coord_t hwwidth; /* Display width (pixels) */ + trv_coord_t hwheight; /* Display height (rows) */ + trv_coord_t swwidth; /* Software render width (pixels) */ + trv_coord_t swheight; /* Software render height height (rows) */ + uint8_t vscale; /* Log2 vertical image scale factor */ + uint8_t hscale; /* Log2 horizontal image scale factor */ struct trv_palette_s palette; /* Color palette */ - FAR nxgl_mxpixel_t *buffer; /* Hardware framebuffer */ + FAR dev_pixel_t *hwbuffer; /* Hardware frame buffer */ + FAR trv_pixel_t *swbuffer; /* Software render buffer */ }; -struct trv_framebuffer_s -{ - nxgl_coord_t width; /* Image width */ - nxgl_coord_t height; /* Image height */ - FAR trv_pixel_t *buffer; /* Software render buffer */ -}; +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef CONFIG_NX +extern FAR const struct nx_callback_s *g_trv_nxcallback; +extern sem_t g_trv_nxevent; +extern volatile bool g_trv_nxresolution; +#ifdef CONFIG_NX_MULTIUSER +extern volatile bool g_trv_nxrconnected; +#endif +#endif /**************************************************************************** * Public Function Prototypes ****************************************************************************/ -int trv_graphics_initialize(uint16_t width, uint16_t height, - uint8_t scale_factor, - FAR struct trv_graphics_info_s *ginfo); -void trv_graphics_terminate(void); +int trv_graphics_initialize(FAR struct trv_graphics_info_s *ginfo); +void trv_graphics_terminate(FAR struct trv_graphics_info_s *ginfo); trv_pixel_t trv_graphics_index2pixel(int index); -void trv_display_update(struct trv_framebuffer_s *fb); +void trv_display_update(struct trv_graphics_info_s *fb); trv_pixel_t *trv_get_renderbuffer(uint16_t width, uint16_t height); +#ifdef CONFIG_NX_MULTIUSER +FAR void *trv_nxlistener(FAR void *arg) +#endif + #endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_GRAPHICS_H */ diff --git a/apps/graphics/traveler/include/trv_main.h b/apps/graphics/traveler/include/trv_main.h index 08d16ef2b..62c5ad61f 100644 --- a/apps/graphics/traveler/include/trv_main.h +++ b/apps/graphics/traveler/include/trv_main.h @@ -56,6 +56,6 @@ extern bool g_trv_terminate; * Public Function Prototypes ****************************************************************************/ -void trv_abort(FAR char *format, ...); +void trv_abort(FAR char *format, ...) noreturn_function; #endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MAIN_H */ diff --git a/apps/graphics/traveler/include/trv_mem.h b/apps/graphics/traveler/include/trv_mem.h new file mode 100644 index 000000000..5ae3866cf --- /dev/null +++ b/apps/graphics/traveler/include/trv_mem.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * apps/graphics/traveler/include/trv_mem.h + * + * Copyright (C) 2014 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 __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MEM_H +#define __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MEM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include "trv_types.h" + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +FAR void *trv_malloc(size_t size); +void trv_free(FAR void *memory); + +#endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_MEM_H */ diff --git a/apps/graphics/traveler/include/trv_raycntl.h b/apps/graphics/traveler/include/trv_raycntl.h index 01cbed191..ffcf2b6d3 100644 --- a/apps/graphics/traveler/include/trv_raycntl.h +++ b/apps/graphics/traveler/include/trv_raycntl.h @@ -41,6 +41,7 @@ ****************************************************************************/ #include "trv_types.h" +#include "trv_graphics.h" /**************************************************************************** * Pre-processor Definitions @@ -54,10 +55,7 @@ * Public Function Prototypes ****************************************************************************/ -extern uint8_t *trv_raycaster_initialize(uint16_t screen_width, - uint16_t screen_height, - uint8_t scale_factor, - FAR uint8_t *screen_buffer); -extern void trv_raycaster(FAR struct trv_camera_s *player); +void trv_raycaster(FAR struct trv_camera_s *player, + FAR struct trv_graphics_info_s *ginfo); #endif /* __APPS_GRAPHICS_TRAVELER_INCLUDE_TRV_RAYCNTL_H */ diff --git a/apps/graphics/traveler/include/trv_types.h b/apps/graphics/traveler/include/trv_types.h index 6fbf61071..2eb9f2618 100644 --- a/apps/graphics/traveler/include/trv_types.h +++ b/apps/graphics/traveler/include/trv_types.h @@ -41,12 +41,12 @@ ****************************************************************************/ #include <nuttx/config.h> +#include <nuttx/compiler.h> +#include <sys/types.h> #include <stdint.h> #include <stdbool.h> -#include <nuttx/nx/nxglib.h> - /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -63,7 +63,8 @@ * Public Types ****************************************************************************/ -typedef uint8_t trv_pixel_t; +typedef uint8_t trv_pixel_t; /* Width of one pixel in rendering phase */ +typedef int16_t trv_coord_t; /* Contains one display coordinate */ /**************************************************************************** * Public Function Prototypes diff --git a/apps/graphics/traveler/include/trv_world.h b/apps/graphics/traveler/include/trv_world.h index b590e2f87..939ec1820 100644 --- a/apps/graphics/traveler/include/trv_world.h +++ b/apps/graphics/traveler/include/trv_world.h @@ -52,11 +52,11 @@ struct trv_camera_s { - nxgl_coord_t x; /* Camera X position */ - nxgl_coord_t y; /* Camera Y position */ - nxgl_coord_t z; /* Camera Z position */ - int16_t yaw; /* Camera yaw orientation */ - int16_t pitch; /* Camera pitch orientation */ + trv_coord_t x; /* Camera X position */ + trv_coord_t y; /* Camera Y position */ + trv_coord_t z; /* Camera Z position */ + int16_t yaw; /* Camera yaw orientation */ + int16_t pitch; /* Camera pitch orientation */ }; /**************************************************************************** diff --git a/apps/graphics/traveler/src/trv_graphics.c b/apps/graphics/traveler/src/trv_graphics.c new file mode 100755 index 000000000..6742147aa --- /dev/null +++ b/apps/graphics/traveler/src/trv_graphics.c @@ -0,0 +1,572 @@ +/**************************************************************************** + * apps/graphics/traveler/src/trv_graphics.c + * + * Copyright (C) 2014 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 "trv_types.h" +#include "trv_main.h" +#include "trv_mem.h" +#include "trv_color.h" +#include "trv_debug.h" +#include "trv_graphics.h" + +#include <string.h> +#ifdef CONFIG_NX_MULTIUSER +# include <semaphore.h> +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef CONFIG_NX +FAR const struct nx_callback_s *g_trv_nxcallback; +sem_t g_trv_nxevent = SEM_INITIZIALIZER(0); +bool g_trv_nxresolution = false; +#ifdef CONFIG_NX_MULTIUSER +bool g_trv_nxrconnected = false; +#endif +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_get_fbdev + * + * Description: + * Get the system framebuffer device + * + ****************************************************************************/ + +#ifndef CONFIG_NX_MULTIUSER +static FAR struct fb_vtable_s *trv_get_fbdev(void) +{ + FAR struct fb_vtable_s *fbdev; + int ret; + + /* Initialize the frame buffer device */ + + ret = up_fbinitialize(); + if (ret < 0) + { + trv_abort("up_fbinitialize failed: %d\n", -ret); + } + + /* Set up to use video plane 0. There is no support for anything but + * video plane 0. + */ + + fbdev = up_fbgetvplane(0); + if (!fbdev) + { + trv_abort("up_fbgetvplane(0) failed\n"); + } + + return fbdev; +} +#endif + +/**************************************************************************** + * Name: trv_fb_initialize + * + * Description: + * Get the system framebuffer device + * + ****************************************************************************/ + +#if !defined(CONFIG_NX_MULTIUSER) && !defined(CONFIG_NX) +static void trv_fb_initialize(FAR struct trv_graphics_info_s *ginfo) +{ + struct fb_videoinfo_s vinfo; + struct fb_planeinfo_s pinfo; + FAR struct fb_vtable_s *fbdev; + int ret; + + /* Get the framebuffer device */ + + fbdev = trv_get_fbdev(); + + /* Get information about video plane 0 */ + + ret = fbdev->getvideoinfo(fbdev, &vinfo); + if (ret < 0) + { + trv_abort("getvideoinfo() failed\n"); + } + + ginfo->hwwidth = vinfo.xres; + ginfo->hwheight = vinfo.yres; + + ret = fbdev->getplaneinfo(fbdev, 0, &pinfo); + if (ret < 0) + { + trv_abort("getplaneinfo() failed\n"); + } + + ginfo->stride = pinfo.stride; + ginfo->hwbuffer = pinfo.fbmem; + + if (vinfo.fmt != TRV_COLOR_FMT || pinfo.bpp != TRV_BPP) + { + trv_abort("Bad color format(%d)/bpp(%b)\n", vinfo.fmt, pinfo.bpp); + } +} +#endif + +/**************************************************************************** + * Name: trv_use_bgwindow + * + * Description: + * Get the NX background window + * + ****************************************************************************/ + +#ifdef CONFIG_NX +static void trv_use_bgwindow(FAR struct trv_graphics_info_s *ginfo) +{ + /* Get the background window */ + + ret = nx_requestbkgd(g_hnx, &g_trv_nxcallback, ginfo); + if (ret < 0) + { + trv_abort("nx_requestbkgd failed: %d\n", errno); + } + + /* Wait until we have the screen resolution. We'll have this immediately + * unless we are dealing with the NX server. + */ + + while (!g_trv_nxresolution) + { + (void)sem_wait(&g_trv_nxevent); + } +} +#endif + +/**************************************************************************** + * Name: trv_nxsu_initialize + ****************************************************************************/ + +#if defined(CONFIG_NX) && !defined(CONFIG_NX_MULTIUSER) +static inline int trv_nxsu_initialize(FAR struct trv_graphics_info_s *ginfo) +{ + FAR struct fb_vtable_s *fbdev; + int ret; + + /* Get the framebuffer device */ + + fbdev = trv_get_fbdev(); + + /* Open NX */ + + ginfo->hnx = nx_open(fbdev); + if (!ginfo->hnx) + { + trv_abort("trv_nxsu_initialize: nx_open failed: %d\n", errno); + } + + /* And use the background window */ + + trv_use_bgwindow(ginfo); +} +#endif + +/**************************************************************************** + * Name: trv_servertask + ****************************************************************************/ + +#ifdef CONFIG_NX_MULTIUSER +int trv_servertask(int argc, char *argv[]) +{ + FAR struct fb_vtable_s *fbdev; + int ret; + + /* Get the framebuffer device */ + + fbdev = trv_get_fbdev(); + + /* Then start the server */ + + ret = nx_run(dev); + trv_abort("nx_run returned: %d\n", errno); +} +#endif + +/**************************************************************************** + * Name: trv_nxmu_initialize + ****************************************************************************/ + +#ifdef CONFIG_NX_MULTIUSER +static inline int trv_nxmu_initialize(FAR struct trv_graphics_info_s *ginfo) +{ + struct sched_param param; + pthread_t thread; + pid_t servrid; + int ret; + + /* Set the client task priority */ + + param.sched_priority = CONFIG_EXAMPLES_NX_CLIENTPRIO; + ret = sched_setparam(0, ¶m); + if (ret < 0) + { + printf("nxeg_initialize: sched_setparam failed: %d\n" , ret); + g_exitcode = NXEXIT_SCHEDSETPARAM; + return ERROR; + } + + /* Start the server task */ + + printf("nxeg_initialize: Starting trv_servertask task\n"); + servrid = task_create("NX Server", CONFIG_EXAMPLES_NX_SERVERPRIO, + CONFIG_EXAMPLES_NX_STACKSIZE, trv_servertask, NULL); + if (servrid < 0) + { + printf("nxeg_initialize: Failed to create trv_servertask task: %d\n", errno); + g_exitcode = NXEXIT_TASKCREATE; + return ERROR; + } + + /* Wait a bit to let the server get started */ + + sleep(1); + + /* Connect to the server */ + + ginfo->hnx = nx_connect(); + if (ginfo->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_NX_LISTENERPRIO; + (void)pthread_attr_setschedparam(&attr, ¶m); + (void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NX_STACKSIZE); + + ret = pthread_create(&thread, &attr, trv_nxlistener, NULL); + if (ret != 0) + { + printf("nxeg_initialize: pthread_create failed: %d\n", ret); + g_exitcode = NXEXIT_PTHREADCREATE; + return ERROR; + } + + /* Don't return until we are connected to the server */ + + while (!g_trv_nxrconnected) + { + /* Wait for the listener thread to wake us up when we really + * are connected. + */ + + (void)sem_wait(&g_trv_nxevent); + } + } + else + { + printf("nxeg_initialize: nx_connect failed: %d\n", errno); + g_exitcode = NXEXIT_NXCONNECT; + return ERROR; + } + + /* And use the background window */ + + trv_use_bgwindow(ginfo); +} +#endif + +/**************************************************************************** + * Name: trv_row_update + * + * Description: + * Expand one one either directly into the frame buffer or else into an + * intermediate line buffer. + * + ****************************************************************************/ + +void trv_row_update(struct trv_graphics_info_s *ginfo, + FAR const trv_pixel_t *src, + FAR dev_pixel_t *dest) +{ + trv_coord_t hexpand; + dev_pixel_t pixel; + trv_coord_t srccol; + int i; + + /* Loop for each column in the src render buffer */ + + hexpand = (1 << ginfo->hscale); + + for (srccol = 0; srccol < ginfo->swwidth; srccol++) + { + /* Map the source pixel */ + + pixel = ginfo->palette.lut[*src++]; + + /* Copy it to the destination, expanding as necessary */ + + for (i = 0; i < hexpand; i++) + { + *dest++ = pixel; + } + } +} + +/**************************************************************************** + * Name: trv_row_tranfer + * + * Description: + * Transfer one line from the line buffer to the NX window. + * + ****************************************************************************/ + +#ifdef CONFIG_NX +void trv_display_update(struct trv_graphics_info_s *ginfo, + FAR dev_pixel_t *dest, trv_coord_t destrow) +{ + /* Transfer the row buffer to the NX window */ +#warning Missing logic + +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_graphics_initialize + * + * Description: + ****************************************************************************/ + +int trv_graphics_initialize(FAR struct trv_graphics_info_s *ginfo) +{ + int swwidth; + int swheight; + int scale; + int ret; + + /* Initialize the graphics device and get information about the display */ + +#if !defined(CONFIG_NX) + trv_fb_initialize(ginfo); +#elif defined(CONFIG_NX_MULTIUSER) + trv_nxmu_initialize(ginfo); +#else + trv_nxsu_initialize(ginfo); +#endif + + /* Check if we need to scale the image */ + + swwidth = ginfo->hwwidth; + scale = 0; + + while (swwidth > MAX_REND_WIDTH) + { + swwidth >>= 1; + scale++; + } + + ginfo->swwidth = swwidth; + ginfo->hscale = scale; + + swheight = ginfo->hwheight; + scale = 0; + + while (swheight > MAX_REND_WIDTH) + { + swheight >>= 1; + scale++; + } + + ginfo->swheight = swheight; + ginfo->vscale = scale; + + /* Allocate buffers + * + * ginfo->swbuffer - Software renders into this buffer using an 8-bit + * encoding and perhaps at a different resolution that the final + * image. + */ + + ginfo->swbuffer = (trv_pixel_t*) + trv_malloc(swwidth * swheight * sizeof(trv_pixel_t)); + if (!ginfo->swbuffer) + { + trv_abort("ERROR: Failed to allocate render buffer\n"); + } + + /* Using the framebuffer driver: + * ginfo->hwbuffer - This address of the final, expanded frame image. + * This address is determined by hardware and is neither allocated + * nor freed. + * + * Using NX + * ginfo->hwbuffer - This address of one line of the final expanded + * image that must transferred to the window. + */ + +#ifdef CONFIG_NX + ginfo->hwbuffer = (trv_pixel_t*) + trv_malloc(ginfo->hwwidth * sizeof(dev_pixel_t)); + if (!ginfo->hwbuffer) + { + trv_abort("ERROR: Failed to allocate hardware line buffer\n"); + } +#endif + + /* Allocate color mapping information */ + + ret = trv_color_allocate(&ginfo->palette); + if (ret < 0) + { + trv_abort("ERROR trv_color_allocate failed: %d"); + } + + trv_vdebug("%d colors allocated\n", ginfo->palette.ncolors); + return OK; +} + +/**************************************************************************** + * Name: trv_graphics_terminate + * + * Description: + ****************************************************************************/ + +void trv_graphics_terminate(FAR struct trv_graphics_info_s *ginfo) +{ + /* Free palette */ + + trv_color_free(&ginfo->palette); + + /* Free image buffers */ + + if (ginfo->swbuffer) + { + trv_free(ginfo->swbuffer); + ginfo->swbuffer = NULL; + } + +#ifdef CONFIG_NX + if (ginfo->hwbuffer) + { + trv_free(ginfo->hwbuffer); + ginfo->hwbuffer = NULL; + } + + /* Close/disconnect NX */ +#warning "Missing Logic" +#endif +} + +/**************************************************************************** + * Name: trv_display_update + * + * Description: + ****************************************************************************/ + +void trv_display_update(struct trv_graphics_info_s *ginfo) +{ + FAR const uint8_t *src = (FAR const uint8_t *)ginfo->swbuffer; + FAR uint8_t *dest = (FAR uint8_t *)ginfo->hwbuffer; + trv_coord_t srcrow; +#ifdef CONFIG_NX + trv_coord_t destrow; +#else + FAR uint8_t *first; + trv_coord_t lnwidth; +#endif + trv_coord_t vexpand; + int i; + + /* Loop for each row in the srce render buffer */ + + vexpand = (1 << ginfo->vscale); +#ifdef CONFIG_NX + destrow = 0; +#else + lnwidth = ginfo->hwwidth * sizeof(dev_pixel_t); +#endif + + for (srcrow = 0; srcrow < ginfo->swheight; srcrow++) + { + /* Transfer the row to the device row/buffer */ + + trv_row_update(ginfo, (FAR const trv_pixel_t *)src, + (FAR dev_pixel_t *)dest); + +#ifdef CONFIG_NX + /* Transfer the row buffer to the NX window */ + + trv_row_tranfer(ginfo, dest, destrow); + destrow++; +#else + first = dest; + dest += ginfo->stride; +#endif + + /* Then replicate as many times as is necessary */ + + for (i = 1; i < vexpand; i++) + { +#ifdef CONFIG_NX + /* Transfer the row buffer to the NX window */ + + trv_row_tranfer(ginfo, dest, destrow); + destrow++; +#else + /* Point to the next row in the frame buffer */ + + memcpy(dest, first, lnwidth); + dest += ginfo->stride; +#endif + } + + /* Point to the next src row */ + + src += ginfo->swwidth; + } +} + diff --git a/apps/graphics/traveler/src/trv_main.c b/apps/graphics/traveler/src/trv_main.c index 604ff2975..fc9de19f6 100755 --- a/apps/graphics/traveler/src/trv_main.c +++ b/apps/graphics/traveler/src/trv_main.c @@ -52,7 +52,7 @@ #include "trv_rayrend.h" #include "trv_input.h" #include "trv_graphics.h" -#include "trv_color.h" +#include "trv_debug.h" #include "trv_main.h" #if CONFIG_GRAPHICS_TRAVELER_PERFMON @@ -78,10 +78,21 @@ static double trv_current_time(void); bool g_trv_terminate; /**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void trv_exit(int exitcode) noreturn_function; +static void trv_usage(char *execname); +#ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON +static double trv_current_time(void); +#endif + +/**************************************************************************** * Private Data *************************************************************************/ static const char g_default_worldfile[] = "transfrm.wld"; +static FAR struct trv_graphics_info_s g_trv_ginfo; /**************************************************************************** * Private Functions @@ -93,7 +104,7 @@ static const char g_default_worldfile[] = "transfrm.wld"; * Description: ****************************************************************************/ -static void trv_exit(int exitCode) +static void trv_exit(int exitcode) { /* Release memory held by the ray casting engine */ @@ -102,9 +113,9 @@ static void trv_exit(int exitCode) /* Close off input */ trv_input_terminate(); - trv_graphics_terminate(); + trv_graphics_terminate(&g_trv_ginfo); - exit(exitCode); + exit(exitcode); } /**************************************************************************** @@ -117,7 +128,6 @@ static void trv_usage(char *execname) { fprintf(stderr, "Usage: %s [-b] [-p<path>] [world]\n", execname); fprintf(stderr, "Where:\n"); - fprintf(stderr, " -b Selects 640x400 window (default is 320x200)\n"); fprintf(stderr, " -p<path> Selects the path to the world data file\n"); fprintf(stderr, " world Selects the world file name\n"); exit(EXIT_FAILURE); @@ -155,10 +165,7 @@ int main(int argc, FAR char *argv[]) int traveler_main(int argc, char *argv[]) #endif { - FAR struct trv_graphics_info_s ginfo; - struct trv_framebuffer_s frame; FAR const char *world_filename; - uint8_t scale_factor = 1; #ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON int32_t frame_count = 0; double elapsed_time = 0.0; @@ -178,10 +185,6 @@ int traveler_main(int argc, char *argv[]) ptr++; switch (*ptr) { - case 'b': - scale_factor = 2; - break; - case 'p' : ptr++; printf("World data path = %s\n", ptr); @@ -204,31 +207,21 @@ int traveler_main(int argc, char *argv[]) } } - printf("World data file = %s\n", world_filename); + trv_debug("World data file = %s\n", world_filename); /* Initialize the graphics interface */ - ret = trv_graphics_initialize(320, 200, scale_factor, &ginfo); - if (ret < 0) - { - fprintf(stderr, "ERROR: trv_graphics_initialize failed: %d\n", ret); - trv_exit(EXIT_FAILURE); - } + trv_graphics_initialize(&g_trv_ginfo); /* Load the word data structures */ ret = trv_world_create(world_filename); if (ret < 0) { - fprintf(stderr, "ERROR: %d loading world file %s: %d\n", - world_filename, ret); - trv_exit(EXIT_FAILURE); + trv_abort("ERROR: %d loading world file %s: %d\n", + world_filename, ret); } - /* We can now release any color mapping tables */ - - trv_color_endmapping(); - /* Set the player's POV in the new world */ trv_pov_reset(); @@ -237,19 +230,6 @@ int traveler_main(int argc, char *argv[]) trv_door_initialize(); - /* Initialize the ray cast engine */ - - frame.width = ginfo.width; - frame.height = ginfo.height; - frame.buffer = trv_get_renderbuffer(ginfo.width, ginfo.height); - - if (!trv_raycaster_initialize(frame.width, frame.height, - scale_factor, frame.buffer)) - { - fprintf(stderr, "Error: Initializing ray cast engine.\n"); - trv_exit(EXIT_FAILURE); - } - /* Set up to receive input */ trv_input_initialize(); @@ -276,11 +256,11 @@ int traveler_main(int argc, char *argv[]) /* Render the 3-D view */ - trv_raycaster(&g_trv_player); + trv_raycaster(&g_trv_player, &g_trv_ginfo); /* Display the world. */ - trv_display_update(&frame); + trv_display_update(&g_trv_ginfo); #ifdef CONFIG_GRAPHICS_TRAVELER_PERFMON frame_count++; elapsed_time += trv_current_time() - start_time; diff --git a/apps/graphics/traveler/src/trv_mem.c b/apps/graphics/traveler/src/trv_mem.c new file mode 100755 index 000000000..84e85c3d0 --- /dev/null +++ b/apps/graphics/traveler/src/trv_mem.c @@ -0,0 +1,85 @@ +/**************************************************************************** + * apps/graphics/traveler/src/trv_mem.c + * + * Copyright (C) 2014 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 "trv_types.h" +#include "trv_main.h" +#include "trv_mem.h" + +#include <stdlib.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_malloc + * + * Description: + ****************************************************************************/ + +FAR void *trv_malloc(size_t size) +{ + FAR void *memory; + + memory = malloc(size); + if (memory == NULL) + { + trv_abort("Out of memory (trv_malloc %x bytes)", size); + } + + return memory; +} + +/**************************************************************************** + * Name: trv_free + * + * Description: + ****************************************************************************/ + +void trv_free(void *memory) +{ + if (memory == NULL) + { + trv_abort("Freeing NULL"); + } + else + { + free(memory); + } +} diff --git a/apps/graphics/traveler/src/trv_nxbkgd.c b/apps/graphics/traveler/src/trv_nxbkgd.c new file mode 100644 index 000000000..4bd8a6997 --- /dev/null +++ b/apps/graphics/traveler/src/trv_nxbkgd.c @@ -0,0 +1,175 @@ +/**************************************************************************** + * apps/graphics/traveler/trv_nxbkgd.c + * + * Copyright (C) 2014 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 "trv_types.h" + +#include <string.h> +#include <semaphore.h> +#include <errno.h> + +#include <nuttx/nx/nx.h> +#include <nuttx/nx/nxfonts.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static void trv_nxredraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, + bool morem, FAR void *arg); +static void trv_nxposition(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_XYINPUT +static void trv_nxmousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg); +#endif + +#ifdef CONFIG_NX_KBD +static void trv_nxkbdin(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_trv_nxcallback = +{ + trv_nxredraw, /* redraw */ + trv_nxposition /* position */ +#ifdef CONFIG_NX_XYINPUT + , trv_nxmousein /* mousein */ +#endif +#ifdef CONFIG_NX_KBD + , trv_nxkbdin /* my kbdin */ +#endif +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_nxredraw + ****************************************************************************/ + +static void trv_nxredraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, + bool more, FAR void *arg) +{ +} + +/**************************************************************************** + * Name: trv_nxposition + ****************************************************************************/ + +static void trv_nxposition(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) +{ + FAR struct trv_graphics_info_s *ginfo = (FAR struct trv_graphics_info_s *)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_trv_nxresolution) + { + /* Save the background window handle */ + + ginnfo->bgwnd = hwnd; + + /* Save the background window size */ + + ginfo->width = size->w; + ginfo->height = size->h; + + g_trv_nxresolution = true; + sem_post(&g_trv_nxevent); + gvdbg("Have width=%d height=%d\n", ginfo->width, ginfo->height); + } +} + +/**************************************************************************** + * Name: trv_nxmousein + ****************************************************************************/ + +#ifdef CONFIG_NX_XYINPUT +static void trv_nxmousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, + uint8_t buttons, FAR void *arg) +{ + printf("trv_nxmousein: hwnd=%p pos=(%d,%d) button=%02x\n", + hwnd, pos->x, pos->y, buttons); +} +#endif + +/**************************************************************************** + * Name: trv_nxkbdin + ****************************************************************************/ + +#ifdef CONFIG_NX_KBD +static void trv_nxkbdin(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/graphics/traveler/src/trv_nxserver.c b/apps/graphics/traveler/src/trv_nxserver.c new file mode 100644 index 000000000..e2cedaa28 --- /dev/null +++ b/apps/graphics/traveler/src/trv_nxserver.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * apps/graphics/traveler/trv_nxlistener.c + * + * Copyright (C) 2014 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 "trv_types.h" + +#include <stdlib.h> +#include <unistd.h> +#include <sched.h> +#include <errno.h> + +#include <nuttx/arch.h> +#include <nuttx/nx/nx.h> +#include <nuttx/video/fb.h> + +#ifdef CONFIG_NX_MULTIUSER + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: trv_nxlistener + ****************************************************************************/ + +FAR void *trv_nxlistener(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_hnx); + if (ret < 0) + { + /* An error occurred... assume that we have lost connection with + * the server. + */ + + trv_abort("Lost server connection: %d\n", errno); + } + + /* If we received a message, we must be connected */ + + if (!g_trv_nxrconnected) + { + g_trv_nxrconnected = true; + sem_post(&g_trv_nxevent); + trv_debug("Connected to server\n"); + } + } +} + +#endif /* CONFIG_NX_MULTIUSER */ |