paul@0 | 1 | /* |
paul@0 | 2 | * Common keypad client functionality for input event generation. |
paul@0 | 3 | * |
paul@152 | 4 | * Copyright (C) 2018, 2023 Paul Boddie <paul@boddie.org.uk> |
paul@0 | 5 | * |
paul@0 | 6 | * This program is free software; you can redistribute it and/or |
paul@0 | 7 | * modify it under the terms of the GNU General Public License as |
paul@0 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@0 | 9 | * the License, or (at your option) any later version. |
paul@0 | 10 | * |
paul@0 | 11 | * This program is distributed in the hope that it will be useful, |
paul@0 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@0 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@0 | 14 | * GNU General Public License for more details. |
paul@0 | 15 | * |
paul@0 | 16 | * You should have received a copy of the GNU General Public License |
paul@0 | 17 | * along with this program; if not, write to the Free Software |
paul@0 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@0 | 19 | * Boston, MA 02110-1301, USA |
paul@0 | 20 | */ |
paul@0 | 21 | |
paul@0 | 22 | #pragma once |
paul@0 | 23 | |
paul@0 | 24 | #include <l4/devices/keypad.h> |
paul@0 | 25 | |
paul@0 | 26 | #include <pthread.h> |
paul@0 | 27 | #include <pthread-l4.h> |
paul@0 | 28 | |
paul@153 | 29 | #include <l4/re/c/dataspace.h> |
paul@0 | 30 | #include <l4/re/event_enums.h> |
paul@0 | 31 | |
paul@0 | 32 | #include <stdint.h> |
paul@0 | 33 | |
paul@152 | 34 | |
paul@152 | 35 | |
paul@0 | 36 | /* Input event and handler. */ |
paul@0 | 37 | |
paul@0 | 38 | typedef struct |
paul@0 | 39 | { |
paul@0 | 40 | enum L4Re_events_ev type; |
paul@0 | 41 | int code; |
paul@0 | 42 | int value; |
paul@0 | 43 | } Input_event; |
paul@0 | 44 | |
paul@0 | 45 | typedef void (*Input_handler)(Input_event, void *); |
paul@0 | 46 | |
paul@0 | 47 | |
paul@0 | 48 | |
paul@0 | 49 | #ifdef __cplusplus |
paul@0 | 50 | |
paul@0 | 51 | /* Client object to provide input event access. */ |
paul@0 | 52 | |
paul@0 | 53 | class Input_keypad_client |
paul@0 | 54 | { |
paul@0 | 55 | /* Memory and keypad access capabilities. */ |
paul@0 | 56 | |
paul@152 | 57 | l4re_ds_t _mem; |
paul@152 | 58 | l4_cap_idx_t _keypad_cap; |
paul@0 | 59 | |
paul@0 | 60 | /* Keypad layout details. */ |
paul@0 | 61 | |
paul@153 | 62 | Keypad_generic *_keypad; |
paul@0 | 63 | |
paul@0 | 64 | /* Keypad memory. */ |
paul@0 | 65 | |
paul@0 | 66 | void *_keymem = 0, *_keymem_previous = 0; |
paul@0 | 67 | |
paul@0 | 68 | /* Input framework integration. */ |
paul@0 | 69 | |
paul@0 | 70 | Input_handler _handler = 0; |
paul@0 | 71 | |
paul@0 | 72 | /* Thread details. */ |
paul@0 | 73 | |
paul@0 | 74 | pthread_t _pthread; |
paul@0 | 75 | void *_priv; |
paul@0 | 76 | |
paul@0 | 77 | /* Initialisation functions. */ |
paul@0 | 78 | |
paul@0 | 79 | void init_memory(); |
paul@0 | 80 | void init_keypad(); |
paul@0 | 81 | void init_keypad_data(); |
paul@0 | 82 | void release_keypad_data(); |
paul@0 | 83 | |
paul@0 | 84 | /* Activity methods. */ |
paul@0 | 85 | |
paul@0 | 86 | static void *scan_mainloop(void *data); |
paul@0 | 87 | void scan_keypad(); |
paul@0 | 88 | |
paul@0 | 89 | public: |
paul@153 | 90 | explicit Input_keypad_client(Keypad_generic *keypad) : _keypad(keypad) |
paul@0 | 91 | { |
paul@0 | 92 | init_memory(); |
paul@0 | 93 | init_keypad(); |
paul@0 | 94 | init_keypad_data(); |
paul@0 | 95 | } |
paul@0 | 96 | |
paul@0 | 97 | ~Input_keypad_client() |
paul@0 | 98 | { |
paul@0 | 99 | release_keypad_data(); |
paul@0 | 100 | } |
paul@0 | 101 | |
paul@0 | 102 | /* Thread initialisation. */ |
paul@0 | 103 | |
paul@0 | 104 | void attach(Input_handler handler, void *priv); |
paul@0 | 105 | }; |
paul@0 | 106 | |
paul@0 | 107 | #endif |