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
This commit is contained in:
23
src/button.h
Normal file
23
src/button.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#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__ */
|
||||
Reference in New Issue
Block a user