Started driver implementation
This commit is contained in:
commit
488b41d0f0
4 changed files with 134 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/target
|
||||||
16
Cargo.lock
generated
Normal file
16
Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "embedded-hal"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zel-gdeq031t10"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"embedded-hal",
|
||||||
|
]
|
||||||
7
Cargo.toml
Normal file
7
Cargo.toml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
[package]
|
||||||
|
name = "zel-gdeq031t10"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
embedded-hal = "1.0.0"
|
||||||
110
src/lib.rs
Normal file
110
src/lib.rs
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
use embedded_hal::{
|
||||||
|
delay::DelayNs,
|
||||||
|
digital::{InputPin, OutputPin}, spi::{Operation, SpiDevice},
|
||||||
|
};
|
||||||
|
|
||||||
|
const EPD_WIDTH: u32 = 240;
|
||||||
|
const EPD_HEIGHT: u32 = 320;
|
||||||
|
const EPD_ARRAY: u32 = EPD_WIDTH * EPD_HEIGHT / 8;
|
||||||
|
|
||||||
|
pub struct EPaperDisplay<BusyPin, ResetPin, DcPin, SpiDevice, Delay> {
|
||||||
|
busy: BusyPin,
|
||||||
|
reset: ResetPin,
|
||||||
|
dc: DcPin,
|
||||||
|
spi: SpiDevice,
|
||||||
|
delay: Delay,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum InitError<ResetError, DcError, SpiError> {
|
||||||
|
ResetError(ResetError),
|
||||||
|
WriteError(WriteError<DcError, SpiError>),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum WriteError<DcError, SpiError> {
|
||||||
|
DcError(DcError),
|
||||||
|
SpiError(SpiError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<
|
||||||
|
BusyPin: InputPin,
|
||||||
|
ResetPin: OutputPin,
|
||||||
|
DcPin: OutputPin,
|
||||||
|
Spi: SpiDevice,
|
||||||
|
Delay: DelayNs,
|
||||||
|
> EPaperDisplay<BusyPin, ResetPin, DcPin, Spi, Delay>
|
||||||
|
{
|
||||||
|
pub fn new(
|
||||||
|
busy: BusyPin,
|
||||||
|
reset: ResetPin,
|
||||||
|
dc: DcPin,
|
||||||
|
spi: Spi,
|
||||||
|
delay: Delay,
|
||||||
|
) -> Result<Self, InitError<ResetPin::Error, DcPin::Error, Spi::Error>> {
|
||||||
|
let mut display = Self {
|
||||||
|
busy,
|
||||||
|
reset,
|
||||||
|
dc,
|
||||||
|
spi,
|
||||||
|
delay,
|
||||||
|
};
|
||||||
|
display.init().map(|_| display)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_command(&mut self, byte: u8) -> Result<(), WriteError<DcPin::Error, Spi::Error>> {
|
||||||
|
self.dc.set_low().map_err(WriteError::DcError)?;
|
||||||
|
self.spi.transaction(&mut [
|
||||||
|
Operation::DelayNs(60),
|
||||||
|
Operation::Write(&[byte]),
|
||||||
|
Operation::DelayNs(20),
|
||||||
|
]).map_err(WriteError::SpiError)?;
|
||||||
|
self.delay.delay_ns(40);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_data(&mut self, byte: u8) -> Result<(), WriteError<DcPin::Error, Spi::Error>> {
|
||||||
|
self.dc.set_high().map_err(WriteError::DcError)?;
|
||||||
|
self.spi.transaction(&mut [
|
||||||
|
Operation::DelayNs(60),
|
||||||
|
Operation::Write(&[byte]),
|
||||||
|
Operation::DelayNs(20),
|
||||||
|
]).map_err(WriteError::SpiError)?;
|
||||||
|
self.delay.delay_ns(40);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wait_for_display(&mut self) {
|
||||||
|
while self.busy.is_low().expect("Failed to read busy pin") {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(&mut self) -> Result<(), InitError<ResetPin::Error, DcPin::Error, Spi::Error>> {
|
||||||
|
self.reset.set_low().map_err(InitError::ResetError)?;
|
||||||
|
self.delay.delay_ms(10);
|
||||||
|
self.reset.set_high().map_err(InitError::ResetError)?;
|
||||||
|
self.delay.delay_ms(10);
|
||||||
|
|
||||||
|
self.write_command(0x00).map_err(InitError::WriteError)?;
|
||||||
|
self.write_data(0x1f).map_err(InitError::WriteError)?;
|
||||||
|
self.write_command(0x04).map_err(InitError::WriteError)?;
|
||||||
|
|
||||||
|
self.wait_for_display();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn clear_display(&mut self) {
|
||||||
|
self.write_command(0x10);
|
||||||
|
for _ in 0..EPD_ARRAY {
|
||||||
|
self.write_data(0xff);
|
||||||
|
}
|
||||||
|
self.write_command(0x13);
|
||||||
|
for _ in 0..EPD_ARRAY {
|
||||||
|
self.write_data(0xff);
|
||||||
|
}
|
||||||
|
self.write_command(0x12);
|
||||||
|
|
||||||
|
self.delay.delay_ms(1);
|
||||||
|
self.wait_for_display();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue