Blame view

RIOT/drivers/include/lsm6dsl.h 4.94 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
  /*
   * Copyright (C) 2017 OTA keys S.A.
   *
   * 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.
   *
   */
  
  /**
   * @defgroup    drivers_lsm6dsl LSM6DSL 3D accelerometer/gyroscope
   * @ingroup     drivers_sensors
   * @brief       Device driver for the LSM6DSL 3D accelerometer/gyroscope
   *
   * @{
   *
   * @file
   * @brief       Device driver interface for the LSM6DSL 3D accelerometer/gyroscope.
   *
   * @author      Vincent Dupont <vincent@otakeys.com>
   * @author      Sebastian Meiling <s@mlng.net>
   *
   */
  
  #ifndef LSM6DSL_H
  #define LSM6DSL_H
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  #include "periph/i2c.h"
  
  /**
   * @brief   Data rate settings
   */
  enum {
      LSM6DSL_DATA_RATE_POWER_DOWN = 0x0,
      LSM6DSL_DATA_RATE_1_6HZ      = 0xB,
      LSM6DSL_DATA_RATE_12_5HZ     = 0x1,
      LSM6DSL_DATA_RATE_26HZ       = 0x2,
      LSM6DSL_DATA_RATE_52HZ       = 0x3,
      LSM6DSL_DATA_RATE_104HZ      = 0x4,
      LSM6DSL_DATA_RATE_208HZ      = 0x5,
      LSM6DSL_DATA_RATE_416HZ      = 0x6,
      LSM6DSL_DATA_RATE_833HZ      = 0x7,
      LSM6DSL_DATA_RATE_1_66KHZ    = 0x8,
      LSM6DSL_DATA_RATE_3_33KHZ    = 0x9,
      LSM6DSL_DATA_RATE_6_66KHZ    = 0xa,
  };
  
  /**
   * @brief   Decimation settings
   */
  enum {
      LSM6DSL_DECIMATION_NOT_IN_FIFO = 0,
      LSM6DSL_DECIMATION_NO,
      LSM6DSL_DECIMATION_2,
      LSM6DSL_DECIMATION_3,
      LSM6DSL_DECIMATION_4,
      LSM6DSL_DECIMATION_8,
      LSM6DSL_DECIMATION_16,
      LSM6DSL_DECIMATION_32,
  };
  
  /**
   * @brief   Accelerometer full scale
   */
  enum {
      LSM6DSL_ACC_FS_2G  = 0,
      LSM6DSL_ACC_FS_16G,
      LSM6DSL_ACC_FS_4G,
      LSM6DSL_ACC_FS_8G,
      LSM6DSL_ACC_FS_MAX,
  };
  
  /**
   * @brief   Gyroscope full scale
   */
  enum {
      LSM6DSL_GYRO_FS_245DPS    = 0,
      LSM6DSL_GYRO_FS_500DPS,
      LSM6DSL_GYRO_FS_1000DPS,
      LSM6DSL_GYRO_FS_2000DPS,
      LSM6DSL_GYRO_FS_MAX,
  };
  
  /**
   * @brief   LSM6DSL driver parameters
   */
  typedef struct {
      i2c_t i2c;                  /**< i2c bus */
      uint8_t addr;               /**< i2c address */
      uint8_t acc_odr;            /**< accelerometer output data rate */
      uint8_t gyro_odr;           /**< gyroscope output data rate */
      uint8_t acc_fs;             /**< accelerometer full scale */
      uint8_t gyro_fs;            /**< gyroscope full scale */
      uint8_t acc_decimation;     /**< accelerometer decimation */
      uint8_t gyro_decimation;    /**< gyroscope decimation */
  } lsm6dsl_params_t;
  
  /**
   * @brief   LSM6DSL device descriptor
   */
  typedef struct {
      lsm6dsl_params_t params; /**< driver parameters */
  } lsm6dsl_t;
  
  /**
   * @brief   3D output data
   */
  typedef struct {
      int16_t x;  /**< X axis */
      int16_t y;  /**< Y axis */
      int16_t z;  /**< Z axis */
  } lsm6dsl_3d_data_t;
  
  /**
   * @brief   Named return values
   */
  enum {
      LSM6DSL_OK = 0,             /**< all good */
      LSM6DSL_ERROR_BUS,          /**< I2C bus error */
      LSM6DSL_ERROR_CNF,          /**< Config error */
      LSM6DSL_ERROR_DEV,          /**< device error */
  };
  
  /**
   * @brief   Initialize a LSM6DSL device
   *
   * @param[out] dev     device to initialize
   * @param[in] params  driver parameters
   *
   * @return LSM6DSL_OK on success
   * @return < 0 on error
   */
  int lsm6dsl_init(lsm6dsl_t *dev, const lsm6dsl_params_t *params);
  
  /**
   * @brief   Read accelerometer data
   *
   * @param[in] dev    device to read
   * @param[out] data  accelerometer values
   *
   * @return LSM6DSL_OK on success
   * @return < 0 on error
   */
  int lsm6dsl_read_acc(const lsm6dsl_t *dev, lsm6dsl_3d_data_t *data);
  
  /**
   * @brief   Read gyroscope data
   *
   * @param[in] dev    device to read
   * @param[out] data  gyroscope values
   *
   * @return LSM6DSL_OK on success
   * @return < 0 on error
   */
  int lsm6dsl_read_gyro(const lsm6dsl_t *dev, lsm6dsl_3d_data_t *data);
  
  /**
   * @brief   Read temperature data
   *
   * @note To avoid floating point data types but still provide high resolution
   *       for temperature readings, resulting values are scale by factor 100.
   *
   *
   * @param[in] dev    device to read
   * @param[out] data  temperature value, in °C x 100
   *
   * @return LSM6DSL_OK on success
   * @return < 0 on error
   */
  int lsm6dsl_read_temp(const lsm6dsl_t *dev, int16_t *data);
  
  /**
   * @brief   Power down accelerometer
   *
   * @param[in] dev    device to power down
   *
   * @return LSM6DSL_OK on success
   * @return < 0 on error
   */
  int lsm6dsl_acc_power_down(const lsm6dsl_t *dev);
  
  /**
   * @brief   Power down gyroscope
   *
   * @param[in] dev    device to power down
   *
   * @return LSM6DSL_OK on success
   * @return < 0 on error
   */
  int lsm6dsl_gyro_power_down(const lsm6dsl_t *dev);
  
  /**
   * @brief   Power up accelerometer
   *
   * @param[in] dev    device to power up
   *
   * @return LSM6DSL_OK on success
   * @return < 0 on error
   */
  int lsm6dsl_acc_power_up(const lsm6dsl_t *dev);
  
  /**
   * @brief   Power up gyroscope
   *
   * @param[in] dev    device to power up
   *
   * @return LSM6DSL_OK on success
   * @return < 0 on error
   */
  int lsm6dsl_gyro_power_up(const lsm6dsl_t *dev);
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* LSM6DSL_H */
  /** @} */