#![no_std]
#![no_main]
use esp_hal::{
clock::ClockControl,
peripherals::Peripherals,
gpio::*,
prelude::*,
systimer::SystemTimer,
timer::TimerGroup,
Rtc,
IO,
Delay,
};
use core::mem::MaybeUninit;
use alloc::string::String;
use keypad2::Keypad;
use esp_println::println;
use esp_backtrace as _;
extern crate alloc;
// === Global allocator for heap-based types (like String) ===
#[global_allocator]
static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty();
fn init_heap() {
const HEAP_SIZE: usize = 32 * 1024;
static mut HEAP: MaybeUninit<[u8; HEAP_SIZE]> = MaybeUninit::uninit();
unsafe {
// TODO: initialize the global allocator using the static heap above
todo!("Call `ALLOCATOR.init(...)` with correct pointer and size");
}
}
#[entry]
fn main() -> ! {
init_heap();
// === Take peripherals and configure system clocks ===
let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split();
// TODO: Set up the system clocks using `ClockControl` and freeze them
let clocks = todo!("Initialize and freeze system clocks");
// === Disable watchdog timers ===
// These are enabled by default on ESP chips and must be disabled
let mut rtc = Rtc::new(peripherals.LPWR);
let mut wdt0 = TimerGroup::new(peripherals.TIMG0, &clocks).wdt;
let mut wdt1 = TimerGroup::new(peripherals.TIMG1, &clocks).wdt;
// TODO: Disable all watchdog timers
todo!("Disable RWDT, WDT0, and WDT1");
// === Initialize delay handler ===
let mut delay = Delay::new(&clocks);
// === GPIO pin setup ===
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// === Initialize the Keypad ===
let mut keypad = Keypad::new( todo!("Initialize Keypad"));
// === Main loop: password entry logic ===
loop {
// TODO: Loop that reads the key input from the keypad.
// # for entering a number
// * for clearning the input
// When password is wrong -> display wrong + red led blinking
// When password is right -> display right + green led blinking
todo!();
}
}