Removed #[allow(non_camel_case_types)] to fix issues

This commit is contained in:
Caemor
2021-04-11 20:31:24 +02:00
parent 0567da80c0
commit ba1b90e2f3
21 changed files with 593 additions and 611 deletions
+40 -41
View File
@@ -5,117 +5,116 @@ use crate::traits;
///
/// More information can be found in the [specification](https://www.waveshare.com/w/upload/d/d8/2.7inch-e-paper-b-specification.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,
PanelSetting = 0x00,
/// Selecting internal and external power
POWER_SETTING = 0x01,
POWER_OFF = 0x02,
PowerSetting = 0x01,
PowerOff = 0x02,
/// Setting Power OFF sequence
POWER_OFF_SEQUENCE_SETTING = 0x03,
POWER_ON = 0x04,
PowerOffSequenceSetting = 0x03,
PowerOn = 0x04,
/// This command enables the internal bandgap, which will be cleared by the next POF.
POWER_ON_MEASURE = 0x05,
PowerOnMeasure = 0x05,
/// Starting data transmission
///
/// ```ignore
/// self.send_data(&[0x07, 0x07, 0x17])?;
/// ```
BOOSTER_SOFT_START = 0x06,
BoosterSoftStart = 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,
DeepSleep = 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.
DATA_START_TRANSMISSION_1 = 0x10,
DataStartTransmission1 = 0x10,
/// Stopping data transmission
DATA_STOP = 0x11,
DataStop = 0x11,
/// After this command is issued, driver will refresh display (data/VCOM) according to SRAM data and LUT.
DISPLAY_REFRESH = 0x12,
DisplayRefresh = 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,
DataStartTransmission2 = 0x13,
/// The command define as follows: The register is indicates that user start to transmit data, then write to SRAM. While data transmission
/// complete, user must send command DSP (Data transmission Stop). Then 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.
PARTIAL_DATA_START_TRANSMISSION_1 = 0x14,
PartialDataStartTransmission1 = 0x14,
/// The command define as follows: The register is indicates that user start to transmit data, then write to SRAM. While data transmission
/// complete, user must send command DSP (Data transmission Stop). Then 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.
PARTIAL_DATA_START_TRANSMISSION_2 = 0x15,
PartialDataStartTransmission2 = 0x15,
/// While user sent this command, driver will refresh display (data/VCOM) base on SRAM data and LUT.
///
/// Only the area (X,Y, W, L) would update, the others pixel output would follow VCOM LUT
PARTIAL_DISPLAY_REFRESH = 0x16,
PartialDisplayRefresh = 0x16,
/// This command builds the Look-up table for VCOM
LUT_FOR_VCOM = 0x20,
LUT_WHITE_TO_WHITE = 0x21,
LUT_BLACK_TO_WHITE = 0x22,
LUT_WHITE_TO_BLACK = 0x23,
LUT_BLACK_TO_BLACK = 0x24,
LutForVcom = 0x20,
LutWhiteToWhite = 0x21,
LutBlackToWhite = 0x22,
LutWhiteToBlack = 0x23,
LutBlackToBlack = 0x24,
/// The command controls the PLL clock frequency.
PLL_CONTROL = 0x30,
PllControl = 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,
TemperatureSensorCommand = 0x40,
/// This command selects Internal or External temperature sensor.
TEMPERATURE_SENSOR_CALIBRATION = 0x41,
TemperatureSensorCalibration = 0x41,
/// Write External Temperature Sensor
TEMPERATURE_SENSOR_WRITE = 0x42,
TemperatureSensorWrite = 0x42,
/// Read External Temperature Sensor
///
/// Doesn't work! Waveshare doesn't connect the read pin
TEMPERATURE_SENSOR_READ = 0x43,
TemperatureSensorRead = 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,
VcomAndDataIntervalSetting = 0x50,
/// This command indicates the input power condition. Host can read this flag to learn the battery condition.
LOW_POWER_DETECTION = 0x51,
LowPowerDetection = 0x51,
/// This command defines non-overlap period of Gate and Source.
TCON_SETTING = 0x60,
TconSetting = 0x60,
/// This command defines alternative resolution and this setting is of higher priority than the RES\[1:0\] in R00H (PSR).
RESOLUTION_SETTING = 0x61,
SOURCE_AND_GATE_SETTING = 0x62,
ResolutionSetting = 0x61,
SourceAndGateSetting = 0x62,
/// This command reads the IC status.
///
/// Doesn't work! Waveshare doesn't connect the read pin
GET_STATUS = 0x71,
GetStatus = 0x71,
/// Automatically measure VCOM. This command reads the IC status
AUTO_MEASUREMENT_VCOM = 0x80,
AutoMeasurementVcom = 0x80,
/// This command gets the VCOM value
///
/// Doesn't work! Waveshare doesn't connect the read pin
READ_VCOM_VALUE = 0x81,
ReadVcomValue = 0x81,
/// This command sets VCOM_DC value.
VCM_DC_SETTING = 0x82,
VcmDcSetting = 0x82,
/// 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,
ProgramMode = 0xA0,
/// After this command is issued, the chip would enter the program mode.
ACTIVE_PROGRAMMING = 0xA1,
ActiveProgramming = 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,
ReadOtp = 0xA2,
/// Not shown in commands table, but used in init sequence
POWER_OPTIMIZATION = 0xf8,
PowerOptimization = 0xf8,
}
impl traits::Command for Command {
@@ -132,7 +131,7 @@ mod tests {
#[test]
fn command_addr() {
assert_eq!(Command::PANEL_SETTING.address(), 0x00);
assert_eq!(Command::DISPLAY_REFRESH.address(), 0x12);
assert_eq!(Command::PanelSetting.address(), 0x00);
assert_eq!(Command::DisplayRefresh.address(), 0x12);
}
}
+39 -39
View File
@@ -60,51 +60,51 @@ where
self.interface.reset(delay, 2);
// power on
self.command(spi, Command::POWER_ON)?;
self.command(spi, Command::PowerOn)?;
delay.delay_ms(5);
self.wait_until_idle();
// set panel settings, 0xbf is bw, 0xaf is multi-color
self.interface
.cmd_with_data(spi, Command::PANEL_SETTING, &[0xaf])?;
.cmd_with_data(spi, Command::PanelSetting, &[0xaf])?;
// pll control
self.interface
.cmd_with_data(spi, Command::PLL_CONTROL, &[0x3a])?;
.cmd_with_data(spi, Command::PllControl, &[0x3a])?;
// set the power settings
self.interface.cmd_with_data(
spi,
Command::POWER_SETTING,
Command::PowerSetting,
&[0x03, 0x00, 0x2b, 0x2b, 0x09],
)?;
// start the booster
self.interface
.cmd_with_data(spi, Command::BOOSTER_SOFT_START, &[0x07, 0x07, 0x17])?;
.cmd_with_data(spi, Command::BoosterSoftStart, &[0x07, 0x07, 0x17])?;
// power optimization
self.interface
.cmd_with_data(spi, Command::POWER_OPTIMIZATION, &[0x60, 0xa5])?;
.cmd_with_data(spi, Command::PowerOptimization, &[0x60, 0xa5])?;
self.interface
.cmd_with_data(spi, Command::POWER_OPTIMIZATION, &[0x89, 0xa5])?;
.cmd_with_data(spi, Command::PowerOptimization, &[0x89, 0xa5])?;
self.interface
.cmd_with_data(spi, Command::POWER_OPTIMIZATION, &[0x90, 0x00])?;
.cmd_with_data(spi, Command::PowerOptimization, &[0x90, 0x00])?;
self.interface
.cmd_with_data(spi, Command::POWER_OPTIMIZATION, &[0x93, 0x2a])?;
.cmd_with_data(spi, Command::PowerOptimization, &[0x93, 0x2a])?;
self.interface
.cmd_with_data(spi, Command::POWER_OPTIMIZATION, &[0x73, 0x41])?;
.cmd_with_data(spi, Command::PowerOptimization, &[0x73, 0x41])?;
self.interface
.cmd_with_data(spi, Command::VCM_DC_SETTING, &[0x12])?;
.cmd_with_data(spi, Command::VcmDcSetting, &[0x12])?;
self.interface
.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x87])?;
.cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0x87])?;
self.set_lut(spi, None)?;
self.interface
.cmd_with_data(spi, Command::PARTIAL_DISPLAY_REFRESH, &[0x00])?;
.cmd_with_data(spi, Command::PartialDisplayRefresh, &[0x00])?;
self.wait_until_idle();
Ok(())
@@ -150,27 +150,27 @@ where
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0xf7])?;
.cmd_with_data(spi, Command::VcomAndDataIntervalSetting, &[0xf7])?;
self.command(spi, Command::POWER_OFF)?;
self.command(spi, Command::PowerOff)?;
self.wait_until_idle();
self.interface
.cmd_with_data(spi, Command::DEEP_SLEEP, &[0xA5])?;
.cmd_with_data(spi, Command::DeepSleep, &[0xA5])?;
Ok(())
}
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.interface
.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
.cmd(spi, Command::DataStartTransmission1)?;
self.send_buffer_helper(spi, buffer)?;
// Clear chromatic layer since we won't be using it here
self.interface
.cmd(spi, Command::DATA_START_TRANSMISSION_2)?;
.cmd(spi, Command::DataStartTransmission2)?;
self.interface
.data_x_times(spi, !self.color.get_byte_value(), WIDTH * HEIGHT / 8)?;
self.interface.cmd(spi, Command::DATA_STOP)?;
self.interface.cmd(spi, Command::DataStop)?;
Ok(())
}
@@ -184,7 +184,7 @@ where
height: u32,
) -> Result<(), SPI::Error> {
self.interface
.cmd(spi, Command::PARTIAL_DATA_START_TRANSMISSION_1)?;
.cmd(spi, Command::PartialDataStartTransmission1)?;
self.send_data(spi, &[(x >> 8) as u8])?;
self.send_data(spi, &[(x & 0xf8) as u8])?;
@@ -198,18 +198,18 @@ where
self.send_buffer_helper(spi, buffer)?;
self.interface.cmd(spi, Command::DATA_STOP)
self.interface.cmd(spi, Command::DataStop)
}
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
self.command(spi, Command::DISPLAY_REFRESH)?;
self.command(spi, Command::DisplayRefresh)?;
self.wait_until_idle();
Ok(())
}
fn update_and_display_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
self.update_frame(spi, buffer)?;
self.command(spi, Command::DISPLAY_REFRESH)?;
self.command(spi, Command::DisplayRefresh)?;
Ok(())
}
@@ -218,17 +218,17 @@ where
let color_value = self.color.get_byte_value();
self.interface
.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
.cmd(spi, Command::DataStartTransmission1)?;
self.interface
.data_x_times(spi, color_value, WIDTH * HEIGHT / 8)?;
self.interface.cmd(spi, Command::DATA_STOP)?;
self.interface.cmd(spi, Command::DataStop)?;
self.interface
.cmd(spi, Command::DATA_START_TRANSMISSION_2)?;
.cmd(spi, Command::DataStartTransmission2)?;
self.interface
.data_x_times(spi, color_value, WIDTH * HEIGHT / 8)?;
self.interface.cmd(spi, Command::DATA_STOP)?;
self.interface.cmd(spi, Command::DataStop)?;
Ok(())
}
@@ -254,11 +254,11 @@ where
_refresh_rate: Option<RefreshLUT>,
) -> Result<(), SPI::Error> {
self.wait_until_idle();
self.cmd_with_data(spi, Command::LUT_FOR_VCOM, &LUT_VCOM_DC)?;
self.cmd_with_data(spi, Command::LUT_WHITE_TO_WHITE, &LUT_WW)?;
self.cmd_with_data(spi, Command::LUT_BLACK_TO_WHITE, &LUT_BW)?;
self.cmd_with_data(spi, Command::LUT_WHITE_TO_BLACK, &LUT_WB)?;
self.cmd_with_data(spi, Command::LUT_BLACK_TO_BLACK, &LUT_BB)?;
self.cmd_with_data(spi, Command::LutForVcom, &LUT_VCOM_DC)?;
self.cmd_with_data(spi, Command::LutWhiteToWhite, &LUT_WW)?;
self.cmd_with_data(spi, Command::LutBlackToWhite, &LUT_BW)?;
self.cmd_with_data(spi, Command::LutWhiteToBlack, &LUT_WB)?;
self.cmd_with_data(spi, Command::LutBlackToBlack, &LUT_BB)?;
Ok(())
}
@@ -295,11 +295,11 @@ where
achromatic: &[u8],
) -> Result<(), SPI::Error> {
self.interface
.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
.cmd(spi, Command::DataStartTransmission1)?;
self.send_buffer_helper(spi, achromatic)?;
self.interface.cmd(spi, Command::DATA_STOP)
self.interface.cmd(spi, Command::DataStop)
}
/// Update only chromatic data of the display.
@@ -311,11 +311,11 @@ where
chromatic: &[u8],
) -> Result<(), SPI::Error> {
self.interface
.cmd(spi, Command::DATA_START_TRANSMISSION_2)?;
.cmd(spi, Command::DataStartTransmission2)?;
self.send_buffer_helper(spi, chromatic)?;
self.interface.cmd(spi, Command::DATA_STOP)?;
self.interface.cmd(spi, Command::DataStop)?;
self.wait_until_idle();
Ok(())
@@ -369,7 +369,7 @@ where
width: u32,
height: u32,
) -> Result<(), SPI::Error> {
self.command(spi, Command::PARTIAL_DISPLAY_REFRESH)?;
self.command(spi, Command::PartialDisplayRefresh)?;
self.send_data(spi, &[(x >> 8) as u8])?;
self.send_data(spi, &[(x & 0xf8) as u8])?;
self.send_data(spi, &[(y >> 8) as u8])?;
@@ -393,7 +393,7 @@ where
height: u32,
) -> Result<(), SPI::Error> {
self.interface
.cmd(spi, Command::PARTIAL_DATA_START_TRANSMISSION_1)?;
.cmd(spi, Command::PartialDataStartTransmission1)?;
self.send_data(spi, &[(x >> 8) as u8])?;
self.send_data(spi, &[(x & 0xf8) as u8])?;
self.send_data(spi, &[(y >> 8) as u8])?;
@@ -423,7 +423,7 @@ where
height: u32,
) -> Result<(), SPI::Error> {
self.interface
.cmd(spi, Command::PARTIAL_DATA_START_TRANSMISSION_2)?;
.cmd(spi, Command::PartialDataStartTransmission2)?;
self.send_data(spi, &[(x >> 8) as u8])?;
self.send_data(spi, &[(x & 0xf8) as u8])?;
self.send_data(spi, &[(y >> 8) as u8])?;