pins probing is implemented

This commit is contained in:
okhsunrog 2024-08-08 23:17:14 +03:00
parent 17f2a44845
commit 6f3cab346d
9 changed files with 158 additions and 3 deletions

5
.idea/.gitignore generated vendored Normal file
View file

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

100
.idea/cody_history.xml generated Normal file
View file

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChatHistory">
<accountData>
<list>
<AccountData>
<accountId value="VXNlcjo0Njg3MzE=" />
<chats>
<list>
<chat>
<internalId value="44262a20-1f6b-41d9-aef0-8466b8eff72f" />
</chat>
<chat>
<internalId value="1e10fa7b-7b50-4f4e-ae21-6d0d0096da27" />
<messages>
<list>
<message>
<speaker value="HUMAN" />
<text value="create 2 tasks (for pin 4 and for pin 5), each one should await for rising edge and print info log when it detects one" />
</message>
<message>
<speaker value="ASSISTANT" />
<text value="Certainly! I'll create two tasks for pins 4 and 5 that await rising edges and print info logs when detected. Here's how we can modify the code to achieve this:&#10;&#10;1. First, let's add the necessary imports:&#10;&#10;```rust&#10;use esp_hal::{gpio::{Gpio4, Gpio5, Input, PullDown}, interrupt};&#10;use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;&#10;use embassy_sync::signal::Signal;&#10;```&#10;&#10;2. Now, let's define our task functions:&#10;&#10;```rust&#10;static SIGNAL_PIN4: Signal&lt;CriticalSectionRawMutex, ()&gt; = Signal::new();&#10;static SIGNAL_PIN5: Signal&lt;CriticalSectionRawMutex, ()&gt; = Signal::new();&#10;&#10;#[embassy_executor::task]&#10;async fn monitor_pin4() {&#10; loop {&#10; SIGNAL_PIN4.wait().await;&#10; info!(&quot;Rising edge detected on Pin 4!&quot;);&#10; }&#10;}&#10;&#10;#[embassy_executor::task]&#10;async fn monitor_pin5() {&#10; loop {&#10; SIGNAL_PIN5.wait().await;&#10; info!(&quot;Rising edge detected on Pin 5!&quot;);&#10; }&#10;}&#10;```&#10;&#10;3. In the `main` function, let's set up the GPIO pins and spawn the tasks:&#10;&#10;```rust&#10;#[main]&#10;async fn main(spawner: Spawner) {&#10; // ... (existing code)&#10;&#10; // Set up GPIO pins&#10; let io = esp_hal::gpio::IO::new(peripherals.GPIO, peripherals.IO_MUX);&#10; let mut pin4 = io.pins.gpio4.into_pull_down_input();&#10; let mut pin5 = io.pins.gpio5.into_pull_down_input();&#10;&#10; pin4.listen(interrupt::InterruptType::PosEdge);&#10; pin5.listen(interrupt::InterruptType::PosEdge);&#10;&#10; // Spawn tasks&#10; spawner.spawn(monitor_pin4()).unwrap();&#10; spawner.spawn(monitor_pin5()).unwrap();&#10;&#10; // ... (existing code)&#10;}&#10;```&#10;&#10;4. Finally, let's add interrupt handlers:&#10;&#10;```rust&#10;#[interrupt]&#10;fn GPIO() {&#10; let io = unsafe { esp_hal::gpio::IO::new(Peripherals::steal().GPIO, Peripherals::steal().IO_MUX) };&#10; &#10; if io.pins.gpio4.is_interrupt_set() {&#10; io.pins.gpio4.clear_interrupt();&#10; SIGNAL_PIN4.signal(());&#10; }&#10; &#10; if io.pins.gpio5.is_interrupt_set() {&#10; io.pins.gpio5.clear_interrupt();&#10; SIGNAL_PIN5.signal(());&#10; }&#10;}&#10;```&#10;&#10;These changes will create two tasks that monitor pins 4 and 5 for rising edges and print info logs when detected. The tasks are spawned in the `main` function, and the GPIO interrupt handler signals the appropriate task when a rising edge is detected on either pin." />
</message>
<message>
<speaker value="HUMAN" />
<text value="we don't actually need embassy_sync, critical sectiona and manual interrupts, the driver does all of that for us. look, we can work with gpio inputs as simple as that:&#10;&#10;//! embassy wait&#10;//!&#10;//! This is an example of asynchronously `Wait`ing for a pin state (boot button) to change.&#10;&#10;//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3&#10;//% FEATURES: async embassy embassy-generic-timers&#10;&#10;#![no_std]&#10;#![no_main]&#10;&#10;use embassy_executor::Spawner;&#10;use embassy_time::{Duration, Timer};&#10;use esp_backtrace as _;&#10;use esp_hal::{&#10; clock::ClockControl,&#10; gpio::{Input, Io, Pull},&#10; peripherals::Peripherals,&#10; system::SystemControl,&#10; timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},&#10;};&#10;&#10;// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html&#10;macro_rules! mk_static {&#10; ($t:ty,$val:expr) =&amp;gt; {{&#10; static STATIC_CELL: static_cell::StaticCell&amp;lt;$t&amp;gt; = static_cell::StaticCell::new();&#10; #[deny(unused_attributes)]&#10; let x = STATIC_CELL.uninit().write(($val));&#10; x&#10; }};&#10;}&#10;&#10;#[esp_hal_embassy::main]&#10;async fn main(_spawner: Spawner) {&#10; esp_println::println!(&amp;quot;Init!&amp;quot;);&#10; let peripherals = Peripherals::take();&#10; let system = SystemControl::new(peripherals.SYSTEM);&#10; let clocks = ClockControl::boot_defaults(system.clock_control).freeze();&#10;&#10; let timg0 = TimerGroup::new(peripherals.TIMG0, &amp;amp;clocks);&#10; let timer0: ErasedTimer = timg0.timer0.into();&#10; let timers = [OneShotTimer::new(timer0)];&#10; let timers = mk_static!([OneShotTimer&amp;lt;ErasedTimer&amp;gt;; 1], timers);&#10; esp_hal_embassy::init(&amp;amp;clocks, timers);&#10;&#10; let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);&#10; #[cfg(any(feature = &amp;quot;esp32&amp;quot;, feature = &amp;quot;esp32s2&amp;quot;, feature = &amp;quot;esp32s3&amp;quot;))]&#10; let mut input = Input::new(io.pins.gpio0, Pull::Down);&#10; #[cfg(not(any(feature = &amp;quot;esp32&amp;quot;, feature = &amp;quot;esp32s2&amp;quot;, feature = &amp;quot;esp32s3&amp;quot;)))]&#10; let mut input = Input::new(io.pins.gpio9, Pull::Down);&#10;&#10; loop {&#10; esp_println::println!(&amp;quot;Waiting...&amp;quot;);&#10; input.wait_for_rising_edge().await;&#10; esp_println::println!(&amp;quot;Ping!&amp;quot;);&#10; Timer::after(Duration::from_millis(100)).await;&#10; }&#10;}" />
</message>
<message>
<speaker value="ASSISTANT" />
</message>
<message>
<speaker value="HUMAN" />
<text value="we don't actually need embassy_sync, critical sectiona and manual interrupts, the driver does all of that for us. look, we can work with gpio inputs as simple as that:&#10;&#10;//! embassy wait&#10;//!&#10;//! This is an example of asynchronously `Wait`ing for a pin state (boot button) to change.&#10;&#10;//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3&#10;//% FEATURES: async embassy embassy-generic-timers&#10;&#10;#![no_std]&#10;#![no_main]&#10;&#10;use embassy_executor::Spawner;&#10;use embassy_time::{Duration, Timer};&#10;use esp_backtrace as _;&#10;use esp_hal::{&#10; clock::ClockControl,&#10; gpio::{Input, Io, Pull},&#10; peripherals::Peripherals,&#10; system::SystemControl,&#10; timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},&#10;};&#10;&#10;// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html&#10;macro_rules! mk_static {&#10; ($t:ty,$val:expr) =&amp;gt; {{&#10; static STATIC_CELL: static_cell::StaticCell&amp;lt;$t&amp;gt; = static_cell::StaticCell::new();&#10; #[deny(unused_attributes)]&#10; let x = STATIC_CELL.uninit().write(($val));&#10; x&#10; }};&#10;}&#10;&#10;#[esp_hal_embassy::main]&#10;async fn main(_spawner: Spawner) {&#10; esp_println::println!(&amp;quot;Init!&amp;quot;);&#10; let peripherals = Peripherals::take();&#10; let system = SystemControl::new(peripherals.SYSTEM);&#10; let clocks = ClockControl::boot_defaults(system.clock_control).freeze();&#10;&#10; let timg0 = TimerGroup::new(peripherals.TIMG0, &amp;amp;clocks);&#10; let timer0: ErasedTimer = timg0.timer0.into();&#10; let timers = [OneShotTimer::new(timer0)];&#10; let timers = mk_static!([OneShotTimer&amp;lt;ErasedTimer&amp;gt;; 1], timers);&#10; esp_hal_embassy::init(&amp;amp;clocks, timers);&#10;&#10; let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);&#10; #[cfg(any(feature = &amp;quot;esp32&amp;quot;, feature = &amp;quot;esp32s2&amp;quot;, feature = &amp;quot;esp32s3&amp;quot;))]&#10; let mut input = Input::new(io.pins.gpio0, Pull::Down);&#10; #[cfg(not(any(feature = &amp;quot;esp32&amp;quot;, feature = &amp;quot;esp32s2&amp;quot;, feature = &amp;quot;esp32s3&amp;quot;)))]&#10; let mut input = Input::new(io.pins.gpio9, Pull::Down);&#10;&#10; loop {&#10; esp_println::println!(&amp;quot;Waiting...&amp;quot;);&#10; input.wait_for_rising_edge().await;&#10; esp_println::println!(&amp;quot;Ping!&amp;quot;);&#10; Timer::after(Duration::from_millis(100)).await;&#10; }&#10;}&#10;" />
</message>
<message>
<speaker value="ASSISTANT" />
</message>
<message>
<speaker value="HUMAN" />
<text value="we don't actually need embassy_sync, critical sectiona and manual interrupts, the driver does all of that for us. look, we can work with gpio inputs as simple as that&#10;&#10;#![no_std]&#10;#![no_main]&#10;&#10;use embassy_executor::Spawner;&#10;use embassy_time::{Duration, Timer};&#10;use esp_backtrace as _;&#10;use esp_hal::{&#10; clock::ClockControl,&#10; gpio::{Input, Io, Pull},&#10; peripherals::Peripherals,&#10; system::SystemControl,&#10; timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},&#10;};&#10;&#10;// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html&#10;macro_rules! mk_static {&#10; ($t:ty,$val:expr) =&amp;gt; {{&#10; static STATIC_CELL: static_cell::StaticCell&amp;lt;$t&amp;gt; = static_cell::StaticCell::new();&#10; #[deny(unused_attributes)]&#10; let x = STATIC_CELL.uninit().write(($val));&#10; x&#10; }};&#10;}&#10;&#10;#[esp_hal_embassy::main]&#10;async fn main(_spawner: Spawner) {&#10; esp_println::println!(&amp;quot;Init!&amp;quot;);&#10; let peripherals = Peripherals::take();&#10; let system = SystemControl::new(peripherals.SYSTEM);&#10; let clocks = ClockControl::boot_defaults(system.clock_control).freeze();&#10;&#10; let timg0 = TimerGroup::new(peripherals.TIMG0, &amp;amp;clocks);&#10; let timer0: ErasedTimer = timg0.timer0.into();&#10; let timers = [OneShotTimer::new(timer0)];&#10; let timers = mk_static!([OneShotTimer&amp;lt;ErasedTimer&amp;gt;; 1], timers);&#10; esp_hal_embassy::init(&amp;amp;clocks, timers);&#10;&#10; let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);&#10; #[cfg(any(feature = &amp;quot;esp32&amp;quot;, feature = &amp;quot;esp32s2&amp;quot;, feature = &amp;quot;esp32s3&amp;quot;))]&#10; let mut input = Input::new(io.pins.gpio0, Pull::Down);&#10; #[cfg(not(any(feature = &amp;quot;esp32&amp;quot;, feature = &amp;quot;esp32s2&amp;quot;, feature = &amp;quot;esp32s3&amp;quot;)))]&#10; let mut input = Input::new(io.pins.gpio9, Pull::Down);&#10;&#10; loop {&#10; esp_println::println!(&amp;quot;Waiting...&amp;quot;);&#10; input.wait_for_rising_edge().await;&#10; esp_println::println!(&amp;quot;Ping!&amp;quot;);&#10; Timer::after(Duration::from_millis(100)).await;&#10; }&#10;}&#10;" />
</message>
<message>
<speaker value="ASSISTANT" />
<text value="You're absolutely right! The esp-hal driver indeed provides a much simpler way to work with GPIO inputs, including built-in support for awaiting rising edges. This approach is cleaner and more straightforward. Let's implement the two tasks for pins 4 and 5 using this simpler method:&#10;&#10;```rust&#10;use embassy_executor::Spawner;&#10;use embassy_time::{Duration, Timer};&#10;use esp_backtrace as _;&#10;use esp_hal::{&#10; clock::ClockControl,&#10; gpio::{Input, Io, Pull},&#10; peripherals::Peripherals,&#10; system::SystemControl,&#10; timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},&#10;};&#10;&#10;#[embassy_executor::task]&#10;async fn monitor_pin4(mut input: Input&lt;'static&gt;) {&#10; loop {&#10; input.wait_for_rising_edge().await;&#10; esp_println::println!(&quot;Rising edge detected on Pin 4!&quot;);&#10; Timer::after(Duration::from_millis(100)).await;&#10; }&#10;}&#10;&#10;#[embassy_executor::task]&#10;async fn monitor_pin5(mut input: Input&lt;'static&gt;) {&#10; loop {&#10; input.wait_for_rising_edge().await;&#10; esp_println::println!(&quot;Rising edge detected on Pin 5!&quot;);&#10; Timer::after(Duration::from_millis(100)).await;&#10; }&#10;}&#10;&#10;#[esp_hal_embassy::main]&#10;async fn main(spawner: Spawner) {&#10; esp_println::println!(&quot;Init!&quot;);&#10; let peripherals = Peripherals::take();&#10; let system = SystemControl::new(peripherals.SYSTEM);&#10; let clocks = ClockControl::boot_defaults(system.clock_control).freeze();&#10;&#10; let timg0 = TimerGroup::new(peripherals.TIMG0, &amp;clocks);&#10; let timer0: ErasedTimer = timg0.timer0.into();&#10; let timers = [OneShotTimer::new(timer0)];&#10; let timers = mk_static!([OneShotTimer&lt;ErasedTimer&gt;; 1], timers);&#10; esp_hal_embassy::init(&amp;clocks, timers);&#10;&#10; let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);&#10; let input4 = Input::new(io.pins.gpio4, Pull::Down);&#10; let input5 = Input::new(io.pins.gpio5, Pull::Down);&#10;&#10; spawner.spawn(monitor_pin4(input4)).unwrap();&#10; spawner.spawn(monitor_pin5(input5)).unwrap();&#10;&#10; loop {&#10; Timer::after(Duration::from_secs(1)).await;&#10; }&#10;}&#10;```&#10;&#10;This implementation is indeed much simpler and more elegant. It uses the built-in `wait_for_rising_edge()` method provided by the esp-hal driver, eliminating the need for manual interrupt handling and synchronization primitives. The tasks are spawned in the main function, each monitoring its respective pin for rising edges." />
</message>
<message>
<speaker value="HUMAN" />
<text value="help me fix this:&#10;&#10;error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied&#10; --&amp;gt; src/main.rs:26:34&#10; |&#10;26 | async fn monitor_pin4(mut input: Input&amp;lt;'static&amp;gt;) {&#10; | ^^^^^ expected 1 generic argument&#10; |&#10;note: struct defined here, with 1 generic parameter: `P`&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-hal-0.19.0/src/gpio/mod.rs:1673:12&#10; |&#10;1673 | pub struct Input&amp;lt;'d, P&amp;gt; {&#10; | ^^^^^ -&#10;help: add missing generic argument&#10; |&#10;26 | async fn monitor_pin4(mut input: Input&amp;lt;'static, P&amp;gt;) {&#10; | +++&#10;&#10;error[E0308]: mismatched types&#10; --&amp;gt; src/main.rs:43:1&#10; |&#10;43 | #[main]&#10; | ^^^^^^^&#10; | |&#10; | expected `Spawner`, found `embassy_executor::spawner::Spawner`&#10; | arguments to this function are incorrect&#10; |&#10; = note: `embassy_executor::spawner::Spawner` and `Spawner` have similar names, but are actually distinct types&#10;note: `embassy_executor::spawner::Spawner` is defined in crate `embassy_executor`&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.5.0/src/spawner.rs:71:1&#10; |&#10;71 | pub struct Spawner {&#10; | ^^^^^^^^^^^^^^^^^^&#10;note: `Spawner` is defined in crate `embassy_executor`&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.6.0/src/spawner.rs:71:1&#10; |&#10;71 | pub struct Spawner {&#10; | ^^^^^^^^^^^^^^^^^^&#10; = note: perhaps two different versions of crate `embassy_executor` are being used?&#10;note: function defined here&#10; --&amp;gt; src/main.rs:43:1&#10; |&#10;43 | #[main]&#10; | ^^^^^^^&#10;44 | async fn main(spawner: Spawner) {&#10; | ----------------&#10; = note: this error originates in the attribute macro `main` (in Nightly builds, run with -Z macro-backtrace for more info)&#10;&#10;error[E0308]: mismatched types&#10; --&amp;gt; src/main.rs:43:1&#10; |&#10;43 | #[main]&#10; | ^^^^^^^&#10; | |&#10; | expected `SpawnToken&amp;lt;_&amp;gt;`, found `SpawnToken&amp;lt;impl Sized&amp;gt;`&#10; | arguments to this method are incorrect&#10; |&#10; = note: `SpawnToken&amp;lt;impl Sized&amp;gt;` and `SpawnToken&amp;lt;_&amp;gt;` have similar names, but are actually distinct types&#10;note: `SpawnToken&amp;lt;impl Sized&amp;gt;` is defined in crate `embassy_executor`&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.6.0/src/spawner.rs:23:1&#10; |&#10;23 | pub struct SpawnToken&amp;lt;S&amp;gt; {&#10; | ^^^^^^^^^^^^^^^^^^^^^^^^&#10;note: `SpawnToken&amp;lt;_&amp;gt;` is defined in crate `embassy_executor`&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.5.0/src/spawner.rs:23:1&#10; |&#10;23 | pub struct SpawnToken&amp;lt;S&amp;gt; {&#10; | ^^^^^^^^^^^^^^^^^^^^^^^^&#10; = note: perhaps two different versions of crate `embassy_executor` are being used?&#10;note: method defined here&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.5.0/src/spawner.rs:127:12&#10; |&#10;127 | pub fn must_spawn&amp;lt;S&amp;gt;(&amp;amp;self, token: SpawnToken&amp;lt;S&amp;gt;) {&#10; | ^^^^^^^^^^&#10; = note: this error originates in the attribute macro `main` (in Nightly builds, run with -Z macro-backtrace for more info)&#10;&#10;Some errors have detailed explanations: E0107, E0308.&#10;For more information about an error, try `rustc --explain E0107`.&#10;error: could not compile `esp_hal_probe` (bin &amp;quot;esp_hal_probe&amp;quot;) due to 3 previous errors&#10;" />
</message>
<message>
<speaker value="ASSISTANT" />
</message>
<message>
<speaker value="HUMAN" />
<text value="help me fix this:&#10;&#10;error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied&#10; --&amp;gt; src/main.rs:26:34&#10; |&#10;26 | async fn monitor_pin4(mut input: Input&amp;lt;'static&amp;gt;) {&#10; | ^^^^^ expected 1 generic argument&#10; |&#10;note: struct defined here, with 1 generic parameter: `P`&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-hal-0.19.0/src/gpio/mod.rs:1673:12&#10; |&#10;1673 | pub struct Input&amp;lt;'d, P&amp;gt; {&#10; | ^^^^^ -&#10;help: add missing generic argument&#10; |&#10;26 | async fn monitor_pin4(mut input: Input&amp;lt;'static, P&amp;gt;) {&#10; | +++&#10;&#10;error[E0308]: mismatched types&#10; --&amp;gt; src/main.rs:43:1&#10; |&#10;43 | #[main]&#10; | ^^^^^^^&#10; | |&#10; | expected `Spawner`, found `embassy_executor::spawner::Spawner`&#10; | arguments to this function are incorrect&#10; |&#10; = note: `embassy_executor::spawner::Spawner` and `Spawner` have similar names, but are actually distinct types&#10;note: `embassy_executor::spawner::Spawner` is defined in crate `embassy_executor`&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.5.0/src/spawner.rs:71:1&#10; |&#10;71 | pub struct Spawner {&#10; | ^^^^^^^^^^^^^^^^^^&#10;note: `Spawner` is defined in crate `embassy_executor`&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.6.0/src/spawner.rs:71:1&#10; |&#10;71 | pub struct Spawner {&#10; | ^^^^^^^^^^^^^^^^^^&#10; = note: perhaps two different versions of crate `embassy_executor` are being used?&#10;note: function defined here&#10; --&amp;gt; src/main.rs:43:1&#10; |&#10;43 | #[main]&#10; | ^^^^^^^&#10;44 | async fn main(spawner: Spawner) {&#10; | ----------------&#10; = note: this error originates in the attribute macro `main` (in Nightly builds, run with -Z macro-backtrace for more info)&#10;&#10;error[E0308]: mismatched types&#10; --&amp;gt; src/main.rs:43:1&#10; |&#10;43 | #[main]&#10; | ^^^^^^^&#10; | |&#10; | expected `SpawnToken&amp;lt;_&amp;gt;`, found `SpawnToken&amp;lt;impl Sized&amp;gt;`&#10; | arguments to this method are incorrect&#10; |&#10; = note: `SpawnToken&amp;lt;impl Sized&amp;gt;` and `SpawnToken&amp;lt;_&amp;gt;` have similar names, but are actually distinct types&#10;note: `SpawnToken&amp;lt;impl Sized&amp;gt;` is defined in crate `embassy_executor`&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.6.0/src/spawner.rs:23:1&#10; |&#10;23 | pub struct SpawnToken&amp;lt;S&amp;gt; {&#10; | ^^^^^^^^^^^^^^^^^^^^^^^^&#10;note: `SpawnToken&amp;lt;_&amp;gt;` is defined in crate `embassy_executor`&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.5.0/src/spawner.rs:23:1&#10; |&#10;23 | pub struct SpawnToken&amp;lt;S&amp;gt; {&#10; | ^^^^^^^^^^^^^^^^^^^^^^^^&#10; = note: perhaps two different versions of crate `embassy_executor` are being used?&#10;note: method defined here&#10; --&amp;gt; /home/okhsunrog/.cargo/registry/src/index.crates.io-6f17d22bba15001f/embassy-executor-0.5.0/src/spawner.rs:127:12&#10; |&#10;127 | pub fn must_spawn&amp;lt;S&amp;gt;(&amp;amp;self, token: SpawnToken&amp;lt;S&amp;gt;) {&#10; | ^^^^^^^^^^&#10; = note: this error originates in the attribute macro `main` (in Nightly builds, run with -Z macro-backtrace for more info)&#10;&#10;" />
</message>
<message>
<speaker value="ASSISTANT" />
</message>
<message>
<speaker value="HUMAN" />
<text value="create one task, that takes these 2 input pins and uses select to wait for rising edge, then uses info! to print logs&#10;&#10;#![no_std]&#10;#![no_main]&#10;#![feature(type_alias_impl_trait)]&#10;&#10;use defmt::info;&#10;use defmt_rtt as _;&#10;use embassy_executor::Spawner;&#10;use embassy_time::{Duration, Timer};&#10;use esp_backtrace as _;&#10;use esp_hal::{&#10; clock::ClockControl,&#10; peripherals::Peripherals,&#10; prelude::*,&#10; rtc_cntl::Rtc,&#10; system::SystemControl,&#10; timer::{timg::TimerGroup, OneShotTimer},&#10;};&#10;use esp_hal::gpio::{GpioPin, Input, Io, Pull};&#10;use static_cell::make_static;&#10;&#10;#[main]&#10;async fn main(spawner: Spawner) {&#10; let peripherals = Peripherals::take();&#10; let system = SystemControl::new(peripherals.SYSTEM);&#10; let clocks = ClockControl::boot_defaults(system.clock_control).freeze();&#10;&#10; // Enable the RWDT watchdog timer:&#10; let mut rtc = Rtc::new(peripherals.LPWR, None);&#10; rtc.rwdt.set_timeout(2.secs());&#10; rtc.rwdt.enable();&#10; info!(&amp;quot;RWDT watchdog enabled!&amp;quot;);&#10;&#10; // Initialize the SYSTIMER peripheral, and then Embassy:&#10; let timg0 = TimerGroup::new(peripherals.TIMG0, &amp;amp;clocks, None);&#10; let timers = [OneShotTimer::new(timg0.timer0.into())];&#10; let timers = make_static!(timers);&#10;&#10; let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);&#10; let input4: Input&amp;lt;GpioPin&amp;lt;4&amp;gt;&amp;gt; = Input::new(io.pins.gpio4, Pull::Down);&#10; let input5: Input&amp;lt;GpioPin&amp;lt;5&amp;gt;&amp;gt; = Input::new(io.pins.gpio5, Pull::Down);&#10;&#10; esp_hal_embassy::init(&amp;amp;clocks, timers);&#10; info!(&amp;quot;Embassy initialized!&amp;quot;);&#10; &#10; &#10;&#10; // TODO: Spawn some tasks&#10; let _ = spawner;&#10;&#10; // Periodically feed the RWDT watchdog timer when our tasks are not running:&#10; loop {&#10; rtc.rwdt.feed();&#10; Timer::after(Duration::from_secs(1)).await;&#10; }&#10;}&#10;" />
</message>
<message>
<speaker value="ASSISTANT" />
</message>
<message>
<speaker value="HUMAN" />
<text value="create one task, that takes these 2 input pins and uses select to wait for rising edge, then uses info! to print logs&#10;&#10;#![no_std]&#10;#![no_main]&#10;#![feature(type_alias_impl_trait)]&#10;&#10;use defmt::info;&#10;use defmt_rtt as _;&#10;use embassy_executor::Spawner;&#10;use embassy_time::{Duration, Timer};&#10;use esp_backtrace as _;&#10;use esp_hal::{&#10; clock::ClockControl,&#10; peripherals::Peripherals,&#10; prelude::*,&#10; rtc_cntl::Rtc,&#10; system::SystemControl,&#10; timer::{timg::TimerGroup, OneShotTimer},&#10;};&#10;use esp_hal::gpio::{GpioPin, Input, Io, Pull};&#10;use static_cell::make_static;&#10;&#10;#[main]&#10;async fn main(spawner: Spawner) {&#10; let peripherals = Peripherals::take();&#10; let system = SystemControl::new(peripherals.SYSTEM);&#10; let clocks = ClockControl::boot_defaults(system.clock_control).freeze();&#10;&#10; // Enable the RWDT watchdog timer:&#10; let mut rtc = Rtc::new(peripherals.LPWR, None);&#10; rtc.rwdt.set_timeout(2.secs());&#10; rtc.rwdt.enable();&#10; info!(&amp;quot;RWDT watchdog enabled!&amp;quot;);&#10;&#10; // Initialize the SYSTIMER peripheral, and then Embassy:&#10; let timg0 = TimerGroup::new(peripherals.TIMG0, &amp;amp;clocks, None);&#10; let timers = [OneShotTimer::new(timg0.timer0.into())];&#10; let timers = make_static!(timers);&#10;&#10; let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);&#10; let input4: Input&amp;lt;GpioPin&amp;lt;4&amp;gt;&amp;gt; = Input::new(io.pins.gpio4, Pull::Down);&#10; let input5: Input&amp;lt;GpioPin&amp;lt;5&amp;gt;&amp;gt; = Input::new(io.pins.gpio5, Pull::Down);&#10;&#10; esp_hal_embassy::init(&amp;amp;clocks, timers);&#10; info!(&amp;quot;Embassy initialized!&amp;quot;);&#10; &#10; &#10;&#10; // TODO: Spawn some tasks&#10; let _ = spawner;&#10;&#10; // Periodically feed the RWDT watchdog timer when our tasks are not running:&#10; loop {&#10; rtc.rwdt.feed();&#10; Timer::after(Duration::from_secs(1)).await;&#10; }&#10;}&#10;" />
</message>
<message>
<speaker value="ASSISTANT" />
</message>
<message>
<speaker value="HUMAN" />
<text value="create one task, that takes these 2 input pins and uses select to wait for rising edge, then uses info! to print logs&#10;&#10;#![no_std]&#10;#![no_main]&#10;#![feature(type_alias_impl_trait)]&#10;&#10;use defmt::info;&#10;use defmt_rtt as _;&#10;use embassy_executor::Spawner;&#10;use embassy_time::{Duration, Timer};&#10;use esp_backtrace as _;&#10;use esp_hal::{&#10; clock::ClockControl,&#10; peripherals::Peripherals,&#10; prelude::*,&#10; rtc_cntl::Rtc,&#10; system::SystemControl,&#10; timer::{timg::TimerGroup, OneShotTimer},&#10;};&#10;use esp_hal::gpio::{GpioPin, Input, Io, Pull};&#10;use static_cell::make_static;&#10;&#10;#[main]&#10;async fn main(spawner: Spawner) {&#10; let peripherals = Peripherals::take();&#10; let system = SystemControl::new(peripherals.SYSTEM);&#10; let clocks = ClockControl::boot_defaults(system.clock_control).freeze();&#10;&#10; // Enable the RWDT watchdog timer:&#10; let mut rtc = Rtc::new(peripherals.LPWR, None);&#10; rtc.rwdt.set_timeout(2.secs());&#10; rtc.rwdt.enable();&#10; info!(&amp;quot;RWDT watchdog enabled!&amp;quot;);&#10;&#10; // Initialize the SYSTIMER peripheral, and then Embassy:&#10; let timg0 = TimerGroup::new(peripherals.TIMG0, &amp;amp;clocks, None);&#10; let timers = [OneShotTimer::new(timg0.timer0.into())];&#10; let timers = make_static!(timers);&#10;&#10; let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);&#10; let input4: Input&amp;lt;GpioPin&amp;lt;4&amp;gt;&amp;gt; = Input::new(io.pins.gpio4, Pull::Down);&#10; let input5: Input&amp;lt;GpioPin&amp;lt;5&amp;gt;&amp;gt; = Input::new(io.pins.gpio5, Pull::Down);&#10;&#10; esp_hal_embassy::init(&amp;amp;clocks, timers);&#10; info!(&amp;quot;Embassy initialized!&amp;quot;);&#10; &#10; &#10;&#10; // TODO: Spawn some tasks&#10; let _ = spawner;&#10;&#10; // Periodically feed the RWDT watchdog timer when our tasks are not running:&#10; loop {&#10; rtc.rwdt.feed();&#10; Timer::after(Duration::from_secs(1)).await;&#10; }&#10;}&#10; " />
</message>
<message>
<speaker value="ASSISTANT" />
</message>
<message>
<speaker value="HUMAN" />
<text value="create one task, that takes these 2 input pins and uses select to wait for rising edge, then uses info! to print logs&#10;&#10;#![no_std]&#10;#![no_main]&#10;#![feature(type_alias_impl_trait)]&#10;&#10;use defmt::info;&#10;use defmt_rtt as _;&#10;use embassy_executor::Spawner;&#10;use embassy_time::{Duration, Timer};&#10;use esp_backtrace as _;&#10;use esp_hal::{&#10; clock::ClockControl,&#10; peripherals::Peripherals,&#10; prelude::*,&#10; rtc_cntl::Rtc,&#10; system::SystemControl,&#10; timer::{timg::TimerGroup, OneShotTimer},&#10;};&#10;use esp_hal::gpio::{GpioPin, Input, Io, Pull};&#10;use static_cell::make_static;&#10;&#10;#[main]&#10;async fn main(spawner: Spawner) {&#10; let peripherals = Peripherals::take();&#10; let system = SystemControl::new(peripherals.SYSTEM);&#10; let clocks = ClockControl::boot_defaults(system.clock_control).freeze();&#10;&#10; // Enable the RWDT watchdog timer:&#10; let mut rtc = Rtc::new(peripherals.LPWR, None);&#10; rtc.rwdt.set_timeout(2.secs());&#10; rtc.rwdt.enable();&#10; info!(&amp;quot;RWDT watchdog enabled!&amp;quot;);&#10;&#10; // Initialize the SYSTIMER peripheral, and then Embassy:&#10; let timg0 = TimerGroup::new(peripherals.TIMG0, &amp;amp;clocks, None);&#10; let timers = [OneShotTimer::new(timg0.timer0.into())];&#10; let timers = make_static!(timers);&#10;&#10; let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);&#10; let input4: Input&amp;lt;GpioPin&amp;lt;4&amp;gt;&amp;gt; = Input::new(io.pins.gpio4, Pull::Down);&#10; let input5: Input&amp;lt;GpioPin&amp;lt;5&amp;gt;&amp;gt; = Input::new(io.pins.gpio5, Pull::Down);&#10;&#10; esp_hal_embassy::init(&amp;amp;clocks, timers);&#10; info!(&amp;quot;Embassy initialized!&amp;quot;);&#10; &#10; &#10;&#10; // TODO: Spawn some tasks&#10; let _ = spawner;&#10;&#10; // Periodically feed the RWDT watchdog timer when our tasks are not running:&#10; loop {&#10; rtc.rwdt.feed();&#10; Timer::after(Duration::from_secs(1)).await;&#10; }&#10;}&#10; " />
</message>
<message>
<speaker value="ASSISTANT" />
<text value="Certainly! Here's how we can create a single task that monitors both input pins using `select` and prints logs using `info!`:&#10;&#10;```rust&#10;use embassy_futures::select::{select, Either};&#10;&#10;#[embassy_executor::task]&#10;async fn monitor_pins(mut input4: Input&lt;'static, GpioPin&lt;4&gt;&gt;, mut input5: Input&lt;'static, GpioPin&lt;5&gt;&gt;) {&#10; loop {&#10; match select(input4.wait_for_rising_edge(), input5.wait_for_rising_edge()).await {&#10; Either::First(_) =&gt; info!(&quot;Rising edge detected on Pin 4!&quot;),&#10; Either::Second(_) =&gt; info!(&quot;Rising edge detected on Pin 5!&quot;),&#10; }&#10; Timer::after(Duration::from_millis(100)).await;&#10; }&#10;}&#10;&#10;#[main]&#10;async fn main(spawner: Spawner) {&#10; // ... (previous code remains the same)&#10;&#10; let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);&#10; let input4 = Input::new(io.pins.gpio4, Pull::Down);&#10; let input5 = Input::new(io.pins.gpio5, Pull::Down);&#10;&#10; spawner.spawn(monitor_pins(input4, input5)).unwrap();&#10;&#10; // ... (rest of the code remains the same)&#10;}&#10;```&#10;&#10;This implementation creates a single task `monitor_pins` that takes both input pins as parameters. It uses `select` to wait for a rising edge on either pin, then prints the appropriate log message using `info!`. The task is spawned in the `main` function, passing both input pins as arguments." />
</message>
</list>
</messages>
<updatedAt value="2024-08-08T23:07:31.542436259" />
</chat>
</list>
</chats>
</AccountData>
</list>
</accountData>
</component>
</project>

11
.idea/esp_hal_probe.iml generated Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View file

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="RsUnusedImport" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

8
.idea/modules.xml generated Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/esp_hal_probe.iml" filepath="$PROJECT_DIR$/.idea/esp_hal_probe.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

1
Cargo.lock generated
View file

@ -639,6 +639,7 @@ dependencies = [
"defmt",
"defmt-rtt",
"embassy-executor",
"embassy-futures",
"embassy-time",
"esp-backtrace",
"esp-hal",

View file

@ -9,6 +9,7 @@ defmt = "0.3.8"
defmt-rtt = "0.4.1"
embassy-executor = { version = "0.5.0", features = ["defmt"] }
embassy-time = { version = "0.3.1", features = ["generic-queue-8"] }
embassy-futures = "0.1.1"
esp-backtrace = { version = "0.13.0", features = ["esp32c3", "defmt", "exception-handler", "panic-handler"] }
esp-hal = { version = "0.19.0", features = ["esp32c3", "defmt", "async"] }
esp-hal-embassy = { version = "0.2.0", features = ["esp32c3", "defmt"] }

View file

@ -15,8 +15,22 @@ use esp_hal::{
system::SystemControl,
timer::{timg::TimerGroup, OneShotTimer},
};
use esp_hal::gpio::{GpioPin, Input, Io, Pull};
use static_cell::make_static;
use embassy_futures::select::{select, Either};
#[embassy_executor::task]
async fn monitor_pins(mut input4: Input<'static, GpioPin<4>>, mut input5: Input<'static, GpioPin<5>>) {
loop {
match select(input4.wait_for_rising_edge(), input5.wait_for_rising_edge()).await {
Either::First(_) => info!("Rising edge detected on Pin 4!"),
Either::Second(_) => info!("Rising edge detected on Pin 5!"),
}
Timer::after(Duration::from_millis(100)).await;
}
}
#[main]
async fn main(spawner: Spawner) {
let peripherals = Peripherals::take();
@ -33,11 +47,14 @@ async fn main(spawner: Spawner) {
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!");
// TODO: Spawn some tasks
let _ = spawner;
spawner.spawn(monitor_pins(input4, input5)).unwrap();
// Periodically feed the RWDT watchdog timer when our tasks are not running:
loop {