@@ -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 {
@@ -160,6 +180,15 @@ pub mod flash {
160
180
pub ( crate ) device : * const raw:: device ,
161
181
}
162
182
183
+ impl FlashController {
184
+ /// Constructor, intended to be called by devicetree generated code.
185
+ ///
186
+ /// TODO: Instance safety
187
+ pub unsafe fn new ( device : * const raw:: device ) -> FlashController {
188
+ FlashController { device }
189
+ }
190
+ }
191
+
163
192
/// A wrapper for flash partitions. There is no Zephyr struct that corresponds with this
164
193
/// information, which is typically used in a more direct underlying manner.
165
194
#[ allow( dead_code) ]
@@ -172,4 +201,14 @@ pub mod flash {
172
201
#[ allow( dead_code) ]
173
202
pub ( crate ) size : u32 ,
174
203
}
204
+
205
+ impl FlashPartition {
206
+ /// Constructor, intended to be called by devicetree generated code.
207
+ pub unsafe fn new ( device : * const raw:: device , offset : u32 , size : u32 ) -> FlashPartition {
208
+ // The `get_instance` on the flash controller would try to guarantee a unique instance,
209
+ // but in this case, we need one for each device, so just construct it here.
210
+ let controller = FlashController :: new ( device) ;
211
+ FlashPartition { controller, offset, size }
212
+ }
213
+ }
175
214
}
0 commit comments