floatpump-firmware/Core/Src/button_input.c

30 lines
796 B
C

//
// Created by robtor on 16.12.22.
//
#include "main.h"
#include "button_input.h"
bool rot_button = false;
uint16_t rot_counter = 0;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
static uint16_t rot_state = 0;
static uint16_t btn_state = 0;
rot_state = (rot_state << 1) | (HAL_GPIO_ReadPin(RRCLK_GPIO_Port, RRCLK_Pin) == GPIO_PIN_SET ? 0x1 : 0x0) | 0xe000;
btn_state = (btn_state << 1) | (HAL_GPIO_ReadPin(RRSW_GPIO_Port, RRSW_Pin) == GPIO_PIN_SET ? 0x1 : 0x0) | 0xe000;
if (rot_state == 0xf000) {
rot_state = 0x0000;
if (HAL_GPIO_ReadPin(RRDT_GPIO_Port, RRDT_Pin) == GPIO_PIN_SET) {
rot_counter++;
} else {
rot_counter--;
}
}
if (btn_state == 0xf000) {
rot_button = true;
}
}