1 /* 2 * Provide access to keypad events on the configured device. 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 #include <l4/devices/dataspace.h> 23 #include <l4/devices/keypad-loader.h> 24 25 #include "input-event-server.h" 26 #include "input-keypad-client.h" 27 28 #include <l4/re/event> 29 30 #include <ipc/cap_alloc.h> 31 #include <ipc/server.h> 32 33 #include "input_server.h" 34 35 36 37 static void handler(Input_event event, void *priv) 38 { 39 Input_event_server *server = (Input_event_server *) priv; 40 41 server->send_event(event.type, event.code, event.value); 42 } 43 44 45 46 int main(void) 47 { 48 /* Load the keypad details from the configured library. */ 49 50 Keypad_generic *keypad = load_keypad(); 51 Input_keypad_client client(keypad); 52 void *buffer; 53 54 /* Memory allocation capability for the event data. */ 55 56 l4re_ds_t mem = allocate_data(L4_PAGESIZE, &buffer); 57 58 if (l4_is_invalid_cap(mem)) 59 return 1; 60 61 /* Obtain a capability for the interrupt. */ 62 63 l4_cap_idx_t irq = ipc_cap_alloc(); 64 65 if (l4_is_invalid_cap(irq)) 66 return 1; 67 68 /* Event buffer for the data. */ 69 70 L4Re::Event_buffer events(buffer, L4_PAGESIZE); 71 72 /* Initialise and register a server object. */ 73 74 Input_event_server obj(mem, events); 75 76 /* Attach the event handler and wait for events. */ 77 78 client.attach(handler, (void *) &obj); 79 80 /* Bind and start the IPC server loop. */ 81 82 if (ipc_server_loop_for(Input, &obj, "ev")) 83 return 1; 84 85 return 0; 86 }