upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 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 
151  upm_result_t bno055_get_chip_id(const bno055_context dev,
152  uint8_t *chip_id);
153 
161  upm_result_t bno055_get_acc_id(const bno055_context dev,
162  uint8_t *chip_id);
163 
171  upm_result_t bno055_get_mag_id(const bno055_context dev,
172  uint8_t *chip_id);
173 
181  upm_result_t bno055_get_gyr_id(const bno055_context dev,
182  uint8_t *chip_id);
183 
191  upm_result_t bno055_get_sw_revision(const bno055_context dev,
192  uint16_t *sw_rev);
193 
201  upm_result_t bno055_get_bootloader_id(const bno055_context dev,
202  uint8_t *bl_id);
203 
213  upm_result_t bno055_set_clock_external(const bno055_context dev,
214  bool extClock);
215 
225  upm_result_t bno055_set_temperature_source(const bno055_context dev,
226  BNO055_TEMP_SOURCES_T src);
227 
235 
247  upm_result_t bno055_set_operation_mode(const bno055_context dev,
248  BNO055_OPERATION_MODES_T mode);
249 
258  upm_result_t bno055_reset_system(const bno055_context dev);
259 
271  upm_result_t bno055_get_calibration_status(const bno055_context dev,
272  int *mag, int *acc,
273  int *gyr, int *sys);
274 
285 
302  upm_result_t bno055_read_calibration_data(const bno055_context dev,
303  uint8_t *data, size_t len);
304 
317  upm_result_t bno055_write_calibration_data(const bno055_context dev,
318  uint8_t *data,
319  size_t len);
320 
330  float bno055_get_temperature(const bno055_context dev);
331 
345  void bno055_get_euler_angles(const bno055_context dev, float *heading,
346  float *roll, float *pitch);
347 
363  void bno055_get_quaternions(const bno055_context dev, float *w, float *x,
364  float *y, float *z);
365 
380  void bno055_get_linear_acceleration(const bno055_context dev, float *x,
381  float *y, float *z);
382 
398  float *x, float *y, float *z);
399 
414  void bno055_get_accelerometer(const bno055_context dev, float *x, float *y,
415  float *z);
416 
431  void bno055_get_magnetometer(const bno055_context dev, float *x, float *y,
432  float *z);
433 
448  void bno055_get_gyroscope(const bno055_context dev,
449  float *x, float *y, float *z);
450 
461  upm_result_t bno055_set_acceleration_config(const bno055_context dev,
462  BNO055_ACC_RANGE_T range,
463  BNO055_ACC_BW_T bw,
464  BNO055_ACC_PWR_MODE_T pwr);
465 
476  upm_result_t bno055_set_magnetometer_config(const bno055_context dev,
477  BNO055_MAG_ODR_T odr,
478  BNO055_MAG_OPR_T opr,
479  BNO055_MAG_POWER_T pwr);
480 
491  upm_result_t bno055_set_gyroscope_config(const bno055_context dev,
492  BNO055_GYR_RANGE_T range,
493  BNO055_GYR_BW_T bw,
494  BNO055_GYR_POWER_MODE_T pwr);
495 
505  upm_result_t bno055_set_accelerometer_units(const bno055_context dev,
506  bool mg);
507 
517  upm_result_t bno055_set_gyroscope_units(const bno055_context dev,
518  bool radians);
519 
529  upm_result_t bno055_set_euler_units(const bno055_context dev,
530  bool radians);
531 
538  upm_result_t bno055_reset_interrupt_status(const bno055_context dev);
539 
548  upm_result_t bno055_get_interrupt_status(const bno055_context dev,
549  uint8_t *istat);
550 
560  upm_result_t bno055_get_interrupt_enable(const bno055_context dev,
561  uint8_t *ienable);
562 
571  upm_result_t bno055_set_interrupt_enable(const bno055_context dev,
572  uint8_t enables);
573 
586  upm_result_t bno055_get_interrupt_mask(const bno055_context dev,
587  uint8_t *imask);
588 
601  upm_result_t bno055_set_interrupt_mask(const bno055_context dev,
602  uint8_t mask);
603 
612  upm_result_t bno055_get_system_status(const bno055_context dev,
613  BNO055_SYS_STATUS_T *sys_stat);
614 
624  upm_result_t bno055_get_system_error(const bno055_context dev,
625  BNO055_SYS_ERR_T *sys_err);
626 
639  upm_result_t bno055_install_isr(const bno055_context dev,
640  int gpio, mraa_gpio_edge_t level,
641  void (*isr)(void *), void *arg);
642 
648  void bno055_uninstall_isr(const bno055_context dev);
649 
661  upm_result_t bno055_set_page(const bno055_context dev, uint8_t page,
662  bool force);
663 
673  upm_result_t bno055_read_reg(const bno055_context dev, uint8_t reg,
674  uint8_t *retval);
675 
686  upm_result_t bno055_read_regs(const bno055_context dev, uint8_t reg,
687  uint8_t *buffer, size_t len);
688 
698  upm_result_t bno055_write_reg(const bno055_context dev,
699  uint8_t reg, uint8_t val);
700 
712  upm_result_t bno055_write_regs(const bno055_context dev, uint8_t reg,
713  uint8_t *buffer, size_t len);
714 
715 #ifdef __cplusplus
716 }
717 #endif
upm_result_t bno055_set_interrupt_enable(const bno055_context dev, uint8_t enables)
Definition: bno055.c:698
void bno055_uninstall_isr(const bno055_context dev)
Definition: bno055.c:1047
upm_result_t bno055_write_calibration_data(const bno055_context dev, uint8_t *data, size_t len)
Definition: bno055.c:806
upm_result_t bno055_get_interrupt_mask(const bno055_context dev, uint8_t *imask)
Definition: bno055.c:709
float bno055_get_temperature(const bno055_context dev)
Definition: bno055.c:842
void bno055_get_accelerometer(const bno055_context dev, float *x, float *y, float *z)
Definition: bno055.c:915
upm_result_t bno055_get_chip_id(const bno055_context dev, uint8_t *chip_id)
Definition: bno055.c:334
upm_result_t bno055_set_temperature_units_celsius(const bno055_context dev)
Definition: bno055.c:469
upm_result_t bno055_set_clock_external(const bno055_context dev, bool extClock)
Definition: bno055.c:426
upm_result_t bno055_read_calibration_data(const bno055_context dev, uint8_t *data, size_t len)
Definition: bno055.c:766
upm_result_t bno055_reset_interrupt_status(const bno055_context dev)
Definition: bno055.c:660
void bno055_get_euler_angles(const bno055_context dev, float *heading, float *roll, float *pitch)
Definition: bno055.c:849
upm_result_t bno055_get_bootloader_id(const bno055_context dev, uint8_t *bl_id)
Definition: bno055.c:393
upm_result_t bno055_set_gyroscope_units(const bno055_context dev, bool radians)
Definition: bno055.c:510
upm_result_t bno055_get_gyr_id(const bno055_context dev, uint8_t *chip_id)
Definition: bno055.c:364
struct _bno055_context * bno055_context
upm_result_t bno055_set_accelerometer_units(const bno055_context dev, bool mg)
Definition: bno055.c:485
upm_result_t bno055_get_system_status(const bno055_context dev, BNO055_SYS_STATUS_T *sys_stat)
Definition: bno055.c:730
void bno055_get_gyroscope(const bno055_context dev, float *x, float *y, float *z)
Definition: bno055.c:948
upm_result_t 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:963
upm_result_t bno055_get_interrupt_enable(const bno055_context dev, uint8_t *ienable)
Definition: bno055.c:687
upm_result_t bno055_set_temperature_source(const bno055_context dev, BNO055_TEMP_SOURCES_T src)
Definition: bno055.c:458
upm_result_t 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:980
void bno055_get_magnetometer(const bno055_context dev, float *x, float *y, float *z)
Definition: bno055.c:930
upm_result_t bno055_set_operation_mode(const bno055_context dev, BNO055_OPERATION_MODES_T mode)
Definition: bno055.c:560
Definition: bno055.h:53
void bno055_close(bno055_context dev)
Definition: bno055.c:230
upm_result_t 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:997
void bno055_get_linear_acceleration(const bno055_context dev, float *x, float *y, float *z)
Definition: bno055.c:885
upm_result_t bno055_get_sw_revision(const bno055_context dev, uint16_t *sw_rev)
Definition: bno055.c:374
upm_result_t bno055_write_reg(const bno055_context dev, uint8_t reg, uint8_t val)
Definition: bno055.c:298
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:1018
upm_result_t bno055_write_regs(const bno055_context dev, uint8_t reg, uint8_t *buffer, size_t len)
Definition: bno055.c:313
upm_result_t bno055_set_page(const bno055_context dev, uint8_t page, bool force)
Definition: bno055.c:403
upm_result_t bno055_reset_system(const bno055_context dev)
Definition: bno055.c:639
void bno055_get_quaternions(const bno055_context dev, float *w, float *x, float *y, float *z)
Definition: bno055.c:864
upm_result_t bno055_get_mag_id(const bno055_context dev, uint8_t *chip_id)
Definition: bno055.c:354
upm_result_t bno055_get_interrupt_status(const bno055_context dev, uint8_t *istat)
Definition: bno055.c:676
upm_result_t bno055_read_reg(const bno055_context dev, uint8_t reg, uint8_t *retval)
Definition: bno055.c:264
upm_result_t bno055_set_euler_units(const bno055_context dev, bool radians)
Definition: bno055.c:535
upm_result_t bno055_get_system_error(const bno055_context dev, BNO055_SYS_ERR_T *sys_err)
Definition: bno055.c:748
upm_result_t bno055_update(const bno055_context dev)
Definition: bno055.c:242
bno055_context bno055_init(int bus, uint8_t addr)
Definition: bno055.c:129
bool bno055_is_fully_calibrated(const bno055_context dev)
Definition: bno055.c:622
upm_result_t bno055_read_regs(const bno055_context dev, uint8_t reg, uint8_t *buffer, size_t len)
Definition: bno055.c:283
upm_result_t bno055_get_calibration_status(const bno055_context dev, int *mag, int *acc, int *gyr, int *sys)
Definition: bno055.c:590
upm_result_t bno055_set_interrupt_mask(const bno055_context dev, uint8_t mask)
Definition: bno055.c:720
upm_result_t bno055_get_acc_id(const bno055_context dev, uint8_t *chip_id)
Definition: bno055.c:344
void bno055_get_gravity_vectors(const bno055_context dev, float *x, float *y, float *z)
Definition: bno055.c:900