Skip to content

Commit 1f8c199

Browse files
committed
[DM/FEATURE] Support input
For joystick, keyboard, button, touchscreen... event. Signed-off-by: GuEe-GUI <[email protected]>
1 parent d025072 commit 1f8c199

File tree

9 files changed

+1408
-0
lines changed

9 files changed

+1408
-0
lines changed

components/drivers/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rsource "touch/Kconfig"
2121
rsource "graphic/Kconfig"
2222
rsource "hwcrypto/Kconfig"
2323
rsource "wlan/Kconfig"
24+
rsource "input/Kconfig"
2425
rsource "mailbox/Kconfig"
2526
rsource "phye/Kconfig"
2627
rsource "ata/Kconfig"
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Copyright (c) 2006-2022, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2022-3-08 GuEe-GUI the first version
9+
*/
10+
11+
#ifndef __INPUT_H__
12+
#define __INPUT_H__
13+
14+
#include <rtthread.h>
15+
16+
#include <bitmap.h>
17+
#include <drivers/touch.h>
18+
#include <dt-bindings/input/event-codes.h>
19+
20+
struct rt_input_poller;
21+
struct rt_input_absinfo;
22+
23+
struct rt_input_event
24+
{
25+
rt_tick_t tick;
26+
27+
rt_uint16_t type;
28+
rt_uint16_t code;
29+
rt_int32_t value;
30+
};
31+
32+
struct rt_input_device
33+
{
34+
struct rt_device parent;
35+
36+
RT_BITMAP_DECLARE(cap, EV_CNT);
37+
RT_BITMAP_DECLARE(key_map, KEY_CNT);
38+
RT_BITMAP_DECLARE(rel_map, REL_CNT);
39+
RT_BITMAP_DECLARE(abs_map, ABS_CNT);
40+
41+
rt_list_t list;
42+
rt_list_t handler_nodes;
43+
struct rt_spinlock lock;
44+
45+
rt_err_t (*trigger)(struct rt_input_device *idev,
46+
rt_uint16_t type, rt_uint16_t code, rt_int32_t value);
47+
48+
struct rt_input_poller *poller;
49+
struct rt_input_absinfo *absinfo;
50+
#ifdef RT_INPUT_TOUCHSCREEN
51+
void *touch;
52+
#endif
53+
};
54+
55+
struct rt_input_handler
56+
{
57+
rt_list_t list;
58+
struct rt_input_device *idev;
59+
60+
rt_bool_t (*identify)(struct rt_input_handler *handler, struct rt_input_device *idev);
61+
rt_bool_t (*callback)(struct rt_input_handler *handler, struct rt_input_event *ev);
62+
63+
void *priv;
64+
};
65+
66+
struct rt_input_poller
67+
{
68+
#define RT_INPUT_POLL_INTERVAL_DEFAULT 17 /* 60fps */
69+
rt_uint32_t interval;
70+
struct rt_timer timer;
71+
72+
void (*poll)(struct rt_input_device *idev);
73+
};
74+
75+
struct rt_input_absinfo
76+
{
77+
rt_int32_t value;
78+
rt_int32_t minimum;
79+
rt_int32_t maximum;
80+
rt_int32_t fuzz;
81+
rt_int32_t flat;
82+
rt_int32_t resolution;
83+
};
84+
85+
rt_err_t rt_input_device_register(struct rt_input_device *idev);
86+
rt_err_t rt_input_device_unregister(struct rt_input_device *idev);
87+
88+
rt_err_t rt_input_set_capability(struct rt_input_device *idev,
89+
rt_uint16_t type, rt_uint16_t code);
90+
91+
rt_err_t rt_input_set_absinfo(struct rt_input_device *idev, rt_uint32_t axis,
92+
rt_int32_t min, rt_int32_t max, rt_int32_t fuzz, rt_int32_t flat);
93+
94+
rt_err_t rt_input_setup_touch(struct rt_input_device *idev,
95+
rt_uint32_t num_slots, struct rt_touch_info *info);
96+
rt_err_t rt_input_parse_touch_position(struct rt_input_device *idev,
97+
rt_uint32_t *out_x, rt_uint32_t *out_y);
98+
99+
rt_err_t rt_input_setup_polling(struct rt_input_device *idev,
100+
void (*work)(struct rt_input_device *idev));
101+
rt_err_t rt_input_set_poll_interval(struct rt_input_device *idev,
102+
rt_uint32_t interval_ms);
103+
104+
rt_err_t rt_input_trigger(struct rt_input_device *idev,
105+
rt_uint16_t type, rt_uint16_t code, rt_int32_t value);
106+
107+
void rt_input_event(struct rt_input_device *idev,
108+
rt_uint16_t type, rt_uint16_t code, rt_int32_t value);
109+
110+
rt_inline void rt_input_report_key(struct rt_input_device *idev,
111+
rt_uint16_t code, rt_int32_t value)
112+
{
113+
rt_input_event(idev, EV_KEY, code, !!value);
114+
}
115+
116+
rt_inline void rt_input_report_rel(struct rt_input_device *idev,
117+
rt_uint16_t code, rt_int32_t value)
118+
{
119+
rt_input_event(idev, EV_REL, code, value);
120+
}
121+
122+
rt_inline void rt_input_report_abs(struct rt_input_device *idev,
123+
rt_uint16_t code, rt_int32_t value)
124+
{
125+
rt_input_event(idev, EV_ABS, code, value);
126+
}
127+
128+
rt_inline void rt_input_report_touch_slot(struct rt_input_device *idev,
129+
rt_uint32_t slot)
130+
{
131+
rt_input_event(idev, EV_ABS, ABS_MT_SLOT, slot);
132+
}
133+
134+
rt_bool_t rt_input_report_touch_inactive(struct rt_input_device *idev,
135+
rt_bool_t active);
136+
137+
void rt_input_report_touch_position(struct rt_input_device *idev,
138+
rt_uint32_t x, rt_uint32_t y, rt_bool_t multitouch);
139+
140+
rt_inline void rt_input_sync(struct rt_input_device *idev)
141+
{
142+
rt_input_event(idev, EV_SYN, SYN_REPORT, 0);
143+
}
144+
145+
rt_err_t rt_input_add_handler(struct rt_input_handler *handler);
146+
rt_err_t rt_input_del_handler(struct rt_input_handler *handler);
147+
148+
#endif /* __INPUT_H__ */

0 commit comments

Comments
 (0)