Issue #17: Add override function for deltas of rotary encoder

This commit is contained in:
Mario Hüttel 2020-08-30 18:25:10 +02:00
parent 914abd8562
commit 0da6925119
2 changed files with 14 additions and 0 deletions

View File

@ -41,4 +41,6 @@ void rotary_encoder_stop(void);
void rotary_encoder_zero(void);
void rotary_encoder_override_delta(int16_t delta);
#endif /* __ROTARY_ENCODER_H__ */

View File

@ -23,6 +23,8 @@
#include <stm-periph/stm32-gpio-macros.h>
#include <helper-macros/helper-macros.h>
static int16_t IN_SECTION(.ccm.bss) override_delta;
static inline void rotary_encoder_setup_pins(void)
{
rcc_manager_enable_clock(&RCC->AHB1ENR, BITMASK_TO_BITNO(ROTARY_ENCODER_RCC_MASK));
@ -45,6 +47,8 @@ void rotary_encoder_setup(void)
ROTARY_ENCODER_TIMER->CCER = TIM_CCER_CC1P | TIM_CCER_CC2P;
ROTARY_ENCODER_TIMER->PSC = 0;
ROTARY_ENCODER_TIMER->CR1 = TIM_CR1_CEN;
override_delta = 0;
}
uint32_t rotary_encoder_get_abs_val(void)
@ -72,6 +76,9 @@ int32_t rotary_encoder_get_change_val(void)
last_val = val;
diff += override_delta;
override_delta = 0;
return diff;
}
@ -88,3 +95,8 @@ void rotary_encoder_zero(void)
{
ROTARY_ENCODER_TIMER->CNT = 0UL;
}
void rotary_encoder_override_delta(int16_t delta)
{
override_delta = delta;
}