upm  1.5.0
Sensor/Actuator repository for libmraa (v1.8.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;
72  float accFactor;
74 
91  lis2ds12_context lis2ds12_init(int bus, int addr, int cs);
92 
99 
106  upm_result_t lis2ds12_update(const lis2ds12_context dev);
107 
114  uint8_t lis2ds12_get_chip_id(const lis2ds12_context dev);
115 
126  upm_result_t lis2ds12_devinit(const lis2ds12_context dev,
127  LIS2DS12_ODR_T odr,
128  LIS2DS12_FS_T fs);
129 
137  upm_result_t lis2ds12_set_odr(const lis2ds12_context dev,
138  LIS2DS12_ODR_T odr);
139 
148  upm_result_t lis2ds12_set_full_scale(const lis2ds12_context dev,
149  LIS2DS12_FS_T fs);
150 
164  float *x, float *y, float *z);
165 
175 
185  upm_result_t lis2ds12_reset(const lis2ds12_context dev);
186 
196  upm_result_t lis2ds12_enable_hp_filtering(const lis2ds12_context dev,
197  bool filter);
198 
208  bool latch);
209 
219  bool high);
220 
229  upm_result_t lis2ds12_set_interrupt_push_pull(const lis2ds12_context dev,
230  bool pp);
231 
239  upm_result_t lis2ds12_set_int1_config(const lis2ds12_context dev,
240  uint8_t cfg);
241 
249  upm_result_t lis2ds12_set_int2_config(const lis2ds12_context dev,
250  uint8_t cfg);
251 
258  uint8_t lis2ds12_get_status(const lis2ds12_context dev);
259 
274  upm_result_t lis2ds12_install_isr(const lis2ds12_context dev,
275  LIS2DS12_INTERRUPT_PINS_T intr, int gpio,
276  mraa_gpio_edge_t level,
277  void (*isr)(void *), void *arg);
278 
287  LIS2DS12_INTERRUPT_PINS_T intr);
288 
296  uint8_t lis2ds12_read_reg(const lis2ds12_context dev, uint8_t reg);
297 
307  int lis2ds12_read_regs(const lis2ds12_context dev, uint8_t reg,
308  uint8_t *buffer, int len);
309 
318  upm_result_t lis2ds12_write_reg(const lis2ds12_context dev,
319  uint8_t reg, uint8_t val);
320 
321 
322 #ifdef __cplusplus
323 }
324 #endif
uint8_t lis2ds12_read_reg(const lis2ds12_context dev, uint8_t reg)
Definition: lis2ds12.c:350
upm_result_t lis2ds12_set_interrupt_push_pull(const lis2ds12_context dev, bool pp)
Definition: lis2ds12.c:544
uint8_t lis2ds12_get_status(const lis2ds12_context dev)
Definition: lis2ds12.c:584
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:374
void lis2ds12_close(lis2ds12_context dev)
Definition: lis2ds12.c:163
upm_result_t lis2ds12_update(const lis2ds12_context dev)
Definition: lis2ds12.c:316
float lis2ds12_get_temperature(const lis2ds12_context dev)
Definition: lis2ds12.c:467
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:490
upm_result_t lis2ds12_set_int2_config(const lis2ds12_context dev, uint8_t cfg)
Definition: lis2ds12.c:573
void lis2ds12_get_accelerometer(const lis2ds12_context dev, float *x, float *y, float *z)
Definition: lis2ds12.c:450
upm_result_t lis2ds12_write_reg(const lis2ds12_context dev, uint8_t reg, uint8_t val)
Definition: lis2ds12.c:409
upm_result_t lis2ds12_reset(const lis2ds12_context dev)
Definition: lis2ds12.c:474
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:591
upm_result_t lis2ds12_set_full_scale(const lis2ds12_context dev, LIS2DS12_FS_T fs)
Definition: lis2ds12.c:278
upm_result_t lis2ds12_set_interrupt_active_high(const lis2ds12_context dev, bool high)
Definition: lis2ds12.c:526
void lis2ds12_uninstall_isr(const lis2ds12_context dev, LIS2DS12_INTERRUPT_PINS_T intr)
Definition: lis2ds12.c:633
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:562
upm_result_t lis2ds12_enable_interrupt_latching(const lis2ds12_context dev, bool latch)
Definition: lis2ds12.c:508
uint8_t lis2ds12_get_chip_id(const lis2ds12_context dev)
Definition: lis2ds12.c:443
Definition: lis2ds12.h:54