harmonize coding style and messagesi; add a few checks

This commit is contained in:
marschap
2006-04-08 19:36:55 +00:00
parent c7569db6ce
commit 8cdb3fef07
+220 -179
View File
@@ -133,7 +133,7 @@
* | | * | |
* '-' * '-'
* | * |
* O Vlc (= -24V ) * O Vlc (= -24V)
* *
* The G242C generates -24V internally. It is available on Vlc. * The G242C generates -24V internally. It is available on Vlc.
* *
@@ -251,11 +251,10 @@
typedef struct p { typedef struct p {
int type; int type;
int port; int port;
char * keymap[KEYPAD_MAXX]; unsigned char * framebuf_text;
char * framebuf_text; unsigned char * lcd_contents_text;
char * lcd_contents_text; unsigned char * framebuf_graph;
char * framebuf_graph; unsigned char * lcd_contents_graph;
char * lcd_contents_graph;
int width, height; int width, height;
int cellwidth, cellheight; int cellwidth, cellheight;
int graph_width, graph_height; int graph_width, graph_height;
@@ -319,111 +318,115 @@ sed1330_init( Driver * drvthis )
PrivateData * p; PrivateData * p;
char data[8]; char data[8];
debug( RPT_DEBUG, "%s( %p )", __FUNCTION__, drvthis ); debug(RPT_DEBUG, "%s( %p )", __FUNCTION__, drvthis);
// Alocate and store private p // Alocate and store private p
p = (PrivateData *) malloc( sizeof(PrivateData) ); p = (PrivateData *) calloc(1, sizeof(PrivateData));
if( ! p ) if (p == NULL)
return -1; return -1;
if( drvthis->store_private_ptr( drvthis, p ) ) if (drvthis->store_private_ptr(drvthis, p))
return -1; return -1;
// Clear keymap // initialize PrivateData
memset( p->keymap, 0, sizeof(p->keymap) ); p->framebuf_text = NULL;
p->lcd_contents_text = NULL;
p->framebuf_graph = NULL;
p->lcd_contents_graph = NULL;
// READ THE CONFIG FILE // READ THE CONFIG FILE
// Port // Port
p->port = drvthis->config_get_int( drvthis->name, "port", 0, 0x278 ); p->port = drvthis->config_get_int(drvthis->name, "Port", 0, 0x278);
// Char size // Char size
s = drvthis->config_get_string( drvthis->name, "cellsize", 0, NULL ); s = drvthis->config_get_string(drvthis->name, "CellSize", 0, "6x10");
if( !s ) { if (sscanf(s, "%dx%d", &(p->cellwidth), &(p->cellheight)) != 2) {
s = "6x10"; report(RPT_ERR, "%s: cannot interpret CellSize %s",
} drvthis->name, s);
if( sscanf( s, "%dx%d", &(p->cellwidth), &(p->cellheight)) != 2 ) {
report( RPT_ERR, "SED1330: cannot interpret cellsize value: %s", s );
return -1; return -1;
} }
if( p->cellwidth < 6 || p->cellwidth > 8 if ((p->cellwidth < 6) || (p->cellwidth > 8)
|| p->cellheight < 7 || p->cellheight > 16 ) { || (p->cellheight < 7) || (p->cellheight > 16)) {
report( RPT_ERR, "SED1330: cellsize exceeds allowed range of 6x7 to 8x16" ); report(RPT_ERR, "%s: CellSize exceeds allowed range of 6x7 to 8x16",
drvthis->name);
return -1; return -1;
} }
// Type // Type
s = drvthis->config_get_string( drvthis->name, "type", 0, NULL ); s = drvthis->config_get_string(drvthis->name, "Type", 0, NULL);
if( !s ) { if (s == NULL) {
report( RPT_ERR, "SED1330: you need to specify the display type" ); report(RPT_ERR, "%s: you need to specify the display type",
drvthis->name);
return -1; return -1;
} else if( strcmp( s, "G321D" ) == 0 ) { } else if (strcmp(s, "G321D") == 0) {
p->type = TYPE_G321D; p->type = TYPE_G321D;
p->graph_width = 320; p->graph_width = 320;
p->graph_height = 200; p->graph_height = 200;
} else if( strcmp( s, "G121C" ) == 0 ) { } else if (strcmp(s, "G121C") == 0) {
p->type = TYPE_G121C; p->type = TYPE_G121C;
p->graph_width = 128; p->graph_width = 128;
p->graph_height = 128; p->graph_height = 128;
} else if( strcmp( s, "G242C" ) == 0 ) { } else if (strcmp(s, "G242C") == 0) {
p->type = TYPE_G242C; p->type = TYPE_G242C;
p->graph_width = 240; p->graph_width = 240;
p->graph_height = 128; p->graph_height = 128;
} else if( strcmp( s, "G191D" ) == 0 ) { } else if (strcmp(s, "G191D") == 0) {
p->type = TYPE_G191D; p->type = TYPE_G191D;
p->graph_width = 192; p->graph_width = 192;
p->graph_height = 192; p->graph_height = 192;
} else if( strcmp( s, "G2446" ) == 0 ) { } else if (strcmp(s, "G2446") == 0) {
p->type = TYPE_G2446; p->type = TYPE_G2446;
p->graph_width = 240; p->graph_width = 240;
p->graph_height = 64; p->graph_height = 64;
} else { } else {
report( RPT_ERR, "SED1330: Unknown display type: %s", s ); report(RPT_ERR, "%s: Unknown display type %s", drvthis->name, s);
return -1; return -1;
} }
report( RPT_INFO, "SED1330: Using LCD type: %s", s ); report(RPT_INFO, "%s: Using LCD type %s", drvthis->name, s);
// Keypad ? // Keypad ?
p->have_keypad = drvthis->config_get_bool( drvthis->name, "keypad", 0, 0 ); p->have_keypad = drvthis->config_get_bool(drvthis->name, "keypad", 0, 0);
// Keymap // Keymap
if ( p->have_keypad ) { if (p->have_keypad) {
int x, y; int x, y;
// Read keymap // Read keymap
for( x=0; x<KEYPAD_MAXX; x++ ) { for (x = 0; x < KEYPAD_MAXX; x++) {
char buf[40]; char buf[40];
// First fill with default value // First fill with default value
p->keyMapDirect[x] = defaultKeyMapDirect[x]; p->keyMapDirect[x] = defaultKeyMapDirect[x];
// Read config value // Read config value
sprintf( buf, "keydirect_%1d", x+1 ); sprintf(buf, "keydirect_%1d", x+1);
s = drvthis->config_get_string( drvthis->name, buf, 0, NULL ); s = drvthis->config_get_string(drvthis->name, buf, 0, NULL);
// Was a key specified in the config file ? // Was a key specified in the config file ?
if( s ) { if (s != NULL) {
p->keyMapDirect[x] = strdup( s ); p->keyMapDirect[x] = strdup(s);
report( RPT_INFO, "SED1330: Direct key %d: \"%s\"", x, s ); report(RPT_INFO, "%s: Direct key %d: \"%s\"",
drvthis->name, x, s );
} }
} }
for( x=0; x<KEYPAD_MAXX; x++ ) { for (x = 0; x < KEYPAD_MAXX; x++) {
for( y=0; y<KEYPAD_MAXY; y++ ) { for (y = 0; y < KEYPAD_MAXY; y++) {
char buf[40]; char buf[40];
// First fill with default value // First fill with default value
p->keyMapMatrix[y][x] = defaultKeyMapMatrix[y][x]; p->keyMapMatrix[y][x] = defaultKeyMapMatrix[y][x];
// Read config value // Read config value
sprintf( buf, "keymatrix_%1d_%d", x+1, y+1 ); sprintf(buf, "keymatrix_%1d_%d", x+1, y+1);
s = drvthis->config_get_string( drvthis->name, buf, 0, NULL ); s = drvthis->config_get_string(drvthis->name, buf, 0, NULL);
// Was a key specified in the config file ? // Was a key specified in the config file ?
if( s ) { if (s != NULL) {
p->keyMapMatrix[y][x] = strdup( s ); p->keyMapMatrix[y][x] = strdup(s);
report( RPT_INFO, "SED1330: Matrix key %d,%d: \"%s\"", x, y, s ); report(RPT_INFO, "%s: Matrix key %d,%d: \"%s\"",
drvthis->name, x, y, s);
} }
} }
} }
@@ -432,57 +435,66 @@ sed1330_init( Driver * drvthis )
// Calculate some sizes // Calculate some sizes
p->width = p->graph_width / p->cellwidth; p->width = p->graph_width / p->cellwidth;
p->height = p->graph_height / p->cellheight; p->height = p->graph_height / p->cellheight;
p->bytesperline = (p->graph_width - 1 ) / p->cellwidth + 1; p->bytesperline = (p->graph_width - 1) / p->cellwidth + 1;
p->textlines_in_memory = (p->graph_height - 1 ) / p->cellheight + 1; p->textlines_in_memory = (p->graph_height - 1) / p->cellheight + 1;
report( RPT_INFO, "SED1330: Text size: %dx%d", p->width, p->height ); report(RPT_INFO, "%s: Text size: %dx%d", drvthis->name, p->width, p->height);
report( RPT_INFO, "SED1330: Cell size: %dx%d", p->cellwidth, p->cellheight ); report(RPT_INFO, "%s: Cell size: %dx%d", drvthis->name, p->cellwidth, p->cellheight);
report( RPT_INFO, "SED1330: Graphical size: %dx%d", p->graph_width, p->graph_height ); report(RPT_INFO, "%s: Graphical size: %dx%d", drvthis->name, p->graph_width, p->graph_height);
// Allocate framebuffer // Allocate framebuffer
p->framebuf_text = (unsigned char *) malloc( p->bytesperline * p->textlines_in_memory ); p->framebuf_text = (unsigned char *) malloc(p->bytesperline * p->textlines_in_memory);
if( ! p->framebuf_text ) if (p->framebuf_text == NULL) {
report(RPT_ERR, "%s: error allocating text framebuffer", drvthis->name);
return -1; return -1;
memset( p->framebuf_text, ' ', p->bytesperline * p->textlines_in_memory ); }
memset(p->framebuf_text, ' ', p->bytesperline * p->textlines_in_memory);
p->lcd_contents_text = (unsigned char *) malloc( p->bytesperline * p->textlines_in_memory ); p->lcd_contents_text = (unsigned char *) malloc(p->bytesperline * p->textlines_in_memory);
if( ! p->lcd_contents_text ) if (p->lcd_contents_text == NULL) {
report(RPT_ERR, "%s: error allocating lcd_contents_text", drvthis->name);
return -1; return -1;
memset( p->lcd_contents_text, 0, p->bytesperline * p->textlines_in_memory ); }
memset(p->lcd_contents_text, 0, p->bytesperline * p->textlines_in_memory);
p->framebuf_graph = (unsigned char *) malloc( p->bytesperline * p->graph_height ); p->framebuf_graph = (unsigned char *) malloc(p->bytesperline * p->graph_height);
if( ! p->framebuf_graph ) if (p->framebuf_graph == NULL) {
report(RPT_ERR, "%s: error allocating graphical framebuffer", drvthis->name);
return -1; return -1;
memset( p->framebuf_graph, 0, p->bytesperline * p->graph_height ); }
memset(p->framebuf_graph, 0, p->bytesperline * p->graph_height);
p->lcd_contents_graph = (unsigned char *) malloc( p->bytesperline * p->graph_height ); p->lcd_contents_graph = (unsigned char *) malloc(p->bytesperline * p->graph_height);
if( ! p->lcd_contents_graph ) if (p->lcd_contents_graph == NULL) {
report(RPT_ERR, "%s: error allocating lcd_contents_graph", drvthis->name);
return -1; return -1;
memset( p->lcd_contents_graph, 0xFF, p->bytesperline * p->graph_height ); }
memset(p->lcd_contents_graph, 0xFF, p->bytesperline * p->graph_height);
// Arrange for access to port // Arrange for access to port
debug( RPT_DEBUG, "%s: getting port access", __FUNCTION__ ); debug(RPT_DEBUG, "%s: getting port access", __FUNCTION__);
port_access(p->port); port_access(p->port);
port_access(p->port+1); port_access(p->port+1);
port_access(p->port+2); port_access(p->port+2);
if (timing_init() == -1) { if (timing_init() == -1) {
report(RPT_ERR, "timing_init: failed (%s)\n", strerror(errno)); report(RPT_ERR, "%s: timing_init() failed (%s)",
drvthis->name, strerror(errno));
return -1; return -1;
} }
// INITIALIZE THE LCD // INITIALIZE THE LCD
// End reset-state // End reset-state
debug( RPT_DEBUG, "%s: initializing LCD", __FUNCTION__ ); debug(RPT_DEBUG, "%s: initializing LCD", __FUNCTION__);
port_out( p->port+2, (nWR) ^ OUTMASK ); // raise ^RD and ^WR port_out(p->port+2, (nWR) ^ OUTMASK); // raise ^RD and ^WR
port_out( p->port+2, (nRESET|nWR) ^ OUTMASK ); // lower RESET port_out(p->port+2, (nRESET|nWR) ^ OUTMASK); // lower RESET
uPause( 200 ); uPause(200);
port_out( p->port+2, (nWR) ^ OUTMASK ); // raise RESET port_out(p->port+2, (nWR) ^ OUTMASK); // raise RESET
uPause( 200 ); uPause(200);
port_out( p->port+2, (nRESET|nWR) ^ OUTMASK ); // lower RESET port_out(p->port+2, (nRESET|nWR) ^ OUTMASK); // lower RESET
uPause( 4000 ); uPause(4000);
switch( p->type ) { switch (p->type) {
case TYPE_G321D: case TYPE_G321D:
data[4] = 0x38; data[4] = 0x38;
break; break;
@@ -511,22 +523,24 @@ sed1330_init( Driver * drvthis )
data[5] = p->graph_height - 1; data[5] = p->graph_height - 1;
data[6] = p->bytesperline; data[6] = p->bytesperline;
data[7] = 0; data[7] = 0;
sed1330_command( p, CMD_SYSTEM_SET, 8, data ); sed1330_command(p, CMD_SYSTEM_SET, 8, data);
// TODO: The memory locations need to be calculated ! // TODO: The memory locations need to be calculated !
sed1330_command( p, CMD_SCROLL, 6, ((char[6]) {SCR1_L,SCR1_H,0xC7,SCR2_L,SCR2_H,0xC7}) ); // screen1 and screen2 memory locations sed1330_command(p, CMD_SCROLL, 6, ((char[6]) {SCR1_L,SCR1_H,0xC7,SCR2_L,SCR2_H,0xC7})); // screen1 and screen2 memory locations
data[0] = p->cellwidth-1; data[0] = p->cellwidth-1;
data[1] = 7; data[1] = 7;
sed1330_command( p, CMD_CSR_FORM, 2, data ); // set cursor size sed1330_command(p, CMD_CSR_FORM, 2, data); // set cursor size
sed1330_command( p, CMD_HDOT_SCR, 1, ((char[1]) {0x00}) ); // horizontal pixel shift=0 sed1330_command(p, CMD_HDOT_SCR, 1, ((char[1]) {0x00})); // horizontal pixel shift=0
sed1330_command( p, CMD_OVLAY, 1, ((char[1]) {0x01}) ); // XOR mode, screen1 text, screen3 text (screen2 and screen4 are always graph) sed1330_command(p, CMD_OVLAY, 1, ((char[1]) {0x01})); // XOR mode, screen1 text, screen3 text (screen2 and screen4 are always graph)
sed1330_command( p, CMD_DISP_DIS, 1, ((char[1]) {0x14}) ); // display off,set cursor off, screen1 on, screen2 on, screen3 off sed1330_command(p, CMD_DISP_DIS, 1, ((char[1]) {0x14})); // display off,set cursor off, screen1 on, screen2 on, screen3 off
sed1330_command( p, CMD_CSR_DIR_R, 0, NULL ); // cursor move right sed1330_command(p, CMD_CSR_DIR_R, 0, NULL); // cursor move right
sed1330_flush( drvthis ); // Clear the contents of the LCD sed1330_flush(drvthis); // Clear the contents of the LCD
sed1330_command( p, CMD_DISP_EN, 0, NULL ); // And display on sed1330_command(p, CMD_DISP_EN, 0, NULL); // And display on
report(RPT_DEBUG, "%s: init() done", drvthis->name);
return 0; return 0;
} }
@@ -542,16 +556,16 @@ sed1330_command( PrivateData * p, char command, int datacount, char * data )
int i; int i;
int port = p->port; int port = p->port;
port_out( port+2, (nRESET|nWR|A0) ^ OUTMASK ); // set A0 to indicate command port_out(port+2, (nRESET|nWR|A0) ^ OUTMASK); // set A0 to indicate command
port_out( port, command ); // set up p port_out(port, command); // set up p
port_out( port+2, (nRESET|A0) ^ OUTMASK ); // activate ^WR port_out(port+2, (nRESET|A0) ^ OUTMASK); // activate ^WR
port_out( port+2, (nRESET|nWR|A0) ^ OUTMASK ); // deactivate ^WR again port_out(port+2, (nRESET|nWR|A0) ^ OUTMASK); // deactivate ^WR again
port_out( port+2, (nRESET|nWR) ^ OUTMASK ); // clear A0 to indicate p port_out(port+2, (nRESET|nWR) ^ OUTMASK); // clear A0 to indicate p
for( i=0; i<datacount; i ++ ) { for (i = 0; i < datacount; i++) {
port_out( port, data[i] ); // set up data port_out(port, data[i]); // set up data
port_out( port+2, (nRESET) ^ OUTMASK ); // activate ^WR port_out(port+2, (nRESET) ^ OUTMASK); // activate ^WR
port_out( port+2, (nRESET|nWR) ^ OUTMASK ); // deactivate ^WR again port_out(port+2, (nRESET|nWR) ^ OUTMASK); // deactivate ^WR again
} }
} }
@@ -564,9 +578,32 @@ sed1330_close( Driver * drvthis )
{ {
PrivateData * p = drvthis->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_DEBUG, "%s()", __FUNCTION__ ); debug(RPT_DEBUG, "%s()", __FUNCTION__);
free( p ); if (p != NULL) {
int i, j;
for (i = 0; i < KEYPAD_MAXX; i++) {
if (p->keyMapDirect[i] != NULL)
free(p->keyMapDirect[i]);
for (j = 0; j < KEYPAD_MAXY; j++) {
if (p->keyMapMatrix[i][j] != NULL)
free(p->keyMapMatrix[i][j]);
}
}
if (p->framebuf_text != NULL)
free(p->framebuf_text);
if (p->lcd_contents_text != NULL)
free(p->lcd_contents_text);
if (p->framebuf_graph != NULL)
free(p->framebuf_graph);
if (p->lcd_contents_graph != NULL)
free(p->lcd_contents_graph);
free(p);
}
drvthis->store_private_ptr(drvthis, NULL);
} }
@@ -578,7 +615,7 @@ sed1330_width( Driver * drvthis )
{ {
PrivateData * p = drvthis->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_INFO, "%s()", __FUNCTION__ ); debug(RPT_INFO, "%s()", __FUNCTION__);
return p->width; return p->width;
} }
@@ -592,7 +629,7 @@ sed1330_height( Driver * drvthis )
{ {
PrivateData * p = drvthis->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_INFO, "%s()", __FUNCTION__ ); debug(RPT_INFO, "%s()", __FUNCTION__);
return p->height; return p->height;
} }
@@ -606,10 +643,10 @@ sed1330_clear( Driver * drvthis )
{ {
PrivateData * p = drvthis->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_DEBUG, "%s()", __FUNCTION__ ); debug(RPT_DEBUG, "%s()", __FUNCTION__);
memset( p->framebuf_text, ' ', p->bytesperline * p->textlines_in_memory); memset(p->framebuf_text, ' ', p->bytesperline * p->textlines_in_memory);
memset( p->framebuf_graph, 0, p->bytesperline * p->graph_height ); memset(p->framebuf_graph, '\0', p->bytesperline * p->graph_height);
} }
@@ -620,30 +657,30 @@ MODULE_EXPORT void
sed1330_string( Driver * drvthis, int x, int y, char *str ) sed1330_string( Driver * drvthis, int x, int y, char *str )
{ {
PrivateData * p = drvthis->private_data; PrivateData * p = drvthis->private_data;
char * dest; unsigned char * dest;
int offset, len; int offset, len;
debug( RPT_DEBUG, "%s( x=%d, y=%d, str=\"%s\" )", __FUNCTION__, x, y, str ); debug(RPT_DEBUG, "%s( x=%d, y=%d, str=\"%s\" )", __FUNCTION__, x, y, str);
if( y < 1 || y > p->height ) { if ((y < 1) || (y > p->height)) {
return; // outside framebuf return; // outside framebuf
} }
// Calculate offset and length to write // Calculate offset and length to write
if( x < 1 ) { if (x < 1) {
offset = (1 - x); offset = (1 - x);
x = 1; x = 1;
} else { } else {
offset = 0; offset = 0;
} }
len = strlen(str) - offset; len = strlen(str) - offset;
if( len > p->width - x + 1 ) { if (len > p->width - x + 1) {
len = p->width - x + 1; len = p->width - x + 1;
} }
// Calculate destination address // Calculate destination address
dest = p->framebuf_text + (y-1)*p->bytesperline + (x-1); dest = p->framebuf_text + (y-1)*p->bytesperline + (x-1);
// And write // And write
memcpy( dest, str, len ); memcpy(dest, str, len);
} }
@@ -655,9 +692,9 @@ sed1330_chr( Driver * drvthis, int x, int y, char c )
{ {
PrivateData * p = drvthis->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_DEBUG, "%s( x=%d, y=%d, c='%c' )", __FUNCTION__, x, y, c ); debug(RPT_DEBUG, "%s( x=%d, y=%d, c='%c' )", __FUNCTION__, x, y, c);
if( y < 1 || y > p->height || x < 1 || x > p->width ) { if ((y < 1) || (y > p->height) || (x < 1) || (x > p->width)) {
return; // outside framebuf return; // outside framebuf
} }
p->framebuf_text[(y-1)*p->bytesperline + (x-1)] = c; p->framebuf_text[(y-1)*p->bytesperline + (x-1)] = c;
@@ -674,53 +711,52 @@ sed1330_flush( Driver * drvthis )
unsigned int pos, start_pos, nr_equal, fblen, len, cursor_pos; unsigned int pos, start_pos, nr_equal, fblen, len, cursor_pos;
char csrloc[2]; char csrloc[2];
debug( RPT_DEBUG, "%s()", __FUNCTION__ ); debug(RPT_DEBUG, "%s()", __FUNCTION__);
/* sed1330_command( p, CMD_DISP_EN, 1, ((char[1]) {0x14}) ); // cursor off */ /* sed1330_command(p, CMD_DISP_EN, 1, ((char[1]) {0x14})); // cursor off */
// TODO: Flickering here needs to be prevented // TODO: Flickering here needs to be prevented
fblen = p->bytesperline * p->textlines_in_memory; fblen = p->bytesperline * p->textlines_in_memory;
for( pos=0; pos<fblen; ) { for (pos = 0; pos < fblen; ) {
start_pos = pos; start_pos = pos;
for( nr_equal=0; pos<fblen && nr_equal<4; pos++ ) { for (nr_equal = 0; pos<fblen && nr_equal<4; pos++) {
if( p->lcd_contents_text[pos] == p->framebuf_text[pos] ) { if (p->lcd_contents_text[pos] == p->framebuf_text[pos]) {
nr_equal ++; nr_equal ++;
} else { } else {
nr_equal = 0; nr_equal = 0;
} }
} }
len = pos - start_pos - nr_equal; len = pos - start_pos - nr_equal;
if( len > 0 ) { if (len > 0) {
cursor_pos = start_pos + 256 * SCR1_H + SCR1_L; cursor_pos = start_pos + 256 * SCR1_H + SCR1_L;
csrloc[0] = cursor_pos % 256; csrloc[0] = cursor_pos % 256;
csrloc[1] = cursor_pos / 256; csrloc[1] = cursor_pos / 256;
sed1330_command( p, CMD_CSRW, 2, csrloc ); sed1330_command(p, CMD_CSRW, 2, csrloc);
sed1330_command( p, CMD_MWRITE, len, p->framebuf_text + start_pos ); sed1330_command(p, CMD_MWRITE, len, p->framebuf_text + start_pos);
memcpy( p->lcd_contents_text + start_pos, p->framebuf_text + start_pos, len ); memcpy(p->lcd_contents_text + start_pos, p->framebuf_text + start_pos, len);
} }
} }
fblen = p->bytesperline * p->graph_height; fblen = p->bytesperline * p->graph_height;
for( pos=0; pos<fblen; ) { for (pos = 0; pos < fblen; ) {
start_pos = pos; start_pos = pos;
for( nr_equal=0; pos<fblen && nr_equal<4; pos++ ) { for (nr_equal = 0; pos < fblen && nr_equal < 4; pos++) {
if( p->lcd_contents_graph[pos] == p->framebuf_graph[pos] ) { if (p->lcd_contents_graph[pos] == p->framebuf_graph[pos]) {
nr_equal ++; nr_equal ++;
} else { } else {
nr_equal = 0; nr_equal = 0;
} }
} }
len = pos - start_pos - nr_equal; len = pos - start_pos - nr_equal;
if( len > 0 ) { if (len > 0) {
cursor_pos = start_pos + 256 * SCR2_H + SCR2_L; cursor_pos = start_pos + 256 * SCR2_H + SCR2_L;
csrloc[0] = cursor_pos % 256; csrloc[0] = cursor_pos % 256;
csrloc[1] = cursor_pos / 256; csrloc[1] = cursor_pos / 256;
sed1330_command( p, CMD_CSRW, 2, csrloc ); sed1330_command(p, CMD_CSRW, 2, csrloc);
sed1330_command( p, CMD_MWRITE, len, p->framebuf_graph + start_pos ); sed1330_command(p, CMD_MWRITE, len, p->framebuf_graph + start_pos);
memcpy( p->lcd_contents_graph + start_pos, p->framebuf_graph + start_pos, len ); memcpy(p->lcd_contents_graph + start_pos, p->framebuf_graph + start_pos, len);
} }
} }
} }
@@ -732,7 +768,7 @@ sed1330_backlight( Driver * drvthis, int on )
{ {
//PrivateData * p = drvthis->private_data; //PrivateData * p = drvthis->private_data;
debug( RPT_DEBUG, "%s( on=%d )", __FUNCTION__, on ); debug(RPT_DEBUG, "%s( on=%d )", __FUNCTION__, on);
// unimplemented // unimplemented
} }
@@ -748,21 +784,21 @@ sed1330_rect ( PrivateData * p, int x1, int y1, int x2, int y2, char pattern )
int x, y; int x, y;
// Swap coordinates if needed // Swap coordinates if needed
if( x1>x2 ) { if (x1 > x2) {
int swap; int swap;
swap=x1; swap = x1;
x1=x2; x1 = x2;
x2=swap; x2 = swap;
} }
if( y1>y2 ) { if (y1 > y2) {
int swap; int swap;
swap=y1; swap = y1;
y1=y2; y1 = y2;
y2=swap; y2 = swap;
} }
for( x=x1; x<=x2; x++ ) { for (x = x1; x <= x2; x++) {
for( y=y1; y<=y2; y++ ) { for (y = y1; y <= y2; y++) {
sed1330_set_pixel( p, x, y, pattern ); sed1330_set_pixel(p, x, y, pattern);
} }
} }
} }
@@ -782,36 +818,36 @@ sed1330_line ( PrivateData * p, int x1, int y1, int x2, int y2, char pattern )
/* Swap coordinates if needed. We want to draw the line from left /* Swap coordinates if needed. We want to draw the line from left
* to right. * to right.
*/ */
if( x1>x2 ) { if (x1 > x2) {
int swap; int swap;
swap=x1; x1=x2; x2=swap; swap = x1; x1 = x2; x2 = swap;
swap=y1; y1=y2; y2=swap; swap = y1; y1 = y2; y2 = swap;
} }
/* Draw from left to right... */ /* Draw from left to right... */
more_x = 1; more_x = 1;
for( x=x1, y=y1; x<=x2; x++ ) { for (x = x1, y = y1; x <= x2; x++) {
int more_y = 1; /* always draw one pixel */ int more_y = 1; /* always draw one pixel */
while( more_y ) {
while (more_y) {
/* set the pixel */ /* set the pixel */
sed1330_set_pixel( p, x, y, pattern ); sed1330_set_pixel(p, x, y, pattern);
/* Check what we need to do next */ /* Check what we need to do next */
if( y1 < y2 ) { if (y1 < y2) {
more_y = (y<=y2); more_y = (y <= y2);
if( x1 != x2 ) { if (x1 != x2) {
more_y &= ((float)y+0.5-y1) < ((float) x+0.5-x1) * (y2-y1) / ((float) x2-x1) ; more_y &= ((float)y+0.5-y1) < ((float) x+0.5-x1) * (y2-y1) / ((float) x2-x1) ;
} }
} else { } else {
more_y = (y>=y2); more_y = (y>=y2);
if( x1 != x2 ) { if (x1 != x2) {
more_y &= ((float)y+0.5-y1) > ((float) x+0.5-x1) * (y2-y1) / ((float) x2-x1) ; more_y &= ((float)y+0.5-y1) > ((float) x+0.5-x1) * (y2-y1) / ((float) x2-x1) ;
} }
} }
/* Increment y if we should draw a other pixel for this x value */ /* Increment y if we should draw a other pixel for this x value */
if( more_y ) { if (more_y) {
if( y1 < y2 ) { if (y1 < y2) {
y ++; y ++;
} else { } else {
y --; y --;
@@ -836,7 +872,7 @@ sed1330_set_pixel( PrivateData * p, int x, int y, int value )
bytepos = y*p->bytesperline + x/p->cellwidth; bytepos = y*p->bytesperline + x/p->cellwidth;
bitmask = 0x80 >> (x % p->cellwidth); bitmask = 0x80 >> (x % p->cellwidth);
if( value ) { if (value) {
p->framebuf_graph[bytepos] |= bitmask; /* set it */ p->framebuf_graph[bytepos] |= bitmask; /* set it */
} else { } else {
p->framebuf_graph[bytepos] &= ~bitmask; /* clear it */ p->framebuf_graph[bytepos] &= ~bitmask; /* clear it */
@@ -852,9 +888,10 @@ sed1330_vbar( Driver * drvthis, int x, int y, int len, int promille, int pattern
{ {
PrivateData * p = drvthis->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_DEBUG, "%s( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", __FUNCTION__, x, y, len, promille, pattern ); debug(RPT_DEBUG, "%s( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", __FUNCTION__, x, y, len, promille, pattern);
sed1330_rect ( p, (x-1) * p->cellwidth, y * p->cellheight, x * p->cellwidth - 2, y * p->cellheight - (long) len * p->cellheight * promille / 1000 - 1, 1 ); sed1330_rect(p, (x-1) * p->cellwidth, y * p->cellheight,
x * p->cellwidth - 2, y * p->cellheight - (long) len * p->cellheight * promille / 1000 - 1, 1);
} }
@@ -867,9 +904,10 @@ sed1330_hbar( Driver * drvthis, int x, int y, int len, int promille, int pattern
{ {
PrivateData * p = drvthis->private_data; PrivateData * p = drvthis->private_data;
debug( RPT_DEBUG, "%s( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", __FUNCTION__, x, y, len, promille, pattern ); debug(RPT_DEBUG, "%s( x=%d, y=%d, len=%d, promille=%d, pattern=%d )", __FUNCTION__, x, y, len, promille, pattern);
sed1330_rect ( p, (x-1) * p->cellwidth, (y-1) * p->cellheight, (x-1) * p->cellwidth + (long) len * p->cellwidth * promille / 1000 - 1, y * p->cellheight - 3, 1 ); sed1330_rect(p, (x-1) * p->cellwidth, (y-1) * p->cellheight,
(x-1) * p->cellwidth + (long) len * p->cellwidth * promille / 1000 - 1, y * p->cellheight - 3, 1);
} }
@@ -881,7 +919,7 @@ sed1330_num( Driver * drvthis, int x, int y, int num )
{ {
//PrivateData * p = drvthis->private_data; //PrivateData * p = drvthis->private_data;
debug( RPT_DEBUG, "%s( x=%d, y=%d, num=%d )", __FUNCTION__, x, y, num ); debug(RPT_DEBUG, "%s( x=%d, y=%d, num=%d )", __FUNCTION__, x, y, num);
// TODO: add code here :) // TODO: add code here :)
} }
@@ -915,17 +953,18 @@ sed1330_heartbeat( Driver * drvthis, int type )
{ 0xFF, 0xFF, 0xCF, 0x87, 0x87, 0xCF, 0xFF, 0xFF }, { 0xFF, 0xFF, 0xCF, 0x87, 0x87, 0xCF, 0xFF, 0xFF },
}; };
debug( RPT_DEBUG, "%s( type=%d )", __FUNCTION__, type ); debug(RPT_DEBUG, "%s( type=%d )", __FUNCTION__, type);
if( type == HEARTBEAT_OFF ) return; if (type == HEARTBEAT_OFF)
return;
p->framebuf_text[p->width-1] = ' '; p->framebuf_text[p->width-1] = ' ';
//whichIcon = (! ((timer + 4) & 5)); //whichIcon = (! ((timer + 4) & 5));
pos = p->width - 1; pos = p->width - 1;
for( n=0; n < p->cellheight; n++ ) { for (n = 0; n < p->cellheight; n++) {
//p->framebuf_graph[pos] = heartdata[whichIcon][n]; //p->framebuf_graph[pos] = heartdata[whichIcon][n];
if( n < 8 ) { if (n < 8) {
p->framebuf_graph[pos] = bouncing_ball[timer][n]; p->framebuf_graph[pos] = bouncing_ball[timer][n];
} else { } else {
p->framebuf_graph[pos] = 0; p->framebuf_graph[pos] = 0;
@@ -944,9 +983,9 @@ sed1330_heartbeat( Driver * drvthis, int type )
MODULE_EXPORT int MODULE_EXPORT int
sed1330_icon( Driver * drvthis, int x, int y, int icon ) sed1330_icon( Driver * drvthis, int x, int y, int icon )
{ {
switch( icon ) { switch (icon) {
case ICON_BLOCK_FILLED: case ICON_BLOCK_FILLED:
sed1330_chr( drvthis, x, y, 255 ); sed1330_chr(drvthis, x, y, 255);
break; break;
default: default:
return -1; return -1;
@@ -966,13 +1005,14 @@ sed1330_get_key(Driver *drvthis)
char * keystr = NULL; char * keystr = NULL;
struct timeval curr_time, time_diff; struct timeval curr_time, time_diff;
if( ! p->have_keypad ) return NULL; if (!p->have_keypad)
return NULL;
gettimeofday(&curr_time,NULL); gettimeofday(&curr_time,NULL);
scancode = sed1330_scankeypad(p); scancode = sed1330_scankeypad(p);
if( scancode ) { if (scancode) {
if( scancode & 0xF0 ) { if (scancode & 0xF0) {
keystr = p->keyMapMatrix[((scancode&0xF0)>>4)-1][(scancode&0x0F)-1]; keystr = p->keyMapMatrix[((scancode&0xF0)>>4)-1][(scancode&0x0F)-1];
} }
else { else {
@@ -980,10 +1020,10 @@ sed1330_get_key(Driver *drvthis)
} }
} }
if( keystr != NULL ) { if (keystr != NULL) {
if (keystr == p->pressed_key) { if (keystr == p->pressed_key) {
timersub (&curr_time, &(p->pressed_key_time), &time_diff); timersub (&curr_time, &(p->pressed_key_time), &time_diff);
if (((time_diff.tv_usec / 1000 + time_diff.tv_sec * 1000) - KEYPAD_AUTOREPEAT_DELAY) < 1000 * p->pressed_key_repetitions / KEYPAD_AUTOREPEAT_FREQ ) { if (((time_diff.tv_usec / 1000 + time_diff.tv_sec * 1000) - KEYPAD_AUTOREPEAT_DELAY) < 1000 * p->pressed_key_repetitions / KEYPAD_AUTOREPEAT_FREQ) {
// The key is already pressed quite some time // The key is already pressed quite some time
// but it's not yet time to return a repeated keypress // but it's not yet time to return a repeated keypress
return NULL; return NULL;
@@ -995,7 +1035,8 @@ sed1330_get_key(Driver *drvthis)
// It's a new keypress // It's a new keypress
p->pressed_key_time = curr_time; p->pressed_key_time = curr_time;
p->pressed_key_repetitions = 0; p->pressed_key_repetitions = 0;
report( RPT_INFO, "sed1330_get_key: Key pressed: %s (%d,%d)\n", keystr, scancode&0x0F, (scancode&0xF0)>>4 ); report(RPT_INFO, "%s: Key pressed: %s (%d,%d)",
drvthis->name, keystr, scancode&0x0F, (scancode&0xF0)>>4);
} }
} }
@@ -1030,8 +1071,8 @@ unsigned char sed1330_scankeypad(PrivateData *p)
// A directly connected key was pressed // A directly connected key was pressed
// Which key was it ? // Which key was it ?
shiftingbit = 1; shiftingbit = 1;
for (shiftcount=0; shiftcount<KEYPAD_MAXX && !scancode; shiftcount++) { for (shiftcount = 0; shiftcount < KEYPAD_MAXX && !scancode; shiftcount++) {
if ( keybits & shiftingbit) { if (keybits & shiftingbit) {
// Found ! Return from function. // Found ! Return from function.
scancode = shiftcount+1; scancode = shiftcount+1;
} }
@@ -1042,7 +1083,7 @@ unsigned char sed1330_scankeypad(PrivateData *p)
// Now check the matrix // Now check the matrix
// First check with all 1's // First check with all 1's
Ypattern = (1 << KEYPAD_MAXY) - 1; Ypattern = (1 << KEYPAD_MAXY) - 1;
if( sed1330_readkeypad (p, Ypattern)) { if (sed1330_readkeypad(p, Ypattern)) {
// Yes, a key on the matrix is pressed // Yes, a key on the matrix is pressed
// OK, now we know a key is pressed. // OK, now we know a key is pressed.
@@ -1052,7 +1093,7 @@ unsigned char sed1330_scankeypad(PrivateData *p)
// Do a 'binary search' to minimize I/O // Do a 'binary search' to minimize I/O
Ypattern = 0; Ypattern = 0;
Yval = 0; Yval = 0;
for (exp=3; exp>=0; exp--) { for (exp = 3; exp >= 0; exp--) {
Ypattern = ((1 << (1 << exp)) - 1) << Yval; Ypattern = ((1 << (1 << exp)) - 1) << Yval;
keybits = sed1330_readkeypad (p, Ypattern); keybits = sed1330_readkeypad (p, Ypattern);
if (!keybits) { if (!keybits) {
@@ -1061,10 +1102,10 @@ unsigned char sed1330_scankeypad(PrivateData *p)
} }
// Which key is pressed in that row ? // Which key is pressed in that row ?
keybits = sed1330_readkeypad (p, 1<<Yval); keybits = sed1330_readkeypad(p, 1 << Yval);
shiftingbit=1; shiftingbit = 1;
for (shiftcount=0; shiftcount<KEYPAD_MAXX && !scancode; shiftcount++) { for (shiftcount = 0; shiftcount < KEYPAD_MAXX && !scancode; shiftcount++) {
if ( keybits & shiftingbit) { if (keybits & shiftingbit) {
// Found ! // Found !
scancode = (Yval+1) << 4 | (shiftcount+1); scancode = (Yval+1) << 4 | (shiftcount+1);
} }
@@ -1087,7 +1128,7 @@ unsigned char sed1330_readkeypad (PrivateData *p, unsigned int YData)
// 8 bits output // 8 bits output
// Convert the positive logic to the negative logic on the LPT port // Convert the positive logic to the negative logic on the LPT port
port_out (p->port, ~YData & 0x00FF ); port_out(p->port, ~YData & 0x00FF);
// Read inputs // Read inputs
readval = ~ port_in (p->port + 1) ^ INMASK; readval = ~ port_in (p->port + 1) ^ INMASK;
@@ -1097,6 +1138,6 @@ unsigned char sed1330_readkeypad (PrivateData *p, unsigned int YData)
((readval & SELIN) / SELIN <<3) | /* pin 13 */ ((readval & SELIN) / SELIN <<3) | /* pin 13 */
((readval & PAPEREND) / PAPEREND <<2) | /* pin 12 */ ((readval & PAPEREND) / PAPEREND <<2) | /* pin 12 */
((readval & BUSY) / BUSY <<1) | /* pin 11 */ ((readval & BUSY) / BUSY <<1) | /* pin 11 */
((readval & ACK) / ACK )) & ~p->stuckinputs; /* pin 10 */ ((readval & ACK) / ACK)) & ~p->stuckinputs; /* pin 10 */
} }