i want to user the timer encoder interface of the F4. I already came up with init code, since the GPT driver does not directly support this.
Code: Select all
void setup_encoder(void) {
palSetPadMode(GPIOD,12, PAL_MODE_ALTERNATE(2));
palSetPadMode(GPIOD,13, PAL_MODE_ALTERNATE(2));
rccEnableTIM4(FALSE);
rccResetTIM4();
STM32_TIM4->SMCR = 3; // Encoder mode 3
STM32_TIM4->CCER = 0; // rising edge polarity
STM32_TIM4->ARR = 0xFFFF; // count from 0-ARR or ARR-0
STM32_TIM4->CCMR1 = 0xC1C1; // f_DTS/16, N=8, IC1->TI1, IC2->TI2
STM32_TIM4->CNT = 0; // Initialize counter
STM32_TIM4->EGR = 1; // Generate an update event
STM32_TIM4->CR1 = 1; // Enable the counter
}
The nice stackoverflow guy i got part of the code from already generates a update event. I want to use this Event/Interrupt to handle the rotations.
What would be the chibios way to do this? I have seen that in the GPT Driver i can configure a callback. Can i use this even if a configure the timer manually?
Or can i somehow use the event system for this?
Context is a Rotary Encoder as a UI input (ugfx). I am new to ChibiOS.
thx