Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target-gen reformat and hexify some YAML properties #2548

Merged
merged 7 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/added-target-gen-refresh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target-gen: Added `refresh` command to reformat a YAML file or a directory of YAML files.
6 changes: 5 additions & 1 deletion probe-rs-target/src/chip.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::collections::HashMap;

use super::memory::MemoryRegion;
use crate::{serialize::hex_option, CoreType};
use crate::{
serialize::{hex_option, hex_u_int},
CoreType,
};
use serde::{Deserialize, Serialize};

/// Represents a DAP scan chain element.
Expand Down Expand Up @@ -144,6 +147,7 @@ pub struct ArmCoreAccessOptions {
/// The access port number to access the core
pub ap: u8,
/// The port select number to access the core
#[serde(serialize_with = "hex_u_int")]
pub psel: u32,
/// The base address of the debug registers for the core.
/// Required for Cortex-A, optional for Cortex-M
Expand Down
2 changes: 2 additions & 0 deletions probe-rs-target/src/chip_family.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::serialize::hex_jep106_option;
use crate::CoreAccessOptions;

use super::chip::Chip;
Expand Down Expand Up @@ -180,6 +181,7 @@ pub struct ChipFamily {
/// E.g. `nRF52832`.
pub name: String,
/// The JEP106 code of the manufacturer.
#[serde(serialize_with = "hex_jep106_option")]
pub manufacturer: Option<JEP106Code>,
/// The `target-gen` process will set this to `true`.
/// Please change this to `false` if this file is modified from the generated, or is a manually created target description.
Expand Down
37 changes: 37 additions & 0 deletions probe-rs-target/src/serialize/hex_jep106.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use jep106::JEP106Code;
use serde::{Serialize, Serializer};

use crate::serialize::hex_u_int;

#[derive(Copy, Clone, PartialEq, Eq, Serialize)]
struct HexJep106 {
#[serde(with = "hex_u_int")]
id: u8,
#[serde(with = "hex_u_int")]
cc: u8,
}

impl From<JEP106Code> for HexJep106 {
fn from(jep: JEP106Code) -> Self {
Self {
id: jep.id,
cc: jep.cc,
}
}
}

pub fn serialize_option<S>(
variant_value: &Option<JEP106Code>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match variant_value {
Some(val) => {
let val = HexJep106::from(*val);
serializer.serialize_some(&val)
}
None => serializer.serialize_none(),
}
}
2 changes: 1 addition & 1 deletion probe-rs-target/src/serialize/hex_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn serialize<S>(memory_range: &Range<u64>, serializer: S) -> Result<S::Ok, S
where
S: Serializer,
{
// We serialize the range as hex strings when generating human-readable formats such as YAML,
// We serialize the range as hex strings when generating human-readable formats such as YAML
let check_for_human_readable = serializer.is_human_readable();
let mut state = serializer.serialize_struct("Range", 2)?;
if check_for_human_readable {
Expand Down
2 changes: 1 addition & 1 deletion probe-rs-target/src/serialize/hex_u_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ where
S: Serializer,
T: std::fmt::LowerHex + SerializeUnsignedInt,
{
// We serialize the range as hex strings when generating human-readable formats such as YAML,
// We serialize the range as hex strings when generating human-readable formats such as YAML
let check_for_human_readable = serializer.is_human_readable();
if check_for_human_readable {
serializer.serialize_str(format!("{memory_address:#x}").as_str())
Expand Down
2 changes: 2 additions & 0 deletions probe-rs-target/src/serialize/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod hex_jep106;
mod hex_option;
mod hex_range;
mod hex_u_int;
mod serialize_u_int;

pub(crate) use hex_jep106::serialize_option as hex_jep106_option;
pub(crate) use hex_option::serialize as hex_option;
pub(crate) use hex_range::serialize as hex_range;
pub(crate) use hex_u_int::serialize as hex_u_int;
2 changes: 1 addition & 1 deletion probe-rs/targets/AIR001_Series.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ variants:
type: armv6m
core_access_options: !Arm
ap: 0
psel: 0
psel: 0x0
memory_map:
- !Ram
name: IRAM1
Expand Down
10 changes: 5 additions & 5 deletions probe-rs/targets/AIR32F1_Series.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ variants:
type: armv7m
core_access_options: !Arm
ap: 0
psel: 0
psel: 0x0
memory_map:
- !Ram
name: IRAM1
Expand All @@ -33,7 +33,7 @@ variants:
type: armv7m
core_access_options: !Arm
ap: 0
psel: 0
psel: 0x0
memory_map:
- !Ram
name: IRAM1
Expand All @@ -58,7 +58,7 @@ variants:
type: armv7m
core_access_options: !Arm
ap: 0
psel: 0
psel: 0x0
memory_map:
- !Ram
name: IRAM1
Expand All @@ -83,7 +83,7 @@ variants:
type: armv7m
core_access_options: !Arm
ap: 0
psel: 0
psel: 0x0
memory_map:
- !Ram
name: IRAM1
Expand All @@ -108,7 +108,7 @@ variants:
type: armv7m
core_access_options: !Arm
ap: 0
psel: 0
psel: 0x0
memory_map:
- !Ram
name: IRAM1
Expand Down
Loading