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 4 wire interface 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>
76 #include <cpu/byteorder.h>
79 static struct KFile *spi;
82 * Display row buffer. When refreshing display one full row of
83 * graphics data is transferred with DMA, to speed up transfer and
86 static uint16_t lcd_row[LCD_WIDTH];
89 struct lcd_ili9225_reg
91 uint8_t cmd; // Register index, if 0xFF wait for value ms
92 uint16_t data; // Register value
95 static const struct lcd_ili9225_reg init_seq[] =
97 {0x01, 0x011c}, // Set SS, SM, GS and NL bits
98 {0x02, 0x0100}, // Set 1 line inversion
99 {0x03, 0x1030}, // Entry Mode set GRAM write direction and BGR=1
100 {0x08, 0x0808}, // Set BP and FP
101 {0x0C, 0x0001}, // RGB Input Interface Control: 16-bit RGB interface
102 {0x0F, 0x0A01}, // Set frame rate: 83Hz
103 {0x20, LCD_WIDTH}, // Set GRAM Address
104 {0x21, LCD_HEIGHT}, // Set GRAM Address
106 /* power on sequence */
107 {0x10, 0x0A00}, // Set asp DSTB,STB
108 {0x11, 0x1038}, // SET APON PON AON VCI1EN VC
109 {0xFF, 50}, // Wait 50 ms
111 {0x12, 0x1121}, // Internal reference voltage = VCI
112 {0x13, 0x06CE}, // Set GVDD
113 {0x14, 0x676F}, // Set VCOMH/VCOML voltage
140 static void lcd_cmd(uint8_t cmd)
144 kfile_write(spi, &cmd, sizeof(cmd));
147 static void lcd_data(uint16_t *data, size_t count)
151 kfile_write(spi, data, count*2);
156 static void lcd_regWrite(uint8_t reg, uint16_t data)
158 uint16_t word = cpu_to_be16(data);
164 static void lcd_startBlit(uint8_t x, uint8_t y, uint8_t width, uint8_t height)
166 ASSERT((x + width) <= LCD_WIDTH);
167 ASSERT((y + height) <= LCD_HEIGHT);
169 lcd_regWrite(0x36, x + width);
170 lcd_regWrite(0x37, x);
171 lcd_regWrite(0x38, y + height);
172 lcd_regWrite(0x39, y);
174 lcd_regWrite(0x20, x);
175 lcd_regWrite(0x21, y);
179 * Refresh a raw image on screen
181 void lcd_ili9225_blitRaw(UNUSED_ARG(const uint8_t *, data),
182 uint8_t x, uint8_t y, uint8_t width, uint8_t height)
184 lcd_startBlit(x, y, width, height);
189 * Refresh a bitmap on screen
191 void lcd_ili9225_blitBitmap(const Bitmap *bm)
196 lcd_startBlit(0, 0, bm->width, bm->height);
198 for (l = 0; l < bm->height / 8; l++)
200 for (mask = 1; mask; mask <<= 1)
202 for (i = 0; i < bm->width; i++)
204 if (bm->raster[l * bm->width + i] & mask)
210 lcd_data(lcd_row, bm->width);
214 for (r = 0, mask = 1; r < bm->height % 8; r++, mask <<= 1)
216 for (i = 0; i < bm->width; i++)
218 if (bm->raster[l * bm->width + i] & mask)
224 lcd_data(lcd_row, bm->width);
229 * Blit a 24 bit color raw raster directly on screen
231 void lcd_ili9225_blitBitmap24(int x, int y, int width, int height, const char *bmp)
235 lcd_startBlit(x, y, width, height);
237 for (l = 0; l < height; l++)
239 for (r = 0; r < width; r++)
242 (((uint16_t)bmp[1] << 11) & 0xE000) |
243 (((uint16_t)bmp[2] << 5) & 0x1F00) |
244 (((uint16_t)bmp[0] << 0) & 0x00F8) |
245 (((uint16_t)bmp[1] >> 5) & 0x0007);
250 lcd_data(lcd_row, width);
257 void lcd_ili9225_off(void)
259 lcd_regWrite(0x07, 0x0000);
265 void lcd_ili9225_on(void)
267 lcd_regWrite(0x07, 0x1017);
273 static void lcd_reset(void)
282 * Display initialization.
284 void lcd_ili9225_init(struct KFile *_spi)
290 lcd_ili9225_hw_bus_init();
295 for (i = 0; i < countof(init_seq); i++)
297 if (init_seq[i].cmd != 0xFF)
298 lcd_regWrite(init_seq[i].cmd, init_seq[i].data);
300 timer_delay(init_seq[i].data);