-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhi.cpp
98 lines (78 loc) · 2.5 KB
/
hi.cpp
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
#include <avr/io.hpp>
#include <avr/pgmspace.h>
#include <ssd1306.hpp>
using namespace avr::io;
using namespace ssd1306;
/** This demos is a "hello world" that setups a display with 128x64
dots with some basic commands and after that erases the content of
the whole screen to print the string 'hi'.
*/
static const uint8_t cmds[] [[gnu::__progmem__]] = {
/** Commands to inform the driver what is the physical
configuration of the display. Note that your display can be
different, take a look at the secton 10.1.18 of the datasheet
with the result on the screen is weird.
*/
0xC8, /** COM Output Scan Direction*/
0xA1, /** Segment Re-map */
0x20, 0, /** Horizontal Addressing Mode*/
0x22, 0, 7, /** Set page address: 0 to 7*/
0x21, 0, 127, /** Set column address: 0 to 127*/
0x8D, 0x14, /** Enable Charge Pump*/
0xAF, /** Turn on the display */
};
static const uint8_t letter_h[] [[gnu::__progmem__]] = {
/**
Bitmap of the letter 'h':
0b10000000, LSB
0b10000000,
0b10111000,
0b11000100,
0b10000100,
0b10000100,
0b10000100,
0b10000100, MSB
Each byte below represents one column from left to right. The
LSB is on the top and the MSB in on the bottom.
*/
0xff, 0x08, 0x04, 0x04, 0x04, 0xf8, 0x00, 0x00
};
static const uint8_t letter_i[] [[gnu::__progmem__]] = {
/**
Bitmap of the letter 'i':
0b00010000, LSB
0b00000000,
0b00110000,
0b00010000,
0b00010000,
0b00010000,
0b00010000,
0b00011000, MSB
Each byte below represents one column from left to right. The
LSB is on the top and the MSB in on the bottom.
*/
0x00, 0x00, 0x04, 0xfd, 0x80, 0x00, 0x00, 0x00
};
int main() {
ssd1306::i2c dev{pb0, pb2};
/** setup the display */
dev.start_commands();
for(uint8_t i{0}; i < sizeof(cmds); ++i)
dev.send_byte(pgm_read_byte(&cmds[i]));
dev.stop_condition();
/** clear the whole screen */
dev.start_data();
for(uint16_t i{0}; i < 128 * 8; ++i)
dev.send_byte(0x00);
dev.stop_condition();
/** print 'hi' at page 0 and column 0 */
dev.start_data();
//send letter 'h'
for(uint8_t i{0}; i < 8; ++i)
dev.send_byte(pgm_read_byte(&letter_h[i]));
//send letter 'i'
for(uint8_t i{0}; i < 8; ++i)
dev.send_byte(pgm_read_byte(&letter_i[i]));
dev.stop_condition();
while(true);
}