@@ -110,6 +110,27 @@ impl LinuxI2CDevice {
110110 Ok ( device)
111111 }
112112
113+ /// Create a new I2CDevice for the specified path, without checking if the
114+ /// device is bound to a driver
115+ ///
116+ /// # Safety
117+ /// Using this can seriously confuse the original driver, and may cause all
118+ /// future communication to perform the wrong operations and/or return wrong results.
119+ pub unsafe fn force_new < P : AsRef < Path > > (
120+ path : P ,
121+ slave_address : u16 ,
122+ ) -> Result < LinuxI2CDevice , LinuxI2CError > {
123+ let file = OpenOptions :: new ( ) . read ( true ) . write ( true ) . open ( path) ?;
124+ let mut device = LinuxI2CDevice {
125+ devfile : file,
126+ slave_address : 0 , // will be set later
127+ pec : false ,
128+ } ;
129+ device. force_set_slave_address ( slave_address) ?;
130+ device. set_smbus_pec ( false ) ?;
131+ Ok ( device)
132+ }
133+
113134 /// Set the slave address for this device
114135 ///
115136 /// Typically the address is expected to be 7-bits but 10-bit addresses
@@ -127,6 +148,16 @@ impl LinuxI2CDevice {
127148 Ok ( ( ) )
128149 }
129150
151+ /// Set the slave address for this device, even if it is already in use
152+ /// by a driver
153+ ///
154+ /// This is private; use `force_new` instead.
155+ unsafe fn force_set_slave_address ( & mut self , slave_address : u16 ) -> Result < ( ) , LinuxI2CError > {
156+ ffi:: i2c_set_slave_address_force ( self . as_raw_fd ( ) , slave_address) ?;
157+ self . slave_address = slave_address;
158+ Ok ( ( ) )
159+ }
160+
130161 /// Enable/Disable PEC support for this device
131162 ///
132163 /// Used only for SMBus transactions. This request only has an effect if the
0 commit comments