/* * btn.h * * Created on: Jul 27, 2024 * Author: true */ #ifndef USER_SRC_BTN_H_ #define USER_SRC_BTN_H_ #define BTN_COUNT 2 #define BTN_DEBOUNCE (12 >> 1) // debounce time in 2ms #define BTN_PORT GPIOC #define BTN_MODE 0x80 #define BTN_PULL_UP (1 << 0) #define BTN_PULL_DOWN (1 << 16) #define BTN1_PIN 5 #define BTN1_PUPD BTN_PULL_UP #define BTN2_PIN 4 #define BTN2_PUPD BTN_PULL_DOWN #define BTN_PUSH (1 << 0) #define BTN_HOLD (1 << 1) #define BTN_RELEASE (1 << 2) #define BTN_IGNORE (1 << 3) typedef struct Btn { uint8_t _mask; uint8_t _pintype; uint16_t _count; // held counts uint16_t hold; // initial hold uint16_t repeat; // repeated hold void (*cb_push)(uint8_t); void (*cb_hold)(uint8_t); void (*cb_release)(uint8_t); } Btn; extern struct Btn btn[BTN_COUNT]; void btn_init(); void btn_poll(); #endif /* USER_SRC_BTN_H_ */