Skip to content

Commit 1f29a61

Browse files
committed
Update source to work with bitflags 1.0
This is an API change so we also include a major version bump along with this. Signed-off-by: Paul Osborne <osbpau@gmail.com>
1 parent 97ef13b commit 1f29a61

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "spidev"
4-
version = "0.3.0"
4+
version = "0.4.0"
55
authors = ["Paul Osborne <osbpau@gmail.com>"]
66
license = "MIT/Apache-2.0"
77
repository = "https://github.com/rust-embedded/rust-spidev"
@@ -15,5 +15,5 @@ half-duplex SPI access, and full-duplex SPI access.
1515

1616
[dependencies]
1717
libc = "0.2.2"
18-
bitflags = "0.3.3"
1918
nix = "0.6.0"
19+
bitflags = "1.0"

examples/spidev-bidir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
extern crate spidev;
2-
use spidev::{Spidev, SpidevOptions, SPI_MODE_0};
2+
use spidev::{Spidev, SpidevOptions, SpiModeFlags};
33
use spidev::spidevioctl::SpidevTransfer;
44

55
fn main() {
@@ -8,7 +8,7 @@ fn main() {
88
.bits_per_word(8)
99
.max_speed_hz(5000)
1010
.lsb_first(false)
11-
.mode(SPI_MODE_0)
11+
.mode(SpiModeFlags::SPI_MODE_0)
1212
.build();
1313
spidev.configure(&options).unwrap();
1414

src/lib.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
//! extern crate spidev;
2626
//! use std::io;
2727
//! use std::io::prelude::*;
28-
//! use spidev::{Spidev, SpidevOptions, SpidevTransfer, SPI_MODE_0};
28+
//! use spidev::{Spidev, SpidevOptions, SpidevTransfer, SpiModeFlags};
2929
//!
3030
//! fn create_spi() -> io::Result<Spidev> {
3131
//! let mut spi = try!(Spidev::open("/dev/spidev0.0"));
3232
//! let options = SpidevOptions::new()
3333
//! .bits_per_word(8)
3434
//! .max_speed_hz(20_000)
35-
//! .mode(SPI_MODE_0)
35+
//! .mode(SpiModeFlags::SPI_MODE_0)
3636
//! .build();
3737
//! try!(spi.configure(&options));
3838
//! Ok(spi)
@@ -85,40 +85,40 @@ use std::os::unix::prelude::*;
8585

8686
// Constants extracted from linux/spi/spidev.h
8787
bitflags! {
88-
flags SpiModeFlags: u32 {
88+
pub struct SpiModeFlags: u32 {
8989
/// Clock Phase
90-
const SPI_CPHA = 0x01,
90+
const SPI_CPHA = 0x01;
9191
/// Clock Polarity
92-
const SPI_CPOL = 0x02,
92+
const SPI_CPOL = 0x02;
9393
/// Chipselect Active High?
94-
const SPI_CS_HIGH = 0x04,
94+
const SPI_CS_HIGH = 0x04;
9595
/// Per-word Bits On Wire
96-
const SPI_LSB_FIRST = 0x08,
96+
const SPI_LSB_FIRST = 0x08;
9797
/// SI/SO Signals Shared
98-
const SPI_3WIRE = 0x10,
98+
const SPI_3WIRE = 0x10;
9999
/// Loopback Mode
100-
const SPI_LOOP = 0x20,
101-
/// 1 dev/bus, no chipselect
102-
const SPI_NO_CS = 0x40,
100+
const SPI_LOOP = 0x20;
101+
/// 1 dev/bus; no chipselect
102+
const SPI_NO_CS = 0x40;
103103
/// Slave pulls low to pause
104-
const SPI_READY = 0x80,
104+
const SPI_READY = 0x80;
105105

106106
// Common Configurations
107-
const SPI_MODE_0 = 0x00,
108-
const SPI_MODE_1 = SPI_CPHA.bits,
109-
const SPI_MODE_2 = SPI_CPOL.bits,
110-
const SPI_MODE_3 = (SPI_CPOL.bits | SPI_CPHA.bits),
107+
const SPI_MODE_0 = 0x00;
108+
const SPI_MODE_1 = Self::SPI_CPHA.bits;
109+
const SPI_MODE_2 = Self::SPI_CPOL.bits;
110+
const SPI_MODE_3 = (Self::SPI_CPOL.bits | Self::SPI_CPHA.bits);
111111

112112
// == Only Supported with 32-bits ==
113113

114114
/// Transmit with 2 wires
115-
const SPI_TX_DUAL = 0x100,
115+
const SPI_TX_DUAL = 0x100;
116116
/// Transmit with 4 wires
117-
const SPI_TX_QUAD = 0x200,
117+
const SPI_TX_QUAD = 0x200;
118118
/// Receive with 2 wires
119-
const SPI_RX_DUAL = 0x400,
119+
const SPI_RX_DUAL = 0x400;
120120
/// Receive with 4 wires
121-
const SPI_RX_QUAD = 0x800,
121+
const SPI_RX_QUAD = 0x800;
122122
}
123123
}
124124

@@ -290,21 +290,20 @@ impl Write for Spidev {
290290

291291
#[cfg(test)]
292292
mod test {
293-
294-
use super::{SpidevOptions, SPI_MODE_0};
293+
use super::{SpidevOptions, SpiModeFlags};
295294

296295
#[test]
297296
fn test_spidev_options_all() {
298297
let options = SpidevOptions::new()
299298
.bits_per_word(8)
300299
.max_speed_hz(20_000)
301300
.lsb_first(false)
302-
.mode(SPI_MODE_0)
301+
.mode(SpiModeFlags::SPI_MODE_0)
303302
.build();
304303
assert_eq!(options.bits_per_word, Some(8));
305304
assert_eq!(options.max_speed_hz, Some(20_000));
306305
assert_eq!(options.lsb_first, Some(false));
307-
assert_eq!(options.spi_mode, Some(SPI_MODE_0));
306+
assert_eq!(options.spi_mode, Some(SpiModeFlags::SPI_MODE_0));
308307
}
309308

310309
#[test]

0 commit comments

Comments
 (0)