diff options
author | inmarket <inmarket@ugfx.org> | 2017-01-20 17:57:18 +1000 |
---|---|---|
committer | inmarket <inmarket@ugfx.org> | 2017-01-20 17:57:18 +1000 |
commit | f57f6be212c779635a6ab9b80dcec3d1778ce8ba (patch) | |
tree | e8ab5d739df43c1f06d3cad08597e35a7fbc83ef | |
parent | 5502aef3e56db8665cba8885f4e5ef050f050f2e (diff) | |
download | uGFX-f57f6be212c779635a6ab9b80dcec3d1778ce8ba.tar.gz uGFX-f57f6be212c779635a6ab9b80dcec3d1778ce8ba.tar.bz2 uGFX-f57f6be212c779635a6ab9b80dcec3d1778ce8ba.zip |
Added Fb24bpp driver for RGB888 and BGR888 packed framebuffer displays
-rw-r--r-- | changelog.txt | 1 | ||||
-rw-r--r-- | drivers/gdisp/Fb24bpp/board_fb24bpp_template.h | 57 | ||||
-rw-r--r-- | drivers/gdisp/Fb24bpp/driver.mk | 2 | ||||
-rw-r--r-- | drivers/gdisp/Fb24bpp/gdisp_lld_config.h | 31 | ||||
-rw-r--r-- | drivers/gdisp/Fb24bpp/gdisp_lld_fb24bpp.c | 196 | ||||
-rw-r--r-- | drivers/gdisp/Fb24bpp/readme.txt | 13 | ||||
-rw-r--r-- | drivers/gdisp/framebuffer/readme.txt | 6 |
7 files changed, 306 insertions, 0 deletions
diff --git a/changelog.txt b/changelog.txt index cc04a7be..ec655b0f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -16,6 +16,7 @@ FEATURE: Added GDISP_IMAGE_PNG_Z_BUFFER_SIZE configuration option FEATURE: Added GDISP_IMAGE_GIF_BLIT_BUFFER_SIZE configuration option FIX: Fixed extra dots when drawing anti-aliased fonts with wordwrap FEATURE: Increase non-UTF8 font support to 0 to 255 rather than just the true ascii set +FEATURE: Added Fb24bpp driver for RGB888 and BGR888 packed framebuffer displays *** Release 2.7 *** diff --git a/drivers/gdisp/Fb24bpp/board_fb24bpp_template.h b/drivers/gdisp/Fb24bpp/board_fb24bpp_template.h new file mode 100644 index 00000000..a8c669c9 --- /dev/null +++ b/drivers/gdisp/Fb24bpp/board_fb24bpp_template.h @@ -0,0 +1,57 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +// Set this to your frame buffer pixel format. +#ifndef GDISP_LLD_PIXELFORMAT + #define GDISP_LLD_PIXELFORMAT GDISP_PIXELFORMAT_BGR888 +#endif + +// Uncomment this if your frame buffer device requires flushing +//#define GDISP_HARDWARE_FLUSH TRUE + +#ifdef GDISP_DRIVER_VMT + + static void board_init(GDisplay *g, fbInfo *fbi) { + // TODO: Initialize your frame buffer device here + + // TODO: Set the details of the frame buffer + g->g.Width = 640; + g->g.Height = 480; + g->g.Backlight = 100; + g->g.Contrast = 50; + fbi->linelen = g->g.Width * 3; // bytes per row - you might need to round this up to a dword boundary. + fbi->pixels = 0; // pointer to the memory frame buffer + } + + #if GDISP_HARDWARE_FLUSH + static void board_flush(GDisplay *g) { + // TODO: Can be an empty function if your hardware doesn't support this + (void) g; + } + #endif + + #if GDISP_NEED_CONTROL + static void board_backlight(GDisplay *g, uint8_t percent) { + // TODO: Can be an empty function if your hardware doesn't support this + (void) g; + (void) percent; + } + + static void board_contrast(GDisplay *g, uint8_t percent) { + // TODO: Can be an empty function if your hardware doesn't support this + (void) g; + (void) percent; + } + + static void board_power(GDisplay *g, powermode_t pwr) { + // TODO: Can be an empty function if your hardware doesn't support this + (void) g; + (void) pwr; + } + #endif + +#endif /* GDISP_LLD_BOARD_IMPLEMENTATION */ diff --git a/drivers/gdisp/Fb24bpp/driver.mk b/drivers/gdisp/Fb24bpp/driver.mk new file mode 100644 index 00000000..33477866 --- /dev/null +++ b/drivers/gdisp/Fb24bpp/driver.mk @@ -0,0 +1,2 @@ +GFXINC += $(GFXLIB)/drivers/gdisp/Fb24bpp +GFXSRC += $(GFXLIB)/drivers/gdisp/Fb24bpp/gdisp_lld_fb24bpp.c diff --git a/drivers/gdisp/Fb24bpp/gdisp_lld_config.h b/drivers/gdisp/Fb24bpp/gdisp_lld_config.h new file mode 100644 index 00000000..40798ea9 --- /dev/null +++ b/drivers/gdisp/Fb24bpp/gdisp_lld_config.h @@ -0,0 +1,31 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#ifndef _GDISP_LLD_CONFIG_H +#define _GDISP_LLD_CONFIG_H + +#if GFX_USE_GDISP + +/*===========================================================================*/ +/* Driver hardware support. */ +/*===========================================================================*/ + +#define GDISP_HARDWARE_DRAWPIXEL TRUE +#define GDISP_HARDWARE_PIXELREAD TRUE +#define GDISP_HARDWARE_CONTROL TRUE + +// Any other support comes from the board file +#include "board_fb24bpp.h" + +// This driver supports a packed 24bit per pixel framebuffer +#ifndef GDISP_LLD_PIXELFORMAT + #error "GDISP Fb24bpp: You must specify a GDISP_LLD_PIXELFORMAT in your board_fb24bpp.h or your makefile" +#endif + +#endif /* GFX_USE_GDISP */ + +#endif /* _GDISP_LLD_CONFIG_H */ diff --git a/drivers/gdisp/Fb24bpp/gdisp_lld_fb24bpp.c b/drivers/gdisp/Fb24bpp/gdisp_lld_fb24bpp.c new file mode 100644 index 00000000..4d981ce4 --- /dev/null +++ b/drivers/gdisp/Fb24bpp/gdisp_lld_fb24bpp.c @@ -0,0 +1,196 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#include "gfx.h" + +#if GFX_USE_GDISP + +#define GDISP_DRIVER_VMT GDISPVMT_fb24bpp +#include "gdisp_lld_config.h" +#include "../../../src/gdisp/gdisp_driver.h" + +typedef struct fbInfo { + void * pixels; // The pixel buffer + coord_t linelen; // The number of bytes per display line + } fbInfo; + +#include "board_fb24bpp.h" + +#if GDISP_LLD_PIXELFORMAT != GDISP_PIXELFORMAT_RGB888 && GDISP_LLD_PIXELFORMAT != GDISP_PIXELFORMAT_BGR888 + #error "GDISP Fb24bpp: Only RGB888 and BGR888 color formats are supported by this driver" +#endif + +typedef struct fbPriv { + fbInfo fbi; // Display information + } fbPriv; + +/*===========================================================================*/ +/* Driver local routines . */ +/*===========================================================================*/ + +#define PIXIL_POS(g, x, y) ((y) * ((fbPriv *)(g)->priv)->fbi.linelen + (x) * 3) +#define PIXEL_ADDR(g, pos) (((uint8_t *)((fbPriv *)(g)->priv)->fbi.pixels)+pos) + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +LLDSPEC bool_t gdisp_lld_init(GDisplay *g) { + + // Initialize the private structure + if (!(g->priv = gfxAlloc(sizeof(fbPriv)))) + gfxHalt("GDISP Fb24bpp: Failed to allocate private memory"); + ((fbPriv *)g->priv)->fbi.pixels = 0; + ((fbPriv *)g->priv)->fbi.linelen = 0; + + // Initialize the GDISP structure + g->g.Orientation = GDISP_ROTATE_0; + g->g.Powermode = powerOn; + g->board = 0; // preinitialize + board_init(g, &((fbPriv *)g->priv)->fbi); + + return TRUE; +} + +#if GDISP_HARDWARE_FLUSH + LLDSPEC void gdisp_lld_flush(GDisplay *g) { + board_flush(g); + } +#endif + +LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) { + unsigned pos; + uint8_t *p; + + #if GDISP_NEED_CONTROL + switch(g->g.Orientation) { + case GDISP_ROTATE_0: + default: + pos = PIXIL_POS(g, g->p.x, g->p.y); + break; + case GDISP_ROTATE_90: + pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-1); + break; + case GDISP_ROTATE_180: + pos = PIXIL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1); + break; + case GDISP_ROTATE_270: + pos = PIXIL_POS(g, g->g.Height-g->p.y-1, g->p.x); + break; + } + #else + pos = PIXIL_POS(g, g->p.x, g->p.y); + #endif + + p = PIXEL_ADDR(g, pos); + + #if GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888 + p[0] = RED_OF(g->p.color); + p[1] = GREEN_OF(g->p.color); + p[2] = BLUE_OF(g->p.color); + #else + p[0] = BLUE_OF(g->p.color); + p[1] = GREEN_OF(g->p.color); + p[2] = RED_OF(g->p.color); + #endif +} + +LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) { + unsigned pos; + uint8_t *p; + + #if GDISP_NEED_CONTROL + switch(g->g.Orientation) { + case GDISP_ROTATE_0: + default: + pos = PIXIL_POS(g, g->p.x, g->p.y); + break; + case GDISP_ROTATE_90: + pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-1); + break; + case GDISP_ROTATE_180: + pos = PIXIL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1); + break; + case GDISP_ROTATE_270: + pos = PIXIL_POS(g, g->g.Height-g->p.y-1, g->p.x); + break; + } + #else + pos = PIXIL_POS(g, g->p.x, g->p.y); + #endif + + p = PIXEL_ADDR(g, pos); + + #if GDISP_LLD_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888 + return RGB2COLOR(p[0], p[1], p[2]); + #else + return RGB2COLOR(p[2], p[1], p[0]); + #endif +} + +#if GDISP_NEED_CONTROL + LLDSPEC void gdisp_lld_control(GDisplay *g) { + switch(g->p.x) { + case GDISP_CONTROL_POWER: + if (g->g.Powermode == (powermode_t)g->p.ptr) + return; + switch((powermode_t)g->p.ptr) { + case powerOff: case powerOn: case powerSleep: case powerDeepSleep: + board_power(g, (powermode_t)g->p.ptr); + break; + default: + return; + } + g->g.Powermode = (powermode_t)g->p.ptr; + return; + + case GDISP_CONTROL_ORIENTATION: + if (g->g.Orientation == (orientation_t)g->p.ptr) + return; + switch((orientation_t)g->p.ptr) { + case GDISP_ROTATE_0: + case GDISP_ROTATE_180: + if (g->g.Orientation == GDISP_ROTATE_90 || g->g.Orientation == GDISP_ROTATE_270) { + coord_t tmp; + + tmp = g->g.Width; + g->g.Width = g->g.Height; + g->g.Height = tmp; + } + break; + case GDISP_ROTATE_90: + case GDISP_ROTATE_270: + if (g->g.Orientation == GDISP_ROTATE_0 || g->g.Orientation == GDISP_ROTATE_180) { + coord_t tmp; + + tmp = g->g.Width; + g->g.Width = g->g.Height; + g->g.Height = tmp; + } + break; + default: + return; + } + g->g.Orientation = (orientation_t)g->p.ptr; + return; + + case GDISP_CONTROL_BACKLIGHT: + if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100; + board_backlight(g, (unsigned)g->p.ptr); + g->g.Backlight = (unsigned)g->p.ptr; + return; + + case GDISP_CONTROL_CONTRAST: + if ((unsigned)g->p.ptr > 100) g->p.ptr = (void *)100; + board_contrast(g, (unsigned)g->p.ptr); + g->g.Contrast = (unsigned)g->p.ptr; + return; + } + } +#endif + +#endif /* GFX_USE_GDISP */ diff --git a/drivers/gdisp/Fb24bpp/readme.txt b/drivers/gdisp/Fb24bpp/readme.txt new file mode 100644 index 00000000..83e7f56b --- /dev/null +++ b/drivers/gdisp/Fb24bpp/readme.txt @@ -0,0 +1,13 @@ +To use this driver: + +1. Add in your gfxconf.h: + a) #define GFX_USE_GDISP TRUE + +2. To your makefile add the following lines: + include $(GFXLIB)/gfx.mk + include $(GFXLIB)/drivers/gdisp/Fb24bpp/driver.mk + +3. Add a board_fb24bpp.h to you project directory (or board directory) + base on one of the templates. + +Note: This driver supports RGB888 and BGR888 packed framebuffer formats. diff --git a/drivers/gdisp/framebuffer/readme.txt b/drivers/gdisp/framebuffer/readme.txt index d07b5dfb..e13321e4 100644 --- a/drivers/gdisp/framebuffer/readme.txt +++ b/drivers/gdisp/framebuffer/readme.txt @@ -9,3 +9,9 @@ To use this driver: 3. Add a board_framebuffer.h to you project directory (or board directory) base on one of the templates. + +Note: This driver supports framebuffers in byte, word or dword sized pixels. + It does not support packed pixel formats eg 1, 2, 4, 15 or 24 bits per pixel + except where the framebuffer format expects those in memory as 1 byte, 2 bytes or 4 bytes per pixel. + +Note: For RGB888 and BGR888 packed framebuffer formats use the Fb24bpp driver instead. |