Skip to content

Commit

Permalink
drivers/l3g4200d: added SAUL integration
Browse files Browse the repository at this point in the history
  • Loading branch information
haukepetersen committed Nov 30, 2015
1 parent 1836163 commit 7a4d622
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 12 deletions.
36 changes: 24 additions & 12 deletions drivers/include/l3g4200d.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
*
Expand Down
44 changes: 44 additions & 0 deletions drivers/l3g4200d/l3g4200d_saul.c
Original file line number Diff line number Diff line change
@@ -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,
};

0 comments on commit 7a4d622

Please sign in to comment.