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; 58 l4_cap_idx_t _keypad_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_memory(); 80 void init_keypad(); 81 void init_keypad_data(); 82 void release_keypad_data(); 83 84 /* Activity methods. */ 85 86 static void *scan_mainloop(void *data); 87 void scan_keypad(); 88 89 public: 90 explicit Input_keypad_client(Keypad_generic *keypad) : _keypad(keypad) 91 { 92 init_memory(); 93 init_keypad(); 94 init_keypad_data(); 95 } 96 97 ~Input_keypad_client() 98 { 99 release_keypad_data(); 100 } 101 102 /* Thread initialisation. */ 103 104 void attach(Input_handler handler, void *priv); 105 }; 106 107 #endif