aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-05-13 02:11:01 +0200
committerDario Nieuwenhuis <[email protected]>2023-05-13 02:13:26 +0200
commit2fcdfc48762849d4de4686f9a4098db49c4031e6 (patch)
treefc13e33e7d855e005798d2ed589ca99cdd5473bc /embassy-rp
parentdec75474d5fd82dd6abe25647f0e221c2266dda2 (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.rs9
-rw-r--r--embassy-rp/src/pwm.rs12
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
7use atomic_polyfill::{AtomicU32, AtomicU8}; 7use atomic_polyfill::{AtomicU32, AtomicU8};
8use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; 8use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
9use embassy_embedded_hal::SetConfig;
10use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; 9use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
11use embassy_sync::waitqueue::AtomicWaker; 10use embassy_sync::waitqueue::AtomicWaker;
12use fixed::types::extra::U8; 11use fixed::types::extra::U8;
@@ -637,10 +636,8 @@ impl<'d, PIO: Instance> Config<'d, PIO> {
637 } 636 }
638} 637}
639 638
640impl<'d, PIO: Instance, const SM: usize> SetConfig for StateMachine<'d, PIO, SM> { 639impl<'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
696impl<'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
3use embassy_embedded_hal::SetConfig;
4use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; 3use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
5use fixed::traits::ToFixed; 4use fixed::traits::ToFixed;
6use fixed::FixedU16; 5use 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);
329impl_pin!(PIN_27, PWM_CH5, PwmPinB); 332impl_pin!(PIN_27, PWM_CH5, PwmPinB);
330impl_pin!(PIN_28, PWM_CH6, PwmPinA); 333impl_pin!(PIN_28, PWM_CH6, PwmPinA);
331impl_pin!(PIN_29, PWM_CH6, PwmPinB); 334impl_pin!(PIN_29, PWM_CH6, PwmPinB);
332
333impl<'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}