clean interface for sub-drivers wrt backlight, contrast and brightness
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
/* Copyright (c) 2004, Bernd Walter <bernd@bwct.de>
|
/* Copyright (c) 2004, Bernd Walter <bernd@bwct.de>
|
||||||
* Contributions:
|
* 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
|
* This file is released under the GNU General Public License. Refer to the
|
||||||
* COPYING file distributed with this package.
|
* COPYING file distributed with this package.
|
||||||
@@ -33,6 +33,12 @@
|
|||||||
#endif
|
#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.
|
* Initialize the driver.
|
||||||
* \param drvthis Pointer to driver structure.
|
* \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->senddata = bwct_usb_HD44780_senddata;
|
||||||
p->hd44780_functions->close = bwct_usb_HD44780_close;
|
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 */
|
/* Read config file's contents: serial number and contrast */
|
||||||
|
|
||||||
@@ -164,9 +170,6 @@ hd_init_bwct_usb(Driver *drvthis)
|
|||||||
|
|
||||||
common_init(p, IF_4BIT);
|
common_init(p, IF_4BIT);
|
||||||
|
|
||||||
/* set contrast: value comes from global init */
|
|
||||||
bwct_usb_set_contrast(drvthis, p->contrast);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,24 +203,14 @@ bwct_usb_HD44780_close(PrivateData *p)
|
|||||||
/**
|
/**
|
||||||
* Change LCD contrast.
|
* Change LCD contrast.
|
||||||
* \param drvthis Pointer to driver structure.
|
* \param drvthis Pointer to driver structure.
|
||||||
* \param promille New contrast value in promille.
|
* \param value New contrast value (one byte).
|
||||||
*/
|
*/
|
||||||
void
|
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,
|
if (usb_control_msg(p->usbHandle, USB_TYPE_VENDOR, BWCT_LCD_SET_CONTRAST,
|
||||||
(promille * 255) / 1000, p->usbIndex, NULL, 0, 1000) < 0)
|
value, p->usbIndex, NULL, 0, 1000) < 0)
|
||||||
report(RPT_WARNING, "hd_init_lcd2usb: setting contrast failed");
|
p->hd44780_functions->drv_report(RPT_WARNING, "bwct_usb_HD44780_set_contrast: setting contrast failed");
|
||||||
else
|
|
||||||
p->contrast = promille;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,4 @@
|
|||||||
// initialise this particular driver
|
// initialise this particular driver
|
||||||
int hd_init_bwct_usb(Driver *drvthis);
|
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
|
#endif
|
||||||
|
|||||||
@@ -32,7 +32,19 @@
|
|||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#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
|
int
|
||||||
hd_init_ftdi(Driver *drvthis)
|
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);
|
vendor_id = drvthis->config_get_int(drvthis->name, "VendorID", 0, 0x0403);
|
||||||
product_id = drvthis->config_get_int(drvthis->name, "ProductID", 0, 0x6001);
|
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_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_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);
|
p->ftdi_line_EN = drvthis->config_get_int(drvthis->name, "ftdi_line_EN", 0, 0x04);
|
||||||
@@ -89,6 +102,7 @@ hd_init_ftdi(Driver *drvthis)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ftdi_HD44780_senddata
|
// ftdi_HD44780_senddata
|
||||||
void
|
void
|
||||||
ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch)
|
ftdi_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch)
|
||||||
|
|||||||
@@ -7,8 +7,4 @@
|
|||||||
// initialise this particular driver
|
// initialise this particular driver
|
||||||
int hd_init_ftdi(Driver *drvthis);
|
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
|
#endif
|
||||||
|
|||||||
@@ -25,6 +25,14 @@
|
|||||||
#endif
|
#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.
|
* Initialize the driver.
|
||||||
* \param drvthis Pointer to driver structure.
|
* \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->backlight = lcd2usb_HD44780_backlight;
|
||||||
p->hd44780_functions->scankeypad = lcd2usb_HD44780_scankeypad;
|
p->hd44780_functions->scankeypad = lcd2usb_HD44780_scankeypad;
|
||||||
p->hd44780_functions->close = lcd2usb_HD44780_close;
|
p->hd44780_functions->close = lcd2usb_HD44780_close;
|
||||||
drvthis->set_contrast = lcd2usb_set_contrast;
|
p->hd44780_functions->set_contrast = lcd2usb_HD44780_set_contrast;
|
||||||
drvthis->set_brightness = lcd2usb_set_brightness;
|
|
||||||
|
|
||||||
/* try to find USB device */
|
/* try to find USB device */
|
||||||
#if 0
|
#if 0
|
||||||
@@ -91,9 +98,6 @@ hd_init_lcd2usb(Driver *drvthis)
|
|||||||
|
|
||||||
common_init(p, IF_4BIT);
|
common_init(p, IF_4BIT);
|
||||||
|
|
||||||
/* set contrast: value comes from global hd44780 init */
|
|
||||||
lcd2usb_set_contrast(drvthis, p->contrast);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,24 +140,14 @@ lcd2usb_HD44780_backlight(PrivateData *p, unsigned char state)
|
|||||||
/**
|
/**
|
||||||
* Change LCD contrast.
|
* Change LCD contrast.
|
||||||
* \param drvthis Pointer to driver structure.
|
* \param drvthis Pointer to driver structure.
|
||||||
* \param promille New contrast value in promille.
|
* \param value New contrast value (one byte).
|
||||||
*/
|
*/
|
||||||
void
|
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,
|
if (usb_control_msg(p->usbHandle, USB_TYPE_VENDOR, LCD2USB_SET_CONTRAST,
|
||||||
(promille * 255) / 1000, 0, NULL, 0, 1000) < 0)
|
value, 0, NULL, 0, 1000) < 0)
|
||||||
report(RPT_WARNING, "hd_init_lcd2usb: setting contrast failed");
|
p->hd44780_functions->drv_report(RPT_WARNING, "lcd2usb_HD44780_set_contrast: setting contrast failed");
|
||||||
else
|
|
||||||
p->contrast = promille;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,12 +34,4 @@
|
|||||||
// initialise this particular driver
|
// initialise this particular driver
|
||||||
int hd_init_lcd2usb(Driver *drvthis);
|
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
|
#endif
|
||||||
|
|||||||
@@ -195,6 +195,7 @@ typedef struct driver_private_data {
|
|||||||
typedef struct hwDependentFns {
|
typedef struct hwDependentFns {
|
||||||
// microsec pauses
|
// microsec pauses
|
||||||
void (*uPause)(PrivateData *p, int usecs);
|
void (*uPause)(PrivateData *p, int usecs);
|
||||||
|
|
||||||
// report and debug helper: set by global hd44780 init
|
// report and debug helper: set by global hd44780 init
|
||||||
void (*drv_report)(const int level, const char *format, .../*args*/);
|
void (*drv_report)(const int level, const char *format, .../*args*/);
|
||||||
void (*drv_debug)(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
|
// value - new value to be set
|
||||||
void (*set_contrast)(PrivateData *p, unsigned char value);
|
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
|
// Read the keypad
|
||||||
// Ydata - the up to 11 bits that should be put on the Y side of the matrix
|
// 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
|
// return - the up to 5 bits that are read out on the X side of the matrix
|
||||||
|
|||||||
@@ -37,13 +37,16 @@
|
|||||||
* This file is released under the GNU General Public License. Refer to the
|
* This file is released under the GNU General Public License. Refer to the
|
||||||
* COPYING file distributed with this package.
|
* COPYING file distributed with this package.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2000, 1999, 1995 Benjamin Tse <blt@Comports.com>
|
* Copyright (c) 1995,1999,2000 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>
|
|
||||||
* 1997 Matthias Prinke <m.prinke@trashcan.mcnet.de>
|
* 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->senddata = NULL;
|
||||||
p->hd44780_functions->backlight = NULL;
|
p->hd44780_functions->backlight = NULL;
|
||||||
p->hd44780_functions->set_contrast = NULL;
|
p->hd44780_functions->set_contrast = NULL;
|
||||||
p->hd44780_functions->set_brightness = NULL;
|
|
||||||
p->hd44780_functions->readkeypad = NULL;
|
p->hd44780_functions->readkeypad = NULL;
|
||||||
p->hd44780_functions->scankeypad = NULL;
|
p->hd44780_functions->scankeypad = NULL;
|
||||||
p->hd44780_functions->output = NULL;
|
p->hd44780_functions->output = NULL;
|
||||||
@@ -408,6 +410,8 @@ HD44780_init(Driver *drvthis)
|
|||||||
if (p->hd44780_functions->output == NULL)
|
if (p->hd44780_functions->output == NULL)
|
||||||
p->have_output = 0;
|
p->have_output = 0;
|
||||||
|
|
||||||
|
// set contrast
|
||||||
|
HD44780_set_contrast(drvthis, p->contrast);
|
||||||
|
|
||||||
// Display startup parameters on the LCD
|
// Display startup parameters on the LCD
|
||||||
HD44780_clear(drvthis);
|
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.
|
* Retrieve brightness.
|
||||||
* \param drvthis Pointer to driver structure.
|
* \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.
|
* Turn the LCD backlight on or off.
|
||||||
* \param drvthis Pointer to driver structure.
|
* \param drvthis Pointer to driver structure.
|
||||||
|
|||||||
@@ -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_free_chars(Driver *drvthis);
|
||||||
|
|
||||||
MODULE_EXPORT int HD44780_get_contrast(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 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_backlight(Driver *drvthis, int on);
|
||||||
MODULE_EXPORT void HD44780_output(Driver *drvthis, int state);
|
MODULE_EXPORT void HD44780_output(Driver *drvthis, int state);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user