1
/* $Id: drv_T6963.c 1136 2010-11-28 16:07:16Z mzuther $
2
* $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/drv_T6963.c $
4
* new style driver for T6963-based displays
6
* Copyright (C) 2003 Michael Reinelt <michael@reinelt.co.at>
7
* Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
9
* This file is part of LCD4Linux.
11
* LCD4Linux is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; either version 2, or (at your option)
16
* LCD4Linux is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31
* struct DRIVER drv_T6963
52
#include "drv_generic_graphic.h"
53
#include "drv_generic_parport.h"
59
static char Name[] = "T6963";
67
static MODEL Models[] = {
73
/* font width of display */
76
/* text rows/columns */
77
static int TROWS, TCOLS;
79
/* SingleScan or DualScan */
80
static int DualScan = 0;
83
static int T_ACC, T_OH, T_PW, T_DH, T_CDS;
86
static unsigned char SIGNAL_CE;
87
static unsigned char SIGNAL_CD;
88
static unsigned char SIGNAL_RD;
89
static unsigned char SIGNAL_WR;
91
unsigned char *Buffer1, *Buffer2;
96
/****************************************/
97
/*** hardware dependant functions ***/
98
/****************************************/
100
/* perform normal status check */
101
static void drv_T6_status1(void)
105
/* turn off data line drivers */
106
drv_generic_parport_direction(1);
108
/* lower CE and RD */
109
drv_generic_parport_control(SIGNAL_CE | SIGNAL_RD, 0);
114
/* wait for STA0=1 and STA1=1 */
119
debug("hang in status1");
123
} while ((drv_generic_parport_read() & 0x03) != 0x03);
126
drv_generic_parport_control(SIGNAL_RD | SIGNAL_CE, SIGNAL_RD | SIGNAL_CE);
128
/* Output Hold Time */
131
/* turn on data line drivers */
132
drv_generic_parport_direction(0);
136
/* perform status check in "auto mode" */
137
static void drv_T6_status2(void)
141
/* turn off data line drivers */
142
drv_generic_parport_direction(1);
144
/* lower RD and CE */
145
drv_generic_parport_control(SIGNAL_RD | SIGNAL_CE, 0);
150
/* wait for STA3=1 */
155
debug("hang in status2");
159
} while ((drv_generic_parport_read() & 0x08) != 0x08);
162
drv_generic_parport_control(SIGNAL_RD | SIGNAL_CE, SIGNAL_RD | SIGNAL_CE);
164
/* Output Hold Time */
167
/* turn on data line drivers */
168
drv_generic_parport_direction(0);
172
static void drv_T6_write_cmd(const unsigned char cmd)
174
/* wait until the T6963 is idle */
177
/* put data on DB1..DB8 */
178
drv_generic_parport_data(cmd);
180
/* lower WR and CE */
181
drv_generic_parport_control(SIGNAL_WR | SIGNAL_CE, 0);
187
drv_generic_parport_control(SIGNAL_WR | SIGNAL_CE, SIGNAL_WR | SIGNAL_CE);
194
static void drv_T6_write_data(const unsigned char data)
196
/* wait until the T6963 is idle */
199
/* put data on DB1..DB8 */
200
drv_generic_parport_data(data);
203
drv_generic_parport_control(SIGNAL_CD, 0);
208
/* lower WR and CE */
209
drv_generic_parport_control(SIGNAL_WR | SIGNAL_CE, 0);
215
drv_generic_parport_control(SIGNAL_WR | SIGNAL_CE, SIGNAL_WR | SIGNAL_CE);
221
drv_generic_parport_control(SIGNAL_CD, SIGNAL_CD);
225
static void drv_T6_write_auto(const unsigned char data)
227
/* wait until the T6963 is idle */
230
/* put data on DB1..DB8 */
231
drv_generic_parport_data(data);
234
drv_generic_parport_control(SIGNAL_CD, 0);
239
/* lower WR and CE */
240
drv_generic_parport_control(SIGNAL_WR | SIGNAL_CE, 0);
246
drv_generic_parport_control(SIGNAL_WR | SIGNAL_CE, SIGNAL_WR | SIGNAL_CE);
252
drv_generic_parport_control(SIGNAL_CD, SIGNAL_CD);
257
static void drv_T6_send_byte(const unsigned char cmd, const unsigned char data)
259
drv_T6_write_data(data);
260
drv_T6_write_cmd(cmd);
264
static void drv_T6_send_word(const unsigned char cmd, const unsigned short data)
266
drv_T6_write_data(data & 0xff);
267
drv_T6_write_data(data >> 8);
268
drv_T6_write_cmd(cmd);
272
static void drv_T6_clear(const unsigned short addr, const int len)
276
drv_T6_send_word(0x24, addr); /* Set Adress Pointer */
277
drv_T6_write_cmd(0xb0); /* Set Data Auto Write */
278
for (i = 0; i < len; i++) {
279
drv_T6_write_auto(0x0);
282
debug("bug occurred at byte %d of %d", i, len);
286
drv_T6_write_cmd(0xb2); /* Auto Reset */
290
static void drv_T6_copy(const unsigned short addr, const unsigned char *data, const int len)
294
drv_T6_send_word(0x24, addr); /* Set Adress Pointer */
295
drv_T6_write_cmd(0xb0); /* Set Data Auto Write */
296
for (i = 0; i < len; i++) {
297
drv_T6_write_auto(*(data++));
300
debug("bug occurred at byte %d of %d, addr=%d", i, len, addr);
304
drv_T6_write_cmd(0xb2); /* Auto Reset */
308
static void drv_T6_blit(const int row, const int col, const int height, const int width)
314
for (r = row; r < row + height; r++) {
315
for (c = col; c < col + width; c++) {
316
unsigned char mask = 1 << (CELL - 1 - c % CELL);
317
if (drv_generic_graphic_black(r, c)) {
319
Buffer1[(r * DCOLS + c) / CELL] |= mask;
322
Buffer1[(r * DCOLS + c) / CELL] &= ~mask;
325
a = (r * DCOLS + col) / CELL;
326
b = (r * DCOLS + col + width + CELL - 1) / CELL;
327
for (i = a; i <= b; i++) {
328
if (Buffer1[i] == Buffer2[i])
330
for (j = i, e = 0; i <= b; i++) {
331
if (Buffer1[i] == Buffer2[i]) {
338
if (DualScan && r >= DROWS / 2) {
339
base = 0x8200 - DCOLS * DROWS / 2 / CELL;
344
memcpy(Buffer2 + j, Buffer1 + j, n);
345
drv_T6_copy(base + j, Buffer1 + j, n);
351
static int drv_T6_start(const char *section)
355
model = cfg_get(section, "Model", "generic");
356
if (model != NULL && *model != '\0') {
358
for (i = 0; Models[i].type != 0xff; i++) {
359
if (strcasecmp(Models[i].name, model) == 0)
362
if (Models[i].type == 0xff) {
363
error("%s: %s.Model '%s' is unknown from %s", Name, section, model, cfg_source());
368
error("%s: empty '%s.Model' entry from %s", Name, section, cfg_source());
372
/* read display size from config */
373
s = cfg_get(section, "Size", NULL);
374
if (s == NULL || *s == '\0') {
375
error("%s: no '%s.Size' entry from %s", Name, section, cfg_source());
381
if (sscanf(s, "%dx%d", &DCOLS, &DROWS) != 2 || DCOLS < 1 || DROWS < 1) {
382
error("%s: bad Size '%s' from %s", Name, s, cfg_source());
386
if (sscanf(s = cfg_get(section, "font", "6x8"), "%dx%d", &XRES, &YRES) != 2 || XRES < 1 || YRES < 1) {
387
error("%s: bad %s.Font '%s' from %s", Name, section, s, cfg_source());
394
/* get font width of display */
395
cfg_number(section, "Cell", 6, 5, 8, &CELL);
397
TROWS = DROWS / 8; /* text rows */
398
TCOLS = DCOLS / CELL; /* text columns */
400
/* get DualScan mode */
401
cfg_number(section, "DualScan", 0, 0, 1, &DualScan);
403
info("%s: %dx%d %sScan %d bits/cell", Name, DCOLS, DROWS, DualScan ? "Dual" : "Single", CELL);
405
Buffer1 = malloc(TCOLS * DROWS);
406
if (Buffer1 == NULL) {
407
error("%s: framebuffer #1 could not be allocated: malloc() failed", Name);
411
Buffer2 = malloc(TCOLS * DROWS);
412
if (Buffer2 == NULL) {
413
error("%s: framebuffer #2 could not be allocated: malloc() failed", Name);
417
memset(Buffer1, 0, TCOLS * DROWS * sizeof(*Buffer1));
418
memset(Buffer2, 0, TCOLS * DROWS * sizeof(*Buffer2));
420
if (drv_generic_parport_open(section, Name) != 0) {
421
error("%s: could not initialize parallel port!", Name);
426
if ((SIGNAL_CE = drv_generic_parport_wire_ctrl("CE", "STROBE")) == 0xff)
428
if ((SIGNAL_CD = drv_generic_parport_wire_ctrl("CD", "SLCTIN")) == 0xff)
430
if ((SIGNAL_RD = drv_generic_parport_wire_ctrl("RD", "AUTOFD")) == 0xff)
432
if ((SIGNAL_WR = drv_generic_parport_wire_ctrl("WR", "INIT")) == 0xff)
436
T_ACC = timing(Name, section, "ACC", 150, "ns"); /* Access Time */
437
T_OH = timing(Name, section, "OH", 50, "ns"); /* Output Hold Time */
438
T_PW = timing(Name, section, "PW", 80, "ns"); /* CE, RD, WR Pulse Width */
439
T_DH = timing(Name, section, "DH", 40, "ns"); /* Data Hold Time */
440
T_CDS = timing(Name, section, "CDS", 100, "ns"); /* C/D Setup Time */
443
/* rise CE, CD, RD and WR */
444
drv_generic_parport_control(SIGNAL_CE | SIGNAL_CD | SIGNAL_RD | SIGNAL_WR,
445
SIGNAL_CE | SIGNAL_CD | SIGNAL_RD | SIGNAL_WR);
446
/* set direction: write */
447
drv_generic_parport_direction(0);
450
/* initialize display */
452
drv_T6_send_word(0x40, 0x0000); /* Set Text Home Address */
453
drv_T6_send_word(0x41, TCOLS); /* Set Text Area */
455
drv_T6_send_word(0x42, 0x0200); /* Set Graphic Home Address */
456
drv_T6_send_word(0x43, TCOLS); /* Set Graphic Area */
458
drv_T6_write_cmd(0x80); /* Mode Set: OR mode, Internal CG RAM mode */
459
drv_T6_send_word(0x22, 0x0002); /* Set Offset Register */
460
drv_T6_write_cmd(0x98); /* Set Display Mode: Curser off, Text off, Graphics on */
461
drv_T6_write_cmd(0xa0); /* Set Cursor Pattern: 1 line cursor */
462
drv_T6_send_word(0x21, 0x0000); /* Set Cursor Pointer to (0,0) */
469
drv_T6_clear(0x0000, TCOLS * TROWS / 2); /* clear text area */
470
drv_T6_clear(0x0200, TCOLS * TROWS * 8 / 2); /* clear graphic area */
472
drv_T6_clear(0x8000, TCOLS * TROWS / 2); /* clear text area */
473
drv_T6_clear(0x8200, TCOLS * TROWS * 8 / 2); /* clear graphic area */
475
drv_T6_clear(0x0000, TCOLS * TROWS); /* clear text area */
476
drv_T6_clear(0x0200, TCOLS * TROWS * 8); /* clear graphic area */
483
/****************************************/
485
/****************************************/
487
/* none at the moment... */
490
/****************************************/
491
/*** exported functions ***/
492
/****************************************/
496
int drv_T6_list(void)
500
for (i = 0; Models[i].type != 0xff; i++) {
501
printf("%s ", Models[i].name);
507
/* initialize driver & display */
508
int drv_T6_init(const char *section, const int quiet)
512
info("%s: %s", Name, "$Rev: 1136 $");
514
/* real worker functions */
515
drv_generic_graphic_real_blit = drv_T6_blit;
518
if ((ret = drv_T6_start(section)) != 0)
521
/* initialize generic graphic driver */
522
if ((ret = drv_generic_graphic_init(section, Name)) != 0)
527
qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS);
528
if (drv_generic_graphic_greet(buffer, NULL)) {
530
drv_generic_graphic_clear();
534
/* register plugins */
535
/* none at the moment... */
542
/* close driver & display */
543
int drv_T6_quit(const int quiet)
546
info("%s: shutting down.", Name);
548
drv_generic_graphic_clear();
551
drv_generic_graphic_greet("goodbye!", NULL);
554
drv_generic_graphic_quit();
555
drv_generic_parport_close();