From 2fcdfc48762849d4de4686f9a4098db49c4031e6 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 13 May 2023 02:11:01 +0200 Subject: [PATCH] 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. --- embassy-rp/src/pio.rs | 9 ++------- embassy-rp/src/pwm.rs | 12 ++++-------- examples/rp/src/bin/pio_async.rs | 1 - examples/rp/src/bin/pio_dma.rs | 1 - examples/rp/src/bin/pio_hd44780.rs | 1 - examples/rp/src/bin/pwm.rs | 1 - examples/rp/src/bin/ws2812-pio.rs | 1 - 7 files changed, 6 insertions(+), 20 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}; use atomic_polyfill::{AtomicU32, AtomicU8}; use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; -use embassy_embedded_hal::SetConfig; use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; use embassy_sync::waitqueue::AtomicWaker; use fixed::types::extra::U8; @@ -637,10 +636,8 @@ impl<'d, PIO: Instance> Config<'d, PIO> { } } -impl<'d, PIO: Instance, const SM: usize> SetConfig for StateMachine<'d, PIO, SM> { - type Config = Config<'d, PIO>; - - fn set_config(&mut self, config: &Self::Config) { +impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { + pub fn set_config(&mut self, config: &Config<'d, PIO>) { // sm expects 0 for 65536, truncation makes that happen assert!(config.clock_divider <= 65536, "clkdiv must be <= 65536"); 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> } } } -} -impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> { #[inline(always)] fn this_sm() -> crate::pac::pio::StateMachine { 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 @@ //! Pulse Width Modulation (PWM) -use embassy_embedded_hal::SetConfig; use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; use fixed::traits::ToFixed; use fixed::FixedU16; @@ -153,6 +152,10 @@ impl<'d, T: Channel> Pwm<'d, T> { Self::new_inner(inner, Some(a.map_into()), Some(b.map_into()), config, mode.into()) } + pub fn set_config(&mut self, config: &Config) { + Self::configure(self.inner.regs(), config); + } + fn configure(p: pac::pwm::Channel, config: &Config) { if config.divider > FixedU16::::from_bits(0xFF_F) { panic!("Requested divider is too large"); @@ -329,10 +332,3 @@ impl_pin!(PIN_26, PWM_CH5, PwmPinA); impl_pin!(PIN_27, PWM_CH5, PwmPinB); impl_pin!(PIN_28, PWM_CH6, PwmPinA); impl_pin!(PIN_29, PWM_CH6, PwmPinB); - -impl<'d, T: Channel> SetConfig for Pwm<'d, T> { - type Config = Config; - fn set_config(&mut self, config: &Self::Config) { - Self::configure(self.inner.regs(), config); - } -} diff --git a/examples/rp/src/bin/pio_async.rs b/examples/rp/src/bin/pio_async.rs index 12484e882..79eda1a09 100644 --- a/examples/rp/src/bin/pio_async.rs +++ b/examples/rp/src/bin/pio_async.rs @@ -2,7 +2,6 @@ #![no_main] #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_embedded_hal::SetConfig; use embassy_executor::Spawner; use embassy_rp::peripherals::PIO0; use embassy_rp::pio::{Common, Config, Irq, Pio, PioPin, ShiftDirection, StateMachine}; diff --git a/examples/rp/src/bin/pio_dma.rs b/examples/rp/src/bin/pio_dma.rs index 7f85288bf..05c0ebb16 100644 --- a/examples/rp/src/bin/pio_dma.rs +++ b/examples/rp/src/bin/pio_dma.rs @@ -2,7 +2,6 @@ #![no_main] #![feature(type_alias_impl_trait)] use defmt::info; -use embassy_embedded_hal::SetConfig; use embassy_executor::Spawner; use embassy_futures::join::join; use embassy_rp::pio::{Config, Pio, ShiftConfig, ShiftDirection}; diff --git a/examples/rp/src/bin/pio_hd44780.rs b/examples/rp/src/bin/pio_hd44780.rs index 088fd5649..bfc6c9908 100644 --- a/examples/rp/src/bin/pio_hd44780.rs +++ b/examples/rp/src/bin/pio_hd44780.rs @@ -4,7 +4,6 @@ use core::fmt::Write; -use embassy_embedded_hal::SetConfig; use embassy_executor::Spawner; use embassy_rp::dma::{AnyChannel, Channel}; use embassy_rp::peripherals::PIO0; diff --git a/examples/rp/src/bin/pwm.rs b/examples/rp/src/bin/pwm.rs index 69d315553..2b3d5d97a 100644 --- a/examples/rp/src/bin/pwm.rs +++ b/examples/rp/src/bin/pwm.rs @@ -3,7 +3,6 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_embedded_hal::SetConfig; use embassy_executor::Spawner; use embassy_rp::pwm::{Config, Pwm}; use embassy_time::{Duration, Timer}; diff --git a/examples/rp/src/bin/ws2812-pio.rs b/examples/rp/src/bin/ws2812-pio.rs index d7c4742d8..f4c2d6313 100644 --- a/examples/rp/src/bin/ws2812-pio.rs +++ b/examples/rp/src/bin/ws2812-pio.rs @@ -3,7 +3,6 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use embassy_embedded_hal::SetConfig; use embassy_executor::Spawner; use embassy_rp::pio::{Common, Config, FifoJoin, Instance, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine}; use embassy_rp::relocate::RelocatedProgram;