This commit is contained in:
Adrian Woźniak 2024-09-18 13:23:15 +02:00
parent c1144d58a3
commit aad0ccef4e
6 changed files with 158 additions and 57 deletions

49
Cargo.lock generated
View File

@ -183,7 +183,7 @@ checksum = "f86b9ec30048b1955da2038fcc3c017f419ab21bb0001879d16c0a3749dc6b7a"
dependencies = [ dependencies = [
"byte-slice-cast", "byte-slice-cast",
"display-interface", "display-interface",
"embedded-hal", "embedded-hal 1.0.0",
"embedded-hal-async", "embedded-hal-async",
] ]
@ -202,7 +202,7 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9d2e857f87ac832df68fa498d18ddc679175cf3d2e4aa893988e5601baf9438" checksum = "e9d2e857f87ac832df68fa498d18ddc679175cf3d2e4aa893988e5601baf9438"
dependencies = [ dependencies = [
"nb", "nb 1.1.0",
] ]
[[package]] [[package]]
@ -237,6 +237,16 @@ dependencies = [
"byteorder", "byteorder",
] ]
[[package]]
name = "embedded-hal"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35949884794ad573cf46071e41c9b60efb0cb311e3ca01f7af807af1debc66ff"
dependencies = [
"nb 0.1.3",
"void",
]
[[package]] [[package]]
name = "embedded-hal" name = "embedded-hal"
version = "1.0.0" version = "1.0.0"
@ -249,7 +259,7 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4c685bbef7fe13c3c6dd4da26841ed3980ef33e841cddfa15ce8a8fb3f1884" checksum = "0c4c685bbef7fe13c3c6dd4da26841ed3980ef33e841cddfa15ce8a8fb3f1884"
dependencies = [ dependencies = [
"embedded-hal", "embedded-hal 1.0.0",
] ]
[[package]] [[package]]
@ -259,7 +269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d3980bf28e8577db59fe2bdb3df868a419469d2cecb363644eea2b6f7797669" checksum = "0d3980bf28e8577db59fe2bdb3df868a419469d2cecb363644eea2b6f7797669"
dependencies = [ dependencies = [
"critical-section", "critical-section",
"embedded-hal", "embedded-hal 1.0.0",
"portable-atomic", "portable-atomic",
] ]
@ -269,8 +279,8 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605" checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605"
dependencies = [ dependencies = [
"embedded-hal", "embedded-hal 1.0.0",
"nb", "nb 1.1.0",
] ]
[[package]] [[package]]
@ -349,7 +359,7 @@ dependencies = [
"document-features", "document-features",
"embedded-can", "embedded-can",
"embedded-dma", "embedded-dma",
"embedded-hal", "embedded-hal 1.0.0",
"embedded-hal-nb", "embedded-hal-nb",
"enumset", "enumset",
"esp-build", "esp-build",
@ -358,7 +368,7 @@ dependencies = [
"esp-riscv-rt", "esp-riscv-rt",
"esp32c6", "esp32c6",
"fugit", "fugit",
"nb", "nb 1.1.0",
"paste", "paste",
"portable-atomic", "portable-atomic",
"rand_core", "rand_core",
@ -523,6 +533,15 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "keypad"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cd098757f3c79a71672ea320a457ba57ab42f25f628145473329fa59c320d37"
dependencies = [
"embedded-hal 0.2.7",
]
[[package]] [[package]]
name = "kinded" name = "kinded"
version = "0.3.0" version = "0.3.0"
@ -619,6 +638,15 @@ dependencies = [
"adler2", "adler2",
] ]
[[package]]
name = "nb"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f"
dependencies = [
"nb 1.1.0",
]
[[package]] [[package]]
name = "nb" name = "nb"
version = "1.1.0" version = "1.1.0"
@ -783,6 +811,7 @@ dependencies = [
"esp-hal", "esp-hal",
"esp-println", "esp-println",
"heapless", "heapless",
"keypad",
"log", "log",
"maze", "maze",
"nutype", "nutype",
@ -829,7 +858,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f5c1b8bf41ea746266cdee443d1d1e9125c86ce1447e1a2615abd34330d33a9" checksum = "2f5c1b8bf41ea746266cdee443d1d1e9125c86ce1447e1a2615abd34330d33a9"
dependencies = [ dependencies = [
"critical-section", "critical-section",
"embedded-hal", "embedded-hal 1.0.0",
] ]
[[package]] [[package]]
@ -1068,7 +1097,7 @@ checksum = "3e531b21e70dfc6294be2429e4f616f634c8ca1a328325dceefc4f92c12d6e9b"
dependencies = [ dependencies = [
"display-interface", "display-interface",
"embedded-graphics", "embedded-graphics",
"embedded-hal", "embedded-hal 1.0.0",
"embedded-hal-async", "embedded-hal-async",
"maybe-async-cfg", "maybe-async-cfg",
"sealed", "sealed",

View File

@ -9,7 +9,7 @@ embedded-graphics = "0.8.1"
embedded-hal-bus = "0.2.0" embedded-hal-bus = "0.2.0"
esp-backtrace = { version = "0.13.0", features = ["esp32c6", "exception-handler", "panic-handler", "println"] } esp-backtrace = { version = "0.13.0", features = ["esp32c6", "exception-handler", "panic-handler", "println"] }
esp-hal = { version = "0.19.0", features = ["esp32c6", "embedded-hal"] } esp-hal = { version = "0.19.0", features = ["esp32c6", "embedded-hal"] }
esp-println = { version = "0.10.0", default-features = false, features = ["esp32c6", "log", "jtag-serial"] } esp-println = { version = "0.10.0", default-features = false, features = ["esp32c6", "log", "auto"] }
heapless = "0.8.0" heapless = "0.8.0"
log = { version = "0.4.21" } log = { version = "0.4.21" }
nutype = { version = "0.5.0", default-features = false } nutype = { version = "0.5.0", default-features = false }
@ -20,6 +20,7 @@ weact-studio-epd = { version = "0.1.2", features = ["blocking"] }
shared = { path = "./shared", features = ['trng'] } 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"
[profile.dev] [profile.dev]
# Rust debug is too slow. # Rust debug is too slow.

13
espflash.toml Normal file
View File

@ -0,0 +1,13 @@
partition_table = "partitions.csv"
[connection]
[[usb_device]]
vid = "1a86"
pid = "55d3"
[[usb_device]]
vid = "04e8"
pid = "6860"
[flash]

5
partitions.csv Normal file
View File

@ -0,0 +1,5 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x00009000, 0x6000,
phy_init, data, phy, 0x0000f000, 0x1000,
factory, app, factory, 0x00010000, 0x003f0000,
1 # Name, Type, SubType, Offset, Size, Flags
2 # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
3 nvs, data, nvs, 0x00009000, 0x6000,
4 phy_init, data, phy, 0x0000f000, 0x1000,
5 factory, app, factory, 0x00010000, 0x003f0000,

View File

@ -1,7 +1,7 @@
use crate::Button; use crate::Button;
use super::*; use super::*;
use profont::PROFONT_24_POINT; use profont::PROFONT_18_POINT;
use strum::IntoEnumIterator; use strum::IntoEnumIterator;
#[derive(Debug, Clone, Copy, Default, PartialEq, strum::EnumIter)] #[derive(Debug, Clone, Copy, Default, PartialEq, strum::EnumIter)]
@ -21,8 +21,8 @@ impl MenuEntry {
fn position(&self) -> Point { fn position(&self) -> Point {
match self { match self {
MenuEntry::Labirynth => Point::new(8, 68), MenuEntry::Labirynth => Point::new(20, 38),
MenuEntry::Pairs => Point::new(38, 68), MenuEntry::Pairs => Point::new(20, 68),
} }
} }
} }
@ -69,10 +69,21 @@ impl App for Menu {
} }
fn draw(&self, display: &mut Display290TriColor) { fn draw(&self, display: &mut Display290TriColor) {
let style = MonoTextStyle::new(&PROFONT_24_POINT, TriColor::Black); let style = MonoTextStyle::new(&PROFONT_18_POINT, TriColor::Black);
let selected_style = MonoTextStyle::new(&PROFONT_24_POINT, TriColor::Red); let selected_style = MonoTextStyle::new(&PROFONT_18_POINT, TriColor::Red);
MenuEntry::iter().for_each(|entry| { MenuEntry::iter().for_each(|entry| {
if entry == self.selected {
let _ = Text::with_text_style(
"> ",
Point::new(2, entry.position().y),
selected_style,
TextStyle::default(),
)
.draw(display)
.unwrap();
};
let _ = Text::with_text_style( let _ = Text::with_text_style(
entry.as_str(), entry.as_str(),
entry.position(), entry.position(),

View File

@ -15,7 +15,7 @@ use esp_hal::{
clock::ClockControl, clock::ClockControl,
delay::Delay, delay::Delay,
gpio::{ gpio::{
Gpio0, Gpio1, Gpio2, Gpio3, Gpio4, Gpio5, Gpio6, Gpio7, GpioPin, Input, Io, Level, Output, Gpio10, Gpio2, Gpio3, Gpio4, Gpio5, Gpio6, Gpio7, Gpio8, Input, Io, Level, Output, Pull,
NO_PIN, NO_PIN,
}, },
peripherals::Peripherals, peripherals::Peripherals,
@ -24,6 +24,8 @@ use esp_hal::{
spi::{master::Spi, SpiMode}, spi::{master::Spi, SpiMode},
system::SystemControl, system::SystemControl,
}; };
use esp_println::println;
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::Display290TriColor, TriColor};
use weact_studio_epd::{graphics::DisplayRotation, WeActStudio290TriColorDriver}; use weact_studio_epd::{graphics::DisplayRotation, WeActStudio290TriColorDriver};
@ -37,16 +39,16 @@ fn main() -> ! {
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 delay = Delay::new(&clocks);
let mut trng = Trng::new(peripherals.RNG, peripherals.ADC1);
let _ = trng.random(); esp_println::logger::init_logger(LevelFilter::Trace);
// esp_println::logger::init_logger_from_env();
esp_println::logger::init_logger_from_env(); println!("init");
log::info!("Intializing SPI Bus..."); log::info!("Intializing SPI Bus...");
// Pins for WeAct // Pins for WeAct
let mosi = io.pins.gpio18; // D10 / GPIO18 let mosi /* sda */ = io.pins.gpio18; // D10 / GPIO18
let sclk = io.pins.gpio19; // D8 / GPIO19 let sclk = io.pins.gpio19; // D8 / GPIO19
let cs = io.pins.gpio20; // D9 / GPIO20 let cs = io.pins.gpio20; // D9 / GPIO20
let dc = io.pins.gpio21; // D3 / GPIO21 let dc = io.pins.gpio21; // D3 / GPIO21
@ -75,62 +77,71 @@ fn main() -> ! {
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 spi_device = 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)");
// Setup EPD // Setup EPD
log::info!("Intializing EPD..."); log::info!("Intializing EPD...");
let mut driver = WeActStudio290TriColorDriver::new(spi_interface, busy, rst, delay); let mut driver = WeActStudio290TriColorDriver::new(spi_interface, busy, rst, delay);
let mut display = Display290TriColor::new(); let mut display = Display290TriColor::new();
display.set_rotation(DisplayRotation::Rotate90); display.set_rotation(DisplayRotation::Rotate90);
log::info!("Driver init...");
driver.init().unwrap(); driver.init().unwrap();
log::info!("Intializing EPD (DONE)");
let style = MonoTextStyle::new(&PROFONT_24_POINT, TriColor::Black); display.clear(TriColor::White);
let _ = Text::with_text_style( log::info!("Printing welcome msg...");
"Welcome in Reddy", let style = MonoTextStyle::new(&PROFONT_24_POINT, TriColor::Red);
Point::new(8, 68), let _ = Text::with_text_style("Witamy", Point::new(8, 68), style, TextStyle::default())
style,
TextStyle::default(),
)
.draw(&mut display); .draw(&mut display);
log::info!("Printing welcome msg (DONE)");
driver.full_update(&display).unwrap(); log::info!("Full update...");
let _ = driver.full_update(&display);
log::info!("Full update (DONE)");
log::info!("Sleeping for 0.5s..."); log::info!("Sleeping for 0.5s...");
driver.sleep().unwrap();
delay.delay(500.millis()); delay.delay(500.millis());
let kbd = Keyboard { let kbd = Keyboard {
gpio0: io.pins.gpio0, rows: Rows {
gpio1: io.pins.gpio1, gpio2: Input::new(io.pins.gpio2, Pull::Up),
gpio2: io.pins.gpio2, gpio3: Input::new(io.pins.gpio3, Pull::Up),
gpio3: io.pins.gpio3, gpio4: Input::new(io.pins.gpio4, Pull::Up),
gpio4: io.pins.gpio4, gpio5: Input::new(io.pins.gpio5, Pull::Up),
gpio5: io.pins.gpio5, },
gpio6: io.pins.gpio6, cols: Cols {
gpio7: io.pins.gpio7, gpio6: Output::new(io.pins.gpio6, Level::Low),
gpio7: Output::new(io.pins.gpio7, Level::Low),
gpio8: Output::new(io.pins.gpio8, Level::Low),
gpio10: Output::new(io.pins.gpio10, Level::Low),
},
}; };
let mut ctx = Context { let mut ctx = Context {
button_pressed: None, button_pressed: None,
}; };
let mut app = Application::Menu(Menu::new()); let mut app = Application::Menu(Menu::new());
let mut trng = Trng::new(peripherals.RNG, peripherals.ADC1);
loop {
log::info!("Wake up!");
driver.wake_up().unwrap();
display.clear(TriColor::White); display.clear(TriColor::White);
app.draw(&mut display);
driver.full_update(&display).unwrap();
driver.sleep().unwrap();
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!");
driver.wake_up().unwrap();
display.clear(TriColor::White);
app.update(&ctx, &mut trng); app.update(&ctx, &mut trng);
app.draw(&mut display); app.draw(&mut display);
// TODO: try fast update?
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(100.millis()); delay.delay(300.millis());
} }
} }
@ -170,20 +181,51 @@ pub struct Context {
button_pressed: Option<Button>, button_pressed: Option<Button>,
} }
struct Keyboard { struct Rows<'d> {
gpio0: Gpio0, // gpio2: Input<'d, Gpio2>, //
gpio1: Gpio1, // gpio3: Input<'d, Gpio3>, //
gpio2: Gpio2, // gpio4: Input<'d, Gpio4>, //
gpio3: Gpio3, // gpio5: Input<'d, Gpio5>, //
//
gpio4: Gpio4, //
gpio5: Gpio5, //
gpio6: Gpio6, //
gpio7: Gpio7, //
} }
impl Keyboard { impl<'d> Rows<'d> {
pub fn states(&self) -> [bool; 4] {
[
self.gpio2.is_low(),
self.gpio3.is_low(),
self.gpio4.is_low(),
self.gpio5.is_low(),
]
}
}
struct Cols<'d> {
gpio6: Output<'d, Gpio6>, //
gpio7: Output<'d, Gpio7>, //
gpio8: Output<'d, Gpio8>, //
gpio10: Output<'d, Gpio10>, //
}
impl<'d> Cols<'d> {
pub fn states(&self) -> [bool; 4] {
[
self.gpio6.is_set_low(),
self.gpio7.is_set_low(),
self.gpio8.is_set_low(),
self.gpio10.is_set_low(),
]
}
}
struct Keyboard<'d> {
rows: Rows<'d>,
cols: Cols<'d>,
}
impl<'d> Keyboard<'d> {
pub fn pressed(&self) -> Option<Button> { pub fn pressed(&self) -> Option<Button> {
println!("***************************************");
println!("rows lows: {:?}", self.rows.states());
println!("cols lows: {:?}", self.cols.states());
None None
} }
} }