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