summaryrefslogtreecommitdiff
path: root/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c')
-rwxr-xr-xfirmware/target/coldfire/iaudio/x5/lcd-remote-x5.c130
1 files changed, 109 insertions, 21 deletions
diff --git a/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c b/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c
index c1ec00f0e7..586104fc0a 100755
--- a/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c
+++ b/firmware/target/coldfire/iaudio/x5/lcd-remote-x5.c
@@ -19,6 +19,7 @@
19#include "config.h" 19#include "config.h"
20#include "system.h" 20#include "system.h"
21#include "kernel.h" 21#include "kernel.h"
22#include "lcd-remote.h"
22 23
23/* The LCD in the iAudio M3/M5/X5 remote control is a Tomato LSI 0350 */ 24/* The LCD in the iAudio M3/M5/X5 remote control is a Tomato LSI 0350 */
24 25
@@ -39,6 +40,7 @@
39#define LCD_SET_GRAY 0x88 40#define LCD_SET_GRAY 0x88
40#define LCD_SET_PWM_FRC 0x90 41#define LCD_SET_PWM_FRC 0x90
41#define LCD_SET_POWER_SAVE 0xa8 42#define LCD_SET_POWER_SAVE 0xa8
43#define LCD_REVERSE 0xa6
42 44
43#define CS_LO and_l(~0x00000020, &GPIO1_OUT) 45#define CS_LO and_l(~0x00000020, &GPIO1_OUT)
44#define CS_HI or_l(0x00000020, &GPIO1_OUT) 46#define CS_HI or_l(0x00000020, &GPIO1_OUT)
@@ -51,8 +53,12 @@
51 53
52#define LCD_REMOTE_DEFAULT_CONTRAST 0x18; 54#define LCD_REMOTE_DEFAULT_CONTRAST 0x18;
53 55
56/* cached settings values */
57static bool cached_invert = false;
58static bool cached_flip = false;
54static int cached_contrast = LCD_REMOTE_DEFAULT_CONTRAST; 59static int cached_contrast = LCD_REMOTE_DEFAULT_CONTRAST;
55static bool remote_initialized = false; 60
61bool remote_initialized = false;
56 62
57static void remote_write(unsigned char byte, bool is_command) 63static void remote_write(unsigned char byte, bool is_command)
58{ 64{
@@ -94,13 +100,6 @@ void lcd_remote_write_data(const unsigned char* p_bytes, int count)
94 remote_write(*p_bytes++, false); 100 remote_write(*p_bytes++, false);
95} 101}
96 102
97void remote_set_row_and_col(int row, int col)
98{
99 lcd_remote_write_command(LCD_SET_PAGE | (row & 0xf));
100 lcd_remote_write_command_ex(LCD_SET_COLUMN | ((col >> 4) & 0xf),
101 col & 0xf);
102}
103
104int lcd_remote_default_contrast(void) 103int lcd_remote_default_contrast(void)
105{ 104{
106 return LCD_REMOTE_DEFAULT_CONTRAST; 105 return LCD_REMOTE_DEFAULT_CONTRAST;
@@ -108,24 +107,27 @@ int lcd_remote_default_contrast(void)
108 107
109void lcd_remote_powersave(bool on) 108void lcd_remote_powersave(bool on)
110{ 109{
111 if (on) 110 if(remote_initialized) {
112 lcd_remote_write_command(LCD_SET_POWER_SAVE | 1); 111 if (on)
113 else 112 lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
114 lcd_remote_write_command(LCD_SET_POWER_SAVE | 1); 113 else
114 lcd_remote_write_command(LCD_SET_POWER_SAVE | 1);
115 }
115} 116}
116 117
117void lcd_remote_set_contrast(int val) 118void lcd_remote_set_contrast(int val)
118{ 119{
119 cached_contrast = val; 120 cached_contrast = val;
120 lcd_remote_write_command_ex(LCD_SET_VOLUME, val); 121 if(remote_initialized)
122 lcd_remote_write_command_ex(LCD_SET_VOLUME, val);
121} 123}
122 124
123bool remote_detect(void) 125bool remote_detect(void)
124{ 126{
125 return (GPIO_READ & 0x01000000); 127 return (GPIO_READ & 0x01000000)?false:true;
126} 128}
127 129
128void remote_init(void) 130void lcd_remote_init_device(void)
129{ 131{
130 or_l(0x0000e000, &GPIO_OUT); 132 or_l(0x0000e000, &GPIO_OUT);
131 or_l(0x0000e000, &GPIO_ENABLE); 133 or_l(0x0000e000, &GPIO_ENABLE);
@@ -135,17 +137,18 @@ void remote_init(void)
135 or_l(0x00000020, &GPIO1_ENABLE); 137 or_l(0x00000020, &GPIO1_ENABLE);
136 or_l(0x00000020, &GPIO1_FUNCTION); 138 or_l(0x00000020, &GPIO1_FUNCTION);
137 139
140 and_l(~0x01000000, &GPIO_OUT);
141 and_l(~0x01000000, &GPIO_ENABLE);
142 or_l(0x01000000, &GPIO_FUNCTION);
143}
144
145void lcd_remote_on(void)
146{
138 sleep(10); 147 sleep(10);
139 148
140 lcd_remote_write_command(LCD_SET_DUTY_RATIO); 149 lcd_remote_write_command(LCD_SET_DUTY_RATIO);
141 lcd_remote_write_command(0x70); /* 1/128 */ 150 lcd_remote_write_command(0x70); /* 1/128 */
142 151
143 lcd_remote_write_command(LCD_SELECT_ADC | 1); /* Reverse direction */
144 lcd_remote_write_command(LCD_SELECT_SHL | 8); /* Reverse direction */
145
146 lcd_remote_write_command(LCD_SET_COM0);
147 lcd_remote_write_command(0x00);
148
149 lcd_remote_write_command(LCD_OSC_ON); 152 lcd_remote_write_command(LCD_OSC_ON);
150 153
151 lcd_remote_write_command(LCD_SELECT_DCDC | 2); /* DC/DC 5xboost */ 154 lcd_remote_write_command(LCD_SELECT_DCDC | 2); /* DC/DC 5xboost */
@@ -173,5 +176,90 @@ void remote_init(void)
173 176
174 remote_initialized = true; 177 remote_initialized = true;
175 178
179 lcd_remote_set_flip(cached_flip);
176 lcd_remote_set_contrast(cached_contrast); 180 lcd_remote_set_contrast(cached_contrast);
181 lcd_remote_set_invert_display(cached_invert);
182}
183
184void lcd_remote_off(void)
185{
186 remote_initialized = false;
187 CS_HI;
188 RS_HI;
189}
190
191/* Update the display.
192 This must be called after all other LCD functions that change the display. */
193void lcd_remote_update(void) ICODE_ATTR;
194void lcd_remote_update(void)
195{
196 int y;
197 if(remote_initialized) {
198 for(y = 0;y < LCD_REMOTE_HEIGHT/8;y++) {
199 /* Copy display bitmap to hardware.
200 The COM48-COM63 lines are not connected so we have to skip
201 them. Further, the column address doesn't wrap, so we
202 have to update one page at a time. */
203 lcd_remote_write_command(LCD_SET_PAGE | (y>5?y+2:y));
204 lcd_remote_write_command_ex(LCD_SET_COLUMN | 0, 0);
205 lcd_remote_write_data((unsigned char *)lcd_remote_framebuffer[y],
206 LCD_REMOTE_WIDTH*2);
207 }
208 }
209}
210
211/* Update a fraction of the display. */
212void lcd_remote_update_rect(int, int, int, int) ICODE_ATTR;
213void lcd_remote_update_rect(int x, int y, int width, int height)
214{
215 if(remote_initialized) {
216 int ymax;
217
218 /* The Y coordinates have to work on even 8 pixel rows */
219 ymax = (y + height-1) >> 3;
220 y >>= 3;
221
222 if(x + width > LCD_REMOTE_WIDTH)
223 width = LCD_REMOTE_WIDTH - x;
224 if (width <= 0)
225 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
226 if(ymax >= LCD_REMOTE_HEIGHT)
227 ymax = LCD_REMOTE_HEIGHT-1;
228
229 /* Copy specified rectangle bitmap to hardware
230 COM48-COM63 are not connected, so we need to skip those */
231 for (; y <= ymax; y++)
232 {
233 lcd_remote_write_command(LCD_SET_PAGE |
234 ((y > 5?y + 2:y) & 0xf));
235 lcd_remote_write_command_ex(LCD_SET_COLUMN | ((x >> 4) & 0xf),
236 x & 0xf);
237
238 lcd_remote_write_data (
239 (unsigned char *)&lcd_remote_framebuffer[y][x], width*2);
240 }
241 }
242}
243
244void lcd_remote_set_invert_display(bool yesno)
245{
246 cached_invert = yesno;
247 if(remote_initialized)
248 lcd_remote_write_command(LCD_REVERSE | yesno);
249}
250
251void lcd_remote_set_flip(bool yesno)
252{
253 cached_flip = yesno;
254 if(remote_initialized) {
255 if(yesno) {
256 lcd_remote_write_command(LCD_SELECT_ADC | 0);
257 lcd_remote_write_command(LCD_SELECT_SHL | 0);
258 lcd_remote_write_command_ex(LCD_SET_COM0, 16);
259 } else {
260 lcd_remote_write_command(LCD_SELECT_ADC | 1);
261 lcd_remote_write_command(LCD_SELECT_SHL | 8);
262 lcd_remote_write_command_ex(LCD_SET_COM0, 0);
263 }
264 }
177} 265}