summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525/sansa-clip/lcd-ssd1303.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525/sansa-clip/lcd-ssd1303.c')
-rw-r--r--firmware/target/arm/as3525/sansa-clip/lcd-ssd1303.c312
1 files changed, 312 insertions, 0 deletions
diff --git a/firmware/target/arm/as3525/sansa-clip/lcd-ssd1303.c b/firmware/target/arm/as3525/sansa-clip/lcd-ssd1303.c
new file mode 100644
index 0000000000..4ae13a5fcc
--- /dev/null
+++ b/firmware/target/arm/as3525/sansa-clip/lcd-ssd1303.c
@@ -0,0 +1,312 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
11 * Copyright (C) 2008 François Dinel
12 * Copyright (C) 2008 Rafaël Carré
13 *
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.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23#include "config.h"
24
25#include "hwcompat.h"
26#include "kernel.h"
27#include "lcd.h"
28#include "system.h"
29#include "cpu.h"
30#include "string.h"
31
32/*** AS3525 specifics ***/
33#include "as3525.h"
34
35/*** definitions ***/
36
37#define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00)
38#define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10)
39#define LCD_SET_DISPLAY_START_LINE ((char)0x40)
40#define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81)
41#define LCD_SET_SEGMENT_REMAP ((char)0xA0)
42#define LCD_SET_SEGMENT_REMAP_INV ((char)0xA1)
43#define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4)
44#define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5)
45#define LCD_SET_NORMAL_DISPLAY ((char)0xA6)
46#define LCD_SET_REVERSE_DISPLAY ((char)0xA7)
47#define LCD_SET_MULTIPLEX_RATIO ((char)0xA8)
48#define LCD_SET_DC_DC ((char)0xAD)
49#define LCD_SET_DC_DC_PART2 ((char)0x8A)
50#define LCD_SET_DISPLAY_OFF ((char)0xAE)
51#define LCD_SET_DISPLAY_ON ((char)0xAF)
52#define LCD_SET_PAGE_ADDRESS ((char)0xB0)
53#define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0)
54#define LCD_SET_COM_OUTPUT_SCAN_DIRECTION_INV ((char)0xC8)
55#define LCD_SET_DISPLAY_CLOCK_AND_OSC_FREQ ((char)0xD5)
56#define LCD_SET_VCOM_DESELECT_LEVEL ((char)0xDB)
57#define LCD_SET_PRECHARGE_PERIOD ((char)0xD9)
58#define LCD_NOP ((char)0xE3)
59
60/* LCD command codes */
61#define LCD_CNTL_CONTRAST 0x81 /* Contrast */
62#define LCD_CNTL_OUTSCAN 0xc8 /* Output scan direction */
63#define LCD_CNTL_SEGREMAP 0xa1 /* Segment remap */
64#define LCD_CNTL_DISPON 0xaf /* Display on */
65
66#define LCD_CNTL_PAGE 0xb0 /* Page address */
67#define LCD_CNTL_HIGHCOL 0x10 /* Upper column address */
68#define LCD_CNTL_LOWCOL 0x00 /* Lower column address */
69
70/* DBOP initialisation, do what OF does */
71static void ams3525_dbop_init(void)
72{
73 int clkdiv = 4 - 1;
74
75 CGU_DBOP |= (1<<3) /* clk enable */ | clkdiv /* clkdiv: 3 bits */ ;
76
77 GPIOB_AFSEL = 0x08; /* DBOP on pin 3 */
78 GPIOC_AFSEL = 0x0f; /* DBOP on pins 3:0 */
79
80 DBOP_CTRL = 0x51008;
81 DBOP_TIMPOL_01 = 0x6E167;
82 DBOP_TIMPOL_23 = 0xA167E06F;
83}
84
85void lcd_write_command(int byte)
86{
87 /* unset D/C# (data or command) */
88 GPIOA_PIN(5) = 0;
89
90 /* Write command */
91 DBOP_DOUT = (byte << 8) | byte;
92
93 /* While push fifo is not empty */
94 while ((DBOP_STAT & (1<<10)) == 0)
95 ;
96}
97
98void lcd_write_data(const fb_data* p_bytes, int count)
99{
100 /* set D/C# (data or command) */
101 GPIOA_PIN(5) = (1<<5);
102
103 while (count--)
104 {
105 /* Write pixels */
106 DBOP_DOUT = (*p_bytes << 8) | *p_bytes;
107
108 p_bytes++; /* next packed pixels */
109
110 /* While push fifo is not empty */
111 while ((DBOP_STAT & (1<<10)) == 0)
112 ;
113 }
114}
115
116
117/** globals **/
118
119static int xoffset; /* needed for flip */
120static bool display_on; /* used by lcd_enable */
121
122/*** hardware configuration ***/
123
124int lcd_default_contrast(void)
125{
126 return 0x1f;
127}
128
129void lcd_set_contrast(int val)
130{
131 lcd_write_command(LCD_CNTL_CONTRAST);
132 lcd_write_command(val);
133}
134
135void lcd_set_invert_display(bool yesno)
136{
137 if (yesno)
138 lcd_write_command(LCD_SET_REVERSE_DISPLAY);
139 else
140 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
141}
142
143/* turn the display upside down (call lcd_update() afterwards) */
144void lcd_set_flip(bool yesno)
145{
146 (void)yesno;
147 /* TODO */
148}
149
150void lcd_enable(bool enable)
151{
152 if( (display_on = enable) ) /* simple '=' is not a typo ! */
153 lcd_write_command(LCD_SET_DISPLAY_ON);
154 else
155 lcd_write_command(LCD_SET_DISPLAY_OFF);
156}
157
158bool lcd_enabled(void)
159{
160 return display_on;
161}
162
163
164/* LCD init, largely based on what OF does */
165void lcd_init_device(void)
166{
167 int i;
168#define LCD_FULLSCREEN (128+4)
169 fb_data p_bytes[LCD_FULLSCREEN]; /* framebuffer used to clear the screen */
170
171 ams3525_dbop_init();
172
173 GPIOA_DIR |= 0x33; /* pins 5:4 and 1:0 out */
174 GPIOB_DIR |= 0x60; /* pin 6:5 out */
175
176 GPIOA_PIN(1) = (1<<1);
177 GPIOA_PIN(0) = (1<<0);
178 GPIOA_PIN(4) = 0;
179 GPIOB_PIN(5) = 0;
180 GPIOB_PIN(6) = (1<<6);
181
182 /* Set display clock (divide ratio = 1) and oscillator frequency (1) */
183 lcd_write_command(LCD_SET_DISPLAY_CLOCK_AND_OSC_FREQ);
184 lcd_write_command(0x10);
185
186 /* Set VCOM deselect level to 0.76V */
187 lcd_write_command(LCD_SET_VCOM_DESELECT_LEVEL);
188 lcd_write_command(0x34);
189
190 /* Set pre-charge period (p1period is 2 dclk and p2period is 5 dclk) */
191 lcd_write_command(LCD_SET_PRECHARGE_PERIOD);
192 lcd_write_command(0x25);
193
194 /* Set contrast register to 12% */
195 lcd_set_contrast(lcd_default_contrast());
196
197 /* Disable DC-DC */
198 lcd_write_command(LCD_SET_DC_DC);
199 lcd_write_command(LCD_SET_DC_DC_PART2/*|0*/);
200
201 /* Set starting line as 0 */
202 lcd_write_command(LCD_SET_DISPLAY_START_LINE /*|(0 & 0x3f)*/);
203
204 /* Column 131 is remapped to SEG0 */
205 lcd_write_command(LCD_SET_SEGMENT_REMAP_INV);
206
207 /* Invert COM scan direction (N-1 to 0) */
208 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION_INV);
209
210 /* Set normal display mode (not every pixel ON) */
211 lcd_write_command(LCD_SET_ENTIRE_DISPLAY_OFF);
212
213 /* Set normal display mode (not inverted) */
214 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
215
216 /* Clear whole framebuffer, including "overscan"
217 * We don't need to handle that out of screen columns in lcd_clear_display()
218 * since we will never write into it anymore
219 */
220 lcd_write_command (LCD_SET_HIGHER_COLUMN_ADDRESS /*| 0*/);
221 lcd_write_command (LCD_SET_LOWER_COLUMN_ADDRESS /*| 0*/);
222
223 memset(p_bytes, 0, sizeof(p_bytes)); /* fills with 0 : pixel off */
224
225 for(i = 0; i < 8; i++)
226 {
227 lcd_write_command (LCD_SET_PAGE_ADDRESS | (i /*& 0xf*/));
228 lcd_write_data(p_bytes, LCD_FULLSCREEN /* overscan */);
229 }
230
231 lcd_update();
232}
233
234/*** Update functions ***/
235
236/* Performance function that works with an external buffer
237 note that by and bheight are in 8-pixel units! */
238void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
239 int bheight, int stride)
240{
241 /* Copy display bitmap to hardware */
242 while (bheight--)
243 {
244 lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf));
245 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+2+xoffset)>>4) & 0xf));
246 lcd_write_command (LCD_CNTL_LOWCOL | ((x+2+xoffset) & 0xf));
247
248 lcd_write_data(data, width);
249 data += stride;
250 }
251}
252
253
254/* Performance function that works with an external buffer
255 note that by and bheight are in 8-pixel units! */
256void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
257 int x, int by, int width, int bheight, int stride)
258{
259 (void)values;
260 (void)phases;
261 (void)x;
262 (void)by;
263 (void)width;
264 (void)bheight;
265 (void)stride;
266}
267
268/* Update the display.
269 This must be called after all other LCD functions that change the display. */
270void lcd_update(void) ICODE_ATTR;
271void lcd_update(void)
272{
273 int y;
274
275 /* Copy display bitmap to hardware */
276 for (y = 0; y < LCD_FBHEIGHT; y++)
277 {
278 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
279 lcd_write_command (LCD_CNTL_HIGHCOL | (((xoffset+2) >> 4) & 0xf));
280 lcd_write_command (LCD_CNTL_LOWCOL | ((xoffset+2) & 0xf));
281
282 lcd_write_data (lcd_framebuffer[y], LCD_WIDTH);
283 }
284}
285
286/* Update a fraction of the display. */
287void lcd_update_rect(int, int, int, int) ICODE_ATTR;
288void lcd_update_rect(int x, int y, int width, int height)
289{
290 int ymax;
291
292 /* The Y coordinates have to work on even 8 pixel rows */
293 ymax = (y + height-1) >> 3;
294 y >>= 3;
295
296 if(x + width > LCD_WIDTH)
297 width = LCD_WIDTH - x;
298 if (width <= 0)
299 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
300 if(ymax >= LCD_FBHEIGHT)
301 ymax = LCD_FBHEIGHT-1;
302
303 /* Copy specified rectange bitmap to hardware */
304 for (; y <= ymax; y++)
305 {
306 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
307 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+2+xoffset) >> 4) & 0xf));
308 lcd_write_command (LCD_CNTL_LOWCOL | ((x+2+xoffset) & 0xf));
309
310 lcd_write_data (&lcd_framebuffer[y][x], width);
311 }
312}