11use anyhow:: { bail, Result } ;
22use std:: path:: { Path , PathBuf } ;
33
4- #[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) ) ]
4+ #[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) , serde ( default ) ) ]
55#[ derive( Clone , PartialEq , Eq , Debug , Default ) ]
6- #[ cfg_attr( feature = "serde" , serde( default ) ) ]
76pub struct Config {
87 pub target : Target ,
98 pub atomics : bool ,
@@ -28,6 +27,7 @@ pub struct Config {
2827 pub interrupt_link_section : Option < String > ,
2928 pub reexport_core_peripherals : bool ,
3029 pub reexport_interrupt : bool ,
30+ pub ident_formats : IdentFormats ,
3131}
3232
3333#[ allow( clippy:: upper_case_acronyms) ]
@@ -116,3 +116,84 @@ impl SourceType {
116116 . unwrap_or_default ( )
117117 }
118118}
119+
120+ #[ cfg_attr(
121+ feature = "serde" ,
122+ derive( serde:: Deserialize ) ,
123+ serde( rename_all = "lowercase" )
124+ ) ]
125+ #[ derive( Clone , Debug , PartialEq , Eq , Default ) ]
126+ #[ non_exhaustive]
127+ pub enum Case {
128+ #[ default]
129+ Constant ,
130+ Pascal ,
131+ Snake ,
132+ }
133+
134+ #[ derive( Clone , Debug , Default , PartialEq , Eq ) ]
135+ #[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) , serde( default ) ) ]
136+ pub struct IdentFormat {
137+ pub case : Option < Case > ,
138+ pub prefix : String ,
139+ pub suffix : String ,
140+ }
141+
142+ impl IdentFormat {
143+ pub fn case ( mut self , case : Case ) -> Self {
144+ self . case = Some ( case) ;
145+ self
146+ }
147+ pub fn constant_case ( mut self ) -> Self {
148+ self . case = Some ( Case :: Constant ) ;
149+ self
150+ }
151+ pub fn pascal_case ( mut self ) -> Self {
152+ self . case = Some ( Case :: Pascal ) ;
153+ self
154+ }
155+ pub fn scake_case ( mut self ) -> Self {
156+ self . case = Some ( Case :: Pascal ) ;
157+ self
158+ }
159+ pub fn prefix ( mut self , prefix : & str ) -> Self {
160+ self . prefix = prefix. into ( ) ;
161+ self
162+ }
163+ pub fn suffix ( mut self , suffix : & str ) -> Self {
164+ self . suffix = suffix. into ( ) ;
165+ self
166+ }
167+ }
168+
169+ #[ derive( Clone , Debug , PartialEq , Eq ) ]
170+ #[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) , serde( default ) ) ]
171+ pub struct IdentFormats {
172+ pub field_reader : IdentFormat ,
173+ pub field_writer : IdentFormat ,
174+ pub enum_name : IdentFormat ,
175+ pub enum_write_name : IdentFormat ,
176+ pub enum_value : IdentFormat ,
177+ pub interrupt : IdentFormat ,
178+ pub cluster : IdentFormat ,
179+ pub register : IdentFormat ,
180+ pub register_spec : IdentFormat ,
181+ pub peripheral : IdentFormat ,
182+ }
183+
184+ impl Default for IdentFormats {
185+ fn default ( ) -> Self {
186+ Self {
187+ field_reader : IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_R" ) ,
188+ field_writer : IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_W" ) ,
189+ enum_name : IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_A" ) ,
190+ enum_write_name : IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_AW" ) ,
191+ enum_value : IdentFormat :: default ( ) . constant_case ( ) ,
192+ interrupt : IdentFormat :: default ( ) . constant_case ( ) ,
193+ cluster : IdentFormat :: default ( ) . constant_case ( ) ,
194+ register : IdentFormat :: default ( ) . constant_case ( ) ,
195+ register_spec : IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_SPEC" ) ,
196+ peripheral : IdentFormat :: default ( ) . constant_case ( ) ,
197+ }
198+ }
199+ }
0 commit comments