Skip to content

Commit 04e0e45

Browse files
committed
input: convert gt911 from kscan
Convert the GT911 driver to the input subsystem, fix the existing boards to work in the default config. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent fd54a9a commit 04e0e45

File tree

12 files changed

+51
-96
lines changed

12 files changed

+51
-96
lines changed

boards/shields/rk055hdmipi4m/Kconfig.defconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ if LVGL
1919
config KSCAN
2020
default y
2121

22-
config KSCAN_GT911_INTERRUPT
22+
config INPUT
23+
default y if KSCAN
24+
25+
config INPUT_GT911_INTERRUPT
2326
default y
2427

2528
config LV_Z_POINTER_KSCAN

boards/shields/rk055hdmipi4m/rk055hdmipi4m.overlay

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
/{
1010
aliases {
11-
kscan0 = &touch_controller;
11+
kscan0 = &kscan_input_gt911;
1212
};
1313

1414
chosen {
1515
zephyr,display = &lcdif;
16-
zephyr,keyboard-scan = &touch_controller;
16+
zephyr,keyboard-scan = &kscan_input_gt911;
1717
};
1818

1919
en_mipi_display: enable-mipi-display {
@@ -31,6 +31,10 @@
3131
reg = <0x5d>;
3232
irq-gpios = <&nxp_mipi_connector 29 GPIO_ACTIVE_HIGH>;
3333
reset-gpios = <&nxp_mipi_connector 28 GPIO_ACTIVE_HIGH>;
34+
35+
kscan_input_gt911: kscan-input {
36+
compatible = "zephyr,kscan-input";
37+
};
3438
};
3539
};
3640

drivers/input/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ zephyr_library_property(ALLOW_EMPTY TRUE)
66
zephyr_library_sources_ifdef(CONFIG_INPUT_FT5336 input_ft5336.c)
77
zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_KEYS input_gpio_keys.c)
88
zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_QDEC input_gpio_qdec.c)
9+
zephyr_library_sources_ifdef(CONFIG_INPUT_GT911 input_gt911.c)
910
zephyr_library_sources_ifdef(CONFIG_INPUT_NPCX_KBD input_npcx_kbd.c)
1011
zephyr_library_sources_ifdef(CONFIG_INPUT_XPT2046 input_xpt2046.c)
1112

drivers/input/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ menu "Input drivers"
88
source "drivers/input/Kconfig.ft5336"
99
source "drivers/input/Kconfig.gpio_keys"
1010
source "drivers/input/Kconfig.gpio_qdec"
11+
source "drivers/input/Kconfig.gt911"
1112
source "drivers/input/Kconfig.npcx"
1213
source "drivers/input/Kconfig.sdl"
1314
source "drivers/input/Kconfig.xpt2046"

drivers/kscan/Kconfig.gt911 renamed to drivers/input/Kconfig.gt911

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
# Copyright (c) 2020 Teslabs Engineering S.L.
33
# SPDX-License-Identifier: Apache-2.0
44

5-
menuconfig KSCAN_GT911
5+
menuconfig INPUT_GT911
66
bool "GT9xx / GT9xxx capacitive touch panel driver"
77
default y
88
depends on DT_HAS_GOODIX_GT911_ENABLED
99
select I2C
1010
help
11-
Enable driver for multiple Goodix capacitive touch panel
12-
controllers. This driver should support gt9110, gt912,
13-
gt927, gt9271, gt928, gt967
11+
Enable driver for multiple Goodix capacitive touch panel controllers.
12+
This driver should support gt9110, gt912, gt927, gt9271, gt928,
13+
gt967.
1414

15-
if KSCAN_GT911
15+
if INPUT_GT911
1616

17-
config KSCAN_GT911_PERIOD
17+
config INPUT_GT911_PERIOD_MS
1818
int "Sample period"
19-
depends on !KSCAN_GT911_INTERRUPT
19+
depends on !INPUT_GT911_INTERRUPT
2020
default 10
2121
help
2222
Sample period in milliseconds when in polling mode.
2323

24-
config KSCAN_GT911_INTERRUPT
24+
config INPUT_GT911_INTERRUPT
2525
bool "Interrupt"
2626
help
2727
Enable interrupt support (requires GPIO).
2828

29-
endif # KSCAN_GT911
29+
endif # INPUT_GT911

drivers/kscan/kscan_gt911.c renamed to drivers/input/input_gt911.c

Lines changed: 22 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
#define DT_DRV_COMPAT goodix_gt911
1010

11-
#include <zephyr/drivers/kscan.h>
12-
#include <zephyr/drivers/i2c.h>
1311
#include <zephyr/drivers/gpio.h>
12+
#include <zephyr/drivers/i2c.h>
13+
#include <zephyr/input/input.h>
1414
#include <zephyr/sys/byteorder.h>
1515

1616
#include <zephyr/logging/log.h>
17-
LOG_MODULE_REGISTER(gt911, CONFIG_KSCAN_LOG_LEVEL);
17+
LOG_MODULE_REGISTER(gt911, CONFIG_INPUT_LOG_LEVEL);
1818

1919
/* GT911 used registers */
2020
#define DEVICE_ID __bswap_16(0x8140U)
@@ -45,11 +45,9 @@ struct gt911_config {
4545
struct gt911_data {
4646
/** Device pointer. */
4747
const struct device *dev;
48-
/** KSCAN Callback. */
49-
kscan_callback_t callback;
5048
/** Work queue (for deferred read). */
5149
struct k_work work;
52-
#ifdef CONFIG_KSCAN_GT911_INTERRUPT
50+
#ifdef CONFIG_INPUT_GT911_INTERRUPT
5351
/** Interrupt GPIO callback. */
5452
struct gpio_callback int_gpio_cb;
5553
#else
@@ -73,7 +71,6 @@ struct gt911_point_reg_t {
7371
static int gt911_process(const struct device *dev)
7472
{
7573
const struct gt911_config *config = dev->config;
76-
struct gt911_data *data = dev->data;
7774

7875
int r;
7976
uint16_t reg_addr;
@@ -124,7 +121,13 @@ static int gt911_process(const struct device *dev)
124121

125122
LOG_DBG("pressed: %d, row: %d, col: %d", pressed, row, col);
126123

127-
data->callback(dev, row, col, pressed);
124+
if (pressed) {
125+
input_report_abs(dev, INPUT_ABS_X, col, false, K_FOREVER);
126+
input_report_abs(dev, INPUT_ABS_Y, row, false, K_FOREVER);
127+
input_report_key(dev, INPUT_BTN_TOUCH, 1, true, K_FOREVER);
128+
} else {
129+
input_report_key(dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER);
130+
}
128131

129132
return 0;
130133
}
@@ -136,7 +139,7 @@ static void gt911_work_handler(struct k_work *work)
136139
gt911_process(data->dev);
137140
}
138141

139-
#ifdef CONFIG_KSCAN_GT911_INTERRUPT
142+
#ifdef CONFIG_INPUT_GT911_INTERRUPT
140143
static void gt911_isr_handler(const struct device *dev,
141144
struct gpio_callback *cb, uint32_t pins)
142145
{
@@ -153,52 +156,6 @@ static void gt911_timer_handler(struct k_timer *timer)
153156
}
154157
#endif
155158

156-
static int gt911_configure(const struct device *dev,
157-
kscan_callback_t callback)
158-
{
159-
struct gt911_data *data = dev->data;
160-
161-
if (!callback) {
162-
LOG_ERR("Invalid callback (NULL)");
163-
return -EINVAL;
164-
}
165-
166-
data->callback = callback;
167-
168-
return 0;
169-
}
170-
171-
static int gt911_enable_callback(const struct device *dev)
172-
{
173-
struct gt911_data *data = dev->data;
174-
175-
#ifdef CONFIG_KSCAN_GT911_INTERRUPT
176-
const struct gt911_config *config = dev->config;
177-
178-
gpio_add_callback(config->int_gpio.port, &data->int_gpio_cb);
179-
#else
180-
k_timer_start(&data->timer, K_MSEC(CONFIG_KSCAN_GT911_PERIOD),
181-
K_MSEC(CONFIG_KSCAN_GT911_PERIOD));
182-
#endif
183-
184-
return 0;
185-
}
186-
187-
static int gt911_disable_callback(const struct device *dev)
188-
{
189-
struct gt911_data *data = dev->data;
190-
191-
#ifdef CONFIG_KSCAN_GT911_INTERRUPT
192-
const struct gt911_config *config = dev->config;
193-
194-
gpio_remove_callback(config->int_gpio.port, &data->int_gpio_cb);
195-
#else
196-
k_timer_stop(&data->timer);
197-
#endif
198-
199-
return 0;
200-
}
201-
202159
static uint8_t gt911_get_firmware_checksum(const uint8_t *firmware)
203160
{
204161
uint8_t sum = 0;
@@ -269,7 +226,7 @@ static int gt911_init(const struct device *dev)
269226
return r;
270227
}
271228

272-
#ifdef CONFIG_KSCAN_GT911_INTERRUPT
229+
#ifdef CONFIG_INPUT_GT911_INTERRUPT
273230
r = gpio_pin_interrupt_configure_dt(&config->int_gpio,
274231
GPIO_INT_EDGE_TO_ACTIVE);
275232
if (r < 0) {
@@ -320,15 +277,16 @@ static int gt911_init(const struct device *dev)
320277
return r;
321278
}
322279

280+
#ifdef CONFIG_INPUT_GT911_INTERRUPT
281+
gpio_add_callback(config->int_gpio.port, &data->int_gpio_cb);
282+
#else
283+
k_timer_start(&data->timer, K_MSEC(CONFIG_INPUT_GT911_PERIOD_MS),
284+
K_MSEC(CONFIG_INPUT_GT911_PERIOD_MS));
285+
#endif
286+
323287
return 0;
324288
}
325289

326-
static const struct kscan_driver_api gt911_driver_api = {
327-
.config = gt911_configure,
328-
.enable_callback = gt911_enable_callback,
329-
.disable_callback = gt911_disable_callback,
330-
};
331-
332290
#define GT911_INIT(index) \
333291
static const struct gt911_config gt911_config_##index = { \
334292
.bus = I2C_DT_SPEC_INST_GET(index), \
@@ -338,7 +296,7 @@ static const struct kscan_driver_api gt911_driver_api = {
338296
static struct gt911_data gt911_data_##index; \
339297
DEVICE_DT_INST_DEFINE(index, gt911_init, NULL, \
340298
&gt911_data_##index, &gt911_config_##index, \
341-
POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \
342-
&gt911_driver_api);
299+
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \
300+
NULL);
343301

344302
DT_INST_FOREACH_STATUS_OKAY(GT911_INIT)

drivers/kscan/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/drivers/kscan.h)
44

55
zephyr_library()
66

7-
zephyr_library_sources_ifdef(CONFIG_KSCAN_GT911 kscan_gt911.c)
87
zephyr_library_sources_ifdef(CONFIG_KSCAN_ITE_IT8XXX2 kscan_ite_it8xxx2.c)
98
zephyr_library_sources_ifdef(CONFIG_KSCAN_XEC kscan_mchp_xec.c)
109
zephyr_library_sources_ifdef(CONFIG_KSCAN_HT16K33 kscan_ht16k33.c)

drivers/kscan/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ menuconfig KSCAN
1010

1111
if KSCAN
1212

13-
source "drivers/kscan/Kconfig.gt911"
1413
source "drivers/kscan/Kconfig.it8xxx2"
1514
source "drivers/kscan/Kconfig.xec"
1615
source "drivers/kscan/Kconfig.ht16k33"

dts/bindings/kscan/goodix,gt911.yaml renamed to dts/bindings/input/goodix,gt911.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: GT9xx / GT9xxx capacitive touch panels
55

66
compatible: "goodix,gt911"
77

8-
include: [kscan.yaml, i2c-device.yaml]
8+
include: i2c-device.yaml
99

1010
properties:
1111
irq-gpios:

samples/drivers/kscan/sample.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,3 @@ tests:
1414
fixture: fixture_connect_keyboard
1515
depends_on: kscan
1616
filter: dt_chosen_enabled("zephyr,keyboard-scan")
17-
sample.drivers.kscan.rk055hdmipi4m:
18-
tags: drivers kscan
19-
harness: console
20-
harness_config:
21-
type: multi_line
22-
ordered: true
23-
regex:
24-
- "kb data(.*)"
25-
fixture: fixture_connect_rk055hdmipi4m
26-
depends_on: kscan
27-
extra_args: SHIELD="rk055hdmipi4m"
28-
platform_allow: mimxrt1170_evk_cm7 mimxrt595_evk_cm33

0 commit comments

Comments
 (0)