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

View File

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

View File

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