Fix menu
This commit is contained in:
parent
c1144d58a3
commit
aad0ccef4e
49
Cargo.lock
generated
49
Cargo.lock
generated
@ -183,7 +183,7 @@ checksum = "f86b9ec30048b1955da2038fcc3c017f419ab21bb0001879d16c0a3749dc6b7a"
|
||||
dependencies = [
|
||||
"byte-slice-cast",
|
||||
"display-interface",
|
||||
"embedded-hal",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
]
|
||||
|
||||
@ -202,7 +202,7 @@ version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9d2e857f87ac832df68fa498d18ddc679175cf3d2e4aa893988e5601baf9438"
|
||||
dependencies = [
|
||||
"nb",
|
||||
"nb 1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -237,6 +237,16 @@ dependencies = [
|
||||
"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]]
|
||||
name = "embedded-hal"
|
||||
version = "1.0.0"
|
||||
@ -249,7 +259,7 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c4c685bbef7fe13c3c6dd4da26841ed3980ef33e841cddfa15ce8a8fb3f1884"
|
||||
dependencies = [
|
||||
"embedded-hal",
|
||||
"embedded-hal 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -259,7 +269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d3980bf28e8577db59fe2bdb3df868a419469d2cecb363644eea2b6f7797669"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"embedded-hal",
|
||||
"embedded-hal 1.0.0",
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
@ -269,8 +279,8 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fba4268c14288c828995299e59b12babdbe170f6c6d73731af1b4648142e8605"
|
||||
dependencies = [
|
||||
"embedded-hal",
|
||||
"nb",
|
||||
"embedded-hal 1.0.0",
|
||||
"nb 1.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -349,7 +359,7 @@ dependencies = [
|
||||
"document-features",
|
||||
"embedded-can",
|
||||
"embedded-dma",
|
||||
"embedded-hal",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-nb",
|
||||
"enumset",
|
||||
"esp-build",
|
||||
@ -358,7 +368,7 @@ dependencies = [
|
||||
"esp-riscv-rt",
|
||||
"esp32c6",
|
||||
"fugit",
|
||||
"nb",
|
||||
"nb 1.1.0",
|
||||
"paste",
|
||||
"portable-atomic",
|
||||
"rand_core",
|
||||
@ -523,6 +533,15 @@ dependencies = [
|
||||
"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]]
|
||||
name = "kinded"
|
||||
version = "0.3.0"
|
||||
@ -619,6 +638,15 @@ dependencies = [
|
||||
"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]]
|
||||
name = "nb"
|
||||
version = "1.1.0"
|
||||
@ -783,6 +811,7 @@ dependencies = [
|
||||
"esp-hal",
|
||||
"esp-println",
|
||||
"heapless",
|
||||
"keypad",
|
||||
"log",
|
||||
"maze",
|
||||
"nutype",
|
||||
@ -829,7 +858,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f5c1b8bf41ea746266cdee443d1d1e9125c86ce1447e1a2615abd34330d33a9"
|
||||
dependencies = [
|
||||
"critical-section",
|
||||
"embedded-hal",
|
||||
"embedded-hal 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1068,7 +1097,7 @@ checksum = "3e531b21e70dfc6294be2429e4f616f634c8ca1a328325dceefc4f92c12d6e9b"
|
||||
dependencies = [
|
||||
"display-interface",
|
||||
"embedded-graphics",
|
||||
"embedded-hal",
|
||||
"embedded-hal 1.0.0",
|
||||
"embedded-hal-async",
|
||||
"maybe-async-cfg",
|
||||
"sealed",
|
||||
|
@ -9,7 +9,7 @@ embedded-graphics = "0.8.1"
|
||||
embedded-hal-bus = "0.2.0"
|
||||
esp-backtrace = { version = "0.13.0", features = ["esp32c6", "exception-handler", "panic-handler", "println"] }
|
||||
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"
|
||||
log = { version = "0.4.21" }
|
||||
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'] }
|
||||
maze = { path = "./maze" }
|
||||
strum = { version = "0.26.3", default-features = false, features = ["derive"] }
|
||||
keypad = "0.2.2"
|
||||
|
||||
[profile.dev]
|
||||
# Rust debug is too slow.
|
||||
|
13
espflash.toml
Normal file
13
espflash.toml
Normal 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
5
partitions.csv
Normal 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,7 +1,7 @@
|
||||
use crate::Button;
|
||||
|
||||
use super::*;
|
||||
use profont::PROFONT_24_POINT;
|
||||
use profont::PROFONT_18_POINT;
|
||||
use strum::IntoEnumIterator;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, strum::EnumIter)]
|
||||
@ -21,8 +21,8 @@ impl MenuEntry {
|
||||
|
||||
fn position(&self) -> Point {
|
||||
match self {
|
||||
MenuEntry::Labirynth => Point::new(8, 68),
|
||||
MenuEntry::Pairs => Point::new(38, 68),
|
||||
MenuEntry::Labirynth => Point::new(20, 38),
|
||||
MenuEntry::Pairs => Point::new(20, 68),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,10 +69,21 @@ impl App for Menu {
|
||||
}
|
||||
|
||||
fn draw(&self, display: &mut Display290TriColor) {
|
||||
let style = MonoTextStyle::new(&PROFONT_24_POINT, TriColor::Black);
|
||||
let selected_style = MonoTextStyle::new(&PROFONT_24_POINT, TriColor::Red);
|
||||
let style = MonoTextStyle::new(&PROFONT_18_POINT, TriColor::Black);
|
||||
let selected_style = MonoTextStyle::new(&PROFONT_18_POINT, TriColor::Red);
|
||||
|
||||
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(
|
||||
entry.as_str(),
|
||||
entry.position(),
|
||||
|
124
src/main.rs
124
src/main.rs
@ -15,7 +15,7 @@ use esp_hal::{
|
||||
clock::ClockControl,
|
||||
delay::Delay,
|
||||
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,
|
||||
},
|
||||
peripherals::Peripherals,
|
||||
@ -24,6 +24,8 @@ use esp_hal::{
|
||||
spi::{master::Spi, SpiMode},
|
||||
system::SystemControl,
|
||||
};
|
||||
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};
|
||||
@ -37,16 +39,16 @@ fn main() -> ! {
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let clocks = ClockControl::max(system.clock_control).freeze();
|
||||
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...");
|
||||
|
||||
// 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 cs = io.pins.gpio20; // D9 / GPIO20
|
||||
let dc = io.pins.gpio21; // D3 / GPIO21
|
||||
@ -75,62 +77,71 @@ fn main() -> ! {
|
||||
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)");
|
||||
|
||||
// Setup EPD
|
||||
log::info!("Intializing EPD...");
|
||||
let mut driver = WeActStudio290TriColorDriver::new(spi_interface, busy, rst, delay);
|
||||
let mut display = Display290TriColor::new();
|
||||
display.set_rotation(DisplayRotation::Rotate90);
|
||||
log::info!("Driver init...");
|
||||
driver.init().unwrap();
|
||||
log::info!("Intializing EPD (DONE)");
|
||||
|
||||
let style = MonoTextStyle::new(&PROFONT_24_POINT, TriColor::Black);
|
||||
let _ = Text::with_text_style(
|
||||
"Welcome in Reddy",
|
||||
Point::new(8, 68),
|
||||
style,
|
||||
TextStyle::default(),
|
||||
)
|
||||
.draw(&mut display);
|
||||
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)");
|
||||
|
||||
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...");
|
||||
driver.sleep().unwrap();
|
||||
delay.delay(500.millis());
|
||||
|
||||
let kbd = Keyboard {
|
||||
gpio0: io.pins.gpio0,
|
||||
gpio1: io.pins.gpio1,
|
||||
gpio2: io.pins.gpio2,
|
||||
gpio3: io.pins.gpio3,
|
||||
gpio4: io.pins.gpio4,
|
||||
gpio5: io.pins.gpio5,
|
||||
gpio6: io.pins.gpio6,
|
||||
gpio7: io.pins.gpio7,
|
||||
rows: Rows {
|
||||
gpio2: Input::new(io.pins.gpio2, Pull::Up),
|
||||
gpio3: Input::new(io.pins.gpio3, Pull::Up),
|
||||
gpio4: Input::new(io.pins.gpio4, Pull::Up),
|
||||
gpio5: Input::new(io.pins.gpio5, Pull::Up),
|
||||
},
|
||||
cols: Cols {
|
||||
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 {
|
||||
button_pressed: None,
|
||||
};
|
||||
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();
|
||||
|
||||
loop {
|
||||
log::info!("Wake up!");
|
||||
driver.wake_up().unwrap();
|
||||
|
||||
display.clear(TriColor::White);
|
||||
|
||||
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);
|
||||
// TODO: try fast update?
|
||||
driver.full_update(&display).unwrap();
|
||||
}
|
||||
|
||||
log::info!("Sleeping for 100ms...");
|
||||
driver.sleep().unwrap();
|
||||
delay.delay(100.millis());
|
||||
delay.delay(300.millis());
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,20 +181,51 @@ pub struct Context {
|
||||
button_pressed: Option<Button>,
|
||||
}
|
||||
|
||||
struct Keyboard {
|
||||
gpio0: Gpio0, //
|
||||
gpio1: Gpio1, //
|
||||
gpio2: Gpio2, //
|
||||
gpio3: Gpio3, //
|
||||
//
|
||||
gpio4: Gpio4, //
|
||||
gpio5: Gpio5, //
|
||||
gpio6: Gpio6, //
|
||||
gpio7: Gpio7, //
|
||||
struct Rows<'d> {
|
||||
gpio2: Input<'d, Gpio2>, //
|
||||
gpio3: Input<'d, Gpio3>, //
|
||||
gpio4: Input<'d, Gpio4>, //
|
||||
gpio5: Input<'d, Gpio5>, //
|
||||
}
|
||||
|
||||
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> {
|
||||
println!("***************************************");
|
||||
println!("rows lows: {:?}", self.rows.states());
|
||||
println!("cols lows: {:?}", self.cols.states());
|
||||
None
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user