clean interface for sub-drivers wrt backlight, contrast and brightness

This commit is contained in:
marschap
2007-11-04 16:58:00 +00:00
parent 280a60d30f
commit 81bc865f1e
9 changed files with 109 additions and 71 deletions
+12 -19
View File
@@ -6,7 +6,7 @@
/* Copyright (c) 2004, Bernd Walter <bernd@bwct.de>
* Contributions:
* Copyright (c) 2004, Peter Marschall <peter@adpm.de>
* Copyright (c) 2004-7, Peter Marschall <peter@adpm.de>
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
@@ -33,6 +33,12 @@
#endif
// connection type specific functions to be exposed using pointers in init()
void bwct_usb_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void bwct_usb_HD44780_set_contrast(PrivateData *p, unsigned char value);
void bwct_usb_HD44780_close(PrivateData *p);
/**
* Initialize the driver.
* \param drvthis Pointer to driver structure.
@@ -51,7 +57,7 @@ hd_init_bwct_usb(Driver *drvthis)
p->hd44780_functions->senddata = bwct_usb_HD44780_senddata;
p->hd44780_functions->close = bwct_usb_HD44780_close;
drvthis->set_contrast = bwct_usb_set_contrast;
p->hd44780_functions->set_contrast = bwct_usb_HD44780_set_contrast;
/* Read config file's contents: serial number and contrast */
@@ -164,9 +170,6 @@ hd_init_bwct_usb(Driver *drvthis)
common_init(p, IF_4BIT);
/* set contrast: value comes from global init */
bwct_usb_set_contrast(drvthis, p->contrast);
return 0;
}
@@ -200,24 +203,14 @@ bwct_usb_HD44780_close(PrivateData *p)
/**
* Change LCD contrast.
* \param drvthis Pointer to driver structure.
* \param promille New contrast value in promille.
* \param value New contrast value (one byte).
*/
void
bwct_usb_set_contrast(Driver *drvthis, int promille)
bwct_usb_HD44780_set_contrast(PrivateData *p, unsigned char value)
{
PrivateData *p = drvthis->private_data;
// Check if value within range
if ((promille < 0) || (promille > 1000))
return;
// And set it (converted from [0,1000] -> [0,255]).
// If successful, update the local value.
if (usb_control_msg(p->usbHandle, USB_TYPE_VENDOR, BWCT_LCD_SET_CONTRAST,
(promille * 255) / 1000, p->usbIndex, NULL, 0, 1000) < 0)
report(RPT_WARNING, "hd_init_lcd2usb: setting contrast failed");
else
p->contrast = promille;
value, p->usbIndex, NULL, 0, 1000) < 0)
p->hd44780_functions->drv_report(RPT_WARNING, "bwct_usb_HD44780_set_contrast: setting contrast failed");
}
-4
View File
@@ -18,8 +18,4 @@
// 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_set_contrast(Driver *drvthis, int promille);
void bwct_usb_HD44780_close(PrivateData *p);
#endif
+17 -3
View File
@@ -32,7 +32,19 @@
# include "config.h"
#endif
// initialize the driver
// connection type specific functions to be exposed using pointers in init()
void ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void ftdi_HD44780_backlight(PrivateData *p, unsigned char state);
void ftdi_HD44780_close(PrivateData *p);
/**
* Initialize the driver.
* \param drvthis Pointer to driver structure.
* \retval 0 Success.
* \retval -1 Error.
*/
int
hd_init_ftdi(Driver *drvthis)
{
@@ -49,6 +61,7 @@ hd_init_ftdi(Driver *drvthis)
vendor_id = drvthis->config_get_int(drvthis->name, "VendorID", 0, 0x0403);
product_id = drvthis->config_get_int(drvthis->name, "ProductID", 0, 0x6001);
// these config settings are not documented intentionally
p->ftdi_line_RS = drvthis->config_get_int(drvthis->name, "ftdi_line_RS", 0, 0x01);
p->ftdi_line_RW = drvthis->config_get_int(drvthis->name, "ftdi_line_RW", 0, 0x02);
p->ftdi_line_EN = drvthis->config_get_int(drvthis->name, "ftdi_line_EN", 0, 0x04);
@@ -58,7 +71,7 @@ hd_init_ftdi(Driver *drvthis)
ftdi_init(&p->ftdic);
ftdi_set_interface(&p->ftdic, INTERFACE_A);
f = ftdi_usb_open(&p->ftdic, vendor_id, product_id);
if(f < 0 && f != -5) {
if (f < 0 && f != -5) {
report(RPT_ERR, "unable to open ftdi device: %d (%s)", f, ftdi_get_error_string(&p->ftdic));
return -1;
}
@@ -71,7 +84,7 @@ hd_init_ftdi(Driver *drvthis)
ftdi_init(&p->ftdic2);
ftdi_set_interface(&p->ftdic2, INTERFACE_B);
f = ftdi_usb_open(&p->ftdic2, vendor_id, product_id);
if(f < 0 && f != -5) {
if (f < 0 && f != -5) {
report(RPT_ERR, "unable to open second ftdi device: %d (%s)", f, ftdi_get_error_string(&p->ftdic2));
return -2;
}
@@ -89,6 +102,7 @@ hd_init_ftdi(Driver *drvthis)
return 0;
}
// ftdi_HD44780_senddata
void
ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch)
-4
View File
@@ -7,8 +7,4 @@
// initialise this particular driver
int hd_init_ftdi(Driver *drvthis);
void ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void ftdi_HD44780_backlight(PrivateData *p, unsigned char state);
void ftdi_HD44780_close(PrivateData *p);
#endif
+13 -19
View File
@@ -25,6 +25,14 @@
#endif
// connection type specific functions to be exposed using pointers in init()
void lcd2usb_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void lcd2usb_HD44780_backlight(PrivateData *p, unsigned char state);
unsigned char lcd2usb_HD44780_scankeypad(PrivateData *p);
void lcd2usb_HD44780_close(PrivateData *p);
void lcd2usb_HD44780_set_contrast(PrivateData *p, unsigned char value);
/**
* Initialize the driver.
* \param drvthis Pointer to driver structure.
@@ -42,8 +50,7 @@ hd_init_lcd2usb(Driver *drvthis)
p->hd44780_functions->backlight = lcd2usb_HD44780_backlight;
p->hd44780_functions->scankeypad = lcd2usb_HD44780_scankeypad;
p->hd44780_functions->close = lcd2usb_HD44780_close;
drvthis->set_contrast = lcd2usb_set_contrast;
drvthis->set_brightness = lcd2usb_set_brightness;
p->hd44780_functions->set_contrast = lcd2usb_HD44780_set_contrast;
/* try to find USB device */
#if 0
@@ -91,9 +98,6 @@ hd_init_lcd2usb(Driver *drvthis)
common_init(p, IF_4BIT);
/* set contrast: value comes from global hd44780 init */
lcd2usb_set_contrast(drvthis, p->contrast);
return 0;
}
@@ -136,24 +140,14 @@ lcd2usb_HD44780_backlight(PrivateData *p, unsigned char state)
/**
* Change LCD contrast.
* \param drvthis Pointer to driver structure.
* \param promille New contrast value in promille.
* \param value New contrast value (one byte).
*/
void
lcd2usb_set_contrast(Driver *drvthis, int promille)
lcd2usb_HD44780_set_contrast(PrivateData *p, unsigned char value)
{
PrivateData *p = drvthis->private_data;
// Check if value within range
if ((promille < 0) || (promille > 1000))
return;
// And set it (converted from [0,1000] -> [0,255]).
// If successful, update the local value.
if (usb_control_msg(p->usbHandle, USB_TYPE_VENDOR, LCD2USB_SET_CONTRAST,
(promille * 255) / 1000, 0, NULL, 0, 1000) < 0)
report(RPT_WARNING, "hd_init_lcd2usb: setting contrast failed");
else
p->contrast = promille;
value, 0, NULL, 0, 1000) < 0)
p->hd44780_functions->drv_report(RPT_WARNING, "lcd2usb_HD44780_set_contrast: setting contrast failed");
}
-8
View File
@@ -34,12 +34,4 @@
// initialise this particular driver
int hd_init_lcd2usb(Driver *drvthis);
void lcd2usb_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void lcd2usb_HD44780_backlight(PrivateData *p, unsigned char state);
unsigned char lcd2usb_HD44780_scankeypad(PrivateData *p);
void lcd2usb_HD44780_close(PrivateData *p);
void lcd2usb_set_contrast(Driver *drvthis, int promille);
void lcd2usb_set_brightness(Driver *drvthis, int state, int promille);
#endif
+1 -5
View File
@@ -195,6 +195,7 @@ typedef struct driver_private_data {
typedef struct hwDependentFns {
// microsec pauses
void (*uPause)(PrivateData *p, int usecs);
// report and debug helper: set by global hd44780 init
void (*drv_report)(const int level, const char *format, .../*args*/);
void (*drv_debug)(const int level, const char *format, .../*args*/);
@@ -213,11 +214,6 @@ typedef struct hwDependentFns {
// value - new value to be set
void (*set_contrast)(PrivateData *p, unsigned char value);
// Switch the backlight on or off
// state - backlight state to set the new value for
// value - new value to be set
void (*set_brightness)(PrivateData *p, int backlight, unsigned char value);
// Read the keypad
// Ydata - the up to 11 bits that should be put on the Y side of the matrix
// return - the up to 5 bits that are read out on the X side of the matrix
+64 -7
View File
@@ -37,13 +37,16 @@
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
*
* Copyright (c) 2000, 1999, 1995 Benjamin Tse <blt@Comports.com>
* 2001 Joris Robijn <joris@robijn.net>
* 2001 Mark Haemmerling <mail@markh.de>
* 2000 Charles Steinkuehler <cstein@newtek.com>
* 1999 Andrew McMeikan <andrewm@engineer.com>
* 1998 Richard Rognlie <rrognlie@gamerz.net>
* Copyright (c) 1995,1999,2000 Benjamin Tse <blt@Comports.com>
* 1997 Matthias Prinke <m.prinke@trashcan.mcnet.de>
* 1998 Richard Rognlie <rrognlie@gamerz.net>
* 1999 Andrew McMeikan <andrewm@engineer.com>
* 2000 Charles Steinkuehler <cstein@newtek.com>
* 2001 Joris Robijn <joris@robijn.net>
* 2001 Guillaume Filion <gfk@logidac.com>
* 2001 Mark Haemmerling <mail@markh.de>
* 2006 Matteo Pillon <matteo.pillon@email.it>
* 2007 Peter Marschall <peter@adpm.de>
*/
@@ -374,7 +377,6 @@ HD44780_init(Driver *drvthis)
p->hd44780_functions->senddata = NULL;
p->hd44780_functions->backlight = NULL;
p->hd44780_functions->set_contrast = NULL;
p->hd44780_functions->set_brightness = NULL;
p->hd44780_functions->readkeypad = NULL;
p->hd44780_functions->scankeypad = NULL;
p->hd44780_functions->output = NULL;
@@ -408,6 +410,8 @@ HD44780_init(Driver *drvthis)
if (p->hd44780_functions->output == NULL)
p->have_output = 0;
// set contrast
HD44780_set_contrast(drvthis, p->contrast);
// Display startup parameters on the LCD
HD44780_clear(drvthis);
@@ -759,6 +763,33 @@ HD44780_get_contrast(Driver *drvthis)
}
/**
* Change LCD contrast.
* \param drvthis Pointer to driver structure.
* \param promille New contrast value in promille.
*/
MODULE_EXPORT void
HD44780_set_contrast (Driver *drvthis, int promille)
{
PrivateData *p = drvthis->private_data;
unsigned char contrast_byte;
/* Check it */
if (promille < 0 || promille > 1000)
return;
/* store the software value since there is not get */
p->contrast = promille;
/* map range [0, 1000] -> [0, 255] (for one byte)) */
contrast_byte = (255 * promille) / 1000;
/* call local function */
if (p->hd44780_functions->set_contrast != NULL)
p->hd44780_functions->set_contrast(p, contrast_byte);
}
/**
* Retrieve brightness.
* \param drvthis Pointer to driver structure.
@@ -774,6 +805,32 @@ HD44780_get_brightness(Driver *drvthis, int state)
}
/**
* Set on/off brightness.
* \param drvthis Pointer to driver structure.
* \param state Brightness state (on/off) for which we want to store the value.
* \param promille New brightness in promille.
*/
MODULE_EXPORT void
HD44780_set_brightness(Driver *drvthis, int state, int promille)
{
PrivateData *p = drvthis->private_data;
/* Check it */
if (promille < 0 || promille > 1000)
return;
/* store the software value since there is not get */
if (state == BACKLIGHT_ON) {
p->brightness = promille;
}
else {
p->offbrightness = promille;
}
//HD44780_backlight(drvthis, state);
}
/**
* Turn the LCD backlight on or off.
* \param drvthis Pointer to driver structure.
+2 -2
View File
@@ -39,9 +39,9 @@ MODULE_EXPORT void HD44780_set_char(Driver *drvthis, int n, unsigned char *dat);
MODULE_EXPORT int HD44780_get_free_chars(Driver *drvthis);
MODULE_EXPORT int HD44780_get_contrast(Driver *drvthis);
//MODULE_EXPORT void HD44780_set_contrast(Driver *drvthis, int promille);
MODULE_EXPORT void HD44780_set_contrast(Driver *drvthis, int promille);
MODULE_EXPORT int HD44780_get_brightness(Driver *drvthis, int state);
//MODULE_EXPORT void HD44780_set_brightness(Driver *drvthis, int state, int promille);
MODULE_EXPORT void HD44780_set_brightness(Driver *drvthis, int state, int promille);
MODULE_EXPORT void HD44780_backlight(Driver *drvthis, int on);
MODULE_EXPORT void HD44780_output(Driver *drvthis, int state);