async: add digital::Wait.#346
Conversation
|
bikeshedding but, do we have any preference for |
|
Would this trait only be meant for implementing on pins themselves, or could it also be used elsewhere? The case I'm thinking of is on the nrf51, which can't implement it on plain pins (in the same way, at least) because it lacks a latch register; would it be implemented on something like a GPIOTE channel instead? |
|
@ryankurte IMO the proposed methods are more consistent with @Liamolucko they could be implemented on pins or on something else, depending on the hardware. On embassy-nrf they're implemented on individual pins. On stm32 using EXTI needs to reseve an "EXTI channel", so in embassy-stm32 they're implemented in a separate struct |
we do actually have a default in this instance it would seem to me to be simpler to provide default impls for |
|
Oh, I didn't know about set_state. hmm... Doesn't "state" refer to the "output pin state", like in Also, there's no way to provide default method impls with GAT-based async traits. Given this, I think it's better to not include these "helper methods" for now, because they'll force every implementor to include boilerplate. There hopefully will with the future async-fn-in-traits, so we can revisit later when we switch to it. |
|
friendly ping @ryankurte @eldruin could we unblock this? I believe Either way, all GPIO traits should be consistent (either all using "state" or all using "high/low"), so if someone feels the "state" based API is better please open an issue and we can discuss and then change all traits (not just |
ryankurte
left a comment
There was a problem hiding this comment.
sgtm, thanks for bearing with us!
bors r+
Add
digital::Waittrait.This is the previously proposed
WaitForXtraits, unified in a single one supporting both edge-triggered and level-triggered waits.It is possible to software-emulate edge-triggered out of level-triggered hardware and vice-versa, so requiring support for both shouldn't make it unimplementable for any MCU. It is a good thing to require both: for example, stm32 EXTI is edge-triggered, but drivers usually want level-triggered. It'd be bad if a HAL decided "the hardware only supports edge-triggered, so I'm only going to impl edge-triggered!".
Impl for nRF's GPIOTE here: https://github.com/embassy-rs/embassy/blob/master/embassy-nrf/src/gpiote.rs
Impl for STM32's EXTI here: https://github.com/embassy-rs/embassy/blob/master/embassy-stm32/src/exti.rs
(impls still not unified, but unifying shouldn't be an issue).