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 2010 Develer S.r.l. (http://www.develer.com/)
33 * \brief ILI9225B 176x220 graphic driver
35 * \author Stefano Fedrigo <aleph@develer.com>
37 * Display initialization sequence is based on Atmel's softpack library
38 * implementation, see license below.
41 /* ----------------------------------------------------------------------------
42 * ATMEL Microcontroller Software Support
43 * ----------------------------------------------------------------------------
44 * Copyright (c) 2010, Atmel Corporation
46 * All rights reserved.
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions are met:
51 * - Redistributions of source code must retain the above copyright notice,
52 * this list of conditions and the disclaimer below.
54 * Atmel's name may not be used to endorse or promote products derived from
55 * this software without specific prior written permission.
57 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
59 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
60 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
61 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
62 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
63 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
64 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
65 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
66 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ----------------------------------------------------------------------------
70 #include "lcd_ili9225.h"
72 #include "hw/hw_ili9225.h"
74 #include <drv/timer.h>
78 static struct KFile *spi;
81 struct lcd_ili9225_reg
83 uint8_t cmd; // Register index, if 0xFF wait for value ms
84 uint16_t data; // Register value
87 static const struct lcd_ili9225_reg init_seq[] =
89 {0x01, 0x011c}, // Set SS, SM, GS and NL bits
90 {0x02, 0x0100}, // Set 1 line inversion
91 {0x03, 0x1030}, // Entry Mode set GRAM write direction and BGR=1
92 {0x08, 0x0808}, // Set BP and FP
93 {0x0C, 0x0001}, // RGB Input Interface Control: 16-bit RGB interface
94 {0x0F, 0x0A01}, // Set frame rate: 83Hz
95 {0x20, LCD_WIDTH}, // Set GRAM Address
96 {0x21, LCD_HEIGHT}, // Set GRAM Address
98 /* power on sequence */
99 {0x10, 0x0A00}, // Set asp DSTB,STB
100 {0x11, 0x1038}, // SET APON PON AON VCI1EN VC
101 {0xFF, 50}, // Wait 50 ms
103 {0x12, 0x1121}, // Internal reference voltage = VCI
104 {0x13, 0x06CE}, // Set GVDD
105 {0x14, 0x676F}, // Set VCOMH/VCOML voltage
132 static void lcd_cmd(uint8_t cmd)
136 kfile_write(spi, &cmd, sizeof(cmd));
139 static void lcd_data(uint16_t data)
142 bytes[0] = data >> 8;
143 bytes[1] = data & 0xFF;
147 kfile_write(spi, bytes, 2);
152 static void lcd_regWrite(uint8_t reg, uint16_t data)
158 static void lcd_startBlit(uint8_t x, uint8_t y, uint8_t width, uint8_t height)
160 ASSERT((x + width) <= LCD_WIDTH);
161 ASSERT((y + height) <= LCD_HEIGHT);
163 lcd_regWrite(0x36, x + width);
164 lcd_regWrite(0x37, x);
165 lcd_regWrite(0x38, y + height);
166 lcd_regWrite(0x39, y);
168 lcd_regWrite(0x20, x);
169 lcd_regWrite(0x21, y);
173 * Refresh a raw image on screen
175 void lcd_ili9225_blitRaw(UNUSED_ARG(const uint8_t *, data),
176 uint8_t x, uint8_t y, uint8_t width, uint8_t height)
178 lcd_startBlit(x, y, width, height);
183 * Refresh a bitmap on screen
185 void lcd_ili9225_blitBitmap(const Bitmap *bm)
187 //uint16_t lcd_row[bm->width];
191 lcd_startBlit(0, 0, bm->width, bm->height);
193 for (l = 0; l < bm->height / 8; l++)
195 for (mask = 1; mask; mask <<= 1)
197 for (i = 0; i < bm->width; i++)
199 if (bm->raster[l * bm->width + i] & mask)
200 lcd_regWrite(0x22, 0xffff);
202 lcd_regWrite(0x22, 0x0000);
207 for (r = 0, mask = 1; r < bm->height % 8; r++, mask <<= 1)
209 for (i = 0; i < bm->width; i++)
211 if (bm->raster[l * bm->width + i] & mask)
212 lcd_regWrite(0x22, 0xffff);
214 lcd_regWrite(0x22, 0x0000);
222 void lcd_ili9225_off(void)
224 lcd_regWrite(0x07, 0x0000);
230 void lcd_ili9225_on(void)
232 lcd_regWrite(0x07, 0x1017);
238 static void lcd_reset(void)
247 * Set display backlight intensity.
249 void lcd_ili9225_backlight(unsigned level)
253 if (level > LCD_BACKLIGHT_MAX)
254 level = LCD_BACKLIGHT_MAX;
256 // Switch off backlight
261 for (i = 0; i <= level; i++)
267 LCD_BACKLIGHT_HIGH();
268 LCD_BACKLIGHT_HIGH();
269 LCD_BACKLIGHT_HIGH();
274 * Display initialization.
276 void lcd_ili9225_init(struct KFile *_spi)
282 lcd_ili9225_hw_bus_init();
287 for (i = 0; i < countof(init_seq); i++)
289 if (init_seq[i].cmd != 0xFF)
290 lcd_regWrite(init_seq[i].cmd, init_seq[i].data);
292 timer_delay(init_seq[i].data);