Browse Source

Adding Linux event input touch driver

Joel Bodenmann 2 years ago
parent
commit
ac5e96cca1

+ 7 - 0
boards/base/Linux-Framebuffer-Touch/board.mk

@@ -0,0 +1,7 @@
1
+GFXINC  += $(GFXLIB)/boards/base/Linux-Framebuffer-Touch
2
+GFXSRC  +=
3
+GFXDEFS += -DGFX_USE_OS_LINUX=TRUE
4
+GFXLIBS += rt
5
+
6
+include $(GFXLIB)/boards/base/Linux-Framebuffer/board.mk
7
+include $(GFXLIB)/drivers/ginput/touch/Linux-Event/driver.mk

+ 32 - 0
boards/base/Linux-Framebuffer-Touch/gmouse_lld_linux_event_board.h

@@ -0,0 +1,32 @@
1
+/*
2
+ * This file is subject to the terms of the GFX License. If a copy of
3
+ * the license was not distributed with this file, you can obtain one at:
4
+ *
5
+ *              http://ugfx.org/license.html
6
+ */
7
+
8
+#ifndef _GINPUT_LLD_MOUSE_BOARD_H
9
+#define _GINPUT_LLD_MOUSE_BOARD_H
10
+
11
+// Resolution and Accuracy Settings
12
+#define GMOUSE_LINUX_EVENT_PEN_CALIBRATE_ERROR		8
13
+#define GMOUSE_LINUX_EVENT_PEN_CLICK_ERROR			6
14
+#define GMOUSE_LINUX_EVENT_PEN_MOVE_ERROR			4
15
+#define GMOUSE_LINUX_EVENT_FINGER_CALIBRATE_ERROR	14
16
+#define GMOUSE_LINUX_EVENT_FINGER_CLICK_ERROR		18
17
+#define GMOUSE_LINUX_EVENT_FINGER_MOVE_ERROR		14
18
+
19
+#define GMOUSE_LINUX_EVENT_NUM_EVENT				64
20
+
21
+// The linux device input used for touchscreen
22
+#define GMOUSE_LINUX_EVENT_DEVICE					"/dev/input/event0"
23
+
24
+// Set this to TRUE if you want self-calibration.
25
+//	NOTE:	This is not as accurate as real calibration.
26
+//			It requires the orientation of the touch panel to match the display.
27
+//			It requires the active area of the touch panel to exactly match the display size.
28
+#define GMOUSE_LINUX_EVENT_SELF_CALIBRATE			FALSE
29
+
30
+#define GMOUSE_LINUX_EVENT_FINGERMODE				TRUE
31
+
32
+#endif /* _GINPUT_LLD_MOUSE_BOARD_H */

+ 1 - 0
docs/releases.txt

@@ -11,6 +11,7 @@ FIX:		Fixed potential crash when GDISP_NEED_TEXT_WORDWRAP is turned on
11 11
 FEATURE:	Added SDL driver
12 12
 FEATURE:	Added ILI9225 driver
13 13
 FEATURE:	Added ST7735 driver
14
+FEATURE:	Added Linux event input driver
14 15
 
15 16
 
16 17
 *** Release 2.6 ***

+ 1 - 0
drivers/ginput/touch/Linux-Event/driver.mk

@@ -0,0 +1 @@
1
+GFXSRC += $(GFXLIB)/drivers/ginput/touch/Linux-Event/gmouse_lld_linux_event.c

+ 142 - 0
drivers/ginput/touch/Linux-Event/gmouse_lld_linux_event.c

@@ -0,0 +1,142 @@
1
+/*
2
+ * This file is subject to the terms of the GFX License. If a copy of
3
+ * the license was not distributed with this file, you can obtain one at:
4
+ *
5
+ *              http://ugfx.org/license.html
6
+ */
7
+
8
+#include "gfx.h"
9
+
10
+#include <linux/input.h>
11
+
12
+#include <fcntl.h>
13
+#include <unistd.h>
14
+#include <stdio.h>
15
+
16
+#if GFX_USE_GINPUT && GINPUT_NEED_MOUSE
17
+
18
+#define GMOUSE_DRIVER_VMT GMOUSEVMT_LINUX_EVENT
19
+#include "src/ginput/ginput_driver_mouse.h"
20
+
21
+// Include the board file
22
+#include "gmouse_lld_linux_event_board.h"
23
+
24
+// Private area definition
25
+// We need to store the last reading ourselves because we only get events
26
+// from the Linux system. When touching the touchscreen and then moving around,
27
+// we only get one z = 1 event. However, the GINPUT module expects z = 1 to be
28
+// true for the entire touch duration.
29
+typedef struct privStruct {
30
+	int fd;
31
+	GMouseReading lastReading;
32
+} privStruct;
33
+
34
+static bool_t _init(GMouse* m, unsigned driverInstance)
35
+{
36
+	(void)driverInstance;
37
+
38
+	// Retrive the private area struct
39
+    privStruct* priv = (privStruct*)(m+1);
40
+
41
+	// Open the device
42
+	priv->fd = open(GMOUSE_LINUX_EVENT_DEVICE, O_RDONLY | O_NONBLOCK);
43
+	if (priv->fd < 0) {
44
+		fprintf(stderr, "GINPUT Mouse: Cannot open input device (%s)\n", GMOUSE_LINUX_EVENT_DEVICE);
45
+		return FALSE;
46
+	}
47
+
48
+	// Initialize
49
+	priv->lastReading.buttons = 0;
50
+	priv->lastReading.x = 0;
51
+	priv->lastReading.y = 0;
52
+	priv->lastReading.z = 0;
53
+
54
+	return TRUE;
55
+}
56
+
57
+static bool_t _read(GMouse* m, GMouseReading* pdr)
58
+{
59
+	int i;
60
+	int rb;
61
+	struct input_event ev[64];
62
+	privStruct* priv;
63
+
64
+	// Retrive the private area struct
65
+    priv = (privStruct*)(m+1);
66
+
67
+	// Assume not touched
68
+	pdr->buttons = 0;
69
+	pdr->z = priv->lastReading.z;
70
+	pdr->x = priv->lastReading.x;
71
+	pdr->y = priv->lastReading.y;
72
+
73
+	// Read
74
+	rb = read(priv->fd, ev, sizeof(struct input_event)*64);
75
+
76
+	// Parse	
77
+	if (rb > 0) {
78
+		for (i = 0;  i < (int)(rb / sizeof(struct input_event)); i++) {
79
+			if (ev[i].type == EV_KEY && ev[i].code == 330 && ev[i].value == 1) {
80
+				pdr->z = 1;
81
+			}
82
+			else if (ev[i].type == EV_KEY && ev[i].code == 330 && ev[i].value == 0) {
83
+				pdr->z = 0;
84
+			}
85
+			else if (ev[i].type == EV_ABS && ev[i].code == 0 && ev[i].value > 0) {
86
+				pdr->x = ev[i].value;
87
+			}
88
+			else if (ev[i].type == EV_ABS  && ev[i].code == 1 && ev[i].value > 0) {
89
+				pdr->y = ev[i].value;
90
+			}
91
+		}
92
+	}
93
+
94
+	// Store the current reading
95
+	priv->lastReading.x = pdr->x;
96
+	priv->lastReading.y = pdr->y;
97
+	priv->lastReading.z = pdr->z;
98
+	priv->lastReading.buttons = pdr->buttons;
99
+	
100
+	return TRUE;
101
+}
102
+
103
+const GMouseVMT const GMOUSE_DRIVER_VMT[1] = {{
104
+	{
105
+		GDRIVER_TYPE_TOUCH,
106
+		#if GMOUSE_LINUX_EVENT_FINGERMODE
107
+			GMOUSE_VFLG_DEFAULTFINGER |
108
+		#endif
109
+		
110
+		#if GMOUSE_LINUX_EVENT_SELF_CALIBRATE
111
+			GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN , 
112
+		#else
113
+			GMOUSE_VFLG_TOUCH | GMOUSE_VFLG_ONLY_DOWN | GMOUSE_VFLG_POORUPDOWN |GMOUSE_VFLG_CALIBRATE,
114
+		#endif
115
+		sizeof(GMouse) + sizeof(privStruct),
116
+		_gmouseInitDriver,
117
+		_gmousePostInitDriver,
118
+		_gmouseDeInitDriver
119
+	},
120
+	1,				// z_max - (currently?) not supported
121
+	0,				// z_min - (currently?) not supported
122
+	1,				// z_touchon
123
+	0,				// z_touchoff
124
+	{				// pen_jitter
125
+		0,			// calibrate
126
+		0,			// click
127
+		0			// move
128
+	},
129
+	{				// finger_jitter
130
+		0,			// calibrate
131
+		0,			// click
132
+		0			// move
133
+	},
134
+	_init, 			// init
135
+	0,				// deinit
136
+	_read,			// get
137
+	0,				// calsave
138
+	0				// calload
139
+}};
140
+
141
+#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
142
+

+ 32 - 0
drivers/ginput/touch/Linux-Event/gmouse_lld_linux_event_board_template.h

@@ -0,0 +1,32 @@
1
+/*
2
+ * This file is subject to the terms of the GFX License. If a copy of
3
+ * the license was not distributed with this file, you can obtain one at:
4
+ *
5
+ *              http://ugfx.org/license.html
6
+ */
7
+
8
+#ifndef _GINPUT_LLD_MOUSE_BOARD_H
9
+#define _GINPUT_LLD_MOUSE_BOARD_H
10
+
11
+// Resolution and Accuracy Settings
12
+#define GMOUSE_LINUX_EVENT_PEN_CALIBRATE_ERROR		8
13
+#define GMOUSE_LINUX_EVENT_PEN_CLICK_ERROR			6
14
+#define GMOUSE_LINUX_EVENT_PEN_MOVE_ERROR			4
15
+#define GMOUSE_LINUX_EVENT_FINGER_CALIBRATE_ERROR	14
16
+#define GMOUSE_LINUX_EVENT_FINGER_CLICK_ERROR		18
17
+#define GMOUSE_LINUX_EVENT_FINGER_MOVE_ERROR		14
18
+
19
+#define GMOUSE_LINUX_EVENT_NUM_EVENT				64
20
+
21
+// The linux device input used for touchscreen
22
+#define GMOUSE_LINUX_EVENT_DEVICE					"/dev/input/event0"
23
+
24
+// Set this to TRUE if you want self-calibration.
25
+//	NOTE:	This is not as accurate as real calibration.
26
+//			It requires the orientation of the touch panel to match the display.
27
+//			It requires the active area of the touch panel to exactly match the display size.
28
+#define GMOUSE_LINUX_EVENT_SELF_CALIBRATE			FALSE
29
+
30
+#define GMOUSE_LINUX_EVENT_FINGERMODE				TRUE
31
+
32
+#endif /* _GINPUT_LLD_MOUSE_BOARD_H */