Merge pull request #258 from vertigo-designs/feature/input-capture-fixes
Updating input capture for timers
This commit is contained in:
commit
5945cfca75
|
@ -71,6 +71,9 @@ const APP: () = {
|
|||
// Start sampling ADCs.
|
||||
stabilizer.adc_dac_timer.start();
|
||||
|
||||
// Enable the timestamper.
|
||||
stabilizer.timestamper.start();
|
||||
|
||||
init::LateResources {
|
||||
afes: stabilizer.afes,
|
||||
adcs: stabilizer.adcs,
|
||||
|
|
|
@ -45,7 +45,7 @@ impl InputStamper {
|
|||
// Utilize the TIM5 CH4 as an input capture channel - use TI4 (the DI0 input trigger) as the
|
||||
// capture source.
|
||||
let input_capture =
|
||||
timer_channel.into_input_capture(timers::CaptureTrigger::Input24);
|
||||
timer_channel.into_input_capture(timers::tim5::CaptureSource4::TI4);
|
||||
|
||||
Self {
|
||||
capture_channel: input_capture,
|
||||
|
|
|
@ -86,7 +86,7 @@ impl Timestamper {
|
|||
|
||||
// The capture channel should capture whenever the trigger input occurs.
|
||||
let input_capture = capture_channel
|
||||
.into_input_capture(timers::CaptureTrigger::TriggerInput);
|
||||
.into_input_capture(timers::tim8::CaptureSource1::TRC);
|
||||
input_capture.listen_dma();
|
||||
|
||||
// The data transfer is always a transfer of data from the peripheral to a RAM buffer.
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
///! The sampling timer is used for managing ADC sampling and external reference timestamping.
|
||||
use super::hal;
|
||||
|
||||
/// The source of an input capture trigger.
|
||||
#[allow(dead_code)]
|
||||
pub enum CaptureTrigger {
|
||||
Input13 = 0b01,
|
||||
Input24 = 0b10,
|
||||
TriggerInput = 0b11,
|
||||
}
|
||||
use hal::stm32::{
|
||||
// TIM1 and TIM8 have identical registers.
|
||||
tim1 as __tim8,
|
||||
tim2 as __tim2,
|
||||
// TIM2 and TIM5 have identical registers.
|
||||
tim2 as __tim5,
|
||||
tim3 as __tim3,
|
||||
};
|
||||
|
||||
/// The event that should generate an external trigger from the peripheral.
|
||||
#[allow(dead_code)]
|
||||
|
@ -225,6 +226,8 @@ macro_rules! timer_channels {
|
|||
|
||||
($index:expr, $TY:ty, $ccmrx:expr, $size:ty) => {
|
||||
paste::paste! {
|
||||
pub use super::[< __ $TY:lower >]::[< $ccmrx _input >]::[< CC $index S_A>] as [< CaptureSource $index >];
|
||||
|
||||
/// A capture/compare channel of the timer.
|
||||
pub struct [< Channel $index >] {}
|
||||
|
||||
|
@ -267,12 +270,10 @@ macro_rules! timer_channels {
|
|||
/// # Args
|
||||
/// * `input` - The input source for the input capture event.
|
||||
#[allow(dead_code)]
|
||||
pub fn into_input_capture(self, input: super::CaptureTrigger) -> [< Channel $index InputCapture >]{
|
||||
pub fn into_input_capture(self, input: [< CaptureSource $index >]) -> [< Channel $index InputCapture >]{
|
||||
let regs = unsafe { &*<$TY>::ptr() };
|
||||
|
||||
// Note(unsafe): The bit configuration is guaranteed to be valid by the
|
||||
// CaptureTrigger enum definition.
|
||||
regs.[< $ccmrx _input >]().modify(|_, w| unsafe { w.[< cc $index s>]().bits(input as u8) });
|
||||
regs.[< $ccmrx _input >]().modify(|_, w| w.[< cc $index s>]().variant(input));
|
||||
|
||||
[< Channel $index InputCapture >] {}
|
||||
}
|
||||
|
@ -316,6 +317,9 @@ macro_rules! timer_channels {
|
|||
/// Enable the input capture to begin capturing timer values.
|
||||
#[allow(dead_code)]
|
||||
pub fn enable(&mut self) {
|
||||
// Read the latest input capture to clear any pending data in the register.
|
||||
let _ = self.latest_capture();
|
||||
|
||||
// Note(unsafe): This channel owns all access to the specific timer channel.
|
||||
// Only atomic operations on completed on the timer registers.
|
||||
let regs = unsafe { &*<$TY>::ptr() };
|
||||
|
|
Loading…
Reference in New Issue