Browse Source

readd data_x_times

digi-v2-tests
Chris 4 years ago
parent
commit
468425881c
  1. 8
      src/epd1in54/mod.rs
  2. 21
      src/interface.rs

8
src/epd1in54/mod.rs

@ -181,11 +181,11 @@ where
let color = self.background_color.get_byte_value();
//TODO: this is using a big buffer atm, is it better to just loop over sending a single byte?
self.interface.cmd_with_data(
self.interface.cmd(
spi,
Command::WRITE_RAM,
&[color; WIDTH as usize / 8 * HEIGHT as usize]
)
Command::WRITE_RAM
)?;
self.interface.data_x_times(spi, color, WIDTH / 8 * HEIGHT)
}

21
src/interface.rs

@ -74,6 +74,27 @@ where
self.data(spi, data)
}
/// Basic function for sending the same byte of data (one u8) multiple times over spi
///
/// Enables direct interaction with the device with the help of [command()](ConnectionInterface::command())
///
/// //TODO: make public?
pub(crate) fn data_x_times(
&mut self,
spi: &mut SPI,
val: u8,
repetitions: u16,
) -> Result<(), SPI::Error> {
// high for data
self.dc.set_high();
// Transfer data (u8) over spi
for _ in 0..repetitions {
self.write(spi, &[val])?;
}
Ok(())
}
// spi write helper/abstraction function
fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error>
{

Loading…
Cancel
Save