Compare commits
No commits in common. "9d4d395a080c69fb11a5adfae81880c4391274f3" and "c91b1d8fe6b912dff589004ad80169cd9e918cc6" have entirely different histories.
9d4d395a08
...
c91b1d8fe6
3 changed files with 11 additions and 114 deletions
56
Cargo.lock
generated
56
Cargo.lock
generated
|
|
@ -73,66 +73,10 @@ dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.103"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.42"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "2.0.111"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thiserror"
|
|
||||||
version = "2.0.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8"
|
|
||||||
dependencies = [
|
|
||||||
"thiserror-impl",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "thiserror-impl"
|
|
||||||
version = "2.0.17"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-ident"
|
|
||||||
version = "1.0.22"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zel-gdeq031t10"
|
name = "zel-gdeq031t10"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"embedded-graphics",
|
"embedded-graphics",
|
||||||
"embedded-hal",
|
"embedded-hal",
|
||||||
"thiserror",
|
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ edition = "2024"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embedded-graphics = { version = "0.8.1", optional = true }
|
embedded-graphics = { version = "0.8.1", optional = true }
|
||||||
embedded-hal = "1.0.0"
|
embedded-hal = "1.0.0"
|
||||||
thiserror = { version = "2.0.17", default-features = false }
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
embedded-graphics = ["dep:embedded-graphics"]
|
embedded-graphics = ["dep:embedded-graphics"]
|
||||||
|
|
|
||||||
58
src/lib.rs
58
src/lib.rs
|
|
@ -13,7 +13,6 @@ use embedded_hal::{
|
||||||
digital::{InputPin, OutputPin},
|
digital::{InputPin, OutputPin},
|
||||||
spi::{Operation, SpiDevice},
|
spi::{Operation, SpiDevice},
|
||||||
};
|
};
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
const EPD_WIDTH: usize = 240;
|
const EPD_WIDTH: usize = 240;
|
||||||
const EPD_HEIGHT: usize = 320;
|
const EPD_HEIGHT: usize = 320;
|
||||||
|
|
@ -28,31 +27,25 @@ pub struct EPaperDisplay<BusyPin, ResetPin, DcPin, SpiDevice, Delay> {
|
||||||
delay: Delay,
|
delay: Delay,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
/// An error that may occur during display initialisation.
|
/// An error that may occur during display initialisation.
|
||||||
pub enum InitError<ResetError, DcError, SpiError> {
|
pub enum InitError<ResetError, DcError, SpiError> {
|
||||||
/// This variant is for any error with setting the level of the reset pin.
|
/// This variant is for any error with setting the level of the reset pin.
|
||||||
///
|
///
|
||||||
/// This variant may be uninhabited if the `ResetPin` type parameter for [EPaperDisplay] is one that
|
/// This variant may be uninhabited if the `ResetPin` type parameter for [EPaperDisplay] is one that
|
||||||
/// doesn't produce errors.
|
/// doesn't produce errors.
|
||||||
#[error("While initialising the display, an error occurred when toggling the reset pin: {0}")]
|
|
||||||
ResetError(ResetError),
|
ResetError(ResetError),
|
||||||
/// This variant is for errors when attempting to communicate with the display controller after reset.
|
/// This variant is for errors when attempting to communicate with the display controller after reset.
|
||||||
#[error("While initialising the display, a communication error occurred: {0}")]
|
|
||||||
WriteError(WriteError<DcError, SpiError>),
|
WriteError(WriteError<DcError, SpiError>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
/// An error when trying to communicate with the display controller.
|
/// An error when trying to communicate with the display controller.
|
||||||
pub enum WriteError<DcError, SpiError> {
|
pub enum WriteError<DcError, SpiError> {
|
||||||
/// This variant is for any error with setting the level of the DC (Data/Command) pin.
|
/// This variant is for any error with setting the level of the DC (Data/Command) pin.
|
||||||
///
|
///
|
||||||
/// This variant may be uninhabited if the `DcPin` type parameter for [EPaperDisplay] is one that
|
/// This variant may be uninhabited if the `DcPin` type parameter for [EPaperDisplay] is one that
|
||||||
/// doesn't produce errors.
|
/// doesn't produce errors.
|
||||||
#[error("Failed to set the data/command line: {0}")]
|
|
||||||
DcError(DcError),
|
DcError(DcError),
|
||||||
/// This variant is for errors produced by the SPI driver.
|
/// This variant is for errors produced by the SPI driver.
|
||||||
#[error("Failed to perform SPI operations: {0}")]
|
|
||||||
SpiError(SpiError),
|
SpiError(SpiError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,20 +210,17 @@ impl DoubleFrame<AutomaticPartialWindow> {
|
||||||
|
|
||||||
impl<PartialWindow: ApplyPartialWindow> DoubleFrame<PartialWindow> {
|
impl<PartialWindow: ApplyPartialWindow> DoubleFrame<PartialWindow> {
|
||||||
pub fn draw_pixel(&mut self, x: u16, y: u16, colour: PixelColour) {
|
pub fn draw_pixel(&mut self, x: u16, y: u16, colour: PixelColour) {
|
||||||
if x >= EPD_WIDTH as u16 || y >= EPD_HEIGHT as u16 {
|
|
||||||
return; // pixel is offscreen so can be skipped
|
|
||||||
}
|
|
||||||
self.partial_window.update_partial_window(x, x, y, y);
|
self.partial_window.update_partial_window(x, x, y, y);
|
||||||
let x_i = x as usize / 8;
|
let x_i = x / 8;
|
||||||
let x_shift = 7 - (x % 8);
|
let x_shift = x % 8;
|
||||||
let i = y as usize * (EPD_WIDTH / 8) + x_i;
|
let i = y * (EPD_WIDTH as u16 / 8) + x_i;
|
||||||
match colour {
|
match colour {
|
||||||
PixelColour::Black => {
|
PixelColour::Black => {
|
||||||
self.new.0[i as usize] &= !(1 << x_shift);
|
self.new.0[i as usize] &= !(1 << x_shift);
|
||||||
}
|
},
|
||||||
PixelColour::White => {
|
PixelColour::White => {
|
||||||
self.new.0[i as usize] |= 1 << x_shift;
|
self.new.0[i as usize] |= 1 << x_shift;
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -282,7 +272,6 @@ impl<BusyPin: InputPin, ResetPin: OutputPin, DcPin: OutputPin, Spi: SpiDevice, D
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wait_for_display(&mut self) {
|
fn wait_for_display(&mut self) {
|
||||||
self.delay.delay_ms(1);
|
|
||||||
while self.busy.is_low().expect("Failed to read busy pin") {}
|
while self.busy.is_low().expect("Failed to read busy pin") {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -292,30 +281,12 @@ impl<BusyPin: InputPin, ResetPin: OutputPin, DcPin: OutputPin, Spi: SpiDevice, D
|
||||||
self.reset.set_high().map_err(InitError::ResetError)?;
|
self.reset.set_high().map_err(InitError::ResetError)?;
|
||||||
self.delay.delay_ms(10);
|
self.delay.delay_ms(10);
|
||||||
|
|
||||||
self.write_command(0x00).map_err(InitError::WriteError)?;
|
|
||||||
self.write_data(0x1e).map_err(InitError::WriteError)?;
|
|
||||||
self.write_data(0x0d).map_err(InitError::WriteError)?;
|
|
||||||
self.delay.delay_ms(1);
|
|
||||||
|
|
||||||
self.write_command(0x00).map_err(InitError::WriteError)?;
|
self.write_command(0x00).map_err(InitError::WriteError)?;
|
||||||
self.write_data(0x1f).map_err(InitError::WriteError)?;
|
self.write_data(0x1f).map_err(InitError::WriteError)?;
|
||||||
self.write_data(0x0d).map_err(InitError::WriteError)?;
|
|
||||||
self.wait_for_display();
|
|
||||||
|
|
||||||
self.write_command(0xE0).map_err(InitError::WriteError)?;
|
|
||||||
self.write_data(0x02).map_err(InitError::WriteError)?;
|
|
||||||
self.write_command(0xE5).map_err(InitError::WriteError)?;
|
|
||||||
self.write_data(0x5A).map_err(InitError::WriteError)?;
|
|
||||||
self.write_command(0x50).map_err(InitError::WriteError)?;
|
|
||||||
|
|
||||||
self.write_data(0x97).map_err(InitError::WriteError)?;
|
|
||||||
|
|
||||||
self.write_command(0x04).map_err(InitError::WriteError)?;
|
self.write_command(0x04).map_err(InitError::WriteError)?;
|
||||||
|
|
||||||
self.wait_for_display();
|
self.wait_for_display();
|
||||||
|
|
||||||
self.write_command(0x12).map_err(InitError::WriteError)?;
|
|
||||||
self.wait_for_display();
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -334,10 +305,7 @@ impl<BusyPin: InputPin, ResetPin: OutputPin, DcPin: OutputPin, Spi: SpiDevice, D
|
||||||
self.wait_for_display();
|
self.wait_for_display();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_full_frame<PartialWindow: ApplyPartialWindow>(
|
pub fn draw_full_frame<PartialWindow: ApplyPartialWindow>(&mut self, double_frame: &mut DoubleFrame<PartialWindow>) {
|
||||||
&mut self,
|
|
||||||
double_frame: &mut DoubleFrame<PartialWindow>,
|
|
||||||
) {
|
|
||||||
double_frame.partial_window.apply(self);
|
double_frame.partial_window.apply(self);
|
||||||
self.write_command(0x10);
|
self.write_command(0x10);
|
||||||
for byte in double_frame.old.0 {
|
for byte in double_frame.old.0 {
|
||||||
|
|
@ -350,20 +318,6 @@ impl<BusyPin: InputPin, ResetPin: OutputPin, DcPin: OutputPin, Spi: SpiDevice, D
|
||||||
self.write_command(0x12);
|
self.write_command(0x12);
|
||||||
double_frame.old.0 = double_frame.new.0;
|
double_frame.old.0 = double_frame.new.0;
|
||||||
|
|
||||||
// self.delay.delay_ms(1);
|
|
||||||
self.wait_for_display();
|
|
||||||
|
|
||||||
self.write_command(0x10);
|
|
||||||
for byte in double_frame.new.0 {
|
|
||||||
self.write_data(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.write_command(0x13);
|
|
||||||
for byte in double_frame.new.0 {
|
|
||||||
self.write_data(byte);
|
|
||||||
}
|
|
||||||
self.write_command(0x12);
|
|
||||||
|
|
||||||
self.delay.delay_ms(1);
|
self.delay.delay_ms(1);
|
||||||
self.wait_for_display();
|
self.wait_for_display();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue