Strange select().await statement

Hi there, Anyone know how to use the select().await statement in this DevConf 2023 video at 05:40 minute point? (https://www.youtube.com/watch?v=QPp4WEjx5jU&list=RDCMUCDBWNF7CJ2U5eLGT7o3rKog)

Screenshot from 2024-05-22 20-52-24

It seems handy but I don't know how to enable and use it, is there any crates must be imported?

Thank you very much, Tuan

It's from embassy_futures.

1 Like

Thank you very much for swift reply. Now I face another issue while using it as following, do you have any suggestion? I just want to detect press & release events on the same button in a no-std, async code and using that elegant select().

    let mut but15: esp_hal::gpio::GpioPin<Input<PullDown>, 15> = io.pins.gpio15.into_pull_down_input();

    loop
    {
        match select (
            but15.wait_for_rising_edge(),          <---- first mutable borrow
            but15.wait_for_falling_edge(),         <---- second mutable borrow hence compile error
        ).await {
            Either::First(_) => log::info!("Button Pressed!"),
            Either::Second(_) => log::info!("Button Released!"),
        }
    }

Maybe check if the pin is currently high or low and depending on that decide to either call wait_for_rising_edge().await of wait_for_falling_edge().await. That is what wait_for_any_edge effectively does: embassy/embassy-nrf/src/gpiote.rs at 4e2296e34458382be4b548fa10e5f6a782059e8d · embassy-rs/embassy · GitHub It seems like wait_for_any_edge is not directly useful to you as it doesn't return whether it is a rising or falling edge.

1 Like

I've just noticed that this is on the "internals" forum, which is more commonly used for discussing the Rust toolchain internals, and not how to use Rust - questions like this are better asked on https://users.rust-lang.org/ where there's plenty of people who can help.

1 Like

Sorry for my ignorance. I will do it next time.

Best regard, Tuan

Thank you for the suggestion. I will try that way.

Cordially, Tuan

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.