LCDproc development and user support list

Text archives Help


[Lcdproc] [PATCH] driver for BWCT USB LCD modules


Chronological Thread 
  • From: peter.marschall AT adpm.de (Peter Marschall)
  • Subject: [Lcdproc] [PATCH] driver for BWCT USB LCD modules
  • Date: Thu Sep 16 18:01:02 2004

Hi,

here is the patch with the driver for the BWCT USB LCD modules that I=20
announced in my previous post.

The patch, that I atteched to this mail inline, applies cleanly to the curr=
ent=20
CVS nightly.

Steps to apply the patch (and to re-generate the configure infrastructure):
1) cd to the current LCDproc CVS directory
2) patch -p 0 < /path/to/lcdproc-BWCT.patch
3) aclocal
4) autoconf
5) automake -a -c

That's it. Now lcdproc can be compiled with BWCT supportusing the standard=
=20
configure; make; make install procedure.

BWCT support is not realized as a driver by itself but a new=20
ConnectionType =3D bwctusb=20
for the hdd44780 driver.
To work properly it depends on a halfway recent libusb.

Please test it and consider its inclusion in LCDproc.

Peter
=2D-=20
Peter Marschall | eMail:
peter.marschall AT adpm.de
Scheffelstra=DFe 15 | Tel: +49 931 14721
D-97072 W=FCrzburg |
PGP: 0BB1 04A3 0FB0 E27F 8018 52BA A286 7B23 9C22 2C83




=2D-- acinclude.m4 2003-08-02 09:00:08.000000000 +0200
+++ acinclude.m4 2004-09-04 15:31:43.000000000 +0200
@@ -136,6 +136,9 @@
else
HD44780_DRIVERS=3D"hd44780-picanlcd.o"
fi
+ if test "$ac_cv_have_libusb" =3D yes ; then
+ HD44780_DRIVERS=3D"${HD44780_DRIVERS}
hd44780-bwct-usb.o"
+ fi =09
DRIVERS=3D"$DRIVERS hd44780${SO}"
actdrivers=3D["$actdrivers hd44780"]
;;
@@ -575,3 +578,71 @@
dnl End of loadable modules determination
]) dnl AC_MODULES_INFO
=20
+dnl Test for LUSB, and define LUSB_CFLAGS and LUSB_LIBS
+dnl to be used as follows:
+dnl AM_PATH_LUSB([MINIMUM-VERSION, [ACTION-IF-FOUND [,=20
ACTION-IF-NOT-FOUND]]])
+dnl
+AC_DEFUN(AM_PATH_LUSB,
+[dnl=20
+dnl Get the cflags and libraries from the libbwct-config script
+dnl
+AC_ARG_WITH(libusb-prefix,[ --with-libusb-prefix=3DPREFIX]
+ [Prefix where libusb is installed (optional)],
+ libusb_config_prefix=3D"$withval", libusb_config_prefix=3D"")
+AC_ARG_WITH(libusb-exec-prefix,[ --with-libusb-exec-prefix=3DPREFIX]
+ [Exec prefix where libusb is installed (optional=
)],
+ libusb_config_exec_prefix=3D"$withval",=20
libusb_config_exec_prefix=3D"")
+AC_ARG_ENABLE(libusbtest, [ --disable-libusbtest Do not try to compil=
e=20
and run a test libusb program],
+ , enable_libusbtest=3Dyes)
+
+ if test x$libusb_config_exec_prefix !=3D x ; then
+ libusb_config_args=3D"$libusb_config_args=20
=2D-exec-prefix=3D$libusb_config_exec_prefix"
+ if test x${LUSB_CONFIG+set} !=3D xset ; then
+ LUSB_CONFIG=3D$libusb_config_exec_prefix/bin/libusb-config
+ fi
+ fi
+ if test x$libusb_config_prefix !=3D x ; then
+ libusb_config_args=3D"$libusb_config_args --prefix=3D$libusb_config_p=
refix"
+ if test x${LUSB_CONFIG+set} !=3D xset ; then
+ LUSB_CONFIG=3D$libusb_config_prefix/bin/libusb-config
+ fi
+ fi
+
+ AC_PATH_PROG(LUSB_CONFIG, [libusb-config], no)
+ min_libusb_version=3Difelse([$1], ,1.7,$1)
+
+ AC_CHECKING(for libusb - version >=3D $min_libusb_version)
+ AC_LANG_SAVE
+ no_libusb=3D""
+ if test "$LUSB_CONFIG" =3D "no" ; then
+ no_libusb=3Dyes
+ else
+ AC_LANG_C
+
+ LUSB_CFLAGS=3D`$LUSB_CONFIG $libusb_config_args --cflags`
+ LUSB_LIBS=3D`$LUSB_CONFIG $libusb_config_args --libs`
+ libusb_config_major_version=3D`$LUSB_CONFIG $libusb_config_args --vers=
ion |=20
\
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
+ libusb_config_minor_version=3D`$LUSB_CONFIG $libusb_config_args --vers=
ion |=20
\
+ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
+ fi
+ if test "x$no_libusb" =3D x ; then
+ AC_MSG_RESULT([yes])
+ ifelse([$2], , :, [$2]) =20
+ else
+ AC_MSG_RESULT([no])
+ if test "$LUSB_CONFIG" =3D "no" ; then
+ echo "*** The libusb-config script installed by libusb could not be=
=20
found"
+ echo "*** If libusb was installed in PREFIX, make sure PREFIX/bin i=
s=20
in"
+ echo "*** your path, or set the LUSB_CONFIG environment variable to=
=20
the"
+ echo "*** full path to libusb-config."
+ fi
+ LUSB_CFLAGS=3D""
+ LUSB_LIBS=3D""
+ ifelse([$3], , :, [$3])
+ fi
+ AC_LANG_RESTORE
+ AC_SUBST(LUSB_CFLAGS)
+ AC_SUBST(LUSB_LIBS)
+])
+
=2D-- config.h.in 2003-12-27 09:00:04.000000000 +0100
+++ config.h.in 2004-09-04 16:11:48.000000000 +0200
@@ -318,6 +318,9 @@
/* Location of your mounted filesystem table file */
#undef MTAB_FILE
=20
+/* Define if you have a workable libusb. */
+#undef HAVE_LIBUSB
+
/* Compile with LDAP lud_exts */
#undef WITH_LDAP_LUD_EXTS
=20
=2D-- configure.in 2004-09-04 09:00:16.000000000 +0200
+++ configure.in 2004-09-04 16:12:52.000000000 +0200
@@ -198,6 +198,16 @@
)
AC_DEFINE_UNQUOTED(LOAD_MIN, $LOAD_MIN)
=20
+AM_PATH_LUSB(1.5,[
+ AC_DEFINE([HAVE_LIBUSB],[1],[Define if you have a workable libusb.])
+ ac_cv_have_libusb=3Dyes
+ ],[
+ echo "no"
+ AC_MSG_WARN([Can't directly talk to USB, disabling drivers that use
it.])
+])
+CFLAGS=3D"$CFLAGS $LUSB_CFLAGS"
+LIBS=3D"$LIBS $LUSB_LIBS"
+
AC_MODULES_INFO
=20
LCD_DRIVERS_SELECT
=2D-- server/drivers/hd44780-drivers.h 2002-05-06 23:14:14.000000000 +0200
+++ server/drivers/hd44780-drivers.h 2004-09-04 16:10:12.000000000 +0200
@@ -17,6 +17,9 @@
# include "hd44780-serialLpt.h"
# include "hd44780-winamp.h"
#endif
+#ifdef HAVE_LIBUSB
+# include "hd44780-bwct-usb.h"
+#endif
#include "hd44780-picanlcd.h"
// add new connection type header files here
=20
@@ -32,6 +35,9 @@
{"winamp", hd_init_winamp, "\tnone\n"},
#endif
{"picanlcd", hd_init_picanlcd, "\tnone\n"},
+#ifdef HAVE_LIBUSB
+ {"bwctusb", hd_init_bwct_usb, "\tnone\n"},
+#endif
// add new connection types and their string specifier here
// default, end of structure element (do not delete)
{NULL, NULL, NULL}
=2D-- server/drivers/Makefile.am 2003-06-04 01:20:36.000000000 +0200
+++ server/drivers/Makefile.am 2004-09-04 15:34:51.000000000 +0200
@@ -43,7 +43,7 @@
curses_SOURCES =3D lcd.h curses_drv.h curses_drv.c report.h
glk_SOURCES =3D lcd.h glk.c glk.h glkproto.c glkproto.h report.h
hd44780_SOURCES =3D lcd.h hd44780.h hd44780.c hd44780-drivers.h=20
hd44780-low.h hd44780-charmap.h report.h
=2DEXTRA_hd44780_SOURCES =3D hd44780-4bit.c hd44780-4bit.h hd44780-ext8bit.=
c=20
hd44780-ext8bit.h lcd_sem.c lcd_sem.h hd44780-serialLpt.c hd44780-serialLpt=
=2Eh=20
hd44780-winamp.c hd44780-winamp.h hd44780-picanlcd.c hd44780-picanlcd.h=20
port.h lpt-port.h timing.h
+EXTRA_hd44780_SOURCES =3D hd44780-4bit.c hd44780-4bit.h hd44780-ext8bit.c=
=20
hd44780-ext8bit.h lcd_sem.c lcd_sem.h hd44780-serialLpt.c hd44780-serialLpt=
=2Eh=20
hd44780-winamp.c hd44780-winamp.h hd44780-picanlcd.c hd44780-picanlcd.h=20
hd44780-bwct-usb.c hd44780-bwct-usb.h port.h lpt-port.h timing.h
=20
icp_a106_SOURCES =3D lcd.h icp_a106.c icp_a106.h report.h
irman_SOURCES =3D lcd.h irmanin.c irmanin.h report.h
=2D-- server/drivers/hd44780.c 2004-02-10 09:45:33.000000000 +0100
+++ server/drivers/hd44780.c 2004-09-04 17:56:59.000000000 +0200
@@ -129,6 +129,7 @@
char buf[40];
char *s;
int i;
+ int usb =3D 0;
PrivateData *p;
=20
// Alocate and store private data
@@ -163,6 +164,9 @@
return -1; // fatal error
} else {
p->connectiontype_index =3D i;
+ if ((strstr(connectionMapping[i].name, "usb") !=3D NULL) ||
+ (strstr(connectionMapping[i].name, "USB") !=3D NULL))
+ usb =3D 1;
}
=20
// Get and parse vspan only when specified
@@ -302,11 +306,20 @@
HD44780_clear (drvthis);
sprintf (buf, "HD44780 %dx%d", p->width, p->height );
HD44780_string (drvthis, 1, 1, buf);
+ if (usb) {
+ sprintf (buf, "USB %s%s%s",
+ (p->have_backlight?" bl":""),
+ (p->have_keypad?" key":""),
+ (p->have_output?" out":"")
+ );
+ }
+ else {
sprintf (buf, "LPT 0x%x%s%s%s", p->port,
(p->have_backlight?" bl":""),
(p->have_keypad?" key":""),
(p->have_output?" out":"")
);
+ }
HD44780_string (drvthis, 1, 2, buf);
HD44780_flush (drvthis);
sleep (2);
=2D-- docs/lcdproc-user/drivers/hd44780.docbook 2003-03-26 01:20:30.0000000=
00=20
+0100
+++ docs/lcdproc-user/drivers/hd44780.docbook 2004-09-04 18:19:58.000000000=
=20
+0200
@@ -1011,6 +1011,22 @@
=20
</sect3>
=20
+</sect3>
+
+<sect3 id=3D"hd44780-bwctusb">
+<title>BWCT USB device "bwctusb"</title>
+
+<para>
+The BWCT USB LCD module is also supported. It is not connected to the LPT=
=20
port
+but to an USB port, which saves you from a lot of potential problems.
+To use it, set the connection type in the config file with the=20
ConnectionType=3D
+setting to "bwctusb" (without the quotes).
+It does not support a keypad nor backlight switching but it supports setti=
ng
+the display's contrast using the "Contrast" configuration parameter.
+</para>
+
+</sect3>
+
</sect2>
=20
<sect2 id=3Dhd44780-compiling>
@@ -1067,6 +1083,10 @@
<entry>PIC-an-LCD serial device "picanlcd"</entry>
<entry>picanlcd</entry>
</row>
+<row>
+<entry>BWCT USB device "bwctusb"</entry>
+<entry>bwctusb</entry>
+</row>
</tbody>
</tgroup>
</table>
=2D-- server/drivers/hd44780-bwct-usb.c 1970-01-01 01:00:00.000000000 +0100
+++ server/drivers/hd44780-bwct-usb.c 2004-09-16 13:38:56.000000000 +0200
@@ -0,0 +1,135 @@
+/*
+ * USB driver module for Hitachi HD44780 based LCD displays.
+ * http://www.bwct.de/lcd.html
+ *
+ * Copyright (c) 2004, Bernd Walter
<bernd AT bwct.de>
+ * Contributions:
+ * Copyright (c) 2004, Peter Marschall <peter@adpm.d>
+ *
+ * This file is released under the GNU General Public License. Refer to the
+ * COPYING file distributed with this package.
+ *
+ */
+
+#include "hd44780-bwct-usb.h"
+#include "hd44780-low.h"
+
+#include "report.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <usb.h>
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include <errno.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+void bwct_usb_HD44780_senddata (PrivateData *p, unsigned char displayID,=20
unsigned char flags, unsigned char ch);
+void bwct_usb_HD44780_backlight (PrivateData *p, unsigned char state);
+unsigned char bwct_usb_HD44780_scankeypad (PrivateData *p);
+
+static int bwct_usb_i;
+static usb_dev_handle *bwct_usb;
+
+// initialise the driver
+int
+hd_init_bwct_usb (Driver *drvthis)
+{
+ PrivateData *p =3D (PrivateData*) drvthis->private_data;
+ struct usb_bus *busses;
+ struct usb_bus *bus;
+ int c, a;
+
+ p->hd44780_functions->senddata =3D bwct_usb_HD44780_senddata;
+ p->hd44780_functions->backlight =3D bwct_usb_HD44780_backlight;
+ p->hd44780_functions->scankeypad =3D bwct_usb_HD44780_scankeypad;
+
+#if 0
+ usb_debug =3D 2;
+#endif
+
+ usb_init();
+ usb_find_busses();
+ usb_find_devices();
+ busses =3D usb_get_busses();
+
+ bwct_usb =3D NULL;
+ for (bus =3D busses; bus; bus =3D bus->next) {
+ struct usb_device *dev;
+
+ for (dev =3D bus->devices; dev; dev =3D dev->next) {
+ /* Check if this device is a BWCT device */
+ if (dev->descriptor.idVendor !=3D 0x03da) {
+ continue;
+ }
+ /* Loop through all of the configurations */
+ for (c =3D 0; c < dev->descriptor.bNumConfigurations;
c++) {
+ /* Loop through all of the interfaces */
+ for (bwct_usb_i =3D 0; bwct_usb_i <
dev->config[c].bNumInterfaces;=20
bwct_usb_i++) {
+ /* Loop through all of the alternate
settings */
+ for (a =3D 0; a <
dev->config[c].interface[bwct_usb_i].num_altsetting=
;=20
a++) {
+ /* Check if this interface is
a ulcd */
+ if
((dev->config[c].interface[bwct_usb_i].altsetting[a].bInterfaceCl=
ass=20
=3D=3D 0xff &&
+ =20
dev->config[c].interface[bwct_usb_i].altsetting[a].bInterfaceSubClass =3D=
=3D=20
0x01) ||
+ dev->descriptor.idProduct
=3D=3D 0x0002) {
+ bwct_usb =3D
usb_open(dev);
+
usb_claim_interface(bwct_usb, bwct_usb_i);
+ goto done;
+ }
+ }
+ }
+ }
+ }
+ }
+ done:
+ if (bwct_usb =3D=3D NULL) {
+ printf("failed to open LCD device\n");
+ exit(1);
+ }
+
+ common_init (p, IF_4BIT);
+
+ /* set contrast */
+ if ((0 <=3D drvthis->config_get_int ( drvthis->name , "Contrast" , 0
,=20
DEFAULT_CONTRAST)) &&
+ (drvthis->config_get_int ( drvthis->name , "Contrast" , 0 ,=20
DEFAULT_CONTRAST) <=3D 1000)) {
+ int contrast =3D drvthis->config_get_int ( drvthis->name ,
"Contrast" , =
0 ,=20
DEFAULT_CONTRAST);
+ int res =3D usb_control_msg(bwct_usb, USB_TYPE_VENDOR,
VENDOR_LCD_CONTRA=
ST,=20
(contrast * 255) / 1000, bwct_usb_i, NULL, 0, 1000);
+ if (res < 0)
+ report (RPT_WARNING, "hd_init_bwct_usb: setting
contrast=
=20
failed.\n");
+ } else {
+ report (RPT_WARNING, "hd_init_bwct_usb: Contrast must betw=
een=20
0 and 1000. Using default value.\n");
+ }
+
+ return 0;
+}
+
+// bwct_usb_HD44780_senddata
+void
+bwct_usb_HD44780_senddata (PrivateData *p, unsigned char displayID, unsign=
ed=20
char flags, unsigned char ch)
+{
+
+ if (flags =3D=3D RS_DATA) {
+ usb_control_msg(bwct_usb, USB_TYPE_VENDOR, VENDOR_LCD_DATA,
ch, bwct_usb=
_i,=20
NULL, 0, 1000);
+ }
+ else {
+ usb_control_msg(bwct_usb, USB_TYPE_VENDOR, VENDOR_LCD_CMD,
ch, bwct_usb_=
i,=20
NULL, 0, 1000);
+ }
+}
+
+void
+bwct_usb_HD44780_backlight (PrivateData *p, unsigned char state)
+{
+}
+
+unsigned char
+bwct_usb_HD44780_scankeypad (PrivateData *p)
+{
+ return 0;
+}
=2D-- server/drivers/hd44780-bwct-usb.h 1970-01-01 01:00:00.000000000 +0100
+++ server/drivers/hd44780-bwct-usb.h 2004-05-28 18:39:36.000000000 +0200
@@ -0,0 +1,16 @@
+#ifndef HD_BWCT_USB_H
+#define HD_BWCT_USB_H
+
+#include "lcd.h" /* for Driver */
+
+#define VENDOR_LCD_RESET 1
+#define VENDOR_LCD_CMD 2
+#define VENDOR_LCD_DATA 3
+#define VENDOR_LCD_CONTRAST 4
+
+#define DEFAULT_CONTRAST 300
+
+// initialise this particular driver
+int hd_init_bwct_usb (Driver *drvthis);
+
+#endif




Archive powered by MHonArc 2.6.18.

Top of page