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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use core::str::from_utf8_unchecked;
macro_rules! define_ptr_type {
($name: ident, $ptr: expr) => (
impl $name {
fn ptr() -> *const Self {
$ptr as *const _
}
pub fn get() -> &'static Self {
unsafe { &*Self::ptr() }
}
}
)
}
#[derive(Hash, Debug)]
#[repr(C)]
pub struct Uid {
x: u16,
y: u16,
waf_lot: [u8; 8],
}
define_ptr_type!(Uid, 0x1FFF_7A10);
impl Uid {
pub fn x(&self) -> u16 {
self.x
}
pub fn y(&self) -> u16 {
self.y
}
pub fn waf_num(&self) -> u8 {
self.waf_lot[0]
}
pub fn lot_num(&self) -> &str {
unsafe {
from_utf8_unchecked(&self.waf_lot[1..])
}
}
}
#[derive(Debug)]
#[repr(C)]
pub struct FlashSize(u16);
define_ptr_type!(FlashSize, 0x1FFF_7A22);
impl FlashSize {
pub fn kilo_bytes(&self) -> u16 {
self.0
}
pub fn bytes(&self) -> usize {
usize::from(self.kilo_bytes()) * 1024
}
}
#[derive(Debug)]
#[repr(C)]
pub struct VrefCal(u16);
define_ptr_type!(VrefCal, 0x1FFF_7A2A);
impl VrefCal {
pub fn read(&self) -> u16 {
self.0
}
}
#[derive(Debug)]
#[repr(C)]
pub struct VtempCal30(u16);
define_ptr_type!(VtempCal30, 0x1FFF_7A2C);
impl VtempCal30 {
pub fn read(&self) -> u16 {
self.0
}
}
#[derive(Debug)]
#[repr(C)]
pub struct VtempCal110(u16);
define_ptr_type!(VtempCal110, 0x1FFF_7A2E);
impl VtempCal110 {
pub fn read(&self) -> u16 {
self.0
}
}