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
3030struct 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
120125static 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-
191133static 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
260217DT_INST_FOREACH_STATUS_OKAY (CAP1203_INIT )
0 commit comments