File tree 1 file changed +22
-6
lines changed
1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -206,18 +206,34 @@ impl SpidevOptions {
206
206
}
207
207
208
208
impl Spidev {
209
+ /// Wrap an already opened [`File`] for use as an spidev
210
+ pub fn new ( devfile : File ) -> Self {
211
+ Self { devfile }
212
+ }
213
+
214
+
209
215
/// Open the spidev device with the provided path
210
216
///
211
217
/// Typically, the path will be something like `"/dev/spidev0.0"`
212
218
/// where the first number if the bus and the second number
213
219
/// is the chip select on that bus for the device being targeted.
214
220
pub fn open < P : AsRef < Path > > ( path : P ) -> io:: Result < Spidev > {
215
- let devfile = try!( OpenOptions :: new ( )
216
- . read ( true )
217
- . write ( true )
218
- . create ( false )
219
- . open ( path) ) ;
220
- Ok ( Spidev { devfile : devfile } )
221
+ let devfile = OpenOptions :: new ( )
222
+ . read ( true )
223
+ . write ( true )
224
+ . create ( false )
225
+ . open ( path) ?;
226
+ Ok ( Self :: new ( devfile) )
227
+ }
228
+
229
+ /// Get a reference to the underlying [`File`] object
230
+ pub fn inner ( & self ) -> & File {
231
+ & self . devfile
232
+ }
233
+
234
+ /// Consume the object and get the underlying [`File`] object
235
+ pub fn into_inner ( self ) -> File {
236
+ self . devfile
221
237
}
222
238
223
239
/// Write the provided configuration to this device
You can’t perform that action at this time.
0 commit comments