svdtools/common/
svd_reader.rs1use anyhow::Result;
2use std::{fs::File, io::Read, path::Path};
3use svd_parser::svd::{Device, Peripheral};
4
5pub fn peripherals<R: Read>(svd: &mut R) -> Result<Vec<Peripheral>> {
6 let xml = &mut String::new();
7 svd.read_to_string(xml).unwrap();
8 let device = parse_device(xml)?;
9 Ok(device.peripherals)
10}
11
12fn parse_device(xml: &str) -> Result<Device> {
13 svd_parser::parse(xml)
14}
15
16pub fn device(path: &Path) -> Result<Device> {
17 let xml = &mut String::new();
18 let mut svd_file = File::open(path).expect("svd path is not correct");
19 svd_file.read_to_string(xml).unwrap();
20 parse_device(xml)
21}