-
Notifications
You must be signed in to change notification settings - Fork 0
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
Extract GPIO pin number constants to common enum #85
Conversation
Thanks for working on this! Maybe there should also be some sort of mechanism that enforces only one use of each pin at a time. I suppose we can also ignore the error in the checks regarding the unused enum field. |
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.
A regular enum would enforce enum fields to be discriminant whereby having multiple of the same value would be an error, but using a regular enum would require casting each pin value with as u8
when passed into Gpio::get
which seems inconvenient (and more generally risks lossy conversion), but perhaps this is preferred to enforce discriminants.
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.
Looks great!
Actually, I found a suitable compromise for having the enum, will update soon. |
- Move all constants for GPIO pin numbers used by components to a single module to avoid having conflicting numbers - Use a struct instead of enum to avoid needing to cast `as u8`
- Install `num_enum` in `pod-operation` - Implements `From<Enum>` for underlying u8 repr so we can use `.into()`
Resolves #84.
Changes
GpioPins
enum will enforce discriminantnum_enum::IntoPrimitive
to convert from enum value tou8
using.into()