Browse Source

tests/mma8x5x: adapted test for driver changes

pr/spi.typo
Hauke Petersen 6 years ago
parent
commit
db24f5e140
  1. 25
      tests/driver_mma8652/Makefile
  2. 10
      tests/driver_mma8652/README.md
  3. 79
      tests/driver_mma8652/main.c
  4. 9
      tests/driver_mma8x5x/Makefile
  5. 18
      tests/driver_mma8x5x/README.md
  6. 57
      tests/driver_mma8x5x/main.c

25
tests/driver_mma8652/Makefile

@ -1,25 +0,0 @@
APPLICATION = driver_mma8652
include ../Makefile.tests_common
FEATURES_REQUIRED = periph_i2c
USEMODULE += mma8652
USEMODULE += xtimer
# set default device parameters in case they are undefined
TEST_MMA8652_I2C ?= I2C_DEV\(0\)
TEST_MMA8652_ADDR ?= 0x1D
TEST_MMA8652_USER_OFFSET_X ?= 0
TEST_MMA8652_USER_OFFSET_Y ?= 0
TEST_MMA8652_USER_OFFSET_Z ?= 0
TEST_MMA8x5x_TYPE ?= MMA8x5x_TYPE_MMA8652
# export parameters
CFLAGS += -DTEST_MMA8652_I2C=$(TEST_MMA8652_I2C)
CFLAGS += -DTEST_MMA8652_ADDR=$(TEST_MMA8652_ADDR)
CFLAGS += -DTEST_MMA8652_USER_OFFSET_X=$(TEST_MMA8652_USER_OFFSET_X)
CFLAGS += -DTEST_MMA8652_USER_OFFSET_Y=$(TEST_MMA8652_USER_OFFSET_Y)
CFLAGS += -DTEST_MMA8652_USER_OFFSET_Z=$(TEST_MMA8652_USER_OFFSET_Z)
CFLAGS += -DTEST_MMA8x5x_TYPE=$(TEST_MMA8x5x_TYPE)
include $(RIOTBASE)/Makefile.include

10
tests/driver_mma8652/README.md

@ -1,10 +0,0 @@
# About
This is a manual test application for the MMA8652 accelerometer driver.
# Usage
This test application will initialize the MMA8652 sensor with the following parameters:
- full scale parameter set to +/-2 g
- 6.25 Hz output data-rate
After initialization, the sensor reads the x-, y-, z-axis values every 1 s
and prints them to STDOUT.

79
tests/driver_mma8652/main.c

@ -1,79 +0,0 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2014 PHYTEC Messtechnik GmbH
*
* 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 MMA8652 accelerometer driver.
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Johann Fischer <j.fischer@phytec.de>
*
* @}
*/
#ifndef TEST_MMA8652_I2C
#error "TEST_MMA8652_I2C not defined"
#endif
#ifndef TEST_MMA8652_ADDR
#error "TEST_MMA8652_ADDR not defined"
#endif
#ifndef TEST_MMA8x5x_TYPE
#error "TEST_MMA8x5x_TYPE not defined"
#endif
#include <stdio.h>
#include "xtimer.h"
#include "mma8652.h"
#define SLEEP (1000 * 1000U)
int main(void)
{
mma8652_t dev;
int16_t x, y, z;
uint8_t status;
puts("MMA8652 accelerometer driver test application\n");
printf("Initializing MMA8652 accelerometer at I2C_%i... ", TEST_MMA8652_I2C);
if (mma8652_init(&dev, TEST_MMA8652_I2C, TEST_MMA8652_ADDR,
MMA8652_DATARATE_DEFAULT,
MMA8652_FS_RANGE_DEFAULT,
TEST_MMA8x5x_TYPE) == 0) {
puts("[OK]\n");
}
else {
puts("[Failed]");
return -1;
}
if (mma8652_set_user_offset(&dev, TEST_MMA8652_USER_OFFSET_X,
TEST_MMA8652_USER_OFFSET_Y,
TEST_MMA8652_USER_OFFSET_Z)) {
puts("Set user offset correction failed.");
return -1;
}
if (mma8652_set_active(&dev)) {
puts("Measurement start failed.");
return -1;
}
while (1) {
mma8652_read(&dev, &x, &y, &z, &status);
printf("Acceleration, in mg: X: %d Y: %d Z: %d S: %2x\n", x, y, z, status);
xtimer_usleep(SLEEP);
}
return 0;
}

9
tests/driver_mma8x5x/Makefile

@ -0,0 +1,9 @@
APPLICATION = driver_mma8x5x
include ../Makefile.tests_common
FEATURES_REQUIRED = periph_i2c
USEMODULE += mma8x5x
USEMODULE += xtimer
include $(RIOTBASE)/Makefile.include

18
tests/driver_mma8x5x/README.md

@ -0,0 +1,18 @@
# About
This is a manual test application for the MMA8x5x accelerometer driver.
# Usage
This test application will initialize the MMA8x5x sensor with the following parameters:
- default device type: MMA8652
- full scale parameter set to +/-2 g
- 200 Hz output data-rate
To change these parameters, you can override them by setting their corresponding
defines in your build environment, e.g.
```bash
CFLAGS=-DMMA8X5X_PARAM_TYPE=MMA8X5X_TYPE_MMA8451 make ...
```
See RIOT/drivers/mma8x5x_params.h for the default configuration.
After initialization, the sensor reads the x-, y-, z-axis values every 100ms
and prints them to STDOUT.

57
tests/driver_mma8x5x/main.c

@ -0,0 +1,57 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2014 PHYTEC Messtechnik GmbH
*
* 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 MMA8652 accelerometer driver.
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Johann Fischer <j.fischer@phytec.de>
*
* @}
*/
#include <stdio.h>
#include "xtimer.h"
#include "mma8x5x.h"
#include "mma8x5x_params.h"
#define SLEEP (100 * 1000U)
static mma8x5x_t dev;
int main(void)
{
mma8x5x_data_t data;
puts("MMA8652 accelerometer driver test application\n");
printf("Initializing MMA8652 accelerometer at I2C_DEV(%i)... ",
mma8x5x_params->i2c);
if (mma8x5x_init(&dev, mma8x5x_params) == MMA8X5X_OK) {
puts("[OK]\n");
}
else {
puts("[Failed]");
return -1;
}
while (1) {
mma8x5x_read(&dev, &data);
printf("Acceleration [in mg]: X: %d Y: %d Z: %d\n",
data.x, data.y, data.z);
xtimer_usleep(SLEEP);
}
return 0;
}
Loading…
Cancel
Save