2024-10-16 23:51:49 -07:00
|
|
|
/*
|
|
|
|
* btn.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef USER_SRC_BTN_H_
|
|
|
|
#define USER_SRC_BTN_H_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <ch32v20x.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define BTN_COUNT 5
|
|
|
|
#define BTN_DEBOUNCE (24 / 4) // debounce time in ~4ms increments
|
|
|
|
|
|
|
|
#define BTN_PORT GPIOB
|
|
|
|
|
2024-10-23 04:19:13 -07:00
|
|
|
#define BTN1 0
|
2024-10-16 23:51:49 -07:00
|
|
|
#define BTN1_PIN 10
|
2024-10-23 04:19:13 -07:00
|
|
|
#define BTN2 1
|
2024-10-16 23:51:49 -07:00
|
|
|
#define BTN2_PIN 11
|
|
|
|
|
2024-10-23 04:19:13 -07:00
|
|
|
#define DIP1 2
|
2024-10-16 23:51:49 -07:00
|
|
|
#define DIP1_PIN 12
|
2024-10-23 04:19:13 -07:00
|
|
|
#define DIP2 3
|
2024-10-16 23:51:49 -07:00
|
|
|
#define DIP2_PIN 13
|
2024-10-23 04:19:13 -07:00
|
|
|
#define DIP3 4
|
2024-10-16 23:51:49 -07:00
|
|
|
#define DIP3_PIN 14
|
|
|
|
|
|
|
|
#define BTN_PIN_MASK 0xf
|
|
|
|
|
|
|
|
|
|
|
|
#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 _pintype;
|
|
|
|
uint8_t _mask;
|
|
|
|
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_ */
|