LCDproc development and user support list

Text archives Help


[Lcdproc] [Patch] Experimental hd44780 wiring using FreeBSD's ppi device


Chronological Thread 
  • From: bsdfan AT nurfuerspam.de (Markus Dolze)
  • Subject: [Lcdproc] [Patch] Experimental hd44780 wiring using FreeBSD's ppi device
  • Date: Tue Mar 29 06:41:01 2005

Hello,

with my limited C knowledge I played a bit with FreeBSD's ppi device. From the man page:

"The ppi driver provides a convenient means for user applications to manipulate the state of the parallel port, enabling easy low-speed I/O operations without the security problems inherent with the use of the /dev/io interface."

I wrote an additional wiring scheme using the ppi device and its ioctl commands. The driver uses winamp style hardware wiring. Although the ppi code adds some latency to the parallel port it is currently working fine with my display (Displaytech 162C).

It would have been best to replace or add the ppi device instead of outb() and inb() calls in port.h, but it requires rewriting of the lcdproc drivers because ppi has different calls for control and data ports. The hd44780 driver currently does only have the outb() call which is passed the port to access.

So if anyone ever writes a replacement for direct port access, this wiring driver demonstrates how it can work on FreeBSD. The driver is therefore not meant to be included in the main lcdproc sources.

--
Markus

Index: server/drivers/Makefile.am
===================================================================
RCS file: /cvsroot/lcdproc/lcdproc/server/drivers/Makefile.am,v
retrieving revision 1.32
diff -u -r1.32 Makefile.am
--- server/drivers/Makefile.am 23 Oct 2004 16:29:22 -0000 1.32
+++ server/drivers/Makefile.am 29 Mar 2005 05:47:10 -0000
@@ -47,7 +47,7 @@
curses_SOURCES = lcd.h curses_drv.h curses_drv.c report.h
glk_SOURCES = lcd.h glk.c glk.h glkproto.c glkproto.h report.h
hd44780_SOURCES = lcd.h hd44780.h hd44780.c hd44780-drivers.h
hd44780-low.h hd44780-charmap.h report.h
-EXTRA_hd44780_SOURCES = hd44780-4bit.c hd44780-4bit.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-bwct-usb.c hd44780-bwct-usb.h port.h lpt-port.h timing.h
+EXTRA_hd44780_SOURCES = hd44780-4bit.c hd44780-4bit.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-bwct-usb.c hd44780-bwct-usb.h port.h lpt-port.h timing.h
hd44780-ppi.c hd44780-ppi.h

icp_a106_SOURCES = lcd.h icp_a106.c icp_a106.h report.h
IOWarrior_SOURCES = lcd.h lcd_lib.h hd44780-charmap.h IOWarrior.c
IOWarrior.h report.h
#ifndef HD_PPI_H
#define HD_PPI_H

#include "lcd.h" /* for Driver */
#include "hd44780-low.h"

// initialise this particular driver
int hd_init_ppi(Driver *drvthis);

void ppi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned
char flags, unsigned char ch);
void ppi_HD44780_backlight(PrivateData *p, unsigned char state);
unsigned char ppi_HD44780_scankeypad(PrivateData *p);

#endif
Index: acinclude.m4
===================================================================
RCS file: /cvsroot/lcdproc/lcdproc/acinclude.m4,v
retrieving revision 1.48
diff -u -r1.48 acinclude.m4
--- acinclude.m4 9 Oct 2004 16:15:37 -0000 1.48
+++ acinclude.m4 29 Mar 2005 05:47:50 -0000
@@ -132,7 +132,7 @@
;;
hd44780)
if test "$ac_cv_port_have_lpt" = yes ; then
- HD44780_DRIVERS="hd44780-4bit.o
hd44780-ext8bit.o lcd_sem.o hd44780-winamp.o hd44780-serialLpt.o
hd44780-picanlcd.o"
+ HD44780_DRIVERS="hd44780-4bit.o
hd44780-ext8bit.o lcd_sem.o hd44780-winamp.o hd44780-serialLpt.o
hd44780-picanlcd.o hd44780-ppi.o"
else
HD44780_DRIVERS="hd44780-picanlcd.o"
fi
/*
* This is a experimental wiring scheme using FreeBSD's ppi device instead
* of directly accessing the LPT port.
*
* It is basically a modified winamp wiring scheme.
*
* Written by Markus Dolze
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
*/

#include "hd44780-ppi.h"
#include "lpt-port.h"
#include "report.h"

#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <dev/ppbus/ppi.h>

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#define EN1 STRB
#define EN2 SEL
#define EN3 LF
#define RW LF
#define RS INIT
#define BL SEL
#define LE LF

#define DEFAULT_DEVICE "/dev/ppi0"

#define sctrl(v) {u_int8_t val; val = v; ioctl(hd_fd, PPISCTRL, &val);}
#define sdata(v) {u_int8_t val; val = v; ioctl(hd_fd, PPISDATA, &val);}

static int hd_fd;
static const unsigned char EnMask[] = { EN1, EN2, EN3 };

/*
* Initialize the driver
*/
int
hd_init_ppi (Driver *drvthis)
{
PrivateData *p = (PrivateData*) drvthis->private_data;
char device[255];

p->hd44780_functions->senddata = ppi_HD44780_senddata;
p->hd44780_functions->backlight = ppi_HD44780_backlight;
p->hd44780_functions->scankeypad = ppi_HD44780_scankeypad;

/* Read the device from the config file */
strncpy(device, drvthis->config_get_string(drvthis->name, "PPIdev",
0, DEFAULT_DEVICE), sizeof(device));
device[sizeof(device)-1] = '\0';
if (*device != '\0')
report(RPT_INFO, "hd_init_ppi: Using device: %s", device);
if ((hd_fd = open(device, O_RDWR, 0)) == -1) {
report(RPT_ERR, "hd_init_ppi: unable to open device");
return -1;
}

/* Initialize the display */
common_init(p, IF_8BIT);
return 0;
}


void
ppi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char
flags, unsigned char ch)
{
u_int8_t enableLines = 0, portControl;

if (flags == RS_DATA)
portControl = RS;
else
portControl = 0;

if (displayID == 0)
enableLines = EnMask[0];
else
enableLines = EnMask[displayID - 1];

/* set RS */
sctrl(portControl ^ OUTMASK);

/* Output the actual data */
sdata((u_int8_t) ch);

if( p->delayBus ) p->hd44780_functions->uPause (p, 1);

/* then set EN high */
sctrl((enableLines|portControl) ^ OUTMASK);

if( p->delayBus ) p->hd44780_functions->uPause (p, 1);

/* Set EN low */
sctrl(portControl ^ OUTMASK);
}


/*
* Not implemented
*/
void
ppi_HD44780_backlight(PrivateData *p, unsigned char state)
{
}

/*
* Not implemented
*/
unsigned char
ppi_HD44780_scankeypad(PrivateData *p)
{
return 0;
}
Index: server/drivers/hd44780.c
===================================================================
RCS file: /cvsroot/lcdproc/lcdproc/server/drivers/hd44780.c,v
retrieving revision 1.43
diff -u -r1.43 hd44780.c
--- server/drivers/hd44780.c 26 Feb 2005 10:02:29 -0000 1.43
+++ server/drivers/hd44780.c 29 Mar 2005 06:03:20 -0000
@@ -315,6 +315,13 @@
(p->have_output?" out":"")
);
}
+ else if (strcasestr(connectionMapping[i].name, "ppi") != NULL) {
+ sprintf (buf, "PPI %s%s%s",
+ (p->have_backlight?" bl":""),
+ (p->have_keypad?" key":""),
+ (p->have_output?" out":"")
+ );
+ }
else {
sprintf (buf, "LPT 0x%x%s%s%s", p->port,
(p->have_backlight?" bl":""),



Archive powered by MHonArc 2.6.18.

Top of page