From 15b226483af0536fa3e8aca265cb16bc85e93e5c Mon Sep 17 00:00:00 2001 From: robijn Date: Thu, 7 Feb 2002 22:10:04 +0000 Subject: [PATCH] Added PIC-an-LCD HD44780 subdriver. Currently untested. --- acinclude.m4 | 2 +- server/drivers/Makefile.am | 1 + server/drivers/hd44780-drivers.h | 14 ++-- server/drivers/hd44780-low.h | 2 + server/drivers/hd44780-picanlcd.c | 128 ++++++++++++++++++++++++++++++ server/drivers/hd44780-picanlcd.h | 9 +++ 6 files changed, 148 insertions(+), 8 deletions(-) create mode 100644 server/drivers/hd44780-picanlcd.c create mode 100644 server/drivers/hd44780-picanlcd.h diff --git a/acinclude.m4 b/acinclude.m4 index 6e4e18f..20a552d 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -116,7 +116,7 @@ dnl else actdrivers=["$actdrivers lb216"] ;; hd44780) - DRIVERS="$DRIVERS hd44780.o hd44780-4bit.o hd44780-ext8bit.o lcd_sem.o hd44780-serialLpt.o hd44780-winamp.o" + DRIVERS="$DRIVERS hd44780.o hd44780-4bit.o hd44780-ext8bit.o lcd_sem.o hd44780-serialLpt.o hd44780-winamp.o hd44780-picanlcd.o" AC_DEFINE(HD44780_DRV) actdrivers=["$actdrivers hd44780"] ;; diff --git a/server/drivers/Makefile.am b/server/drivers/Makefile.am index 5f2acb5..afe07bb 100644 --- a/server/drivers/Makefile.am +++ b/server/drivers/Makefile.am @@ -8,6 +8,7 @@ EXTRA_libLCDdrivers_a_SOURCES = MtxOrb.c MtxOrb.h text.c text.h \ hd44780-ext8bit.c hd44780-ext8bit.h lcd_sem.c lcd_sem.h \ hd44780-serialLpt.c hd44780-serialLpt.h \ hd44780-winamp.c hd44780-winamp.h \ + hd44780-picanlcd.c hd44780-picanlcd.h \ hd44780-low.h hd44780-drivers.h hd44780-charmap.h \ sed1330.c sed1330.h \ sed1520.c sed1520.h sed1520fm.c \ diff --git a/server/drivers/hd44780-drivers.h b/server/drivers/hd44780-drivers.h index 717bed4..42baa23 100644 --- a/server/drivers/hd44780-drivers.h +++ b/server/drivers/hd44780-drivers.h @@ -15,6 +15,7 @@ #include "hd44780-ext8bit.h" #include "hd44780-serialLpt.h" #include "hd44780-winamp.h" +#include "hd44780-picanlcd.h" // add new connection type header files here static const ConnectionMapping connectionMapping[] = { @@ -22,15 +23,14 @@ static const ConnectionMapping connectionMapping[] = { // string to identify connection on command line // your initialisation function // help string for your particular connection - { - "4bit", hd_init_4bit, "\tnone\n"}, { - "8bit", hd_init_ext8bit, "\tnone\n"}, { - "serialLpt", hd_init_serialLpt, "\tnone\n"}, { - "winamp", hd_init_winamp, "\tnone\n"}, + {"4bit", hd_init_4bit, "\tnone\n"}, + {"8bit", hd_init_ext8bit, "\tnone\n"}, + {"serialLpt", hd_init_serialLpt, "\tnone\n"}, + {"winamp", hd_init_winamp, "\tnone\n"}, + {"picanlcd", hd_init_picanlcd, "\tnone\n"}, // add new connection types and their string specifier here // default, end of structure element (do not delete) - { - NULL, NULL, NULL} + {NULL, NULL, NULL} }; #endif diff --git a/server/drivers/hd44780-low.h b/server/drivers/hd44780-low.h index 504d31c..c8c9e95 100644 --- a/server/drivers/hd44780-low.h +++ b/server/drivers/hd44780-low.h @@ -47,6 +47,8 @@ typedef struct driver_private_data { unsigned int port; + int fd; /* for picanlcd connection type */ + int width, height; int cellwidth, cellheight; diff --git a/server/drivers/hd44780-picanlcd.c b/server/drivers/hd44780-picanlcd.c new file mode 100644 index 0000000..cbd3878 --- /dev/null +++ b/server/drivers/hd44780-picanlcd.c @@ -0,0 +1,128 @@ +/* + * "PIC-an-LCD" serial driver module for Hitachi HD44780 based LCD displays. + * + * Copyright (c) 1997, Matthias Prinke + * 1998, Richard Rognlie + * 1999, Ethan Dicks + * 1999-2000, Benjamin Tse + * 2001, Rene Wagner + * 2001-2002, Joris Robijn + * + * This file is released under the GNU General Public License. Refer to the + * COPYING file distributed with this package. + * + * See the PIC-an-LCD documentation for data on how it should be connected + * to the computer. + * http://dalewheat.com/products/PIC-an-LCD/index.html + * + */ + +#include "hd44780-picanlcd.h" +#include "hd44780.h" + +#include "shared/str.h" +#include "report.h" + +#include +#include +#include + +#include +#include +#include +#include + +#include + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +// Generally, any function that accesses the LCD control lines needs to be +// implemented separately for each HW design. This is typically (but not +// restricted to): +// HD44780_senddata +// HD44780_readkeypad + +void picanlcd_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch); + +// PIC-an-LCD ASCII commands +//#define PICANLCD_HOME '\001' +//#define PICANLCD_CLR '\014' +#define PICANLCD_LED '\025' +#define PICANLCD_LCDI '\021' +#define PICANLCD_LCDD '\022' + +#define DEFAULT_DEVICE "/dev/lcd" + +// initialise the driver +int +hd_init_picanlcd (Driver *drvthis) +{ + PrivateData *p = (PrivateData*) drvthis->private_data; + + struct termios portset; + char device[256] = DEFAULT_DEVICE; + + /* READ CONFIG FILE */ + + /* Get serial device to use */ + strncpy(device, drvthis->config_get_string ( drvthis->name , "device" , 0 , DEFAULT_DEVICE),sizeof(device)); + device[sizeof(device)-1]=0; + report (RPT_INFO,"HD44780: PC-an-LCD: Using device: %s", device); + + // Set up io port correctly, and open it... + p->fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); + if (p->fd == -1) { + report(RPT_ERR, "HD44780: PC-an-LCD: could not open device %s (%s)\n", device, strerror(errno)); + return -1; + } + + /* Get serial device parameters */ + tcgetattr(p->fd, &portset); + + /* We use RAW mode */ +#ifdef HAVE_CFMAKERAW + /* The easy way */ + cfmakeraw( &portset ); +#else + /* The hard way */ + portset.c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP + | INLCR | IGNCR | ICRNL | IXON ); + portset.c_oflag &= ~OPOST; + portset.c_lflag &= ~( ECHO | ECHONL | ICANON | ISIG | IEXTEN ); + portset.c_cflag &= ~( CSIZE | PARENB | CRTSCTS ); + portset.c_cflag |= CS8 | CREAD | CLOCAL ; +#endif + /* Set port speed to 9600 baud */ + cfsetospeed(&portset, B9600); + + /* Set TCSANOW mode of serial device */ + tcsetattr(p->fd, TCSANOW, &portset); + + p->hd44780_functions->senddata = picanlcd_HD44780_senddata; + + common_init (p); + + return 0; +} + +// picanlcd_HD44780_senddata +void +picanlcd_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch) +{ + static const char data_byte = PICANLCD_LCDD; + static const char instr_byte = PICANLCD_LCDI; + + if (flags == RS_DATA) { + // Do we need a DATA indicator byte ? + if( ch < 32 ) { + write( p->fd, &data_byte, 1 ); + } + write( p->fd, &ch, 1 ); + } + else { + write( p->fd, &instr_byte, 1 ); + write( p->fd, &ch, 1 ); + } +} diff --git a/server/drivers/hd44780-picanlcd.h b/server/drivers/hd44780-picanlcd.h new file mode 100644 index 0000000..bac51fb --- /dev/null +++ b/server/drivers/hd44780-picanlcd.h @@ -0,0 +1,9 @@ +#ifndef HD_PICANLCD_H +#define HD_PICANLCD_H + +#include "lcd.h" /* for Driver */ + +// initialise this particular driver +int hd_init_picanlcd (Driver *drvthis); + +#endif