Created
November 22, 2023 18:24
-
-
Save noahbliss/958e144251b5819d959ad9793cef5475 to your computer and use it in GitHub Desktop.
esp-hal-nostd.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_std] | |
#![no_main] | |
#![feature(type_alias_impl_trait)] | |
use embassy_executor::Spawner; | |
use embassy_time::{Duration, Timer}; | |
use embedded_hal_async::digital::Wait; | |
use esp_backtrace as _; | |
use hal::{ | |
clock::ClockControl, | |
embassy::{self}, | |
gpio::*, | |
peripherals::Peripherals, | |
prelude::*, | |
IO, | |
}; | |
#[main] | |
async fn main(spawner: Spawner) -> ! { | |
esp_println::println!("Init!"); | |
let peripherals = Peripherals::take(); | |
let system = peripherals.SYSTEM.split(); | |
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); | |
{ | |
let timer_group0 = hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); | |
embassy::init(&clocks, timer_group0.timer0); | |
} | |
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); | |
// GPIO 0 as input | |
let mut input = io.pins.gpio0.into_pull_up_input().degrade(); | |
let mut output = io.pins.gpio2.into_push_pull_output().degrade(); | |
output.set_high().unwrap(); | |
// Async requires the GPIO interrupt to wake futures | |
hal::interrupt::enable( | |
hal::peripherals::Interrupt::GPIO, | |
hal::interrupt::Priority::Priority1, | |
) | |
.unwrap(); | |
spawner.spawn(run(input)).ok(); | |
loop { | |
esp_println::println!("nom"); | |
Timer::after(Duration::from_millis(1000)).await; | |
} | |
} | |
#[embassy_executor::task] | |
async fn run(mut input: AnyPin<Input<PullUp>>) { | |
//mut input: AnyPin<Input<PullDown>>) { | |
if input.is_low().unwrap() { | |
esp_println::println!("init low"); | |
} else { | |
esp_println::println!("init high"); | |
} | |
loop { | |
input.wait_for_any_edge().await.unwrap(); | |
if input.is_high().unwrap() { | |
esp_println::println!("hi hi high"); | |
} else if input.is_low().unwrap() { | |
esp_println::println!("low low low") | |
} else { | |
esp_println::println!("something else") | |
} | |
//Timer::after(Duration::from_millis(100)).await; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment