Skip to content

Commit 61a1680

Browse files
authored
Add support for setting the channel input filter (#2136)
* Add support for setting the channel input filter * Format with astyle * Start enum from 0 so we can directly convert enum to filter value
1 parent 1ee0a03 commit 61a1680

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

cores/arduino/HardwareTimer.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ typedef enum {
9090
PERCENT_COMPARE_FORMAT, // used for Dutycycle
9191
} TimerCompareFormat_t;
9292

93+
typedef enum {
94+
FILTER_NONE = 0, // No filter
95+
FILTER_CKINT_N2, // Sampling rate is same as clock interrupt, n=2 events
96+
FILTER_CKINT_N4, // Sampling rate is same as clock interrupt, n=4 events
97+
FILTER_CKINT_N8, // Sampling rate is same as clock interrupt, n=8 events
98+
FILTER_DTS2_N6, // Sampling rate is DTS/2, n=6 events
99+
FILTER_DTS2_N8, // Sampling rate is DTS/2, n=8 events
100+
FILTER_DTS4_N6, // Sampling rate is DTS/4, n=6 events
101+
FILTER_DTS4_N8, // Sampling rate is DTS/4, n=8 events
102+
FILTER_DTS8_N6, // Sampling rate is DTS/8, n=6 events
103+
FILTER_DTS8_N8, // Sampling rate is DTS/8, n=8 events
104+
FILTER_DTS16_N5, // Sampling rate is DTS/16, n=5 events
105+
FILTER_DTS16_N6, // Sampling rate is DTS/16, n=6 events
106+
FILTER_DTS16_N8, // Sampling rate is DTS/16, n=8 events
107+
FILTER_DTS32_N5, // Sampling rate is DTS/32, n=5 events
108+
FILTER_DTS32_N6, // Sampling rate is DTS/32, n=6 events
109+
FILTER_DTS32_N8, // Sampling rate is DTS/32, n=8 events
110+
} ChannelInputFilter_t;
111+
93112
#ifdef __cplusplus
94113

95114
#include <functional>
@@ -121,8 +140,8 @@ class HardwareTimer {
121140
void setCount(uint32_t val, TimerFormat_t format = TICK_FORMAT); // set timer counter to value 'val' depending on format provided
122141
uint32_t getCount(TimerFormat_t format = TICK_FORMAT); // return current counter value of timer depending on format provided
123142

124-
void setMode(uint32_t channel, TimerModes_t mode, PinName pin = NC); // Configure timer channel with specified mode on specified pin if available
125-
void setMode(uint32_t channel, TimerModes_t mode, uint32_t pin);
143+
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
144+
void setMode(uint32_t channel, TimerModes_t mode, uint32_t pin, ChannelInputFilter_t filter = FILTER_NONE);
126145

127146
TimerModes_t getMode(uint32_t channel); // Retrieve configured mode
128147

libraries/SrcWrapper/src/HardwareTimer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,9 @@ void HardwareTimer::setCount(uint32_t counter, TimerFormat_t format)
619619
* @param pin: Arduino pin number, ex: D1, 1 or PA1
620620
* @retval None
621621
*/
622-
void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, uint32_t pin)
622+
void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, uint32_t pin, ChannelInputFilter_t filter)
623623
{
624-
setMode(channel, mode, digitalPinToPinName(pin));
624+
setMode(channel, mode, digitalPinToPinName(pin), filter);
625625
}
626626

627627
/**
@@ -631,7 +631,7 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, uint32_t pin)
631631
* @param pin: pin name, ex: PB_0
632632
* @retval None
633633
*/
634-
void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin)
634+
void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin, ChannelInputFilter_t filter)
635635
{
636636
int timChannel = getChannel(channel);
637637
int timAssociatedInputChannel;
@@ -659,7 +659,7 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin)
659659
channelIC.ICPolarity = TIM_ICPOLARITY_RISING;
660660
channelIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
661661
channelIC.ICPrescaler = TIM_ICPSC_DIV1;
662-
channelIC.ICFilter = 0;
662+
channelIC.ICFilter = filter;
663663

664664
switch (mode) {
665665
case TIMER_DISABLED:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy