Skip to content

Commit

Permalink
generate SVD-YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Mar 29, 2024
1 parent 6256183 commit 8ee0719
Show file tree
Hide file tree
Showing 14 changed files with 345,048 additions and 5 deletions.
31,810 changes: 31,810 additions & 0 deletions esp32/svd/esp32.svd.yaml

Large diffs are not rendered by default.

15,269 changes: 15,269 additions & 0 deletions esp32c2/svd/esp32c2.svd.yaml

Large diffs are not rendered by default.

24,629 changes: 24,629 additions & 0 deletions esp32c3/svd/esp32c3.svd.yaml

Large diffs are not rendered by default.

4,582 changes: 4,582 additions & 0 deletions esp32c6-lp/svd/esp32c6-lp.svd.yaml

Large diffs are not rendered by default.

49,968 changes: 49,968 additions & 0 deletions esp32c6/svd/esp32c6.svd.yaml

Large diffs are not rendered by default.

37,846 changes: 37,846 additions & 0 deletions esp32h2/svd/esp32h2.svd.yaml

Large diffs are not rendered by default.

92,833 changes: 92,833 additions & 0 deletions esp32p4/svd/esp32p4.svd.yaml

Large diffs are not rendered by default.

1,905 changes: 1,905 additions & 0 deletions esp32s2-ulp/svd/esp32s2-ulp.svd.yaml

Large diffs are not rendered by default.

33,272 changes: 33,272 additions & 0 deletions esp32s2/svd/esp32s2.svd.yaml

Large diffs are not rendered by default.

3,359 changes: 3,359 additions & 0 deletions esp32s3-ulp/svd/esp32s3-ulp.svd.yaml

Large diffs are not rendered by default.

49,533 changes: 49,533 additions & 0 deletions esp32s3/svd/esp32s3.svd.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions xtask/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ log = "0.4.20"
semver = "1.0.21"
strum = { version = "0.26.1", features = ["derive"] }
svd2rust = { version = "0.32.0", default-features = false }
svdtools = "0.3.12"
svdtools = "0.3.13"
toml_edit = "0.22.4"
41 changes: 39 additions & 2 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use anyhow::{Error, Result};
use clap::{Parser, Subcommand, ValueEnum};
use strum::{Display, EnumIter, IntoEnumIterator};
use svd2rust::{
config::{IdentFormats, IdentFormatsTheme}, util::IdentFormat, Config, Target
config::{IdentFormats, IdentFormatsTheme},
util::IdentFormat,
Config, Target,
};
use svdtools::{html::html_cli::svd2html, patch::Config as PatchConfig};
use toml_edit::Document;
Expand Down Expand Up @@ -67,6 +69,13 @@ enum Commands {
chips: Vec<Chip>,
},

/// Patches and generates SVD-like YAML
SvdYaml {
/// Package(s) to target
#[arg(value_enum, default_values_t = Chip::iter())]
chips: Vec<Chip>,
},

/// Generate the specified package(s)
///
/// Additionally patches the releavant SVD(s) prior to generating the
Expand Down Expand Up @@ -130,6 +139,10 @@ fn main() -> Result<()> {
.iter()
.try_for_each(|chip| patch_svd(&workspace, chip)),

Commands::SvdYaml { chips } => chips
.iter()
.try_for_each(|chip| generate_yaml(&workspace, chip)),

Commands::Generate { chips } => chips
.iter()
.try_for_each(|chip: &Chip| generate_package(&workspace, chip)),
Expand Down Expand Up @@ -182,6 +195,27 @@ fn patch_svd(workspace: &Path, chip: &Chip) -> Result<()> {
Ok(())
}

fn generate_yaml(workspace: &Path, chip: &Chip) -> Result<()> {
use svdtools::convert::convert_cli::{convert, InputFormat, OutputFormat, ParserConfig};
patch_svd(workspace, chip)?;
let svd_path = workspace.join(chip.to_string()).join("svd");
let from = svd_path.join(format!("{chip}.svd"));
let to = svd_path.join(format!("{chip}.svd.yaml"));
let parser_config = ParserConfig {
expand: false,
expand_properties: false,
ignore_enums: false,
};
convert(
&from,
&to,
Some(InputFormat::Xml),
Some(OutputFormat::Yaml),
parser_config,
None,
)
}

fn generate_package(workspace: &Path, chip: &Chip) -> Result<()> {
// Patch the SVD prior to generating the package:
patch_svd(workspace, chip)?;
Expand Down Expand Up @@ -222,7 +256,10 @@ fn generate_package(workspace: &Path, chip: &Chip) -> Result<()> {
_ => IdentFormats::default_theme(),
};
ident_formats.insert("enum_name".into(), IdentFormat::default().constant_case());
ident_formats.insert("enum_read_name".into(), IdentFormat::default().constant_case());
ident_formats.insert(
"enum_read_name".into(),
IdentFormat::default().constant_case(),
);
ident_formats.insert("enum_value".into(), IdentFormat::default().pascal_case());
ident_formats.extend(config.ident_formats.drain());
config.ident_formats = ident_formats;
Expand Down

0 comments on commit 8ee0719

Please sign in to comment.