Skip to content

Commit 9dabb21

Browse files
kartbencfriedt
authored andcommitted
samples: sensor: paj7620: refactor handling of trigger mode
The current sample was always trying to enable trigger mode in the driver no matter what, causing issues for instances where the sensor simply has no interrupt pin configured in Devicetree. Cleaned things up so that enabling trigger mode is done via the driver's Kconfig option, and cleaned up the Twister testcases accordingly (plus, made sure they are actually built by setting min_ram to a value compatibel with the nucleo_f334r8). README has also been updated to clearly document how to enable either mode. Signed-off-by: Benjamin Cabé <[email protected]>
1 parent 5c95ff5 commit 9dabb21

File tree

6 files changed

+57
-39
lines changed

6 files changed

+57
-39
lines changed

samples/sensor/paj7620_gesture/Kconfig

Lines changed: 0 additions & 10 deletions
This file was deleted.

samples/sensor/paj7620_gesture/README.rst

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,44 @@
77
Overview
88
********
99

10-
This sample application gets the output of a gesture sensor (paj7620) using either polling or
11-
triggers (depending on CONFIG_APP_USE_POLLING) and outputs the corresponding gesture to the
12-
console, each time one is detected.
10+
This sample application gets the output of a gesture sensor (PAJ7620) using either polling or
11+
triggers, and outputs the corresponding gesture to the console, each time one is detected.
1312

1413
Requirements
1514
************
1615

1716
To use this sample, the following hardware is required:
1817

19-
* A board with I2C support and GPIO to detect external interrutps
18+
* A board with I2C support (and GPIO to detect external interrupts in trigger mode)
2019
* PAJ7620 sensor
2120

2221
Building and Running
2322
********************
2423

2524
This sample outputs data to the console. It requires a PAJ7620 sensor.
2625

26+
Polling Mode
27+
============
28+
29+
.. zephyr-app-commands::
30+
:zephyr-app: samples/sensor/paj7620_gesture
31+
:board: nucleo_f334r8
32+
:goals: build
33+
:compact:
34+
35+
Trigger Mode
36+
============
37+
38+
In trigger mode, the sample application uses a GPIO to detect external interrupts, therefore GPIO
39+
support must be enabled. Just like every sensor supporting trigger mode, it is possible to choose
40+
between using a global thread (``CONFIG_PAJ7620_TRIGGER_GLOBAL_THREAD``) or a dedicated thread
41+
(``CONFIG_PAJ7620_TRIGGER_OWN_THREAD``) for the interrupt handling.
42+
2743
.. zephyr-app-commands::
2844
:zephyr-app: samples/sensor/paj7620_gesture
2945
:board: nucleo_f334r8
3046
:goals: build
47+
:gen-args: -DEXTRA_CONF_FILE=trigger.conf
3148
:compact:
3249

3350
Sample Output
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
CONFIG_GPIO=y
21
CONFIG_STDOUT_CONSOLE=y
32
CONFIG_I2C=y
43
CONFIG_SENSOR=y
5-
CONFIG_PAJ7620_TRIGGER_OWN_THREAD=y
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
sample:
22
name: PAJ7620 gesture trigger sample
3+
common:
4+
min_ram: 12
5+
tags: sensors
6+
platform_allow: nucleo_f334r8
7+
filter: dt_compat_enabled("pixart,paj7620")
38
tests:
49
sample.sensor.paj7620_gesture_trig:
510
build_only: true
6-
tags: sensors
7-
platform_allow: nucleo_f334r8
811
depends_on:
912
- i2c
1013
- gpio
11-
filter: dt_compat_enabled("pixart,paj7620")
14+
extra_args: EXTRA_CONF_FILE=trigger.conf
1215
sample.sensor.paj7620_gesture_polling:
1316
build_only: true
14-
tags: sensors
15-
platform_allow: nucleo_f334r8
16-
depends_on: i2c
17-
filter: dt_compat_enabled("pixart,paj7620")
17+
depends_on:
18+
- i2c
19+
extra_configs:
20+
- CONFIG_PAJ7620_TRIGGER_NONE=y

samples/sensor/paj7620_gesture/src/main.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#define GESTURE_POLL_TIME_MS 100
1212

13+
#ifdef CONFIG_PAJ7620_TRIGGER
1314
K_SEM_DEFINE(sem, 0, 1); /* starts off "not available" */
1415

1516
static void trigger_handler(const struct device *dev, const struct sensor_trigger *trigger)
@@ -23,6 +24,7 @@ static void trigger_handler(const struct device *dev, const struct sensor_trigge
2324

2425
k_sem_give(&sem);
2526
}
27+
#endif
2628

2729
static void print_hand_gesture(uint16_t gest_flags)
2830
{
@@ -52,6 +54,7 @@ static void print_hand_gesture(uint16_t gest_flags)
5254
}
5355
}
5456

57+
#ifdef CONFIG_PAJ7620_TRIGGER_OWN_THREAD
5558
static void trigger_main_loop(const struct device *dev)
5659
{
5760
struct sensor_value data;
@@ -65,7 +68,9 @@ static void trigger_main_loop(const struct device *dev)
6568
print_hand_gesture(data.val1);
6669
}
6770
}
71+
#endif
6872

73+
#ifdef CONFIG_PAJ7620_TRIGGER_NONE
6974
static void polling_main_loop(const struct device *dev)
7075
{
7176
struct sensor_value data;
@@ -79,32 +84,35 @@ static void polling_main_loop(const struct device *dev)
7984
k_msleep(GESTURE_POLL_TIME_MS);
8085
}
8186
}
87+
#endif
8288

8389
int main(void)
8490
{
85-
int ret;
8691
const struct device *dev = DEVICE_DT_GET_ONE(pixart_paj7620);
8792

93+
if (!device_is_ready(dev)) {
94+
printf("Device %s is not ready\n", dev->name);
95+
return -ENODEV;
96+
}
97+
98+
#ifdef CONFIG_PAJ7620_TRIGGER
8899
struct sensor_trigger trig = {
89100
.type = SENSOR_TRIG_MOTION,
90101
.chan = (enum sensor_channel)SENSOR_CHAN_PAJ7620_GESTURES,
91102
};
103+
int ret;
92104

93-
if (!device_is_ready(dev)) {
94-
printf("Device %s is not ready\n", dev->name);
95-
return -ENODEV;
96-
}
105+
printf("PAJ7620 gesture sensor sample - trigger mode\n");
97106

98-
if (IS_ENABLED(CONFIG_APP_USE_POLLING)) {
99-
polling_main_loop(dev);
100-
} else {
101-
/* App was configured to NOT use polling, so use triggers */
102-
ret = sensor_trigger_set(dev, &trig, trigger_handler);
103-
if (ret < 0) {
104-
printf("Could not set trigger\n");
105-
return ret;
106-
}
107-
108-
trigger_main_loop(dev);
107+
ret = sensor_trigger_set(dev, &trig, trigger_handler);
108+
if (ret < 0) {
109+
printf("Could not set trigger\n");
110+
return ret;
109111
}
112+
113+
trigger_main_loop(dev);
114+
#else
115+
printf("PAJ7620 gesture sensor sample - polling mode\n");
116+
polling_main_loop(dev);
117+
#endif
110118
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_GPIO=y
2+
CONFIG_PAJ7620_TRIGGER_OWN_THREAD=y

0 commit comments

Comments
 (0)