1
/* $Id: drv_MatrixOrbital.c 1140 2011-01-05 03:49:07Z michael $
2
* $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/drv_MatrixOrbital.c $
4
* new style driver for Matrix Orbital serial display modules
6
* Copyright (C) 1999, 2000 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_MatrixOrbital
47
#include "widget_text.h"
48
#include "widget_icon.h"
49
#include "widget_bar.h"
51
#include "drv_generic_text.h"
52
#include "drv_generic_gpio.h"
53
#include "drv_generic_serial.h"
56
static char Name[] = "MatrixOrbital";
61
static char dispBuffer[4][20];
73
/* Fixme #1: number of gpo's should be verified */
74
/* Fixme #2: protocol should be verified */
76
static MODEL Models[] = {
77
{0x01, "LCD0821", 2, 8, 0, 1, 1},
78
{0x03, "LCD2021", 2, 20, 0, 1, 1},
79
{0x04, "LCD1641", 4, 16, 0, 1, 1},
80
{0x05, "LCD2041", 4, 20, 0, 1, 1},
81
{0x06, "LCD4021", 2, 40, 0, 1, 1},
82
{0x07, "LCD4041", 4, 40, 0, 1, 1},
83
{0x08, "LK202-25", 2, 20, 8, 8, 2},
84
{0x09, "LK204-25", 4, 20, 8, 8, 2},
85
{0x0a, "LK404-55", 4, 40, 8, 8, 2},
86
{0x0b, "VFD2021", 2, 20, 0, 1, 1},
87
{0x0c, "VFD2041", 4, 20, 0, 1, 1},
88
{0x0d, "VFD4021", 2, 40, 0, 1, 1},
89
{0x0e, "VK202-25", 2, 20, 0, 1, 1},
90
{0x0f, "VK204-25", 4, 20, 0, 1, 1},
91
{0x10, "GLC12232", -1, -1, 0, 1, 1},
92
{0x13, "GLC24064", -1, -1, 0, 1, 1},
93
{0x15, "GLK24064-25", -1, -1, 0, 1, 1},
94
{0x22, "GLK12232-25", -1, -1, 0, 1, 1},
95
{0x31, "LK404-AT", 4, 40, 8, 8, 2},
96
{0x32, "VFD1621", 2, 16, 0, 1, 1},
97
{0x33, "LK402-12", 2, 40, 8, 8, 2},
98
{0x34, "LK162-12", 2, 16, 8, 8, 2},
99
{0x35, "LK204-25PC", 4, 20, 8, 8, 2},
100
{0x36, "LK202-24-USB", 2, 20, 8, 8, 2},
101
{0x38, "LK204-24-USB", 4, 20, 8, 8, 2},
102
{0x39, "VK204-24-USB", 4, 20, 8, 8, 2},
103
{0x40, "DE-LD011", 2, 16, 0, 0, 3}, /* Sure electronics USB LCD board Rev.I */
104
{0x41, "DE-LD021", 4, 20, 0, 0, 3},
105
{0xff, "Unknown", -1, -1, 0, 0, 0}
109
/****************************************/
110
/*** hardware dependant functions ***/
111
/****************************************/
113
static void drv_MO_write(const int row, const int col, const char *data, const int len)
115
char cmd[5] = "\376Gyx";
117
if (Models[Model].protocol == 3) { // Sure electronics USB LCD board - full line output
119
cmd[3] = (char) row + 1;
120
strncpy(&(dispBuffer[row][col]), data, len);
121
drv_generic_serial_write(cmd, 4);
122
drv_generic_serial_write(dispBuffer[row], Models[Model].cols);
124
cmd[2] = (char) col + 1;
125
cmd[3] = (char) row + 1;
126
drv_generic_serial_write(cmd, 4);
127
drv_generic_serial_write(data, len);
132
static void drv_MO_clear(void)
138
drv_generic_serial_write("\014", 1); /* Clear Screen */
141
drv_generic_serial_write("\376\130", 2); /* Clear Screen */
145
/* Sure electronics USB LCD board - clear buffer */
146
for (i = 0; i < Models[Model].rows; i++) {
147
for (j = 0; j < Models[Model].cols; j++) {
148
dispBuffer[i][j] = ' ';
150
drv_MO_write(1, i + 1, dispBuffer[i], Models[Model].cols);
157
static void drv_MO_defchar(const int ascii, const unsigned char *matrix)
160
char cmd[11] = "\376N";
162
cmd[2] = (char) ascii;
163
for (i = 0; i < 8; i++) {
164
cmd[i + 3] = matrix[i] & 0x1f;
166
drv_generic_serial_write(cmd, 11);
170
static int drv_MO_contrast(int contrast)
172
static unsigned char Contrast = 0;
173
char cmd[3] = "\376Pn";
175
/* -1 is used to query the current contrast */
187
drv_generic_serial_write(cmd, 3);
193
static int drv_MO_backlight(int backlight)
195
static unsigned char Backlight = 0;
196
char cmd[3] = "\376Bn";
198
/* -1 is used to query the current backlight */
206
Backlight = backlight;
208
if (backlight <= 0) {
210
drv_generic_serial_write("\376F", 2);
212
/* backlight on for n minutes */
214
drv_generic_serial_write(cmd, 3);
221
static int drv_MO_GPI(const int num)
223
static int GPI[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
224
static time_t T[8], now;
227
if (num < 0 || num > 7) {
231
/* read RPM every two seconds */
232
if (time(&now) - T[num] >= 2) {
235
unsigned char ans[7];
241
cmd[2] = (char) num + 1;
242
drv_generic_serial_write(cmd, 3);
245
if (drv_generic_serial_read((char *) ans, 7) == 7) {
246
if (ans[0] == 0x23 && ans[1] == 0x2a && ans[2] == 0x03 && ans[3] == 0x52 && ans[4] == num + 1) {
247
GPI[num] = 18750000 / (256 * ans[5] + ans[6]);
249
error("%s: strange answer %02x %02x %02x %02x %02x %02x %02x", Name, ans[0], ans[1], ans[2], ans[3],
250
ans[4], ans[5], ans[6]);
259
static int drv_MO_GPO(const int num, const int val)
269
drv_generic_serial_write("\376W", 2); /* GPO on */
272
drv_generic_serial_write("\376V", 2); /* GPO off */
281
cmd[1] = 'V'; /* GPO off */
282
cmd[2] = (char) num + 1;
283
drv_generic_serial_write(cmd, 3);
284
} else if (val >= 255) {
287
cmd[1] = 'W'; /* GPO on */
288
cmd[2] = (char) num + 1;
289
drv_generic_serial_write(cmd, 3);
293
cmd[1] = '\300'; /* PWM control */
294
cmd[2] = (char) num + 1;
296
drv_generic_serial_write(cmd, 4);
305
static int drv_MO_start(const char *section, const int quiet)
311
model = cfg_get(section, "Model", NULL);
312
if (model != NULL && *model != '\0') {
313
for (i = 0; Models[i].type != 0xff; i++) {
314
if (strcasecmp(Models[i].name, model) == 0)
317
if (Models[i].type == 0xff) {
318
error("%s: %s.Model '%s' is unknown from %s", Name, section, model, cfg_source());
322
info("%s: using model '%s'", Name, Models[Model].name);
324
info("%s: no '%s.Model' entry from %s, auto-dedecting", Name, section, cfg_source());
328
if (Model != -1 && Models[Model].protocol == 3) { // Sure electronics USB LCD board - full line output
330
for (i = 0; i < Models[Model].rows; i++) { // Clear buffer
331
for (j = 0; j < Models[Model].cols; j++) {
332
dispBuffer[i][j] = ' ';
337
if (drv_generic_serial_open(section, Name, 0) < 0)
340
if (Model == -1 || Models[Model].protocol > 1) {
341
/* read module type */
342
drv_generic_serial_write("\3767", 2);
344
if (drv_generic_serial_read(buffer, 1) == 1) {
345
for (i = 0; Models[i].type != 0xff; i++) {
346
if (Models[i].type == (int) *buffer)
349
info("%s: display reports model '%s' (type 0x%02x)", Name, Models[i].name, Models[i].type);
355
/* auto-dedection matches specified model? */
356
if (Models[i].type != 0xff && Model != i) {
357
error("%s: %s.Model '%s' from %s does not match dedected Model '%s'", Name, section, model,
358
cfg_source(), Models[i].name);
363
info("%s: display detection failed.", Name);
367
/* initialize global variables */
368
DROWS = Models[Model].rows;
369
DCOLS = Models[Model].cols;
370
GPIS = Models[Model].gpis;
371
GPOS = Models[Model].gpos;
372
Protocol = Models[Model].protocol;
375
/* read serial number */
376
drv_generic_serial_write("\3765", 2);
378
if (drv_generic_serial_read(buffer, 2) == 2) {
379
info("%s: display reports serial number 0x%x", Name, *(short *) buffer);
382
/* read version number */
383
drv_generic_serial_write("\3766", 2);
385
if (drv_generic_serial_read(buffer, 1) == 1) {
386
info("%s: display reports firmware version 0x%x", Name, *buffer);
392
drv_generic_serial_write("\376B", 3); /* backlight on */
393
drv_generic_serial_write("\376K", 2); /* cursor off */
394
drv_generic_serial_write("\376T", 2); /* blink off */
395
drv_generic_serial_write("\376D", 2); /* line wrapping off */
396
drv_generic_serial_write("\376R", 2); /* auto scroll off */
399
if (cfg_number(section, "Contrast", 0, 0, 255, &i) > 0) {
404
if (cfg_number(section, "Backlight", 0, 0, 255, &i) > 0) {
409
if (drv_generic_text_greet(Models[Model].name, "MatrixOrbital")) {
419
/****************************************/
421
/****************************************/
424
static void plugin_contrast(RESULT * result, const int argc, RESULT * argv[])
430
contrast = drv_MO_contrast(-1);
431
SetResult(&result, R_NUMBER, &contrast);
434
contrast = drv_MO_contrast(R2N(argv[0]));
435
SetResult(&result, R_NUMBER, &contrast);
438
error("%s::contrast(): wrong number of parameters", Name);
439
SetResult(&result, R_STRING, "");
444
static void plugin_backlight(RESULT * result, const int argc, RESULT * argv[])
450
backlight = drv_MO_backlight(-1);
451
SetResult(&result, R_NUMBER, &backlight);
454
backlight = drv_MO_backlight(R2N(argv[0]));
455
SetResult(&result, R_NUMBER, &backlight);
458
error("%s::backlight(): wrong number of parameters", Name);
459
SetResult(&result, R_STRING, "");
464
/****************************************/
465
/*** widget callbacks ***/
466
/****************************************/
468
/* using drv_generic_text_draw(W) */
469
/* using drv_generic_text_icon_draw(W) */
470
/* using drv_generic_text_bar_draw(W) */
471
/* using drv_generic_gpio_draw(W) */
474
/****************************************/
475
/*** exported functions ***/
476
/****************************************/
480
int drv_MO_list(void)
484
for (i = 0; Models[i].type != 0xff; i++) {
485
printf("%s ", Models[i].name);
491
/* initialize driver & display */
492
int drv_MO_init(const char *section, const int quiet)
498
info("%s: %s", Name, "$Rev: 1140 $");
500
/* display preferences */
501
XRES = 5; /* pixel width of one char */
502
YRES = 8; /* pixel height of one char */
503
CHARS = 8; /* number of user-defineable characters */
504
CHAR0 = 0; /* ASCII of first user-defineable char */
505
GOTO_COST = 4; /* number of bytes a goto command requires */
507
/* real worker functions */
508
drv_generic_text_real_write = drv_MO_write;
509
drv_generic_text_real_defchar = drv_MO_defchar;
510
drv_generic_gpio_real_get = drv_MO_GPI;
511
drv_generic_gpio_real_set = drv_MO_GPO;
515
if ((ret = drv_MO_start(section, quiet)) != 0)
518
/* initialize generic text driver */
519
if ((ret = drv_generic_text_init(section, Name)) != 0)
522
/* initialize generic icon driver */
523
if ((ret = drv_generic_text_icon_init()) != 0)
526
/* initialize generic bar driver */
527
if ((ret = drv_generic_text_bar_init(0)) != 0)
530
/* add fixed chars to the bar driver */
531
/* most displays have a full block on ascii 255, but some have kind of */
532
/* an 'inverted P'. If you specify 'asc255bug 1 in the config, this */
533
/* char will not be used, but rendered by the bar driver */
534
cfg_number(section, "asc255bug", 0, 0, 1, &asc255bug);
535
drv_generic_text_bar_add_segment(0, 0, 255, 32); /* ASCII 32 = blank */
537
drv_generic_text_bar_add_segment(255, 255, 255, 255); /* ASCII 255 = block */
539
/* initialize generic GPIO driver */
540
if ((ret = drv_generic_gpio_init(section, Name)) != 0)
543
/* register text widget */
545
wc.draw = drv_generic_text_draw;
546
widget_register(&wc);
548
/* register icon widget */
550
wc.draw = drv_generic_text_icon_draw;
551
widget_register(&wc);
553
/* register bar widget */
555
wc.draw = drv_generic_text_bar_draw;
556
widget_register(&wc);
558
/* register plugins */
559
AddFunction("LCD::contrast", -1, plugin_contrast);
560
AddFunction("LCD::backlight", -1, plugin_backlight);
566
/* close driver & display */
567
int drv_MO_quit(const int quiet)
570
info("%s: shutting down display.", Name);
572
drv_generic_text_quit();
573
drv_generic_gpio_quit();
582
drv_generic_text_greet("goodbye!", NULL);
587
drv_generic_serial_close();
593
DRIVER drv_MatrixOrbital = {