-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stm32xx-sys: configure GPIO IRQ edge with an enum #1706
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The current `Sys::gpio_irq_configure` IPC interface is a bit confusing, as it takes two `bool`s for the rising and falling edge sensitivities, as in: ```rust sys.gpio_irq_configure(mask, true, false); ``` This isn't particularly clear for a reader, who then has to remember the order of the arguments to determine which edge sensitivity is being enabled here. This is a case of ["boolean blindness"][1]. This commit improves the interface by changing it to take an `enum` with variants for `Rising`, `Falling`, and `Both`. Now, the same call to the IPC looks like this: ```rust sys.gpio_irq_configure(mask, Edge::Rising); ``` which should be much more obvious to a reader, who no longer needs to remember the argument ordering to decypher calls to this function. Also, this has the advantage of preventing the case where both rising and falling edge sensitivities are disabled at compile-time. Currently, this is a runtime error (reply fault), but with the new interface, a caller can provide an invalid configuration if they hand-write the input buffer rather than using the Idol client stub, so it should be harder to mess up. [1]: https://runtimeverification.com/blog/code-smell-boolean-blindness
ceb691a
to
2aa8d76
Compare
cbiffle
approved these changes
Apr 2, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mere nits and suggestions below.
Signed-off-by: Eliza Weisman <eliza@elizas.website>
bcantrill
approved these changes
Apr 2, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great and will be less error prone to write and easier to review -- thank you!
Signed-off-by: Eliza Weisman <eliza@elizas.website>
hawkw
added a commit
that referenced
this pull request
Apr 5, 2024
The current `Sys::gpio_irq_configure` IPC interface is a bit confusing, as it takes two `bool`s for the rising and falling edge sensitivities, as in: ```rust sys.gpio_irq_configure(mask, true, false); ``` This isn't particularly clear for a reader, who then has to remember the order of the arguments to determine which edge sensitivity is being enabled here. This is a case of ["boolean blindness"][1]. This commit improves the interface by changing it to take an `enum` with variants for `Rising`, `Falling`, and `Both`. Now, the same call to the IPC looks like this: ```rust sys.gpio_irq_configure(mask, Edge::Rising); ``` which should be much more obvious to a reader, who no longer needs to remember the argument ordering to decypher calls to this function. Also, this has the advantage of preventing the case where both rising and falling edge sensitivities are disabled at compile-time. Currently, this is a runtime error (reply fault), but with the new interface, a caller can provide an invalid configuration if they hand-write the input buffer rather than using the Idol client stub, so it should be harder to mess up. [1]: https://runtimeverification.com/blog/code-smell-boolean-blindness
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The current
Sys::gpio_irq_configure
IPC interface is a bit confusing, as it takes twobool
s for the rising and falling edge sensitivities, as in:This isn't particularly clear for a reader, who then has to remember the order of the arguments to determine which edge sensitivity is being enabled here. This is a case of "boolean blindness".
This commit improves the interface by changing it to take an
enum
with variants forRising
,Falling
, andBoth
. Now, the same call to the IPC looks like this:which should be much more obvious to a reader, who no longer needs to remember the argument ordering to decypher calls to this function.
Also, this has the advantage of preventing the case where both rising and falling edge sensitivities are disabled at compile-time. Currently, this is a runtime error (reply fault), but with the new interface, a caller can provide an invalid configuration if they hand-write the input buffer rather than using the Idol client stub, so it should be harder to mess up.