rtic/examples/esp32c3/examples/sw_and_hw.rs
Jesse Braham 1f6b6a42e5
Update support/example for ESP32-C3 to use latest versions of dependencies (#975)
* Update `rtic` package to use latest version of `esp32c3` dependency

* Update `rtic-macros` ESP32-C3 bindings to reflect changes in HAL

* Update the ESP32-C3 examples to use latest versions of all dependencies

* Update changelogs

* adjust expected qemu output, add compile-time checks

* remove runtime checks, this is checked at compile time

* fix expected qemu output

* Clean up interrupt enable code a bit

* Update `rtic-monotonic` to use the latest PAC for ESP32-C3

* Update `CHANGELOG.md` for `rtic-monotonic`

* ci: esp32c3: Format runner.sh

* ci: esp32c3: Default to silent boot

export DEBUGGING while running to get verbose boot

env DEBUGGING=1 cargo xtask ...

* ci: esp32c3: Update expected example output

---------

Co-authored-by: onsdagens <pawdzi-7@student.ltu.se>
Co-authored-by: Henrik Tjäder <henrik@tjaders.com>
2024-10-16 19:29:51 +00:00

66 lines
1.7 KiB
Rust

#![no_main]
#![no_std]
#[rtic::app(device = esp32c3, dispatchers=[FROM_CPU_INTR0, FROM_CPU_INTR1])]
mod app {
use esp_backtrace as _;
use esp_hal::{
gpio::{Event, GpioPin, Input, Io, Pull},
peripherals::Peripherals,
};
use esp_println::println;
#[shared]
struct Shared {}
#[local]
struct Local {
button: Input<'static, GpioPin<9>>,
}
// do nothing in init
#[init]
fn init(_: init::Context) -> (Shared, Local) {
println!("init");
let peripherals = Peripherals::take();
let io = Io::new_no_bind_interrupt(peripherals.GPIO, peripherals.IO_MUX);
let mut button = Input::new(io.pins.gpio9, Pull::Up);
button.listen(Event::FallingEdge);
foo::spawn().unwrap();
(Shared {}, Local { button })
}
#[idle]
fn idle(_: idle::Context) -> ! {
println!("idle");
loop {}
}
#[task(priority = 5)]
async fn foo(_: foo::Context) {
bar::spawn().unwrap(); //enqueue low prio task
println!("Inside high prio task, press button now!");
let mut x = 0;
while x < 5000000 {
x += 1; //burn cycles
esp_hal::riscv::asm::nop();
}
println!("Leaving high prio task.");
}
#[task(priority = 2)]
async fn bar(_: bar::Context) {
println!("Inside low prio task, press button now!");
let mut x = 0;
while x < 5000000 {
x += 1; //burn cycles
esp_hal::riscv::asm::nop();
}
println!("Leaving low prio task.");
}
#[task(binds=GPIO, local=[button], priority = 3)]
fn gpio_handler(cx: gpio_handler::Context) {
cx.local.button.clear_interrupt();
println!("button");
}
}