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 #include <l4/devices/keypad-client.h> 26 27 #include <pthread.h> 28 #include <pthread-l4.h> 29 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 #include <l4/re/dataspace> 52 #include <l4/re/env> 53 54 /* Client object to provide input event access. */ 55 56 class Input_keypad_client 57 { 58 /* Memory and keypad access capabilities. */ 59 60 l4re_ds_t _mem; 61 l4_cap_idx_t _keypad_cap; 62 63 /* Keypad layout details. */ 64 65 Keypad *_keypad; 66 67 /* Keypad memory. */ 68 69 void *_keymem = 0, *_keymem_previous = 0; 70 71 /* Input framework integration. */ 72 73 Input_handler _handler = 0; 74 75 /* Thread details. */ 76 77 pthread_t _pthread; 78 void *_priv; 79 80 /* Initialisation functions. */ 81 82 void init_memory(); 83 void init_keypad(); 84 void init_keypad_data(); 85 void release_keypad_data(); 86 87 /* Activity methods. */ 88 89 static void *scan_mainloop(void *data); 90 void scan_keypad(); 91 92 public: 93 explicit Input_keypad_client(Keypad *keypad) : _keypad(keypad) 94 { 95 init_memory(); 96 init_keypad(); 97 init_keypad_data(); 98 } 99 100 ~Input_keypad_client() 101 { 102 release_keypad_data(); 103 } 104 105 /* Thread initialisation. */ 106 107 void attach(Input_handler handler, void *priv); 108 }; 109 110 #endif