@@ -82,8 +82,6 @@ impl Error for LinuxI2CError {
82
82
}
83
83
}
84
84
85
- type I2CResult < T > = Result < T , LinuxI2CError > ;
86
-
87
85
impl AsRawFd for LinuxI2CDevice {
88
86
fn as_raw_fd ( & self ) -> RawFd {
89
87
self . devfile . as_raw_fd ( )
@@ -118,7 +116,7 @@ impl LinuxI2CDevice {
118
116
/// (it is done internally). Calling this method is only
119
117
/// necessary if you need to change the slave device and you do
120
118
/// not want to create a new device.
121
- fn set_slave_address ( & mut self , slave_address : u16 ) -> I2CResult < ( ) > {
119
+ fn set_slave_address ( & mut self , slave_address : u16 ) -> Result < ( ) , LinuxI2CError > {
122
120
try!( ffi:: i2c_set_slave_address ( self . as_raw_fd ( ) , slave_address) ) ;
123
121
self . slave_address = slave_address;
124
122
Ok ( ( ) )
@@ -129,17 +127,17 @@ impl I2CDevice for LinuxI2CDevice {
129
127
type Error = LinuxI2CError ;
130
128
131
129
/// Read data from the device to fill the provided slice
132
- fn read ( & mut self , data : & mut [ u8 ] ) -> I2CResult < ( ) > {
130
+ fn read ( & mut self , data : & mut [ u8 ] ) -> Result < ( ) , LinuxI2CError > {
133
131
self . devfile . read ( data) . map_err ( From :: from) . map ( drop)
134
132
}
135
133
136
134
/// Write the provided buffer to the device
137
- fn write ( & mut self , data : & [ u8 ] ) -> I2CResult < ( ) > {
135
+ fn write ( & mut self , data : & [ u8 ] ) -> Result < ( ) , LinuxI2CError > {
138
136
self . devfile . write ( data) . map_err ( From :: from) . map ( drop)
139
137
}
140
138
141
139
/// This sends a single bit to the device, at the place of the Rd/Wr bit
142
- fn smbus_write_quick ( & mut self , bit : bool ) -> I2CResult < ( ) > {
140
+ fn smbus_write_quick ( & mut self , bit : bool ) -> Result < ( ) , LinuxI2CError > {
143
141
ffi:: i2c_smbus_write_quick ( self . as_raw_fd ( ) , bit) . map_err ( From :: from)
144
142
}
145
143
@@ -148,44 +146,44 @@ impl I2CDevice for LinuxI2CDevice {
148
146
/// Some devices are so simple that this interface is enough; for
149
147
/// others, it is a shorthand if you want to read the same register as in
150
148
/// the previous SMBus command.
151
- fn smbus_read_byte ( & mut self ) -> I2CResult < u8 > {
149
+ fn smbus_read_byte ( & mut self ) -> Result < u8 , LinuxI2CError > {
152
150
ffi:: i2c_smbus_read_byte ( self . as_raw_fd ( ) ) . map_err ( From :: from)
153
151
}
154
152
155
153
/// Write a single byte to a sdevice, without specifying a device register
156
154
///
157
155
/// This is the opposite operation as smbus_read_byte. As with read_byte,
158
156
/// no register is specified.
159
- fn smbus_write_byte ( & mut self , value : u8 ) -> I2CResult < ( ) > {
157
+ fn smbus_write_byte ( & mut self , value : u8 ) -> Result < ( ) , LinuxI2CError > {
160
158
ffi:: i2c_smbus_write_byte ( self . as_raw_fd ( ) , value) . map_err ( From :: from)
161
159
}
162
160
163
161
/// Read a single byte from a device, from a designated register
164
162
///
165
163
/// The register is specified through the Comm byte.
166
- fn smbus_read_byte_data ( & mut self , register : u8 ) -> I2CResult < u8 > {
164
+ fn smbus_read_byte_data ( & mut self , register : u8 ) -> Result < u8 , LinuxI2CError > {
167
165
ffi:: i2c_smbus_read_byte_data ( self . as_raw_fd ( ) , register) . map_err ( From :: from)
168
166
}
169
167
170
168
/// Write a single byte to a specific register on a device
171
169
///
172
170
/// The register is specified through the Comm byte.
173
- fn smbus_write_byte_data ( & mut self , register : u8 , value : u8 ) -> I2CResult < ( ) > {
171
+ fn smbus_write_byte_data ( & mut self , register : u8 , value : u8 ) -> Result < ( ) , LinuxI2CError > {
174
172
ffi:: i2c_smbus_write_byte_data ( self . as_raw_fd ( ) , register, value) . map_err ( From :: from)
175
173
}
176
174
177
175
/// Read 2 bytes form a given register on a device
178
- fn smbus_read_word_data ( & mut self , register : u8 ) -> I2CResult < u16 > {
176
+ fn smbus_read_word_data ( & mut self , register : u8 ) -> Result < u16 , LinuxI2CError > {
179
177
ffi:: i2c_smbus_read_word_data ( self . as_raw_fd ( ) , register) . map_err ( From :: from)
180
178
}
181
179
182
180
/// Write 2 bytes to a given register on a device
183
- fn smbus_write_word_data ( & mut self , register : u8 , value : u16 ) -> I2CResult < ( ) > {
181
+ fn smbus_write_word_data ( & mut self , register : u8 , value : u16 ) -> Result < ( ) , LinuxI2CError > {
184
182
ffi:: i2c_smbus_write_word_data ( self . as_raw_fd ( ) , register, value) . map_err ( From :: from)
185
183
}
186
184
187
185
/// Select a register, send 16 bits of data to it, and read 16 bits of data
188
- fn smbus_process_word ( & mut self , register : u8 , value : u16 ) -> I2CResult < u16 > {
186
+ fn smbus_process_word ( & mut self , register : u8 , value : u16 ) -> Result < u16 , LinuxI2CError > {
189
187
ffi:: i2c_smbus_process_call ( self . as_raw_fd ( ) , register, value) . map_err ( From :: from)
190
188
}
191
189
@@ -194,7 +192,7 @@ impl I2CDevice for LinuxI2CDevice {
194
192
/// The actual number of bytes available to read is returned in the count
195
193
/// byte. This code returns a correctly sized vector containing the
196
194
/// count bytes read from the device.
197
- fn smbus_read_block_data ( & mut self , register : u8 ) -> I2CResult < Vec < u8 > > {
195
+ fn smbus_read_block_data ( & mut self , register : u8 ) -> Result < Vec < u8 > , LinuxI2CError > {
198
196
ffi:: i2c_smbus_read_block_data ( self . as_raw_fd ( ) , register) . map_err ( From :: from)
199
197
}
200
198
@@ -203,13 +201,13 @@ impl I2CDevice for LinuxI2CDevice {
203
201
/// The opposite of the Block Read command, this writes up to 32 bytes to
204
202
/// a device, to a designated register that is specified through the
205
203
/// Comm byte. The amount of data is specified in the Count byte.
206
- fn smbus_write_block_data ( & mut self , register : u8 , values : & [ u8 ] ) -> I2CResult < ( ) > {
204
+ fn smbus_write_block_data ( & mut self , register : u8 , values : & [ u8 ] ) -> Result < ( ) , LinuxI2CError > {
207
205
ffi:: i2c_smbus_write_block_data ( self . as_raw_fd ( ) , register, values) . map_err ( From :: from)
208
206
}
209
207
210
208
/// Select a register, send 1 to 31 bytes of data to it, and reads
211
209
/// 1 to 31 bytes of data from it.
212
- fn smbus_process_block ( & mut self , register : u8 , values : & [ u8 ] ) -> I2CResult < ( ) > {
210
+ fn smbus_process_block ( & mut self , register : u8 , values : & [ u8 ] ) -> Result < ( ) , LinuxI2CError > {
213
211
ffi:: i2c_smbus_write_i2c_block_data ( self . as_raw_fd ( ) , register, values) . map_err ( From :: from)
214
212
}
215
213
}
0 commit comments