no pulldown + simplify + no watchdog

This commit is contained in:
okhsunrog 2024-08-08 23:41:20 +03:00
parent 05b468e8ba
commit 527b54b1d6

View file

@ -6,24 +6,33 @@ use defmt::info;
use defmt_rtt as _;
use embassy_executor::Spawner;
use embassy_futures::select::{select, Either};
use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::{GpioPin, Input, Io, Pull},
peripherals::Peripherals,
prelude::*,
rtc_cntl::Rtc,
system::SystemControl,
timer::{timg::TimerGroup, OneShotTimer},
};
use static_cell::make_static;
#[embassy_executor::task]
async fn monitor_pins(
mut input4: Input<'static, GpioPin<4>>,
mut input5: Input<'static, GpioPin<5>>,
) {
#[main]
async fn main(_spawner: Spawner) {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
// Initialize the SYSTIMER peripheral, and then Embassy:
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks, None);
let timers = make_static!([OneShotTimer::new(timg0.timer0.into())]);
esp_hal_embassy::init(&clocks, timers);
info!("Embassy initialized!");
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let mut input4: Input<GpioPin<4>> = Input::new(io.pins.gpio4, Pull::None);
let mut input5: Input<GpioPin<5>> = Input::new(io.pins.gpio5, Pull::None);
loop {
match select(input4.wait_for_rising_edge(), input5.wait_for_rising_edge()).await {
Either::First(_) => info!("Rising edge detected on Pin 4!"),
@ -31,35 +40,3 @@ async fn monitor_pins(
}
}
}
#[main]
async fn main(spawner: Spawner) {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
// Enable the RWDT watchdog timer:
let mut rtc = Rtc::new(peripherals.LPWR, None);
rtc.rwdt.set_timeout(2.secs());
rtc.rwdt.enable();
info!("RWDT watchdog enabled!");
// Initialize the SYSTIMER peripheral, and then Embassy:
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks, None);
let timers = [OneShotTimer::new(timg0.timer0.into())];
let timers = make_static!(timers);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let input4: Input<GpioPin<4>> = Input::new(io.pins.gpio4, Pull::Down);
let input5: Input<GpioPin<5>> = Input::new(io.pins.gpio5, Pull::Down);
esp_hal_embassy::init(&clocks, timers);
info!("Embassy initialized!");
spawner.spawn(monitor_pins(input4, input5)).unwrap();
// Periodically feed the RWDT watchdog timer when our tasks are not running:
loop {
rtc.rwdt.feed();
Timer::after(Duration::from_secs(1)).await;
}
}