upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
lsm303d.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 "lsm303d_defs.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
53  typedef struct _lsm303d_context {
54  mraa_i2c_context i2c;
55 
56  // uncompensated temperature in C
57  float temperature;
58 
59  // accelerometer scaling
60  float accScale;
61 
62  // magnetometer scaling
63  float magScale;
64 
65  // uncompensated acc data
66  float accX;
67  float accY;
68  float accZ;
69 
70  // uncompensated mag data
71  float magX;
72  float magY;
73  float magZ;
74  } *lsm303d_context;
75 
76 
89  lsm303d_context lsm303d_init(int bus, int addr);
90 
97 
104  upm_result_t lsm303d_update(const lsm303d_context dev);
105 
119  float *x, float *y, float *z);
120 
134  float *x, float *y, float *z);
135 
143  float lsm303d_get_temperature(const lsm303d_context dev);
144 
153  upm_result_t lsm303d_set_acc_full_scale(const lsm303d_context dev,
154  LSM303D_AFS_T fs);
155 
164  upm_result_t lsm303d_set_mag_full_scale(const lsm303d_context dev,
165  LSM303D_MFS_T fs);
166 
180  upm_result_t lsm303d_devinit(const lsm303d_context dev,
181  LSM303D_M_RES_T res);
182 
191  upm_result_t lsm303d_set_acc_odr(const lsm303d_context dev,
192  LSM303D_AODR_T odr);
193 
202  upm_result_t lsm303d_set_mag_odr(const lsm303d_context dev,
203  LSM303D_MODR_T odr);
204 
212  uint8_t lsm303d_read_reg(const lsm303d_context dev, uint8_t reg);
213 
222  int lsm303d_read_regs(const lsm303d_context dev, uint8_t reg,
223  uint8_t *buffer, int len);
224 
233  upm_result_t lsm303d_write_reg(const lsm303d_context dev,
234  uint8_t reg, uint8_t val);
235 
236 #ifdef __cplusplus
237 }
238 #endif
upm_result_t lsm303d_write_reg(const lsm303d_context dev, uint8_t reg, uint8_t val)
Definition: lsm303d.c:337
upm_result_t lsm303d_set_acc_full_scale(const lsm303d_context dev, LSM303D_AFS_T fs)
Definition: lsm303d.c:188
lsm303d_context lsm303d_init(int bus, int addr)
Definition: lsm303d.c:48
Definition: lsm303d.h:53
struct _lsm303d_context * lsm303d_context
void lsm303d_close(lsm303d_context dev)
Definition: lsm303d.c:103
upm_result_t lsm303d_set_mag_odr(const lsm303d_context dev, LSM303D_MODR_T odr)
Definition: lsm303d.c:404
upm_result_t lsm303d_update(const lsm303d_context dev)
Definition: lsm303d.c:268
uint8_t lsm303d_read_reg(const lsm303d_context dev, uint8_t reg)
Definition: lsm303d.c:311
void lsm303d_get_accelerometer(const lsm303d_context dev, float *x, float *y, float *z)
Definition: lsm303d.c:376
void lsm303d_get_magnetometer(const lsm303d_context dev, float *x, float *y, float *z)
Definition: lsm303d.c:361
upm_result_t lsm303d_set_mag_full_scale(const lsm303d_context dev, LSM303D_MFS_T fs)
Definition: lsm303d.c:230
upm_result_t lsm303d_devinit(const lsm303d_context dev, LSM303D_M_RES_T res)
Definition: lsm303d.c:113
int lsm303d_read_regs(const lsm303d_context dev, uint8_t reg, uint8_t *buffer, int len)
Definition: lsm303d.c:325
float lsm303d_get_temperature(const lsm303d_context dev)
Definition: lsm303d.c:352
upm_result_t lsm303d_set_acc_odr(const lsm303d_context dev, LSM303D_AODR_T odr)
Definition: lsm303d.c:389