Skip to content

Commit 193a70f

Browse files
committed
tests/drivers/abp2: test implementation
1 parent 664d769 commit 193a70f

File tree

6 files changed

+205
-0
lines changed

6 files changed

+205
-0
lines changed

tests/drivers/abp2/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include ../Makefile.drivers_common
2+
3+
# include and auto-initialize all available sensors
4+
USEMODULE += saul_default
5+
6+
# use abp2_spi for SPI-Mode and abp2_i2c for I2C-Mode
7+
USEMODULE += abp2
8+
ABP2_INTERFACE ?= abp2_spi
9+
USEMODULE += $(ABP2_INTERFACE)
10+
11+
USEMODULE += ztimer
12+
USEMODULE += ztimer_msec
13+
USEMODULE += phydat
14+
15+
include $(RIOTBASE)/Makefile.include

tests/drivers/abp2/Makefile.ci

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BOARD_INSUFFICIENT_MEMORY := \
2+
atmega8 \
3+
#

tests/drivers/abp2/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# About
2+
3+
This is a test application for the Honeywell [ABP2 series][1] pressure and temperature sensor.
4+
5+
# Usage
6+
7+
This test application initializes the sensor and measures pressure and
8+
temperature periodically.
9+
The results are printed to the standard output.
10+
11+
Every few seconds, it switches between blocking and non-blocking modes.
12+
13+
14+
[1]: https://sps.honeywell.com/us/en/products/advanced-sensing-technologies/healthcare-sensing/board-mount-pressure-sensors/basic-abp2-series "ABP2 series"

tests/drivers/abp2/app.config.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# this file enables modules defined in Kconfig. Do not use this file for
2+
# application configuration. This is only needed during migration.
3+
CONFIG_MODULE_ABP2=y
4+
CONFIG_MODULE_ZTIMER=y
5+
CONFIG_MODULE_ZTIMER_MSEC=y

tests/drivers/abp2/main.c

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* Copyright (C) 2024 CNRS, France
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup tests
11+
* @{
12+
*
13+
* @file
14+
* @brief Test application for the Honeywell ABP2 series
15+
* pressure and temperature sensor driver.
16+
*
17+
* @author David Picard <[email protected]>
18+
* @}
19+
*/
20+
21+
#include <stdio.h>
22+
#include <string.h>
23+
24+
#include "ztimer.h"
25+
#include "timex.h"
26+
#include "phydat.h"
27+
#include "abp2.h"
28+
#include "abp2_params.h"
29+
#include "saul_reg.h"
30+
31+
#define STATUS_SLEEP_MS (1)
32+
#define MEASUREMENT_SLEEP_MS (1000)
33+
#define MAX_LOOPS_STATUS (10)
34+
#define MAX_LOOPS_MEAS (3)
35+
36+
/* supported acquisition modes */
37+
enum {
38+
NON_BLOCKING,
39+
BLOCKING,
40+
SAUL
41+
} acqmode = NON_BLOCKING;
42+
43+
static abp2_t dev;
44+
45+
int main(void)
46+
{
47+
int32_t press = 0;
48+
int32_t temp = 0;
49+
abp2_params_t prms;
50+
phydat_t phyPress;
51+
phydat_t phyTemp;
52+
void *ptr;
53+
int cntMeas = 0;
54+
saul_reg_t *saulDev = saul_reg;
55+
phydat_t saulData;
56+
57+
puts("ABP2 Honeywell series pressure and temperature sensor\n");
58+
59+
if (saulDev == NULL) {
60+
puts("ERROR: no SAUL devices detected");
61+
}
62+
63+
ptr = memcpy(&prms, &abp2_params, sizeof(abp2_params));
64+
if (!ptr)
65+
{
66+
puts("main() >> ERROR: memcpy() failed");
67+
return 1;
68+
}
69+
70+
printf("Initializing SPI bus %d\n", prms.spi);
71+
spi_init(prms.spi);
72+
73+
printf("Initializing ABP2 at SPI_DEV(%i)... ", prms.spi);
74+
75+
if (abp2_init(&dev, &prms) == 0)
76+
{
77+
puts("[OK]");
78+
}
79+
else {
80+
puts("[Failed]");
81+
return -1;
82+
}
83+
84+
puts("=========================");
85+
puts(" Measuring");
86+
puts("=========================");
87+
88+
printf("Pressure range = %d .. %d\n", (int)prms.rangeMin, (int)prms.rangeMax);
89+
90+
while (1) {
91+
int res;
92+
93+
ztimer_sleep(ZTIMER_MSEC, MEASUREMENT_SLEEP_MS);
94+
switch (acqmode) {
95+
case NON_BLOCKING:
96+
res = abp2_read_nb(&dev, &press, &temp);
97+
if (res)
98+
{
99+
printf("abp2_read_nb() >> ERROR errno = %d", res);
100+
continue;
101+
}
102+
break;
103+
case BLOCKING:
104+
res = abp2_read(&dev, &press, &temp);
105+
if (res)
106+
{
107+
printf("abp2_read() >> ERROR errno = %d", res);
108+
continue;
109+
}
110+
break;
111+
case SAUL:
112+
while (saulDev) {
113+
int dim = saul_reg_read(saulDev, &saulData);
114+
printf("\nDev: %s\tType: %s" "\n", saulDev->name,
115+
saul_class_to_str(saulDev->driver->type));
116+
phydat_dump(&saulData, dim);
117+
saulDev = saulDev->next;
118+
}
119+
saulDev = saul_reg; /* reset pointer for next read */
120+
break;
121+
default:
122+
acqmode = 0;
123+
}
124+
125+
/* display data retrieved in blocking and non-blocking modes: */
126+
if (acqmode != SAUL) {
127+
phyPress.val[0] = press / 100; /* let int32_t fit into int16_t */
128+
phyPress.scale = -4; /* and set the exponent accordingly */
129+
phyPress.unit = UNIT_BAR; /* set the unit */
130+
phydat_dump(&phyPress, 1); /* print the value in a pretty format */
131+
132+
phyTemp.val[0] = temp; /* temp is already in mdeg C */
133+
phyTemp.scale = -3; /* 1 mdegC = 1e-03 degC */
134+
phyTemp.unit = UNIT_TEMP_C; /* set the unit */
135+
phydat_dump(&phyTemp, 1); /* print the value in a pretty format */
136+
}
137+
138+
/* Switch modes periodically: */
139+
cntMeas++;
140+
if (cntMeas == MAX_LOOPS_MEAS) {
141+
cntMeas = 0;
142+
acqmode++;
143+
if (acqmode > SAUL) {
144+
acqmode = 0;
145+
}
146+
puts("------------------------------");
147+
switch (acqmode) {
148+
case NON_BLOCKING:
149+
puts("Switch to non-blocking mode");
150+
break;
151+
case BLOCKING:
152+
puts("Switch to blocking mode");
153+
break;
154+
case SAUL:
155+
puts("Switch to SAUL mode");
156+
break;
157+
default:
158+
acqmode = 0;
159+
puts("ERROR: unsupported mode");
160+
}
161+
puts("------------------------------");
162+
}
163+
}
164+
return 0;
165+
}

tests/drivers/saul_drivers/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ DRIVERS ?= $(subst _saul.c,,$(notdir $(DRIVERS_WITH_SAUL_PATHS)))
1616
USEMODULE += $(DRIVERS)
1717

1818
# Somes drivers with submodules needs special care to select a precise driver variant
19+
ifneq (,$(filter abp2,$(DRIVERS)))
20+
USEMODULE += abp2_spi
21+
endif
1922
ifneq (,$(filter adcxx1c,$(DRIVERS)))
2023
USEMODULE += adc081c
2124
endif

0 commit comments

Comments
 (0)