rust-embedded / svd2rust

Generate Rust register maps (`struct`s) from SVD files
Apache License 2.0
687 stars 149 forks source link

Rework: Enum typename considering name in enumeratedValues #627

Closed luojia65 closed 2 years ago

luojia65 commented 2 years ago

~Marked as draft: this pull request depends on https://github.com/rust-embedded/svd2rust/pull/626, and should be merged after that pull request is merged.~ Ready for review as #626 is merged.

This pull request is a rework to https://github.com/rust-embedded/svd2rust/pull/612; commits in this pull request only considers enumeration name other than writer structure and reader structure. Names to those two proxy structures are yet to be discussed.

svd2rust has a good mechanism to parse enumeratedValues into Rust enums. However, current code would pick name of the first field the enum resides, and use pub type to re-export it into other names.

SVD files provide name field in enumeratedValues, this commit make use of them to name the Rust enums it generated. After this commit, more information of SVD file is considered in output pac crate. Users may also discover a significant drop in amount of types, which will speed up rustdoc generation and crate compilation.

After this pull request is merged, we can discuss on how the read proxy and write proxy should be named as is mentioned in comment at #612.

Before this pull request:

![图片](https://user-images.githubusercontent.com/40385009/178151338-2e327886-0ce7-44f8-b12c-8ef9ee8d671a.png)

After this pull request:

![图片](https://user-images.githubusercontent.com/40385009/178151280-c2b83445-2f15-4a18-9d9a-f511c6ea85f8.png)

SVD file for this example:

```xml interrupt Interrupt enables, states and masks 0x04 0x3f003f00 0xffffffff fifo_error_enable Transmit or receive FIFO error interrupt enable 29 29 true InterruptEnable enable Enable interrupt 1 disable Disable interrupt 0 arbitrate_lost_enable Arbitration lost interrupt enable 28 28 true ```
rust-highfive commented 2 years ago

r? @ryankurte

(rust-highfive has picked a reviewer for you, use r? to override)

burrbull commented 2 years ago

rebase, please. You can use last commit from https://github.com/rust-embedded/svd2rust/commits/enum-names2

luojia65 commented 2 years ago

thanks, I'll rebase to adapt main branch changes.

luojia65 commented 2 years ago

@burrbull: Hello! I have rebased to master and pushed my commit.

burrbull commented 2 years ago

@burrbull: Hello! I have rebased to master and pushed my commit.

Thanks. Could you also look at GD32 https://github.com/rust-embedded/svd2rust/pull/628 ? Possibly you have idea how to fix it.

burrbull commented 2 years ago

bors r+

bors[bot] commented 2 years ago

Build succeeded: