diff --git a/samples/sensor/veaa_x_3/CMakeLists.txt b/samples/sensor/veaa_x_3/CMakeLists.txt new file mode 100644 index 00000000000000..e43b188ab7d9cb --- /dev/null +++ b/samples/sensor/veaa_x_3/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(app) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/sensor/veaa_x_3/Kconfig b/samples/sensor/veaa_x_3/Kconfig new file mode 100644 index 00000000000000..7eca02930fd6b6 --- /dev/null +++ b/samples/sensor/veaa_x_3/Kconfig @@ -0,0 +1,23 @@ +# +# Copyright (c) 2024 Vitrolife A/S +# +# SPDX-License-Identifier: Apache-2.0 +# + +mainmenu "VEAA sample application" + +config SAMPLE_USE_SHELL + bool "Use sensor shell and disable loop" + default n + select SHELL + select SENSOR_SHELL + +config SAMPLE_LOOP_INTERVAL + int "Sample loop delay in milliseconds" + default 200 + +config SAMPLE_LOOP_INCREMENT + int "Sample kPa increment per loop" + default 1 + +source "Kconfig.zephyr" diff --git a/samples/sensor/veaa_x_3/README.rst b/samples/sensor/veaa_x_3/README.rst new file mode 100644 index 00000000000000..09d85eacacfab3 --- /dev/null +++ b/samples/sensor/veaa_x_3/README.rst @@ -0,0 +1,38 @@ +.. veaa_x_3: + +VEAA-X-3 sample +########################## + +Overview +******** + +A sensor sample that demonstrates how to use a VEAA-X-3 device. + +Building and Running +******************** + +This sample sets the valve setpoint then reads the actual pressure. +This is done continuously. When the maximum supported pressure is reached the setpoint is reset to +the valve's minimum supported pressure value. + +.. zephyr-app-commands:: + :zephyr-app: samples/sensor/veaa_x_3 + :board: + :goals: build flash + :compact: + +Sample Output +============= + +.. code-block:: console + + Testing test_veaa_x_3 + Valve range: 1 to 200 kPa + Setpoint: 1 kPa, actual: 1 kPa + Setpoint: 2 kPa, actual: 2 kPa + Setpoint: 3 kPa, actual: 3 kPa + ... + Setpoint: 199 kPa, actual: 199 kPa + Setpoint: 200 kPa, actual: 200 kPa + Setpoint: 1 kPa, actual: 1 kPa + diff --git a/samples/sensor/veaa_x_3/boards/nucleo_h563zi.overlay b/samples/sensor/veaa_x_3/boards/nucleo_h563zi.overlay new file mode 100644 index 00000000000000..10b9676ac80be3 --- /dev/null +++ b/samples/sensor/veaa_x_3/boards/nucleo_h563zi.overlay @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright (c) 2024, Vitrolife A/S + */ + +/* spi1 sck conflicts with dac1 channel 3 */ +/delete-node/ &spi1; + +/ { + test_veaa_x_3: test_veaa_x_3 { + status = "okay"; + compatible = "festo,veaa-x-3"; + io-channels = <&adc1 3>; + dac = <&dac1>; + dac-channel-id = <2>; + dac-resolution = <12>; + pressure-range-type = "D2"; + }; + +}; + +&adc1 { + #address-cells = <1>; + #size-cells = <0>; + + channel@3 { + reg = <3>; + zephyr,gain = "ADC_GAIN_1"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,resolution = <12>; + }; + +}; diff --git a/samples/sensor/veaa_x_3/prj.conf b/samples/sensor/veaa_x_3/prj.conf new file mode 100644 index 00000000000000..e0bc48f5dfef20 --- /dev/null +++ b/samples/sensor/veaa_x_3/prj.conf @@ -0,0 +1,4 @@ +CONFIG_ADC=y +CONFIG_DAC=y +CONFIG_SENSOR=y +CONFIG_LOG=y diff --git a/samples/sensor/veaa_x_3/sample.yaml b/samples/sensor/veaa_x_3/sample.yaml new file mode 100644 index 00000000000000..2039dd9e7ed1a1 --- /dev/null +++ b/samples/sensor/veaa_x_3/sample.yaml @@ -0,0 +1,8 @@ +sample: + name: VEAA-X-3 sensor sample +tests: + sample.sensor.veaa_x_3: + harness: sensor + tags: sensors + filter: dt_compat_enabled("festo,veaa-x-3") + depends_on: adc dac diff --git a/samples/sensor/veaa_x_3/src/main.c b/samples/sensor/veaa_x_3/src/main.c new file mode 100644 index 00000000000000..db00cda87159bb --- /dev/null +++ b/samples/sensor/veaa_x_3/src/main.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 Vitrolife A/S + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +static const struct device *const dev = DEVICE_DT_GET_ONE(festo_veaa_x_3); + +int main(void) +{ + int rc; + struct sensor_value range, setpoint, pressure; + + printk("Testing %s\n", dev->name); + + if (!device_is_ready(dev)) { + printk("%s not ready\n", dev->name); + return -ENODEV; + } + + rc = sensor_attr_get(dev, SENSOR_CHAN_PRESS, + (enum sensor_attribute)SENSOR_ATTR_VEAA_X_3_RANGE, &range); + if (rc != 0) { + printk("get range failed: %d\n", rc); + return rc; + } + printk("Valve range: %u to %u kPa\n", range.val1, range.val2); + + if (IS_ENABLED(CONFIG_SAMPLE_USE_SHELL)) { + printk("Loop is disabled. Use the `sensor` command to test %s", dev->name); + return 0; + } + + setpoint.val1 = range.val1; + while (1) { + rc = sensor_attr_set(dev, SENSOR_CHAN_PRESS, + (enum sensor_attribute)SENSOR_ATTR_VEAA_X_3_SETPOINT, + &setpoint); + if (rc != 0) { + printk("Set setpoint to %u failed: %d\n", setpoint.val1, rc); + } + + /* Sleep before get to allow DAC and ADC to stabilize */ + k_msleep(CONFIG_SAMPLE_LOOP_INTERVAL); + + rc = sensor_sample_fetch(dev); + if (rc != 0) { + printk("Fetch sample failed: %d", rc); + } + + rc = sensor_channel_get(dev, SENSOR_CHAN_PRESS, &pressure); + if (rc != 0) { + printk("Get sample failed: %d", rc); + } + + printk("Setpoint: %4u kPa, actual: %4u kPa\n", setpoint.val1, pressure.val1); + + setpoint.val1 += CONFIG_SAMPLE_LOOP_INCREMENT; + if (setpoint.val1 > range.val2) { + setpoint.val1 = range.val1; + } + } + + return 0; +}