summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/mpio/hd200/lcd-hd200.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/mpio/hd200/lcd-hd200.c')
-rw-r--r--firmware/target/coldfire/mpio/hd200/lcd-hd200.c241
1 files changed, 241 insertions, 0 deletions
diff --git a/firmware/target/coldfire/mpio/hd200/lcd-hd200.c b/firmware/target/coldfire/mpio/hd200/lcd-hd200.c
new file mode 100644
index 0000000000..8cb9e8e087
--- /dev/null
+++ b/firmware/target/coldfire/mpio/hd200/lcd-hd200.c
@@ -0,0 +1,241 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
9 *
10 * Copyright (C) 2010 Marcin Bukat
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23
24#include "system.h"
25#include "kernel.h"
26#include "lcd.h"
27
28/*** definitions ***/
29/* TOMATO LSI 0350 - definitions and slightly tweaked functions
30 * taken from lcd-remote-iaudio.c
31 */
32
33#define LCD_SET_DUTY_RATIO 0x48
34#define LCD_SELECT_ADC 0xa0
35#define LCD_SELECT_SHL 0xc0
36#define LCD_SET_COM0 0x44
37#define LCD_OSC_ON 0xab
38#define LCD_SELECT_DCDC 0x64
39#define LCD_SELECT_RES 0x20
40#define LCD_SET_VOLUME 0x81
41#define LCD_SET_BIAS 0x50
42#define LCD_CONTROL_POWER 0x28
43#define LCD_DISPLAY_ON 0xae
44#define LCD_SET_INITLINE 0x40
45#define LCD_SET_COLUMN 0x10
46#define LCD_SET_PAGE 0xb0
47#define LCD_SET_GRAY 0x88
48#define LCD_SET_PWM_FRC 0x90
49#define LCD_SET_POWER_SAVE 0xa8
50#define LCD_REVERSE 0xa6
51#define LCD_RESET 0xe2
52
53/* cached settings */
54static bool cached_invert = false;
55static bool cached_flip = false;
56static int cached_contrast = DEFAULT_CONTRAST_SETTING;
57bool lcd_initialized = false;
58
59/*** hardware configuration ***/
60int lcd_default_contrast(void)
61{
62 return DEFAULT_CONTRAST_SETTING;
63}
64
65void lcd_powersave(bool on)
66{
67/* What is the point of having else construct here? */
68 if(lcd_initialized) {
69 if (on)
70 lcd_write_command(LCD_SET_POWER_SAVE | 1);
71 else
72 lcd_write_command(LCD_SET_POWER_SAVE | 1);
73 }
74}
75
76void lcd_set_contrast(int val)
77{
78 if (val < MIN_CONTRAST_SETTING)
79 val = MIN_CONTRAST_SETTING;
80 else if (val > MAX_CONTRAST_SETTING)
81 val = MAX_CONTRAST_SETTING;
82
83 cached_contrast = val;
84 if(lcd_initialized)
85 lcd_write_command_e(LCD_SET_VOLUME, val);
86}
87
88void lcd_set_invert_display(bool yesno)
89{
90 cached_invert = yesno;
91 if(lcd_initialized)
92 lcd_write_command(LCD_REVERSE | yesno);
93
94}
95
96/* turn the display upside down (call lcd_update() afterwards) */
97void lcd_set_flip(bool yesno)
98{
99 cached_flip = yesno;
100 if(lcd_initialized)
101 {
102 if(yesno)
103 {
104 lcd_write_command(LCD_SELECT_ADC | 1);
105 lcd_write_command(LCD_SELECT_SHL | 0);
106 lcd_write_command_e(LCD_SET_COM0, 0);
107 }
108 else
109 {
110 lcd_write_command(LCD_SELECT_ADC | 0);
111 lcd_write_command(LCD_SELECT_SHL | 8);
112 lcd_write_command_e(LCD_SET_COM0, 0);
113 }
114 }
115
116}
117
118void lcd_shutdown(void)
119{
120 /* Set power save -> Power OFF (VDD - VSS) .. that's it */
121 if (lcd_initialized)
122 lcd_write_command(LCD_SET_POWER_SAVE | 1);
123}
124
125void lcd_init_device(void)
126{
127 and_l(~0x00000800, &GPIO_FUNCTION); /* CS3 line */
128
129 /* LCD Reset GPO34 */
130 or_l(0x00000004, &GPIO1_ENABLE); /* set as output */
131 or_l(0x00000004, &GPIO1_FUNCTION); /* switch to secondary function - GPIO */
132
133 and_l(~0x00000004, &GPIO1_OUT); /* RESET low */
134 sleep(1); /* delay at least 1000 ns */
135 or_l(0x00000004, &GPIO1_OUT); /* RESET high */
136 sleep(1);
137
138 /* parameters setup taken from original firmware */
139 lcd_write_command(LCD_RESET);
140 lcd_write_command_e(LCD_SET_DUTY_RATIO,0x80); /* 1/128 */
141 lcd_write_command(LCD_OSC_ON);
142 lcd_write_command(LCD_SELECT_DCDC | 3); /* DC/DC 6xboost */
143 lcd_write_command(LCD_SELECT_RES | 7); /* Regulator resistor: 7.2 */
144 lcd_write_command(LCD_SET_BIAS | 6); /* 1/11 */
145 lcd_write_command(LCD_SET_PWM_FRC | 6); /* 3FRC + 12PWM */
146 lcd_write_command_e(LCD_SET_GRAY | 0, 0x00);
147 lcd_write_command_e(LCD_SET_GRAY | 1, 0x00);
148 lcd_write_command_e(LCD_SET_GRAY | 2, 0x0c);
149 lcd_write_command_e(LCD_SET_GRAY | 3, 0x00);
150 lcd_write_command_e(LCD_SET_GRAY | 4, 0xc4);
151 lcd_write_command_e(LCD_SET_GRAY | 5, 0x00);
152 lcd_write_command_e(LCD_SET_GRAY | 6, 0xcc);
153 lcd_write_command_e(LCD_SET_GRAY | 7, 0x00);
154
155 lcd_write_command(LCD_CONTROL_POWER | 7); /* All circuits ON */
156 lcd_write_command(LCD_DISPLAY_ON | 1); /* display on */
157
158 /* Ok we are ready */
159 lcd_initialized = true;
160
161 lcd_set_flip(cached_flip);
162 lcd_set_contrast(cached_contrast);
163 lcd_set_invert_display(cached_invert);
164
165 lcd_update();
166}
167
168/* Update the display.
169 This must be called after all other LCD functions that change the display. */
170void lcd_update(void) ICODE_ATTR;
171void lcd_update(void)
172{
173 int y;
174 if(!lcd_initialized)
175 return;
176
177 for(y = 0;y < LCD_FBHEIGHT;y++)
178 {
179 lcd_write_command(LCD_SET_PAGE | y);
180 lcd_write_command_e(LCD_SET_COLUMN, 0);
181 lcd_write_data(lcd_framebuffer[y], LCD_WIDTH);
182 }
183
184
185}
186
187/* Update a fraction of the display. */
188void lcd_update_rect(int, int, int, int) ICODE_ATTR;
189void lcd_update_rect(int x, int y, int width, int height)
190{
191 int ymax;
192
193 if (!lcd_initialized)
194 return;
195
196
197 /* The Y coordinates have to work on even 8 pixel rows */
198 ymax = (y + height-1) >> 3;
199 y >>= 3;
200
201 if(x + width > LCD_WIDTH)
202 width = LCD_WIDTH - x;
203 if (width <= 0)
204 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
205 if(ymax >= LCD_FBHEIGHT)
206 ymax = LCD_FBHEIGHT-1;
207
208 /* Copy specified rectange bitmap to hardware */
209 for (; y <= ymax; y++)
210 {
211 lcd_write_command(LCD_SET_PAGE | y );
212 lcd_write_command_e(LCD_SET_COLUMN | ((x >> 4) & 0xf), x & 0x0f);
213 lcd_write_data (&lcd_framebuffer[y][x], width);
214 }
215
216}
217
218void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
219 int x, int by, int width, int bheight, int stride)
220{
221 (void)values;
222 (void)phases;
223 (void)x;
224 (void)by;
225 (void)width;
226 (void)bheight;
227 (void)stride;
228 /* empty stub */
229}
230
231void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
232 int bheight, int stride)
233{
234 (void)data;
235 (void)x;
236 (void)by;
237 (void)width;
238 (void)bheight;
239 (void)stride;
240 /* empty stub */
241}