Browse Source

drivers/l3g4200d: added SAUL integration

cc430
Hauke Petersen 7 years ago
parent
commit
7a4d6227c4
  1. 36
      drivers/include/l3g4200d.h
  2. 44
      drivers/l3g4200d/l3g4200d_saul.c

36
drivers/include/l3g4200d.h

@ -37,23 +37,12 @@
*/
#define L3G4200D_DEFAULT_ADDRESS 0x68
/**
* @brief Device descriptor for L3G4200D sensors
*/
typedef struct {
i2c_t i2c; /**< I2C device the sensor is connected to */
uint8_t addr; /**< the sensors slave address on the I2C bus */
gpio_t int1; /**< INT1 pin */
gpio_t int2; /**< INT2 (DRDY) pin */
int32_t scale; /**< scaling factor to normalize results */
} l3g4200d_t;
/**
* @brief Result vector for gyro measurement
*/
typedef struct {
int16_t acc_x; /**< roll rate in dgs (degree per second) */
int16_t acc_y; /**< pitch rate in dgs */
int16_t acc_y; /**< pitch rate in dgs */
int16_t acc_z; /**< yaw rate in dgs */
} l3g4200d_data_t;
@ -86,6 +75,29 @@ typedef enum {
L3G4200D_MODE_800_110 = 0xf /**< data rate: 800Hz, cut-off: 110Hz */
} l3g4200d_mode_t;
/**
* @brief Device descriptor for L3G4200D sensors
*/
typedef struct {
i2c_t i2c; /**< I2C device the sensor is connected to */
uint8_t addr; /**< the sensors slave address on the I2C bus */
gpio_t int1; /**< INT1 pin */
gpio_t int2; /**< INT2 (DRDY) pin */
int32_t scale; /**< scaling factor to normalize results */
} l3g4200d_t;
/**
* @brief Data structure holding the device parameters needed for initialization
*/
typedef struct {
i2c_t i2c; /**< I2C bus the device is connected to */
uint8_t addr; /**< the address on that bus */
gpio_t int1_pin; /**< GPIO pin connected to the INT1 line */
gpio_t int2_pin; /**< GPIO pin connected to the INT2 line */
l3g4200d_mode_t mode; /**< sampling mode to use */
l3g4200d_scale_t scale; /**< scaling to use */
} l3g4200d_params_t;
/**
* @brief Initialize a gyro
*

44
drivers/l3g4200d/l3g4200d_saul.c

@ -0,0 +1,44 @@
/*
* 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_isl29020
* @{
*
* @file
* @brief L3G4200D adaption to the RIOT actuator/sensor interface
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include <string.h>
#include "saul.h"
#include "l3g4200d.h"
static int read(void *dev, phydat_t *res)
{
l3g4200d_t *d = (l3g4200d_t *)dev;
l3g4200d_read(d, (l3g4200d_data_t *)res);
res->unit = UNIT_DPS;
res->scale = 0;
return 3;
}
static int write(void *dev, phydat_t *state)
{
return -ENOTSUP;
}
const saul_driver_t l3g4200d_saul_driver = {
.read = read,
.write = write,
.type = SAUL_SENSE_GYRO,
};
Loading…
Cancel
Save