diff --git a/LCDd.conf b/LCDd.conf index 3c6d757..434e917 100644 --- a/LCDd.conf +++ b/LCDd.conf @@ -210,6 +210,10 @@ Keypad=no Backlight=no # If you have a switchable backlight. +Outputport=no +# If you have the additional output port ("bargraph") and you want to +# be able to control it with the lcdproc OUTPUT command + Size=20x4 # Specifies the size of the LCD. # In case of multiple combined displays, this should be the total size. diff --git a/server/drivers/hd44780-ext8bit.c b/server/drivers/hd44780-ext8bit.c index 06e7751..23caadb 100644 --- a/server/drivers/hd44780-ext8bit.c +++ b/server/drivers/hd44780-ext8bit.c @@ -32,8 +32,8 @@ * D3 (5) Y3 * D4 (6) Y4 * D5 (7) Y5 - * D6 (7) Y6 - * D7 (7) Y7 + * D6 (8) Y6 + * D7 (9) Y7 * nSTRB (1) Y8 * nSEL (17) Y9 * nACK (10) X0 @@ -70,11 +70,13 @@ void lcdtime_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch); void lcdtime_HD44780_backlight (PrivateData *p, unsigned char state); unsigned char lcdtime_HD44780_readkeypad (PrivateData *p, unsigned int YData); +void lcdtime_HD44780_output(PrivateData *p, int data); #define RS STRB #define RW LF #define EN1 INIT #define BL SEL +#define LE SEL static int semid; @@ -110,6 +112,8 @@ hd_init_ext8bit (Driver *drvthis) // Remember which input lines are stuck p->stuckinputs = lcdtime_HD44780_readkeypad (p, 0); } + // Writes new value to the "bargraph" latches + hd44780_functions->output = lcdtime_HD44780_output; return 0; } @@ -176,3 +180,14 @@ unsigned char lcdtime_HD44780_readkeypad (PrivateData *p, unsigned int YData) ((readval & BUSY) / BUSY <<1) | /* pin 11 */ ((readval & ACK) / ACK )) & ~p->stuckinputs; /* pin 10 */ } + +void lcdtime_HD44780_output(PrivateData *p, int data) +{ + // Setup data bus + port_out(p->port, data); + // Strobe the latch (374 latches on rising edge, 3/574 on trailing. No matter) + port_out (p->port + 2, (LE | p->backlight_bit) ^ OUTMASK); + if ( p->delayBus ) p->hd44780_functions->uPause (p, 1); + port_out (p->port + 2, (p->backlight_bit) ^ OUTMASK); + if ( p->delayBus ) p->hd44780_functions->uPause (p, 1); +} diff --git a/server/drivers/hd44780-low.h b/server/drivers/hd44780-low.h index ef626bd..0411023 100644 --- a/server/drivers/hd44780-low.h +++ b/server/drivers/hd44780-low.h @@ -81,6 +81,7 @@ typedef struct driver_private_data { char have_keypad; // off by default char have_backlight; // off by default char extIF; // off by default + char have_output; // have extra output port (off by default) int delayMult; // Delay multiplier for slow displays char delayBus; // Delay if the computer can send data too fast over // its bus to LPT port @@ -101,6 +102,8 @@ typedef struct driver_private_data { int backlight_bit; + int output_state; // what was most recently output to the output port + int ccmode; } PrivateData; @@ -132,6 +135,8 @@ typedef struct hwDependentFns { // - override scankeypad. unsigned char (*scankeypad) (PrivateData *p); + // Output "data" to output latch if there is one + void (*output) (PrivateData *p, int data); } HD44780_functions; /* for want of a better name :-) */ diff --git a/server/drivers/hd44780-winamp.c b/server/drivers/hd44780-winamp.c index 8865d86..c916cfd 100644 --- a/server/drivers/hd44780-winamp.c +++ b/server/drivers/hd44780-winamp.c @@ -32,6 +32,11 @@ * Backlight * SEL (17) backlight (optional, see documentation) * + * Additional output latch strobe + * Not part of the hd44780 itself - addl '373/4, '574 chip or similar + * (optional, see documentation (eventually)) + * nLF (14) LE + * * Keypad connection (optional): * Some diodes and resistors are needed, see further documentation. * printer port keypad @@ -41,11 +46,8 @@ * D3 (5) Y3 * D4 (6) Y4 * D5 (7) Y5 - * D6 (7) Y6 - * D7 (7) Y7 - * nLF (14) Y8 - * INIT (16) Y9 - * nSEL (17) Y10 + * D6 (8) Y6 + * D7 (9) Y7 * nACK (10) X0 * BUSY (11) X1 * PAPEREND (12) X2 @@ -76,6 +78,7 @@ void lcdwinamp_HD44780_senddata (PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch); void lcdwinamp_HD44780_backlight (PrivateData *p, unsigned char state); unsigned char lcdwinamp_HD44780_readkeypad (PrivateData *p, unsigned int YData); +void lcdwinamp_HD44780_output(PrivateData *p, int data); #define EN1 STRB #define EN2 SEL @@ -83,6 +86,7 @@ unsigned char lcdwinamp_HD44780_readkeypad (PrivateData *p, unsigned int YData); #define RW LF #define RS INIT #define BL SEL +#define LE LF static const unsigned char EnMask[] = { EN1, EN2, EN3 }; @@ -117,6 +121,9 @@ hd_init_winamp (Driver *drvthis) p->stuckinputs = lcdwinamp_HD44780_readkeypad (p, 0); } + // Write new value to output port latches + hd44780_functions->output = lcdwinamp_HD44780_output; + return 0; } @@ -183,9 +190,6 @@ unsigned char lcdwinamp_HD44780_readkeypad (PrivateData *p, unsigned int YData) // Read inputs readval = ~ port_in (p->port + 1) ^ INMASK; - // Set output back to idle state for backlight - port_out (p->port + 2, p->backlight_bit ^ OUTMASK ); - // And convert value back (MSB first). return (((readval & FAULT) / FAULT <<4) | /* pin 15 */ ((readval & SELIN) / SELIN <<3) | /* pin 13 */ @@ -193,3 +197,14 @@ unsigned char lcdwinamp_HD44780_readkeypad (PrivateData *p, unsigned int YData) ((readval & BUSY) / BUSY <<1) | /* pin 11 */ ((readval & ACK) / ACK )) & ~p->stuckinputs; /* pin 10 */ } + +void lcdwinamp_HD44780_output(PrivateData *p, int data) +{ + // Setup data bus + port_out(p->port, data); + // Strobe the latch (374 latches on rising edge, 3/574 on trailing. No matter) + port_out (p->port + 2, (LE | p->backlight_bit) ^ OUTMASK); + if ( p->delayBus ) p->hd44780_functions->uPause (p, 1); + port_out (p->port + 2, (p->backlight_bit) ^ OUTMASK); + if ( p->delayBus ) p->hd44780_functions->uPause (p, 1); +} diff --git a/server/drivers/hd44780.c b/server/drivers/hd44780.c index 7fbaba0..3f94157 100644 --- a/server/drivers/hd44780.c +++ b/server/drivers/hd44780.c @@ -9,7 +9,7 @@ * * To add support for additional HD44780 connections: * 1. Add a connection type and mapping to hd44780-drivers.h - * 2. Call your initialisation routine + * 2. Call your initialisation roUine * 3. Create the low-level driver (use hd44780-ext8bit.c as a starting point) * 4. Modify the makefile * @@ -151,6 +151,7 @@ HD44780_init (Driver * drvthis, char *args) p->extIF = drvthis->config_get_bool( drvthis->name, "extended", 0, 0 ); p->have_keypad = drvthis->config_get_bool( drvthis->name, "keypad", 0, 0 ); p->have_backlight = drvthis->config_get_bool( drvthis->name, "backlight", 0, 0 ); + p->have_output = drvthis->config_get_bool( drvthis->name, "outputport", 0, 0 ); p->delayMult = drvthis->config_get_int( drvthis->name, "delaymult", 0, 1 ); p->delayBus = drvthis->config_get_bool( drvthis->name, "delaybus", 0, 1 ); @@ -285,12 +286,16 @@ HD44780_init (Driver * drvthis, char *args) } } + // Output latch state - init to a non-valid value + p->output_state = 999999; + if ((p->hd44780_functions = (HD44780_functions *) malloc (sizeof (HD44780_functions))) == NULL) { report (RPT_ERR, "Error mallocing"); return -1; } p->hd44780_functions->uPause = uPause; p->hd44780_functions->scankeypad = HD44780_scankeypad; + p->hd44780_functions->output = NULL; // Do connection type specific display init connectionMapping[p->connectiontype_index].init_fn (drvthis); @@ -299,7 +304,11 @@ HD44780_init (Driver * drvthis, char *args) HD44780_clear (drvthis); sprintf (buf, "HD44780 %dx%d", p->width, p->height ); HD44780_string (drvthis, 1, 1, buf); - sprintf (buf, "LPT 0x%x %s %s", p->port, (p->have_backlight?"bl":""), (p->have_keypad?"key":"") ); + sprintf (buf, "LPT 0x%x%s%s%s", p->port, + (p->have_backlight?" bl":""), + (p->have_keypad?" key":""), + (p->have_output?" out":"") + ); HD44780_string (drvthis, 1, 2, buf); HD44780_flush (drvthis); sleep (2); @@ -1186,6 +1195,27 @@ unsigned char HD44780_scankeypad(PrivateData *p) } +///////////////////////////////////////////////////////////// +// Output to the optional output latch(es) +// +MODULE_EXPORT void +HD44780_output (Driver *drvthis, int on) +{ + PrivateData *p = drvthis->private_data; + + if (!p->have_output) return; /* output disabled */ + if (!p->hd44780_functions->output) return; /* unsupported for selected connectiontype */ + + // perhaps it is better just to do this every time in case of a glitch + // but leaving this in does make sure that any latch-enable line glitches + // are more easily seen + if (p->output_state == on) return; + + p->output_state = on; + p->hd44780_functions->output(p, on); +} + + ///////////////////////////////////////////////////////////// // Parse the span list // spanListArray - array to store vertical spans diff --git a/server/drivers/hd44780.h b/server/drivers/hd44780.h index 2436f22..9906f48 100644 --- a/server/drivers/hd44780.h +++ b/server/drivers/hd44780.h @@ -35,6 +35,7 @@ MODULE_EXPORT int HD44780_icon (Driver *drvthis, int x, int y, int icon); MODULE_EXPORT void HD44780_set_char (Driver *drvthis, int n, char *dat); MODULE_EXPORT void HD44780_backlight (Driver *drvthis, int on); +MODULE_EXPORT void HD44780_output (Driver *drvthis, int state); MODULE_EXPORT char * HD44780_get_key (Driver *drvthis); diff --git a/server/drivers/lpt-port.h b/server/drivers/lpt-port.h index 6ad8058..cfc64ae 100644 --- a/server/drivers/lpt-port.h +++ b/server/drivers/lpt-port.h @@ -60,6 +60,6 @@ #define INMASK 0x84 /* BUSY input and the IRQ indicator are inverted */ /* Use this mask only for the control input lines */ - /* XOR with this mask ( ^ OUTMASK ) */ + /* XOR with this mask ( ^ INMASK ) */ #endif