Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

kernel/lcd.c File Reference

Implementation: wrapper for ROM LCD number display functions. More...

#include <config.h>
#include <dlcd.h>
#include <conio.h>
#include <string.h>
#include <sys/h8.h>
#include <sys/lcd.h>
#include <rom/registers.h>
#include <lnp/sys/irq.h>

Include dependency graph for lcd.c:

Include dependency graph

Go to the source code of this file.

Defines

#define set(b)   __asm__ __volatile__("bset %0,@0xbb:8" : : "i"(b));
 set single bit convenience macro

#define clr(b)   __asm__ __volatile__("bclr %0,@0xbb:8" : : "i"(b));
 clear single bit convenience macro

#define slowdown()
 generate the necessary delay for the i2c bus.


Functions

void lcd_number (int i, lcd_number_style n, lcd_comma_style c)
 show number on LCD display

__inline__ void i2c_start (void)
 generate an i2c start condition.

__inline__ void i2c_stop (void)
 generate an i2c stop condition.

__inline__ void i2c_read_ack (void)
 read the acknoledge from the i2c bus.

__inline__ void i2c_write (unsigned char val)
 write one byte to the i2c bus.

void lcd_write_data (unsigned char *data, unsigned char len)
 write an array of bytes to the i2c bus.

 HANDLER_WRAPPER ("lcd_refresh_next_byte","lcd_refresh_next_byte_core")
 lcd refresh handler, called from system timer interrupt

void lcd_refresh_next_byte_core (void)
 alternate name for the refresh next byte routine

void lcd_refresh (void)
 show LCD display contents to the world

void lcd_power_on (void)
 power on LCD display, also called from lcd_init()

void lcd_power_off (void)
 power off LCD display

void lcd_init (void)
 initialize LCD driver


Variables

unsigned char lcd_refresh_counter
 counter for lcd refresh in ms

unsigned char lcd_byte_counter
 LCD byte to refresh.

unsigned char lcd_refresh_period = 2
 LCD refresh period in ms.

unsigned char lcd_shadow [LCD_DATA_OFFSET+LCD_DATA_SIZE]
 lcd_shadow buffer:


Detailed Description

Implementation: wrapper for ROM LCD number display functions.

Author:
Markus L. Noga <markus@noga.de>

Definition in file lcd.c.


Define Documentation

#define clr  )     __asm__ __volatile__("bclr %0,@0xbb:8" : : "i"(b));
 

clear single bit convenience macro

Definition at line 113 of file lcd.c.

Referenced by i2c_read_ack(), i2c_start(), i2c_stop(), i2c_write(), lcd_init(), and lcd_power_off().

#define set  )     __asm__ __volatile__("bset %0,@0xbb:8" : : "i"(b));
 

set single bit convenience macro

Definition at line 111 of file lcd.c.

Referenced by i2c_read_ack(), i2c_start(), i2c_stop(), and i2c_write().

 
#define slowdown  ) 
 

generate the necessary delay for the i2c bus.

the h8/300 at 16 MHz is slow enough to run without delay, when running this code from RAM. There might be some delay necessary when running from ROM.

Definition at line 121 of file lcd.c.

Referenced by i2c_read_ack(), i2c_start(), i2c_stop(), and i2c_write().


Function Documentation

HANDLER_WRAPPER "lcd_refresh_next_byte"  ,
"lcd_refresh_next_byte_core" 
 

lcd refresh handler, called from system timer interrupt

refresh one byte of display_memory.

Bytes are refreshed in round robin fashon and the lcd_shadow buffer is updated. If there was no difference between display_memory and the lcd_shadow buffer, the actual write to the LCD controller is skipped.

This routine is called every 6ms from the timer interrupt, resulting in a complete LCD update every 54ms, which is a refresh rate of 18 updates per second.

__inline__ void i2c_read_ack void   )  [static]
 

read the acknoledge from the i2c bus.

Warning: the value of the acknoledge is ignored. We can't do much on errors anyway.

Definition at line 153 of file lcd.c.

References clr, PORT6_DDR, rom_port6_ddr, SCL, SDA, set, and slowdown.

Referenced by lcd_write_data().

__inline__ void i2c_start void   )  [static]
 

generate an i2c start condition.

Definition at line 124 of file lcd.c.

References clr, SCL, SDA, set, and slowdown.

Referenced by lcd_write_data().

__inline__ void i2c_stop void   )  [static]
 

generate an i2c stop condition.

Definition at line 136 of file lcd.c.

References clr, SCL, SDA, set, and slowdown.

Referenced by lcd_write_data().

__inline__ void i2c_write unsigned char  val  )  [static]
 

write one byte to the i2c bus.

Parameters:
val byte to write to the i2c bus

Definition at line 169 of file lcd.c.

References clr, SCL, SDA, set, and slowdown.

Referenced by lcd_write_data().

void lcd_init void   ) 
 

initialize LCD driver

output drivers are configured as outputs. the lcd_shadow buffer is cleared and initialized. the LCD controller is enabled.

Definition at line 295 of file lcd.c.

References clr, I2C_WRITE, lcd_byte_counter, LCD_DEV_ID, LCD_LONG_CMD, lcd_power_on(), lcd_refresh_counter, lcd_shadow, LCD_SHORT_CMD, memset(), PORT6_DDR, rom_port6_ddr, SCL, and SDA.

void lcd_number int  i,
lcd_number_style  n,
lcd_comma_style  c
 

show number on LCD display

Parameters:
i the number
n a number style
c a comma style

void lcd_power_off void   ) 
 

power off LCD display

the LCD controller is put in low power mode and output drivers to the LCD controller are disabled.

Note: without disabling the output drivers the CPU will not save power in sleep mode.

Definition at line 279 of file lcd.c.

References clr, LCD_DISABLE, LCD_MODE_SET, lcd_refresh(), lcd_shadow, LCD_SHORT_CMD, lcd_write_data(), SCL, and SDA.

void lcd_power_on void   ) 
 

power on LCD display, also called from lcd_init()

the LCD controller is enabled.

Definition at line 266 of file lcd.c.

References LCD_ENABLE, LCD_MODE_SET, lcd_shadow, LCD_SHORT_CMD, and lcd_write_data().

Referenced by lcd_init().

void lcd_refresh void   ) 
 

show LCD display contents to the world

the entire 9 bytes of display_memory are written to the LCD controller unconditionally. lcd_shadow is updated to the new values.

Definition at line 254 of file lcd.c.

References display_memory, LCD_DATA_OFFSET, LCD_DATA_SIZE, LCD_LONG_CMD, lcd_shadow, and lcd_write_data().

Referenced by lcd_power_off(), show_off(), and show_on().

void lcd_refresh_next_byte_core void   ) 
 

alternate name for the refresh next byte routine

Todo:
find a better description for this

Definition at line 229 of file lcd.c.

References display_memory, lcd_byte_counter, LCD_DATA_OFFSET, LCD_DATA_SIZE, lcd_shadow, LCD_SHORT_CMD, and lcd_write_data().

void lcd_write_data unsigned char *  data,
unsigned char  len
[static]
 

write an array of bytes to the i2c bus.

Parameters:
data array of bytes to write to the i2c bus
len number of bytes to write
len bytes are written to the i2c bus, including initial start condition and final stop condition. The first byte must contain a device address and the r/w flag.

Definition at line 195 of file lcd.c.

References i2c_read_ack(), i2c_start(), i2c_stop(), and i2c_write().

Referenced by lcd_power_off(), lcd_power_on(), lcd_refresh(), and lcd_refresh_next_byte_core().


Variable Documentation

unsigned char lcd_byte_counter
 

LCD byte to refresh.

Definition at line 43 of file lcd.c.

Referenced by lcd_init(), and lcd_refresh_next_byte_core().

unsigned char lcd_refresh_counter
 

counter for lcd refresh in ms

Definition at line 42 of file lcd.c.

Referenced by lcd_init().

unsigned char lcd_refresh_period = 2
 

LCD refresh period in ms.

Definition at line 44 of file lcd.c.

unsigned char lcd_shadow[LCD_DATA_OFFSET + LCD_DATA_SIZE] [static]
 

lcd_shadow buffer:

contains the last display_memory bytes written to the LCD controller at position LCD_DATA_OFFSET.

lcd_shadow also contains the buffer for the i2c commands written to the LCD controller.

At offset LCD_SHORT_CMD a small piece of memory is reserved for direct commands to the LCD controller. This is used for power on/off, and for single byte updates.

At offset LCD_LONG_CMD a small piece of memory is reserved for the i2c command header to do a full LCD update. The display data directly follows this header.

The entire buffer in memory looks like this:

0 1 2 3 4 5 +------+------+------+------+------+--- ---+ | Addr | Cmd | Data | Addr | 0x00 | display data (9 bytes) | +------+------+------+------+------+--- ---+ / / LCD_SHORT_CMD LCD_LONG_CMD with display data

Definition at line 72 of file lcd.c.

Referenced by lcd_init(), lcd_power_off(), lcd_power_on(), lcd_refresh(), and lcd_refresh_next_byte_core().


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

Generated on Mon Feb 16 21:02:31 2004 for brickOS Kernel Developer by doxygen 1.3.5