You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the current API we don't have a simple to write a bool to a field if that field has an enumeration. Compared to numeric fields where we have a conversion via into() we need to manually match here:
For my tests is added an enumeration to the boolrw() bitfield in our simple.xml:
whereas for a boolean field (with the enumeration) these don't work:
// fails since we use RegValue for the fieldTIMER.bitfield_reg().modify(|r| r.boolrw().set(true)));// fails since there is no bool -> EnumBitfieldStruct conversionTIMER.bitfield_reg().modify(|r| r.boolrw().set(true.into()));
The currently working workarounds are:
// the explicit matchlet xx = match x {true => timer::bitfield_reg::BoolRw::SOME_BOOLEAN_ENABLED,false => timer::bitfield_reg::BoolRw::SOME_BOOLEAN_DISABLED,};// comparing against the enums if we don't want to presume to values of the enumslet xx = if x == (timer::bitfield_reg::BoolRw::SOME_BOOLEAN_ENABLED.0 == 1){
timer::bitfield_reg::BoolRw::SOME_BOOLEAN_ENABLED}else{
timer::bitfield_reg::BoolRw::SOME_BOOLEAN_DISABLED};// cast to ux and use `.into()`TIMER.bitfield_reg().modify(|r| r.boolrw().set((x asu8).into()));
Us using RegValue here has the side-effect that this:
compiles. Doesn't cause much harm though since the mask is applied before it's written to the RegisterValue. It's just a bit weird that we allow this.
Describe the solution you'd like
A matching usage between enumerated and non-enumerated fields.
Describe alternatives you've considered
Add a RegisterFieldEnumBool to use instead of RegisterField (I don't see a nice way to extend RegisterFieldBool to handle enums as well atm)
Add a BooleanEnumBitfieldStruct to use instead of EnumBitfieldStruct that implements From<bool>
Generate an impl like impl From<bool> for BoolRw {...} for every boolean bitfield with enumerations - seems hacky and leads to quite a bit more code in our case
impl RegNumberT for bool - doesn't work since bool does e.g. not implement Shr and might need some additional bounds across the code
Keep as is - considering that for numeric fields .into() works it should work for boolean fields as well for consistency and "least surprise"
I'd favour the first option, but posting here for discussion and possible additional ideas.
The text was updated successfully, but these errors were encountered:
In the current API we don't have a simple to write a bool to a field if that field has an enumeration. Compared to numeric fields where we have a conversion via
into()
we need to manually match here:For my tests is added an enumeration to the boolrw() bitfield in our
simple.xml
:For enumerated numeric fields we can do:
whereas for a boolean field (with the enumeration) these don't work:
The currently working workarounds are:
Us using
RegValue
here has the side-effect that this:compiles. Doesn't cause much harm though since the mask is applied before it's written to the
RegisterValue
. It's just a bit weird that we allow this.Describe the solution you'd like
A matching usage between enumerated and non-enumerated fields.
Describe alternatives you've considered
RegisterFieldEnumBool
to use instead ofRegisterField
(I don't see a nice way to extendRegisterFieldBool
to handle enums as well atm)BooleanEnumBitfieldStruct
to use instead ofEnumBitfieldStruct
that implementsFrom<bool>
impl From<bool> for BoolRw {...}
for every boolean bitfield with enumerations - seems hacky and leads to quite a bit more code in our caseimpl RegNumberT for bool
- doesn't work sincebool
does e.g. not implementShr
and might need some additional bounds across the code.into()
works it should work for boolean fields as well for consistency and "least surprise"I'd favour the first option, but posting here for discussion and possible additional ideas.
The text was updated successfully, but these errors were encountered: