Browse Source

Write data over SPI 1 byte at a time

Fixes #82
main
Kaleb Elwert 4 years ago
parent
commit
247a78acb7
  1. 16
      src/interface.rs

16
src/interface.rs

@ -57,11 +57,15 @@ where
/// ///
/// Enables direct interaction with the device with the help of [command()](Epd4in2::command()) /// Enables direct interaction with the device with the help of [command()](Epd4in2::command())
pub(crate) fn data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> { pub(crate) fn data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
// high for data for val in data.iter().copied() {
let _ = self.dc.set_high(); // high for data
let _ = self.dc.set_high();
// Transfer data (u8-array) over spi // Transfer data one u8 at a time over spi
self.write(spi, data) self.write(spi, &[val])?;
}
Ok(())
} }
/// Basic function for sending [Commands](Command) and the data belonging to it. /// Basic function for sending [Commands](Command) and the data belonging to it.
@ -86,11 +90,9 @@ where
val: u8, val: u8,
repetitions: u32, repetitions: u32,
) -> Result<(), SPI::Error> { ) -> Result<(), SPI::Error> {
// high for data
let _ = self.dc.set_high();
// Transfer data (u8) over spi // Transfer data (u8) over spi
for _ in 0..repetitions { for _ in 0..repetitions {
self.write(spi, &[val])?; self.data(spi, &[val])?;
} }
Ok(()) Ok(())
} }

Loading…
Cancel
Save