@@ -90,6 +90,13 @@ pub mod gpio {
90
90
}
91
91
92
92
impl Gpio {
93
+ /// Constructor, used by the devicetree generated code.
94
+ ///
95
+ /// TODO: Guarantee single instancing.
96
+ pub unsafe fn new ( device : * const raw:: device ) -> Gpio {
97
+ Gpio { device }
98
+ }
99
+
93
100
/// Verify that the device is ready for use. At a minimum, this means the device has been
94
101
/// successfully initialized.
95
102
pub fn is_ready ( & self ) -> bool {
@@ -107,6 +114,19 @@ pub mod gpio {
107
114
}
108
115
109
116
impl GpioPin {
117
+ /// Constructor, used by the devicetree generated code.
118
+ ///
119
+ /// TODO: Guarantee single instancing.
120
+ pub unsafe fn new ( device : * const raw:: device , pin : u32 , dt_flags : u32 ) -> GpioPin {
121
+ GpioPin {
122
+ pin : raw:: gpio_dt_spec {
123
+ port : device,
124
+ pin : pin as raw:: gpio_pin_t ,
125
+ dt_flags : dt_flags as raw:: gpio_dt_flags_t ,
126
+ }
127
+ }
128
+ }
129
+
110
130
/// Verify that the device is ready for use. At a minimum, this means the device has been
111
131
/// successfully initialized.
112
132
pub fn is_ready ( & self ) -> bool {
@@ -156,6 +176,15 @@ pub mod flash {
156
176
pub ( crate ) device : * const raw:: device ,
157
177
}
158
178
179
+ impl FlashController {
180
+ /// Constructor, intended to be called by devicetree generated code.
181
+ ///
182
+ /// TODO: Instance safety
183
+ pub unsafe fn new ( device : * const raw:: device ) -> FlashController {
184
+ FlashController { device }
185
+ }
186
+ }
187
+
159
188
/// A wrapper for flash partitions. There is no Zephyr struct that corresponds with this
160
189
/// information, which is typically used in a more direct underlying manner.
161
190
#[ allow( dead_code) ]
@@ -168,4 +197,14 @@ pub mod flash {
168
197
#[ allow( dead_code) ]
169
198
pub ( crate ) size : u32 ,
170
199
}
200
+
201
+ impl FlashPartition {
202
+ /// Constructor, intended to be called by devicetree generated code.
203
+ pub unsafe fn new ( device : * const raw:: device , offset : u32 , size : u32 ) -> FlashPartition {
204
+ // The `get_instance` on the flash controller would try to guarantee a unique instance,
205
+ // but in this case, we need one for each device, so just construct it here.
206
+ let controller = FlashController :: new ( device) ;
207
+ FlashPartition { controller, offset, size }
208
+ }
209
+ }
171
210
}
0 commit comments