upm  1.0.2
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
37 #define BMI160_CHIP_ID 0xd1
38 
66  typedef struct _bmi160_context {
67  // uncompensated accelerometer and gyroscope values
68  float accelX;
69  float accelY;
70  float accelZ;
71 
72  float gyroX;
73  float gyroY;
74  float gyroZ;
75 
76  float magX;
77  float magY;
78  float magZ;
79 
80  unsigned int sensorTime;
81 
82  // accelerometer and gyro scaling factors, depending on their Full
83  // Scale (Range) settings.
84  float accelScale;
85  float gyroScale;
86 
87  // is the magnetometer enabled?
88  bool magEnabled;
89 
90  } *bmi160_context;
91 
92  typedef enum {
93  BMI160_ACC_RANGE_2G = 0, // 2 Gravities
94  BMI160_ACC_RANGE_4G,
95  BMI160_ACC_RANGE_8G,
96  BMI160_ACC_RANGE_16G
97  } BMI160_ACC_RANGE_T;
98 
99  typedef enum {
100  BMI160_GYRO_RANGE_125 = 0, // 125 degrees/sec
101  BMI160_GYRO_RANGE_250,
102  BMI160_GYRO_RANGE_500,
103  BMI160_GYRO_RANGE_1000,
104  BMI160_GYRO_RANGE_2000
105  } BMI160_GYRO_RANGE_T;
106 
120  bmi160_context bmi160_init(unsigned int bus, int address, int cs_pin,
121  bool enable_mag);
122 
128  void bmi160_close(bmi160_context dev);
129 
138  void bmi160_update(const bmi160_context dev);
139 
146  void bmi160_set_accelerometer_scale(const bmi160_context dev,
147  BMI160_ACC_RANGE_T scale);
148 
155  void bmi160_set_gyroscope_scale(const bmi160_context dev,
156  BMI160_GYRO_RANGE_T scale);
157 
168  void bmi160_get_accelerometer(const bmi160_context dev,
169  float *x, float *y, float *z);
170 
181  void bmi160_get_gyroscope(const bmi160_context dev,
182  float *x, float *y, float *z);
183 
194  void bmi160_get_magnetometer(const bmi160_context dev,
195  float *x, float *y, float *z);
196 
204  void bmi160_enable_magnetometer(const bmi160_context dev, bool enable);
205 
214  unsigned int bmi160_get_time(const bmi160_context dev);
215 
230  s8 bmi160_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt);
231 
246  s8 bmi160_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt);
247 
248 #ifdef __cplusplus
249 }
250 #endif
BMI160 3-axis Accelerometer, Gyroscope and (optionally) a Magnetometer.
Definition: bmi160.h:66