aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-06-30 23:43:40 +0200
committerDario Nieuwenhuis <[email protected]>2021-06-30 23:46:00 +0200
commit53c236fde8b4b96db855f7bb23255106c0917ff8 (patch)
treef65f7c7709c10c67d17c6ae61bf324dcdab3e8b1
parentf073bdfe43a243a2f5846c27c6a9af09a9bbe702 (diff)
rp/spi: add configurable pha/pol
-rw-r--r--embassy-rp/src/spi.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs
index c919672a7..3316d248a 100644
--- a/embassy-rp/src/spi.rs
+++ b/embassy-rp/src/spi.rs
@@ -3,20 +3,27 @@ use core::marker::PhantomData;
3use embassy::util::Unborrow; 3use embassy::util::Unborrow;
4use embassy_extras::unborrow; 4use embassy_extras::unborrow;
5use embedded_hal::blocking::spi as eh; 5use embedded_hal::blocking::spi as eh;
6use embedded_hal::spi as ehnb;
6 7
7use crate::gpio::sealed::Pin as _; 8use crate::gpio::sealed::Pin as _;
8use crate::gpio::{NoPin, OptionalPin}; 9use crate::gpio::{NoPin, OptionalPin};
9use crate::{pac, peripherals}; 10use crate::{pac, peripherals};
10 11
12pub use ehnb::{Phase, Polarity};
13
11#[non_exhaustive] 14#[non_exhaustive]
12pub struct Config { 15pub struct Config {
13 pub frequency: u32, 16 pub frequency: u32,
17 pub phase: ehnb::Phase,
18 pub polarity: ehnb::Polarity,
14} 19}
15 20
16impl Default for Config { 21impl Default for Config {
17 fn default() -> Self { 22 fn default() -> Self {
18 Self { 23 Self {
19 frequency: 1_000_000, 24 frequency: 1_000_000,
25 phase: ehnb::Phase::CaptureOnFirstTransition,
26 polarity: ehnb::Polarity::IdleLow,
20 } 27 }
21 } 28 }
22} 29}
@@ -65,8 +72,8 @@ impl<'d, T: Instance> Spi<'d, T> {
65 p.cpsr().write(|w| w.set_cpsdvsr(presc as _)); 72 p.cpsr().write(|w| w.set_cpsdvsr(presc as _));
66 p.cr0().write(|w| { 73 p.cr0().write(|w| {
67 w.set_dss(0b0111); // 8bit 74 w.set_dss(0b0111); // 8bit
68 w.set_spo(false); 75 w.set_spo(config.polarity == ehnb::Polarity::IdleHigh);
69 w.set_sph(false); 76 w.set_sph(config.phase == ehnb::Phase::CaptureOnSecondTransition);
70 w.set_scr((postdiv - 1) as u8); 77 w.set_scr((postdiv - 1) as u8);
71 }); 78 });
72 p.cr1().write(|w| { 79 p.cr1().write(|w| {