Waveshare

This commit is contained in:
Adrian Woźniak 2024-09-23 17:07:30 +02:00
parent cb5633c0c4
commit b76727a01e
3 changed files with 64 additions and 40 deletions

17
Cargo.lock generated
View File

@ -90,6 +90,12 @@ dependencies = [
"serde",
]
[[package]]
name = "bit_field"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
[[package]]
name = "bitfield"
version = "0.16.1"
@ -380,6 +386,15 @@ dependencies = [
"syn 2.0.77",
]
[[package]]
name = "epd-waveshare"
version = "0.5.0"
dependencies = [
"bit_field",
"embedded-graphics-core",
"embedded-hal 1.0.0",
]
[[package]]
name = "equivalent"
version = "1.0.1"
@ -883,7 +898,9 @@ version = "0.1.0"
dependencies = [
"display-interface-spi",
"embedded-graphics",
"embedded-hal 1.0.0",
"embedded-hal-bus",
"epd-waveshare",
"esp-backtrace",
"esp-hal",
"esp-println",

View File

@ -21,6 +21,8 @@ shared = { path = "./shared", features = ['trng'] }
maze = { path = "./maze" }
strum = { version = "0.26.3", default-features = false, features = ["derive"] }
keypad = "0.2.2"
epd-waveshare = { path = "./epd-waveshare" }
embedded-hal = "1.0.0"
[profile.dev]
# Rust debug is too slow.

View File

@ -5,18 +5,21 @@ use apps::{menu::Menu, Application};
use display_interface_spi::SPIInterface;
use embedded_graphics::{
geometry::Point,
mono_font::MonoTextStyle,
text::{Text, TextStyle},
mono_font::{MonoTextStyle, MonoTextStyleBuilder},
text::{Baseline, Text, TextStyle, TextStyleBuilder},
Drawable,
};
use embedded_hal::delay::DelayNs;
use embedded_hal_bus::spi::ExclusiveDevice;
use epd_waveshare::epd3in7::*;
use epd_waveshare::prelude::*;
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
delay::Delay,
gpio::{
Gpio10, Gpio2, Gpio3, Gpio4, Gpio5, Gpio6, Gpio7, Gpio8, Input, InputPin, Io, Level,
Output, OutputPin, Pull, NO_PIN,
Gpio10, Gpio2, Gpio3, Gpio4, Gpio5, Gpio6, Gpio7, Gpio8, Input, Io, Level, Output, Pull,
NO_PIN,
},
peripherals::Peripherals,
prelude::*,
@ -27,8 +30,9 @@ use esp_hal::{
use esp_println::println;
use log::LevelFilter;
use profont::PROFONT_24_POINT;
use weact_studio_epd::{graphics::Display290TriColor, TriColor};
use weact_studio_epd::{graphics::DisplayRotation, WeActStudio290TriColorDriver};
// use weact_studio_epd::{graphics::Display290TriColor, TriColor};
// use weact_studio_epd::{graphics::DisplayRotation, WeActStudio290TriColorDriver};
mod apps;
@ -38,7 +42,7 @@ fn main() -> ! {
let system = SystemControl::new(peripherals.SYSTEM);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let clocks = ClockControl::max(system.clock_control).freeze();
let delay = Delay::new(&clocks);
let mut delay = Delay::new(&clocks);
esp_println::logger::init_logger(LevelFilter::Trace);
// esp_println::logger::init_logger_from_env();
@ -46,6 +50,8 @@ fn main() -> ! {
println!("init");
log::info!("Intializing SPI Bus...");
// Configure SPI
// Settings are taken from
// Pins for WeAct
let mosi /* sda */ = io.pins.gpio18; // D10 / GPIO18
@ -55,7 +61,7 @@ fn main() -> ! {
let rst = io.pins.gpio22; // D4 / GPIO22
let busy = io.pins.gpio23; // D5 / GPIO23
let spi_bus = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks).with_pins(
let spi_bus = Spi::new(peripherals.SPI2, 4_000.kHz(), SpiMode::Mode0, &clocks).with_pins(
Some(sclk),
Some(mosi),
NO_PIN,
@ -75,32 +81,32 @@ fn main() -> ! {
let rst = Output::new(rst, Level::High);
log::info!("Intializing SPI Device...");
let spi_device = ExclusiveDevice::new(spi_bus, cs, delay).expect("SPI device initialize error");
let spi_interface = SPIInterface::new(spi_device, dc);
log::info!("Intializing SPI Device (DONE)");
let mut spi = ExclusiveDevice::new(spi_bus, cs, delay).expect("SPI device initialize error");
// let spi_interface = SPIInterface::new(spi_device, dc);
let mut epd2in13 =
EPD3in7::new(&mut spi, busy, dc, rst, &mut delay, None).expect("eink initalize error");
// Setup EPD
log::info!("Intializing EPD...");
let mut driver = WeActStudio290TriColorDriver::new(spi_interface, busy, rst, delay);
let mut display = Display290TriColor::new();
let mut display = Display3in7::default();
display.set_rotation(DisplayRotation::Rotate90);
log::info!("Driver init...");
driver.init().unwrap();
log::info!("Intializing EPD (DONE)");
display.clear(TriColor::White);
log::info!("Printing welcome msg...");
let style = MonoTextStyle::new(&PROFONT_24_POINT, TriColor::Red);
let _ = Text::with_text_style("Witamy", Point::new(8, 68), style, TextStyle::default())
.draw(&mut display);
log::info!("Printing welcome msg (DONE)");
// draw white on black background
let style = MonoTextStyleBuilder::new()
.font(&embedded_graphics::mono_font::ascii::FONT_6X10)
.text_color(Color::White)
.background_color(Color::Black)
.build();
let text_style = TextStyleBuilder::new().baseline(Baseline::Top).build();
let _ =
Text::with_text_style("Witamy!", Point::new(90, 10), style, text_style).draw(&mut display);
epd2in13
.update_and_display_frame(&mut spi, display.buffer(), &mut delay)
.expect("display frame new graphics");
delay.delay_ms(500);
log::info!("Full update...");
let _ = driver.full_update(&display);
log::info!("Full update (DONE)");
log::info!("Sleeping for 0.5s...");
delay.delay(500.millis());
// epd2in13
// .set_refresh(&mut spi, &mut delay, RefreshLut::Quick)
// .unwrap();
epd2in13.clear_frame(&mut spi, &mut delay).unwrap();
let mut kbd = Keyboard {
rows: Rows {
@ -123,24 +129,23 @@ fn main() -> ! {
let mut app = Application::Menu(Menu::new());
let mut trng = Trng::new(peripherals.RNG, peripherals.ADC1);
display.clear(TriColor::White);
app.draw(&mut display);
driver.full_update(&display).unwrap();
driver.sleep().unwrap();
//app.draw(&mut display);
//driver.full_update(&display).unwrap();
//driver.sleep().unwrap();
loop {
ctx.button_pressed = kbd.pressed();
if !ctx.button_pressed.is_none() {
log::info!("Wake up!");
driver.wake_up().unwrap();
display.clear(TriColor::White);
app.update(&ctx, &mut trng);
app.draw(&mut display);
driver.full_update(&display).unwrap();
//driver.wake_up().unwrap();
//display.clear(TriColor::White);
//app.update(&ctx, &mut trng);
// app.draw(&mut display);
//driver.full_update(&display).unwrap();
}
log::info!("Sleeping for 100ms...");
driver.sleep().unwrap();
//driver.sleep().unwrap();
delay.delay(300.millis());
}
}