samples: sensor: Added sample for grow_r502a fingerprint sensor
Added sample application for grow_r502a fingerprint sensor Signed-off-by: Dinesh Kumar K <dinesh@linumiz.com>
This commit is contained in:
parent
f050e18798
commit
4eb1a34cac
6 changed files with 247 additions and 0 deletions
8
samples/sensor/grow_r502a/CMakeLists.txt
Normal file
8
samples/sensor/grow_r502a/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
project(grow_r502a)
|
||||||
|
|
||||||
|
FILE(GLOB app_sources src/*.c)
|
||||||
|
target_sources(app PRIVATE ${app_sources})
|
69
samples/sensor/grow_r502a/README.rst
Normal file
69
samples/sensor/grow_r502a/README.rst
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
.. _grow_r502a:
|
||||||
|
|
||||||
|
GROW_R502A Fingerprint Sensor
|
||||||
|
#############################
|
||||||
|
|
||||||
|
Overview
|
||||||
|
********
|
||||||
|
|
||||||
|
This sample has the below functionalities:
|
||||||
|
|
||||||
|
#. Shows the number of fingerprints stored in the sensor.
|
||||||
|
#. When SENSOR_ATTR_RECORD_FREE_IDX is set then it search for free index in sensor library.
|
||||||
|
#. When SENSOR_ATTR_RECORD_ADD is set then it adds a new fingerprint to the sensor.
|
||||||
|
#. When SENSOR_ATTR_RECORD_FIND is set then it tries to find a match for the input fingerprint. On finding a match it returns ID and confidence.
|
||||||
|
#. When SENSOR_ATTR_RECORD_DEL is set then it deletes a fingerprint from the sensor.
|
||||||
|
|
||||||
|
Note: Fingerprint add & delete functionalities work only when SENSOR_TRIG_TOUCH is set.
|
||||||
|
Tricolored LED in the sensor hardware will, flash on the below conditions:
|
||||||
|
|
||||||
|
#. On successful addition or deletion of fingerprint it will flash in blue three times.
|
||||||
|
#. On finding a match for the input fingerprint it will flash in purple.
|
||||||
|
#. In all other cases it will flash in red.
|
||||||
|
|
||||||
|
Wiring
|
||||||
|
*******
|
||||||
|
|
||||||
|
This sample uses an external breakout for the sensor. A devicetree
|
||||||
|
overlay must be provided to identify the UART bus and the GPIO
|
||||||
|
used to control the sensor. Sensor can be powered using mentioned optional GPIO.
|
||||||
|
|
||||||
|
References
|
||||||
|
**********
|
||||||
|
|
||||||
|
For more information about the GROW_R502A Fingerprint Sensor see
|
||||||
|
http://en.hzgrow.com/product/143.html
|
||||||
|
|
||||||
|
Building and Running
|
||||||
|
********************
|
||||||
|
|
||||||
|
After providing a devicetree overlay that specifies the sensor location,
|
||||||
|
build this sample app using:
|
||||||
|
|
||||||
|
.. zephyr-app-commands::
|
||||||
|
:zephyr-app: samples/sensor/grow_r502a
|
||||||
|
:board: nrf52840dk_nrf52840
|
||||||
|
:goals: build flash
|
||||||
|
|
||||||
|
Sample Output
|
||||||
|
*************
|
||||||
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
*** Booting Zephyr OS build zephyr-v3.1.0-2640-g328bb73113d4 ***
|
||||||
|
template count : 0
|
||||||
|
Fingerprint Deleted at ID #3
|
||||||
|
Fingerprint template free idx at ID #0
|
||||||
|
Waiting for valid finger to enroll as ID #0
|
||||||
|
Place your finger
|
||||||
|
Fingerprint successfully stored at #0
|
||||||
|
template count : 1
|
||||||
|
Matched ID : 0
|
||||||
|
confidence : 170
|
||||||
|
template count : 1
|
||||||
|
Matched ID : 0
|
||||||
|
confidence : 136
|
||||||
|
template count : 1
|
||||||
|
Matched ID : 0
|
||||||
|
confidence : 318
|
||||||
|
<repeats endlessly>
|
28
samples/sensor/grow_r502a/boards/esp32.overlay
Normal file
28
samples/sensor/grow_r502a/boards/esp32.overlay
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
&pinctrl {
|
||||||
|
uart2_default: uart2_default {
|
||||||
|
group1 {
|
||||||
|
pinmux = <UART2_TX_GPIO32>;
|
||||||
|
};
|
||||||
|
group2 {
|
||||||
|
pinmux = <UART2_RX_GPIO33>;
|
||||||
|
bias-pull-up;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
&uart2 {
|
||||||
|
status = "okay";
|
||||||
|
current-speed = <57600>;
|
||||||
|
pinctrl-0 = <&uart2_default>;
|
||||||
|
pinctrl-names = "default";
|
||||||
|
|
||||||
|
fps {
|
||||||
|
#address-cells=<1>;
|
||||||
|
#size-cells=<0>;
|
||||||
|
grow_r502a@ffffffff {
|
||||||
|
compatible = "hzgrow,r502a";
|
||||||
|
reg = <0xffffffff>;
|
||||||
|
int-gpios = <&gpio1 3 GPIO_ACTIVE_LOW>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
5
samples/sensor/grow_r502a/prj.conf
Normal file
5
samples/sensor/grow_r502a/prj.conf
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
CONFIG_SERIAL=y
|
||||||
|
CONFIG_UART_INTERRUPT_DRIVEN=y
|
||||||
|
|
||||||
|
CONFIG_SENSOR=y
|
||||||
|
CONFIG_GROW_R502A_TRIGGER_OWN_THREAD=y
|
14
samples/sensor/grow_r502a/sample.yaml
Normal file
14
samples/sensor/grow_r502a/sample.yaml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2021 Linumiz.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
sample:
|
||||||
|
name: grow_r502a fingerprint sensor sample
|
||||||
|
tests:
|
||||||
|
sample.sensor.grow_r502a:
|
||||||
|
tags: sensors
|
||||||
|
harness: sensor
|
||||||
|
build_only: true
|
||||||
|
depends_on: serial
|
||||||
|
filter: dt_compat_enabled("hzgrow,r502a")
|
123
samples/sensor/grow_r502a/src/main.c
Normal file
123
samples/sensor/grow_r502a/src/main.c
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Linumiz
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/device.h>
|
||||||
|
#include <zephyr/drivers/sensor.h>
|
||||||
|
#include <zephyr/drivers/uart.h>
|
||||||
|
#include <zephyr/drivers/gpio.h>
|
||||||
|
#include <zephyr/drivers/sensor/grow_r502a.h>
|
||||||
|
|
||||||
|
static bool enroll;
|
||||||
|
static struct sensor_value fid, val;
|
||||||
|
|
||||||
|
static void finger_match(const struct device *dev)
|
||||||
|
{
|
||||||
|
struct sensor_value input;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = sensor_attr_get(dev, SENSOR_CHAN_FINGERPRINT,
|
||||||
|
SENSOR_ATTR_R502A_RECORD_FIND, &input);
|
||||||
|
if (ret != 0) {
|
||||||
|
printk("Sensor attr get failed %d\n", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printk("Matched ID : %d\n", input.val1);
|
||||||
|
printk("confidence : %d\n", input.val2);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void finger_enroll(const struct device *dev)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = sensor_attr_set(dev, SENSOR_CHAN_FINGERPRINT, SENSOR_ATTR_R502A_RECORD_ADD, &fid);
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
|
printk("Fingerprint successfully stored at #%d\n", fid.val1);
|
||||||
|
enroll = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void template_count_get(const struct device *dev)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = sensor_sample_fetch(dev);
|
||||||
|
if (ret < 0) {
|
||||||
|
printk("Sample Fetch Error %d\n", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ret = sensor_channel_get(dev, SENSOR_CHAN_FINGERPRINT, &val);
|
||||||
|
if (ret < 0) {
|
||||||
|
printk("Channel Get Error %d\n", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printk("template count : %d\n", val.val1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void trigger_handler(const struct device *dev,
|
||||||
|
const struct sensor_trigger *trigger)
|
||||||
|
{
|
||||||
|
if (enroll) {
|
||||||
|
finger_enroll(dev);
|
||||||
|
} else {
|
||||||
|
template_count_get(dev);
|
||||||
|
finger_match(dev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
static struct sensor_value del, fid_get;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
const struct device *dev = DEVICE_DT_GET_ONE(hzgrow_r502a);
|
||||||
|
|
||||||
|
if (dev == NULL) {
|
||||||
|
printk("Error: no device found\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!device_is_ready(dev)) {
|
||||||
|
printk("Error: Device %s is not ready\n", dev->name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
template_count_get(dev);
|
||||||
|
|
||||||
|
del.val1 = 3;
|
||||||
|
ret = sensor_attr_set(dev, SENSOR_CHAN_FINGERPRINT, SENSOR_ATTR_R502A_RECORD_DEL, &del);
|
||||||
|
if (ret != 0) {
|
||||||
|
printk("Sensor attr set failed %d\n", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printk("Fingerprint Deleted at ID #%d\n", del.val1);
|
||||||
|
|
||||||
|
ret = sensor_attr_get(dev, SENSOR_CHAN_FINGERPRINT,
|
||||||
|
SENSOR_ATTR_R502A_RECORD_FREE_IDX, &fid_get);
|
||||||
|
if (ret != 0) {
|
||||||
|
printk("Sensor attr get failed %d\n", ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printk("Fingerprint template free idx at ID #%d\n", fid_get.val1);
|
||||||
|
|
||||||
|
fid.val1 = fid_get.val1;
|
||||||
|
printk("Waiting for valid finger to enroll as ID #%d\n"
|
||||||
|
"Place your finger\n", fid.val1);
|
||||||
|
enroll = true;
|
||||||
|
|
||||||
|
if (IS_ENABLED(CONFIG_GROW_R502A_TRIGGER)) {
|
||||||
|
struct sensor_trigger trig = {
|
||||||
|
.type = SENSOR_TRIG_TOUCH,
|
||||||
|
.chan = SENSOR_CHAN_FINGERPRINT,
|
||||||
|
};
|
||||||
|
ret = sensor_trigger_set(dev, &trig, trigger_handler);
|
||||||
|
if (ret != 0) {
|
||||||
|
printk("Could not set trigger\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue