lcd.c
Go to the documentation of this file.
1
6/*
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.0 (the "License"); you may not use this file except in
9 * compliance with the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS"
13 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
14 * License for the specific language governing rights and limitations
15 * under the License.
16 *
17 * The Original Code is legOS code, released October 17, 1999.
18 *
19 * The Initial Developer of the Original Code is Markus L. Noga.
20 * Portions created by Markus L. Noga are Copyright (C) 1999
21 * Markus L. Noga. All Rights Reserved.
22 *
23 * Contributor(s): Markus L. Noga <markus@noga.de>
24 */
25
26#include <config.h>
27#include <dlcd.h>
28#include <conio.h>
29#include <string.h>
30#include <sys/h8.h>
31#include <sys/lcd.h>
32#include <rom/registers.h>
33#include <lnp/sys/irq.h>
34
36//
37// Variables
38//
40
41#ifdef CONF_LCD_REFRESH
42unsigned char lcd_refresh_counter;
43unsigned char lcd_byte_counter;
44unsigned char lcd_refresh_period = 2;
45#endif
46
48
73
75//
76// Functions
77//
79
81
86#ifndef DOXYGEN_SHOULD_SKIP_THIS
87__asm__("\n\
88.text\n\
89.align 1\n\
90.globl _lcd_number\n\
91_lcd_number:\n\
92 push r6 ; save r6\n\
93 \n\
94 push r2 ; comma_style -> stack\n\
95 push r0 ; number -> stack\n\
96 \n\
97 mov.w r1,r6 ; number_style -> r6\n\
98 \n\
99 jsr @lcd_number ; call ROM\n\
100 \n\
101 adds #0x02,sp ; clear stack\n\
102 adds #0x02,sp\n\
103 \n\
104 pop r6 ; restore r6\n\
105 rts\n\
106 \n\
107 ");
108#endif // DOXYGEN_SHOULD_SKIP_THIS
109
111#define set(b) __asm__ __volatile__("bset %0,@0xbb:8" : : "i"(b));
113#define clr(b) __asm__ __volatile__("bclr %0,@0xbb:8" : : "i"(b));
114
116
121#define slowdown()
122
124static __inline__ void i2c_start(void)
125{
126 set(SDA);
127 set(SCL);
128 slowdown();
129 clr(SDA);
130 slowdown();
131 clr(SCL);
132 slowdown();
133}
134
136static __inline__ void i2c_stop(void)
137{
138 clr(SDA);
139 set(SCL);
140 slowdown();
141 set(SDA);
142 slowdown();
143 clr(SCL);
144 slowdown();
145 set(SCL); // relax output driver (saves 0.5 mA)
146}
147
149
153static __inline__ void i2c_read_ack(void)
154{
155 rom_port6_ddr &= ~(1 << SDA);
157 slowdown();
158 set(SCL);
159 slowdown();
160 clr(SCL);
161 rom_port6_ddr |= (1 << SDA);
163 slowdown();
164}
165
167
169static __inline__ void i2c_write(unsigned char val)
170{
171 unsigned char bit;
172
173 for (bit = (1 << 7); bit; bit >>= 1) {
174 if (bit & val) {
175 set(SDA);
176 } else {
177 clr(SDA);
178 }
179 slowdown();
180 set(SCL);
181 slowdown();
182 clr(SCL);
183 slowdown();
184 }
185}
186
188
195static void lcd_write_data(unsigned char *data, unsigned char len)
196{
197 unsigned char i;
198
199 i2c_start();
200 for (i = 0; i < len; i++) {
201 i2c_write(*data++);
202 i2c_read_ack();
203 }
204 i2c_stop();
205}
206
207
208#ifdef CONF_LCD_REFRESH
209
211
222#ifdef CONF_RCX_COMPILER
223void lcd_refresh_next_byte(void)
224#else
225HANDLER_WRAPPER("lcd_refresh_next_byte", "lcd_refresh_next_byte_core");
227
230#endif
231{
232 unsigned char byte;
233
234 byte = lcd_byte_counter++;
237
238 if (lcd_shadow[byte + LCD_DATA_OFFSET] == display_memory[byte])
239 return;
240
242 lcd_shadow[LCD_SHORT_CMD + 1] = byte << 1;
245}
246
247#endif // CONF_LCD_REFRESH
248
250
254void lcd_refresh(void)
255{
256 unsigned char i;
257
258 for (i = 0; i < LCD_DATA_SIZE; i++)
261}
262
264
266void lcd_power_on(void)
267{
270}
271
273
280{
281 lcd_refresh();
282
285
286 clr(SCL);
287 clr(SDA);
288}
289
291
295void lcd_init(void)
296{
297 rom_port6_ddr |= (1 << SCL);
299 clr(SCL);
300 rom_port6_ddr |= (1 << SDA);
302 clr(SDA);
303
304 memset(lcd_shadow, 0, sizeof(lcd_shadow));
307
308 lcd_power_on();
309
310#ifdef CONF_LCD_REFRESH
313#endif
314}
__asm__("\n\ .text\n\ .globl _atomic_inc\n\ _atomic_inc:\n\ stc ccr, r1h ; save flags\n\ orc #0x80, ccr ; disable all but NMI\n\ mov.b @r0, r1l\n\ inc r1l\n\ mov.b r1l, @r0\n\ ldc r1h, ccr ; restore flags\n\ rts\n\ ")
kernel configuration file
Interface: console input / output.
Interface: direct control of LCD display.
Internal Interface: H8/3297 processor registers.
unsigned char PORT6_DDR
port 6 data direction register
Internal LNP Interface: RCX redirected IRQ vectors.
unsigned char lcd_byte_counter
LCD byte to refresh.
Definition: lcd.c:43
HANDLER_WRAPPER("lcd_refresh_next_byte", "lcd_refresh_next_byte_core")
lcd refresh handler, called from system timer interrupt
unsigned char lcd_refresh_period
LCD refresh period in ms.
Definition: lcd.c:44
void lcd_refresh(void)
refresh the entire LCD display
Definition: lcd.c:254
#define slowdown()
generate the necessary delay for the i2c bus.
Definition: lcd.c:121
static __inline__ void i2c_stop(void)
generate an i2c stop condition.
Definition: lcd.c:136
static __inline__ void i2c_write(unsigned char val)
write one byte to the i2c bus.
Definition: lcd.c:169
void lcd_init(void)
initialize the LCD display driver
Definition: lcd.c:295
static unsigned char lcd_shadow[LCD_DATA_OFFSET+LCD_DATA_SIZE]
lcd_shadow buffer:
Definition: lcd.c:72
void lcd_refresh_next_byte_core(void)
alternate name for the refresh next byte routine
Definition: lcd.c:229
#define set(b)
set single bit convenience macro
Definition: lcd.c:111
static __inline__ void i2c_read_ack(void)
read the acknoledge from the i2c bus.
Definition: lcd.c:153
unsigned char lcd_refresh_counter
counter for lcd refresh in ms
Definition: lcd.c:42
void lcd_number(int i, lcd_number_style n, lcd_comma_style c)
show number on LCD display
void lcd_power_on(void)
power on the LCD controller
Definition: lcd.c:266
static __inline__ void i2c_start(void)
generate an i2c start condition.
Definition: lcd.c:124
static void lcd_write_data(unsigned char *data, unsigned char len)
write an array of bytes to the i2c bus.
Definition: lcd.c:195
#define clr(b)
clear single bit convenience macro
Definition: lcd.c:113
void lcd_power_off(void)
power off the LCD controller
Definition: lcd.c:279
ROM Interface: RCX registers cached by ROM functions.
unsigned char rom_port6_ddr
ROM shadow of port 6 DDR.
lcd_number_style
LCD number display styles.
Definition: lcd.h:99
lcd_comma_style
LCD comma display styles.
Definition: lcd.h:111
Interface: string functions.
void * memset(void *s, int c, size_t n)
fill memory block with a byte value.
Internal Interface: LCD control and constants.
#define LCD_DATA_OFFSET
Definition: lcd.h:47
#define LCD_LONG_CMD
Definition: lcd.h:46
#define LCD_SHORT_CMD
Definition: lcd.h:45
#define LCD_DATA_SIZE
Definition: lcd.h:48
#define LCD_DEV_ID
Definition: lcd.h:58
#define SDA
Definition: lcd.h:64
#define I2C_WRITE
Definition: lcd.h:60
#define LCD_ENABLE
Definition: lcd.h:53
#define SCL
Definition: lcd.h:63
#define LCD_DISABLE
Definition: lcd.h:54
unsigned char display_memory[]
LCD display data buffer.
void lcd_refresh_next_byte(void)
show LCD display contents to the world
#define LCD_MODE_SET
Definition: lcd.h:52

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS Kernel Developer by doxygen 1.9.4