lsm303dlhc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
24 #ifndef LSM303DLHC_H
25 #define LSM303DLHC_H
26 
27 #include <stdint.h>
28 #include "periph/i2c.h"
29 #include "periph/gpio.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
39 #define LSM303DLHC_ACC_DEFAULT_ADDRESS (0x19)
40 #define LSM303DLHC_MAG_DEFAULT_ADDRESS (0x1e)
41 
46 typedef enum {
58 
62 typedef enum {
68 
72 typedef enum {
82 
86  typedef enum {
95 
99 typedef struct {
100  int16_t x_axis;
101  int16_t y_axis;
102  int16_t z_axis;
104 
108 typedef struct {
110  uint8_t acc_addr;
111  gpio_t acc_pin;
114  uint8_t mag_addr;
115  gpio_t mag_pin;
119 
123 typedef struct {
125 } lsm303dlhc_t;
126 
136 int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params);
137 
158 
182 
192 int lsm303dlhc_read_temp(const lsm303dlhc_t *dev, int16_t *value);
193 
202 int lsm303dlhc_enable(const lsm303dlhc_t *dev);
203 
212 int lsm303dlhc_disable(const lsm303dlhc_t *dev);
213 
214 #ifdef __cplusplus
215 }
216 #endif
217 
218 #endif /* LSM303DLHC_H */
219 
LSM303DLHC_ACC_SAMPLE_RATE_400HZ
@ LSM303DLHC_ACC_SAMPLE_RATE_400HZ
400Hz sample rate
Definition: lsm303dlhc.h:53
LSM303DLHC_ACC_SCALE_2G
@ LSM303DLHC_ACC_SCALE_2G
+- 2g range
Definition: lsm303dlhc.h:63
LSM303DLHC_ACC_SAMPLE_RATE_1620HZ
@ LSM303DLHC_ACC_SAMPLE_RATE_1620HZ
1620Hz sample rate
Definition: lsm303dlhc.h:54
lsm303dlhc_params_t::acc_addr
uint8_t acc_addr
accelerometer I2C address
Definition: lsm303dlhc.h:110
lsm303dlhc_read_mag
int lsm303dlhc_read_mag(const lsm303dlhc_t *dev, lsm303dlhc_3d_data_t *data)
Read a magnetometer value from the sensor.
lsm303dlhc_params_t::acc_pin
gpio_t acc_pin
accelerometer EXTI pin
Definition: lsm303dlhc.h:111
lsm303dlhc_acc_scale_t
lsm303dlhc_acc_scale_t
Possible accelerometer scales.
Definition: lsm303dlhc.h:62
LSM303DLHC_MAG_GAIN_450_400_GAUSS
@ LSM303DLHC_MAG_GAIN_450_400_GAUSS
450Gauss XYZ 400Gauss Z
Definition: lsm303dlhc.h:90
lsm303dlhc_3d_data_t::z_axis
int16_t z_axis
surprise, holds the z axis value
Definition: lsm303dlhc.h:102
lsm303dlhc_3d_data_t
3d data container
Definition: lsm303dlhc.h:99
lsm303dlhc_params_t::mag_gain
lsm303dlhc_mag_gain_t mag_gain
magnetometer gain
Definition: lsm303dlhc.h:117
LSM303DLHC_ACC_SAMPLE_RATE_1HZ
@ LSM303DLHC_ACC_SAMPLE_RATE_1HZ
1Hz sample rate
Definition: lsm303dlhc.h:47
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
lsm303dlhc_acc_sample_rate_t
lsm303dlhc_acc_sample_rate_t
Possible accelerometer sample rates.
Definition: lsm303dlhc.h:46
lsm303dlhc_enable
int lsm303dlhc_enable(const lsm303dlhc_t *dev)
Enable the given sensor.
lsm303dlhc_read_temp
int lsm303dlhc_read_temp(const lsm303dlhc_t *dev, int16_t *value)
Read a temperature value from the sensor.
lsm303dlhc_params_t::acc_rate
lsm303dlhc_acc_sample_rate_t acc_rate
accelerometer sample rate
Definition: lsm303dlhc.h:112
LSM303DLHC_ACC_SAMPLE_RATE_50HZ
@ LSM303DLHC_ACC_SAMPLE_RATE_50HZ
50Hz sample rate
Definition: lsm303dlhc.h:50
lsm303dlhc_params_t::mag_rate
lsm303dlhc_mag_sample_rate_t mag_rate
magnetometer sample rate
Definition: lsm303dlhc.h:116
lsm303dlhc_disable
int lsm303dlhc_disable(const lsm303dlhc_t *dev)
Disable the given sensor.
lsm303dlhc_3d_data_t::x_axis
int16_t x_axis
holds the x axis value.
Definition: lsm303dlhc.h:100
lsm303dlhc_t
Device descriptor for LSM303DLHC sensors.
Definition: lsm303dlhc.h:123
LSM303DLHC_ACC_SAMPLE_RATE_25HZ
@ LSM303DLHC_ACC_SAMPLE_RATE_25HZ
25Hz sample rate
Definition: lsm303dlhc.h:49
LSM303DLHC_MAG_GAIN_1100_980_GAUSS
@ LSM303DLHC_MAG_GAIN_1100_980_GAUSS
1100Gauss XYZ 980Gauss Z
Definition: lsm303dlhc.h:87
lsm303dlhc_read_acc
int lsm303dlhc_read_acc(const lsm303dlhc_t *dev, lsm303dlhc_3d_data_t *data)
Read a accelerometer value from the sensor.
LSM303DLHC_MAG_SAMPLE_RATE_30HZ
@ LSM303DLHC_MAG_SAMPLE_RATE_30HZ
30 Hz sample rate
Definition: lsm303dlhc.h:78
LSM303DLHC_MAG_GAIN_855_760_GAUSS
@ LSM303DLHC_MAG_GAIN_855_760_GAUSS
855Gauss XYZ 760Gauss Z
Definition: lsm303dlhc.h:88
LSM303DLHC_MAG_SAMPLE_RATE_1_5HZ
@ LSM303DLHC_MAG_SAMPLE_RATE_1_5HZ
1.5 Hz sample rate
Definition: lsm303dlhc.h:74
LSM303DLHC_MAG_SAMPLE_RATE_3HZ
@ LSM303DLHC_MAG_SAMPLE_RATE_3HZ
3 Hz sample rate
Definition: lsm303dlhc.h:75
LSM303DLHC_MAG_SAMPLE_RATE_7_5HZ
@ LSM303DLHC_MAG_SAMPLE_RATE_7_5HZ
7.5 Hz sample rate
Definition: lsm303dlhc.h:76
LSM303DLHC_MAG_GAIN_230_205_GAUSS
@ LSM303DLHC_MAG_GAIN_230_205_GAUSS
230Gauss XYZ 205Gauss Z
Definition: lsm303dlhc.h:93
LSM303DLHC_ACC_SCALE_4G
@ LSM303DLHC_ACC_SCALE_4G
+- 4g range
Definition: lsm303dlhc.h:64
LSM303DLHC_MAG_SAMPLE_RATE_75HZ
@ LSM303DLHC_MAG_SAMPLE_RATE_75HZ
75 Hz sample rate
Definition: lsm303dlhc.h:79
LSM303DLHC_ACC_SCALE_8G
@ LSM303DLHC_ACC_SCALE_8G
+- 8g range
Definition: lsm303dlhc.h:65
lsm303dlhc_mag_sample_rate_t
lsm303dlhc_mag_sample_rate_t
Possible magnetometer sample rates.
Definition: lsm303dlhc.h:72
lsm303dlhc_params_t::mag_pin
gpio_t mag_pin
magnetometer EXTI pin
Definition: lsm303dlhc.h:115
gpio.h
Low-level GPIO peripheral driver interface definitions.
lsm303dlhc_params_t::i2c
i2c_t i2c
I2C bus used.
Definition: lsm303dlhc.h:109
lsm303dlhc_t::params
lsm303dlhc_params_t params
device initialization parameters
Definition: lsm303dlhc.h:124
lsm303dlhc_3d_data_t::y_axis
int16_t y_axis
holds the y axis value.
Definition: lsm303dlhc.h:101
LSM303DLHC_MAG_GAIN_400_355_GAUSS
@ LSM303DLHC_MAG_GAIN_400_355_GAUSS
400Gauss XYZ 355Gauss Z
Definition: lsm303dlhc.h:91
LSM303DLHC_ACC_SCALE_16G
@ LSM303DLHC_ACC_SCALE_16G
+-16g range
Definition: lsm303dlhc.h:66
LSM303DLHC_ACC_SAMPLE_RATE_100HZ
@ LSM303DLHC_ACC_SAMPLE_RATE_100HZ
100Hz sample rate
Definition: lsm303dlhc.h:51
LSM303DLHC_MAG_GAIN_330_295_GAUSS
@ LSM303DLHC_MAG_GAIN_330_295_GAUSS
330Gauss XYZ 295Gauss Z
Definition: lsm303dlhc.h:92
lsm303dlhc_mag_gain_t
lsm303dlhc_mag_gain_t
Possible magnetometer gain values.
Definition: lsm303dlhc.h:86
lsm303dlhc_init
int lsm303dlhc_init(lsm303dlhc_t *dev, const lsm303dlhc_params_t *params)
Initialize a new LSM303DLHC device.
lsm303dlhc_params_t::mag_addr
uint8_t mag_addr
magnetometer I2C address
Definition: lsm303dlhc.h:114
LSM303DLHC_ACC_SAMPLE_RATE_10HZ
@ LSM303DLHC_ACC_SAMPLE_RATE_10HZ
10Hz sample rate
Definition: lsm303dlhc.h:48
LSM303DLHC_MAG_SAMPLE_RATE_15HZ
@ LSM303DLHC_MAG_SAMPLE_RATE_15HZ
15 Hz sample rate
Definition: lsm303dlhc.h:77
lsm303dlhc_params_t
Data structure holding all the information needed for initialization.
Definition: lsm303dlhc.h:108
LSM303DLHC_ACC_SAMPLE_RATE_200HZ
@ LSM303DLHC_ACC_SAMPLE_RATE_200HZ
200Hz sample rate
Definition: lsm303dlhc.h:52
LSM303DLHC_MAG_GAIN_670_600_GAUSS
@ LSM303DLHC_MAG_GAIN_670_600_GAUSS
670Gauss XYZ 600Gauss Z
Definition: lsm303dlhc.h:89
i2c.h
Low-level I2C peripheral driver interface definition.
LSM303DLHC_MAG_SAMPLE_RATE_220HZ
@ LSM303DLHC_MAG_SAMPLE_RATE_220HZ
220 Hz sample rate
Definition: lsm303dlhc.h:80
lsm303dlhc_params_t::acc_scale
lsm303dlhc_acc_scale_t acc_scale
accelerometer scale factor
Definition: lsm303dlhc.h:113
LSM303DLHC_MAG_SAMPLE_RATE_0_75HZ
@ LSM303DLHC_MAG_SAMPLE_RATE_0_75HZ
0.75Hz sample rate
Definition: lsm303dlhc.h:73
LSM303DLHC_ACC_SAMPLE_RATE_N1344HZ_L5376HZ
@ LSM303DLHC_ACC_SAMPLE_RATE_N1344HZ_L5376HZ
1344Hz normal mode, 5376Hz low power mode
Definition: lsm303dlhc.h:55