Skip to content

Commit

Permalink
Start enum from 0 so we can directly convert enum to filter value
Browse files Browse the repository at this point in the history
  • Loading branch information
dberlin committed Sep 25, 2023
1 parent 2823485 commit d243cf8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 57 deletions.
2 changes: 1 addition & 1 deletion cores/arduino/HardwareTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ typedef enum {
} TimerCompareFormat_t;

typedef enum {
FILTER_NONE = 1, // No filter
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
Expand Down
57 changes: 1 addition & 56 deletions libraries/SrcWrapper/src/HardwareTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,61 +624,6 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, uint32_t pin, C
setMode(channel, mode, digitalPinToPinName(pin), filter);
}

inline uint8_t getICFBitsFromFilterMode(ChannelInputFilter_t filter)
{
switch (filter) {
case FILTER_NONE:
return 0;
break;
case FILTER_CKINT_N2:
return 1;
break;
case FILTER_CKINT_N4:
return 2;
break;
case FILTER_CKINT_N8:
return 3;
break;
case FILTER_DTS2_N6:
return 4;
break;
case FILTER_DTS2_N8:
return 5;
break;
case FILTER_DTS4_N6:
return 6;
break;
case FILTER_DTS4_N8:
return 7;
break;
case FILTER_DTS8_N6:
return 8;
break;
case FILTER_DTS8_N8:
return 9;
break;
case FILTER_DTS16_N5:
return 10;
break;
case FILTER_DTS16_N6:
return 11;
break;
case FILTER_DTS16_N8:
return 12;
break;
case FILTER_DTS32_N5:
return 13;
break;
case FILTER_DTS32_N6:
return 14;
break;
case FILTER_DTS32_N8:
return 15;
break;
}
return 0;
}

/**
* @brief Set channel mode
* @param channel: Arduino channel [1..4]
Expand Down Expand Up @@ -714,7 +659,7 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin, Ch
channelIC.ICPolarity = TIM_ICPOLARITY_RISING;
channelIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
channelIC.ICPrescaler = TIM_ICPSC_DIV1;
channelIC.ICFilter = getICFBitsFromFilterMode(filter);
channelIC.ICFilter = filter;

switch (mode) {
case TIMER_DISABLED:
Expand Down

0 comments on commit d243cf8

Please sign in to comment.