drivers/lsm303dlhc: added SAUL integration
This commit is contained in:
parent
5274c4e851
commit
84a094d092
@ -35,26 +35,6 @@ extern "C" {
|
|||||||
#define LSM303DLHC_ACC_DEFAULT_ADDRESS (0x19)
|
#define LSM303DLHC_ACC_DEFAULT_ADDRESS (0x19)
|
||||||
#define LSM303DLHC_MAG_DEFAULT_ADDRESS (0x1e)
|
#define LSM303DLHC_MAG_DEFAULT_ADDRESS (0x1e)
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief 3d data container
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
int16_t x_axis;
|
|
||||||
int16_t y_axis;
|
|
||||||
int16_t z_axis;
|
|
||||||
} lsm303dlhc_3d_data_t;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Device descriptor for LSM303DLHC sensors
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
i2c_t i2c; /**< I2C device */
|
|
||||||
uint8_t acc_address; /**< accelerometer's I2C address */
|
|
||||||
uint8_t mag_address; /**< magnetometer's I2C address */
|
|
||||||
gpio_t acc_pin; /**< accelerometer's data ready pin */
|
|
||||||
gpio_t mag_pin; /**< magnetometer's data ready pin */
|
|
||||||
} lsm303dlhc_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Possible accelerometer sample rates
|
* @brief Possible accelerometer sample rates
|
||||||
*/
|
*/
|
||||||
@ -108,6 +88,41 @@ typedef enum {
|
|||||||
LSM303DLHC_MAG_GAIN_230_205_GAUSS = 0xe0, /**< 230Gauss XYZ 205Gauss Z */
|
LSM303DLHC_MAG_GAIN_230_205_GAUSS = 0xe0, /**< 230Gauss XYZ 205Gauss Z */
|
||||||
} lsm303dlhc_mag_gain_t;
|
} lsm303dlhc_mag_gain_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 3d data container
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
int16_t x_axis;
|
||||||
|
int16_t y_axis;
|
||||||
|
int16_t z_axis;
|
||||||
|
} lsm303dlhc_3d_data_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Device descriptor for LSM303DLHC sensors
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
i2c_t i2c; /**< I2C device */
|
||||||
|
uint8_t acc_address; /**< accelerometer's I2C address */
|
||||||
|
uint8_t mag_address; /**< magnetometer's I2C address */
|
||||||
|
gpio_t acc_pin; /**< accelerometer's data ready pin */
|
||||||
|
gpio_t mag_pin; /**< magnetometer's data ready pin */
|
||||||
|
} lsm303dlhc_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Data structure holding all the information needed for initialization
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
i2c_t i2c; /**< I2C bus used */
|
||||||
|
uint8_t acc_addr; /**< accelerometer I2C address */
|
||||||
|
gpio_t acc_pin; /**< accelerometer EXTI pin */
|
||||||
|
lsm303dlhc_acc_sample_rate_t acc_rate; /**< accelerometer sample rate */
|
||||||
|
lsm303dlhc_acc_scale_t acc_scale; /**< accelerometer scale factor */
|
||||||
|
uint8_t mag_addr; /**< magnetometer I2C address */
|
||||||
|
gpio_t mag_pin; /**< magnetometer EXTI pin */
|
||||||
|
lsm303dlhc_mag_sample_rate_t mag_rate; /**< magnetometer sample rate */
|
||||||
|
lsm303dlhc_mag_gain_t mag_gain; /**< magnetometer gain */
|
||||||
|
} lsm303dlhc_params_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialize a new LSM303DLHC device
|
* @brief Initialize a new LSM303DLHC device
|
||||||
*
|
*
|
||||||
|
|||||||
59
drivers/lsm303dlhc/lsm303dlhc_saul.c
Normal file
59
drivers/lsm303dlhc/lsm303dlhc_saul.c
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 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 driver_lsm303dlhc
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief LSM303DLHC adaption to the RIOT actuator/sensor interface
|
||||||
|
*
|
||||||
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "saul.h"
|
||||||
|
#include "lsm303dlhc.h"
|
||||||
|
|
||||||
|
static int read_acc(void *dev, phydat_t *res)
|
||||||
|
{
|
||||||
|
lsm303dlhc_t *d = (lsm303dlhc_t *)dev;
|
||||||
|
lsm303dlhc_read_acc(d, (lsm303dlhc_3d_data_t *)res);
|
||||||
|
res->unit = UNIT_G;
|
||||||
|
res->scale = 0;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read_mag(void *dev, phydat_t *res)
|
||||||
|
{
|
||||||
|
lsm303dlhc_t *d = (lsm303dlhc_t *)dev;
|
||||||
|
lsm303dlhc_read_mag(d, (lsm303dlhc_3d_data_t *)res);
|
||||||
|
res->unit = UNIT_GS;
|
||||||
|
res->scale = 0;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int write(void *dev, phydat_t *state)
|
||||||
|
{
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
const saul_driver_t lsm303dlhc_saul_acc_driver = {
|
||||||
|
.read = read_acc,
|
||||||
|
.write = write,
|
||||||
|
.type = SAUL_SENSE_ACCEL,
|
||||||
|
};
|
||||||
|
|
||||||
|
const saul_driver_t lsm303dlhc_saul_mag_driver = {
|
||||||
|
.read = read_mag,
|
||||||
|
.write = write,
|
||||||
|
.type = SAUL_SENSE_MAG,
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user