4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2003, 2004, 2005, 2006 Develer S.r.l. (http://www.develer.com/)
30 * Copyright 2001 Bernie Innocenti <bernie@codewiz.org>
34 * \brief Displaytech 32122A LCD driver
36 * \author Bernie Innocenti <bernie@codewiz.org>
37 * \author Stefano Fedrigo <aleph@develer.com>
42 #include "lcd_32122a.h"
44 #include "hw/hw_lcd_32122a.h"
46 #include "cfg/cfg_lcd_32122a.h"
48 #include <cfg/macros.h> /* BV() */
49 #include <cfg/debug.h>
50 #include <cfg/module.h>
54 #include <drv/timer.h>
58 #include <cpu/types.h>
61 /** Number of LCD pages */
64 /** Width of an LCD page */
65 #define LCD_PAGESIZE (LCD_WIDTH / 2)
68 * \name 32122A Commands
71 #define LCD_CMD_DISPLAY_ON 0xAF
72 #define LCD_CMD_DISPLAY_OFF 0xAE
73 #define LCD_CMD_STARTLINE 0xC0
74 #define LCD_CMD_PAGEADDR 0xB8
75 #define LCD_CMD_COLADDR 0x00
76 #define LCD_CMD_ADC_LEFT 0xA1
77 #define LCD_CMD_ADC_RIGHT 0xA0
78 #define LCD_CMD_STATIC_OFF 0xA4
79 #define LCD_CMD_STATIC_ON 0xA5
80 #define LCD_CMD_DUTY_32 0xA9
81 #define LCD_CMD_DUTY_16 0xA8
82 #define LCD_CMD_RMW_ON 0xE0
83 #define LCD_CMD_RMW_OFF 0xEE
84 #define LCD_CMD_RESET 0xE2
89 #define LCDF_BUSY BV(7)
95 * RS __\____________/__
118 } while (status & LCDF_BUSY); \
121 #else /* CONFIG_LCD_WAIT */
122 #define WAIT_LCD do {} while(0)
123 #endif /* CONFIG_LCD_WAIT */
127 * Raster buffer to draw into.
129 * Bits in the bitmap bytes have vertical orientation,
130 * as required by the LCD driver.
132 static uint8_t lcd_raster[RAST_SIZE(LCD_WIDTH, LCD_HEIGHT)];
134 /** Default LCD bitmap */
135 struct Bitmap lcd_bitmap;
138 #if CONFIG_LCD_SOFTINT_REFRESH
140 /** Timer for regular LCD refresh */
141 static Timer lcd_refresh_timer;
143 #endif /* CONFIG_LCD_SOFTINT_REFRESH */
146 INLINE void lcd_32122_cmd(uint8_t cmd, uint8_t chip)
151 * A0 __\____________/__
153 * R/W __________________
157 * DATA --<============>--
171 INLINE uint8_t lcd_32122_read(uint8_t chip)
186 * DATA -------<=====>----
204 INLINE void lcd_32122_write(uint8_t c, uint8_t chip)
213 * R/W __________________
217 * DATA -<==============>-
231 static void lcd_32122_clear(void)
235 for (page = 0; page < LCD_PAGES; ++page)
237 lcd_32122_cmd(LCD_CMD_COLADDR, LCDF_E1 | LCDF_E2);
238 lcd_32122_cmd(LCD_CMD_PAGEADDR | page, LCDF_E1 | LCDF_E2);
239 for (j = 0; j < LCD_PAGESIZE; j++)
240 lcd_32122_write(0, LCDF_E1 | LCDF_E2);
245 static void lcd_32122_writeRaster(const uint8_t *raster)
248 const uint8_t *right_raster;
250 for (page = 0; page < LCD_PAGES; ++page)
252 lcd_32122_cmd(LCD_CMD_PAGEADDR | page, LCDF_E1 | LCDF_E2);
253 lcd_32122_cmd(LCD_CMD_COLADDR | 0, LCDF_E1 | LCDF_E2);
255 /* Super optimized lamer loop */
256 right_raster = raster + LCD_PAGESIZE;
260 lcd_32122_write(*raster++, LCDF_E1);
261 lcd_32122_write(*right_raster++, LCDF_E2);
264 raster = right_raster;
268 #if CONFIG_LCD_SOFTINT_REFRESH
270 static void lcd_32122_refreshSoftint(void)
272 lcd_32122_blitBitmap(&lcd_bitmap);
273 timer_setDelay(&lcd_refresh_timer, ms_to_ticks(CONFIG_LCD_REFRESH));
274 timer_add(&lcd_refresh_timer);
277 #endif /* CONFIG_LCD_SOFTINT_REFRESH */
280 * Set LCD contrast PWM.
282 void lcd_32122_setPwm(int duty)
284 ASSERT(duty >= LCD_MIN_PWM);
285 ASSERT(duty <= LCD_MAX_PWM);
287 pwm_setDuty(LCD_PWM_CH, duty);
288 pwm_enable(LCD_PWM_CH, true);
292 * Update the LCD display with data from the provided bitmap.
294 void lcd_32122_blitBitmap(const Bitmap *bm)
296 lcd_32122_writeRaster(bm->raster);
301 * Initialize LCD subsystem.
303 * \note The PWM used for LCD contrast is initialized in drv/pwm.c
304 * because it is the same PWM used for output attenuation.
306 void lcd_32122_init(void)
312 lcd_32122a_hw_bus_init();
315 lcd_32122_cmd(LCD_CMD_RESET, LCDF_E1 | LCDF_E2);
316 lcd_32122_cmd(LCD_CMD_DISPLAY_ON, LCDF_E1 | LCDF_E2);
317 lcd_32122_cmd(LCD_CMD_STARTLINE | 0, LCDF_E1 | LCDF_E2);
321 lcd_32122_setPwm(LCD_DEF_PWM);
323 gfx_bitmapInit(&lcd_bitmap, lcd_raster, LCD_WIDTH, LCD_HEIGHT);
324 gfx_bitmapClear(&lcd_bitmap);
326 #if CONFIG_LCD_SOFTINT_REFRESH
327 /* Init IRQ driven LCD refresh */
328 timer_setSoftint(&lcd_refresh_timer, (Hook)lcd_32122_refreshSoftint, 0);
329 timer_setDelay(&lcd_refresh_timer, ms_to_ticks(CONFIG_LCD_REFRESH));
330 timer_add(&lcd_refresh_timer);
331 #endif /* CONFIG_LCD_SOFTINT_REFRESH */