summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd-player.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd-player.c')
-rw-r--r--firmware/drivers/lcd-player.c348
1 files changed, 348 insertions, 0 deletions
diff --git a/firmware/drivers/lcd-player.c b/firmware/drivers/lcd-player.c
new file mode 100644
index 0000000000..f2a034f8da
--- /dev/null
+++ b/firmware/drivers/lcd-player.c
@@ -0,0 +1,348 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20
21#ifdef HAVE_LCD_CHARCELLS
22
23#include "lcd.h"
24#include "kernel.h"
25#include "thread.h"
26#include <string.h>
27#include <stdlib.h>
28#include "file.h"
29#include "debug.h"
30#include "system.h"
31#include "font.h"
32
33#if defined(SIMULATOR)
34#include "sim_icons.h"
35#endif
36
37/*** definitions ***/
38
39#ifdef HAVE_NEW_CHARCELL_LCD
40# define LCD_CONTRAST_SET ((char)0x50)
41# define LCD_CRAM ((char)0x80) /* Characters */
42# define LCD_PRAM ((char)0xC0) /* Patterns */
43# define LCD_IRAM ((char)0x40) /* Icons */
44#else
45# define LCD_CONTRAST_SET ((char)0xA8)
46# define LCD_CRAM ((char)0xB0) /* Characters */
47# define LCD_PRAM ((char)0x80) /* Patterns */
48# define LCD_IRAM ((char)0xE0) /* Icons */
49#endif
50#define LCD_CURSOR(x,y) ((char)(LCD_CRAM+((y)*16+(x))))
51#define LCD_ICON(i) ((char)(LCD_IRAM+i))
52
53/*** generic code ***/
54
55struct scrollinfo {
56 char text[MAX_PATH];
57 char line[32];
58 int textlen;
59 int offset;
60 int startx;
61 int starty;
62 int space;
63};
64
65static void scroll_thread(void);
66static char scroll_stack[DEFAULT_STACK_SIZE];
67static char scroll_name[] = "scroll";
68static char scroll_speed = 8; /* updates per second */
69static char scroll_spacing = 3; /* spaces between end and start of text */
70
71
72static struct scrollinfo scroll; /* only one scroll line at the moment */
73static int scroll_count = 0;
74
75#ifdef HAVE_NEW_CHARCELL_LCD
76
77static const unsigned char lcd_ascii[] = {
78 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
79 0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
80 0x10,0x11,0x05,0x13,0x14,0x15,0x16,0x17,
81 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
82 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
83 0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
84 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,
85 0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
86 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,
87 0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
88 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,
89 0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
90 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
91 0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,
92 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,
93 0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
94 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
95 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
96 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
97 0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
98 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
99 0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
100 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,
101 0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
102 0x41,0x41,0x41,0x41,0x41,0x41,0x20,0x43,
103 0x45,0x45,0x45,0x45,0x49,0x49,0x49,0x49,
104 0x44,0x4e,0x4f,0x4f,0x4f,0x4f,0x4f,0x20,
105 0x20,0x55,0x55,0x55,0x55,0x59,0x20,0x20,
106 0x61,0x61,0x61,0x61,0x61,0x61,0x20,0x63,
107 0x65,0x65,0x65,0x65,0x69,0x69,0x69,0x69,
108 0x6f,0x6e,0x6f,0x6f,0x6f,0x6f,0x6f,0x20,
109 0x20,0x75,0x75,0x75,0x75,0x79,0x20,0x79
110};
111
112#else
113
114static const unsigned char lcd_ascii[] = {
115 0x00,0x01,0x02,0x03,0x00,0x84,0x85,0x89,
116 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
117 0xec,0xe3,0xe2,0xe1,0xe0,0xdf,0x15,0x00,
118 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
119 0x24,0x25,0x26,0x37,0x06,0x29,0x2a,0x2b,
120 0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,
121 0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,
122 0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,
123 0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,
124 0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,
125 0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,
126 0x5c,0x5d,0x5e,0xa9,0x33,0xce,0x00,0x15,
127 0x00,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,
128 0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,
129 0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,
130 0x7c,0x7d,0x7e,0x24,0x24,0x24,0x24,0x24,
131 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,
132 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
133 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,
134 0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
135 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
136 0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
137 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,
138 0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
139 0x45,0x45,0x45,0x45,0x45,0x45,0x24,0x47,
140 0x49,0x49,0x49,0x49,0x4d,0x4d,0x4d,0x4d,
141 0x48,0x52,0x53,0x53,0x53,0x53,0x53,0x24,
142 0x24,0x59,0x59,0x59,0x59,0x5d,0x24,0x24,
143 0x65,0x65,0x65,0x65,0x65,0x65,0x24,0x67,
144 0x69,0x69,0x69,0x69,0x6d,0x6d,0x6d,0x6d,
145 0x73,0x72,0x73,0x73,0x73,0x73,0x73,0x24,
146 0x24,0x79,0x79,0x79,0x79,0x7d,0x24,0x7d
147};
148#endif /* HAVE_NEW_CHARCELL_LCD */
149
150void lcd_clear_display(void)
151{
152 int i;
153 lcd_write(true,LCD_CURSOR(0,0));
154 for (i=0;i<32;i++)
155 lcd_write(false,lcd_ascii[' ']);
156}
157
158void lcd_puts(int x, int y, unsigned char *string)
159{
160 int i;
161 lcd_write(true,LCD_CURSOR(x,y));
162 for (i=0; *string && x++<11; i++)
163 lcd_write(false,lcd_ascii[*(unsigned char*)string++]);
164 for (; x<11; x++)
165 lcd_write(false,lcd_ascii[' ']);
166}
167
168void lcd_putc(int x, int y, unsigned char ch)
169{
170 lcd_write(true,LCD_CURSOR(x,y));
171 lcd_write(false,lcd_ascii[ch]);
172}
173
174void lcd_define_pattern (int which,char *pattern,int length)
175{
176 int i;
177 lcd_write(true,LCD_PRAM|which);
178 for (i=0;i<length;i++)
179 lcd_write(false,pattern[i]);
180}
181
182void lcd_double_height(bool on)
183{
184 lcd_write(true,on?9:8);
185}
186
187static char icon_pos[] =
188{
189 0, 0, 0, 0, /* Battery */
190 2, /* USB */
191 3, /* Play */
192 4, /* Record */
193 5, /* Pause */
194 5, /* Audio */
195 6, /* Repeat */
196 7, /* 1 */
197 9, /* Volume */
198 9, /* Volume 1 */
199 9, /* Volume 2 */
200 10, /* Volume 3 */
201 10, /* Volume 4 */
202 10, /* Volume 5 */
203 10, /* Param */
204};
205
206static char icon_mask[] =
207{
208 0x02, 0x08, 0x04, 0x10, /* Battery */
209 0x04, /* USB */
210 0x10, /* Play */
211 0x10, /* Record */
212 0x02, /* Pause */
213 0x10, /* Audio */
214 0x02, /* Repeat */
215 0x01, /* 1 */
216 0x04, /* Volume */
217 0x02, /* Volume 1 */
218 0x01, /* Volume 2 */
219 0x08, /* Volume 3 */
220 0x04, /* Volume 4 */
221 0x01, /* Volume 5 */
222 0x10, /* Param */
223};
224
225void lcd_icon(int icon, bool enable)
226{
227 static unsigned char icon_mirror[11] = {0};
228 int pos, mask;
229
230 pos = icon_pos[icon];
231 mask = icon_mask[icon];
232
233 lcd_write(true, LCD_ICON(pos));
234
235 if(enable)
236 icon_mirror[pos] |= mask;
237 else
238 icon_mirror[pos] &= ~mask;
239
240 lcd_write(false, icon_mirror[pos]);
241}
242
243void lcd_init (void)
244{
245 create_thread(scroll_thread, scroll_stack,
246 sizeof(scroll_stack), scroll_name);
247}
248
249void lcd_set_contrast(int val)
250{
251 lcd_write(true, LCD_CONTRAST_SET);
252 lcd_write(false, 31-val);
253}
254
255void lcd_puts_scroll(int x, int y, unsigned char* string )
256{
257 struct scrollinfo* s = &scroll;
258 s->space = 11 - x;
259
260 lcd_puts(x,y,string);
261 s->textlen = strlen(string);
262
263 if ( s->textlen > s->space ) {
264 s->offset=s->space;
265 s->startx=x;
266 s->starty=y;
267 strncpy(s->text,string,sizeof s->text);
268 s->text[sizeof s->text - 1] = 0;
269 memset(s->line, 0, sizeof s->line);
270 strncpy(s->line,string,
271 s->space > (int)sizeof s->line ?
272 (int)sizeof s->line : s->space );
273 s->line[sizeof s->line - 1] = 0;
274 scroll_count = 1;
275 }
276}
277
278
279void lcd_stop_scroll(void)
280{
281 if ( scroll_count ) {
282 struct scrollinfo* s = &scroll;
283 scroll_count = 0;
284
285 /* restore scrolled row */
286 lcd_puts(s->startx,s->starty,s->text);
287 lcd_update();
288 }
289}
290
291void lcd_scroll_pause(void)
292{
293 scroll_count = 0;
294}
295
296void lcd_scroll_resume(void)
297{
298 scroll_count = 1;
299}
300
301void lcd_scroll_speed(int speed)
302{
303 scroll_speed = speed;
304}
305
306static void scroll_thread(void)
307{
308 struct scrollinfo* s = &scroll;
309
310 while ( 1 ) {
311 if ( !scroll_count ) {
312 yield();
313 continue;
314 }
315 /* wait 0.5s before starting scroll */
316 if ( scroll_count < scroll_speed/2 )
317 scroll_count++;
318 else {
319 int i;
320 for ( i=0; i<s->space-1; i++ )
321 s->line[i] = s->line[i+1];
322
323 if ( s->offset < s->textlen ) {
324 s->line[(int)s->space - 1] = s->text[(int)s->offset];
325 s->offset++;
326 }
327 else {
328 s->line[s->space - 1] = ' ';
329 if ( s->offset < s->textlen + scroll_spacing - 1 )
330 s->offset++;
331 else
332 s->offset = 0;
333 }
334
335 lcd_puts(s->startx,s->starty,s->line);
336 lcd_update();
337 }
338 sleep(HZ/scroll_speed);
339 }
340}
341
342#endif /* HAVE_LCD_CHARCELLS */
343
344/* -----------------------------------------------------------------
345 * local variables:
346 * eval: (load-file "../rockbox-mode.el")
347 * end:
348 */