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
use display_interface::{DataFormat::U8, DisplayError, WriteOnlyDataCommand};
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
pub enum Command {
AYAddress(u8),
Bias(u8),
VoltageClock(u8),
PowerControl(u8),
DisplayOn(bool),
StartLine(u8),
DisplayControl(bool, bool, bool, bool),
AYWindow(u8, u8),
AXWindow(u8, u8),
SWReset,
Duty(u8),
Contrast(u8),
AXAddress(u8),
Booster(Booster),
}
impl Command {
pub fn send<DI>(self, iface: &mut DI) -> Result<(), DisplayError>
where
DI: WriteOnlyDataCommand,
{
let (data, len) = match self {
Command::AYAddress(address) => ([0x01, address & 0x1f, 0], 2),
Command::Bias(bias) => ([0x30, bias & 0x3f, 0], 2),
Command::VoltageClock(clock) => ([0x31, clock & 0x3f, 0], 2),
Command::PowerControl(control) => ([0x33, control, 0], 2),
Command::DisplayOn(on) => ([0x3c | (on as u8), 0, 0], 1),
Command::StartLine(start) => ([0x40, start, 0], 2),
Command::DisplayControl(shl, adc, eon, rev) => (
[
0x60 | (shl as u8) << 3 | (adc as u8) << 2 | (eon as u8) << 1 | (rev as u8),
0,
0,
],
1,
),
Command::AYWindow(start, end) => ([0x74, start & 0x1f, end & 0x1f], 3),
Command::AXWindow(start, end) => ([0x75, start & 0x7f, end & 0x7f], 3),
Command::SWReset => ([0x76, 0, 0], 1),
Command::Duty(duty) => ([0x90, duty, 0], 2),
Command::Contrast(contrast) => ([0xb1, contrast, 0], 2),
Command::AXAddress(address) => ([0xc0, address & 0x7f, 0], 2),
Command::Booster(booster) => ([0xfc | (0x03 & (booster as u8)), 0, 0], 1),
};
iface.send_commands(U8(&data[0..len]))
}
}
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
pub enum Booster {
VddX2 = 0b00,
VddX3 = 0b01,
VddX4 = 0b10,
VddX5 = 0b11,
}