pi-frame-server/src/display.rs

58 lines
1.7 KiB
Rust
Raw Normal View History

2024-07-02 15:57:29 +00:00
use epd_waveshare::{epd7in3f::Epd7in3f, prelude::WaveshareDisplay};
use linux_embedded_hal::spidev::SpiModeFlags;
use linux_embedded_hal::spidev::SpidevOptions;
2024-07-03 23:33:04 +00:00
use linux_embedded_hal::{CdevPin, Delay, SpidevDevice};
2024-07-02 15:57:29 +00:00
use linux_embedded_hal::gpio_cdev::{Chip, LineRequestFlags};
use anyhow::Result;
2024-07-16 23:55:59 +00:00
pub struct Wrapper {
2024-07-02 15:57:29 +00:00
spi: SpidevDevice,
gpiochip: Chip,
delay: Delay,
panel: Epd7in3f<SpidevDevice, CdevPin, CdevPin, CdevPin, Delay>
}
2024-07-16 23:55:59 +00:00
impl Wrapper {
pub fn new() -> Result<Wrapper> {
2024-07-02 15:57:29 +00:00
let mut spi = SpidevDevice::open("/dev/spidev0.0")?;
let spi_options = SpidevOptions::new()
.bits_per_word(8)
.max_speed_hz(10_000_000)
.mode(SpiModeFlags::SPI_MODE_0)
.build();
spi.configure(&spi_options)?;
let mut gpiochip = Chip::new("/dev/gpiochip0")?;
let busy_pin = CdevPin::new(gpiochip.get_line(24)?.request(
LineRequestFlags::INPUT,
0,
"frametool",
)?)?;
let dc_pin = CdevPin::new(gpiochip.get_line(25)?.request(
LineRequestFlags::OUTPUT,
0,
"frametool",
)?)?;
let rst_pin = CdevPin::new(gpiochip.get_line(17)?.request(
LineRequestFlags::OUTPUT,
0,
"frametool",
)?)?;
let mut delay = Delay {};
let panel = Epd7in3f::new(&mut spi, busy_pin, dc_pin, rst_pin, &mut delay, None)?;
2024-07-16 23:55:59 +00:00
Ok(Wrapper {
2024-07-02 15:57:29 +00:00
spi,
gpiochip,
delay,
panel
})
}
pub fn display(&mut self, buf: &[u8]) -> Result<()>{
self.panel.update_and_display_frame(&mut self.spi, buf, &mut self.delay)?;
Ok(())
}
}
2024-07-03 23:33:04 +00:00