lcd drivers: Convert lcd_[remote_]framebuffer to a pointer
[maemo-rb.git] / firmware / target / sh / archos / lcd-archos-bitmap.c
blobf23289053d85e6e067ed7dfea14b0d6962eaee7b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Alan Korr
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "config.h"
23 #include "hwcompat.h"
24 #include "kernel.h"
25 #include "lcd.h"
26 #include "system.h"
28 /*** definitions ***/
30 #define LCD_SET_LOWER_COLUMN_ADDRESS ((char)0x00)
31 #define LCD_SET_HIGHER_COLUMN_ADDRESS ((char)0x10)
32 #define LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO ((char)0x20)
33 #define LCD_SET_POWER_CONTROL_REGISTER ((char)0x28)
34 #define LCD_SET_DISPLAY_START_LINE ((char)0x40)
35 #define LCD_SET_CONTRAST_CONTROL_REGISTER ((char)0x81)
36 #define LCD_SET_SEGMENT_REMAP ((char)0xA0)
37 #define LCD_SET_LCD_BIAS ((char)0xA2)
38 #define LCD_SET_ENTIRE_DISPLAY_OFF ((char)0xA4)
39 #define LCD_SET_ENTIRE_DISPLAY_ON ((char)0xA5)
40 #define LCD_SET_NORMAL_DISPLAY ((char)0xA6)
41 #define LCD_SET_REVERSE_DISPLAY ((char)0xA7)
42 #define LCD_SET_MULTIPLEX_RATIO ((char)0xA8)
43 #define LCD_SET_BIAS_TC_OSC ((char)0xA9)
44 #define LCD_SET_1OVER4_BIAS_RATIO ((char)0xAA)
45 #define LCD_SET_INDICATOR_OFF ((char)0xAC)
46 #define LCD_SET_INDICATOR_ON ((char)0xAD)
47 #define LCD_SET_DISPLAY_OFF ((char)0xAE)
48 #define LCD_SET_DISPLAY_ON ((char)0xAF)
49 #define LCD_SET_PAGE_ADDRESS ((char)0xB0)
50 #define LCD_SET_COM_OUTPUT_SCAN_DIRECTION ((char)0xC0)
51 #define LCD_SET_TOTAL_FRAME_PHASES ((char)0xD2)
52 #define LCD_SET_DISPLAY_OFFSET ((char)0xD3)
53 #define LCD_SET_READ_MODIFY_WRITE_MODE ((char)0xE0)
54 #define LCD_SOFTWARE_RESET ((char)0xE2)
55 #define LCD_NOP ((char)0xE3)
56 #define LCD_SET_END_OF_READ_MODIFY_WRITE_MODE ((char)0xEE)
58 /* LCD command codes */
59 #define LCD_CNTL_RESET 0xe2 /* Software reset */
60 #define LCD_CNTL_POWER 0x2f /* Power control */
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 */
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 */
70 /** globals **/
72 static int xoffset; /* needed for flip */
74 /*** hardware configuration ***/
76 int lcd_default_contrast(void)
78 return (HW_MASK & LCD_CONTRAST_BIAS) ? 31 : 49;
81 void lcd_set_contrast(int val)
83 lcd_write_command(LCD_CNTL_CONTRAST);
84 lcd_write_command(val);
87 void lcd_set_invert_display(bool yesno)
89 if (yesno)
90 lcd_write_command(LCD_SET_REVERSE_DISPLAY);
91 else
92 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
95 /* turn the display upside down (call lcd_update() afterwards) */
96 void lcd_set_flip(bool yesno)
98 #ifdef HAVE_DISPLAY_FLIPPED
99 if (!yesno)
100 #else
101 if (yesno)
102 #endif
104 lcd_write_command(LCD_SET_SEGMENT_REMAP);
105 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION);
106 xoffset = 132 - LCD_WIDTH; /* 132 colums minus the 112 we have */
108 else
110 lcd_write_command(LCD_SET_SEGMENT_REMAP | 0x01);
111 lcd_write_command(LCD_SET_COM_OUTPUT_SCAN_DIRECTION | 0x08);
112 xoffset = 0;
116 void lcd_init_device(void)
118 /* Initialize PB0-3 as output pins */
119 PBCR2 &= 0xff00; /* MD = 00 */
120 PBIOR |= 0x000f; /* IOR = 1 */
122 /* inits like the original firmware */
123 lcd_write_command(LCD_SOFTWARE_RESET);
124 lcd_write_command(LCD_SET_INTERNAL_REGULATOR_RESISTOR_RATIO + 4);
125 lcd_write_command(LCD_SET_1OVER4_BIAS_RATIO + 0); /* force 1/4 bias: 0 */
126 lcd_write_command(LCD_SET_POWER_CONTROL_REGISTER + 7);
127 /* power control register: op-amp=1, regulator=1, booster=1 */
128 lcd_write_command(LCD_SET_DISPLAY_ON);
129 lcd_write_command(LCD_SET_NORMAL_DISPLAY);
130 lcd_set_flip(false);
131 lcd_write_command(LCD_SET_DISPLAY_START_LINE + 0);
132 lcd_set_contrast(lcd_default_contrast());
133 lcd_write_command(LCD_SET_PAGE_ADDRESS);
134 lcd_write_command(LCD_SET_LOWER_COLUMN_ADDRESS + 0);
135 lcd_write_command(LCD_SET_HIGHER_COLUMN_ADDRESS + 0);
137 lcd_clear_display();
138 lcd_update();
141 /*** Update functions ***/
143 /* Performance function that works with an external buffer
144 note that by and bheight are in 8-pixel units! */
145 void lcd_blit_mono(const unsigned char *data, int x, int by, int width,
146 int bheight, int stride)
148 /* Copy display bitmap to hardware */
149 while (bheight--)
151 lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf));
152 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset)>>4) & 0xf));
153 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
155 lcd_write_data(data, width);
156 data += stride;
160 /* Helper function for lcd_grey_phase_blit(). */
161 void lcd_grey_data(unsigned char *values, unsigned char *phases, int count);
163 /* Performance function that works with an external buffer
164 note that by and bheight are in 8-pixel units! */
165 void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases,
166 int x, int by, int width, int bheight, int stride)
168 stride <<= 3; /* 8 pixels per block */
169 while (bheight--)
171 lcd_write_command (LCD_CNTL_PAGE | (by++ & 0xf));
172 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset)>>4) & 0xf));
173 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
175 lcd_grey_data(values, phases, width);
176 values += stride;
177 phases += stride;
182 /* Update the display.
183 This must be called after all other LCD functions that change the display. */
184 void lcd_update(void)
186 int y;
188 /* Copy display bitmap to hardware */
189 for (y = 0; y < LCD_FBHEIGHT; y++)
191 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
192 lcd_write_command (LCD_CNTL_HIGHCOL | ((xoffset >> 4) & 0xf));
193 lcd_write_command (LCD_CNTL_LOWCOL | (xoffset & 0xf));
195 lcd_write_data (FBADDR(0, y), LCD_WIDTH);
199 /* Update a fraction of the display. */
200 void lcd_update_rect(int x, int y, int width, int height)
202 int ymax;
204 /* The Y coordinates have to work on even 8 pixel rows */
205 ymax = (y + height-1) >> 3;
206 y >>= 3;
208 if(x + width > LCD_WIDTH)
209 width = LCD_WIDTH - x;
210 if (width <= 0)
211 return; /* nothing left to do, 0 is harmful to lcd_write_data() */
212 if(ymax >= LCD_FBHEIGHT)
213 ymax = LCD_FBHEIGHT-1;
215 /* Copy specified rectange bitmap to hardware */
216 for (; y <= ymax; y++)
218 lcd_write_command (LCD_CNTL_PAGE | (y & 0xf));
219 lcd_write_command (LCD_CNTL_HIGHCOL | (((x+xoffset) >> 4) & 0xf));
220 lcd_write_command (LCD_CNTL_LOWCOL | ((x+xoffset) & 0xf));
222 lcd_write_data (FBADDR(x,y), width);