diff options
author | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2021-06-30 23:43:40 +0200 |
---|---|---|
committer | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2021-06-30 23:46:00 +0200 |
commit | 53c236fde8b4b96db855f7bb23255106c0917ff8 (patch) | |
tree | f65f7c7709c10c67d17c6ae61bf324dcdab3e8b1 /embassy-rp | |
parent | f073bdfe43a243a2f5846c27c6a9af09a9bbe702 (diff) | |
download | embassy-53c236fde8b4b96db855f7bb23255106c0917ff8.zip |
rp/spi: add configurable pha/pol
Diffstat (limited to 'embassy-rp')
-rw-r--r-- | embassy-rp/src/spi.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index c919672a..3316d248 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs @@ -3,20 +3,27 @@ use core::marker::PhantomData; use embassy::util::Unborrow; use embassy_extras::unborrow; use embedded_hal::blocking::spi as eh; +use embedded_hal::spi as ehnb; use crate::gpio::sealed::Pin as _; use crate::gpio::{NoPin, OptionalPin}; use crate::{pac, peripherals}; +pub use ehnb::{Phase, Polarity}; + #[non_exhaustive] pub struct Config { pub frequency: u32, + pub phase: ehnb::Phase, + pub polarity: ehnb::Polarity, } impl Default for Config { fn default() -> Self { Self { frequency: 1_000_000, + phase: ehnb::Phase::CaptureOnFirstTransition, + polarity: ehnb::Polarity::IdleLow, } } } @@ -65,8 +72,8 @@ impl<'d, T: Instance> Spi<'d, T> { p.cpsr().write(|w| w.set_cpsdvsr(presc as _)); p.cr0().write(|w| { w.set_dss(0b0111); // 8bit - w.set_spo(false); - w.set_sph(false); + w.set_spo(config.polarity == ehnb::Polarity::IdleHigh); + w.set_sph(config.phase == ehnb::Phase::CaptureOnSecondTransition); w.set_scr((postdiv - 1) as u8); }); p.cr1().write(|w| { |