1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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
gCoord 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 gBool 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 = gPowerOn;
g->board = 0; // preinitialize
board_init(g, &((fbPriv *)g->priv)->fbi);
return gTrue;
}
#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 gColor 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 == (gPowermode)g->p.ptr)
return;
switch((gPowermode)g->p.ptr) {
case gPowerOff: case gPowerOn: case gPowerSleep: case gPowerDeepSleep:
board_power(g, (gPowermode)g->p.ptr);
break;
default:
return;
}
g->g.Powermode = (gPowermode)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) {
gCoord 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) {
gCoord 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 */
|