forked from adafruit/ST7565-LCD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stlcd.c
485 lines (396 loc) · 14.3 KB
/
stlcd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
/*
$Id:$
ST7565 LCD library!
Copyright (C) 2010 Limor Fried, Adafruit Industries
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// some of this code was written by <cstone@pobox.com> originally; it is in the public domain.
*/
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include "stlcd.h"
#include "glcd.h"
#include "util.h"
#include "icon.h"
#define BLA_DDR DDRB
#define BLA_PIN PINB
#define BLA_PORT PORTB
#define BLA 2
#define SID_DDR DDRB
#define SID_PIN PINB
#define SID_PORT PORTB
#define SID 1
#define SCLK_DDR DDRB
#define SCLK_PIN PINB
#define SCLK_PORT PORTB
#define SCLK 0
#define A0_DDR DDRD
#define A0_PIN PIND
#define A0_PORT PORTD
#define A0 7
#define RST_DDR DDRD
#define RST_PIN PIND
#define RST_PORT PORTD
#define RST 6
#define CS_DDR DDRD
#define CS_PIN PIND
#define CS_PORT PORTD
#define CS 5
#define LED_DDR DDRD
#define LED_PORT PORTD
#define LED 2
uint8_t is_reversed = 0;
int pagemap[] = { 3, 2, 1, 0, 7, 6, 5, 4 };
uint8_t buffer[128*64/8] = {
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0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, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
};
int main(void) {
setup();
while (1) {
loop();
}
}
void loop(void) {}
void setup(void) {
//Serial.begin(9600);
uart_init(BRRL_192);
// turn on backlight
BLA_DDR |= _BV(BLA);
BLA_PORT |= _BV(BLA);
LED_DDR |= _BV(LED);
// Serial.println("init");
putstring_nl("init!");
st7565_init();
/*
while (1) {
spiwrite(0x55);
_delay_ms(100);
}
*/
//Serial.println("on");
putstring_nl("on");
st7565_command(CMD_DISPLAY_ON);
//Serial.println("normal");
putstring_nl("normal");
st7565_command(CMD_SET_ALLPTS_NORMAL);
//Serial.println("bright");
putstring_nl("bright");
st7565_set_brightness(0x18);
//Serial.println("clear");
putstring_nl("clear");
clear_screen();
//Serial.println("blit");
putstring_nl("blit");
write_buffer(buffer);
putstring_nl("done");
_delay_ms(250);
clear_buffer(buffer);
LED_PORT |= _BV(LED);
//drawrect(buffer, 10, 10, 2, 2, 1);
// testdrawrect(buffer);
// testfillrect(buffer);
// testdrawline(buffer);
//testdrawcircle(buffer);
//fillcircle(buffer, 32, 32, 10, 1);
//testdrawchar(buffer);
// drawstring(buffer, 0, 0, "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
testdrawbitmap(buffer, logo16_glcd_bmp, 16, 16);
LED_PORT &= ~_BV(LED);
write_buffer(buffer);
}
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
void testdrawbitmap(uint8_t *buff, const uint8_t *bitmap, uint8_t w, uint8_t h) {
uint8_t icons[NUMFLAKES][3];
srandom(buff[666]);
// initialize
for (uint8_t f=0; f< NUMFLAKES; f++) {
icons[f][XPOS] = random() % 128;
icons[f][YPOS] = 0;
icons[f][DELTAY] = random() % 5 + 1;
}
while (1) {
// draw each icon
for (uint8_t f=0; f< NUMFLAKES; f++) {
drawbitmap(buffer, icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, 1);
}
write_buffer(buffer);
_delay_ms(200);
// then erase it + move it
for (uint8_t f=0; f< NUMFLAKES; f++) {
drawbitmap(buffer, icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, 0);
// move it
icons[f][YPOS] += icons[f][DELTAY];
// if its gone, reinit
if (icons[f][YPOS] > 64) {
icons[f][XPOS] = random() % 128;
icons[f][YPOS] = 0;
icons[f][DELTAY] = random() % 5 + 1;
}
}
}
}
void testdrawchar(uint8_t *buff) {
for (uint8_t i=0; i < 168; i++) {
drawchar(buffer, (i % 21) * 6, i/21, i);
}
}
void testdrawcircle(uint8_t *buff) {
for (uint8_t i=0; i<64; i+=2) {
drawcircle(buffer, 63, 31, i, 1);
}
}
void testdrawline(uint8_t *buff) {
for (uint8_t i=0; i<128; i+=4) {
drawline(buffer, 0, 0, i, 63, 1);
}
for (uint8_t i=0; i<64; i+=4) {
drawline(buffer, 0, 0, 127, i, 1);
}
write_buffer(buffer);
_delay_ms(1000);
for (uint8_t i=0; i<128; i+=4) {
drawline(buffer, i, 63, 0, 0, 0);
}
for (uint8_t i=0; i<64; i+=4) {
drawline(buffer, 127, i, 0, 0, 0);
}
}
void testdrawrect(uint8_t *buff) {
for (uint8_t i=0; i<64; i+=2) {
drawrect(buff, i, i, 128-i, 64-i, 1);
}
}
void testfillrect(uint8_t *buff) {
for (uint8_t i=0; i<64; i++) {
fillrect(buff, i, i, 128-i, 64-i, i%2);
}
}
void clear_screen(void) {
uint8_t p, c;
for(p = 0; p < 8; p++) {
/*
putstring("new page! ");
uart_putw_dec(p);
putstring_nl("");
*/
st7565_command(CMD_SET_PAGE | p);
for(c = 0; c < 129; c++) {
//uart_putw_dec(c);
//uart_putchar(' ');
st7565_command(CMD_SET_COLUMN_LOWER | (c & 0xf));
st7565_command(CMD_SET_COLUMN_UPPER | ((c >> 4) & 0xf));
st7565_data(0x0);
}
}
}
void st7565_init(void) {
// set pin directions
SID_DDR |= _BV(SID);
SCLK_DDR |= _BV(SCLK);
A0_DDR |= _BV(A0);
RST_DDR |= _BV(RST);
CS_DDR |= _BV(CS);
// toggle RST low to reset; CS low so it'll listen to us
CS_PORT &= ~_BV(CS);
RST_PORT &= ~_BV(RST);
_delay_ms(500);
RST_PORT |= _BV(RST);
// LCD bias select
st7565_command(CMD_SET_BIAS_7);
// ADC select
st7565_command(CMD_SET_ADC_NORMAL);
// SHL select
st7565_command(CMD_SET_COM_NORMAL);
// Initial display line
st7565_command(CMD_SET_DISP_START_LINE);
// turn on voltage converter (VC=1, VR=0, VF=0)
st7565_command(CMD_SET_POWER_CONTROL | 0x4);
// wait for 50% rising
_delay_ms(50);
// turn on voltage regulator (VC=1, VR=1, VF=0)
st7565_command(CMD_SET_POWER_CONTROL | 0x6);
// wait >=50ms
_delay_ms(50);
// turn on voltage follower (VC=1, VR=1, VF=1)
st7565_command(CMD_SET_POWER_CONTROL | 0x7);
// wait
_delay_ms(10);
// set lcd operating voltage (regulator resistor, ref voltage resistor)
st7565_command(CMD_SET_RESISTOR_RATIO | 0x6);
// initial display line
// set page address
// set column address
// write display data
}
inline void spiwrite(uint8_t c) {
int8_t i;
for (i=7; i>=0; i--) {
SCLK_PORT &= ~_BV(SCLK);
if (c & _BV(i))
SID_PORT |= _BV(SID);
else
SID_PORT &= ~_BV(SID);
SCLK_PORT |= _BV(SCLK);
}
/*
// loop unwrapped! too fast doesnt work :(
SCLK_PORT &= ~_BV(SCLK);
if (c & _BV(7))
SID_PORT |= _BV(SID);
else
SID_PORT &= ~_BV(SID);
SCLK_PORT |= _BV(SCLK);
SCLK_PORT &= ~_BV(SCLK);
if (c & _BV(6))
SID_PORT |= _BV(SID);
else
SID_PORT &= ~_BV(SID);
SCLK_PORT |= _BV(SCLK);
SCLK_PORT &= ~_BV(SCLK);
if (c & _BV(5))
SID_PORT |= _BV(SID);
else
SID_PORT &= ~_BV(SID);
SCLK_PORT |= _BV(SCLK);
SCLK_PORT &= ~_BV(SCLK);
if (c & _BV(4))
SID_PORT |= _BV(SID);
else
SID_PORT &= ~_BV(SID);
SCLK_PORT |= _BV(SCLK);
SCLK_PORT &= ~_BV(SCLK);
if (c & _BV(3))
SID_PORT |= _BV(SID);
else
SID_PORT &= ~_BV(SID);
SCLK_PORT |= _BV(SCLK);
SCLK_PORT &= ~_BV(SCLK);
if (c & _BV(2))
SID_PORT |= _BV(SID);
else
SID_PORT &= ~_BV(SID);
SCLK_PORT |= _BV(SCLK);
SCLK_PORT &= ~_BV(SCLK);
if (c & _BV(1))
SID_PORT |= _BV(SID);
else
SID_PORT &= ~_BV(SID);
SCLK_PORT |= _BV(SCLK);
SCLK_PORT &= ~_BV(SCLK);
if (c & _BV(0))
SID_PORT |= _BV(SID);
else
SID_PORT &= ~_BV(SID);
SCLK_PORT |= _BV(SCLK);
*/
}
void st7565_command(uint8_t c) {
A0_PORT &= ~_BV(A0);
spiwrite(c);
}
void st7565_data(uint8_t c) {
A0_PORT |= _BV(A0);
spiwrite(c);
}
void st7565_set_brightness(uint8_t val) {
st7565_command(CMD_SET_VOLUME_FIRST);
st7565_command(CMD_SET_VOLUME_SECOND | (val & 0x3f));
}
void write_buffer(uint8_t *buffer) {
uint8_t c, p;
for(p = 0; p < 8; p++) {
/*
putstring("new page! ");
uart_putw_dec(p);
putstring_nl("");
*/
st7565_command(CMD_SET_PAGE | pagemap[p]);
st7565_command(CMD_SET_COLUMN_LOWER | (0x0 & 0xf));
st7565_command(CMD_SET_COLUMN_UPPER | ((0x0 >> 4) & 0xf));
st7565_command(CMD_RMW);
st7565_data(0xff);
//st7565_data(0x80);
//continue;
for(c = 0; c < 128; c++) {
//uart_putw_dec(c);
//uart_putchar(' ');
st7565_data(buffer[(128*p)+c]);
}
}
}