upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
lis2ds12.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 "lis2ds12_defs.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
54  typedef struct _lis2ds12_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  // temperature
63  float temperature;
64 
65  // uncompensated acc data
66  float accX;
67  float accY;
68  float accZ;
69 
70  // acc scaling
71  float accScale;
73 
90  lis2ds12_context lis2ds12_init(int bus, int addr, int cs);
91 
98 
105  upm_result_t lis2ds12_update(const lis2ds12_context dev);
106 
113  uint8_t lis2ds12_get_chip_id(const lis2ds12_context dev);
114 
125  upm_result_t lis2ds12_devinit(const lis2ds12_context dev,
126  LIS2DS12_ODR_T odr,
127  LIS2DS12_FS_T fs);
128 
136  upm_result_t lis2ds12_set_odr(const lis2ds12_context dev,
137  LIS2DS12_ODR_T odr);
138 
147  upm_result_t lis2ds12_set_full_scale(const lis2ds12_context dev,
148  LIS2DS12_FS_T fs);
149 
163  float *x, float *y, float *z);
164 
174 
184  upm_result_t lis2ds12_reset(const lis2ds12_context dev);
185 
195  upm_result_t lis2ds12_enable_hp_filtering(const lis2ds12_context dev,
196  bool filter);
197 
207  bool latch);
208 
218  bool high);
219 
228  upm_result_t lis2ds12_set_interrupt_push_pull(const lis2ds12_context dev,
229  bool pp);
230 
238  upm_result_t lis2ds12_set_int1_config(const lis2ds12_context dev,
239  uint8_t cfg);
240 
248  upm_result_t lis2ds12_set_int2_config(const lis2ds12_context dev,
249  uint8_t cfg);
250 
257  uint8_t lis2ds12_get_status(const lis2ds12_context dev);
258 
273  upm_result_t lis2ds12_install_isr(const lis2ds12_context dev,
274  LIS2DS12_INTERRUPT_PINS_T intr, int gpio,
275  mraa_gpio_edge_t level,
276  void (*isr)(void *), void *arg);
277 
286  LIS2DS12_INTERRUPT_PINS_T intr);
287 
295  uint8_t lis2ds12_read_reg(const lis2ds12_context dev, uint8_t reg);
296 
306  int lis2ds12_read_regs(const lis2ds12_context dev, uint8_t reg,
307  uint8_t *buffer, int len);
308 
317  upm_result_t lis2ds12_write_reg(const lis2ds12_context dev,
318  uint8_t reg, uint8_t val);
319 
320 
321 #ifdef __cplusplus
322 }
323 #endif
uint8_t lis2ds12_read_reg(const lis2ds12_context dev, uint8_t reg)
Definition: lis2ds12.c:316
upm_result_t lis2ds12_set_interrupt_push_pull(const lis2ds12_context dev, bool pp)
Definition: lis2ds12.c:510
uint8_t lis2ds12_get_status(const lis2ds12_context dev)
Definition: lis2ds12.c:550
struct _lis2ds12_context * lis2ds12_context
upm_result_t lis2ds12_set_odr(const lis2ds12_context dev, LIS2DS12_ODR_T odr)
Definition: lis2ds12.c:209
int lis2ds12_read_regs(const lis2ds12_context dev, uint8_t reg, uint8_t *buffer, int len)
Definition: lis2ds12.c:340
void lis2ds12_close(lis2ds12_context dev)
Definition: lis2ds12.c:163
upm_result_t lis2ds12_update(const lis2ds12_context dev)
Definition: lis2ds12.c:282
float lis2ds12_get_temperature(const lis2ds12_context dev)
Definition: lis2ds12.c:433
upm_result_t lis2ds12_devinit(const lis2ds12_context dev, LIS2DS12_ODR_T odr, LIS2DS12_FS_T fs)
Definition: lis2ds12.c:180
upm_result_t lis2ds12_enable_hp_filtering(const lis2ds12_context dev, bool filter)
Definition: lis2ds12.c:456
upm_result_t lis2ds12_set_int2_config(const lis2ds12_context dev, uint8_t cfg)
Definition: lis2ds12.c:539
void lis2ds12_get_accelerometer(const lis2ds12_context dev, float *x, float *y, float *z)
Definition: lis2ds12.c:416
upm_result_t lis2ds12_write_reg(const lis2ds12_context dev, uint8_t reg, uint8_t val)
Definition: lis2ds12.c:375
upm_result_t lis2ds12_reset(const lis2ds12_context dev)
Definition: lis2ds12.c:440
upm_result_t lis2ds12_install_isr(const lis2ds12_context dev, LIS2DS12_INTERRUPT_PINS_T intr, int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
Definition: lis2ds12.c:557
upm_result_t lis2ds12_set_full_scale(const lis2ds12_context dev, LIS2DS12_FS_T fs)
Definition: lis2ds12.c:244
upm_result_t lis2ds12_set_interrupt_active_high(const lis2ds12_context dev, bool high)
Definition: lis2ds12.c:492
void lis2ds12_uninstall_isr(const lis2ds12_context dev, LIS2DS12_INTERRUPT_PINS_T intr)
Definition: lis2ds12.c:599
lis2ds12_context lis2ds12_init(int bus, int addr, int cs)
Definition: lis2ds12.c:65
upm_result_t lis2ds12_set_int1_config(const lis2ds12_context dev, uint8_t cfg)
Definition: lis2ds12.c:528
upm_result_t lis2ds12_enable_interrupt_latching(const lis2ds12_context dev, bool latch)
Definition: lis2ds12.c:474
uint8_t lis2ds12_get_chip_id(const lis2ds12_context dev)
Definition: lis2ds12.c:409
Definition: lis2ds12.h:54