diff --git a/tests/driver_lis2dh12/Makefile b/tests/driver_lis2dh12/Makefile new file mode 100644 index 000000000..0b5d594f7 --- /dev/null +++ b/tests/driver_lis2dh12/Makefile @@ -0,0 +1,10 @@ +include ../Makefile.tests_common + +# as default we use the SPI mode for now, as the I2C mode is not supported, yet +DRIVER ?= lis2dh12_spi + +USEMODULE += fmt +USEMODULE += xtimer +USEMODULE += $(DRIVER) + +include $(RIOTBASE)/Makefile.include diff --git a/tests/driver_lis2dh12/README.md b/tests/driver_lis2dh12/README.md new file mode 100644 index 000000000..9152598c6 --- /dev/null +++ b/tests/driver_lis2dh12/README.md @@ -0,0 +1,11 @@ +# About +This is a manual test application for the LIS2DH12 accelerometer driver. + +# Usage +This test application will initialize the accelerometer with its default +parameters (as defined in `drivers/lis2dh12/include/lis2dh12_params.h`: + - `LIS2DH12_PARAM_SCALE`: 100Hz + - `LIS2DH12_PARAM_RATE`: 2G + +After initialization, the sensor reads the acceleration values every 100ms +and prints them to the STDOUT. diff --git a/tests/driver_lis2dh12/main.c b/tests/driver_lis2dh12/main.c new file mode 100644 index 000000000..0f8721c61 --- /dev/null +++ b/tests/driver_lis2dh12/main.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2018 Freie Universität Berlin + * + * 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 LIS2DH12 accelerometer driver + * + * @author Hauke Petersen + * + * @} + */ + +#include + +#include "fmt.h" +#include "xtimer.h" +#include "lis2dh12.h" +#include "lis2dh12_params.h" + + +#define DELAY (100UL * US_PER_MS) + +/* allocate some memory to hold one formated string for each sensor output, so + * one string for the X, Y, and Z reading, respectively */ +static char str_out[3][8]; + +/* allocate device descriptor */ +static lis2dh12_t dev; + +int main(void) +{ + puts("LIS2DH12 accelerometer driver test application\n"); + + puts("Initializing LIS2DH12 sensor... "); + if (lis2dh12_init(&dev, &lis2dh12_params[0]) == LIS2DH12_OK) { + puts("[OK]"); + } + else { + puts("[Failed]\n"); + return 1; + } + + xtimer_ticks32_t last_wakeup = xtimer_now(); + while (1) { + /* read sensor data */ + int16_t data[3]; + if (lis2dh12_read(&dev, data) != LIS2DH12_OK) { + puts("error: unable to retrieve data from sensor, quitting now"); + return 1; + } + + /* format data */ + for (int i = 0; i < 3; i++) { + size_t len = fmt_s16_dfp(str_out[i], data[i], 3); + str_out[i][len] = '\0'; + } + + /* print data to STDIO */ + printf("X: %8s Y: %8s Z: %8s\n", str_out[0], str_out[1], str_out[2]); + + xtimer_periodic_wakeup(&last_wakeup, DELAY); + } + + return 0; +}