diff options
author | 2021-12-31 17:50:41 +0000 | |
---|---|---|
committer | 2021-12-31 17:50:41 +0000 | |
commit | cde498dab4fbae0bbf093046dc2ae196ce4308d5 (patch) | |
tree | 124f84fc0fca7b5cc46535dd2bed17a0700d69f8 /src/peripheral | |
parent | 42065a6864a00f9f7d47fe8fd123c2f175362d37 (diff) | |
parent | 3b44533324499d355445b502dfff987da8546f1c (diff) | |
download | cortex-m-cde498dab4fbae0bbf093046dc2ae196ce4308d5.tar.gz cortex-m-cde498dab4fbae0bbf093046dc2ae196ce4308d5.tar.zst cortex-m-cde498dab4fbae0bbf093046dc2ae196ce4308d5.zip |
Merge #366
366: itm: derive serde for `LocalTimestampOptions`, impl gated `TryFrom<u8>` r=adamgreig a=tmplt
This PR is an upstream push of more std-features required by `cargo-rtic-scope`. If required, the `TryFrom<u8>` impl can be kept downstream.
Co-authored-by: Viktor Sonesten <v@tmplt.dev>
Diffstat (limited to 'src/peripheral')
-rw-r--r-- | src/peripheral/itm.rs | 22 | ||||
-rw-r--r-- | src/peripheral/scb.rs | 4 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/peripheral/itm.rs b/src/peripheral/itm.rs index 4d0aa22..f8e9e25 100644 --- a/src/peripheral/itm.rs +++ b/src/peripheral/itm.rs @@ -10,6 +10,9 @@ use volatile_register::{RO, RW, WO}; use crate::peripheral::ITM; use bitfield::bitfield; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + /// Register block #[repr(C)] pub struct RegisterBlock { @@ -91,6 +94,7 @@ impl Stim { /// The possible local timestamp options. #[derive(Debug, Eq, PartialEq, Copy, Clone)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum LocalTimestampOptions { /// Disable local timestamps. Disabled, @@ -107,6 +111,24 @@ pub enum LocalTimestampOptions { EnabledDiv64, } +#[cfg(feature = "std")] +impl core::convert::TryFrom<u8> for LocalTimestampOptions { + type Error = (); + + /// Converts an integer value to an enabled [LocalTimestampOptions] + /// variant. Accepted values are: 1, 4, 16, 64. Any other value + /// yields `Err(())`. + fn try_from(value: u8) -> Result<Self, Self::Error> { + match value { + 1 => Ok(Self::Enabled), + 4 => Ok(Self::EnabledDiv4), + 16 => Ok(Self::EnabledDiv16), + 64 => Ok(Self::EnabledDiv64), + _ => Err(()), + } + } +} + /// The possible global timestamp options. #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum GlobalTimestampOptions { diff --git a/src/peripheral/scb.rs b/src/peripheral/scb.rs index b61c4ff..eeea0c5 100644 --- a/src/peripheral/scb.rs +++ b/src/peripheral/scb.rs @@ -197,7 +197,7 @@ impl SCB { /// Processor core exceptions (internal interrupts) #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "std-map", derive(PartialOrd, Hash))] +#[cfg_attr(feature = "std", derive(PartialOrd, Hash))] pub enum Exception { /// Non maskable interrupt NonMaskableInt, @@ -264,7 +264,7 @@ impl Exception { /// Active exception number #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "std-map", derive(PartialOrd, Hash))] +#[cfg_attr(feature = "std", derive(PartialOrd, Hash))] pub enum VectActive { /// Thread mode ThreadMode, |