File tree Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Expand file tree Collapse file tree 1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -206,18 +206,34 @@ impl SpidevOptions {
206206}
207207
208208impl 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+
209215 /// Open the spidev device with the provided path
210216 ///
211217 /// Typically, the path will be something like `"/dev/spidev0.0"`
212218 /// where the first number if the bus and the second number
213219 /// is the chip select on that bus for the device being targeted.
214220 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
221237 }
222238
223239 /// Write the provided configuration to this device
You can’t perform that action at this time.
0 commit comments