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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use tock_registers::{
fields::{Field, FieldValue},
register_structs,
registers::{ReadOnly, ReadWrite, WriteOnly},
RegisterLongName,
};
use crate::Vpa;
pub const BASE: Vpa = Vpa(0x4_7e20_0000);
register_structs! {
pub Registers {
(0x00 => pub gpfsel: [ReadWrite<u32, GPFSEL::Register>; 6]),
(0x18 => _reserved9),
(0x1c => pub gpset: [WriteOnly<u32, GPSET::Register>; 2]),
(0x24 => _reserved10),
(0x28 => pub gpclr: [WriteOnly<u32, GPCLR::Register>; 2]),
(0x30 => _reserved0),
(0x34 => pub gplev: [ReadOnly<u32, GPLEV::Register>; 2]),
(0x3c => _reserved1),
(0x40 => pub gpeds: [ReadWrite<u32, GPEDS::Register>; 2]),
(0x48 => _reserved2),
(0x4c => pub gpren: [ReadWrite<u32, GPREN::Register>; 2]),
(0x54 => _reserved3),
(0x58 => pub gpfen: [ReadWrite<u32, GPFEN::Register>; 2]),
(0x60 => _reserved4),
(0x64 => pub gphen: [ReadWrite<u32, GPHEN::Register>; 2]),
(0x6c => _reserved5),
(0x70 => pub gplen: [ReadWrite<u32, GPLEN::Register>; 2]),
(0x78 => _reserved6),
(0x7c => pub gparen: [ReadWrite<u32, GPAREN::Register>; 2]),
(0x84 => _reserved7),
(0x88 => pub gpafen: [ReadWrite<u32, GPAFEN::Register>; 2]),
(0x90 => _reserved8),
(0xe4 => pub gpio_pup_pdn_cntrl_reg: [ReadWrite<u32>; 4]),
(0xf4 => @END),
}
}
#[allow(non_snake_case)]
pub mod GPFSEL {
use super::*;
pub struct Register;
impl RegisterLongName for Register {}
pub const PINS_PER_REGISTER: usize = 10;
pub const INPUT: u32 = 0b000;
pub const OUTPUT: u32 = 0b001;
pub const ALT0: u32 = 0b100;
pub const ALT1: u32 = 0b101;
pub const ALT2: u32 = 0b110;
pub const ALT3: u32 = 0b111;
pub const ALT4: u32 = 0b011;
pub const ALT5: u32 = 0b010;
#[inline]
pub const fn pin(i: usize) -> Field<u32, Register> {
assert!(i < PINS_PER_REGISTER);
Field::new(0b111, 3 * i)
}
}
#[macropol::macropol]
macro_rules! register_pin_field {
(
$( #[$meta:meta] )*
pub mod $NAME:ident {
$(
#[field_value($value:expr)]
$( #[$value_meta:meta] )*
pub const fn $value_name:ident();
)*
}
) => {
$( #[$meta] )*
#[allow(non_snake_case)]
pub mod $NAME {
use super::*;
pub struct Register;
impl RegisterLongName for Register {}
pub const PINS_PER_REGISTER: usize = 32;
#[inline]
pub const fn pin(i: usize) -> Field<u32, Register> {
assert!(i < PINS_PER_REGISTER);
Field::new(0b1, i)
}
$(
$( #[$value_meta] )*
#[inline]
pub const fn $value_name(i: usize) -> FieldValue<u32, Register> {
assert!(i < PINS_PER_REGISTER);
FieldValue::<u32, _>::new(0b1, i, $value)
}
)*
}
};
}
register_pin_field! {
pub mod pin_generic {}
}
pub use pin_generic as GPLEV;
pub use pin_generic as GPEDS;
pub use pin_generic as GPREN;
pub use pin_generic as GPFEN;
pub use pin_generic as GPHEN;
pub use pin_generic as GPLEN;
pub use pin_generic as GPAREN;
pub use pin_generic as GPAFEN;
register_pin_field! {
pub mod GPSET {
#[field_value(1)]
pub const fn set();
}
}
register_pin_field! {
pub mod GPCLR {
#[field_value(1)]
pub const fn clear();
}
}