1.1 --- a/pkg/landfall-examples/qi_lb60_keypad_physical/Makefile Mon Jun 19 16:58:52 2023 +0200
1.2 +++ b/pkg/landfall-examples/qi_lb60_keypad_physical/Makefile Mon Jun 19 16:59:21 2023 +0200
1.3 @@ -2,7 +2,35 @@
1.4 L4DIR ?= $(PKGDIR)/../..
1.5
1.6 TARGET = ex_qi_lb60_keypad_physical
1.7 -SRC_C = qi_lb60_keypad_physical.c
1.8 -REQUIRES_LIBS = l4re_c-util
1.9 +
1.10 +# Locations for interface input and generated output.
1.11 +
1.12 +IDL_DIR = $(L4DIR)/pkg/devices/idl
1.13 +IDL_MK_DIR = $(L4DIR)/idl4re/mk
1.14 +IDL_BUILD_DIR = .
1.15 +IDL_EXPORT_DIR = .
1.16 +
1.17 +include $(IDL_MK_DIR)/idl.mk
1.18 +
1.19 +# Individual interfaces.
1.20 +
1.21 +CLIENT_INTERFACES_C = keypad
1.22 +
1.23 +# Generated and plain source files.
1.24 +
1.25 +CLIENT_INTERFACES_SRC_C = $(call interfaces_to_client_c,$(CLIENT_INTERFACES_C))
1.26 +
1.27 +PLAIN_SRC_C = qi_lb60_keypad_physical.c
1.28 +
1.29 +# Normal definitions.
1.30 +
1.31 +SRC_C = $(CLIENT_INTERFACES_SRC_C) $(PLAIN_SRC_C)
1.32 +
1.33 +REQUIRES_LIBS = l4re_c l4re_c-util libipc
1.34 +
1.35 +PRIVATE_INCDIR = $(IDL_BUILD_DIR) $(IDL_EXPORT_DIR)
1.36
1.37 include $(L4DIR)/mk/prog.mk
1.38 +include $(IDL_MK_DIR)/interface_rules.mk
1.39 +
1.40 +$(PLAIN_SRC_C): $(CLIENT_INTERFACES_SRC_C)
2.1 --- a/pkg/landfall-examples/qi_lb60_keypad_physical/qi_lb60_keypad_physical.c Mon Jun 19 16:58:52 2023 +0200
2.2 +++ b/pkg/landfall-examples/qi_lb60_keypad_physical/qi_lb60_keypad_physical.c Mon Jun 19 16:59:21 2023 +0200
2.3 @@ -20,20 +20,19 @@
2.4 */
2.5
2.6 #include <l4/re/c/rm.h>
2.7 -#include <l4/re/c/util/cap_alloc.h>
2.8 #include <l4/re/env.h>
2.9 -#include <l4/util/util.h>
2.10 -#include <l4/sys/ipc.h>
2.11
2.12 #include <l4/re/c/util/video/goos_fb.h>
2.13 #include <l4/re/c/video/view.h>
2.14
2.15 -#include <l4/util/util.h>
2.16 -#include <stdio.h>
2.17 #include <unistd.h>
2.18 #include <stdint.h>
2.19 #include <stdlib.h>
2.20
2.21 +#include "keypad_client.h"
2.22 +
2.23 +
2.24 +
2.25 enum Jz4740_keypad_gpio
2.26 {
2.27 Jz4740_keypad_gpio_inputs_count = 8,
2.28 @@ -48,8 +47,7 @@
2.29
2.30 /* Keypad status and dimensions. */
2.31
2.32 -uint32_t *keypad = 0;
2.33 -void *keymem = 0;
2.34 +uint32_t *keymem = 0;
2.35 int columns = Jz4740_keypad_gpio_outputs_count, rows = Jz4740_keypad_gpio_inputs_count;
2.36
2.37 /* Position units. */
2.38 @@ -246,7 +244,7 @@
2.39 /* Plot the rectangle for the key. */
2.40
2.41 fill_rectangle((pos[0] * fbi.width) / WIDTH, pos[1] * rowsize, colsize, rowsize,
2.42 - keypad[column] & mask ? 0xffffff : 0);
2.43 + keymem[column] & mask ? 0xffffff : 0);
2.44 }
2.45
2.46 /* Refresh the display. */
2.47 @@ -258,9 +256,8 @@
2.48
2.49 int main(void)
2.50 {
2.51 - l4_cap_idx_t keypad_server;
2.52 + l4_cap_idx_t keypad_cap;
2.53 l4re_ds_t mem;
2.54 - l4_msgtag_t tag;
2.55
2.56 if (l4re_util_video_goos_fb_setup_name(&gfb, "fb"))
2.57 return 1;
2.58 @@ -273,28 +270,21 @@
2.59
2.60 /* Obtain a reference to the keypad. */
2.61
2.62 - keypad_server = l4re_env_get_cap("keypad");
2.63 - if (l4_is_invalid_cap(keypad_server)) return 1;
2.64 + keypad_cap = l4re_env_get_cap("keypad");
2.65
2.66 - /* Obtain a capability for the keypad data. */
2.67 -
2.68 - mem = l4re_util_cap_alloc();
2.69 - if (l4_is_invalid_cap(mem)) return 1;
2.70 + if (l4_is_invalid_cap(keypad_cap))
2.71 + return 1;
2.72
2.73 /* Obtain a reference to the keypad data. */
2.74
2.75 - l4_utcb_br()->bdr = 0;
2.76 - l4_utcb_br()->br[0] = L4_RCV_ITEM_SINGLE_CAP | mem;
2.77 + Keypad keypad = {.ref={.cap=keypad_cap}, .iface=&client_iface_Keypad};
2.78
2.79 - tag = l4_ipc_call(keypad_server, l4_utcb(),
2.80 - l4_msgtag(0, 0, 0, 0), /* label zero, zero words, zero *sent* items */
2.81 - L4_IPC_NEVER);
2.82 -
2.83 - if (l4_ipc_error(tag, l4_utcb())) return 1;
2.84 + if (keypad.iface->get_keypad_data(keypad.ref, &mem))
2.85 + return 1;
2.86
2.87 /* Attach the keypad data to a region in this task. */
2.88
2.89 - if (l4re_rm_attach(&keymem, l4re_ds_size(mem),
2.90 + if (l4re_rm_attach((void **) &keymem, l4re_ds_size(mem),
2.91 L4RE_RM_F_SEARCH_ADDR | L4RE_RM_F_R,
2.92 mem, 0,
2.93 L4_PAGESHIFT))
2.94 @@ -302,9 +292,8 @@
2.95
2.96 /* Show the keypad state. */
2.97
2.98 - keypad = (uint32_t *) keymem;
2.99 -
2.100 - while (1) show_keypad();
2.101 + while (1)
2.102 + show_keypad();
2.103
2.104 return 0;
2.105 }