diff options
Diffstat (limited to 'firmware/lcd.h')
-rw-r--r-- | firmware/lcd.h | 263 |
1 files changed, 263 insertions, 0 deletions
diff --git a/firmware/lcd.h b/firmware/lcd.h new file mode 100644 index 0000000000..03c459c303 --- /dev/null +++ b/firmware/lcd.h | |||
@@ -0,0 +1,263 @@ | |||
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 | |||
20 | #ifndef __LCD_H__ | ||
21 | #define __LCD_H__ | ||
22 | |||
23 | #include <sh7034.h> | ||
24 | #include <system.h> | ||
25 | |||
26 | #define LCDR (PBDR+1) | ||
27 | |||
28 | /* PA14 : /LCD-BL --- backlight */ | ||
29 | #define LCD_BL (14-8) | ||
30 | |||
31 | #ifdef JBP /* JukeBox MP3 Player - AJB6K, AJBS20 */ | ||
32 | # define LCD_DS +1 // PB0 = 1 --- 0001 --- LCD-DS | ||
33 | # define LCD_CS +2 // PB1 = 1 --- 0010 --- /LCD-CS | ||
34 | # define LCD_SD +4 // PB2 = 1 --- 0100 --- LCD-SD | ||
35 | # define LCD_SC +8 // PB3 = 1 --- 1000 --- LCD-SC | ||
36 | # ifndef JBP_OLD | ||
37 | # define LCD_CONTRAST_SET ((char)0x50) | ||
38 | # define LCD_CRAM ((char)0x80) /* Characters */ | ||
39 | # define LCD_PRAM ((char)0xC0) /* Patterns */ | ||
40 | # define LCD_IRAM ((char)0x40) /* Icons */ | ||
41 | # else | ||
42 | # define LCD_CONTRAST_SET ((char)0xA8) | ||
43 | # define LCD_CRAM ((char)0xB0) /* Characters */ | ||
44 | # define LCD_PRAM ((char)0x80) /* Patterns */ | ||
45 | # define LCD_IRAM ((char)0xE0) /* Icons */ | ||
46 | # endif | ||
47 | # define LCD_ASCII(c) (lcd_ascii[(c)&255]) | ||
48 | # define LCD_CURSOR(x,y) ((char)(LCD_CRAM+((y)*16+(x)))) | ||
49 | # define LCD_ICON(i) ((char)(LCD_IRAM+i)) | ||
50 | # define LCD_ICON_BATTERY 0 | ||
51 | # define LCD_BATTERY_FRAME 0x02 | ||
52 | # define LCD_BATTERY_BAR1 0x08 | ||
53 | # define LCD_BATTERY_BAR2 0x04 | ||
54 | # define LCD_BATTERY_BAR3 0x10 | ||
55 | # define LCD_ICON_USB 2 | ||
56 | # define LCD_USB_LOGO 0xFF | ||
57 | # define LCD_ICON_PLAY 3 | ||
58 | # define LCD_PLAY_ICON 0xFF | ||
59 | # define LCD_ICON_RECORD 4 | ||
60 | # define LCD_RECORD_ICON 0x10 | ||
61 | # define LCD_ICON_STOP 5 | ||
62 | # define LCD_STOP_ICON 0x0F | ||
63 | # define LCD_ICON_AUDIO 5 | ||
64 | # define LCD_AUDIO_ICON 0xF0 | ||
65 | # define LCD_ICON_REVERSE 6 | ||
66 | # define LCD_REVERSE_ICON 0xFF | ||
67 | # define LCD_ICON_SINGLE 7 | ||
68 | # define LCD_SINGLE_ICON 0xFF | ||
69 | # define LCD_ICON_VOLUME0 9 | ||
70 | # define LCD_VOLUME_ICON 0x04 | ||
71 | # define LCD_VOLUME_BAR1 0x02 | ||
72 | # define LCD_VOLUME_BAR2 0x01 | ||
73 | # define LCD_ICON_VOLUME1 10 | ||
74 | # define LCD_VOLUME_BAR3 0x08 | ||
75 | # define LCD_VOLUME_BAR4 0x04 | ||
76 | # define LCD_VOLUME_BAR5 0x01 | ||
77 | # define LCD_ICON_PARAM 10 | ||
78 | # define LCD_PARAM_SYMBOL 0xF0 | ||
79 | #endif | ||
80 | |||
81 | #ifdef JBR /* JukeBox MP3 Recorder - AJBR --- FIXME */ | ||
82 | # error "JBR : FIX ME" | ||
83 | #endif | ||
84 | |||
85 | |||
86 | /* | ||
87 | * About /CS,DS,SC,SD | ||
88 | * ------------------ | ||
89 | * | ||
90 | * LCD on JBP and JBR uses a SPI protocol to receive orders (SDA and SCK lines) | ||
91 | * | ||
92 | * - /CS -> Chip Selection line : | ||
93 | * 0 : LCD chipset is activated. | ||
94 | * - DS -> Data Selection line, latched at the rising edge | ||
95 | * of the 8th serial clock (*) : | ||
96 | * 0 : instruction register, | ||
97 | * 1 : data register; | ||
98 | * - SC -> Serial Clock line (SDA). | ||
99 | * - SD -> Serial Data line (SCK), latched at the rising edge | ||
100 | * of each serial clock (*). | ||
101 | * | ||
102 | * _ _ | ||
103 | * /CS \ / | ||
104 | * \______________________________________________________/ | ||
105 | * _____ ____ ____ ____ ____ ____ ____ ____ ____ _____ | ||
106 | * SD \/ D7 \/ D6 \/ D5 \/ D4 \/ D3 \/ D2 \/ D1 \/ D0 \/ | ||
107 | * _____/\____/\____/\____/\____/\____/\____/\____/\____/\_____ | ||
108 | * | ||
109 | * _____ _ _ _ _ _ _ _ ________ | ||
110 | * SC \ * \ * \ * \ * \ * \ * \ * \ * | ||
111 | * \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ | ||
112 | * _ _________________________________________________________ | ||
113 | * DS \/ | ||
114 | * _/\_________________________________________________________ | ||
115 | * | ||
116 | */ | ||
117 | |||
118 | /* | ||
119 | * The only way to do logical operations in an atomic way | ||
120 | * on SH1 is using : | ||
121 | * | ||
122 | * or.b/and.b/tst.b/xor.b #imm,@(r0,gbr) | ||
123 | * | ||
124 | * but GCC doesn't generate them at all so some assembly | ||
125 | * codes are needed here. | ||
126 | * | ||
127 | * The Global Base Register gbr is expected to be zero | ||
128 | * and r0 is the address of one register in the on-chip | ||
129 | * peripheral module. | ||
130 | * | ||
131 | */ | ||
132 | |||
133 | static inline void lcd_start (void) | ||
134 | /* | ||
135 | * Enter a LCD session : | ||
136 | * | ||
137 | * QI(LCDR) &= ~(LCD_CS|LCD_DS|LCD_SD|LCD_SC); | ||
138 | */ | ||
139 | { | ||
140 | asm | ||
141 | ("and.b\t%0,@(r0,gbr)" | ||
142 | : | ||
143 | : /* %0 */ "I"(~(LCD_CS|LCD_DS|LCD_SD|LCD_SC)), | ||
144 | /* %1 */ "z"(LCDR)); | ||
145 | } | ||
146 | |||
147 | static inline void lcd_stop (void) | ||
148 | /* | ||
149 | * Leave a LCD session : | ||
150 | * | ||
151 | * QI(LCDR) |= LCD_CS|LCD_RS|LCD_SD|LCD_SC; | ||
152 | */ | ||
153 | { | ||
154 | asm | ||
155 | ("or.b\t%0,@(r0,gbr)" | ||
156 | : | ||
157 | : /* %0 */ "I"(LCD_CS|LCD_DS|LCD_SD|LCD_SC), | ||
158 | /* %1 */ "z"(LCDR)); | ||
159 | } | ||
160 | |||
161 | static inline void lcd_byte (int byte,int rs) | ||
162 | /* | ||
163 | * char j = 0x80; | ||
164 | * if (rs) | ||
165 | * do | ||
166 | * { | ||
167 | * QI(LCDR) &= ~(LCD_SC|LCD_SD); | ||
168 | * if (j & byte) | ||
169 | * QI(LCDR) |= LCD_SD; | ||
170 | * QI(LCDR) |= LCD_SC|LCD_DS; | ||
171 | * } | ||
172 | * while ((unsigned char)j >>= 1); | ||
173 | * else | ||
174 | * do | ||
175 | * { | ||
176 | * QI(LCDR) &= ~(LCD_SC|LCD_SD|LCD_DS); | ||
177 | * if (j & byte) | ||
178 | * QI(LCDR) |= LCD_SD; | ||
179 | * QI(LCDR) |= LCD_SC; | ||
180 | * } | ||
181 | * while ((unsigned char)j >>= 1); | ||
182 | */ | ||
183 | { | ||
184 | if (rs > 0) | ||
185 | asm | ||
186 | ("shll8\t%0\n" | ||
187 | "0:\n\t" | ||
188 | "and.b\t%2,@(r0,gbr)\n\t" | ||
189 | "shll\t%0\n\t" | ||
190 | "bf\t1f\n\t" | ||
191 | "or.b\t%3,@(r0,gbr)\n" | ||
192 | "1:\n\t" | ||
193 | "or.b\t%4,@(r0,gbr)\n" | ||
194 | "add\t#-1,%1\n\t" | ||
195 | "cmp/pl\t%1\n\t" | ||
196 | "bt\t0b" | ||
197 | : | ||
198 | : /* %0 */ "r"(((unsigned)byte)<<16), | ||
199 | /* %1 */ "r"(8), | ||
200 | /* %2 */ "I"(~(LCD_SC|LCD_SD)), | ||
201 | /* %3 */ "I"(LCD_SD), | ||
202 | /* %4 */ "I"(LCD_SC|LCD_DS), | ||
203 | /* %5 */ "z"(LCDR)); | ||
204 | else | ||
205 | asm | ||
206 | ("shll8\t%0\n" | ||
207 | "0:\n\t" | ||
208 | "and.b\t%2,@(r0,gbr)\n\t" | ||
209 | "shll\t%0\n\t" | ||
210 | "bf\t1f\n\t" | ||
211 | "or.b\t%3,@(r0,gbr)\n" | ||
212 | "1:\n\t" | ||
213 | "or.b\t%4,@(r0,gbr)\n" | ||
214 | "add\t#-1,%1\n\t" | ||
215 | "cmp/pl\t%1\n\t" | ||
216 | "bt\t0b" | ||
217 | : | ||
218 | : /* %0 */ "r"(((unsigned)byte)<<16), | ||
219 | /* %1 */ "r"(8), | ||
220 | /* %2 */ "I"(~(LCD_SC|LCD_DS|LCD_SD)), | ||
221 | /* %3 */ "I"(LCD_SD), | ||
222 | /* %4 */ "I"(LCD_SC), | ||
223 | /* %5 */ "z"(LCDR)); | ||
224 | } | ||
225 | |||
226 | extern void lcd_data (int data); | ||
227 | extern void lcd_instruction (int instruction); | ||
228 | extern void lcd_zero (int length); | ||
229 | extern void lcd_fill (int data,int length); | ||
230 | extern void lcd_copy (void *data,int count); | ||
231 | |||
232 | #ifdef JBP | ||
233 | |||
234 | extern void lcd_puts (char const *string); | ||
235 | extern void lcd_putns (char const *string,int n); | ||
236 | extern void lcd_putc (int character); | ||
237 | extern void lcd_puthex (unsigned int value,int digits); | ||
238 | |||
239 | extern void lcd_pattern (int which,char const *pattern,int count); | ||
240 | |||
241 | static inline void lcd_goto (int x,int y) | ||
242 | { lcd_instruction (LCD_CURSOR(x,y)); } | ||
243 | |||
244 | #endif | ||
245 | |||
246 | #ifdef JBR | ||
247 | # error "JBR : FIX ME" | ||
248 | #endif | ||
249 | |||
250 | /*** BACKLIGHT ***/ | ||
251 | |||
252 | static inline void lcd_toggle_backlight (void) | ||
253 | { toggle_bit (LCD_BL,PAIOR); } | ||
254 | |||
255 | static inline void lcd_turn_on_backlight (void) | ||
256 | { set_bit (LCD_BL,PAIOR); } | ||
257 | |||
258 | static inline void lcd_turn_off_backlight (void) | ||
259 | { clear_bit (LCD_BL,PAIOR); } | ||
260 | |||
261 | /*** ICONS ***/ | ||
262 | |||
263 | #endif | ||