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 OLED-RIT-128x96 (P14201) graphic display driver
35 * \author Andrea Righi <arighi@develer.com>
38 #include <cfg/debug.h>
39 #include <cfg/macros.h>
41 #include "lcd_rit128x96.h"
44 * Hard-coded command initialization sequence.
46 * NOTE: the first byte is the size of the command.
48 static const uint8_t init_cmd[] =
60 /* Pre-charge current */
64 /* Display Start Line */
68 /* Display Mode Normal */
74 /* Front Clock Divider */
76 /* Set gray scale table */
77 17, 0xb8, 1, 2, 3, 4, 5, 6, 8, 10, 12, 14, 16, 19, 22, 26, 30, 0xe3,
78 /* Second pre-charge period */
80 /* Pre-charge voltage */
87 * Hard-coded command shutdown sequence.
89 static const uint8_t exit_cmd[] =
96 * Hard-coded horizontal increment command.
98 static const uint8_t horizontal_inc[] =
104 * Write a sequence of data bytes to the LCD controller
106 static void lcd_dataWrite(const uint8_t *buf, size_t count)
112 /* Turn on the OLED display */
113 void rit128x96_on(void)
117 /* Loop through the SSD1329 controller initialization sequence */
119 for (i = 0; i < sizeof(init_cmd); i += init_cmd[i] + 1)
120 lcd_dataWrite(init_cmd + i + 1, init_cmd[i] - 1);
123 /* Turn off the OLED display */
124 void rit128x96_off(void)
127 lcd_dataWrite(exit_cmd, sizeof(exit_cmd));
130 static void lcd_start_blit(uint8_t x, uint8_t y, uint8_t width, uint8_t height)
134 ASSERT(width == LCD_WIDTH && height == LCD_HEIGHT);
136 /* Enter command mode */
141 buffer[2] = (x + width - 2) / 2;
142 lcd_dataWrite(buffer, 3);
146 buffer[2] = y + height - 1;
147 lcd_dataWrite(buffer, 3);
148 lcd_dataWrite((const uint8_t *)&horizontal_inc, sizeof(horizontal_inc));
151 /* Refresh a raw image on screen */
152 void rit128x96_blitRaw(const uint8_t *data,
153 uint8_t x, uint8_t y, uint8_t width, uint8_t height)
155 lcd_start_blit(x, y, width, height);
157 * Enter data mode and send the encoded image data to the OLED display,
163 /* Write an entire row at once */
164 lcd_dataWrite(data, width / 2);
169 /* Refresh a bitmap on screen */
170 void rit128x96_blitBitmap(const Bitmap *bm)
172 uint8_t lcd_row[bm->width / 2];
176 lcd_start_blit(0, 0, bm->width, bm->height);
178 * Enter data mode and send the encoded image data to the OLED display,
182 for (l = 0; l < bm->height / 8; l++)
184 for (mask = 1; mask; mask <<= 1)
186 for (i = 0; i < bm->width; i++)
188 if (bm->raster[l * bm->width + i] & mask)
189 lcd_row[i / 2] |= i & 1 ? 0x0f : 0xf0;
191 lcd_row[i / 2] &= i & 1 ? 0xf0 : 0x0f;
193 /* Write an entire row at once */
194 lcd_dataWrite(lcd_row, sizeof(lcd_row));
199 /* Initialize the OLED display */
200 void rit128x96_init(void)
202 /* Initialize the communication bus */
205 /* Turn on the OLED display */