Formatting and derive copy for counter config
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
//! Counts edges on an external signal entirely in hardware. Supports three
|
//! Counts edges on an external signal entirely in hardware. Supports three
|
||||||
//! pin sources per timer: the dedicated ETR pin, or any CH1/CH2 pin.
|
//! pin sources per timer: the dedicated ETR pin, or any CH1/CH2 pin.
|
||||||
|
|
||||||
|
use embassy_stm32::Peri;
|
||||||
use embassy_stm32::gpio::{AfType, Flex, Pull};
|
use embassy_stm32::gpio::{AfType, Flex, Pull};
|
||||||
use embassy_stm32::pac::timer::vals::{Etp, Etps};
|
use embassy_stm32::pac::timer::vals::{Etp, Etps};
|
||||||
use embassy_stm32::timer::low_level::{
|
use embassy_stm32::timer::low_level::{
|
||||||
@@ -11,7 +12,6 @@ use embassy_stm32::timer::low_level::{
|
|||||||
use embassy_stm32::timer::{
|
use embassy_stm32::timer::{
|
||||||
Ch1, Ch2, Channel, ExternalTriggerPin, GeneralInstance4Channel, TimerPin,
|
Ch1, Ch2, Channel, ExternalTriggerPin, GeneralInstance4Channel, TimerPin,
|
||||||
};
|
};
|
||||||
use embassy_stm32::Peri;
|
|
||||||
|
|
||||||
/// Which edge increments the counter.
|
/// Which edge increments the counter.
|
||||||
#[derive(Clone, Copy, Default, defmt::Format)]
|
#[derive(Clone, Copy, Default, defmt::Format)]
|
||||||
@@ -25,7 +25,7 @@ pub enum CountEdge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Pulse counter configuration.
|
/// Pulse counter configuration.
|
||||||
#[derive(Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct PulseCounterConfig {
|
pub struct PulseCounterConfig {
|
||||||
pub edge: CountEdge,
|
pub edge: CountEdge,
|
||||||
pub filter: FilterValue,
|
pub filter: FilterValue,
|
||||||
@@ -84,7 +84,10 @@ impl<'d, T: GeneralInstance4Channel> PulseCounter<'d, T> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
inner.start();
|
inner.start();
|
||||||
Self { inner, _pin: flex_pin }
|
Self {
|
||||||
|
inner,
|
||||||
|
_pin: flex_pin,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Count pulses on a CH1 pin.
|
/// Count pulses on a CH1 pin.
|
||||||
@@ -101,7 +104,10 @@ impl<'d, T: GeneralInstance4Channel> PulseCounter<'d, T> {
|
|||||||
Self::configure_channel(&inner, Channel::Ch1, TriggerSource::TI1FP1, &config);
|
Self::configure_channel(&inner, Channel::Ch1, TriggerSource::TI1FP1, &config);
|
||||||
|
|
||||||
inner.start();
|
inner.start();
|
||||||
Self { inner, _pin: flex_pin }
|
Self {
|
||||||
|
inner,
|
||||||
|
_pin: flex_pin,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Count pulses on a CH2 pin.
|
/// Count pulses on a CH2 pin.
|
||||||
@@ -118,7 +124,10 @@ impl<'d, T: GeneralInstance4Channel> PulseCounter<'d, T> {
|
|||||||
Self::configure_channel(&inner, Channel::Ch2, TriggerSource::TI2FP2, &config);
|
Self::configure_channel(&inner, Channel::Ch2, TriggerSource::TI2FP2, &config);
|
||||||
|
|
||||||
inner.start();
|
inner.start();
|
||||||
Self { inner, _pin: flex_pin }
|
Self {
|
||||||
|
inner,
|
||||||
|
_pin: flex_pin,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Common channel setup: put the channel in input mode, configure its
|
/// Common channel setup: put the channel in input mode, configure its
|
||||||
@@ -133,11 +142,14 @@ impl<'d, T: GeneralInstance4Channel> PulseCounter<'d, T> {
|
|||||||
// Normal = direct mapping (TI1→IC1, TI2→IC2).
|
// Normal = direct mapping (TI1→IC1, TI2→IC2).
|
||||||
inner.set_input_ti_selection(channel, InputTISelection::Normal);
|
inner.set_input_ti_selection(channel, InputTISelection::Normal);
|
||||||
inner.set_input_capture_filter(channel, config.filter);
|
inner.set_input_capture_filter(channel, config.filter);
|
||||||
inner.set_input_capture_mode(channel, match config.edge {
|
inner.set_input_capture_mode(
|
||||||
|
channel,
|
||||||
|
match config.edge {
|
||||||
CountEdge::Rising => InputCaptureMode::Rising,
|
CountEdge::Rising => InputCaptureMode::Rising,
|
||||||
CountEdge::Falling => InputCaptureMode::Falling,
|
CountEdge::Falling => InputCaptureMode::Falling,
|
||||||
CountEdge::Both => InputCaptureMode::BothEdges,
|
CountEdge::Both => InputCaptureMode::BothEdges,
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
inner.set_trigger_source(trigger);
|
inner.set_trigger_source(trigger);
|
||||||
inner.set_slave_mode(SlaveMode::EXT_CLOCK_MODE);
|
inner.set_slave_mode(SlaveMode::EXT_CLOCK_MODE);
|
||||||
|
|||||||
Reference in New Issue
Block a user