annotate service/arduinoNode/arduino-libraries/ST7565/ST7565.cpp @ 1303:f97e060d860c

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