diff --git a/server/drivers/hd44780-4bit.c b/server/drivers/hd44780-4bit.c index f458725..d931583 100644 --- a/server/drivers/hd44780-4bit.c +++ b/server/drivers/hd44780-4bit.c @@ -117,9 +117,9 @@ hd_init_4bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver enableLines |= EN3; port_out (lptPort + 2, 0 ^ OUTMASK); } - port_out (lptPort, 0x03); if( delayBus ) hd44780_functions->uPause (1); + port_out (lptPort, enableLines | 0x03); if (extIF) port_out (lptPort + 2, ALLEXT ^ OUTMASK); @@ -148,6 +148,9 @@ hd_init_4bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver hd44780_functions->uPause (40); // now in 8-bit mode... set 4-bit mode + port_out (lptPort, 0x02); + if( delayBus ) hd44780_functions->uPause (1); + port_out (lptPort, enableLines | 0x02); if (extIF) port_out (lptPort + 2, ALLEXT ^ OUTMASK); @@ -157,6 +160,10 @@ hd_init_4bit (HD44780_functions * hd44780_functions, lcd_logical_driver * driver port_out (lptPort + 2, 0 ^ OUTMASK); hd44780_functions->uPause (40); + // Set up two-line, small character (5x8) mode + hd44780_functions->senddata (0, RS_INSTR, FUNCSET | TWOLINE | SMALLCHAR ); + hd44780_functions->uPause (40); + common_init (); if (have_keypad) { diff --git a/server/drivers/hd44780.c b/server/drivers/hd44780.c index 747fb34..5c4a86a 100644 --- a/server/drivers/hd44780.c +++ b/server/drivers/hd44780.c @@ -151,6 +151,9 @@ static char pressed_key = 0; static int pressed_key_repetitions = 0; static struct timeval pressed_key_time; +// for incremental updates store last lcd contents +static char * lcd_contents = (char *) 0; + // function declarations void HD44780_close (); void HD44780_flush (); @@ -272,6 +275,15 @@ HD44780_init (lcd_logical_driver * driver, char *args) //HD44780_close(); return -1; } + + // Allocate and clear the buffer for incremental updates + lcd_contents = (unsigned char *) malloc (HD44780->wid * HD44780->hgt); + if (!lcd_contents) { + return -1; + } + memset(lcd_contents, ' ', HD44780->wid * HD44780->hgt); + + // Set the functions the driver supports... // These are the default HD44780 functions driver->init = HD44780_init; @@ -384,6 +396,8 @@ uPause (int usecs) // void HD44780_close() { + free( HD44780->framebuf ); + free( lcd_contents ); } ///////////////////////////////////////////////////////////////// @@ -813,21 +827,30 @@ void HD44780_draw_frame (char *dat) { int x, y; + int wid = HD44780->wid; + char drawing; if (!dat) return; - for (y = 0; y < HD44780->hgt; y++) { - //printf("\n%d :",y); - for (x = 0; x < HD44780->wid; x++) { - - if( x % 8 == 0 ) - HD44780_position (x, y); - hd44780_functions->senddata (spanList[y], RS_DATA, HD44780_charmap[(unsigned char)dat[(y * HD44780->wid) + x]]); - hd44780_functions->uPause (40); // Minimum exec time for all commands + // Update LCD incrementally by comparing with last contents + for (y=0; yhgt; y++) { + drawing = 0; + for (x=0 ; xsenddata( spanList[y], RS_DATA, HD44780_charmap[(unsigned char)dat[(y * wid) + x]]); + hd44780_functions->uPause (40); // Minimum exec time for all commands + lcd_contents[(y*wid)+x] = dat[(y*wid)+x]; + } + else { + drawing = 0; + } } } - } /////////////////////////////////////////////////////////////