first steps to rustfmt althought it sometimes doesn#t exactly looks good

This commit is contained in:
Christoph Groß
2018-08-07 16:00:13 +02:00
parent e5a1e3bf25
commit cd98033204
12 changed files with 593 additions and 659 deletions
+142 -145
View File
@@ -1,170 +1,167 @@
//! SPI Commands for the Waveshare 4.2" E-Ink Display
use interface;
/// EPD4IN2 commands
///
///
/// Should rarely (never?) be needed directly.
///
/// For more infos about the addresses and what they are doing look into the pdfs
///
///
/// For more infos about the addresses and what they are doing look into the pdfs
///
/// The description of the single commands is mostly taken from IL0398.pdf
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[derive(Copy, Clone)]
pub(crate) enum Command {
/// Set Resolution, LUT selection, BWR pixels, gate scan direction, source shift direction, booster switch, soft reset
PANEL_SETTING = 0x00,
/// selecting internal and external power
POWER_SETTING = 0x01,
/// 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.
/// Source Driver output and Vcom will remain as previous condition, which may have 2 conditions: floating.
POWER_OFF = 0x02,
/// Setting Power OFF sequence
POWER_OFF_SEQUENCE_SETTING = 0x03,
/// Turning On the Power
POWER_ON = 0x04,
/// This command enables the internal bandgap, which will be cleared by the next POF.
POWER_ON_MEASURE = 0x05,
/// Starting data transmission
BOOSTER_SOFT_START = 0x06,
/// After this command is transmitted, the chip would enter the deep-sleep mode to save power.
///
/// The deep sleep mode would return to standby by hardware reset.
///
/// The only one parameter is a check code, the command would be excuted if check code = 0xA5.
DEEP_SLEEP = 0x07,
/// This command starts transmitting data and write them into SRAM. To complete data transmission, command DSP (Data
/// transmission Stop) must be issued. Then the chip will start to send data/VCOM for panel.
///
/// - In B/W mode, this command writes “OLD” data to SRAM.
/// - In B/W/Red mode, this command writes “B/W” data to SRAM.
/// - In Program mode, this command writes “OTP” data to SRAM for programming.
DATA_START_TRANSMISSION_1 = 0x10,
/// Stopping data transmission
DATA_STOP = 0x11,
/// While user sent this command, driver will refresh display (data/VCOM) according to SRAM data and LUT.
///
/// After Display Refresh command, BUSY_N signal will become “0” and the refreshing of panel starts.
DISPLAY_REFRESH = 0x12,
/// This command starts transmitting data and write them into SRAM. To complete data transmission, command DSP (Data
/// transmission Stop) must be issued. Then the chip will start to send data/VCOM for panel.
/// - In B/W mode, this command writes “NEW” data to SRAM.
/// - In B/W/Red mode, this command writes “RED” data to SRAM.
DATA_START_TRANSMISSION_2 = 0x13,
PANEL_SETTING = 0x00,
/// selecting internal and external power
POWER_SETTING = 0x01,
/// 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.
/// Source Driver output and Vcom will remain as previous condition, which may have 2 conditions: floating.
POWER_OFF = 0x02,
/// Setting Power OFF sequence
POWER_OFF_SEQUENCE_SETTING = 0x03,
/// Turning On the Power
POWER_ON = 0x04,
/// This command enables the internal bandgap, which will be cleared by the next POF.
POWER_ON_MEASURE = 0x05,
/// Starting data transmission
BOOSTER_SOFT_START = 0x06,
/// After this command is transmitted, the chip would enter the deep-sleep mode to save power.
///
/// The deep sleep mode would return to standby by hardware reset.
///
/// The only one parameter is a check code, the command would be excuted if check code = 0xA5.
DEEP_SLEEP = 0x07,
/// This command starts transmitting data and write them into SRAM. To complete data transmission, command DSP (Data
/// transmission Stop) must be issued. Then the chip will start to send data/VCOM for panel.
///
/// - In B/W mode, this command writes “OLD” data to SRAM.
/// - In B/W/Red mode, this command writes “B/W” data to SRAM.
/// - In Program mode, this command writes “OTP” data to SRAM for programming.
DATA_START_TRANSMISSION_1 = 0x10,
/// Stopping data transmission
DATA_STOP = 0x11,
/// While user sent this command, driver will refresh display (data/VCOM) according to SRAM data and LUT.
///
/// After Display Refresh command, BUSY_N signal will become “0” and the refreshing of panel starts.
DISPLAY_REFRESH = 0x12,
/// This command starts transmitting data and write them into SRAM. To complete data transmission, command DSP (Data
/// transmission Stop) must be issued. Then the chip will start to send data/VCOM for panel.
/// - In B/W mode, this command writes “NEW” data to SRAM.
/// - In B/W/Red mode, this command writes “RED” data to SRAM.
DATA_START_TRANSMISSION_2 = 0x13,
/// This command stores VCOM Look-Up Table with 7 groups of data. Each group contains information for one state and is stored
/// with 6 bytes, while the sixth byte indicates how many times that phase will repeat.
///
/// from IL0373
LUT_FOR_VCOM = 0x20,
/// This command stores White-to-White Look-Up Table with 7 groups of data. Each group contains information for one state and is
/// stored with 6 bytes, while the sixth byte indicates how many times that phase will repeat.
///
/// from IL0373
LUT_WHITE_TO_WHITE = 0x21,
/// This command stores Black-to-White Look-Up Table with 7 groups of data. Each group contains information for one state and is
/// stored with 6 bytes, while the sixth byte indicates how many times that phase will repeat.
///
/// from IL0373
LUT_BLACK_TO_WHITE = 0x22,
/// This command stores White-to-Black Look-Up Table with 7 groups of data. Each group contains information for one state and is
/// stored with 6 bytes, while the sixth byte indicates how many times that phase will repeat.
///
/// from IL0373
LUT_WHITE_TO_BLACK = 0x23,
/// This command stores Black-to-Black Look-Up Table with 7 groups of data. Each group contains information for one state and is
/// stored with 6 bytes, while the sixth byte indicates how many times that phase will repeat.
///
/// from IL0373
LUT_BLACK_TO_BLACK = 0x24,
/// The command controls the PLL clock frequency.
PLL_CONTROL = 0x30,
/// This command reads the temperature sensed by the temperature sensor.
///
/// Doesn't work! Waveshare doesn't connect the read pin
TEMPERATURE_SENSOR_COMMAND = 0x40,
/// Selects the Internal or External temperature sensor and offset
TEMPERATURE_SENSOR_SELECTION = 0x41,
/// Write External Temperature Sensor
TEMPERATURE_SENSOR_WRITE = 0x42,
/// Read External Temperature Sensor
///
/// Doesn't work! Waveshare doesn't connect the read pin
TEMPERATURE_SENSOR_READ = 0x43,
/// This command indicates the interval of Vcom and data output. When setting the vertical back porch, the total blanking will be kept (20 Hsync)
VCOM_AND_DATA_INTERVAL_SETTING = 0x50,
/// This command indicates the input power condition. Host can read this flag to learn the battery condition.
LOW_POWER_DETECTION = 0x51,
/// This command defines non-overlap period of Gate and Source.
TCON_SETTING = 0x60,
/// This command defines alternative resolution and this setting is of higher priority than the RES\[1:0\] in R00H (PSR).
RESOLUTION_SETTING = 0x61,
/// This command defines the Fist Active Gate and First Active Source of active channels.
GSST_SETTING = 0x65,
/// The LUT_REV / Chip Revision is read from OTP address = 0x001.
///
/// Doesn't work! Waveshare doesn't connect the read pin
REVISION = 0x70,
/// Read Flags. This command reads the IC status
/// PTL, I2C_ERR, I2C_BUSY, DATA, PON, POF, BUSY
///
/// Doesn't work! Waveshare doesn't connect the read pin
GET_STATUS = 0x71,
/// Automatically measure VCOM. This command reads the IC status
AUTO_MEASUREMENT_VCOM = 0x80,
/// This command gets the VCOM value
///
/// Doesn't work! Waveshare doesn't connect the read pin
READ_VCOM_VALUE = 0x81,
/// Set VCM_DC
VCM_DC_SETTING = 0x82,
/// This command sets partial window
PARTIAL_WINDOW = 0x90,
/// This command makes the display enter partial mode
PARTIAL_IN = 0x91,
/// This command makes the display exit partial mode and enter normal mode
PARTIAL_OUT = 0x92,
/// After this command is issued, the chip would enter the program mode.
///
/// After the programming procedure completed, a hardware reset is necessary for leaving program mode.
///
/// The only one parameter is a check code, the command would be excuted if check code = 0xA5.
PROGRAM_MODE = 0xA0,
/// After this command is transmitted, the programming state machine would be activated.
///
/// The BUSY flag would fall to 0 until the programming is completed.
ACTIVE_PROGRAMMING = 0xA1,
/// The command is used for reading the content of OTP for checking the data of programming.
///
/// The value of (n) is depending on the amount of programmed data, tha max address = 0xFFF.
READ_OTP = 0xA2,
/// This command is set for saving power during fresh period. If the output voltage of VCOM / Source is from negative to positive or
/// from positive to negative, the power saving mechanism will be activated. The active period width is defined by the following two
/// parameters.
POWER_SAVING = 0xE3,
/// This command stores VCOM Look-Up Table with 7 groups of data. Each group contains information for one state and is stored
/// with 6 bytes, while the sixth byte indicates how many times that phase will repeat.
///
/// from IL0373
LUT_FOR_VCOM = 0x20,
/// This command stores White-to-White Look-Up Table with 7 groups of data. Each group contains information for one state and is
/// stored with 6 bytes, while the sixth byte indicates how many times that phase will repeat.
///
/// from IL0373
LUT_WHITE_TO_WHITE = 0x21,
/// This command stores Black-to-White Look-Up Table with 7 groups of data. Each group contains information for one state and is
/// stored with 6 bytes, while the sixth byte indicates how many times that phase will repeat.
///
/// from IL0373
LUT_BLACK_TO_WHITE = 0x22,
/// This command stores White-to-Black Look-Up Table with 7 groups of data. Each group contains information for one state and is
/// stored with 6 bytes, while the sixth byte indicates how many times that phase will repeat.
///
/// from IL0373
LUT_WHITE_TO_BLACK = 0x23,
/// This command stores Black-to-Black Look-Up Table with 7 groups of data. Each group contains information for one state and is
/// stored with 6 bytes, while the sixth byte indicates how many times that phase will repeat.
///
/// from IL0373
LUT_BLACK_TO_BLACK = 0x24,
/// The command controls the PLL clock frequency.
PLL_CONTROL = 0x30,
/// This command reads the temperature sensed by the temperature sensor.
///
/// Doesn't work! Waveshare doesn't connect the read pin
TEMPERATURE_SENSOR_COMMAND = 0x40,
/// Selects the Internal or External temperature sensor and offset
TEMPERATURE_SENSOR_SELECTION = 0x41,
/// Write External Temperature Sensor
TEMPERATURE_SENSOR_WRITE = 0x42,
/// Read External Temperature Sensor
///
/// Doesn't work! Waveshare doesn't connect the read pin
TEMPERATURE_SENSOR_READ = 0x43,
/// This command indicates the interval of Vcom and data output. When setting the vertical back porch, the total blanking will be kept (20 Hsync)
VCOM_AND_DATA_INTERVAL_SETTING = 0x50,
/// This command indicates the input power condition. Host can read this flag to learn the battery condition.
LOW_POWER_DETECTION = 0x51,
/// This command defines non-overlap period of Gate and Source.
TCON_SETTING = 0x60,
/// This command defines alternative resolution and this setting is of higher priority than the RES\[1:0\] in R00H (PSR).
RESOLUTION_SETTING = 0x61,
/// This command defines the Fist Active Gate and First Active Source of active channels.
GSST_SETTING = 0x65,
/// The LUT_REV / Chip Revision is read from OTP address = 0x001.
///
/// Doesn't work! Waveshare doesn't connect the read pin
REVISION = 0x70,
/// Read Flags. This command reads the IC status
/// PTL, I2C_ERR, I2C_BUSY, DATA, PON, POF, BUSY
///
/// Doesn't work! Waveshare doesn't connect the read pin
GET_STATUS = 0x71,
/// Automatically measure VCOM. This command reads the IC status
AUTO_MEASUREMENT_VCOM = 0x80,
/// This command gets the VCOM value
///
/// Doesn't work! Waveshare doesn't connect the read pin
READ_VCOM_VALUE = 0x81,
/// Set VCM_DC
VCM_DC_SETTING = 0x82,
/// This command sets partial window
PARTIAL_WINDOW = 0x90,
/// This command makes the display enter partial mode
PARTIAL_IN = 0x91,
/// This command makes the display exit partial mode and enter normal mode
PARTIAL_OUT = 0x92,
/// After this command is issued, the chip would enter the program mode.
///
/// After the programming procedure completed, a hardware reset is necessary for leaving program mode.
///
/// The only one parameter is a check code, the command would be excuted if check code = 0xA5.
PROGRAM_MODE = 0xA0,
/// After this command is transmitted, the programming state machine would be activated.
///
/// The BUSY flag would fall to 0 until the programming is completed.
ACTIVE_PROGRAMMING = 0xA1,
/// The command is used for reading the content of OTP for checking the data of programming.
///
/// The value of (n) is depending on the amount of programmed data, tha max address = 0xFFF.
READ_OTP = 0xA2,
/// This command is set for saving power during fresh period. If the output voltage of VCOM / Source is from negative to positive or
/// from positive to negative, the power saving mechanism will be activated. The active period width is defined by the following two
/// parameters.
POWER_SAVING = 0xE3,
}
impl interface::Command for Command {
/// Returns the address of the command
fn address(self) -> u8 {
self as u8
}
/// Returns the address of the command
fn address(self) -> u8 {
self as u8
}
}
#[cfg(test)]
mod tests {
use super::*;
use interface::Command as CommandTrait;
use interface::Command as CommandTrait;
#[test]
fn command_addr() {
assert_eq!(Command::POWER_SAVING.address(), 0xE3);
assert_eq!(Command::POWER_SAVING.address(), 0xE3);
assert_eq!(Command::PANEL_SETTING.address(), 0x00);
assert_eq!(Command::PANEL_SETTING.address(), 0x00);
assert_eq!(Command::DISPLAY_REFRESH.address(), 0x12);
assert_eq!(Command::DISPLAY_REFRESH.address(), 0x12);
}
}
}
+1 -1
View File
@@ -108,4 +108,4 @@ pub(crate) const LUT_WB_QUICK: [u8; 42] =[
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
];
+8 -14
View File
@@ -62,11 +62,9 @@ use drawing::color::Color;
pub mod command;
use self::command::Command;
/// EPD4in2 driver
///
pub struct EPD4in2<SPI, CS, BUSY, DC, RST, D>
{
pub struct EPD4in2<SPI, CS, BUSY, DC, RST, D> {
/// Connection Interface
interface: ConnectionInterface<SPI, CS, BUSY, DC, RST, D>,
/// Width
@@ -77,11 +75,10 @@ pub struct EPD4in2<SPI, CS, BUSY, DC, RST, D>
color: Color,
}
impl<SPI, CS, BUSY, DataCommand, RST, Delay, SpiError> WaveshareInterface<SPI, CS, BUSY, DataCommand, RST, Delay, SpiError>
impl<SPI, CS, BUSY, DataCommand, RST, Delay, SpiError>
WaveshareInterface<SPI, CS, BUSY, DataCommand, RST, Delay, SpiError>
for EPD4in2<SPI, CS, BUSY, DataCommand, RST, Delay>
where
where
SPI: Write<u8, Error = SpiError>,
CS: OutputPin,
BUSY: InputPin,
@@ -116,7 +113,6 @@ where
let width = WIDTH as u16;
let height = HEIGHT as u16;
let color = Color::White;
let mut epd = EPD4in2 {
interface,
@@ -227,7 +223,7 @@ where
self.send_command(Command::DATA_START_TRANSMISSION_2)?;
//self.send_multiple_data(buffer)?;
for &elem in buffer.iter() {
self.send_data(elem)?;
}
@@ -243,7 +239,6 @@ where
width: u16,
height: u16,
) -> Result<(), SpiError> {
if buffer.len() as u16 != width / 8 * height {
//TODO: panic!! or sth like that
//return Err("Wrong buffersize");
@@ -279,12 +274,11 @@ where
self.send_command(Command::PARTIAL_OUT)
}
fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), SpiError>{
fn update_and_display_frame(&mut self, buffer: &[u8]) -> Result<(), SpiError> {
self.update_frame(buffer)?;
self.display_frame()
}
fn display_frame(&mut self) -> Result<(), SpiError> {
self.send_command(Command::DISPLAY_REFRESH)?;
@@ -366,8 +360,8 @@ where
}
/// Fill the look-up table for a quick display (partial refresh)
///
/// Is automatically done by [EPD4in2::display_frame_quick()](EPD4in2::display_frame_quick())
///
/// Is automatically done by [EPD4in2::display_frame_quick()](EPD4in2::display_frame_quick())
/// //TODO: make public?
#[cfg(feature = "epd4in2_fast_update")]
fn set_lut_quick(&mut self) -> Result<(), SpiError> {