-
Notifications
You must be signed in to change notification settings - Fork 0
/
DRW_SSD1306_SPI_char.h
199 lines (175 loc) · 7.87 KB
/
DRW_SSD1306_SPI_char.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
Copyright (c) 2015 David Wheeler
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "Arduino.h"
#include "Print.h"
#define DRW_SSD1306_SPI_USE_CS
// Datasheet : http://www.allshore.com/pdf/ssd1309.pdf
// 0. Charge Pump Commands
#define SSD1306_CHARGEPUMP 0x8D // Set the charge pump ( bit 2 : 0 default off, 1 on ) in the next byte **010X00b
// 1. Fundamental Commands
#define SSD1306_SETCONTRAST 0x81 // Set contrast to next byte ( default = 7Fh )
#define SSD1306_DISPLAYALLON_RESUME 0xA4 // Display on and show RAM contents
#define SSD1306_DISPLAYALLON 0xA5 // Display all lit
#define SSD1306_NORMALDISPLAY 0xA6 // RAM : bit = 0 => dark
#define SSD1306_INVERTDISPLAY 0xA7 // RAM : bit = 0 => lit
#define SSD1306_DISPLAYOFF 0xAE // Sleep mode
#define SSD1306_DISPLAYON 0xAF // Normal mode
// 2. Scrolling Commands
// 3. Addressing Setting Commands
#define SSD1306_SETLOWCOLUMN 0x00 // Set lower nibble of column start address for page addressing mode ( 3:0 default 0000b )
#define SSD1306_SETHIGHCOLUMN 0x10 // Set upper nibble of column start address for page addressing mode ( 3:0 default 0000b )
#define SSD1306_MEMORYMODE 0x20 // Set memory addressing mode ( 1:0 00b horizontal 01b vertical 10b page default 11 Invalid ) in next byte
#define SSD1306_COLUMNADDR 0x21 // Set column start and end address ( 6:0 default 0d 127d ) in next two bytes
#define SSD1306_PAGEADDR 0x22 // Set page start and end address ( 2:0 default 0d ) in next two bytes
#define SSD1306_PAGESTART 0xB0 // Set RAM page start address for page addressing mode ( 2:0 )
// 4. Hardware Configuration Commands
#define SSD1306_SETSTARTLINE 0x40 // Set the display RAM start line ( 5:0 default 000000b )
#define SSD1306_SEGREMAP 0xA0 // Set segment remap ( bit 0 : default 0 = col0 => seg0, mirror 1 = col127 => seg0 )
#define SSD1306_SETMULTIPLEX 0xA8 // Set the com multiplex mode ( 5:0 default 111111b = 64 ) in the next byte. 0 to 14 is invalid
#define SSD1306_COMSCANINC 0xC0 // Set the com output scan direction increasing
#define SSD1306_COMSCANDEC 0xC8 // Set the com output scan direction decreasing
#define SSD1306_SETDISPLAYOFFSET 0xD3 // Set vertical display offset
#define SSD1306_SETCOMPINS 0xDA // Set COM pins hardware configuration ( 5:4 ) in next byte
// 5. Timing & Drivings Scheme Setting Commands
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5 // Set the oscillator frequency ( 7:4 default 1000b ) and divide ratio ( 3:0 default 0000b = 1 ) in the next byte
#define SSD1306_SETPRECHARGE 0xD9 // Set the pre-charge period ( phase 2 7:4 default 0010b = 2 DClk's, phase 1 3:0 default 0000b ) in the next byte
#define SSD1306_SETVCOMDETECT 0xDB // Set the VCOMH regulator output deselect level ( 6:4 ~0.65*Vcc, 0.77#Vcc, ~0.83*Vcc ) in the next byte
#define SSD1306_NOP 0xE3 // No operation
class DRW_SSD1306_SPI_char : public Print {
public:
#ifdef DRW_SSD1306_SPI_USE_CS
void begin(const uint8_t dc_pin, const uint8_t cs_pin);
#endif
void begin(const uint8_t dc_pin);
void clear_display();
size_t write(uint8_t c);
size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
size_t write(const uint8_t *buffer, size_t size);
void set_char_cursor(uint8_t x, uint8_t y);
uint8_t get_char_cursor_x();
uint8_t get_char_cursor_y();
private:
#ifdef DRW_SSD1306_SPI_USE_CS
uint8_t cs; // Chip select pin
#endif
uint8_t dc; // Data or Command pin
uint8_t char_cursor_x, // Character cursor position
char_cursor_y;
};
// 5x7 monospace font
const byte font5x7[][5] PROGMEM = {
{0x00,0x00,0x00,0x00,0x00}, // <space>
{0x00,0x5F,0x00,0x00,0x00}, // !
{0x00,0x07,0x00,0x07,0x00}, // "
{0x14,0x7F,0x14,0x7F,0x14}, // #
{0x24,0x2A,0x7F,0x2A,0x12}, // $
{0x23,0x13,0x08,0x64,0x62}, // %
{0x36,0x49,0x55,0x22,0x50}, // &
{0x00,0x05,0x03,0x00,0x00}, // '
{0x1C,0x22,0x41,0x00,0x00}, // (
{0x41,0x22,0x1C,0x00,0x00}, // )
{0x08,0x2A,0x1C,0x2A,0x08}, // *
{0x08,0x08,0x3E,0x08,0x08}, // +
{0xA0,0x60,0x00,0x00,0x00}, // ,
{0x08,0x08,0x08,0x08,0x08}, // -
{0x60,0x60,0x00,0x00,0x00}, // .
{0x20,0x10,0x08,0x04,0x02}, // /
{0x3E,0x51,0x49,0x45,0x3E}, // 0
{0x00,0x42,0x7F,0x40,0x00}, // 1
{0x62,0x51,0x49,0x49,0x46}, // 2
{0x22,0x41,0x49,0x49,0x36}, // 3
{0x18,0x14,0x12,0x7F,0x10}, // 4
{0x27,0x45,0x45,0x45,0x39}, // 5
{0x3C,0x4A,0x49,0x49,0x30}, // 6
{0x01,0x71,0x09,0x05,0x03}, // 7
{0x36,0x49,0x49,0x49,0x36}, // 8
{0x06,0x49,0x49,0x29,0x1E}, // 9
{0x00,0x36,0x36,0x00,0x00}, // :
{0x00,0xAC,0x6C,0x00,0x00}, // ;
{0x08,0x14,0x22,0x41,0x00}, // <
{0x14,0x14,0x14,0x14,0x14}, // =
{0x41,0x22,0x14,0x08,0x00}, // >
{0x02,0x01,0x51,0x09,0x06}, // ?
{0x32,0x49,0x79,0x41,0x3E}, // @
{0x7E,0x09,0x09,0x09,0x7E}, // A
{0x7F,0x49,0x49,0x49,0x36}, // B
{0x3E,0x41,0x41,0x41,0x22}, // C
{0x7F,0x41,0x41,0x22,0x1C}, // D
{0x7F,0x49,0x49,0x49,0x41}, // E
{0x7F,0x09,0x09,0x09,0x01}, // F
{0x3E,0x41,0x41,0x51,0x72}, // G
{0x7F,0x08,0x08,0x08,0x7F}, // H
{0x41,0x7F,0x41,0x00,0x00}, // I
{0x20,0x40,0x41,0x3F,0x01}, // J
{0x7F,0x08,0x14,0x22,0x41}, // K
{0x7F,0x40,0x40,0x40,0x40}, // L
{0x7F,0x02,0x0C,0x02,0x7F}, // M
{0x7F,0x04,0x08,0x10,0x7F}, // N
{0x3E,0x41,0x41,0x41,0x3E}, // O
{0x7F,0x09,0x09,0x09,0x06}, // P
{0x3E,0x41,0x51,0x21,0x5E}, // Q
{0x7F,0x09,0x19,0x29,0x46}, // R
{0x26,0x49,0x49,0x49,0x32}, // S
{0x01,0x01,0x7F,0x01,0x01}, // T
{0x3F,0x40,0x40,0x40,0x3F}, // U
{0x1F,0x20,0x40,0x20,0x1F}, // V
{0x3F,0x40,0x38,0x40,0x3F}, // W
{0x63,0x14,0x08,0x14,0x63}, // X
{0x03,0x04,0x78,0x04,0x03}, // Y
{0x61,0x51,0x49,0x45,0x43}, // Z
{0x7F,0x41,0x41,0x00,0x00}, // [
{0x02,0x04,0x08,0x10,0x20}, // |
{0x41,0x41,0x7F,0x00,0x00}, // ]
{0x04,0x02,0x01,0x02,0x04}, // ^
{0x80,0x80,0x80,0x80,0x80}, // _
{0x01,0x02,0x04,0x00,0x00}, // `
{0x20,0x54,0x54,0x54,0x78}, // a
{0x7F,0x48,0x44,0x44,0x38}, // b
{0x38,0x44,0x44,0x28,0x00}, // c
{0x38,0x44,0x44,0x48,0x7F}, // d
{0x38,0x54,0x54,0x54,0x18}, // e
{0x08,0x7E,0x09,0x02,0x00}, // f
{0x18,0xA4,0xA4,0xA4,0x7C}, // g
{0x7F,0x08,0x04,0x04,0x78}, // h
{0x00,0x7D,0x00,0x00,0x00}, // i
{0x80,0x84,0x7D,0x00,0x00}, // j
{0x7F,0x10,0x28,0x44,0x00}, // k
{0x41,0x7F,0x40,0x00,0x00}, // l
{0x7C,0x04,0x18,0x04,0x78}, // m
{0x7C,0x08,0x04,0x7C,0x00}, // n
{0x38,0x44,0x44,0x38,0x00}, // o
{0xFC,0x24,0x24,0x18,0x00}, // p
{0x18,0x24,0x24,0xFC,0x00}, // q
{0x00,0x7C,0x08,0x04,0x00}, // r
{0x48,0x54,0x54,0x24,0x00}, // s
{0x04,0x7F,0x44,0x00,0x00}, // t
{0x3C,0x40,0x40,0x7C,0x00}, // u
{0x1C,0x20,0x40,0x20,0x1C}, // v
{0x3C,0x40,0x30,0x40,0x3C}, // w
{0x44,0x28,0x10,0x28,0x44}, // x
{0x1C,0xA0,0xA0,0x7C,0x00}, // y
{0x44,0x64,0x54,0x4C,0x44}, // z
{0x08,0x36,0x41,0x00,0x00}, // {
{0x00,0x7F,0x00,0x00,0x00}, // |
{0x41,0x36,0x08,0x00,0x00}, // }
{0x02,0x01,0x01,0x02,0x01}, // ~
{0x02,0x05,0x05,0x02,0x00} // º
};