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 /software/rhmixxx/gpio.c | |
parent | 23b29a81a9df8768ca88a8015f02fbb34f5328cb (diff) |
added support gpio inputs (no lp until now)
Diffstat (limited to 'software/rhmixxx/gpio.c')
-rw-r--r-- | software/rhmixxx/gpio.c | 24 |
1 files changed, 20 insertions, 4 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 + } + } } |