mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/lis2dh12: add SAUL mapping
This commit is contained in:
parent
09dab1a9fb
commit
ba8ab6c88b
@ -33,6 +33,7 @@
|
||||
#ifndef LIS2DH12_H
|
||||
#define LIS2DH12_H
|
||||
|
||||
#include "saul.h"
|
||||
#include "periph/spi.h"
|
||||
#include "periph/gpio.h"
|
||||
|
||||
@ -98,6 +99,11 @@ enum {
|
||||
LIS2DH12_NODEV = -2, /**< unable to talk to device */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Export the SAUL interface for this driver
|
||||
*/
|
||||
extern const saul_driver_t lis2dh12_saul_driver;
|
||||
|
||||
/**
|
||||
* @brief Initialize the given LIS2DH12 sensor device
|
||||
*
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "board.h"
|
||||
#include "lis2dh12.h"
|
||||
#include "saul_reg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -43,10 +44,16 @@ extern "C" {
|
||||
#define LIS2DH12_PARAM_RATE LIS2DH12_RATE_100HZ
|
||||
#endif
|
||||
|
||||
#define LIS2DH12_PARAMS_DEFAULT { .spi = LIS2DH12_PARAM_SPI, \
|
||||
#ifndef LIS2DH12_PARAMS
|
||||
#define LIS2DH12_PARAMS { .spi = LIS2DH12_PARAM_SPI, \
|
||||
.cs = LIS2DH12_PARAM_CS, \
|
||||
.scale = LIS2DH12_PARAM_SCALE, \
|
||||
.rate = LIS2DH12_PARAM_RATE }
|
||||
#endif
|
||||
|
||||
#ifndef LIS2DH12_SAULINFO
|
||||
#define LIS2DH12_SAULINFO { .name = "lis2dh12" }
|
||||
#endif
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
@ -54,11 +61,15 @@ extern "C" {
|
||||
*/
|
||||
static const lis2dh12_params_t lis2dh12_params[] =
|
||||
{
|
||||
#ifdef LIS2DH12_PARAMS_BOARD
|
||||
LIS2DH12_PARAMS_BOARD,
|
||||
#else
|
||||
LIS2DH12_PARAMS_DEFAULT,
|
||||
#endif
|
||||
LIS2DH12_PARAMS
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Additional meta information to keep in the SAUL registry
|
||||
*/
|
||||
static const saul_reg_info_t lis2dh12_saul_info[] =
|
||||
{
|
||||
LIS2DH12_SAULINFO
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
38
drivers/lis2dh12/lis2dh12_saul.c
Normal file
38
drivers/lis2dh12/lis2dh12_saul.c
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 drivers_lis2dh12
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief LIS2DH12 accelerometer SAUL mapping
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "saul.h"
|
||||
#include "lis2dh12.h"
|
||||
|
||||
static int read_accelerometer(const void *dev, phydat_t *res)
|
||||
{
|
||||
if (lis2dh12_read((const lis2dh12_t *)dev, res->val) != LIS2DH12_OK) {
|
||||
return 0;
|
||||
}
|
||||
res->unit = UNIT_G;
|
||||
res->scale = -3;
|
||||
return 3;
|
||||
}
|
||||
|
||||
const saul_driver_t lis2dh12_saul_driver = {
|
||||
.read = read_accelerometer,
|
||||
.write = saul_notsup,
|
||||
.type = SAUL_SENSE_ACCEL
|
||||
};
|
Loading…
Reference in New Issue
Block a user