diff options
author | Christian Pointner <equinox@helsinki.at> | 2014-06-02 01:47:54 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2014-06-02 01:47:54 (GMT) |
commit | 78068e9588cdbd7d99c4334685d5b6664444d8bd (patch) | |
tree | 4ad43126f527be0c2f52efc43dd454eac1e8e77f | |
parent | 23b29a81a9df8768ca88a8015f02fbb34f5328cb (diff) |
added support gpio inputs (no lp until now)
-rw-r--r-- | software/rhmixxx/gpio.c | 24 | ||||
-rw-r--r-- | software/rhmixxx/keypad.c | 7 |
2 files changed, 21 insertions, 10 deletions
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 <avr/io.h> #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)); } } } |