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 <fabianblatz@gmail.com>
This commit is contained in:
parent
1d56b8e2aa
commit
e1e4fcc701
3 changed files with 32 additions and 30 deletions
|
@ -19,12 +19,15 @@ LOG_MODULE_REGISTER(cap1203, CONFIG_INPUT_LOG_LEVEL);
|
||||||
#define REG_INPUT_STATUS 0x03
|
#define REG_INPUT_STATUS 0x03
|
||||||
|
|
||||||
#define REG_INTERRUPT_ENABLE 0x27
|
#define REG_INTERRUPT_ENABLE 0x27
|
||||||
#define INTERRUPT_ENABLE 0x7
|
#define INTERRUPT_ENABLE 0x7
|
||||||
#define INTERRUPT_DISABLE 0x0
|
#define INTERRUPT_DISABLE 0x0
|
||||||
|
|
||||||
|
#define TOUCH_INPUT_COUNT 3
|
||||||
|
|
||||||
struct cap1203_config {
|
struct cap1203_config {
|
||||||
struct i2c_dt_spec i2c;
|
struct i2c_dt_spec i2c;
|
||||||
struct gpio_dt_spec int_gpio;
|
struct gpio_dt_spec int_gpio;
|
||||||
|
const uint16_t *input_codes;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cap1203_data {
|
struct cap1203_data {
|
||||||
|
@ -32,6 +35,7 @@ struct cap1203_data {
|
||||||
struct k_work work;
|
struct k_work work;
|
||||||
/* Interrupt GPIO callback. */
|
/* Interrupt GPIO callback. */
|
||||||
struct gpio_callback int_gpio_cb;
|
struct gpio_callback int_gpio_cb;
|
||||||
|
uint8_t prev_input_state;
|
||||||
#ifdef CONFIG_INPUT_CAP1203_POLL
|
#ifdef CONFIG_INPUT_CAP1203_POLL
|
||||||
/* Timer (polling mode). */
|
/* Timer (polling mode). */
|
||||||
struct k_timer timer;
|
struct k_timer timer;
|
||||||
|
@ -65,24 +69,21 @@ static int cap1203_process(const struct device *dev)
|
||||||
struct cap1203_data *data = dev->data;
|
struct cap1203_data *data = dev->data;
|
||||||
int r;
|
int r;
|
||||||
uint8_t input;
|
uint8_t input;
|
||||||
uint16_t col;
|
uint8_t single_input_state;
|
||||||
bool pressed;
|
|
||||||
|
|
||||||
r = i2c_reg_read_byte_dt(&config->i2c, REG_INPUT_STATUS, &input);
|
r = i2c_reg_read_byte_dt(&config->i2c, REG_INPUT_STATUS, &input);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
pressed = !!input;
|
for (uint8_t i = 0; i < TOUCH_INPUT_COUNT; i++) {
|
||||||
if (input & BIT(0)) {
|
single_input_state = input & BIT(i);
|
||||||
col = 0;
|
if (single_input_state != (data->prev_input_state & BIT(i))) {
|
||||||
}
|
input_report_key(dev, config->input_codes[i], single_input_state, true,
|
||||||
if (input & BIT(1)) {
|
K_FOREVER);
|
||||||
col = 1;
|
}
|
||||||
}
|
|
||||||
if (input & BIT(2)) {
|
|
||||||
col = 2;
|
|
||||||
}
|
}
|
||||||
|
data->prev_input_state = input;
|
||||||
|
|
||||||
LOG_DBG("event: input: %d\n", input);
|
LOG_DBG("event: input: %d\n", input);
|
||||||
|
|
||||||
|
@ -95,14 +96,6 @@ static int cap1203_process(const struct device *dev)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pressed) {
|
|
||||||
input_report_abs(dev, INPUT_ABS_X, col, false, K_FOREVER);
|
|
||||||
input_report_abs(dev, INPUT_ABS_Y, 0, false, K_FOREVER);
|
|
||||||
input_report_key(dev, INPUT_BTN_TOUCH, 1, true, K_FOREVER);
|
|
||||||
} else {
|
|
||||||
input_report_key(dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,15 +196,17 @@ static int cap1203_init(const struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CAP1203_INIT(index) \
|
#define CAP1203_INIT(index) \
|
||||||
static const struct cap1203_config cap1203_config_##index = { \
|
static const uint16_t cap1203_input_codes_##inst[] = DT_INST_PROP(index, input_codes); \
|
||||||
.i2c = I2C_DT_SPEC_INST_GET(index), \
|
BUILD_ASSERT(DT_INST_PROP_LEN(index, input_codes) == TOUCH_INPUT_COUNT); \
|
||||||
.int_gpio = GPIO_DT_SPEC_INST_GET_OR(index, int_gpios, {0}), \
|
static const struct cap1203_config cap1203_config_##index = { \
|
||||||
}; \
|
.i2c = I2C_DT_SPEC_INST_GET(index), \
|
||||||
static struct cap1203_data cap1203_data_##index; \
|
.int_gpio = GPIO_DT_SPEC_INST_GET_OR(index, int_gpios, {0}), \
|
||||||
DEVICE_DT_INST_DEFINE(index, cap1203_init, NULL, \
|
.input_codes = cap1203_input_codes_##inst, \
|
||||||
&cap1203_data_##index, &cap1203_config_##index, \
|
}; \
|
||||||
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \
|
static struct cap1203_data cap1203_data_##index; \
|
||||||
|
DEVICE_DT_INST_DEFINE(index, cap1203_init, NULL, &cap1203_data_##index, \
|
||||||
|
&cap1203_config_##index, POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(CAP1203_INIT)
|
DT_INST_FOREACH_STATUS_OKAY(CAP1203_INIT)
|
||||||
|
|
|
@ -10,3 +10,9 @@ include: i2c-device.yaml
|
||||||
properties:
|
properties:
|
||||||
int-gpios:
|
int-gpios:
|
||||||
type: phandle-array
|
type: phandle-array
|
||||||
|
|
||||||
|
input-codes:
|
||||||
|
type: array
|
||||||
|
required: true
|
||||||
|
description: |
|
||||||
|
Array of input event key codes (INPUT_KEY_* or INPUT_BTN_*).
|
||||||
|
|
|
@ -76,6 +76,7 @@
|
||||||
compatible = "microchip,cap1203";
|
compatible = "microchip,cap1203";
|
||||||
reg = <0x3>;
|
reg = <0x3>;
|
||||||
int-gpios = <&gpio0 0 0>;
|
int-gpios = <&gpio0 0 0>;
|
||||||
|
input-codes = <0 1 2>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue