Skip to content

Commit 93c1983

Browse files
committed
tests/drivers/abp2: test implementation
1 parent 8636ec8 commit 93c1983

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed

tests/drivers/abp2/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
include ../Makefile.drivers_common
2+
3+
# use abp2_spi for SPI-Mode and abp2_i2c for I2C-Mode
4+
USEMODULE += abp2
5+
ABP2_INTERFACE ?= abp2_spi
6+
USEMODULE += $(ABP2_INTERFACE)
7+
8+
USEMODULE += ztimer
9+
USEMODULE += ztimer_msec
10+
USEMODULE += phydat
11+
12+
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: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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 ABP2 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+
30+
#define STATUS_SLEEP_MS (1)
31+
#define MEASUREMENT_SLEEP_MS (1000)
32+
#define MAX_LOOPS_STATUS (10)
33+
#define MAX_LOOPS_MEAS (5)
34+
35+
static abp2_t dev;
36+
37+
int main(void)
38+
{
39+
int32_t press = 0;
40+
int32_t temp = 0;
41+
abp2_params_t prms;
42+
phydat_t phyPress;
43+
phydat_t phyTemp;
44+
void *ptr;
45+
int blockingMode = 1;
46+
int cntMeas = 0;
47+
48+
puts("ABP2 Honeywell series pressure and temperature sensor\n");
49+
50+
ptr = memcpy(&prms, &abp2_params, sizeof(abp2_params));
51+
if(!ptr)
52+
{
53+
puts("main() >> ERROR: memcpy() failed");
54+
return 1;
55+
}
56+
57+
printf("Initializing SPI bus %d\n", prms.spi);
58+
spi_init(prms.spi);
59+
60+
printf("Initializing ABP2 at SPI_DEV(%i)... ", prms.spi);
61+
62+
if (abp2_init(&dev, &prms) == 0)
63+
{
64+
puts("[OK]");
65+
}
66+
else {
67+
puts("[Failed]");
68+
return -1;
69+
}
70+
71+
puts("=========================");
72+
puts(" Measuring");
73+
puts("=========================");
74+
75+
printf("Pressure range = %d .. %d\n", (int)prms.rangeMin, (int)prms.rangeMax);
76+
77+
while (1) {
78+
int res;
79+
80+
ztimer_sleep(ZTIMER_MSEC, MEASUREMENT_SLEEP_MS);
81+
82+
if (blockingMode) {
83+
res = abp2_read(&dev, &press, &temp);
84+
if (res)
85+
{
86+
printf("abp2_read() >> ERROR errno = %d", res);
87+
continue;
88+
}
89+
}
90+
else {
91+
res = abp2_read_nb(&dev, &press, &temp);
92+
if (res)
93+
{
94+
printf("abp2_read_nb() >> ERROR errno = %d", res);
95+
continue;
96+
}
97+
}
98+
/* printf() doesn't support %f on all boards. This is where phydat comes in handy.
99+
* The default range in RIOT/drivers/abp2/include/abp2_params.h is 0..160000ubar = 0..160mbar.
100+
*/
101+
102+
phyPress.val[0] = press; /* press is already in ubar */
103+
phyPress.scale = -6; /* 1 ubar = 1e-06 bar */
104+
phyPress.unit = UNIT_BAR; /* set the unit */
105+
phydat_dump(&phyPress, 1); /* print the value in a pretty format */
106+
107+
phyTemp.val[0] = temp; /* temp is already in mdeg C */
108+
phyTemp.scale = -3; /* 1 mdegC = 1e-03 degC */
109+
phyTemp.unit = UNIT_TEMP_C; /* set the unit */
110+
phydat_dump(&phyTemp, 1); /* print the value in a pretty format */
111+
112+
/* Switch between blocking and non-blocking modes periodically: */
113+
cntMeas++;
114+
if (cntMeas == MAX_LOOPS_MEAS)
115+
{
116+
cntMeas = 0;
117+
blockingMode = 1 - blockingMode;
118+
if(blockingMode)
119+
puts("Switch to blocking mode");
120+
else
121+
puts("Switch to non-blocking mode");
122+
}
123+
}
124+
125+
return 0;
126+
}

0 commit comments

Comments
 (0)