Successfully port custom display driver to esp32

This commit is contained in:
Sofia 2026-05-13 17:11:25 +03:00
parent 4221a98277
commit c6327b8523
2 changed files with 6 additions and 14 deletions

View File

@ -94,7 +94,6 @@ impl Color {
pub struct Display<'d, DM: DriverMode, T: DelayNs> { pub struct Display<'d, DM: DriverMode, T: DelayNs> {
pub spi: Spi<'d, DM>, pub spi: Spi<'d, DM>,
pub cs: Output<'d>,
pub dc: Output<'d>, pub dc: Output<'d>,
pub rst: Output<'d>, pub rst: Output<'d>,
pub delay: T, pub delay: T,
@ -169,16 +168,14 @@ pub enum Rotation {
impl<'d, DM: DriverMode, T: DelayNs> Display<'d, DM, T> { impl<'d, DM: DriverMode, T: DelayNs> Display<'d, DM, T> {
pub fn write(&mut self, writeable: Writeable) { pub fn write(&mut self, writeable: Writeable) {
self.cs.set_low();
match writeable { match writeable {
Writeable::Command(cmd) => { Writeable::Command(cmd) => {
self.dc.set_low(); self.dc.set_low();
SpiBus::write(&mut self.spi, &[cmd as u8]).unwrap() SpiBus::write(&mut self.spi, &[cmd as u8]).unwrap();
self.dc.set_high();
} }
Writeable::Data(data) => { Writeable::Data(data) => {
self.dc.set_high();
SpiBus::write(&mut self.spi, data).unwrap(); SpiBus::write(&mut self.spi, data).unwrap();
self.cs.set_high();
} }
} }
} }
@ -213,7 +210,6 @@ impl<'d, DM: DriverMode, T: DelayNs> Display<'d, DM, T> {
} }
pub fn hard_reset(&mut self) { pub fn hard_reset(&mut self) {
self.cs.set_low();
self.rst.set_high(); self.rst.set_high();
self.delay.delay_ms(50); self.delay.delay_ms(50);
@ -222,8 +218,6 @@ impl<'d, DM: DriverMode, T: DelayNs> Display<'d, DM, T> {
self.rst.set_high(); self.rst.set_high();
self.delay.delay_ms(150); self.delay.delay_ms(150);
self.cs.set_high();
} }
pub fn soft_reset(&mut self) { pub fn soft_reset(&mut self) {
@ -271,9 +265,9 @@ impl<'d, DM: DriverMode, T: DelayNs> Display<'d, DM, T> {
pub fn set_window(&mut self, pos0: Position, pos1: Position) { pub fn set_window(&mut self, pos0: Position, pos1: Position) {
self.set_columns(pos0.x, pos1.x); self.set_columns(pos0.x, pos1.x);
self.delay.delay_ms(10); self.delay.delay_ms(1);
self.set_rows(pos0.y, pos1.y); self.set_rows(pos0.y, pos1.y);
self.delay.delay_ms(10); self.delay.delay_ms(1);
self.write(Writeable::Command(Command::RamWR)); self.write(Writeable::Command(Command::RamWR));
} }
@ -284,7 +278,6 @@ impl<'d, DM: DriverMode, T: DelayNs> Display<'d, DM, T> {
pub fn draw_rect(&mut self, pos0: Position, pos1: Position, color: Color) { pub fn draw_rect(&mut self, pos0: Position, pos1: Position, color: Color) {
self.set_window(pos0, pos1); self.set_window(pos0, pos1);
self.dc.set_high();
let width = pos1.x - pos0.x; let width = pos1.x - pos0.x;
let height = pos1.y - pos0.y; let height = pos1.y - pos0.y;
let pixels = width * height; let pixels = width * height;

View File

@ -77,15 +77,14 @@ fn main() -> ! {
.unwrap() .unwrap()
.with_sck(peripherals.GPIO5) .with_sck(peripherals.GPIO5)
.with_mosi(peripherals.GPIO18) .with_mosi(peripherals.GPIO18)
.with_miso(peripherals.GPIO19); .with_miso(peripherals.GPIO19)
.with_cs(peripherals.GPIO21);
let rst = Output::new(peripherals.GPIO14, Level::Low, OutputConfig::default()); let rst = Output::new(peripherals.GPIO14, Level::Low, OutputConfig::default());
let dc = Output::new(peripherals.GPIO32, Level::Low, OutputConfig::default()); let dc = Output::new(peripherals.GPIO32, Level::Low, OutputConfig::default());
let cs = Output::new(peripherals.GPIO21, Level::Low, OutputConfig::default());
let mut display = Display { let mut display = Display {
spi, spi,
cs,
dc, dc,
rst, rst,
delay: Delay::new(), delay: Delay::new(),