embassy-nrf: add gpiote::InputChannel::wait_for_high/low()
#4810
+77
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR turns
gpiote::InputChannel::wait()into afn wait() -> impl Futureinstead of anasync fn. This guarantees that the interrupt is enabled and the event flag is cleared directly when the function is called, and not delayed until the future is polled.This enables use cases like this:
Which should give race-free waiting for a pin to become low.
Note: I also think this function should actually take
&mut self. It clears the event flag, so multiple concurrent calls will interfere with each-other.However, making it
&mut selfwill actually break the use case above :pSo.. do we 🙈 about the
&selfor should I maybe directly implement functions likewait_for_high()andwait_for_low()to avoid races and still support the use case above?Those functions might also actually want to change the event polarity though, or they would need to report an error if the polarity is wrong. Or we would need separate types for the different polarities, but that feels a bit overkill.