upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
lsm6ds3h.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 "lsm6ds3h_defs.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
54  typedef struct _lsm6ds3h_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;
78 
95  lsm6ds3h_context lsm6ds3h_init(int bus, int addr, int cs);
96 
103 
110  upm_result_t lsm6ds3h_update(const lsm6ds3h_context dev);
111 
118  uint8_t lsm6ds3h_get_chip_id(const lsm6ds3h_context dev);
119 
134  upm_result_t lsm6ds3h_devinit(const lsm6ds3h_context dev,
135  LSM6DS3H_XL_ODR_T acc_odr,
136  LSM6DS3H_XL_FS_T acc_fs,
137  LSM6DS3H_G_ODR_T gyr_odr,
138  LSM6DS3H_G_FS_T gyr_fs);
139 
147  upm_result_t lsm6ds3h_set_acc_odr(const lsm6ds3h_context dev,
148  LSM6DS3H_XL_ODR_T odr);
149 
157  upm_result_t lsm6ds3h_set_gyr_odr(const lsm6ds3h_context dev,
158  LSM6DS3H_G_ODR_T odr);
159 
168  upm_result_t lsm6ds3h_set_acc_full_scale(const lsm6ds3h_context dev,
169  LSM6DS3H_XL_FS_T fs);
170 
180  upm_result_t lsm6ds3h_set_gyr_full_scale(const lsm6ds3h_context dev,
181  LSM6DS3H_G_FS_T fs);
182 
196  float *x, float *y, float *z);
197 
212  float *x, float *y, float *z);
213 
223 
233  upm_result_t lsm6ds3h_high_performance(const lsm6ds3h_context dev,
234  bool enable);
235 
245  upm_result_t lsm6ds3h_reset(const lsm6ds3h_context dev);
246 
256  bool high);
257 
266  upm_result_t lsm6ds3h_set_interrupt_push_pull(const lsm6ds3h_context dev,
267  bool pp);
268 
275  uint8_t lsm6ds3h_get_status(const lsm6ds3h_context dev);
276 
291  upm_result_t lsm6ds3h_install_isr(const lsm6ds3h_context dev,
292  LSM6DS3H_INTERRUPT_PINS_T intr, int gpio,
293  mraa_gpio_edge_t level,
294  void (*isr)(void *), void *arg);
295 
304  LSM6DS3H_INTERRUPT_PINS_T intr);
305 
313  uint8_t lsm6ds3h_read_reg(const lsm6ds3h_context dev, uint8_t reg);
314 
323  int lsm6ds3h_read_regs(const lsm6ds3h_context dev, uint8_t reg,
324  uint8_t *buffer, int len);
325 
334  upm_result_t lsm6ds3h_write_reg(const lsm6ds3h_context dev,
335  uint8_t reg, uint8_t val);
336 
337 
338 #ifdef __cplusplus
339 }
340 #endif
void lsm6ds3h_get_accelerometer(const lsm6ds3h_context dev, float *x, float *y, float *z)
Definition: lsm6ds3h.c:443
upm_result_t lsm6ds3h_set_acc_odr(const lsm6ds3h_context dev, LSM6DS3H_XL_ODR_T odr)
Definition: lsm6ds3h.c:214
upm_result_t lsm6ds3h_update(const lsm6ds3h_context dev)
Definition: lsm6ds3h.c:312
upm_result_t lsm6ds3h_set_gyr_odr(const lsm6ds3h_context dev, LSM6DS3H_G_ODR_T odr)
Definition: lsm6ds3h.c:231
uint8_t lsm6ds3h_get_chip_id(const lsm6ds3h_context dev)
Definition: lsm6ds3h.c:436
upm_result_t lsm6ds3h_install_isr(const lsm6ds3h_context dev, LSM6DS3H_INTERRUPT_PINS_T intr, int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
Definition: lsm6ds3h.c:573
void lsm6ds3h_get_gyroscope(const lsm6ds3h_context dev, float *x, float *y, float *z)
Definition: lsm6ds3h.c:458
float lsm6ds3h_get_temperature(const lsm6ds3h_context dev)
Definition: lsm6ds3h.c:473
lsm6ds3h_context lsm6ds3h_init(int bus, int addr, int cs)
Definition: lsm6ds3h.c:65
upm_result_t lsm6ds3h_set_interrupt_push_pull(const lsm6ds3h_context dev, bool pp)
Definition: lsm6ds3h.c:548
upm_result_t lsm6ds3h_write_reg(const lsm6ds3h_context dev, uint8_t reg, uint8_t val)
Definition: lsm6ds3h.c:402
upm_result_t lsm6ds3h_set_acc_full_scale(const lsm6ds3h_context dev, LSM6DS3H_XL_FS_T fs)
Definition: lsm6ds3h.c:248
upm_result_t lsm6ds3h_devinit(const lsm6ds3h_context dev, LSM6DS3H_XL_ODR_T acc_odr, LSM6DS3H_XL_FS_T acc_fs, LSM6DS3H_G_ODR_T gyr_odr, LSM6DS3H_G_FS_T gyr_fs)
Definition: lsm6ds3h.c:181
int lsm6ds3h_read_regs(const lsm6ds3h_context dev, uint8_t reg, uint8_t *buffer, int len)
Definition: lsm6ds3h.c:367
upm_result_t lsm6ds3h_set_interrupt_active_high(const lsm6ds3h_context dev, bool high)
Definition: lsm6ds3h.c:530
Definition: lsm6ds3h.h:54
upm_result_t lsm6ds3h_high_performance(const lsm6ds3h_context dev, bool enable)
Definition: lsm6ds3h.c:482
upm_result_t lsm6ds3h_set_gyr_full_scale(const lsm6ds3h_context dev, LSM6DS3H_G_FS_T fs)
Definition: lsm6ds3h.c:285
void lsm6ds3h_close(lsm6ds3h_context dev)
Definition: lsm6ds3h.c:164
struct _lsm6ds3h_context * lsm6ds3h_context
uint8_t lsm6ds3h_get_status(const lsm6ds3h_context dev)
Definition: lsm6ds3h.c:566
uint8_t lsm6ds3h_read_reg(const lsm6ds3h_context dev, uint8_t reg)
Definition: lsm6ds3h.c:343
upm_result_t lsm6ds3h_reset(const lsm6ds3h_context dev)
Definition: lsm6ds3h.c:514
void lsm6ds3h_uninstall_isr(const lsm6ds3h_context dev, LSM6DS3H_INTERRUPT_PINS_T intr)
Definition: lsm6ds3h.c:615