~siretart/lcd4linux/debian

« back to all changes in this revision

Viewing changes to drv_FW8888.c

  • Committer: Reinhard Tartler
  • Date: 2011-04-27 17:28:49 UTC
  • mfrom: (0.1.1 upstream)
  • Revision ID: siretart@tauware.de-20110427172849-mj5cj5a0igpcc9fn
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: drv_FW8888.c 1123 2010-06-21 02:07:13Z michael $
 
2
 * $URL: https://ssl.bulix.org/svn/lcd4linux/trunk/drv_FW8888.c $
 
3
 *
 
4
 * driver for Allnet FW8888 display
 
5
 *
 
6
 * Copyright (C) 2005 Michael Reinelt <michael@reinelt.co.at>
 
7
 * Copyright (C) 2005, 2006, 2007 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
 
8
 * Copyright (C) 2010 Linum Software GmbH <support@linum.com>
 
9
 *
 
10
 * This file is part of LCD4Linux.
 
11
 *
 
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)
 
15
 * any later version.
 
16
 *
 
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.
 
21
 *
 
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.
 
25
 *
 
26
 */
 
27
 
 
28
/* 
 
29
 *
 
30
 * exported fuctions:
 
31
 *
 
32
 * struct DRIVER drv_FW8888
 
33
 *
 
34
 */
 
35
 
 
36
#include "config.h"
 
37
 
 
38
#include <stdlib.h>
 
39
#include <stdio.h>
 
40
#include <unistd.h>
 
41
#include <string.h>
 
42
#include <errno.h>
 
43
 
 
44
#include "debug.h"
 
45
#include "cfg.h"
 
46
#include "qprintf.h"
 
47
#include "udelay.h"
 
48
#include "plugin.h"
 
49
#include "widget.h"
 
50
#include "widget_text.h"
 
51
#include "widget_icon.h"
 
52
#include "widget_bar.h"
 
53
#include "drv.h"
 
54
 
 
55
/* text mode display? */
 
56
#include "drv_generic_text.h"
 
57
 
 
58
/* serial port? */
 
59
#include "drv_generic_serial.h"
 
60
 
 
61
static char Name[] = "FW8888";
 
62
 
 
63
 
 
64
/****************************************/
 
65
/***  hardware dependant functions    ***/
 
66
/****************************************/
 
67
 
 
68
static int drv_FW8888_open(const char *section)
 
69
{
 
70
    /* open serial port */
 
71
    /* don't mind about device, speed and stuff, this function will take care of */
 
72
 
 
73
    if (drv_generic_serial_open(section, Name, 0) < 0)
 
74
        return -1;
 
75
 
 
76
    return 0;
 
77
}
 
78
 
 
79
 
 
80
static int drv_FW8888_close(void)
 
81
{
 
82
    /* close whatever port you've opened */
 
83
    drv_generic_serial_close();
 
84
 
 
85
    return 0;
 
86
}
 
87
 
 
88
 
 
89
static void drv_FW8888_send_cmd(const unsigned int cmd)
 
90
{
 
91
    char cmd_str[2];
 
92
 
 
93
    cmd_str[0] = 0x10;
 
94
    cmd_str[1] = cmd;
 
95
    drv_generic_serial_write(cmd_str, 2);
 
96
}
 
97
 
 
98
 
 
99
static void drv_FW8888_send_text(const char *text, const unsigned int len)
 
100
{
 
101
    unsigned int i;
 
102
    char cmd_str[2];
 
103
 
 
104
    cmd_str[0] = 0x12;
 
105
 
 
106
    for (i = 0; i < len; i++) {
 
107
        cmd_str[1] = text[i];
 
108
        drv_generic_serial_write(cmd_str, 2);
 
109
    }
 
110
}
 
111
 
 
112
/* text mode displays only */
 
113
static void drv_FW8888_clear(void)
 
114
{
 
115
    drv_FW8888_send_cmd(0x01);
 
116
}
 
117
 
 
118
static void drv_FW8888_home(void)
 
119
{
 
120
    drv_FW8888_send_cmd(0x02);
 
121
}
 
122
 
 
123
static void drv_FW8888_display_off(void)
 
124
{
 
125
    drv_FW8888_send_cmd(0x08);
 
126
}
 
127
 
 
128
static void drv_FW8888_display_on_cursor_off(void)
 
129
{
 
130
    drv_FW8888_send_cmd(0x0C);
 
131
}
 
132
 
 
133
static void drv_FW8888_display_on_cursor_on(void)
 
134
{
 
135
    drv_FW8888_send_cmd(0x0E);
 
136
}
 
137
 
 
138
static void drv_FW8888_backlight_off(void)
 
139
{
 
140
    drv_FW8888_send_cmd(0x38);
 
141
}
 
142
 
 
143
static void drv_FW8888_backlight_on(void)
 
144
{
 
145
    drv_FW8888_send_cmd(0x39);
 
146
}
 
147
 
 
148
static void drv_FW8888_set_cursor(int row, int col)
 
149
{
 
150
    int pos;
 
151
    switch (row) {
 
152
    case 0:
 
153
        pos = 0x80 + col;
 
154
        break;
 
155
    case 1:
 
156
        pos = 0xC0 + col;
 
157
        break;
 
158
    default:
 
159
        error("%s: invalid row(%d) or col(%d)", Name, row, col);
 
160
        return;
 
161
    }
 
162
    drv_FW8888_send_cmd(pos);
 
163
}
 
164
 
 
165
 
 
166
/* text mode displays only */
 
167
static void drv_FW8888_write(const int row, const int col, const char *data, int len)
 
168
{
 
169
    /* do the cursor positioning here */
 
170
    drv_FW8888_set_cursor(row, col);
 
171
 
 
172
    /* send string to the display */
 
173
    drv_FW8888_send_text(data, len);
 
174
}
 
175
 
 
176
 
 
177
/* start text mode display */
 
178
static int drv_FW8888_start(const char *section)
 
179
{
 
180
    /* display preferences */
 
181
    XRES = 5;                   /* pixel width of one char  */
 
182
    YRES = 8;                   /* pixel height of one char  */
 
183
    CHARS = 0;                  /* number of user-defineable characters */
 
184
    CHAR0 = 0;                  /* ASCII of first user-defineable char */
 
185
    DROWS = 2;
 
186
    DCOLS = 16;
 
187
 
 
188
    GOTO_COST = -1;             /* number of bytes a goto command requires */
 
189
 
 
190
    /* open communication with the display */
 
191
    if (drv_FW8888_open(section) < 0) {
 
192
        return -1;
 
193
    }
 
194
 
 
195
    drv_FW8888_clear();         /* clear display */
 
196
 
 
197
    return 0;
 
198
}
 
199
 
 
200
 
 
201
 
 
202
/****************************************/
 
203
/***            plugins               ***/
 
204
/****************************************/
 
205
 
 
206
/* none */
 
207
 
 
208
/****************************************/
 
209
/***        widget callbacks          ***/
 
210
/****************************************/
 
211
 
 
212
 
 
213
/* using drv_generic_text_draw(W) */
 
214
/* using drv_generic_text_icon_draw(W) */
 
215
/* using drv_generic_text_bar_draw(W) */
 
216
/* using drv_generic_gpio_draw(W) */
 
217
 
 
218
 
 
219
/****************************************/
 
220
/***        exported functions        ***/
 
221
/****************************************/
 
222
 
 
223
 
 
224
/* list models */
 
225
int drv_FW8888_list(void)
 
226
{
 
227
    printf("Allnet-FW8888");
 
228
    return 0;
 
229
}
 
230
 
 
231
 
 
232
/* initialize driver & display */
 
233
/* use this function for a text display */
 
234
int drv_FW8888_init(const char *section, const int quiet)
 
235
{
 
236
    WIDGET_CLASS wc;
 
237
    int ret;
 
238
 
 
239
    info("%s: %s", Name, "$Rev: 1123 $");
 
240
 
 
241
    /* display preferences */
 
242
    XRES = 5;                   /* pixel width of one char  */
 
243
    YRES = 7;                   /* pixel height of one char  */
 
244
    CHARS = 0;                  /* number of user-defineable characters */
 
245
    CHAR0 = 0;                  /* ASCII of first user-defineable char */
 
246
 
 
247
    /* real worker functions */
 
248
    drv_generic_text_real_write = drv_FW8888_write;
 
249
 
 
250
    /* start display */
 
251
    if ((ret = drv_FW8888_start(section)) != 0)
 
252
        return ret;
 
253
 
 
254
    if (!quiet) {
 
255
        char buffer[40];
 
256
        qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS);
 
257
        if (drv_generic_text_greet(buffer, "www.linum.com")) {
 
258
            sleep(3);
 
259
            drv_FW8888_clear();
 
260
        }
 
261
    }
 
262
 
 
263
    /* initialize generic text driver */
 
264
    if ((ret = drv_generic_text_init(section, Name)) != 0)
 
265
        return ret;
 
266
 
 
267
    /* register text widget */
 
268
    wc = Widget_Text;
 
269
    wc.draw = drv_generic_text_draw;
 
270
    widget_register(&wc);
 
271
 
 
272
    /* register plugins */
 
273
    //    AddFunction("LCD::contrast", 1, plugin_contrast);
 
274
 
 
275
    return 0;
 
276
}
 
277
 
 
278
 
 
279
/* close driver & display */
 
280
/* use this function for a text display */
 
281
int drv_FW8888_quit(const int quiet)
 
282
{
 
283
 
 
284
    info("%s: shutting down.", Name);
 
285
 
 
286
    drv_generic_text_quit();
 
287
 
 
288
    /* clear display */
 
289
    drv_FW8888_clear();
 
290
 
 
291
    /* say goodbye... */
 
292
    if (!quiet) {
 
293
        drv_generic_text_greet("goodbye!", NULL);
 
294
    }
 
295
 
 
296
    debug("closing connection");
 
297
    drv_FW8888_close();
 
298
 
 
299
    return (0);
 
300
}
 
301
 
 
302
 
 
303
/* use this one for a text display */
 
304
DRIVER drv_FW8888 = {
 
305
    .name = Name,
 
306
    .list = drv_FW8888_list,
 
307
    .init = drv_FW8888_init,
 
308
    .quit = drv_FW8888_quit,
 
309
};