1.1 --- a/pkg/devices/keypad/src/letux400/keypad-letux400.cc Fri May 18 23:41:51 2018 +0200
1.2 +++ b/pkg/devices/keypad/src/letux400/keypad-letux400.cc Sat May 19 00:58:00 2018 +0200
1.3 @@ -24,20 +24,13 @@
1.4 #include <l4/devices/dataspace.h>
1.5 #include <l4/devices/memory.h>
1.6 #include "keypad-server.h"
1.7 +#include "keypad-event-loop.h"
1.8
1.9 -#include <l4/sys/thread.h>
1.10 -#include <pthread.h>
1.11 -#include <pthread-l4.h>
1.12 -
1.13 -#include <l4/cxx/ipc_server>
1.14 #include <l4/re/dataspace>
1.15 #include <l4/re/env>
1.16 -#include <l4/re/rm>
1.17 -#include <l4/re/util/cap_alloc>
1.18 #include <l4/re/util/object_registry>
1.19
1.20 #include <l4/sys/cache.h>
1.21 -#include <l4/util/util.h>
1.22
1.23 #include <stdint.h>
1.24
1.25 @@ -79,15 +72,26 @@
1.26
1.27 void *keymem = 0;
1.28
1.29 -/* Thread details. */
1.30 +
1.31 +
1.32 +/* Set up access to memory. */
1.33
1.34 -static pthread_t _pthread;
1.35 +static int setup_memory()
1.36 +{
1.37 + if (get_memory("jz4730-gpio", &gpio_virt_base, &gpio_virt_base_end) < 0)
1.38 + return 1;
1.39 +
1.40 + gpio_port_a = jz4730_gpio_init(gpio_virt_base, gpio_virt_base + 0x30, 32);
1.41 + gpio_port_d = jz4730_gpio_init(gpio_virt_base + 0x90, gpio_virt_base + 0xc0, 32);
1.42 +
1.43 + return 0;
1.44 +}
1.45
1.46
1.47
1.48 /* Initialise the pins for scanning the keypad. */
1.49
1.50 -static void init_keyscan(void)
1.51 +static void init_keyscan()
1.52 {
1.53 jz4730_gpio_multi_setup(gpio_port_a, &Jz4730_keypad_inputs_mask, Hw::Gpio_chip::Input, 0);
1.54 jz4730_gpio_multi_config_pull(gpio_port_a, &Jz4730_keypad_inputs_mask, Hw::Gpio_chip::Pull_up);
1.55 @@ -99,7 +103,7 @@
1.56 Store each column bitmap in the keypad array.
1.57 */
1.58
1.59 -static void scan_keypad(void)
1.60 +static void scan_keypad()
1.61 {
1.62 uint8_t column, row, value;
1.63
1.64 @@ -122,54 +126,6 @@
1.65 (unsigned long) keypad + Jz4730_keypad_gpio_outputs_count);
1.66 }
1.67
1.68 -/* Set up access to memory. */
1.69 -
1.70 -static int setup_memory(void)
1.71 -{
1.72 - if (get_memory("jz4730-gpio", &gpio_virt_base, &gpio_virt_base_end) < 0)
1.73 - return 1;
1.74 -
1.75 - gpio_port_a = jz4730_gpio_init(gpio_virt_base, gpio_virt_base + 0x30, 32);
1.76 - gpio_port_d = jz4730_gpio_init(gpio_virt_base + 0x90, gpio_virt_base + 0xc0, 32);
1.77 -
1.78 - return 0;
1.79 -}
1.80 -
1.81 -
1.82 -
1.83 -/* Worker thread for scanning the keypad. */
1.84 -
1.85 -static void *scan_thread(void *data)
1.86 -{
1.87 - (void) data;
1.88 -
1.89 - while (1)
1.90 - {
1.91 - scan_keypad();
1.92 - l4_sleep(20); /* 20ms -> 50Hz */
1.93 - }
1.94 -
1.95 - return 0;
1.96 -}
1.97 -
1.98 -/* Thread initialisation. */
1.99 -
1.100 -static int init_thread(void)
1.101 -{
1.102 - pthread_attr_t thread_attr;
1.103 - struct sched_param sp;
1.104 -
1.105 - if (pthread_attr_init(&thread_attr))
1.106 - return 1;
1.107 -
1.108 - sp.sched_priority = 0x20;
1.109 - pthread_attr_setschedpolicy(&thread_attr, SCHED_L4);
1.110 - pthread_attr_setschedparam(&thread_attr, &sp);
1.111 - pthread_attr_setinheritsched(&thread_attr, PTHREAD_EXPLICIT_SCHED);
1.112 -
1.113 - return pthread_create(&_pthread, &thread_attr, scan_thread, 0);
1.114 -}
1.115 -
1.116
1.117
1.118 static L4Re::Util::Registry_server<> server;
1.119 @@ -199,7 +155,9 @@
1.120
1.121 /* Set up a thread to scan the keypad concurrently with the server loop. */
1.122
1.123 - init_thread();
1.124 + Keypad_event_loop loop;
1.125 + loop.attach(scan_keypad);
1.126 + loop.start();
1.127
1.128 /* Initialise and register a server object. */
1.129