diff options
| m--------- | stm32-data | 0 | ||||
| -rw-r--r-- | stm32-metapac/build.rs | 43 |
2 files changed, 36 insertions, 7 deletions
diff --git a/stm32-data b/stm32-data | |||
| Subproject dfc67fe255e1e70101e9f1e3fb8b4fd8bb37362 | Subproject 33dfa674865b1b5f0bfb86f3217055a6a057a6f | ||
diff --git a/stm32-metapac/build.rs b/stm32-metapac/build.rs index 49ca76201..1d0696ba9 100644 --- a/stm32-metapac/build.rs +++ b/stm32-metapac/build.rs | |||
| @@ -40,11 +40,22 @@ pub struct Peripheral { | |||
| 40 | pub block: Option<String>, | 40 | pub block: Option<String>, |
| 41 | #[serde(default)] | 41 | #[serde(default)] |
| 42 | pub clock: Option<String>, | 42 | pub clock: Option<String>, |
| 43 | #[serde(default)] | ||
| 44 | pub pins: Option<Vec<Pin>>, | ||
| 45 | } | ||
| 46 | |||
| 47 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize)] | ||
| 48 | pub struct Pin { | ||
| 49 | pub pin: String, | ||
| 50 | pub signal: String, | ||
| 51 | pub af: Option<String>, | ||
| 43 | } | 52 | } |
| 44 | 53 | ||
| 45 | struct BlockInfo { | 54 | struct BlockInfo { |
| 46 | module: String, // usart_v1/USART -> usart | 55 | module: String, |
| 47 | version: String, // usart_v1/USART -> v1 | 56 | // usart_v1/USART -> usart |
| 57 | version: String, | ||
| 58 | // usart_v1/USART -> v1 | ||
| 48 | block: String, // usart_v1/USART -> USART | 59 | block: String, // usart_v1/USART -> USART |
| 49 | } | 60 | } |
| 50 | 61 | ||
| @@ -79,7 +90,7 @@ macro_rules! {} {{ | |||
| 79 | ", | 90 | ", |
| 80 | name, name | 91 | name, name |
| 81 | ) | 92 | ) |
| 82 | .unwrap(); | 93 | .unwrap(); |
| 83 | 94 | ||
| 84 | for row in data { | 95 | for row in data { |
| 85 | write!(out, " __{}_inner!(({}));\n", name, row.join(",")).unwrap(); | 96 | write!(out, " __{}_inner!(({}));\n", name, row.join(",")).unwrap(); |
| @@ -90,7 +101,7 @@ macro_rules! {} {{ | |||
| 90 | " }}; | 101 | " }}; |
| 91 | }}" | 102 | }}" |
| 92 | ) | 103 | ) |
| 93 | .unwrap(); | 104 | .unwrap(); |
| 94 | } | 105 | } |
| 95 | 106 | ||
| 96 | fn main() { | 107 | fn main() { |
| @@ -123,6 +134,7 @@ fn main() { | |||
| 123 | let mut cfgs: HashSet<String> = HashSet::new(); | 134 | let mut cfgs: HashSet<String> = HashSet::new(); |
| 124 | let mut pin_table: Vec<Vec<String>> = Vec::new(); | 135 | let mut pin_table: Vec<Vec<String>> = Vec::new(); |
| 125 | let mut interrupt_table: Vec<Vec<String>> = Vec::new(); | 136 | let mut interrupt_table: Vec<Vec<String>> = Vec::new(); |
| 137 | let mut peripheral_pins_table: Vec<Vec<String>> = Vec::new(); | ||
| 126 | 138 | ||
| 127 | let dma_base = chip | 139 | let dma_base = chip |
| 128 | .peripherals | 140 | .peripherals |
| @@ -149,11 +161,27 @@ fn main() { | |||
| 149 | if let Some(block) = &p.block { | 161 | if let Some(block) = &p.block { |
| 150 | let bi = BlockInfo::parse(block); | 162 | let bi = BlockInfo::parse(block); |
| 151 | 163 | ||
| 164 | if let Some(pins) = &p.pins { | ||
| 165 | for pin in pins { | ||
| 166 | let mut row = Vec::new(); | ||
| 167 | row.push(name.clone()); | ||
| 168 | row.push(bi.module.clone()); | ||
| 169 | row.push(bi.block.clone()); | ||
| 170 | row.push(pin.pin.clone()); | ||
| 171 | row.push(pin.signal.clone()); | ||
| 172 | if let Some(ref af) = pin.af { | ||
| 173 | row.push(af.clone()); | ||
| 174 | } | ||
| 175 | peripheral_pins_table.push(row); | ||
| 176 | } | ||
| 177 | } | ||
| 178 | |||
| 179 | |||
| 152 | cfgs.insert(bi.module.clone()); | 180 | cfgs.insert(bi.module.clone()); |
| 153 | cfgs.insert(format!("{}_{}", bi.module, bi.version)); | 181 | cfgs.insert(format!("{}_{}", bi.module, bi.version)); |
| 154 | 182 | ||
| 155 | if let Some(old_version) = | 183 | if let Some(old_version) = |
| 156 | peripheral_versions.insert(bi.module.clone(), bi.version.clone()) | 184 | peripheral_versions.insert(bi.module.clone(), bi.version.clone()) |
| 157 | { | 185 | { |
| 158 | if old_version != bi.version { | 186 | if old_version != bi.version { |
| 159 | panic!( | 187 | panic!( |
| @@ -227,6 +255,7 @@ fn main() { | |||
| 227 | make_table(&mut extra, "pins", &pin_table); | 255 | make_table(&mut extra, "pins", &pin_table); |
| 228 | make_table(&mut extra, "interrupts", &interrupt_table); | 256 | make_table(&mut extra, "interrupts", &interrupt_table); |
| 229 | make_table(&mut extra, "peripheral_versions", &peripheral_version_table); | 257 | make_table(&mut extra, "peripheral_versions", &peripheral_version_table); |
| 258 | make_table(&mut extra, "peripheral_pins", &peripheral_pins_table); | ||
| 230 | 259 | ||
| 231 | for (module, version) in peripheral_versions { | 260 | for (module, version) in peripheral_versions { |
| 232 | println!("loading {} {}", module, version); | 261 | println!("loading {} {}", module, version); |
| @@ -248,7 +277,7 @@ fn main() { | |||
| 248 | transform::NameKind::Enum => format!("{}::vals::{}", prefix, s), | 277 | transform::NameKind::Enum => format!("{}::vals::{}", prefix, s), |
| 249 | _ => s.to_string(), | 278 | _ => s.to_string(), |
| 250 | }) | 279 | }) |
| 251 | .unwrap(); | 280 | .unwrap(); |
| 252 | 281 | ||
| 253 | ir.merge(peri); | 282 | ir.merge(peri); |
| 254 | } | 283 | } |
| @@ -277,7 +306,7 @@ fn main() { | |||
| 277 | "PROVIDE({} = DefaultHandler);\n", | 306 | "PROVIDE({} = DefaultHandler);\n", |
| 278 | name.to_ascii_uppercase() | 307 | name.to_ascii_uppercase() |
| 279 | ) | 308 | ) |
| 280 | .unwrap(); | 309 | .unwrap(); |
| 281 | } | 310 | } |
| 282 | 311 | ||
| 283 | File::create(out.join("device.x")) | 312 | File::create(out.join("device.x")) |
