[rendering] This simple trick didn't work...
[wikipediardware.git] / kernel / gpio.c
blob23a322d68687768a78a6be33bf9cd1e73d3aa5a7
1 /*
2 * mahatma - a simple kernel framework
3 * Copyright (c) 2008, 2009 Daniel Mack <daniel@caiaq.de>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <stdio.h>
20 #include <input.h>
21 #include <regs.h>
22 #include <msg.h>
23 #include <wikireader.h>
24 #include <wikilib.h>
27 #if BOARD_SAMO_A1
28 static const int keymap[] = {
29 WL_INPUT_KEY_RANDOM,
30 WL_INPUT_KEY_SEARCH,
31 WL_INPUT_KEY_HISTORY,
33 #else
34 static const int keymap[] = {
35 WL_INPUT_KEY_SEARCH,
36 WL_INPUT_KEY_HISTORY,
37 WL_INPUT_KEY_RANDOM,
39 #endif
41 #define N_PINS 3
42 STATIC_ASSERT(ARRAY_SIZE(keymap) == N_PINS, right_pins)
44 static unsigned char gpio_state;
45 static unsigned char last_state;
47 void gpio_irq(void)
49 /* the current gpio state is our new comparison reference */
50 gpio_state = get_key_state();
51 REG_KINTCOMP_SCPK0 = gpio_state;
54 int gpio_get_event(struct wl_input_event *ev)
56 unsigned int i, changed = gpio_state ^ last_state;
58 if (!changed)
59 return 0;
61 for (i = 0; i < N_PINS; i++) {
62 if (!(changed & (1 << i)))
63 continue;
65 ev->type = WL_INPUT_EV_TYPE_KEYBOARD;
66 ev->key_event.keycode = keymap[i];
67 ev->key_event.value = !!(gpio_state & (1 << i));
68 last_state ^= (1 << i);
69 return 1;
72 return 0;
75 void gpio_init(void)
77 prepare_keys();
78 gpio_state = 0;
79 last_state = 0;