Get something to work on custom display driver
This commit is contained in:
parent
301bf3a400
commit
4221a98277
@ -109,7 +109,7 @@ pub enum Command {
|
||||
SleepIn = 0x10,
|
||||
SleepOut = 0x11,
|
||||
PTLON = 0x12,
|
||||
NoRon = 0x13,
|
||||
NormalModeOn = 0x13,
|
||||
|
||||
InversionOff = 0x20,
|
||||
InversionOn = 0x21,
|
||||
@ -185,21 +185,31 @@ impl<'d, DM: DriverMode, T: DelayNs> Display<'d, DM, T> {
|
||||
|
||||
pub fn init(&mut self) {
|
||||
self.hard_reset();
|
||||
self.soft_reset();
|
||||
self.delay.delay_ms(150);
|
||||
// self.soft_reset();
|
||||
self.set_sleep(false);
|
||||
self.delay.delay_ms(50);
|
||||
|
||||
// TODO fix madctl
|
||||
self.write(Writeable::Command(Command::MADCTL));
|
||||
self.write(Writeable::Data(&[0b0000_1000]));
|
||||
self.delay.delay_ms(150);
|
||||
|
||||
self.set_color_mode((ColorMode::ColorMode65K as u8) | (ColorMode::ColorMode16BIT as u8));
|
||||
self.delay.delay_ms(50);
|
||||
self.set_inversion(true);
|
||||
self.write(Writeable::Command(Command::NoRon));
|
||||
self.draw_rect(
|
||||
Position { x: 0, y: 0 },
|
||||
Position { x: 240, y: 240 },
|
||||
Color { bytes: [255, 255] },
|
||||
);
|
||||
self.write(Writeable::Command(Command::NormalModeOn));
|
||||
self.delay.delay_ms(50);
|
||||
|
||||
self.write(Writeable::Command(Command::DisplayOn));
|
||||
|
||||
self.delay.delay_ms(500);
|
||||
|
||||
self.draw_rect(
|
||||
Position { x: 0, y: 0 },
|
||||
Position { x: 240, y: 240 },
|
||||
Color::default(),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn hard_reset(&mut self) {
|
||||
@ -261,7 +271,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.set_rows(pos0.y, pos1.y);
|
||||
self.delay.delay_ms(10);
|
||||
self.write(Writeable::Command(Command::RamWR));
|
||||
}
|
||||
|
||||
|
||||
62
src/main.rs
62
src/main.rs
@ -7,8 +7,8 @@
|
||||
)]
|
||||
#![deny(clippy::large_stack_frames)]
|
||||
|
||||
use embedded_graphics::{pixelcolor::Rgb565, prelude::DrawTarget};
|
||||
use embedded_hal_bus::spi::ExclusiveDevice;
|
||||
// use embedded_graphics::{pixelcolor::Rgb565, prelude::DrawTarget};
|
||||
// use embedded_hal_bus::spi::ExclusiveDevice;
|
||||
use esp_hal::{
|
||||
clock::CpuClock,
|
||||
delay::Delay,
|
||||
@ -19,7 +19,9 @@ use esp_hal::{
|
||||
};
|
||||
|
||||
use esp_backtrace as _;
|
||||
use mipidsi::{Builder, interface::SpiInterface, models::ST7789};
|
||||
// use mipidsi::{Builder, interface::SpiInterface, models::ST7789};
|
||||
|
||||
use crate::display::{Color, Display, Position, Rgb565};
|
||||
|
||||
// use crate::display::{Color, Display, Position, Rgb565, Rotation};
|
||||
|
||||
@ -81,32 +83,32 @@ fn main() -> ! {
|
||||
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(),
|
||||
// };
|
||||
let mut display = Display {
|
||||
spi,
|
||||
cs,
|
||||
dc,
|
||||
rst,
|
||||
delay: Delay::new(),
|
||||
};
|
||||
|
||||
// display.init();
|
||||
// display.draw_rect(
|
||||
// Position::new(0, 0),
|
||||
// Position::new(32, 32),
|
||||
// Rgb565::yellow().as_color(),
|
||||
// );
|
||||
display.init();
|
||||
display.draw_rect(
|
||||
Position::new(0, 0),
|
||||
Position::new(32, 32),
|
||||
Rgb565::yellow().as_color(),
|
||||
);
|
||||
|
||||
// let mut led = Output::new(peripherals.GPIO5, Level::Low, OutputConfig::default());
|
||||
|
||||
let mut test_delay = Delay::new();
|
||||
|
||||
let mut buffer = [0u8; 512];
|
||||
let spi_device = ExclusiveDevice::new_no_delay(spi, cs).unwrap();
|
||||
let di = SpiInterface::new(spi_device, dc, &mut buffer);
|
||||
let mut display = Builder::new(ST7789, di)
|
||||
.reset_pin(rst)
|
||||
.init(&mut test_delay)
|
||||
.unwrap(); // delay provider from your MCU
|
||||
// let mut buffer = [0u8; 512];
|
||||
// let spi_device = ExclusiveDevice::new_no_delay(spi, cs).unwrap();
|
||||
// let di = SpiInterface::new(spi_device, dc, &mut buffer);
|
||||
// let mut display = Builder::new(ST7789, di)
|
||||
// .reset_pin(rst)
|
||||
// .init(&mut test_delay)
|
||||
// .unwrap(); // delay provider from your MCU
|
||||
|
||||
let mut color = 0;
|
||||
|
||||
@ -115,13 +117,15 @@ fn main() -> ! {
|
||||
|
||||
color = (color + 50) % 200;
|
||||
|
||||
display.clear(Rgb565::new(color, color, color)).unwrap();
|
||||
// display.clear(Rgb565::new(color, color, color)).unwrap();
|
||||
|
||||
// display.draw_rect(
|
||||
// Position::new(0, 0),
|
||||
// Position::new(color as u16, color as u16),
|
||||
// Rgb565::red().as_color(),
|
||||
// );
|
||||
display.draw_rect(
|
||||
Position::new(0, 0),
|
||||
Position::new(240, 240),
|
||||
Color {
|
||||
bytes: [color, color],
|
||||
},
|
||||
);
|
||||
|
||||
// let delay_start = Instant::now();
|
||||
// while delay_start.elapsed() < Duration::from_millis(500) {}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user