Skip to content

Commit 9fb7866

Browse files
committed
Update dependencies to latest stable and fix fallout
Several dependencies had quite out of date and there are some nice stabilizations and features (for nix ioctl) upstream. Nothing here should change the external API. Signed-off-by: Paul Osborne <[email protected]>
1 parent bc12c4e commit 9fb7866

File tree

3 files changed

+61
-65
lines changed

3 files changed

+61
-65
lines changed

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
name = "i2cdev"
44
build = "build.rs"
5-
version = "0.3.1"
5+
version = "0.3.2"
66
authors = ["Paul Osborne <[email protected]>"]
77
license = "MIT/Apache-2.0"
88
repository = "https://github.com/rust-embedded/rust-i2cdev"
@@ -15,14 +15,14 @@ https://www.kernel.org/doc/Documentation/i2c/dev-interface
1515
"""
1616

1717
[dependencies]
18-
libc = "^0.2.7"
19-
bitflags = "^0.5.0"
20-
byteorder = "^0.4.2"
21-
nix = "^0.6.0"
18+
libc = "0.2"
19+
bitflags = "1"
20+
byteorder = "1"
21+
nix = "0.10"
2222

2323
[dev-dependencies]
24-
docopt = "^0.6.78"
25-
skeptic = "^0.5"
24+
docopt = "0.8"
25+
skeptic = "0.13"
2626

2727
[build-dependencies]
28-
skeptic = "^0.5"
28+
skeptic = "0.13"

src/ffi.rs

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ use byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
1919
pub type I2CError = nix::Error;
2020

2121
bitflags! {
22-
flags I2CMsgFlags: u16 {
22+
struct I2CMsgFlags: u16 {
2323
/// this is a ten bit chip address
24-
const I2C_M_TEN = 0x0010,
24+
const I2C_M_TEN = 0x0010;
2525
/// read data, from slave to master
26-
const I2C_M_RD = 0x0001,
26+
const I2C_M_RD = 0x0001;
2727
/// if I2C_FUNC_PROTOCOL_MANGLING
28-
const I2C_M_STOP = 0x8000,
28+
const I2C_M_STOP = 0x8000;
2929
/// if I2C_FUNC_NOSTART
30-
const I2C_M_NOSTART = 0x4000,
30+
const I2C_M_NOSTART = 0x4000;
3131
/// if I2C_FUNC_PROTOCOL_MANGLING
32-
const I2C_M_REV_DIR_ADDR = 0x2000,
32+
const I2C_M_REV_DIR_ADDR = 0x2000;
3333
/// if I2C_FUNC_PROTOCOL_MANGLING
34-
const I2C_M_IGNORE_NAK = 0x1000,
34+
const I2C_M_IGNORE_NAK = 0x1000;
3535
/// if I2C_FUNC_PROTOCOL_MANGLING
36-
const I2C_M_NO_RD_ACK = 0x0800,
36+
const I2C_M_NO_RD_ACK = 0x0800;
3737
/// length will be first received byte
38-
const I2C_M_RECV_LEN = 0x0400,
38+
const I2C_M_RECV_LEN = 0x0400;
3939
}
4040
}
4141

@@ -52,44 +52,44 @@ struct i2c_msg {
5252
}
5353

5454
bitflags! {
55-
flags I2CFunctions: u32 {
56-
const I2C_FUNC_I2C = 0x00000001,
57-
const I2C_FUNC_10BIT_ADDR = 0x00000002,
58-
const I2C_FUNC_PROTOCOL_MANGLING = 0x00000004, /* I2C_M_IGNORE_NAK etc. */
59-
const I2C_FUNC_SMBUS_PEC = 0x00000008,
60-
const I2C_FUNC_NOSTART = 0x00000010, /* I2C_M_NOSTART */
61-
const I2C_FUNC_SMBUS_BLOCK_PROC_CALL = 0x00008000, /* SMBus 2.0 */
62-
const I2C_FUNC_SMBUS_QUICK = 0x00010000,
63-
const I2C_FUNC_SMBUS_READ_BYTE = 0x00020000,
64-
const I2C_FUNC_SMBUS_WRITE_BYTE = 0x00040000,
65-
const I2C_FUNC_SMBUS_READ_BYTE_DATA = 0x00080000,
66-
const I2C_FUNC_SMBUS_WRITE_BYTE_DATA = 0x00100000,
67-
const I2C_FUNC_SMBUS_READ_WORD_DATA = 0x00200000,
68-
const I2C_FUNC_SMBUS_WRITE_WORD_DATA = 0x00400000,
69-
const I2C_FUNC_SMBUS_PROC_CALL = 0x00800000,
70-
const I2C_FUNC_SMBUS_READ_BLOCK_DATA = 0x01000000,
71-
const I2C_FUNC_SMBUS_WRITE_BLOCK_DATA = 0x02000000,
72-
const I2C_FUNC_SMBUS_READ_I2C_BLOCK = 0x04000000, /* I2C-like block xfer */
73-
const I2C_FUNC_SMBUS_WRITE_I2C_BLOCK = 0x08000000, /* w/ 1-byte reg. addr. */
74-
75-
const I2C_FUNC_SMBUS_BYTE = (I2C_FUNC_SMBUS_READ_BYTE.bits |
76-
I2C_FUNC_SMBUS_WRITE_BYTE.bits),
77-
const I2C_FUNC_SMBUS_BYTE_DATA = (I2C_FUNC_SMBUS_READ_BYTE_DATA.bits |
78-
I2C_FUNC_SMBUS_WRITE_BYTE_DATA.bits),
79-
const I2C_FUNC_SMBUS_WORD_DATA = (I2C_FUNC_SMBUS_READ_WORD_DATA.bits |
80-
I2C_FUNC_SMBUS_WRITE_WORD_DATA.bits),
81-
const I2C_FUNC_SMBUS_BLOCK_DATA = (I2C_FUNC_SMBUS_READ_BLOCK_DATA.bits |
82-
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA.bits),
83-
const I2C_FUNC_SMBUS_I2C_BLOCK = (I2C_FUNC_SMBUS_READ_I2C_BLOCK.bits |
84-
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK.bits),
85-
const I2C_FUNC_SMBUS_EMUL = (I2C_FUNC_SMBUS_QUICK.bits |
86-
I2C_FUNC_SMBUS_BYTE.bits |
87-
I2C_FUNC_SMBUS_BYTE_DATA.bits |
88-
I2C_FUNC_SMBUS_WORD_DATA.bits |
89-
I2C_FUNC_SMBUS_PROC_CALL.bits |
90-
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA.bits |
91-
I2C_FUNC_SMBUS_I2C_BLOCK.bits |
92-
I2C_FUNC_SMBUS_PEC.bits),
55+
struct I2CFunctions: u32 {
56+
const I2C_FUNC_I2C = 0x00000001;
57+
const I2C_FUNC_10BIT_ADDR = 0x00000002;
58+
const I2C_FUNC_PROTOCOL_MANGLING = 0x00000004; /* I2C_M_IGNORE_NAK etc. */
59+
const I2C_FUNC_SMBUS_PEC = 0x00000008;
60+
const I2C_FUNC_NOSTART = 0x00000010; /* I2C_M_NOSTART */
61+
const I2C_FUNC_SMBUS_BLOCK_PROC_CALL = 0x00008000; /* SMBus 2.0 */
62+
const I2C_FUNC_SMBUS_QUICK = 0x00010000;
63+
const I2C_FUNC_SMBUS_READ_BYTE = 0x00020000;
64+
const I2C_FUNC_SMBUS_WRITE_BYTE = 0x00040000;
65+
const I2C_FUNC_SMBUS_READ_BYTE_DATA = 0x00080000;
66+
const I2C_FUNC_SMBUS_WRITE_BYTE_DATA = 0x00100000;
67+
const I2C_FUNC_SMBUS_READ_WORD_DATA = 0x00200000;
68+
const I2C_FUNC_SMBUS_WRITE_WORD_DATA = 0x00400000;
69+
const I2C_FUNC_SMBUS_PROC_CALL = 0x00800000;
70+
const I2C_FUNC_SMBUS_READ_BLOCK_DATA = 0x01000000;
71+
const I2C_FUNC_SMBUS_WRITE_BLOCK_DATA = 0x02000000;
72+
const I2C_FUNC_SMBUS_READ_I2C_BLOCK = 0x04000000; /* I2C-like block xfer */
73+
const I2C_FUNC_SMBUS_WRITE_I2C_BLOCK = 0x08000000; /* w/ 1-byte reg. addr. */
74+
75+
const I2C_FUNC_SMBUS_BYTE = (I2CFunctions::I2C_FUNC_SMBUS_READ_BYTE.bits |
76+
I2CFunctions::I2C_FUNC_SMBUS_WRITE_BYTE.bits);
77+
const I2C_FUNC_SMBUS_BYTE_DATA = (I2CFunctions::I2C_FUNC_SMBUS_READ_BYTE_DATA.bits |
78+
I2CFunctions::I2C_FUNC_SMBUS_WRITE_BYTE_DATA.bits);
79+
const I2C_FUNC_SMBUS_WORD_DATA = (I2CFunctions::I2C_FUNC_SMBUS_READ_WORD_DATA.bits |
80+
I2CFunctions::I2C_FUNC_SMBUS_WRITE_WORD_DATA.bits);
81+
const I2C_FUNC_SMBUS_BLOCK_DATA = (I2CFunctions::I2C_FUNC_SMBUS_READ_BLOCK_DATA.bits |
82+
I2CFunctions::I2C_FUNC_SMBUS_WRITE_BLOCK_DATA.bits);
83+
const I2C_FUNC_SMBUS_I2C_BLOCK = (I2CFunctions::I2C_FUNC_SMBUS_READ_I2C_BLOCK.bits |
84+
I2CFunctions::I2C_FUNC_SMBUS_WRITE_I2C_BLOCK.bits);
85+
const I2C_FUNC_SMBUS_EMUL = (I2CFunctions::I2C_FUNC_SMBUS_QUICK.bits |
86+
I2CFunctions::I2C_FUNC_SMBUS_BYTE.bits |
87+
I2CFunctions::I2C_FUNC_SMBUS_BYTE_DATA.bits |
88+
I2CFunctions::I2C_FUNC_SMBUS_WORD_DATA.bits |
89+
I2CFunctions::I2C_FUNC_SMBUS_PROC_CALL.bits |
90+
I2CFunctions::I2C_FUNC_SMBUS_WRITE_BLOCK_DATA.bits |
91+
I2CFunctions::I2C_FUNC_SMBUS_I2C_BLOCK.bits |
92+
I2CFunctions::I2C_FUNC_SMBUS_PEC.bits);
9393
}
9494
}
9595

@@ -151,7 +151,7 @@ const I2C_RDRW_IOCTL_MAX_MSGS: u8 = 42;
151151

152152
/// This is the structure as used in the I2C_SMBUS ioctl call
153153
#[repr(C)]
154-
struct i2c_smbus_ioctl_data {
154+
pub struct i2c_smbus_ioctl_data {
155155
// __u8 read_write;
156156
read_write: u8,
157157
// __u8 command;
@@ -171,15 +171,12 @@ struct i2c_rdwr_ioctl_data {
171171
nmsgs: u32,
172172
}
173173

174-
ioctl!(bad ioctl_set_i2c_slave_address with I2C_SLAVE);
175-
ioctl!(bad ioctl_i2c_smbus with I2C_SMBUS);
174+
ioctl!(bad write_int ioctl_set_i2c_slave_address with I2C_SLAVE);
175+
ioctl!(bad write_ptr ioctl_i2c_smbus with I2C_SMBUS; i2c_smbus_ioctl_data);
176176

177177
pub fn i2c_set_slave_address(fd: RawFd, slave_address: u16) -> Result<(), nix::Error> {
178178
try!(unsafe {
179-
// NOTE: the generated ioctl call expected as pointer to a u8 but
180-
// we just want to provide the u8 directly, so we just cast to a pointer.
181-
// This is correct behavior.
182-
ioctl_set_i2c_slave_address(fd, slave_address as *mut u8)
179+
ioctl_set_i2c_slave_address(fd, slave_address as i32)
183180
});
184181
Ok(())
185182
}
@@ -198,8 +195,7 @@ unsafe fn i2c_smbus_access(fd: RawFd,
198195
};
199196

200197
// remove type information
201-
let p_args: *mut u8 = mem::transmute(&mut args);
202-
ioctl_i2c_smbus(fd, p_args).map(drop)
198+
ioctl_i2c_smbus(fd, &mut args).map(drop)
203199
}
204200

205201
#[inline]

src/linux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl From<LinuxI2CError> for io::Error {
4848
LinuxI2CError::Nix(e) => {
4949
match e {
5050
nix::Error::Sys(e) => io::Error::from_raw_os_error(e as i32),
51-
nix::Error::InvalidPath => {
51+
e => {
5252
io::Error::new(io::ErrorKind::InvalidInput, format!("{:?}", e))
5353
}
5454
}

0 commit comments

Comments
 (0)