aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-05-22 17:21:19 +1000
committerinmarket <andrewh@inmarket.com.au>2014-05-22 17:21:19 +1000
commit285bd0f4d66fa3161a80bf6711d1bef226b17fe3 (patch)
tree93666d6d8831a67f2e6cd6fd008bfa0bf7c4b4d9 /drivers
parent52cfaf00ccd35f5a0740a489a1a2af64c800b537 (diff)
downloaduGFX-285bd0f4d66fa3161a80bf6711d1bef226b17fe3.tar.gz
uGFX-285bd0f4d66fa3161a80bf6711d1bef226b17fe3.tar.bz2
uGFX-285bd0f4d66fa3161a80bf6711d1bef226b17fe3.zip
GDISP framebuffer driver + an implementation for the linux kernel framebuffer device
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gdisp/framebuffer/board_framebuffer_template.h57
-rw-r--r--drivers/gdisp/framebuffer/driver.mk2
-rw-r--r--drivers/gdisp/framebuffer/gdisp_lld_config.h38
-rw-r--r--drivers/gdisp/framebuffer/gdisp_lld_framebuffer.c175
-rw-r--r--drivers/gdisp/framebuffer/readme.txt11
5 files changed, 283 insertions, 0 deletions
diff --git a/drivers/gdisp/framebuffer/board_framebuffer_template.h b/drivers/gdisp/framebuffer/board_framebuffer_template.h
new file mode 100644
index 00000000..0ee08ef2
--- /dev/null
+++ b/drivers/gdisp/framebuffer/board_framebuffer_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 * sizeof(LLDCOLOR_TYPE); // bytes per row
+ 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/framebuffer/driver.mk b/drivers/gdisp/framebuffer/driver.mk
new file mode 100644
index 00000000..6b473c72
--- /dev/null
+++ b/drivers/gdisp/framebuffer/driver.mk
@@ -0,0 +1,2 @@
+GFXINC += $(GFXLIB)/drivers/gdisp/framebuffer
+GFXSRC += $(GFXLIB)/drivers/gdisp/framebuffer/gdisp_lld_framebuffer.c
diff --git a/drivers/gdisp/framebuffer/gdisp_lld_config.h b/drivers/gdisp/framebuffer/gdisp_lld_config.h
new file mode 100644
index 00000000..08dbbb39
--- /dev/null
+++ b/drivers/gdisp/framebuffer/gdisp_lld_config.h
@@ -0,0 +1,38 @@
+/*
+ * 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_framebuffer.h"
+
+#ifndef GDISP_LLD_PIXELFORMAT
+ #error "GDISP FrameBuffer: You must specify a GDISP_LLD_PIXELFORMAT in your board_framebuffer.h or your makefile"
+#endif
+
+// This driver currently only supports unpacked formats with more than 8 bits per pixel
+// that is, we only support GRAY_SCALE with 8 bits per pixel or any unpacked TRUE_COLOR format.
+// Note: At the time this file is included we have not calculated all our color
+// definitions so we need to do this by hand.
+#if (GDISP_LLD_PIXELFORMAT & 0x4000) && (GDISP_LLD_PIXELFORMAT & 0xFF) != 8
+ #error "GDISP FrameBuffer: This driver does not support the specified GDISP_LLD_PIXELFORMAT"
+#endif
+
+#endif /* GFX_USE_GDISP */
+
+#endif /* _GDISP_LLD_CONFIG_H */
diff --git a/drivers/gdisp/framebuffer/gdisp_lld_framebuffer.c b/drivers/gdisp/framebuffer/gdisp_lld_framebuffer.c
new file mode 100644
index 00000000..6e38b5f4
--- /dev/null
+++ b/drivers/gdisp/framebuffer/gdisp_lld_framebuffer.c
@@ -0,0 +1,175 @@
+/*
+ * 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
+
+typedef struct fbInfo {
+ void * pixels; // The pixel buffer
+ coord_t linelen; // The number of bytes per display line
+ } fbInfo;
+
+#define GDISP_DRIVER_VMT GDISPVMT_framebuffer
+#include "drivers/gdisp/framebuffer/gdisp_lld_config.h"
+#include "src/gdisp/driver.h"
+#include "board_framebuffer.h"
+
+typedef struct fbPriv {
+ fbInfo fbi; // Display information
+ } fbPriv;
+
+/*===========================================================================*/
+/* Driver local routines . */
+/*===========================================================================*/
+
+#define PIXIL_POS(g, x, y) ((y) * ((fbPriv *)(g)->priv)->fbi.linelen + (x) * sizeof(LLDCOLOR_TYPE))
+#define PIXEL_ADDR(g, pos) ((LLDCOLOR_TYPE *)(((char *)((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 Framebuffer: 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;
+
+ #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
+
+ PIXEL_ADDR(g, pos)[0] = gdispColor2Native(g->p.color);
+}
+
+LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
+ unsigned pos;
+ LLDCOLOR_TYPE color;
+
+ #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
+
+ color = PIXEL_ADDR(g, pos)[0];
+ return gdispNative2Color(color);
+}
+
+#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/framebuffer/readme.txt b/drivers/gdisp/framebuffer/readme.txt
new file mode 100644
index 00000000..d07b5dfb
--- /dev/null
+++ b/drivers/gdisp/framebuffer/readme.txt
@@ -0,0 +1,11 @@
+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/framebuffer/driver.mk
+
+3. Add a board_framebuffer.h to you project directory (or board directory)
+ base on one of the templates.