summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-16bit.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd-16bit.c')
-rw-r--r--firmware/drivers/lcd-16bit.c359
1 files changed, 4 insertions, 355 deletions
diff --git a/firmware/drivers/lcd-16bit.c b/firmware/drivers/lcd-16bit.c
index 844db296c6..60dfc7bcf2 100644
--- a/firmware/drivers/lcd-16bit.c
+++ b/firmware/drivers/lcd-16bit.c
@@ -8,7 +8,6 @@
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2005 by Dave Chapman 10 * Copyright (C) 2005 by Dave Chapman
11 *
12 * Copyright (C) 2009 by Karl Kurbjun 11 * Copyright (C) 2009 by Karl Kurbjun
13 * 12 *
14 * Rockbox driver for 16-bit colour LCDs 13 * Rockbox driver for 16-bit colour LCDs
@@ -39,228 +38,14 @@
39#include "bidi.h" 38#include "bidi.h"
40#include "scroll_engine.h" 39#include "scroll_engine.h"
41 40
42enum fill_opt { 41#define ROW_INC LCD_WIDTH
43 OPT_NONE = 0, 42#define COL_INC 1
44 OPT_SET,
45 OPT_COPY
46};
47
48/*** globals ***/
49fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH]
50 IRAM_LCDFRAMEBUFFER CACHEALIGN_AT_LEAST_ATTR(16);
51
52
53static fb_data* lcd_backdrop = NULL;
54static long lcd_backdrop_offset IDATA_ATTR = 0;
55
56static struct viewport default_vp =
57{
58 .x = 0,
59 .y = 0,
60 .width = LCD_WIDTH,
61 .height = LCD_HEIGHT,
62 .font = FONT_SYSFIXED,
63 .drawmode = DRMODE_SOLID,
64 .fg_pattern = LCD_DEFAULT_FG,
65 .bg_pattern = LCD_DEFAULT_BG,
66 .lss_pattern = LCD_DEFAULT_BG,
67 .lse_pattern = LCD_DEFAULT_BG,
68 .lst_pattern = LCD_DEFAULT_BG,
69};
70
71static struct viewport* current_vp IDATA_ATTR = &default_vp;
72
73/* LCD init */
74void lcd_init(void)
75{
76 lcd_clear_display();
77
78 /* Call device specific init */
79 lcd_init_device();
80 scroll_init();
81}
82/*** Viewports ***/
83
84void lcd_set_viewport(struct viewport* vp)
85{
86 if (vp == NULL)
87 current_vp = &default_vp;
88 else
89 current_vp = vp;
90
91#if defined(SIMULATOR)
92 /* Force the viewport to be within bounds. If this happens it should
93 * be considered an error - the viewport will not draw as it might be
94 * expected.
95 */
96 if((unsigned) current_vp->x > (unsigned) LCD_WIDTH
97 || (unsigned) current_vp->y > (unsigned) LCD_HEIGHT
98 || current_vp->x + current_vp->width > LCD_WIDTH
99 || current_vp->y + current_vp->height > LCD_HEIGHT)
100 {
101#if !defined(HAVE_VIEWPORT_CLIP)
102 DEBUGF("ERROR: "
103#else
104 DEBUGF("NOTE: "
105#endif
106 "set_viewport out of bounds: x: %d y: %d width: %d height:%d\n",
107 current_vp->x, current_vp->y,
108 current_vp->width, current_vp->height);
109 }
110
111#endif
112}
113
114void lcd_update_viewport(void)
115{
116 lcd_update_rect(current_vp->x, current_vp->y,
117 current_vp->width, current_vp->height);
118}
119
120void lcd_update_viewport_rect(int x, int y, int width, int height)
121{
122 lcd_update_rect(current_vp->x + x, current_vp->y + y, width, height);
123}
124
125/*** parameter handling ***/
126
127void lcd_set_drawmode(int mode)
128{
129 current_vp->drawmode = mode & (DRMODE_SOLID|DRMODE_INVERSEVID);
130}
131
132int lcd_get_drawmode(void)
133{
134 return current_vp->drawmode;
135}
136
137void lcd_set_foreground(unsigned color)
138{
139 current_vp->fg_pattern = color;
140}
141
142unsigned lcd_get_foreground(void)
143{
144 return current_vp->fg_pattern;
145}
146
147void lcd_set_background(unsigned color)
148{
149 current_vp->bg_pattern = color;
150}
151
152unsigned lcd_get_background(void)
153{
154 return current_vp->bg_pattern;
155}
156
157void lcd_set_selector_start(unsigned color)
158{
159 current_vp->lss_pattern = color;
160}
161
162void lcd_set_selector_end(unsigned color)
163{
164 current_vp->lse_pattern = color;
165}
166
167void lcd_set_selector_text(unsigned color)
168{
169 current_vp->lst_pattern = color;
170}
171
172void lcd_set_drawinfo(int mode, unsigned fg_color, unsigned bg_color)
173{
174 lcd_set_drawmode(mode);
175 current_vp->fg_pattern = fg_color;
176 current_vp->bg_pattern = bg_color;
177}
178
179int lcd_getwidth(void)
180{
181 return current_vp->width;
182}
183
184int lcd_getheight(void)
185{
186 return current_vp->height;
187}
188
189void lcd_setfont(int newfont)
190{
191 current_vp->font = newfont;
192}
193
194int lcd_getfont(void)
195{
196 return current_vp->font;
197}
198
199int lcd_getstringsize(const unsigned char *str, int *w, int *h)
200{
201 return font_getstringsize(str, w, h, current_vp->font);
202}
203
204/*** low-level drawing functions ***/
205 43
206#define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)]) 44#define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
207 45
208static void ICODE_ATTR setpixel(fb_data *address) 46#include "lcd-16bit-common.c"
209{
210 *address = current_vp->fg_pattern;
211}
212
213static void ICODE_ATTR clearpixel(fb_data *address)
214{
215 *address = current_vp->bg_pattern;
216}
217
218static void ICODE_ATTR clearimgpixel(fb_data *address)
219{
220 *address = *(fb_data *)((long)address + lcd_backdrop_offset);
221}
222
223static void ICODE_ATTR flippixel(fb_data *address)
224{
225 *address = ~(*address);
226}
227
228static void ICODE_ATTR nopixel(fb_data *address)
229{
230 (void)address;
231}
232
233lcd_fastpixelfunc_type* const lcd_fastpixelfuncs_bgcolor[8] = {
234 flippixel, nopixel, setpixel, setpixel,
235 nopixel, clearpixel, nopixel, clearpixel
236};
237
238lcd_fastpixelfunc_type* const lcd_fastpixelfuncs_backdrop[8] = {
239 flippixel, nopixel, setpixel, setpixel,
240 nopixel, clearimgpixel, nopixel, clearimgpixel
241};
242
243lcd_fastpixelfunc_type* const * lcd_fastpixelfuncs = lcd_fastpixelfuncs_bgcolor;
244
245void lcd_set_backdrop(fb_data* backdrop)
246{
247 lcd_backdrop = backdrop;
248 if (backdrop)
249 {
250 lcd_backdrop_offset = (long)backdrop - (long)&lcd_framebuffer[0][0];
251 lcd_fastpixelfuncs = lcd_fastpixelfuncs_backdrop;
252 }
253 else
254 {
255 lcd_backdrop_offset = 0;
256 lcd_fastpixelfuncs = lcd_fastpixelfuncs_bgcolor;
257 }
258}
259 47
260fb_data* lcd_get_backdrop(void) 48#include "lcd-bitmap-common.c"
261{
262 return lcd_backdrop;
263}
264 49
265/*** drawing functions ***/ 50/*** drawing functions ***/
266 51
@@ -314,120 +99,6 @@ void lcd_clear_viewport(void)
314 } 99 }
315} 100}
316 101
317/* Clear the whole display */
318void lcd_clear_display(void)
319{
320 struct viewport* old_vp = current_vp;
321
322 current_vp = &default_vp;
323
324 lcd_clear_viewport();
325
326 current_vp = old_vp;
327}
328
329/* Set a single pixel */
330void lcd_drawpixel(int x, int y)
331{
332 if ( ((unsigned)x < (unsigned)current_vp->width)
333 && ((unsigned)y < (unsigned)current_vp->height)
334#if defined(HAVE_VIEWPORT_CLIP)
335 && ((unsigned)x < (unsigned)LCD_WIDTH)
336 && ((unsigned)y < (unsigned)LCD_HEIGHT)
337#endif
338 )
339 lcd_fastpixelfuncs[current_vp->drawmode](LCDADDR(current_vp->x+x, current_vp->y+y));
340}
341
342/* Draw a line */
343void lcd_drawline(int x1, int y1, int x2, int y2)
344{
345 int numpixels;
346 int i;
347 int deltax, deltay;
348 int d, dinc1, dinc2;
349 int x, xinc1, xinc2;
350 int y, yinc1, yinc2;
351 lcd_fastpixelfunc_type *pfunc = lcd_fastpixelfuncs[current_vp->drawmode];
352
353 deltay = abs(y2 - y1);
354 if (deltay == 0)
355 {
356 /* DEBUGF("lcd_drawline() called for horizontal line - optimisation.\n"); */
357 lcd_hline(x1, x2, y1);
358 return;
359 }
360 deltax = abs(x2 - x1);
361 if (deltax == 0)
362 {
363 /* DEBUGF("lcd_drawline() called for vertical line - optimisation.\n"); */
364 lcd_vline(x1, y1, y2);
365 return;
366 }
367 xinc2 = 1;
368 yinc2 = 1;
369
370 if (deltax >= deltay)
371 {
372 numpixels = deltax;
373 d = 2 * deltay - deltax;
374 dinc1 = deltay * 2;
375 dinc2 = (deltay - deltax) * 2;
376 xinc1 = 1;
377 yinc1 = 0;
378 }
379 else
380 {
381 numpixels = deltay;
382 d = 2 * deltax - deltay;
383 dinc1 = deltax * 2;
384 dinc2 = (deltax - deltay) * 2;
385 xinc1 = 0;
386 yinc1 = 1;
387 }
388 numpixels++; /* include endpoints */
389
390 if (x1 > x2)
391 {
392 xinc1 = -xinc1;
393 xinc2 = -xinc2;
394 }
395
396 if (y1 > y2)
397 {
398 yinc1 = -yinc1;
399 yinc2 = -yinc2;
400 }
401
402 x = x1;
403 y = y1;
404
405 for (i = 0; i < numpixels; i++)
406 {
407 if ( ((unsigned)x < (unsigned)current_vp->width)
408 && ((unsigned)y < (unsigned)current_vp->height)
409#if defined(HAVE_VIEWPORT_CLIP)
410 && ((unsigned)x < (unsigned)LCD_WIDTH)
411 && ((unsigned)y < (unsigned)LCD_HEIGHT)
412#endif
413 )
414 pfunc(LCDADDR(x + current_vp->x, y + current_vp->y));
415
416 if (d < 0)
417 {
418 d += dinc1;
419 x += xinc1;
420 y += yinc1;
421 }
422 else
423 {
424 d += dinc2;
425 x += xinc2;
426 y += yinc2;
427 }
428 }
429}
430
431/* Draw a horizontal line (optimised) */ 102/* Draw a horizontal line (optimised) */
432void lcd_hline(int x1, int x2, int y) 103void lcd_hline(int x1, int x2, int y)
433{ 104{
@@ -581,21 +252,6 @@ void lcd_vline(int x, int y1, int y2)
581 while (dst <= dst_end); 252 while (dst <= dst_end);
582} 253}
583 254
584/* Draw a rectangular box */
585void lcd_drawrect(int x, int y, int width, int height)
586{
587 if ((width <= 0) || (height <= 0))
588 return;
589
590 int x2 = x + width - 1;
591 int y2 = y + height - 1;
592
593 lcd_vline(x, y, y2);
594 lcd_vline(x2, y, y2);
595 lcd_hline(x, x2, y);
596 lcd_hline(x, x2, y2);
597}
598
599/* Fill a rectangular area */ 255/* Fill a rectangular area */
600void lcd_fillrect(int x, int y, int width, int height) 256void lcd_fillrect(int x, int y, int width, int height)
601{ 257{
@@ -912,10 +568,3 @@ void lcd_bitmap_transparent(const fb_data *src, int x, int y,
912{ 568{
913 lcd_bitmap_transparent_part(src, 0, 0, width, x, y, width, height); 569 lcd_bitmap_transparent_part(src, 0, 0, width, x, y, width, height);
914} 570}
915
916#define ROW_INC LCD_WIDTH
917#define COL_INC 1
918
919#include "lcd-16bit-common.c"
920
921#include "lcd-bitmap-common.c"