|
1 /* |
|
2 * GraphLCD driver library |
|
3 * |
|
4 * gu256x64-372.c - 8-bit driver module for Noritake GU256x64-372 |
|
5 * VFD displays. The VFD is operating in its 8-bit |
|
6 * mode connected to a single PC parallel port. |
|
7 * |
|
8 * based on: |
|
9 * gu256x32f driver module for graphlcd |
|
10 * (c) 2003 Andreas Brachold <vdr04 AT deltab.de> |
|
11 * HD61830 device |
|
12 * (c) 2001-2003 by Carsten Siebholz <c.siebholz AT t-online.de> |
|
13 * lcdproc 0.4 driver hd44780-ext8bit |
|
14 * (c) 1999, 1995 Benjamin Tse <blt AT comports.com> |
|
15 * |
|
16 * This file is released under the GNU General Public License. Refer |
|
17 * to the COPYING file distributed with this package. |
|
18 * |
|
19 * (c) 2004 Andreas 'randy' Weinberger (randy AT smue.org) |
|
20 */ |
|
21 |
|
22 #include <errno.h> |
|
23 #include <syslog.h> |
|
24 #include <unistd.h> |
|
25 #include <sys/time.h> |
|
26 |
|
27 #include "common.h" |
|
28 #include "config.h" |
|
29 #include "gu256x64-372.h" |
|
30 #include "port.h" |
|
31 |
|
32 |
|
33 namespace GLCD |
|
34 { |
|
35 |
|
36 #define SCREENSOFF 0x00 // both screens are off |
|
37 #define SCREEN1ON 0x01 // only screen #1 is on (graphic screen) |
|
38 #define SCREEN2ON 0x02 // only screen #2 is on (graphic/character screen) |
|
39 #define SCREENSON 0x03 // both screens are on |
|
40 |
|
41 #define CURS_AUTOINC 0x04 // cursor increments automatically |
|
42 #define CURS_HOLD 0x05 // cursor holds |
|
43 |
|
44 #define SCREEN2CHAR 0x06 // screen #2 sets to "character" display |
|
45 #define SCREEN2GRAPH 0x07 // screen #2 sets to "graphic" display |
|
46 |
|
47 #define DATA_WRITE 0x08 // data write mode |
|
48 #define DATA_READ 0x09 // data read mode |
|
49 |
|
50 #define DISP_LOSTA1 0x0A // lower addr. of display start of screen #1 |
|
51 #define DISP_HISTA1 0x0B // upper addr. of display start of screen #1 |
|
52 #define DISP_LOSTA2 0x0C // lower addr. of display start of screen #2 |
|
53 #define DISP_HISTA2 0x0D // upper addr. of display start of screen #2 |
|
54 #define CURS_LOADDR 0x0E // lower addr. of cursor of screen #1 & #2 |
|
55 #define CURS_HIADDR 0x0F // upper addr. of cursor start of screen #1 & #2 |
|
56 |
|
57 #define DISP_OR 0x10 // or display of screen #1 & #2 |
|
58 #define DISP_EXOR 0x11 // ex-or display of screen #1 & #2 |
|
59 #define DISP_AND 0x12 // and display of screen #1 & #2 |
|
60 |
|
61 #define BRIGHT_1 0x18 // luminance level 1 100.0% |
|
62 #define BRIGHT_2 0x19 // luminance level 2 87.5% |
|
63 #define BRIGHT_3 0x1A // luminance level 3 75.0% |
|
64 #define BRIGHT_4 0x1B // luminance level 4 62.5% |
|
65 |
|
66 #define WRHI 0x04 // INIT |
|
67 #define WRLO 0x00 |
|
68 #define CDHI 0x00 // nSEL |
|
69 #define CDLO 0x08 |
|
70 |
|
71 |
|
72 cDriverGU256X64_372::cDriverGU256X64_372(cDriverConfig * config) |
|
73 : config(config) |
|
74 { |
|
75 oldConfig = new cDriverConfig(*config); |
|
76 |
|
77 port = new cParallelPort(); |
|
78 |
|
79 m_nRefreshCounter = 0; |
|
80 } |
|
81 |
|
82 cDriverGU256X64_372::~cDriverGU256X64_372() |
|
83 { |
|
84 delete oldConfig; |
|
85 delete port; |
|
86 } |
|
87 |
|
88 int cDriverGU256X64_372::Init() |
|
89 { |
|
90 int x; |
|
91 struct timeval tv1, tv2; |
|
92 |
|
93 width = config->width; |
|
94 if (width <= 0) |
|
95 width = 256; |
|
96 height = config->height; |
|
97 if (height <= 0) |
|
98 height = 64; |
|
99 m_iSizeYb = (height + 7) / 8; |
|
100 |
|
101 for (unsigned int i = 0; i < config->options.size(); i++) |
|
102 { |
|
103 if (config->options[i].name == "") |
|
104 { |
|
105 } |
|
106 } |
|
107 |
|
108 // setup linear lcd array |
|
109 m_pDrawMem = new unsigned char *[width]; |
|
110 if (m_pDrawMem) |
|
111 { |
|
112 for (x = 0; x < width; x++) |
|
113 { |
|
114 m_pDrawMem[x] = new unsigned char[m_iSizeYb]; |
|
115 memset(m_pDrawMem[x], 0, m_iSizeYb); |
|
116 } |
|
117 } |
|
118 Clear(); |
|
119 |
|
120 // setup the lcd array for the "vertical" mem |
|
121 m_pVFDMem = new unsigned char *[width]; |
|
122 if (m_pVFDMem) |
|
123 { |
|
124 for (x = 0; x < width; x++) |
|
125 { |
|
126 m_pVFDMem[x] = new unsigned char[m_iSizeYb]; |
|
127 memset(m_pVFDMem[x], 0, m_iSizeYb); |
|
128 } |
|
129 } |
|
130 ClearVFDMem(); |
|
131 |
|
132 if (config->device == "") |
|
133 { |
|
134 // use DirectIO |
|
135 if (port->Open(config->port) != 0) |
|
136 return -1; |
|
137 uSleep(10); |
|
138 } |
|
139 else |
|
140 { |
|
141 // use ppdev |
|
142 if (port->Open(config->device.c_str()) != 0) |
|
143 return -1; |
|
144 } |
|
145 |
|
146 if (nSleepInit() != 0) |
|
147 { |
|
148 syslog(LOG_ERR, "%s: INFO: cannot change wait parameters Err: %s (cDriver::Init)\n", config->name.c_str(), strerror(errno)); |
|
149 m_bSleepIsInit = false; |
|
150 } |
|
151 else |
|
152 { |
|
153 m_bSleepIsInit = true; |
|
154 } |
|
155 |
|
156 syslog(LOG_DEBUG, "%s: benchmark started.\n", config->name.c_str()); |
|
157 gettimeofday(&tv1, 0); |
|
158 for (x = 0; x < 10000; x++) |
|
159 { |
|
160 port->WriteData(x % 0x100); |
|
161 } |
|
162 gettimeofday(&tv2, 0); |
|
163 nSleepDeInit(); |
|
164 m_nTimingAdjustCmd = ((tv2.tv_sec - tv1.tv_sec) * 10000 + (tv2.tv_usec - tv1.tv_usec)) / 1000; |
|
165 syslog(LOG_DEBUG, "%s: benchmark stopped. Time for Port Command: %ldns\n", config->name.c_str(), m_nTimingAdjustCmd); |
|
166 |
|
167 GU256X64Cmd(SCREEN1ON); |
|
168 GU256X64Cmd(CURS_AUTOINC); |
|
169 GU256X64Cmd(SCREEN2CHAR); |
|
170 |
|
171 GU256X64Cmd(DISP_LOSTA1); GU256X64Data(0x00); |
|
172 GU256X64Cmd(DISP_HISTA1); GU256X64Data(0x00); |
|
173 GU256X64Cmd(DISP_LOSTA2); GU256X64Data(0x00); |
|
174 GU256X64Cmd(DISP_HISTA2); GU256X64Data(0x10); |
|
175 GU256X64Cmd(CURS_LOADDR); GU256X64Data(0x00); |
|
176 GU256X64Cmd(CURS_HIADDR); GU256X64Data(0x00); |
|
177 |
|
178 GU256X64Cmd(DISP_OR); |
|
179 |
|
180 port->Release(); |
|
181 |
|
182 *oldConfig = *config; |
|
183 |
|
184 // Set Display SetBrightness |
|
185 SetBrightness(config->brightness); |
|
186 // clear display |
|
187 Clear(); |
|
188 ClearVFDMem(); |
|
189 |
|
190 syslog(LOG_INFO, "%s: gu256x64-372 initialized.\n", config->name.c_str()); |
|
191 return 0; |
|
192 } |
|
193 |
|
194 int cDriverGU256X64_372::DeInit() |
|
195 { |
|
196 int x; |
|
197 |
|
198 if (m_pVFDMem) |
|
199 for (x = 0; x < width; x++) |
|
200 { |
|
201 delete[] m_pVFDMem[x]; |
|
202 } |
|
203 delete[] m_pVFDMem; |
|
204 |
|
205 if (m_pDrawMem) |
|
206 for (x = 0; x < width; x++) |
|
207 { |
|
208 delete[] m_pDrawMem[x]; |
|
209 } |
|
210 delete[] m_pDrawMem; |
|
211 |
|
212 if (port->Close() != 0) |
|
213 return -1; |
|
214 return 0; |
|
215 } |
|
216 |
|
217 int cDriverGU256X64_372::CheckSetup() |
|
218 { |
|
219 if (config->device != oldConfig->device || |
|
220 config->port != oldConfig->port || |
|
221 config->width != oldConfig->width || |
|
222 config->height != oldConfig->height) |
|
223 { |
|
224 DeInit(); |
|
225 Init(); |
|
226 return 0; |
|
227 } |
|
228 |
|
229 if (config->brightness != oldConfig->brightness) |
|
230 { |
|
231 oldConfig->brightness = config->brightness; |
|
232 SetBrightness(config->brightness); |
|
233 } |
|
234 if (config->upsideDown != oldConfig->upsideDown || |
|
235 config->invert != oldConfig->invert) |
|
236 { |
|
237 oldConfig->upsideDown = config->upsideDown; |
|
238 oldConfig->invert = config->invert; |
|
239 return 1; |
|
240 } |
|
241 return 0; |
|
242 } |
|
243 |
|
244 void cDriverGU256X64_372::ClearVFDMem() |
|
245 { |
|
246 for (int x = 0; x < width; x++) |
|
247 memset(m_pVFDMem[x], 0, m_iSizeYb); |
|
248 } |
|
249 |
|
250 void cDriverGU256X64_372::Clear() |
|
251 { |
|
252 for (int x = 0; x < width; x++) |
|
253 memset(m_pDrawMem[x], 0, m_iSizeYb); |
|
254 } |
|
255 |
|
256 void cDriverGU256X64_372::SetBrightness(unsigned int percent) |
|
257 { |
|
258 port->Claim(); |
|
259 |
|
260 if (percent > 88) { |
|
261 GU256X64Cmd(BRIGHT_1); |
|
262 } else if (percent > 75) { |
|
263 GU256X64Cmd(BRIGHT_2); |
|
264 } else if (percent > 66) { |
|
265 GU256X64Cmd(BRIGHT_3); |
|
266 } else if (percent > 0 ) { |
|
267 GU256X64Cmd(BRIGHT_4); |
|
268 } else { |
|
269 GU256X64Cmd(SCREENSOFF); |
|
270 } |
|
271 port->Release(); |
|
272 } |
|
273 |
|
274 void cDriverGU256X64_372::GU256X64Cmd(unsigned char data) |
|
275 { |
|
276 if (m_bSleepIsInit) |
|
277 nSleepInit(); |
|
278 |
|
279 port->WriteControl(CDHI | WRHI); |
|
280 port->WriteData(data); |
|
281 nSleep(100 + (100 * config->adjustTiming) - m_nTimingAdjustCmd); |
|
282 port->WriteControl(CDHI | WRLO); |
|
283 nSleep(100 + (100 * config->adjustTiming) - m_nTimingAdjustCmd); |
|
284 port->WriteControl(CDHI | WRHI); |
|
285 nSleep(100 + (100 * config->adjustTiming) - m_nTimingAdjustCmd); |
|
286 } |
|
287 |
|
288 void cDriverGU256X64_372::GU256X64Data(unsigned char data) |
|
289 { |
|
290 if (m_bSleepIsInit) |
|
291 nSleepInit(); |
|
292 |
|
293 port->WriteControl(CDLO | WRHI); |
|
294 port->WriteData(data); |
|
295 nSleep(100 + (100 * config->adjustTiming) - m_nTimingAdjustCmd); |
|
296 port->WriteControl(CDLO | WRLO); |
|
297 nSleep(100 + (100 * config->adjustTiming) - m_nTimingAdjustCmd); |
|
298 port->WriteControl(CDLO | WRHI); |
|
299 nSleep(100 + (100 * config->adjustTiming) - m_nTimingAdjustCmd); |
|
300 } |
|
301 |
|
302 void cDriverGU256X64_372::SetPixel(int x, int y) |
|
303 { |
|
304 unsigned char c; |
|
305 |
|
306 if (!m_pDrawMem) |
|
307 return; |
|
308 |
|
309 if (x >= width || x < 0) |
|
310 return; |
|
311 if (y >= height || y < 0) |
|
312 return; |
|
313 |
|
314 if (config->upsideDown) |
|
315 { |
|
316 x = width - 1 - x; |
|
317 y = height - 1 - y; |
|
318 } |
|
319 |
|
320 c = 0x80 >> (y % 8); |
|
321 |
|
322 m_pDrawMem[x][y/8] = m_pDrawMem[x][y/8] | c; |
|
323 } |
|
324 |
|
325 void cDriverGU256X64_372::Set8Pixels(int x, int y, unsigned char data) |
|
326 { |
|
327 int n; |
|
328 |
|
329 // x - pos is'nt mayby align to 8 |
|
330 x &= 0xFFF8; |
|
331 |
|
332 for (n = 0; n < 8; ++n) |
|
333 { |
|
334 if (data & (0x80 >> n)) // if bit is set |
|
335 SetPixel(x + n, y); |
|
336 } |
|
337 } |
|
338 |
|
339 void cDriverGU256X64_372::Refresh(bool refreshAll) |
|
340 { |
|
341 int xb, yb; |
|
342 |
|
343 if (!m_pVFDMem || !m_pDrawMem) |
|
344 return; |
|
345 |
|
346 bool doRefresh = false; |
|
347 int minX = width; |
|
348 int maxX = 0; |
|
349 int minYb = m_iSizeYb; |
|
350 int maxYb = 0; |
|
351 |
|
352 if (CheckSetup() > 0) |
|
353 refreshAll = true; |
|
354 |
|
355 for (xb = 0; xb < width; ++xb) |
|
356 { |
|
357 for (yb = 0; yb < m_iSizeYb; ++yb) |
|
358 { |
|
359 if (m_pVFDMem[xb][yb] != m_pDrawMem[xb][yb]) |
|
360 { |
|
361 m_pVFDMem[xb][yb] = m_pDrawMem[xb][yb]; |
|
362 minX = std::min(minX, xb); |
|
363 maxX = std::max(maxX, xb); |
|
364 minYb = std::min(minYb, yb); |
|
365 maxYb = std::max(maxYb, yb + 1); |
|
366 doRefresh = true; |
|
367 } |
|
368 } |
|
369 } |
|
370 |
|
371 m_nRefreshCounter = (m_nRefreshCounter + 1) % config->refreshDisplay; |
|
372 if (!refreshAll && !m_nRefreshCounter) |
|
373 refreshAll = true; |
|
374 |
|
375 if (refreshAll || doRefresh) |
|
376 { |
|
377 if (refreshAll) { |
|
378 minX = 0; |
|
379 maxX = width; |
|
380 minYb = 0; |
|
381 maxYb = m_iSizeYb; |
|
382 // and reset RefreshCounter |
|
383 m_nRefreshCounter = 0; |
|
384 } |
|
385 |
|
386 minX = std::max(minX, 0); |
|
387 maxX = std::min(maxX, width - 1); |
|
388 minYb = std::max(minYb, 0); |
|
389 maxYb = std::min(maxYb, m_iSizeYb); |
|
390 |
|
391 port->Claim(); |
|
392 |
|
393 GU256X64Cmd(CURS_LOADDR); GU256X64Data(0x00); |
|
394 GU256X64Cmd(CURS_HIADDR); GU256X64Data(0x00); |
|
395 GU256X64Cmd(DATA_WRITE); |
|
396 |
|
397 for (xb = 0; xb < width; xb++) |
|
398 { |
|
399 for (yb = 0; yb < m_iSizeYb; yb++) |
|
400 { |
|
401 GU256X64Data((m_pVFDMem[xb][yb]) ^ (config->invert ? 0xff : 0x00)); |
|
402 } |
|
403 } |
|
404 port->Release(); |
|
405 } |
|
406 } |
|
407 |
|
408 } // end of namespace |