2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 #include <ao_button.h>
23 #define ao_button_queue(b,v) ao_event_put_isr(AO_EVENT_BUTTON, b, v)
25 #define ao_button_queue(b,v)
28 static uint8_t ao_button[AO_BUTTON_COUNT];
29 static AO_TICK_TYPE ao_button_time[AO_BUTTON_COUNT];
31 #define AO_DEBOUNCE AO_MS_TO_TICKS(20)
33 #define port(q) AO_BUTTON_ ## q ## _PORT
34 #define bit(q) AO_BUTTON_ ## q
35 #define pin(q) AO_BUTTON_ ## q ## _PIN
38 ao_button_do(uint8_t b, uint8_t v)
41 if ((AO_TICK_SIGNED) (ao_tick_count - ao_button_time[b]) < AO_DEBOUNCE)
44 /* pins are inverted */
46 if (ao_button[b] != v) {
48 ao_button_time[b] = ao_tick_count;
49 ao_button_queue(b, v);
50 ao_wakeup(&ao_button[b]);
54 #define ao_button_update(b) ao_button_do(b, ao_gpio_get(port(b), bit(b), pin(b)))
59 #if AO_BUTTON_COUNT > 0
62 #if AO_BUTTON_COUNT > 1
65 #if AO_BUTTON_COUNT > 2
68 #if AO_BUTTON_COUNT > 3
71 #if AO_BUTTON_COUNT > 4
76 #define init(b) do { \
77 ao_enable_port(port(b)); \
79 ao_exti_setup(port(b), bit(b), \
80 AO_BUTTON_MODE|AO_EXTI_MODE_FALLING|AO_EXTI_MODE_RISING|AO_EXTI_PRIORITY_MED, \
82 ao_exti_enable(port(b), bit(b)); \
88 #if AO_BUTTON_COUNT > 0
91 #if AO_BUTTON_COUNT > 1