aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--drv_Crystalfontz.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/drv_Crystalfontz.c b/drv_Crystalfontz.c
index 7bdd196..a92ff30 100644
--- a/drv_Crystalfontz.c
+++ b/drv_Crystalfontz.c
@@ -1,4 +1,4 @@
-/* $Id: drv_Crystalfontz.c,v 1.31 2005/02/24 07:06:48 reinelt Exp $
+/* $Id: drv_Crystalfontz.c,v 1.32 2005/03/23 12:23:35 reinelt Exp $
*
* new style driver for Crystalfontz display modules
*
@@ -23,6 +23,9 @@
*
*
* $Log: drv_Crystalfontz.c,v $
+ * Revision 1.32 2005/03/23 12:23:35 reinelt
+ * fixed some signed/unsigned char mismatches in the Crystalfontz driver (ticket #12)
+ *
* Revision 1.31 2005/02/24 07:06:48 reinelt
* SimpleLCD driver added
*
@@ -186,7 +189,7 @@ static int Protocol;
static int Payload;
/* ring buffer for bytes received from the display */
-static char RingBuffer[256];
+static unsigned char RingBuffer[256];
static unsigned int RingRPos = 0;
static unsigned int RingWPos = 0;
@@ -198,7 +201,7 @@ struct {
} Packet;
/* Line Buffer for 633 displays */
-static char Line[2*16];
+static unsigned char Line[2*16];
/* Fan RPM */
static double Fan_RPM[4] = {0.0,};
@@ -243,7 +246,7 @@ static MODEL Models[] = {
/* x^0 + x^5 + x^12 */
#define CRCPOLY 0x8408
-static unsigned short CRC (const char *p, size_t len, unsigned short seed)
+static unsigned short CRC (const unsigned char *p, size_t len, unsigned short seed)
{
int i;
while (len--) {
@@ -254,18 +257,18 @@ static unsigned short CRC (const char *p, size_t len, unsigned short seed)
return ~seed;
}
-static char LSB (const unsigned short word)
+static unsigned char LSB (const unsigned short word)
{
return word & 0xff;
}
-static char MSB (const unsigned short word)
+static unsigned char MSB (const unsigned short word)
{
return word >> 8;
}
-static char byte (unsigned int pos)
+static unsigned char byte (unsigned int pos)
{
pos += RingRPos;
if (pos >= sizeof(RingBuffer))
@@ -318,13 +321,12 @@ static void drv_CF_process_packet (void)
static int drv_CF_poll (void)
{
- char buffer[32];
- unsigned short crc;
- int n, num, size;
+ unsigned char buffer[32];
/* read into RingBuffer */
while (1) {
- num = drv_generic_serial_poll(buffer, 32);
+ int num, n;
+ num = drv_generic_serial_poll(buffer, sizeof(buffer));
if (num <= 0) break;
/* put result into RingBuffer */
for (n = 0; n < num; n++) {
@@ -335,38 +337,41 @@ static int drv_CF_poll (void)
/* process RingBuffer */
while (1) {
+ int n, num, size;
+ unsigned short crc;
/* packet size */
- num=RingWPos-RingRPos;
- if (num < 0) num+=sizeof(RingBuffer);
+ num = RingWPos - RingRPos;
+ if (num < 0) num += sizeof(RingBuffer);
/* minimum packet size=4 */
if (num < 4) return 0;
/* valid response types: 01xxxxx 10.. 11.. */
/* therefore: 00xxxxxx is invalid */
- if (byte(0)>>6 == 0) goto GARBAGE;
+ if (byte(0) >> 6 == 0) goto GARBAGE;
+ /* command length */
+ size = byte(1);
/* valid command length is 0 to 16 */
- if (byte(1) > 16) goto GARBAGE;
+ if (size > 16) goto GARBAGE;
/* all bytes available? */
- size=byte(1);
if (num < size+4) return 0;
/* check CRC */
- for (n=0; n<size+4; n++) buffer[n]=byte(n);
+ for (n = 0; n < size+4; n++) buffer[n] = byte(n);
crc = CRC(buffer, size+2, 0xffff);
- if (LSB(crc) != byte(size+2)) goto GARBAGE;
- if (MSB(crc) != byte(size+3)) goto GARBAGE;
+ if (LSB(crc) != buffer[size+2]) goto GARBAGE;
+ if (MSB(crc) != buffer[size+3]) goto GARBAGE;
/* process packet */
Packet.type = buffer[0];
Packet.size = size;
memcpy(Packet.data, buffer+2, size);
- Packet.data[size]='\0'; /* trailing zero */
+ Packet.data[size] = '\0'; /* trailing zero */
/* increment read pointer */
RingRPos += size+4;
if (RingRPos >= sizeof(RingBuffer)) RingRPos -= sizeof(RingBuffer);
/* a packet arrived */
return 1;
GARBAGE:
- debug ("dropping garbage byte %d", byte(0));
+ debug ("dropping garbage byte %02x", byte(0));
RingRPos++;
- if (RingRPos>=sizeof(RingBuffer)) RingRPos=0;
+ if (RingRPos >= sizeof(RingBuffer)) RingRPos = 0;
continue;
}
@@ -385,7 +390,7 @@ static void drv_CF_timer (void __attribute__((unused)) *notused)
static void drv_CF_send (const int cmd, int len, const unsigned char *data)
{
- char buffer[22];
+ unsigned char buffer[22];
unsigned short crc;
if (len > Payload) {
@@ -411,7 +416,7 @@ static void drv_CF_send (const int cmd, int len, const unsigned char *data)
static void drv_CF_write1 (const int row, const int col, const char *data, const int len)
{
- char cmd[3]="\021xy"; /* set cursor position */
+ unsigned char cmd[3]="\021xy"; /* set cursor position */
if (row==0 && col==0) {
drv_generic_serial_write ("\001", 1); /* cursor home */
@@ -470,7 +475,7 @@ static void drv_CF_write3 (const int row, const int col, const char *data, const
static void drv_CF_defchar1 (const int ascii, const unsigned char *matrix)
{
int i;
- char cmd[10]="\031n"; /* set custom char bitmap */
+ unsigned char cmd[10]="\031n"; /* set custom char bitmap */
/* user-defineable chars start at 128, but are defined at 0 */
cmd[1]=(char)(ascii-CHAR0);
@@ -501,7 +506,7 @@ static void drv_CF_defchar23 (const int ascii, const unsigned char *matrix)
static int drv_CF_contrast (int contrast)
{
static unsigned char Contrast=0;
- char buffer[2];
+ unsigned char buffer[2];
/* -1 is used to query the current contrast */
if (contrast == -1) return Contrast;
@@ -539,7 +544,7 @@ static int drv_CF_contrast (int contrast)
static int drv_CF_backlight (int backlight)
{
static unsigned char Backlight=0;
- char buffer[2];
+ unsigned char buffer[2];
/* -1 is used to query the current backlight */
if (backlight == -1) return Backlight;
[lcd4linux @ 2003-09-13 06:20:39 by reinelt]reinelt7-8673/+459 HD44780 timings changed; deactivated libtool git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@242 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-11[lcd4linux @ 2003-09-11 15:05:24 by reinelt]reinelt3-89/+1519 missing files for autoconf/automake/libtool git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@241 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-11[lcd4linux @ 2003-09-11 04:09:52 by reinelt]reinelt6-14/+46 minor cleanups git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@240 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-10[lcd4linux @ 2003-09-10 15:59:39 by reinelt]reinelt4-13/+391 minor cleanups git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@239 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-10[lcd4linux @ 2003-09-10 15:09:21 by reinelt]reinelt1-0/+28 ChangeLog git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@238 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-10[lcd4linux @ 2003-09-10 14:01:52 by reinelt]reinelt6-21/+110 icons nearly finished\! git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@237 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-10[lcd4linux @ 2003-09-10 08:37:09 by reinelt]reinelt2-50/+73 icons: reorganized tick_* again... git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@236 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-10[lcd4linux @ 2003-09-10 03:48:22 by reinelt]reinelt7-47/+130 Icons for M50530, new processing scheme (Ticks.Text...) git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@235 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-09[lcd4linux @ 2003-09-09 11:47:47 by reinelt]reinelt3-14/+37 basic icon support for HD44780 git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@234 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-09[lcd4linux @ 2003-09-09 06:54:43 by reinelt]reinelt15-135/+177 new function 'cfg_number()' git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@233 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-09[lcd4linux @ 2003-09-09 05:30:33 by reinelt]reinelt11-90/+243 even more icons stuff git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@232 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-01[lcd4linux @ 2003-09-01 07:07:03 by reinelt]reinelt8-402/+13825 shared liblcd4linux git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@231 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-09-01[lcd4linux @ 2003-09-01 04:09:34 by reinelt]reinelt9-28/+127 icons nearly finished, but MatrixOrbital only git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@230 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-24[lcd4linux @ 2003-08-24 05:28:31 by reinelt]reinelt1-119/+156 ChangeLog git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@229 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-24[lcd4linux @ 2003-08-24 05:17:58 by reinelt]reinelt25-131/+217 liblcd4linux patch from Patrick Schemitz git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@228 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-24[lcd4linux @ 2003-08-24 04:31:56 by reinelt]reinelt6-11/+154 icon.c icon.h added git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@227 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-22[lcd4linux @ 2003-08-22 03:45:08 by reinelt]reinelt3-8/+25 bug in parallel port code fixed, more icons stuff git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@226 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-20[lcd4linux @ 2003-08-20 05:26:43 by reinelt]reinelt1-9/+11 small bug in bar compaction fixed git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@225 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-19[lcd4linux @ 2003-08-19 05:23:55 by reinelt]reinelt2-62/+123 HD44780 dual-controller patch from Jesse Brook Kovach git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@224 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-19[lcd4linux @ 2003-08-19 04:28:41 by reinelt]reinelt4-19/+42 more Icon stuff, minor glitches fixed git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@223 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-17[lcd4linux @ 2003-08-17 16:37:39 by reinelt]reinelt5-23/+77 more icon framework git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@222 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-17[lcd4linux @ 2003-08-17 12:11:58 by reinelt]reinelt6-27/+118 framework for icons prepared git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@221 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-17[lcd4linux @ 2003-08-17 08:25:30 by reinelt]reinelt6-46/+185 preparations for liblcd4linux; minor bugs in SIN.c and Skeleton.c git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@220 3ae390bd-cb1e-0410-b409-cd5a39f66f1f 2003-08-17[lcd4linux @ 2003-08-17 06:57:04 by reinelt]reinelt5-544/+325 complete rewrite of the Crystalfontz driver git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@219 3ae390bd-cb1e-0410-b409-cd5a39f66f1f