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/>.
23 #include <wikireader.h>
28 static const int keymap
[] = {
34 static const int keymap
[] = {
42 STATIC_ASSERT(ARRAY_SIZE(keymap
) == N_PINS
, right_pins
)
44 static unsigned char gpio_state
;
45 static unsigned char last_state
;
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
;
61 for (i
= 0; i
< N_PINS
; i
++) {
62 if (!(changed
& (1 << i
)))
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
);