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
use hal;
use hal::digital::OutputPin;
use super::properties::DisplayRotation;
use super::properties::DisplaySize;
use super::interface::{SpiInterface};
use super::display::Display;
use super::mode::displaymode::DisplayMode;
use super::mode::raw::RawMode;
#[derive(Clone)]
pub struct Builder {
display_size: DisplaySize,
rotation: DisplayRotation,
}
impl Default for Builder {
fn default() -> Self {
Self::new()
}
}
impl Builder {
pub fn new() -> Self {
Self {
display_size: DisplaySize::Display128x128,
rotation: DisplayRotation::Rotate0
}
}
pub fn with_size(&self, display_size: DisplaySize) -> Self {
Self {
display_size,
..*self
}
}
pub fn with_rotation(&self, rotation: DisplayRotation) -> Self {
Self { rotation, ..*self }
}
#[cfg(feature = "buffered")]
pub fn connect_spi<SPI, DC>(
&self,
spi: SPI,
dc: DC,
buffer: &'static mut [u8],
) -> DisplayMode<RawMode<SpiInterface<SPI, DC>>>
where
SPI: hal::blocking::spi::Transfer<u8> + hal::blocking::spi::Write<u8>,
DC: OutputPin,
{
assert_eq!(buffer.len(), 128 * 128 * 2);
let properties =
Display::new(SpiInterface::new(spi, dc), self.display_size, self.rotation);
DisplayMode::<RawMode<SpiInterface<SPI, DC>>>::new(properties, buffer)
}
#[cfg(not(feature = "buffered"))]
pub fn connect_spi<SPI, DC>(
&self,
spi: SPI,
dc: DC,
) -> DisplayMode<RawMode<SpiInterface<SPI, DC>>>
where
SPI: hal::blocking::spi::Transfer<u8> + hal::blocking::spi::Write<u8>,
DC: OutputPin,
{
let properties =
Display::new(SpiInterface::new(spi, dc), self.display_size, self.rotation);
DisplayMode::<RawMode<SpiInterface<SPI, DC>>>::new(properties)
}
}