diff --git a/drivers/input/Kconfig.cst816s b/drivers/input/Kconfig.cst816s index c7cbc59e245..0b8bb058fc4 100644 --- a/drivers/input/Kconfig.cst816s +++ b/drivers/input/Kconfig.cst816s @@ -25,4 +25,9 @@ config INPUT_CST816S_INTERRUPT help Enable interrupt support (requires GPIO). +config INPUT_CST816S_EV_DEVICE + bool "Device specific event support" + help + Enable device specific event support. + endif # INPUT_CST816S diff --git a/drivers/input/input_cst816s.c b/drivers/input/input_cst816s.c index ee1c6c3de74..06d68d1ea75 100644 --- a/drivers/input/input_cst816s.c +++ b/drivers/input/input_cst816s.c @@ -11,6 +11,7 @@ #include #include #include +#include LOG_MODULE_REGISTER(cst816s, CONFIG_INPUT_LOG_LEVEL); @@ -115,6 +116,16 @@ static int cst816s_process(const struct device *dev) uint16_t x; uint16_t y; +#ifdef CONFIG_INPUT_CST816S_EV_DEVICE + uint8_t gesture; + + r = i2c_burst_read_dt(&cfg->i2c, CST816S_REG_GESTURE_ID, &gesture, sizeof(gesture)); + if (r < 0) { + LOG_ERR("Could not read gesture-ID data"); + return r; + } +#endif + r = i2c_burst_read_dt(&cfg->i2c, CST816S_REG_XPOS_H, (uint8_t *)&x, sizeof(x)); if (r < 0) { LOG_ERR("Could not read x data"); @@ -142,6 +153,18 @@ static int cst816s_process(const struct device *dev) input_report_key(dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER); } +#ifdef CONFIG_INPUT_CST816S_EV_DEVICE + /* Also put the custom touch gestures into the input queue, + * some applications may want to process it + */ + + LOG_DBG("gesture: %d", gesture); + + if (gesture != CST816S_GESTURE_CODE_NONE) { + input_report(dev, INPUT_EV_DEVICE, (uint16_t)gesture, 0, true, K_FOREVER); + } +#endif + return r; } diff --git a/include/zephyr/dt-bindings/input/cst816s-gesture-codes.h b/include/zephyr/dt-bindings/input/cst816s-gesture-codes.h new file mode 100644 index 00000000000..ec96e193279 --- /dev/null +++ b/include/zephyr/dt-bindings/input/cst816s-gesture-codes.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Felipe Neves. + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_INPUT_CST816S_GESTURE_CODES_H_ +#define ZEPHYR_INCLUDE_DT_BINDINGS_INPUT_CST816S_GESTURE_CODES_H_ + +#define CST816S_GESTURE_CODE_NONE 0x00 +#define CST816S_GESTURE_CODE_SWIPE_UP 0x01 +#define CST816S_GESTURE_CODE_SWIPE_DOWN 0x02 +#define CST816S_GESTURE_CODE_SWIPE_LEFT 0x03 +#define CST816S_GESTURE_CODE_SWIPE_RIGHT 0x04 +#define CST816S_GESTURE_CODE_SINGLE_CLICK 0x05 +#define CST816S_GESTURE_CODE_DOUBLE_CLICK 0x0B +#define CST816S_GESTURE_CODE_LONG_PRESS 0x0C + +#endif