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
#[macro_export]
macro_rules! define_ap_register {
(
$(#[$outer:meta])*
$port_type:ident,
$name:ident,
$address:expr,
[$(($field:ident: $type:ty)$(,)?)*],
$param:ident,
$from:expr,
$to:expr
)
=> {
$(#[$outer])*
#[allow(non_snake_case)]
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub struct $name {
$(pub $field: $type,)*
}
impl Register for $name {
const ADDRESS: u8 = $address;
const NAME: &'static str = stringify!($name);
}
impl From<u32> for $name {
fn from($param: u32) -> $name {
$from
}
}
impl From<$name> for u32 {
fn from($param: $name) -> u32 {
$to
}
}
impl ApRegister<$port_type> for $name {
}
}
}
macro_rules! define_ap {
($name:ident) => {
#[derive(Clone, Copy, Debug)]
pub struct $name {
address: ApAddress,
}
impl $name {
pub const fn new(address: ApAddress) -> Self {
Self { address }
}
}
impl AccessPort for $name {
fn ap_address(&self) -> ApAddress {
self.address
}
}
};
}