3
3
4
4
pub use sophgo_rom_rt_macros:: entry;
5
5
6
+ /// Rom runtime prelude.
6
7
pub mod prelude {
7
8
pub use crate :: { entry, Peripherals } ;
8
9
pub use sophgo_hal:: prelude:: * ;
9
10
}
10
11
12
+ #[ macro_use]
13
+ mod macros;
11
14
use sophgo_hal:: {
12
15
gpio:: { Gpio , Input } ,
13
16
pad:: { FMux , Floating , GpioFunc , Pad , PadConfigs , PinMux , PwrPadConfigs , UartFunc } ,
14
17
} ;
15
18
16
19
/// Peripherals available on ROM start.
17
20
pub struct Peripherals {
21
+ /// Pad function multiplexer peripheral.
18
22
pub pinmux : PINMUX ,
19
23
// TODO pub pads: sophgo_hal::gpio::Pads<Static<xxxx>>,
20
24
/// General Purpose Input/Output 0.
@@ -60,21 +64,39 @@ pub struct Peripherals {
60
64
// TODO sd1: sophgo_hal::SD<Static<0x04320000>>,
61
65
// TODO usb: sophgo_hal::USB<Static<0x04340000>>,
62
66
// TODO documents
67
+ /// SoC pads.
63
68
pub pads : Pads < PINMUX > ,
69
+ /// Low-power Domain General Purpose Input/Output signal port.
64
70
pub pwr_gpio : GpioPort < PWR_GPIO > ,
71
+ /// Low-power Domain SoC pads.
65
72
pub pwr_pads : PwrPads < PWR_PINMUX > ,
66
73
}
67
74
68
- /// Pad function multiplexer peripheral.
69
- pub struct PINMUX {
70
- _private : ( ) ,
71
- }
72
-
73
- impl AsRef < PinMux > for PINMUX {
74
- #[ inline( always) ]
75
- fn as_ref ( & self ) -> & sophgo_hal:: pad:: PinMux {
76
- unsafe { & * ( 0x03001000 as * const _ ) }
77
- }
75
+ soc ! {
76
+ /// Pad function multiplexer peripheral.
77
+ pub struct PINMUX => 0x03001000 , PinMux ;
78
+ /// General Purpose Input/Output peripheral 0.
79
+ pub struct GPIO0 => 0x03020000 , sophgo_hal:: gpio:: RegisterBlock ;
80
+ /// General Purpose Input/Output peripheral 1.
81
+ pub struct GPIO1 => 0x03021000 , sophgo_hal:: gpio:: RegisterBlock ;
82
+ /// General Purpose Input/Output peripheral 2.
83
+ pub struct GPIO2 => 0x03022000 , sophgo_hal:: gpio:: RegisterBlock ;
84
+ /// General Purpose Input/Output peripheral 3.
85
+ pub struct GPIO3 => 0x03023000 , sophgo_hal:: gpio:: RegisterBlock ;
86
+ /// Universal Asynchronous Receiver/Transmitter peripheral 0.
87
+ pub struct UART0 => 0x04140000 , sophgo_hal:: uart:: RegisterBlock ;
88
+ /// Universal Asynchronous Receiver/Transmitter peripheral 1.
89
+ pub struct UART1 => 0x04150000 , sophgo_hal:: uart:: RegisterBlock ;
90
+ /// Universal Asynchronous Receiver/Transmitter peripheral 2.
91
+ pub struct UART2 => 0x04160000 , sophgo_hal:: uart:: RegisterBlock ;
92
+ /// Universal Asynchronous Receiver/Transmitter peripheral 3.
93
+ pub struct UART3 => 0x04170000 , sophgo_hal:: uart:: RegisterBlock ;
94
+ /// Universal Asynchronous Receiver/Transmitter peripheral 4.
95
+ pub struct UART4 => 0x041C0000 , sophgo_hal:: uart:: RegisterBlock ;
96
+ /// Low-power Domain General Purpose Input/Output peripheral.
97
+ pub struct PWR_GPIO => 0x05021000 , sophgo_hal:: gpio:: RegisterBlock ;
98
+ /// Low-power Domain pad configuration peripheral.
99
+ pub struct PWR_PINMUX => 0x05027000 , PadConfigs , PwrPadConfigs ;
78
100
}
79
101
80
102
impl AsRef < FMux > for PINMUX {
@@ -91,93 +113,15 @@ impl AsRef<PadConfigs> for PINMUX {
91
113
}
92
114
}
93
115
94
- /// General Purpose Input/Output peripheral 0.
95
- pub struct GPIO0 {
96
- _private : ( ) ,
97
- }
98
-
99
- impl AsRef < sophgo_hal:: gpio:: RegisterBlock > for GPIO0 {
100
- #[ inline( always) ]
101
- fn as_ref ( & self ) -> & sophgo_hal:: gpio:: RegisterBlock {
102
- unsafe { & * ( 0x03020000 as * const _ ) }
103
- }
104
- }
105
-
106
- /// General Purpose Input/Output peripheral 1.
107
- pub struct GPIO1 {
108
- _private : ( ) ,
109
- }
110
-
111
- impl AsRef < sophgo_hal:: gpio:: RegisterBlock > for GPIO1 {
112
- #[ inline( always) ]
113
- fn as_ref ( & self ) -> & sophgo_hal:: gpio:: RegisterBlock {
114
- unsafe { & * ( 0x03021000 as * const _ ) }
115
- }
116
- }
117
-
118
- /// General Purpose Input/Output peripheral 2.
119
- pub struct GPIO2 {
120
- _private : ( ) ,
121
- }
122
-
123
- impl AsRef < sophgo_hal:: gpio:: RegisterBlock > for GPIO2 {
124
- #[ inline( always) ]
125
- fn as_ref ( & self ) -> & sophgo_hal:: gpio:: RegisterBlock {
126
- unsafe { & * ( 0x03022000 as * const _ ) }
127
- }
128
- }
129
-
130
- /// General Purpose Input/Output peripheral 3.
131
- pub struct GPIO3 {
132
- _private : ( ) ,
133
- }
134
-
135
- impl AsRef < sophgo_hal:: gpio:: RegisterBlock > for GPIO3 {
136
- #[ inline( always) ]
137
- fn as_ref ( & self ) -> & sophgo_hal:: gpio:: RegisterBlock {
138
- unsafe { & * ( 0x03023000 as * const _ ) }
139
- }
140
- }
141
-
142
- /// Low-power Domain General Purpose Input/Output peripheral.
143
- #[ allow( non_camel_case_types) ]
144
- pub struct PWR_GPIO {
145
- _private : ( ) ,
146
- }
147
-
148
- impl AsRef < sophgo_hal:: gpio:: RegisterBlock > for PWR_GPIO {
149
- #[ inline( always) ]
150
- fn as_ref ( & self ) -> & sophgo_hal:: gpio:: RegisterBlock {
151
- unsafe { & * ( 0x05021000 as * const _ ) }
152
- }
153
- }
154
-
116
+ /// General Purpose Input/Output signal port.
155
117
pub struct GpioPort < T > {
156
118
pub a0 : Gpio < T , 0 , Input > ,
157
119
pub a1 : Gpio < T , 1 , Input > ,
158
120
pub a2 : Gpio < T , 2 , Input > ,
159
121
// TODO a3 to a31
160
122
}
161
123
162
- #[ allow( non_camel_case_types) ]
163
- pub struct PWR_PINMUX {
164
- _private : ( ) ,
165
- }
166
-
167
- impl AsRef < PwrPadConfigs > for PWR_PINMUX {
168
- #[ inline( always) ]
169
- fn as_ref ( & self ) -> & PwrPadConfigs {
170
- unsafe { & * ( 0x05027000 as * const _ ) }
171
- }
172
- }
173
-
174
- impl AsRef < PadConfigs > for PWR_PINMUX {
175
- #[ inline( always) ]
176
- fn as_ref ( & self ) -> & PadConfigs {
177
- unsafe { & * ( 0x05027000 as * const _ ) }
178
- }
179
- }
180
-
124
+ /// SoC pads.
181
125
pub struct Pads < T > {
182
126
pub sd0_clk : Pad < T , 6 , ( ) > , // TODO sd0_clk default function
183
127
pub uart0_tx : Pad < T , 18 , UartFunc < 0 > > ,
@@ -187,80 +131,17 @@ pub struct Pads<T> {
187
131
// TODO ...
188
132
}
189
133
134
+ /// Low-power Domain SoC pads.
190
135
pub struct PwrPads < T > {
191
136
pub gpio1 : Pad < T , 48 , GpioFunc < Floating > > ,
192
137
pub gpio2 : Pad < T , 49 , GpioFunc < Floating > > ,
193
138
// TODO ...
194
139
}
195
140
196
- /// Universal Asynchronous Receiver/Transmitter peripheral 0.
197
- pub struct UART0 {
198
- _private : ( ) ,
199
- }
200
-
201
- impl AsRef < sophgo_hal:: uart:: RegisterBlock > for UART0 {
202
- #[ inline( always) ]
203
- fn as_ref ( & self ) -> & sophgo_hal:: uart:: RegisterBlock {
204
- unsafe { & * ( 0x04140000 as * const _ ) }
205
- }
206
- }
207
-
208
141
impl sophgo_hal:: uart:: UartExt < 0 > for UART0 { }
209
-
210
- /// Universal Asynchronous Receiver/Transmitter peripheral 1.
211
- pub struct UART1 {
212
- _private : ( ) ,
213
- }
214
-
215
- impl AsRef < sophgo_hal:: uart:: RegisterBlock > for UART1 {
216
- #[ inline( always) ]
217
- fn as_ref ( & self ) -> & sophgo_hal:: uart:: RegisterBlock {
218
- unsafe { & * ( 0x04150000 as * const _ ) }
219
- }
220
- }
221
-
222
142
impl sophgo_hal:: uart:: UartExt < 1 > for UART1 { }
223
-
224
- /// Universal Asynchronous Receiver/Transmitter peripheral 2.
225
- pub struct UART2 {
226
- _private : ( ) ,
227
- }
228
-
229
- impl AsRef < sophgo_hal:: uart:: RegisterBlock > for UART2 {
230
- #[ inline( always) ]
231
- fn as_ref ( & self ) -> & sophgo_hal:: uart:: RegisterBlock {
232
- unsafe { & * ( 0x04160000 as * const _ ) }
233
- }
234
- }
235
-
236
143
impl sophgo_hal:: uart:: UartExt < 2 > for UART2 { }
237
-
238
- /// Universal Asynchronous Receiver/Transmitter peripheral 3.
239
- pub struct UART3 {
240
- _private : ( ) ,
241
- }
242
-
243
- impl AsRef < sophgo_hal:: uart:: RegisterBlock > for UART3 {
244
- #[ inline( always) ]
245
- fn as_ref ( & self ) -> & sophgo_hal:: uart:: RegisterBlock {
246
- unsafe { & * ( 0x04170000 as * const _ ) }
247
- }
248
- }
249
-
250
144
impl sophgo_hal:: uart:: UartExt < 3 > for UART3 { }
251
-
252
- /// Universal Asynchronous Receiver/Transmitter peripheral 3.
253
- pub struct UART4 {
254
- _private : ( ) ,
255
- }
256
-
257
- impl AsRef < sophgo_hal:: uart:: RegisterBlock > for UART4 {
258
- #[ inline( always) ]
259
- fn as_ref ( & self ) -> & sophgo_hal:: uart:: RegisterBlock {
260
- unsafe { & * ( 0x041C0000 as * const _ ) }
261
- }
262
- }
263
-
264
145
impl sophgo_hal:: uart:: UartExt < 4 > for UART4 { }
265
146
266
147
#[ cfg( target_arch = "riscv64" ) ]
0 commit comments