1448: rp: don't use SetConfig trait in PWM and PIO. r=Dirbaio a=Dirbaio

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.

bors r+

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
bors[bot] 2023-05-13 00:14:50 +00:00 committed by GitHub
commit 82f7e104d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 6 additions and 20 deletions

View file

@ -6,7 +6,6 @@ use core::task::{Context, Poll};
use atomic_polyfill::{AtomicU32, AtomicU8}; use atomic_polyfill::{AtomicU32, AtomicU8};
use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
use embassy_embedded_hal::SetConfig;
use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
use embassy_sync::waitqueue::AtomicWaker; use embassy_sync::waitqueue::AtomicWaker;
use fixed::types::extra::U8; 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> { impl<'d, PIO: Instance + 'd, const SM: usize> StateMachine<'d, PIO, SM> {
type Config = Config<'d, PIO>; pub fn set_config(&mut self, config: &Config<'d, PIO>) {
fn set_config(&mut self, config: &Self::Config) {
// sm expects 0 for 65536, truncation makes that happen // sm expects 0 for 65536, truncation makes that happen
assert!(config.clock_divider <= 65536, "clkdiv must be <= 65536"); assert!(config.clock_divider <= 65536, "clkdiv must be <= 65536");
assert!(config.clock_divider >= 1, "clkdiv must be >= 1"); 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)] #[inline(always)]
fn this_sm() -> crate::pac::pio::StateMachine { fn this_sm() -> crate::pac::pio::StateMachine {
PIO::PIO.sm(SM) PIO::PIO.sm(SM)

View file

@ -1,6 +1,5 @@
//! Pulse Width Modulation (PWM) //! Pulse Width Modulation (PWM)
use embassy_embedded_hal::SetConfig;
use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; use embassy_hal_common::{into_ref, Peripheral, PeripheralRef};
use fixed::traits::ToFixed; use fixed::traits::ToFixed;
use fixed::FixedU16; 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()) 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) { fn configure(p: pac::pwm::Channel, config: &Config) {
if config.divider > FixedU16::<fixed::types::extra::U4>::from_bits(0xFF_F) { if config.divider > FixedU16::<fixed::types::extra::U4>::from_bits(0xFF_F) {
panic!("Requested divider is too large"); 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_27, PWM_CH5, PwmPinB);
impl_pin!(PIN_28, PWM_CH6, PwmPinA); impl_pin!(PIN_28, PWM_CH6, PwmPinA);
impl_pin!(PIN_29, PWM_CH6, PwmPinB); 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);
}
}

View file

@ -2,7 +2,6 @@
#![no_main] #![no_main]
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
use defmt::info; use defmt::info;
use embassy_embedded_hal::SetConfig;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;
use embassy_rp::pio::{Common, Config, Irq, Pio, PioPin, ShiftDirection, StateMachine}; use embassy_rp::pio::{Common, Config, Irq, Pio, PioPin, ShiftDirection, StateMachine};

View file

@ -2,7 +2,6 @@
#![no_main] #![no_main]
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
use defmt::info; use defmt::info;
use embassy_embedded_hal::SetConfig;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_futures::join::join; use embassy_futures::join::join;
use embassy_rp::pio::{Config, Pio, ShiftConfig, ShiftDirection}; use embassy_rp::pio::{Config, Pio, ShiftConfig, ShiftDirection};

View file

@ -4,7 +4,6 @@
use core::fmt::Write; use core::fmt::Write;
use embassy_embedded_hal::SetConfig;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::dma::{AnyChannel, Channel}; use embassy_rp::dma::{AnyChannel, Channel};
use embassy_rp::peripherals::PIO0; use embassy_rp::peripherals::PIO0;

View file

@ -3,7 +3,6 @@
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
use defmt::*; use defmt::*;
use embassy_embedded_hal::SetConfig;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::pwm::{Config, Pwm}; use embassy_rp::pwm::{Config, Pwm};
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};

View file

@ -3,7 +3,6 @@
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
use defmt::*; use defmt::*;
use embassy_embedded_hal::SetConfig;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_rp::pio::{Common, Config, FifoJoin, Instance, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine}; use embassy_rp::pio::{Common, Config, FifoJoin, Instance, Pio, PioPin, ShiftConfig, ShiftDirection, StateMachine};
use embassy_rp::relocate::RelocatedProgram; use embassy_rp::relocate::RelocatedProgram;