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_DC_DC_PART2 ((char)0x8A)
48 #define LCD_SET_DISPLAY_OFF ((char)0xAE)
49 #define LCD_SET_DISPLAY_ON ((char)0xAF)
50 #define LCD_SET_PAGE_ADDRESS ((char)0xB0)
51 #define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0)
52 #define LCD_SET_COM_OUTPUT_SCAN_DIRECTION_INV ((char)0xC8)
53 #define LCD_SET_DISPLAY_CLOCK_AND_OSC_FREQ ((char)0xD5)
54 #define LCD_SET_VCOM_DESELECT_LEVEL ((char)0xDB)
55 #define LCD_SET_PRECHARGE_PERIOD ((char)0xD9)
56 #define LCD_NOP ((char)0xE3)
58 /* LCD command codes */
59 #define LCD_CNTL_CONTRAST 0x81 /* Contrast */
60 #define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */
61 #define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */
62 #define LCD_CNTL_DISPON 0xaf /* Display on */
64 #define LCD_CNTL_PAGE 0xb0 /* Page address */
65 #define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */
66 #define LCD_CNTL_LOWCOL 0x00 /* Lower column address */
70 static bool display_on
; /* used by lcd_enable */
71 static int offset
; /* column offset */
73 /*** hardware configuration ***/
75 int lcd_default_contrast(void)
77 return DEFAULT_CONTRAST_SETTING
;
80 void lcd_set_contrast(int val
)
82 lcd_write_command(LCD_CNTL_CONTRAST
);
83 lcd_write_command(val
);
86 void lcd_set_invert_display(bool yesno
)
89 lcd_write_command(LCD_SET_REVERSE_DISPLAY
);
91 lcd_write_command(LCD_SET_NORMAL_DISPLAY
);
94 /* turn the display upside down (call lcd_update() afterwards) */
95 void lcd_set_flip(bool yesno
)
99 lcd_write_command(LCD_SET_SEGMENT_REMAP
);
100 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION
);
104 lcd_write_command(LCD_SET_SEGMENT_REMAP_INV
);
105 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION_INV
);
109 #ifdef HAVE_LCD_ENABLE
110 void lcd_enable(bool enable
)
112 if(display_on
== enable
)
115 if( (display_on
= enable
) ) /* simple '=' is not a typo ! */
117 lcd_enable_power(enable
);
118 lcd_write_command(LCD_SET_DISPLAY_ON
);
119 send_event(LCD_EVENT_ACTIVATION
, NULL
);
123 lcd_write_command(LCD_SET_DISPLAY_OFF
);
124 lcd_enable_power(enable
);
128 bool lcd_active(void)
135 /* LCD init, largely based on what OF does */
136 void lcd_init_device(void)
140 lcd_hw_init(&offset
);
142 /* Set display clock (divide ratio = 1) and oscillator frequency (1) */
143 lcd_write_command(LCD_SET_DISPLAY_CLOCK_AND_OSC_FREQ
);
144 lcd_write_command(0x10);
146 /* Set VCOM deselect level to 0.76V */
147 lcd_write_command(LCD_SET_VCOM_DESELECT_LEVEL
);
148 lcd_write_command(0x34);
150 /* Set pre-charge period (p1period is 2 dclk and p2period is 5 dclk) */
151 lcd_write_command(LCD_SET_PRECHARGE_PERIOD
);
152 lcd_write_command(0x25);
154 /* Set contrast register to 12% */
155 lcd_set_contrast(lcd_default_contrast());
158 lcd_write_command(LCD_SET_DC_DC
);
159 lcd_write_command(LCD_SET_DC_DC_PART2
/*|0*/);
161 /* Set starting line as 0 */
162 lcd_write_command(LCD_SET_DISPLAY_START_LINE
/*|(0 & 0x3f)*/);
164 /* Column 131 is remapped to SEG0 */
165 lcd_write_command(LCD_SET_SEGMENT_REMAP_INV
);
167 /* Invert COM scan direction (N-1 to 0) */
168 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION_INV
);
170 /* Set normal display mode (not every pixel ON) */
171 lcd_write_command(LCD_SET_ENTIRE_DISPLAY_OFF
);
173 /* Set normal display mode (not inverted) */
174 lcd_write_command(LCD_SET_NORMAL_DISPLAY
);
176 /* Clear whole framebuffer, including "overscan"
177 * We don't need to handle that out of screen columns in lcd_clear_display()
178 * since we will never write into it anymore
180 lcd_write_command (LCD_SET_HIGHER_COLUMN_ADDRESS
/*| 0*/);
181 lcd_write_command (LCD_SET_LOWER_COLUMN_ADDRESS
/*| 0*/);
183 fb_data p_bytes
[LCD_WIDTH
+ 2 * offset
];
184 memset(p_bytes
, 0, sizeof(p_bytes
)); /* fills with 0 : pixel off */
185 for(i
= 0; i
< 8; i
++)
187 lcd_write_command (LCD_SET_PAGE_ADDRESS
| (i
/*& 0xf*/));
188 lcd_write_data(p_bytes
, LCD_WIDTH
+ 2 * offset
);
196 /*** Update functions ***/
198 /* Performance function that works with an external buffer
199 note that by and bheight are in 8-pixel units! */
200 void lcd_blit_mono(const unsigned char *data
, int x
, int by
, int width
,
201 int bheight
, int stride
)
206 /* Copy display bitmap to hardware */
209 lcd_write_command (LCD_CNTL_PAGE
| (by
++ & 0xf));
210 lcd_write_command (LCD_CNTL_HIGHCOL
| (((x
+offset
)>>4) & 0xf));
211 lcd_write_command (LCD_CNTL_LOWCOL
| ((x
+offset
) & 0xf));
213 lcd_write_data(data
, width
);
220 /* Helper function for lcd_grey_phase_blit(). */
221 void lcd_grey_data(unsigned char *values
, unsigned char *phases
, int count
);
223 /* Performance function that works with an external buffer
224 note that by and bheight are in 8-pixel units! */
225 void lcd_blit_grey_phase(unsigned char *values
, unsigned char *phases
,
226 int x
, int by
, int width
, int bheight
, int stride
)
231 stride
<<= 3; /* 8 pixels per block */
232 /* Copy display bitmap to hardware */
235 lcd_write_command (LCD_CNTL_PAGE
| (by
++ & 0xf));
236 lcd_write_command (LCD_CNTL_HIGHCOL
| (((x
+offset
)>>4) & 0xf));
237 lcd_write_command (LCD_CNTL_LOWCOL
| ((x
+offset
) & 0xf));
239 lcd_grey_data(values
, phases
, width
);
249 /* Update the display.
250 This must be called after all other LCD functions that change the display. */
251 void lcd_update(void) ICODE_ATTR
;
252 void lcd_update(void)
259 /* Copy display bitmap to hardware */
260 for (y
= 0; y
< LCD_FBHEIGHT
; y
++)
262 lcd_write_command (LCD_CNTL_PAGE
| (y
& 0xf));
263 lcd_write_command (LCD_CNTL_HIGHCOL
| ((offset
>> 4) & 0xf));
264 lcd_write_command (LCD_CNTL_LOWCOL
| (offset
& 0xf));
266 lcd_write_data (lcd_framebuffer
[y
], LCD_WIDTH
);
270 /* Update a fraction of the display. */
271 void lcd_update_rect(int, int, int, int) ICODE_ATTR
;
272 void lcd_update_rect(int x
, int y
, int width
, int height
)
279 /* The Y coordinates have to work on even 8 pixel rows */
280 ymax
= (y
+ height
-1) >> 3;
283 if(x
+ width
> LCD_WIDTH
)
284 width
= LCD_WIDTH
- x
;
286 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
287 if(ymax
>= LCD_FBHEIGHT
)
288 ymax
= LCD_FBHEIGHT
-1;
290 /* Copy specified rectange bitmap to hardware */
291 for (; y
<= ymax
; y
++)
293 lcd_write_command (LCD_CNTL_PAGE
| (y
& 0xf));
294 lcd_write_command (LCD_CNTL_HIGHCOL
| (((x
+offset
) >> 4) & 0xf));
295 lcd_write_command (LCD_CNTL_LOWCOL
| ((x
+offset
) & 0xf));
297 lcd_write_data (&lcd_framebuffer
[y
][x
], width
);