From 3a3a4dc8d9e0dad2c3c72c32f46819de0d3a439d Mon Sep 17 00:00:00 2001 From: marschap Date: Sat, 3 Nov 2007 20:55:49 +0000 Subject: [PATCH] afew doc cleanups, and cleanups /more checks ofr the hd44780 driver --- docs/lcdproc-user/drivers/hd44780.docbook | 15 +++--- docs/lcdproc-user/drivers/lis.docbook | 8 +-- server/drivers/hd44780-charmap.h | 4 +- server/drivers/hd44780-ftdi.c | 6 +-- server/drivers/hd44780-low.h | 2 +- server/drivers/hd44780.c | 64 ++++++++++++++--------- 6 files changed, 57 insertions(+), 42 deletions(-) diff --git a/docs/lcdproc-user/drivers/hd44780.docbook b/docs/lcdproc-user/drivers/hd44780.docbook index 3685a91..686dd08 100644 --- a/docs/lcdproc-user/drivers/hd44780.docbook +++ b/docs/lcdproc-user/drivers/hd44780.docbook @@ -1693,7 +1693,7 @@ and drives both channels as outputs to control the display in 8bit mode. BDBUS2 38 - E + EN 6 @@ -2586,8 +2586,9 @@ This can be done by specifying or by inclu SECONDS - Some displays (e.g. vdr-wakeup) need a message from the driver to that it - is still alive. When set to a value bigger then 0 the character in the + Some displays (e.g. vdr-wakeup) need a message from the driver to + indicate that it is still alive. + When set to a value greater than 0 the character in the upper left corner is updated every SECONDS seconds. The default 0 does not cause any extra updates. @@ -2600,8 +2601,8 @@ This can be done by specifying or by inclu If you experience occasional garbage on your display you can use this - option as workaround. If set to a value bigger than 0 it forces a - full screen refresh SECONDS seconds. + option as workaround. If set to a value greater than 0 it forces a + full screen refresh every SECONDS seconds. Default: 0. @@ -2637,7 +2638,7 @@ This can be done by specifying or by inclu VENDORID - USB vendor ID to look for a FTDI chip. + USB vendor ID to look for a FTDI chip with ConnectionType=ftdi. Default: 0x4003. @@ -2648,7 +2649,7 @@ This can be done by specifying or by inclu PRODUCTID - USB product ID to look for a FTDI chip. + USB product ID to look for a FTDI chip with ConnectionType=ftdi. Default: 0x6001. diff --git a/docs/lcdproc-user/drivers/lis.docbook b/docs/lcdproc-user/drivers/lis.docbook index 2c36a42..e37aa26 100644 --- a/docs/lcdproc-user/drivers/lis.docbook +++ b/docs/lcdproc-user/drivers/lis.docbook @@ -16,8 +16,8 @@ This device uses a vacuum flourescent display of 20 characters by 2 lines. Each each character is 5 pixels wide by 8 pixels high. The device is connected by USB. The FTDI chip -translates the USB protocol to serial expected by the VFD driver chip, an NEC UPD16314. A -programmable interrupt controller (PIC), the PIC16F716 by Microchip, provides the glue +translates the USB protocol to serial expected by the VFD driver chip, an NEC UPD16314. +A programmable interrupt controller (PIC), the PIC16F716 by Microchip, provides the glue between the FTDI and the NEC chips. @@ -78,7 +78,7 @@ can be done by specifying "--enable-drivers=all" or by The USB Vendor ID of the device to use. If not given, it defaults to 0x0403 for a VLSystems L.I.S. MCE 2005 VFD - based on a FT232BL USB-to-RS232 converter by FTDIi, which was produced + based on a FT232BL USB-to-RS232 converter by FTDI, which was produced before March 2007. @@ -98,7 +98,7 @@ can be done by specifying "--enable-drivers=all" or by The USB Product ID of the device to use. If not given, it defaults to 0x6001 for a VLSystems L.I.S. MCE 2005 VFD - based on a FT232BL USB-to-RS232 converter by FTDIi, which was produced + based on a FT232BL USB-to-RS232 converter by FTDI, which was produced before March 2007. diff --git a/server/drivers/hd44780-charmap.h b/server/drivers/hd44780-charmap.h index 1ecc680..e0f2163 100644 --- a/server/drivers/hd44780-charmap.h +++ b/server/drivers/hd44780-charmap.h @@ -406,10 +406,10 @@ const unsigned char SED1278F_0B_charmap[] = { /* 255 ( 'ÿ' ) */ 253 }; -#define MAX_CHARMAP_NAME_LENGHT 16 +#define MAX_CHARMAP_NAME_LENGTH 16 struct charmap { - char name[MAX_CHARMAP_NAME_LENGHT]; + char name[MAX_CHARMAP_NAME_LENGTH]; const unsigned char *charmap; }; diff --git a/server/drivers/hd44780-ftdi.c b/server/drivers/hd44780-ftdi.c index 378e5a6..d466b4c 100644 --- a/server/drivers/hd44780-ftdi.c +++ b/server/drivers/hd44780-ftdi.c @@ -48,7 +48,7 @@ hd_init_ftdi(Driver *drvthis) p->ftdi_line_RS = drvthis->config_get_int(drvthis->name, "ftdi_line_RS", 0, 0x01); p->ftdi_line_RW = drvthis->config_get_int(drvthis->name, "ftdi_line_RW", 0, 0x02); - p->ftdi_line_E = drvthis->config_get_int(drvthis->name, "ftdi_line_E", 0, 0x04); + p->ftdi_line_EN = drvthis->config_get_int(drvthis->name, "ftdi_line_EN", 0, 0x04); p->ftdi_line_backlight = drvthis->config_get_int(drvthis->name, "ftdi_line_backlight", 0, 0x08); // Init 1. channel: data @@ -97,8 +97,8 @@ ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char fla exit (-1); } - // Setup RS and R/W and E - ch = p->ftdi_line_E | p->backlight_bit; + // Setup RS and R/W and EN + ch = p->ftdi_line_EN | p->backlight_bit; if (flags == RS_DATA) { ch |= p->ftdi_line_RS; } diff --git a/server/drivers/hd44780-low.h b/server/drivers/hd44780-low.h index fe97c3f..cf37df1 100644 --- a/server/drivers/hd44780-low.h +++ b/server/drivers/hd44780-low.h @@ -113,7 +113,7 @@ typedef struct driver_private_data { int ftdi_line_RS; int ftdi_line_RW; - int ftdi_line_E; + int ftdi_line_EN; int ftdi_line_backlight; #endif diff --git a/server/drivers/hd44780.c b/server/drivers/hd44780.c index 2856022..6294477 100644 --- a/server/drivers/hd44780.c +++ b/server/drivers/hd44780.c @@ -338,12 +338,12 @@ HD44780_init(Driver *drvthis) } // Get configured charmap - char conf_charmap[MAX_CHARMAP_NAME_LENGHT]; + char conf_charmap[MAX_CHARMAP_NAME_LENGTH]; - strncpy(conf_charmap, drvthis->config_get_string(drvthis->name, "charmap", 0, "hd44780_default"), MAX_CHARMAP_NAME_LENGHT); - conf_charmap[MAX_CHARMAP_NAME_LENGHT-1]='\0'; - p->charmap=0; - for (i=0; i<(sizeof(available_charmaps)/sizeof(struct charmap)); i++) { + strncpy(conf_charmap, drvthis->config_get_string(drvthis->name, "charmap", 0, "hd44780_default"), MAX_CHARMAP_NAME_LENGTH); + conf_charmap[MAX_CHARMAP_NAME_LENGTH-1] = '\0'; + p->charmap = 0; + for (i = 0; i < (sizeof(available_charmaps)/sizeof(struct charmap)); i++) { if (strcasecmp(conf_charmap, available_charmaps[i].name) == 0) { p->charmap=i; break; @@ -384,6 +384,17 @@ HD44780_init(Driver *drvthis) if (init_fn(drvthis) != 0) return -1; + // consistency check: local keypad functions missing => no keypad + if ((p->hd44780_functions->readkeypad == NULL) && + (p->hd44780_functions->scankeypad == HD44780_scankeypad)) { + p->hd44780_functions->scankeypad = NULL; + p->have_keypad = 0; + } + + // consistency check: no local output function => no output + if (p->hd44780_functions->output == NULL) + p->have_output = 0; + // fail if local senddata function was not defined if (p->hd44780_functions->senddata == NULL) { report(RPT_ERR, "%s: incomplete functions for connection type"); @@ -596,34 +607,32 @@ HD44780_flush(Driver *drvthis) PrivateData *p = (PrivateData *) drvthis->private_data; int x, y; int wid = p->width; - char ch; - char drawing; - int row; int i; int count; char refreshNow = 0; char keepaliveNow = 0; + time_t now = time(NULL); // force full refresh of display - if ((p->refreshdisplay > 0) && (time(NULL) > p->nextrefresh)) - { + if ((p->refreshdisplay > 0) && (now > p->nextrefresh)) { refreshNow = 1; - p->nextrefresh = time(NULL) + p->refreshdisplay; + p->nextrefresh = now + p->refreshdisplay; } // keepalive refresh of display - if ((p->keepalivedisplay > 0) && (time(NULL) > p->nextkeepalive)) - { + if ((p->keepalivedisplay > 0) && (now > p->nextkeepalive)) { keepaliveNow = 1; - p->nextkeepalive = time(NULL) + p->keepalivedisplay; + p->nextkeepalive = now + p->keepalivedisplay; } // Update LCD incrementally by comparing with last contents count = 0; for (y = 0; y < p->height; y++) { - drawing = 0; + int drawing = 0; + for (x = 0 ; x < wid; x++) { - ch = p->framebuf[(y * wid) + x]; + char ch = p->framebuf[(y * wid) + x]; + if (refreshNow || (x + y == 0 && keepaliveNow) || ch != p->lcd_contents[(y*wid)+x]) { if (!drawing || x % 8 == 0) { // x%8 is for 16x1 displays ! drawing = 1; @@ -645,6 +654,7 @@ HD44780_flush(Driver *drvthis) count = 0; for (i = 0; i < NUM_CCs; i++) { if (!p->cc[i].clean) { + int row; /* Tell the HD44780 we will redefine char number i */ p->hd44780_functions->senddata(p, 0, RS_INSTR, SETCHAR | i * 8); @@ -1133,21 +1143,21 @@ HD44780_get_key(Driver *drvthis) { PrivateData *p = (PrivateData *) drvthis->private_data; unsigned char scancode; - char * keystr = NULL; + char *keystr = NULL; struct timeval curr_time, time_diff; - if (!p->have_keypad) return NULL; + // return "no key pressed" if required functions mission or input disabled + if ((!p->have_keypad) || (p->hd44780_functions->scankeypad == NULL)) + return NULL; gettimeofday(&curr_time, NULL); scancode = p->hd44780_functions->scankeypad(p); - if (scancode) { - if (scancode & 0xF0) { - keystr = p->keyMapMatrix[((scancode&0xF0)>>4)-1][(scancode&0x0F)-1]; - } - else { - keystr = p->keyMapDirect[scancode - 1]; - } + if (scancode != '\0') { + // TODO: check if arrays are large enough + keystr = (scancode & 0xF0) + ? p->keyMapMatrix[((scancode&0xF0)>>4)-1][(scancode&0x0F)-1] + : p->keyMapDirect[scancode - 1]; } if (keystr != NULL) { @@ -1191,6 +1201,10 @@ unsigned char HD44780_scankeypad(PrivateData *p) unsigned char scancode = 0; + // return "no ke pressed if no keypad reading function defined + if (p->hd44780_functions->readkeypad == NULL) + return('\0'); + // First check if a directly connected key is pressed // Put all zeros on Y of keypad keybits = p->hd44780_functions->readkeypad(p, 0);