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 ****************************************************************************/
32 #define STAT_BUS_IDLE (1<<8) /* Data bus idle */
33 #define STAT_FULL (1<<4) /* FIFO full */
34 #define STAT_READON (1<<0) /* Read operation done */
37 static uint8_t lcd_type
;
38 static int xoffset
; /* needed for flip */
40 /*** hardware configuration ***/
42 int lcd_default_contrast(void)
47 void lcd_set_contrast(int val
)
51 void lcd_set_invert_display(bool yesno
)
55 /* turn the display upside down (call lcd_update() afterwards) */
56 void lcd_set_flip(bool yesno
)
58 /* TODO: flip mode isn't working. The commands in the else part of
59 this function are how the original firmware inits the LCD */
63 xoffset
= 132 - LCD_WIDTH
; /* 132 colums minus the 128 we have */
71 static void lcd_sleep(uint32_t t
)
77 static uint8_t lcd_readdata(void)
81 return (LCD_DBUFF
/* & 0xff*/);
84 static void lcd_writereg(uint32_t reg
, uint32_t data
)
86 while (LCD_STATUS
& STAT_FULL
);
88 while (LCD_STATUS
& STAT_FULL
);
89 LCD_WCMD
= reg
& 0xff;
90 while (LCD_STATUS
& STAT_FULL
);
91 LCD_WDATA
= data
>> 8;
92 while (LCD_STATUS
& STAT_FULL
);
93 LCD_WDATA
= data
& 0xff;
100 lcd_writereg(0x7, 0x21);
101 lcd_writereg(0x12, 0x137);
103 lcd_writereg(0x7, 0x21);
104 lcd_writereg(0x12, 0x1137);
106 lcd_writereg(0x7, 0x233);
111 /* FIXME wait for DMA to finnish */
121 void lcd_init_device(void)
126 /* init basic things */
134 LCD_RST_TIME
= 0x7ff;
136 /* detect lcd type, it's not detected the first time for some reason */
145 data
[0]=lcd_readdata();
146 data
[1]=lcd_readdata();
147 data
[2]=lcd_readdata();
148 data
[3]=lcd_readdata();
149 data
[4]=lcd_readdata();
152 if (((data
[1]==0x38) && ((data
[2] & 0xf0) == 0x80)) ||
153 ((data
[2]==0x38) && ((data
[3] & 0xf0) == 0x80)))
177 lcd_writereg(0xa4, 0x1);
179 lcd_writereg(0x1, 0x100);
180 lcd_writereg(0x2, 0x300);
181 lcd_writereg(0x3, 0x9230);
182 lcd_writereg(0x8, 0x404);
183 lcd_writereg(0xe, 0x10);
184 lcd_writereg(0x70, 0x1000);
185 lcd_writereg(0x71, 0x1);
186 lcd_writereg(0x30, 0x2);
187 lcd_writereg(0x31, 0x400);
188 lcd_writereg(0x32, 0x7);
189 lcd_writereg(0x33, 0x500);
190 lcd_writereg(0x34, 0x7);
191 lcd_writereg(0x35, 0x703);
192 lcd_writereg(0x36, 0x507);
193 lcd_writereg(0x37, 0x5);
194 lcd_writereg(0x38, 0x1404);
195 lcd_writereg(0x39, 0xe);
196 lcd_writereg(0x40, 0x202);
197 lcd_writereg(0x41, 0x3);
198 lcd_writereg(0x42, 0x0);
199 lcd_writereg(0x43, 0x200);
200 lcd_writereg(0x44, 0x707);
201 lcd_writereg(0x45, 0x407);
202 lcd_writereg(0x46, 0x505);
203 lcd_writereg(0x47, 0x2);
204 lcd_writereg(0x48, 0x4);
205 lcd_writereg(0x49, 0x4);
206 lcd_writereg(0x60, 0x202);
207 lcd_writereg(0x61, 0x3);
208 lcd_writereg(0x62, 0x0);
209 lcd_writereg(0x63, 0x200);
210 lcd_writereg(0x64, 0x707);
211 lcd_writereg(0x65, 0x407);
212 lcd_writereg(0x66, 0x505);
213 lcd_writereg(0x67, 0x2);
214 lcd_writereg(0x68, 0x4);
215 lcd_writereg(0x69, 0x4);
216 lcd_writereg(0x7, 0x1);
217 lcd_writereg(0x18, 0x1);
218 lcd_writereg(0x10, 0x1690);
219 lcd_writereg(0x11, 0x100);
220 lcd_writereg(0x12, 0x117);
221 lcd_writereg(0x13, 0xf80);
222 lcd_writereg(0x12, 0x137);
223 lcd_writereg(0x20, 0x0);
224 lcd_writereg(0x21, 0x0);
225 lcd_writereg(0x50, 0x0);
226 lcd_writereg(0x51, 0xaf);
227 lcd_writereg(0x52, 0x0);
228 lcd_writereg(0x53, 0x83);
229 lcd_writereg(0x90, 0x0);
230 lcd_writereg(0x91, 0x0);
231 lcd_writereg(0x92, 0x0);
232 lcd_writereg(0x98, 0x0);
233 lcd_writereg(0x99, 0x903);
234 lcd_writereg(0x9a, 0x502);
235 lcd_writereg(0x9b, 0x300);
243 /*** Update functions ***/
245 /* Performance function that works with an external buffer
246 note that by and bheight are in 8-pixel units! */
247 void lcd_blit_mono(const unsigned char *data
, int x
, int by
, int width
,
248 int bheight
, int stride
)
250 /* Copy display bitmap to hardware */
257 /* Performance function that works with an external buffer
258 note that by and bheight are in 8-pixel units! */
259 void lcd_blit_grey_phase_blit(unsigned char *values
, unsigned char *phases
,
260 int x
, int by
, int width
, int bheight
, int stride
)
271 /* Update the display.
272 This must be called after all other LCD functions that change the display. */
273 void lcd_update(void) ICODE_ATTR
;
274 void lcd_update(void)
279 /* Copy display bitmap to hardware */
293 lcd_writereg(0x20, 0x0);
294 lcd_writereg(0x21, 0x0);
298 for(p
=&lcd_framebuffer
[0][0], i
=0;i
<LCD_WIDTH
*LCD_FBHEIGHT
;++i
, ++p
) {
299 while (LCD_STATUS
& STAT_FULL
);
300 LCD_WDATA
= RGB_UNPACK_RED(*p
);
301 while (LCD_STATUS
& STAT_FULL
);
302 LCD_WDATA
= RGB_UNPACK_GREEN(*p
);
303 while (LCD_STATUS
& STAT_FULL
);
304 LCD_WDATA
= RGB_UNPACK_BLUE(*p
);
308 /* Update a fraction of the display. */
309 void lcd_update_rect(int, int, int, int) ICODE_ATTR
;
310 void lcd_update_rect(int x
, int y
, int width
, int height
)
315 void lcd_blit_yuv(unsigned char * const src
[3],
316 int src_x
, int src_y
, int stride
,
317 int x
, int y
, int width
, int height
)