diff options
Diffstat (limited to 'software')
-rw-r--r-- | software/rhmixxx/keypad.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/software/rhmixxx/keypad.c b/software/rhmixxx/keypad.c index 196050b..7a58ad0 100644 --- a/software/rhmixxx/keypad.c +++ b/software/rhmixxx/keypad.c @@ -28,19 +28,22 @@ #define KEYPAD_PIN PINA #define KEYPAD_PORT PORTA #define KEYPAD_DDR DDRA +#define KEYPAD_NUM_COLS 4 +#define KEYPAD_NUM_ROWS 4 +#define KEYPAD_NUM_KEYS KEYPAD_NUM_COLS * KEYPAD_NUM_ROWS #define KEYPAD_LP_CNT_MAX 200 static struct { uint8_t last_sent; int16_t lp_cnt; -} keypad_state[16]; +} keypad_state[KEYPAD_NUM_KEYS]; void keypad_init(void) { KEYPAD_DDR = 0x00; KEYPAD_PORT = 0x0F; uint8_t i; - for(i = 0; i < 16; ++i) { + for(i = 0; i < KEYPAD_NUM_KEYS; ++i) { keypad_state[i].last_sent = 0; keypad_state[i].lp_cnt = 0; } @@ -146,13 +149,13 @@ static void keypad_key_lowpass(uint8_t key_idx, uint8_t current_state) void keypad_task(void) { uint8_t col, row; - for(col = 0; col < 4; ++col) { + for(col = 0; col < KEYPAD_NUM_COLS; ++col) { KEYPAD_DDR = 1 << (col + 4); KEYPAD_PORT = 0x0F; _delay_us(10); - for(row = 0; row < 4; ++row) { - uint8_t key_idx = col*4 + row; + for(row = 0; row < KEYPAD_NUM_ROWS; ++row) { + uint8_t key_idx = col*KEYPAD_NUM_ROWS + row; uint8_t current_state = KEYPAD_PIN & (1 << row); keypad_key_lowpass(key_idx, current_state); |