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