-
Notifications
You must be signed in to change notification settings - Fork 1
/
CosaOLED_Text_test.ino
297 lines (242 loc) · 5.62 KB
/
CosaOLED_Text_test.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/**
* @file CosaOLED_Text_test.ino
* @version 0.1
*
* @section License
* Copyright (C) 2014-2015, jeditekunum
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
//#define ONE_CHAR '&'
#define CYCLE_CHARS 0 // ms; 0 to benchmark
#define FLIPPED false
//#define FLIPPED true
#define SH1106
//#define SSD1306_64_TWI
//#define SSD1306_64_SPI
//#define SSD1306_32_TWI
//#define SSD1306_32_SPI
#define SYSTEM_5x7
//#define FIXEDNUMS_8x16
//#define SEGMENT_32x50
//#define FONT_5x8
//#define FONT_6x9
//#define FONT_6x10
//#define FONT_6x12
//#define FONT_6x13
//#define FONT_6x13B
//#define FONT_7x13
//#define FONT_7x13B
//#define FONT_7x14
//#define FONT_7x14B
//#define FONT_8x13
//#define FONT_8x13B
//#define FONT_8x16
//#define FONT_9x15
//#define FONT_9x15B
//#define FONT_10x20
//#define FONT_12x24
#include "Cosa/UART.hh"
#include "Cosa/Trace.hh"
#include "Cosa/RTT.hh"
#include "OLED_IO_TWI.hh"
#include "OLED_IO_SPI.hh"
#ifdef SYSTEM_5x7
#include <System5x7.hh>
#define FONT system5x7
#endif
#ifdef FONT_5x8
#include <Font5x8.hh>
#define FONT font5x8
#endif
#ifdef FONT_6x9
#include <Font6x9.hh>
#define FONT font6x9
#endif
#ifdef FONT_6x10
#include <Font6x10.hh>
#define FONT font6x10
#endif
#ifdef FONT_6x12
#include <Font6x12.hh>
#define FONT font6x12
#endif
#ifdef FONT_6x13
#include <Font6x13.hh>
#define FONT font6x13
#endif
#ifdef FONT_6x13B
#include <Font6x13B.hh>
#define FONT font6x13B
#endif
#ifdef FONT_7x13
#include <Font7x13.hh>
#define FONT font7x13
#endif
#ifdef FONT_7x13B
#include <Font7x13B.hh>
#define FONT font7x13B
#endif
#ifdef FONT_7x14
#include <Font7x14.hh>
#define FONT font7x14
#endif
#ifdef FONT_7x14B
#include <Font7x14B.hh>
#define FONT font7x14B
#endif
#ifdef FONT_8x13
#include <Font8x13.hh>
#define FONT font8x13
#endif
#ifdef FONT_8x13B
#include <Font8x13B.hh>
#define FONT font8x13B
#endif
#ifdef FONT_8x16
#include <Font8x16.hh>
#define FONT font8x16
#endif
#ifdef FONT_9x15
#include <Font9x15.hh>
#define FONT font9x15
#endif
#ifdef FONT_9x15B
#include <Font9x15B.hh>
#define FONT font9x15B
#endif
#ifdef FONT_10x20
#include <Font10x20.hh>
#define FONT font10x20
#endif
#ifdef FONT_12x24
#include <Font12x24.hh>
#define FONT font12x24
#endif
#ifdef FIXEDNUMS_8x16
#include <FixedNums8x16.hh>
#define FONT fixednums8x16
#endif
#ifdef SEGMENT_32x50
#include <Segment32x50.hh>
#define FONT segment32x50
#endif
#ifdef SH1106
#define DEVICE "SH1106"
#include "SH1106_Text.hh"
static OLED_IO_TWI oled_port(0x3c);
static SH1106_Text oled(&oled_port, (Font*)&FONT, FLIPPED);
#endif
#ifdef SSD1306_64_TWI
#define DEVICE "SSD1306 64 TWI"
#include "SSD1306x64_Text.hh"
static OLED_IO_TWI oled_port(0x3d);
static SSD1306x64_Text oled(&oled_port, (Font*)&FONT, FLIPPED);
#endif
#ifdef SSD1306_32_TWI
#define DEVICE "SSD1306 32 TWI"
#include "SSD1306x32_Text.hh"
static OLED_IO_TWI oled_port(0x3c);
static SSD1306x32_Text oled(&oled_port, (Font*)&FONT, FLIPPED);
#endif
#ifdef SSD1306_64_SPI
#define DEVICE "SSD1306 64 SPI"
#include "SSD1306x64_Text.hh"
static OLED_IO_SPI oled_port(Board::D11);
static SSD1306x64_Text oled(&oled_port, (Font*)&FONT, FLIPPED);
#endif
#ifdef SSD1306_32_SPI
#define DEVICE "SSD1306 32 SPI"
#include "SSD1306x32_Text.hh"
static OLED_IO_SPI oled_port(Board::D11);
static SSD1306x32_Text oled(&oled_port, (Font*)&FONT, FLIPPED);
#endif
IOStream ios(&uart);
static IOStream oledout(&oled);
#define STRINGIFY_(x) #x
#define STRINGIFY(x) STRINGIFY_(x)
#ifdef SYSTEM_5x7
#define FONT_FIRST 0x0
#define FONT_LAST 0x7f
#else
#define FONT_FIRST FONT.FIRST
#define FONT_LAST FONT.LAST
#endif
uint8_t col = 0;
uint8_t row = 0;
void setup()
{
RTT::begin();
uart.begin(9600);
trace.begin(&uart);
trace << PSTR("CosaCanvasFont: started ")
<< PSTR(DEVICE)
<< PSTR(" font ") << STRINGIFY(FONT)
<< endl;
oled.begin();
// Flash
oled.display_inverse();
delay(250);
oled.display_normal();
oled.set_cursor(col, row);
#ifdef ONE_CHAR
oled.putchar(ONE_CHAR);
#endif
#if !defined(ONE_CHAR) && !defined(CYCLE_CHARS)
oledout << PSTR("Hello World!");
#endif
#ifdef CYCLE_CHARS
trace << PSTR("Font has ") << (FONT.LAST-FONT.FIRST+1)
<< PSTR(" characters")
<< endl;
oled.text_mode(OLED_Text::RAW_TEXT_MODE);
#endif
}
void loop()
{
#ifdef CYCLE_CHARS
if (FONT.FIRST < ' ')
oled.text_mode(oled.text_mode() | OLED_Text::INVERTED_TEXT_MODE);
#if CYCLE_CHARS == 0
MEASURE("full character set ", 1)
#endif
{
for (uint16_t c = FONT.FIRST; c <= FONT.LAST; c++)
{
if (c == ' ' || c == 128)
oled.text_mode(oled.text_mode() ^ OLED_Text::INVERTED_TEXT_MODE);
oled.putchar(c);
if (CYCLE_CHARS != 0) delay(CYCLE_CHARS);
}
}
// Save text mode, set to normal
uint8_t savemode = oled.text_mode();
oled.text_mode(OLED_Text::NORMAL_TEXT_MODE);
// Clear rest of screen
uint8_t x, y;
oled.get_cursor(x, y);
for (uint8_t row = y; row < oled.height(); row++)
{
if (row > y)
oled.set_cursor(0, row);
oled.line_clear();
}
// Restore text mode
oled.text_mode(savemode);
// Flip underline for next pass
oled.text_mode(oled.text_mode() ^ OLED_Text::UNDERLINED_TEXT_MODE);
sleep(2);
oled.display_clear();
#else
delay(100);
#endif
}