sc8-gat-stand/gat_stand_fw/user/periph/btn.h

64 lines
1.0 KiB
C
Raw Normal View History

/*
* btn.h
*/
#ifndef USER_PERIPH_BTN_H_
#define USER_PERIPH_BTN_H_
#include <ch32v20x.h>
#define BTN_COUNT 5
#define BTN_DEBOUNCE (24 / 4) // debounce time in ~4ms increments
#define BTN_PORT GPIOB
#define BTN1 0
#define BTN1_PIN 10
#define BTN2 1
#define BTN2_PIN 11
#define DIP1 2
#define DIP1_PIN 12
#define DIP2 3
#define DIP2_PIN 13
#define DIP3 4
#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_PERIPH_BTN_H_ */