Skip to content

Commit

Permalink
WIP make clippy happier
Browse files Browse the repository at this point in the history
  • Loading branch information
dkm committed Aug 27, 2020
1 parent f216a71 commit 1a6c896
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 43 deletions.
37 changes: 26 additions & 11 deletions src/epd2in13_v2/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ pub(crate) enum Command {

/// These are not directly documented, but the bitfield is easily reversed from
/// documentation and sample code
#[allow(dead_code)]
#[allow(non_camel_case_types)]
pub(crate) enum DisplayUpdateControl2V {
E_CLOCK = 0x80,
E_ANALOG = 0x40,
ENABLE_CLOCK = 0x80,
ENABLE_ANALOG = 0x40,

LOAD_TEMP = 0x20,
LOAD_LUT = 0x10,
Expand All @@ -70,8 +72,8 @@ pub(crate) enum DisplayUpdateControl2V {

DISPLAY = 0x04,

D_ANALOG = 0x02,
D_CLOCK = 0x01,
DISABLE_ANALOG = 0x02,
DISABLE_CLOCK = 0x01,
}

pub(crate) struct DriverOutput {
Expand All @@ -84,29 +86,30 @@ pub(crate) struct DriverOutput {

impl DriverOutput {
pub fn to_bytes(&self) -> [u8; 3] {
return [
[
self.width as u8,
(self.width >> 8) as u8,
!self.scan_dir_incr as u8
| ((!self.scan_g0_is_first as u8) << 1)
| ((!self.scan_is_linear as u8) << 2),
];
]
}
}

pub(crate) struct DisplayUpdateControl2(pub u8);

#[allow(dead_code)]
impl DisplayUpdateControl2 {
pub fn new() -> DisplayUpdateControl2 {
DisplayUpdateControl2(0x00)
}

pub fn enable_clock(mut self) -> Self {
self.0 |= DisplayUpdateControl2V::E_CLOCK as u8;
self.0 |= DisplayUpdateControl2V::ENABLE_CLOCK as u8;
self
}
pub fn enable_analog(mut self) -> Self {
self.0 |= DisplayUpdateControl2V::E_ANALOG as u8;
self.0 |= DisplayUpdateControl2V::ENABLE_ANALOG as u8;
self
}

Expand All @@ -128,34 +131,42 @@ impl DisplayUpdateControl2 {
self
}
pub fn disable_analog(mut self) -> Self {
self.0 |= DisplayUpdateControl2V::D_ANALOG as u8;
self.0 |= DisplayUpdateControl2V::DISABLE_ANALOG as u8;
self
}
pub fn disable_clock(mut self) -> Self {
self.0 |= DisplayUpdateControl2V::D_CLOCK as u8;
self.0 |= DisplayUpdateControl2V::DISABLE_CLOCK as u8;
self
}
}

#[allow(dead_code)]
#[allow(non_camel_case_types)]
pub(crate) enum DataEntryModeIncr {
X_DECR_Y_DECR = 0x0,
X_INCR_Y_DECR = 0x1,
X_DECR_Y_INCR = 0x2,
X_INCR_Y_INCR = 0x3,
}

#[allow(dead_code)]
#[allow(non_camel_case_types)]
pub(crate) enum DataEntryModeDir {
X_DIR = 0x0,
Y_DIR = 0x4,
}

#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[derive(Copy, Clone)]
pub(crate) enum BorderWaveFormVBD {
GS = 0x0,
FIX_LEVEL = 0x1,
VCOM = 0x2,
}

#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[derive(Copy, Clone)]
pub(crate) enum BorderWaveFormFixLevel {
VSS = 0x0,
Expand All @@ -164,6 +175,8 @@ pub(crate) enum BorderWaveFormFixLevel {
VSH2 = 0x3,
}

#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[derive(Copy, Clone)]
pub(crate) enum BorderWaveFormGS {
LUT0 = 0x0,
Expand All @@ -186,6 +199,8 @@ impl BorderWaveForm {
}
}

#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[derive(Copy, Clone)]
pub enum DeepSleepMode {
// Sleeps and keeps access to RAM and controller
Expand Down Expand Up @@ -260,7 +275,7 @@ impl I32Ext for i32 {
|| (self >= -180 && self <= -90 && self % 5 == 0)
);

if (self >= 24 && self <= 88) {
if self >= 24 && self <= 88 {
SourceDrivingVoltage(((self - 24) + 0x8E) as u8)
} else if self >= 90 && self <= 180 {
SourceDrivingVoltage(((self - 90) / 2 + 0x23) as u8)
Expand Down
60 changes: 28 additions & 32 deletions src/epd2in13_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use crate::traits::{InternalWiAdditions, RefreshLUT, WaveshareDisplay};
pub(crate) mod command;
use self::command::{
BorderWaveForm, BorderWaveFormFixLevel, BorderWaveFormGS, BorderWaveFormVBD, Command,
DataEntryModeDir, DataEntryModeIncr, DeepSleepMode, DisplayUpdateControl2,
DisplayUpdateControl2V, DriverOutput, GateDrivingVoltage, I32Ext, SourceDrivingVoltage, VCOM,
DataEntryModeDir, DataEntryModeIncr, DeepSleepMode, DisplayUpdateControl2, DriverOutput,
GateDrivingVoltage, I32Ext, SourceDrivingVoltage, VCOM,
};

pub(crate) mod constants;
Expand Down Expand Up @@ -76,7 +76,7 @@ where
self.set_vcom_register(spi, (-9).vcom())?;
self.wait_until_idle();

self.set_lut(spi, Some(RefreshLUT::QUICK))?;
self.set_lut(spi, Some(self.refresh))?;

// Python code does this, not sure why
// self.cmd_with_data(spi, Command::WRITE_OTP_SELECTION, &[0, 0, 0, 0, 0x40, 0, 0])?;
Expand Down Expand Up @@ -140,11 +140,11 @@ where
150.source_driving_decivolt(),
50.source_driving_decivolt(),
(-150).source_driving_decivolt(),
);
)?;

self.cmd_with_data(spi, Command::SET_GATE_LINE_WIDTH, &[0x0A])?;

self.set_lut(spi, Some(RefreshLUT::FULL))?;
self.set_lut(spi, Some(self.refresh))?;
}

self.wait_until_idle();
Expand Down Expand Up @@ -299,9 +299,9 @@ where
spi: &mut SPI,
refresh_rate: Option<RefreshLUT>,
) -> Result<(), SPI::Error> {
let buffer = match self.refresh {
RefreshLUT::FULL => &LUT_FULL_UPDATE,
RefreshLUT::QUICK => &LUT_PARTIAL_UPDATE,
let buffer = match refresh_rate {
Some(RefreshLUT::FULL) | None => &LUT_FULL_UPDATE,
Some(RefreshLUT::QUICK) => &LUT_PARTIAL_UPDATE,
};

self.cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer)
Expand Down Expand Up @@ -352,18 +352,18 @@ where
Ok(())
}

fn set_gate_scan_start_position(
&mut self,
spi: &mut SPI,
start: u16,
) -> Result<(), SPI::Error> {
assert!(start <= 295);
self.cmd_with_data(
spi,
Command::GATE_SCAN_START_POSITION,
&[(start & 0xFF) as u8, ((start >> 8) & 0x1) as u8],
)
}
// fn set_gate_scan_start_position(
// &mut self,
// spi: &mut SPI,
// start: u16,
// ) -> Result<(), SPI::Error> {
// assert!(start <= 295);
// self.cmd_with_data(
// spi,
// Command::GATE_SCAN_START_POSITION,
// &[(start & 0xFF) as u8, ((start >> 8) & 0x1) as u8],
// )
// }

fn set_border_waveform(
&mut self,
Expand All @@ -389,14 +389,14 @@ where
self.cmd_with_data(spi, Command::GATE_DRIVING_VOLTAGE_CTRL, &[voltage.0])
}

fn set_dummy_line_period(
&mut self,
spi: &mut SPI,
number_of_lines: u8,
) -> Result<(), SPI::Error> {
assert!(number_of_lines <= 127);
self.cmd_with_data(spi, Command::SET_DUMMY_LINE_PERIOD, &[number_of_lines])
}
// fn set_dummy_line_period(
// &mut self,
// spi: &mut SPI,
// number_of_lines: u8,
// ) -> Result<(), SPI::Error> {
// assert!(number_of_lines <= 127);
// self.cmd_with_data(spi, Command::SET_DUMMY_LINE_PERIOD, &[number_of_lines])
// }

/// Sets the source driving voltage value
fn set_source_driving_voltage(
Expand Down Expand Up @@ -493,10 +493,6 @@ where
self.interface.cmd(spi, command)
}

fn send_data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
self.interface.data(spi, data)
}

fn cmd_with_data(
&mut self,
spi: &mut SPI,
Expand Down

0 comments on commit 1a6c896

Please sign in to comment.