1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2008 by Denes Balatoni
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
35 static uint8_t lcd_type
;
36 static int xoffset
; /* needed for flip */
38 /*** hardware configuration ***/
40 int lcd_default_contrast(void)
45 void lcd_set_contrast(int val
)
49 void lcd_set_invert_display(bool yesno
)
53 /* turn the display upside down (call lcd_update() afterwards) */
54 void lcd_set_flip(bool yesno
)
56 /* TODO: flip mode isn't working. The commands in the else part of
57 this function are how the original firmware inits the LCD */
61 xoffset
= 132 - LCD_WIDTH
; /* 132 colums minus the 128 we have */
69 static void lcd_sleep(uint32_t t
)
75 static uint8_t lcd_readdata()
79 return (LCD_DBUFF
/* & 0xff*/);
82 static void lcd_writereg(uint32_t reg
, uint32_t data
)
85 LCD_WCMD
= reg
& 0xff;
86 LCD_WDATA
= data
>> 8;
87 LCD_WDATA
= data
& 0xff;
94 lcd_writereg(0x7, 0x21);
95 lcd_writereg(0x12, 0x137);
97 lcd_writereg(0x7, 0x21);
98 lcd_writereg(0x12, 0x1137);
100 lcd_writereg(0x7, 0x233);
105 /* FIXME wait for DMA to finnish */
115 void lcd_init_device(void)
119 /* init basic things */
127 LCD_RST_TIME
= 0x7ff;
129 /* detect lcd type */
137 data
[0]=lcd_readdata();
138 data
[1]=lcd_readdata();
139 data
[2]=lcd_readdata();
140 data
[3]=lcd_readdata();
141 data
[4]=lcd_readdata();
144 if (((data
[1]==0x38) && ((data
[2] & 0xf0) == 0x80)) ||
145 ((data
[2]==0x38) && ((data
[3] & 0xf0) == 0x80)))
169 lcd_writereg(0xa4, 0x1);
171 lcd_writereg(0x1, 0x100);
172 lcd_writereg(0x2, 0x300);
173 lcd_writereg(0x3, 0x9230);
174 lcd_writereg(0x8, 0x404);
175 lcd_writereg(0xe, 0x10);
176 lcd_writereg(0x70, 0x1000);
177 lcd_writereg(0x71, 0x1);
178 lcd_writereg(0x30, 0x2);
179 lcd_writereg(0x31, 0x400);
180 lcd_writereg(0x32, 0x7);
181 lcd_writereg(0x33, 0x500);
182 lcd_writereg(0x34, 0x7);
183 lcd_writereg(0x35, 0x703);
184 lcd_writereg(0x36, 0x507);
185 lcd_writereg(0x37, 0x5);
186 lcd_writereg(0x38, 0x1404);
187 lcd_writereg(0x39, 0xe);
188 lcd_writereg(0x40, 0x202);
189 lcd_writereg(0x41, 0x3);
190 lcd_writereg(0x42, 0x0);
191 lcd_writereg(0x43, 0x200);
192 lcd_writereg(0x44, 0x707);
193 lcd_writereg(0x45, 0x407);
194 lcd_writereg(0x46, 0x505);
195 lcd_writereg(0x47, 0x2);
196 lcd_writereg(0x48, 0x4);
197 lcd_writereg(0x49, 0x4);
198 lcd_writereg(0x60, 0x202);
199 lcd_writereg(0x61, 0x3);
200 lcd_writereg(0x62, 0x0);
201 lcd_writereg(0x63, 0x200);
202 lcd_writereg(0x64, 0x707);
203 lcd_writereg(0x65, 0x407);
204 lcd_writereg(0x66, 0x505);
205 lcd_writereg(0x67, 0x2);
206 lcd_writereg(0x68, 0x4);
207 lcd_writereg(0x69, 0x4);
208 lcd_writereg(0x7, 0x1);
209 lcd_writereg(0x18, 0x1);
210 lcd_writereg(0x10, 0x1690);
211 lcd_writereg(0x11, 0x100);
212 lcd_writereg(0x12, 0x117);
213 lcd_writereg(0x13, 0xf80);
214 lcd_writereg(0x12, 0x137);
215 lcd_writereg(0x20, 0x0);
216 lcd_writereg(0x21, 0x0);
217 lcd_writereg(0x50, 0x0);
218 lcd_writereg(0x51, 0xaf);
219 lcd_writereg(0x52, 0x0);
220 lcd_writereg(0x53, 0x83);
221 lcd_writereg(0x90, 0x0);
222 lcd_writereg(0x91, 0x0);
223 lcd_writereg(0x92, 0x0);
224 lcd_writereg(0x98, 0x0);
225 lcd_writereg(0x99, 0x903);
226 lcd_writereg(0x9a, 0x502);
227 lcd_writereg(0x9b, 0x300);
235 /*** Update functions ***/
237 /* Performance function that works with an external buffer
238 note that by and bheight are in 8-pixel units! */
239 void lcd_blit_mono(const unsigned char *data
, int x
, int by
, int width
,
240 int bheight
, int stride
)
242 /* Copy display bitmap to hardware */
249 /* Performance function that works with an external buffer
250 note that by and bheight are in 8-pixel units! */
251 void lcd_blit_grey_phase_blit(unsigned char *values
, unsigned char *phases
,
252 int x
, int by
, int width
, int bheight
, int stride
)
263 /* Update the display.
264 This must be called after all other LCD functions that change the display. */
265 void lcd_update(void) ICODE_ATTR
;
266 void lcd_update(void)
271 /* Copy display bitmap to hardware */
285 lcd_writereg(0x20, 0x0);
286 lcd_writereg(0x21, 0x0);
290 for(p
=&lcd_framebuffer
[0][0], i
=0;i
<LCD_WIDTH
*LCD_FBHEIGHT
;++i
, ++p
) {
291 LCD_WDATA
= RGB_UNPACK_RED(*p
)<<3;
292 LCD_WDATA
= RGB_UNPACK_GREEN(*p
)<<2;
293 LCD_WDATA
= RGB_UNPACK_BLUE(*p
)<<3;
294 lcd_sleep(1); /* if data is sent too fast to lcdif, machine freezes */
298 /* Update a fraction of the display. */
299 void lcd_update_rect(int, int, int, int) ICODE_ATTR
;
300 void lcd_update_rect(int x
, int y
, int width
, int height
)