brewpanel/slcd.c

changeset 415
d9b7e0705f56
parent 412
f1a042a59b61
child 426
e54611453d29
equal deleted inserted replaced
414:0fa885045e20 415:d9b7e0705f56
31 31
32 #ifdef HAVE_SDL_SDL_H 32 #ifdef HAVE_SDL_SDL_H
33 33
34 // HD44780U Commands 34 // HD44780U Commands
35 35
36 #define SLCD_CLEAR 0x01 36 //#define SLCD_CLEAR 0x01
37 #define SLCD_HOME 0x02 37 //#define SLCD_HOME 0x02
38 #define SLCD_ENTRY 0x04 38 //#define SLCD_ENTRY 0x04
39 #define SLCD_CTRL 0x08 39 //#define SLCD_CTRL 0x08
40 #define SLCD_CDSHIFT 0x10 40 //#define SLCD_CDSHIFT 0x10
41 #define SLCD_FUNC 0x20 41 //#define SLCD_FUNC 0x20
42 #define SLCD_CGRAM 0x40 42 //#define SLCD_CGRAM 0x40
43 #define SLCD_DGRAM 0x80 43 //#define SLCD_DGRAM 0x80
44 44
45 // // Bits in the entry register 45 // // Bits in the entry register
46 // 46 //
47 // #define LCD_ENTRY_SH 0x01 47 // #define LCD_ENTRY_SH 0x01
48 // #define LCD_ENTRY_ID 0x02 48 // #define LCD_ENTRY_ID 0x02
49 // 49
50 // // Bits in the control register 50 // Bits in the control register
51 // 51 #define SLCD_BLINK_CTRL 0x01
52 // #define LCD_BLINK_CTRL 0x01 52 #define SLCD_CURSOR_CTRL 0x02
53 // #define LCD_CURSOR_CTRL 0x02 53 #define SLCD_DISPLAY_CTRL 0x04
54 // #define LCD_DISPLAY_CTRL 0x04
55 54
56 55
57 struct slcdDataStruct 56 struct slcdDataStruct
58 { 57 {
59 int x; /* Start x pixels */ 58 int x; /* Start x pixels */
63 int cols; /* Width in characters */ 62 int cols; /* Width in characters */
64 int rows; /* Height in characters */ 63 int rows; /* Height in characters */
65 int cx; /* Cursor x position */ 64 int cx; /* Cursor x position */
66 int cy; /* Cursor y position */ 65 int cy; /* Cursor y position */
67 Uint8 cgram[8][8]; /* Characters in CGRAM */ 66 Uint8 cgram[8][8]; /* Characters in CGRAM */
67 int control; /* Control register */
68 }; 68 };
69 struct slcdDataStruct *slcds [MAX_SLCDS] ; 69 struct slcdDataStruct *slcds [MAX_SLCDS] ;
70 70
71 71
72 /* Low level */
73
74 void sendDataCmd (struct slcdDataStruct *slcd, unsigned char data)
75 {
76 }
77
78
79 void putCommand (struct slcdDataStruct *slcd, unsigned char command)
80 {
81 }
82
83 72
84 73
85 void slcdHome(int fd) 74 void slcdHome(int fd)
86 { 75 {
87 struct slcdDataStruct *lcd = slcds [fd]; 76 struct slcdDataStruct *lcd = slcds [fd];
88 77
89 lcd->cx = lcd->cy = 0; 78 lcd->cx = lcd->cy = 0;
79 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL);
90 } 80 }
91 81
92 82
93 83
94 void slcdClear(int fd) 84 void slcdClear(int fd)
95 { 85 {
96 struct slcdDataStruct *lcd = slcds [fd]; 86 struct slcdDataStruct *lcd = slcds [fd];
87 int i;
97 88
98 lcd->cx = lcd->cy = 0; 89 lcd->cx = lcd->cy = 0;
90 for (i = 0; i < (lcd->cols * lcd->rows); i++)
91 slcdPutchar(fd, ' ');
92 lcd->cx = lcd->cy = 0;
93 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL);
99 } 94 }
100 95
101 96
102 97
103 void slcdDisplay(int fd, int state) 98 void slcdDisplay(int fd, int state)
104 { 99 {
100 struct slcdDataStruct *lcd = slcds [fd];
101
102 if (state)
103 lcd->control |= SLCD_DISPLAY_CTRL;
104 else
105 lcd->control &= ~SLCD_DISPLAY_CTRL;
105 } 106 }
106 107
107 108
108 109
109 void slcdCursor(int fd, int state) 110 void slcdCursor(int fd, int state)
110 { 111 {
112 struct slcdDataStruct *lcd = slcds [fd];
113
114 if (state)
115 lcd->control |= SLCD_CURSOR_CTRL;
116 else
117 lcd->control &= ~SLCD_CURSOR_CTRL;
118 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL);
111 } 119 }
112 120
113 121
114 122
115 void slcdCursorBlink(int fd, int state) 123 void slcdCursorBlink(int fd, int state)
116 { 124 {
117 } 125 struct slcdDataStruct *lcd = slcds [fd];
118 126
119 127 if (state)
120 128 lcd->control |= SLCD_BLINK_CTRL;
121 void slcdSendCommand(int fd, Uint8 command) 129 else
122 { 130 lcd->control &= ~SLCD_BLINK_CTRL;
131 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL);
123 } 132 }
124 133
125 134
126 135
127 void slcdPosition(int fd, int x, int y) 136 void slcdPosition(int fd, int x, int y)
131 if ((x > lcd->cols) || (x < 0)) 140 if ((x > lcd->cols) || (x < 0))
132 return ; 141 return ;
133 if ((y > lcd->rows) || (y < 0)) 142 if ((y > lcd->rows) || (y < 0))
134 return ; 143 return ;
135 144
136 // putCommand (lcd, x + (LCD_DGRAM | rowOff [y])) ;
137
138 lcd->cx = x ; 145 lcd->cx = x ;
139 lcd->cy = y ; 146 lcd->cy = y ;
147 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL);
140 } 148 }
141 149
142 150
143 151
144 void slcdCharDef(int fd, int index, Uint8 data[8]) 152 void slcdCharDef(int fd, int index, Uint8 data[8])
162 if (++lcd->cx == lcd->cols) { 170 if (++lcd->cx == lcd->cols) {
163 lcd->cx = 0; 171 lcd->cx = 0;
164 if (++lcd->cy == lcd->rows) 172 if (++lcd->cy == lcd->rows)
165 lcd->cy = 0; 173 lcd->cy = 0;
166 } 174 }
167 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8); 175 SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL);
168 } 176 }
169 177
170 178
171 179
172 void slcdPuts(int fd, const char *string) 180 void slcdPuts(int fd, const char *string)
228 lcd->cx = 0; 236 lcd->cx = 0;
229 lcd->cy = 0; 237 lcd->cy = 0;
230 for (i = 0; i < 8; i++) 238 for (i = 0; i < 8; i++)
231 for (j = 0; j < 8; j++) 239 for (j = 0; j < 8; j++)
232 lcd->cgram[i][j] = 0; 240 lcd->cgram[i][j] = 0;
241 lcd->control = 0;
233 242
234 slcds[fd] = lcd; 243 slcds[fd] = lcd;
235 244
236 slcdDisplay(fd, TRUE); 245 slcdDisplay(fd, TRUE);
237 slcdCursor(fd, FALSE); 246 slcdCursor(fd, FALSE);
242 * Most LCD's start with the top row filled with blocks. 251 * Most LCD's start with the top row filled with blocks.
243 */ 252 */
244 for (i = 0; i < lcd->cols; i++) 253 for (i = 0; i < lcd->cols; i++)
245 slcdPutchar(fd, 0x0ff); 254 slcdPutchar(fd, 0x0ff);
246 255
256 slcdDisplay(fd, TRUE);
257 slcdCursor(fd, FALSE);
258 slcdCursorBlink(fd, FALSE);
259 slcdClear(fd);
260
247 return fd; 261 return fd;
248 } 262 }
249 263
250 264
251 #endif 265 #endif

mercurial