You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.1 KiB
74 lines
2.1 KiB
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 display: 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 { |
|
display, |
|
epd, |
|
spi, |
|
delay, |
|
}; |
|
} |
|
|
|
fn update(&mut self) { |
|
self.epd |
|
.update_and_display_frame(&mut self.spi, self.display.buffer(), &mut self.delay) |
|
.expect("updating"); |
|
} |
|
}
|
|
|