mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-27 20:30:35 +00:00
Tweak config table (#3734)
* Tweak config table * Restore active condition on xtal-frequenc * Print values using display hint * Fix clippy lints
This commit is contained in:
parent
b76a738263
commit
a7798f6902
@ -145,7 +145,7 @@ fn parse_configs(
|
|||||||
chip_from_args: Option<esp_metadata::Chip>,
|
chip_from_args: Option<esp_metadata::Chip>,
|
||||||
config_file: Option<&str>,
|
config_file: Option<&str>,
|
||||||
) -> Result<Vec<CrateConfig>, Box<dyn Error>> {
|
) -> Result<Vec<CrateConfig>, Box<dyn Error>> {
|
||||||
let config_toml_path = path.join(config_file.as_deref().unwrap_or(DEFAULT_CONFIG_PATH));
|
let config_toml_path = path.join(config_file.unwrap_or(DEFAULT_CONFIG_PATH));
|
||||||
let config_toml_content = std::fs::read_to_string(config_toml_path)?;
|
let config_toml_content = std::fs::read_to_string(config_toml_path)?;
|
||||||
let config_toml = config_toml_content.as_str().parse::<DocumentMut>()?;
|
let config_toml = config_toml_content.as_str().parse::<DocumentMut>()?;
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ impl Item {
|
|||||||
match self {
|
match self {
|
||||||
Item::TopLevel(crate_name) => crate_name.clone(),
|
Item::TopLevel(crate_name) => crate_name.clone(),
|
||||||
Item::CrateLevel(config_option) => {
|
Item::CrateLevel(config_option) => {
|
||||||
let display_value = format_using_display_hint(
|
let display_value = config_option
|
||||||
&config_option.actual_value,
|
.option
|
||||||
&config_option.option.display_hint,
|
.display_hint
|
||||||
);
|
.format_value(&config_option.actual_value);
|
||||||
let default_indicator =
|
let default_indicator =
|
||||||
if config_option.actual_value == config_option.option.default_value {
|
if config_option.actual_value == config_option.option.default_value {
|
||||||
ui_elements.default_value
|
ui_elements.default_value
|
||||||
@ -81,24 +81,11 @@ impl Item {
|
|||||||
fn display_hint(&self) -> DisplayHint {
|
fn display_hint(&self) -> DisplayHint {
|
||||||
match self {
|
match self {
|
||||||
Item::TopLevel(_) => unreachable!(),
|
Item::TopLevel(_) => unreachable!(),
|
||||||
Item::CrateLevel(config_option) => config_option.option.display_hint.clone(),
|
Item::CrateLevel(config_option) => config_option.option.display_hint,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_using_display_hint(value: &Value, hint: &DisplayHint) -> String {
|
|
||||||
match value {
|
|
||||||
Value::Bool(b) => b.to_string(),
|
|
||||||
Value::Integer(i) => match hint {
|
|
||||||
DisplayHint::None => format!("{}", i),
|
|
||||||
DisplayHint::Binary => format!("0b{:0b}", i),
|
|
||||||
DisplayHint::Hex => format!("0x{:x}", i),
|
|
||||||
DisplayHint::Octal => format!("0o{:o}", i),
|
|
||||||
},
|
|
||||||
Value::String(s) => s.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Repository {
|
impl Repository {
|
||||||
pub fn new(options: Vec<crate::CrateConfig>) -> Self {
|
pub fn new(options: Vec<crate::CrateConfig>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -474,11 +461,10 @@ impl App<'_> {
|
|||||||
self.handle_error(set_res);
|
self.handle_error(set_res);
|
||||||
}
|
}
|
||||||
Value::Integer(_) => {
|
Value::Integer(_) => {
|
||||||
let display_value = format_using_display_hint(
|
let display_value = self.repository.current_level()
|
||||||
¤t,
|
[selected]
|
||||||
&self.repository.current_level()[selected]
|
.display_hint()
|
||||||
.display_hint(),
|
.format_value(¤t);
|
||||||
);
|
|
||||||
self.textarea =
|
self.textarea =
|
||||||
make_text_area(&display_value, &self.colors);
|
make_text_area(&display_value, &self.colors);
|
||||||
self.editing_constraints = constraint;
|
self.editing_constraints = constraint;
|
||||||
|
@ -3,8 +3,8 @@ use std::fmt::Write;
|
|||||||
use crate::{ConfigOption, Value};
|
use crate::{ConfigOption, Value};
|
||||||
|
|
||||||
pub(crate) const DOC_TABLE_HEADER: &str = r#"
|
pub(crate) const DOC_TABLE_HEADER: &str = r#"
|
||||||
| Name | Description | Default value | Allowed value |
|
| Option | Stability | Default value | Allowed values |
|
||||||
|------|-------------|--------------------|--------------------|
|
|--------|:---------:|:------------------:|:-------------------:|
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
pub(crate) const SELECTED_TABLE_HEADER: &str = r#"
|
pub(crate) const SELECTED_TABLE_HEADER: &str = r#"
|
||||||
@ -21,11 +21,11 @@ pub(crate) fn write_doc_table_line(mut table: impl Write, name: &str, option: &C
|
|||||||
|
|
||||||
writeln!(
|
writeln!(
|
||||||
table,
|
table,
|
||||||
"| <p>{key}</p><p>{stability}</p> | <p>{description}</p> | <center>{default}</center> | <center>{allowed}</center>",
|
"| <p>**{key}**</p> <p>{description}</p> | {stability} | {default} | {allowed}",
|
||||||
description = option.description,
|
description = option.description,
|
||||||
key = name,
|
key = name,
|
||||||
stability = option.stability,
|
stability = option.stability,
|
||||||
default = option.default_value,
|
default = option.display_hint.format_value(&option.default_value),
|
||||||
allowed = allowed_values
|
allowed = allowed_values
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -440,7 +440,7 @@ impl Display for Stability {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A display hint (for tooling only)
|
/// A display hint (for tooling only)
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum DisplayHint {
|
pub enum DisplayHint {
|
||||||
/// No display hint
|
/// No display hint
|
||||||
None,
|
None,
|
||||||
@ -455,6 +455,22 @@ pub enum DisplayHint {
|
|||||||
Octal,
|
Octal,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DisplayHint {
|
||||||
|
/// Converts a [Value] to String applying the correct display hint.
|
||||||
|
pub fn format_value(self, value: &Value) -> String {
|
||||||
|
match value {
|
||||||
|
Value::Bool(b) => b.to_string(),
|
||||||
|
Value::Integer(i) => match self {
|
||||||
|
DisplayHint::None => format!("{i}"),
|
||||||
|
DisplayHint::Binary => format!("0b{i:0b}"),
|
||||||
|
DisplayHint::Hex => format!("0x{i:X}"),
|
||||||
|
DisplayHint::Octal => format!("0o{i:o}"),
|
||||||
|
},
|
||||||
|
Value::String(s) => s.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A configuration option.
|
/// A configuration option.
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ConfigOption {
|
pub struct ConfigOption {
|
||||||
|
@ -55,6 +55,7 @@ options:
|
|||||||
validator: enumeration
|
validator: enumeration
|
||||||
value:
|
value:
|
||||||
- '32'
|
- '32'
|
||||||
|
active: 'chip == "esp32" || chip == "esp32c2"'
|
||||||
|
|
||||||
- name: spi-address-workaround
|
- name: spi-address-workaround
|
||||||
description: "Enables a workaround for the issue where SPI in
|
description: "Enables a workaround for the issue where SPI in
|
||||||
|
Loading…
x
Reference in New Issue
Block a user