Add field layout attr to manually specify bit range #81
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi @hecatia-elegua,
I was trying to learn low-level programming, e.g. SD driver, which interact a lot with MMIO register. Then I found several bitfield projects like modular-bitfield, bitbybit and this one, bilge.
After testing a while, to be honest, I feel bitbybit's design a little more fit for my usecase, especially the
#[bit(<bit index>, rw)]
/#[bits(<start bit>..=<end bit>)]
syntax to manually specify field bit range, which is more readable when there are many gaps (reserved bits) between fields. But bitbybit misses an important feature : derive sensible Debug impl. Then I found bilge already resolved it by using "#[bitsize] as a scope" trick, brilliant idea!So here I'm trying to add bitbybit style
#[bit(..)]
/#[bits(...)]
to bilge. As a side-effect it allows overlapping field which might be helpful in some cases, e.g. multi-version register, or dangerous. (Maybe better to add a flag to switch between non-overlap and overlap mode?).Here is a brief overview of the changes I made:
#[bitsize(...)]
, e.g.#[bitsize(32, manual)]
means manually specify bit range for fields. Default is auto pack fields like before.#[bit(<bit index>, <access mode>)
for single bit field and#[bits(<start bit>..=<end bit>, <access mode>)]
for multi bits field, which only allowed in manual layout. (For simplicity, access mode is not implemented yet.)I'd appreciate it if you could review my changes and let me know if you have any feedback.
Thanks!