diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-03-28 19:29:30 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-03-28 19:29:30 +0000 |
commit | 61c5ec1bc7de3c47fa8b484392026c68942d8f16 (patch) | |
tree | 3e362aceae490cf42ce2a690d5e86f7fcb1cfe5b /nuttx/graphics/nxconsole | |
parent | 9e5d37dcddb921166d203682b52ce5357f9fe5d7 (diff) | |
download | px4-firmware-61c5ec1bc7de3c47fa8b484392026c68942d8f16.tar.gz px4-firmware-61c5ec1bc7de3c47fa8b484392026c68942d8f16.tar.bz2 px4-firmware-61c5ec1bc7de3c47fa8b484392026c68942d8f16.zip |
The NX console appears to be fully functional
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4536 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/graphics/nxconsole')
-rw-r--r-- | nuttx/graphics/nxconsole/nxcon_font.c | 45 | ||||
-rw-r--r-- | nuttx/graphics/nxconsole/nxcon_internal.h | 47 | ||||
-rwxr-xr-x | nuttx/graphics/nxconsole/nxcon_redraw.c | 21 | ||||
-rw-r--r-- | nuttx/graphics/nxconsole/nxcon_register.c | 21 | ||||
-rw-r--r-- | nuttx/graphics/nxconsole/nxcon_unregister.c | 6 |
5 files changed, 81 insertions, 59 deletions
diff --git a/nuttx/graphics/nxconsole/nxcon_font.c b/nuttx/graphics/nxconsole/nxcon_font.c index c8336a289..436f91477 100644 --- a/nuttx/graphics/nxconsole/nxcon_font.c +++ b/nuttx/graphics/nxconsole/nxcon_font.c @@ -47,6 +47,8 @@ #include <errno.h> #include <debug.h> +#include <nuttx/kmalloc.h> + #include <nuttx/nx/nx.h> #include <nuttx/nx/nxtk.h> #include <nuttx/nx/nxfonts.h> @@ -103,14 +105,16 @@ * Name: nxcon_freeglyph ****************************************************************************/ +#ifdef CONFIG_NXCONSOLE_FONTCACHE static void nxcon_freeglyph(FAR struct nxcon_glyph_s *glyph) { if (glyph->bitmap) { - free(glyph->bitmap); + kfree(glyph->bitmap); } memset(glyph, 0, sizeof(struct nxcon_glyph_s)); } +#endif /**************************************************************************** * Name: nxcon_allocglyph @@ -183,9 +187,6 @@ nxcon_allocglyph(FAR struct nxcon_state_s *priv) luglyph->usecnt = 1; return luglyph; #else - /* TODO: Instead allocating an freeing, just allocate the max glyph once */ - - nxcon_freeglyph(&priv->glyph); return &priv->glyph; #endif } @@ -236,7 +237,6 @@ nxcon_renderglyph(FAR struct nxcon_state_s *priv, #if CONFIG_NXCONSOLE_BPP < 8 nxgl_mxpixel_t pixel; #endif - int bmsize; int row; int col; int ret; @@ -255,29 +255,50 @@ nxcon_renderglyph(FAR struct nxcon_state_s *priv, glyph->width = fbm->metric.width + fbm->metric.xoffset; glyph->height = fbm->metric.height + fbm->metric.yoffset; - /* Allocate memory to hold the glyph with its offsets */ + /* Get the physical width of the glyph in bytes */ glyph->stride = (glyph->width * CONFIG_NXCONSOLE_BPP + 7) / 8; - bmsize = glyph->stride * glyph->height; - glyph->bitmap = (FAR uint8_t *)malloc(bmsize); + + /* Allocate memory to hold the glyph with its offsets */ + +#ifdef CONFIG_NXCONSOLE_FONTCACHE + { + DEBUGASSERT(glyph->bitmap == NULL); + int bmsize = glyph->stride * glyph->height; + glyph->bitmap = (FAR uint8_t *)kmalloc(bmsize); + } +#else + DEBUGASSERT(glyph->bitmap != NULL); +#endif if (glyph->bitmap) { - /* Initialize the glyph memory to the background color */ + /* Initialize the glyph memory to the background color using the + * hard-coded bits-per-pixel (BPP). + * + * TODO: The rest of NX is configured to support multiple devices + * with differing BPP. They logic should be extended to support + * differing BPP's as well. + */ #if CONFIG_NXCONSOLE_BPP < 8 pixel = priv->wcolor[0]; + # if CONFIG_NXCONSOLE_BPP == 1 + /* Pack 1-bit pixels into a 2-bits */ pixel &= 0x01; - pixel = (pixel) << 1 |pixel; + pixel = (pixel) << 1 | pixel; + # endif # if CONFIG_NXCONSOLE_BPP < 4 + /* Pack 2-bit pixels into a nibble */ pixel &= 0x03; - pixel = (pixel) << 2 |pixel; + pixel = (pixel) << 2 | pixel; + # endif /* Pack 4-bit nibbles into a byte */ @@ -323,7 +344,9 @@ nxcon_renderglyph(FAR struct nxcon_state_s *priv, /* Actually, the RENDERER never returns a failure */ gdbg("nxcon_renderglyph: RENDERER failed\n"); +#ifdef CONFIG_NXCONSOLE_FONTCACHE nxcon_freeglyph(glyph); +#endif glyph = NULL; } } diff --git a/nuttx/graphics/nxconsole/nxcon_internal.h b/nuttx/graphics/nxconsole/nxcon_internal.h index f5cbc9c6d..963511b29 100644 --- a/nuttx/graphics/nxconsole/nxcon_internal.h +++ b/nuttx/graphics/nxconsole/nxcon_internal.h @@ -55,53 +55,6 @@ /**************************************************************************** * Definitions ****************************************************************************/ -/* Configuration ************************************************************/ -/* The maximum number of characters that can be remembered */ - -#ifndef CONFIG_NXCONSOLE_MXCHARS -# define CONFIG_NXCONSOLE_MXCHARS 128 -#endif - -/* Font cache -- this is the number or pre-rendered font glyphs that can be - * remembered. - */ - -#ifdef CONFIG_NXCONSOLE_FONTCACHE -# ifndef CONFIG_NXCONSOLE_CACHESIZE -# define CONFIG_NXCONSOLE_CACHESIZE 16 -# endif -#else -# undef CONFIG_NXCONSOLE_CACHESIZE -#endif - -/* Pixel depth */ - -#ifndef CONFIG_NXCONSOLE_BPP -# if !defined(CONFIG_NX_DISABLE_1BPP) -# define CONFIG_NXCONSOLE_BPP 1 -# elif !defined(CONFIG_NX_DISABLE_2BPP) -# define CONFIG_NXCONSOLE_BPP 2 -# elif !defined(CONFIG_NX_DISABLE_4BPP) -# define CONFIG_NXCONSOLE_BPP 4 -# elif !defined(CONFIG_NX_DISABLE_8BPP) -# define CONFIG_NXCONSOLE_BPP 8 -# elif !defined(CONFIG_NX_DISABLE_16BPP) -# define CONFIG_NXCONSOLE_BPP 16 -//#elif !defined(CONFIG_NX_DISABLE_24BPP) -//# define CONFIG_NXCONSOLE_BPP 24 -# elif !defined(CONFIG_NX_DISABLE_32BPP) -# define CONFIG_NXCONSOLE_BPP 32 -# else -# error "No pixel depth provided" -# endif -#endif - -/* Space (in rows) between lines */ - -#ifndef CONFIG_NXCONSOLE_LINESEPARATION -# define CONFIG_NXCONSOLE_LINESEPARATION 2 -#endif - /* NxConsole Definitions ****************************************************/ /* Bitmap flags */ diff --git a/nuttx/graphics/nxconsole/nxcon_redraw.c b/nuttx/graphics/nxconsole/nxcon_redraw.c index 23bebd622..1a40a7ee1 100755 --- a/nuttx/graphics/nxconsole/nxcon_redraw.c +++ b/nuttx/graphics/nxconsole/nxcon_redraw.c @@ -41,6 +41,7 @@ #include <stdint.h> #include <stdbool.h> +#include <semaphore.h> #include <assert.h> #include <errno.h> #include <debug.h> @@ -112,6 +113,25 @@ void nxcon_redraw(NXCONSOLE handle, FAR const struct nxgl_rect_s *rect, bool mor priv = (FAR struct nxcon_state_s *)handle; + /* Get exclusive access to the state structure */ + + do + { + ret = sem_wait(&priv->exclsem); + + /* Check for errors */ + + if (ret < 0) + { + /* The only expected error is if the wait failed because of it + * was interrupted by a signal. + */ + + DEBUGASSERT(errno == EINTR); + } + } + while (ret < 0); + /* Fill the rectangular region with the window background color */ ret = priv->ops->fill(priv, rect, priv->wndo.wcolor); @@ -128,4 +148,5 @@ void nxcon_redraw(NXCONSOLE handle, FAR const struct nxgl_rect_s *rect, bool mor { nxcon_fillchar(priv, rect, &priv->bm[i]); } + ret = sem_post(&priv->exclsem); } diff --git a/nuttx/graphics/nxconsole/nxcon_register.c b/nuttx/graphics/nxconsole/nxcon_register.c index cc878b239..78f6a1051 100644 --- a/nuttx/graphics/nxconsole/nxcon_register.c +++ b/nuttx/graphics/nxconsole/nxcon_register.c @@ -120,13 +120,32 @@ FAR struct nxcon_state_s * priv->fwidth = fontset->mxwidth; priv->spwidth = fontset->spwidth; - /* Set up the text caches */ + /* Set up the text cache */ priv->maxchars = CONFIG_NXCONSOLE_MXCHARS; + + /* Set up the font glyph bitmap cache (if enabled) */ + #ifdef CONFIG_NXCONSOLE_FONTCACHE priv->maxglyphs = CONFIG_NXCONSOLE_CACHESIZE; #endif + /* Pre-allocate maximal sized glyph bitmap memory (only if we are not + * using the glyph cache. + */ + +#ifndef CONFIG_NXCONSOLE_FONTCACHE + { + int allocsize = (priv->fheight * priv->fwidth * CONFIG_NXCONSOLE_BPP + 7) >> 3; + priv->glyph.bitmap = (FAR uint8_t *)kmalloc(allocsize); + if (!priv->glyph.bitmap) + { + gdbg("Failed to allocate glyph memory\n"); + goto errout; + } + } +#endif + /* Set the initial display position */ nxcon_home(priv); diff --git a/nuttx/graphics/nxconsole/nxcon_unregister.c b/nuttx/graphics/nxconsole/nxcon_unregister.c index 8a19736ed..25dbd40c6 100644 --- a/nuttx/graphics/nxconsole/nxcon_unregister.c +++ b/nuttx/graphics/nxconsole/nxcon_unregister.c @@ -97,6 +97,12 @@ void nxcon_unregister(NXCONSOLE handle) priv = (FAR struct nxcon_state_s *)handle; sem_destroy(&priv->exclsem); + /* Free the pre-allocated glyph bitmap */ + +#ifndef CONFIG_NXCONSOLE_FONTCACHE + kfree(priv->glyph.bitmap); +#endif + /* Unregister the driver */ snprintf(devname, NX_DEVNAME_SIZE, NX_DEVNAME_FORMAT, priv->minor); |