@@ -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
2527struct cap1203_config {
2628 struct i2c_dt_spec i2c ;
2729 struct gpio_dt_spec int_gpio ;
30+ const uint16_t * input_codes ;
2831};
2932
3033struct 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
217212DT_INST_FOREACH_STATUS_OKAY (CAP1203_INIT )
0 commit comments