diff options
| author | Henrik Alsér <[email protected]> | 2022-07-09 00:32:55 +0200 |
|---|---|---|
| committer | Henrik Alsér <[email protected]> | 2022-07-09 00:32:55 +0200 |
| commit | 85e67d94ad1a2ce35afcb64b4f9a527b863e8a50 (patch) | |
| tree | e1003f8e00612f586193b399423ba7b6c3ca1fe1 | |
| parent | d637510b44ec8e58581f3e22f8398b53145503dc (diff) | |
impl SetConfig for rp2040 SPI
| -rw-r--r-- | embassy-rp/Cargo.toml | 1 | ||||
| -rw-r--r-- | embassy-rp/src/spi.rs | 18 |
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"] | |||
| 30 | embassy = { version = "0.1.0", path = "../embassy", features = [ "time-tick-1mhz", "nightly"] } | 30 | embassy = { version = "0.1.0", path = "../embassy", features = [ "time-tick-1mhz", "nightly"] } |
| 31 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} | 31 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} |
| 32 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } | 32 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } |
| 33 | embassy-embedded-hal = {version = "0.1.0", path = "../embassy-embedded-hal" } | ||
| 33 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["rp"]} | 34 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["rp"]} |
| 34 | atomic-polyfill = "0.1.5" | 35 | atomic-polyfill = "0.1.5" |
| 35 | defmt = { version = "0.3", optional = true } | 36 | defmt = { 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 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy_embedded_hal::SetConfig; | ||
| 3 | use embassy_hal_common::unborrow; | 4 | use embassy_hal_common::unborrow; |
| 4 | pub use embedded_hal_02::spi::{Phase, Polarity}; | 5 | pub use embedded_hal_02::spi::{Phase, Polarity}; |
| 5 | 6 | ||
| @@ -350,3 +351,20 @@ mod eh1 { | |||
| 350 | } | 351 | } |
| 351 | } | 352 | } |
| 352 | } | 353 | } |
| 354 | |||
| 355 | impl<'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 | } | ||
