From 7e478dc7dadf34c884899dc993e6ca04ca4cce3f Mon Sep 17 00:00:00 2001 From: robijn Date: Sun, 26 May 2002 19:22:50 +0000 Subject: [PATCH] HD44780 update: reporting fixed, serialLpt behaviour improved. --- server/drivers/hd44780-serialLpt.c | 53 ++++++++++++++++++++---------- server/drivers/hd44780.c | 16 ++++----- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/server/drivers/hd44780-serialLpt.c b/server/drivers/hd44780-serialLpt.c index 96044fb..d3792f0 100644 --- a/server/drivers/hd44780-serialLpt.c +++ b/server/drivers/hd44780-serialLpt.c @@ -161,10 +161,18 @@ unsigned char lcdserLpt_HD44780_scankeypad (PrivateData *p) unsigned int scancode = 0; // While scanning the keypad, the 2-wire version will place the - // character 0xFF on the current cursor position. Therefor we fisrt - // set the cursor position to -1, so it's harmless. + // character 0xFF on the current cursor position. Therefor we first + // set the cursor position to home, do the keypad reading and + // afterwards restore the first character (on all connected displays). + // // I could not prevent this, while staying compatible with both - // wiring versions. + // wiring versions. Joris. + // + // (Positioning the cursor out of screen does not work either :( ) + + // Set cursor position + p->hd44780_functions->senddata (p, 0, RS_INSTR, POSITION | 0 ); + p->hd44780_functions->uPause (p, 40); // Clear the shiftregister, needed for 3-wire version rawshift(p, 0); @@ -173,11 +181,11 @@ unsigned char lcdserLpt_HD44780_scankeypad (PrivateData *p) readval = ~ port_in (p->port + 1) ^ INMASK; // And convert value back (MSB first). - inputs_zero = (((readval & FAULT) / FAULT <<4) | /* pin 15 */ - ((readval & SELIN) / SELIN <<3) | /* pin 13 */ - ((readval & PAPEREND) / PAPEREND <<2) | /* pin 12 */ - ((readval & BUSY) / BUSY <<1) | /* pin 11 */ - ((readval & ACK) / ACK )); /* pin 10 */ + inputs_zero = (((readval & FAULT) / FAULT <<4) | /* pin 15 */ + ((readval & SELIN) / SELIN <<3) | /* pin 13 */ + ((readval & PAPEREND) / PAPEREND <<2) | /* pin 12 */ + ((readval & BUSY) / BUSY <<1) | /* pin 11 */ + ((readval & ACK) / ACK )); /* pin 10 */ if( inputs_zero == 0 ) { @@ -188,16 +196,12 @@ unsigned char lcdserLpt_HD44780_scankeypad (PrivateData *p) return 0; } - // Set cursor position to -1 - p->hd44780_functions->senddata (p, 0, RS_INSTR, POSITION | 127); - p->hd44780_functions->uPause (p, 40); - // Scan the keypad while sending the first half of the command (high nibble) for (i = 7; i >= 0; i--) { /* MSB first */ port_out (p->port, LCDDATA); /*set up data */ port_out (p->port, LCDDATA | LCDCLOCK); /*rising edge of clock */ - p->hd44780_functions->uPause (p, 2); + p->hd44780_functions->uPause (p, 1); if( !scancode ) { // Read input line(s) @@ -230,11 +234,26 @@ unsigned char lcdserLpt_HD44780_scankeypad (PrivateData *p) // Needed for 2-wire version. rawshift (p, 0xFF); - // Wait for 2-wire version to clear the latch... - p->hd44780_functions->uPause (p, 6); + // Wait 6us for 2-wire version to clear the latch and wait for + // the data to be processed + p->hd44780_functions->uPause (p, 40); - // Restore line status for backlight. - port_out (p->port, p->backlight_bit ); + // Restore the screen state + // Move back to home cursor position + p->hd44780_functions->senddata (p, 0, RS_INSTR, POSITION | 0 ); + p->hd44780_functions->uPause (p, 40); + + // Output the corect byte + p->hd44780_functions->senddata (p, 1, RS_DATA, + p->framebuf[0] ); + // ... and second display if connected ... + if (p->numDisplays>1) { + p->hd44780_functions->senddata (p, 2, RS_DATA, + p->framebuf[ p->width * p->dispVOffset[2-1] ] ); + } + p->hd44780_functions->uPause (p, 40); + + // No need to restore the line for backlight, already done by senddata. return scancode; } diff --git a/server/drivers/hd44780.c b/server/drivers/hd44780.c index 13cd147..7fbaba0 100644 --- a/server/drivers/hd44780.c +++ b/server/drivers/hd44780.c @@ -158,7 +158,7 @@ HD44780_init (Driver * drvthis, char *args) s = drvthis->config_get_string( drvthis->name, "connectiontype", 0, "4bit" ); for (i = 0; connectionMapping[i].name != NULL && strcmp (s, connectionMapping[i].name) != 0; i++); if (connectionMapping[i].name == NULL) { - fprintf (stderr, "HD44780_init: Unknown connection type: %s\n", s); + report (RPT_ERR, "HD44780_init: Unknown connection type: %s", s); return -1; // fatal error } else { p->connectiontype_index = i; @@ -168,7 +168,7 @@ HD44780_init (Driver * drvthis, char *args) s = drvthis->config_get_string( drvthis->name, "vspan", 0, "" ); if( s[0] != 0 ) { if (parse_span_list (&(p->spanList), &(p->numLines), &(p->dispVOffset), &(p->numDisplays), &(p->dispSizes), s) == -1) { - fprintf (stderr, "HD44780_init: invalid vspan value: %s\n", s ); + report (RPT_ERR, "HD44780_init: invalid vspan value: %s", s ); return -1; } } @@ -178,7 +178,7 @@ HD44780_init (Driver * drvthis, char *args) if( sscanf( s, "%dx%d", &(p->width), &(p->height) ) != 2 || (p->width <= 0) || (p->width > LCD_MAX_WIDTH) || (p->height <= 0) || (p->height > LCD_MAX_HEIGHT)) { - fprintf( stderr, "HD44780_init: Cannot read size: %s\n", s ); + report (RPT_ERR, "HD44780_init: Cannot read size: %s", s ); } // default case for when spans aren't indicated @@ -191,7 +191,7 @@ HD44780_init (Driver * drvthis, char *args) p->numLines = p->height; } } else - fprintf (stderr, "Error mallocing for span list\n"); + report (RPT_ERR, "Error mallocing"); } if (p->numDisplays == 0) { if ((p->dispVOffset = (int *) malloc (sizeof (int))) && (p->dispSizes = (int *) malloc (sizeof (int)))) { @@ -199,7 +199,7 @@ HD44780_init (Driver * drvthis, char *args) p->dispSizes[0] = p->height; p->numDisplays = 1; } else - fprintf (stderr, "Error mallocing for display sizes list\n"); + report (RPT_ERR, "Error mallocing"); } if (timing_init() == -1) @@ -212,7 +212,7 @@ HD44780_init (Driver * drvthis, char *args) struct sched_param param; param.sched_priority=1; if (( sched_setscheduler(0, SCHED_RR, ¶m)) == -1) { - fprintf (stderr, "HD44780_init: failed (%s)\n", strerror (errno)); + report (RPT_ERR, "HD44780_init: failed (%s)", strerror (errno)); return -1; } } @@ -286,7 +286,7 @@ HD44780_init (Driver * drvthis, char *args) } if ((p->hd44780_functions = (HD44780_functions *) malloc (sizeof (HD44780_functions))) == NULL) { - fprintf (stderr, "Error mallocing for function struct"); + report (RPT_ERR, "Error mallocing"); return -1; } p->hd44780_functions->uPause = uPause; @@ -1227,11 +1227,9 @@ parse_span_list (int *spanListArray[], int *spLsize, int *dispOffsets[], int *dO // find the next number (\0 is also outside this range) for (++j; spanlist[j] < '1' || spanlist[j] > '9'; ++j); } else { - fprintf (stderr, "Error reallocing for span list\n"); retVal = -1; } } else { - fprintf (stderr, "Error reading spansize\n"); retVal = -1; } }