upm  1.2.0
Sensor/Actuator repository for libmraa (v1.6.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bno055.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 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 <stdlib.h>
29 #include <unistd.h>
30 #include <stdio.h>
31 #include <upm.h>
32 
33 #include <mraa/i2c.h>
34 #include <mraa/gpio.h>
35 
36 #include "bno055_regs.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
53  typedef struct _bno055_context {
54  mraa_i2c_context i2c;
55  mraa_gpio_context gpio;
56 
57  // always stored in C
58  float temperature;
59 
60  int currentPage;
61  BNO055_OPERATION_MODES_T currentMode;
62 
63  // uncompensated data
64 
65  // mag data
66  float magX;
67  float magY;
68  float magZ;
69 
70  // acc data
71  float accX;
72  float accY;
73  float accZ;
74 
75  // acc units
76  float accUnitScale;
77 
78  // gyr data
79  float gyrX;
80  float gyrY;
81  float gyrZ;
82 
83  // gyr units
84  float gyrUnitScale;
85 
86  // eul (euler angle) data
87  float eulHeading;
88  float eulRoll;
89  float eulPitch;
90 
91  // eul units
92  float eulUnitScale;
93 
94  // qua (quaternion) data
95  float quaW;
96  float quaX;
97  float quaY;
98  float quaZ;
99 
100  // lia (linear acceleration) data
101  float liaX;
102  float liaY;
103  float liaZ;
104 
105  // grv (gravity vector) data
106  float grvX;
107  float grvY;
108  float grvZ;
109  } *bno055_context;
110 
127  bno055_context bno055_init(int bus, uint8_t addr);
128 
134  void bno055_close(bno055_context dev);
135 
142  upm_result_t bno055_update(const bno055_context dev);
143 
150  uint8_t bno055_get_chip_id(const bno055_context dev);
151 
158  uint8_t bno055_get_acc_id(const bno055_context dev);
159 
166  uint8_t bno055_get_mag_id(const bno055_context dev);
167 
174  uint8_t bno055_get_gyr_id(const bno055_context dev);
175 
182  uint16_t bno055_get_sw_revision(const bno055_context dev);
183 
190  uint8_t bno055_get_bootloader_id(const bno055_context dev);
191 
200  void bno055_set_clock_external(const bno055_context dev, bool extClock);
201 
211  BNO055_TEMP_SOURCES_T src);
212 
219 
231  BNO055_OPERATION_MODES_T mode);
232 
240  void bno055_reset_system(const bno055_context dev);
241 
253  int *mag, int *acc,
254  int *gyr, int *sys);
255 
266 
283  upm_result_t bno055_read_calibration_data(const bno055_context dev,
284  uint8_t *data, size_t len);
285 
298  upm_result_t bno055_write_calibration_data(const bno055_context dev,
299  uint8_t *data,
300  size_t len);
301 
311  float bno055_get_temperature(const bno055_context dev);
312 
326  void bno055_get_euler_angles(const bno055_context dev, float *heading,
327  float *roll, float *pitch);
328 
344  void bno055_get_quaternions(const bno055_context dev, float *w, float *x,
345  float *y, float *z);
346 
361  void bno055_get_linear_acceleration(const bno055_context dev, float *x,
362  float *y, float *z);
363 
379  float *x, float *y, float *z);
380 
395  void bno055_get_accelerometer(const bno055_context dev, float *x, float *y,
396  float *z);
397 
412  void bno055_get_magnetometer(const bno055_context dev, float *x, float *y,
413  float *z);
414 
429  void bno055_get_gyroscope(const bno055_context dev,
430  float *x, float *y, float *z);
431 
442  BNO055_ACC_RANGE_T range,
443  BNO055_ACC_BW_T bw,
444  BNO055_ACC_PWR_MODE_T pwr);
445 
456  BNO055_MAG_ODR_T odr,
457  BNO055_MAG_OPR_T opr,
458  BNO055_MAG_POWER_T pwr);
459 
470  BNO055_GYR_RANGE_T range,
471  BNO055_GYR_BW_T bw,
472  BNO055_GYR_POWER_MODE_T pwr);
473 
482  void bno055_set_accelerometer_units(const bno055_context dev, bool mg);
483 
492  void bno055_set_gyroscope_units(const bno055_context dev, bool radians);
493 
502  void bno055_set_euler_units(const bno055_context dev, bool radians);
503 
510 
518  uint8_t bno055_get_interrupt_status(const bno055_context dev);
519 
528  uint8_t bno055_get_interrupt_enable(const bno055_context dev);
529 
538  uint8_t enables);
539 
551  uint8_t bno055_get_interrupt_mask(const bno055_context dev);
552 
564  void bno055_set_interrupt_mask(const bno055_context dev, uint8_t mask);
565 
573  BNO055_SYS_STATUS_T bno055_get_system_status(const bno055_context dev);
574 
583  BNO055_SYS_ERR_T bno055_get_system_error(const bno055_context dev);
584 
597  upm_result_t bno055_install_isr(const bno055_context dev,
598  int gpio, mraa_gpio_edge_t level,
599  void (*isr)(void *), void *arg);
600 
606  void bno055_uninstall_isr(const bno055_context dev);
607 
619  upm_result_t bno055_set_page(const bno055_context dev, uint8_t page,
620  bool force);
621 
630  uint8_t bno055_read_reg(const bno055_context dev, uint8_t reg);
631 
642  upm_result_t bno055_read_regs(const bno055_context dev, uint8_t reg,
643  uint8_t *buffer, size_t len);
644 
654  upm_result_t bno055_write_reg(const bno055_context dev,
655  uint8_t reg, uint8_t val);
656 
668  upm_result_t bno055_write_regs(const bno055_context dev, uint8_t reg,
669  uint8_t *buffer, size_t len);
670 
671 #ifdef __cplusplus
672 }
673 #endif
void bno055_set_accelerometer_units(const bno055_context dev, bool mg)
Definition: bno055.c:410
void bno055_uninstall_isr(const bno055_context dev)
Definition: bno055.c:900
upm_result_t bno055_write_calibration_data(const bno055_context dev, uint8_t *data, size_t len)
Definition: bno055.c:667
float bno055_get_temperature(const bno055_context dev)
Definition: bno055.c:699
void bno055_get_accelerometer(const bno055_context dev, float *x, float *y, float *z)
Definition: bno055.c:772
void bno055_reset_system(const bno055_context dev)
Definition: bno055.c:541
upm_result_t bno055_read_calibration_data(const bno055_context dev, uint8_t *data, size_t len)
Definition: bno055.c:631
uint8_t bno055_get_chip_id(const bno055_context dev)
Definition: bno055.c:292
uint8_t bno055_get_interrupt_status(const bno055_context dev)
Definition: bno055.c:568
uint8_t bno055_read_reg(const bno055_context dev, uint8_t reg)
Definition: bno055.c:237
void bno055_get_euler_angles(const bno055_context dev, float *heading, float *roll, float *pitch)
Definition: bno055.c:706
void bno055_set_acceleration_config(const bno055_context dev, BNO055_ACC_RANGE_T range, BNO055_ACC_BW_T bw, BNO055_ACC_PWR_MODE_T pwr)
Definition: bno055.c:820
struct _bno055_context * bno055_context
uint8_t bno055_get_interrupt_mask(const bno055_context dev)
Definition: bno055.c:595
BNO055_SYS_ERR_T bno055_get_system_error(const bno055_context dev)
Definition: bno055.c:622
BNO055_SYS_STATUS_T bno055_get_system_status(const bno055_context dev)
Definition: bno055.c:613
uint8_t bno055_get_gyr_id(const bno055_context dev)
Definition: bno055.c:316
void bno055_get_gyroscope(const bno055_context dev, float *x, float *y, float *z)
Definition: bno055.c:805
uint8_t bno055_get_interrupt_enable(const bno055_context dev)
Definition: bno055.c:577
void bno055_set_euler_units(const bno055_context dev, bool radians)
Definition: bno055.c:454
void bno055_set_magnetometer_config(const bno055_context dev, BNO055_MAG_ODR_T odr, BNO055_MAG_OPR_T opr, BNO055_MAG_POWER_T pwr)
Definition: bno055.c:836
void bno055_set_operation_mode(const bno055_context dev, BNO055_OPERATION_MODES_T mode)
Definition: bno055.c:476
void bno055_set_gyroscope_units(const bno055_context dev, bool radians)
Definition: bno055.c:432
void bno055_get_calibration_status(const bno055_context dev, int *mag, int *acc, int *gyr, int *sys)
Definition: bno055.c:499
void bno055_set_temperature_source(const bno055_context dev, BNO055_TEMP_SOURCES_T src)
Definition: bno055.c:388
void bno055_set_temperature_units_celsius(const bno055_context dev)
Definition: bno055.c:397
void bno055_get_magnetometer(const bno055_context dev, float *x, float *y, float *z)
Definition: bno055.c:787
uint8_t bno055_get_mag_id(const bno055_context dev)
Definition: bno055.c:308
Definition: bno055.h:53
void bno055_set_gyroscope_config(const bno055_context dev, BNO055_GYR_RANGE_T range, BNO055_GYR_BW_T bw, BNO055_GYR_POWER_MODE_T pwr)
Definition: bno055.c:852
void bno055_close(bno055_context dev)
Definition: bno055.c:207
uint16_t bno055_get_sw_revision(const bno055_context dev)
Definition: bno055.c:324
void bno055_get_linear_acceleration(const bno055_context dev, float *x, float *y, float *z)
Definition: bno055.c:742
upm_result_t bno055_write_reg(const bno055_context dev, uint8_t reg, uint8_t val)
Definition: bno055.c:264
void bno055_set_clock_external(const bno055_context dev, bool extClock)
Definition: bno055.c:365
upm_result_t bno055_install_isr(const bno055_context dev, int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
Definition: bno055.c:871
upm_result_t bno055_write_regs(const bno055_context dev, uint8_t reg, uint8_t *buffer, size_t len)
Definition: bno055.c:275
upm_result_t bno055_set_page(const bno055_context dev, uint8_t page, bool force)
Definition: bno055.c:345
void bno055_set_interrupt_enable(const bno055_context dev, uint8_t enables)
Definition: bno055.c:586
void bno055_get_quaternions(const bno055_context dev, float *w, float *x, float *y, float *z)
Definition: bno055.c:721
void bno055_reset_interrupt_status(const bno055_context dev)
Definition: bno055.c:555
void bno055_set_interrupt_mask(const bno055_context dev, uint8_t mask)
Definition: bno055.c:604
uint8_t bno055_get_bootloader_id(const bno055_context dev)
Definition: bno055.c:337
upm_result_t bno055_update(const bno055_context dev)
Definition: bno055.c:219
bno055_context bno055_init(int bus, uint8_t addr)
Definition: bno055.c:120
bool bno055_is_fully_calibrated(const bno055_context dev)
Definition: bno055.c:526
upm_result_t bno055_read_regs(const bno055_context dev, uint8_t reg, uint8_t *buffer, size_t len)
Definition: bno055.c:253
uint8_t bno055_get_acc_id(const bno055_context dev)
Definition: bno055.c:300
void bno055_get_gravity_vectors(const bno055_context dev, float *x, float *y, float *z)
Definition: bno055.c:757