Skip to content

Commit

Permalink
tests/drivers/abp2: test implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dpproto committed Mar 25, 2024
1 parent c1ad1b5 commit b7198cc
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/drivers/abp2/Makefile
Original file line number Diff line number Diff line change
@@ -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_msec
USEMODULE += phydat

include $(RIOTBASE)/Makefile.include
3 changes: 3 additions & 0 deletions tests/drivers/abp2/Makefile.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BOARD_INSUFFICIENT_MEMORY := \
atmega8 \
#
14 changes: 14 additions & 0 deletions tests/drivers/abp2/README.md
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions tests/drivers/abp2/app.config.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# this file enables modules defined in Kconfig. Do not use this file for
# application configuration. This is only needed during migration.
CONFIG_MODULE_ABP2=y
CONFIG_MODULE_ZTIMER=y
CONFIG_MODULE_ZTIMER_MSEC=y
165 changes: 165 additions & 0 deletions tests/drivers/abp2/main.c
Original file line number Diff line number Diff line change
@@ -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 {
NON_BLOCKING,
BLOCKING,
SAUL
} acqmode = 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 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_MSEC, MEASUREMENT_SLEEP_MS);
switch (acqmode) {
case NON_BLOCKING:
res = abp2_read_nb(&dev, &press, &temp);
if (res)
{
printf("abp2_read_nb() >> ERROR errno = %d", res);
continue;
}
break;
case BLOCKING:
res = abp2_read(&dev, &press, &temp);
if (res)
{
printf("abp2_read() >> ERROR errno = %d", res);
continue;
}
break;
case 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 != 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 > SAUL) {
acqmode = 0;
}
puts("------------------------------");
switch (acqmode) {
case NON_BLOCKING:
puts("Switch to non-blocking mode");
break;
case BLOCKING:
puts("Switch to blocking mode");
break;
case SAUL:
puts("Switch to SAUL mode");
break;
default:
acqmode = 0;
puts("ERROR: unsupported mode");
}
puts("------------------------------");
}
}
return 0;
}
3 changes: 3 additions & 0 deletions tests/drivers/saul_drivers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b7198cc

Please sign in to comment.