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é <benjamin@zephyrproject.org>
This commit is contained in:
Benjamin Cabé 2025-07-11 23:51:54 +02:00 committed by Chris Friedt
parent 5c95ff509f
commit 9dabb21ced
6 changed files with 57 additions and 39 deletions

View File

@ -1,10 +0,0 @@
# Copyright (c) 2025 Paul Timke <ptimkec@live.com>
# SPDX-License-Identifier: Apache-2.0
mainmenu "PAJ7620 sample application"
config APP_USE_POLLING
bool "Select y to use polling, otherwise the sample will use triggers"
default y
source "Kconfig.zephyr"

View File

@ -7,16 +7,15 @@
Overview
********
This sample application gets the output of a gesture sensor (paj7620) using either polling or
triggers (depending on CONFIG_APP_USE_POLLING) and outputs the corresponding gesture to the
console, each time one is detected.
This sample application gets the output of a gesture sensor (PAJ7620) using either polling or
triggers, and outputs the corresponding gesture to the console, each time one is detected.
Requirements
************
To use this sample, the following hardware is required:
* A board with I2C support and GPIO to detect external interrutps
* A board with I2C support (and GPIO to detect external interrupts in trigger mode)
* PAJ7620 sensor
Building and Running
@ -24,12 +23,30 @@ Building and Running
This sample outputs data to the console. It requires a PAJ7620 sensor.
Polling Mode
============
.. zephyr-app-commands::
:zephyr-app: samples/sensor/paj7620_gesture
:board: nucleo_f334r8
:goals: build
:compact:
Trigger Mode
============
In trigger mode, the sample application uses a GPIO to detect external interrupts, therefore GPIO
support must be enabled. Just like every sensor supporting trigger mode, it is possible to choose
between using a global thread (``CONFIG_PAJ7620_TRIGGER_GLOBAL_THREAD``) or a dedicated thread
(``CONFIG_PAJ7620_TRIGGER_OWN_THREAD``) for the interrupt handling.
.. zephyr-app-commands::
:zephyr-app: samples/sensor/paj7620_gesture
:board: nucleo_f334r8
:goals: build
:gen-args: -DEXTRA_CONF_FILE=trigger.conf
:compact:
Sample Output
=============

View File

@ -1,5 +1,3 @@
CONFIG_GPIO=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_PAJ7620_TRIGGER_OWN_THREAD=y

View File

@ -1,17 +1,20 @@
sample:
name: PAJ7620 gesture trigger sample
common:
min_ram: 12
tags: sensors
platform_allow: nucleo_f334r8
filter: dt_compat_enabled("pixart,paj7620")
tests:
sample.sensor.paj7620_gesture_trig:
build_only: true
tags: sensors
platform_allow: nucleo_f334r8
depends_on:
- i2c
- gpio
filter: dt_compat_enabled("pixart,paj7620")
extra_args: EXTRA_CONF_FILE=trigger.conf
sample.sensor.paj7620_gesture_polling:
build_only: true
tags: sensors
platform_allow: nucleo_f334r8
depends_on: i2c
filter: dt_compat_enabled("pixart,paj7620")
depends_on:
- i2c
extra_configs:
- CONFIG_PAJ7620_TRIGGER_NONE=y

View File

@ -10,6 +10,7 @@
#define GESTURE_POLL_TIME_MS 100
#ifdef CONFIG_PAJ7620_TRIGGER
K_SEM_DEFINE(sem, 0, 1); /* starts off "not available" */
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
k_sem_give(&sem);
}
#endif
static void print_hand_gesture(uint16_t gest_flags)
{
@ -52,6 +54,7 @@ static void print_hand_gesture(uint16_t gest_flags)
}
}
#ifdef CONFIG_PAJ7620_TRIGGER_OWN_THREAD
static void trigger_main_loop(const struct device *dev)
{
struct sensor_value data;
@ -65,7 +68,9 @@ static void trigger_main_loop(const struct device *dev)
print_hand_gesture(data.val1);
}
}
#endif
#ifdef CONFIG_PAJ7620_TRIGGER_NONE
static void polling_main_loop(const struct device *dev)
{
struct sensor_value data;
@ -79,32 +84,35 @@ static void polling_main_loop(const struct device *dev)
k_msleep(GESTURE_POLL_TIME_MS);
}
}
#endif
int main(void)
{
int ret;
const struct device *dev = DEVICE_DT_GET_ONE(pixart_paj7620);
struct sensor_trigger trig = {
.type = SENSOR_TRIG_MOTION,
.chan = (enum sensor_channel)SENSOR_CHAN_PAJ7620_GESTURES,
};
if (!device_is_ready(dev)) {
printf("Device %s is not ready\n", dev->name);
return -ENODEV;
}
if (IS_ENABLED(CONFIG_APP_USE_POLLING)) {
polling_main_loop(dev);
} else {
/* App was configured to NOT use polling, so use triggers */
ret = sensor_trigger_set(dev, &trig, trigger_handler);
if (ret < 0) {
printf("Could not set trigger\n");
return ret;
}
#ifdef CONFIG_PAJ7620_TRIGGER
struct sensor_trigger trig = {
.type = SENSOR_TRIG_MOTION,
.chan = (enum sensor_channel)SENSOR_CHAN_PAJ7620_GESTURES,
};
int ret;
trigger_main_loop(dev);
printf("PAJ7620 gesture sensor sample - trigger mode\n");
ret = sensor_trigger_set(dev, &trig, trigger_handler);
if (ret < 0) {
printf("Could not set trigger\n");
return ret;
}
trigger_main_loop(dev);
#else
printf("PAJ7620 gesture sensor sample - polling mode\n");
polling_main_loop(dev);
#endif
}

View File

@ -0,0 +1,2 @@
CONFIG_GPIO=y
CONFIG_PAJ7620_TRIGGER_OWN_THREAD=y