adjust exec_param to keep track of sp_el0, fix incorrect use sys regs
[lunaix-os.git] / lunaix-os / includes / lunaix / input.h
1 #ifndef __LUNAIX_INPUT_H
2 #define __LUNAIX_INPUT_H
3
4 #include <lunaix/clock.h>
5 #include <lunaix/device.h>
6 #include <lunaix/ds/ldga.h>
7 #include <lunaix/ds/llist.h>
8 #include <lunaix/ds/waitq.h>
9 #include <lunaix/types.h>
10
11 // event should propagate further
12 #define INPUT_EVT_NEXT 0
13 // event should be captured here
14 #define INPUT_EVT_CATCH 1
15
16 // key pressed (key-type device)
17 #define PKT_PRESS 0x1
18 // key released (key-type device)
19 #define PKT_RELEASE 0x2
20 // vector (e.g. mice wheel scroll, mice maneuver)
21 #define PKT_VECTOR 0x3
22
23 #define EXPORT_INPUT_DEV(id, init_fn)                                          \
24     export_ldga_el(inputdev, id, ptr_t, init_fn)
25
26 struct input_evt_pkt
27 {
28     u32_t pkt_type;   // packet type
29     u32_t scan_code;  // hardware raw code
30     u32_t sys_code;   // driver translated code
31     time_t timestamp; // event timestamp
32 };
33
34 struct input_device
35 {
36     struct device* dev_if;            // device interface
37     struct input_evt_pkt current_pkt; // recieved event packet
38     waitq_t readers;                  // reader wait queue
39 };
40
41 typedef int (*input_evt_cb)(struct input_device* dev);
42
43 struct input_evt_chain
44 {
45     struct llist_header chain;
46     input_evt_cb evt_cb;
47 };
48
49 void
50 input_init();
51
52 void
53 input_fire_event(struct input_device* idev, struct input_evt_pkt* pkt);
54
55 void
56 input_add_listener(input_evt_cb listener);
57
58 struct input_device*
59 input_add_device(struct devclass* class, char* name_fmt, ...);
60
61 #endif /* __LUNAIX_INPUT_H */