Skip to content

Commit e1e4fcc

Browse files
faxe1008carlescufi
authored andcommitted
input: remove cap1203 kscan-like state report
Previously the driver was retrofitted to the kscan api, handling it as a input device with one row and three columns. With the move to the input subsystem each input can have its proper input code instead. Signed-off-by: Fabian Blatz <[email protected]>
1 parent 1d56b8e commit e1e4fcc

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

drivers/input/input_cap1203.c

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,23 @@ LOG_MODULE_REGISTER(cap1203, CONFIG_INPUT_LOG_LEVEL);
1919
#define REG_INPUT_STATUS 0x03
2020

2121
#define REG_INTERRUPT_ENABLE 0x27
22-
#define INTERRUPT_ENABLE 0x7
23-
#define INTERRUPT_DISABLE 0x0
22+
#define INTERRUPT_ENABLE 0x7
23+
#define INTERRUPT_DISABLE 0x0
24+
25+
#define TOUCH_INPUT_COUNT 3
2426

2527
struct cap1203_config {
2628
struct i2c_dt_spec i2c;
2729
struct gpio_dt_spec int_gpio;
30+
const uint16_t *input_codes;
2831
};
2932

3033
struct cap1203_data {
3134
const struct device *dev;
3235
struct k_work work;
3336
/* Interrupt GPIO callback. */
3437
struct gpio_callback int_gpio_cb;
38+
uint8_t prev_input_state;
3539
#ifdef CONFIG_INPUT_CAP1203_POLL
3640
/* Timer (polling mode). */
3741
struct k_timer timer;
@@ -65,24 +69,21 @@ static int cap1203_process(const struct device *dev)
6569
struct cap1203_data *data = dev->data;
6670
int r;
6771
uint8_t input;
68-
uint16_t col;
69-
bool pressed;
72+
uint8_t single_input_state;
7073

7174
r = i2c_reg_read_byte_dt(&config->i2c, REG_INPUT_STATUS, &input);
7275
if (r < 0) {
7376
return r;
7477
}
7578

76-
pressed = !!input;
77-
if (input & BIT(0)) {
78-
col = 0;
79-
}
80-
if (input & BIT(1)) {
81-
col = 1;
82-
}
83-
if (input & BIT(2)) {
84-
col = 2;
79+
for (uint8_t i = 0; i < TOUCH_INPUT_COUNT; i++) {
80+
single_input_state = input & BIT(i);
81+
if (single_input_state != (data->prev_input_state & BIT(i))) {
82+
input_report_key(dev, config->input_codes[i], single_input_state, true,
83+
K_FOREVER);
84+
}
8585
}
86+
data->prev_input_state = input;
8687

8788
LOG_DBG("event: input: %d\n", input);
8889

@@ -95,14 +96,6 @@ static int cap1203_process(const struct device *dev)
9596
return r;
9697
}
9798

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-
}
105-
10699
return 0;
107100
}
108101

@@ -203,15 +196,17 @@ static int cap1203_init(const struct device *dev)
203196
return 0;
204197
}
205198

206-
#define CAP1203_INIT(index) \
207-
static const struct cap1203_config cap1203_config_##index = { \
208-
.i2c = I2C_DT_SPEC_INST_GET(index), \
209-
.int_gpio = GPIO_DT_SPEC_INST_GET_OR(index, int_gpios, {0}), \
210-
}; \
211-
static struct cap1203_data cap1203_data_##index; \
212-
DEVICE_DT_INST_DEFINE(index, cap1203_init, NULL, \
213-
&cap1203_data_##index, &cap1203_config_##index, \
214-
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \
199+
#define CAP1203_INIT(index) \
200+
static const uint16_t cap1203_input_codes_##inst[] = DT_INST_PROP(index, input_codes); \
201+
BUILD_ASSERT(DT_INST_PROP_LEN(index, input_codes) == TOUCH_INPUT_COUNT); \
202+
static const struct cap1203_config cap1203_config_##index = { \
203+
.i2c = I2C_DT_SPEC_INST_GET(index), \
204+
.int_gpio = GPIO_DT_SPEC_INST_GET_OR(index, int_gpios, {0}), \
205+
.input_codes = cap1203_input_codes_##inst, \
206+
}; \
207+
static struct cap1203_data cap1203_data_##index; \
208+
DEVICE_DT_INST_DEFINE(index, cap1203_init, NULL, &cap1203_data_##index, \
209+
&cap1203_config_##index, POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \
215210
NULL);
216211

217212
DT_INST_FOREACH_STATUS_OKAY(CAP1203_INIT)

dts/bindings/kscan/microchip,cap1203.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ include: i2c-device.yaml
1010
properties:
1111
int-gpios:
1212
type: phandle-array
13+
14+
input-codes:
15+
type: array
16+
required: true
17+
description: |
18+
Array of input event key codes (INPUT_KEY_* or INPUT_BTN_*).

tests/drivers/build_all/input/app.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
compatible = "microchip,cap1203";
7777
reg = <0x3>;
7878
int-gpios = <&gpio0 0 0>;
79+
input-codes = <0 1 2>;
7980
};
8081
};
8182

0 commit comments

Comments
 (0)