First commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
use epd_waveshare::{
|
||||
color::OctColor as Color,
|
||||
epd5in65f::{Display5in65f as EpdDisplay, Epd5in65f as Epd},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use embedded_hal::prelude::*;
|
||||
use linux_embedded_hal::{
|
||||
spidev::{self, SpidevOptions},
|
||||
sysfs_gpio::Direction,
|
||||
Delay, Pin, Spidev,
|
||||
};
|
||||
|
||||
pub struct Display {
|
||||
pub target: EpdDisplay,
|
||||
epd: Epd<Spidev, Pin, Pin, Pin, Pin, Delay>,
|
||||
spi: Spidev,
|
||||
delay: Delay,
|
||||
}
|
||||
|
||||
impl Display {
|
||||
pub fn new() -> Self {
|
||||
let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory");
|
||||
let options = SpidevOptions::new()
|
||||
.bits_per_word(8)
|
||||
.max_speed_hz(4_000_000)
|
||||
.mode(spidev::SpiModeFlags::SPI_MODE_0)
|
||||
.build();
|
||||
spi.configure(&options).expect("spi configuration");
|
||||
|
||||
let cs = Pin::new(26);
|
||||
cs.export().expect("cs export");
|
||||
while !cs.is_exported() {}
|
||||
cs.set_direction(Direction::Out).expect("CS direction");
|
||||
cs.set_value(1).expect("CS value set to 1");
|
||||
|
||||
let busy = Pin::new(24);
|
||||
busy.export().expect("busy export");
|
||||
while !busy.is_exported() {}
|
||||
busy.set_direction(Direction::In).expect("busy Direction");
|
||||
|
||||
let dc = Pin::new(25);
|
||||
dc.export().expect("dc export");
|
||||
while !dc.is_exported() {}
|
||||
dc.set_direction(Direction::Out).expect("dc Direction");
|
||||
dc.set_value(1).expect("dc Value set to 1");
|
||||
|
||||
let rst = Pin::new(17);
|
||||
rst.export().expect("rst export");
|
||||
while !rst.is_exported() {}
|
||||
rst.set_direction(Direction::Out).expect("rst Direction");
|
||||
rst.set_value(1).expect("rst Value set to 1");
|
||||
|
||||
let mut delay = Delay {};
|
||||
|
||||
let mut epd =
|
||||
Epd::new(&mut spi, cs, busy, dc, rst, &mut delay).expect("eink initialize error");
|
||||
|
||||
let mut display = EpdDisplay::default();
|
||||
|
||||
return Display {
|
||||
target: display,
|
||||
epd,
|
||||
spi,
|
||||
delay,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
self.epd
|
||||
.update_and_display_frame(&mut self.spi, self.target.buffer(), &mut self.delay)
|
||||
.expect("updating");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#[cfg(feature = "epd")]
|
||||
mod epd;
|
||||
|
||||
#[cfg(feature = "epd")]
|
||||
pub use epd::Display;
|
||||
|
||||
#[cfg(not(feature = "epd"))]
|
||||
mod simulation;
|
||||
|
||||
#[cfg(not(feature = "epd"))]
|
||||
pub use simulation::Display;
|
||||
@@ -0,0 +1,33 @@
|
||||
use embedded_graphics::{
|
||||
pixelcolor::{BinaryColor, Rgb888},
|
||||
prelude::*,
|
||||
};
|
||||
use embedded_graphics_simulator::{
|
||||
BinaryColorTheme, OutputSettings, OutputSettingsBuilder, SimulatorDisplay, Window,
|
||||
};
|
||||
|
||||
pub struct Display<C> {
|
||||
pub target: SimulatorDisplay<C>,
|
||||
output_settings: OutputSettings,
|
||||
}
|
||||
|
||||
impl<C> Display<C>
|
||||
where
|
||||
C: PixelColor + From<BinaryColor> + Into<Rgb888> + From<Rgb888>,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
let display = SimulatorDisplay::<C>::new(Size::new(600, 448));
|
||||
let output_settings = OutputSettingsBuilder::new()
|
||||
.theme(BinaryColorTheme::Default)
|
||||
.build();
|
||||
|
||||
Self {
|
||||
target: display,
|
||||
output_settings,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
Window::new("Simulator", &self.output_settings).show_static(&self.target);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user