diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-05-13 02:11:01 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-05-13 02:13:26 +0200 |
| commit | 2fcdfc48762849d4de4686f9a4098db49c4031e6 (patch) | |
| tree | fc13e33e7d855e005798d2ed589ca99cdd5473bc /embassy-rp | |
| parent | dec75474d5fd82dd6abe25647f0e221c2266dda2 (diff) | |
rp: don't use SetConfig trait in PWM and PIO.
It was intended to allow changing baudrate on shared spi/i2c. There's no
advantage in using it for PWM or PIO, and makes it less usable because you have to
have `embassy-embedded-hal` as a dep to use it.
Diffstat (limited to 'embassy-rp')
| -rw-r--r-- | embassy-rp/src/pio.rs | 9 | ||||
| -rw-r--r-- | embassy-rp/src/pwm.rs | 12 |
2 files changed, 6 insertions, 15 deletions
diff --git a/embassy-rp/src/pio.rs b/embassy-rp/src/pio.rs index 1e41bed30..cbe45334a 100644 --- a/embassy-rp/src/pio.rs +++ b/embassy-rp/src/pio.rs | |||
| @@ -6,7 +6,6 @@ use core::task::{Context, Poll}; | |||
| 6 | 6 | ||
| 7 | use atomic_polyfill::{AtomicU32, AtomicU8}; | 7 | use atomic_polyfill::{AtomicU32, AtomicU8}; |
| 8 | use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; | 8 | use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; |
| 9 | use embassy_embedded_hal::SetConfig; | ||
| 10 | use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; | 9 | use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; |
| 11 | use embassy_sync::waitqueue::AtomicWaker; | 10 | use embassy_sync::waitqueue::AtomicWaker; |
| 12 | use fixed::types::extra::U8; | 11 | use fixed::types::extra::U8; |
| @@ -637,10 +636,8 @@ impl<'d, PIO: Instance> Config<'d, PIO> { | |||
| 637 | } | 636 | } |
| 638 | } | 637 | } |
| 639 | 638 | ||
| 640 | impl<'d, PIO: Instance, const SM: usize> SetConfig for StateMachine<'d, PIO, SM> { | 639 | impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { |
| 641 | type Config = Config<'d, PIO>; | 640 | pub fn set_config(&mut self, config: &Config<'d, PIO>) { |
| 642 | |||
| 643 | fn set_config(&mut self, config: &Self::Config) { | ||
| 644 | // sm expects 0 for 65536, truncation makes that happen | 641 | // sm expects 0 for 65536, truncation makes that happen |
| 645 | assert!(config.clock_divider <= 65536, "clkdiv must be <= 65536"); | 642 | assert!(config.clock_divider <= 65536, "clkdiv must be <= 65536"); |
| 646 | assert!(config.clock_divider >= 1, "clkdiv must be >= 1"); | 643 | assert!(config.clock_divider >= 1, "clkdiv must be >= 1"); |
| @@ -691,9 +688,7 @@ impl<'d, PIO: Instance, const SM: usize> SetConfig for StateMachine<'d, PIO, SM> | |||
| 691 | } | 688 | } |
| 692 | } | 689 | } |
| 693 | } | 690 | } |
| 694 | } | ||
| 695 | 691 | ||
| 696 | impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { | ||
| 697 | #[inline(always)] | 692 | #[inline(always)] |
| 698 | fn this_sm() -> crate::pac::pio::StateMachine { | 693 | fn this_sm() -> crate::pac::pio::StateMachine { |
| 699 | PIO::PIO.sm(SM) | 694 | PIO::PIO.sm(SM) |
diff --git a/embassy-rp/src/pwm.rs b/embassy-rp/src/pwm.rs index d2bf79584..0f9dcf479 100644 --- a/embassy-rp/src/pwm.rs +++ b/embassy-rp/src/pwm.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | //! Pulse Width Modulation (PWM) | 1 | //! Pulse Width Modulation (PWM) |
| 2 | 2 | ||
| 3 | use embassy_embedded_hal::SetConfig; | ||
| 4 | use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; | 3 | use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; |
| 5 | use fixed::traits::ToFixed; | 4 | use fixed::traits::ToFixed; |
| 6 | use fixed::FixedU16; | 5 | use fixed::FixedU16; |
| @@ -153,6 +152,10 @@ impl<'d, T: Channel> Pwm<'d, T> { | |||
| 153 | Self::new_inner(inner, Some(a.map_into()), Some(b.map_into()), config, mode.into()) | 152 | Self::new_inner(inner, Some(a.map_into()), Some(b.map_into()), config, mode.into()) |
| 154 | } | 153 | } |
| 155 | 154 | ||
| 155 | pub fn set_config(&mut self, config: &Config) { | ||
| 156 | Self::configure(self.inner.regs(), config); | ||
| 157 | } | ||
| 158 | |||
| 156 | fn configure(p: pac::pwm::Channel, config: &Config) { | 159 | fn configure(p: pac::pwm::Channel, config: &Config) { |
| 157 | if config.divider > FixedU16::<fixed::types::extra::U4>::from_bits(0xFF_F) { | 160 | if config.divider > FixedU16::<fixed::types::extra::U4>::from_bits(0xFF_F) { |
| 158 | panic!("Requested divider is too large"); | 161 | panic!("Requested divider is too large"); |
| @@ -329,10 +332,3 @@ impl_pin!(PIN_26, PWM_CH5, PwmPinA); | |||
| 329 | impl_pin!(PIN_27, PWM_CH5, PwmPinB); | 332 | impl_pin!(PIN_27, PWM_CH5, PwmPinB); |
| 330 | impl_pin!(PIN_28, PWM_CH6, PwmPinA); | 333 | impl_pin!(PIN_28, PWM_CH6, PwmPinA); |
| 331 | impl_pin!(PIN_29, PWM_CH6, PwmPinB); | 334 | impl_pin!(PIN_29, PWM_CH6, PwmPinB); |
| 332 | |||
| 333 | impl<'d, T: Channel> SetConfig for Pwm<'d, T> { | ||
| 334 | type Config = Config; | ||
| 335 | fn set_config(&mut self, config: &Self::Config) { | ||
| 336 | Self::configure(self.inner.regs(), config); | ||
| 337 | } | ||
| 338 | } | ||
