Skip to content

Register spec & traits #464

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

Merged
merged 12 commits into from
Aug 7, 2020
Merged

Conversation

couchand
Copy link
Contributor

@couchand couchand commented Aug 7, 2020

Part 1 of #463.

  • Publishes the register spec zero-sized type and moves all relevant register traits to that struct, which fixes Awkward to write code generic over registers #459 and improves generated documentation.
  • Removes the extra type parameter on Reg, making the register spec the sole authority on the shape of the register (but not its address).

One thing that's changed since the previous PR, this renames the spec struct so that it won't cause a conflict on NXP, Freescale, and possibly other architectures. I've gone with register::REGISTER_SPEC since that seems reasonably clear and I can't think of how it would cause a conflict (but I'm ready to be proven wrong since I've tried several ideas only to be stymied by various architectures' oddball register naming patterns).

I'd prefer the spec to be in the parent module, but I can't come up with a way to do that which guarantees that the generated code will be free from naming conflicts. This seems good enough, plus it maintains the rule that when we make up a name it belongs in the child mod (except for RegisterBlock).

There is potential for breaking changes here, though the impact seems pretty minimal. Specifically:

  • If users referred to the traits in mod generic, their usage would break. Writing code referring to those traits was previously pretty awkward (see Register trait improvements #463), and this PR makes such usage much more ergonomic, so it would seem to be a net benefit.
  • If users named the full reader/writer incantation the reference would break. It doesn't seem users are likely to name the readers/writers at all, but if they do it seems very likely they would use the type alias.
  • If users named the previously #[docs(hidden)] spec struct the reference would break. I don't see why they would have done so.
  • If users patched something in to the generated module with the same name as our new register spec, it would break. That case seems highly unlikely.

r? @burrbull

@couchand couchand requested a review from a team as a code owner August 7, 2020 03:55
@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools labels Aug 7, 2020
@burrbull
Copy link
Member

burrbull commented Aug 7, 2020

Looks good in first view. One question. Have you tested this for result firmware size? In release and debug mode.

@couchand couchand mentioned this pull request Aug 7, 2020
@couchand
Copy link
Contributor Author

couchand commented Aug 7, 2020

Have you tested this for result firmware size? In release and debug mode.

In my testing of binaries built using code generated from the previous PR, the assembly produced (RUSTFLAGS='--emit asm') was identical to master.

I'll repeat that testing here to make sure I've maintained that property.

Edit: wow nope. My test setup was not properly pulling in the modified build. I thought it seemed suspicious how identical it was. Will reevaluate.

@couchand
Copy link
Contributor Author

couchand commented Aug 7, 2020

arduino uno blink example

bytes master #464
debug 1090816 1094812
release 7016 7016

@couchand
Copy link
Contributor Author

couchand commented Aug 7, 2020

After strip --strip-unneeded, the numbers are:

bytes master #464
debug 11148 11148
release 2444 2444

Copy link
Contributor

@therealprof therealprof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@bors bors bot merged commit 5356990 into rust-embedded:master Aug 7, 2020
bors bot added a commit that referenced this pull request Aug 8, 2020
465: Accessor newtypes r=therealprof a=couchand

Part 2 of #463, builds on #464.

- Wraps register reader/writer and field readers in newtype wrappers, which significantly improves the documentation output.

Again there's some minor potential for breaking changes:

- If users named the complete type of the previous type alias, it would break.  It seems more likely that they would use the alias, which will silently upgrade to a reference to the newtype.

r? @burrbull 

Co-authored-by: Andrew Dona-Couch <hi@andrewcou.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Awkward to write code generic over registers
4 participants