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
The parameters are: the struct name, size of the wrapped value, and list of fields and position of those fields (e.g. NONE is one bit long, and it's the lsb).
We could also add another input for a default value (and remove all the DEFAULTconsts).
Generally grouping the registers together sounds very nice. I think we can go further down and provide abstractions for the main components of the serial console. For example, if we take the interrupts, there are 3 main operations (which have separate defines):
enabling interrupts -> corresponds to IER defines
adding/deleting an interrupt -> corresponds to the IIR defines
-trigering the interrupt
A non significant overhead in the serial console comes from handling interrupts. If we can "modularize" working with an interrupt, we get "for free" the separation you are proposing because we can then define the bit shifts in the context of the newly created interface. Does that make sense?
I'm not sure I understand correctly your proposal, can you maybe show an example of the interface you're referrng to? I thnk you're proposing to not expose the bit masks, but instead to provide methods like "set_bit_x".
Context
If you look at serial.rs, this is the current situation:
At the top, we have some
const
definedThe pattern is
<register>_<field_name>
.An example of usage in the wild is:
Problem
Proposal
First proposal
I know it's not preferable to include external dependencies like bitfield but I think I simple macro will do the trick.
I would propose a macro which will allow the following:
The parameters are: the struct name, size of the wrapped value, and list of fields and position of those fields (e.g. NONE is one bit long, and it's the lsb).
We could also add another input for a default value (and remove all the
DEFAULT
consts).Second proposal
A simple struct based wrapper. Playground.
We can then define the similar methods as above (clear_bit and set_bit).
The text was updated successfully, but these errors were encountered: