upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bmi160.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <upm.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include "bosch_bmi160.h"
36 #include "bmi160_defs.h"
37 
65  typedef struct _bmi160_context {
66  // uncompensated accelerometer and gyroscope values
67  float accelX;
68  float accelY;
69  float accelZ;
70 
71  float gyroX;
72  float gyroY;
73  float gyroZ;
74 
75  float magX;
76  float magY;
77  float magZ;
78 
79  unsigned int sensorTime;
80 
81  // accelerometer and gyro scaling factors, depending on their Full
82  // Scale (Range) settings.
83  float accelScale;
84  float gyroScale;
85 
86  // is the magnetometer enabled?
87  bool magEnabled;
88 
89  } *bmi160_context;
90 
104  bmi160_context bmi160_init(unsigned int bus, int address, int cs_pin,
105  bool enable_mag);
106 
112  void bmi160_close(bmi160_context dev);
113 
122  void bmi160_update(const bmi160_context dev);
123 
130  void bmi160_set_accelerometer_scale(const bmi160_context dev,
131  BMI160_ACC_RANGE_T scale);
132 
139  void bmi160_set_gyroscope_scale(const bmi160_context dev,
140  BMI160_GYRO_RANGE_T scale);
141 
152  void bmi160_get_accelerometer(const bmi160_context dev,
153  float *x, float *y, float *z);
154 
165  void bmi160_get_gyroscope(const bmi160_context dev,
166  float *x, float *y, float *z);
167 
178  void bmi160_get_magnetometer(const bmi160_context dev,
179  float *x, float *y, float *z);
180 
188  void bmi160_enable_magnetometer(const bmi160_context dev, bool enable);
189 
198  unsigned int bmi160_get_time(const bmi160_context dev);
199 
214  s8 bmi160_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt);
215 
230  s8 bmi160_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt);
231 
232 #ifdef __cplusplus
233 }
234 #endif
BMI160 3-axis Accelerometer, Gyroscope and (optionally) a Magnetometer.
Definition: bmi160.h:65