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