rust-embedded / svd2rust

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

Custom prefix/case/suffix for identifiers #794

Closed burrbull closed 9 months ago

burrbull commented 9 months ago

This PR doesn't add new cli options (yet?). But you can pass options by config:

❯ cat svd2rust.toml 
make_mod = true
generic_mod = true
strict = true
pascal_enum_values = true
max_cluster_size = true
atomics = true
atomics_feature = "atomics"
debug_impl = true
defmt_impl = "defmt"
reexport_core_peripherals = true
reexport_interrupt = true

[ident_formats.register_spec]
case = "constant"
suffix = "rs"

[ident_formats.enum_name]
case = "constant"

[ident_formats.enum_write_name]
case = "constant"
prefix = "w"

[ident_formats.field_reader]
case = "constant"
suffix = "r"

[ident_formats.field_writer]
case = "constant"
suffix = "w"

cc @Emilgardis what do you think? This should not be a breaking change.

Emilgardis commented 9 months ago

I like it :)

burrbull commented 9 months ago

Could we merge this as it is?

Emilgardis commented 9 months ago

/ci diff pr

github-actions[bot] commented 9 months ago

Diff for comment

Emilgardis commented 9 months ago

is the diff ok?

@@ -87431,13 +87431,13 @@ pub struct Peripherals {
     pub OTG_FS_HOST: OTG_FS_HOST,
     ///OTG_FS_PWRCLK
     pub OTG_FS_PWRCLK: OTG_FS_PWRCLK,
-    ///ETHERNET_MMC
+    ///Ethernet_MMC
     pub ETHERNET_MMC: ETHERNET_MMC,
-    ///ETHERNET_MAC
+    ///Ethernet_MAC
     pub ETHERNET_MAC: ETHERNET_MAC,
-    ///ETHERNET_PTP
+    ///Ethernet_PTP
     pub ETHERNET_PTP: ETHERNET_PTP,
-    ///ETHERNET_DMA
+    ///Ethernet_DMA
     pub ETHERNET_DMA: ETHERNET_DMA,
     ///SCB_ACTRL
     pub SCB_ACTRL: SCB_ACTRL,
burrbull commented 9 months ago

Yes. I think it is better do not change case of peripheral name in documentation.