Base: LCDproc 0.5.2
[lcdproc-de200c.git] / server / drivers / hd44780-low.h
blob0c9321813938cc52342d3fc73a15d5f81c075dd2
1 // This header contains low level code to export from hd44780.c to "lower" HW
2 // implementation dependent files.
4 #ifndef HD_LOW_H
5 #define HD_LOW_H
7 #ifdef HAVE_CONFIG_H
8 # include "config.h"
9 #endif
11 # if TIME_WITH_SYS_TIME
12 # include <sys/time.h>
13 # include <time.h>
14 # else
15 # if HAVE_SYS_TIME_H
16 # include <sys/time.h>
17 # else
18 # include <time.h>
19 # endif
20 # endif
23 //struct hwDependentFns;
25 // Maximum sizes of the keypad
26 // DO NOT CHANGE THESE 2 VALUES, unless you change the functions too
27 #define KEYPAD_MAXX 5
28 #define KEYPAD_MAXY 11
30 /* Constants for userdefchar_mode */
31 #define NUM_CCs 8 /* number of custom characters */
33 typedef enum {
34 standard, /* only char 0 is used for heartbeat */
35 vbar, /* vertical bars */
36 hbar, /* horizontal bars */
37 bignum, /* big numbers */
38 bigchar /* big characters */
39 } CGmode;
41 typedef struct cgram_cache {
42 unsigned char cache[LCD_DEFAULT_CELLHEIGHT];
43 int clean;
44 } CGram;
46 typedef struct ConnectionMapping {
47 char *name;
48 int (*init_fn)(Driver *drvthis);
49 const char *helpMsg;
50 } ConnectionMapping;
52 typedef struct driver_private_data {
54 unsigned int port;
56 /* for serial connection type */
57 int fd;
58 int serial_type;
60 int charmap;
62 int width, height;
63 int cellwidth, cellheight;
65 // The framebuffer
66 char *framebuf;
68 // For incremental updates store last lcd contents
69 char *lcd_contents;
71 // The defineable characters
72 CGram cc[NUM_CCs];
73 CGmode ccmode;
75 // Connection type data
76 int connectiontype_index;
77 struct hwDependentFns *hd44780_functions;
79 // spanList[line number] = display line number is in
80 int *spanList;
81 int numLines;
83 // dispVOffset is a cumulative sized array of line numbers for each display.
84 // use this to determine the vertical positioning on a given display
85 int *dispVOffset;
86 int numDisplays;
88 // dispSizes is the vertical size of each display. This is the same as the
89 // input span list but is kept to save some cpu cycles.
90 int *dispSizes;
92 // Keypad, backlight extended interface and delay options
93 char have_keypad; // off by default
94 char have_backlight; // off by default
95 char have_output; // have extra output port (off by default)
96 char ext_mode; // use of extended mode required for some weird controllers
97 int delayMult; // Delay multiplier for slow displays
98 char delayBus; // Delay if the computer can send data too fast over
99 // its bus to LPT port
100 char lastline; // lastline controls the use of the last line, if pixel addressable (true, default) or
101 // underline effect (false). To avoid the underline effect, last line is always zeroed
102 // for whatever redefined character
104 // keyMapDirect contains an array of the ascii-codes that should be generated
105 // when a directly connected key is pressed (not in matrix).
106 char *keyMapDirect[KEYPAD_MAXX];
108 // keyMapMatrix contrains an array with arrays of the ascii-codes that should be generated
109 // when a key in the matrix is pressed.
110 char *keyMapMatrix[KEYPAD_MAXY][KEYPAD_MAXX];
112 char *pressed_key;
113 int pressed_key_repetitions;
114 struct timeval pressed_key_time;
116 int stuckinputs;
118 int backlight_bit;
120 // force full refresh of display
121 time_t nextrefresh;
122 int refreshdisplay; // When >0 make a full display update every <refreshdisplay> seconds
123 time_t nextkeepalive;
124 int keepalivedisplay; // When >0 refresh upper left char every <keepalivedisplay> seconds to keep display alive
126 int output_state; // what was most recently output to the output port
127 } PrivateData;
129 // Structures holding pointers to HD44780 specific functions
130 typedef struct hwDependentFns {
131 // microsec pauses
132 void (*uPause)(PrivateData *p, int usecs);
134 // Senddata to the LCD
135 // dispID - display to send data to (0 = all displays)
136 // flags - data or instruction command (RS_DATA | RS_INSTR)
137 // ch - character to display or instruction value
138 void (*senddata)(PrivateData *p, unsigned char dispID, unsigned char flags, unsigned char ch);
140 // Switch the backlight on or off
141 // state - to be or not to be on
142 void (*backlight)(PrivateData *p, unsigned char state);
144 // Read the keypad
145 // Ydata - the up to 11 bits that should be put on the Y side of the matrix
146 // return - the up to 5 bits that are read out on the X side of the matrix
147 unsigned char (*readkeypad)(PrivateData *p, unsigned int Ydata);
149 // Scan the keypad and return a scancode.
150 // The code is the Yvalue in the high nibble and the Xvalue in the low nibble.
151 // A subdriver should do only one of two things:
152 // - set readkeypad; or
153 // - override scankeypad.
154 unsigned char (*scankeypad)(PrivateData *p);
156 // Output "data" to output latch if there is one
157 void (*output)(PrivateData *p, int data);
159 // Close the interface on shutdown
160 void (*close)(PrivateData *p);
162 } HD44780_functions; /* for want of a better name :-) */
165 void common_init(PrivateData *p, unsigned char if_bit);
168 // commands for senddata
169 #define RS_DATA 0x00
170 #define RS_INSTR 0x01
172 #define CLEAR 0x01
174 #define HOMECURSOR 0x02
176 #define ENTRYMODE 0x04
177 #define E_MOVERIGHT 0x02
178 #define E_MOVELEFT 0x00
179 #define EDGESCROLL 0x01
180 #define NOSCROLL 0x00
182 #define ONOFFCTRL 0x08 /* Only reachable with EXTREG clear */
183 #define DISPON 0x04
184 #define DISPOFF 0x00
185 #define CURSORON 0x02
186 #define CURSOROFF 0x00
187 #define CURSORBLINK 0x01
188 #define CURSORNOBLINK 0x00
190 #define EXTMODESET 0x08 /* Only reachable with EXTREG set */
191 #define FONT6WIDE 0x04
192 #define INVCURSOR 0x02
193 #define FOURLINE 0x01
195 #define CURSORSHIFT 0x10 /* Only reachable with EXTREG clear */
196 #define SCROLLDISP 0x08
197 #define MOVECURSOR 0x00
198 #define MOVERIGHT 0x04
199 #define MOVELEFT 0x00
201 #define HSCROLLEN 0x10 /* Only reachable with EXTREG set */
203 #define FUNCSET 0x20
204 #define IF_8BIT 0x10
205 #define IF_4BIT 0x00
206 #define TWOLINE 0x08
207 #define ONELINE 0x00
208 #define LARGECHAR 0x04 /* 5x11 characters */
209 #define SMALLCHAR 0x00 /* 5x8 characters */
210 #define EXTREG 0x04 /* Select ext. registers (Yes, the same bits)*/
211 #define SEGBLINK 0x02 /* Only reachable with EXTREG set */
212 #define POWERDOWN 0x01 /* Only reachable with EXTREG set */
214 #define SETCHAR 0x40 /* Only reachable with EXTREG clear */
216 #define SETSEG 0x40 /* Only reachable with EXTREG set */
218 #define POSITION 0x80 /* Only reachable with EXTREG clear */
220 #define HSCROLLAMOUNT 0x80 /* Only reachable with EXTREG set */
222 #endif