diff --git a/cores/arduino/HardwareTimer.h b/cores/arduino/HardwareTimer.h index d975ffb1b2..2215743df1 100644 --- a/cores/arduino/HardwareTimer.h +++ b/cores/arduino/HardwareTimer.h @@ -90,6 +90,25 @@ typedef enum { PERCENT_COMPARE_FORMAT, // used for Dutycycle } TimerCompareFormat_t; +typedef enum { + FILTER_NONE = 0, // No filter + FILTER_CKINT_N2, // Sampling rate is same as clock interrupt, n=2 events + FILTER_CKINT_N4, // Sampling rate is same as clock interrupt, n=4 events + FILTER_CKINT_N8, // Sampling rate is same as clock interrupt, n=8 events + FILTER_DTS2_N6, // Sampling rate is DTS/2, n=6 events + FILTER_DTS2_N8, // Sampling rate is DTS/2, n=8 events + FILTER_DTS4_N6, // Sampling rate is DTS/4, n=6 events + FILTER_DTS4_N8, // Sampling rate is DTS/4, n=8 events + FILTER_DTS8_N6, // Sampling rate is DTS/8, n=6 events + FILTER_DTS8_N8, // Sampling rate is DTS/8, n=8 events + FILTER_DTS16_N5, // Sampling rate is DTS/16, n=5 events + FILTER_DTS16_N6, // Sampling rate is DTS/16, n=6 events + FILTER_DTS16_N8, // Sampling rate is DTS/16, n=8 events + FILTER_DTS32_N5, // Sampling rate is DTS/32, n=5 events + FILTER_DTS32_N6, // Sampling rate is DTS/32, n=6 events + FILTER_DTS32_N8, // Sampling rate is DTS/32, n=8 events +} ChannelInputFilter_t; + #ifdef __cplusplus #include @@ -121,8 +140,8 @@ class HardwareTimer { void setCount(uint32_t val, TimerFormat_t format = TICK_FORMAT); // set timer counter to value 'val' depending on format provided uint32_t getCount(TimerFormat_t format = TICK_FORMAT); // return current counter value of timer depending on format provided - void setMode(uint32_t channel, TimerModes_t mode, PinName pin = NC); // Configure timer channel with specified mode on specified pin if available - void setMode(uint32_t channel, TimerModes_t mode, uint32_t pin); + void setMode(uint32_t channel, TimerModes_t mode, PinName pin = NC, ChannelInputFilter_t filter = FILTER_NONE); // Configure timer channel with specified mode on specified pin if available + void setMode(uint32_t channel, TimerModes_t mode, uint32_t pin, ChannelInputFilter_t filter = FILTER_NONE); TimerModes_t getMode(uint32_t channel); // Retrieve configured mode diff --git a/libraries/SrcWrapper/src/HardwareTimer.cpp b/libraries/SrcWrapper/src/HardwareTimer.cpp index 231f53f41d..f65a4f4f13 100644 --- a/libraries/SrcWrapper/src/HardwareTimer.cpp +++ b/libraries/SrcWrapper/src/HardwareTimer.cpp @@ -619,9 +619,9 @@ void HardwareTimer::setCount(uint32_t counter, TimerFormat_t format) * @param pin: Arduino pin number, ex: D1, 1 or PA1 * @retval None */ -void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, uint32_t pin) +void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, uint32_t pin, ChannelInputFilter_t filter) { - setMode(channel, mode, digitalPinToPinName(pin)); + setMode(channel, mode, digitalPinToPinName(pin), filter); } /** @@ -631,7 +631,7 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, uint32_t pin) * @param pin: pin name, ex: PB_0 * @retval None */ -void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin) +void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin, ChannelInputFilter_t filter) { int timChannel = getChannel(channel); int timAssociatedInputChannel; @@ -659,7 +659,7 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin) channelIC.ICPolarity = TIM_ICPOLARITY_RISING; channelIC.ICSelection = TIM_ICSELECTION_DIRECTTI; channelIC.ICPrescaler = TIM_ICPSC_DIV1; - channelIC.ICFilter = 0; + channelIC.ICFilter = filter; switch (mode) { case TIMER_DISABLED: