Successfully port custom display driver to esp32
This commit is contained in:
parent
4221a98277
commit
c6327b8523
@ -94,7 +94,6 @@ impl Color {
|
||||
|
||||
pub struct Display<'d, DM: DriverMode, T: DelayNs> {
|
||||
pub spi: Spi<'d, DM>,
|
||||
pub cs: Output<'d>,
|
||||
pub dc: Output<'d>,
|
||||
pub rst: Output<'d>,
|
||||
pub delay: T,
|
||||
@ -169,16 +168,14 @@ pub enum Rotation {
|
||||
|
||||
impl<'d, DM: DriverMode, T: DelayNs> Display<'d, DM, T> {
|
||||
pub fn write(&mut self, writeable: Writeable) {
|
||||
self.cs.set_low();
|
||||
match writeable {
|
||||
Writeable::Command(cmd) => {
|
||||
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) => {
|
||||
self.dc.set_high();
|
||||
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) {
|
||||
self.cs.set_low();
|
||||
self.rst.set_high();
|
||||
self.delay.delay_ms(50);
|
||||
|
||||
@ -222,8 +218,6 @@ impl<'d, DM: DriverMode, T: DelayNs> Display<'d, DM, T> {
|
||||
|
||||
self.rst.set_high();
|
||||
self.delay.delay_ms(150);
|
||||
|
||||
self.cs.set_high();
|
||||
}
|
||||
|
||||
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) {
|
||||
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.delay.delay_ms(10);
|
||||
self.delay.delay_ms(1);
|
||||
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) {
|
||||
self.set_window(pos0, pos1);
|
||||
self.dc.set_high();
|
||||
let width = pos1.x - pos0.x;
|
||||
let height = pos1.y - pos0.y;
|
||||
let pixels = width * height;
|
||||
|
||||
@ -77,15 +77,14 @@ fn main() -> ! {
|
||||
.unwrap()
|
||||
.with_sck(peripherals.GPIO5)
|
||||
.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 dc = Output::new(peripherals.GPIO32, Level::Low, OutputConfig::default());
|
||||
let cs = Output::new(peripherals.GPIO21, Level::Low, OutputConfig::default());
|
||||
|
||||
let mut display = Display {
|
||||
spi,
|
||||
cs,
|
||||
dc,
|
||||
rst,
|
||||
delay: Delay::new(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user