diff --git a/Cargo.lock b/Cargo.lock index 3764ad5..bbe00bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,6 +340,27 @@ dependencies = [ "void", ] +[[package]] +name = "embedded-layout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7adbc16ba694006a121bce08a8935186d16cb008a4c9e20c5e346517ad1e0ac8" +dependencies = [ + "embedded-graphics", + "embedded-layout-macros", +] + +[[package]] +name = "embedded-layout-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "352186cee85e4cf9104c42b4dfd0295a22901c5d2bf0c26efd47265adcf1c52d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "embedded-sdmmc" version = "0.3.0" @@ -821,11 +842,13 @@ dependencies = [ "cfg-if", "embedded-graphics", "embedded-graphics-simulator", + "embedded-layout", "embedded-sdmmc", "embedded-text", "epd-waveshare", "maduino_zero_4g", "panic-halt", + "static_assertions", "tz-rs", "tzdb", ] diff --git a/Cargo.toml b/Cargo.toml index a067b98..ce5a626 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,13 @@ arrayvec = { version = "0.7.4", default_features = false } atsamd-hal = { version = "0.15.1", default_features = false, features = ["samd21g", "samd21g-rt", "usb"] } cfg-if = "1.0.0" embedded-graphics = "0.7.1" +embedded-layout = "0.2.0" embedded-text = "0.5.0" embedded-sdmmc = { version = "0.3.0", default_features = false } epd-waveshare = "0.5.0" maduino_zero_4g = { git = "https://github.com/ZettaScript/atsamd", branch = "maduino-zero-4g", features = ["usb"] } panic-halt = "0.2.0" +static_assertions = "1.1.0" tz-rs = { version = "0.6.14", default_features = false, features = ["const"] } tzdb = { version = "0.5.7", optional = true } diff --git a/README.md b/README.md index be8b40b..8d44bba 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,11 @@ GSM will be shutting down in France in a few years so if you have an old cellpho ## Install tools ```bash +# Choose one line depending on your distro sudo pacman -S arm-none-eabi-gcc +sudo apt install gcc-arm-none-eabi + +# Install Rust target rustup target add thumbv6m-none-eabi ``` diff --git a/src/apps/dial.rs b/src/apps/dial.rs index 234c037..7de9d86 100644 --- a/src/apps/dial.rs +++ b/src/apps/dial.rs @@ -69,6 +69,7 @@ impl App for Dial { } Key::OptionRight => { if mode_state.line.pop().is_some() { + // TODO redraw background over the erased character mode_state.line_changed = true; } else { return Some(ModeState::Clock(Default::default())); diff --git a/src/keypad.rs b/src/keypad.rs index c2300c6..dbaa953 100644 --- a/src/keypad.rs +++ b/src/keypad.rs @@ -69,8 +69,7 @@ impl Keypad { #[cfg(feature = "simulator")] fn get_keys(&self) -> [bool; NB_KEYS] { - use embedded_graphics_simulator::sdl2::Keycode; - use embedded_graphics_simulator::SimulatorEvent; + use embedded_graphics_simulator::{sdl2::Keycode, SimulatorEvent}; let mut keys = [false; NB_KEYS]; crate::display::window_mut() @@ -88,7 +87,7 @@ impl Keypad { Keycode::Num8 | Keycode::Kp8 => Some(Key::D8), Keycode::Num9 | Keycode::Kp9 => Some(Key::D9), Keycode::KpEnter | Keycode::Return => Some(Key::Enter), - Keycode::Asterisk => Some(Key::Asterisk), + Keycode::Asterisk | Keycode::KpMultiply => Some(Key::Asterisk), Keycode::Hash | Keycode::KpHash => Some(Key::Hash), // TODO more _ => None, @@ -148,19 +147,22 @@ impl KeyEvent { pub fn get_char(&self, key_input_mode: KeyInputMode) -> Option { use Key::*; match key_input_mode { - KeyInputMode::Digit => match self.key { - D0 => Some('0'), - D1 => Some('1'), - D2 => Some('2'), - D3 => Some('3'), - D4 => Some('4'), - D5 => Some('5'), - D6 => Some('6'), - D7 => Some('7'), - D8 => Some('8'), - D9 => Some('9'), - Asterisk => Some('*'), - Hash => Some('#'), + KeyInputMode::Digit => match (self.key, self.repeats) { + (D0, _) => Some('0'), + (D1, _) => Some('1'), + (D2, _) => Some('2'), + (D3, _) => Some('3'), + (D4, _) => Some('4'), + (D5, _) => Some('5'), + (D6, _) => Some('6'), + (D7, _) => Some('7'), + (D8, _) => Some('8'), + (D9, _) => Some('9'), + (Asterisk, 1) => Some('*'), + (Asterisk, 2) => Some('+'), + (Asterisk, 3) => Some('p'), + (Asterisk, 4) => Some('W'), + (Hash, _) => Some('#'), _ => None, }, _ => { diff --git a/src/main.rs b/src/main.rs index 859301a..0456869 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ mod gui; mod keypad; mod state; mod strf; +mod text_input; mod time; use apps::App; @@ -21,7 +22,10 @@ use state::*; use arrayvec::ArrayString; use core::fmt::Write; use embedded_graphics::{ - mono_font::{ascii::FONT_10X20, ascii::FONT_6X10, ascii::FONT_9X15, MonoTextStyleBuilder}, + mono_font::{ + ascii::{FONT_10X20, FONT_6X10, FONT_9X15}, + MonoTextStyleBuilder, + }, pixelcolor::BinaryColor, prelude::*, primitives::{Line, PrimitiveStyle, PrimitiveStyleBuilder, Rectangle, StrokeAlignment}, @@ -41,6 +45,22 @@ use maduino_zero_4g::{ use panic_halt as _; use tz::DateTime; +// Check that stack overflow is unlikely +#[cfg(not(feature = "simulator"))] +static_assertions::const_assert!( + core::mem::size_of::<( + State, + ModeState, + Peripherals, + maduino_zero_4g::Pins, + CorePeripherals, + keypad::Keypad, + Display, + Context, + fs::Fs, + )>() < 16 * 1024 +); + #[cfg_attr(not(feature = "simulator"), bsp::entry)] fn main() -> ! { cfg_if::cfg_if! { diff --git a/src/text_input.rs b/src/text_input.rs new file mode 100644 index 0000000..4e73609 --- /dev/null +++ b/src/text_input.rs @@ -0,0 +1,6 @@ +use arrayvec::ArrayString; + +pub struct TextInput { + cursor: usize, + value: ArrayString, +}