|
1 /* |
|
2 * GraphLCD driver library |
|
3 * |
|
4 * sed1520.c - SED1520 driver class |
|
5 * |
|
6 * This file is released under the GNU General Public License. Refer |
|
7 * to the COPYING file distributed with this package. |
|
8 * |
|
9 * (c) 2003 Andreas 'randy' Weinberger <vdr AT smue.org> |
|
10 */ |
|
11 |
|
12 #include <syslog.h> |
|
13 #include <sys/time.h> |
|
14 |
|
15 #include "common.h" |
|
16 #include "config.h" |
|
17 #include "port.h" |
|
18 #include "sed1520.h" |
|
19 |
|
20 |
|
21 namespace GLCD |
|
22 { |
|
23 |
|
24 // commands |
|
25 const unsigned char kSEAD = 0x00; // Set (X) Column Address |
|
26 const unsigned char kSEPA = 0xb8; // Set (Y) Page Address |
|
27 const unsigned char kSEDS = 0xc0; // Set Display Start Line |
|
28 const unsigned char kDION = 0xaf; // Display on |
|
29 const unsigned char kDIOF = 0xae; // Display off |
|
30 |
|
31 // control bits for DirectIO |
|
32 #define CE1 0x01 |
|
33 #define CE1HI 0x01 // Chip Enable 1 on |
|
34 #define CE1LO 0x00 // Chip Enable 1 off |
|
35 |
|
36 const unsigned char kCS1HI = 0x00; // Chip Select 1 |
|
37 const unsigned char kCS1LO = 0x01; |
|
38 const unsigned char kCS2HI = 0x04; // Chip Select 2 |
|
39 const unsigned char kCS2LO = 0x00; |
|
40 const unsigned char kCDHI = 0x08; // Command/Data Register Select |
|
41 const unsigned char kCDLO = 0x00; |
|
42 const unsigned char kLEDHI = 0x02; // LED Backlight (not supported currently) |
|
43 const unsigned char kLEDLO = 0x00; |
|
44 |
|
45 |
|
46 cDriverSED1520::cDriverSED1520(cDriverConfig * config) |
|
47 : config(config) |
|
48 { |
|
49 oldConfig = new cDriverConfig(*config); |
|
50 |
|
51 port = new cParallelPort(); |
|
52 |
|
53 refreshCounter = 0; |
|
54 } |
|
55 |
|
56 cDriverSED1520::~cDriverSED1520() |
|
57 { |
|
58 delete port; |
|
59 delete oldConfig; |
|
60 } |
|
61 |
|
62 int cDriverSED1520::Init() |
|
63 { |
|
64 int x; |
|
65 int i; |
|
66 struct timeval tv1, tv2; |
|
67 |
|
68 if (!(config->width % 8) == 0) { |
|
69 width = config->width + (8 - (config->width % 8)); |
|
70 } else { |
|
71 width = config->width; |
|
72 } |
|
73 |
|
74 if (!(config->height % 8) == 0) { |
|
75 height = config->height + (8 - (config->height % 8)); |
|
76 } else { |
|
77 height = config->height; |
|
78 } |
|
79 |
|
80 if (width <= 0) |
|
81 width = 120; |
|
82 if (height <= 0) |
|
83 height = 32; |
|
84 |
|
85 SEAD = kSEAD; |
|
86 SEPA = kSEPA; |
|
87 SEDS = kSEDS; |
|
88 DION = kDION; |
|
89 DIOF = kDIOF; |
|
90 LED = kLEDHI; |
|
91 CDHI = kCDHI; |
|
92 CDLO = kCDLO; |
|
93 CS1HI = kCS1HI; |
|
94 CS1LO = kCS1LO; |
|
95 CS2HI = kCS2HI; |
|
96 CS2LO = kCS2LO; |
|
97 |
|
98 for (unsigned int i = 0; i < config->options.size(); i++) |
|
99 { |
|
100 if (config->options[i].name == "") |
|
101 { |
|
102 } |
|
103 } |
|
104 |
|
105 // setup linear lcd array |
|
106 LCD = new unsigned char *[(width + 7) / 8]; |
|
107 if (LCD) |
|
108 { |
|
109 for (x = 0; x < (width + 7) / 8; x++) |
|
110 { |
|
111 LCD[x] = new unsigned char[height]; |
|
112 memset(LCD[x], 0, height); |
|
113 } |
|
114 } |
|
115 // setup the lcd array for the paged sed1520 |
|
116 LCD_page = new unsigned char *[width]; |
|
117 if (LCD_page) |
|
118 { |
|
119 for (x = 0; x < width; x++) |
|
120 { |
|
121 LCD_page[x] = new unsigned char[(height + 7) / 8]; |
|
122 memset(LCD_page[x], 0, (height + 7) / 8); |
|
123 } |
|
124 } |
|
125 |
|
126 if (config->device == "") |
|
127 { |
|
128 // use DirectIO |
|
129 if (port->Open(config->port) != 0) |
|
130 return -1; |
|
131 uSleep(10); |
|
132 } |
|
133 else |
|
134 { |
|
135 // use ppdev |
|
136 if (port->Open(config->device.c_str()) != 0) |
|
137 return -1; |
|
138 } |
|
139 |
|
140 if (nSleepInit() != 0) |
|
141 { |
|
142 syslog(LOG_DEBUG, "%s: INFO: cannot change wait parameters (cDriver::Init)\n", config->name.c_str()); |
|
143 useSleepInit = false; |
|
144 } |
|
145 else |
|
146 { |
|
147 useSleepInit = true; |
|
148 } |
|
149 |
|
150 syslog(LOG_DEBUG, "%s: benchmark started.\n", config->name.c_str()); |
|
151 gettimeofday(&tv1, 0); |
|
152 for (i = 0; i < 1000; i++) |
|
153 { |
|
154 port->WriteData(i % 0x100); |
|
155 } |
|
156 gettimeofday(&tv2, 0); |
|
157 if (useSleepInit) |
|
158 nSleepDeInit(); |
|
159 timeForPortCmdInNs = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec); |
|
160 syslog(LOG_DEBUG, "%s: benchmark stopped. Time for Command: %ldns\n", config->name.c_str(), timeForPortCmdInNs); |
|
161 |
|
162 // initialize graphic mode |
|
163 InitGraphic(); |
|
164 |
|
165 port->Release(); |
|
166 |
|
167 *oldConfig = *config; |
|
168 |
|
169 // clear display |
|
170 Clear(); |
|
171 |
|
172 syslog(LOG_INFO, "%s: SED1520 initialized.\n", config->name.c_str()); |
|
173 return 0; |
|
174 } |
|
175 |
|
176 int cDriverSED1520::DeInit() |
|
177 { |
|
178 int x; |
|
179 |
|
180 // free linear lcd array |
|
181 if (LCD) |
|
182 { |
|
183 for (x = 0; x < (width + 7) / 8; x++) |
|
184 { |
|
185 delete[] LCD[x]; |
|
186 } |
|
187 delete[] LCD; |
|
188 } |
|
189 // free the lcd array for the paged sed1520 |
|
190 if (LCD_page) |
|
191 { |
|
192 for (x = 0; x < width; x++) |
|
193 { |
|
194 delete[] LCD_page[x]; |
|
195 } |
|
196 delete[] LCD_page; |
|
197 } |
|
198 |
|
199 if (port->Close() != 0) |
|
200 return -1; |
|
201 return 0; |
|
202 } |
|
203 |
|
204 int cDriverSED1520::CheckSetup() |
|
205 { |
|
206 if (config->device != oldConfig->device || |
|
207 config->port != oldConfig->port || |
|
208 config->width != oldConfig->width || |
|
209 config->height != oldConfig->height) |
|
210 { |
|
211 DeInit(); |
|
212 Init(); |
|
213 return 0; |
|
214 } |
|
215 |
|
216 if (config->upsideDown != oldConfig->upsideDown || |
|
217 config->invert != oldConfig->invert) |
|
218 { |
|
219 oldConfig->upsideDown = config->upsideDown; |
|
220 oldConfig->invert = config->invert; |
|
221 return 1; |
|
222 } |
|
223 return 0; |
|
224 } |
|
225 |
|
226 int cDriverSED1520::InitGraphic() |
|
227 { |
|
228 // initialize controller1, set display start 0, set page 0, set y address 0, display on |
|
229 SED1520Cmd(SEDS, 1); |
|
230 SED1520Cmd(SEPA, 1); |
|
231 SED1520Cmd(SEAD, 1); |
|
232 SED1520Cmd(DION, 1); |
|
233 |
|
234 // initialize controller2, set display start 0, set page 0, set y address 0, display on |
|
235 SED1520Cmd(SEDS, 2); |
|
236 SED1520Cmd(SEPA, 2); |
|
237 SED1520Cmd(SEAD, 2); |
|
238 SED1520Cmd(DION, 2); |
|
239 |
|
240 return 0; |
|
241 } |
|
242 |
|
243 void cDriverSED1520::SED1520Cmd(unsigned char data, int cmdcs) |
|
244 { |
|
245 if (useSleepInit) |
|
246 nSleepInit(); |
|
247 |
|
248 switch (cmdcs) |
|
249 { |
|
250 case 1: |
|
251 port->WriteControl(CDHI | CS1LO | CS2LO | LEDHI); |
|
252 nSleep(450 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
253 port->WriteData(data); |
|
254 nSleep(650 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
255 port->WriteControl(CDHI | CS1HI | CS2LO | LEDHI); |
|
256 nSleep(450 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
257 break; |
|
258 case 2: |
|
259 port->WriteControl(CDHI | CS1LO | CS2LO | LED); |
|
260 nSleep(450 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
261 port->WriteData(data); |
|
262 nSleep(650 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
263 port->WriteControl(CDHI | CS1LO | CS2HI | LED); |
|
264 nSleep(450 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
265 break; |
|
266 } |
|
267 if (useSleepInit) |
|
268 nSleepDeInit(); |
|
269 } |
|
270 |
|
271 void cDriverSED1520::SED1520Data(unsigned char data, int datacs) |
|
272 { |
|
273 if (useSleepInit) |
|
274 nSleepInit(); |
|
275 |
|
276 switch (datacs) |
|
277 { |
|
278 case 1: |
|
279 port->WriteControl(CDLO | CS1LO | CS2LO | LEDHI); |
|
280 nSleep(450 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
281 port->WriteData(data); |
|
282 nSleep(650 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
283 port->WriteControl(CDLO | CS1HI | CS2LO | LEDHI); |
|
284 nSleep(450 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
285 break; |
|
286 case 2: |
|
287 port->WriteControl(CDLO | CS1LO | CS2LO | LED); |
|
288 nSleep(450 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
289 port->WriteData(data); |
|
290 nSleep(650 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
291 port->WriteControl(CDLO | CS1LO | CS2HI | LED); |
|
292 nSleep(450 - timeForPortCmdInNs + 100 * config->adjustTiming); |
|
293 break; |
|
294 } |
|
295 if (useSleepInit) |
|
296 nSleepDeInit(); |
|
297 } |
|
298 |
|
299 void cDriverSED1520::Clear() |
|
300 { |
|
301 for (int x = 0; x < (width + 7) / 8; x++) |
|
302 memset(LCD[x], 0, height); |
|
303 } |
|
304 |
|
305 void cDriverSED1520::Set8Pixels (int x, int y, unsigned char data) |
|
306 { |
|
307 if (x >= width || y >= height) |
|
308 return; |
|
309 |
|
310 if (!config->upsideDown) |
|
311 { |
|
312 // normal orientation |
|
313 LCD[x / 8][y] = LCD[x / 8][y] | data; |
|
314 } |
|
315 else |
|
316 { |
|
317 // upside down orientation |
|
318 x = width - 1 - x; |
|
319 y = height - 1 - y; |
|
320 LCD[x / 8][y] = LCD[x / 8][y] | ReverseBits(data); |
|
321 } |
|
322 } |
|
323 |
|
324 void cDriverSED1520::Refresh(bool refreshAll) |
|
325 { |
|
326 int x,y,xx,yy; |
|
327 unsigned char dByte, oneBlock[8]; |
|
328 |
|
329 if (CheckSetup() > 0) |
|
330 refreshAll = true; |
|
331 |
|
332 if (config->refreshDisplay > 0) |
|
333 { |
|
334 refreshCounter = (refreshCounter + 1) % config->refreshDisplay; |
|
335 if (!refreshAll && !refreshCounter) |
|
336 refreshAll = true; |
|
337 } |
|
338 |
|
339 refreshAll = true; // differential update is not yet supported |
|
340 |
|
341 if (refreshAll) |
|
342 { |
|
343 // draw all |
|
344 |
|
345 // convert the linear lcd array to the paged array for the display |
|
346 for (y = 0; y < (height + 7) / 8; y++) |
|
347 { |
|
348 for (x = 0; x < (width + 7) / 8; x++) |
|
349 { |
|
350 for (yy = 0; yy < 8; yy++) |
|
351 { |
|
352 oneBlock[yy] = LCD[x][yy + (y * 8)] ^ (config->invert ? 0xff : 0x00); |
|
353 } |
|
354 for (xx = 0; xx < 8; xx++) |
|
355 { |
|
356 dByte = 0; |
|
357 for (yy = 0; yy < 8; yy++) |
|
358 { |
|
359 if (oneBlock[yy] & bitmask[xx]) |
|
360 { |
|
361 dByte += (1 << yy); |
|
362 } |
|
363 } |
|
364 LCD_page[x * 8 + xx][y] = dByte; |
|
365 } |
|
366 } |
|
367 } |
|
368 |
|
369 port->Claim(); |
|
370 |
|
371 // send lcd_soll data to display, controller 1 |
|
372 // set page and start address |
|
373 for (y = 0; y < (height + 7) / 8; y++) |
|
374 { |
|
375 SED1520Cmd(SEAD, 1); |
|
376 SED1520Cmd(SEPA + y, 1); |
|
377 SED1520Data(0x00 ^ (config->invert ? 0xff : 0x00), 1); // fill first row with zero |
|
378 |
|
379 for (x = 0; x < width / 2 + 1; x++) |
|
380 { |
|
381 SED1520Data(LCD_page[x][y], 1); |
|
382 } |
|
383 |
|
384 SED1520Cmd(SEAD, 2); |
|
385 SED1520Cmd(SEPA + y, 2); |
|
386 |
|
387 for (x = width / 2; x < width; x++) |
|
388 { |
|
389 SED1520Data(LCD_page[x][y], 2); |
|
390 } |
|
391 |
|
392 SED1520Data(0x00 ^ (config->invert ? 0xff : 0x00), 2); // fill last row with zero |
|
393 } |
|
394 port->Release(); |
|
395 } |
|
396 else |
|
397 { |
|
398 // draw only the changed bytes |
|
399 } |
|
400 } |
|
401 |
|
402 } // end of namespace |