Run cargo fmt (reverted for constants and some graphic calculations)
parent
375adf4bff
commit
e518265273
|
|
@ -1,6 +1,5 @@
|
||||||
//! B/W Color for EPDs
|
//! B/W Color for EPDs
|
||||||
|
|
||||||
|
|
||||||
/// Only for the Black/White-Displays
|
/// Only for the Black/White-Displays
|
||||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||||
pub enum Color {
|
pub enum Color {
|
||||||
|
|
@ -34,7 +33,10 @@ impl Color {
|
||||||
match val {
|
match val {
|
||||||
0 => Color::Black,
|
0 => Color::Black,
|
||||||
1 => Color::White,
|
1 => Color::White,
|
||||||
e => panic!("DisplayColor only parses 0 and 1 (Black and White) and not `{}`", e),
|
e => panic!(
|
||||||
|
"DisplayColor only parses 0 and 1 (Black and White) and not `{}`",
|
||||||
|
e
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,8 +62,6 @@ impl From<u8> for Color {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use epd1in54::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
use epd1in54::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
|
||||||
|
|
||||||
/// Full size buffer for use with the 1in54 EPD
|
/// Full size buffer for use with the 1in54 EPD
|
||||||
///
|
///
|
||||||
|
|
@ -11,23 +11,20 @@ pub struct Buffer1in54BlackWhite {
|
||||||
impl Default for Buffer1in54BlackWhite {
|
impl Default for Buffer1in54BlackWhite {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Buffer1in54BlackWhite {
|
Buffer1in54BlackWhite {
|
||||||
buffer: [
|
buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
||||||
DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
WIDTH as usize * HEIGHT as usize / 8],
|
||||||
WIDTH as usize * HEIGHT as usize / 8
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use graphics::{DisplayRotation, Display};
|
|
||||||
use embedded_graphics::coord::Coord;
|
|
||||||
use embedded_graphics::primitives::Line;
|
|
||||||
use color::Color;
|
use color::Color;
|
||||||
|
use embedded_graphics::coord::Coord;
|
||||||
use embedded_graphics::prelude::*;
|
use embedded_graphics::prelude::*;
|
||||||
|
use embedded_graphics::primitives::Line;
|
||||||
|
use graphics::{Display, DisplayRotation};
|
||||||
|
|
||||||
// test buffer length
|
// test buffer length
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -107,7 +104,6 @@ mod tests {
|
||||||
for &byte in buffer.iter().skip(1) {
|
for &byte in buffer.iter().skip(1) {
|
||||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -131,6 +127,5 @@ mod tests {
|
||||||
for &byte in buffer.iter().skip(1) {
|
for &byte in buffer.iter().skip(1) {
|
||||||
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
assert_eq!(byte, DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -45,12 +45,12 @@ use hal::{
|
||||||
|
|
||||||
use type_a::{
|
use type_a::{
|
||||||
command::Command,
|
command::Command,
|
||||||
constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE}
|
constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE},
|
||||||
};
|
};
|
||||||
|
|
||||||
use color::Color;
|
use color::Color;
|
||||||
|
|
||||||
use traits::{WaveshareDisplay, RefreshLUT};
|
use traits::{RefreshLUT, WaveshareDisplay};
|
||||||
|
|
||||||
use interface::DisplayInterface;
|
use interface::DisplayInterface;
|
||||||
|
|
||||||
|
|
@ -76,7 +76,11 @@ where
|
||||||
DC: OutputPin,
|
DC: OutputPin,
|
||||||
RST: OutputPin,
|
RST: OutputPin,
|
||||||
{
|
{
|
||||||
fn init<DELAY: DelayMs<u8>>(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
|
fn init<DELAY: DelayMs<u8>>(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
delay: &mut DELAY,
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
self.interface.reset(delay);
|
self.interface.reset(delay);
|
||||||
|
|
||||||
// 3 Databytes:
|
// 3 Databytes:
|
||||||
|
|
@ -87,7 +91,7 @@ where
|
||||||
self.interface.cmd_with_data(
|
self.interface.cmd_with_data(
|
||||||
spi,
|
spi,
|
||||||
Command::DRIVER_OUTPUT_CONTROL,
|
Command::DRIVER_OUTPUT_CONTROL,
|
||||||
&[HEIGHT as u8, (HEIGHT >> 8) as u8, 0x00]
|
&[HEIGHT as u8, (HEIGHT >> 8) as u8, 0x00],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 3 Databytes: (and default values from datasheet and arduino)
|
// 3 Databytes: (and default values from datasheet and arduino)
|
||||||
|
|
@ -95,24 +99,31 @@ where
|
||||||
// 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.cmd_with_data(spi, Command::BOOSTER_SOFT_START_CONTROL, &[0xD7, 0xD6, 0x9D])?;
|
self.interface.cmd_with_data(
|
||||||
|
spi,
|
||||||
|
Command::BOOSTER_SOFT_START_CONTROL,
|
||||||
|
&[0xD7, 0xD6, 0x9D],
|
||||||
|
)?;
|
||||||
|
|
||||||
// One Databyte with value 0xA8 for 7V VCOM
|
// One Databyte with value 0xA8 for 7V VCOM
|
||||||
self.interface.cmd_with_data(spi, Command::WRITE_VCOM_REGISTER, &[0xA8])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, 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.cmd_with_data(spi, Command::SET_DUMMY_LINE_PERIOD, &[0x1A])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, 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.cmd_with_data(spi, Command::SET_GATE_LINE_WIDTH, &[0x08])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, 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.cmd_with_data(spi, Command::DATA_ENTRY_MODE_SETTING, &[0x03])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::DATA_ENTRY_MODE_SETTING, &[0x03])?;
|
||||||
|
|
||||||
self.set_lut(spi, None)
|
self.set_lut(spi, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<SPI, CS, BUSY, DC, RST, E> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
|
impl<SPI, CS, BUSY, DC, RST, E> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
|
||||||
|
|
@ -133,14 +144,19 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new<DELAY: DelayMs<u8>>(
|
fn new<DELAY: DelayMs<u8>>(
|
||||||
spi: &mut SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: &mut DELAY,
|
spi: &mut SPI,
|
||||||
|
cs: CS,
|
||||||
|
busy: BUSY,
|
||||||
|
dc: DC,
|
||||||
|
rst: RST,
|
||||||
|
delay: &mut DELAY,
|
||||||
) -> Result<Self, SPI::Error> {
|
) -> Result<Self, SPI::Error> {
|
||||||
let interface = DisplayInterface::new(cs, busy, dc, rst);
|
let interface = DisplayInterface::new(cs, busy, dc, rst);
|
||||||
|
|
||||||
let mut epd = EPD1in54 {
|
let mut epd = EPD1in54 {
|
||||||
interface,
|
interface,
|
||||||
background_color: DEFAULT_BACKGROUND_COLOR,
|
background_color: DEFAULT_BACKGROUND_COLOR,
|
||||||
refresh: RefreshLUT::FULL
|
refresh: RefreshLUT::FULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
epd.init(spi, delay)?;
|
epd.init(spi, delay)?;
|
||||||
|
|
@ -148,16 +164,19 @@ where
|
||||||
Ok(epd)
|
Ok(epd)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wake_up<DELAY: DelayMs<u8>>(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
|
fn wake_up<DELAY: DelayMs<u8>>(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
delay: &mut DELAY,
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
self.init(spi, delay)
|
self.init(spi, delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||||
// 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.cmd_with_data(spi, Command::DEEP_SLEEP_MODE, &[0x00])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::DEEP_SLEEP_MODE, &[0x00])?;
|
||||||
|
|
||||||
self.wait_until_idle();
|
self.wait_until_idle();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -165,7 +184,8 @@ where
|
||||||
|
|
||||||
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
||||||
self.use_full_frame(spi)?;
|
self.use_full_frame(spi)?;
|
||||||
self.interface.cmd_with_data(spi, Command::WRITE_RAM, buffer)
|
self.interface
|
||||||
|
.cmd_with_data(spi, 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
|
||||||
|
|
@ -181,13 +201,15 @@ where
|
||||||
self.set_ram_area(spi, x, y, x + width, y + height)?;
|
self.set_ram_area(spi, x, y, x + width, y + height)?;
|
||||||
self.set_ram_counter(spi, x, y)?;
|
self.set_ram_counter(spi, x, y)?;
|
||||||
|
|
||||||
self.interface.cmd_with_data(spi, Command::WRITE_RAM, buffer)
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::WRITE_RAM, buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||||
// 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.cmd_with_data(spi, Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?;
|
||||||
|
|
||||||
self.interface.cmd(spi, Command::MASTER_ACTIVATION)?;
|
self.interface.cmd(spi, 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
|
||||||
|
|
@ -202,34 +224,29 @@ where
|
||||||
let color = self.background_color.get_byte_value();
|
let color = self.background_color.get_byte_value();
|
||||||
|
|
||||||
//TODO: this is using a big buffer atm, is it better to just loop over sending a single byte?
|
//TODO: this is using a big buffer atm, is it better to just loop over sending a single byte?
|
||||||
self.interface.cmd(
|
self.interface.cmd(spi, Command::WRITE_RAM)?;
|
||||||
spi,
|
|
||||||
Command::WRITE_RAM
|
|
||||||
)?;
|
|
||||||
self.interface.data_x_times(spi, color, WIDTH / 8 * HEIGHT)
|
self.interface.data_x_times(spi, color, WIDTH / 8 * HEIGHT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn set_background_color(&mut self, background_color: Color) {
|
fn set_background_color(&mut self, background_color: Color) {
|
||||||
self.background_color = background_color;
|
self.background_color = background_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn background_color(&self) -> &Color {
|
fn background_color(&self) -> &Color {
|
||||||
&self.background_color
|
&self.background_color
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option<RefreshLUT>) -> Result<(), SPI::Error> {
|
fn set_lut(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
refresh_rate: Option<RefreshLUT>,
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
if let Some(refresh_lut) = refresh_rate {
|
if let Some(refresh_lut) = refresh_rate {
|
||||||
self.refresh = refresh_lut;
|
self.refresh = refresh_lut;
|
||||||
}
|
}
|
||||||
match self.refresh {
|
match self.refresh {
|
||||||
RefreshLUT::FULL => {
|
RefreshLUT::FULL => self.set_lut_helper(spi, &LUT_FULL_UPDATE),
|
||||||
self.set_lut_helper(spi, &LUT_FULL_UPDATE)
|
RefreshLUT::QUICK => self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE),
|
||||||
},
|
|
||||||
RefreshLUT::QUICK => {
|
|
||||||
self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -240,7 +257,7 @@ where
|
||||||
CS: OutputPin,
|
CS: OutputPin,
|
||||||
BUSY: InputPin,
|
BUSY: InputPin,
|
||||||
DC: OutputPin,
|
DC: OutputPin,
|
||||||
RST: OutputPin
|
RST: OutputPin,
|
||||||
{
|
{
|
||||||
fn wait_until_idle(&mut self) {
|
fn wait_until_idle(&mut self) {
|
||||||
self.interface.wait_until_idle(false);
|
self.interface.wait_until_idle(false);
|
||||||
|
|
@ -270,30 +287,39 @@ where
|
||||||
self.interface.cmd_with_data(
|
self.interface.cmd_with_data(
|
||||||
spi,
|
spi,
|
||||||
Command::SET_RAM_X_ADDRESS_START_END_POSITION,
|
Command::SET_RAM_X_ADDRESS_START_END_POSITION,
|
||||||
&[(start_x >> 3) as u8, (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.cmd_with_data(
|
self.interface.cmd_with_data(
|
||||||
spi,
|
spi,
|
||||||
Command::SET_RAM_Y_ADDRESS_START_END_POSITION,
|
Command::SET_RAM_Y_ADDRESS_START_END_POSITION,
|
||||||
&[start_y as u8, (start_y >> 8) as u8, end_y as u8, (end_y >> 8) as u8]
|
&[
|
||||||
|
start_y as u8,
|
||||||
|
(start_y >> 8) as u8,
|
||||||
|
end_y as u8,
|
||||||
|
(end_y >> 8) as u8,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), SPI::Error> {
|
pub(crate) fn set_ram_counter(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
x: u32,
|
||||||
|
y: u32,
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
// 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.cmd_with_data(spi, Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, 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.cmd_with_data(
|
self.interface.cmd_with_data(
|
||||||
spi,
|
spi,
|
||||||
Command::SET_RAM_Y_ADDRESS_COUNTER,
|
Command::SET_RAM_Y_ADDRESS_COUNTER,
|
||||||
&[
|
&[y as u8, (y >> 8) as u8],
|
||||||
y as u8,
|
)?;
|
||||||
(y >> 8) as u8
|
|
||||||
])?;
|
|
||||||
|
|
||||||
self.wait_until_idle();
|
self.wait_until_idle();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -301,7 +327,8 @@ where
|
||||||
|
|
||||||
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
||||||
assert!(buffer.len() == 30);
|
assert!(buffer.len() == 30);
|
||||||
self.interface.cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer)
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use epd2in9::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
use epd2in9::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
|
||||||
|
|
||||||
/// Full size buffer for use with the 2in9 EPD
|
/// Full size buffer for use with the 2in9 EPD
|
||||||
///
|
///
|
||||||
|
|
@ -11,15 +11,12 @@ pub struct Buffer2in9 {
|
||||||
impl Default for Buffer2in9 {
|
impl Default for Buffer2in9 {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Buffer2in9 {
|
Buffer2in9 {
|
||||||
buffer: [
|
buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
||||||
DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
WIDTH as usize * HEIGHT as usize / 8],
|
||||||
WIDTH as usize * HEIGHT as usize / 8
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ use hal::{
|
||||||
|
|
||||||
use type_a::{
|
use type_a::{
|
||||||
command::Command,
|
command::Command,
|
||||||
constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE}
|
constants::{LUT_FULL_UPDATE, LUT_PARTIAL_UPDATE},
|
||||||
};
|
};
|
||||||
|
|
||||||
use color::Color;
|
use color::Color;
|
||||||
|
|
@ -77,7 +77,11 @@ where
|
||||||
DC: OutputPin,
|
DC: OutputPin,
|
||||||
RST: OutputPin,
|
RST: OutputPin,
|
||||||
{
|
{
|
||||||
fn init<DELAY: DelayMs<u8>>(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
|
fn init<DELAY: DelayMs<u8>>(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
delay: &mut DELAY,
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
self.interface.reset(delay);
|
self.interface.reset(delay);
|
||||||
|
|
||||||
// 3 Databytes:
|
// 3 Databytes:
|
||||||
|
|
@ -85,34 +89,42 @@ 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.cmd_with_data(spi, Command::DRIVER_OUTPUT_CONTROL, &[0x27, 0x01, 0x00])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::DRIVER_OUTPUT_CONTROL, &[0x27, 0x01, 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.cmd_with_data(spi, Command::BOOSTER_SOFT_START_CONTROL, &[0xD7, 0xD6, 0x9D])?;
|
self.interface.cmd_with_data(
|
||||||
|
spi,
|
||||||
|
Command::BOOSTER_SOFT_START_CONTROL,
|
||||||
|
&[0xD7, 0xD6, 0x9D],
|
||||||
|
)?;
|
||||||
|
|
||||||
// One Databyte with value 0xA8 for 7V VCOM
|
// One Databyte with value 0xA8 for 7V VCOM
|
||||||
self.interface.cmd_with_data(spi, Command::WRITE_VCOM_REGISTER, &[0xA8])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, 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.cmd_with_data(spi, Command::SET_DUMMY_LINE_PERIOD, &[0x1A])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, 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.cmd_with_data(spi, Command::SET_GATE_LINE_WIDTH, &[0x08])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, 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.cmd_with_data(spi, Command::DATA_ENTRY_MODE_SETTING, &[0x03])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::DATA_ENTRY_MODE_SETTING, &[0x03])?;
|
||||||
|
|
||||||
self.set_lut(spi, None)
|
self.set_lut(spi, None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<SPI, CS, BUSY, DC, RST>
|
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
|
||||||
WaveshareDisplay<SPI, CS, BUSY, DC, RST>
|
|
||||||
for EPD2in9<SPI, CS, BUSY, DC, RST>
|
for EPD2in9<SPI, CS, BUSY, DC, RST>
|
||||||
where
|
where
|
||||||
SPI: Write<u8>,
|
SPI: Write<u8>,
|
||||||
|
|
@ -130,7 +142,12 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new<DELAY: DelayMs<u8>>(
|
fn new<DELAY: DelayMs<u8>>(
|
||||||
spi: &mut SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: &mut DELAY,
|
spi: &mut SPI,
|
||||||
|
cs: CS,
|
||||||
|
busy: BUSY,
|
||||||
|
dc: DC,
|
||||||
|
rst: RST,
|
||||||
|
delay: &mut DELAY,
|
||||||
) -> Result<Self, SPI::Error> {
|
) -> Result<Self, SPI::Error> {
|
||||||
let interface = DisplayInterface::new(cs, busy, dc, rst);
|
let interface = DisplayInterface::new(cs, busy, dc, rst);
|
||||||
|
|
||||||
|
|
@ -145,25 +162,29 @@ where
|
||||||
Ok(epd)
|
Ok(epd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||||
// 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.cmd_with_data(spi, Command::DEEP_SLEEP_MODE, &[0x00])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::DEEP_SLEEP_MODE, &[0x00])?;
|
||||||
|
|
||||||
self.wait_until_idle();
|
self.wait_until_idle();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wake_up<DELAY: DelayMs<u8>>(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
|
fn wake_up<DELAY: DelayMs<u8>>(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
delay: &mut DELAY,
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
self.init(spi, delay)
|
self.init(spi, delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
||||||
self.use_full_frame(spi)?;
|
self.use_full_frame(spi)?;
|
||||||
|
|
||||||
self.interface.cmd_with_data(spi, Command::WRITE_RAM, buffer)
|
self.interface
|
||||||
|
.cmd_with_data(spi, 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
|
||||||
|
|
@ -179,13 +200,15 @@ where
|
||||||
self.set_ram_area(spi, x, y, x + width, y + height)?;
|
self.set_ram_area(spi, x, y, x + width, y + height)?;
|
||||||
self.set_ram_counter(spi, x, y)?;
|
self.set_ram_counter(spi, x, y)?;
|
||||||
|
|
||||||
self.interface.cmd_with_data(spi, Command::WRITE_RAM, buffer)
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::WRITE_RAM, buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||||
// 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.cmd_with_data(spi, Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::DISPLAY_UPDATE_CONTROL_2, &[0xC4])?;
|
||||||
|
|
||||||
self.interface.cmd(spi, Command::MASTER_ACTIVATION)?;
|
self.interface.cmd(spi, 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
|
||||||
|
|
@ -212,17 +235,17 @@ where
|
||||||
&self.background_color
|
&self.background_color
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option<RefreshLUT>) -> Result<(), SPI::Error> {
|
fn set_lut(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
refresh_rate: Option<RefreshLUT>,
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
if let Some(refresh_lut) = refresh_rate {
|
if let Some(refresh_lut) = refresh_rate {
|
||||||
self.refresh = refresh_lut;
|
self.refresh = refresh_lut;
|
||||||
}
|
}
|
||||||
match self.refresh {
|
match self.refresh {
|
||||||
RefreshLUT::FULL => {
|
RefreshLUT::FULL => self.set_lut_helper(spi, &LUT_FULL_UPDATE),
|
||||||
self.set_lut_helper(spi, &LUT_FULL_UPDATE)
|
RefreshLUT::QUICK => self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE),
|
||||||
},
|
|
||||||
RefreshLUT::QUICK => {
|
|
||||||
self.set_lut_helper(spi, &LUT_PARTIAL_UPDATE)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -263,22 +286,34 @@ where
|
||||||
self.interface.cmd_with_data(
|
self.interface.cmd_with_data(
|
||||||
spi,
|
spi,
|
||||||
Command::SET_RAM_X_ADDRESS_START_END_POSITION,
|
Command::SET_RAM_X_ADDRESS_START_END_POSITION,
|
||||||
&[(start_x >> 3) as u8, (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.cmd_with_data(spi, Command::SET_RAM_Y_ADDRESS_START_END_POSITION,
|
self.interface.cmd_with_data(
|
||||||
&[start_y as u8, (start_y >> 8) as u8, end_y as u8, (end_y >> 8) as u8]
|
spi,
|
||||||
|
Command::SET_RAM_Y_ADDRESS_START_END_POSITION,
|
||||||
|
&[
|
||||||
|
start_y as u8,
|
||||||
|
(start_y >> 8) as u8,
|
||||||
|
end_y as u8,
|
||||||
|
(end_y >> 8) as u8,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), SPI::Error> {
|
fn set_ram_counter(&mut self, spi: &mut SPI, x: u32, y: u32) -> Result<(), SPI::Error> {
|
||||||
// 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.cmd_with_data(spi, Command::SET_RAM_X_ADDRESS_COUNTER, &[(x >> 3) as u8])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, 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.cmd_with_data(spi, Command::SET_RAM_Y_ADDRESS_COUNTER, &[y as u8, (y >> 8) as u8])?;
|
self.interface.cmd_with_data(
|
||||||
|
spi,
|
||||||
|
Command::SET_RAM_Y_ADDRESS_COUNTER,
|
||||||
|
&[y as u8, (y >> 8) as u8],
|
||||||
|
)?;
|
||||||
|
|
||||||
self.wait_until_idle();
|
self.wait_until_idle();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -286,11 +321,11 @@ where
|
||||||
|
|
||||||
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
fn set_lut_helper(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
||||||
assert!(buffer.len() == 30);
|
assert!(buffer.len() == 30);
|
||||||
self.interface.cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer)
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::WRITE_LUT_REGISTER, buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ pub const WIDTH: u32 = 400;
|
||||||
pub const HEIGHT: u32 = 300;
|
pub const HEIGHT: u32 = 300;
|
||||||
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::White;
|
||||||
|
|
||||||
|
|
||||||
pub(crate) const LUT_VCOM0: [u8; 44] = [
|
pub(crate) const LUT_VCOM0: [u8; 44] = [
|
||||||
0x00, 0x17, 0x00, 0x00, 0x00, 0x02,
|
0x00, 0x17, 0x00, 0x00, 0x00, 0x02,
|
||||||
0x00, 0x17, 0x17, 0x00, 0x00, 0x02,
|
0x00, 0x17, 0x17, 0x00, 0x00, 0x02,
|
||||||
|
|
@ -15,7 +14,6 @@ pub(crate) const LUT_VCOM0: [u8; 44] = [
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
pub(crate) const LUT_VCOM0_QUICK: [u8; 44] = [
|
pub(crate) const LUT_VCOM0_QUICK: [u8; 44] = [
|
||||||
0x00, 0x0E, 0x00, 0x00, 0x00, 0x01,
|
0x00, 0x0E, 0x00, 0x00, 0x00, 0x01,
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, WIDTH, HEIGHT};
|
use epd4in2::constants::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
|
||||||
|
|
||||||
/// Full size buffer for use with the 4in2 EPD
|
/// Full size buffer for use with the 4in2 EPD
|
||||||
///
|
///
|
||||||
|
|
@ -11,24 +11,21 @@ pub struct Buffer4in2 {
|
||||||
impl Default for Buffer4in2 {
|
impl Default for Buffer4in2 {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Buffer4in2 {
|
Buffer4in2 {
|
||||||
buffer: [
|
buffer: [DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
||||||
DEFAULT_BACKGROUND_COLOR.get_byte_value();
|
WIDTH as usize * HEIGHT as usize / 8],
|
||||||
WIDTH as usize * HEIGHT as usize / 8
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use epd4in2;
|
|
||||||
use graphics::{DisplayRotation, Display};
|
|
||||||
use embedded_graphics::coord::Coord;
|
|
||||||
use embedded_graphics::primitives::Line;
|
|
||||||
use color::Color;
|
use color::Color;
|
||||||
|
use embedded_graphics::coord::Coord;
|
||||||
use embedded_graphics::prelude::*;
|
use embedded_graphics::prelude::*;
|
||||||
|
use embedded_graphics::primitives::Line;
|
||||||
|
use epd4in2;
|
||||||
|
use graphics::{Display, DisplayRotation};
|
||||||
|
|
||||||
// test buffer length
|
// test buffer length
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -45,7 +42,10 @@ mod tests {
|
||||||
let display = Display::new(WIDTH, HEIGHT, &mut display4in2.buffer);
|
let display = Display::new(WIDTH, HEIGHT, &mut display4in2.buffer);
|
||||||
use epd4in2;
|
use epd4in2;
|
||||||
for &byte in display.buffer() {
|
for &byte in display.buffer() {
|
||||||
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
assert_eq!(
|
||||||
|
byte,
|
||||||
|
epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +64,10 @@ mod tests {
|
||||||
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
||||||
|
|
||||||
for &byte in buffer.iter().skip(1) {
|
for &byte in buffer.iter().skip(1) {
|
||||||
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
assert_eq!(
|
||||||
|
byte,
|
||||||
|
epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,7 +87,10 @@ mod tests {
|
||||||
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
||||||
|
|
||||||
for &byte in buffer.iter().skip(1) {
|
for &byte in buffer.iter().skip(1) {
|
||||||
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
assert_eq!(
|
||||||
|
byte,
|
||||||
|
epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,9 +113,11 @@ mod tests {
|
||||||
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
||||||
|
|
||||||
for &byte in buffer.iter().skip(1) {
|
for &byte in buffer.iter().skip(1) {
|
||||||
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
assert_eq!(
|
||||||
|
byte,
|
||||||
|
epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -131,9 +139,10 @@ mod tests {
|
||||||
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
assert_eq!(buffer[0], Color::Black.get_byte_value());
|
||||||
|
|
||||||
for &byte in buffer.iter().skip(1) {
|
for &byte in buffer.iter().skip(1) {
|
||||||
assert_eq!(byte, epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value());
|
assert_eq!(
|
||||||
|
byte,
|
||||||
|
epd4in2::constants::DEFAULT_BACKGROUND_COLOR.get_byte_value()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ use hal::{
|
||||||
digital::*,
|
digital::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
use traits::{WaveshareDisplay, InternalWiAdditions, RefreshLUT};
|
|
||||||
use interface::DisplayInterface;
|
use interface::DisplayInterface;
|
||||||
|
use traits::{InternalWiAdditions, RefreshLUT, WaveshareDisplay};
|
||||||
|
|
||||||
//The Lookup Tables for the Display
|
//The Lookup Tables for the Display
|
||||||
mod constants; //TODO: Limit to crate::drawing
|
mod constants; //TODO: Limit to crate::drawing
|
||||||
|
|
@ -66,7 +66,6 @@ use self::command::Command;
|
||||||
mod graphics;
|
mod graphics;
|
||||||
pub use self::graphics::Buffer4in2;
|
pub use self::graphics::Buffer4in2;
|
||||||
|
|
||||||
|
|
||||||
/// EPD4in2 driver
|
/// EPD4in2 driver
|
||||||
///
|
///
|
||||||
pub struct EPD4in2<SPI, CS, BUSY, DC, RST> {
|
pub struct EPD4in2<SPI, CS, BUSY, DC, RST> {
|
||||||
|
|
@ -78,11 +77,7 @@ pub struct EPD4in2<SPI, CS, BUSY, DC, RST> {
|
||||||
refresh: RefreshLUT,
|
refresh: RefreshLUT,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<SPI, CS, BUSY, DC, RST> InternalWiAdditions<SPI, CS, BUSY, DC, RST>
|
||||||
|
|
||||||
|
|
||||||
impl<SPI, CS, BUSY, DC, RST>
|
|
||||||
InternalWiAdditions<SPI, CS, BUSY, DC, RST>
|
|
||||||
for EPD4in2<SPI, CS, BUSY, DC, RST>
|
for EPD4in2<SPI, CS, BUSY, DC, RST>
|
||||||
where
|
where
|
||||||
SPI: Write<u8>,
|
SPI: Write<u8>,
|
||||||
|
|
@ -91,15 +86,24 @@ where
|
||||||
DC: OutputPin,
|
DC: OutputPin,
|
||||||
RST: OutputPin,
|
RST: OutputPin,
|
||||||
{
|
{
|
||||||
fn init<DELAY: DelayMs<u8>>(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
|
fn init<DELAY: DelayMs<u8>>(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
delay: &mut DELAY,
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
// reset the device
|
// reset the device
|
||||||
self.interface.reset(delay);
|
self.interface.reset(delay);
|
||||||
|
|
||||||
// set the power settings
|
// set the power settings
|
||||||
self.interface.cmd_with_data(spi, Command::POWER_SETTING, &[0x03, 0x00, 0x2b, 0x2b, 0xff])?;
|
self.interface.cmd_with_data(
|
||||||
|
spi,
|
||||||
|
Command::POWER_SETTING,
|
||||||
|
&[0x03, 0x00, 0x2b, 0x2b, 0xff],
|
||||||
|
)?;
|
||||||
|
|
||||||
// start the booster
|
// start the booster
|
||||||
self.interface.cmd_with_data(spi, Command::BOOSTER_SOFT_START, &[0x17, 0x17, 0x17])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::BOOSTER_SOFT_START, &[0x17, 0x17, 0x17])?;
|
||||||
|
|
||||||
// power on
|
// power on
|
||||||
self.command(spi, Command::POWER_ON)?;
|
self.command(spi, Command::POWER_ON)?;
|
||||||
|
|
@ -121,8 +125,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<SPI, CS, BUSY, DC, RST>
|
impl<SPI, CS, BUSY, DC, RST> WaveshareDisplay<SPI, CS, BUSY, DC, RST>
|
||||||
WaveshareDisplay<SPI, CS, BUSY, DC, RST>
|
|
||||||
for EPD4in2<SPI, CS, BUSY, DC, RST>
|
for EPD4in2<SPI, CS, BUSY, DC, RST>
|
||||||
where
|
where
|
||||||
SPI: Write<u8>,
|
SPI: Write<u8>,
|
||||||
|
|
@ -146,14 +149,21 @@ where
|
||||||
///
|
///
|
||||||
/// epd4in2.sleep();
|
/// epd4in2.sleep();
|
||||||
/// ```
|
/// ```
|
||||||
fn new<DELAY: DelayMs<u8>>(spi: &mut SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: &mut DELAY) -> Result<Self, SPI::Error> {
|
fn new<DELAY: DelayMs<u8>>(
|
||||||
|
spi: &mut SPI,
|
||||||
|
cs: CS,
|
||||||
|
busy: BUSY,
|
||||||
|
dc: DC,
|
||||||
|
rst: RST,
|
||||||
|
delay: &mut DELAY,
|
||||||
|
) -> Result<Self, SPI::Error> {
|
||||||
let interface = DisplayInterface::new(cs, busy, dc, rst);
|
let interface = DisplayInterface::new(cs, busy, dc, rst);
|
||||||
let color = DEFAULT_BACKGROUND_COLOR;
|
let color = DEFAULT_BACKGROUND_COLOR;
|
||||||
|
|
||||||
let mut epd = EPD4in2 {
|
let mut epd = EPD4in2 {
|
||||||
interface,
|
interface,
|
||||||
color,
|
color,
|
||||||
refresh: RefreshLUT::FULL
|
refresh: RefreshLUT::FULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
epd.init(spi, delay)?;
|
epd.init(spi, delay)?;
|
||||||
|
|
@ -161,12 +171,17 @@ where
|
||||||
Ok(epd)
|
Ok(epd)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wake_up<DELAY: DelayMs<u8>>(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error> {
|
fn wake_up<DELAY: DelayMs<u8>>(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
delay: &mut DELAY,
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
self.init(spi, delay)
|
self.init(spi, delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||||
self.interface.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x17])?; //border floating
|
||||||
self.command(spi, Command::VCM_DC_SETTING)?; // VCOM to 0V
|
self.command(spi, Command::VCM_DC_SETTING)?; // VCOM to 0V
|
||||||
self.command(spi, Command::PANEL_SETTING)?;
|
self.command(spi, Command::PANEL_SETTING)?;
|
||||||
|
|
||||||
|
|
@ -177,7 +192,8 @@ where
|
||||||
|
|
||||||
self.command(spi, Command::POWER_OFF)?;
|
self.command(spi, Command::POWER_OFF)?;
|
||||||
self.wait_until_idle();
|
self.wait_until_idle();
|
||||||
self.interface.cmd_with_data(spi, Command::DEEP_SLEEP, &[0xA5])
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::DEEP_SLEEP, &[0xA5])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
fn update_frame(&mut self, spi: &mut SPI, buffer: &[u8]) -> Result<(), SPI::Error> {
|
||||||
|
|
@ -185,15 +201,20 @@ where
|
||||||
|
|
||||||
self.send_resolution(spi)?;
|
self.send_resolution(spi)?;
|
||||||
|
|
||||||
self.interface.cmd_with_data(spi, Command::VCM_DC_SETTING, &[0x12])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::VCM_DC_SETTING, &[0x12])?;
|
||||||
|
|
||||||
//VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7
|
//VBDF 17|D7 VBDW 97 VBDB 57 VBDF F7 VBDW 77 VBDB 37 VBDR B7
|
||||||
self.interface.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x97])?;
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::VCOM_AND_DATA_INTERVAL_SETTING, &[0x97])?;
|
||||||
|
|
||||||
self.interface.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
|
self.interface
|
||||||
self.interface.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?;
|
.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
|
||||||
|
self.interface
|
||||||
|
.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?;
|
||||||
|
|
||||||
self.interface.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_2, buffer)
|
self.interface
|
||||||
|
.cmd_with_data(spi, Command::DATA_START_TRANSMISSION_2, buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_partial_frame(
|
fn update_partial_frame(
|
||||||
|
|
@ -240,8 +261,6 @@ where
|
||||||
self.command(spi, Command::PARTIAL_OUT)
|
self.command(spi, Command::PARTIAL_OUT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
fn display_frame(&mut self, spi: &mut SPI) -> Result<(), SPI::Error> {
|
||||||
self.command(spi, Command::DISPLAY_REFRESH)?;
|
self.command(spi, Command::DISPLAY_REFRESH)?;
|
||||||
|
|
||||||
|
|
@ -254,14 +273,18 @@ where
|
||||||
|
|
||||||
let color_value = self.color.get_byte_value();
|
let color_value = self.color.get_byte_value();
|
||||||
|
|
||||||
self.interface.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
|
self.interface
|
||||||
self.interface.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?;
|
.cmd(spi, Command::DATA_START_TRANSMISSION_1)?;
|
||||||
|
self.interface
|
||||||
|
.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)?;
|
||||||
|
|
||||||
//TODO: Removal of delay. TEST!
|
//TODO: Removal of delay. TEST!
|
||||||
//self.delay_ms(2);
|
//self.delay_ms(2);
|
||||||
|
|
||||||
self.interface.cmd(spi, Command::DATA_START_TRANSMISSION_2)?;
|
self.interface
|
||||||
self.interface.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)
|
.cmd(spi, Command::DATA_START_TRANSMISSION_2)?;
|
||||||
|
self.interface
|
||||||
|
.data_x_times(spi, color_value, WIDTH / 8 * HEIGHT)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_background_color(&mut self, color: Color) {
|
fn set_background_color(&mut self, color: Color) {
|
||||||
|
|
@ -280,24 +303,26 @@ where
|
||||||
HEIGHT
|
HEIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option<RefreshLUT>) -> Result<(), SPI::Error> {
|
fn set_lut(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
refresh_rate: Option<RefreshLUT>,
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
if let Some(refresh_lut) = refresh_rate {
|
if let Some(refresh_lut) = refresh_rate {
|
||||||
self.refresh = refresh_lut;
|
self.refresh = refresh_lut;
|
||||||
}
|
}
|
||||||
match self.refresh {
|
match self.refresh {
|
||||||
RefreshLUT::FULL => {
|
RefreshLUT::FULL => {
|
||||||
self.set_lut_helper(spi, &LUT_VCOM0, &LUT_WW, &LUT_BW, &LUT_WB, &LUT_BB)
|
self.set_lut_helper(spi, &LUT_VCOM0, &LUT_WW, &LUT_BW, &LUT_WB, &LUT_BB)
|
||||||
},
|
}
|
||||||
RefreshLUT::QUICK => {
|
RefreshLUT::QUICK => self.set_lut_helper(
|
||||||
self.set_lut_helper(
|
|
||||||
spi,
|
spi,
|
||||||
&LUT_VCOM0_QUICK,
|
&LUT_VCOM0_QUICK,
|
||||||
&LUT_WW_QUICK,
|
&LUT_WW_QUICK,
|
||||||
&LUT_BW_QUICK,
|
&LUT_BW_QUICK,
|
||||||
&LUT_WB_QUICK,
|
&LUT_WB_QUICK,
|
||||||
&LUT_BB_QUICK,
|
&LUT_BB_QUICK,
|
||||||
)
|
),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -318,7 +343,12 @@ where
|
||||||
self.interface.data(spi, data)
|
self.interface.data(spi, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cmd_with_data(&mut self, spi: &mut SPI, command: Command, data: &[u8]) -> Result<(), SPI::Error> {
|
fn cmd_with_data(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
command: Command,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
self.interface.cmd_with_data(spi, command, data)
|
self.interface.cmd_with_data(spi, command, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -347,43 +377,22 @@ where
|
||||||
lut_bb: &[u8],
|
lut_bb: &[u8],
|
||||||
) -> Result<(), SPI::Error> {
|
) -> Result<(), SPI::Error> {
|
||||||
// LUT VCOM
|
// LUT VCOM
|
||||||
self.cmd_with_data(
|
self.cmd_with_data(spi, Command::LUT_FOR_VCOM, lut_vcom)?;
|
||||||
spi,
|
|
||||||
Command::LUT_FOR_VCOM,
|
|
||||||
lut_vcom
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// LUT WHITE to WHITE
|
// LUT WHITE to WHITE
|
||||||
self.cmd_with_data(
|
self.cmd_with_data(spi, Command::LUT_WHITE_TO_WHITE, lut_ww)?;
|
||||||
spi,
|
|
||||||
Command::LUT_WHITE_TO_WHITE,
|
|
||||||
lut_ww
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// LUT BLACK to WHITE
|
// LUT BLACK to WHITE
|
||||||
self.cmd_with_data(
|
self.cmd_with_data(spi, Command::LUT_BLACK_TO_WHITE, lut_bw)?;
|
||||||
spi,
|
|
||||||
Command::LUT_BLACK_TO_WHITE,
|
|
||||||
lut_bw
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// LUT WHITE to BLACK
|
// LUT WHITE to BLACK
|
||||||
self.cmd_with_data(
|
self.cmd_with_data(spi, Command::LUT_WHITE_TO_BLACK, lut_wb)?;
|
||||||
spi,
|
|
||||||
Command::LUT_WHITE_TO_BLACK,
|
|
||||||
lut_wb,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// LUT BLACK to BLACK
|
// LUT BLACK to BLACK
|
||||||
self.cmd_with_data(
|
self.cmd_with_data(spi, Command::LUT_BLACK_TO_BLACK, lut_bb)
|
||||||
spi,
|
|
||||||
Command::LUT_BLACK_TO_BLACK,
|
|
||||||
lut_bb,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -60,14 +60,12 @@ impl<'a> Display<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<'a> Drawing<Color> for Display<'a> {
|
impl<'a> Drawing<Color> for Display<'a> {
|
||||||
fn draw<T>(&mut self, item_pixels: T)
|
fn draw<T>(&mut self, item_pixels: T)
|
||||||
where
|
where
|
||||||
T: Iterator<Item = Pixel<Color>>
|
T: Iterator<Item = Pixel<Color>>,
|
||||||
{
|
{
|
||||||
for Pixel(UnsignedCoord(x,y), color) in item_pixels {
|
for Pixel(UnsignedCoord(x, y), color) in item_pixels {
|
||||||
|
|
||||||
if outside_display(x, y, self.width, self.height, self.rotation) {
|
if outside_display(x, y, self.width, self.height, self.rotation) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -89,14 +87,13 @@ impl<'a> Drawing<Color> for Display<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn outside_display(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation) -> bool {
|
fn outside_display(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation) -> bool {
|
||||||
match rotation {
|
match rotation {
|
||||||
DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => {
|
DisplayRotation::Rotate0 | DisplayRotation::Rotate180 => {
|
||||||
if x >= width || y >= height {
|
if x >= width || y >= height {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => {
|
DisplayRotation::Rotate90 | DisplayRotation::Rotate270 => {
|
||||||
if y >= width || x >= height {
|
if y >= width || x >= height {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -127,19 +124,17 @@ fn rotation(x: u32, y: u32, width: u32, height: u32, rotation: DisplayRotation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{DisplayRotation, outside_display, rotation, Display};
|
use super::{outside_display, rotation, Display, DisplayRotation};
|
||||||
use color::Color;
|
use color::Color;
|
||||||
use embedded_graphics::coord::Coord;
|
use embedded_graphics::coord::Coord;
|
||||||
use embedded_graphics::primitives::Line;
|
|
||||||
use embedded_graphics::prelude::*;
|
use embedded_graphics::prelude::*;
|
||||||
|
use embedded_graphics::primitives::Line;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn buffer_clear() {
|
fn buffer_clear() {
|
||||||
use epd4in2::{WIDTH, HEIGHT};
|
use epd4in2::{HEIGHT, WIDTH};
|
||||||
|
|
||||||
let mut buffer = [Color::Black.get_byte_value(); WIDTH as usize / 8 * HEIGHT as usize];
|
let mut buffer = [Color::Black.get_byte_value(); WIDTH as usize / 8 * HEIGHT as usize];
|
||||||
let mut display = Display::new(WIDTH, HEIGHT, &mut buffer);
|
let mut display = Display::new(WIDTH, HEIGHT, &mut buffer);
|
||||||
|
|
@ -155,22 +150,21 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rotation_overflow() {
|
fn rotation_overflow() {
|
||||||
use epd4in2::{WIDTH, HEIGHT};
|
use epd4in2::{HEIGHT, WIDTH};
|
||||||
let width = WIDTH as u32;
|
let width = WIDTH as u32;
|
||||||
let height = HEIGHT as u32;
|
let height = HEIGHT as u32;
|
||||||
test_rotation_overflow(width, height, DisplayRotation::Rotate0);
|
test_rotation_overflow(width, height, DisplayRotation::Rotate0);
|
||||||
test_rotation_overflow(width, height, DisplayRotation::Rotate90);
|
test_rotation_overflow(width, height, DisplayRotation::Rotate90);
|
||||||
test_rotation_overflow(width, height, DisplayRotation::Rotate180);
|
test_rotation_overflow(width, height, DisplayRotation::Rotate180);
|
||||||
test_rotation_overflow(width, height, DisplayRotation::Rotate270);
|
test_rotation_overflow(width, height, DisplayRotation::Rotate270);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_rotation_overflow(width: u32, height: u32, rotation2: DisplayRotation) {
|
fn test_rotation_overflow(width: u32, height: u32, rotation2: DisplayRotation) {
|
||||||
let max_value = width / 8 * height;
|
let max_value = width / 8 * height;
|
||||||
for x in 0..(width + height) { //limit x because it runs too long
|
for x in 0..(width + height) {
|
||||||
|
//limit x because it runs too long
|
||||||
for y in 0..(u32::max_value()) {
|
for y in 0..(u32::max_value()) {
|
||||||
if outside_display(x, y, width, height, rotation2) {
|
if outside_display(x, y, width, height, rotation2) {
|
||||||
break;
|
break;
|
||||||
|
|
@ -182,11 +176,9 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn graphics_rotation_0() {
|
fn graphics_rotation_0() {
|
||||||
use epd2in9::{DEFAULT_BACKGROUND_COLOR};
|
use epd2in9::DEFAULT_BACKGROUND_COLOR;
|
||||||
let width = 128;
|
let width = 128;
|
||||||
let height = 296;
|
let height = 296;
|
||||||
|
|
||||||
|
|
@ -210,7 +202,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn graphics_rotation_90() {
|
fn graphics_rotation_90() {
|
||||||
use epd2in9::{DEFAULT_BACKGROUND_COLOR};
|
use epd2in9::DEFAULT_BACKGROUND_COLOR;
|
||||||
let width = 128;
|
let width = 128;
|
||||||
let height = 296;
|
let height = 296;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
|
use core::marker::PhantomData;
|
||||||
use hal::{
|
use hal::{
|
||||||
blocking::{delay::*, spi::Write},
|
blocking::{delay::*, spi::Write},
|
||||||
digital::*,
|
digital::*,
|
||||||
};
|
};
|
||||||
use core::marker::PhantomData;
|
|
||||||
use traits::Command;
|
use traits::Command;
|
||||||
|
|
||||||
/// The Connection Interface of all (?) Waveshare EPD-Devices
|
/// The Connection Interface of all (?) Waveshare EPD-Devices
|
||||||
|
|
@ -20,8 +20,7 @@ pub(crate) struct DisplayInterface<SPI, CS, BUSY, DC, RST> {
|
||||||
rst: RST,
|
rst: RST,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<SPI, CS, BUSY, DC, RST>
|
impl<SPI, CS, BUSY, DC, RST> DisplayInterface<SPI, CS, BUSY, DC, RST>
|
||||||
DisplayInterface<SPI, CS, BUSY, DC, RST>
|
|
||||||
where
|
where
|
||||||
SPI: Write<u8>,
|
SPI: Write<u8>,
|
||||||
CS: OutputPin,
|
CS: OutputPin,
|
||||||
|
|
@ -64,12 +63,16 @@ where
|
||||||
/// 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: directly use ::write? cs wouldn't needed to be changed twice than
|
/// TODO: directly use ::write? cs wouldn't needed to be changed twice than
|
||||||
pub(crate) fn cmd_with_data<T: Command>(&mut self, spi: &mut SPI, command: T, data: &[u8]) -> Result<(), SPI::Error> {
|
pub(crate) fn cmd_with_data<T: Command>(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
command: T,
|
||||||
|
data: &[u8],
|
||||||
|
) -> Result<(), SPI::Error> {
|
||||||
self.cmd(spi, command)?;
|
self.cmd(spi, command)?;
|
||||||
self.data(spi, data)
|
self.data(spi, 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
|
||||||
///
|
///
|
||||||
/// Enables direct interaction with the device with the help of [command()](ConnectionInterface::command())
|
/// Enables direct interaction with the device with the help of [command()](ConnectionInterface::command())
|
||||||
|
|
@ -89,8 +92,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// spi write helper/abstraction function
|
// spi write helper/abstraction function
|
||||||
fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error>
|
fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> {
|
||||||
{
|
|
||||||
// activate spi with cs low
|
// activate spi with cs low
|
||||||
self.cs.set_low();
|
self.cs.set_low();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,12 +67,11 @@ pub mod epd2in9;
|
||||||
pub(crate) mod type_a;
|
pub(crate) mod type_a;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
pub use traits::{WaveshareDisplay, RefreshLUT};
|
|
||||||
pub use color::Color;
|
pub use color::Color;
|
||||||
|
pub use traits::{RefreshLUT, WaveshareDisplay};
|
||||||
pub use SPI_MODE;
|
pub use SPI_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern crate embedded_hal as hal;
|
extern crate embedded_hal as hal;
|
||||||
use hal::spi::{Mode, Phase, Polarity};
|
use hal::spi::{Mode, Phase, Polarity};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
|
use color::Color;
|
||||||
use core::marker::Sized;
|
use core::marker::Sized;
|
||||||
use hal::{
|
use hal::{
|
||||||
blocking::{delay::*, spi::Write},
|
blocking::{delay::*, spi::Write},
|
||||||
digital::*,
|
digital::*,
|
||||||
};
|
};
|
||||||
use color::Color;
|
|
||||||
|
|
||||||
|
|
||||||
/// All commands need to have this trait which gives the address of the command
|
/// All commands need to have this trait which gives the address of the command
|
||||||
/// which needs to be send via SPI with activated CommandsPin (Data/Command Pin in CommandMode)
|
/// which needs to be send via SPI with activated CommandsPin (Data/Command Pin in CommandMode)
|
||||||
|
|
@ -18,7 +17,7 @@ pub enum RefreshLUT {
|
||||||
FULL,
|
FULL,
|
||||||
/// The quick LUT where not the full refresh sequence is followed.
|
/// The quick LUT where not the full refresh sequence is followed.
|
||||||
/// This might lead to some
|
/// This might lead to some
|
||||||
QUICK
|
QUICK,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RefreshLUT {
|
impl Default for RefreshLUT {
|
||||||
|
|
@ -45,10 +44,13 @@ where
|
||||||
/// This function calls [reset()](WaveshareInterface::reset()),
|
/// This function calls [reset()](WaveshareInterface::reset()),
|
||||||
/// so you don't need to call reset your self when trying to wake your device up
|
/// so you don't need to call reset your self when trying to wake your device up
|
||||||
/// after setting it to sleep.
|
/// after setting it to sleep.
|
||||||
fn init<DELAY: DelayMs<u8>>(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
|
fn init<DELAY: DelayMs<u8>>(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
delay: &mut DELAY,
|
||||||
|
) -> Result<(), SPI::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// All the functions to interact with the EPDs
|
/// All the functions to interact with the EPDs
|
||||||
///
|
///
|
||||||
/// This trait includes all public functions to use the EPDS
|
/// This trait includes all public functions to use the EPDS
|
||||||
|
|
@ -64,7 +66,12 @@ where
|
||||||
///
|
///
|
||||||
/// This already initialises the device. That means [init()](WaveshareInterface::init()) isn't needed directly afterwards
|
/// This already initialises the device. That means [init()](WaveshareInterface::init()) isn't needed directly afterwards
|
||||||
fn new<DELAY: DelayMs<u8>>(
|
fn new<DELAY: DelayMs<u8>>(
|
||||||
spi: &mut SPI, cs: CS, busy: BUSY, dc: DC, rst: RST, delay: &mut DELAY,
|
spi: &mut SPI,
|
||||||
|
cs: CS,
|
||||||
|
busy: BUSY,
|
||||||
|
dc: DC,
|
||||||
|
rst: RST,
|
||||||
|
delay: &mut DELAY,
|
||||||
) -> Result<Self, SPI::Error>
|
) -> Result<Self, SPI::Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
|
|
@ -78,7 +85,11 @@ where
|
||||||
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>;
|
fn sleep(&mut self, spi: &mut SPI) -> Result<(), SPI::Error>;
|
||||||
|
|
||||||
/// Wakes the device up from sleep
|
/// Wakes the device up from sleep
|
||||||
fn wake_up<DELAY: DelayMs<u8>>(&mut self, spi: &mut SPI, delay: &mut DELAY) -> Result<(), SPI::Error>;
|
fn wake_up<DELAY: DelayMs<u8>>(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
delay: &mut DELAY,
|
||||||
|
) -> Result<(), SPI::Error>;
|
||||||
|
|
||||||
/// Sets the backgroundcolor for various commands like [clear_frame()](WaveshareInterface::clear_frame())
|
/// Sets the backgroundcolor for various commands like [clear_frame()](WaveshareInterface::clear_frame())
|
||||||
fn set_background_color(&mut self, color: Color);
|
fn set_background_color(&mut self, color: Color);
|
||||||
|
|
@ -125,5 +136,9 @@ where
|
||||||
/// WARNING: Quick Refresh might lead to ghosting-effects/problems with your display. Especially for the 4.2in Display!
|
/// WARNING: Quick Refresh might lead to ghosting-effects/problems with your display. Especially for the 4.2in Display!
|
||||||
///
|
///
|
||||||
/// If None is used the old value will be loaded on the LUTs once more
|
/// If None is used the old value will be loaded on the LUTs once more
|
||||||
fn set_lut(&mut self, spi: &mut SPI, refresh_rate: Option<RefreshLUT>) -> Result<(), SPI::Error>;
|
fn set_lut(
|
||||||
|
&mut self,
|
||||||
|
spi: &mut SPI,
|
||||||
|
refresh_rate: Option<RefreshLUT>,
|
||||||
|
) -> Result<(), SPI::Error>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue