Closed sosthene-nitrokey closed 8 months ago
In my experience, things are usually generated with masks lsb aligned and combined with a "pos" constant for the required shifts.
Used like in ((value >> FIELD1_POS) & FIELD1_MASK)
which is essentially what bitfield does for us.
What is you usecase for such a thing though? Doesn’t handling masking/shifting manualy defeat the point of using bitfield!
?
Writing device drivers for embedded I'm encountering the case where the device I'm communicating has "registers" that I can read/write.
Bitfields allows me to create/parse values for these registers. But the devices also accepts writing to specific bits of the register. In that case you send the full byte, plus a mask for which bits should actually be written.
Bitfield does not give me a straightforward way to build this mask. I could build the mask by setting each bit that I want to change, but that is not really explicit, and not straightforward for some cases where a field spans multiple bits.
That's right, I'm too used to the svd2rust generated API hiding all this.
Hi!
When dealing with bitfields we often also want to address the fields with bit masks.
I'm thinking of the following:
would generate an associated constant for
field1
: