-
Notifications
You must be signed in to change notification settings - Fork 1
/
parlcd.c
235 lines (183 loc) · 4.88 KB
/
parlcd.c
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Copyright 2000-2001 by Geert Uytterhoeven <[email protected]>
*
* This programs is subject to the terms and conditions of the GNU General
* Public License
*/
#ifdef __KERNEL__
#include <asm/errno.h>
#include <linux/ioport.h>
#include <linux/module.h>
#include <linux/types.h>
#include <asm/io.h>
#else /* !__KERNEL__ */
typedef unsigned char u8;
#include <sys/io.h>
#endif /* !__KERNEL__ */
#include "hd44780.h"
#include "parlcd.h"
/*
* Parallel Port Register Access
*/
static inline void parport_mod_data(u8 clear, u8 set)
{
parport_write_data((parport_read_data() & ~clear) | set);
}
static inline void parport_mod_control(u8 clear, u8 set)
{
parport_write_control((parport_read_control() & ~clear) | set);
}
/* ------------------------------------------------------------------------- */
#if 0 /* -- Custom wiring -------------------------------------------------- */
/*
* Low-Level LCD Access
*
* These are hardware dependent!
*
* Wiring:
*
* LCD Parport (8 bit) Parport (4 bit)
* ------------------------------------------------------
* RS *SELECTIN *SELECTIN
* RW *AUTOFD (or GND) *AUTOFD (or GND)
* E *INIT *INIT
* Backlight *STROBE *STROBE
* D0 D0 -
* D1 D1 -
* D2 D2 -
* D3 D3 -
* D4 D4 D4
* D5 D5 D5
* D6 D6 D6
* D7 D7 D7
*/
#define PARLCD_RS (PARPORT_CONTROL_SELECT) /* inverted! */
#define PARLCD_RW (PARPORT_CONTROL_AUTOFD) /* inverted! */
#define PARLCD_E (PARPORT_CONTROL_INIT)
#define PARLCD_BL (PARPORT_CONTROL_STROBE) /* inverted! */
#define PARLCD_RS_1 0
#define PARLCD_RS_0 PARLCD_RS
#define PARLCD_RW_1 0
#define PARLCD_RW_0 PARLCD_RW
#define PARLCD_E_1 PARLCD_E
#define PARLCD_E_0 0
#define PARLCD_BL_1 0
#define PARLCD_BL_0 PARLCD_BL
#else /* -- WinAmp wiring -------------------------------------------------- */
/*
* Low-Level LCD Access
*
* These are hardware dependent!
*
* Wiring:
*
* LCD Parport (8 bit) Parport (4 bit)
* ------------------------------------------------------
* RS *INIT *INIT
* RW *AUTOFD (or GND) *AUTOFD (or GND)
* E *STROBE *STROBE
* Backlight *SELECTIN *SELECTIN
* D0 D0 -
* D1 D1 -
* D2 D2 -
* D3 D3 -
* D4 D4 D4
* D5 D5 D5
* D6 D6 D6
* D7 D7 D7
*/
#define PARLCD_RS (PARPORT_CONTROL_INIT)
#define PARLCD_RW (PARPORT_CONTROL_AUTOFD) /* inverted! */
#define PARLCD_E (PARPORT_CONTROL_STROBE) /* inverted! */
#define PARLCD_BL (PARPORT_CONTROL_SELECT) /* inverted! */
#define PARLCD_RS_1 PARLCD_RS
#define PARLCD_RS_0 0
#define PARLCD_RW_1 0
#define PARLCD_RW_0 PARLCD_RW
#define PARLCD_E_1 0
#define PARLCD_E_0 PARLCD_E
#define PARLCD_BL_1 0
#define PARLCD_BL_0 PARLCD_BL
#endif /* ------------------------------------------------------------------ */
/*
* Set the Register Select and Read/Write Signals
*/
static inline void parlcd_set_rs_rw(int rs, int rw)
{
parport_mod_control(PARLCD_RS | PARLCD_RW,
(rs ? PARLCD_RS_1 : PARLCD_RS_0) |
(rw ? PARLCD_RW_1 : PARLCD_RW_1));
}
/*
* Set the Enable Signal
*/
static inline void parlcd_set_e(int e)
{
parport_mod_control(PARLCD_E, e ? PARLCD_E_1 : PARLCD_E_0);
}
/*
* Set the Blanking Signal
*/
static inline void parlcd_set_bl(int bl)
{
parport_mod_control(PARLCD_BL, bl ? PARLCD_BL_1 : PARLCD_BL_0);
}
/*
* Set the DATA Signals
*
* For 8 bit operation, all 8 bits are valid
* For 4 bit operation, data is transfered using the 4 MSB bits only
*/
static int parlcd_bus_width = 8;
static void parlcd_set_data(u8 val)
{
if (parlcd_bus_width == 4)
val |= 0x0f; /* Drive unconnected lines high */
parport_write_data(val);
}
static inline u8 parlcd_get_data(void)
{
return parport_read_data();
}
static const struct lcd_driver parlcd_driver = {
set_rs_rw: parlcd_set_rs_rw,
set_e: parlcd_set_e,
set_bl: parlcd_set_bl,
set_data: parlcd_set_data,
get_data: parlcd_get_data
};
/*
* Parallel Port LCD Control
*/
void parlcd_init(int width)
{
parlcd_bus_width = width;
lcd_register_driver(&parlcd_driver);
lcd_init(width);
}
void parlcd_cleanup(void)
{
lcd_cleanup();
lcd_unregister_driver(&parlcd_driver);
}
#ifdef MODULE
int init_module(void)
{
if (check_region(PARPORT_BASE, 3))
return -EBUSY;
request_region(PARPORT_BASE, 3, "parlcd");
parlcd_init(8);
#if 0
lcd_printf("Welcome to your\n"
"Hitachi HD44780U\n"
"driving a 20x4 LCD!\n"
"[%d bit interface]", parlcd_bus_width);
#endif
return 0;
}
void cleanup_module(void)
{
parlcd_cleanup();
release_region(PARPORT_BASE, 3);
}
#endif /* MODULE */