lsm6dsl.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 OTA keys S.A.
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  */
9 
27 #ifndef LSM6DSL_H
28 #define LSM6DSL_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include "periph/i2c.h"
35 
39 enum {
40  LSM6DSL_DATA_RATE_POWER_DOWN = 0x0,
41  LSM6DSL_DATA_RATE_1_6HZ = 0xB,
42  LSM6DSL_DATA_RATE_12_5HZ = 0x1,
43  LSM6DSL_DATA_RATE_26HZ = 0x2,
44  LSM6DSL_DATA_RATE_52HZ = 0x3,
45  LSM6DSL_DATA_RATE_104HZ = 0x4,
46  LSM6DSL_DATA_RATE_208HZ = 0x5,
47  LSM6DSL_DATA_RATE_416HZ = 0x6,
48  LSM6DSL_DATA_RATE_833HZ = 0x7,
49  LSM6DSL_DATA_RATE_1_66KHZ = 0x8,
50  LSM6DSL_DATA_RATE_3_33KHZ = 0x9,
51  LSM6DSL_DATA_RATE_6_66KHZ = 0xa,
52 };
53 
57 enum {
58  LSM6DSL_DECIMATION_NOT_IN_FIFO = 0,
59  LSM6DSL_DECIMATION_NO,
60  LSM6DSL_DECIMATION_2,
61  LSM6DSL_DECIMATION_3,
62  LSM6DSL_DECIMATION_4,
63  LSM6DSL_DECIMATION_8,
64  LSM6DSL_DECIMATION_16,
65  LSM6DSL_DECIMATION_32,
66 };
67 
71 enum {
72  LSM6DSL_ACC_FS_2G = 0,
73  LSM6DSL_ACC_FS_16G,
74  LSM6DSL_ACC_FS_4G,
75  LSM6DSL_ACC_FS_8G,
76  LSM6DSL_ACC_FS_MAX,
77 };
78 
82 enum {
83  LSM6DSL_GYRO_FS_245DPS = 0,
84  LSM6DSL_GYRO_FS_500DPS,
85  LSM6DSL_GYRO_FS_1000DPS,
86  LSM6DSL_GYRO_FS_2000DPS,
87  LSM6DSL_GYRO_FS_MAX,
88 };
89 
93 typedef struct {
95  uint8_t addr;
96  uint8_t acc_odr;
97  uint8_t gyro_odr;
98  uint8_t acc_fs;
99  uint8_t gyro_fs;
100  uint8_t acc_decimation;
101  uint8_t gyro_decimation;
103 
107 typedef struct {
109 } lsm6dsl_t;
110 
114 typedef struct {
115  int16_t x;
116  int16_t y;
117  int16_t z;
119 
123 enum {
128 };
129 
139 int lsm6dsl_init(lsm6dsl_t *dev, const lsm6dsl_params_t *params);
140 
150 int lsm6dsl_read_acc(const lsm6dsl_t *dev, lsm6dsl_3d_data_t *data);
151 
161 int lsm6dsl_read_gyro(const lsm6dsl_t *dev, lsm6dsl_3d_data_t *data);
162 
176 int lsm6dsl_read_temp(const lsm6dsl_t *dev, int16_t *data);
177 
186 int lsm6dsl_acc_power_down(const lsm6dsl_t *dev);
187 
196 int lsm6dsl_gyro_power_down(const lsm6dsl_t *dev);
197 
206 int lsm6dsl_acc_power_up(const lsm6dsl_t *dev);
207 
216 int lsm6dsl_gyro_power_up(const lsm6dsl_t *dev);
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif /* LSM6DSL_H */
223 
lsm6dsl_params_t::addr
uint8_t addr
i2c address
Definition: lsm6dsl.h:95
LSM6DSL_OK
@ LSM6DSL_OK
all good
Definition: lsm6dsl.h:124
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
lsm6dsl_params_t::i2c
i2c_t i2c
i2c bus
Definition: lsm6dsl.h:94
lsm6dsl_params_t::acc_fs
uint8_t acc_fs
accelerometer full scale
Definition: lsm6dsl.h:98
lsm6dsl_t::params
lsm6dsl_params_t params
driver parameters
Definition: lsm6dsl.h:108
lsm6dsl_params_t
LSM6DSL driver parameters.
Definition: lsm6dsl.h:93
LSM6DSL_ERROR_DEV
@ LSM6DSL_ERROR_DEV
device error
Definition: lsm6dsl.h:127
lsm6dsl_init
int lsm6dsl_init(lsm6dsl_t *dev, const lsm6dsl_params_t *params)
Initialize a LSM6DSL device.
lsm6dsl_params_t::acc_odr
uint8_t acc_odr
accelerometer output data rate
Definition: lsm6dsl.h:96
lsm6dsl_read_temp
int lsm6dsl_read_temp(const lsm6dsl_t *dev, int16_t *data)
Read temperature data.
lsm6dsl_3d_data_t::y
int16_t y
Y axis.
Definition: lsm6dsl.h:116
lsm6dsl_params_t::gyro_odr
uint8_t gyro_odr
gyroscope output data rate
Definition: lsm6dsl.h:97
lsm6dsl_params_t::gyro_decimation
uint8_t gyro_decimation
gyroscope decimation
Definition: lsm6dsl.h:101
lsm6dsl_3d_data_t::z
int16_t z
Z axis.
Definition: lsm6dsl.h:117
lsm6dsl_3d_data_t::x
int16_t x
X axis.
Definition: lsm6dsl.h:115
lsm6dsl_3d_data_t
3D output data
Definition: lsm6dsl.h:114
lsm6dsl_gyro_power_up
int lsm6dsl_gyro_power_up(const lsm6dsl_t *dev)
Power up gyroscope.
lsm6dsl_acc_power_down
int lsm6dsl_acc_power_down(const lsm6dsl_t *dev)
Power down accelerometer.
LSM6DSL_ERROR_CNF
@ LSM6DSL_ERROR_CNF
Config error.
Definition: lsm6dsl.h:126
lsm6dsl_params_t::gyro_fs
uint8_t gyro_fs
gyroscope full scale
Definition: lsm6dsl.h:99
LSM6DSL_ERROR_BUS
@ LSM6DSL_ERROR_BUS
I2C bus error.
Definition: lsm6dsl.h:125
lsm6dsl_read_gyro
int lsm6dsl_read_gyro(const lsm6dsl_t *dev, lsm6dsl_3d_data_t *data)
Read gyroscope data.
lsm6dsl_acc_power_up
int lsm6dsl_acc_power_up(const lsm6dsl_t *dev)
Power up accelerometer.
lsm6dsl_t
LSM6DSL device descriptor.
Definition: lsm6dsl.h:107
lsm6dsl_params_t::acc_decimation
uint8_t acc_decimation
accelerometer decimation
Definition: lsm6dsl.h:100
lsm6dsl_read_acc
int lsm6dsl_read_acc(const lsm6dsl_t *dev, lsm6dsl_3d_data_t *data)
Read accelerometer data.
i2c.h
Low-level I2C peripheral driver interface definition.
lsm6dsl_gyro_power_down
int lsm6dsl_gyro_power_down(const lsm6dsl_t *dev)
Power down gyroscope.