-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_serde.rs
91 lines (78 loc) · 1.87 KB
/
build_serde.rs
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Profile {
pub name: String,
pub block: String,
pub endpoints_num: Option<u8>,
pub base_address: Option<u32>,
pub fifo: FifoConfig,
#[serde(default)]
pub reg_bit_size: RegBitSize,
#[serde(default = "Vec::new")]
pub patches: Vec<Patch>,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum FifoConfig {
#[serde(rename = "dynamic")]
Dynamic(DynamicFifoConfig),
#[serde(rename = "fixed")]
Fixed(FixedFifoConfig),
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DynamicFifoConfig {
pub dword_size_total: u32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct FixedFifoConfig {
pub shared: bool,
pub equal_size: bool,
#[serde(default = "Vec::new")]
pub dword_size_endpoints: Vec<u8>, // when equal_size is false
pub dword_size: Option<u8>, // when equal_size is true
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RegBitSize {
#[serde(default = "default_8")]
pub fifo: u8,
#[serde(default = "default_16")]
pub intr: u8,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Patch {
pub fieldset: String,
pub version: String,
}
impl Default for RegBitSize {
fn default() -> Self {
RegBitSize {
fifo: 8,
intr: 16,
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Block {
pub description: Option<String>,
pub items: Vec<BlockItem>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct BlockItem {
pub name: String,
pub description: Option<String>,
pub byte_offset: Option<String>,
pub bit_size: Option<String>,
pub fieldset: String,
}
fn default_16() -> u8 {
16
}
fn default_8() -> u8 {
8
}
// fn default_true() -> bool {
// true
// }
// fn default_false() -> bool {
// false
// }