mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-15 01:23:49 +01:00
tests/drivers/abp2: test implementation
This commit is contained in:
parent
67f46778e4
commit
2c97a5330f
15
tests/drivers/abp2/Makefile
Normal file
15
tests/drivers/abp2/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
include ../Makefile.drivers_common
|
||||
|
||||
# include and auto-initialize all available sensors
|
||||
USEMODULE += saul_default
|
||||
|
||||
# use abp2_spi for SPI-Mode and abp2_i2c for I2C-Mode
|
||||
USEMODULE += abp2
|
||||
ABP2_INTERFACE ?= abp2_spi
|
||||
USEMODULE += $(ABP2_INTERFACE)
|
||||
|
||||
USEMODULE += ztimer
|
||||
USEMODULE += ztimer_usec
|
||||
USEMODULE += phydat
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
3
tests/drivers/abp2/Makefile.ci
Normal file
3
tests/drivers/abp2/Makefile.ci
Normal file
@ -0,0 +1,3 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
atmega8 \
|
||||
#
|
||||
14
tests/drivers/abp2/README.md
Normal file
14
tests/drivers/abp2/README.md
Normal file
@ -0,0 +1,14 @@
|
||||
# About
|
||||
|
||||
This is a test application for the Honeywell [ABP2 series][1] pressure and temperature sensor.
|
||||
|
||||
# Usage
|
||||
|
||||
This test application initializes the sensor and measures pressure and
|
||||
temperature periodically.
|
||||
The results are printed to the standard output.
|
||||
|
||||
Every few seconds, it switches between blocking and non-blocking modes.
|
||||
|
||||
|
||||
[1]: https://sps.honeywell.com/us/en/products/advanced-sensing-technologies/healthcare-sensing/board-mount-pressure-sensors/basic-abp2-series "ABP2 series"
|
||||
165
tests/drivers/abp2/main.c
Normal file
165
tests/drivers/abp2/main.c
Normal file
@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (C) 2024 CNRS, France
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Test application for the Honeywell ABP2 series
|
||||
* pressure and temperature sensor driver.
|
||||
*
|
||||
* @author David Picard <david.picard@clermont.in2p3.fr>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ztimer.h"
|
||||
#include "timex.h"
|
||||
#include "phydat.h"
|
||||
#include "abp2.h"
|
||||
#include "abp2_params.h"
|
||||
#include "saul_reg.h"
|
||||
|
||||
#define STATUS_SLEEP_MS (1)
|
||||
#define MEASUREMENT_SLEEP_MS (1000)
|
||||
#define MAX_LOOPS_STATUS (10)
|
||||
#define MAX_LOOPS_MEAS (3)
|
||||
|
||||
/* supported acquisition modes */
|
||||
enum {
|
||||
ABP2_NON_BLOCKING,
|
||||
ABP2_BLOCKING,
|
||||
ABP2_SAUL
|
||||
} acqmode = ABP2_NON_BLOCKING;
|
||||
|
||||
static abp2_t dev;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int32_t press = 0;
|
||||
int32_t temp = 0;
|
||||
abp2_params_t prms;
|
||||
phydat_t phyPress;
|
||||
phydat_t phyTemp;
|
||||
void *ptr;
|
||||
int cntMeas = 0;
|
||||
saul_reg_t *saulDev = saul_reg;
|
||||
phydat_t saulData;
|
||||
|
||||
puts("ABP2 Honeywell series pressure and temperature sensor\n");
|
||||
|
||||
if (saulDev == NULL) {
|
||||
puts("ERROR: no ABP2_SAUL devices detected");
|
||||
}
|
||||
|
||||
ptr = memcpy(&prms, &abp2_params, sizeof(abp2_params));
|
||||
if (!ptr)
|
||||
{
|
||||
puts("main() >> ERROR: memcpy() failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Initializing SPI bus %d\n", prms.spi);
|
||||
spi_init(prms.spi);
|
||||
|
||||
printf("Initializing ABP2 at SPI_DEV(%i)... ", prms.spi);
|
||||
|
||||
if (abp2_init(&dev, &prms) == 0)
|
||||
{
|
||||
puts("[OK]");
|
||||
}
|
||||
else {
|
||||
puts("[Failed]");
|
||||
return -1;
|
||||
}
|
||||
|
||||
puts("=========================");
|
||||
puts(" Measuring");
|
||||
puts("=========================");
|
||||
|
||||
printf("Pressure range = %d .. %d\n", (int)prms.rangeMin, (int)prms.rangeMax);
|
||||
|
||||
while (1) {
|
||||
int res;
|
||||
|
||||
ztimer_sleep(ZTIMER_USEC, MEASUREMENT_SLEEP_MS * US_PER_MS);
|
||||
switch (acqmode) {
|
||||
case ABP2_NON_BLOCKING:
|
||||
res = abp2_read_nb(&dev, &press, &temp);
|
||||
if (res)
|
||||
{
|
||||
printf("abp2_read_nb() >> ERROR errno = %d", res);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ABP2_BLOCKING:
|
||||
res = abp2_read(&dev, &press, &temp);
|
||||
if (res)
|
||||
{
|
||||
printf("abp2_read() >> ERROR errno = %d", res);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case ABP2_SAUL:
|
||||
while (saulDev) {
|
||||
int dim = saul_reg_read(saulDev, &saulData);
|
||||
printf("\nDev: %s\tType: %s" "\n", saulDev->name,
|
||||
saul_class_to_str(saulDev->driver->type));
|
||||
phydat_dump(&saulData, dim);
|
||||
saulDev = saulDev->next;
|
||||
}
|
||||
saulDev = saul_reg; /* reset pointer for next read */
|
||||
break;
|
||||
default:
|
||||
acqmode = 0;
|
||||
}
|
||||
|
||||
/* display data retrieved in blocking and non-blocking modes: */
|
||||
if (acqmode != ABP2_SAUL) {
|
||||
phyPress.val[0] = press / 100; /* let int32_t fit into int16_t */
|
||||
phyPress.scale = -4; /* and set the exponent accordingly */
|
||||
phyPress.unit = UNIT_BAR; /* set the unit */
|
||||
phydat_dump(&phyPress, 1); /* print the value in a pretty format */
|
||||
|
||||
phyTemp.val[0] = temp; /* temp is already in mdeg C */
|
||||
phyTemp.scale = -3; /* 1 mdegC = 1e-03 degC */
|
||||
phyTemp.unit = UNIT_TEMP_C; /* set the unit */
|
||||
phydat_dump(&phyTemp, 1); /* print the value in a pretty format */
|
||||
}
|
||||
|
||||
/* Switch modes periodically: */
|
||||
cntMeas++;
|
||||
if (cntMeas == MAX_LOOPS_MEAS) {
|
||||
cntMeas = 0;
|
||||
acqmode++;
|
||||
if (acqmode > ABP2_SAUL) {
|
||||
acqmode = 0;
|
||||
}
|
||||
puts("------------------------------");
|
||||
switch (acqmode) {
|
||||
case ABP2_NON_BLOCKING:
|
||||
puts("Switch to non-blocking mode");
|
||||
break;
|
||||
case ABP2_BLOCKING:
|
||||
puts("Switch to blocking mode");
|
||||
break;
|
||||
case ABP2_SAUL:
|
||||
puts("Switch to ABP2_SAUL mode");
|
||||
break;
|
||||
default:
|
||||
acqmode = 0;
|
||||
puts("ERROR: unsupported mode");
|
||||
}
|
||||
puts("------------------------------");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -16,6 +16,9 @@ DRIVERS ?= $(subst _saul.c,,$(notdir $(DRIVERS_WITH_SAUL_PATHS)))
|
||||
USEMODULE += $(DRIVERS)
|
||||
|
||||
# Somes drivers with submodules needs special care to select a precise driver variant
|
||||
ifneq (,$(filter abp2,$(DRIVERS)))
|
||||
USEMODULE += abp2_spi
|
||||
endif
|
||||
ifneq (,$(filter adcxx1c,$(DRIVERS)))
|
||||
USEMODULE += adc081c
|
||||
endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user