floatpump-firmware/Core/Src/button_input.c

30 lines
796 B
C
Raw Normal View History

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