mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 14:44:42 +00:00

* Separate TIMG into timer0, (timer1), wdt * Apply suggestions from code review * Remove left-over code * Ignore settings.json
51 lines
1.3 KiB
Rust
51 lines
1.3 KiB
Rust
#![no_std]
|
|
#![no_main]
|
|
|
|
use esp32c3_hal::{
|
|
clock::ClockControl,
|
|
gpio::IO,
|
|
pac::Peripherals,
|
|
prelude::*,
|
|
system::SystemExt,
|
|
timer::TimerGroup,
|
|
Delay,
|
|
RtcCntl,
|
|
};
|
|
use panic_halt as _;
|
|
use riscv_rt::entry;
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let peripherals = Peripherals::take().unwrap();
|
|
let system = peripherals.SYSTEM.split();
|
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
// Disable the watchdog timers. For the ESP32-C3, this includes the Super WDT,
|
|
// the RTC WDT, and the TIMG WDTs.
|
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
|
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
|
let mut wdt0 = timer_group0.wdt;
|
|
let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks);
|
|
let mut wdt1 = timer_group1.wdt;
|
|
|
|
rtc_cntl.set_super_wdt_enable(false);
|
|
rtc_cntl.set_wdt_enable(false);
|
|
wdt0.disable();
|
|
wdt1.disable();
|
|
|
|
// Set GPIO5 as an output, and set its state high initially.
|
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
let mut led = io.pins.gpio5.into_push_pull_output();
|
|
|
|
led.set_high().unwrap();
|
|
|
|
// Initialize the Delay peripheral, and use it to toggle the LED state in a
|
|
// loop.
|
|
let mut delay = Delay::new(&clocks);
|
|
|
|
loop {
|
|
led.toggle().unwrap();
|
|
delay.delay_ms(500u32);
|
|
}
|
|
}
|