static void nxeg_initstate(FAR struct nxeg_state_s *st, int wnum, nxgl_mxpixel_t color) { #ifdef CONFIG_NX_KBD FAR const struct nx_font_s *fontset; #endif /* Initialize the window number (used for debug output only) and color * (used for redrawing the window) */ st->wnum = wnum; st->color[0] = color; /* Get information about the font set being used and save this in the * state structure */ #ifdef CONFIG_NX_KBD fontset = nxf_getfontset(g_fonthandle); st->nchars = 0; st->nglyphs = 0; st->height = fontset->mxheight; st->width = fontset->mxwidth; st->spwidth = fontset->spwidth; #endif }
FAR struct nxterm_state_s * nxterm_register(NXTERM handle, FAR struct nxterm_window_s *wndo, FAR const struct nxterm_operations_s *ops, int minor) { FAR struct nxterm_state_s *priv; FAR const struct nx_font_s *fontset; char devname[NX_DEVNAME_SIZE]; NXHANDLE hfont; int ret; DEBUGASSERT(handle && wndo && ops && (unsigned)minor < 256); /* Allocate the driver structure */ priv = (FAR struct nxterm_state_s *)kmm_zalloc(sizeof(struct nxterm_state_s)); if (!priv) { gerr("ERROR: Failed to allocate the NX driver structure\n"); return NULL; } /* Initialize the driver structure */ priv->ops = ops; priv->handle = handle; priv->minor = minor; memcpy(&priv->wndo, wndo, sizeof(struct nxterm_window_s)); nxsem_init(&priv->exclsem, 0, 1); #ifdef CONFIG_DEBUG_FEATURES priv->holder = NO_HOLDER; #endif #ifdef CONFIG_NXTERM_NXKBDIN /* The waitsem semaphore is used for signaling and, hence, should not have * priority inheritance enabled. */ nxsem_init(&priv->waitsem, 0, 0); nxsem_setprotocol(&priv->waitsem, SEM_PRIO_NONE); #endif /* Connect to the font cache for the configured font characteristics */ priv->fcache = nxf_cache_connect(wndo->fontid, wndo->fcolor[0], wndo->wcolor[0], CONFIG_NXTERM_BPP, CONFIG_NXTERM_CACHESIZE); if (priv->fcache == NULL) { gerr("ERROR: Failed to connect to font cache for font ID %d: %d\n", wndo->fontid, errno); goto errout; } /* Get the handle of the font managed by the font cache */ hfont = nxf_cache_getfonthandle(priv->fcache); if (hfont == NULL) { gerr("ERROR: Failed to get handlr for font ID %d: %d\n", wndo->fontid, errno); goto errout; } /* Get information about the font set being used and save this in the * state structure */ fontset = nxf_getfontset(hfont); priv->fheight = fontset->mxheight; priv->fwidth = fontset->mxwidth; priv->spwidth = fontset->spwidth; /* Set up the text cache */ priv->maxchars = CONFIG_NXTERM_MXCHARS; /* Set the initial display position */ nxterm_home(priv); /* Show the cursor */ priv->cursor.code = CONFIG_NXTERM_CURSORCHAR; nxterm_showcursor(priv); /* Register the driver */ snprintf(devname, NX_DEVNAME_SIZE, NX_DEVNAME_FORMAT, minor); ret = register_driver(devname, &g_nxterm_drvrops, 0666, priv); if (ret < 0) { gerr("ERROR: Failed to register %s\n", devname); } return (NXTERM)priv; errout: kmm_free(priv); return NULL; }
void nxhello_hello(NXWINDOW hwnd) { FAR const struct nx_font_s *fontset; FAR const struct nx_fontbitmap_s *fbm; FAR uint8_t *glyph; FAR const char *ptr; FAR struct nxgl_point_s pos; FAR struct nxgl_rect_s dest; FAR const void *src[CONFIG_NX_NPLANES]; unsigned int glyphsize; unsigned int mxstride; int ret; /* Get information about the font we are going to use */ fontset = nxf_getfontset(g_nxhello.hfont); /* Allocate a bit of memory to hold the largest rendered font */ mxstride = (fontset->mxwidth * CONFIG_EXAMPLES_NXHELLO_BPP + 7) >> 3; glyphsize = (unsigned int)fontset->mxheight * mxstride; glyph = (FAR uint8_t*)malloc(glyphsize); /* NOTE: no check for failure to allocate the memory. In a real application * you would need to handle that event. */ /* Get a position so the the "Hello, World!" string will be centered on the * display. */ nxhello_center(&pos, fontset); message("nxhello_hello: Position (%d,%d)\n", pos.x, pos.y); /* Now we can say "hello" in the center of the display. */ for (ptr = g_hello; *ptr; ptr++) { /* Get the bitmap font for this ASCII code */ fbm = nxf_getbitmap(g_nxhello.hfont, *ptr); if (fbm) { uint8_t fheight; /* Height of this glyph (in rows) */ uint8_t fwidth; /* Width of this glyph (in pixels) */ uint8_t fstride; /* Width of the glyph row (in bytes) */ /* Get information about the font bitmap */ fwidth = fbm->metric.width + fbm->metric.xoffset; fheight = fbm->metric.height + fbm->metric.yoffset; fstride = (fwidth * CONFIG_EXAMPLES_NXHELLO_BPP + 7) >> 3; /* Initialize the glyph memory to the background color */ nxhello_initglyph(glyph, fheight, fwidth, fstride); /* Then render the glyph into the allocated memory */ #if CONFIG_NX_NPLANES > 1 # warning "More logic is needed for the case where CONFIG_NX_PLANES > 1" #endif (void)RENDERER((FAR nxgl_mxpixel_t*)glyph, fheight, fwidth, fstride, fbm, CONFIG_EXAMPLES_NXHELLO_FONTCOLOR); /* Describe the destination of the font with a rectangle */ dest.pt1.x = pos.x; dest.pt1.y = pos.y; dest.pt2.x = pos.x + fwidth - 1; dest.pt2.y = pos.y + fheight - 1; /* Then put the font on the display */ src[0] = (FAR const void *)glyph; #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, fstride); if (ret < 0) { message("nxhello_write: nx_bitmapwindow failed: %d\n", errno); } /* Skip to the right the width of the font */ pos.x += fwidth; } else { /* No bitmap (probably because the font is a space). Skip to the * right the width of a space. */ pos.x += fontset->spwidth; } }
FAR struct nxcon_state_s * nxcon_register(NXCONSOLE handle, FAR struct nxcon_window_s *wndo, FAR const struct nxcon_operations_s *ops, int minor) { FAR struct nxcon_state_s *priv; char devname[NX_DEVNAME_SIZE]; int ret; DEBUGASSERT(handle && wndo && ops && (unsigned)minor < 256); /* Allocate the driver structure */ priv = (FAR struct nxcon_state_s *)kzalloc(sizeof(struct nxcon_state_s)); if (!priv) { gdbg("Failed to allocate the NX driver structure\n"); return NULL; } /* Initialize the driver structure */ priv->ops = ops; priv->handle = handle; priv->minor = minor; memcpy(&priv->wndo, wndo, sizeof( struct nxcon_window_s)); sem_init(&priv->exclsem, 0, 1); #ifdef CONFIG_DEBUG priv->holder = NO_HOLDER; #endif #ifdef CONFIG_NXCONSOLE_NXKBDIN sem_init(&priv->waitsem, 0, 0); #endif /* Select the font */ priv->font = nxf_getfonthandle(wndo->fontid); if (!priv->font) { gdbg("Failed to get font ID %d: %d\n", wndo->fontid, errno); goto errout; } FAR const struct nx_font_s *fontset; /* Get information about the font set being used and save this in the * state structure */ fontset = nxf_getfontset(priv->font); priv->fheight = fontset->mxheight; priv->fwidth = fontset->mxwidth; priv->spwidth = fontset->spwidth; /* Set up the text cache */ priv->maxchars = CONFIG_NXCONSOLE_MXCHARS; /* Set up the font glyph bitmap cache */ priv->maxglyphs = CONFIG_NXCONSOLE_CACHESIZE; /* Set the initial display position */ nxcon_home(priv); /* Show the cursor */ priv->cursor.code = CONFIG_NXCONSOLE_CURSORCHAR; nxcon_showcursor(priv); /* Register the driver */ snprintf(devname, NX_DEVNAME_SIZE, NX_DEVNAME_FORMAT, minor); ret = register_driver(devname, &g_nxcon_drvrops, 0666, priv); if (ret < 0) { gdbg("Failed to register %s\n", devname); } return (NXCONSOLE)priv; errout: kfree(priv); return NULL; }