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