Started writing frame drawing
This commit is contained in:
parent
488b41d0f0
commit
f30e0b7dc4
1 changed files with 69 additions and 21 deletions
90
src/lib.rs
90
src/lib.rs
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
use embedded_hal::{
|
||||
delay::DelayNs,
|
||||
digital::{InputPin, OutputPin}, spi::{Operation, SpiDevice},
|
||||
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;
|
||||
const EPD_WIDTH: usize = 240;
|
||||
const EPD_HEIGHT: usize = 320;
|
||||
const EPD_ARRAY: usize = EPD_WIDTH * EPD_HEIGHT / 8;
|
||||
|
||||
pub struct EPaperDisplay<BusyPin, ResetPin, DcPin, SpiDevice, Delay> {
|
||||
busy: BusyPin,
|
||||
|
|
@ -27,13 +28,40 @@ pub enum WriteError<DcError, SpiError> {
|
|||
SpiError(SpiError),
|
||||
}
|
||||
|
||||
impl<
|
||||
BusyPin: InputPin,
|
||||
ResetPin: OutputPin,
|
||||
DcPin: OutputPin,
|
||||
Spi: SpiDevice,
|
||||
Delay: DelayNs,
|
||||
> EPaperDisplay<BusyPin, ResetPin, DcPin, Spi, Delay>
|
||||
pub struct Frame([u8; EPD_ARRAY]);
|
||||
|
||||
impl Frame {
|
||||
pub const fn new_white() -> Self {
|
||||
Self([0xff; EPD_ARRAY])
|
||||
}
|
||||
|
||||
pub const fn new_black() -> Self {
|
||||
Self([0x00; EPD_ARRAY])
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DoubleFrame {
|
||||
old: Frame,
|
||||
new: Frame,
|
||||
}
|
||||
|
||||
pub enum PixelColour {
|
||||
Black = 0,
|
||||
White = 1,
|
||||
}
|
||||
|
||||
impl DoubleFrame {
|
||||
pub fn new(old: Frame, new: Frame) -> Self {
|
||||
Self { old, new }
|
||||
}
|
||||
|
||||
pub fn draw_pixel(&mut self, x: usize, y: usize, colour: PixelColour) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
impl<BusyPin: InputPin, ResetPin: OutputPin, DcPin: OutputPin, Spi: SpiDevice, Delay: DelayNs>
|
||||
EPaperDisplay<BusyPin, ResetPin, DcPin, Spi, Delay>
|
||||
{
|
||||
pub fn new(
|
||||
busy: BusyPin,
|
||||
|
|
@ -54,22 +82,26 @@ impl<
|
|||
|
||||
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.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.spi
|
||||
.transaction(&mut [
|
||||
Operation::DelayNs(60),
|
||||
Operation::Write(&[byte]),
|
||||
Operation::DelayNs(20),
|
||||
])
|
||||
.map_err(WriteError::SpiError)?;
|
||||
self.delay.delay_ns(40);
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -107,4 +139,20 @@ impl<
|
|||
self.delay.delay_ms(1);
|
||||
self.wait_for_display();
|
||||
}
|
||||
|
||||
pub fn draw_full_frame(&mut self, double_frame: &mut DoubleFrame) {
|
||||
self.write_command(0x10);
|
||||
for byte in double_frame.old.0 {
|
||||
self.write_data(byte);
|
||||
}
|
||||
self.write_command(0x13);
|
||||
for byte in double_frame.new.0 {
|
||||
self.write_data(byte);
|
||||
}
|
||||
self.write_command(0x12);
|
||||
double_frame.old.0 = double_frame.new.0;
|
||||
|
||||
self.delay.delay_ms(1);
|
||||
self.wait_for_display();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue