Skip to content

Commit 16034d8

Browse files
committed
drivers: sensor: apds9960: Setup gesture sensing configuration
Created sensor specific channels and Kconfig for gesture sensing. Signed-off-by: Thomas Lang <[email protected]>
1 parent 8075a76 commit 16034d8

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

drivers/sensor/apds9960/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ config APDS9960_ENABLE_ALS
5858
help
5959
Enable Ambient Light Sense (ALS).
6060

61+
config APDS9960_ENABLE_GESTURE
62+
bool "Gesture Sense"
63+
default n
64+
help
65+
Enable Gesture Sense.
66+
6167
endif # APDS9960

drivers/sensor/apds9960/apds9960.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,16 @@ static DEVICE_API(sensor, apds9960_driver_api) = {
527527
#define APDS9960_CONFIG_INTERRUPT(inst)
528528
#endif
529529

530+
#if CONFIG_APDS9960_ENABLE_GESTURE
531+
#define APDS9960_CONFIG_GESTURE(inst) \
532+
.gesture_config = { \
533+
.proximity = DT_INST_PROP(inst, proximity), \
534+
.ir_difference = DT_INST_PROP(inst, ir_difference), \
535+
},
536+
#else
537+
#define APDS9960_CONFIG_GESTURE(inst)
538+
#endif
539+
530540
#define APDS9960_INIT(i) \
531541
static struct apds9960_config apds9960_data_##i; \
532542
static const struct apds9960_config apds9960_config_##i = { \
@@ -536,6 +546,7 @@ static DEVICE_API(sensor, apds9960_driver_api) = {
536546
.again = DT_INST_PROP(i, again), \
537547
.ppcount = DT_INST_PROP(i, ppulse_length) | (DT_INST_PROP(i, ppulse_count) - 1), \
538548
.pled_boost = DT_INST_PROP(i, pled_boost) << 4, \
549+
APDS9960_CONFIG_GESTURE(i) \
539550
}; \
540551
\
541552
PM_DEVICE_DT_INST_DEFINE(i, apds9960_pm_action); \

dts/bindings/sensor/avago,apds9960.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,13 @@ properties:
6060
type: int
6161
default: 0x8
6262
description: Proximity Pulse Count
63+
64+
proximity:
65+
type: int
66+
description: Gesture Proximity Enter Threshold
67+
default: 40
68+
69+
ir-difference:
70+
type: int
71+
description: Minimum IR diode difference for gesture
72+
default: 5

drivers/sensor/apds9960/apds9960.h renamed to include/zephyr/drivers/sensor/apds9960.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#define ZEPHYR_DRIVERS_SENSOR_APDS9960_APDS9960_H_
1010

1111
#include <zephyr/drivers/gpio.h>
12+
#include <zephyr/drivers/i2c.h>
1213

1314
#define APDS9960_ENABLE_REG 0x80
1415
#define APDS9960_ENABLE_GEN BIT(6)
@@ -216,6 +217,11 @@
216217
#define APDS9960_DEFAULT_WAIT_TIME 2.78
217218
#define APDS9960_MAX_WAIT_TIME 10000
218219

220+
struct apds9960_gesture_setup {
221+
int proximity;
222+
int ir_difference;
223+
};
224+
219225
struct apds9960_config {
220226
struct i2c_dt_spec i2c;
221227
#ifdef CONFIG_APDS9960_FETCH_MODE_INTERRUPT
@@ -225,6 +231,22 @@ struct apds9960_config {
225231
uint8_t again;
226232
uint8_t ppcount;
227233
uint8_t pled_boost;
234+
#ifdef CONFIG_APDS9960_ENABLE_GESTURE
235+
struct apds9960_gesture_setup gesture_config;
236+
#endif
237+
};
238+
239+
/* apds9960 specific channels */
240+
enum sensor_channel_apds9960 {
241+
SENSOR_CHAN_APDS9960_GESTURE = SENSOR_CHAN_PRIV_START,
242+
};
243+
244+
enum apds9960_gesture {
245+
APDS9960_GESTURE_NONE,
246+
APDS9960_GESTURE_UP,
247+
APDS9960_GESTURE_DOWN,
248+
APDS9960_GESTURE_LEFT,
249+
APDS9960_GESTURE_RIGHT,
228250
};
229251

230252
struct apds9960_data {
@@ -233,6 +255,7 @@ struct apds9960_data {
233255
const struct device *dev;
234256
uint16_t sample_crgb[4];
235257
uint8_t pdata;
258+
enum apds9960_gesture gesture;
236259

237260
#ifdef CONFIG_APDS9960_TRIGGER
238261
sensor_trigger_handler_t p_th_handler;

0 commit comments

Comments
 (0)