Skip to content

Commit

Permalink
hd44780: added handling of backlight using internal commands
Browse files Browse the repository at this point in the history
Added handling of backlight using internal commands of WINSTAR
OLED and PT6314_VFD models, where brightness can be set.

Make this the default value of Backlight for Winstar and VFD Models, as it
seems to be wanted behaviour.
  • Loading branch information
mskalski authored and haraldg committed Oct 9, 2017
1 parent c25ffed commit bf717f1
Show file tree
Hide file tree
Showing 13 changed files with 491 additions and 66 deletions.
35 changes: 33 additions & 2 deletions LCDd.conf
Expand Up @@ -584,8 +584,38 @@ Keypad=no
# [default: 300; legal: 0 - 1000]
#OffBrightness=0

# If you have a switchable backlight.
Backlight=no
# Specify if you have a switchable backlight and if yes, can select method for turning it on/off:
#
# - none - no switchable backlight is available. For compability also boolean
# 0, n, no, off and false are aliases.
# - external - use external pin or any other method defined with ConnectionType backlight
# handling. For backward compability also this value is chosen for boolean
# TRUE values: 1, y, yes, on and true.
# - internal - means that backlight is handled using internal commands according
# to selected display model (with Model option). Depending on model,
# Brightness and OffBrightness options can be taken into account.
# - internalCmds - means that commands for turning on and off backlight are given
# with extra options BacklightOnCmd and BacklightOffCmd, which would be treated
# as catch up (last resort) for other types of displays which have similar features.
#
# You can provide multiple occurences of this option to use more than one method.
# Default is model specific: Winstar OLED and PT6314 VFD enables internal backlight mode,
# for others it is set to none.
#Backlight = none

# Commands for enabling internal backlight for use with Backlight=internalCmds.
# Up to 4 bytes can be encoded, as integer number in big-endian order.
#
# NOTE: this is advanced option, if command contains bits other than only brighness handling,
# they must be set accordingly to not disrupt display state. If for example 'FUNCTION SET' command
# is used for this purpose, bits of interface length (4-bit / 8-bit) must be set according to
# selected ConnectionType.
#BacklightCmdOn=0x1223

# Commands for disabling internal backlight for use with Backlight=internalCmds.
# Up to 4 bytes can be encoded, as integer number in big-endian order.
#BacklightCmdOff=0x1234


# If you have the additional output port ("bargraph") and you want to
# be able to control it with the lcdproc OUTPUT command
Expand All @@ -609,6 +639,7 @@ Size=20x4
# As an additional restriction, controllers with and without extended mode
# AND 4 lines cannot be mixed for those connection types that support more
# than one display!
# NOTE: This option is deprecated in favour of choosing Model=extended option.
#ExtendedMode=yes

# In extended mode, on some controllers like the ST7036 (in 3 line mode)
Expand Down
79 changes: 77 additions & 2 deletions docs/lcdproc-user/drivers/hd44780.docbook
Expand Up @@ -3771,10 +3771,85 @@ This can be done by specifying <option>--enable-drivers=all</option> or by inclu

<varlistentry>
<term>
<property>Backlight</property> = &parameters.yesnodef;
<property>Backlight</property> =
{
<emphasis><parameter><literal>none</literal></parameter></emphasis> |
<parameter><literal>external</literal></parameter> |
<parameter><literal>internal</literal></parameter> |
<parameter><literal>internalCmds</literal></parameter>
}
</term>
<listitem>
<para>
Specify if you have a switchable backlight and if yes, can select method for
turning it on/off:
<itemizedlist>
<listitem><para>
<literal>none</literal> - no switchable backlight is available.
For compability also boolean <literal>0</literal>, <literal>n</literal>,
<literal>no</literal>, <literal>off</literal> and <literal>false</literal> are aliases.
</para></listitem>
<listitem><para>
<literal>external</literal> - use external pin or any other method defined with <literal>ConnectionType</literal>
backlight handling. For backward compability also this value is chosen for boolean TRUE values:
<literal>1</literal>, <literal>y</literal>, <literal>yes</literal>, <literal>on</literal> and <literal>true</literal>.
</para></listitem>
<listitem><para>
<literal>internal</literal> means that backlight is handled using internal commands according to
selected display model (with <literal>Model</literal> option).
Depending on model, <literal>Brightness</literal> and <literal>OffBrightness</literal> options can be taken into account.
</para></listitem>
<listitem>
<para>
<literal>internalCmds</literal> means that commands for turning on and off backlight are given with
extra options <literal>BacklightOnCmd</literal> and <literal>BacklightOffCmd</literal>,
which would be treated as catch up (last resort) for other types of displays which have similar features.
</para>
</listitem>
</itemizedlist>
</para>
<para>
You can provide multiple occurences of this option to use more than one method.
This can be useful for example for glowing buttons with external pin when backlight is on and
using internal command to set high brightness of display.
</para>
<para>
Default is model specific (depends on <literal>Model</literal> option): Winstar OLED and PT6314 VFD
enables <literal>internal</literal> backlight mode, for others it is set to <literal>none</literal>.
</para>
</listitem>
</varlistentry>


<varlistentry>
<term>
<property>BacklightCmdOn</property> =
<parameter><replaceable>COMMAND(s)</replaceable></parameter>
</term>
<listitem><para>
Commands for enabling internal backlight for use with <literal>Backlight=internalCmds</literal>.
Up to 4 bytes can be encoded, as integer number (hex) in big-endian order.
Ignored if <literal>Backlight</literal> does not specify <literal>internalCmds</literal>,
required otherwise.
</para>
<note><para>
This is advanced option, if command contains bits other than only brighness handling, they must be
set accordingly to not disrupt display state. If for example 'FUNCTION SET' command is used for this
purpose, bits of interface length (4-bit / 8-bit) must be set according to selected ConnectionType.
</para></note>
</listitem>
</varlistentry>

<varlistentry>
<term>
<property>BacklightCmdOff</property> =
<parameter><replaceable>COMMAND(s)</replaceable></parameter>
</term>
<listitem><para>
Specify if you have a switchable backlight.
Commands for disabling internal backlight for use with <literal>Backlight=internalCmds</literal>.
Up to 4 bytes can be encoded, as integer number (hex) in big-endian order.
Ignored if <literal>Backlight</literal> does not specify <literal>internalCmds</literal>,
required otherwise. See above note about <literal>BacklightCmdOn</literal>.
</para></listitem>
</varlistentry>

Expand Down
4 changes: 2 additions & 2 deletions server/drivers/hd44780-4bit.c
Expand Up @@ -262,7 +262,7 @@ lcdstat_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char
*/
void lcdstat_HD44780_backlight(PrivateData *p, unsigned char state)
{
p->backlight_bit = ((!p->have_backlight||state)?0:BL);
p->backlight_bit = ((have_backlight_pin(p)||state)?0:BL);

port_out(p->port, p->backlight_bit);
}
Expand All @@ -279,7 +279,7 @@ unsigned char lcdstat_HD44780_readkeypad(PrivateData *p, unsigned int YData)
unsigned char readval;

/* If at most two controllers and NO backlight, 10 bits may be used */
if ((p->numDisplays <= 2) && (!p->have_backlight)) {
if ((p->numDisplays <= 2) && (have_backlight_pin(p))) {
port_out(p->port, ~YData & 0x003F);
port_out(p->port + 2, (((~YData & 0x03C0) >> 6)) ^ OUTMASK);
}
Expand Down
2 changes: 1 addition & 1 deletion server/drivers/hd44780-ext8bit.c
Expand Up @@ -181,7 +181,7 @@ unsigned char lcdtime_HD44780_readkeypad(PrivateData *p, unsigned int YData)
// Convert the positive logic to the negative logic on the LPT port
port_out(p->port, ~YData & 0x00FF);
// 9 bits output if backlight is used, 10 bits otherwise
if (p->have_backlight)
if (have_backlight_pin(p))
port_out(p->port + 2, (((~YData & 0x0100) >> 8) | p->backlight_bit) ^ OUTMASK);
else
port_out(p->port + 2, (((~YData & 0x0100) >> 8) | ((~YData & 0x0200) >> 6)) ^ OUTMASK);
Expand Down
8 changes: 4 additions & 4 deletions server/drivers/hd44780-gpio.c
Expand Up @@ -81,7 +81,7 @@ init_gpio_pin(Driver *drvthis, ugpio_t **pin, const char *name)
return -1;
}

debug(RPT_INFO, "init_gpio_pin: Pin %s mapped to GPIO%d", name, number);
report(RPT_INFO, "init_gpio_pin: Pin %s mapped to GPIO%d", name, number);

return 0;
}
Expand Down Expand Up @@ -159,11 +159,11 @@ hd_init_gpio(Driver *drvthis)
p->hd44780_functions->senddata = gpio_HD44780_senddata;
p->hd44780_functions->close = gpio_HD44780_close;

if (p->have_backlight) {
if (have_backlight_pin(p)) {
if (init_gpio_pin(drvthis, &pins->bl, "BL") != 0) {
report(RPT_WARNING,
"hd_init_gpio: unable to initialize pin_BL - disabling backlight");
p->have_backlight = 0;
set_have_backlight_pin(p, 0);
}
else {
p->hd44780_functions->backlight = gpio_HD44780_backlight;
Expand Down Expand Up @@ -256,7 +256,7 @@ gpio_HD44780_close(PrivateData *p)
if (p->numDisplays > 1)
release_gpio_pin(&pins->en2);

if (p->have_backlight)
if (have_backlight_pin(p))
release_gpio_pin(&pins->bl);

if (pins->rw)
Expand Down
14 changes: 7 additions & 7 deletions server/drivers/hd44780-i2c.c
Expand Up @@ -29,7 +29,7 @@
PCF8574AP: P0 P1 P2 P3 P4 P5 P6 P7
| | | | | | | |
HD44780: RS RW EN BL D4 D5 D6 D7
in LCDd.conf we then need to define
i2c_line_RS=0x01
i2c_line_RW=0x02
Expand Down Expand Up @@ -155,7 +155,7 @@ hd_init_i2c(Driver *drvthis)
p->i2c_line_D5 = drvthis->config_get_int(drvthis->name, "i2c_line_D5", 0, D5);
p->i2c_line_D6 = drvthis->config_get_int(drvthis->name, "i2c_line_D6", 0, D6);
p->i2c_line_D7 = drvthis->config_get_int(drvthis->name, "i2c_line_D7", 0, D7);

report(RPT_INFO, "HD44780: I2C: Init using D4 and D5, and or'd lines, invert", p->i2c_line_RS);
report(RPT_INFO, "HD44780: I2C: Pin RS mapped to 0x%02X", p->i2c_line_RS);
report(RPT_INFO, "HD44780: I2C: Pin RW mapped to 0x%02X", p->i2c_line_RW);
Expand All @@ -166,7 +166,7 @@ hd_init_i2c(Driver *drvthis)
report(RPT_INFO, "HD44780: I2C: Pin D6 mapped to 0x%02X", p->i2c_line_D6);
report(RPT_INFO, "HD44780: I2C: Pin D7 mapped to 0x%02X", p->i2c_line_D7);
report(RPT_INFO, "HD44780: I2C: Invert Backlight %d", p->i2c_backlight_invert);

p->backlight_bit = p->i2c_line_BL;

/* READ CONFIG FILE */
Expand Down Expand Up @@ -249,8 +249,8 @@ hd_init_i2c(Driver *drvthis)
hd44780_functions->uPause(p, 100);

// Set up two-line, small character (5x8) mode
hd44780_functions->senddata(p, 0, RS_INSTR, FUNCSET | IF_4BIT | TWOLINE | SMALLCHAR);
hd44780_functions->uPause(p, 40);
//hd44780_functions->senddata(p, 0, RS_INSTR, FUNCSET | IF_4BIT | TWOLINE | SMALLCHAR);
//hd44780_functions->uPause(p, 40);

common_init(p, IF_4BIT);

Expand Down Expand Up @@ -318,8 +318,8 @@ i2c_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flag
void i2c_HD44780_backlight(PrivateData *p, unsigned char state)
{
if ( p->i2c_backlight_invert == 0 )
p->backlight_bit = ((!p->have_backlight||state) ? 0 : p->i2c_line_BL);
p->backlight_bit = ((!have_backlight_pin(p)||state) ? 0 : p->i2c_line_BL);
else // Inverted backlight - npn transistor
p->backlight_bit = ((p->have_backlight && state) ? p->i2c_line_BL : 0);
p->backlight_bit = ((have_backlight_pin(p) && state) ? p->i2c_line_BL : 0);
i2c_out(p, p->backlight_bit);
}
67 changes: 66 additions & 1 deletion server/drivers/hd44780-low.h
Expand Up @@ -97,13 +97,42 @@

/** @} */

/** \name Types of backlight handling
* @{
* Shall be treated as bitmask
*/


/** No backlight handling at all */
#define BACKLIGHT_NONE 0

/** Backlight handled hrough external pin. */
#define BACKLIGHT_EXTERNAL_PIN 0x0001

/** Backlight handled through internal commands built in driver,
* usually through special commands for model chosen with Model option*/
#define BACKLIGHT_INTERNAL 0x0002

/** Backlight handled through internal commands defined in configuration file */
#define BACKLIGHT_CONFIG_CMDS 0x0004

/** @} */


/** \name Symbolic default values
*@{*/
#define DEFAULT_CONTRAST 800
#define DEFAULT_BRIGHTNESS 800
#define DEFAULT_OFFBRIGHTNESS 300
/**@}*/

/** Maximum value of brightness */
#define MAX_BRIGHTNESS 1000

/** Maximum value of contrast */
#define MAX_CONTRAST 1000


/** \name Maximum sizes of the keypad
*@{*/
/* DO NOT CHANGE THESE VALUES, unless you change the functions too! */
Expand Down Expand Up @@ -246,14 +275,24 @@ typedef struct hd44780_private_data {
/** \name Display features
*@{*/
char have_keypad;
char have_backlight;
char have_output;
/* have_backlight moved to function have_backlight_pin() below */
/**@}*/

int model; /**< model selected in configuration.
For extended mode on some weird controllers
set to HD44780_MODEL_EXTENDED */
int line_address; /**< address of the next line in extended mode */
int backlight_type; /**< way of handling backlight. */
int backlight_cmd_on; /**< internal command(s) for enabling backlight */
int backlight_cmd_off; /**< internal command(s) for disabling backlight */

/** Value saved during display initialization in common_init(),
* given for FUNC_SET command, to use for later.
*
* NOTE: if common_init() from specific connection type is not called,
* update it for correct value. For now used only for PT6314_VFD model */
int func_set_mode;

int delayMult; /**< Delay multiplier for slow displays */
char delayBus; /**< Delay if data is sent too fast over LPT port */
Expand Down Expand Up @@ -394,6 +433,19 @@ has_extended_mode(PrivateData *p) {
return p->model == HD44780_MODEL_EXTENDED;
}

/* returns if display is configured to use external backlight pin */
static char have_backlight_pin(PrivateData *p) {

return (p->backlight_type & BACKLIGHT_EXTERNAL_PIN);
}

/* sets configration value for using external pin for backlight */
static void set_have_backlight_pin(PrivateData *p, int on) {
if (on)
p->backlight_type |= BACKLIGHT_EXTERNAL_PIN;
else
p->backlight_type &= ~BACKLIGHT_EXTERNAL_PIN;
}


/* commands for senddata */
Expand Down Expand Up @@ -458,6 +510,7 @@ has_extended_mode(PrivateData *p) {
#define WINST_PWRON 0x04 /**< Internal power on (high brightness)*/
#define WINST_PWROFF 0x00 /**< Internal power off (low brightness)*/


/** Function set (RE=0) */
#define FUNCSET 0x20
#define IF_8BIT 0x10
Expand All @@ -469,6 +522,18 @@ has_extended_mode(PrivateData *p) {
#define EXTREG 0x04 /**< Select ext. registers (Yes, the same bits) */
#define SEGBLINK 0x02 /**< CGRAM/SEGRAM blink, only if RE=1 */

/** Extra definitions for setting PT6314_VFD brihtness
* yes - same bits used as extended registers */
#define PT6314_BRIGHT_100 0x00
#define PT6314_BRIGHT_75 0x01
#define PT6314_BRIGHT_50 0x02
#define PT6314_BRIGHT_25 0x03

/* mask for brightness */
#define PT6314_BRIGHT_MASK 0x03



/** Set CGRAM address (RE=0) */
#define SETCHAR 0x40

Expand Down

0 comments on commit bf717f1

Please sign in to comment.