Skip to content

Commit 549c360

Browse files
committed
Implement a test for the driver.
1 parent 7163cb5 commit 549c360

File tree

5 files changed

+167
-0
lines changed

5 files changed

+167
-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: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (C) 2024 CNRS
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+
#ifdef BOARD_NUCLEO_L031K6
58+
/* change chip select pin: */
59+
prms.cs = GPIO_PIN(PORT_A, 11);
60+
#endif
61+
62+
printf("Initializing SPI bus %d\n", prms.spi);
63+
spi_init(prms.spi);
64+
65+
printf("Initializing ABP2 at SPI_DEV(%i)... ", prms.spi);
66+
67+
if (abp2_init(&dev, &prms) == 0)
68+
{
69+
puts("[OK]");
70+
}
71+
else {
72+
puts("[Failed]");
73+
return -1;
74+
}
75+
#ifdef BOARD_NUCLEO_L031K6
76+
ztimer_sleep(ZTIMER_MSEC, 5000);
77+
#endif
78+
puts("=========================");
79+
puts(" Measuring");
80+
puts("=========================");
81+
82+
printf("Pressure range = %d .. %d\n", (int)prms.rangeMin, (int)prms.rangeMax);
83+
84+
while (1) {
85+
int res;
86+
87+
ztimer_sleep(ZTIMER_MSEC, MEASUREMENT_SLEEP_MS);
88+
89+
if (blockingMode) {
90+
res = abp2_read(&dev, &press, &temp);
91+
if (res)
92+
{
93+
printf("abp2_read() >> ERROR errno = %d", res);
94+
continue;
95+
}
96+
}
97+
else {
98+
res = abp2_read_nb(&dev, &press, &temp);
99+
if (res)
100+
{
101+
printf("abp2_read_nb() >> ERROR errno = %d", res);
102+
continue;
103+
}
104+
}
105+
/* printf() doesn't support %f on all boards. This is where phydat comes in handy.
106+
* The default range in RIOT/drivers/abp2/include/abp2_params.h is 0..160000ubar = 0..160mbar.
107+
*/
108+
109+
phyPress.val[0] = press; /* press is already in ubar */
110+
phyPress.scale = -6; /* 1 ubar = 1e-06 bar */
111+
phyPress.unit = UNIT_BAR; /* set the unit */
112+
phydat_dump(&phyPress, 1); /* print the value in a pretty format */
113+
114+
phyTemp.val[0] = temp; /* temp is already in mdeg C */
115+
phyTemp.scale = -3; /* 1 mdegC = 1e-03 degC */
116+
phyTemp.unit = UNIT_TEMP_C; /* set the unit */
117+
phydat_dump(&phyTemp, 1); /* print the value in a pretty format */
118+
119+
/* Switch between blocking and non-blocking modes periodically: */
120+
cntMeas++;
121+
if (cntMeas == MAX_LOOPS_MEAS)
122+
{
123+
cntMeas = 0;
124+
blockingMode = 1 - blockingMode;
125+
if(blockingMode)
126+
puts("Switch to blocking mode");
127+
else
128+
puts("Switch to non-blocking mode");
129+
}
130+
}
131+
132+
return 0;
133+
}

0 commit comments

Comments
 (0)