Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 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" |
Linus Nielsen Feltzing | 0a4b247 | 2002-10-15 12:25:57 +0000 | [diff] [blame] | 20 | #include "hwcompat.h" |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 21 | |
| 22 | #ifdef HAVE_LCD_CHARCELLS |
| 23 | |
| 24 | #include "lcd.h" |
| 25 | #include "kernel.h" |
| 26 | #include "thread.h" |
| 27 | #include <string.h> |
| 28 | #include <stdlib.h> |
| 29 | #include "file.h" |
| 30 | #include "debug.h" |
| 31 | #include "system.h" |
| 32 | #include "font.h" |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 33 | #include "lcd-player-charset.h" |
Marcoen Hirschberg | b0fee17 | 2005-12-06 13:27:15 +0000 | [diff] [blame^] | 34 | #include "rbunicode.h" |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 35 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 36 | /*** definitions ***/ |
| 37 | |
Linus Nielsen Feltzing | 0a4b247 | 2002-10-15 12:25:57 +0000 | [diff] [blame] | 38 | #define OLD_LCD_CONTRAST_SET ((char)0xA8) |
| 39 | #define OLD_LCD_CRAM ((char)0xB0) /* Characters */ |
| 40 | #define OLD_LCD_PRAM ((char)0x80) /* Patterns */ |
| 41 | #define OLD_LCD_IRAM ((char)0xE0) /* Icons */ |
| 42 | |
| 43 | #define NEW_LCD_CONTRAST_SET ((char)0x50) |
| 44 | #define NEW_LCD_CRAM ((char)0x80) /* Characters */ |
| 45 | #define NEW_LCD_PRAM ((char)0xC0) /* Patterns */ |
| 46 | #define NEW_LCD_IRAM ((char)0x40) /* Icons */ |
Jens Arnold | 2e290d6 | 2004-11-11 01:11:06 +0000 | [diff] [blame] | 47 | #define NEW_LCD_FUNCTION_SET ((char)0x10) |
| 48 | #define NEW_LCD_POWER_SAVE_MODE_OSC_CONTROL_SET ((char)0x0c) |
| 49 | #define NEW_LCD_POWER_CONTROL_REGISTER_SET ((char)0x20) |
| 50 | #define NEW_LCD_DISPLAY_CONTROL_SET ((char)0x28) |
Linus Nielsen Feltzing | 0a4b247 | 2002-10-15 12:25:57 +0000 | [diff] [blame] | 51 | |
Jens Arnold | 2e290d6 | 2004-11-11 01:11:06 +0000 | [diff] [blame] | 52 | #define LCD_CURSOR(x,y) ((char)(lcd_cram+((y)*16+(x)))) |
| 53 | #define LCD_ICON(i) ((char)(lcd_iram+i)) |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 54 | |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 55 | #define SCROLLABLE_LINES 2 |
| 56 | |
| 57 | #define SCROLL_MODE_OFF 0 |
| 58 | #define SCROLL_MODE_PAUSE 1 |
| 59 | #define SCROLL_MODE_RUN 2 |
| 60 | |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 61 | extern unsigned short new_lcd_rocklatin1_to_xlcd[]; |
| 62 | extern unsigned short old_lcd_rocklatin1_to_xlcd[]; |
Jens Arnold | 9478cc6 | 2004-08-03 19:22:56 +0000 | [diff] [blame] | 63 | extern const unsigned char lcd_player_extended_lcd_to_rocklatin1[]; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 64 | extern unsigned char extended_font_player[NO_EXTENDED_LCD_CHARS][8]; |
| 65 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 66 | /*** generic code ***/ |
| 67 | |
Kjell Ericson | 565505a | 2003-01-27 14:37:03 +0000 | [diff] [blame] | 68 | #define MAX_CURSOR_CHARS 8 |
| 69 | struct cursorinfo { |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 70 | int len; |
| 71 | char text[MAX_CURSOR_CHARS]; |
| 72 | int textpos; |
| 73 | int y_pos; |
| 74 | int x_pos; |
| 75 | int divider; |
| 76 | int downcount; |
Kjell Ericson | 565505a | 2003-01-27 14:37:03 +0000 | [diff] [blame] | 77 | } cursor; |
| 78 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 79 | static void scroll_thread(void); |
| 80 | static char scroll_stack[DEFAULT_STACK_SIZE]; |
Jens Arnold | 2b0694c | 2004-08-03 05:58:46 +0000 | [diff] [blame] | 81 | static const char scroll_name[] = "scroll"; |
Jens Arnold | 05af280 | 2005-07-28 08:36:24 +0000 | [diff] [blame] | 82 | static int scroll_ticks = 12; /* # of ticks between updates */ |
Kjell Ericson | dc88e23 | 2003-01-10 12:23:36 +0000 | [diff] [blame] | 83 | static int scroll_delay = HZ/2; /* delay before starting scroll */ |
Kjell Ericson | 6143eeb | 2003-05-27 12:54:11 +0000 | [diff] [blame] | 84 | static int jump_scroll_delay = HZ/4; /* delay between jump scroll jumps */ |
Jens Arnold | 05af280 | 2005-07-28 08:36:24 +0000 | [diff] [blame] | 85 | static int scroll_spacing = 3; /* spaces between end and start of text */ |
Mats Lidell | 4c7f70f | 2003-01-14 10:45:57 +0000 | [diff] [blame] | 86 | static int bidir_limit = 50; /* percent */ |
Kjell Ericson | 6143eeb | 2003-05-27 12:54:11 +0000 | [diff] [blame] | 87 | static int jump_scroll = 0; /* 0=off, 1=once, ..., JUMP_SCROLL_ALWAYS */ |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 88 | |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 89 | static struct scrollinfo scroll[SCROLLABLE_LINES]; |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 90 | |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 91 | static char extended_chars_mapped[NO_EXTENDED_LCD_CHARS]; |
| 92 | static char extended_pattern_content[8]; /* Which char is mapped in pattern */ |
| 93 | static char extended_pattern_usage[8]; /* Counting number of times used */ |
| 94 | static char pattern_size; /* Last pattern, 3 for old LCD, 7 for new LCD */ |
Linus Nielsen Feltzing | 0a4b247 | 2002-10-15 12:25:57 +0000 | [diff] [blame] | 95 | |
| 96 | static bool new_lcd; |
| 97 | |
Daniel Stenberg | 006b2c1 | 2003-12-12 13:23:33 +0000 | [diff] [blame] | 98 | unsigned short *lcd_ascii; |
Linus Nielsen Feltzing | 0a4b247 | 2002-10-15 12:25:57 +0000 | [diff] [blame] | 99 | static char lcd_contrast_set; |
| 100 | static char lcd_cram; |
| 101 | static char lcd_pram; |
| 102 | static char lcd_iram; |
| 103 | |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 104 | unsigned short buffer_xlcd[11][2]; |
| 105 | unsigned short buffer_lcd_mirror[11][2]; |
| 106 | |
| 107 | #ifdef SIMULATOR |
| 108 | unsigned char hardware_buffer_lcd[11][2]; |
Jens Arnold | 1aa9cda | 2004-04-21 11:00:51 +0000 | [diff] [blame] | 109 | #else |
| 110 | static unsigned char lcd_data_byte; /* global write buffer */ |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 111 | #endif |
Jens Arnold | 1aa9cda | 2004-04-21 11:00:51 +0000 | [diff] [blame] | 112 | |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 113 | #define NO_CHAR -1 |
| 114 | |
| 115 | static void lcd_free_pat(int map_ch) |
| 116 | { |
| 117 | int x, y; |
Jens Arnold | 38e8a11 | 2004-04-21 09:39:29 +0000 | [diff] [blame] | 118 | unsigned char substitute_char; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 119 | |
| 120 | int pat; |
| 121 | pat=extended_chars_mapped[map_ch]; |
| 122 | if (pat!=NO_CHAR) { |
| 123 | |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 124 | substitute_char=lcd_player_extended_lcd_to_rocklatin1[map_ch]; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 125 | |
Daniel Stenberg | 006b2c1 | 2003-12-12 13:23:33 +0000 | [diff] [blame] | 126 | /* TODO: use a define for the screen width! */ |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 127 | for (x=0; x<11; x++) { |
Daniel Stenberg | 006b2c1 | 2003-12-12 13:23:33 +0000 | [diff] [blame] | 128 | /* TODO: use a define for the screen height! */ |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 129 | for (y=0; y<2; y++) { |
| 130 | if (map_ch==lcd_ascii[buffer_xlcd[x][y]]-512) { |
| 131 | buffer_xlcd[x][y]=substitute_char; |
| 132 | buffer_lcd_mirror[x][y]=substitute_char; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 133 | #ifdef SIMULATOR |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 134 | hardware_buffer_lcd[x][y]=substitute_char; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 135 | #else |
Jens Arnold | 38e8a11 | 2004-04-21 09:39:29 +0000 | [diff] [blame] | 136 | lcd_write_command(LCD_CURSOR(x, y)); |
| 137 | lcd_write_data(&substitute_char, 1); |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 138 | #endif |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 141 | } |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 142 | extended_chars_mapped[map_ch]=NO_CHAR; |
| 143 | extended_pattern_content[pat]=NO_CHAR; |
| 144 | extended_pattern_usage[pat]=0; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 145 | } |
| 146 | #ifdef SIMULATOR |
| 147 | lcd_update(); |
| 148 | #endif |
| 149 | } |
| 150 | |
| 151 | static int lcd_get_free_pat(int ch) |
| 152 | { |
| 153 | int pat; |
| 154 | int last_pat=0; |
| 155 | static int last_used_pat=0; |
| 156 | int loop; |
| 157 | |
Mats Lidell | 1a4fd1f | 2003-01-13 13:09:54 +0000 | [diff] [blame] | 158 | pat=last_used_pat; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 159 | for (loop=0; loop<=pattern_size; loop++) { |
| 160 | pat=(pat+1)&pattern_size; /* Keep 'pat' within limits */ |
| 161 | if (extended_pattern_usage[pat]==0) { |
| 162 | int map_ch=extended_pattern_content[pat]; |
| 163 | if (map_ch != NO_CHAR) { |
| 164 | extended_chars_mapped[map_ch]=NO_CHAR; |
| 165 | extended_pattern_content[pat]=NO_CHAR; |
| 166 | } |
Mats Lidell | 1a4fd1f | 2003-01-13 13:09:54 +0000 | [diff] [blame] | 167 | last_used_pat=pat; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 168 | return pat; |
| 169 | } |
| 170 | if (extended_pattern_content[pat]>extended_pattern_content[last_pat]) |
| 171 | last_pat=pat; |
| 172 | } |
| 173 | if (ch<32) { /* Prioritized char */ |
| 174 | /* Remove last_pat */ |
| 175 | lcd_free_pat(extended_pattern_content[last_pat]); |
| 176 | last_used_pat=last_pat; |
| 177 | return last_pat; |
| 178 | } |
| 179 | return NO_CHAR; |
| 180 | |
| 181 | } |
| 182 | |
Kjell Ericson | a33d6b2 | 2003-01-10 10:12:17 +0000 | [diff] [blame] | 183 | void xlcd_update(void) |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 184 | { |
| 185 | int x, y; |
| 186 | for (x=0; x<11; x++) { |
| 187 | for (y=0; y<2; y++) { |
| 188 | unsigned short ch=buffer_xlcd[x][y]; |
| 189 | unsigned char hw_ch=0xff; |
| 190 | if (ch==buffer_lcd_mirror[x][y]) |
| 191 | continue; /* No need to redraw */ |
| 192 | buffer_lcd_mirror[x][y]=ch; |
| 193 | if (ch>=256 && ch<512) { |
| 194 | hw_ch=ch-256; |
| 195 | } else { |
| 196 | int map_ch=lcd_ascii[ch]; |
| 197 | if (map_ch<512) { |
| 198 | hw_ch=map_ch; |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 199 | } |
| 200 | else { |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 201 | map_ch=map_ch-512; |
| 202 | if (extended_chars_mapped[map_ch]!=NO_CHAR) { |
| 203 | hw_ch=extended_chars_mapped[map_ch]; |
| 204 | extended_pattern_usage[hw_ch]++; |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 205 | } |
| 206 | else { |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 207 | int pat; |
| 208 | pat=lcd_get_free_pat(map_ch); |
| 209 | if (pat<0) { |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 210 | DEBUGF("Substitute for %02x (map 0x%02x)" |
| 211 | " is used.\n", ch, map_ch); |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 212 | /* Find substitute char */ |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 213 | map_ch= |
| 214 | lcd_player_extended_lcd_to_rocklatin1[map_ch]; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 215 | hw_ch=lcd_ascii[map_ch]; |
| 216 | } else { |
| 217 | #ifdef DEBUG |
| 218 | if (extended_pattern_usage[pat]!=0) { |
Kjell Ericson | 3639325 | 2003-01-10 10:13:48 +0000 | [diff] [blame] | 219 | DEBUGF("***Pattern %d is not zero!\n", pat); |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 220 | } |
| 221 | #endif |
| 222 | extended_chars_mapped[map_ch]=pat; |
| 223 | extended_pattern_content[pat]=map_ch; |
| 224 | extended_pattern_usage[pat]=1; |
| 225 | lcd_define_hw_pattern(pat*8, |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 226 | extended_font_player[map_ch], |
| 227 | 8); |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 228 | hw_ch=pat; |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | #ifdef SIMULATOR |
| 234 | hardware_buffer_lcd[x][y]=hw_ch; |
| 235 | #else |
Jens Arnold | 38e8a11 | 2004-04-21 09:39:29 +0000 | [diff] [blame] | 236 | lcd_write_command(LCD_CURSOR(x,y)); |
| 237 | lcd_write_data(&hw_ch, 1); |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 238 | #endif |
| 239 | } |
| 240 | } |
| 241 | lcd_update(); |
| 242 | } |
| 243 | |
| 244 | bool lcdx_putc(int x, int y, unsigned short ch) |
| 245 | { |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 246 | int lcd_char; |
| 247 | if (buffer_xlcd[x][y]==ch) |
| 248 | return false; /* Same char, ignore any update */ |
| 249 | lcd_char=lcd_ascii[buffer_xlcd[x][y]]; |
| 250 | if (lcd_char>=512) { |
| 251 | /* The removed char is a defined pattern, count down the reference. */ |
| 252 | extended_pattern_usage[(int)extended_chars_mapped[lcd_char-512]]--; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 253 | #ifdef DEBUG |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 254 | if (extended_pattern_usage[(int)extended_chars_mapped[lcd_char]]<0) { |
| 255 | DEBUGF("**** Mapped char %02x is less than 0!\n", lcd_char); |
| 256 | } |
| 257 | #endif |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 258 | } |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 259 | |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 260 | buffer_xlcd[x][y]=ch; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 261 | |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 262 | lcd_char=lcd_ascii[ch]; |
| 263 | if (lcd_char>=256) |
| 264 | return true; /* Caller shall call xlcd_update() when done */ |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 265 | |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 266 | buffer_lcd_mirror[x][y]=lcd_char; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 267 | #ifdef SIMULATOR |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 268 | hardware_buffer_lcd[x][y]=lcd_char; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 269 | #else |
Jens Arnold | 38e8a11 | 2004-04-21 09:39:29 +0000 | [diff] [blame] | 270 | lcd_data_byte = (unsigned char) lcd_char; |
| 271 | lcd_write_command(LCD_CURSOR(x, y)); |
| 272 | lcd_write_data(&lcd_data_byte, 1); |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 273 | #endif |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 274 | return false; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Björn Stenberg | 067262d | 2003-07-09 23:07:49 +0000 | [diff] [blame] | 277 | int lcd_default_contrast(void) |
| 278 | { |
| 279 | return 30; |
| 280 | } |
| 281 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 282 | void lcd_clear_display(void) |
| 283 | { |
| 284 | int i; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 285 | bool update=false; |
| 286 | DEBUGF("lcd_clear_display()\n"); |
Kjell Ericson | 75361e5 | 2003-01-14 13:51:09 +0000 | [diff] [blame] | 287 | lcd_stop_scroll(); |
Kjell Ericson | 565505a | 2003-01-27 14:37:03 +0000 | [diff] [blame] | 288 | cursor.len=0; /* Stop cursor */ |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 289 | for (i=0;i<22;i++) |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 290 | update|=lcdx_putc(i%11, i/11, ' '); |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 291 | if (update) |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 292 | xlcd_update(); |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Jens Arnold | 1413f0c | 2004-08-01 22:11:08 +0000 | [diff] [blame] | 295 | static void lcd_puts_cont_scroll(int x, int y, const unsigned char *string) |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 296 | { |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 297 | bool update=false; |
Kjell Ericson | 7f9d713 | 2003-01-22 12:16:14 +0000 | [diff] [blame] | 298 | DEBUGF("lcd_puts_cont_scroll(%d, %d, \"", x, y); |
Kjell Ericson | d618fb0 | 2003-01-21 14:25:24 +0000 | [diff] [blame] | 299 | |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 300 | for (; *string && x<11; x++) |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 301 | { |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 302 | #ifdef DEBUGF |
| 303 | if (*string>=32 && *string<128) |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 304 | { |
| 305 | DEBUGF("%c", *string); |
| 306 | } |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 307 | else |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 308 | { |
| 309 | DEBUGF("(0x%02x)", *string); |
| 310 | } |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 311 | #endif |
| 312 | /* We should check if char is over 256 */ |
| 313 | update|=lcdx_putc(x, y, *(unsigned char*)string++); |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 314 | } |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 315 | DEBUGF("\")\n"); |
| 316 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 317 | for (; x<11; x++) |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 318 | update|=lcdx_putc(x, y, ' '); |
| 319 | if (update) |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 320 | xlcd_update(); |
Linus Nielsen Feltzing | 80ebaab | 2004-07-20 11:43:44 +0000 | [diff] [blame] | 321 | #ifdef SIMULATOR |
| 322 | lcd_update(); |
| 323 | #endif |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 324 | } |
Jens Arnold | 1413f0c | 2004-08-01 22:11:08 +0000 | [diff] [blame] | 325 | void lcd_puts(int x, int y, const unsigned char *string) |
Kjell Ericson | d618fb0 | 2003-01-21 14:25:24 +0000 | [diff] [blame] | 326 | { |
Marcoen Hirschberg | b0fee17 | 2005-12-06 13:27:15 +0000 | [diff] [blame^] | 327 | int i=0; |
| 328 | unsigned short ucs; |
| 329 | const unsigned char *utf8 = string; |
| 330 | unsigned char tmp[12]; |
| 331 | |
| 332 | while (*utf8 && i<11) { |
| 333 | utf8 = utf8decode(utf8, &ucs); |
| 334 | if (ucs < 256) |
| 335 | tmp[i++] = ucs; |
| 336 | else |
| 337 | tmp[i++] = '?'; |
| 338 | } |
| 339 | |
| 340 | tmp[i] = 0; |
| 341 | |
Kjell Ericson | 7f9d713 | 2003-01-22 12:16:14 +0000 | [diff] [blame] | 342 | DEBUGF("lcd_puts(%d, %d) -> ", x, y); |
Kjell Ericson | d618fb0 | 2003-01-21 14:25:24 +0000 | [diff] [blame] | 343 | scroll[y].mode=SCROLL_MODE_OFF; |
Marcoen Hirschberg | b0fee17 | 2005-12-06 13:27:15 +0000 | [diff] [blame^] | 344 | return lcd_puts_cont_scroll(x, y, tmp); |
Kjell Ericson | d618fb0 | 2003-01-21 14:25:24 +0000 | [diff] [blame] | 345 | } |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 346 | |
Kjell Ericson | 565505a | 2003-01-27 14:37:03 +0000 | [diff] [blame] | 347 | void lcd_put_cursor(int x, int y, char cursor_char) |
| 348 | { |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 349 | if (cursor.len == 0) { |
| 350 | cursor.text[0]=buffer_xlcd[x][y]; |
| 351 | cursor.text[1]=cursor_char; |
| 352 | cursor.len=2; |
| 353 | cursor.textpos=0; |
| 354 | cursor.y_pos=y; |
| 355 | cursor.x_pos=x; |
| 356 | cursor.downcount=0; |
| 357 | cursor.divider=4; |
| 358 | } |
Kjell Ericson | 9d40f7e | 2003-01-29 11:48:35 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | void lcd_remove_cursor(void) |
| 362 | { |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 363 | if (cursor.len!=0) { |
| 364 | bool up; |
| 365 | cursor.len=0; |
| 366 | up = lcdx_putc(cursor.x_pos, cursor.y_pos, cursor.text[0]); |
| 367 | #ifdef SIMULATOR |
Daniel Stenberg | 7b9edd6 | 2003-01-29 17:34:28 +0000 | [diff] [blame] | 368 | if(up) |
| 369 | lcd_update(); |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 370 | #endif |
| 371 | } |
Kjell Ericson | 565505a | 2003-01-27 14:37:03 +0000 | [diff] [blame] | 372 | } |
| 373 | |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 374 | void lcd_putc(int x, int y, unsigned short ch) |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 375 | { |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 376 | bool update; |
| 377 | DEBUGF("lcd_putc(%d, %d, %d '0x%02x')\n", x, y, ch, ch); |
| 378 | if (x<0 || y<0) { |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 379 | return; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 380 | } |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 381 | update=lcdx_putc(x, y, ch); |
| 382 | |
| 383 | if (update) |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 384 | xlcd_update(); |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Kjell Ericson | a33d6b2 | 2003-01-10 10:12:17 +0000 | [diff] [blame] | 387 | unsigned char lcd_get_locked_pattern(void) |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 388 | { |
| 389 | unsigned char pat=1; |
| 390 | while (pat<LAST_RESERVED_CHAR) { |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 391 | if (lcd_ascii[pat]==RESERVED_CHAR) { |
| 392 | lcd_ascii[pat]=0x200+pat; |
| 393 | return pat; |
| 394 | } |
| 395 | pat++; |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 396 | } |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | void lcd_unlock_pattern(unsigned char pat) |
| 401 | { |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 402 | lcd_ascii[pat]=RESERVED_CHAR; |
| 403 | lcd_free_pat(pat); |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Jens Arnold | 0ceaa5e | 2004-08-17 01:45:48 +0000 | [diff] [blame] | 406 | void lcd_define_pattern(int pat, const char *pattern) |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 407 | { |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 408 | int i; |
| 409 | for (i=0; i<7; i++) { |
| 410 | extended_font_player[pat][i]=pattern[i]; |
| 411 | } |
| 412 | if (extended_chars_mapped[pat]!=NO_CHAR) { |
| 413 | lcd_define_hw_pattern(extended_chars_mapped[pat]*8, pattern, 7); |
| 414 | } |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | #ifndef SIMULATOR |
Jens Arnold | 0ceaa5e | 2004-08-17 01:45:48 +0000 | [diff] [blame] | 418 | void lcd_define_hw_pattern (int which,const char *pattern,int length) |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 419 | { |
Jens Arnold | 38e8a11 | 2004-04-21 09:39:29 +0000 | [diff] [blame] | 420 | lcd_write_command(lcd_pram | which); |
| 421 | lcd_write_data(pattern, length); |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | void lcd_double_height(bool on) |
| 425 | { |
Linus Nielsen Feltzing | 0a4b247 | 2002-10-15 12:25:57 +0000 | [diff] [blame] | 426 | if(new_lcd) |
Jens Arnold | 38e8a11 | 2004-04-21 09:39:29 +0000 | [diff] [blame] | 427 | lcd_write_command(on?9:8); |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Jens Arnold | 2b0694c | 2004-08-03 05:58:46 +0000 | [diff] [blame] | 430 | static const char icon_pos[] = |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 431 | { |
| 432 | 0, 0, 0, 0, /* Battery */ |
| 433 | 2, /* USB */ |
| 434 | 3, /* Play */ |
| 435 | 4, /* Record */ |
| 436 | 5, /* Pause */ |
| 437 | 5, /* Audio */ |
| 438 | 6, /* Repeat */ |
| 439 | 7, /* 1 */ |
| 440 | 9, /* Volume */ |
| 441 | 9, /* Volume 1 */ |
| 442 | 9, /* Volume 2 */ |
| 443 | 10, /* Volume 3 */ |
| 444 | 10, /* Volume 4 */ |
| 445 | 10, /* Volume 5 */ |
| 446 | 10, /* Param */ |
| 447 | }; |
| 448 | |
Jens Arnold | 2b0694c | 2004-08-03 05:58:46 +0000 | [diff] [blame] | 449 | static const char icon_mask[] = |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 450 | { |
| 451 | 0x02, 0x08, 0x04, 0x10, /* Battery */ |
| 452 | 0x04, /* USB */ |
| 453 | 0x10, /* Play */ |
| 454 | 0x10, /* Record */ |
| 455 | 0x02, /* Pause */ |
| 456 | 0x10, /* Audio */ |
| 457 | 0x02, /* Repeat */ |
| 458 | 0x01, /* 1 */ |
| 459 | 0x04, /* Volume */ |
| 460 | 0x02, /* Volume 1 */ |
| 461 | 0x01, /* Volume 2 */ |
| 462 | 0x08, /* Volume 3 */ |
| 463 | 0x04, /* Volume 4 */ |
| 464 | 0x01, /* Volume 5 */ |
| 465 | 0x10, /* Param */ |
| 466 | }; |
| 467 | |
| 468 | void lcd_icon(int icon, bool enable) |
| 469 | { |
| 470 | static unsigned char icon_mirror[11] = {0}; |
| 471 | int pos, mask; |
| 472 | |
| 473 | pos = icon_pos[icon]; |
| 474 | mask = icon_mask[icon]; |
| 475 | |
Jens Arnold | 38e8a11 | 2004-04-21 09:39:29 +0000 | [diff] [blame] | 476 | lcd_write_command(LCD_ICON(pos)); |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 477 | |
| 478 | if(enable) |
| 479 | icon_mirror[pos] |= mask; |
| 480 | else |
| 481 | icon_mirror[pos] &= ~mask; |
| 482 | |
Jens Arnold | 38e8a11 | 2004-04-21 09:39:29 +0000 | [diff] [blame] | 483 | lcd_write_data(&icon_mirror[pos], 1); |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 484 | } |
| 485 | |
Mats Lidell | 8ca78b6 | 2002-10-18 09:24:23 +0000 | [diff] [blame] | 486 | void lcd_set_contrast(int val) |
| 487 | { |
Jens Arnold | 38e8a11 | 2004-04-21 09:39:29 +0000 | [diff] [blame] | 488 | lcd_data_byte = (unsigned char) (31 - val); |
| 489 | lcd_write_command(lcd_contrast_set); |
| 490 | lcd_write_data(&lcd_data_byte, 1); |
Mats Lidell | 8ca78b6 | 2002-10-18 09:24:23 +0000 | [diff] [blame] | 491 | } |
| 492 | #endif /* SIMULATOR */ |
| 493 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 494 | void lcd_init (void) |
| 495 | { |
Jens Arnold | 2e290d6 | 2004-11-11 01:11:06 +0000 | [diff] [blame] | 496 | unsigned char data_vector[64]; |
Jens Arnold | 1710e38 | 2004-11-11 01:36:37 +0000 | [diff] [blame] | 497 | |
| 498 | (void)data_vector; |
Jens Arnold | 2e290d6 | 2004-11-11 01:11:06 +0000 | [diff] [blame] | 499 | |
Jens Arnold | d4e5397 | 2004-11-22 21:20:54 +0000 | [diff] [blame] | 500 | new_lcd = is_new_player(); |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 501 | memset(extended_chars_mapped, NO_CHAR, sizeof(extended_chars_mapped)); |
| 502 | memset(extended_pattern_content, NO_CHAR,sizeof(extended_pattern_content)); |
| 503 | memset(extended_pattern_usage, 0, sizeof(extended_pattern_usage)); |
Linus Nielsen Feltzing | 0a4b247 | 2002-10-15 12:25:57 +0000 | [diff] [blame] | 504 | |
| 505 | if(new_lcd) { |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 506 | lcd_ascii = new_lcd_rocklatin1_to_xlcd; |
Linus Nielsen Feltzing | 0a4b247 | 2002-10-15 12:25:57 +0000 | [diff] [blame] | 507 | lcd_contrast_set = NEW_LCD_CONTRAST_SET; |
| 508 | lcd_cram = NEW_LCD_CRAM; |
| 509 | lcd_pram = NEW_LCD_PRAM; |
| 510 | lcd_iram = NEW_LCD_IRAM; |
Daniel Stenberg | 006b2c1 | 2003-12-12 13:23:33 +0000 | [diff] [blame] | 511 | pattern_size=7; /* Last pattern, 7 for new LCD */ |
Jens Arnold | 2e290d6 | 2004-11-11 01:11:06 +0000 | [diff] [blame] | 512 | |
Jens Arnold | 1710e38 | 2004-11-11 01:36:37 +0000 | [diff] [blame] | 513 | #ifndef SIMULATOR |
Jens Arnold | 2e290d6 | 2004-11-11 01:11:06 +0000 | [diff] [blame] | 514 | /* LCD init for cold start */ |
| 515 | PBCR2 &= 0xff00; /* Set PB0..PB3 to GPIO */ |
| 516 | or_b(0x0f, &PBIORL); /* ... output */ |
| 517 | or_b(0x0f, &PBDRL); /* ... and high */ |
| 518 | |
| 519 | lcd_write_command(NEW_LCD_FUNCTION_SET + 1); /* CGRAM selected */ |
| 520 | lcd_write_command(NEW_LCD_CONTRAST_SET); |
| 521 | lcd_data_byte = 0x08; |
| 522 | lcd_write_data(&lcd_data_byte, 1); |
| 523 | lcd_write_command(NEW_LCD_POWER_SAVE_MODE_OSC_CONTROL_SET + 2); |
| 524 | /* oscillator on */ |
| 525 | lcd_write_command(NEW_LCD_POWER_CONTROL_REGISTER_SET + 7); |
| 526 | /* opamp buffer + voltage booster on*/ |
| 527 | |
| 528 | memset(data_vector, 0x20, 64); |
| 529 | lcd_write_command(NEW_LCD_CRAM); /* Set DDRAM address */ |
| 530 | lcd_write_data(data_vector, 64); /* all spaces */ |
| 531 | |
| 532 | memset(data_vector, 0, 64); |
| 533 | lcd_write_command(NEW_LCD_PRAM); /* Set CGRAM address */ |
| 534 | lcd_write_data(data_vector, 64); /* zero out */ |
| 535 | lcd_write_command(NEW_LCD_IRAM); /* Set ICONRAM address */ |
| 536 | lcd_write_data(data_vector, 16); /* zero out */ |
| 537 | |
| 538 | lcd_write_command(NEW_LCD_DISPLAY_CONTROL_SET + 1); /* display on */ |
Jens Arnold | 1710e38 | 2004-11-11 01:36:37 +0000 | [diff] [blame] | 539 | #endif /* !SIMULATOR */ |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 540 | } |
| 541 | else { |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 542 | lcd_ascii = old_lcd_rocklatin1_to_xlcd; |
Linus Nielsen Feltzing | 0a4b247 | 2002-10-15 12:25:57 +0000 | [diff] [blame] | 543 | lcd_contrast_set = OLD_LCD_CONTRAST_SET; |
| 544 | lcd_cram = OLD_LCD_CRAM; |
| 545 | lcd_pram = OLD_LCD_PRAM; |
| 546 | lcd_iram = OLD_LCD_IRAM; |
Daniel Stenberg | 006b2c1 | 2003-12-12 13:23:33 +0000 | [diff] [blame] | 547 | pattern_size=3; /* Last pattern, 3 for old LCD */ |
Jens Arnold | 1710e38 | 2004-11-11 01:36:37 +0000 | [diff] [blame] | 548 | |
| 549 | #ifndef SIMULATOR |
Jens Arnold | 2e290d6 | 2004-11-11 01:11:06 +0000 | [diff] [blame] | 550 | #if 1 |
| 551 | /* LCD init for cold start */ |
| 552 | PBCR2 &= 0xff00; /* Set PB0..PB3 to GPIO */ |
| 553 | or_b(0x0f, &PBIORL); /* ... output */ |
| 554 | or_b(0x0f, &PBDRL); /* ... and high */ |
| 555 | |
| 556 | lcd_write_command(0x61); |
| 557 | lcd_write_command(0x42); |
| 558 | lcd_write_command(0x57); |
| 559 | |
| 560 | memset(data_vector, 0x24, 13); |
| 561 | lcd_write_command(OLD_LCD_CRAM); /* Set DDRAM address */ |
| 562 | lcd_write_data(data_vector, 13); /* all spaces */ |
| 563 | lcd_write_command(OLD_LCD_CRAM + 0x10); |
| 564 | lcd_write_data(data_vector, 13); |
| 565 | lcd_write_command(OLD_LCD_CRAM + 0x20); |
| 566 | lcd_write_data(data_vector, 13); |
| 567 | |
| 568 | memset(data_vector, 0, 32); |
| 569 | lcd_write_command(OLD_LCD_PRAM); /* Set CGRAM address */ |
| 570 | lcd_write_data(data_vector, 32); /* zero out */ |
| 571 | lcd_write_command(OLD_LCD_IRAM); /* Set ICONRAM address */ |
| 572 | lcd_write_data(data_vector, 13); /* zero out */ |
| 573 | lcd_write_command(OLD_LCD_IRAM + 0x10); |
| 574 | lcd_write_data(data_vector, 13); |
| 575 | |
| 576 | lcd_write_command(0x31); |
| 577 | #else |
| 578 | /* archos look-alike code, left here for reference. As soon as the |
| 579 | * rockbox version is confirmed working, this will go away */ |
| 580 | { |
| 581 | int i; |
| 582 | |
| 583 | PBCR2 &= 0xc000; |
| 584 | PBIOR |= 0x000f; |
| 585 | PBDR |= 0x0002; |
| 586 | PBDR |= 0x0001; |
| 587 | PBDR |= 0x0004; |
| 588 | PBDR |= 0x0008; |
| 589 | |
| 590 | for (i=0; i<200; i++) asm volatile ("nop"); /* wait 100 us */ |
| 591 | |
| 592 | PBDR &= 0xfffd; /* CS low (assert) */ |
| 593 | |
| 594 | for (i=0; i<100; i++) asm volatile ("nop"); /* wait 50 us */ |
| 595 | |
| 596 | lcd_write_command(0x61); |
| 597 | lcd_write_command(0x42); |
| 598 | lcd_write_command(0x57); |
| 599 | |
| 600 | memset(data_vector, 0x24, 13); |
| 601 | lcd_write_command(0xb0); /* Set DDRAM address */ |
| 602 | lcd_write_data(data_vector, 13); /* all spaces */ |
| 603 | lcd_write_command(0xc0); |
| 604 | lcd_write_data(data_vector, 13); |
| 605 | lcd_write_command(0xd0); |
| 606 | lcd_write_data(data_vector, 13); |
| 607 | |
| 608 | memset(data_vector, 0, 32); |
| 609 | lcd_write_command(0x80); /* Set CGRAM address */ |
| 610 | lcd_write_data(data_vector, 32); /* zero out */ |
| 611 | lcd_write_command(0xe0); /* Set ICONRAM address */ |
| 612 | lcd_write_data(data_vector, 13); /* zero out */ |
| 613 | lcd_write_command(0xf0); |
| 614 | lcd_write_data(data_vector, 13); |
| 615 | |
| 616 | for (i=0; i<300000; i++) asm volatile ("nop"); /* wait 150 ms */ |
| 617 | |
| 618 | lcd_write_command(0x31); |
| 619 | lcd_write_command(0xa8); /* Set contrast control */ |
| 620 | lcd_data_byte = 0; |
| 621 | lcd_write_data(&lcd_data_byte, 1); /* 0 */ |
| 622 | } |
| 623 | #endif |
Jens Arnold | 1710e38 | 2004-11-11 01:36:37 +0000 | [diff] [blame] | 624 | #endif /* !SIMULATOR */ |
Linus Nielsen Feltzing | 0a4b247 | 2002-10-15 12:25:57 +0000 | [diff] [blame] | 625 | } |
| 626 | |
Björn Stenberg | 067262d | 2003-07-09 23:07:49 +0000 | [diff] [blame] | 627 | lcd_set_contrast(lcd_default_contrast()); |
| 628 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 629 | create_thread(scroll_thread, scroll_stack, |
| 630 | sizeof(scroll_stack), scroll_name); |
| 631 | } |
| 632 | |
Kjell Ericson | 6143eeb | 2003-05-27 12:54:11 +0000 | [diff] [blame] | 633 | void lcd_jump_scroll (int mode) /* 0=off, 1=once, ..., JUMP_SCROLL_ALWAYS */ |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 634 | { |
| 635 | jump_scroll=mode; |
| 636 | } |
| 637 | |
Mats Lidell | 4c7f70f | 2003-01-14 10:45:57 +0000 | [diff] [blame] | 638 | void lcd_bidir_scroll(int percent) |
| 639 | { |
| 640 | bidir_limit = percent; |
| 641 | } |
| 642 | |
Jens Arnold | c76c568 | 2004-08-16 23:37:23 +0000 | [diff] [blame] | 643 | void lcd_puts_scroll(int x, int y, const unsigned char* string ) |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 644 | { |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 645 | struct scrollinfo* s; |
Marcoen Hirschberg | b0fee17 | 2005-12-06 13:27:15 +0000 | [diff] [blame^] | 646 | int i=0; |
| 647 | unsigned short ucs; |
| 648 | const unsigned char *utf8 = string; |
| 649 | unsigned char tmp[utf8length(string)+1]; |
| 650 | |
| 651 | while (*utf8) { |
| 652 | utf8 = utf8decode(utf8, &ucs); |
| 653 | if (ucs < 256) |
| 654 | tmp[i++] = ucs; |
| 655 | else |
| 656 | tmp[i++] = '?'; |
| 657 | } |
| 658 | |
| 659 | tmp[i] = 0; |
| 660 | |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 661 | |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 662 | DEBUGF("lcd_puts_scroll(%d, %d, %s)\n", x, y, string); |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 663 | |
Kjell Ericson | dd7f294 | 2003-01-10 09:58:04 +0000 | [diff] [blame] | 664 | s = &scroll[y]; |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 665 | |
Marcoen Hirschberg | b0fee17 | 2005-12-06 13:27:15 +0000 | [diff] [blame^] | 666 | lcd_puts_cont_scroll(x,y,tmp); |
| 667 | s->textlen = strlen(tmp); |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 668 | |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 669 | if ( s->textlen > 11-x ) { |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 670 | s->mode = SCROLL_MODE_RUN; |
Kjell Ericson | dc88e23 | 2003-01-10 12:23:36 +0000 | [diff] [blame] | 671 | s->scroll_start_tick = current_tick + scroll_delay; |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 672 | s->offset=0; |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 673 | s->startx=x; |
| 674 | s->starty=y; |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 675 | s->direction=+1; |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 676 | s->jump_scroll=0; |
Kjell Ericson | 6143eeb | 2003-05-27 12:54:11 +0000 | [diff] [blame] | 677 | s->jump_scroll_steps=0; |
Jens Arnold | 566eae2 | 2004-10-15 20:30:29 +0000 | [diff] [blame] | 678 | if (jump_scroll && jump_scroll_delay<scroll_ticks*(s->textlen-11+x)) { |
Kjell Ericson | 6143eeb | 2003-05-27 12:54:11 +0000 | [diff] [blame] | 679 | s->jump_scroll_steps=11-x; |
| 680 | s->jump_scroll=jump_scroll; |
| 681 | } |
Marcoen Hirschberg | b0fee17 | 2005-12-06 13:27:15 +0000 | [diff] [blame^] | 682 | strncpy(s->text,tmp,sizeof s->text); |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 683 | s->turn_offset=-1; |
Mats Lidell | 4c7f70f | 2003-01-14 10:45:57 +0000 | [diff] [blame] | 684 | if (bidir_limit && (s->textlen < ((11-x)*(100+bidir_limit))/100)) { |
Kjell Ericson | b113073 | 2003-01-10 14:48:53 +0000 | [diff] [blame] | 685 | s->turn_offset=s->textlen+x-11; |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 686 | } |
| 687 | else { |
| 688 | for (i=0; i<scroll_spacing && |
| 689 | s->textlen<(int)sizeof(s->text); i++) { |
Kjell Ericson | ac984ed | 2003-01-10 14:45:15 +0000 | [diff] [blame] | 690 | s->text[s->textlen++]=' '; |
| 691 | } |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 692 | } |
| 693 | if (s->textlen<(int)sizeof(s->text)) |
| 694 | s->text[s->textlen]=' '; |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 695 | s->text[sizeof s->text - 1] = 0; |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 696 | } |
| 697 | else |
Kjell Ericson | dc88e23 | 2003-01-10 12:23:36 +0000 | [diff] [blame] | 698 | s->mode = SCROLL_MODE_OFF; |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 699 | } |
| 700 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 701 | void lcd_stop_scroll(void) |
| 702 | { |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 703 | struct scrollinfo* s; |
| 704 | int index; |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 705 | |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 706 | for ( index = 0; index < SCROLLABLE_LINES; index++ ) { |
| 707 | s = &scroll[index]; |
| 708 | if ( s->mode == SCROLL_MODE_RUN || |
| 709 | s->mode == SCROLL_MODE_PAUSE ) { |
| 710 | /* restore scrolled row */ |
| 711 | lcd_puts(s->startx, s->starty, s->text); |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 712 | } |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 713 | } |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 714 | |
| 715 | lcd_update(); |
| 716 | } |
| 717 | |
Jens Arnold | 566eae2 | 2004-10-15 20:30:29 +0000 | [diff] [blame] | 718 | static const char scroll_tick_table[16] = { |
| 719 | /* Hz values: |
| 720 | 1, 1.25, 1.55, 2, 2.5, 3.12, 4, 5, 6.25, 8.33, 10, 12.5, 16.7, 20, 25, 33 */ |
| 721 | 100, 80, 64, 50, 40, 32, 25, 20, 16, 12, 10, 8, 6, 5, 4, 3 |
| 722 | }; |
| 723 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 724 | void lcd_scroll_speed(int speed) |
| 725 | { |
Jens Arnold | 566eae2 | 2004-10-15 20:30:29 +0000 | [diff] [blame] | 726 | scroll_ticks = scroll_tick_table[speed]; |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Björn Stenberg | a2e98c1 | 2002-12-12 15:20:37 +0000 | [diff] [blame] | 729 | void lcd_scroll_delay(int ms) |
| 730 | { |
| 731 | scroll_delay = ms / (HZ / 10); |
Kjell Ericson | dc88e23 | 2003-01-10 12:23:36 +0000 | [diff] [blame] | 732 | DEBUGF("scroll_delay=%d (ms=%d, HZ=%d)\n", scroll_delay, ms, HZ); |
Björn Stenberg | a2e98c1 | 2002-12-12 15:20:37 +0000 | [diff] [blame] | 733 | } |
Kjell Ericson | 6143eeb | 2003-05-27 12:54:11 +0000 | [diff] [blame] | 734 | |
| 735 | void lcd_jump_scroll_delay(int ms) |
| 736 | { |
| 737 | jump_scroll_delay = ms / (HZ / 10); |
| 738 | DEBUGF("jump_scroll_delay=%d (ms=%d, HZ=%d)\n", jump_scroll_delay, ms, HZ); |
| 739 | } |
| 740 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 741 | static void scroll_thread(void) |
| 742 | { |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 743 | struct scrollinfo* s; |
| 744 | int index; |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 745 | int i, o; |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 746 | bool update; |
| 747 | |
| 748 | /* initialize scroll struct array */ |
| 749 | for (index = 0; index < SCROLLABLE_LINES; index++) { |
| 750 | scroll[index].mode = SCROLL_MODE_OFF; |
| 751 | } |
| 752 | |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 753 | while ( 1 ) { |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 754 | |
| 755 | update = false; |
| 756 | |
Kjell Ericson | dc88e23 | 2003-01-10 12:23:36 +0000 | [diff] [blame] | 757 | for ( index = 0; index < SCROLLABLE_LINES; index++ ) { |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 758 | s = &scroll[index]; |
| 759 | if ( s->mode == SCROLL_MODE_RUN ) { |
| 760 | if ( TIME_AFTER(current_tick, s->scroll_start_tick) ) { |
| 761 | char buffer[12]; |
Kjell Ericson | 6143eeb | 2003-05-27 12:54:11 +0000 | [diff] [blame] | 762 | int jumping_scroll=s->jump_scroll; |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 763 | update = true; |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 764 | if (s->jump_scroll) { |
Mats Lidell | 3798249 | 2003-08-18 05:27:13 +0000 | [diff] [blame] | 765 | |
| 766 | /* Find new position to start jump scroll by |
| 767 | * finding last white space within |
| 768 | * jump_scroll_steps */ |
| 769 | int i; |
| 770 | o = s->offset = s->offset + s->jump_scroll_steps; |
| 771 | for (i = 0; i < s->jump_scroll_steps; i++, o--) { |
| 772 | if (o < s->textlen && |
| 773 | ((0x20 <= s->text[o] && s->text[o] <= 0x2f) || s->text[o] == '_')) |
| 774 | { |
| 775 | s->offset = o; |
| 776 | break; |
| 777 | } |
| 778 | } |
| 779 | |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 780 | s->scroll_start_tick = current_tick + |
Kjell Ericson | 6143eeb | 2003-05-27 12:54:11 +0000 | [diff] [blame] | 781 | jump_scroll_delay; |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 782 | /* Eat space */ |
| 783 | while (s->offset < s->textlen && |
Mats Lidell | 3798249 | 2003-08-18 05:27:13 +0000 | [diff] [blame] | 784 | ((0x20 <= s->text[s->offset] && s->text[s->offset] <= 0x2f) || |
| 785 | s->text[s->offset] == '_')) { |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 786 | s->offset++; |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 787 | } |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 788 | if (s->offset >= s->textlen) { |
| 789 | s->offset=0; |
Kjell Ericson | 6143eeb | 2003-05-27 12:54:11 +0000 | [diff] [blame] | 790 | s->scroll_start_tick = current_tick + |
| 791 | scroll_delay; |
| 792 | if (s->jump_scroll != JUMP_SCROLL_ALWAYS) { |
| 793 | s->jump_scroll--; |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 794 | s->direction=1; |
| 795 | } |
| 796 | } |
| 797 | } else { |
| 798 | if ( s->offset < s->textlen-1 ) { |
| 799 | s->offset+=s->direction; |
| 800 | if (s->offset==0) { |
| 801 | s->direction=+1; |
| 802 | s->scroll_start_tick = current_tick + |
| 803 | scroll_delay; |
| 804 | } else { |
| 805 | if (s->offset == s->turn_offset) { |
| 806 | s->direction=-1; |
| 807 | s->scroll_start_tick = current_tick + |
| 808 | scroll_delay; |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | else { |
| 813 | s->offset = 0; |
| 814 | } |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 815 | } |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 816 | |
| 817 | i=0; |
| 818 | o=s->offset; |
| 819 | while (i<11) { |
| 820 | buffer[i++]=s->text[o++]; |
Mats Lidell | 3798249 | 2003-08-18 05:27:13 +0000 | [diff] [blame] | 821 | if (o==s->textlen /* || (jump_scroll && buffer[i-1] == ' ') */) |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 822 | break; |
| 823 | } |
| 824 | o=0; |
Kjell Ericson | 6143eeb | 2003-05-27 12:54:11 +0000 | [diff] [blame] | 825 | if (s->turn_offset == -1 && !jumping_scroll) { |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 826 | while (i<11) { |
| 827 | buffer[i++]=s->text[o++]; |
| 828 | } |
| 829 | } else { |
| 830 | while (i<11) { |
| 831 | buffer[i++]=' '; |
| 832 | } |
Kjell Ericson | 54c8c71 | 2003-01-10 13:22:07 +0000 | [diff] [blame] | 833 | } |
| 834 | buffer[11]=0; |
Kjell Ericson | 53f156a | 2003-05-22 06:42:14 +0000 | [diff] [blame] | 835 | |
Kjell Ericson | 7f9d713 | 2003-01-22 12:16:14 +0000 | [diff] [blame] | 836 | lcd_puts_cont_scroll(s->startx, s->starty, buffer); |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 837 | } |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 838 | } |
Kjell Ericson | 565505a | 2003-01-27 14:37:03 +0000 | [diff] [blame] | 839 | if (cursor.len>0) { |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 840 | if (cursor.downcount--<0) { |
| 841 | cursor.downcount=cursor.divider; |
| 842 | cursor.textpos++; |
| 843 | if (cursor.textpos>=cursor.len) |
| 844 | cursor.textpos=0; |
Jens Arnold | ba4df32 | 2005-05-08 13:03:57 +0000 | [diff] [blame] | 845 | #ifdef SIMULATOR |
| 846 | lcdx_putc(cursor.x_pos, cursor.y_pos, |
| 847 | cursor.text[cursor.textpos]); |
| 848 | update=true; |
| 849 | #else |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 850 | update|=lcdx_putc(cursor.x_pos, cursor.y_pos, |
| 851 | cursor.text[cursor.textpos]); |
Jens Arnold | ba4df32 | 2005-05-08 13:03:57 +0000 | [diff] [blame] | 852 | #endif |
Daniel Stenberg | 0c4a35f | 2003-01-29 17:31:55 +0000 | [diff] [blame] | 853 | } |
Kjell Ericson | 565505a | 2003-01-27 14:37:03 +0000 | [diff] [blame] | 854 | } |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 855 | if (update) { |
| 856 | lcd_update(); |
| 857 | } |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 858 | } |
Markus Braun | bc254fe | 2002-10-21 13:14:25 +0000 | [diff] [blame] | 859 | |
Jens Arnold | 566eae2 | 2004-10-15 20:30:29 +0000 | [diff] [blame] | 860 | sleep(scroll_ticks); |
Björn Stenberg | 86f9a84 | 2002-09-23 11:17:52 +0000 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | |
| 864 | #endif /* HAVE_LCD_CHARCELLS */ |