Skip to content

Fixes to PAJ7620 driver and code sample #93044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/sensor/pixart/paj7620/paj7620_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <zephyr/logging/log.h>
#include <zephyr/drivers/gpio.h>

LOG_MODULE_REGISTER(paj7620, CONFIG_SENSOR_LOG_LEVEL);
LOG_MODULE_REGISTER(paj7620_trigger, CONFIG_SENSOR_LOG_LEVEL);

static void paj7620_gpio_callback(const struct device *dev,
struct gpio_callback *cb,
Expand Down
10 changes: 0 additions & 10 deletions samples/sensor/paj7620_gesture/Kconfig

This file was deleted.

25 changes: 21 additions & 4 deletions samples/sensor/paj7620_gesture/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,44 @@
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
********************

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
Expand Down
2 changes: 0 additions & 2 deletions samples/sensor/paj7620_gesture/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CONFIG_GPIO=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_PAJ7620_TRIGGER_OWN_THREAD=y
17 changes: 10 additions & 7 deletions samples/sensor/paj7620_gesture/sample.yaml
Original file line number Diff line number Diff line change
@@ -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
40 changes: 24 additions & 16 deletions samples/sensor/paj7620_gesture/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);

if (!device_is_ready(dev)) {
printf("Device %s is not ready\n", dev->name);
return -ENODEV;
}

#ifdef CONFIG_PAJ7620_TRIGGER
struct sensor_trigger trig = {
.type = SENSOR_TRIG_MOTION,
.chan = (enum sensor_channel)SENSOR_CHAN_PAJ7620_GESTURES,
};
int ret;

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

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;
}

trigger_main_loop(dev);
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
}
2 changes: 2 additions & 0 deletions samples/sensor/paj7620_gesture/trigger.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_GPIO=y
CONFIG_PAJ7620_TRIGGER_OWN_THREAD=y