-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/drivers/abp2: test implementation
- Loading branch information
Showing
5 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
BOARD_INSUFFICIENT_MEMORY := \ | ||
atmega8 \ | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
// blockingMode = 1 - blockingMode; | ||
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; | ||
} |