From 78068e9588cdbd7d99c4334685d5b6664444d8bd Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 2 Jun 2014 01:47:54 +0000 Subject: added support gpio inputs (no lp until now) diff --git a/software/rhmixxx/gpio.c b/software/rhmixxx/gpio.c index bdc1378..4b3171a 100644 --- a/software/rhmixxx/gpio.c +++ b/software/rhmixxx/gpio.c @@ -21,36 +21,52 @@ #include #include "gpio.h" +#include "eventqueue.h" #define GPIO_PIN PINE #define GPIO_PORT PORTE #define GPIO_DDR DDRE +#define GPIO_NUM_INPUTS 4 +#define GPIO_NUM_OUTPUTS 4 + +uint8_t input_last_sent[GPIO_NUM_INPUTS]; void gpio_init(void) { GPIO_DDR = 0x0F; GPIO_PORT = 0xF0; + + uint8_t i; + for(i = 0; i < GPIO_NUM_INPUTS; ++i) + input_last_sent[i] = 0; } void gpio_out_on(uint8_t num) { - if(num < 4) + if(num < GPIO_NUM_OUTPUTS) GPIO_PORT |= (1 << num); } void gpio_out_off(uint8_t num) { - if(num < 4) + if(num < GPIO_NUM_OUTPUTS) GPIO_PORT &= ~(1 << num); } void gpio_out_toggle(uint8_t num) { - if(num < 4) + if(num < GPIO_NUM_OUTPUTS) GPIO_PORT ^= (1 << num); } void gpio_task(void) { - // TODO generate events on change of GPI + uint8_t i; + for(i = 0; i < GPIO_NUM_INPUTS; ++i) { + uint8_t current_state = GPIO_PIN & (1<<(i+4)); + if(current_state != input_last_sent[i]) { + input_last_sent[i] = current_state; + eventqueue_push(i + 64, ((current_state) ? 0 : 1)); // TODO: offset should be defined somewhere + } + } } diff --git a/software/rhmixxx/keypad.c b/software/rhmixxx/keypad.c index 6bdb01f..f27c711 100644 --- a/software/rhmixxx/keypad.c +++ b/software/rhmixxx/keypad.c @@ -160,12 +160,7 @@ static inline void keypad_key_lowpass(uint8_t key_idx, uint8_t current_state) 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); - } + eventqueue_push(key_idx, ((current_state) ? 0 : 1)); } } } -- cgit v0.10.2