Loading...
Searching...
No Matches

Device Driver for ST L3Gxxxx 3-axis gyroscope sensor family. More...

Detailed Description

Device Driver for ST L3Gxxxx 3-axis gyroscope sensor family.

Definition in file l3gxxxx.h.

#include <stdbool.h>
#include <stdint.h>
#include "mutex.h"
#include "periph/gpio.h"
#include "periph/i2c.h"
#include "periph/spi.h"
#include "l3gxxxx_regs.h"
+ Include dependency graph for l3gxxxx.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  l3gxxxx_int_event_cfg_t
 Event interrupt generator configuration (axis movement and wake-up) More...
 
union  l3gxxxx_int_event_src_t
 Event interrupt sources (axis movement and wake-up) More...
 
union  l3gxxxx_int_data_src_t
 Data interrupt sources (data ready and FIFO status) More...
 
struct  l3gxxxx_int_src_t
 Composite type for all possible interrupt sources. More...
 
struct  l3gxxxx_raw_data_t
 Raw output data set as two's complements. More...
 
struct  l3gxxxx_data_t
 Angular rates in millidegrees per seconds (mdps) More...
 
struct  l3gxxxx_i2c_params_t
 L3Gxxxx I2C interface parameters. More...
 
struct  l3gxxxx_spi_params_t
 L3Gxxxx SPI interface parameters. More...
 
struct  l3gxxxx_if_params_t
 L3Gxxxx Hardware interface parameters union. More...
 
struct  l3gxxxx_params_t
 L3Gxxxx device initialization parameters. More...
 
struct  l3gxxxx_t
 L3Gxxxx sensor device data structure type. More...
 

Macros

#define L3GXXXX_INT_DATA
 Data interrupts (Data ready and FIFO status)
 

Typedefs

typedef l3gxxxx_raw_data_t l3gxxxx_raw_data_fifo_t[32]
 Raw output data FIFO type.
 
typedef l3gxxxx_data_t l3gxxxx_data_fifo_t[32]
 Angular rates FIFO type.
 

Enumerations

enum  l3gxxxx_error_codes_t {
  L3GXXXX_OK , L3GXXXX_ERROR_I2C , L3GXXXX_ERROR_SPI , L3GXXXX_ERROR_WRONG_CHIP_ID ,
  L3GXXXX_ERROR_INV_DEV , L3GXXXX_ERROR_INV_MODE , L3GXXXX_ERROR_INV_FIFO_MODE , L3GXXXX_ERROR_INV_INT_TYPE ,
  L3GXXXX_ERROR_NO_NEW_DATA , L3GXXXX_ERROR_RAW_DATA , L3GXXXX_ERROR_RAW_DATA_FIFO , L3GXXXX_ERROR_NO_INT1_PIN ,
  L3GXXXX_ERROR_NO_INT2_PIN , L3GXXXX_ERROR_BYPASS_MODE , L3GXXXX_ERROR_FIFO_MODE
}
 Definition of error codes. More...
 
enum  l3gxxxx_odr_t {
  L3GXXXX_ODR_100_12 = 0x00 , L3GXXXX_ODR_100_25 = 0x01 , L3GXXXX_ODR_200_12 = 0x04 , L3GXXXX_ODR_200_25 = 0x05 ,
  L3GXXXX_ODR_200_50 = 0x06 , L3GXXXX_ODR_200_70 = 0x07 , L3GXXXX_ODR_400_20 = 0x08 , L3GXXXX_ODR_400_25 = 0x09 ,
  L3GXXXX_ODR_400_50 = 0x0a , L3GXXXX_ODR_400_110 = 0x0b , L3GXXXX_ODR_800_30 = 0x0c , L3GXXXX_ODR_800_35 = 0x0d ,
  L3GXXXX_ODR_800_50 = 0x0e , L3GXXXX_ODR_800_100 = 0x0f , L3GXXXX_ODR_12 = 0x10 , L3GXXXX_ODR_25 = 0x14 ,
  L3GXXXX_ODR_50 = 0x18
}
 Sensor output data rates (ODR) and LPF2 cutoff frequencies. More...
 
enum  l3gxxxx_scale_t { L3GXXXX_SCALE_245_DPS = 0 , L3GXXXX_SCALE_500_DPS = 1 , L3GXXXX_SCALE_2000_DPS = 2 }
 Full scale in degrees per second (dps) More...
 
enum  l3gxxxx_fifo_mode_t {
  L3GXXXX_BYPASS = 0 , L3GXXXX_FIFO = 1 , L3GXXXX_STREAM = 2 , L3GXXXX_STREAM_TO_FIFO = 3 ,
  L3GXXXX_BYPASS_TO_STREAM = 4 , L3GXXXX_DYNAMIC_STREAM = 6 , L3GXXXX_BYPASS_TO_FIFO = 7
}
 FIFO mode. More...
 
enum  l3gxxxx_filter_sel_t { L3GXXXX_NO_FILTER = 0 , L3GXXXX_HPF_ONLY = 1 , L3GXXXX_LPF2_ONLY = 2 , L3GXXXX_HPF_AND_LPF2 = 3 }
 High pass filter (HPF) and low pass filter 2 (LPF2) selection. More...
 
enum  l3gxxxx_hpf_mode_t { L3GXXXX_HPF_NORMAL = 0 , L3GXXXX_HPF_REFERENCE = 1 , L3GXXXX_HPF_AUTORESET = 3 }
 HPF (high pass filter) modes. More...
 
enum  l3gxxxx_int_types_t {
  L3GXXXX_INT_DATA_READY = L3GXXXX_INT2_DRDY , L3GXXXX_INT_FIFO_WATERMARK = L3GXXXX_INT2_WTM , L3GXXXX_INT_FIFO_OVERRUN = L3GXXXX_INT2_ORUN , L3GXXXX_INT_FIFO_EMPTY = L3GXXXX_INT2_EMPTY ,
  L3GXXXX_INT_EVENT = L3GXXXX_INT1_IG
}
 Interrupt types. More...
 
enum  l3gxxxx_int_pin_level_t { L3GXXXX_HIGH = 0 , L3GXXXX_LOW }
 INT1, INT2/DRDY sensor signal activity level More...
 
enum  l3gxxxx_int_pin_type_t { L3GXXXX_PUSH_PULL = 0 , L3GXXXX_OPEN_DRAIN }
 INT1, INT2/DRDY sensor signal type More...
 
enum  l3gxxxx_if_t { L3GXXXX_I2C , L3GXXXX_SPI }
 L3Gxxxx interface types. More...
 

L3Gxxxx addresses

#define L3GXXXX_I2C_ADDR_1   (0x68)
 SDO pin is low.
 
#define L3GXXXX_I2C_ADDR_2   (0x69)
 SDO pin is high.
 

L3Gxxxx chip ids

#define L3GXXXX_CHIP_ID_L3GD20H   (0xd7)
 Chip ID for L3GD20H.
 
#define L3GXXXX_CHIP_ID_L3GD20   (0xd4)
 Chip ID for L3GD20.
 
#define L3GXXXX_CHIP_ID_X3G42XXD   (0xd3)
 Chip ID for L3G4200D, I3G4250D, A3G4250D.
 

Sensor initialization and configuration

int l3gxxxx_init (l3gxxxx_t *dev, const l3gxxxx_params_t *params)
 Initialize the L3Gxxxx sensor device.
 
int l3gxxxx_set_mode (l3gxxxx_t *dev, l3gxxxx_odr_t odr, bool x, bool y, bool z)
 Set sensor mode.
 
int l3gxxxx_set_scale (l3gxxxx_t *dev, l3gxxxx_scale_t scale)
 Set full scale.
 

Power saving functions

int l3gxxxx_power_down (l3gxxxx_t *dev)
 Power down the sensor.
 
int l3gxxxx_power_up (l3gxxxx_t *dev)
 Power up the sensor.
 
int l3gxxxx_sleep (l3gxxxx_t *dev)
 Sleep mode.
 
int l3gxxxx_wake_up (l3gxxxx_t *dev)
 Wake-up the sensor.
 

Basic sensor data handling

int l3gxxxx_data_ready (const l3gxxxx_t *dev)
 Data ready status function.
 
int l3gxxxx_read (const l3gxxxx_t *dev, l3gxxxx_data_t *data)
 Read last sample of angular rates in millidegree per second (mpds)
 
int l3gxxxx_read_raw (const l3gxxxx_t *dev, l3gxxxx_raw_data_t *raw)
 Read last sample of raw output data as 16 bit two's complements.
 

FIFO handling

int l3gxxxx_set_fifo_mode (l3gxxxx_t *dev, l3gxxxx_fifo_mode_t mode, uint8_t watermark)
 Set FIFO mode and watermark level (threshold)
 
int l3gxxxx_read_fifo (const l3gxxxx_t *dev, l3gxxxx_data_fifo_t data)
 Get all samples of angular rates stored in the FIFO (unit mdps)
 
int l3gxxxx_read_raw_fifo (const l3gxxxx_t *dev, l3gxxxx_raw_data_fifo_t raw)
 Get all samples of raw output data stored in the FIFO.
 

Filter configuration and handling

int l3gxxxx_select_output_filter (l3gxxxx_t *dev, l3gxxxx_filter_sel_t filter)
 Filter selection for raw output data.
 
int l3gxxxx_config_hpf (const l3gxxxx_t *dev, l3gxxxx_hpf_mode_t mode, uint8_t cutoff)
 Config HPF (high pass filter) for output data.
 
int l3gxxxx_set_hpf_ref (const l3gxxxx_t *dev, int8_t ref)
 Set HPF (high pass filter) reference.
 
int l3gxxxx_get_hpf_ref (const l3gxxxx_t *dev, int8_t *ref)
 Get HPF (high pass filter) reference.
 

Interrupt configuration and handling

int l3gxxxx_enable_int (const l3gxxxx_t *dev, l3gxxxx_int_types_t mask, bool enable)
 Enable or disable event and/or data interrupts on signal INT1 and INT2/DRDY
 
l3gxxxx_int_src_t l3gxxxx_wait_int (l3gxxxx_t *dev)
 Wait for event and/or data interrupts on signals INT1 and INT2/DRDY
 
int l3gxxxx_set_int_event_cfg (const l3gxxxx_t *dev, const l3gxxxx_int_event_cfg_t *cfg)
 Set new configuration for event interrupt generation.
 
int l3gxxxx_get_int_event_cfg (const l3gxxxx_t *dev, l3gxxxx_int_event_cfg_t *cfg)
 Get current configuration of event interrupt generation.
 

Low level interface functions

int l3gxxxx_reg_write (const l3gxxxx_t *dev, uint8_t reg, const uint8_t *data, uint8_t len)
 Direct write to register.
 
int l3gxxxx_reg_read (const l3gxxxx_t *dev, uint8_t reg, uint8_t *data, uint8_t len)
 Direct read from register.