File: hd44780-lcm162.c

package info (click to toggle)
lcdproc 0.5.9-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 5,064 kB
  • sloc: ansic: 59,645; sh: 1,740; perl: 681; makefile: 417
file content (133 lines) | stat: -rw-r--r-- 3,898 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * 8-bit driver module for Hitachi HD44780 based LCD displays.
 * The LCD is operated in it's 8 bit-mode to be connected to a single
 * PC parallel port.
 *
 * Copyright (c)  1999, 1995 Benjamin Tse <blt@Comports.com>
 *                2001 Joris Robijn <joris@robijn.net>
 *		  2009 Holger Rasch <rasch@bytemine.net>
 *
 * Created modular driver Dec 1999, Benjamin Tse <blt@Comports.com>
 *
 * Based on the code in the lcdtime package which uses the LCD
 * controller in its 8-bit mode.
 *
 * This file is released under the GNU General Public License. Refer to the
 * COPYING file distributed with this package.
 */

/*
 * Copied from "hd44780-ext8.c" and modified for lcm-162 module
 * found in nexcom nsaXXXX models.
 */

#include "hd44780-lcm162.h"
#include "hd44780-low.h"
#include "lpt-port.h"
#include "port.h"
#include "shared/report.h"

#include <stdio.h>
#include <string.h>
#include <errno.h>

// Generally, any function that accesses the LCD control lines needs to be
// implemented separately for each HW design. This is typically (but not
// restricted to):
// HD44780_senddata
// HD44780_readkeypad

void lcm162_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch);
void lcm162_HD44780_backlight(PrivateData *p, unsigned char state);
unsigned char lcm162_HD44780_readkeypad(PrivateData *p, unsigned int YData);
void lcm162_HD44780_output(PrivateData *p, int data);

/* lcm-162 specific mapping parport <-> hd44780 signals */
#define	RS	SEL
#define	RW	INIT
#define	EN1	LF


// initialise the driver
int
hd_init_lcm162(Driver *drvthis)
{
	PrivateData *p = (PrivateData*) drvthis->private_data;
	HD44780_functions *hd44780_functions = p->hd44780_functions;

	// Reserve the port registers
	if (port_access_multiple(p->port,3)) {
		report(RPT_ERR, "%s: cannot get IO-permission for 0x%03X: %s",
				drvthis->name, p->port, strerror(errno));
		return -1;
	}

	hd44780_functions->senddata = lcm162_HD44780_senddata;
	hd44780_functions->backlight = lcm162_HD44780_backlight;
	hd44780_functions->readkeypad = lcm162_HD44780_readkeypad;

	// setup the lcd in 8 bit mode
	hd44780_functions->senddata(p, 0, RS_INSTR, FUNCSET | IF_8BIT);
	hd44780_functions->uPause(p, 4100);
	hd44780_functions->senddata(p, 0, RS_INSTR, FUNCSET | IF_8BIT);
	hd44780_functions->uPause(p, 100);
	hd44780_functions->senddata(p, 0, RS_INSTR, FUNCSET | IF_8BIT | TWOLINE | SMALLCHAR);
	hd44780_functions->uPause(p, 40);

	common_init (p, IF_8BIT);

	if (p->have_keypad)
		p->stuckinputs = 0;	/* unused here */

	// Writes new value to the "bargraph" latches
	hd44780_functions->output = 0;
	return 0;
}

// lcm162_HD44780_senddata
void
lcm162_HD44780_senddata(PrivateData *p, unsigned char displayID, unsigned char flags, unsigned char ch)
{
	unsigned char enableLines = 0, portControl;

	// Only one controller is supported
	enableLines = EN1;

	if (flags == RS_INSTR)
		portControl = 0;
	else //if (iflags == RS_DATA)
		portControl = RS;

	portControl |= p->backlight_bit;

	port_out(p->port + 2, portControl ^ OUTMASK);
	port_out(p->port, ch);
	if (p->delayBus) p->hd44780_functions->uPause(p, 1);
	port_out(p->port + 2, (enableLines|portControl) ^ OUTMASK);
	if (p->delayBus) p->hd44780_functions->uPause(p, 1);
	port_out(p->port + 2, portControl ^ OUTMASK);
}

void lcm162_HD44780_backlight(PrivateData *p, unsigned char state)
{
	/* ignore config, there is no backlight control on the lcm-162 */
	return;
}

unsigned char lcm162_HD44780_readkeypad(PrivateData *p, unsigned int YData)
{
	unsigned char readval;

	if (YData) return 0;	/* no keymatrix */

	readval = port_in(p->port + 1);
	if (readval & ACK) {	/* a key is pressed */
		/* 4 keys encoded in signals PAPEREND and FAULT */
		/* map them to low nibble (multiple keys not supported) */
		return 1 << (
			((readval & FAULT) / FAULT << 1) |
			((readval & PAPEREND) / PAPEREND)
		);
	} else
		return 0;
}