1
/* $Id: drv_Pertelian.c 975 2009-01-18 11:16:20Z michael $
2
* $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/drv_Pertelian.c $
4
* Pertelian lcd4linux driver
5
* Copyright (C) 2007 Andy Powell <lcd4linux@automted.it>
7
* Copyright (C) 2005 Michael Reinelt <michael@reinelt.co.at>
8
* Copyright (C) 2005, 2006, 2007 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
10
* This file is part of LCD4Linux.
12
* LCD4Linux is free software; you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation; either version 2, or (at your option)
17
* LCD4Linux is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32
* struct DRIVER drv_Pertelian
50
#include "widget_text.h"
51
#include "widget_icon.h"
52
#include "widget_bar.h"
55
#include "drv_generic_text.h"
56
#include "drv_generic_serial.h"
58
static char Name[] = "Pertelian";
60
static unsigned char rowoffset[4] = { 0x80, 0x80 + 0x40, 0x80 + 0x14, 0x80 + 0x40 + 0x14 };
62
#define PERTELIAN_LCDCOMMAND 0xfe
64
/****************************************/
65
/*** hardware dependant functions ***/
66
/****************************************/
69
static int drv_Pertelian_open(const char *section)
71
if (drv_generic_serial_open(section, Name, 0) < 0)
77
static int drv_Pertelian_close(void)
79
drv_generic_serial_close();
84
static void drv_Pertelian_send(const char *data, const unsigned int len)
88
/* Pertelian interface seems to offer no buffering at all
89
so we have to slow things down a tad yes 1usec is enough */
91
for (i = 0; i < len; i++) {
92
drv_generic_serial_write(&data[i], 1);
98
static void drv_Pertelian_clear(void)
102
cmd[0] = PERTELIAN_LCDCOMMAND;
104
drv_Pertelian_send(cmd, 2);
108
static void drv_Pertelian_write(const int row, const int col, const char *data, int len)
112
cmd[0] = PERTELIAN_LCDCOMMAND;
113
cmd[1] = ((rowoffset[row]) + (col));
114
drv_Pertelian_send(cmd, 2);
115
drv_Pertelian_send(data, len);
119
static void drv_Pertelian_defchar(const int ascii, const unsigned char *matrix)
124
cmd[0] = PERTELIAN_LCDCOMMAND;
125
cmd[1] = (0x40 + (8 * ascii));
126
for (i = 0; i < 8; i++) {
127
cmd[i + 2] = matrix[i] & 0x1f;
129
drv_Pertelian_send(cmd, 10);
133
static int drv_Pertelian_backlight(int backlight)
139
else if (backlight >= 1)
142
cmd[0] = PERTELIAN_LCDCOMMAND;
145
drv_Pertelian_send(cmd, 2);
151
static int drv_Pertelian_start(const char *section)
154
int rows = -1, cols = -1;
158
s = cfg_get(section, "Size", NULL);
159
if (s == NULL || *s == '\0') {
160
error("%s: no '%s.Size' entry from %s", Name, section, cfg_source());
163
if (sscanf(s, "%dx%d", &cols, &rows) != 2 || rows < 1 || cols < 1) {
164
error("%s: bad %s.Size '%s' from %s", Name, section, s, cfg_source());
172
/* open communication with the display */
173
if (drv_Pertelian_open(section) < 0) {
177
/* reset & initialize display */
178
cmd[0] = PERTELIAN_LCDCOMMAND;
180
cmd[2] = PERTELIAN_LCDCOMMAND;
182
cmd[4] = PERTELIAN_LCDCOMMAND;
183
cmd[5] = 0x10; /* move cursor on data write */
184
cmd[6] = PERTELIAN_LCDCOMMAND;
188
drv_Pertelian_send(cmd, 8);
190
if (cfg_number(section, "Backlight", 0, 0, 1, &backlight) > 0) {
191
drv_Pertelian_backlight(backlight);
194
drv_Pertelian_clear(); /* clear display */
199
/****************************************/
201
/****************************************/
203
static void plugin_backlight(RESULT * result, RESULT * arg1)
205
double backlight = 0;
206
backlight = drv_Pertelian_backlight(R2N(arg1));
207
SetResult(&result, R_NUMBER, &backlight);
210
/****************************************/
211
/*** widget callbacks ***/
212
/****************************************/
215
/* using drv_generic_text_draw(W) */
216
/* using drv_generic_text_icon_draw(W) */
217
/* using drv_generic_text_bar_draw(W) */
218
/* using drv_generic_gpio_draw(W) */
221
/****************************************/
222
/*** exported functions ***/
223
/****************************************/
227
int drv_Pertelian_list(void)
229
printf("Pertelian X2040 displays");
234
/* initialize driver & display */
235
int drv_Pertelian_init(const char *section, const int quiet)
240
info("%s: %s", Name, "$Rev: 975 $");
242
/* display preferences */
243
XRES = 5; /* pixel width of one char */
244
YRES = 8; /* pixel height of one char */
245
CHARS = 8; /* number of user-defineable characters */
246
CHAR0 = 0; /* ASCII of first user-defineable char */
247
GOTO_COST = 2; /* number of bytes a goto command requires */
249
/* real worker functions */
250
drv_generic_text_real_write = drv_Pertelian_write;
251
drv_generic_text_real_defchar = drv_Pertelian_defchar;
255
if ((ret = drv_Pertelian_start(section)) != 0)
260
qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS);
261
if (drv_generic_text_greet(buffer, "LinITX.com")) {
263
drv_Pertelian_clear();
267
/* initialize generic text driver */
268
if ((ret = drv_generic_text_init(section, Name)) != 0)
271
/* initialize generic icon driver */
272
if ((ret = drv_generic_text_icon_init()) != 0)
275
/* initialize generic bar driver */
276
if ((ret = drv_generic_text_bar_init(0)) != 0)
279
/* add fixed chars to the bar driver */
280
drv_generic_text_bar_add_segment(0, 0, 255, 32); /* ASCII 32 = blank */
283
/* register text widget */
285
wc.draw = drv_generic_text_draw;
286
widget_register(&wc);
288
/* register icon widget */
290
wc.draw = drv_generic_text_icon_draw;
291
widget_register(&wc);
293
/* register bar widget */
295
wc.draw = drv_generic_text_bar_draw;
296
widget_register(&wc);
297
AddFunction("LCD::backlight", 1, plugin_backlight);
302
/* close driver & display */
303
int drv_Pertelian_quit(const int quiet)
306
info("%s: shutting down.", Name);
308
drv_generic_text_quit();
311
drv_Pertelian_clear();
315
drv_generic_text_greet("goodbye!", NULL);
318
drv_Pertelian_backlight(0);
319
debug("closing connection");
320
drv_Pertelian_close();
326
DRIVER drv_Pertelian = {
328
.list = drv_Pertelian_list,
329
.init = drv_Pertelian_init,
330
.quit = drv_Pertelian_quit,