Mercurial > code > home > repos > homeauto
annotate service/arduinoNode/arduino-libraries/ST7565/ST7565.cpp @ 1714:4cbe3df8f48f
rewrite to use starlette/etc
author | drewp@bigasterisk.com |
---|---|
date | Sun, 24 Apr 2022 02:15:30 -0700 |
parents | b2f909325bb2 |
children |
rev | line source |
---|---|
168
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
1 /* |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
2 $Id:$ |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
3 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
4 ST7565 LCD library! |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
5 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
6 Copyright (C) 2010 Limor Fried, Adafruit Industries |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
7 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
8 This library is free software; you can redistribute it and/or |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
9 modify it under the terms of the GNU Lesser General Public |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
10 License as published by the Free Software Foundation; either |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
11 version 2.1 of the License, or (at your option) any later version. |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
12 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
13 This library is distributed in the hope that it will be useful, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
16 Lesser General Public License for more details. |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
17 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
18 You should have received a copy of the GNU Lesser General Public |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
19 License along with this library; if not, write to the Free Software |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
21 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
22 // some of this code was written by <cstone@pobox.com> originally; it is in the public domain. |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
23 */ |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
24 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
25 //#include <Wire.h> |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
26 #include <avr/pgmspace.h> |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
27 #include <util/delay.h> |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
28 #include <stdlib.h> |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
29 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
30 #include "ST7565.h" |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
31 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
32 #define ST7565_STARTBYTES 1 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
33 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
34 uint8_t is_reversed = 0; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
35 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
36 // a handy reference to where the pages are on the screen |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
37 const uint8_t pagemap[] = { 3, 2, 1, 0, 7, 6, 5, 4 }; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
38 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
39 // a 5x7 font table |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
40 const extern uint8_t PROGMEM font[]; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
41 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
42 // the memory buffer for the LCD |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
43 uint8_t st7565_buffer[1024] = { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
44 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
45 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
46 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
47 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
48 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
49 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
50 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
51 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
52 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
53 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
54 0x0, 0x0, 0x0, 0x3, 0x7, 0xF, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x7, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
55 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
56 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
57 0x0, 0x0, 0x7F, 0x3F, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
58 0x0, 0x0, 0x1F, 0x3F, 0x70, 0x70, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
59 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x6, 0x0, 0x0, 0x0, 0x3, 0x3, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
60 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
61 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
62 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0xF, 0x7, 0x7, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
63 0x7, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3E, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
64 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xF, 0x3F, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
65 0x70, 0x60, 0x60, 0x60, 0x60, 0x30, 0x7F, 0x3F, 0x0, 0x0, 0x1F, 0x3F, 0x70, 0x60, 0x60, 0x60, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
66 0x60, 0x39, 0xFF, 0xFF, 0x0, 0x6, 0x1F, 0x39, 0x60, 0x60, 0x60, 0x60, 0x30, 0x3F, 0x7F, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
67 0x0, 0x60, 0xFF, 0xFF, 0x60, 0x60, 0x0, 0x7F, 0x7F, 0x70, 0x60, 0x60, 0x40, 0x0, 0x7F, 0x7F, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
68 0x0, 0x0, 0x0, 0x0, 0x7F, 0x7F, 0x0, 0x0, 0x0, 0x7F, 0x7F, 0x0, 0x0, 0x60, 0xFF, 0xFF, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
69 0x60, 0x60, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
70 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
71 0x80, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xEF, 0xE7, 0xE7, 0xE3, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
72 0xF3, 0xF9, 0xFF, 0xFF, 0xFF, 0xF7, 0x7, 0x1F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
73 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0xF, 0x7, 0x3, 0x0, 0x0, 0x0, 0xC0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
74 0xE0, 0x60, 0x20, 0x20, 0x60, 0xE0, 0xE0, 0xE0, 0x0, 0x0, 0x80, 0xC0, 0xE0, 0x60, 0x20, 0x60, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
75 0x60, 0xE0, 0xE0, 0xE0, 0x0, 0x0, 0x80, 0xC0, 0x60, 0x60, 0x20, 0x60, 0x60, 0xE0, 0xE0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
76 0x0, 0x0, 0xE0, 0xE0, 0x0, 0x0, 0x0, 0xE0, 0xE0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0xE0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
77 0x60, 0x60, 0x60, 0x60, 0xE0, 0x80, 0x0, 0x0, 0x0, 0xE0, 0xE0, 0x0, 0x0, 0x0, 0xE0, 0xE0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
78 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
79 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
80 0x0, 0x0, 0x0, 0x3, 0x7, 0x1F, 0x9F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xF1, 0xE3, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
81 0xE3, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF0, 0xFC, 0x7F, 0x3F, 0x3F, 0x3F, 0x3F, 0x7F, 0xFF, 0xFF, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
82 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFC, 0xF0, 0xE0, 0x80, 0x0, 0x0, 0x0, 0xC, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
83 0x1C, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
84 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7F, 0x7F, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
85 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x7, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
86 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1C, 0xC, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
87 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
88 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
89 0x0, 0x7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFC, 0xF8, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
90 0xF8, 0xF0, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
91 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xFF, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
92 0xFF, 0x0, 0x0, 0x0, 0xFF, 0xFF, 0xE0, 0xC0, 0xC0, 0xC0, 0xFF, 0x7F, 0x0, 0x0, 0x1E, 0x7F, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
93 0xE1, 0xC0, 0xC0, 0xC0, 0xC0, 0x61, 0xFF, 0xFF, 0x0, 0x0, 0xFE, 0xFF, 0x1, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
94 0xFF, 0xFF, 0x0, 0x0, 0x21, 0xF9, 0xF8, 0xDC, 0xCC, 0xCF, 0x7, 0x0, 0xC0, 0xFF, 0xFF, 0xC0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
95 0x80, 0x0, 0xFF, 0xFF, 0xC0, 0xC0, 0x80, 0x0, 0x0, 0xFF, 0xFF, 0x0, 0x0, 0x1F, 0x7F, 0xF9, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
96 0xC8, 0xC8, 0xC8, 0xC8, 0x79, 0x39, 0x0, 0x0, 0x71, 0xF9, 0xD8, 0xCC, 0xCE, 0x47, 0x3, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
97 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
98 0x0, 0x0, 0x0, 0x0, 0x80, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
99 0x0, 0x0, 0x0, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xF8, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF0, 0xC0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
100 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xC0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
101 0xC0, 0x0, 0x0, 0x0, 0xC0, 0xC0, 0x0, 0x0, 0x0, 0x0, 0xC0, 0xC0, 0x0, 0x0, 0x0, 0x80, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
102 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0xC0, 0xC0, 0x0, 0x0, 0x0, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
103 0xC0, 0x80, 0x0, 0x0, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x0, 0x0, 0x0, 0xC0, 0xC0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
104 0x0, 0x0, 0xC0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0xC0, 0xC0, 0x0, 0x0, 0x0, 0x80, 0xC0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
105 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x80, 0x0, 0x0, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0x80, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
106 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
107 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
108 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
109 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
110 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
111 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
112 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
113 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
114 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,}; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
115 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
116 // reduces how much is refreshed, which speeds it up! |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
117 // originally derived from Steve Evans/JCW's mod but cleaned up and |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
118 // optimized |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
119 #define enablePartialUpdate |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
120 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
121 #ifdef enablePartialUpdate |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
122 static uint8_t xUpdateMin, xUpdateMax, yUpdateMin, yUpdateMax; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
123 #endif |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
124 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
125 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
126 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
127 static void updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
128 #ifdef enablePartialUpdate |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
129 if (xmin < xUpdateMin) xUpdateMin = xmin; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
130 if (xmax > xUpdateMax) xUpdateMax = xmax; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
131 if (ymin < yUpdateMin) yUpdateMin = ymin; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
132 if (ymax > yUpdateMax) yUpdateMax = ymax; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
133 #endif |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
134 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
135 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
136 void ST7565::drawbitmap(uint8_t x, uint8_t y, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
137 const uint8_t *bitmap, uint8_t w, uint8_t h, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
138 uint8_t color) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
139 for (uint8_t j=0; j<h; j++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
140 for (uint8_t i=0; i<w; i++ ) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
141 if (pgm_read_byte(bitmap + i + (j/8)*w) & _BV(j%8)) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
142 my_setpixel(x+i, y+j, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
143 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
144 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
145 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
146 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
147 updateBoundingBox(x, y, x+w, y+h); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
148 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
149 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
150 void ST7565::drawstring(uint8_t x, uint8_t line, char *c) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
151 while (c[0] != 0) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
152 drawchar(x, line, c[0]); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
153 c++; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
154 x += 6; // 6 pixels wide |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
155 if (x + 6 >= LCDWIDTH) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
156 x = 0; // ran out of this line |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
157 line++; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
158 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
159 if (line >= (LCDHEIGHT/8)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
160 return; // ran out of space :( |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
161 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
162 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
163 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
164 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
165 void ST7565::drawstring_P(uint8_t x, uint8_t line, const char *str) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
166 while (1) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
167 char c = pgm_read_byte(str++); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
168 if (! c) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
169 return; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
170 drawchar(x, line, c); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
171 x += 6; // 6 pixels wide |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
172 if (x + 6 >= LCDWIDTH) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
173 x = 0; // ran out of this line |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
174 line++; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
175 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
176 if (line >= (LCDHEIGHT/8)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
177 return; // ran out of space :( |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
178 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
179 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
180 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
181 void ST7565::drawchar(uint8_t x, uint8_t line, char c) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
182 for (uint8_t i =0; i<5; i++ ) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
183 st7565_buffer[x + (line*128) ] = pgm_read_byte(font+(c*5)+i); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
184 x++; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
185 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
186 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
187 updateBoundingBox(x, line*8, x+5, line*8 + 8); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
188 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
189 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
190 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
191 // bresenham's algorithm - thx wikpedia |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
192 void ST7565::drawline(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
193 uint8_t color) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
194 uint8_t steep = abs(y1 - y0) > abs(x1 - x0); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
195 if (steep) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
196 swap(x0, y0); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
197 swap(x1, y1); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
198 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
199 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
200 if (x0 > x1) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
201 swap(x0, x1); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
202 swap(y0, y1); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
203 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
204 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
205 // much faster to put the test here, since we've already sorted the points |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
206 updateBoundingBox(x0, y0, x1, y1); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
207 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
208 uint8_t dx, dy; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
209 dx = x1 - x0; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
210 dy = abs(y1 - y0); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
211 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
212 int8_t err = dx / 2; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
213 int8_t ystep; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
214 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
215 if (y0 < y1) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
216 ystep = 1; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
217 } else { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
218 ystep = -1;} |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
219 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
220 for (; x0<=x1; x0++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
221 if (steep) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
222 my_setpixel(y0, x0, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
223 } else { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
224 my_setpixel(x0, y0, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
225 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
226 err -= dy; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
227 if (err < 0) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
228 y0 += ystep; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
229 err += dx; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
230 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
231 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
232 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
233 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
234 // filled rectangle |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
235 void ST7565::fillrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
236 uint8_t color) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
237 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
238 // stupidest version - just pixels - but fast with internal buffer! |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
239 for (uint8_t i=x; i<x+w; i++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
240 for (uint8_t j=y; j<y+h; j++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
241 my_setpixel(i, j, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
242 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
243 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
244 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
245 updateBoundingBox(x, y, x+w, y+h); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
246 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
247 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
248 // draw a rectangle |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
249 void ST7565::drawrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
250 uint8_t color) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
251 // stupidest version - just pixels - but fast with internal buffer! |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
252 for (uint8_t i=x; i<x+w; i++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
253 my_setpixel(i, y, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
254 my_setpixel(i, y+h-1, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
255 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
256 for (uint8_t i=y; i<y+h; i++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
257 my_setpixel(x, i, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
258 my_setpixel(x+w-1, i, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
259 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
260 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
261 updateBoundingBox(x, y, x+w, y+h); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
262 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
263 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
264 // draw a circle outline |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
265 void ST7565::drawcircle(uint8_t x0, uint8_t y0, uint8_t r, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
266 uint8_t color) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
267 updateBoundingBox(x0-r, y0-r, x0+r, y0+r); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
268 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
269 int8_t f = 1 - r; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
270 int8_t ddF_x = 1; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
271 int8_t ddF_y = -2 * r; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
272 int8_t x = 0; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
273 int8_t y = r; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
274 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
275 my_setpixel(x0, y0+r, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
276 my_setpixel(x0, y0-r, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
277 my_setpixel(x0+r, y0, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
278 my_setpixel(x0-r, y0, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
279 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
280 while (x<y) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
281 if (f >= 0) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
282 y--; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
283 ddF_y += 2; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
284 f += ddF_y; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
285 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
286 x++; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
287 ddF_x += 2; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
288 f += ddF_x; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
289 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
290 my_setpixel(x0 + x, y0 + y, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
291 my_setpixel(x0 - x, y0 + y, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
292 my_setpixel(x0 + x, y0 - y, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
293 my_setpixel(x0 - x, y0 - y, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
294 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
295 my_setpixel(x0 + y, y0 + x, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
296 my_setpixel(x0 - y, y0 + x, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
297 my_setpixel(x0 + y, y0 - x, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
298 my_setpixel(x0 - y, y0 - x, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
299 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
300 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
301 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
302 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
303 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
304 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
305 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
306 void ST7565::fillcircle(uint8_t x0, uint8_t y0, uint8_t r, |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
307 uint8_t color) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
308 updateBoundingBox(x0-r, y0-r, x0+r, y0+r); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
309 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
310 int8_t f = 1 - r; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
311 int8_t ddF_x = 1; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
312 int8_t ddF_y = -2 * r; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
313 int8_t x = 0; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
314 int8_t y = r; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
315 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
316 for (uint8_t i=y0-r; i<=y0+r; i++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
317 my_setpixel(x0, i, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
318 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
319 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
320 while (x<y) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
321 if (f >= 0) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
322 y--; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
323 ddF_y += 2; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
324 f += ddF_y; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
325 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
326 x++; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
327 ddF_x += 2; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
328 f += ddF_x; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
329 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
330 for (uint8_t i=y0-y; i<=y0+y; i++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
331 my_setpixel(x0+x, i, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
332 my_setpixel(x0-x, i, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
333 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
334 for (uint8_t i=y0-x; i<=y0+x; i++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
335 my_setpixel(x0+y, i, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
336 my_setpixel(x0-y, i, color); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
337 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
338 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
339 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
340 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
341 void ST7565::my_setpixel(uint8_t x, uint8_t y, uint8_t color) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
342 if ((x >= LCDWIDTH) || (y >= LCDHEIGHT)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
343 return; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
344 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
345 // x is which column |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
346 if (color) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
347 st7565_buffer[x+ (y/8)*128] |= _BV(7-(y%8)); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
348 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
349 st7565_buffer[x+ (y/8)*128] &= ~_BV(7-(y%8)); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
350 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
351 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
352 // the most basic function, set a single pixel |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
353 void ST7565::setpixel(uint8_t x, uint8_t y, uint8_t color) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
354 if ((x >= LCDWIDTH) || (y >= LCDHEIGHT)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
355 return; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
356 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
357 // x is which column |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
358 if (color) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
359 st7565_buffer[x+ (y/8)*128] |= _BV(7-(y%8)); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
360 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
361 st7565_buffer[x+ (y/8)*128] &= ~_BV(7-(y%8)); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
362 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
363 updateBoundingBox(x,y,x,y); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
364 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
365 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
366 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
367 // the most basic function, get a single pixel |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
368 uint8_t ST7565::getpixel(uint8_t x, uint8_t y) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
369 if ((x >= LCDWIDTH) || (y >= LCDHEIGHT)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
370 return 0; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
371 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
372 return (st7565_buffer[x+ (y/8)*128] >> (7-(y%8))) & 0x1; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
373 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
374 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
375 void ST7565::begin(uint8_t contrast) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
376 st7565_init(); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
377 st7565_command(CMD_DISPLAY_ON); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
378 st7565_command(CMD_SET_ALLPTS_NORMAL); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
379 st7565_set_brightness(contrast); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
380 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
381 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
382 void ST7565::st7565_init(void) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
383 // set pin directions |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
384 pinMode(sid, OUTPUT); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
385 pinMode(sclk, OUTPUT); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
386 pinMode(a0, OUTPUT); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
387 pinMode(rst, OUTPUT); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
388 pinMode(cs, OUTPUT); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
389 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
390 // toggle RST low to reset; CS low so it'll listen to us |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
391 if (cs > 0) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
392 digitalWrite(cs, LOW); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
393 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
394 digitalWrite(rst, LOW); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
395 _delay_ms(500); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
396 digitalWrite(rst, HIGH); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
397 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
398 // LCD bias select |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
399 st7565_command(CMD_SET_BIAS_7); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
400 // ADC select |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
401 st7565_command(CMD_SET_ADC_NORMAL); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
402 // SHL select |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
403 st7565_command(CMD_SET_COM_NORMAL); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
404 // Initial display line |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
405 st7565_command(CMD_SET_DISP_START_LINE); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
406 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
407 // turn on voltage converter (VC=1, VR=0, VF=0) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
408 st7565_command(CMD_SET_POWER_CONTROL | 0x4); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
409 // wait for 50% rising |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
410 _delay_ms(50); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
411 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
412 // turn on voltage regulator (VC=1, VR=1, VF=0) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
413 st7565_command(CMD_SET_POWER_CONTROL | 0x6); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
414 // wait >=50ms |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
415 _delay_ms(50); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
416 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
417 // turn on voltage follower (VC=1, VR=1, VF=1) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
418 st7565_command(CMD_SET_POWER_CONTROL | 0x7); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
419 // wait |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
420 _delay_ms(10); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
421 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
422 // set lcd operating voltage (regulator resistor, ref voltage resistor) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
423 st7565_command(CMD_SET_RESISTOR_RATIO | 0x6); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
424 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
425 // initial display line |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
426 // set page address |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
427 // set column address |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
428 // write display data |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
429 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
430 // set up a bounding box for screen updates |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
431 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
432 updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
433 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
434 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
435 inline void ST7565::spiwrite(uint8_t c) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
436 shiftOut(sid, sclk, MSBFIRST, c); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
437 /* |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
438 int8_t i; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
439 for (i=7; i>=0; i--) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
440 SCLK_PORT &= ~_BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
441 if (c & _BV(i)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
442 SID_PORT |= _BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
443 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
444 SID_PORT &= ~_BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
445 SCLK_PORT |= _BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
446 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
447 */ |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
448 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
449 /* |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
450 // loop unwrapped! too fast doesnt work :( |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
451 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
452 SCLK_PORT &= ~_BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
453 if (c & _BV(7)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
454 SID_PORT |= _BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
455 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
456 SID_PORT &= ~_BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
457 SCLK_PORT |= _BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
458 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
459 SCLK_PORT &= ~_BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
460 if (c & _BV(6)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
461 SID_PORT |= _BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
462 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
463 SID_PORT &= ~_BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
464 SCLK_PORT |= _BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
465 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
466 SCLK_PORT &= ~_BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
467 if (c & _BV(5)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
468 SID_PORT |= _BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
469 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
470 SID_PORT &= ~_BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
471 SCLK_PORT |= _BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
472 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
473 SCLK_PORT &= ~_BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
474 if (c & _BV(4)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
475 SID_PORT |= _BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
476 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
477 SID_PORT &= ~_BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
478 SCLK_PORT |= _BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
479 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
480 SCLK_PORT &= ~_BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
481 if (c & _BV(3)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
482 SID_PORT |= _BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
483 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
484 SID_PORT &= ~_BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
485 SCLK_PORT |= _BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
486 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
487 SCLK_PORT &= ~_BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
488 if (c & _BV(2)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
489 SID_PORT |= _BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
490 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
491 SID_PORT &= ~_BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
492 SCLK_PORT |= _BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
493 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
494 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
495 SCLK_PORT &= ~_BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
496 if (c & _BV(1)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
497 SID_PORT |= _BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
498 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
499 SID_PORT &= ~_BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
500 SCLK_PORT |= _BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
501 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
502 SCLK_PORT &= ~_BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
503 if (c & _BV(0)) |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
504 SID_PORT |= _BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
505 else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
506 SID_PORT &= ~_BV(SID); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
507 SCLK_PORT |= _BV(SCLK); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
508 */ |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
509 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
510 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
511 void ST7565::st7565_command(uint8_t c) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
512 digitalWrite(a0, LOW); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
513 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
514 spiwrite(c); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
515 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
516 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
517 void ST7565::st7565_data(uint8_t c) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
518 digitalWrite(a0, HIGH); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
519 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
520 spiwrite(c); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
521 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
522 void ST7565::st7565_set_brightness(uint8_t val) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
523 st7565_command(CMD_SET_VOLUME_FIRST); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
524 st7565_command(CMD_SET_VOLUME_SECOND | (val & 0x3f)); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
525 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
526 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
527 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
528 void ST7565::display(void) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
529 uint8_t col, maxcol, p; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
530 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
531 /* |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
532 Serial.print("Refresh ("); Serial.print(xUpdateMin, DEC); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
533 Serial.print(", "); Serial.print(xUpdateMax, DEC); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
534 Serial.print(","); Serial.print(yUpdateMin, DEC); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
535 Serial.print(", "); Serial.print(yUpdateMax, DEC); Serial.println(")"); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
536 */ |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
537 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
538 for(p = 0; p < 8; p++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
539 /* |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
540 putstring("new page! "); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
541 uart_putw_dec(p); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
542 putstring_nl(""); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
543 */ |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
544 #ifdef enablePartialUpdate |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
545 // check if this page is part of update |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
546 if ( yUpdateMin >= ((p+1)*8) ) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
547 continue; // nope, skip it! |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
548 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
549 if (yUpdateMax < p*8) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
550 break; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
551 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
552 #endif |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
553 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
554 st7565_command(CMD_SET_PAGE | pagemap[p]); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
555 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
556 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
557 #ifdef enablePartialUpdate |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
558 col = xUpdateMin; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
559 maxcol = xUpdateMax; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
560 #else |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
561 // start at the beginning of the row |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
562 col = 0; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
563 maxcol = LCDWIDTH-1; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
564 #endif |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
565 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
566 st7565_command(CMD_SET_COLUMN_LOWER | ((col+ST7565_STARTBYTES) & 0xf)); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
567 st7565_command(CMD_SET_COLUMN_UPPER | (((col+ST7565_STARTBYTES) >> 4) & 0x0F)); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
568 st7565_command(CMD_RMW); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
569 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
570 for(; col <= maxcol; col++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
571 //uart_putw_dec(col); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
572 //uart_putchar(' '); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
573 st7565_data(st7565_buffer[(128*p)+col]); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
574 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
575 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
576 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
577 #ifdef enablePartialUpdate |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
578 xUpdateMin = LCDWIDTH - 1; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
579 xUpdateMax = 0; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
580 yUpdateMin = LCDHEIGHT-1; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
581 yUpdateMax = 0; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
582 #endif |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
583 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
584 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
585 // clear everything |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
586 void ST7565::clear(void) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
587 memset(st7565_buffer, 0, 1024); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
588 updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
589 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
590 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
591 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
592 // this doesnt touch the buffer, just clears the display RAM - might be handy |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
593 void ST7565::clear_display(void) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
594 uint8_t p, c; |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
595 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
596 for(p = 0; p < 8; p++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
597 /* |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
598 putstring("new page! "); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
599 uart_putw_dec(p); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
600 putstring_nl(""); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
601 */ |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
602 |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
603 st7565_command(CMD_SET_PAGE | p); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
604 for(c = 0; c < 129; c++) { |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
605 //uart_putw_dec(c); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
606 //uart_putchar(' '); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
607 st7565_command(CMD_SET_COLUMN_LOWER | (c & 0xf)); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
608 st7565_command(CMD_SET_COLUMN_UPPER | ((c >> 4) & 0xf)); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
609 st7565_data(0x0); |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
610 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
611 } |
b2f909325bb2
core files from https://github.com/adafruit/ST7565-LCD
drewp@bigasterisk.com
parents:
diff
changeset
|
612 } |