Skip to content

Commit

Permalink
spi: re-export spi MODEs defined in embedded_hal.
Browse files Browse the repository at this point in the history
SPI mode is defined by CPOL and CPHA parameters, where CPOL determines
the polarity of the clock and CPHA determines the timing of the data
bits relative to the clock pulses.

Constants for all four SPI modes are defined in embedded_hal. Re-export
them from bitbang_hal to simplify its usage: now there is no no need
to pull embedded_hal as dependency just to use MODE_* consts.

Besides, update spi example accordingly.

Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
  • Loading branch information
geomatsi committed Jun 29, 2019
1 parent c2ab291 commit b81ca5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 4 additions & 8 deletions examples/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
use panic_halt;

use metro_m4 as hal;
use embedded_hal;
use hal::clock::GenericClockController;
use hal::delay::Delay;
use hal::prelude::*;
use hal::{entry, CorePeripherals, Peripherals};
use hal::timer::TimerCounter;
use nb::block;
use bitbang_hal;

use bitbang_hal::spi::SPI;
use bitbang_hal::spi::MODE_0;

#[entry]
fn main() -> ! {
Expand All @@ -39,12 +40,7 @@ fn main() -> ! {
let mosi = pins.mosi.into_push_pull_output(&mut pins.port);
let sck = pins.sck.into_push_pull_output(&mut pins.port);

let mode = embedded_hal::spi::Mode {
polarity: embedded_hal::spi::Polarity::IdleLow,
phase: embedded_hal::spi::Phase::CaptureOnFirstTransition,
};
let mut spi = bitbang_hal::spi::SPI::new(mode, miso, mosi, sck, timer);

let mut spi = SPI::new(MODE_0, miso, mosi, sck, timer);
let mut delay = Delay::new(core.SYST, &mut clocks);

loop {
Expand Down
2 changes: 2 additions & 0 deletions src/spi.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub use embedded_hal::spi::{MODE_0, MODE_1, MODE_2, MODE_3};

use embedded_hal::spi::{FullDuplex, Mode, Phase::*, Polarity::*};
use embedded_hal::digital::{InputPin, OutputPin};
use embedded_hal::timer::{CountDown, Periodic};
Expand Down

0 comments on commit b81ca5e

Please sign in to comment.