A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __LCD_H__
23#define __LCD_H__
24
25#include <stdbool.h>
26#include <stddef.h>
27#include "cpu.h"
28#include "config.h"
29#include "events.h"
30
31
32/* Frame buffer stride
33 *
34 * Stride describes the amount that you need to increment to get to the next
35 * line. For screens that have the pixels in contiguous horizontal strips
36 * stride should be equal to the image width.
37 *
38 * For example, if the screen pixels are layed out as follows:
39 *
40 * width0 width1 width2 widthX-1
41 * ------ ------ ------ ------------------ --------
42 * height0 | pixel0 pixel1 pixel2 ----------------> pixelX-1
43 * height1 | pixelX
44 *
45 * then you need to add X pixels to get to the next line. (the next line
46 * in this case is height1).
47 *
48 * Similarly, if the screen has the pixels in contiguous vertical strips
49 * the stride would be equal to the image height.
50 *
51 * For example if the screen pixels are layed out as follows:
52 *
53 * width0 width1
54 * ------ ------
55 * height0 | pixel0 pixelY
56 * height1 | pixel1
57 * height2 | pixel2
58 * | | |
59 * \|/ | \|/
60 * heightY-1 | pixelY-1
61 *
62 * then you would need to add Y pixels to get to the next line (the next
63 * line in this case is from width0 to width1).
64 *
65 * The remote might have a different stride than the main screen so the screen
66 * number needs to be passed to the STRIDE macro so that the appropriate height
67 * or width can be passed to the lcd_bitmap, or lcd_remote_bitmap calls.
68 *
69 * STRIDE_REMOTE and STRIDE_MAIN should never be used when it is not clear whether
70 * lcd_remote_bitmap calls or lcd_bitmap calls are being made (for example the
71 * screens api).
72 *
73 * Screen should always use the screen_type enum that is at the top of this
74 * header.
75 */
76enum screen_type {
77 SCREEN_MAIN
78#ifdef HAVE_REMOTE_LCD
79 ,SCREEN_REMOTE
80#endif
81};
82
83struct scrollinfo;
84
85#if LCD_STRIDEFORMAT == VERTICAL_STRIDE
86#define STRIDE_MAIN(w, h) (h)
87#else
88#define STRIDE_MAIN(w, h) (w)
89#endif
90
91#define STRIDE_REMOTE(w, h) (w)
92
93#define STRIDE(screen, w, h) (screen==SCREEN_MAIN?STRIDE_MAIN((w), \
94 (h)):STRIDE_REMOTE((w),(h)))
95
96#if LCD_DEPTH <=8
97#if (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED) \
98 || (LCD_PIXELFORMAT == HORIZONTAL_INTERLEAVED)
99 typedef unsigned short fb_data;
100#define FB_DATA_SZ 2
101#else
102 typedef unsigned char fb_data;
103#define FB_DATA_SZ 1
104#endif
105#elif LCD_DEPTH <= 16
106 typedef unsigned short fb_data;
107#define FB_DATA_SZ 2
108#elif LCD_DEPTH <= 24
109 struct _fb_pixel {
110 unsigned char b, g, r;
111 };
112 typedef struct _fb_pixel fb_data;
113#define FB_DATA_SZ 3
114#else /* LCD_DEPTH > 24 */
115#if (LCD_PIXELFORMAT == XRGB8888)
116 struct _fb_pixel {
117 unsigned char b, g, r, x;
118 };
119 typedef struct _fb_pixel fb_data;
120#else
121 typedef unsigned long fb_data;
122#endif
123#define FB_DATA_SZ 4
124#endif /* LCD_DEPTH */
125
126#ifdef HAVE_REMOTE_LCD
127#if LCD_REMOTE_DEPTH <= 8
128#if (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED) \
129 || (LCD_REMOTE_PIXELFORMAT == HORIZONTAL_INTERLEAVED)
130 typedef unsigned short fb_remote_data;
131#define FB_RDATA_SZ 2
132#else
133 typedef unsigned char fb_remote_data;
134#define FB_RDATA_SZ 1
135#endif
136#elif LCD_DEPTH <= 16
137 typedef unsigned short fb_remote_data;
138#define FB_RDATA_SZ 2
139#else
140 typedef unsigned long fb_remote_data;
141#define FB_RDATA_SZ 4
142#endif
143#endif
144
145#if defined(HAVE_LCD_MODES)
146 void lcd_set_mode(int mode);
147#define LCD_MODE_RGB565 0x00000001
148#define LCD_MODE_YUV 0x00000002
149#define LCD_MODE_PAL256 0x00000004
150
151#if HAVE_LCD_MODES & LCD_MODE_PAL256
152 void lcd_blit_pal256(unsigned char *src, int src_x, int src_y, int x, int y,
153 int width, int height);
154 void lcd_pal256_update_pal(fb_data *palette);
155#endif
156#endif
157
158struct frame_buffer_t {
159 union
160 {
161 void *data;
162 char *ch_ptr;
163 fb_data *fb_ptr;
164#ifdef HAVE_REMOTE_LCD
165 fb_remote_data *fb_remote_ptr;
166#endif
167 };
168 void *(*get_address_fn)(int x, int y);
169 ptrdiff_t stride;
170 size_t elems;
171};
172
173#define VP_FLAG_ALIGN_RIGHT 0x01
174#define VP_FLAG_ALIGN_CENTER 0x02
175
176#define VP_FLAG_ALIGNMENT_MASK \
177 (VP_FLAG_ALIGN_RIGHT|VP_FLAG_ALIGN_CENTER)
178
179#define VP_IS_RTL(vp) (((vp)->flags & VP_FLAG_ALIGNMENT_MASK) == VP_FLAG_ALIGN_RIGHT)
180
181#define VP_FLAG_OWNER_UPDATE 0x2000 /* block update_vp functions */
182#define VP_FLAG_VP_DIRTY 0x4000
183#define VP_FLAG_CLEAR_FLAG 0x8000
184#define VP_FLAG_VP_SET_CLEAN (VP_FLAG_CLEAR_FLAG | VP_FLAG_VP_DIRTY)
185/* flags set by viewport_set_defaults() */
186#define VP_DEFAULT_FLAGS (VP_FLAG_VP_DIRTY)
187
188struct viewport {
189 int x;
190 int y;
191 int width;
192 int height;
193 int flags;
194 int font;
195 int drawmode;
196 struct frame_buffer_t *buffer;
197 /* needed for even for mono displays to support greylib */
198 unsigned fg_pattern;
199 unsigned bg_pattern;
200};
201
202/* common functions */
203extern void lcd_write_command(int byte);
204extern void lcd_write_command_e(int cmd, int data);
205extern void lcd_write_command_ex(int cmd, int data1, int data2);
206extern void lcd_write_data(const fb_data* p_bytes, int count);
207extern void lcd_init(void) INIT_ATTR;
208extern void lcd_init_device(void) INIT_ATTR;
209
210extern void lcd_backlight(bool on);
211extern int lcd_default_contrast(void);
212extern void lcd_set_contrast(int val);
213extern int lcd_getwidth(void);
214extern int lcd_getheight(void);
215extern int lcd_getstringsize(const unsigned char *str, int *w, int *h);
216
217extern struct viewport* lcd_init_viewport(struct viewport* vp);
218extern struct viewport* lcd_set_viewport(struct viewport* vp);
219extern struct viewport* lcd_set_viewport_ex(struct viewport* vp, int flags);
220
221extern void lcd_update(void);
222extern void lcd_update_viewport(void);
223extern void lcd_update_viewport_rect(int x, int y, int width, int height);
224extern void lcd_clear_viewport(void);
225extern void lcd_clear_display(void);
226extern void lcd_putsxy(int x, int y, const unsigned char *string);
227extern void lcd_putsxyf(int x, int y, const unsigned char *fmt, ...);
228extern void lcd_putsxy_style_offset(int x, int y, const unsigned char *str,
229 int style, int offset);
230extern void lcd_puts(int x, int y, const unsigned char *string);
231extern void lcd_putsf(int x, int y, const unsigned char *fmt, ...);
232extern void lcd_putc(int x, int y, unsigned long ucs);
233extern bool lcd_puts_scroll(int x, int y, const unsigned char* string);
234extern bool lcd_putsxy_scroll_func(int x, int y, const unsigned char *string,
235 void (*scroll_func)(struct scrollinfo *),
236 void *data, int x_offset);
237
238/* performance function */
239#if defined(HAVE_LCD_COLOR)
240#if MEMORYSIZE > 2
241#define LCD_YUV_DITHER 0x1
242 extern void lcd_yuv_set_options(unsigned options);
243 extern void lcd_blit_yuv(unsigned char * const src[3],
244 int src_x, int src_y, int stride,
245 int x, int y, int width, int height);
246#endif /* MEMORYSIZE > 2 */
247#else
248 extern void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
249 int bheight, int stride);
250 extern void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
251 int bx, int by, int bwidth, int bheight,
252 int stride);
253#endif
254
255
256/* update a fraction of the screen */
257extern void lcd_update_rect(int x, int y, int width, int height);
258
259#ifdef HAVE_REMOTE_LCD
260 extern void lcd_remote_update(void);
261 /* update a fraction of the screen */
262 extern void lcd_remote_update_rect(int x, int y, int width, int height);
263#endif /* HAVE_REMOTE_LCD */
264
265/* Bitmap formats */
266enum
267{
268 FORMAT_MONO,
269 FORMAT_NATIVE,
270 FORMAT_ANY /* For passing to read_bmp_file() */
271};
272
273
274/* Draw modes */
275#define DRMODE_COMPLEMENT 0
276#define DRMODE_BG 1
277#define DRMODE_FG 2
278#define DRMODE_SOLID 3
279#define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
280/* Internal drawmode modifiers. DO NOT use with set_drawmode() */
281#define DRMODE_INT_BD 8
282#define DRMODE_INT_IMG 16
283
284/* Low-level drawing function types */
285typedef void lcd_pixelfunc_type(int x, int y);
286typedef void lcd_blockfunc_type(fb_data *address, unsigned mask, unsigned bits);
287#if LCD_DEPTH >= 8
288 typedef void lcd_fastpixelfunc_type(fb_data *address);
289#endif
290
291#if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
292 LCD_REMOTE_DEPTH > 1
293/* Just return color for screens use */
294 static inline unsigned lcd_color_to_native(unsigned color)
295 { return color; }
296#define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
297#else
298#define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
299#endif
300
301#ifdef HAVE_LCD_COLOR
302#if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
303#define LCD_MAX_RED 31
304#define LCD_MAX_GREEN 63
305#define LCD_MAX_BLUE 31
306#define LCD_RED_BITS 5
307#define LCD_GREEN_BITS 6
308#define LCD_BLUE_BITS 5
309
310/* pack/unpack native RGB values */
311#define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
312#define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
313#define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
314#define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
315
316/* pack/unpack 24-bit RGB values */
317#define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
318#define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 13) & 0x07) )
319#define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03) )
320#define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) >> 2) & 0x07) )
321
322#if (LCD_PIXELFORMAT == RGB565SWAPPED)
323/* RGB3553 */
324#define _LCD_UNSWAP_COLOR(x) swap16(x)
325#define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
326 (((g) >> 3) ) | \
327 (((g) & 0x07) << 13) | \
328 (((b) << 8) ) )
329#define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
330 (((g) >> 5) ) | \
331 (((g) & 0x1c) << 11) | \
332 (((b) >> 3) << 8) )
333/* swap color once - not currenly used in static inits */
334#define _SWAPUNPACK(x, _unp_) \
335 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
336#define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
337#define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
338#define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
339#define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
340#define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
341#define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
342#else /* LCD_PIXELFORMAT == RGB565 */
343/* RGB565 */
344#define _LCD_UNSWAP_COLOR(x) (x)
345#define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
346#define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
347#define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
348#define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
349#define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
350#define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
351#define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
352#define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
353#endif /* RGB565* */
354
355#elif (LCD_PIXELFORMAT == RGB888) || (LCD_PIXELFORMAT == XRGB8888)
356#define LCD_MAX_RED 255
357#define LCD_MAX_GREEN 255
358#define LCD_MAX_BLUE 255
359#define LCD_RED_BITS 8
360#define LCD_GREEN_BITS 8
361#define LCD_BLUE_BITS 8
362
363/* pack/unpack native RGB values */
364#define _RGBPACK(r, g, b) ( r << 16 | g << 8 | b )
365#define _RGB_UNPACK_RED(x) ((x >> 16) & 0xff)
366#define _RGB_UNPACK_GREEN(x) ((x >> 8) & 0xff)
367#define _RGB_UNPACK_BLUE(x) ((x >> 0) & 0xff)
368
369#define _LCD_UNSWAP_COLOR(x) (x)
370#define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
371#define LCD_RGBPACK_LCD(r, g, b) _RGBPACK((r), (g), (b))
372#define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
373#define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
374#define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
375#define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED(x)
376#define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN(x)
377#define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE(x)
378
379#else
380/* other colour depths */
381#endif
382
383#define LCD_BLACK LCD_RGBPACK(0, 0, 0)
384#define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
385#define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
386#define LCD_WHITE LCD_RGBPACK(255, 255, 255)
387#define LCD_DEFAULT_FG LCD_WHITE
388#define LCD_DEFAULT_BG LCD_BLACK
389#define LCD_DEFAULT_LS LCD_WHITE
390
391#elif LCD_DEPTH > 1 /* greyscale */
392
393#define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
394#define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
395
396#define LCD_BLACK LCD_BRIGHTNESS(0)
397#define LCD_DARKGRAY LCD_BRIGHTNESS(85)
398#define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
399#define LCD_WHITE LCD_BRIGHTNESS(255)
400#define LCD_DEFAULT_FG LCD_BLACK
401#define LCD_DEFAULT_BG LCD_WHITE
402
403#endif /* HAVE_LCD_COLOR */
404
405/* Framebuffer conversion macros: Convert from and to the native display data
406 * format (fb_data).
407 *
408 * FB_RGBPACK: Convert the three r,g,b values to fb_data. r,g,b are
409 * assumed to in 8-bit format.
410 * FB_RGBPACK_LCD Like FB_RGBPACK, except r,g,b shall be in display-native
411 * bit format (e.g. 5-bit r for RGB565)
412 * FB_UNPACK_RED Extract the red component of fb_data into 8-bit red value.
413 * FB_UNPACK_GREEN Like FB_UNPACK_RED, just for the green component.
414 * FB_UNPACK_BLIE Like FB_UNPACK_RED, just for the green component.
415 * FB_SCALARPACK Similar to FB_RGBPACK, except that the channels are already
416 * combined into a single scalar value. Again, 8-bit per channel.
417 * FB_SCALARPACK_LCD Like FB_SCALARPACK, except the channels shall be in
418 * display-native format (i.e. the scalar is 16bits on RGB565)
419 * FB_UNPACK_SCALAR_LCD Converts an fb_data to a scalar value in display-native
420 * format, so it's the reverse of FB_SCALARPACK_LCD
421 */
422#if LCD_DEPTH >= 24
423 static inline fb_data scalar_to_fb(unsigned p)
424 {
425 union { fb_data st; unsigned sc; } convert;
426 convert.sc = p; return convert.st;
427 }
428 static inline unsigned fb_to_scalar(fb_data p)
429 {
430 union { fb_data st; unsigned sc; } convert;
431 convert.st = p; return convert.sc;
432 }
433#define FB_RGBPACK(r_, g_, b_) ((fb_data){.r = r_, .g = g_, .b = b_})
434#define FB_RGBPACK_LCD(r_, g_, b_) FB_RGBPACK(r_, g_, b_)
435#define FB_UNPACK_RED(fb) ((fb).r)
436#define FB_UNPACK_GREEN(fb) ((fb).g)
437#define FB_UNPACK_BLUE(fb) ((fb).b)
438#define FB_SCALARPACK(c) scalar_to_fb(c)
439#define FB_SCALARPACK_LCD(c) scalar_to_fb(c)
440#define FB_UNPACK_SCALAR_LCD(fb) fb_to_scalar(fb)
441#elif defined(HAVE_LCD_COLOR)
442#define FB_RGBPACK(r_, g_, b_) LCD_RGBPACK(r_, g_, b_)
443#define FB_RGBPACK_LCD(r_, g_, b_) LCD_RGBPACK_LCD(r_, g_, b_)
444#define FB_UNPACK_RED(fb) RGB_UNPACK_RED(fb)
445#define FB_UNPACK_GREEN(fb) RGB_UNPACK_GREEN(fb)
446#define FB_UNPACK_BLUE(fb) RGB_UNPACK_BLUE(fb)
447#define FB_SCALARPACK(c) LCD_RGBPACK(RGB_UNPACK_RED(c), RGB_UNPACK_GREEN(c), RGB_UNPACK_BLUE(c))
448#define FB_SCALARPACK_LCD(c) (c)
449#define FB_UNPACK_SCALAR_LCD(fb) (fb)
450#else
451#define FB_SCALARPACK(c) (c)
452#define FB_SCALARPACK_LCD(c) (c)
453#define FB_UNPACK_SCALAR_LCD(fb) (fb)
454#endif
455
456
457/* Frame buffer dimensions */
458#if LCD_DEPTH == 1
459#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
460#define LCD_FBSTRIDE(w, h) ((w+7)/8)
461#define LCD_FBWIDTH LCD_FBSTRIDE(LCD_WIDTH, LCD_HEIGHT)
462#define LCD_NBELEMS(w, h) ((((h-1)*LCD_FBSTRIDE(w, h)) + w) / sizeof(fb_data))
463#else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
464#define LCD_FBSTRIDE(w, h) ((h+7)/8)
465#define LCD_FBHEIGHT LCD_FBSTRIDE(LCD_WIDTH, LCD_HEIGHT)
466#define LCD_NBELEMS(w, h) ((((w-1)*LCD_FBSTRIDE(w, h)) + h) / sizeof(fb_data))
467#endif /* LCD_PIXELFORMAT */
468#elif LCD_DEPTH == 2
469#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
470#define LCD_FBSTRIDE(w, h) ((w+3)>>2)
471#define LCD_NATIVE_STRIDE(s) LCD_FBSTRIDE(s, s)
472#define LCD_FBWIDTH LCD_FBSTRIDE(LCD_WIDTH, LCD_HEIGHT)
473#define LCD_NBELEMS(w, h) ((((h-1)*LCD_FBSTRIDE(w, h)) + w) / sizeof(fb_data))
474#elif LCD_PIXELFORMAT == VERTICAL_PACKING
475#define LCD_FBSTRIDE(w, h) ((h+3)/4)
476#define LCD_FBHEIGHT LCD_FBSTRIDE(LCD_WIDTH, LCD_HEIGHT)
477#define LCD_NBELEMS(w, h) ((((w-1)*LCD_FBSTRIDE(w, h)) + h) / sizeof(fb_data))
478#elif LCD_PIXELFORMAT == VERTICAL_INTERLEAVED
479#define LCD_FBSTRIDE(w, h) ((h+7)/8)
480#define LCD_FBHEIGHT LCD_FBSTRIDE(LCD_WIDTH, LCD_HEIGHT)
481#define LCD_NBELEMS(w, h) ((((w-1)*LCD_FBSTRIDE(w, h)) + h) / sizeof(fb_data))
482#endif /* LCD_PIXELFORMAT */
483#endif /* LCD_DEPTH */
484/* Set defaults if not defined different yet. The defaults apply to both
485 * dimensions for LCD_DEPTH >= 8 */
486#ifndef LCD_FBWIDTH
487#define LCD_FBWIDTH LCD_WIDTH
488#endif
489#ifndef LCD_FBHEIGHT
490#define LCD_FBHEIGHT LCD_HEIGHT
491#endif
492
493#ifndef LCD_NATIVE_STRIDE
494/* 2-bit Horz is the only display that actually defines this */
495#define LCD_NATIVE_STRIDE(s) (s)
496#endif
497
498#ifndef LCD_NBELEMS
499#if LCD_STRIDEFORMAT == VERTICAL_STRIDE
500#define LCD_NBELEMS(w, h) (((w-1)*STRIDE_MAIN(w, h)) + h)
501#else
502#define LCD_NBELEMS(w, h) (((h-1)*STRIDE_MAIN(w, h)) + w)
503#endif
504#define LCD_FBSTRIDE(w, h) STRIDE_MAIN(w, h)
505#endif
506
507#ifndef LCD_STRIDE
508 #define LCD_STRIDE(w, h) STRIDE_MAIN(w, h)
509#endif
510
511extern struct viewport* lcd_current_viewport;
512
513#define FB_CURRENTVP_BUFFER (lcd_current_viewport->buffer)
514#define FBADDRBUF(buffer,x,y) ((fb_data*) buffer->get_address_fn(x,y))
515#define FBADDR(x,y) (FBADDRBUF(lcd_current_viewport->buffer,x,y))
516
517#define FRAMEBUFFER_SIZE (sizeof(fb_data)*LCD_FBWIDTH*LCD_FBHEIGHT)
518
519/** Port-specific functions. Enable in port config file. **/
520#ifdef HAVE_REMOTE_LCD_AS_MAIN
521void lcd_on(void);
522void lcd_off(void);
523void lcd_poweroff(void);
524#endif
525
526#ifdef HAVE_LCD_ENABLE
527/* Enable/disable the main display. */
528extern void lcd_enable(bool on);
529#endif /* HAVE_LCD_ENABLE */
530
531#ifdef HAVE_LCD_SLEEP
532/* Put the LCD into a power saving state deeper than lcd_enable(false). */
533extern void lcd_sleep(void);
534#endif /* HAVE_LCD_SLEEP */
535#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
536/* Register a hook that is called when the lcd is powered and after the
537 * framebuffer data is synchronized */
538/* Sansa Clip has these function in it's lcd driver, since it's the only
539 * 1-bit display featuring lcd_active, so far */
540
541enum {
542 LCD_EVENT_ACTIVATION = (EVENT_CLASS_LCD|1),
543};
544
545extern bool lcd_active(void);
546#endif
547
548#ifdef HAVE_LCD_SHUTDOWN
549extern void lcd_shutdown(void);
550#endif
551
552#define FORMAT_TRANSPARENT 0x40000000
553#define FORMAT_DITHER 0x20000000
554#define FORMAT_REMOTE 0x10000000
555#define FORMAT_RESIZE 0x08000000
556#define FORMAT_KEEP_ASPECT 0x04000000
557#define FORMAT_RETURN_SIZE 0x02000000
558
559#define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
560#define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
561
562struct bitmap {
563 int width;
564 int height;
565#if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
566 int format;
567 unsigned char *maskdata;
568#endif
569#ifdef HAVE_LCD_COLOR
570 int alpha_offset; /* byte-offset of alpha channel in data */
571#endif
572 unsigned char *data;
573};
574
575extern void lcd_set_invert_display(bool yesno);
576#ifdef HAVE_BACKLIGHT_INVERSION
577 extern void lcd_set_backlight_inversion(bool yesno);
578#endif /* HAVE_BACKLIGHT_INVERSION */
579extern void lcd_set_flip(bool yesno);
580
581extern void lcd_set_drawmode(int mode);
582extern int lcd_get_drawmode(void);
583extern void lcd_setfont(int font);
584extern int lcd_getfont(void);
585
586/* low level drawing function pointer arrays */
587#if LCD_DEPTH >= 8
588 extern lcd_fastpixelfunc_type* const *lcd_fastpixelfuncs;
589#elif LCD_DEPTH > 1
590 extern lcd_pixelfunc_type* const *lcd_pixelfuncs;
591 extern lcd_blockfunc_type* const *lcd_blockfuncs;
592#else /* LCD_DEPTH == 1*/
593 extern lcd_pixelfunc_type* const lcd_pixelfuncs[8];
594 extern lcd_blockfunc_type* const lcd_blockfuncs[8];
595#endif /* LCD_DEPTH */
596
597extern void lcd_drawpixel(int x, int y);
598extern void lcd_drawline(int x1, int y1, int x2, int y2);
599extern void lcd_hline(int x1, int x2, int y);
600extern void lcd_vline(int x, int y1, int y2);
601extern void lcd_drawrect(int x, int y, int width, int height);
602extern void lcd_fillrect(int x, int y, int width, int height);
603extern void lcd_gradient_fillrect(int x, int y, int width, int height,
604 unsigned start_rgb, unsigned end_rgb);
605extern void lcd_gradient_fillrect_part(int x, int y, int width, int height,
606 unsigned start_rgb, unsigned end_rgb, int src_height, int row_skip);
607extern void lcd_draw_border_viewport(void);
608extern void lcd_fill_viewport(void);
609extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
610 int stride, int x, int y, int width, int height);
611extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
612 int height);
613
614extern void lcd_scroll_step(int pixels);
615
616#if LCD_DEPTH > 1
617 extern void lcd_set_foreground(unsigned foreground);
618 extern unsigned lcd_get_foreground(void);
619 extern void lcd_set_background(unsigned background);
620 extern unsigned lcd_get_background(void);
621#ifdef HAVE_LCD_COLOR
622 extern void lcd_set_selector_start(unsigned selector);
623 extern void lcd_set_selector_end(unsigned selector);
624 extern void lcd_set_selector_text(unsigned selector_text);
625#endif
626 extern void lcd_set_drawinfo(int mode, unsigned foreground,
627 unsigned background);
628 void lcd_set_backdrop(fb_data* backdrop);
629
630 fb_data* lcd_get_backdrop(void);
631
632 extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
633 int stride, int x, int y, int width, int height);
634 extern void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width,
635 int height);
636 extern void lcd_bitmap_transparent_part(const fb_data *src,
637 int src_x, int src_y,
638 int stride, int x, int y, int width,
639 int height);
640 extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
641 int width, int height);
642#else /* LCD_DEPTH == 1 */
643#define lcd_mono_bitmap lcd_bitmap
644#define lcd_mono_bitmap_part lcd_bitmap_part
645#endif /* LCD_DEPTH */
646extern void lcd_bmp_part(const struct bitmap* bm, int src_x, int src_y,
647 int x, int y, int width, int height);
648extern void lcd_bmp(const struct bitmap* bm, int x, int y);
649extern void lcd_nine_segment_bmp(const struct bitmap* bm, int x, int y,
650 int width, int height);
651
652/* TODO: Impement this for remote displays if ever needed */
653#if defined(LCD_DPI) && (LCD_DPI > 0)
654 /* returns the pixel density of the display */
655 static inline int lcd_get_dpi(void) { return LCD_DPI; }
656#else
657 extern int lcd_get_dpi(void);
658#endif /* LCD_DPI */
659
660#ifdef FB_DOUBLEBUF
661extern int doublebuf;
662#endif
663
664#endif /* __LCD_H__ */