@@ -95,18 +95,36 @@ fn main() -> Result<(), String> {
95
95
}
96
96
97
97
match generate {
98
- GenerateTarget :: Features => generate_features ( & mcu_gpio_map) ?,
98
+ GenerateTarget :: Features => generate_features ( & mcu_gpio_map, & mcu_family ) ?,
99
99
GenerateTarget :: PinMappings => generate_pin_mappings ( & mcu_gpio_map, & db_dir) ?,
100
100
} ;
101
101
102
102
Ok ( ( ) )
103
103
}
104
104
105
+ lazy_static ! {
106
+ static ref FEATURE_DEPENDENCIES : HashMap <& ' static str , HashMap <& ' static str , & ' static str >> = {
107
+ let mut m = HashMap :: new( ) ;
108
+
109
+ // STM32L0
110
+ let mut l0 = HashMap :: new( ) ;
111
+ l0. insert( "^STM32L0.1" , "stm32l0/stm32l0x1" ) ;
112
+ l0. insert( "^STM32L0.2" , "stm32l0/stm32l0x2" ) ;
113
+ l0. insert( "^STM32L0.3" , "stm32l0/stm32l0x3" ) ;
114
+ m. insert( "STM32L0" , l0) ;
115
+
116
+ m
117
+ } ;
118
+ }
119
+
105
120
/// Print the IO features, followed by MCU features that act purely as aliases
106
121
/// for the IO features.
107
122
///
108
123
/// Both lists are sorted alphanumerically.
109
- fn generate_features ( mcu_gpio_map : & HashMap < String , Vec < String > > ) -> Result < ( ) , String > {
124
+ fn generate_features (
125
+ mcu_gpio_map : & HashMap < String , Vec < String > > ,
126
+ mcu_family : & str ,
127
+ ) -> Result < ( ) , String > {
110
128
let mut main_features = mcu_gpio_map
111
129
. keys ( )
112
130
. map ( |gpio| gpio_version_to_feature ( gpio) )
@@ -117,18 +135,46 @@ fn generate_features(mcu_gpio_map: &HashMap<String, Vec<String>>) -> Result<(),
117
135
for ( gpio, mcu_list) in mcu_gpio_map {
118
136
let gpio_version_feature = gpio_version_to_feature ( gpio) . unwrap ( ) ;
119
137
for mcu in mcu_list {
138
+ let mut dependencies = vec ! [ ] ;
139
+
140
+ // PAC feature
141
+ if let Some ( family) = FEATURE_DEPENDENCIES . get ( mcu_family) {
142
+ for ( pattern, feature) in family {
143
+ if Regex :: new ( pattern) . unwrap ( ) . is_match ( & mcu) {
144
+ dependencies. push ( feature. to_string ( ) ) ;
145
+ break ;
146
+ }
147
+ }
148
+ }
149
+
150
+ // GPIO version feature
151
+ dependencies. push ( gpio_version_feature. clone ( ) ) ;
152
+
120
153
let mcu_feature = format ! ( "mcu-{}" , mcu) ;
121
- mcu_aliases. push ( format ! ( "{} = [\" {}\" ]" , mcu_feature, gpio_version_feature) ) ;
154
+ mcu_aliases. push ( format ! (
155
+ "{} = [{}]" ,
156
+ mcu_feature,
157
+ & dependencies. iter( ) . map( |val| format!( "\" {}\" " , val) ) . fold(
158
+ String :: new( ) ,
159
+ |mut acc, x| {
160
+ if !acc. is_empty( ) {
161
+ acc. push_str( ", " ) ;
162
+ }
163
+ acc. push_str( & x) ;
164
+ acc
165
+ }
166
+ )
167
+ ) ) ;
122
168
}
123
169
}
124
170
mcu_aliases. sort ( ) ;
125
171
126
- println ! ( "// Features based on the GPIO peripheral version." ) ;
127
- println ! ( "// This determines the pin function mapping of the MCU." ) ;
172
+ println ! ( "# Features based on the GPIO peripheral version." ) ;
173
+ println ! ( "# This determines the pin function mapping of the MCU." ) ;
128
174
for feature in main_features {
129
175
println ! ( "{} = []" , feature) ;
130
176
}
131
- println ! ( "\n // Per-MCU aliases for the GPIO peripheral version." ) ;
177
+ println ! ( "\n # Per-MCU aliases for the GPIO peripheral version." ) ;
132
178
for alias in mcu_aliases {
133
179
println ! ( "{}" , alias) ;
134
180
}
0 commit comments