upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
lsm303agr.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/gpio.h>
33 
34 #include "upm.h"
35 
36 #include "lsm303agr_defs.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
53  typedef struct _lsm303agr_context {
54  mraa_i2c_context i2cACC; // accelerometer
55  mraa_i2c_context i2cMAG; // magnetometer
56  mraa_gpio_context gpioACC1; // acc intr
57  mraa_gpio_context gpioACC2; // acc intr
58  mraa_gpio_context gpioMAG; // mag intr
59 
60  // currently set power mode
61  LSM303AGR_POWER_MODE_T powerMode;
62 
63  // uncompensated temperature in C
64  float temperature;
65 
66  // accelerometer scaling, depends on full scale sensitivity and
67  // power mode
68  float accScale;
69  float accDivisor;
70 
71  // uncompensated acc data
72  float accX;
73  float accY;
74  float accZ;
75 
76  // uncompensated mag data
77  float magX;
78  float magY;
79  float magZ;
81 
82 
100  lsm303agr_context lsm303agr_init(int bus, int acc_addr, int mag_addr);
101 
108 
115  upm_result_t lsm303agr_update(const lsm303agr_context dev);
116 
130  float *x, float *y, float *z);
131 
145  float *x, float *y, float *z);
146 
155 
164  upm_result_t lsm303agr_set_full_scale(const lsm303agr_context dev,
165  LSM303AGR_A_FS_T fs);
166 
191  upm_result_t lsm303agr_devinit(const lsm303agr_context dev,
192  LSM303AGR_POWER_MODE_T mode);
193 
204  upm_result_t lsm303agr_set_power_mode(const lsm303agr_context dev,
205  LSM303AGR_POWER_MODE_T mode);
206 
215  upm_result_t lsm303agr_set_acc_odr(const lsm303agr_context dev,
216  LSM303AGR_A_ODR_T odr);
217 
226  upm_result_t lsm303agr_set_mag_odr(const lsm303agr_context dev,
227  LSM303AGR_CFG_A_M_ODR_T odr);
228 
238 
248 
257  upm_result_t lsm303agr_set_acc_int1_config(const lsm303agr_context dev,
258  uint8_t bits);
259 
268  upm_result_t lsm303agr_set_acc_int2_config(const lsm303agr_context dev,
269  uint8_t bits);
270 
279 
287  upm_result_t lsm303agr_set_mag_int_config(const lsm303agr_context dev,
288  uint8_t bits);
289 
299 
309 
318  uint8_t lsm303agr_get_mag_int_src(const lsm303agr_context dev);
319 
334  upm_result_t lsm303agr_install_isr(const lsm303agr_context dev,
335  LSM303AGR_INTERRUPT_PINS_T intr,
336  int gpio, mraa_gpio_edge_t level,
337  void (*isr)(void *), void *arg);
338 
347  LSM303AGR_INTERRUPT_PINS_T intr);
348 
356  uint8_t lsm303agr_read_reg(const lsm303agr_context dev, uint8_t reg);
357 
366  int lsm303agr_read_regs(const lsm303agr_context dev, uint8_t reg,
367  uint8_t *buffer, int len);
368 
377  upm_result_t lsm303agr_write_reg(const lsm303agr_context dev,
378  uint8_t reg, uint8_t val);
379 
380 #ifdef __cplusplus
381 }
382 #endif
int lsm303agr_read_regs(const lsm303agr_context dev, uint8_t reg, uint8_t *buffer, int len)
Definition: lsm303agr.c:487
void lsm303agr_get_magnetometer(const lsm303agr_context dev, float *x, float *y, float *z)
Definition: lsm303agr.c:546
upm_result_t lsm303agr_set_acc_odr(const lsm303agr_context dev, LSM303AGR_A_ODR_T odr)
Definition: lsm303agr.c:574
upm_result_t lsm303agr_set_acc_int1_config(const lsm303agr_context dev, uint8_t bits)
Definition: lsm303agr.c:620
void lsm303agr_close(lsm303agr_context dev)
Definition: lsm303agr.c:144
uint8_t lsm303agr_get_mag_int_src(const lsm303agr_context dev)
Definition: lsm303agr.c:702
uint8_t lsm303agr_get_acc_int2_src(const lsm303agr_context dev)
Definition: lsm303agr.c:692
upm_result_t lsm303agr_install_isr(const lsm303agr_context dev, LSM303AGR_INTERRUPT_PINS_T intr, int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
Definition: lsm303agr.c:712
upm_result_t lsm303agr_set_power_mode(const lsm303agr_context dev, LSM303AGR_POWER_MODE_T mode)
Definition: lsm303agr.c:256
upm_result_t lsm303agr_update(const lsm303agr_context dev)
Definition: lsm303agr.c:414
void lsm303agr_get_accelerometer(const lsm303agr_context dev, float *x, float *y, float *z)
Definition: lsm303agr.c:561
upm_result_t lsm303agr_set_acc_int2_config(const lsm303agr_context dev, uint8_t bits)
Definition: lsm303agr.c:644
upm_result_t lsm303agr_set_mag_int_config(const lsm303agr_context dev, uint8_t bits)
Definition: lsm303agr.c:668
Definition: lsm303agr.h:53
struct _lsm303agr_context * lsm303agr_context
upm_result_t lsm303agr_write_reg(const lsm303agr_context dev, uint8_t reg, uint8_t val)
Definition: lsm303agr.c:510
upm_result_t lsm303agr_set_full_scale(const lsm303agr_context dev, LSM303AGR_A_FS_T fs)
Definition: lsm303agr.c:315
uint8_t lsm303agr_get_mag_int_config(const lsm303agr_context dev)
Definition: lsm303agr.c:658
upm_result_t lsm303agr_devinit(const lsm303agr_context dev, LSM303AGR_POWER_MODE_T mode)
Definition: lsm303agr.c:160
float lsm303agr_get_temperature(const lsm303agr_context dev)
Definition: lsm303agr.c:536
uint8_t lsm303agr_get_acc_int2_config(const lsm303agr_context dev)
Definition: lsm303agr.c:634
void lsm303agr_uninstall_isr(const lsm303agr_context dev, LSM303AGR_INTERRUPT_PINS_T intr)
Definition: lsm303agr.c:758
lsm303agr_context lsm303agr_init(int bus, int acc_addr, int mag_addr)
Definition: lsm303agr.c:47
upm_result_t lsm303agr_set_mag_odr(const lsm303agr_context dev, LSM303AGR_CFG_A_M_ODR_T odr)
Definition: lsm303agr.c:592
uint8_t lsm303agr_read_reg(const lsm303agr_context dev, uint8_t reg)
Definition: lsm303agr.c:463
uint8_t lsm303agr_get_acc_int1_src(const lsm303agr_context dev)
Definition: lsm303agr.c:682
uint8_t lsm303agr_get_acc_int1_config(const lsm303agr_context dev)
Definition: lsm303agr.c:610