From 468425881cd9c741ee9f2478204351eeeba27ff2 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 11 Oct 2018 00:33:44 +0200 Subject: [PATCH] readd data_x_times --- src/epd1in54/mod.rs | 8 ++++---- src/interface.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index 35e47d0..99732d1 100644 --- a/src/epd1in54/mod.rs +++ b/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) } diff --git a/src/interface.rs b/src/interface.rs index 623a2fc..1b1a6b9 100644 --- a/src/interface.rs +++ b/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> {