1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr
11 * Copyright (C) 2008 François Dinel
12 * Copyright (C) 2008-2009 Rafaël Carré
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
35 #define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00)
36 #define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10)
37 #define LCD_SET_DISPLAY_START_LINE ((char)0x40)
38 #define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81)
39 #define LCD_SET_SEGMENT_REMAP ((char)0xA0)
40 #define LCD_SET_SEGMENT_REMAP_INV ((char)0xA1)
41 #define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4)
42 #define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5)
43 #define LCD_SET_NORMAL_DISPLAY ((char)0xA6)
44 #define LCD_SET_REVERSE_DISPLAY ((char)0xA7)
45 #define LCD_SET_MULTIPLEX_RATIO ((char)0xA8)
46 #define LCD_SET_DC_DC ((char)0xAD)
47 #define LCD_SET_DISPLAY_OFF ((char)0xAE)
48 #define LCD_SET_DISPLAY_ON ((char)0xAF)
49 #define LCD_SET_PAGE_ADDRESS ((char)0xB0)
50 #define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0)
51 #define LCD_SET_COM_OUTPUT_SCAN_DIRECTION_INV ((char)0xC8)
52 #define LCD_SET_DISPLAY_CLOCK_AND_OSC_FREQ ((char)0xD5)
53 #define LCD_SET_VCOM_DESELECT_LEVEL ((char)0xDB)
54 #define LCD_SET_PRECHARGE_PERIOD ((char)0xD9)
55 #define LCD_NOP ((char)0xE3)
57 /* LCD command codes */
58 #define LCD_CNTL_CONTRAST 0x81 /* Contrast */
59 #define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */
60 #define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */
61 #define LCD_CNTL_DISPON 0xaf /* Display on */
63 #define LCD_CNTL_PAGE 0xb0 /* Page address */
64 #define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */
65 #define LCD_CNTL_LOWCOL 0x00 /* Lower column address */
69 static bool display_on
; /* used by lcd_enable */
71 /* Display variant, always 0 in clipv1, clipv2, can be 0 or 1 in clip+
72 * variant 0: has 132 pixel wide framebuffer, max brightness about 50
73 * variant 1: has 128 pixel wide framebuffer, max brightness about 128
77 static int offset
; /* column offset */
79 /*** hardware configuration ***/
81 int lcd_default_contrast(void)
83 return DEFAULT_CONTRAST_SETTING
;
86 void lcd_set_contrast(int val
)
88 lcd_write_command(LCD_CNTL_CONTRAST
);
92 lcd_write_command(val
);
95 void lcd_set_invert_display(bool yesno
)
98 lcd_write_command(LCD_SET_REVERSE_DISPLAY
);
100 lcd_write_command(LCD_SET_NORMAL_DISPLAY
);
103 /* turn the display upside down (call lcd_update() afterwards) */
104 void lcd_set_flip(bool yesno
)
108 lcd_write_command(LCD_SET_SEGMENT_REMAP
);
109 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION
);
113 lcd_write_command(LCD_SET_SEGMENT_REMAP_INV
);
114 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION_INV
);
118 #ifdef HAVE_LCD_ENABLE
119 void lcd_enable(bool enable
)
121 if(display_on
== enable
)
124 if( (display_on
= enable
) ) /* simple '=' is not a typo ! */
126 lcd_enable_power(enable
);
127 lcd_write_command(LCD_SET_DISPLAY_ON
);
128 send_event(LCD_EVENT_ACTIVATION
, NULL
);
132 lcd_write_command(LCD_SET_DISPLAY_OFF
);
133 lcd_enable_power(enable
);
137 bool lcd_active(void)
144 /* LCD init, largely based on what OF does */
145 void lcd_init_device(void)
149 variant
= lcd_hw_init();
150 offset
= (variant
== 0) ? 2 : 0;
152 /* Set display clock (divide ratio = 1) and oscillator frequency (1) */
153 lcd_write_command(LCD_SET_DISPLAY_CLOCK_AND_OSC_FREQ
);
154 lcd_write_command(0x10);
156 /* Set VCOM deselect level to 0.76V */
157 lcd_write_command(LCD_SET_VCOM_DESELECT_LEVEL
);
158 lcd_write_command(0x34);
160 /* Set pre-charge period (p1period is 2 dclk and p2period is 5 dclk) */
161 lcd_write_command(LCD_SET_PRECHARGE_PERIOD
);
162 lcd_write_command(0x25);
164 /* Set contrast register to 12% */
165 lcd_set_contrast(lcd_default_contrast());
167 /* Configure DC-DC */
168 lcd_write_command(LCD_SET_DC_DC
);
169 lcd_write_command((variant
== 0) ? 0x8A : 0x10);
171 /* Set starting line as 0 */
172 lcd_write_command(LCD_SET_DISPLAY_START_LINE
/*|(0 & 0x3f)*/);
174 /* Column 131 is remapped to SEG0 */
175 lcd_write_command(LCD_SET_SEGMENT_REMAP_INV
);
177 /* Invert COM scan direction (N-1 to 0) */
178 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION_INV
);
180 /* Set normal display mode (not every pixel ON) */
181 lcd_write_command(LCD_SET_ENTIRE_DISPLAY_OFF
);
183 /* Set normal display mode (not inverted) */
184 lcd_write_command(LCD_SET_NORMAL_DISPLAY
);
186 /* Clear whole framebuffer, including "overscan"
187 * We don't need to handle that out of screen columns in lcd_clear_display()
188 * since we will never write into it anymore
190 lcd_write_command (LCD_SET_HIGHER_COLUMN_ADDRESS
/*| 0*/);
191 lcd_write_command (LCD_SET_LOWER_COLUMN_ADDRESS
/*| 0*/);
193 fb_data p_bytes
[LCD_WIDTH
+ 2 * offset
];
194 memset(p_bytes
, 0, sizeof(p_bytes
)); /* fills with 0 : pixel off */
195 for(i
= 0; i
< 8; i
++)
197 lcd_write_command (LCD_SET_PAGE_ADDRESS
| (i
/*& 0xf*/));
198 lcd_write_data(p_bytes
, LCD_WIDTH
+ 2 * offset
);
206 /*** Update functions ***/
208 /* Performance function that works with an external buffer
209 note that by and bheight are in 8-pixel units! */
210 void lcd_blit_mono(const unsigned char *data
, int x
, int by
, int width
,
211 int bheight
, int stride
)
216 /* Copy display bitmap to hardware */
219 lcd_write_command (LCD_CNTL_PAGE
| (by
++ & 0xf));
220 lcd_write_command (LCD_CNTL_HIGHCOL
| (((x
+offset
)>>4) & 0xf));
221 lcd_write_command (LCD_CNTL_LOWCOL
| ((x
+offset
) & 0xf));
223 lcd_write_data(data
, width
);
230 /* Helper function for lcd_grey_phase_blit(). */
231 void lcd_grey_data(unsigned char *values
, unsigned char *phases
, int count
);
233 /* Performance function that works with an external buffer
234 note that by and bheight are in 8-pixel units! */
235 void lcd_blit_grey_phase(unsigned char *values
, unsigned char *phases
,
236 int x
, int by
, int width
, int bheight
, int stride
)
241 stride
<<= 3; /* 8 pixels per block */
242 /* Copy display bitmap to hardware */
245 lcd_write_command (LCD_CNTL_PAGE
| (by
++ & 0xf));
246 lcd_write_command (LCD_CNTL_HIGHCOL
| (((x
+offset
)>>4) & 0xf));
247 lcd_write_command (LCD_CNTL_LOWCOL
| ((x
+offset
) & 0xf));
249 lcd_grey_data(values
, phases
, width
);
259 /* Update the display.
260 This must be called after all other LCD functions that change the display. */
261 void lcd_update(void) ICODE_ATTR
;
262 void lcd_update(void)
269 /* Copy display bitmap to hardware */
270 for (y
= 0; y
< LCD_FBHEIGHT
; y
++)
272 lcd_write_command (LCD_CNTL_PAGE
| (y
& 0xf));
273 lcd_write_command (LCD_CNTL_HIGHCOL
| ((offset
>> 4) & 0xf));
274 lcd_write_command (LCD_CNTL_LOWCOL
| (offset
& 0xf));
276 lcd_write_data (FBADDR(0, y
), LCD_WIDTH
);
280 /* Update a fraction of the display. */
281 void lcd_update_rect(int, int, int, int) ICODE_ATTR
;
282 void lcd_update_rect(int x
, int y
, int width
, int height
)
289 /* The Y coordinates have to work on even 8 pixel rows */
290 ymax
= (y
+ height
-1) >> 3;
293 if(x
+ width
> LCD_WIDTH
)
294 width
= LCD_WIDTH
- x
;
296 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
297 if(ymax
>= LCD_FBHEIGHT
)
298 ymax
= LCD_FBHEIGHT
-1;
300 /* Copy specified rectange bitmap to hardware */
301 for (; y
<= ymax
; y
++)
303 lcd_write_command (LCD_CNTL_PAGE
| (y
& 0xf));
304 lcd_write_command (LCD_CNTL_HIGHCOL
| (((x
+offset
) >> 4) & 0xf));
305 lcd_write_command (LCD_CNTL_LOWCOL
| ((x
+offset
) & 0xf));
307 lcd_write_data (FBADDR(x
,y
), width
);