mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 06:42:32 +00:00
Remove generics from embassy-rp
This commit is contained in:
parent
c7c5723f8b
commit
24032d0853
@ -81,24 +81,22 @@ impl From<InputMode> for Divmode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// PWM driver.
|
/// PWM driver.
|
||||||
pub struct Pwm<'d, T: Slice> {
|
pub struct Pwm<'d> {
|
||||||
inner: PeripheralRef<'d, T>,
|
|
||||||
pin_a: Option<PeripheralRef<'d, AnyPin>>,
|
pin_a: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
pin_b: Option<PeripheralRef<'d, AnyPin>>,
|
pin_b: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
|
channel: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: Slice> Pwm<'d, T> {
|
impl<'d> Pwm<'d> {
|
||||||
fn new_inner(
|
fn new_inner(
|
||||||
inner: impl Peripheral<P = T> + 'd,
|
channel: usize,
|
||||||
a: Option<PeripheralRef<'d, AnyPin>>,
|
a: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
b: Option<PeripheralRef<'d, AnyPin>>,
|
b: Option<PeripheralRef<'d, AnyPin>>,
|
||||||
b_pull: Pull,
|
b_pull: Pull,
|
||||||
config: Config,
|
config: Config,
|
||||||
divmode: Divmode,
|
divmode: Divmode,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(inner);
|
let p = pac::PWM.ch(channel);
|
||||||
|
|
||||||
let p = inner.regs();
|
|
||||||
p.csr().modify(|w| {
|
p.csr().modify(|w| {
|
||||||
w.set_divmode(divmode);
|
w.set_divmode(divmode);
|
||||||
w.set_en(false);
|
w.set_en(false);
|
||||||
@ -117,51 +115,66 @@ impl<'d, T: Slice> Pwm<'d, T> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
Self {
|
Self {
|
||||||
inner,
|
// inner: p.into(),
|
||||||
pin_a: a,
|
pin_a: a,
|
||||||
pin_b: b,
|
pin_b: b,
|
||||||
|
channel,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create PWM driver without any configured pins.
|
/// Create PWM driver without any configured pins.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_free(inner: impl Peripheral<P = T> + 'd, config: Config) -> Self {
|
pub fn new_free<T: Slice>(channel: impl Peripheral<P = T> + 'd, config: Config) -> Self {
|
||||||
Self::new_inner(inner, None, None, Pull::None, config, Divmode::DIV)
|
Self::new_inner(channel.number(), None, None, Pull::None, config, Divmode::DIV)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create PWM driver with a single 'a' as output.
|
/// Create PWM driver with a single 'a' as output.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_output_a(
|
pub fn new_output_a<T: Slice>(
|
||||||
inner: impl Peripheral<P = T> + 'd,
|
channel: impl Peripheral<P = T> + 'd,
|
||||||
a: impl Peripheral<P = impl ChannelAPin<T>> + 'd,
|
a: impl Peripheral<P = impl ChannelAPin<T>> + 'd,
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(a);
|
into_ref!(a);
|
||||||
Self::new_inner(inner, Some(a.map_into()), None, Pull::None, config, Divmode::DIV)
|
Self::new_inner(
|
||||||
|
channel.number(),
|
||||||
|
Some(a.map_into()),
|
||||||
|
None,
|
||||||
|
Pull::None,
|
||||||
|
config,
|
||||||
|
Divmode::DIV,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create PWM driver with a single 'b' pin as output.
|
/// Create PWM driver with a single 'b' pin as output.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_output_b(
|
pub fn new_output_b<T: Slice>(
|
||||||
inner: impl Peripheral<P = T> + 'd,
|
channel: impl Peripheral<P = T> + 'd,
|
||||||
b: impl Peripheral<P = impl ChannelBPin<T>> + 'd,
|
b: impl Peripheral<P = impl ChannelBPin<T>> + 'd,
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(b);
|
into_ref!(b);
|
||||||
Self::new_inner(inner, None, Some(b.map_into()), Pull::None, config, Divmode::DIV)
|
Self::new_inner(
|
||||||
|
channel.number(),
|
||||||
|
None,
|
||||||
|
Some(b.map_into()),
|
||||||
|
Pull::None,
|
||||||
|
config,
|
||||||
|
Divmode::DIV,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create PWM driver with a 'a' and 'b' pins as output.
|
/// Create PWM driver with a 'a' and 'b' pins as output.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_output_ab(
|
pub fn new_output_ab<T: Slice>(
|
||||||
inner: impl Peripheral<P = T> + 'd,
|
channel: impl Peripheral<P = T> + 'd,
|
||||||
a: impl Peripheral<P = impl ChannelAPin<T>> + 'd,
|
a: impl Peripheral<P = impl ChannelAPin<T>> + 'd,
|
||||||
b: impl Peripheral<P = impl ChannelBPin<T>> + 'd,
|
b: impl Peripheral<P = impl ChannelBPin<T>> + 'd,
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(a, b);
|
into_ref!(a, b);
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
inner,
|
channel.number(),
|
||||||
Some(a.map_into()),
|
Some(a.map_into()),
|
||||||
Some(b.map_into()),
|
Some(b.map_into()),
|
||||||
Pull::None,
|
Pull::None,
|
||||||
@ -172,21 +185,21 @@ impl<'d, T: Slice> Pwm<'d, T> {
|
|||||||
|
|
||||||
/// Create PWM driver with a single 'b' as input pin.
|
/// Create PWM driver with a single 'b' as input pin.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_input(
|
pub fn new_input<T: Slice>(
|
||||||
inner: impl Peripheral<P = T> + 'd,
|
channel: impl Peripheral<P = T> + 'd,
|
||||||
b: impl Peripheral<P = impl ChannelBPin<T>> + 'd,
|
b: impl Peripheral<P = impl ChannelBPin<T>> + 'd,
|
||||||
b_pull: Pull,
|
b_pull: Pull,
|
||||||
mode: InputMode,
|
mode: InputMode,
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(b);
|
into_ref!(b);
|
||||||
Self::new_inner(inner, None, Some(b.map_into()), b_pull, config, mode.into())
|
Self::new_inner(channel.number(), None, Some(b.map_into()), b_pull, config, mode.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create PWM driver with a 'a' and 'b' pins in the desired input mode.
|
/// Create PWM driver with a 'a' and 'b' pins in the desired input mode.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_output_input(
|
pub fn new_output_input<T: Slice>(
|
||||||
inner: impl Peripheral<P = T> + 'd,
|
channel: impl Peripheral<P = T> + 'd,
|
||||||
a: impl Peripheral<P = impl ChannelAPin<T>> + 'd,
|
a: impl Peripheral<P = impl ChannelAPin<T>> + 'd,
|
||||||
b: impl Peripheral<P = impl ChannelBPin<T>> + 'd,
|
b: impl Peripheral<P = impl ChannelBPin<T>> + 'd,
|
||||||
b_pull: Pull,
|
b_pull: Pull,
|
||||||
@ -195,7 +208,7 @@ impl<'d, T: Slice> Pwm<'d, T> {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
into_ref!(a, b);
|
into_ref!(a, b);
|
||||||
Self::new_inner(
|
Self::new_inner(
|
||||||
inner,
|
channel.number(),
|
||||||
Some(a.map_into()),
|
Some(a.map_into()),
|
||||||
Some(b.map_into()),
|
Some(b.map_into()),
|
||||||
b_pull,
|
b_pull,
|
||||||
@ -206,7 +219,7 @@ impl<'d, T: Slice> Pwm<'d, T> {
|
|||||||
|
|
||||||
/// Set the PWM config.
|
/// Set the PWM config.
|
||||||
pub fn set_config(&mut self, config: &Config) {
|
pub fn set_config(&mut self, config: &Config) {
|
||||||
Self::configure(self.inner.regs(), config);
|
Self::configure(pac::PWM.ch(self.channel), config);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn configure(p: pac::pwm::Channel, config: &Config) {
|
fn configure(p: pac::pwm::Channel, config: &Config) {
|
||||||
@ -228,22 +241,22 @@ impl<'d, T: Slice> Pwm<'d, T> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Advances a slice’s output phase by one count while it is running
|
/// Advances a slice's output phase by one count while it is running
|
||||||
/// by inserting a pulse into the clock enable. The counter
|
/// by inserting a pulse into the clock enable. The counter
|
||||||
/// will not count faster than once per cycle.
|
/// will not count faster than once per cycle.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn phase_advance(&mut self) {
|
pub fn phase_advance(&mut self) {
|
||||||
let p = self.inner.regs();
|
let p = pac::PWM.ch(self.channel);
|
||||||
p.csr().write_set(|w| w.set_ph_adv(true));
|
p.csr().write_set(|w| w.set_ph_adv(true));
|
||||||
while p.csr().read().ph_adv() {}
|
while p.csr().read().ph_adv() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retards a slice’s output phase by one count while it is running
|
/// Retards a slice's output phase by one count while it is running
|
||||||
/// by deleting a pulse from the clock enable. The counter will not
|
/// by deleting a pulse from the clock enable. The counter will not
|
||||||
/// count backward when clock enable is permenantly low.
|
/// count backward when clock enable is permanently low.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn phase_retard(&mut self) {
|
pub fn phase_retard(&mut self) {
|
||||||
let p = self.inner.regs();
|
let p = pac::PWM.ch(self.channel);
|
||||||
p.csr().write_set(|w| w.set_ph_ret(true));
|
p.csr().write_set(|w| w.set_ph_ret(true));
|
||||||
while p.csr().read().ph_ret() {}
|
while p.csr().read().ph_ret() {}
|
||||||
}
|
}
|
||||||
@ -251,13 +264,13 @@ impl<'d, T: Slice> Pwm<'d, T> {
|
|||||||
/// Read PWM counter.
|
/// Read PWM counter.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn counter(&self) -> u16 {
|
pub fn counter(&self) -> u16 {
|
||||||
self.inner.regs().ctr().read().ctr()
|
pac::PWM.ch(self.channel).ctr().read().ctr()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write PWM counter.
|
/// Write PWM counter.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_counter(&self, ctr: u16) {
|
pub fn set_counter(&self, ctr: u16) {
|
||||||
self.inner.regs().ctr().write(|w| w.set_ctr(ctr))
|
pac::PWM.ch(self.channel).ctr().write(|w| w.set_ctr(ctr))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wait for channel interrupt.
|
/// Wait for channel interrupt.
|
||||||
@ -281,7 +294,7 @@ impl<'d, T: Slice> Pwm<'d, T> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn bit(&self) -> u32 {
|
fn bit(&self) -> u32 {
|
||||||
1 << self.inner.number() as usize
|
1 << self.channel as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +304,7 @@ pub struct PwmBatch(u32);
|
|||||||
impl PwmBatch {
|
impl PwmBatch {
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Enable a PWM slice in this batch.
|
/// Enable a PWM slice in this batch.
|
||||||
pub fn enable(&mut self, pwm: &Pwm<'_, impl Slice>) {
|
pub fn enable(&mut self, pwm: &Pwm<'_>) {
|
||||||
self.0 |= pwm.bit();
|
self.0 |= pwm.bit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,9 +321,9 @@ impl PwmBatch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: Slice> Drop for Pwm<'d, T> {
|
impl<'d> Drop for Pwm<'d> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.inner.regs().csr().write_clear(|w| w.set_en(false));
|
pac::PWM.ch(self.channel).csr().write_clear(|w| w.set_en(false));
|
||||||
if let Some(pin) = &self.pin_a {
|
if let Some(pin) = &self.pin_a {
|
||||||
pin.gpio().ctrl().write(|w| w.set_funcsel(31));
|
pin.gpio().ctrl().write(|w| w.set_funcsel(31));
|
||||||
}
|
}
|
||||||
@ -327,11 +340,6 @@ trait SealedSlice {}
|
|||||||
pub trait Slice: Peripheral<P = Self> + SealedSlice + Sized + 'static {
|
pub trait Slice: Peripheral<P = Self> + SealedSlice + Sized + 'static {
|
||||||
/// Slice number.
|
/// Slice number.
|
||||||
fn number(&self) -> u8;
|
fn number(&self) -> u8;
|
||||||
|
|
||||||
/// Slice register block.
|
|
||||||
fn regs(&self) -> pac::pwm::Channel {
|
|
||||||
pac::PWM.ch(self.number() as _)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! slice {
|
macro_rules! slice {
|
||||||
|
Loading…
Reference in New Issue
Block a user