@@ -96,6 +96,13 @@ pub mod gpio {
96
96
}
97
97
98
98
impl Gpio {
99
+ /// Constructor, used by the devicetree generated code.
100
+ ///
101
+ /// TODO: Guarantee single instancing.
102
+ pub unsafe fn new ( device : * const raw:: device ) -> Gpio {
103
+ Gpio { device }
104
+ }
105
+
99
106
/// Verify that the device is ready for use. At a minimum, this means the device has been
100
107
/// successfully initialized.
101
108
pub fn is_ready ( & self ) -> bool {
@@ -113,6 +120,19 @@ pub mod gpio {
113
120
}
114
121
115
122
impl GpioPin {
123
+ /// Constructor, used by the devicetree generated code.
124
+ ///
125
+ /// TODO: Guarantee single instancing.
126
+ pub unsafe fn new ( device : * const raw:: device , pin : u32 , dt_flags : u32 ) -> GpioPin {
127
+ GpioPin {
128
+ pin : raw:: gpio_dt_spec {
129
+ port : device,
130
+ pin : pin as raw:: gpio_pin_t ,
131
+ dt_flags : dt_flags as raw:: gpio_dt_flags_t ,
132
+ }
133
+ }
134
+ }
135
+
116
136
/// Verify that the device is ready for use. At a minimum, this means the device has been
117
137
/// successfully initialized.
118
138
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