1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use super::{access::Access, deserialize_int_opt};
use serde::Deserialize;
#[non_exhaustive]
#[derive(Clone, Debug, Default, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Field {
#[serde(default, deserialize_with = "deserialize_int_opt")]
pub dim: Option<u32>,
#[serde(default, deserialize_with = "deserialize_int_opt")]
pub dim_increment: Option<u32>,
pub name: String,
#[serde(default)]
pub description: String,
#[serde(default, deserialize_with = "deserialize_int_opt")]
pub bit_offset: Option<u32>,
#[serde(default, deserialize_with = "deserialize_int_opt")]
pub bit_width: Option<u32>,
#[serde(default, deserialize_with = "deserialize_int_opt")]
pub lsb: Option<u32>,
#[serde(default, deserialize_with = "deserialize_int_opt")]
pub msb: Option<u32>,
pub access: Option<Access>,
}
impl Field {
pub fn bit_offset(&self) -> u32 {
self.bit_offset.or(self.lsb).expect("bit-range is missing")
}
pub fn bit_width(&self) -> u32 {
self.bit_width
.or_else(|| self.lsb.and_then(|lsb| self.msb.map(|msb| msb - lsb + 1)))
.expect("bit-range is missing")
}
}