diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index 7b19b7d..6c17f3e 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -178,8 +178,11 @@ where // clear the ram with the background color let color = self.background_color.get_byte_value(); - self.interface.cmd(Command::WRITE_RAM)?; - self.interface.data_x_times(color, WIDTH / 8 * HEIGHT) + //TODO: this is using a big buffer atm, is it better to just loop over sending a single byte? + self.interface.cmd_with_data( + Command::WRITE_RAM, + &[color; WIDTH as usize / 8 * HEIGHT as usize] + ) } diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index 7eaeccd..35199f0 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -175,8 +175,11 @@ where // clear the ram with the background color let color = self.background_color.get_byte_value(); - self.interface.cmd(Command::WRITE_RAM)?; - self.interface.data_x_times(color, WIDTH / 8 * HEIGHT) + //TODO: this is using a big buffer atm, is it better to just loop over sending a single byte? + self.interface.cmd_with_data( + Command::WRITE_RAM, + &[color; WIDTH as usize / 8 * HEIGHT as usize] + ) } /// Sets the backgroundcolor for various commands like [WaveshareInterface::clear_frame()](clear_frame()) diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index f4bac81..ca8e494 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -191,7 +191,9 @@ where self.command(Command::DATA_START_TRANSMISSION_1)?; - self.interface.data_x_times(color_value, buffer.len() as u16)?; + for _ in 0..buffer.len() { + self.send_data(&[color_value])?; + } //TODO: Removal of delay. TEST! //self.delay_ms(2); @@ -254,17 +256,23 @@ where fn clear_frame(&mut self) -> Result<(), ERR> { self.send_resolution()?; - let size = WIDTH / 8 * HEIGHT; + //let size = WIDTH as usize / 8 * HEIGHT as usize; let color_value = self.color.get_byte_value(); - self.command(Command::DATA_START_TRANSMISSION_1)?; - self.interface.data_x_times(color_value, size)?; + //TODO: this is using a big buffer atm, is it better to just loop over sending a single byte? + self.interface.cmd_with_data( + Command::DATA_START_TRANSMISSION_1, + &[color_value; WIDTH as usize / 8 * HEIGHT as usize] + )?; //TODO: Removal of delay. TEST! //self.delay_ms(2); - self.command(Command::DATA_START_TRANSMISSION_2)?; - self.interface.data_x_times(color_value, size) + //TODO: this is using a big buffer atm, is it better to just loop over sending a single byte? + self.interface.cmd_with_data( + Command::DATA_START_TRANSMISSION_2, + &[color_value; WIDTH as usize / 8 * HEIGHT as usize] + ) } /// Sets the backgroundcolor for various commands like [WaveshareInterface::clear_frame()](clear_frame()) diff --git a/src/traits/connection_interface.rs b/src/traits/connection_interface.rs index 978ba2e..a3da8c6 100644 --- a/src/traits/connection_interface.rs +++ b/src/traits/connection_interface.rs @@ -73,30 +73,6 @@ where self.data(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, - val: u8, - repetitions: u16, - ) -> Result<(), ERR> { - // high for data - self.dc.set_high(); - - // Transfer data (u8) over spi - self.with_cs(|epd| { - for _ in 0..repetitions { - epd.spi.write(&[val])?; - } - Ok(()) - }) - } - - - // spi write helper/abstraction function fn with_cs(&mut self, f: F) -> Result<(), ERR> where