|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2015 Eistec AB |
|
|
|
|
* 2017 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 |
|
|
|
@ -13,55 +14,20 @@
|
|
|
|
|
* @file |
|
|
|
|
* @brief Test application for the LIS3DH accelerometer driver |
|
|
|
|
* |
|
|
|
|
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se |
|
|
|
|
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se> |
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de> |
|
|
|
|
* |
|
|
|
|
* @} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
|
|
#include "board.h" |
|
|
|
|
#include "xtimer.h" |
|
|
|
|
#include "periph/spi.h" |
|
|
|
|
#include "periph/gpio.h" |
|
|
|
|
#include "lis3dh.h" |
|
|
|
|
#include "lis3dh_params.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Check for definition of hardware pins, default to board.h values if not set. */ |
|
|
|
|
#ifndef TEST_LIS3DH_SPI |
|
|
|
|
#ifdef LIS3DH_SPI |
|
|
|
|
#define TEST_LIS3DH_SPI LIS3DH_SPI |
|
|
|
|
#else |
|
|
|
|
#error "TEST_LIS3DH_SPI not defined" |
|
|
|
|
#endif |
|
|
|
|
#endif |
|
|
|
|
#ifndef TEST_LIS3DH_CS |
|
|
|
|
#ifdef LIS3DH_CS |
|
|
|
|
#define TEST_LIS3DH_CS LIS3DH_CS |
|
|
|
|
#else |
|
|
|
|
#error "TEST_LIS3DH_CS not defined" |
|
|
|
|
#endif |
|
|
|
|
#endif |
|
|
|
|
#ifndef TEST_LIS3DH_INT1 |
|
|
|
|
#ifdef LIS3DH_INT1 |
|
|
|
|
#define TEST_LIS3DH_INT1 LIS3DH_INT1 |
|
|
|
|
#else |
|
|
|
|
#error "TEST_LIS3DH_INT1 not defined" |
|
|
|
|
#endif |
|
|
|
|
#endif |
|
|
|
|
#ifndef TEST_LIS3DH_INT2 |
|
|
|
|
#ifdef LIS3DH_INT2 |
|
|
|
|
#define TEST_LIS3DH_INT2 LIS3DH_INT2 |
|
|
|
|
#else |
|
|
|
|
#error "TEST_LIS3DH_INT2 not defined" |
|
|
|
|
#endif |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SCALE 4 |
|
|
|
|
#define ODR LIS3DH_ODR_100Hz |
|
|
|
|
#define SLEEP (100 * 1000U) |
|
|
|
|
#define SPI_CONF (SPI_CONF_SECOND_FALLING) |
|
|
|
|
#define SPI_CLK (SPI_CLK_10MHZ) |
|
|
|
|
|
|
|
|
|
#define WATERMARK_LEVEL 16 |
|
|
|
|
|
|
|
|
@ -81,7 +47,7 @@ int main(void)
|
|
|
|
|
puts("LIS3DH accelerometer driver test application\n"); |
|
|
|
|
|
|
|
|
|
puts("Initializing LIS3DH sensor... "); |
|
|
|
|
if (lis3dh_init(&dev, TEST_LIS3DH_SPI, SPI_CLK, TEST_LIS3DH_CS, SCALE) == 0) { |
|
|
|
|
if (lis3dh_init(&dev, &lis3dh_params[0]) == 0) { |
|
|
|
|
puts("[OK]"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
@ -90,7 +56,7 @@ int main(void)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
puts("Set ODR... "); |
|
|
|
|
if (lis3dh_set_odr(&dev, ODR) == 0) { |
|
|
|
|
if (lis3dh_set_odr(&dev, lis3dh_params[0].odr) == 0) { |
|
|
|
|
puts("[OK]"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
@ -99,7 +65,7 @@ int main(void)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
puts("Set scale... "); |
|
|
|
|
if (lis3dh_set_scale(&dev, SCALE) == 0) { |
|
|
|
|
if (lis3dh_set_scale(&dev, lis3dh_params[0].scale) == 0) { |
|
|
|
|
puts("[OK]"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
@ -144,7 +110,8 @@ int main(void)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
puts("Set INT1 callback"); |
|
|
|
|
if (gpio_init_int(TEST_LIS3DH_INT1, GPIO_IN, GPIO_RISING, test_int1, (void*)&int1_count) == 0) { |
|
|
|
|
if (gpio_init_int(lis3dh_params[0].int1, GPIO_IN, GPIO_RISING, |
|
|
|
|
test_int1, (void*)&int1_count) == 0) { |
|
|
|
|
puts("[OK]"); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
@ -172,7 +139,7 @@ int main(void)
|
|
|
|
|
puts("[Failed]\n"); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
int1 = gpio_read(TEST_LIS3DH_INT1); |
|
|
|
|
int1 = gpio_read(lis3dh_params[0].int1); |
|
|
|
|
printf("X: %6d Y: %6d Z: %6d Temp: %6d, INT1: %08x\n", |
|
|
|
|
acc_data.acc_x, acc_data.acc_y, acc_data.acc_z, temperature, int1); |
|
|
|
|
--fifo_level; |
|
|
|
|