drivers: input: cst816s: read the gesture-ID register
And report the gestures as specific device event type to the input subsystem. Signed-off-by: Felipe Neves <ryukokki.felipe@gmail.com>
This commit is contained in:
parent
acaee9f019
commit
804db65928
3 changed files with 46 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/dt-bindings/input/cst816s-gesture-codes.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
18
include/zephyr/dt-bindings/input/cst816s-gesture-codes.h
Normal file
18
include/zephyr/dt-bindings/input/cst816s-gesture-codes.h
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue