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
use hal;
use hal::digital::v2::OutputPin;
use super::DisplayInterface;
use crate::Error;
pub struct SpiInterface<SPI, DC> {
spi: SPI,
dc: DC,
}
impl<SPI, DC, CommE, PinE> SpiInterface<SPI, DC>
where
SPI: hal::blocking::spi::Write<u8, Error = CommE>,
DC: OutputPin<Error = PinE>,
{
pub fn new(spi: SPI, dc: DC) -> Self {
Self { spi, dc }
}
}
impl<SPI, DC, CommE, PinE> DisplayInterface for SpiInterface<SPI, DC>
where
SPI: hal::blocking::spi::Write<u8, Error = CommE>,
DC: OutputPin<Error = PinE>,
{
type Error = Error<CommE, PinE>;
fn send_commands(&mut self, cmds: &[u8]) -> Result<(), Self::Error> {
self.dc.set_low().map_err(Error::Pin)?;
self.spi.write(&cmds).map_err(Error::Comm)?;
self.dc.set_high().map_err(Error::Pin)
}
fn send_data(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
self.dc.set_high().map_err(Error::Pin)?;
self.spi.write(&buf).map_err(Error::Comm)
}
}