diff options
Diffstat (limited to 'firmware/target/coldfire/mpio/hd300/lcd-hd300.c')
-rw-r--r-- | firmware/target/coldfire/mpio/hd300/lcd-hd300.c | 244 |
1 files changed, 244 insertions, 0 deletions
diff --git a/firmware/target/coldfire/mpio/hd300/lcd-hd300.c b/firmware/target/coldfire/mpio/hd300/lcd-hd300.c new file mode 100644 index 0000000000..10ee59571e --- /dev/null +++ b/firmware/target/coldfire/mpio/hd300/lcd-hd300.c | |||
@@ -0,0 +1,244 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Adopted for MPIO HD300 by Marcin Bukat | ||
11 | * Copyright (C) 2007 by Jens Arnold | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | #include "config.h" | ||
23 | |||
24 | #include "system.h" | ||
25 | #include "kernel.h" | ||
26 | #include "lcd.h" | ||
27 | |||
28 | /*** definitions ***/ | ||
29 | |||
30 | /* LCD command codes */ | ||
31 | #define LCD_CNTL_POWER_CONTROL 0x25 | ||
32 | #define LCD_CNTL_VOLTAGE_SELECT 0x2b | ||
33 | #define LCD_CNTL_LINE_INVERT_DRIVE 0x36 | ||
34 | #define LCD_CNTL_GRAY_SCALE_PATTERN 0x39 | ||
35 | #define LCD_CNTL_TEMP_GRADIENT_SELECT 0x4e | ||
36 | #define LCD_CNTL_OSC_FREQUENCY 0x5f | ||
37 | #define LCD_CNTL_ON_OFF 0xae | ||
38 | #define LCD_CNTL_OSC_ON_OFF 0xaa | ||
39 | #define LCD_CNTL_OFF_MODE 0xbe | ||
40 | #define LCD_CNTL_POWER_SAVE 0xa8 | ||
41 | #define LCD_CNTL_REVERSE 0xa6 | ||
42 | #define LCD_CNTL_ALL_LIGHTING 0xa4 | ||
43 | #define LCD_CNTL_COMMON_OUTPUT_STATUS 0xc4 | ||
44 | #define LCD_CNTL_COLUMN_ADDRESS_DIR 0xa0 | ||
45 | #define LCD_CNTL_NLINE_ON_OFF 0xe4 | ||
46 | #define LCD_CNTL_DISPLAY_MODE 0x66 | ||
47 | #define LCD_CNTL_DUTY_SET 0x6d | ||
48 | #define LCD_CNTL_ELECTRONIC_VOLUME 0x81 | ||
49 | #define LCD_CNTL_DATA_INPUT_DIR 0x84 | ||
50 | #define LCD_CNTL_DISPLAY_START_LINE 0x8a | ||
51 | #define LCD_CNTL_AREA_SCROLL 0x10 | ||
52 | |||
53 | #define LCD_CNTL_PAGE 0xb1 | ||
54 | #define LCD_CNTL_COLUMN 0x13 | ||
55 | #define LCD_CNTL_DATA_WRITE 0x1d | ||
56 | |||
57 | /*** shared semi-private declarations ***/ | ||
58 | extern const unsigned char lcd_dibits[16] ICONST_ATTR; | ||
59 | |||
60 | /*** hardware configuration ***/ | ||
61 | int lcd_default_contrast(void) | ||
62 | { | ||
63 | return DEFAULT_CONTRAST_SETTING; | ||
64 | } | ||
65 | |||
66 | void lcd_set_contrast(int val) | ||
67 | { | ||
68 | /* Keep val in acceptable hw range */ | ||
69 | if (val < 0) | ||
70 | val = 0; | ||
71 | else if (val > 127) | ||
72 | val = 127; | ||
73 | |||
74 | lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, val, -1); | ||
75 | } | ||
76 | |||
77 | void lcd_set_invert_display(bool yesno) | ||
78 | { | ||
79 | lcd_write_command(LCD_CNTL_REVERSE | (yesno?1:0)); | ||
80 | } | ||
81 | |||
82 | /* turn the display upside down (call lcd_update() afterwards) */ | ||
83 | void lcd_set_flip(bool yesno) | ||
84 | { | ||
85 | if (yesno) | ||
86 | { | ||
87 | lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 1); | ||
88 | lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 0); | ||
89 | lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 0); | ||
90 | } | ||
91 | else | ||
92 | { | ||
93 | lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0); | ||
94 | lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1); | ||
95 | lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void lcd_init_device(void) | ||
100 | { | ||
101 | and_l(~0x00000800, &GPIO_FUNCTION); /* CS3 line */ | ||
102 | |||
103 | /* LCD Reset GPO34 */ | ||
104 | or_l(0x00000004, &GPIO1_ENABLE); /* set as output */ | ||
105 | or_l(0x00000004, &GPIO1_FUNCTION); /* switch to secondary function - GPIO */ | ||
106 | |||
107 | and_l(~0x00000004, &GPIO1_OUT); /* RESET low */ | ||
108 | sleep(1); /* delay at least 1000 ns */ | ||
109 | or_l(0x00000004, &GPIO1_OUT); /* RESET high */ | ||
110 | sleep(1); | ||
111 | |||
112 | lcd_write_command(LCD_CNTL_ON_OFF | 1); /* LCD ON */ | ||
113 | lcd_write_command(LCD_CNTL_OFF_MODE | 1); /* OFF -> VCC on drivers */ | ||
114 | lcd_write_command(LCD_CNTL_REVERSE | 0); /* Reverse OFF */ | ||
115 | lcd_write_command(LCD_CNTL_ALL_LIGHTING | 0); /* Normal */ | ||
116 | lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1); /* Reverse dir */ | ||
117 | lcd_write_command_ex(LCD_CNTL_DISPLAY_START_LINE, 0, -1); | ||
118 | lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0); /* Normal */ | ||
119 | lcd_write_command_ex(LCD_CNTL_DISPLAY_MODE, 0, -1); /* Greyscale mode */ | ||
120 | lcd_write_command_ex(LCD_CNTL_GRAY_SCALE_PATTERN, 0x53, -1); | ||
121 | lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1); | ||
122 | lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, 24, -1); /* 0x18 */ | ||
123 | |||
124 | lcd_write_command(LCD_CNTL_OSC_ON_OFF | 1); /* Oscillator ON */ | ||
125 | lcd_write_command(LCD_CNTL_POWER_SAVE | 0); | ||
126 | lcd_write_command_ex(LCD_CNTL_VOLTAGE_SELECT, 3, -1); | ||
127 | lcd_write_command_ex(LCD_CNTL_POWER_CONTROL, 0x17, -1); | ||
128 | lcd_write_command_ex(LCD_CNTL_OSC_FREQUENCY, 3, -1); | ||
129 | lcd_write_command(LCD_CNTL_NLINE_ON_OFF | 1); /* N-line ON */ | ||
130 | lcd_write_command_ex(LCD_CNTL_LINE_INVERT_DRIVE, 0x10, -1); | ||
131 | lcd_write_command_ex(LCD_CNTL_TEMP_GRADIENT_SELECT, 0, -1); | ||
132 | |||
133 | lcd_update(); | ||
134 | } | ||
135 | |||
136 | /*** update functions ***/ | ||
137 | |||
138 | /* Performance function that works with an external buffer | ||
139 | note that by and bheight are in 8-pixel units! */ | ||
140 | void lcd_blit_mono(const unsigned char *data, int x, int by, int width, | ||
141 | int bheight, int stride) | ||
142 | { | ||
143 | const unsigned char *src, *src_end; | ||
144 | unsigned char *dst_u, *dst_l; | ||
145 | static unsigned char upper[LCD_WIDTH] IBSS_ATTR; | ||
146 | static unsigned char lower[LCD_WIDTH] IBSS_ATTR; | ||
147 | unsigned int byte; | ||
148 | |||
149 | by *= 2; | ||
150 | |||
151 | while (bheight--) | ||
152 | { | ||
153 | src = data; | ||
154 | src_end = data + width; | ||
155 | dst_u = upper; | ||
156 | dst_l = lower; | ||
157 | do | ||
158 | { | ||
159 | byte = *src++; | ||
160 | *dst_u++ = lcd_dibits[byte & 0x0F]; | ||
161 | byte >>= 4; | ||
162 | *dst_l++ = lcd_dibits[byte & 0x0F]; | ||
163 | } | ||
164 | while (src < src_end); | ||
165 | |||
166 | lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1); | ||
167 | lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1); | ||
168 | lcd_write_command(LCD_CNTL_DATA_WRITE); | ||
169 | lcd_write_data(upper, width); | ||
170 | |||
171 | lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1); | ||
172 | lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1); | ||
173 | lcd_write_command(LCD_CNTL_DATA_WRITE); | ||
174 | lcd_write_data(lower, width); | ||
175 | |||
176 | data += stride; | ||
177 | } | ||
178 | } | ||
179 | |||
180 | /* Helper function for lcd_grey_phase_blit(). */ | ||
181 | void lcd_grey_data(unsigned char *values, unsigned char *phases, int count); | ||
182 | |||
183 | /* Performance function that works with an external buffer | ||
184 | note that by and bheight are in 4-pixel units! */ | ||
185 | void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases, | ||
186 | int x, int by, int width, int bheight, int stride) | ||
187 | { | ||
188 | stride <<= 2; /* 4 pixels per block */ | ||
189 | while (bheight--) | ||
190 | { | ||
191 | lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1); | ||
192 | lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1); | ||
193 | lcd_write_command(LCD_CNTL_DATA_WRITE); | ||
194 | lcd_grey_data(values, phases, width); | ||
195 | values += stride; | ||
196 | phases += stride; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | /* Update the display. | ||
201 | This must be called after all other LCD functions that change the display. */ | ||
202 | void lcd_update(void) ICODE_ATTR; | ||
203 | void lcd_update(void) | ||
204 | { | ||
205 | int y; | ||
206 | |||
207 | /* Copy display bitmap to hardware */ | ||
208 | for (y = 0; y < LCD_FBHEIGHT; y++) | ||
209 | { | ||
210 | lcd_write_command_ex(LCD_CNTL_PAGE, y, -1); | ||
211 | lcd_write_command_ex(LCD_CNTL_COLUMN, 0, -1); | ||
212 | |||
213 | lcd_write_command(LCD_CNTL_DATA_WRITE); | ||
214 | lcd_write_data (lcd_framebuffer[y], LCD_WIDTH); | ||
215 | } | ||
216 | } | ||
217 | |||
218 | /* Update a fraction of the display. */ | ||
219 | void lcd_update_rect(int, int, int, int) ICODE_ATTR; | ||
220 | void lcd_update_rect(int x, int y, int width, int height) | ||
221 | { | ||
222 | int ymax; | ||
223 | |||
224 | /* The Y coordinates have to work on even 8 pixel rows */ | ||
225 | ymax = (y + height-1) >> 2; | ||
226 | y >>= 2; | ||
227 | |||
228 | if(x + width > LCD_WIDTH) | ||
229 | width = LCD_WIDTH - x; | ||
230 | if (width <= 0) | ||
231 | return; /* nothing left to do, 0 is harmful to lcd_write_data() */ | ||
232 | if(ymax >= LCD_FBHEIGHT) | ||
233 | ymax = LCD_FBHEIGHT-1; | ||
234 | |||
235 | /* Copy specified rectange bitmap to hardware */ | ||
236 | for (; y <= ymax; y++) | ||
237 | { | ||
238 | lcd_write_command_ex(LCD_CNTL_PAGE, y, -1); | ||
239 | lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1); | ||
240 | |||
241 | lcd_write_command(LCD_CNTL_DATA_WRITE); | ||
242 | lcd_write_data (&lcd_framebuffer[y][x], width); | ||
243 | } | ||
244 | } | ||