Driver for the Hitachi HD44780 used in many small LCD panels.
Written by Dennis Chernoivanov.
This commit is contained in:
parent
d19c8682f2
commit
ec3de7e879
|
@ -0,0 +1,392 @@
|
|||
/* $NetBSD: hd44780_subr.c,v 1.1 2003/01/20 01:20:50 soren Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 Dennis I. Chernoivanov
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Subroutines for Hitachi HD44870 style displays
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: hd44780_subr.c,v 1.1 2003/01/20 01:20:50 soren Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioccom.h>
|
||||
|
||||
#include <machine/autoconf.h>
|
||||
#include <machine/intr.h>
|
||||
#include <machine/bus.h>
|
||||
|
||||
#include <dev/ic/hd44780reg.h>
|
||||
#include <dev/ic/hd44780_subr.h>
|
||||
|
||||
static void hd44780_init(struct hd44780_chip *);
|
||||
|
||||
/*
|
||||
* Finish device attach. sc_writereg, sc_readreg and sc_flags must be properly
|
||||
* initialized prior to this call.
|
||||
*/
|
||||
void
|
||||
hd44780_attach_subr(sc)
|
||||
struct hd44780_chip *sc;
|
||||
{
|
||||
/* Putc/getc are supposed to be set by platform-dependent code. */
|
||||
if ((sc->sc_rwrite == NULL) || (sc->sc_rread == NULL))
|
||||
sc->sc_dev_ok = 0;
|
||||
|
||||
/* Make sure that HD_MAX_CHARS is enough. */
|
||||
if ((sc->sc_flags & HD_MULTILINE) && (2 * sc->sc_rows > HD_MAX_CHARS))
|
||||
sc->sc_dev_ok = 0;
|
||||
else if (sc->sc_rows > HD_MAX_CHARS)
|
||||
sc->sc_dev_ok = 0;
|
||||
|
||||
if (sc->sc_dev_ok) {
|
||||
hd44780_init(sc);
|
||||
|
||||
/* Turn display on and clear it. */
|
||||
hd44780_ir_write(sc, cmd_dispctl(1, 0, 0));
|
||||
hd44780_ir_write(sc, cmd_clear());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize 4-bit or 8-bit connected device.
|
||||
*/
|
||||
static void
|
||||
hd44780_init(sc)
|
||||
struct hd44780_chip *sc;
|
||||
{
|
||||
u_int8_t cmd;
|
||||
|
||||
bus_space_tag_t iot;
|
||||
bus_space_handle_t ioh;
|
||||
|
||||
iot = sc->sc_iot;
|
||||
ioh = sc->sc_ioir;
|
||||
|
||||
if (sc->sc_irwrite == NULL)
|
||||
sc->sc_irwrite = sc->sc_rwrite;
|
||||
|
||||
cmd = cmd_init(sc->sc_flags & HD_8BIT);
|
||||
sc->sc_irwrite(iot, ioh, cmd);
|
||||
delay(TIMEOUT_LONG);
|
||||
sc->sc_irwrite(iot, ioh, cmd);
|
||||
sc->sc_irwrite(iot, ioh, cmd);
|
||||
|
||||
cmd = cmd_funcset(
|
||||
sc->sc_flags & HD_8BIT,
|
||||
sc->sc_flags & HD_MULTILINE,
|
||||
sc->sc_flags & HD_BIGFONT);
|
||||
|
||||
if ((sc->sc_flags & HD_8BIT) == 0)
|
||||
sc->sc_irwrite(iot, ioh, cmd);
|
||||
|
||||
/* Interface is set to the proper width, use normal 'write' op. */
|
||||
sc->sc_rwrite(iot, ioh, cmd);
|
||||
cmd = cmd_dispctl(0, 0, 0);
|
||||
sc->sc_rwrite(iot, ioh, cmd);
|
||||
cmd = cmd_clear();
|
||||
sc->sc_rwrite(iot, ioh, cmd);
|
||||
cmd = cmd_modset(1, 0);
|
||||
sc->sc_rwrite(iot, ioh, cmd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Standard hd44780 ioctl() functions.
|
||||
*/
|
||||
int
|
||||
hd44780_ioctl_subr(sc, cmd, data)
|
||||
struct hd44780_chip *sc;
|
||||
u_long cmd;
|
||||
caddr_t data;
|
||||
{
|
||||
u_int8_t tmp;
|
||||
int error = 0;
|
||||
|
||||
#define hd44780_io() ((struct hd44780_io *)data)
|
||||
#define hd44780_info() ((struct hd44780_info*)data)
|
||||
#define hd44780_ctrl() ((struct hd44780_dispctl*)data)
|
||||
|
||||
switch (cmd) {
|
||||
/* Clear the LCD. */
|
||||
case HLCD_CLEAR:
|
||||
hd44780_ir_write(sc, cmd_clear());
|
||||
break;
|
||||
|
||||
/* Move the cursor one position to the left. */
|
||||
case HLCD_CURSOR_LEFT:
|
||||
hd44780_ir_write(sc, cmd_shift(0, 0));
|
||||
break;
|
||||
|
||||
/* Move the cursor one position to the right. */
|
||||
case HLCD_CURSOR_RIGHT:
|
||||
hd44780_ir_write(sc, cmd_shift(0, 1));
|
||||
break;
|
||||
|
||||
/* Control the LCD. */
|
||||
case HLCD_DISPCTL:
|
||||
hd44780_ir_write(sc, cmd_dispctl(
|
||||
hd44780_ctrl()->display_on,
|
||||
hd44780_ctrl()->cursor_on,
|
||||
hd44780_ctrl()->blink_on));
|
||||
break;
|
||||
|
||||
/* Get LCD configuration. */
|
||||
case HLCD_GET_INFO:
|
||||
hd44780_info()->lines
|
||||
= (sc->sc_flags & HD_MULTILINE) ? 2 : 1;
|
||||
hd44780_info()->phys_rows = sc->sc_rows;
|
||||
hd44780_info()->virt_rows = sc->sc_vrows;
|
||||
hd44780_info()->is_wide = sc->sc_flags & HD_8BIT;
|
||||
hd44780_info()->is_bigfont = sc->sc_flags & HD_BIGFONT;
|
||||
hd44780_info()->kp_present = sc->sc_flags & HD_KEYPAD;
|
||||
break;
|
||||
|
||||
|
||||
/* Reset the LCD. */
|
||||
case HLCD_RESET:
|
||||
hd44780_ir_write(sc, cmd_init(sc->sc_flags & HD_8BIT));
|
||||
hd44780_ir_write(sc, cmd_init(sc->sc_flags & HD_8BIT));
|
||||
hd44780_ir_write(sc, cmd_init(sc->sc_flags & HD_8BIT));
|
||||
hd44780_ir_write(sc, cmd_init(sc->sc_flags & HD_8BIT));
|
||||
hd44780_ir_write(sc, cmd_modset(1, 0));
|
||||
hd44780_ir_write(sc, cmd_dispctl(1, 0, 0));
|
||||
hd44780_ir_write(sc, cmd_clear());
|
||||
break;
|
||||
|
||||
/* Get the current cursor position. */
|
||||
case HLCD_GET_CURSOR_POS:
|
||||
hd44780_io()->dat = (hd44780_ir_read(sc) & 0x7f);
|
||||
break;
|
||||
|
||||
/* Set the cursor position. */
|
||||
case HLCD_SET_CURSOR_POS:
|
||||
hd44780_ir_write(sc, cmd_ddramset(hd44780_io()->dat));
|
||||
break;
|
||||
|
||||
/* Get the value at the current cursor position. */
|
||||
case HLCD_GETC:
|
||||
tmp = (hd44780_ir_read(sc) & 0x7f);
|
||||
hd44780_ir_write(sc, cmd_ddramset(tmp));
|
||||
hd44780_io()->dat = hd44780_dr_read(sc);
|
||||
break;
|
||||
|
||||
/* Set the character at the cursor position + advance cursor. */
|
||||
case HLCD_PUTC:
|
||||
hd44780_dr_write(sc, hd44780_io()->dat);
|
||||
break;
|
||||
|
||||
/* Shift display left. */
|
||||
case HLCD_SHIFT_LEFT:
|
||||
hd44780_ir_write(sc, cmd_shift(1, 0));
|
||||
break;
|
||||
|
||||
/* Shift display right. */
|
||||
case HLCD_SHIFT_RIGHT:
|
||||
hd44780_ir_write(sc, cmd_shift(1, 1));
|
||||
break;
|
||||
|
||||
/* Return home. */
|
||||
case HLCD_HOME:
|
||||
hd44780_ir_write(sc, cmd_rethome());
|
||||
break;
|
||||
|
||||
/* Write a string to the LCD virtual area. */
|
||||
case HLCD_WRITE:
|
||||
error = hd44780_ddram_io(sc, hd44780_io(), HD_DDRAM_WRITE);
|
||||
break;
|
||||
|
||||
/* Read LCD virtual area. */
|
||||
case HLCD_READ:
|
||||
error = hd44780_ddram_io(sc, hd44780_io(), HD_DDRAM_READ);
|
||||
break;
|
||||
|
||||
/* Write to the LCD visible area. */
|
||||
case HLCD_REDRAW:
|
||||
hd44780_ddram_redraw(sc, hd44780_io());
|
||||
break;
|
||||
|
||||
/* Write raw instruction. */
|
||||
case HLCD_WRITE_INST:
|
||||
hd44780_ir_write(sc, hd44780_io()->dat);
|
||||
break;
|
||||
|
||||
/* Write raw data. */
|
||||
case HLCD_WRITE_DATA:
|
||||
hd44780_dr_write(sc, hd44780_io()->dat);
|
||||
break;
|
||||
|
||||
default:
|
||||
error = EINVAL;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read/write particular area of the LCD screen.
|
||||
*/
|
||||
int
|
||||
hd44780_ddram_io(sc, io, dir)
|
||||
struct hd44780_chip *sc;
|
||||
struct hd44780_io *io;
|
||||
u_char dir;
|
||||
{
|
||||
u_int8_t hi;
|
||||
u_int8_t addr;
|
||||
|
||||
int error = 0;
|
||||
u_int8_t i = 0;
|
||||
|
||||
if (io->dat < sc->sc_vrows) {
|
||||
hi = HD_ROW1_ADDR + sc->sc_vrows;
|
||||
addr = HD_ROW1_ADDR + io->dat;
|
||||
for (; (addr < hi) && (i < io->len); addr++, i++) {
|
||||
hd44780_ir_write(sc, cmd_ddramset(addr));
|
||||
if (dir == HD_DDRAM_READ)
|
||||
io->buf[i] = hd44780_dr_read(sc);
|
||||
else
|
||||
hd44780_dr_write(sc, io->buf[i]);
|
||||
}
|
||||
}
|
||||
if (io->dat < 2 * sc->sc_vrows) {
|
||||
hi = HD_ROW2_ADDR + sc->sc_vrows;
|
||||
if (io->dat >= sc->sc_vrows)
|
||||
addr = HD_ROW2_ADDR + io->dat - sc->sc_vrows;
|
||||
else
|
||||
addr = HD_ROW2_ADDR;
|
||||
for (; (addr < hi) && (i < io->len); addr++, i++) {
|
||||
hd44780_ir_write(sc, cmd_ddramset(addr));
|
||||
if (dir == HD_DDRAM_READ)
|
||||
io->buf[i] = hd44780_dr_read(sc);
|
||||
else
|
||||
hd44780_dr_write(sc, io->buf[i]);
|
||||
}
|
||||
if (i < io->len)
|
||||
io->len = i;
|
||||
} else {
|
||||
error = EINVAL;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to the visible area of the display.
|
||||
*/
|
||||
void
|
||||
hd44780_ddram_redraw(sc, io)
|
||||
struct hd44780_chip *sc;
|
||||
struct hd44780_io *io;
|
||||
{
|
||||
u_int8_t i;
|
||||
|
||||
hd44780_ir_write(sc, cmd_clear());
|
||||
hd44780_ir_write(sc, cmd_rethome());
|
||||
for (i = 0; (i < io->len) && (i < sc->sc_rows); i++) {
|
||||
hd44780_dr_write(sc, io->buf[i]);
|
||||
}
|
||||
hd44780_ir_write(sc, cmd_ddramset(HD_ROW2_ADDR));
|
||||
for (; (i < io->len); i++)
|
||||
hd44780_dr_write(sc, io->buf[i]);
|
||||
}
|
||||
|
||||
#if defined(HD44780_STD_WIDE)
|
||||
/*
|
||||
* Standard 8-bit version of 'sc_rwrite' (8-bit port, 8-bit access)
|
||||
*/
|
||||
void
|
||||
hd44780_rwrite(iot, ioh, cmd)
|
||||
bus_space_tag_t iot;
|
||||
bus_space_handle_t ioh;
|
||||
u_int8_t cmd;
|
||||
{
|
||||
bus_space_write_1(iot, ioh, 0x00, cmd);
|
||||
delay(TIMEOUT_NORMAL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Standard 8-bit version of 'sc_rread' (8-bit port, 8-bit access)
|
||||
*/
|
||||
u_int8_t
|
||||
hd44780_rread(iot, ioh)
|
||||
bus_space_tag_t iot;
|
||||
bus_space_handle_t ioh;
|
||||
{
|
||||
delay(TIMEOUT_NORMAL);
|
||||
return bus_space_read_1(iot, ioh, 0x00);
|
||||
}
|
||||
#elif defined(HD44780_STD_SHORT)
|
||||
/*
|
||||
* Standard 4-bit version of 'sc_irwrite' (4-bit port, 8-bit access)
|
||||
*/
|
||||
void
|
||||
hd44780_irwrite(iot, ioh, cmd)
|
||||
bus_space_tag_t iot;
|
||||
bus_space_handle_t ioh;
|
||||
u_int8_t cmd;
|
||||
{
|
||||
/* first four instructions emitted in 8-bit mode */
|
||||
bus_space_write_1(iot, ioh, 0x00, hi_bits(cmd));
|
||||
delay(TIMEOUT_NORMAL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Standard 4-bit version of 'sc_rrwrite' (4-bit port, 8-bit access)
|
||||
*/
|
||||
void
|
||||
hd44780_rwrite(iot, ioh, cmd)
|
||||
bus_space_tag_t iot;
|
||||
bus_space_handle_t ioh;
|
||||
u_int8_t cmd;
|
||||
{
|
||||
bus_space_write_1(iot, ioh, 0x00, hi_bits(cmd));
|
||||
bus_space_write_1(iot, ioh, 0x00, lo_bits(cmd));
|
||||
delay(TIMEOUT_NORMAL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Standard 4-bit version of 'sc_rread' (4-bit port, 8-bit access)
|
||||
*/
|
||||
u_int8_t
|
||||
hd44780_rread(iot, ioh)
|
||||
bus_space_tag_t iot;
|
||||
bus_space_handle_t ioh;
|
||||
{
|
||||
u_int8_t rd;
|
||||
u_int8_t dat;
|
||||
|
||||
delay(TIMEOUT_NORMAL);
|
||||
rd = bus_space_read_1(iot, ioh, 0x00);
|
||||
dat = (rd & 0x0f) << 4;
|
||||
rd = bus_space_read_1(iot, ioh, 0x00);
|
||||
return (dat | (rd & 0x0f));
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,145 @@
|
|||
/* $NetBSD: hd44780_subr.h,v 1.1 2003/01/20 01:20:51 soren Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 Dennis I. Chernoivanov
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _DEV_IC_HD44780_SUBR_H_
|
||||
#define _DEV_IC_HD44780_SUBR_H_
|
||||
|
||||
/* IOCTL definitions */
|
||||
#define HLCD_DISPCTL _IOW('h', 1, struct hd44780_dispctl)
|
||||
#define HLCD_RESET _IO('h', 2)
|
||||
#define HLCD_CLEAR _IO('h', 3)
|
||||
#define HLCD_CURSOR_LEFT _IO('h', 4)
|
||||
#define HLCD_CURSOR_RIGHT _IO('h', 5)
|
||||
#define HLCD_GET_CURSOR_POS _IOR('h', 6, struct hd44780_io)
|
||||
#define HLCD_SET_CURSOR_POS _IOW('h', 7, struct hd44780_io)
|
||||
#define HLCD_GETC _IOR('h', 8, struct hd44780_io)
|
||||
#define HLCD_PUTC _IOW('h', 9, struct hd44780_io)
|
||||
#define HLCD_SHIFT_LEFT _IO('h', 10)
|
||||
#define HLCD_SHIFT_RIGHT _IO('h', 11)
|
||||
#define HLCD_HOME _IO('h', 12)
|
||||
#define HLCD_WRITE _IOWR('h', 13, struct hd44780_io)
|
||||
#define HLCD_READ _IOWR('h', 14, struct hd44780_io)
|
||||
#define HLCD_REDRAW _IOW('h', 15, struct hd44780_io)
|
||||
#define HLCD_WRITE_INST _IOW('h', 16, struct hd44780_io)
|
||||
#define HLCD_WRITE_DATA _IOW('h', 17, struct hd44780_io)
|
||||
#define HLCD_GET_INFO _IOR('h', 18, struct hd44780_info)
|
||||
|
||||
struct hd44780_dispctl {
|
||||
u_char display_on:1,
|
||||
blink_on:1,
|
||||
cursor_on:1;
|
||||
};
|
||||
|
||||
struct hd44780_io {
|
||||
u_int8_t dat;
|
||||
u_int8_t len;
|
||||
u_int8_t buf[HD_MAX_CHARS];
|
||||
};
|
||||
|
||||
struct hd44780_info {
|
||||
u_char lines;
|
||||
u_char phys_rows;
|
||||
u_char virt_rows;
|
||||
|
||||
u_char is_wide:1,
|
||||
is_bigfont:1,
|
||||
kp_present:1;
|
||||
};
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
||||
/* HLCD driver structure */
|
||||
struct hd44780_chip {
|
||||
#define HD_8BIT 0x01 /* 8-bit if set, 4-bit otherwise */
|
||||
#define HD_MULTILINE 0x02 /* 2 lines if set, 1 otherwise */
|
||||
#define HD_BIGFONT 0x04 /* 5x10 if set, 5x8 otherwise */
|
||||
#define HD_KEYPAD 0x08 /* if set, keypad is connected */
|
||||
u_char sc_flags;
|
||||
|
||||
u_char sc_rows; /* visible rows */
|
||||
u_char sc_vrows; /* virtual rows (normally 40) */
|
||||
u_char sc_dev_ok;
|
||||
|
||||
bus_space_tag_t sc_iot;
|
||||
|
||||
bus_space_handle_t sc_ioir; /* instruction register */
|
||||
bus_space_handle_t sc_iodr; /* data register */
|
||||
|
||||
/*
|
||||
* This one is here to make initialization generic. If 4-bit
|
||||
* connection is used, the device still starts as if it was
|
||||
* 8-bit connected, so a special care is needed for such case.
|
||||
* If set to NULL, normal 'sc_rwrite()' function will be used
|
||||
* during initialization.
|
||||
*/
|
||||
void (* sc_irwrite)(bus_space_tag_t, bus_space_handle_t, u_int8_t);
|
||||
|
||||
/* Generic write/read byte entries. */
|
||||
void (* sc_rwrite)(bus_space_tag_t, bus_space_handle_t, u_int8_t);
|
||||
u_int8_t (* sc_rread)(bus_space_tag_t, bus_space_handle_t);
|
||||
};
|
||||
|
||||
#define hd44780_busy_wait(sc) \
|
||||
while((hd44780_ir_read(sc) & BUSY_FLAG) == BUSY_FLAG)
|
||||
|
||||
#define hd44780_ir_write(sc, dat) \
|
||||
do { \
|
||||
hd44780_busy_wait(sc); \
|
||||
(sc)->sc_rwrite((sc)->sc_iot, (sc)->sc_ioir, (dat)); \
|
||||
} while(0)
|
||||
|
||||
#define hd44780_ir_read(sc) \
|
||||
(sc)->sc_rread((sc)->sc_iot, (sc)->sc_ioir)
|
||||
|
||||
#define hd44780_dr_write(sc, dat) \
|
||||
(sc)->sc_rwrite((sc)->sc_iot, (sc)->sc_iodr, (dat))
|
||||
|
||||
#define hd44780_dr_read(sc) \
|
||||
(sc)->sc_rread((sc)->sc_iot, (sc)->sc_iodr)
|
||||
|
||||
void hd44780_attach_subr(struct hd44780_chip *);
|
||||
int hd44780_ioctl_subr(struct hd44780_chip *, u_long, caddr_t);
|
||||
void hd44780_ddram_redraw(struct hd44780_chip *, struct hd44780_io *);
|
||||
|
||||
#define HD_DDRAM_READ 0x0
|
||||
#define HD_DDRAM_WRITE 0x1
|
||||
int hd44780_ddram_io(struct hd44780_chip *, struct hd44780_io *, u_char);
|
||||
|
||||
#if defined(HD44780_STD_SHORT)
|
||||
void hd44780_irwrite(bus_space_tag_t, bus_space_handle_t, u_int8_t);
|
||||
#endif
|
||||
|
||||
#if defined(HD44780_STD_WIDE) || defined(HD44780_STD_SHORT)
|
||||
void hd44780_rwrite(bus_space_tag_t, bus_space_handle_t, u_int8_t);
|
||||
u_int8_t hd44780_rread(bus_space_tag_t, bus_space_handle_t);
|
||||
#endif
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif /* _DEV_IC_HD44780_SUBR_H_ */
|
|
@ -0,0 +1,112 @@
|
|||
/* $NetBSD: hd44780reg.h,v 1.1 2003/01/20 01:20:51 soren Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 Dennis I. Chernoivanov
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _DEV_IC_HD44780REG_H_
|
||||
#define _DEV_IC_HD44780REG_H_
|
||||
|
||||
/*
|
||||
* Register definitions for Hitachi HD44870 style displays
|
||||
*/
|
||||
|
||||
#define HD_MAX_CHARS 80
|
||||
|
||||
#define HD_ROW1_ADDR 0x00
|
||||
#define HD_ROW2_ADDR 0x40
|
||||
|
||||
#define TIMEOUT_LONG 5000
|
||||
#define TIMEOUT_SHORT 100
|
||||
#define TIMEOUT_NORMAL 200
|
||||
|
||||
#define BUSY_FLAG 0x80
|
||||
|
||||
/* Bit set helper */
|
||||
#define bset(cond, bit) ((cond) ? (bit) : 0x00)
|
||||
|
||||
/* Get 4 most/least significant bits */
|
||||
#define hi_bits(byte) (((byte) & 0xf0) >> 4)
|
||||
#define lo_bits(byte) ((byte) & 0x0f)
|
||||
|
||||
/*
|
||||
* 'Initialize by instruction' 8bit=1/0 8-bit/4-bit operation
|
||||
*/
|
||||
#define cmd_init(mode) ((u_int8_t)(mode ? 0x3f : 0x03))
|
||||
|
||||
/*
|
||||
* 'Clear display'
|
||||
*/
|
||||
#define cmd_clear() ((u_int8_t)0x01)
|
||||
|
||||
/*
|
||||
* 'Return home'
|
||||
*/
|
||||
#define cmd_rethome() ((u_int8_t)0x03)
|
||||
|
||||
/*
|
||||
* 'Entry mode set' id=1/0 increment/decrement
|
||||
* s=1 display shift
|
||||
*/
|
||||
#define cmd_modset(id, s) \
|
||||
((u_int8_t)(0x04 | bset(id, 0x2) | bset(s, 0x1)))
|
||||
|
||||
/*
|
||||
* 'Display on/off control' d=1/0 display on/off
|
||||
* c=1/0 cursor on/off
|
||||
* b=1/0 blinking of cursor position on/off
|
||||
*/
|
||||
#define cmd_dispctl(d, c, b) \
|
||||
((u_int8_t)(0x08 | bset(d, 0x04) | bset(c, 0x02) | bset(b, 0x01)))
|
||||
|
||||
/*
|
||||
* 'Cursor or display shift' sc=1/0 display shift/cursor move
|
||||
* rl=1/0 shift to the right/left
|
||||
*/
|
||||
#define cmd_shift(sc, rl) \
|
||||
((u_int8_t)(0x13 | bset(sc, 0x08) | bset(rl, 0x04)))
|
||||
|
||||
/*
|
||||
* 'Function set' dl=1/0 8 bits/4 bits operation
|
||||
* n=1/0 2 lines/1 line
|
||||
* f=1/0 5x10/5x8 dots font
|
||||
*/
|
||||
#define cmd_funcset(dl, n, f) \
|
||||
((u_int8_t)(0x23 | bset(dl, 0x10) | bset(n, 0x08) | bset(f, 0x04)))
|
||||
|
||||
/*
|
||||
* 'Set CGRAM address'
|
||||
*/
|
||||
#define cmd_cgramset(acg) \
|
||||
((u_int8_t)(0x40 | ((acg) & 0x3f)))
|
||||
|
||||
/*
|
||||
* 'Set DDRAM address'
|
||||
*/
|
||||
#define cmd_ddramset(add) \
|
||||
((u_int8_t)(0x80 | ((add) & 0x7f)))
|
||||
|
||||
#endif /* _DEV_IC_HD44780REG_H_ */
|
Loading…
Reference in New Issue