-/* $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
#define CHARS 8
#define BARS ( BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2 )
-static LCD Lcd;
-
typedef struct {
int len1;
int len2;
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];
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);
}
}
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;
}
}
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
}
}
Bar[row][col].segment=-1;
}
}
- HD_command (0x01); // clear display
- HD_delay (1640);
+ HD_command (0x01, 1640); // clear display
return 0;
}
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;
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)
if (Txt[row][col]=='\t') break;
*p=Txt[row][col];
}
- HD_write (buffer, p-buffer);
+ HD_write (buffer, p-buffer, 40);
}
}
return 0;
-/* $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
* char *Processor (void);
* returns processor type ('i686')
*
+ * double BogoMips (void);
+ * returns BogoMips from /proc/cpuinfo
+ *
* int Memory (void);
* returns main memory (Megabytes)
*
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) {
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;
}
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;
}
}
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;
}
-/* $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