aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Kröger <[email protected]>2021-07-30 17:06:58 +0200
committerTimo Kröger <[email protected]>2021-08-03 17:58:26 +0200
commitfba8b86005958fafa7e188b20b4212773ce912cb (patch)
treed6ead97361d6612f264350ddebf5f318ef1d606c
parentad62900a4004f53f7831547bcc75a564d5b8d2ad (diff)
BTreeMaps to preserve ordering of generated code
Makes diffing of changes easier
-rw-r--r--stm32-metapac-gen/src/lib.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs
index 5e0cc58d4..8a2698d8e 100644
--- a/stm32-metapac-gen/src/lib.rs
+++ b/stm32-metapac-gen/src/lib.rs
@@ -1,7 +1,7 @@
1use chiptool::generate::CommonModule; 1use chiptool::generate::CommonModule;
2use regex::Regex; 2use regex::Regex;
3use serde::Deserialize; 3use serde::Deserialize;
4use std::collections::{HashMap, HashSet}; 4use std::collections::{BTreeMap, HashMap, HashSet};
5use std::env; 5use std::env;
6use std::fmt::Write as _; 6use std::fmt::Write as _;
7use std::fs; 7use std::fs;
@@ -39,9 +39,9 @@ pub struct MemoryRegion {
39#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] 39#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
40pub struct Core { 40pub struct Core {
41 pub name: String, 41 pub name: String,
42 pub peripherals: HashMap<String, Peripheral>, 42 pub peripherals: BTreeMap<String, Peripheral>,
43 pub interrupts: HashMap<String, u32>, 43 pub interrupts: BTreeMap<String, u32>,
44 pub dma_channels: HashMap<String, DmaChannel>, 44 pub dma_channels: BTreeMap<String, DmaChannel>,
45} 45}
46 46
47#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] 47#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
@@ -62,9 +62,9 @@ pub struct Peripheral {
62 #[serde(default)] 62 #[serde(default)]
63 pub pins: Vec<Pin>, 63 pub pins: Vec<Pin>,
64 #[serde(default)] 64 #[serde(default)]
65 pub dma_channels: HashMap<String, Vec<PeripheralDmaChannel>>, 65 pub dma_channels: BTreeMap<String, Vec<PeripheralDmaChannel>>,
66 #[serde(default)] 66 #[serde(default)]
67 pub interrupts: HashMap<String, String>, 67 pub interrupts: BTreeMap<String, String>,
68} 68}
69 69
70#[derive(Debug, Eq, PartialEq, Clone, Deserialize)] 70#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
@@ -144,7 +144,7 @@ fn find_reg_for_field<'c>(
144 }) 144 })
145} 145}
146 146
147fn make_peripheral_counts(out: &mut String, data: &HashMap<String, u8>) { 147fn make_peripheral_counts(out: &mut String, data: &BTreeMap<String, u8>) {
148 write!( 148 write!(
149 out, 149 out,
150 "#[macro_export] 150 "#[macro_export]
@@ -158,7 +158,7 @@ macro_rules! peripheral_count {{
158 write!(out, " }}\n").unwrap(); 158 write!(out, " }}\n").unwrap();
159} 159}
160 160
161fn make_dma_channel_counts(out: &mut String, data: &HashMap<String, u8>) { 161fn make_dma_channel_counts(out: &mut String, data: &BTreeMap<String, u8>) {
162 write!( 162 write!(
163 out, 163 out,
164 "#[macro_export] 164 "#[macro_export]
@@ -219,7 +219,7 @@ pub fn gen(options: Options) {
219 println!("cwd: {:?}", env::current_dir()); 219 println!("cwd: {:?}", env::current_dir());
220 220
221 let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new(); 221 let mut all_peripheral_versions: HashSet<(String, String)> = HashSet::new();
222 let mut chip_cores: HashMap<String, Option<String>> = HashMap::new(); 222 let mut chip_cores: BTreeMap<String, Option<String>> = BTreeMap::new();
223 223
224 for chip_name in &options.chips { 224 for chip_name in &options.chips {
225 let mut s = chip_name.split('_'); 225 let mut s = chip_name.split('_');
@@ -291,7 +291,7 @@ pub fn gen(options: Options) {
291 } 291 }
292 }); 292 });
293 293
294 let mut peripheral_versions: HashMap<String, String> = HashMap::new(); 294 let mut peripheral_versions: BTreeMap<String, String> = BTreeMap::new();
295 let mut pin_table: Vec<Vec<String>> = Vec::new(); 295 let mut pin_table: Vec<Vec<String>> = Vec::new();
296 let mut interrupt_table: Vec<Vec<String>> = Vec::new(); 296 let mut interrupt_table: Vec<Vec<String>> = Vec::new();
297 let mut peripherals_table: Vec<Vec<String>> = Vec::new(); 297 let mut peripherals_table: Vec<Vec<String>> = Vec::new();
@@ -299,8 +299,8 @@ pub fn gen(options: Options) {
299 let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new(); 299 let mut peripheral_rcc_table: Vec<Vec<String>> = Vec::new();
300 let mut dma_channels_table: Vec<Vec<String>> = Vec::new(); 300 let mut dma_channels_table: Vec<Vec<String>> = Vec::new();
301 let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new(); 301 let mut peripheral_dma_channels_table: Vec<Vec<String>> = Vec::new();
302 let mut peripheral_counts: HashMap<String, u8> = HashMap::new(); 302 let mut peripheral_counts: BTreeMap<String, u8> = BTreeMap::new();
303 let mut dma_channel_counts: HashMap<String, u8> = HashMap::new(); 303 let mut dma_channel_counts: BTreeMap<String, u8> = BTreeMap::new();
304 let mut dbgmcu_table: Vec<Vec<String>> = Vec::new(); 304 let mut dbgmcu_table: Vec<Vec<String>> = Vec::new();
305 let mut gpio_rcc_table: Vec<Vec<String>> = Vec::new(); 305 let mut gpio_rcc_table: Vec<Vec<String>> = Vec::new();
306 let mut gpio_regs: HashSet<String> = HashSet::new(); 306 let mut gpio_regs: HashSet<String> = HashSet::new();
@@ -504,10 +504,10 @@ pub fn gen(options: Options) {
504 } 504 }
505 } 505 }
506 (None, Some(_)) => { 506 (None, Some(_)) => {
507 print!("Unable to find enable register for {}", name) 507 println!("Unable to find enable register for {}", name)
508 } 508 }
509 (None, None) => { 509 (None, None) => {
510 print!("Unable to find enable and reset register for {}", name) 510 println!("Unable to find enable and reset register for {}", name)
511 } 511 }
512 } 512 }
513 } 513 }