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
use super::command::Command;
use display_interface::{DisplayError, WriteOnlyDataCommand};
pub trait NewZeroed {
fn new_zeroed() -> Self;
}
impl<const N: usize> NewZeroed for [u8; N] {
fn new_zeroed() -> Self {
[0u8; N]
}
}
pub trait DisplaySize {
const WIDTH: u8;
const HEIGHT: u8;
const DRIVER_COLS: u8 = 128;
const DRIVER_ROWS: u8 = 64;
const OFFSETX: u8 = 0;
const OFFSETY: u8 = 0;
type Buffer: AsMut<[u8]> + NewZeroed;
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError>;
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize128x64;
impl DisplaySize for DisplaySize128x64 {
const WIDTH: u8 = 128;
const HEIGHT: u8 = 64;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(true, false).send(iface)
}
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize128x32;
impl DisplaySize for DisplaySize128x32 {
const WIDTH: u8 = 128;
const HEIGHT: u8 = 32;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(false, false).send(iface)
}
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize96x16;
impl DisplaySize for DisplaySize96x16 {
const WIDTH: u8 = 96;
const HEIGHT: u8 = 16;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(false, false).send(iface)
}
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize72x40;
impl DisplaySize for DisplaySize72x40 {
const WIDTH: u8 = 72;
const HEIGHT: u8 = 40;
const OFFSETX: u8 = 28;
const OFFSETY: u8 = 0;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(true, false).send(iface)?;
Command::InternalIref(true, true).send(iface)
}
}
#[derive(Debug, Copy, Clone)]
pub struct DisplaySize64x48;
impl DisplaySize for DisplaySize64x48 {
const WIDTH: u8 = 64;
const HEIGHT: u8 = 48;
const OFFSETX: u8 = 32;
const OFFSETY: u8 = 0;
type Buffer = [u8; Self::WIDTH as usize * Self::HEIGHT as usize / 8];
fn configure(&self, iface: &mut impl WriteOnlyDataCommand) -> Result<(), DisplayError> {
Command::ComPinConfig(true, false).send(iface)
}
}