add global proxy / cache settings to httpget class. This removes the need of passing...
[Rockbox.git] / firmware / export / lcd.h
blob669ef67f02f89a56cf9d16096fda4486cf2fa378
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Alan Korr
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #ifndef __LCD_H__
21 #define __LCD_H__
23 #include <stdbool.h>
24 #include "cpu.h"
25 #include "config.h"
27 struct viewport {
28 int x;
29 int y;
30 int width;
31 int height;
32 #ifdef HAVE_LCD_BITMAP
33 int font;
34 int drawmode;
35 #endif
36 int xmargin; /* During the transition only - to be removed */
37 int ymargin; /* During the transition only - to be removed */
38 #if LCD_DEPTH > 1
39 unsigned fg_pattern;
40 unsigned bg_pattern;
41 #ifdef HAVE_LCD_COLOR
42 unsigned lss_pattern;
43 unsigned lse_pattern;
44 unsigned lst_pattern;
45 #endif
46 #endif
49 #define STYLE_DEFAULT 0x00000000
50 #define STYLE_COLORED 0x10000000
51 #define STYLE_INVERT 0x20000000
52 #define STYLE_COLORBAR 0x40000000
53 #define STYLE_GRADIENT 0x80000000
54 #define STYLE_MODE_MASK 0xF0000000
55 #define STYLE_COLOR_MASK 0x0000FFFF
56 #ifdef HAVE_LCD_COLOR
57 #define STYLE_CURLN_MASK 0x0000FF00
58 #define STYLE_MAXLN_MASK 0x000000FF
59 #define CURLN_PACK(x) (((x)<<8) & STYLE_CURLN_MASK)
60 #define CURLN_UNPACK(x) ((unsigned char)(((x)&STYLE_CURLN_MASK) >> 8))
61 #define NUMLN_PACK(x) ((x) & STYLE_MAXLN_MASK)
62 #define NUMLN_UNPACK(x) ((unsigned char)((x) & STYLE_MAXLN_MASK))
63 #endif
65 #ifdef SIMULATOR
66 #ifndef MAX_PATH
67 #define MAX_PATH 260
68 #endif
69 #else
70 #include "file.h" /* for MAX_PATH; FIXME: Why does this not work for sims? */
71 #endif /* SIMULATOR */
73 #if LCD_DEPTH <=8
74 typedef unsigned char fb_data;
75 #elif LCD_DEPTH <= 16
76 typedef unsigned short fb_data;
77 #else /* LCD_DEPTH > 16 */
78 typedef unsigned long fb_data;
79 #endif /* LCD_DEPTH */
81 /* common functions */
82 extern void lcd_write_command(int byte);
83 extern void lcd_write_command_e(int cmd, int data);
84 extern void lcd_write_command_ex(int cmd, int data1, int data2);
85 extern void lcd_write_data(const fb_data* p_bytes, int count);
86 extern void lcd_init(void);
88 #ifdef SIMULATOR
89 /* Define a dummy device specific init for the sims */
90 #define lcd_init_device()
91 #else
92 extern void lcd_init_device(void);
93 #endif /* SIMULATOR */
95 extern void lcd_backlight(bool on);
96 extern int lcd_default_contrast(void);
97 extern void lcd_set_contrast(int val);
98 extern void lcd_setmargins(int xmargin, int ymargin);
99 extern int lcd_getxmargin(void);
100 extern int lcd_getymargin(void);
101 extern int lcd_getwidth(void);
102 extern int lcd_getheight(void);
103 extern int lcd_getstringsize(const unsigned char *str, int *w, int *h);
105 extern void lcd_set_viewport(struct viewport* vp);
106 extern void lcd_update(void);
107 extern void lcd_update_viewport(void);
108 extern void lcd_clear_viewport(void);
109 extern void lcd_clear_display(void);
110 extern void lcd_putsxy(int x, int y, const unsigned char *string);
111 extern void lcd_puts(int x, int y, const unsigned char *string);
112 extern void lcd_puts_style(int x, int y, const unsigned char *string, int style);
113 extern void lcd_puts_offset(int x, int y, const unsigned char *str, int offset);
114 extern void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
115 int offset);
116 extern void lcd_putc(int x, int y, unsigned long ucs);
117 extern void lcd_stop_scroll(void);
118 extern void lcd_bidir_scroll(int threshold);
119 extern void lcd_scroll_speed(int speed);
120 extern void lcd_scroll_delay(int ms);
121 extern void lcd_puts_scroll(int x, int y, const unsigned char* string);
122 extern void lcd_puts_scroll_style(int x, int y, const unsigned char* string,
123 int style);
125 #ifdef HAVE_LCD_BITMAP
127 #if defined(HAVE_LCD_COLOR)
128 #define LCD_YUV_DITHER 0x1
129 extern void lcd_yuv_set_options(unsigned options);
130 extern void lcd_yuv_blit(unsigned char * const src[3],
131 int src_x, int src_y, int stride,
132 int x, int y, int width, int height);
133 #else
134 extern void lcd_grey_phase_blit(unsigned char *values, unsigned char *phases,
135 int bx, int by, int bwidth, int bheight,
136 int stride);
137 #endif
139 /* performance function */
140 extern void lcd_blit(const fb_data* data, int x, int by, int width,
141 int bheight, int stride);
143 /* update a fraction of the screen */
144 extern void lcd_update_rect(int x, int y, int width, int height);
145 extern void lcd_update_viewport_rect(int x, int y, int width, int height);
147 #ifdef HAVE_REMOTE_LCD
148 extern void lcd_remote_update(void);
149 /* update a fraction of the screen */
150 extern void lcd_remote_update_rect(int x, int y, int width, int height);
151 #endif /* HAVE_REMOTE_LCD */
152 #endif /* HAVE_LCD_BITMAP */
154 #ifdef HAVE_LCD_CHARCELLS
156 /* Icon definitions for lcd_icon() */
157 enum
159 ICON_BATTERY = 0,
160 ICON_BATTERY_1,
161 ICON_BATTERY_2,
162 ICON_BATTERY_3,
163 ICON_USB,
164 ICON_PLAY,
165 ICON_RECORD,
166 ICON_PAUSE,
167 ICON_AUDIO,
168 ICON_REPEAT,
169 ICON_1,
170 ICON_VOLUME,
171 ICON_VOLUME_1,
172 ICON_VOLUME_2,
173 ICON_VOLUME_3,
174 ICON_VOLUME_4,
175 ICON_VOLUME_5,
176 ICON_PARAM
179 void lcd_icon(int icon, bool enable);
180 void lcd_double_height(bool on);
181 void lcd_define_pattern(unsigned long ucs, const char *pattern);
182 unsigned long lcd_get_locked_pattern(void);
183 void lcd_unlock_pattern(unsigned long ucs);
184 void lcd_put_cursor(int x, int y, unsigned long cursor_ucs);
185 void lcd_remove_cursor(void);
186 #define JUMP_SCROLL_ALWAYS 5
187 extern void lcd_jump_scroll(int mode); /* 0=off, 1=once, ..., ALWAYS */
188 extern void lcd_jump_scroll_delay(int ms);
189 #endif /* HAVE_LCD_CHARCELLS */
191 /* Draw modes */
192 #define DRMODE_COMPLEMENT 0
193 #define DRMODE_BG 1
194 #define DRMODE_FG 2
195 #define DRMODE_SOLID 3
196 #define DRMODE_INVERSEVID 4 /* used as bit modifier for basic modes */
198 /* Low-level drawing function types */
199 typedef void lcd_pixelfunc_type(int x, int y);
200 typedef void lcd_blockfunc_type(fb_data *address, unsigned mask, unsigned bits);
201 #if LCD_DEPTH >= 8
202 typedef void lcd_fastpixelfunc_type(fb_data *address);
203 #endif
205 #ifdef HAVE_LCD_BITMAP
207 #if defined(HAVE_LCD_COLOR) && defined(LCD_REMOTE_DEPTH) && \
208 LCD_REMOTE_DEPTH > 1
209 /* Just return color for screens use */
210 static inline unsigned lcd_color_to_native(unsigned color)
211 { return color; }
212 #define SCREEN_COLOR_TO_NATIVE(screen, color) (screen)->color_to_native(color)
213 #else
214 #define SCREEN_COLOR_TO_NATIVE(screen, color) (color)
215 #endif
217 #ifdef HAVE_LCD_COLOR
218 #if LCD_PIXELFORMAT == RGB565 || LCD_PIXELFORMAT == RGB565SWAPPED
219 #define LCD_MAX_RED 31
220 #define LCD_MAX_GREEN 63
221 #define LCD_MAX_BLUE 31
222 #define LCD_RED_BITS 5
223 #define LCD_GREEN_BITS 6
224 #define LCD_BLUE_BITS 5
226 /* pack/unpack native RGB values */
227 #define _RGBPACK_LCD(r, g, b) ( ((r) << 11) | ((g) << 5) | (b) )
228 #define _RGB_UNPACK_RED_LCD(x) ( (((x) >> 11) ) )
229 #define _RGB_UNPACK_GREEN_LCD(x) ( (((x) >> 5) & 0x3f) )
230 #define _RGB_UNPACK_BLUE_LCD(x) ( (((x) ) & 0x1f) )
232 /* pack/unpack 24-bit RGB values */
233 #define _RGBPACK(r, g, b) _RGBPACK_LCD((r) >> 3, (g) >> 2, (b) >> 3)
234 #define _RGB_UNPACK_RED(x) ( (((x) >> 8) & 0xf8) | (((x) >> 13) & 0x07) )
235 #define _RGB_UNPACK_GREEN(x) ( (((x) >> 3) & 0xfc) | (((x) >> 9) & 0x03) )
236 #define _RGB_UNPACK_BLUE(x) ( (((x) << 3) & 0xf8) | (((x) >> 2) & 0x07) )
238 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
239 /* RGB3553 */
240 #define _LCD_UNSWAP_COLOR(x) swap16(x)
241 #define LCD_RGBPACK_LCD(r, g, b) ( (((r) << 3) ) | \
242 (((g) >> 3) ) | \
243 (((g) & 0x07) << 13) | \
244 (((b) << 8) ) )
245 #define LCD_RGBPACK(r, g, b) ( (((r) >> 3) << 3) | \
246 (((g) >> 5) ) | \
247 (((g) & 0x1c) << 11) | \
248 (((b) >> 3) << 8) )
249 /* swap color once - not currenly used in static inits */
250 #define _SWAPUNPACK(x, _unp_) \
251 ({ typeof (x) _x_ = swap16(x); _unp_(_x_); })
252 #define RGB_UNPACK_RED(x) _SWAPUNPACK((x), _RGB_UNPACK_RED)
253 #define RGB_UNPACK_GREEN(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN)
254 #define RGB_UNPACK_BLUE(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE)
255 #define RGB_UNPACK_RED_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_RED_LCD)
256 #define RGB_UNPACK_GREEN_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_GREEN_LCD)
257 #define RGB_UNPACK_BLUE_LCD(x) _SWAPUNPACK((x), _RGB_UNPACK_BLUE_LCD)
258 #else /* LCD_PIXELFORMAT == RGB565 */
259 /* RGB565 */
260 #define _LCD_UNSWAP_COLOR(x) (x)
261 #define LCD_RGBPACK(r, g, b) _RGBPACK((r), (g), (b))
262 #define LCD_RGBPACK_LCD(r, g, b) _RGBPACK_LCD((r), (g), (b))
263 #define RGB_UNPACK_RED(x) _RGB_UNPACK_RED(x)
264 #define RGB_UNPACK_GREEN(x) _RGB_UNPACK_GREEN(x)
265 #define RGB_UNPACK_BLUE(x) _RGB_UNPACK_BLUE(x)
266 #define RGB_UNPACK_RED_LCD(x) _RGB_UNPACK_RED_LCD(x)
267 #define RGB_UNPACK_GREEN_LCD(x) _RGB_UNPACK_GREEN_LCD(x)
268 #define RGB_UNPACK_BLUE_LCD(x) _RGB_UNPACK_BLUE_LCD(x)
269 #endif /* RGB565* */
270 #else
271 /* other colour depths */
272 #endif
274 #define LCD_BLACK LCD_RGBPACK(0, 0, 0)
275 #define LCD_DARKGRAY LCD_RGBPACK(85, 85, 85)
276 #define LCD_LIGHTGRAY LCD_RGBPACK(170, 170, 170)
277 #define LCD_WHITE LCD_RGBPACK(255, 255, 255)
278 #define LCD_DEFAULT_FG LCD_BLACK
279 #define LCD_DEFAULT_BG LCD_RGBPACK(182, 198, 229) /* rockbox blue */
280 #define LCD_DEFAULT_LS LCD_WHITE
282 #elif LCD_DEPTH > 1 /* greyscale */
284 #define LCD_MAX_LEVEL ((1 << LCD_DEPTH) - 1)
285 #define LCD_BRIGHTNESS(y) (((y) * LCD_MAX_LEVEL + 127) / 255)
287 #define LCD_BLACK LCD_BRIGHTNESS(0)
288 #define LCD_DARKGRAY LCD_BRIGHTNESS(85)
289 #define LCD_LIGHTGRAY LCD_BRIGHTNESS(170)
290 #define LCD_WHITE LCD_BRIGHTNESS(255)
291 #define LCD_DEFAULT_FG LCD_BLACK
292 #define LCD_DEFAULT_BG LCD_WHITE
294 #endif /* HAVE_LCD_COLOR */
296 /* Frame buffer dimensions */
297 #if LCD_DEPTH == 1
298 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
299 #define LCD_FBWIDTH ((LCD_WIDTH+7)/8)
300 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
301 #define LCD_FBHEIGHT ((LCD_HEIGHT+7)/8)
302 #endif /* LCD_PIXELFORMAT */
303 #elif LCD_DEPTH == 2
304 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
305 #define LCD_FBWIDTH ((LCD_WIDTH+3)/4)
306 #else /* LCD_PIXELFORMAT == VERTICAL_PACKING */
307 #define LCD_FBHEIGHT ((LCD_HEIGHT+3)/4)
308 #endif /* LCD_PIXELFORMAT */
309 #endif /* LCD_DEPTH */
310 /* Set defaults if not defined different yet. The defaults apply to both
311 * dimensions for LCD_DEPTH >= 8 */
312 #ifndef LCD_FBWIDTH
313 #define LCD_FBWIDTH LCD_WIDTH
314 #endif
315 #ifndef LCD_FBHEIGHT
316 #define LCD_FBHEIGHT LCD_HEIGHT
317 #endif
318 /* The actual framebuffer */
319 extern fb_data lcd_framebuffer[LCD_FBHEIGHT][LCD_FBWIDTH];
321 /** Port-specific functions. Enable in port config file. **/
322 #ifdef HAVE_LCD_ENABLE
323 /* Enable/disable the main display. */
324 extern void lcd_enable(bool on);
325 extern bool lcd_enabled(void);
326 #endif /* HAVE_LCD_ENABLE */
328 #ifdef HAVE_LCD_SLEEP
329 /* Put the LCD into a power saving state deeper than lcd_enable(false). */
330 extern void lcd_sleep(void);
331 #endif /* HAVE_LCD_SLEEP */
333 #ifdef HAVE_LCD_SHUTDOWN
334 void lcd_shutdown(void);
335 #endif
337 /* Bitmap formats */
338 enum
340 FORMAT_MONO,
341 FORMAT_NATIVE,
342 FORMAT_ANY /* For passing to read_bmp_file() */
345 #define FORMAT_TRANSPARENT 0x40000000
346 #define FORMAT_DITHER 0x20000000
347 #define FORMAT_REMOTE 0x10000000
349 #define TRANSPARENT_COLOR LCD_RGBPACK(255,0,255)
350 #define REPLACEWITHFG_COLOR LCD_RGBPACK(0,255,255)
352 struct bitmap {
353 int width;
354 int height;
355 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
356 int format;
357 unsigned char *maskdata;
358 #endif
359 unsigned char *data;
362 extern void lcd_set_invert_display(bool yesno);
363 #ifdef HAVE_BACKLIGHT_INVERSION
364 extern void lcd_set_backlight_inversion(bool yesno);
365 #endif /* HAVE_BACKLIGHT_INVERSION */
366 extern void lcd_set_flip(bool yesno);
368 extern void lcd_set_drawmode(int mode);
369 extern int lcd_get_drawmode(void);
370 extern void lcd_setfont(int font);
371 extern int lcd_getfont(void);
373 extern void lcd_puts_style_offset(int x, int y, const unsigned char *str,
374 int style, int offset);
375 extern void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
376 int style, int offset);
378 /* low level drawing function pointer arrays */
379 #if LCD_DEPTH >= 8
380 extern lcd_fastpixelfunc_type* const *lcd_fastpixelfuncs;
381 #elif LCD_DEPTH > 1
382 extern lcd_pixelfunc_type* const *lcd_pixelfuncs;
383 extern lcd_blockfunc_type* const *lcd_blockfuncs;
384 #else /* LCD_DEPTH == 1*/
385 extern lcd_pixelfunc_type* const lcd_pixelfuncs[8];
386 extern lcd_blockfunc_type* const lcd_blockfuncs[8];
387 #endif /* LCD_DEPTH */
389 extern void lcd_drawpixel(int x, int y);
390 extern void lcd_drawline(int x1, int y1, int x2, int y2);
391 extern void lcd_hline(int x1, int x2, int y);
392 extern void lcd_vline(int x, int y1, int y2);
393 extern void lcd_drawrect(int x, int y, int width, int height);
394 extern void lcd_fillrect(int x, int y, int width, int height);
395 extern void lcd_bitmap_part(const fb_data *src, int src_x, int src_y,
396 int stride, int x, int y, int width, int height);
397 extern void lcd_bitmap(const fb_data *src, int x, int y, int width,
398 int height);
400 extern void lcd_scroll_step(int pixels);
402 #if LCD_DEPTH > 1
403 extern void lcd_set_foreground(unsigned foreground);
404 extern unsigned lcd_get_foreground(void);
405 extern void lcd_set_background(unsigned background);
406 extern unsigned lcd_get_background(void);
407 #ifdef HAVE_LCD_COLOR
408 extern void lcd_set_selector_start(unsigned selector);
409 extern void lcd_set_selector_end(unsigned selector);
410 extern void lcd_set_selector_text(unsigned selector_text);
411 #endif
412 extern void lcd_set_drawinfo(int mode, unsigned foreground,
413 unsigned background);
414 void lcd_set_backdrop(fb_data* backdrop);
416 fb_data* lcd_get_backdrop(void);
418 extern void lcd_mono_bitmap_part(const unsigned char *src, int src_x, int src_y,
419 int stride, int x, int y, int width, int height);
420 extern void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width,
421 int height);
422 extern void lcd_bitmap_transparent_part(const fb_data *src,
423 int src_x, int src_y,
424 int stride, int x, int y, int width,
425 int height);
426 extern void lcd_bitmap_transparent(const fb_data *src, int x, int y,
427 int width, int height);
428 #else /* LCD_DEPTH == 1 */
429 #define lcd_mono_bitmap lcd_bitmap
430 #define lcd_mono_bitmap_part lcd_bitmap_part
431 #endif /* LCD_DEPTH */
433 #endif /* HAVE_LCD_BITMAP */
435 #endif /* __LCD_H__ */