Browse Source

Deletion of single u8 data Transfers and renaming of various functions

command_with_data -> cmd_with_data
command -> cmd
multiple_data -> data
embedded-hal-1.0
Chris 7 years ago
parent
commit
0ddaf9679a
  1. 57
      src/epd1in54/mod.rs
  2. 61
      src/epd2in9/mod.rs
  3. 11
      src/epd4in2/command.rs
  4. 87
      src/epd4in2/mod.rs
  5. 29
      src/interface/connection_interface.rs

57
src/epd1in54/mod.rs

@ -65,33 +65,30 @@ where
// 0.. A[8] // 0.. A[8]
// 0.. B[2:0] // 0.. B[2:0]
// Default Values: A = Height of Screen (0x127), B = 0x00 (GD, SM and TB=0?) // Default Values: A = Height of Screen (0x127), B = 0x00 (GD, SM and TB=0?)
self.interface.command(Command::DRIVER_OUTPUT_CONTROL)?; self.interface.cmd_with_data(
self.interface.data(HEIGHT as u8)?; Command::DRIVER_OUTPUT_CONTROL,
self.interface.data((HEIGHT >> 8) as u8)?; &[HEIGHT as u8, (HEIGHT >> 8) as u8, 0x00]
self.interface.data(0x00)?; )?;
// 3 Databytes: (and default values from datasheet and arduino) // 3 Databytes: (and default values from datasheet and arduino)
// 1 .. A[6:0] = 0xCF | 0xD7 // 1 .. A[6:0] = 0xCF | 0xD7
// 1 .. B[6:0] = 0xCE | 0xD6 // 1 .. B[6:0] = 0xCE | 0xD6
// 1 .. C[6:0] = 0x8D | 0x9D // 1 .. C[6:0] = 0x8D | 0x9D
//TODO: test //TODO: test
self.interface.command(Command::BOOSTER_SOFT_START_CONTROL)?; self.interface.cmd_with_data(Command::BOOSTER_SOFT_START_CONTROL, &[0xD7, 0xD6, 0x9D])?;
self.interface.data(0xD7)?;
self.interface.data(0xD6)?;
self.interface.data(0x9D)?;
// One Databyte with value 0xA8 for 7V VCOM // One Databyte with value 0xA8 for 7V VCOM
self.interface.command_with_data(Command::WRITE_VCOM_REGISTER, &[0xA8])?; self.interface.cmd_with_data(Command::WRITE_VCOM_REGISTER, &[0xA8])?;
// One Databyte with default value 0x1A for 4 dummy lines per gate // One Databyte with default value 0x1A for 4 dummy lines per gate
self.interface.command_with_data(Command::SET_DUMMY_LINE_PERIOD, &[0x1A])?; self.interface.cmd_with_data(Command::SET_DUMMY_LINE_PERIOD, &[0x1A])?;
// One Databyte with default value 0x08 for 2us per line // One Databyte with default value 0x08 for 2us per line
self.interface.command_with_data(Command::SET_GATE_LINE_WIDTH, &[0x08])?; self.interface.cmd_with_data(Command::SET_GATE_LINE_WIDTH, &[0x08])?;
// One Databyte with default value 0x03 // One Databyte with default value 0x03
// -> address: x increment, y increment, address counter is updated in x direction // -> address: x increment, y increment, address counter is updated in x direction
self.interface.command_with_data(Command::DATA_ENTRY_MODE_SETTING, &[0x03])?; self.interface.cmd_with_data(Command::DATA_ENTRY_MODE_SETTING, &[0x03])?;
self.set_lut() self.set_lut()
} }
@ -140,7 +137,7 @@ where
fn sleep(&mut self) -> Result<(), E> { fn sleep(&mut self) -> Result<(), E> {
// 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode // 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode
//TODO: is 0x00 needed here or would 0x01 be even more efficient? //TODO: is 0x00 needed here or would 0x01 be even more efficient?
self.interface.command_with_data(Command::DEEP_SLEEP_MODE, &[0x00])?; self.interface.cmd_with_data(Command::DEEP_SLEEP_MODE, &[0x00])?;
self.wait_until_idle(); self.wait_until_idle();
Ok(()) Ok(())
@ -152,7 +149,7 @@ where
fn update_frame(&mut self, buffer: &[u8]) -> Result<(), E> { fn update_frame(&mut self, buffer: &[u8]) -> Result<(), E> {
self.use_full_frame()?; self.use_full_frame()?;
self.interface.command_with_data(Command::WRITE_RAM, buffer) self.interface.cmd_with_data(Command::WRITE_RAM, buffer)
} }
//TODO: update description: last 3 bits will be ignored for width and x_pos //TODO: update description: last 3 bits will be ignored for width and x_pos
@ -167,18 +164,18 @@ where
self.set_ram_area(x, y, x + width, y + height)?; self.set_ram_area(x, y, x + width, y + height)?;
self.set_ram_counter(x, y)?; self.set_ram_counter(x, y)?;
self.interface.command_with_data(Command::WRITE_RAM, buffer) self.interface.cmd_with_data(Command::WRITE_RAM, buffer)
} }
fn display_frame(&mut self) -> Result<(), E> { fn display_frame(&mut self) -> Result<(), E> {
// enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version) // enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version)
//TODO: test control_1 or control_2 with default value 0xFF (from the datasheet) //TODO: test control_1 or control_2 with default value 0xFF (from the datasheet)
self.interface.command_with_data(Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?; self.interface.cmd_with_data(Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?;
self.interface.command(Command::MASTER_ACTIVATION)?; self.interface.cmd(Command::MASTER_ACTIVATION)?;
// MASTER Activation should not be interupted to avoid currption of panel images // MASTER Activation should not be interupted to avoid currption of panel images
// therefore a terminate command is send // therefore a terminate command is send
self.interface.command(Command::NOP) self.interface.cmd(Command::NOP)
} }
fn clear_frame(&mut self) -> Result<(), E> { fn clear_frame(&mut self) -> Result<(), E> {
@ -187,7 +184,7 @@ where
// clear the ram with the background color // clear the ram with the background color
let color = self.background_color.get_byte_value(); let color = self.background_color.get_byte_value();
self.interface.command(Command::WRITE_RAM)?; self.interface.cmd(Command::WRITE_RAM)?;
self.interface.data_x_times(color, WIDTH / 8 * HEIGHT) self.interface.data_x_times(color, WIDTH / 8 * HEIGHT)
} }
@ -235,25 +232,25 @@ where
// x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram
// aren't relevant // aren't relevant
self.interface.command(Command::SET_RAM_X_ADDRESS_START_END_POSITION)?; self.interface.cmd_with_data(
self.interface.data((start_x >> 3) as u8)?; Command::SET_RAM_X_ADDRESS_START_END_POSITION,
self.interface.data((end_x >> 3) as u8)?; &[(start_x >> 3) as u8, (end_x >> 3) as u8]
)?;
// 2 Databytes: A[7:0] & 0..A[8] for each - start and end // 2 Databytes: A[7:0] & 0..A[8] for each - start and end
self.interface.command(Command::SET_RAM_Y_ADDRESS_START_END_POSITION)?; self.interface.cmd_with_data(
self.interface.data(start_y as u8)?; Command::SET_RAM_Y_ADDRESS_START_END_POSITION,
self.interface.data((start_y >> 8) as u8)?; &[start_y as u8, (start_y >> 8) as u8, end_y as u8, (end_y >> 8) as u8]
self.interface.data(end_y as u8)?; )
self.interface.data((end_y >> 8) as u8)
} }
pub(crate) fn set_ram_counter(&mut self, x: u16, y: u16) -> Result<(), E> { pub(crate) fn set_ram_counter(&mut self, x: u16, y: u16) -> Result<(), E> {
// x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram
// aren't relevant // aren't relevant
self.interface.command_with_data(Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?; self.interface.cmd_with_data(Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?;
// 2 Databytes: A[7:0] & 0..A[8] // 2 Databytes: A[7:0] & 0..A[8]
self.interface.command_with_data( self.interface.cmd_with_data(
Command::SET_RAM_Y_ADDRESS_COUNTER, Command::SET_RAM_Y_ADDRESS_COUNTER,
&[ &[
y as u8, y as u8,
@ -281,7 +278,7 @@ where
fn set_lut_helper(&mut self, buffer: &[u8]) -> Result<(), E> { fn set_lut_helper(&mut self, buffer: &[u8]) -> Result<(), E> {
assert!(buffer.len() == 30); assert!(buffer.len() == 30);
self.interface.command_with_data(Command::WRITE_LUT_REGISTER, buffer) self.interface.cmd_with_data(Command::WRITE_LUT_REGISTER, buffer)
} }
} }

61
src/epd2in9/mod.rs

@ -64,42 +64,30 @@ where
// 0.. A[8] // 0.. A[8]
// 0.. B[2:0] // 0.. B[2:0]
// Default Values: A = Height of Screen (0x127), B = 0x00 (GD, SM and TB=0?) // Default Values: A = Height of Screen (0x127), B = 0x00 (GD, SM and TB=0?)
self.interface.command(Command::DRIVER_OUTPUT_CONTROL)?; self.interface.cmd_with_data(Command::DRIVER_OUTPUT_CONTROL, &[0x27, 0x01, 0x00])?;
self.interface.data(HEIGHT as u8)?;
self.interface.data((HEIGHT >> 8) as u8)?;
self.interface.data(0x00)?;
// 3 Databytes: (and default values from datasheet and arduino) // 3 Databytes: (and default values from datasheet and arduino)
// 1 .. A[6:0] = 0xCF | 0xD7 // 1 .. A[6:0] = 0xCF | 0xD7
// 1 .. B[6:0] = 0xCE | 0xD6 // 1 .. B[6:0] = 0xCE | 0xD6
// 1 .. C[6:0] = 0x8D | 0x9D // 1 .. C[6:0] = 0x8D | 0x9D
//TODO: test //TODO: test
self.interface.command(Command::BOOSTER_SOFT_START_CONTROL)?; self.interface.cmd_with_data(Command::BOOSTER_SOFT_START_CONTROL, &[0xD7, 0xD6, 0x9D])?;
self.interface.data(0xD7)?;
self.interface.data(0xD6)?;
self.interface.data(0x9D)?;
// One Databyte with value 0xA8 for 7V VCOM // One Databyte with value 0xA8 for 7V VCOM
self.interface.command(Command::WRITE_VCOM_REGISTER)?; self.interface.cmd_with_data(Command::WRITE_VCOM_REGISTER, &[0xA8])?;
self.interface.data(0xA8)?;
// One Databyte with default value 0x1A for 4 dummy lines per gate // One Databyte with default value 0x1A for 4 dummy lines per gate
self.interface.command(Command::SET_DUMMY_LINE_PERIOD)?; self.interface.cmd_with_data(Command::SET_DUMMY_LINE_PERIOD, &[0x1A])?;
self.interface.data(0x1A)?;
// One Databyte with default value 0x08 for 2us per line // One Databyte with default value 0x08 for 2us per line
self.interface.command(Command::SET_GATE_LINE_WIDTH)?; self.interface.cmd_with_data(Command::SET_GATE_LINE_WIDTH, &[0x08])?;
self.interface.data(0x08)?;
// One Databyte with default value 0x03 // One Databyte with default value 0x03
// -> address: x increment, y increment, address counter is updated in x direction // -> address: x increment, y increment, address counter is updated in x direction
self.interface.command(Command::DATA_ENTRY_MODE_SETTING)?; self.interface.cmd_with_data(Command::DATA_ENTRY_MODE_SETTING, &[0x03])?;
self.interface.data(0x03)?;
self.set_lut() self.set_lut()
} }
} }
impl<SPI, CS, BUSY, DC, RST, Delay, ERR> impl<SPI, CS, BUSY, DC, RST, Delay, ERR>
@ -141,7 +129,7 @@ where
fn sleep(&mut self) -> Result<(), ERR> { fn sleep(&mut self) -> Result<(), ERR> {
// 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode // 0x00 for Normal mode (Power on Reset), 0x01 for Deep Sleep Mode
//TODO: is 0x00 needed here? (see also epd1in54) //TODO: is 0x00 needed here? (see also epd1in54)
self.interface.command_with_data(Command::DEEP_SLEEP_MODE, &[0x00])?; self.interface.cmd_with_data(Command::DEEP_SLEEP_MODE, &[0x00])?;
self.wait_until_idle(); self.wait_until_idle();
Ok(()) Ok(())
@ -158,7 +146,7 @@ where
fn update_frame(&mut self, buffer: &[u8]) -> Result<(), ERR> { fn update_frame(&mut self, buffer: &[u8]) -> Result<(), ERR> {
self.use_full_frame()?; self.use_full_frame()?;
self.interface.command_with_data(Command::WRITE_RAM, buffer) self.interface.cmd_with_data(Command::WRITE_RAM, buffer)
} }
//TODO: update description: last 3 bits will be ignored for width and x_pos //TODO: update description: last 3 bits will be ignored for width and x_pos
@ -173,18 +161,18 @@ where
self.set_ram_area(x, y, x + width, y + height)?; self.set_ram_area(x, y, x + width, y + height)?;
self.set_ram_counter(x, y)?; self.set_ram_counter(x, y)?;
self.interface.command_with_data(Command::WRITE_RAM, buffer) self.interface.cmd_with_data(Command::WRITE_RAM, buffer)
} }
fn display_frame(&mut self) -> Result<(), ERR> { fn display_frame(&mut self) -> Result<(), ERR> {
// enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version) // enable clock signal, enable cp, display pattern -> 0xC4 (tested with the arduino version)
//TODO: test control_1 or control_2 with default value 0xFF (from the datasheet) //TODO: test control_1 or control_2 with default value 0xFF (from the datasheet)
self.interface.command_with_data(Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?; self.interface.cmd_with_data(Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?;
self.interface.command(Command::MASTER_ACTIVATION)?; self.interface.cmd(Command::MASTER_ACTIVATION)?;
// MASTER Activation should not be interupted to avoid currption of panel images // MASTER Activation should not be interupted to avoid currption of panel images
// therefore a terminate command is send // therefore a terminate command is send
self.interface.command(Command::NOP) self.interface.cmd(Command::NOP)
} }
fn clear_frame(&mut self) -> Result<(), ERR> { fn clear_frame(&mut self) -> Result<(), ERR> {
@ -193,7 +181,7 @@ where
// clear the ram with the background color // clear the ram with the background color
let color = self.background_color.get_byte_value(); let color = self.background_color.get_byte_value();
self.interface.command(Command::WRITE_RAM)?; self.interface.cmd(Command::WRITE_RAM)?;
self.interface.data_x_times(color, WIDTH / 8 * HEIGHT) self.interface.data_x_times(color, WIDTH / 8 * HEIGHT)
} }
@ -240,27 +228,24 @@ where
// x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram
// aren't relevant // aren't relevant
self.interface.command(Command::SET_RAM_X_ADDRESS_START_END_POSITION)?; self.interface.cmd_with_data(
self.interface.data((start_x >> 3) as u8)?; Command::SET_RAM_X_ADDRESS_START_END_POSITION,
self.interface.data((end_x >> 3) as u8)?; &[(start_x >> 3) as u8, (end_x >> 3) as u8]
)?;
// 2 Databytes: A[7:0] & 0..A[8] for each - start and end // 2 Databytes: A[7:0] & 0..A[8] for each - start and end
self.interface.command(Command::SET_RAM_Y_ADDRESS_START_END_POSITION)?; self.interface.cmd_with_data(Command::SET_RAM_Y_ADDRESS_START_END_POSITION,
self.interface.data(start_y as u8)?; &[start_y as u8, (start_y >> 8) as u8, end_y as u8, (end_y >> 8) as u8]
self.interface.data((start_y >> 8) as u8)?; )
self.interface.data(end_y as u8)?;
self.interface.data((end_y >> 8) as u8)
} }
pub(crate) fn set_ram_counter(&mut self, x: u16, y: u16) -> Result<(), E> { pub(crate) fn set_ram_counter(&mut self, x: u16, y: u16) -> Result<(), E> {
// x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram // x is positioned in bytes, so the last 3 bits which show the position inside a byte in the ram
// aren't relevant // aren't relevant
self.interface.command_with_data(Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?; self.interface.cmd_with_data(Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?;
// 2 Databytes: A[7:0] & 0..A[8] // 2 Databytes: A[7:0] & 0..A[8]
self.interface.command(Command::SET_RAM_Y_ADDRESS_COUNTER)?; self.interface.cmd_with_data(Command::SET_RAM_Y_ADDRESS_COUNTER, &[y as u8, (y >> 8) as u8])?;
self.interface.data(y as u8)?;
self.interface.data((y >> 8) as u8)?;
self.wait_until_idle(); self.wait_until_idle();
Ok(()) Ok(())
@ -283,7 +268,7 @@ where
fn set_lut_helper(&mut self, buffer: &[u8]) -> Result<(), E> { fn set_lut_helper(&mut self, buffer: &[u8]) -> Result<(), E> {
assert!(buffer.len() == 30); assert!(buffer.len() == 30);
self.interface.command_with_data(Command::WRITE_LUT_REGISTER, buffer) self.interface.cmd_with_data(Command::WRITE_LUT_REGISTER, buffer)
} }
} }

11
src/epd4in2/command.rs

@ -12,8 +12,18 @@ use interface;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub(crate) enum Command { pub(crate) enum Command {
/// Set Resolution, LUT selection, BWR pixels, gate scan direction, source shift direction, booster switch, soft reset /// Set Resolution, LUT selection, BWR pixels, gate scan direction, source shift direction, booster switch, soft reset
/// One Byte of Data:
/// 0x0F Red Mode, LUT from OTP
/// 0x1F B/W Mode, LUT from OTP
/// 0x2F Red Mode, LUT set by registers
/// 0x3F B/W Mode, LUT set by registers
PANEL_SETTING = 0x00, PANEL_SETTING = 0x00,
/// selecting internal and external power /// selecting internal and external power
/// self.send_data(0x03)?; //VDS_EN, VDG_EN
/// self.send_data(0x00)?; //VCOM_HV, VGHL_LV[1], VGHL_LV[0]
/// self.send_data(0x2b)?; //VDH
/// self.send_data(0x2b)?; //VDL
/// self.send_data(0xff)?; //VDHR
POWER_SETTING = 0x01, POWER_SETTING = 0x01,
/// After the Power Off command, the driver will power off following the Power Off Sequence. This command will turn off charge /// After the Power Off command, the driver will power off following the Power Off Sequence. This command will turn off charge
/// pump, T-con, source driver, gate driver, VCOM, and temperature sensor, but register data will be kept until VDD becomes OFF. /// pump, T-con, source driver, gate driver, VCOM, and temperature sensor, but register data will be kept until VDD becomes OFF.
@ -26,6 +36,7 @@ pub(crate) enum Command {
/// This command enables the internal bandgap, which will be cleared by the next POF. /// This command enables the internal bandgap, which will be cleared by the next POF.
POWER_ON_MEASURE = 0x05, POWER_ON_MEASURE = 0x05,
/// Starting data transmission /// Starting data transmission
/// 3-times: self.send_data(0x17)?; //07 0f 17 1f 27 2F 37 2f
BOOSTER_SOFT_START = 0x06, BOOSTER_SOFT_START = 0x06,
/// After this command is transmitted, the chip would enter the deep-sleep mode to save power. /// After this command is transmitted, the chip would enter the deep-sleep mode to save power.
/// ///

87
src/epd4in2/mod.rs

@ -90,42 +90,23 @@ where
self.interface.reset(); self.interface.reset();
// set the power settings // set the power settings
self.command(Command::POWER_SETTING)?; self.interface.cmd_with_data(Command::POWER_SETTING, &[0x03, 0x00, 0x2b, 0x2b, 0xff])?;
self.send_data(0x03)?; //VDS_EN, VDG_EN
self.send_data(0x00)?; //VCOM_HV, VGHL_LV[1], VGHL_LV[0]
self.send_data(0x2b)?; //VDH
self.send_data(0x2b)?; //VDL
self.send_data(0xff)?; //VDHR
// start the booster // start the booster
self.command(Command::BOOSTER_SOFT_START)?; self.interface.cmd_with_data(Command::BOOSTER_SOFT_START, &[0x17, 0x17, 0x17])?;
for _ in 0..3 {
self.send_data(0x17)?; //07 0f 17 1f 27 2F 37 2f
}
// power on // power on
self.command(Command::POWER_ON)?; self.command(Command::POWER_ON)?;
self.wait_until_idle(); self.wait_until_idle();
// set the panel settings // set the panel settings
self.command(Command::PANEL_SETTING)?; self.cmd_with_data(Command::PANEL_SETTING, &[0x3F])?;
// 0x0F Red Mode, LUT from OTP
// 0x1F B/W Mode, LUT from OTP
// 0x2F Red Mode, LUT set by registers
// 0x3F B/W Mode, LUT set by registers
self.send_data(0x3F)?;
// the values used by waveshare before for the panel settings
// instead of our one liner:
// SendData(0xbf); // KW-BF KWR-AF BWROTP 0f
// SendData(0x0b);
// Set Frequency, 200 Hz didn't work on my board // Set Frequency, 200 Hz didn't work on my board
// 150Hz and 171Hz wasn't tested yet // 150Hz and 171Hz wasn't tested yet
// TODO: Test these other frequencies // TODO: Test these other frequencies
// 3A 100HZ 29 150Hz 39 200HZ 31 171HZ DEFAULT: 3c 50Hz // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ DEFAULT: 3c 50Hz
self.command(Command::PLL_CONTROL)?; self.cmd_with_data(Command::PLL_CONTROL, &[0x3A])?;
self.send_data(0x3A)?;
self.set_lut()?; self.set_lut()?;
@ -179,20 +160,20 @@ where
//TODO: is such a long delay really needed inbetween? //TODO: is such a long delay really needed inbetween?
fn sleep(&mut self) -> Result<(), ERR> { fn sleep(&mut self) -> Result<(), ERR> {
self.interface.command_with_data(Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating self.interface.cmd_with_data(Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating
self.command(Command::VCM_DC_SETTING)?; // VCOM to 0V self.command(Command::VCM_DC_SETTING)?; // VCOM to 0V
self.command(Command::PANEL_SETTING)?; self.command(Command::PANEL_SETTING)?;
self.delay_ms(100); self.delay_ms(100);
self.command(Command::POWER_SETTING)?; //VG&VS to 0V fast self.command(Command::POWER_SETTING)?; //VG&VS to 0V fast
for _ in 0..4 { for _ in 0..4 {
self.send_data(0x00)?; self.send_data(&[0x00])?;
} }
self.delay_ms(100); self.delay_ms(100);
self.command(Command::POWER_OFF)?; self.command(Command::POWER_OFF)?;
self.wait_until_idle(); self.wait_until_idle();
self.interface.command_with_data(Command::DEEP_SLEEP, &[0xA5]) self.interface.cmd_with_data(Command::DEEP_SLEEP, &[0xA5])
} }
fn update_frame(&mut self, buffer: &[u8]) -> Result<(), ERR> { fn update_frame(&mut self, buffer: &[u8]) -> Result<(), ERR> {
@ -200,11 +181,11 @@ where
self.send_resolution()?; self.send_resolution()?;
self.interface.command_with_data(Command::VCM_DC_SETTING, &[0x12])?; self.interface.cmd_with_data(Command::VCM_DC_SETTING, &[0x12])?;
//TODO: this was a send_command instead of a send_data. check if it's alright and doing what it should do (setting the default values) //TODO: this was a send_command instead of a send_data. check if it's alright and doing what it should do (setting the default values)
//self.send_command_u8(0x97)?; //VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7 //self.send_command_u8(0x97)?; //VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7
self.interface.command_with_data(Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x97])?; self.interface.cmd_with_data(Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x97])?;
self.command(Command::DATA_START_TRANSMISSION_1)?; self.command(Command::DATA_START_TRANSMISSION_1)?;
@ -212,7 +193,7 @@ where
self.delay_ms(2); self.delay_ms(2);
self.interface.command_with_data(Command::DATA_START_TRANSMISSION_2, buffer) self.interface.cmd_with_data(Command::DATA_START_TRANSMISSION_2, buffer)
} }
fn update_partial_frame( fn update_partial_frame(
@ -230,20 +211,20 @@ where
self.command(Command::PARTIAL_IN)?; self.command(Command::PARTIAL_IN)?;
self.command(Command::PARTIAL_WINDOW)?; self.command(Command::PARTIAL_WINDOW)?;
self.send_data((x >> 8) as u8)?; self.send_data(&[(x >> 8) as u8])?;
let tmp = x & 0xf8; let tmp = x & 0xf8;
self.send_data(tmp as u8)?; // x should be the multiple of 8, the last 3 bit will always be ignored self.send_data(&[tmp as u8])?; // x should be the multiple of 8, the last 3 bit will always be ignored
let tmp = tmp + width - 1; let tmp = tmp + width - 1;
self.send_data((tmp >> 8) as u8)?; self.send_data(&[(tmp >> 8) as u8])?;
self.send_data((tmp | 0x07) as u8)?; self.send_data(&[(tmp | 0x07) as u8])?;
self.send_data((y >> 8) as u8)?; self.send_data(&[(y >> 8) as u8])?;
self.send_data(y as u8)?; self.send_data(&[y as u8])?;
self.send_data(((y + height - 1) >> 8) as u8)?; self.send_data(&[((y + height - 1) >> 8) as u8])?;
self.send_data((y + height - 1) as u8)?; self.send_data(&[(y + height - 1) as u8])?;
self.send_data(0x01)?; // Gates scan both inside and outside of the partial window. (default) self.send_data(&[0x01])?; // Gates scan both inside and outside of the partial window. (default)
//TODO: handle dtm somehow //TODO: handle dtm somehow
let is_dtm1 = false; let is_dtm1 = false;
@ -253,7 +234,7 @@ where
self.command(Command::DATA_START_TRANSMISSION_2)? self.command(Command::DATA_START_TRANSMISSION_2)?
} }
self.send_multiple_data(buffer)?; self.send_data(buffer)?;
self.command(Command::PARTIAL_OUT) self.command(Command::PARTIAL_OUT)
} }
@ -315,15 +296,15 @@ where
D: DelayUs<u16> + DelayMs<u16>, D: DelayUs<u16> + DelayMs<u16>,
{ {
fn command(&mut self, command: Command) -> Result<(), ERR> { fn command(&mut self, command: Command) -> Result<(), ERR> {
self.interface.command(command) self.interface.cmd(command)
} }
fn send_data(&mut self, val: u8) -> Result<(), ERR> { fn send_data(&mut self, data: &[u8]) -> Result<(), ERR> {
self.interface.data(val) self.interface.data(data)
} }
fn send_multiple_data(&mut self, data: &[u8]) -> Result<(), ERR> { fn cmd_with_data(&mut self, command: Command, data: &[u8]) -> Result<(), ERR> {
self.interface.multiple_data(data) self.interface.cmd_with_data(command, data)
} }
fn wait_until_idle(&mut self) { fn wait_until_idle(&mut self) {
@ -335,10 +316,10 @@ where
let h = self.height(); let h = self.height();
self.command(Command::RESOLUTION_SETTING)?; self.command(Command::RESOLUTION_SETTING)?;
self.send_data((w >> 8) as u8)?; self.send_data(&[(w >> 8) as u8])?;
self.send_data(w as u8)?; self.send_data(&[w as u8])?;
self.send_data((h >> 8) as u8)?; self.send_data(&[(h >> 8) as u8])?;
self.send_data(h as u8) self.send_data(&[h as u8])
} }
/// Fill the look-up table for the EPD /// Fill the look-up table for the EPD
@ -372,23 +353,23 @@ where
) -> Result<(), ERR> { ) -> Result<(), ERR> {
// LUT VCOM // LUT VCOM
self.command(Command::LUT_FOR_VCOM)?; self.command(Command::LUT_FOR_VCOM)?;
self.send_multiple_data(lut_vcom)?; self.send_data(lut_vcom)?;
// LUT WHITE to WHITE // LUT WHITE to WHITE
self.command(Command::LUT_WHITE_TO_WHITE)?; self.command(Command::LUT_WHITE_TO_WHITE)?;
self.send_multiple_data(lut_ww)?; self.send_data(lut_ww)?;
// LUT BLACK to WHITE // LUT BLACK to WHITE
self.command(Command::LUT_BLACK_TO_WHITE)?; self.command(Command::LUT_BLACK_TO_WHITE)?;
self.send_multiple_data(lut_bw)?; self.send_data(lut_bw)?;
// LUT WHITE to BLACK // LUT WHITE to BLACK
self.command(Command::LUT_WHITE_TO_BLACK)?; self.command(Command::LUT_WHITE_TO_BLACK)?;
self.send_multiple_data(lut_wb)?; self.send_data(lut_wb)?;
// LUT BLACK to BLACK // LUT BLACK to BLACK
self.command(Command::LUT_BLACK_TO_BLACK)?; self.command(Command::LUT_BLACK_TO_BLACK)?;
self.send_multiple_data(lut_bb)?; self.send_data(lut_bb)?;
Ok(()) Ok(())
} }

29
src/interface/connection_interface.rs

@ -48,7 +48,7 @@ where
/// Enables direct interaction with the device with the help of [data()](ConnectionInterface::data()) /// Enables direct interaction with the device with the help of [data()](ConnectionInterface::data())
/// ///
/// //TODO: make public? /// //TODO: make public?
pub(crate) fn command<T: Command>(&mut self, command: T) -> Result<(), ERR> { pub(crate) fn cmd<T: Command>(&mut self, command: T) -> Result<(), ERR> {
// low for commands // low for commands
self.dc.set_low(); self.dc.set_low();
@ -56,25 +56,25 @@ where
self.with_cs(|epd| epd.spi.write(&[command.address()])) self.with_cs(|epd| epd.spi.write(&[command.address()]))
} }
/// Basic function for sending a single u8 of data over spi /// Basic function for sending an array of u8-values of data over spi
/// ///
/// Enables direct interaction with the device with the help of [Ecommand()](ConnectionInterface::command()) /// Enables direct interaction with the device with the help of [command()](EPD4in2::command())
/// ///
/// //TODO: make public? /// //TODO: make public?
pub(crate) fn data(&mut self, val: u8) -> Result<(), ERR> { pub(crate) fn data(&mut self, data: &[u8]) -> Result<(), ERR> {
// high for data // high for data
self.dc.set_high(); self.dc.set_high();
// Transfer data (u8) over spi // Transfer data (u8-array) over spi
self.with_cs(|epd| epd.spi.write(&[val])) self.with_cs(|epd| epd.spi.write(data))
} }
/// Basic function for sending [Commands](Command) and the data belonging to it. /// Basic function for sending [Commands](Command) and the data belonging to it.
/// ///
/// //TODO: make public? /// //TODO: make public?
pub(crate) fn command_with_data<T: Command>(&mut self, command: T, data: &[u8]) -> Result<(), ERR> { pub(crate) fn cmd_with_data<T: Command>(&mut self, command: T, data: &[u8]) -> Result<(), ERR> {
self.command(command)?; self.cmd(command)?;
self.multiple_data(data) self.data(data)
} }
/// Basic function for sending the same byte of data (one u8) multiple times over spi /// Basic function for sending the same byte of data (one u8) multiple times over spi
@ -99,18 +99,7 @@ where
}) })
} }
/// Basic function for sending an array of u8-values of data over spi
///
/// Enables direct interaction with the device with the help of [command()](EPD4in2::command())
///
/// //TODO: make public?
pub(crate) fn multiple_data(&mut self, data: &[u8]) -> Result<(), ERR> {
// high for data
self.dc.set_high();
// Transfer data (u8-array) over spi
self.with_cs(|epd| epd.spi.write(data))
}
// spi write helper/abstraction function // spi write helper/abstraction function
fn with_cs<F>(&mut self, f: F) -> Result<(), ERR> fn with_cs<F>(&mut self, f: F) -> Result<(), ERR>

Loading…
Cancel
Save