aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Alsér <[email protected]>2022-07-09 00:32:55 +0200
committerHenrik Alsér <[email protected]>2022-07-09 00:32:55 +0200
commit85e67d94ad1a2ce35afcb64b4f9a527b863e8a50 (patch)
treee1003f8e00612f586193b399423ba7b6c3ca1fe1
parentd637510b44ec8e58581f3e22f8398b53145503dc (diff)
impl SetConfig for rp2040 SPI
-rw-r--r--embassy-rp/Cargo.toml1
-rw-r--r--embassy-rp/src/spi.rs18
2 files changed, 19 insertions, 0 deletions
diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml
index 217221b0e..0a278ab00 100644
--- a/embassy-rp/Cargo.toml
+++ b/embassy-rp/Cargo.toml
@@ -30,6 +30,7 @@ unstable-traits = ["embedded-hal-1"]
30embassy = { version = "0.1.0", path = "../embassy", features = [ "time-tick-1mhz", "nightly"] } 30embassy = { version = "0.1.0", path = "../embassy", features = [ "time-tick-1mhz", "nightly"] }
31embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} 31embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]}
32embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } 32embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" }
33embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" }
33embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["rp"]} 34embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["rp"]}
34atomic-polyfill = "0.1.5" 35atomic-polyfill = "0.1.5"
35defmt = { version = "0.3", optional = true } 36defmt = { version = "0.3", optional = true }
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs
index e988e41d2..6b3f2238a 100644
--- a/embassy-rp/src/spi.rs
+++ b/embassy-rp/src/spi.rs
@@ -1,5 +1,6 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use embassy_embedded_hal::SetConfig;
3use embassy_hal_common::unborrow; 4use embassy_hal_common::unborrow;
4pub use embedded_hal_02::spi::{Phase, Polarity}; 5pub use embedded_hal_02::spi::{Phase, Polarity};
5 6
@@ -350,3 +351,20 @@ mod eh1 {
350 } 351 }
351 } 352 }
352} 353}
354
355impl<'d, T: Instance> SetConfig for Spi<'d, T> {
356 type Config = Config;
357 fn set_config(&mut self, config: &Self::Config) {
358 let p = self.inner.regs();
359 let (presc, postdiv) = calc_prescs(config.frequency);
360 unsafe {
361 p.cpsr().write(|w| w.set_cpsdvsr(presc));
362 p.cr0().write(|w| {
363 w.set_dss(0b0111); // 8bit
364 w.set_spo(config.polarity == Polarity::IdleHigh);
365 w.set_sph(config.phase == Phase::CaptureOnSecondTransition);
366 w.set_scr(postdiv);
367 });
368 }
369 }
370}