1#[derive(Debug, Clone, PartialEq, Eq)]
2pub struct Config {
3 words: [u16; Self::WORD_COUNT],
4}
5
6impl Default for Config {
7 fn default() -> Self {
8 Self {
9 words: [0u16; Self::WORD_COUNT],
10 }
11 }
12}
13
14impl Config {
15 pub const WORD_COUNT: usize = 64;
16
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn from_words(words: [u16; Self::WORD_COUNT]) -> Self {
22 Self { words }
23 }
24
25 pub fn words(&self) -> &[u16; Self::WORD_COUNT] {
26 &self.words
27 }
28
29 pub fn words_mut(&mut self) -> &mut [u16; Self::WORD_COUNT] {
30 &mut self.words
31 }
32
33 pub fn vericomm_clock_high_delay(&self) -> u16 {
34 self.words[0]
35 }
36
37 pub fn set_vericomm_clock_high_delay(&mut self, delay: u16) {
38 self.words[0] = delay;
39 }
40
41 pub fn vericomm_clock_low_delay(&self) -> u16 {
42 self.words[1]
43 }
44
45 pub fn set_vericomm_clock_low_delay(&mut self, delay: u16) {
46 self.words[1] = delay;
47 }
48
49 pub fn vericomm_isv(&self) -> u8 {
50 ((self.words[2] >> 4) & 0x000f) as u8
51 }
52
53 pub fn set_vericomm_isv(&mut self, value: u8) {
54 let value = (value & 0x0f) as u16;
55 let clock_check = self.words[2] & 0x0001;
56 self.words[2] = (value << 4) | clock_check;
57 }
58
59 pub fn vericomm_clock_check_enabled(&self) -> bool {
60 self.words[2] & 0x0001 != 0
61 }
62
63 pub fn set_vericomm_clock_check_enabled(&mut self, enabled: bool) {
64 if enabled {
65 self.words[2] |= 0x0001;
66 } else {
67 self.words[2] &= !0x0001;
68 }
69 }
70
71 pub fn veri_sdk_channel_selector(&self) -> u8 {
72 (self.words[3] & 0x00ff) as u8
73 }
74
75 pub fn set_veri_sdk_channel_selector(&mut self, channel: u8) {
76 self.words[3] = (self.words[3] & 0xff00) | channel as u16;
77 }
78
79 pub fn mode_selector(&self) -> u8 {
80 (self.words[3] >> 8) as u8
81 }
82
83 pub fn set_mode_selector(&mut self, mode: u8) {
84 self.words[3] = (self.words[3] & 0x00ff) | ((mode as u16) << 8);
85 }
86
87 pub fn flash_begin_block_addr(&self) -> u16 {
88 self.words[4]
89 }
90
91 pub fn set_flash_begin_block_addr(&mut self, addr: u16) {
92 self.words[4] = addr;
93 }
94
95 pub fn flash_begin_cluster_addr(&self) -> u16 {
96 self.words[5]
97 }
98
99 pub fn set_flash_begin_cluster_addr(&mut self, addr: u16) {
100 self.words[5] = addr;
101 }
102
103 pub fn flash_read_end_block_addr(&self) -> u16 {
104 self.words[6]
105 }
106
107 pub fn set_flash_read_end_block_addr(&mut self, addr: u16) {
108 self.words[6] = addr;
109 }
110
111 pub fn flash_read_end_cluster_addr(&self) -> u16 {
112 self.words[7]
113 }
114
115 pub fn set_flash_read_end_cluster_addr(&mut self, addr: u16) {
116 self.words[7] = addr;
117 }
118
119 pub fn licence_key(&self) -> u16 {
120 self.words[31]
121 }
122
123 pub fn security_key(&self) -> u16 {
124 self.words[31]
125 }
126
127 pub fn set_licence_key(&mut self, key: u16) {
128 self.words[31] = key;
129 }
130
131 pub fn smims_version_raw(&self) -> u16 {
132 self.words[32]
133 }
134
135 pub fn smims_major_version(&self) -> u8 {
136 (self.words[32] >> 8) as u8
137 }
138
139 pub fn smims_sub_version(&self) -> u8 {
140 ((self.words[32] >> 4) & 0x000f) as u8
141 }
142
143 pub fn smims_patch_version(&self) -> u8 {
144 (self.words[32] & 0x000f) as u8
145 }
146
147 pub fn fifo_size(&self) -> u16 {
148 self.words[33]
149 }
150
151 pub fn flash_total_block(&self) -> u16 {
152 self.words[34]
153 }
154
155 pub fn flash_block_size(&self) -> u16 {
156 self.words[35]
157 }
158
159 pub fn flash_cluster_size(&self) -> u16 {
160 self.words[36]
161 }
162
163 pub fn vericomm_ability(&self) -> bool {
164 self.has_state_flag(0x0001)
165 }
166
167 pub fn veri_instrument_ability(&self) -> bool {
168 self.has_state_flag(0x0002)
169 }
170
171 pub fn veri_link_ability(&self) -> bool {
172 self.has_state_flag(0x0004)
173 }
174
175 pub fn veri_soc_ability(&self) -> bool {
176 self.has_state_flag(0x0008)
177 }
178
179 pub fn vericomm_pro_ability(&self) -> bool {
180 self.has_state_flag(0x0010)
181 }
182
183 pub fn veri_sdk_ability(&self) -> bool {
184 self.has_state_flag(0x0100)
185 }
186
187 pub fn is_programmed(&self) -> bool {
188 self.words[48] & 0x0001 != 0
189 }
190
191 pub fn is_pcb_connected(&self) -> bool {
192 self.words[48] & 0x0100 == 0
193 }
194
195 pub fn vericomm_clock_continues(&self) -> bool {
196 self.words[49] & 0x0001 == 0
197 }
198
199 fn has_state_flag(&self, mask: u16) -> bool {
200 self.words[37] & mask != 0
201 }
202}