2017-01-20 07:57:18 +00:00
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*
|
2018-10-01 15:32:39 +00:00
|
|
|
* http://ugfx.io/license.html
|
2017-01-20 07:57:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
2018-07-08 00:54:19 +00:00
|
|
|
gCoord linelen; // The number of bytes per display line
|
2017-01-20 07:57:18 +00:00
|
|
|
} 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)
|
2018-11-03 00:51:23 +00:00
|
|
|
#define PIXEL_ADDR(g, pos) (((gU8 *)((fbPriv *)(g)->priv)->fbi.pixels)+pos)
|
2017-01-20 07:57:18 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver exported functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
LLDSPEC gBool gdisp_lld_init(GDisplay *g) {
|
2017-01-20 07:57:18 +00:00
|
|
|
|
|
|
|
// 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
|
2018-07-08 03:51:20 +00:00
|
|
|
g->g.Orientation = gOrientation0;
|
2018-07-08 01:47:36 +00:00
|
|
|
g->g.Powermode = gPowerOn;
|
2017-01-20 07:57:18 +00:00
|
|
|
g->board = 0; // preinitialize
|
|
|
|
board_init(g, &((fbPriv *)g->priv)->fbi);
|
|
|
|
|
2018-06-23 03:02:07 +00:00
|
|
|
return gTrue;
|
2017-01-20 07:57:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#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;
|
2018-11-03 00:51:23 +00:00
|
|
|
gU8 *p;
|
2017-01-20 07:57:18 +00:00
|
|
|
|
|
|
|
#if GDISP_NEED_CONTROL
|
|
|
|
switch(g->g.Orientation) {
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation0:
|
2017-01-20 07:57:18 +00:00
|
|
|
default:
|
|
|
|
pos = PIXIL_POS(g, g->p.x, g->p.y);
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation90:
|
2017-01-20 07:57:18 +00:00
|
|
|
pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-1);
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation180:
|
2017-01-20 07:57:18 +00:00
|
|
|
pos = PIXIL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1);
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation270:
|
2017-01-20 07:57:18 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-07-08 01:19:43 +00:00
|
|
|
LLDSPEC gColor gdisp_lld_get_pixel_color(GDisplay *g) {
|
2017-01-20 07:57:18 +00:00
|
|
|
unsigned pos;
|
2018-11-03 00:51:23 +00:00
|
|
|
gU8 *p;
|
2017-01-20 07:57:18 +00:00
|
|
|
|
|
|
|
#if GDISP_NEED_CONTROL
|
|
|
|
switch(g->g.Orientation) {
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation0:
|
2017-01-20 07:57:18 +00:00
|
|
|
default:
|
|
|
|
pos = PIXIL_POS(g, g->p.x, g->p.y);
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation90:
|
2017-01-20 07:57:18 +00:00
|
|
|
pos = PIXIL_POS(g, g->p.y, g->g.Width-g->p.x-1);
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation180:
|
2017-01-20 07:57:18 +00:00
|
|
|
pos = PIXIL_POS(g, g->g.Width-g->p.x-1, g->g.Height-g->p.y-1);
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation270:
|
2017-01-20 07:57:18 +00:00
|
|
|
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:
|
2018-07-08 01:47:36 +00:00
|
|
|
if (g->g.Powermode == (gPowermode)g->p.ptr)
|
2017-01-20 07:57:18 +00:00
|
|
|
return;
|
2018-07-08 01:47:36 +00:00
|
|
|
switch((gPowermode)g->p.ptr) {
|
|
|
|
case gPowerOff: case gPowerOn: case gPowerSleep: case gPowerDeepSleep:
|
|
|
|
board_power(g, (gPowermode)g->p.ptr);
|
2017-01-20 07:57:18 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2018-07-08 01:47:36 +00:00
|
|
|
g->g.Powermode = (gPowermode)g->p.ptr;
|
2017-01-20 07:57:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case GDISP_CONTROL_ORIENTATION:
|
2018-07-08 03:51:20 +00:00
|
|
|
if (g->g.Orientation == (gOrientation)g->p.ptr)
|
2017-01-20 07:57:18 +00:00
|
|
|
return;
|
2018-07-08 03:51:20 +00:00
|
|
|
switch((gOrientation)g->p.ptr) {
|
|
|
|
case gOrientation0:
|
|
|
|
case gOrientation180:
|
|
|
|
if (g->g.Orientation == gOrientation90 || g->g.Orientation == gOrientation270) {
|
2018-07-08 00:54:19 +00:00
|
|
|
gCoord tmp;
|
2017-01-20 07:57:18 +00:00
|
|
|
|
|
|
|
tmp = g->g.Width;
|
|
|
|
g->g.Width = g->g.Height;
|
|
|
|
g->g.Height = tmp;
|
|
|
|
}
|
|
|
|
break;
|
2018-07-08 03:51:20 +00:00
|
|
|
case gOrientation90:
|
|
|
|
case gOrientation270:
|
|
|
|
if (g->g.Orientation == gOrientation0 || g->g.Orientation == gOrientation180) {
|
2018-07-08 00:54:19 +00:00
|
|
|
gCoord tmp;
|
2017-01-20 07:57:18 +00:00
|
|
|
|
|
|
|
tmp = g->g.Width;
|
|
|
|
g->g.Width = g->g.Height;
|
|
|
|
g->g.Height = tmp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2018-07-08 03:51:20 +00:00
|
|
|
g->g.Orientation = (gOrientation)g->p.ptr;
|
2017-01-20 07:57:18 +00:00
|
|
|
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 */
|