-
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.
- Loading branch information
Showing
5 changed files
with
160 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,12 @@ | ||
include ../Makefile.drivers_common | ||
|
||
# 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,126 @@ | ||
/* | ||
* 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 ABP2 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" | ||
|
||
#define STATUS_SLEEP_MS (1) | ||
#define MEASUREMENT_SLEEP_MS (1000) | ||
#define MAX_LOOPS_STATUS (10) | ||
#define MAX_LOOPS_MEAS (5) | ||
|
||
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 blockingMode = 1; | ||
int cntMeas = 0; | ||
|
||
puts("ABP2 Honeywell series pressure and temperature sensor\n"); | ||
|
||
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); | ||
|
||
if (blockingMode) { | ||
res = abp2_read(&dev, &press, &temp); | ||
if (res) | ||
{ | ||
printf("abp2_read() >> ERROR errno = %d", res); | ||
continue; | ||
} | ||
} | ||
else { | ||
res = abp2_read_nb(&dev, &press, &temp); | ||
if (res) | ||
{ | ||
printf("abp2_read_nb() >> ERROR errno = %d", res); | ||
continue; | ||
} | ||
} | ||
/* printf() doesn't support %f on all boards. This is where phydat comes in handy. | ||
* The default range in RIOT/drivers/abp2/include/abp2_params.h is 0..160000ubar = 0..160mbar. | ||
*/ | ||
|
||
phyPress.val[0] = press; /* press is already in ubar */ | ||
phyPress.scale = -6; /* 1 ubar = 1e-06 bar */ | ||
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 between blocking and non-blocking modes periodically: */ | ||
cntMeas++; | ||
if (cntMeas == MAX_LOOPS_MEAS) | ||
{ | ||
cntMeas = 0; | ||
blockingMode = 1 - blockingMode; | ||
if(blockingMode) | ||
puts("Switch to blocking mode"); | ||
else | ||
puts("Switch to non-blocking mode"); | ||
} | ||
} | ||
|
||
return 0; | ||
} |