aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--HD44780.c73
-rw-r--r--MatrixOrbital.c20
-rw-r--r--lcd4linux.conf.sample2
-rw-r--r--system.c54
-rw-r--r--system.h31
5 files changed, 126 insertions, 54 deletions
diff --git a/HD44780.c b/HD44780.c
index cdea5bf..5d3d6dd 100644
--- a/HD44780.c
+++ b/HD44780.c
@@ -1,4 +1,4 @@
-/* $Id: HD44780.c,v 1.1 2000/04/12 08:05:45 reinelt Exp $
+/* $Id: HD44780.c,v 1.2 2000/04/13 06:09:52 reinelt Exp $
*
* driver for display modules based on the HD44780 chip
*
@@ -20,6 +20,14 @@
*
*
* $Log: HD44780.c,v $
+ * Revision 1.2 2000/04/13 06:09:52 reinelt
+ *
+ * added BogoMips() to system.c (not used by now, maybe sometimes we can
+ * calibrate our delay loop with this value)
+ *
+ * added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully
+ * no compiler will optimize away the delay loop!
+ *
* Revision 1.1 2000/04/12 08:05:45 reinelt
*
* first version of the HD44780 driver
@@ -49,8 +57,6 @@
#define CHARS 8
#define BARS ( BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2 )
-static LCD Lcd;
-
typedef struct {
int len1;
int len2;
@@ -66,7 +72,9 @@ typedef struct {
int ascii;
} SEGMENT;
+static LCD Lcd;
static unsigned short Port=0;
+static unsigned long Delay;
static char Txt[4][40];
static BAR Bar[4][40];
@@ -75,28 +83,29 @@ static int nSegment=2;
static SEGMENT Segment[128] = {{ len1:0, len2:0, type:255, used:0, ascii:32 },
{ len1:255, len2:255, type:255, used:0, ascii:255 }};
-
static void HD_delay (unsigned long usec)
{
- usleep(usec);
+ unsigned long i=usec*Delay/2;
+ while (i--);
}
-static void HD_command (unsigned char cmd)
+static void HD_command (unsigned char cmd, int delay)
{
outb (cmd, Port); // put data on DB1..DB8
outb (0x02, Port+2); // set Enable = bit 0 invertet
HD_delay(1);
outb (0x03, Port+2); // clear Enable
+ HD_delay(delay);
}
-static void HD_write (char *string, int len)
+static void HD_write (char *string, int len, int delay)
{
while (len--) {
outb (*string++, Port); // put data on DB1..DB8
outb (0x00, Port+2); // set Enable = bit 0 invertet
HD_delay(1);
outb (0x01, Port+2); // clear Enable
- HD_delay(40);
+ HD_delay(delay);
}
}
@@ -107,20 +116,13 @@ static int HD_open (void)
return -1;
}
- HD_command (0x30); // 8 Bit mode
- HD_delay (4100); // wait 4.1 ms
- HD_command (0x30); // 8 Bit mode
- HD_delay (100); // wait 100 us
- HD_command (0x30); // 8 Bit mode
- HD_delay (4100); // wait 4.1 ms
- HD_command (0x38); // 8 Bit mode, 1/16 duty cycle, 5x8 font
- HD_delay (40); // wait 40 us
- HD_command (0x08); // Display off, cursor off, blink off
- HD_delay (40); // wait 40 us
- HD_command (0x0c); // Display on, cursor off, blink off
- HD_delay (1640); // wait 1.64 ms
- HD_command (0x06); // curser moves to right, no shift
- HD_delay (40); // wait 40 us
+ HD_command (0x30, 4100); // 8 Bit mode, wait 4.1 ms
+ HD_command (0x30, 100); // 8 Bit mode, wait 100 us
+ HD_command (0x30, 4100); // 8 Bit mode, wait 4.1 ms
+ HD_command (0x38, 40); // 8 Bit mode, 1/16 duty cycle, 5x8 font
+ HD_command (0x08, 40); // Display off, cursor off, blink off
+ HD_command (0x0c, 1640); // Display on, cursor off, blink off, wait 1.64 ms
+ HD_command (0x06, 40); // curser moves to right, no shift
return 0;
}
@@ -287,8 +289,8 @@ static void HD_define_chars (void)
}
break;
}
- HD_command (0x40|8*c);
- HD_write (buffer, 8);
+ HD_command (0x40|8*c, 40);
+ HD_write (buffer, 8, 120); // 120 usec delay for CG RAM write
}
}
@@ -305,8 +307,7 @@ int HD_clear (void)
Bar[row][col].segment=-1;
}
}
- HD_command (0x01); // clear display
- HD_delay (1640);
+ HD_command (0x01, 1640); // clear display
return 0;
}
@@ -332,16 +333,25 @@ int HD_init (LCD *Self)
fprintf (stderr, "HD44780: no 'Size' entry in %s\n", cfg_file());
return -1;
}
-
if (sscanf(s,"%dx%d",&cols,&rows)!=2 || rows<1 || cols<1) {
fprintf(stderr,"HD44780: bad size '%s'\n",s);
return -1;
}
-
+
+ s=cfg_get ("Delay");
+ if (s==NULL || *s=='\0') {
+ fprintf (stderr, "HD44780: no 'Delay' entry in %s\n", cfg_file());
+ return -1;
+ }
+ if ((Delay=strtol(s, &e, 0))==0 || *e!='\0' || Delay<1) {
+ fprintf (stderr, "HD44780: bad delay '%s' in %s\n", s, cfg_file());
+ return -1;
+ }
+
Self->rows=rows;
Self->cols=cols;
Lcd=*Self;
-
+
if (HD_open()!=0)
return -1;
@@ -359,8 +369,7 @@ void HD_goto (int row, int col)
int pos;
pos=(row%2)*64+col;
if (row>2) pos+=20;
- HD_command (0x80|pos);
- HD_delay(40);
+ HD_command (0x80|pos, 40);
}
int HD_put (int row, int col, char *text)
@@ -474,7 +483,7 @@ int HD_flush (void)
if (Txt[row][col]=='\t') break;
*p=Txt[row][col];
}
- HD_write (buffer, p-buffer);
+ HD_write (buffer, p-buffer, 40);
}
}
return 0;
diff --git a/MatrixOrbital.c b/MatrixOrbital.c
index e178f79..b9575b2 100644
--- a/MatrixOrbital.c
+++ b/MatrixOrbital.c
@@ -1,4 +1,4 @@
-/* $Id: MatrixOrbital.c,v 1.15 2000/04/12 08:05:45 reinelt Exp $
+/* $Id: MatrixOrbital.c,v 1.16 2000/04/13 06:09:52 reinelt Exp $
*
* driver for Matrix Orbital serial display modules
*
@@ -20,6 +20,14 @@
*
*
* $Log: MatrixOrbital.c,v $
+ * Revision 1.16 2000/04/13 06:09:52 reinelt
+ *
+ * added BogoMips() to system.c (not used by now, maybe sometimes we can
+ * calibrate our delay loop with this value)
+ *
+ * added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully
+ * no compiler will optimize away the delay loop!
+ *
* Revision 1.15 2000/04/12 08:05:45 reinelt
*
* first version of the HD44780 driver
@@ -104,11 +112,6 @@
#define CHARS 8
#define BARS ( BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2 )
-static LCD Lcd;
-static char *Port=NULL;
-static speed_t Speed;
-static int Device=-1;
-
typedef struct {
int len1;
int len2;
@@ -124,6 +127,11 @@ typedef struct {
int ascii;
} SEGMENT;
+static LCD Lcd;
+static char *Port=NULL;
+static speed_t Speed;
+static int Device=-1;
+
static char Txt[4][40];
static BAR Bar[4][40];
diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample
index f3ed752..dba2ced 100644
--- a/lcd4linux.conf.sample
+++ b/lcd4linux.conf.sample
@@ -6,7 +6,7 @@
Display HD44780
Port 0x378
Size 16x2
-
+Delay 600
#Display PPM
#size 20x4
diff --git a/system.c b/system.c
index e2f979c..72db0ce 100644
--- a/system.c
+++ b/system.c
@@ -1,4 +1,4 @@
-/* $Id: system.c,v 1.9 2000/03/28 07:22:15 reinelt Exp $
+/* $Id: system.c,v 1.10 2000/04/13 06:09:52 reinelt Exp $
*
* system status retreivement
*
@@ -20,6 +20,14 @@
*
*
* $Log: system.c,v $
+ * Revision 1.10 2000/04/13 06:09:52 reinelt
+ *
+ * added BogoMips() to system.c (not used by now, maybe sometimes we can
+ * calibrate our delay loop with this value)
+ *
+ * added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully
+ * no compiler will optimize away the delay loop!
+ *
* Revision 1.9 2000/03/28 07:22:15 reinelt
*
* version 0.95 released
@@ -71,6 +79,9 @@
* char *Processor (void);
* returns processor type ('i686')
*
+ * double BogoMips (void);
+ * returns BogoMips from /proc/cpuinfo
+ *
* int Memory (void);
* returns main memory (Megabytes)
*
@@ -126,7 +137,7 @@ static int parse_meminfo (char *tag, char *buffer)
p=strstr(buffer, tag);
if (p==NULL) {
- fprintf (stderr, "parse(/proc/meminfo) failed: no %s line\n", tag);
+ fprintf (stderr, "parse(/proc/meminfo) failed: no '%s' line\n", tag);
return -1;
}
if (sscanf(p+strlen(tag), "%lu", &val)<1) {
@@ -184,6 +195,41 @@ char *Processor(void)
return buffer;
}
+double BogoMips (void)
+{
+ static double val=-2;
+ char buffer[4096];
+
+ if (val==-1) return -1;
+
+ if (val==-2) {
+ char *p;
+ int fd=open("/proc/meminfo", O_RDONLY);
+ if (fd==-1) {
+ perror ("open(/proc/cpuinfo) failed");
+ val=-1;
+ return -1;
+ }
+ if (read (fd, &buffer, sizeof(buffer)-1)==-1) {
+ perror ("read(/proc/cpuinfo) failed");
+ val=-1;
+ return -1;
+ }
+ p=strstr(buffer, "bogomips");
+ if (p==NULL) {
+ fprintf (stderr, "parse(/proc/cpuinfo) failed: no 'bogomips' line\n");
+ val=-1;
+ return -1;
+ }
+ if (sscanf(p+8, " : %lf", &val)<1) {
+ fprintf (stderr, "scanf(/proc/cpuinfo) failed\n");
+ val=-1;
+ return -1;
+ }
+ }
+ return val;
+}
+
int Memory(void)
{
static int value=-1;
@@ -404,7 +450,7 @@ int Disk (int *r, int *w)
}
p=strstr(buffer, "disk_rblk");
if (p==NULL) {
- fprintf (stderr, "parse(/proc/stat) failed: no disk_rblk line\n");
+ fprintf (stderr, "parse(/proc/stat) failed: no 'disk_rblk' line\n");
fd=-1;
return -1;
}
@@ -415,7 +461,7 @@ int Disk (int *r, int *w)
}
p=strstr(buffer, "disk_wblk");
if (p==NULL) {
- fprintf (stderr, "parse(/proc/stat) failed: no disk_wblk line\n");
+ fprintf (stderr, "parse(/proc/stat) failed: no 'disk_wblk' line\n");
fd=-1;
return -1;
}
diff --git a/system.h b/system.h
index 5cb5e0e..1c8dd30 100644
--- a/system.h
+++ b/system.h
@@ -1,4 +1,4 @@
-/* $Id: system.h,v 1.5 2000/03/17 09:21:42 reinelt Exp $
+/* $Id: system.h,v 1.6 2000/04/13 06:09:52 reinelt Exp $
*
* system status retreivement
*
@@ -20,6 +20,14 @@
*
*
* $Log: system.h,v $
+ * Revision 1.6 2000/04/13 06:09:52 reinelt
+ *
+ * added BogoMips() to system.c (not used by now, maybe sometimes we can
+ * calibrate our delay loop with this value)
+ *
+ * added delay loop to HD44780 driver. It seems to be quite fast now. Hopefully
+ * no compiler will optimize away the delay loop!
+ *
* Revision 1.5 2000/03/17 09:21:42 reinelt
*
* various memory statistics added
@@ -43,15 +51,16 @@
#define SENSORS 9
-char *System (void);
-char *Release (void);
-char *Processor (void);
-int Memory (void);
-int Ram (int *total, int *free, int *shared, int *buffered, int *cached);
-int Load (double *load1, double *load2, double *load3);
-int Busy (double *user, double *nice, double *system, double *idle);
-int Disk (int *r, int *w);
-int Net (int *rx, int *tx);
-int Sensor (int index, double *val, double *min, double *max);
+char *System (void);
+char *Release (void);
+char *Processor (void);
+double BogoMips (void);
+int Memory (void);
+int Ram (int *total, int *free, int *shared, int *buffered, int *cached);
+int Load (double *load1, double *load2, double *load3);
+int Busy (double *user, double *nice, double *system, double *idle);
+int Disk (int *r, int *w);
+int Net (int *rx, int *tx);
+int Sensor (int index, double *val, double *min, double *max);
#endif