svd_rs/modifiedwritevalues.rs
1/// Describe the manipulation of data written to a register/field.
2/// If not specified, the value written to the field is the value stored in the field
3#[cfg_attr(
4 feature = "serde",
5 derive(serde::Deserialize, serde::Serialize),
6 serde(rename_all = "camelCase")
7)]
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum ModifiedWriteValues {
10 /// Write data bit of one shall clear (set to zero) the corresponding bit in the field
11 OneToClear,
12
13 /// Write data bit of one shall set (set to one) the corresponding bit in the field
14 OneToSet,
15
16 /// Write data bit of one shall toggle (invert) the corresponding bit in the field
17 OneToToggle,
18
19 /// Write data bit of zero shall clear (set to zero) the corresponding bit in the field
20 ZeroToClear,
21
22 /// Write data bit of zero shall set (set to one) the corresponding bit in the field
23 ZeroToSet,
24
25 /// Write data bit of zero shall toggle (invert) the corresponding bit in the field
26 ZeroToToggle,
27
28 /// After a write operation all bits in the field are cleared (set to zero)
29 Clear,
30
31 /// After a write operation all bits in the field are set (set to one)
32 Set,
33
34 /// After a write operation all bit in the field may be modified (default)
35 Modify,
36}
37
38impl Default for ModifiedWriteValues {
39 fn default() -> Self {
40 Self::Modify
41 }
42}
43
44impl ModifiedWriteValues {
45 /// Parse a string into an [`ModifiedWriteValues`] value, returning [`Option::None`] if the string is not valid.
46 pub fn parse_str(s: &str) -> Option<Self> {
47 use self::ModifiedWriteValues::*;
48 match s {
49 "oneToClear" => Some(OneToClear),
50 "oneToSet" => Some(OneToSet),
51 "oneToToggle" => Some(OneToToggle),
52 "zeroToClear" => Some(ZeroToClear),
53 "zeroToSet" => Some(ZeroToSet),
54 "zeroToToggle" => Some(ZeroToToggle),
55 "clear" => Some(Clear),
56 "set" => Some(Set),
57 "modify" => Some(Modify),
58 _ => None,
59 }
60 }
61
62 /// Convert this [`ModifiedWriteValues`] into a static string.
63 pub const fn as_str(self) -> &'static str {
64 match self {
65 Self::OneToClear => "oneToClear",
66 Self::OneToSet => "oneToSet",
67 Self::OneToToggle => "oneToToggle",
68 Self::ZeroToClear => "zeroToClear",
69 Self::ZeroToSet => "zeroToSet",
70 Self::ZeroToToggle => "zeroToToggle",
71 Self::Clear => "clear",
72 Self::Set => "set",
73 Self::Modify => "modify",
74 }
75 }
76}