>>What's the best way to modify bitfields used for hardware register
is to not use bitfields.
>> I want to modify 'DR' (bits 3,2)
I don't see how that matches your bitfields DR
==============
See if this is what you are driving for:
In any case, it seems that you want your UpdateReg() function to be general enough to handle any scenario.
UpdateReg( char mask, char newPattern );
where mask is a set of arbitrarily placed bits that will clear
I'm assuming that you can read the register in a temp variable, and then manipulate it, and finally write it back to the HW register. (This isn't always true, since sometimes reading the HW register changes the value.)
So the mask is adapted to first clear the corresponding bits in the temp variable (after you read the HW register). Then, using the mask again with the newPattern, I now have the valid set of bits (or 0's) to or into the temp register. Then write the temp back to the HW.