upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
lsm6dsl.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2017 Intel Corporation.
4  *
5  * The MIT License
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <unistd.h>
29 #include <string.h>
30 
31 #include <mraa/i2c.h>
32 #include <mraa/spi.h>
33 #include <mraa/gpio.h>
34 
35 #include "upm.h"
36 
37 #include "lsm6dsl_defs.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
54  typedef struct _lsm6dsl_context {
55  mraa_i2c_context i2c;
56  mraa_spi_context spi;
57 
58  mraa_gpio_context gpioCS; // SPI CS pin
59  mraa_gpio_context gpioINT1; // intr 1
60  mraa_gpio_context gpioINT2; // intr 2
61 
62  // uncompensated temperature
63  float temperature;
64 
65  // uncompensated acc data
66  float accX;
67  float accY;
68  float accZ;
69 
70  // uncompensated gyr data
71  float gyrX;
72  float gyrY;
73  float gyrZ;
74 
75  // acc scaling
76  float accScale;
77  } *lsm6dsl_context;
78 
95  lsm6dsl_context lsm6dsl_init(int bus, int addr, int cs);
96 
102  void lsm6dsl_close(lsm6dsl_context dev);
103 
110  upm_result_t lsm6dsl_update(const lsm6dsl_context dev);
111 
118  uint8_t lsm6dsl_get_chip_id(const lsm6dsl_context dev);
119 
134  upm_result_t lsm6dsl_devinit(const lsm6dsl_context dev,
135  LSM6DSL_XL_ODR_T acc_odr,
136  LSM6DSL_XL_FS_T acc_fs,
137  LSM6DSL_G_ODR_T gyr_odr,
138  LSM6DSL_G_FS_T gyr_fs);
139 
147  upm_result_t lsm6dsl_set_acc_odr(const lsm6dsl_context dev,
148  LSM6DSL_XL_ODR_T odr);
149 
157  upm_result_t lsm6dsl_set_gyr_odr(const lsm6dsl_context dev,
158  LSM6DSL_G_ODR_T odr);
159 
168  upm_result_t lsm6dsl_set_acc_full_scale(const lsm6dsl_context dev,
169  LSM6DSL_XL_FS_T fs);
170 
180  upm_result_t lsm6dsl_set_gyr_full_scale(const lsm6dsl_context dev,
181  LSM6DSL_G_FS_T fs);
182 
196  float *x, float *y, float *z);
197 
211  void lsm6dsl_get_gyroscope(const lsm6dsl_context dev,
212  float *x, float *y, float *z);
213 
222  float lsm6dsl_get_temperature(const lsm6dsl_context dev);
223 
233  upm_result_t lsm6dsl_high_performance(const lsm6dsl_context dev,
234  bool enable);
235 
245  upm_result_t lsm6dsl_reset(const lsm6dsl_context dev);
246 
255  upm_result_t lsm6dsl_set_interrupt_active_high(const lsm6dsl_context dev,
256  bool high);
257 
266  upm_result_t lsm6dsl_set_interrupt_push_pull(const lsm6dsl_context dev,
267  bool pp);
268 
275  uint8_t lsm6dsl_get_status(const lsm6dsl_context dev);
276 
293  upm_result_t lsm6dsl_set_acc_offsets(const lsm6dsl_context dev,
294  int x, int y, int z, bool weight);
295 
296 
311  upm_result_t lsm6dsl_install_isr(const lsm6dsl_context dev,
312  LSM6DSL_INTERRUPT_PINS_T intr, int gpio,
313  mraa_gpio_edge_t level,
314  void (*isr)(void *), void *arg);
315 
323  void lsm6dsl_uninstall_isr(const lsm6dsl_context dev,
324  LSM6DSL_INTERRUPT_PINS_T intr);
325 
333  uint8_t lsm6dsl_read_reg(const lsm6dsl_context dev, uint8_t reg);
334 
343  int lsm6dsl_read_regs(const lsm6dsl_context dev, uint8_t reg,
344  uint8_t *buffer, int len);
345 
354  upm_result_t lsm6dsl_write_reg(const lsm6dsl_context dev,
355  uint8_t reg, uint8_t val);
356 
357 
358 #ifdef __cplusplus
359 }
360 #endif
upm_result_t lsm6dsl_update(const lsm6dsl_context dev)
Definition: lsm6dsl.c:312
upm_result_t lsm6dsl_set_acc_full_scale(const lsm6dsl_context dev, LSM6DSL_XL_FS_T fs)
Definition: lsm6dsl.c:248
upm_result_t lsm6dsl_set_interrupt_active_high(const lsm6dsl_context dev, bool high)
Definition: lsm6dsl.c:530
upm_result_t lsm6dsl_reset(const lsm6dsl_context dev)
Definition: lsm6dsl.c:514
upm_result_t lsm6dsl_install_isr(const lsm6dsl_context dev, LSM6DSL_INTERRUPT_PINS_T intr, int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
Definition: lsm6dsl.c:603
upm_result_t lsm6dsl_high_performance(const lsm6dsl_context dev, bool enable)
Definition: lsm6dsl.c:482
uint8_t lsm6dsl_read_reg(const lsm6dsl_context dev, uint8_t reg)
Definition: lsm6dsl.c:343
upm_result_t lsm6dsl_set_acc_odr(const lsm6dsl_context dev, LSM6DSL_XL_ODR_T odr)
Definition: lsm6dsl.c:214
void lsm6dsl_uninstall_isr(const lsm6dsl_context dev, LSM6DSL_INTERRUPT_PINS_T intr)
Definition: lsm6dsl.c:645
upm_result_t lsm6dsl_devinit(const lsm6dsl_context dev, LSM6DSL_XL_ODR_T acc_odr, LSM6DSL_XL_FS_T acc_fs, LSM6DSL_G_ODR_T gyr_odr, LSM6DSL_G_FS_T gyr_fs)
Definition: lsm6dsl.c:181
uint8_t lsm6dsl_get_status(const lsm6dsl_context dev)
Definition: lsm6dsl.c:566
uint8_t lsm6dsl_get_chip_id(const lsm6dsl_context dev)
Definition: lsm6dsl.c:436
float lsm6dsl_get_temperature(const lsm6dsl_context dev)
Definition: lsm6dsl.c:473
upm_result_t lsm6dsl_set_gyr_odr(const lsm6dsl_context dev, LSM6DSL_G_ODR_T odr)
Definition: lsm6dsl.c:231
struct _lsm6dsl_context * lsm6dsl_context
upm_result_t lsm6dsl_write_reg(const lsm6dsl_context dev, uint8_t reg, uint8_t val)
Definition: lsm6dsl.c:402
upm_result_t lsm6dsl_set_gyr_full_scale(const lsm6dsl_context dev, LSM6DSL_G_FS_T fs)
Definition: lsm6dsl.c:285
void lsm6dsl_get_gyroscope(const lsm6dsl_context dev, float *x, float *y, float *z)
Definition: lsm6dsl.c:458
void lsm6dsl_get_accelerometer(const lsm6dsl_context dev, float *x, float *y, float *z)
Definition: lsm6dsl.c:443
upm_result_t lsm6dsl_set_interrupt_push_pull(const lsm6dsl_context dev, bool pp)
Definition: lsm6dsl.c:548
void lsm6dsl_close(lsm6dsl_context dev)
Definition: lsm6dsl.c:164
upm_result_t lsm6dsl_set_acc_offsets(const lsm6dsl_context dev, int x, int y, int z, bool weight)
Definition: lsm6dsl.c:573
Definition: lsm6dsl.h:54
int lsm6dsl_read_regs(const lsm6dsl_context dev, uint8_t reg, uint8_t *buffer, int len)
Definition: lsm6dsl.c:367
lsm6dsl_context lsm6dsl_init(int bus, int addr, int cs)
Definition: lsm6dsl.c:65