Skip to content

Commit

Permalink
Code improvements for epd12in48
Browse files Browse the repository at this point in the history
Merge concatenated if statements and rename LUTXXX to LutXXX
  • Loading branch information
caemor committed Oct 30, 2024
1 parent 6b89b15 commit e3c9bcf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
12 changes: 6 additions & 6 deletions src/epd12in48b_v2/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ pub enum Command {
DisplayRefresh = 0x12,
DataStartTransmission2 = 0x13,
DualSPI = 0x15,
LUTC = 0x20,
LUTWW = 0x21,
LUTKW_LUTR = 0x22,
LUTWK_LUTW = 0x23,
LUTKK_LUTK = 0x24,
LUTBD = 0x25,
LutC = 0x20,
LutWW = 0x21,
LutKW_LutR = 0x22,
LutWK_LutW = 0x23,
LutKK_LutK = 0x24,
LutBD = 0x25,
KWLUTOption = 0x2B,
VcomAndDataIntervalSetting = 0x50,
TconSetting = 0x60,
Expand Down
36 changes: 14 additions & 22 deletions src/epd12in48b_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,37 +291,37 @@ where
/// Note that stored lookup tables need to be activated by setting
/// [`Config::external_lut`](config::Config::external_lut)`=true`.
pub fn set_lutc(&mut self, data: &[u8]) -> Result<(), SPI::Error> {
self.set_lut(Command::LUTC, data, 60)
self.set_lut(Command::LutC, data, 60)
}

/// Store White-to-White Look-Up Table.
/// See also [`write_data1`](EpdDriver::set_lutc).
pub fn set_lutww(&mut self, data: &[u8]) -> Result<(), SPI::Error> {
self.set_lut(Command::LUTWW, data, 42)
self.set_lut(Command::LutWW, data, 42)
}

/// Store Black-to-White (KW mode) / Red (KWR mode) Look-Up Table.
/// See also [`write_data1`](EpdDriver::set_lutc).
pub fn set_lutkw_lutr(&mut self, data: &[u8]) -> Result<(), SPI::Error> {
self.set_lut(Command::LUTKW_LUTR, data, 60)
self.set_lut(Command::LutKW_LutR, data, 60)
}

/// Store White-to-Black (KW mode) / White (KWR mode) Look-Up Table.
/// See also [`write_data1`](EpdDriver::set_lutc).
pub fn set_lutwk_lutw(&mut self, data: &[u8]) -> Result<(), SPI::Error> {
self.set_lut(Command::LUTWK_LUTW, data, 60)
self.set_lut(Command::LutWK_LutW, data, 60)
}

/// Store Black-to-Black (KW mode) / Black (KWR mode) Look-Up Table.
/// See also [`write_data1`](EpdDriver::set_lutc).
pub fn set_lutkk_lutk(&mut self, data: &[u8]) -> Result<(), SPI::Error> {
self.set_lut(Command::LUTKK_LUTK, data, 60)
self.set_lut(Command::LutKK_LutK, data, 60)
}

/// Store Border Look-Up Table.
/// See also [`write_data1`](EpdDriver::set_lutc).
pub fn set_lutbd(&mut self, data: &[u8]) -> Result<(), SPI::Error> {
self.set_lut(Command::LUTBD, data, 42)
self.set_lut(Command::LutBD, data, 42)
}

fn set_lut(&mut self, cmd: Command, data: &[u8], reqd_len: usize) -> Result<(), SPI::Error> {
Expand Down Expand Up @@ -610,25 +610,17 @@ where

fn busy_chips(&mut self, chips: CS) -> Result<CS, INPUT::Error> {
let mut busy = 0;
if chips & CS_M1 != 0 {
if self.peris.m1_busy.is_low()? {
busy |= CS_M1;
}
if chips & CS_M1 != 0 && self.peris.m1_busy.is_low()? {
busy |= CS_M1;
}
if chips & CS_S1 != 0 {
if self.peris.s1_busy.is_low()? {
busy |= CS_S1;
}
if chips & CS_S1 != 0 && self.peris.s1_busy.is_low()? {
busy |= CS_S1;
}
if chips & CS_M2 != 0 {
if self.peris.m2_busy.is_low()? {
busy |= CS_M2;
}
if chips & CS_M2 != 0 && self.peris.m2_busy.is_low()? {
busy |= CS_M2;
}
if chips & CS_S2 != 0 {
if self.peris.s2_busy.is_low()? {
busy |= CS_S2;
}
if chips & CS_S2 != 0 && self.peris.s2_busy.is_low()? {
busy |= CS_S2;
}
Ok(busy)
}
Expand Down

0 comments on commit e3c9bcf

Please sign in to comment.