X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fdrivers%2Fao_button.c;h=4c18400a406d175725e599d2c62ca78b2f9989c2;hp=725ac45a762334a6bdbf5a303d1bb028200081e6;hb=HEAD;hpb=be84201495fa3cabd699012e57e797355e2bd792 diff --git a/src/drivers/ao_button.c b/src/drivers/ao_button.c index 725ac45a..4c18400a 100644 --- a/src/drivers/ao_button.c +++ b/src/drivers/ao_button.c @@ -19,6 +19,7 @@ #include #include #include +#include #if AO_EVENT #include #define ao_button_queue(b,v) ao_event_put_isr(AO_EVENT_BUTTON, b, v) @@ -37,10 +38,17 @@ static struct ao_button_state ao_button_state[AO_BUTTON_COUNT]; #define port(q) AO_BUTTON_ ## q ## _PORT #define bit(q) AO_BUTTON_ ## q -#define pin(q) AO_BUTTON_ ## q ## _PIN +#ifndef AO_BUTTON_INVERTED +#define AO_BUTTON_INVERTED 1 +#endif + +#if AO_BUTTON_INVERTED /* pins are inverted */ -#define ao_button_value(b) !ao_gpio_get(port(b), bit(b), pin(b)) +#define ao_button_value(b) !ao_gpio_get(port(b), bit(b)) +#else +#define ao_button_value(b) ao_gpio_get(port(b), bit(b)) +#endif static uint8_t _ao_button_get(uint8_t b) @@ -60,6 +68,39 @@ _ao_button_get(uint8_t b) #endif #if AO_BUTTON_COUNT > 4 case 4: return ao_button_value(4); +#endif +#if AO_BUTTON_COUNT > 5 + case 5: return ao_button_value(5); +#endif +#if AO_BUTTON_COUNT > 6 + case 6: return ao_button_value(6); +#endif +#if AO_BUTTON_COUNT > 7 + case 7: return ao_button_value(7); +#endif +#if AO_BUTTON_COUNT > 8 + case 8: return ao_button_value(8); +#endif +#if AO_BUTTON_COUNT > 9 + case 9: return ao_button_value(9); +#endif +#if AO_BUTTON_COUNT > 10 + case 10: return ao_button_value(10); +#endif +#if AO_BUTTON_COUNT > 11 + case 11: return ao_button_value(11); +#endif +#if AO_BUTTON_COUNT > 12 + case 12: return ao_button_value(12); +#endif +#if AO_BUTTON_COUNT > 13 + case 13: return ao_button_value(13); +#endif +#if AO_BUTTON_COUNT > 14 + case 14: return ao_button_value(14); +#endif +#if AO_BUTTON_COUNT > 15 + case 15: return ao_button_value(15); #endif } return 0; @@ -84,7 +125,7 @@ _ao_button_check(uint8_t b) static void _ao_button_init(uint8_t b) { - uint8_t m = ao_arch_irqsave(); + uint32_t m = ao_arch_irqsave(); uint8_t value = _ao_button_get(b); ao_button_state[b].value = value; ao_button_state[b].time = ao_time(); @@ -109,12 +150,7 @@ ao_button_isr(void) } #define init(b) do { \ - ao_enable_port(port(b)); \ - \ - ao_exti_setup(port(b), bit(b), \ - AO_BUTTON_MODE|AO_EXTI_MODE_FALLING|AO_EXTI_MODE_RISING|AO_EXTI_PRIORITY_MED, \ - ao_button_isr); \ - ao_exti_enable(port(b), bit(b)); \ + ao_enable_input(port(b), bit(b), AO_BUTTON_MODE); \ _ao_button_init(b); \ } while (0) @@ -136,4 +172,42 @@ ao_button_init(void) #if AO_BUTTON_COUNT > 4 init(4); #endif +#if AO_BUTTON_COUNT > 5 + init(5); +#endif +#if AO_BUTTON_COUNT > 6 + init(6); +#endif +#if AO_BUTTON_COUNT > 7 + init(7); +#endif +#if AO_BUTTON_COUNT > 8 + init(8); +#endif +#if AO_BUTTON_COUNT > 9 + init(9); +#endif +#if AO_BUTTON_COUNT > 10 + init(10); +#endif +#if AO_BUTTON_COUNT > 11 + init(11); +#endif +#if AO_BUTTON_COUNT > 12 + init(12); +#endif +#if AO_BUTTON_COUNT > 13 + init(13); +#endif +#if AO_BUTTON_COUNT > 14 + init(14); +#endif +#if AO_BUTTON_COUNT > 15 + init(15); +#endif +#if AO_BUTTON_COUNT > 16 + #error too many buttons +#endif + ao_fast_timer_init(); + ao_fast_timer_on(ao_button_isr); }