diff options
| -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 c919672a7..3316d248a 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs | |||
| @@ -3,20 +3,27 @@ use core::marker::PhantomData; | |||
| 3 | use embassy::util::Unborrow; | 3 | use embassy::util::Unborrow; |
| 4 | use embassy_extras::unborrow; | 4 | use embassy_extras::unborrow; |
| 5 | use embedded_hal::blocking::spi as eh; | 5 | use embedded_hal::blocking::spi as eh; |
| 6 | use embedded_hal::spi as ehnb; | ||
| 6 | 7 | ||
| 7 | use crate::gpio::sealed::Pin as _; | 8 | use crate::gpio::sealed::Pin as _; |
| 8 | use crate::gpio::{NoPin, OptionalPin}; | 9 | use crate::gpio::{NoPin, OptionalPin}; |
| 9 | use crate::{pac, peripherals}; | 10 | use crate::{pac, peripherals}; |
| 10 | 11 | ||
| 12 | pub use ehnb::{Phase, Polarity}; | ||
| 13 | |||
| 11 | #[non_exhaustive] | 14 | #[non_exhaustive] |
| 12 | pub struct Config { | 15 | pub struct Config { |
| 13 | pub frequency: u32, | 16 | pub frequency: u32, |
| 17 | pub phase: ehnb::Phase, | ||
| 18 | pub polarity: ehnb::Polarity, | ||
| 14 | } | 19 | } |
| 15 | 20 | ||
| 16 | impl Default for Config { | 21 | impl 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| { |
