diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index 217221b0..0a278ab0 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml @@ -30,6 +30,7 @@ unstable-traits = ["embedded-hal-1"] embassy = { version = "0.1.0", path = "../embassy", features = [ "time-tick-1mhz", "nightly"] } embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } +embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["rp"]} atomic-polyfill = "0.1.5" defmt = { version = "0.3", optional = true } diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index e988e41d..6b3f2238 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs @@ -1,5 +1,6 @@ use core::marker::PhantomData; +use embassy_embedded_hal::SetConfig; use embassy_hal_common::unborrow; pub use embedded_hal_02::spi::{Phase, Polarity}; @@ -350,3 +351,20 @@ mod eh1 { } } } + +impl<'d, T: Instance> SetConfig for Spi<'d, T> { + type Config = Config; + fn set_config(&mut self, config: &Self::Config) { + let p = self.inner.regs(); + let (presc, postdiv) = calc_prescs(config.frequency); + unsafe { + p.cpsr().write(|w| w.set_cpsdvsr(presc)); + p.cr0().write(|w| { + w.set_dss(0b0111); // 8bit + w.set_spo(config.polarity == Polarity::IdleHigh); + w.set_sph(config.phase == Phase::CaptureOnSecondTransition); + w.set_scr(postdiv); + }); + } + } +}