add ConnectionType sub-driver for BWCT USB devices to the HD44780 driver

This commit is contained in:
marschap
2004-10-09 16:15:37 +00:00
parent 885fa75470
commit 11fe596351
8 changed files with 394 additions and 10 deletions
+6 -3
View File
@@ -21,15 +21,18 @@ pkglib_PROGRAMS = @DRIVERS@
EXTRA_PROGRAMS = bayrad CFontz CFontz633 curses CwLnx glk hd44780 irman icp_a106 joy lb216 mtc_s16209x lcdm001 lcterm lirc MtxOrb sed1330 sed1520 stv5730 svga t6963 text wirz_sli ms6931 IOWarrior
noinst_LIBRARIES = libLCD.a
IOWarrior_CFLAGS = @libusb_cflags@
hd44780_CFLAGS = @libusb_cflags@
CFontz_LDADD = libLCD.a
CFontz633_LDADD = libLCD.a
curses_LDADD = @LIBCURSES@
CwLnx_LDADD = libLCD.a
CwLnx_SOURCES = lcd.h CwLnx.c CwLnx.h report.h
hd44780_LDADD = libLCD.a @HD44780_DRIVERS@
hd44780_LDADD = libLCD.a @HD44780_DRIVERS@ @libusb_libs@
hd44780_DEPENDENCIES = @HD44780_DRIVERS@
icp_a106_LDADD = libLCD.a
IOWarrior_LDADD = @LIBUSB@ libLCD.a
IOWarrior_LDADD = @libusb_libs@ libLCD.a
irman_LDADD = @LIBIRMAN@
lirc_LDADD = @LIBLIRC_CLIENT@
lcterm_LDADD = libLCD.a
@@ -44,7 +47,7 @@ CFontz633_SOURCES = lcd.h CFontz633.c CFontz633.h CFontz633io.c CFontz633io.h r
curses_SOURCES = lcd.h curses_drv.h curses_drv.c report.h
glk_SOURCES = lcd.h glk.c glk.h glkproto.c glkproto.h report.h
hd44780_SOURCES = lcd.h hd44780.h hd44780.c hd44780-drivers.h hd44780-low.h hd44780-charmap.h report.h
EXTRA_hd44780_SOURCES = hd44780-4bit.c hd44780-4bit.h hd44780-ext8bit.c hd44780-ext8bit.h lcd_sem.c lcd_sem.h hd44780-serialLpt.c hd44780-serialLpt.h hd44780-winamp.c hd44780-winamp.h hd44780-picanlcd.c hd44780-picanlcd.h port.h lpt-port.h timing.h
EXTRA_hd44780_SOURCES = hd44780-4bit.c hd44780-4bit.h hd44780-ext8bit.c hd44780-ext8bit.h lcd_sem.c lcd_sem.h hd44780-serialLpt.c hd44780-serialLpt.h hd44780-winamp.c hd44780-winamp.h hd44780-picanlcd.c hd44780-picanlcd.h hd44780-bwct-usb.c hd44780-bwct-usb.h port.h lpt-port.h timing.h
icp_a106_SOURCES = lcd.h icp_a106.c icp_a106.h report.h
IOWarrior_SOURCES = lcd.h lcd_lib.h hd44780-charmap.h IOWarrior.c IOWarrior.h report.h
+202
View File
@@ -0,0 +1,202 @@
/*
* USB driver module for Hitachi HD44780 based LCD displays.
* http://www.bwct.de/lcd.html
*
* Copyright (c) 2004, Bernd Walter <bernd@bwct.de>
* Contributions:
* Copyright (c) 2004, Peter Marschall <peter@adpm.de>
*
* 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 "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
/* USB device handle & interface index we write to */
static usb_dev_handle *bwct_usb;
static int bwct_usb_i;
// initialize the driver
int
hd_init_bwct_usb (Driver *drvthis)
{
PrivateData *p = (PrivateData*) drvthis->private_data;
struct usb_bus *busses;
struct usb_bus *bus;
char device_manufacturer[LCD_MAX_WIDTH+1] = "";
char device_serial[LCD_MAX_WIDTH+1] = DEFAULT_SERIALNO;
char serial[LCD_MAX_WIDTH+1] = DEFAULT_SERIALNO;
int contrast = -1; /* illegal contrast value (to detect errors) */
p->hd44780_functions->senddata = bwct_usb_HD44780_senddata;
p->hd44780_functions->backlight = bwct_usb_HD44780_backlight;
p->hd44780_functions->scankeypad = bwct_usb_HD44780_scankeypad;
/* Read config file's contents: serial number and contrast */
strncpy(serial, drvthis->config_get_string(drvthis->name, "SerialNumber",
0, DEFAULT_SERIALNO), sizeof(serial));
serial[sizeof(serial)-1] = '\0';
if (*serial != '\0') {
report(RPT_INFO, "hd_init_bwct_usb: Using serial number: %s", serial);
}
contrast = drvthis->config_get_int(drvthis->name, "Contrast", 0, DEFAULT_CONTRAST);
/* try to find USB device */
#if 0
usb_debug = 2;
#endif
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
bwct_usb = NULL;
for (bus = busses; bus; bus = bus->next) {
struct usb_device *dev;
for (dev = bus->devices; dev; dev = dev->next) {
int c;
/* Check if this device is a BWCT device */
if (dev->descriptor.idVendor != 0x03DA) {
continue;
}
/* Loop through all of the configurations */
for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
/* Loop through all of the interfaces */
for (bwct_usb_i = 0; bwct_usb_i < dev->config[c].bNumInterfaces; bwct_usb_i++) {
int a;
/* Loop through all of the alternate settings */
for (a = 0; a < dev->config[c].interface[bwct_usb_i].num_altsetting; a++) {
/* Check if this interface is a BWCT ulcd */
if (((dev->config[c].interface[bwct_usb_i].altsetting[a].bInterfaceClass == 0xFf) &&
(dev->config[c].interface[bwct_usb_i].altsetting[a].bInterfaceSubClass == 0x01)) ||
(dev->descriptor.idProduct == 0x0002)) {
/* BWCT device found; try to find its description and serial number */
bwct_usb = usb_open(dev);
if (bwct_usb == NULL) {
report(RPT_WARNING, "hd_init_bwct_usb: unable to open device");
// return -1; /* it's better to continue */
}
else {
/* get device information & check for serial number */
//if (usb_get_string_simple(bwct_usb, dev->descriptor.iManufacturer,
// manufacturer, LCD_MAX_WIDTH) <= 0)
// *manufacturer = '\0';
//manufacturer[sizeof(manufacturer)-1] = '\0';
//if (usb_get_string_simple(bwct_usb, dev->descriptor.iProduct,
// product, LCD_MAX_WIDTH) <= 0)
// *product = '\0';
//product[sizeof(product)-1] = '\0';
if (usb_get_string_simple(bwct_usb, dev->descriptor.iSerialNumber,
device_serial, LCD_MAX_WIDTH) <= 0)
*device_serial = '\0';
device_serial[sizeof(device_serial)-1] = '\0';
if ((*serial != '\0') && (*device_serial == '\0')) {
report(RPT_ERR, "hd_init_bwct_usb: unable to get device's serial number");
usb_close(bwct_usb);
return -1;
}
/* succeed if no serial was given in the config or the 2 numbers match */
if ((*serial == '\0') || (strcmp(serial, device_serial) == 0))
goto done;
usb_close(bwct_usb);
bwct_usb = NULL;
}
}
}
}
}
}
}
done:
if (bwct_usb != NULL) {
debug(RPT_DEBUG, "hd_init_bwct_usb: opening device succeeded\n");
if (usb_claim_interface(bwct_usb, bwct_usb_i) < 0) {
#if defined(LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP)
if ((usb_detach_kernel_driver_np(bwct_usb, bwct_usb_i) < 0) ||
(usb_claim_interface(bwct_usb, bwct_usb_i) < 0)) {
usb_close(bwct_usb);
report(RPT_ERR, "hd_init_bwct_usb: unable to re-claim interface");
return -1;
}
#else
usb_close(bwct_usb);
report(RPT_ERR, "hd_init_bwct_usb: unable to claim interface");
return -1;
#endif
}
}
else {
report(RPT_ERR, "hd_init_bwct_usb: no (matching) BWCT device found");
return -1;
}
common_init(p, IF_4BIT);
/* set contrast */
if ((0 <= contrast) && (contrast <= 1000)) {
int res = usb_control_msg(bwct_usb, USB_TYPE_VENDOR, VENDOR_LCD_CONTRAST,
(contrast * 255) / 1000, bwct_usb_i, NULL, 0, 1000);
if (res < 0)
report(RPT_WARNING, "hd_init_bwct_usb: setting contrast failed.\n");
} else {
report(RPT_WARNING, "hd_init_bwct_usb: Using default contrast value.\n");
}
return 0;
}
// bwct_usb_HD44780_senddata
void
bwct_usb_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch)
{
int type = (flags == RS_DATA) ? VENDOR_LCD_DATA : VENDOR_LCD_CMD;
usb_control_msg(bwct_usb, USB_TYPE_VENDOR, type, ch, bwct_usb_i, NULL, 0, 1000);
}
void
bwct_usb_HD44780_backlight(PrivateData *p, unsigned char state)
{
}
unsigned char
bwct_usb_HD44780_scankeypad(PrivateData *p)
{
return 0;
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef HD_BWCT_USB_H
#define HD_BWCT_USB_H
#include "lcd.h" /* for Driver */
#include "hd44780-low.h"
#define VENDOR_LCD_RESET 1
#define VENDOR_LCD_CMD 2
#define VENDOR_LCD_DATA 3
#define VENDOR_LCD_CONTRAST 4
#define DEFAULT_SERIALNO ""
#define DEFAULT_CONTRAST 300
// initialise this particular driver
int hd_init_bwct_usb(Driver *drvthis);
void bwct_usb_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void bwct_usb_HD44780_backlight(PrivateData *p, unsigned char state);
unsigned char bwct_usb_HD44780_scankeypad(PrivateData *p);
#endif
+6
View File
@@ -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
@@ -32,6 +35,9 @@ static const ConnectionMapping connectionMapping[] = {
{"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}
+14
View File
@@ -129,6 +129,7 @@ HD44780_init (Driver * drvthis, char *args)
char buf[40];
char *s;
int i;
int usb = 0;
PrivateData *p;
// Alocate and store private data
@@ -163,6 +164,10 @@ HD44780_init (Driver * drvthis, char *args)
return -1; // fatal error
} else {
p->connectiontype_index = i;
# check if ConnectionType contains the string "USB" or "usb"
if ((strstr(connectionMapping[i].name, "usb") != NULL) ||
(strstr(connectionMapping[i].name, "USB") != NULL))
usb = 1;
}
// Get and parse vspan only when specified
@@ -302,11 +307,20 @@ HD44780_init (Driver * drvthis, char *args)
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);