Add a NuttX logo image example
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3804 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
5c0f5e790f
commit
f22dbcb8f3
@ -38,13 +38,13 @@
|
||||
# Sub-directories
|
||||
|
||||
SUBDIRS = buttons dhcpd ftpc hello helloxx hidkbd igmp mm mount nettest \
|
||||
nsh null nx nxffs nxflat nxtext nxhello ostest pashello pipe poll \
|
||||
rgmp romfs sendmail serloop thttpd udp uip usbserial usbstorage \
|
||||
nsh null nx nxffs nxflat nxhello nximage nxtext stest pashello pipe \
|
||||
poll rgmp romfs sendmail serloop thttpd udp uip usbserial usbstorage \
|
||||
wget wlan
|
||||
|
||||
# Sub-directories that might need context setup
|
||||
|
||||
CNTXTDIRS = nx nxhello nxtext
|
||||
CNTXTDIRS = nx nxhello nximage nxtext
|
||||
|
||||
all: nothing
|
||||
.PHONY: nothing context depend clean distclean
|
||||
|
@ -339,6 +339,44 @@ examplex/nxhello
|
||||
FAR struct fb_vtable_s *up_nxdrvinit(unsigned int devno);
|
||||
#endif
|
||||
|
||||
examples/nximage
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This is a simple example that just puts the NuttX logo image in the center
|
||||
of the display. This only works for RGB23 (888), RGB16 (656), and RGB8 (332
|
||||
for now.
|
||||
|
||||
CONFIG_EXAMPLES_NXIMAGE_BUILTIN -- Build the NXIMAGE example as a "built-in"
|
||||
that can be executed from the NSH command line
|
||||
CONFIG_EXAMPLES_NXIMAGE_VPLANE -- The plane to select from the frame-
|
||||
buffer driver for use in the test. Default: 0
|
||||
CONFIG_EXAMPLES_NXIMAGE_DEVNO - The LCD device to select from the LCD
|
||||
driver for use in the test: Default: 0
|
||||
CONFIG_EXAMPLES_NXIMAGE_BPP -- Pixels per pixel to use. Valid options
|
||||
include 8, 16, and 24. Default is 16.
|
||||
CONFIG_EXAMPLES_NXIMAGE_XSCALEp5, CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5,
|
||||
CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0 -- The logo image width is 160 columns.
|
||||
One of these may be defined to rescale the image horizontally by .5, 1.5,
|
||||
or 2.0.
|
||||
CONFIG_EXAMPLES_NXIMAGE_YSCALEp5, CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5,
|
||||
CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0 -- The logo image height is 160 rows.
|
||||
One of these may be defined to rescale the image vertically by .5, 1.5,
|
||||
or 2.0.
|
||||
CONFIG_EXAMPLES_NXIMAGE_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
|
||||
|
||||
NOTE: As of this writing, not all of the scaling options and combinations
|
||||
have been tested.
|
||||
|
||||
examples/nxtext
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
|
@ -332,10 +332,10 @@ static void nxhello_initglyph(FAR uint8_t *glyph, uint8_t height,
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxhello_write
|
||||
* Name: nxhello_hello
|
||||
*
|
||||
* Description:
|
||||
* Put a sequence of bytes in the window.
|
||||
* Print "Hello, World!" in the center of the display.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
|
@ -274,7 +274,7 @@ int MAIN_NAME(int argc, char *argv[])
|
||||
}
|
||||
message(MAIN_NAME_STRING ": Screen resolution (%d,%d)\n", g_nxhello.xres, g_nxhello.yres);
|
||||
|
||||
/* Now, say hello and exit, leeping a little before each. */
|
||||
/* Now, say hello and exit, sleeping a little before each. */
|
||||
|
||||
sleep(1);
|
||||
nxhello_hello(g_nxhello.hbkgd);
|
||||
|
105
examples/nximage/Makefile
Executable file
105
examples/nximage/Makefile
Executable file
@ -0,0 +1,105 @@
|
||||
############################################################################
|
||||
# apps/examples/nximage/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 Graphics Example.
|
||||
|
||||
ASRCS =
|
||||
CSRCS = nximage_main.c nximage_bkgd.c nximage_bitmap.c
|
||||
|
||||
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 .
|
||||
|
||||
# NXIMAGE built-in application info
|
||||
|
||||
APPNAME = nximage
|
||||
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_EXAMPLES_NXIMAGE_BUILTIN),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
|
219
examples/nximage/nximage.h
Executable file
219
examples/nximage/nximage.h
Executable file
@ -0,0 +1,219 @@
|
||||
/****************************************************************************
|
||||
* examples/nximage/nximage.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __APPS_EXAMPLES_NXIMAGE_NXIMAGE_H
|
||||
#define __APPS_EXAMPLES_NXIMAGE_NXIMAGE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <nuttx/nx.h>
|
||||
#include <nuttx/nxglib.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_NX
|
||||
# error "NX is not enabled (CONFIG_NX)"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NXIMAGE_VPLANE
|
||||
# define CONFIG_EXAMPLES_NXIMAGE_VPLANE 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NXIMAGE_BPP
|
||||
# define CONFIG_EXAMPLES_NXIMAGE_BPP 16
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_XSCALEp5)
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALE1p0
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5)
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALEp5
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALE1p0
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0)
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALEp5
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALE1p0
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5
|
||||
#else
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALEp5
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALE1p0
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0
|
||||
# define CONFIG_EXAMPLES_NXIMAGE_XSCALE1p0 1
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_YSCALEp5)
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALE1p0
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5)
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALEp5
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALE1p0
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0)
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALEp5
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALE1p0
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5
|
||||
#else
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALEp5
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALE1p0
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5
|
||||
# undef CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0
|
||||
# define CONFIG_EXAMPLES_NXIMAGE_YSCALE1p0 1
|
||||
#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
|
||||
|
||||
/* Image Information ********************************************************/
|
||||
|
||||
#define IMAGE_HEIGHT 160 /* Number of rows in the raw image */
|
||||
#define IMAGE_WIDTH 160 /* Number of columns in the raw image */
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_XSCALEp5)
|
||||
# define SCALED_WIDTH 80 /* Number of columns in the scaled image */
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5)
|
||||
# define SCALED_WIDTH 240 /* Number of columns in the scaled image */
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0)
|
||||
# define SCALED_WIDTH 320 /* Number of columns in the scaled image */
|
||||
#else
|
||||
# define SCALED_WIDTH 160 /* Number of columns in the scaled image */
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_YSCALEp5)
|
||||
# define SCALED_HEIGHT 80 /* Number of rows in the scaled image */
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5)
|
||||
# define SCALED_HEIGHT 240 /* Number of rows in the scaled image */
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0)
|
||||
# define SCALED_HEIGHT 320 /* Number of rows in the scaled image */
|
||||
#else
|
||||
# define SCALED_HEIGHT 160 /* Number of rows in the scaled image */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
enum exitcode_e
|
||||
{
|
||||
NXEXIT_SUCCESS = 0,
|
||||
NXEXIT_EXTINITIALIZE,
|
||||
NXEXIT_FBINITIALIZE,
|
||||
NXEXIT_FBGETVPLANE,
|
||||
NXEXIT_LCDINITIALIZE,
|
||||
NXEXIT_LCDGETDEV,
|
||||
NXEXIT_NXOPEN,
|
||||
NXEXIT_NXREQUESTBKGD,
|
||||
NXEXIT_NXSETBGCOLOR
|
||||
};
|
||||
|
||||
struct nximage_data_s
|
||||
{
|
||||
/* The NX handles */
|
||||
|
||||
NXHANDLE hnx;
|
||||
NXHANDLE hbkgd;
|
||||
|
||||
/* The screen resolution */
|
||||
|
||||
nxgl_coord_t xres;
|
||||
nxgl_coord_t yres;
|
||||
|
||||
volatile bool havepos;
|
||||
sem_t sem;
|
||||
volatile int code;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/* NXIMAGE state data */
|
||||
|
||||
extern struct nximage_data_s g_nximage;
|
||||
|
||||
/* NX callback vtables */
|
||||
|
||||
extern const struct nx_callback_s g_bgcb;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NXIMAGE_EXTERNINIT
|
||||
extern FAR NX_DRIVERTYPE *up_nxdrvinit(unsigned int devno);
|
||||
#endif
|
||||
|
||||
/* Background window interfaces */
|
||||
|
||||
extern void nximage_image(NXWINDOW hwnd);
|
||||
|
||||
/* Image interfaces */
|
||||
|
||||
extern nxgl_mxpixel_t nximage_bgcolor(void);
|
||||
extern nxgl_mxpixel_t nximage_avgcolor(nxgl_mxpixel_t color1, nxgl_mxpixel_t color2);
|
||||
extern void nximage_blitrow(FAR nxgl_mxpixel_t *run, FAR const void **state);
|
||||
|
||||
#endif /* __APPS_EXAMPLES_NXIMAGE_NXIMAGE_H */
|
1274
examples/nximage/nximage_bitmap.c
Normal file
1274
examples/nximage/nximage_bitmap.c
Normal file
File diff suppressed because it is too large
Load Diff
390
examples/nximage/nximage_bkgd.c
Executable file
390
examples/nximage/nximage_bkgd.c
Executable file
@ -0,0 +1,390 @@
|
||||
/****************************************************************************
|
||||
* examples/nximage/nximage_bkgd.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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.h>
|
||||
#include <nuttx/nxglib.h>
|
||||
#include <nuttx/nxfonts.h>
|
||||
|
||||
#include "nximage.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Select renderer -- Some additional logic would be required to support
|
||||
* pixel depths that are not directly addressable (1,2,4, and 24).
|
||||
*/
|
||||
|
||||
#if CONFIG_EXAMPLES_NXIMAGE_BPP == 1
|
||||
# define RENDERER nxf_convert_1bpp
|
||||
#elif CONFIG_EXAMPLES_NXIMAGE_BPP == 2
|
||||
# define RENDERER nxf_convert_2bpp
|
||||
#elif CONFIG_EXAMPLES_NXIMAGE_BPP == 4
|
||||
# define RENDERER nxf_convert_4bpp
|
||||
#elif CONFIG_EXAMPLES_NXIMAGE_BPP == 8
|
||||
# define RENDERER nxf_convert_8bpp
|
||||
#elif CONFIG_EXAMPLES_NXIMAGE_BPP == 16
|
||||
# define RENDERER nxf_convert_16bpp
|
||||
#elif CONFIG_EXAMPLES_NXIMAGE_BPP == 24
|
||||
# define RENDERER nxf_convert_24bpp
|
||||
#elif CONFIG_EXAMPLES_NXIMAGE_BPP == 32
|
||||
# define RENDERER nxf_convert_32bpp
|
||||
#else
|
||||
# error "Unsupported CONFIG_EXAMPLES_NXIMAGE_BPP"
|
||||
#endif
|
||||
|
||||
/* Vertical scaling */
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_YSCALEp5)
|
||||
|
||||
/* Read two rows, output one averaged row */
|
||||
|
||||
#define NINPUT_ROWS 2
|
||||
#define NOUTPUT_ROWS 1
|
||||
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5)
|
||||
/* Read two rows, output three rows */
|
||||
|
||||
#define NINPUT_ROWS 2
|
||||
#define NOUTPUT_ROWS 3
|
||||
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0)
|
||||
/* Read one row, output two rows */
|
||||
|
||||
#define NINPUT_ROWS 1
|
||||
#define NOUTPUT_ROWS 2
|
||||
|
||||
#else
|
||||
/* Read one rows, output one or two rows */
|
||||
|
||||
#define NINPUT_ROWS 1
|
||||
#define NOUTPUT_ROWS 1
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct nximage_run_t
|
||||
{
|
||||
nxgl_mxpixel_t run[SCALED_WIDTH];
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void nximage_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool more, FAR void *arg);
|
||||
static void nximage_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 nximage_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
static void nximage_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
|
||||
FAR void *arg);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const char g_hello[] = "Hello, World!";
|
||||
|
||||
/* Read one or two rows, output one tow or three rows */
|
||||
|
||||
static struct nximage_run_t g_runs[NINPUT_ROWS];
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Background window call table */
|
||||
|
||||
const struct nx_callback_s g_bgcb =
|
||||
{
|
||||
nximage_redraw, /* redraw */
|
||||
nximage_position /* position */
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
, nximage_mousein /* mousein */
|
||||
#endif
|
||||
#ifdef CONFIG_NX_KBD
|
||||
, nximage_kbdin /* my kbdin */
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nximage_redraw
|
||||
*
|
||||
* Description:
|
||||
* NX re-draw handler
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void nximage_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: nximage_position
|
||||
*
|
||||
* Description:
|
||||
* NX position change handler
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void nximage_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_nximage.havepos)
|
||||
{
|
||||
/* Save the background window handle */
|
||||
|
||||
g_nximage.hbkgd = hwnd;
|
||||
|
||||
/* Save the window limits */
|
||||
|
||||
g_nximage.xres = bounds->pt2.x + 1;
|
||||
g_nximage.yres = bounds->pt2.y + 1;
|
||||
|
||||
g_nximage.havepos = true;
|
||||
sem_post(&g_nximage.sem);
|
||||
gvdbg("Have xres=%d yres=%d\n", g_nximage.xres, g_nximage.yres);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nximage_mousein
|
||||
*
|
||||
* Description:
|
||||
* NX mouse input handler
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
static void nximage_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg)
|
||||
{
|
||||
message("nximage_mousein: hwnd=%p pos=(%d,%d) button=%02x\n",
|
||||
hwnd, pos->x, pos->y, buttons);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nximage_kbdin
|
||||
*
|
||||
* Description:
|
||||
* NX keyboard input handler
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
static void nximage_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
|
||||
FAR void *arg)
|
||||
{
|
||||
gvdbg("hwnd=%p nch=%d\n", hwnd, nch);
|
||||
|
||||
/* In this example, there is no keyboard so a keyboard event is not
|
||||
* expected.
|
||||
*/
|
||||
|
||||
message("nximage_kbdin: Unexpected keyboard callback\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nximage_image
|
||||
*
|
||||
* Description:
|
||||
* Put the NuttX logo in the center of the display.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void nximage_image(NXWINDOW hwnd)
|
||||
{
|
||||
FAR const void *state = NULL;
|
||||
FAR struct nxgl_point_s pos;
|
||||
FAR struct nxgl_rect_s dest;
|
||||
FAR const void *src[CONFIG_NX_NPLANES];
|
||||
nxgl_coord_t row;
|
||||
int ret;
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_YSCALEp5) || defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5)
|
||||
int i;
|
||||
#endif
|
||||
|
||||
/* Center the image. Note: these may extend off the display. */
|
||||
|
||||
pos.x = (g_nximage.xres - SCALED_WIDTH) / 2;
|
||||
pos.y = (g_nximage.yres - SCALED_HEIGHT) / 2;
|
||||
|
||||
/* Set up the invariant part of the destination bounding box */
|
||||
|
||||
dest.pt1.x = pos.x;
|
||||
dest.pt2.x = pos.x + SCALED_WIDTH - 1;
|
||||
|
||||
/* Now output the rows */
|
||||
|
||||
for (row = 0; row < IMAGE_HEIGHT; row += NINPUT_ROWS)
|
||||
{
|
||||
/* Read input row(s) */
|
||||
|
||||
nximage_blitrow(g_runs[0].run, &state);
|
||||
#if NINPUT_ROWS > 1
|
||||
nximage_blitrow(g_runs[1].run, &state);
|
||||
#endif
|
||||
|
||||
/* Output rows before averaging */
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5) || defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0)
|
||||
|
||||
/* Output row[0] */
|
||||
|
||||
dest.pt1.y = pos.y;
|
||||
dest.pt2.y = pos.y;
|
||||
|
||||
src[0] = (FAR const void *)g_runs[0].run;
|
||||
#if CONFIG_NX_NPLANES > 1
|
||||
# warning "More logic is needed for the case where CONFIG_NX_PLANES > 1"
|
||||
#endif
|
||||
ret = nx_bitmap((NXWINDOW)hwnd, &dest, src, &pos, SCALED_WIDTH*sizeof(nxgl_mxpixel_t));
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nximage_image: nx_bitmapwindow failed: %d\n", errno);
|
||||
}
|
||||
|
||||
/* Increment the vertical position */
|
||||
|
||||
pos.y++;
|
||||
#endif
|
||||
|
||||
/* Perform averaging */
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_YSCALEp5) || defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5)
|
||||
|
||||
/* Average row[0] and row[1], output results in row[0] */
|
||||
|
||||
for (i = 0; i < SCALED_WIDTH; i++)
|
||||
{
|
||||
g_runs[0].run[i] = nximage_avgcolor(g_runs[0].run[i], g_runs[1].run[i]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Output rows after averaging */
|
||||
|
||||
/* Output row[0] */
|
||||
|
||||
dest.pt1.y = pos.y;
|
||||
dest.pt2.y = pos.y;
|
||||
|
||||
src[0] = (FAR const void *)g_runs[0].run;
|
||||
#if CONFIG_NX_NPLANES > 1
|
||||
# warning "More logic is needed for the case where CONFIG_NX_PLANES > 1"
|
||||
#endif
|
||||
ret = nx_bitmap((NXWINDOW)hwnd, &dest, src, &pos, SCALED_WIDTH*sizeof(nxgl_mxpixel_t));
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nximage_image: nx_bitmapwindow failed: %d\n", errno);
|
||||
}
|
||||
|
||||
/* Increment the vertical position */
|
||||
|
||||
pos.y++;
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5)
|
||||
|
||||
/* Output row[0] and row[1] */
|
||||
|
||||
dest.pt1.y = pos.y;
|
||||
dest.pt2.y = pos.y;
|
||||
|
||||
src[0] = (FAR const void *)g_runs[1].run;
|
||||
#if CONFIG_NX_NPLANES > 1
|
||||
# warning "More logic is needed for the case where CONFIG_NX_PLANES > 1"
|
||||
#endif
|
||||
ret = nx_bitmap((NXWINDOW)hwnd, &dest, src, &pos, SCALED_WIDTH*sizeof(nxgl_mxpixel_t));
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nximage_image: nx_bitmapwindow failed: %d\n", errno);
|
||||
}
|
||||
|
||||
/* Increment the vertical position */
|
||||
|
||||
pos.y++;
|
||||
#endif
|
||||
}
|
||||
}
|
289
examples/nximage/nximage_main.c
Executable file
289
examples/nximage/nximage_main.c
Executable file
@ -0,0 +1,289 @@
|
||||
/****************************************************************************
|
||||
* examples/nximage/nximage_main.c
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <sched.h>
|
||||
#include <pthread.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.h>
|
||||
#include <nuttx/nxglib.h>
|
||||
#include <nuttx/nxfonts.h>
|
||||
|
||||
#include "nximage.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
/* If not specified, assume that the hardware supports one video plane */
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NXIMAGE_VPLANE
|
||||
# define CONFIG_EXAMPLES_NXIMAGE_VPLANE 0
|
||||
#endif
|
||||
|
||||
/* If not specified, assume that the hardware supports one LCD device */
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NXIMAGE_DEVNO
|
||||
# define CONFIG_EXAMPLES_NXIMAGE_DEVNO 0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
struct nximage_data_s g_nximage =
|
||||
{
|
||||
NULL, /* hnx */
|
||||
NULL, /* hbkgd */
|
||||
0, /* xres */
|
||||
0, /* yres */
|
||||
false, /* havpos */
|
||||
{ 0 }, /* sem */
|
||||
NXEXIT_SUCCESS /* exit code */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nximage_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the LCD or framebuffer device (single user mode only), then
|
||||
* open NX.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int nximage_initialize(void)
|
||||
{
|
||||
FAR NX_DRIVERTYPE *dev;
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_EXTERNINIT)
|
||||
/* Use external graphics driver initialization */
|
||||
|
||||
message("nximage_initialize: Initializing external graphics device\n");
|
||||
dev = up_nxdrvinit(CONFIG_EXAMPLES_NXIMAGE_DEVNO);
|
||||
if (!dev)
|
||||
{
|
||||
message("nximage_initialize: up_nxdrvinit failed, devno=%d\n",
|
||||
CONFIG_EXAMPLES_NXIMAGE_DEVNO);
|
||||
g_nximage.code = NXEXIT_EXTINITIALIZE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_NX_LCDDRIVER)
|
||||
int ret;
|
||||
|
||||
/* Initialize the LCD device */
|
||||
|
||||
message("nximage_initialize: Initializing LCD\n");
|
||||
ret = up_lcdinitialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nximage_initialize: up_lcdinitialize failed: %d\n", -ret);
|
||||
g_nximage.code = NXEXIT_LCDINITIALIZE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Get the device instance */
|
||||
|
||||
dev = up_lcdgetdev(CONFIG_EXAMPLES_NXIMAGE_DEVNO);
|
||||
if (!dev)
|
||||
{
|
||||
message("nximage_initialize: up_lcdgetdev failed, devno=%d\n", CONFIG_EXAMPLES_NXIMAGE_DEVNO);
|
||||
g_nximage.code = NXEXIT_LCDGETDEV;
|
||||
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("nximage_initialize: Initializing framebuffer\n");
|
||||
ret = up_fbinitialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nximage_initialize: up_fbinitialize failed: %d\n", -ret);
|
||||
g_nximage.code = NXEXIT_FBINITIALIZE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
dev = up_fbgetvplane(CONFIG_EXAMPLES_NXIMAGE_VPLANE);
|
||||
if (!dev)
|
||||
{
|
||||
message("nximage_initialize: up_fbgetvplane failed, vplane=%d\n", CONFIG_EXAMPLES_NXIMAGE_VPLANE);
|
||||
g_nximage.code = NXEXIT_FBGETVPLANE;
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Then open NX */
|
||||
|
||||
message("nximage_initialize: Open NX\n");
|
||||
g_nximage.hnx = nx_open(dev);
|
||||
if (!g_nximage.hnx)
|
||||
{
|
||||
message("nximage_initialize: nx_open failed: %d\n", errno);
|
||||
g_nximage.code = NXEXIT_NXOPEN;
|
||||
return ERROR;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: user_start/nximage_main
|
||||
*
|
||||
* Description:
|
||||
* Main entry pointer. Configures the basic display resources.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NXIMAGE_BUILTIN
|
||||
# define MAIN_NAME nximage_main
|
||||
# define MAIN_NAME_STRING "nximage_main"
|
||||
#else
|
||||
# define MAIN_NAME user_start
|
||||
# define MAIN_NAME_STRING "user_start"
|
||||
#endif
|
||||
|
||||
int MAIN_NAME(int argc, char *argv[])
|
||||
{
|
||||
nxgl_mxpixel_t color;
|
||||
int ret;
|
||||
|
||||
/* Initialize NX */
|
||||
|
||||
ret = nximage_initialize();
|
||||
message(MAIN_NAME_STRING ": NX handle=%p\n", g_nximage.hnx);
|
||||
if (!g_nximage.hnx || ret < 0)
|
||||
{
|
||||
message(MAIN_NAME_STRING ": Failed to get NX handle: %d\n", errno);
|
||||
g_nximage.code = NXEXIT_NXOPEN;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Set the background to the configured background color */
|
||||
|
||||
color = nximage_bgcolor();
|
||||
message(MAIN_NAME_STRING ": Set background color=%d\n", color);
|
||||
|
||||
ret = nx_setbgcolor(g_nximage.hnx, &color);
|
||||
if (ret < 0)
|
||||
{
|
||||
message(MAIN_NAME_STRING ": nx_setbgcolor failed: %d\n", errno);
|
||||
g_nximage.code = NXEXIT_NXSETBGCOLOR;
|
||||
goto errout_with_nx;
|
||||
}
|
||||
|
||||
/* Get the background window */
|
||||
|
||||
ret = nx_requestbkgd(g_nximage.hnx, &g_bgcb, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
message(MAIN_NAME_STRING ": nx_setbgcolor failed: %d\n", errno);
|
||||
g_nximage.code = NXEXIT_NXREQUESTBKGD;
|
||||
goto errout_with_nx;
|
||||
}
|
||||
|
||||
/* Wait until we have the screen resolution. We'll have this immediately
|
||||
* unless we are dealing with the NX server.
|
||||
*/
|
||||
|
||||
while (!g_nximage.havepos)
|
||||
{
|
||||
(void)sem_wait(&g_nximage.sem);
|
||||
}
|
||||
message(MAIN_NAME_STRING ": Screen resolution (%d,%d)\n", g_nximage.xres, g_nximage.yres);
|
||||
|
||||
/* Now, put up the NuttX logo. */
|
||||
|
||||
nximage_image(g_nximage.hbkgd);
|
||||
|
||||
/* Release background */
|
||||
|
||||
(void)nx_releasebkgd(g_nximage.hbkgd);
|
||||
|
||||
/* Close NX */
|
||||
|
||||
errout_with_nx:
|
||||
message(MAIN_NAME_STRING ": Close NX\n");
|
||||
nx_close(g_nximage.hnx);
|
||||
errout:
|
||||
return g_nximage.code;
|
||||
}
|
Loading…
Reference in New Issue
Block a user