Files
badgemagic-firmware/src/button.h
Dien-Nhung Nguyen-Phu 799d8e43b5 button: add basic button functionalities
- Provided a way to set handler for each button one-press/long-press
- Debouncing with RC filter and Schmitt trigger
2024-06-10 19:26:48 +07:00

24 lines
448 B
C

#ifndef __BUTTON_H__
#define __BUTTON_H__
#include "CH58x_common.h"
enum keys {
KEY1 = 0,
KEY2,
KEY_INDEX,
};
#define KEY2_PIN (GPIO_Pin_22) // PB
#define KEY1_PIN (GPIO_Pin_1) // PA
#define isPressed(key) ((key) ? \
!GPIOB_ReadPortPin(KEY2_PIN) : \
GPIOA_ReadPortPin(KEY1_PIN))
void btn_onOnePress(int key, void (*handler)(void));
void btn_onLongPress(int key, void (*handler)(void));
void btn_init();
#endif /* __BUTTON_H__ */