Skip to content

Commit 1d56b8e

Browse files
faxe1008carlescufi
authored andcommitted
input: convert cap1203 from kscan
Convert the CAP1203 driver to the input subsystem, add to build_all tests. Signed-off-by: Fabian Blatz <[email protected]>
1 parent 305423c commit 1d56b8e

File tree

8 files changed

+51
-88
lines changed

8 files changed

+51
-88
lines changed

drivers/input/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
zephyr_library()
44
zephyr_library_property(ALLOW_EMPTY TRUE)
55

6+
zephyr_library_sources_ifdef(CONFIG_INPUT_CAP1203 input_cap1203.c)
67
zephyr_library_sources_ifdef(CONFIG_INPUT_CST816S input_cst816s.c)
78
zephyr_library_sources_ifdef(CONFIG_INPUT_FT5336 input_ft5336.c)
89
zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_KEYS input_gpio_keys.c)

drivers/input/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ if INPUT
55

66
menu "Input drivers"
77

8+
source "drivers/input/Kconfig.cap1203"
89
source "drivers/input/Kconfig.cst816s"
910
source "drivers/input/Kconfig.ft5336"
1011
source "drivers/input/Kconfig.gpio_keys"
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) 2022 Keiya Nobuta
22
# SPDX-License-Identifier: Apache-2.0
33

4-
menuconfig KSCAN_CAP1203
4+
menuconfig INPUT_CAP1203
55
bool "CAP1203 3-cannel capacitive touch sensor driver"
66
default y
77
depends on DT_HAS_MICROCHIP_CAP1203_ENABLED
@@ -10,18 +10,18 @@ menuconfig KSCAN_CAP1203
1010
Enable driver for microchip CAP1203 3-cannel capacitive
1111
touch sensor.
1212

13-
if KSCAN_CAP1203
13+
if INPUT_CAP1203
1414

15-
config KSCAN_CAP1203_POLL
15+
config INPUT_CAP1203_POLL
1616
bool "Polling"
1717
help
1818
Enable polling mode when interrupt GPIO is not specified.
1919

20-
config KSCAN_CAP1203_PERIOD
20+
config INPUT_CAP1203_PERIOD
2121
int "Sample period"
22-
depends on KSCAN_CAP1203_POLL
22+
depends on INPUT_CAP1203_POLL
2323
default 10
2424
help
2525
Sample period in milliseconds when in polling mode.
2626

27-
endif # KSCAN_CAP1203
27+
endif # INPUT_CAP1203

drivers/kscan/kscan_cap1203.c renamed to drivers/input/input_cap1203.c

Lines changed: 36 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
#define DT_DRV_COMPAT microchip_cap1203
88

9-
#include <zephyr/drivers/kscan.h>
109
#include <zephyr/drivers/i2c.h>
1110
#include <zephyr/drivers/gpio.h>
11+
#include <zephyr/input/input.h>
1212

1313
#include <zephyr/logging/log.h>
14-
LOG_MODULE_REGISTER(cap1203, CONFIG_KSCAN_LOG_LEVEL);
14+
LOG_MODULE_REGISTER(cap1203, CONFIG_INPUT_LOG_LEVEL);
1515

1616
#define REG_MAIN_CONTROL 0x0
1717
#define CONTROL_INT 0x1
@@ -28,12 +28,11 @@ struct cap1203_config {
2828
};
2929

3030
struct cap1203_data {
31-
struct device *dev;
32-
kscan_callback_t callback;
31+
const struct device *dev;
3332
struct k_work work;
3433
/* Interrupt GPIO callback. */
3534
struct gpio_callback int_gpio_cb;
36-
#ifdef CONFIG_KSCAN_CAP1203_POLL
35+
#ifdef CONFIG_INPUT_CAP1203_POLL
3736
/* Timer (polling mode). */
3837
struct k_timer timer;
3938
#endif
@@ -96,7 +95,13 @@ static int cap1203_process(const struct device *dev)
9695
return r;
9796
}
9897

99-
data->callback(dev, 0, col, pressed);
98+
if (pressed) {
99+
input_report_abs(dev, INPUT_ABS_X, col, false, K_FOREVER);
100+
input_report_abs(dev, INPUT_ABS_Y, 0, false, K_FOREVER);
101+
input_report_key(dev, INPUT_BTN_TOUCH, 1, true, K_FOREVER);
102+
} else {
103+
input_report_key(dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER);
104+
}
100105

101106
return 0;
102107
}
@@ -116,7 +121,7 @@ static void cap1203_isr_handler(const struct device *dev,
116121
k_work_submit(&data->work);
117122
}
118123

119-
#ifdef CONFIG_KSCAN_CAP1203_POLL
124+
#ifdef CONFIG_INPUT_CAP1203_POLL
120125
static void cap1203_timer_handler(struct k_timer *timer)
121126
{
122127
struct cap1203_data *data = CONTAINER_OF(timer, struct cap1203_data, timer);
@@ -125,69 +130,6 @@ static void cap1203_timer_handler(struct k_timer *timer)
125130
}
126131
#endif
127132

128-
static int cap1203_configure(const struct device *dev,
129-
kscan_callback_t callback)
130-
{
131-
struct cap1203_data *data = dev->data;
132-
const struct cap1203_config *config = dev->config;
133-
134-
data->callback = callback;
135-
136-
if (config->int_gpio.port != NULL) {
137-
int r;
138-
139-
/* Clear pending interrupt */
140-
r = cap1203_clear_interrupt(&config->i2c);
141-
if (r < 0) {
142-
LOG_ERR("Could not clear interrupt");
143-
return r;
144-
}
145-
146-
r = cap1203_enable_interrupt(&config->i2c, true);
147-
if (r < 0) {
148-
LOG_ERR("Could not configure interrupt");
149-
return r;
150-
}
151-
}
152-
153-
return 0;
154-
}
155-
156-
static int cap1203_enable_callback(const struct device *dev)
157-
{
158-
struct cap1203_data *data = dev->data;
159-
160-
const struct cap1203_config *config = dev->config;
161-
162-
if (config->int_gpio.port != NULL) {
163-
gpio_add_callback(config->int_gpio.port, &data->int_gpio_cb);
164-
}
165-
#ifdef CONFIG_KSCAN_CAP1203_POLL
166-
else {
167-
k_timer_start(&data->timer, K_MSEC(CONFIG_KSCAN_CAP1203_PERIOD),
168-
K_MSEC(CONFIG_KSCAN_CAP1203_PERIOD));
169-
}
170-
#endif
171-
return 0;
172-
}
173-
174-
static int cap1203_disable_callback(const struct device *dev)
175-
{
176-
struct cap1203_data *data = dev->data;
177-
178-
const struct cap1203_config *config = dev->config;
179-
180-
if (config->int_gpio.port != NULL) {
181-
gpio_remove_callback(config->int_gpio.port, &data->int_gpio_cb);
182-
}
183-
#ifdef CONFIG_KSCAN_CAP1203_POLL
184-
else {
185-
k_timer_stop(&data->timer);
186-
}
187-
#endif
188-
return 0;
189-
}
190-
191133
static int cap1203_init(const struct device *dev)
192134
{
193135
const struct cap1203_config *config = dev->config;
@@ -224,8 +166,26 @@ static int cap1203_init(const struct device *dev)
224166

225167
gpio_init_callback(&data->int_gpio_cb, cap1203_isr_handler,
226168
BIT(config->int_gpio.pin));
169+
170+
r = gpio_add_callback(config->int_gpio.port, &data->int_gpio_cb);
171+
if (r < 0) {
172+
LOG_ERR("Could not set gpio callback");
173+
return r;
174+
}
175+
176+
r = cap1203_clear_interrupt(&config->i2c);
177+
if (r < 0) {
178+
LOG_ERR("Could not clear interrupt");
179+
return r;
180+
}
181+
182+
r = cap1203_enable_interrupt(&config->i2c, true);
183+
if (r < 0) {
184+
LOG_ERR("Could not configure interrupt");
185+
return r;
186+
}
227187
}
228-
#ifdef CONFIG_KSCAN_CAP1203_POLL
188+
#ifdef CONFIG_INPUT_CAP1203_POLL
229189
else {
230190
k_timer_init(&data->timer, cap1203_timer_handler, NULL);
231191

@@ -234,18 +194,15 @@ static int cap1203_init(const struct device *dev)
234194
LOG_ERR("Could not configure interrupt");
235195
return r;
236196
}
197+
198+
k_timer_start(&data->timer, K_MSEC(CONFIG_INPUT_CAP1203_PERIOD),
199+
K_MSEC(CONFIG_INPUT_CAP1203_PERIOD));
237200
}
238201
#endif
239202

240203
return 0;
241204
}
242205

243-
static const struct kscan_driver_api cap1203_driver_api = {
244-
.config = cap1203_configure,
245-
.enable_callback = cap1203_enable_callback,
246-
.disable_callback = cap1203_disable_callback,
247-
};
248-
249206
#define CAP1203_INIT(index) \
250207
static const struct cap1203_config cap1203_config_##index = { \
251208
.i2c = I2C_DT_SPEC_INST_GET(index), \
@@ -254,7 +211,7 @@ static const struct kscan_driver_api cap1203_driver_api = {
254211
static struct cap1203_data cap1203_data_##index; \
255212
DEVICE_DT_INST_DEFINE(index, cap1203_init, NULL, \
256213
&cap1203_data_##index, &cap1203_config_##index, \
257-
POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, \
258-
&cap1203_driver_api);
214+
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \
215+
NULL);
259216

260217
DT_INST_FOREACH_STATUS_OKAY(CAP1203_INIT)

drivers/kscan/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ zephyr_library()
77
zephyr_library_sources_ifdef(CONFIG_KSCAN_ITE_IT8XXX2 kscan_ite_it8xxx2.c)
88
zephyr_library_sources_ifdef(CONFIG_KSCAN_XEC kscan_mchp_xec.c)
99
zephyr_library_sources_ifdef(CONFIG_KSCAN_HT16K33 kscan_ht16k33.c)
10-
zephyr_library_sources_ifdef(CONFIG_KSCAN_CAP1203 kscan_cap1203.c)
1110
zephyr_library_sources_ifdef(CONFIG_KSCAN_INPUT kscan_input.c)
1211

1312
zephyr_library_sources_ifdef(CONFIG_USERSPACE kscan_handlers.c)

drivers/kscan/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ if KSCAN
1313
source "drivers/kscan/Kconfig.it8xxx2"
1414
source "drivers/kscan/Kconfig.xec"
1515
source "drivers/kscan/Kconfig.ht16k33"
16-
source "drivers/kscan/Kconfig.cap1203"
1716
source "drivers/kscan/Kconfig.input"
1817

1918
module = KSCAN

dts/bindings/kscan/microchip,cap1203.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: CAP1203 3-channel capacitive touch sensor
55

66
compatible: "microchip,cap1203"
77

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

1010
properties:
1111
int-gpios:

tests/drivers/build_all/input/app.overlay

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
irq-gpios = <&gpio0 0 0>;
7272
rst-gpios = <&gpio0 0 0>;
7373
};
74+
75+
cap1203@3 {
76+
compatible = "microchip,cap1203";
77+
reg = <0x3>;
78+
int-gpios = <&gpio0 0 0>;
79+
};
7480
};
7581

7682
spi@2 {

0 commit comments

Comments
 (0)