@@ -77,25 +77,38 @@ fn main() -> Result<(), String> {
77
77
. find ( |v| v. name == mcu_family)
78
78
. ok_or_else ( || format ! ( "Could not find family {}" , mcu_family) ) ?;
79
79
80
- // Build MCU map
80
+ // MCU map
81
81
//
82
82
// The keys of this map are GPIO peripheral version strings (e.g.
83
83
// "STM32L051_gpio_v1_0"), while the value is a Vec of MCU ref names.
84
84
let mut mcu_gpio_map: HashMap < String , Vec < String > > = HashMap :: new ( ) ;
85
+
86
+ // Package map
87
+ //
88
+ // The keys of this map are MCU ref names, the values are package names
89
+ // (e.g. ).
90
+ let mut mcu_package_map: HashMap < String , String > = HashMap :: new ( ) ;
91
+
85
92
for sf in family {
86
93
for mcu in sf {
87
94
let mcu_dat = mcu:: Mcu :: load ( & db_dir, & mcu. name )
88
95
. map_err ( |e| format ! ( "Could not load MCU data: {}" , e) ) ?;
96
+
89
97
let gpio_version = mcu_dat. get_ip ( "GPIO" ) . unwrap ( ) . get_version ( ) . to_string ( ) ;
90
98
mcu_gpio_map
91
99
. entry ( gpio_version)
92
100
. or_insert ( vec ! [ ] )
93
101
. push ( mcu. ref_name . clone ( ) ) ;
102
+
103
+ if mcu_family == "STM32L0" {
104
+ // The stm32l0xx-hal has package based features
105
+ mcu_package_map. insert ( mcu. ref_name . clone ( ) , mcu. package_name . clone ( ) ) ;
106
+ }
94
107
}
95
108
}
96
109
97
110
match generate {
98
- GenerateTarget :: Features => generate_features ( & mcu_gpio_map, & mcu_family) ?,
111
+ GenerateTarget :: Features => generate_features ( & mcu_gpio_map, & mcu_package_map , & mcu_family) ?,
99
112
GenerateTarget :: PinMappings => generate_pin_mappings ( & mcu_gpio_map, & db_dir) ?,
100
113
} ;
101
114
@@ -108,9 +121,9 @@ lazy_static! {
108
121
109
122
// STM32L0
110
123
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" ) ;
124
+ l0. insert( "^STM32L0.1" , "stm32l0x1" ) ;
125
+ l0. insert( "^STM32L0.2" , "stm32l0x2" ) ;
126
+ l0. insert( "^STM32L0.3" , "stm32l0x3" ) ;
114
127
m. insert( "STM32L0" , l0) ;
115
128
116
129
m
@@ -123,6 +136,7 @@ lazy_static! {
123
136
/// Both lists are sorted alphanumerically.
124
137
fn generate_features (
125
138
mcu_gpio_map : & HashMap < String , Vec < String > > ,
139
+ mcu_package_map : & HashMap < String , String > ,
126
140
mcu_family : & str ,
127
141
) -> Result < ( ) , String > {
128
142
let mut main_features = mcu_gpio_map
@@ -137,7 +151,10 @@ fn generate_features(
137
151
for mcu in mcu_list {
138
152
let mut dependencies = vec ! [ ] ;
139
153
140
- // PAC feature
154
+ // GPIO version feature
155
+ dependencies. push ( gpio_version_feature. clone ( ) ) ;
156
+
157
+ // Additional dependencies
141
158
if let Some ( family) = FEATURE_DEPENDENCIES . get ( mcu_family) {
142
159
for ( pattern, feature) in family {
143
160
if Regex :: new ( pattern) . unwrap ( ) . is_match ( & mcu) {
@@ -147,8 +164,10 @@ fn generate_features(
147
164
}
148
165
}
149
166
150
- // GPIO version feature
151
- dependencies. push ( gpio_version_feature. clone ( ) ) ;
167
+ // Package based feature
168
+ if let Some ( package) = mcu_package_map. get ( mcu) {
169
+ dependencies. push ( package. to_lowercase ( ) ) ;
170
+ }
152
171
153
172
let mcu_feature = format ! ( "mcu-{}" , mcu) ;
154
173
mcu_aliases. push ( format ! (
@@ -169,12 +188,23 @@ fn generate_features(
169
188
}
170
189
mcu_aliases. sort ( ) ;
171
190
172
- println ! ( "# Features based on the GPIO peripheral version. " ) ;
173
- println ! ( "# This determines the pin function mapping of the MCU. " ) ;
191
+ println ! ( "# Features based on the GPIO peripheral version" ) ;
192
+ println ! ( "# This determines the pin function mapping of the MCU" ) ;
174
193
for feature in main_features {
175
194
println ! ( "{} = []" , feature) ;
176
195
}
177
- println ! ( "\n # Per-MCU aliases for the GPIO peripheral version." ) ;
196
+ println ! ( ) ;
197
+ if !mcu_package_map. is_empty ( ) {
198
+ println ! ( "# Physical packages" ) ;
199
+ let mut packages = mcu_package_map. values ( ) . map ( |v| v. to_lowercase ( ) ) . collect :: < Vec < _ > > ( ) ;
200
+ packages. sort_by ( |a, b| compare_str ( a, b) ) ;
201
+ packages. dedup ( ) ;
202
+ for pkg in packages {
203
+ println ! ( "{} = []" , pkg) ;
204
+ }
205
+ println ! ( ) ;
206
+ }
207
+ println ! ( "# MCUs" ) ;
178
208
for alias in mcu_aliases {
179
209
println ! ( "{}" , alias) ;
180
210
}
0 commit comments