Misc KNF.

This commit is contained in:
tsutsui 2009-08-30 02:07:05 +00:00
parent ce7dbb45a0
commit 4ca1400e03
3 changed files with 160 additions and 148 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: hd44780_subr.c,v 1.19 2009/03/16 23:11:15 dsl Exp $ */
/* $NetBSD: hd44780_subr.c,v 1.20 2009/08/30 02:07:05 tsutsui Exp $ */
/*
* Copyright (c) 2002 Dennis I. Chernoivanov
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: hd44780_subr.c,v 1.19 2009/03/16 23:11:15 dsl Exp $");
__KERNEL_RCSID(0, "$NetBSD: hd44780_subr.c,v 1.20 2009/08/30 02:07:05 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -118,12 +118,13 @@ hlcd_cursor(void *id, int on, int row, int col)
static int
hlcd_mapchar(void *id, int uni, unsigned int *index)
{
if (uni < 256) {
*index = uni;
return (5);
return 5;
}
*index = ' ';
return (0);
return 0;
}
static void
@ -202,6 +203,7 @@ hlcd_eraserows(void *id, int startrow, int nrows, long fillattr)
static int
hlcd_allocattr(void *id, int fg, int bg, int flags, long *attrp)
{
*attrp = flags;
return 0;
}
@ -231,11 +233,13 @@ hlcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
static paddr_t
hlcd_mmap(void *v, void *vs, off_t offset, int prot)
{
return -1;
}
static int
hlcd_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep, int *curxp, int *curyp, long *defattrp)
hlcd_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
int *curxp, int *curyp, long *defattrp)
{
struct hlcd_screen *hdscr = v, *new;
@ -254,13 +258,14 @@ hlcd_free_screen(void *v, void *cookie)
}
static int
hlcd_show_screen(void *v, void *cookie, int waitok, void (*cb)(void *, int, int), void *cbarg)
hlcd_show_screen(void *v, void *cookie, int waitok,
void (*cb)(void *, int, int), void *cbarg)
{
struct hlcd_screen *hdscr = v;
hdscr->hlcd_sc->sc_curscr = cookie;
callout_schedule(&hdscr->hlcd_sc->redraw, 1);
return (0);
return 0;
}
static void
@ -288,7 +293,7 @@ hlcd_redraw(void *arg)
struct hd44780_chip *sc = arg;
int len, crsridx, startidx, x, y;
int old_en, new_en;
u_char *img, *curimg;
uint8_t *img, *curimg;
if (sc->sc_curscr == NULL)
return;
@ -361,6 +366,7 @@ void
hd44780_attach_subr(struct hd44780_chip *sc)
{
int err = 0;
/* Putc/getc are supposed to be set by platform-dependent code. */
if ((sc->sc_writereg == NULL) || (sc->sc_readreg == NULL))
sc->sc_dev_ok = 0;
@ -375,8 +381,8 @@ hd44780_attach_subr(struct hd44780_chip *sc)
if ((sc->sc_flags & HD_UP) == 0)
err = hd44780_init(sc);
if (err != 0)
aprint_error_dev(sc->sc_dev, "LCD not responding or unconnected\n");
aprint_error_dev(sc->sc_dev,
"LCD not responding or unconnected\n");
}
sc->sc_screen.hlcd_sc = sc;
@ -389,23 +395,24 @@ hd44780_attach_subr(struct hd44780_chip *sc)
callout_setfunc(&sc->redraw, hlcd_redraw, sc);
}
int hd44780_init(sc)
struct hd44780_chip *sc;
int hd44780_init(struct hd44780_chip *sc)
{
int ret;
ret = hd44780_chipinit(sc, 0);
if (ret != 0 || !(sc->sc_flags & HD_MULTICHIP)) return ret;
else return hd44780_chipinit(sc, 1);
if (ret != 0 || !(sc->sc_flags & HD_MULTICHIP))
return ret;
else
return hd44780_chipinit(sc, 1);
}
/*
* Initialize 4-bit or 8-bit connected device.
*/
int
hd44780_chipinit(struct hd44780_chip *sc, u_int32_t en)
hd44780_chipinit(struct hd44780_chip *sc, uint32_t en)
{
u_int8_t cmd, dat;
uint8_t cmd, dat;
sc->sc_flags &= ~(HD_TIMEDOUT|HD_UP);
sc->sc_dev_ok = 1;
@ -460,131 +467,131 @@ hd44780_chipinit(struct hd44780_chip *sc, u_int32_t en)
int
hd44780_ioctl_subr(struct hd44780_chip *sc, u_long cmd, void *data)
{
u_int8_t tmp;
uint8_t tmp;
int error = 0;
u_int32_t en = sc->sc_curchip;
uint32_t en = sc->sc_curchip;
#define hd44780_io() ((struct hd44780_io *)data)
#define hd44780_info() ((struct hd44780_info*)data)
#define hd44780_ctrl() ((struct hd44780_dispctl*)data)
#define hd44780_info() ((struct hd44780_info *)data)
#define hd44780_ctrl() ((struct hd44780_dispctl *)data)
switch (cmd) {
case HLCD_CLEAR:
/* Clear the LCD. */
case HLCD_CLEAR:
hd44780_ir_write(sc, en, cmd_clear());
break;
hd44780_ir_write(sc, en, cmd_clear());
break;
case HLCD_CURSOR_LEFT:
/* Move the cursor one position to the left. */
case HLCD_CURSOR_LEFT:
hd44780_ir_write(sc, en, cmd_shift(0, 0));
hd44780_ir_write(sc, en, cmd_shift(0, 0));
break;
case HLCD_CURSOR_RIGHT:
/* Move the cursor one position to the right. */
case HLCD_CURSOR_RIGHT:
hd44780_ir_write(sc, en, cmd_shift(0, 1));
break;
hd44780_ir_write(sc, en, cmd_shift(0, 1));
break;
case HLCD_DISPCTL:
/* Control the LCD. */
case HLCD_DISPCTL:
hd44780_ir_write(sc, en, cmd_dispctl(
hd44780_ctrl()->display_on,
hd44780_ctrl()->cursor_on,
hd44780_ctrl()->blink_on));
break;
hd44780_ir_write(sc, en, cmd_dispctl(
hd44780_ctrl()->display_on,
hd44780_ctrl()->cursor_on,
hd44780_ctrl()->blink_on));
break;
case HLCD_GET_INFO:
/* Get LCD configuration. */
case HLCD_GET_INFO:
hd44780_info()->lines
= (sc->sc_flags & HD_MULTILINE) ? 2 : 1;
if (sc->sc_flags & HD_MULTICHIP)
hd44780_info()->lines *= 2;
hd44780_info()->phys_rows = sc->sc_cols;
hd44780_info()->virt_rows = sc->sc_vcols;
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;
hd44780_info()->lines
= (sc->sc_flags & HD_MULTILINE) ? 2 : 1;
if (sc->sc_flags & HD_MULTICHIP)
hd44780_info()->lines *= 2;
hd44780_info()->phys_rows = sc->sc_cols;
hd44780_info()->virt_rows = sc->sc_vcols;
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;
case HLCD_RESET:
/* Reset the LCD. */
case HLCD_RESET:
error = hd44780_init(sc);
break;
error = hd44780_init(sc);
break;
case HLCD_GET_CURSOR_POS:
/* Get the current cursor position. */
case HLCD_GET_CURSOR_POS:
hd44780_io()->dat = (hd44780_ir_read(sc, en) & 0x7f);
break;
hd44780_io()->dat = (hd44780_ir_read(sc, en) & 0x7f);
break;
case HLCD_SET_CURSOR_POS:
/* Set the cursor position. */
case HLCD_SET_CURSOR_POS:
hd44780_ir_write(sc, en, cmd_ddramset(hd44780_io()->dat));
break;
hd44780_ir_write(sc, en, cmd_ddramset(hd44780_io()->dat));
break;
case HLCD_GETC:
/* Get the value at the current cursor position. */
case HLCD_GETC:
tmp = (hd44780_ir_read(sc, en) & 0x7f);
hd44780_ir_write(sc, en, cmd_ddramset(tmp));
hd44780_io()->dat = hd44780_dr_read(sc, en);
break;
tmp = (hd44780_ir_read(sc, en) & 0x7f);
hd44780_ir_write(sc, en, cmd_ddramset(tmp));
hd44780_io()->dat = hd44780_dr_read(sc, en);
break;
case HLCD_PUTC:
/* Set the character at the cursor position + advance cursor. */
case HLCD_PUTC:
hd44780_dr_write(sc, en, hd44780_io()->dat);
break;
hd44780_dr_write(sc, en, hd44780_io()->dat);
break;
case HLCD_SHIFT_LEFT:
/* Shift display left. */
case HLCD_SHIFT_LEFT:
hd44780_ir_write(sc, en, cmd_shift(1, 0));
break;
hd44780_ir_write(sc, en, cmd_shift(1, 0));
break;
case HLCD_SHIFT_RIGHT:
/* Shift display right. */
case HLCD_SHIFT_RIGHT:
hd44780_ir_write(sc, en, cmd_shift(1, 1));
break;
hd44780_ir_write(sc, en, cmd_shift(1, 1));
break;
case HLCD_HOME:
/* Return home. */
case HLCD_HOME:
hd44780_ir_write(sc, en, cmd_rethome());
break;
hd44780_ir_write(sc, en, cmd_rethome());
break;
case HLCD_WRITE:
/* Write a string to the LCD virtual area. */
case HLCD_WRITE:
error = hd44780_ddram_io(sc, en, hd44780_io(), HD_DDRAM_WRITE);
break;
error = hd44780_ddram_io(sc, en, hd44780_io(), HD_DDRAM_WRITE);
break;
case HLCD_READ:
/* Read LCD virtual area. */
case HLCD_READ:
error = hd44780_ddram_io(sc, en, hd44780_io(), HD_DDRAM_READ);
break;
error = hd44780_ddram_io(sc, en, hd44780_io(), HD_DDRAM_READ);
break;
case HLCD_REDRAW:
/* Write to the LCD visible area. */
case HLCD_REDRAW:
hd44780_ddram_redraw(sc, en, hd44780_io());
break;
hd44780_ddram_redraw(sc, en, hd44780_io());
break;
case HLCD_WRITE_INST:
/* Write raw instruction. */
case HLCD_WRITE_INST:
hd44780_ir_write(sc, en, hd44780_io()->dat);
break;
hd44780_ir_write(sc, en, hd44780_io()->dat);
break;
case HLCD_WRITE_DATA:
/* Write raw data. */
case HLCD_WRITE_DATA:
hd44780_dr_write(sc, en, hd44780_io()->dat);
break;
hd44780_dr_write(sc, en, hd44780_io()->dat);
break;
case HLCD_GET_CHIPNO:
/* Get current chip 0 or 1 (top or bottom) */
case HLCD_GET_CHIPNO:
*(u_int8_t *)data = sc->sc_curchip;
break;
*(uint8_t *)data = sc->sc_curchip;
break;
case HLCD_SET_CHIPNO:
/* Set current chip 0 or 1 (top or bottom) */
case HLCD_SET_CHIPNO:
sc->sc_curchip = *(u_int8_t *)data;
break;
sc->sc_curchip = *(uint8_t *)data;
break;
default:
error = EINVAL;
default:
error = EINVAL;
}
if (sc->sc_flags & HD_TIMEDOUT)
@ -597,13 +604,13 @@ hd44780_ioctl_subr(struct hd44780_chip *sc, u_long cmd, void *data)
* Read/write particular area of the LCD screen.
*/
int
hd44780_ddram_io(struct hd44780_chip *sc, u_int32_t en, struct hd44780_io *io, u_char dir)
hd44780_ddram_io(struct hd44780_chip *sc, uint32_t en, struct hd44780_io *io,
uint8_t dir)
{
u_int8_t hi;
u_int8_t addr;
uint8_t hi;
uint8_t addr;
int error = 0;
u_int8_t i = 0;
uint8_t i = 0;
if (io->dat < sc->sc_vcols) {
hi = HD_ROW1_ADDR + sc->sc_vcols;
@ -641,9 +648,10 @@ hd44780_ddram_io(struct hd44780_chip *sc, u_int32_t en, struct hd44780_io *io, u
* Write to the visible area of the display.
*/
void
hd44780_ddram_redraw(struct hd44780_chip *sc, u_int32_t en, struct hd44780_io *io)
hd44780_ddram_redraw(struct hd44780_chip *sc, uint32_t en,
struct hd44780_io *io)
{
u_int8_t i;
uint8_t i;
hd44780_ir_write(sc, en, cmd_clear());
hd44780_ir_write(sc, en, cmd_rethome());
@ -657,14 +665,15 @@ hd44780_ddram_redraw(struct hd44780_chip *sc, u_int32_t en, struct hd44780_io *i
}
void
hd44780_busy_wait(struct hd44780_chip *sc, u_int32_t en)
hd44780_busy_wait(struct hd44780_chip *sc, uint32_t en)
{
int nloops = 100;
if (sc->sc_flags & HD_TIMEDOUT)
return;
while(nloops-- && (hd44780_ir_read(sc, en) & BUSY_FLAG) == BUSY_FLAG);
while (nloops-- && (hd44780_ir_read(sc, en) & BUSY_FLAG) == BUSY_FLAG)
continue;
if (nloops == 0) {
sc->sc_flags |= HD_TIMEDOUT;
@ -677,7 +686,8 @@ hd44780_busy_wait(struct hd44780_chip *sc, u_int32_t en)
* Standard 8-bit version of 'sc_writereg' (8-bit port, 8-bit access)
*/
void
hd44780_writereg(struct hd44780_chip *sc, u_int32_t en, u_int32_t reg, u_int8_t cmd)
hd44780_writereg(struct hd44780_chip *sc, uint32_t en, uint32_t reg,
uint8_t cmd)
{
bus_space_tag_t iot = sc->sc_iot;
bus_space_handle_t ioh;
@ -697,8 +707,8 @@ hd44780_writereg(struct hd44780_chip *sc, u_int32_t en, u_int32_t reg, u_int8_t
/*
* Standard 8-bit version of 'sc_readreg' (8-bit port, 8-bit access)
*/
u_int8_t
hd44780_readreg(struct hd44780_chip *sc, u_int32_t en, u_int32_t reg)
uint8_t
hd44780_readreg(struct hd44780_chip *sc, uint32_t en, uint32_t reg)
{
bus_space_tag_t iot = sc->sc_iot;
bus_space_handle_t ioh;
@ -719,7 +729,8 @@ hd44780_readreg(struct hd44780_chip *sc, u_int32_t en, u_int32_t reg)
* Standard 4-bit version of 'sc_writereg' (4-bit port, 8-bit access)
*/
void
hd44780_writereg(struct hd44780_chip *sc, u_int32_t en, u_int32_t reg, u_int8_t cmd)
hd44780_writereg(struct hd44780_chip *sc, uint32_t en, uint32_t reg,
uint8_t cmd)
{
bus_space_tag_t iot = sc->sc_iot;
bus_space_handle_t ioh;
@ -741,12 +752,12 @@ hd44780_writereg(struct hd44780_chip *sc, u_int32_t en, u_int32_t reg, u_int8_t
/*
* Standard 4-bit version of 'sc_readreg' (4-bit port, 8-bit access)
*/
u_int8_t
hd44780_readreg(struct hd44780_chip *sc, u_int32_t en, u_int32_t reg)
uint8_t
hd44780_readreg(struct hd44780_chip *sc, uint32_t en, uint32_t reg)
{
bus_space_tag_t iot = sc->sc_iot;
bus_space_handle_t ioh;
u_int8_t rd, dat;
uint8_t rd, dat;
if (sc->sc_dev_ok == 0)
return;

View File

@ -1,4 +1,4 @@
/* $NetBSD: hd44780reg.h,v 1.3 2005/12/11 12:21:26 christos Exp $ */
/* $NetBSD: hd44780reg.h,v 1.4 2009/08/30 02:07:05 tsutsui Exp $ */
/*
* Copyright (c) 2002 Dennis I. Chernoivanov
@ -55,24 +55,24 @@
/*
* 'Initialize by instruction' 8bit=1/0 8-bit/4-bit operation
*/
#define cmd_init(mode) ((u_int8_t)(mode ? 0x3f : 0x03))
#define cmd_init(mode) ((uint8_t)(mode ? 0x3f : 0x03))
/*
* 'Clear display'
*/
#define cmd_clear() ((u_int8_t)0x01)
#define cmd_clear() ((uint8_t)0x01)
/*
* 'Return home'
*/
#define cmd_rethome() ((u_int8_t)0x03)
#define cmd_rethome() ((uint8_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)))
((uint8_t)(0x04 | bset(id, 0x2) | bset(s, 0x1)))
/*
* 'Display on/off control' d=1/0 display on/off
@ -80,14 +80,14 @@
* 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)))
((uint8_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)))
((uint8_t)(0x13 | bset(sc, 0x08) | bset(rl, 0x04)))
/*
* 'Function set' dl=1/0 8 bits/4 bits operation
@ -95,18 +95,18 @@
* 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)))
((uint8_t)(0x23 | bset(dl, 0x10) | bset(n, 0x08) | bset(f, 0x04)))
/*
* 'Set CGRAM address'
*/
#define cmd_cgramset(acg) \
((u_int8_t)(0x40 | ((acg) & 0x3f)))
((uint8_t)(0x40 | ((acg) & 0x3f)))
/*
* 'Set DDRAM address'
*/
#define cmd_ddramset(add) \
((u_int8_t)(0x80 | ((add) & 0x7f)))
((uint8_t)(0x80 | ((add) & 0x7f)))
#endif /* _DEV_IC_HD44780REG_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: hd44780var.h,v 1.6 2009/05/12 14:25:17 cegger Exp $ */
/* $NetBSD: hd44780var.h,v 1.7 2009/08/30 02:07:05 tsutsui Exp $ */
/*
* Copyright (c) 2002 Dennis I. Chernoivanov
@ -49,29 +49,29 @@
#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)
#define HLCD_GET_CHIPNO _IOR('h', 19, u_int8_t)
#define HLCD_SET_CHIPNO _IOW('h', 20, u_int8_t)
#define HLCD_GET_CHIPNO _IOR('h', 19, uint8_t)
#define HLCD_SET_CHIPNO _IOW('h', 20, uint8_t)
struct hd44780_dispctl {
u_int8_t chip;
u_char display_on:1,
uint8_t chip;
uint8_t display_on:1,
blink_on:1,
cursor_on:1;
};
struct hd44780_io {
u_int8_t chip;
u_int8_t dat;
u_int8_t len;
u_int8_t buf[HD_MAX_CHARS];
uint8_t chip;
uint8_t dat;
uint8_t len;
uint8_t buf[HD_MAX_CHARS];
};
struct hd44780_info {
u_char lines;
u_char phys_rows;
u_char virt_rows;
uint8_t lines;
uint8_t phys_rows;
uint8_t virt_rows;
u_char is_wide:1,
uint8_t is_wide:1,
is_bigfont:1,
kp_present:1;
};
@ -82,7 +82,7 @@ struct hlcd_screen {
int hlcd_curon;
int hlcd_curx;
int hlcd_cury;
u_char *image; /* characters of screen */
uint8_t *image; /* characters of screen */
struct hd44780_chip *hlcd_sc;
};
@ -95,12 +95,12 @@ struct hd44780_chip {
#define HD_UP 0x10 /* if set, lcd has been initialized */
#define HD_TIMEDOUT 0x20 /* lcd has recently stopped talking */
#define HD_MULTICHIP 0x40 /* two HD44780 controllers (4-line) */
u_char sc_flags;
uint8_t sc_flags;
u_char sc_cols; /* visible columns */
u_char sc_vcols; /* virtual columns (normally 40) */
u_char sc_dev_ok;
u_char sc_curchip;
uint8_t sc_cols; /* visible columns */
uint8_t sc_vcols; /* virtual columns (normally 40) */
uint8_t sc_dev_ok;
uint8_t sc_curchip;
bus_space_tag_t sc_iot;
@ -113,9 +113,9 @@ struct hd44780_chip {
struct callout redraw; /* wsdisplay refresh/redraw timer */
/* Generic write/read byte entries. */
void (* sc_writereg)(struct hd44780_chip *, u_int32_t, u_int32_t,
u_int8_t);
u_int8_t (* sc_readreg)(struct hd44780_chip *, u_int32_t, u_int32_t);
void (* sc_writereg)(struct hd44780_chip *, uint32_t, uint32_t,
uint8_t);
uint8_t (* sc_readreg)(struct hd44780_chip *, uint32_t, uint32_t);
};
#define hd44780_ir_write(sc, en, dat) \
@ -134,19 +134,20 @@ struct hd44780_chip {
(sc)->sc_readreg((sc), (en), 1)
void hd44780_attach_subr(struct hd44780_chip *);
void hd44780_busy_wait(struct hd44780_chip *, u_int32_t);
void hd44780_busy_wait(struct hd44780_chip *, uint32_t);
int hd44780_init(struct hd44780_chip *);
int hd44780_chipinit(struct hd44780_chip *, u_int32_t);
int hd44780_chipinit(struct hd44780_chip *, uint32_t);
int hd44780_ioctl_subr(struct hd44780_chip *, u_long, void *);
void hd44780_ddram_redraw(struct hd44780_chip *, u_int32_t, struct hd44780_io *);
void hd44780_ddram_redraw(struct hd44780_chip *, uint32_t, struct hd44780_io *);
#define HD_DDRAM_READ 0x0
#define HD_DDRAM_WRITE 0x1
int hd44780_ddram_io(struct hd44780_chip *, u_int32_t, struct hd44780_io *, u_char);
int hd44780_ddram_io(struct hd44780_chip *, uint32_t, struct hd44780_io *,
uint8_t);
#if defined(HD44780_STD_WIDE) || defined(HD44780_STD_SHORT)
void hd44780_writereg(struct hd44780_chip *, u_int32_t, u_int32_t, u_int8_t);
u_int8_t hd44780_readreg(struct hd44780_chip *, u_int32_t, u_int32_t);
void hd44780_writereg(struct hd44780_chip *, uint32_t, uint32_t, uint8_t);
uint8_t hd44780_readreg(struct hd44780_chip *, uint32_t, uint32_t);
#endif
#endif /* _KERNEL */