]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2000-04-13 06:09:52 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Thu, 13 Apr 2000 06:09:52 +0000 (06:09 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Thu, 13 Apr 2000 06:09:52 +0000 (06:09 +0000)
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!

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@44 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

HD44780.c
MatrixOrbital.c
lcd4linux.conf.sample
system.c
system.h

index cdea5bf3930c5a5fc36aa670e3f0c3b3ab6ebbd5..5d3d6dd326cf2e0427b9666d46dbaee41c03929c 100644 (file)
--- 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
  *
  *
  *
  * $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;
index e178f79c3aa5306da4c7d8b5ca320a5dc5e98674..b9575b2e954c28900b98c311981973a282da41ff 100644 (file)
@@ -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
  *
  *
  *
  * $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
 #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];
 
index f3ed75207fd4cba21462b67336845ea285b7484f..dba2ced061e912ad130c0d82483ab2a577283cf0 100644 (file)
@@ -6,7 +6,7 @@
 Display HD44780
 Port 0x378
 Size 16x2
-
+Delay 600
 
 #Display PPM
 #size 20x4
index e2f979c361068f2b3b58f6f6799ea4f0cb260f9b..72db0ce5df1a46a9d560e19bb31a40162a74aa34 100644 (file)
--- 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
  *
  *
  *
  * $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;
   }
index 5cb5e0ed025ae12a2b6e176e99cefaf7af0c5f81..1c8dd30fe348573b25e3da3585318d94631a4728 100644 (file)
--- 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
  *
  *
  *
  * $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
 
 #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