summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-06-01 18:55:33 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-06-01 18:55:33 (GMT)
commit683f79ee498764e2dff0f61760f6f9d075d6fbb4 (patch)
tree4f59fd8b58724073bf146f2d306127dd0a7ee2b8
parent96e244403e182672ee15706c8419e61a2075fa01 (diff)
cleanups
-rw-r--r--software/rhmixxx/keypad.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/software/rhmixxx/keypad.c b/software/rhmixxx/keypad.c
index 7cda7b9..196050b 100644
--- a/software/rhmixxx/keypad.c
+++ b/software/rhmixxx/keypad.c
@@ -30,12 +30,11 @@
#define KEYPAD_DDR DDRA
#define KEYPAD_LP_CNT_MAX 200
-static struct key_state_struct {
+static struct {
uint8_t last_sent;
int16_t lp_cnt;
} keypad_state[16];
-
void keypad_init(void)
{
KEYPAD_DDR = 0x00;
@@ -124,6 +123,26 @@ void keypad_led_toggle(uint8_t led)
}
}
+static void keypad_key_lowpass(uint8_t key_idx, uint8_t current_state)
+{
+ keypad_state[key_idx].lp_cnt += current_state ? -1 : +1;
+ if(keypad_state[key_idx].lp_cnt <= 0 ||
+ keypad_state[key_idx].lp_cnt >= KEYPAD_LP_CNT_MAX) {
+
+ keypad_state[key_idx].lp_cnt = keypad_state[key_idx].lp_cnt <= 0 ? 0 : KEYPAD_LP_CNT_MAX;
+
+ if(current_state != keypad_state[key_idx].last_sent) {
+ keypad_state[key_idx].last_sent = current_state;
+
+ if(current_state) {
+ eventqueue_push(key_idx, 0);
+ } else {
+ eventqueue_push(key_idx, 1);
+ }
+ }
+ }
+}
+
void keypad_task(void)
{
uint8_t col, row;
@@ -134,23 +153,9 @@ void keypad_task(void)
for(row = 0; row < 4; ++row) {
uint8_t key_idx = col*4 + row;
- uint8_t current_state = KEYPAD_PIN & (1 << row);
- keypad_state[key_idx].lp_cnt += current_state ? -1 : +1;
- if(keypad_state[key_idx].lp_cnt <= 0 ||
- keypad_state[key_idx].lp_cnt >= KEYPAD_LP_CNT_MAX) {
-
- keypad_state[key_idx].lp_cnt = keypad_state[key_idx].lp_cnt <= 0 ? 0 : KEYPAD_LP_CNT_MAX;
- if(current_state != keypad_state[key_idx].last_sent) {
- keypad_state[key_idx].last_sent = current_state;
-
- if(current_state) {
- eventqueue_push(key_idx, 0);
- } else {
- eventqueue_push(key_idx, 1);
- }
- }
- }
+ uint8_t current_state = KEYPAD_PIN & (1 << row);
+ keypad_key_lowpass(key_idx, current_state);
}
}
KEYPAD_DDR = 0x00;