-
Notifications
You must be signed in to change notification settings - Fork 156
Fix handling of isDefault'
enumeratedValue's
#486
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
Fix handling of isDefault'
enumeratedValue's
#486
Conversation
In the case that a register field has only a single `isDefault` `enumeratedValue` defined in the SVD file, don't emit an `_A` `enum` (as there are no valid variants to enumerate). Instead, emit a tuple struct with a single field which holds the value of the register field.
r? @adamgreig (rust-highfive has picked a reviewer for you, use r? to override) |
isDefault
enumeratedValue
sisDefault'
enumeratedValue's
Comes initially from #485 |
Is there a specific svd file that exhibits this conflict? |
@therealprof: it was mentioned in #485, but specifically it happens with this file. One example is the <register>
<name>FSADDR</name>
<description>Flash Start Address</description>
<addressOffset>0x0030</addressOffset>
<size>32</size>
<access>read-write</access>
<resetValue>0x00000000</resetValue>
<resetMask>0xFFFFFFFF</resetMask>
<fields>
<field>
<name>FSA</name>
<description>Start Address of Flash Sequencer Command Target Area
These bits can be written when FRDY bit of FSTATR register is "1". Writing to these bits in FRDY = "0" is ignored.</description>
<lsb>0</lsb>
<msb>31</msb>
<access>read-write</access>
<enumeratedValues>
<enumeratedValue>
<name>others</name>
<description>Specifies start address for each command processing.</description>
<isDefault>true</isDefault>
</enumeratedValue>
</enumeratedValues>
</field>
</fields>
</register> |
Anything I could do to make this easier/more ready to review? |
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.
Sorry for the delay, LGTM. Thanks a lot.
bors r+
Currently, an
enumeratedValue
is ignored if (and only if) it's name matches "reserved", and all remainingenumeratedValue
s are expected to have avalue
child element. However, the SVD schema allows anenumeratedValue
to contain either avalue
element or anisDefault
element. Whensvd2rust
hits anisDefault
element that isn't named "reserved", an error is thrown.In general, filtering these out should be safe, as they don't represent specific values that can be assigned to a field, but rather a range of values. The ability to read and write such arbitrary values is already handled with the
bits()
method defined on field readers/writers. The one corner case, however, is for fields with only a singleenumeratedValue
which has anisDefault
child element. Attempting to handle these in the usual way results in emitting emptyenum
s which causes compilation failures. Instead, emit anewtype
encapsulating the field's base type.