upm  0.8.0
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bno055.hpp
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 <string>
27 #include <mraa/i2c.hpp>
28 #include <mraa/gpio.hpp>
29 
30 #define BNO055_I2C_BUS 0
31 #define BNO055_DEFAULT_ADDR 0x28
32 
33 namespace upm {
34 
105  class BNO055 {
106  public:
107  // The chip ID, for verification in the ctor.
108  const uint8_t BNO055_CHIPID = 0xa0;
109 
110  // number of bytes of stored calibration data
111  const int calibrationDataNumBytes = 22;
112 
113  // NOTE: Reserved registers should not be written into. Reading
114  // from them will return indeterminate values.
115  //
116  // The register map is divided into two pages - page 1 contains
117  // sensor specific configuration registers, and page 0 contains all
118  // other configuration data and sensor output registers.
119 
123  typedef enum : uint8_t {
124  // The first register listed here is the page ID register. It
125  // is the same on both pages, and selects or indicates the
126  // currently active register page.
127 
128  REG_PAGE_ID = 0x07,
129 
130  // Page 0
131  REG_CHIP_ID = 0x00,
132  REG_ACC_ID = 0x01, // accel id
133  REG_MAG_ID = 0x02, // mag id
134  REG_GYR_ID = 0x03, // gyro id
135  REG_SW_REV_ID_LSB = 0x04,
136  REG_SW_REV_ID_MSB = 0x05,
137  REG_BL_REV_ID = 0x06, // bootloader rev
138 
139  // REG_PAGE_ID = 0x07
140 
141  REG_ACC_DATA_X_LSB = 0x08,
142  REG_ACC_DATA_X_MSB = 0x09,
143  REG_ACC_DATA_Y_LSB = 0x0a,
144  REG_ACC_DATA_Y_MSB = 0x0b,
145  REG_ACC_DATA_Z_LSB = 0x0c,
146  REG_ACC_DATA_Z_MSB = 0x0d,
147 
148  REG_MAG_DATA_X_LSB = 0x0e,
149  REG_MAG_DATA_X_MSB = 0x0f,
150  REG_MAG_DATA_Y_LSB = 0x10,
151  REG_MAG_DATA_Y_MSB = 0x11,
152  REG_MAG_DATA_Z_LSB = 0x12,
153  REG_MAG_DATA_Z_MSB = 0x13,
154 
155  REG_GYR_DATA_X_LSB = 0x14,
156  REG_GYR_DATA_X_MSB = 0x15,
157  REG_GYR_DATA_Y_LSB = 0x16,
158  REG_GYR_DATA_Y_MSB = 0x17,
159  REG_GYR_DATA_Z_LSB = 0x18,
160  REG_GYR_DATA_Z_MSB = 0x19,
161 
162  // euler angles
163  REG_EUL_HEADING_LSB = 0x1a,
164  REG_EUL_HEADING_MSB = 0x1b,
165  REG_EUL_ROLL_LSB = 0x1c,
166  REG_EUL_ROLL_MSB = 0x1d,
167  REG_EUL_PITCH_LSB = 0x1e,
168  REG_EUL_PITCH_MSB = 0x1f,
169 
170  // Quaternions
171  REG_QUA_DATA_W_LSB = 0x20,
172  REG_QUA_DATA_W_MSB = 0x21,
173  REG_QUA_DATA_X_LSB = 0x22,
174  REG_QUA_DATA_X_MSB = 0x23,
175  REG_QUA_DATA_Y_LSB = 0x24,
176  REG_QUA_DATA_Y_MSB = 0x25,
177  REG_QUA_DATA_Z_LSB = 0x26,
178  REG_QUA_DATA_Z_MSB = 0x27,
179 
180  // linear accel data
181  REG_LIA_DATA_X_LSB = 0x28,
182  REG_LIA_DATA_X_MSB = 0x29,
183  REG_LIA_DATA_Y_LSB = 0x2a,
184  REG_LIA_DATA_Y_MSB = 0x2b,
185  REG_LIA_DATA_Z_LSB = 0x2c,
186  REG_LIA_DATA_Z_MSB = 0x2d,
187 
188  // gravity vector
189  REG_GRV_DATA_X_LSB = 0x2e,
190  REG_GRV_DATA_X_MSB = 0x2f,
191  REG_GRV_DATA_Y_LSB = 0x30,
192  REG_GRV_DATA_Y_MSB = 0x31,
193  REG_GRV_DATA_Z_LSB = 0x32,
194  REG_GRV_DATA_Z_MSB = 0x33,
195 
196  REG_TEMPERATURE = 0x34,
197 
198  REG_CALIB_STAT = 0x35, // calibration status
199  REG_ST_RESULT = 0x36, // selftest result
200 
201  REG_INT_STA = 0x37, // interrupt status
202 
203  REG_SYS_CLK_STATUS = 0x38,
204 
205  REG_SYS_STATUS = 0x39,
206  REG_SYS_ERROR = 0x3a,
207 
208  REG_UNIT_SEL = 0x3b,
209 
210  // 0x3c reserved
211 
212  REG_OPER_MODE = 0x3d, // operating mode
213  REG_POWER_MODE = 0x3e,
214 
215  REG_SYS_TRIGGER = 0x3f,
216  REG_TEMP_SOURCE = 0x40, // temperature src
217 
218  REG_AXIS_MAP_CONFIG = 0x41,
219  REG_AXIS_MAP_SIGN = 0x42,
220 
221  // 0x43-0x54 reserved
222 
223  // stored configuration data
224  REG_ACC_OFFSET_X_LSB = 0x55,
225  REG_ACC_OFFSET_X_MSB = 0x56,
226  REG_ACC_OFFSET_Y_LSB = 0x57,
227  REG_ACC_OFFSET_Y_MSB = 0x58,
228  REG_ACC_OFFSET_Z_LSB = 0x59,
229  REG_ACC_OFFSET_Z_MSB = 0x5a,
230 
231  REG_MAG_OFFSET_X_LSB = 0x5b,
232  REG_MAG_OFFSET_X_MSB = 0x5c,
233  REG_MAG_OFFSET_Y_LSB = 0x5d,
234  REG_MAG_OFFSET_Y_MSB = 0x5e,
235  REG_MAG_OFFSET_Z_LSB = 0x5f,
236  REG_MAG_OFFSET_Z_MSB = 0x60,
237 
238  REG_GYR_OFFSET_X_LSB = 0x61,
239  REG_GYR_OFFSET_X_MSB = 0x62,
240  REG_GYR_OFFSET_Y_LSB = 0x63,
241  REG_GYR_OFFSET_Y_MSB = 0x64,
242  REG_GYR_OFFSET_Z_LSB = 0x65,
243  REG_GYR_OFFSET_Z_MSB = 0x66,
244 
245  REG_ACC_RADIUS_LSB = 0x67,
246  REG_ACC_RADIUS_MSB = 0x68,
247 
248  REG_MAG_RADIUS_LSB = 0x69,
249  REG_MAG_RADIUS_MSB = 0x6a,
250 
251  // 0x6b-0x7f reserved
252  // end of page 0
253 
254  // Page 1
255 
256  // 0x00-0x06 reserved
257  // 0x07 - page id
258 
259  REG_ACC_CONFIG = 0x08,
260  REG_MAG_CONFIG = 0x09,
261  REG_GYR_CONFIG0 = 0x0a,
262  REG_GYR_CONFIG1 = 0x0b,
263  REG_ACC_SLEEP_CONFIG = 0x0c,
264  REG_GYR_SLEEP_CONFIG = 0x0d,
265 
266  // 0x0e reserved
267  REG_INT_MSK = 0x0f,
268  REG_INT_EN = 0x10,
269 
270  REG_ACC_AM_THRES = 0x11,
271  REG_ACC_INT_SETTINGS = 0x12,
272  REG_ACC_HG_DURATION = 0x13,
273  REG_ACC_HG_THRES = 0x14,
274  REG_ACC_NM_THRES = 0x15,
275  REG_ACC_NM_SET = 0x16,
276 
277  REG_GYR_INT_SETTING = 0x17,
278  REG_GYR_HR_X_SET = 0x18,
279  REG_GYR_DUR_X = 0x19,
280  REG_GYR_HR_Y_SET = 0x1a,
281  REG_GYR_DUR_Y = 0x1b,
282  REG_GYR_HR_Z_SET = 0x1c,
283  REG_GYR_DUR_Z = 0x1d,
284  REG_GYR_AM_THRES = 0x1e,
285  REG_GYR_AM_SET = 0x1f,
286 
287  // 0x20-0x4f reserved
288 
289  // 16 byte (0x50-0x5f) unique ID
290  REG_BNO_UNIQUE_ID = 0x50
291 
292  // 0x60-0x7f reserved
293  } REGS_T;
294 
295  // Page 0 register enumerants
296 
300  typedef enum {
301  CALIB_STAT_MAG0 = 0x01,
302  CALIB_STAT_MAG1 = 0x02,
303  _CALIB_STAT_MAG_MASK = 3,
304  _CALIB_STAT_MAG_SHIFT = 0,
305 
306  CALIB_STAT_ACC0 = 0x04,
307  CALIB_STAT_ACC1 = 0x08,
308  _CALIB_STAT_ACC_MASK = 3,
309  _CALIB_STAT_ACC_SHIFT = 2,
310 
311  CALIB_STAT_GYR0 = 0x10,
312  CALIB_STAT_GYR1 = 0x20,
313  _CALIB_STAT_GYR_MASK = 3,
314  _CALIB_STAT_GYR_SHIFT = 4,
315 
316  CALIB_STAT_SYS0 = 0x40,
317  CALIB_STAT_SYS1 = 0x80,
318  _CALIB_STAT_SYS_MASK = 3,
319  _CALIB_STAT_SYS_SHIFT = 6
321 
325  typedef enum {
326  ST_RESULT_ACC = 0x01,
327  ST_RESULT_MAG = 0x02,
328  ST_RESULT_GYR = 0x04,
329  ST_RESULT_MCU = 0x08
330  // 0x10-0x80 reserved
332 
336  typedef enum {
337  // 0x01-0x02 reserved
338  INT_STA_GYRO_AM = 0x04, // gyro any-motion
339  INT_STA_GYR_HIGH_RATE = 0x08,
340  // 0x010 reserved
341  INT_STA_ACC_HIGH_G = 0x20,
342  INT_STA_ACC_AM = 0x40, // accel any-motion
343  INT_STA_ACC_NM = 0x80 // accel no-motion
344  } INT_STA_BITS_T;
345 
349  typedef enum {
350  SYS_CLK_STATUS_ST_MAIN_CLK = 0x01
351  // 0x02-0x80 reserved
353 
357  typedef enum {
358  SYS_STATUS_IDLE = 0,
359  SYS_STATUS_SYS_ERR = 1,
360  SYS_STATUS_INIT_PERIPHERALS = 2,
361  SYS_STATUS_SYSTEM_INIT = 3,
362  SYS_STATUS_EXECUTING_SELFTEST = 4,
363  SYS_STATUS_FUSION_RUNNING = 5,
364  SYS_STATUS_NO_FUSION_RUNNING = 6
365  } SYS_STATUS_T;
366 
370  typedef enum {
371  SYS_ERR_NOERROR = 0,
372  SYS_ERR_PERIPH_INIT_ERROR = 1,
373  SYS_ERR_SYS_INIT_ERROR = 2,
374  SYS_ERR_SELFTEST_FAIL_ERROR = 3,
375  SYS_ERR_REG_VAL_OUTOFRANGE_ERROR = 4,
376  SYS_ERR_REG_ADDR_OUTOFRANGE_ERROR = 5,
377  SYS_ERR_REG_WRITE_ERROR = 6,
378  SYS_ERR_LP_MODE_NOT_AVAIL_ERROR = 7,
379  SYS_ERR_ACC_PWR_MODE_NOT_AVAIL_ERROR = 8,
380  SYS_ERR_FUSION_CONFIG_ERROR = 9,
381  SYS_ERR_SENSOR_CONFIG_ERROR = 10
382  } SYS_ERR_T;
383 
384 
388  typedef enum {
389  UNIT_SEL_ACC_UNIT = 0x01, // 0=m/s^2, 1=mg
390  UNIT_SEL_GYR_UNIT = 0x02, // 0=dps, 1=rps
391  UNIT_SEL_EUL_UNIT = 0x04, // 0=degrees, 1=radians
392  // 0x08 reserved
393  UNIT_SEL_TEMP_UNIT = 0x10, // 0=C, 1=F
394  // 0x20-0x40 reserved
395  UNIT_SEL_ORI_ANDROID_WINDOWS = 0x80 // 0=windows orient, 1=android
396  } UNIT_SEL_BITS_T;
397 
401  typedef enum {
402  OPR_MODE_OPERATION_MODE0 = 0x01,
403  OPR_MODE_OPERATION_MODE1 = 0x02,
404  OPR_MODE_OPERATION_MODE2 = 0x04,
405  OPR_MODE_OPERATION_MODE3 = 0x08,
406  _OPR_MODE_OPERATION_MODE_MASK = 15,
407  _OPR_MODE_OPERATION_MODE_SHIFT = 0
408  // 0x10-0x80 reserved
409  } OPR_MODE_BITS_T;
410 
414  typedef enum {
415  OPERATION_MODE_CONFIGMODE = 0,
416  OPERATION_MODE_ACCONLY = 1,
417  OPERATION_MODE_MAGONLY = 2,
418  OPERATION_MODE_GYROONLY = 3,
419  OPERATION_MODE_ACCMAG = 4,
420  OPERATION_MODE_ACCGYRO = 5,
421  OPERATION_MODE_MAGGYRO = 6,
422  OPERATION_MODE_AMG = 7,
423  // fusion modes
424  OPERATION_MODE_IMU = 8,
425  OPERATION_MODE_COMPASS = 9,
426  OPERATION_MODE_M4G = 10,
427  OPERATION_MODE_NDOF_FMC_OFF = 11,
428  OPERATION_MODE_NDOF = 12
430 
434  typedef enum {
435  PWR_MODE_POWER_MODE0 = 0x01,
436  PWR_MODE_POWER_MODE1 = 0x02,
437  _PWR_MODE_POWER_MODE_MASK = 3,
438  _PWR_MODE_POWER_MODE_SHIFT = 0
439  // 0x04-0x80 reserved
440  } PWR_MODE_BITS_T;
441 
445  typedef enum {
446  POWER_MODE_NORMAL = 0,
447  POWER_MODE_LOW = 1,
448  POWER_MODE_SUSPEND = 2
449  } POWER_MODES_T;
450 
454  typedef enum {
455  SYS_TRIGGER_SELF_TEST = 0x01,
456  // 0x02-0x10 reserved
457  SYS_TRIGGER_RST_SYS = 0x20,
458  SYS_TRIGGER_RST_INT = 0x40,
459  SYS_TRIGGER_CLK_SEL = 0x80
461 
465  typedef enum {
466  TEMP_SOURCE_TEMP_SOURCE0 = 0x01,
467  TEMP_SOURCE_TEMP_SOURCE1 = 0x02,
468  _TEMP_SOURCE_TEMP_SOURCE_MASK = 3,
469  _TEMP_SOURCE_TEMP_SOURCE_SHIFT = 0
470  // 0x04-0x80 reserved
472 
476  typedef enum {
477  TEMP_SOURCE_ACC = 0,
478  TEMP_SOURCE_GYR = 1
479  } TEMP_SOURCES_T;
480 
484  typedef enum {
485  AXIS_MAP_CONFIG_REMAPPED_X_VAL0 = 0x01,
486  AXIS_MAP_CONFIG_REMAPPED_X_VAL1 = 0x02,
487  _AXIS_MAP_CONFIG_REMAPPED_X_VAL_MASK = 3,
488  _AXIS_MAP_CONFIG_REMAPPED_X_VAL_SHIFT = 0,
489 
490  AXIS_MAP_CONFIG_REMAPPED_Y_VAL0 = 0x04,
491  AXIS_MAP_CONFIG_REMAPPED_Y_VAL1 = 0x08,
492  _AXIS_MAP_CONFIG_REMAPPED_Y_VAL_MASK = 3,
493  _AXIS_MAP_CONFIG_REMAPPED_Y_VAL_SHIFT = 2,
494 
495  AXIS_MAP_CONFIG_REMAPPED_Z_VAL0 = 0x10,
496  AXIS_MAP_CONFIG_REMAPPED_Z_VAL1 = 0x20,
497  _AXIS_MAP_CONFIG_REMAPPED_Z_VAL_MASK = 3,
498  _AXIS_MAP_CONFIG_REMAPPED_Z_VAL_SHIFT = 4
499  // 0x40-0x80 reserved
501 
506  typedef enum {
507  REMAPPED_AXIS_X = 0,
508  REMAPPED_AXIS_Y = 1,
509  REMAPPED_AXIS_Z = 2
510  } REMAPPED_AXIS_T;
511 
512 
516  typedef enum {
517  AXIS_MAP_SIGN_REMAPPED_Z_SIGN = 0x01,
518  AXIS_MAP_SIGN_REMAPPED_Y_SIGN = 0x02,
519  AXIS_MAP_SIGN_REMAPPED_X_SIGN = 0x04
520  // 0x08-0x80 reserved
522 
523  // Page 1 register enumerants
524 
528  typedef enum {
529  ACC_CONFIG_ACC_RANGE0 = 0x01,
530  ACC_CONFIG_ACC_RANGE1 = 0x02,
531  _ACC_CONFIG_ACC_RANGE_MASK = 3,
532  _ACC_CONFIG_ACC_RANGE_SHIFT = 0,
533 
534  ACC_CONFIG_ACC_BW0 = 0x04,
535  ACC_CONFIG_ACC_BW1 = 0x08,
536  ACC_CONFIG_ACC_BW2 = 0x10,
537  _ACC_CONFIG_ACC_BW_MASK = 7,
538  _ACC_CONFIG_ACC_BW_SHIFT = 2,
539 
540  ACC_CONFIG_ACC_PWR_MODE0 = 0x20,
541  ACC_CONFIG_ACC_PWR_MODE1 = 0x40,
542  ACC_CONFIG_ACC_PWR_MODE2 = 0x80,
543  _ACC_CONFIG_ACC_PWR_MODE_MASK = 7,
544  _ACC_CONFIG_ACC_PWR_MODE_SHIFT = 5
546 
550  typedef enum {
551  ACC_RANGE_2G = 0,
552  ACC_RANGE_4G = 1,
553  ACC_RANGE_8G = 2,
554  ACC_RANGE_16G = 3
555  } ACC_RANGE_T;
556 
560  typedef enum {
561  ACC_BW_7_81 = 0, // 7.81 Hz
562  ACC_BW_15_53 = 1,
563  ACC_BW_31_25 = 2,
564  ACC_BW_62_5 = 3,
565  ACC_BW_125 = 4, // 125 Hz
566  ACC_BW_250 = 5,
567  ACC_BW_500 = 6,
568  ACC_BW_1000 = 7
569  } ACC_BW_T;
570 
574  typedef enum {
575  ACC_PWR_MODE_NORMAL = 0,
576  ACC_PWR_MODE_SUSPEND = 1,
577  ACC_PWR_MODE_LOWPOWER1 = 2,
578  ACC_PWR_MODE_STANDBY = 3,
579  ACC_PWR_MODE_LOWPOWER2 = 4,
580  ACC_PWR_MODE_DEEPSUSPEND = 5
581  } ACC_PWR_MODE_T;
582 
586  typedef enum {
587  MAG_CONFIG_MAG_ODR0 = 0x01,
588  MAG_CONFIG_MAG_ODR1 = 0x02,
589  MAG_CONFIG_MAG_ODR2 = 0x04,
590  _MAG_CONFIG_MAG_ODR_MASK = 7,
591  _MAG_CONFIG_MAG_ODR_SHIFT = 0,
592 
593  MAG_CONFIG_MAG_OPR_MODE0 = 0x08,
594  MAG_CONFIG_MAG_OPR_MODE1 = 0x10,
595  _MAG_CONFIG_MAG_OPR_MODE_MASK = 3,
596  _MAG_CONFIG_MAG_OPR_MODE_SHIFT = 3,
597 
598  MAG_CONFIG_MAG_POWER_MODE0 = 0x20,
599  MAG_CONFIG_MAG_POWER_MODE1 = 0x40,
600  _MAG_CONFIG_MAG_POWER_MODE_MASK = 3,
601  _MAG_CONFIG_MAG_POWER_MODE_SHIFT = 5
602  // 0x80 reserved
604 
608  typedef enum {
609  MAG_ODR_2 = 0, // 2Hz
610  MAG_ODR_6 = 1,
611  MAG_ODR_8 = 2,
612  MAG_ODR_10 = 3,
613  MAG_ODR_15 = 4,
614  MAG_ODR_20 = 5,
615  MAG_ODR_25 = 6,
616  MAG_ODR_30 = 7
617  } MAG_ODR_T;
618 
622  typedef enum {
623  MAG_OPR_LOW = 0, // low power
624  MAG_OPR_REGULAR = 1,
625  MAG_OPR_ENHANCED_REGULAR = 2,
626  MAG_OPR_HIGH_ACCURACY = 3
627  } MAG_OPR_T;
628 
632  typedef enum {
633  MAG_POWER_NORMAL = 0,
634  MAG_POWER_SLEEP = 1,
635  MAG_POWER_SUSPEND = 2,
636  MAG_POWER_FORCE_MODE = 3
637  } MAG_POWER_T;
638 
642  typedef enum {
643  GYR_CONFIG0_GYR_RANGE0 = 0x01,
644  GYR_CONFIG0_GYR_RANGE1 = 0x02,
645  GYR_CONFIG0_GYR_RANGE2 = 0x04,
646  _GYR_CONFIG0_GYR_RANGE_MASK = 7,
647  _GYR_CONFIG0_GYR_RANGE_SHIFT = 0,
648 
649  GYR_CONFIG0_GYR_BW0 = 0x08,
650  GYR_CONFIG0_GYR_BW1 = 0x10,
651  GYR_CONFIG0_GYR_BW2 = 0x20,
652  _GYR_CONFIG0_GYR_BW_MASK = 7,
653  _GYR_CONFIG0_GYR_BW_SHIFT = 3
654  // 0x40-0x80 reserved
656 
660  typedef enum {
661  GYR_RANGE_2000 = 0, // degrees/sec
662  GYR_RANGE_1000 = 1,
663  GYR_RANGE_500 = 2,
664  GYR_RANGE_250 = 3,
665  GYR_RANGE_125 = 4
666  } GYR_RANGE_T;
667 
671  typedef enum {
672  GYR_BW_523 = 0, // Hz
673  GYR_BW_230 = 1,
674  GYR_BW_116 = 2,
675  GYR_BW_47 = 3,
676  GYR_BW_23 = 4,
677  GYR_BW_12 = 5,
678  GYR_BW_64 = 6,
679  GYR_BW_32 = 7
680  } GYR_BW_T;
681 
685  typedef enum {
686  GYR_CONFIG1_GYR_POWER_MODE0 = 0x01,
687  GYR_CONFIG1_GYR_POWER_MODE1 = 0x02,
688  GYR_CONFIG1_GYR_POWER_MODE2 = 0x04,
689  _GYR_CONFIG1_GYR_POWER_MODE_MASK = 7,
690  _GYR_CONFIG1_GYR_POWER_MODE_SHIFT = 0
691  // 0x08-0x80 reserved
693 
697  typedef enum {
698  GYR_POWER_MODE_NORMAL = 0,
699  GYR_POWER_MODE_FAST_POWERUP = 1,
700  GYR_POWER_MODE_DEEP_SUSPEND = 2,
701  GYR_POWER_MODE_SUSPEND = 3,
702  GYR_POWER_MODE_ADVANCED_POWERSAVE= 4
704 
708  typedef enum {
709  ACC_SLEEP_CONFIG_SLP_MODE = 0x01, // 0=event, 1=equidistant sample
710 
711  ACC_SLEEP_CONFIG_ACC_SLP_DUR0 = 0x02,
712  ACC_SLEEP_CONFIG_ACC_SLP_DUR1 = 0x04,
713  ACC_SLEEP_CONFIG_ACC_SLP_DUR2 = 0x08,
714  ACC_SLEEP_CONFIG_ACC_SLP_DUR3 = 0x10,
715  _ACC_SLEEP_CONFIG_ACC_SLP_DUR_MASK = 15,
716  _ACC_SLEEP_CONFIG_ACC_SLP_DUR_SHIFT = 1
717  // 0x20-0x80 reserved
719 
723  typedef enum {
724  ACC_SLP_DUR_0_5 = 0, // 0.5ms
725  // same for 1-5
726 
727  ACC_SLP_DUR_1 = 6, // 1ms
728  ACC_SLP_DUR_2 = 7,
729  ACC_SLP_DUR_4 = 8,
730  ACC_SLP_DUR_6 = 9,
731  ACC_SLP_DUR_10 = 10,
732  ACC_SLP_DUR_25 = 11,
733  ACC_SLP_DUR_50 = 12,
734  ACC_SLP_DUR_100 = 13,
735  ACC_SLP_DUR_500 = 14
736  // 15 = 1ms
737  } ACC_SLP_DUR_T;
738 
742  typedef enum {
743  GYR_SLEEP_CONFIG_GYR_SLEEP_DUR0 = 0x01,
744  GYR_SLEEP_CONFIG_GYR_SLEEP_DUR1 = 0x02,
745  GYR_SLEEP_CONFIG_GYR_SLEEP_DUR2 = 0x04,
746  _GYR_SLEEP_CONFIG_GYR_SLEEP_DUR_MASK = 7,
747  _GYR_SLEEP_CONFIG_GYR_SLEEP_DUR_SHIFT = 0,
748 
749  GYR_SLEEP_CONFIG_GYR_AUTO_SLP_DUR0 = 0x08,
750  GYR_SLEEP_CONFIG_GYR_AUTO_SLP_DUR1 = 0x10,
751  GYR_SLEEP_CONFIG_GYR_AUTO_SLP_DUR2 = 0x20,
752  _GYR_SLEEP_CONFIG_GYR_AUTO_SLP_DUR_MASK = 7,
753  _GYR_SLEEP_CONFIG_GYR_AUTO_SLP_DUR_SHIFT = 3
754  // 0x40-0x80 reserved
756 
760  typedef enum {
761  GYR_SLEEP_DUR_2 = 0, // 2ms
762  GYR_SLEEP_DUR_4 = 1,
763  GYR_SLEEP_DUR_5 = 2,
764  GYR_SLEEP_DUR_8 = 3,
765  GYR_SLEEP_DUR_10 = 4,
766  GYR_SLEEP_DUR_15 = 5,
767  GYR_SLEEP_DUR_18 = 6,
768  GYR_SLEEP_DUR_20 = 7
769  } GYR_SLEEP_DUR_T;
770 
774  typedef enum {
775  // 0 = illegal
776  GYR_AUTO_SLP_DUR_4 = 1, // ms
777  GYR_AUTO_SLP_DUR_5 = 2,
778  GYR_AUTO_SLP_DUR_8 = 3,
779  GYR_AUTO_SLP_DUR_10 = 4,
780  GYR_AUTO_SLP_DUR_15 = 5,
781  GYR_AUTO_SLP_DUR_20 = 6,
782  GYR_AUTO_SLP_DUR_40 = 7
784 
788  typedef enum {
789  // 0x00-0x02 reserved
790  INT_GYRO_AM = 0x04, // gyro any-motion
791  INT_GYRO_HIGH_RATE = 0x08,
792  // 0x10 reserved
793  INT_ACC_HIGH_G = 0x20,
794  INT_ACC_AM = 0x40, // acc any-motion
795  INT_ACC_NM = 0x80, // acc no-motion
796  } INT_BITS_T;
797 
801  typedef enum {
802  ACC_INT_SETTINGS_AM_DUR0 = 0x01,
803  ACC_INT_SETTINGS_AM_DUR1 = 0x02,
804  _ACC_INT_SETTINGS_AM_DUR_MASK = 3,
805  _ACC_INT_SETTINGS_AM_DUR_SHIFT = 0,
806 
807  ACC_INT_SETTINGS_AM_NM_X_AXIS = 0x04,
808  ACC_INT_SETTINGS_AM_NM_Y_AXIS = 0x08,
809  ACC_INT_SETTINGS_AM_NM_Z_AXIS = 0x10,
810 
811  ACC_INT_SETTINGS_HG_X_AXIS = 0x20,
812  ACC_INT_SETTINGS_HG_Y_AXIS = 0x40,
813  ACC_INT_SETTINGS_HG_Z_AXIS = 0x80
815 
819  typedef enum {
820  ACC_NM_SET_SM_NM = 0x01, // 0=slowmotion, 1=nomotion
821 
822  ACC_NM_SET_SM_NM_DUR0 = 0x02,
823  ACC_NM_SET_SM_NM_DUR1 = 0x04,
824  ACC_NM_SET_SM_NM_DUR2 = 0x08,
825  ACC_NM_SET_SM_NM_DUR3 = 0x10,
826  ACC_NM_SET_SM_NM_DUR4 = 0x20,
827  ACC_NM_SET_SM_NM_DUR5 = 0x40,
828  _ACC_NM_SET_SM_NM_DUR_MASK = 63,
829  _ACC_NM_SET_SM_NM_DUR_SHIFT = 1
830  // 0x80 reserved
832 
836  typedef enum {
837  GYR_INT_SETTING_AM_X_AXIS = 0x01,
838  GYR_INT_SETTING_AM_Y_AXIS = 0x02,
839  GYR_INT_SETTING_AM_Z_AXIS = 0x04,
840 
841  GYR_INT_SETTING_HR_X_AXIS = 0x08,
842  GYR_INT_SETTING_HR_Y_AXIS = 0x10,
843  GYR_INT_SETTING_HR_Z_AXIS = 0x20,
844 
845  GYR_INT_SETTING_AM_FILT = 0x40,
846  GYR_INT_SETTING_HR_FILT = 0x80
848 
852  typedef enum {
853  GYR_HR_XYZ_SET_HR_THRESH0 = 0x01,
854  GYR_HR_XYZ_SET_HR_THRESH1 = 0x02,
855  GYR_HR_XYZ_SET_HR_THRESH2 = 0x04,
856  GYR_HR_XYZ_SET_HR_THRESH3 = 0x08,
857  GYR_HR_XYZ_SET_HR_THRESH4 = 0x10,
858  _GYR_HR_XYZ_SET_HR_THRESH_MASK = 31,
859  _GYR_HR_XYZ_SET_HR_THRESH_SHIFT = 0,
860 
861  GYR_HR_XYZ_SET_HR_THRESH_HYST0 = 0x20,
862  GYR_HR_XYZ_SET_HR_THRESH_HYST1 = 0x40,
863  _GYR_HR_XYZ_SET_HR_THRESH_HYST_MASK = 3,
864  _GYR_HR_XYZ_SET_HR_THRESH_HYST_SHIFT = 5
866 
870  typedef enum {
871  GYR_AM_SET_SLOPE_SAMPLES0 = 0x01,
872  GYR_AM_SET_SLOPE_SAMPLES1 = 0x02,
873  _GYR_AM_SET_SLOPE_SAMPLES_MASK = 3,
874  _GYR_AM_SET_SLOPE_SAMPLES_SHIFT = 0,
875 
876  GYR_AM_SET_AWAKE_DUR0 = 0x04,
877  GYR_AM_SET_AWAKE_DUR1 = 0x08,
878  _GYR_AM_SET_AWAKE_DUR_MASK = 3,
879  _GYR_AM_SET_AWAKE_DUR_SHIFT = 2
880 
881  // 0x10-0x80 reserved
883 
887  typedef enum {
888  SLOPE_SAMPLES_8 = 0, // 8 samples
889  SLOPE_SAMPLES_16 = 1,
890  SLOPE_SAMPLES_32 = 2,
891  SLOPE_SAMPLES_64 = 3
892  } SLOPE_SAMPLES_T;
893 
909  BNO055(int bus=BNO055_I2C_BUS, uint8_t addr=BNO055_DEFAULT_ADDR);
910 
914  ~BNO055();
915 
919  void update();
920 
926  uint8_t getChipID();
927 
933  uint8_t getACCID();
934 
940  uint8_t getMAGID();
941 
947  uint8_t getGYRID();
948 
954  uint16_t getSWRevID();
955 
961  uint8_t getBootLoaderID();
962 
970  void setClockExternal(bool extClock);
971 
980 
987  void setTemperatureUnits(bool celsius);
988 
999 
1005  void resetSystem();
1006 
1016  void getCalibrationStatus(int *mag, int *acc, int *gyr, int *sys);
1017 
1026  int *getCalibrationStatus();
1027 
1036  bool isFullyCalibrated();
1037 
1045  std::string readCalibrationData();
1046 
1054  void writeCalibrationData(std::string calibData);
1055 
1066  float getTemperature(bool fahrenheit=false);
1067 
1080  void getEulerAngles(float *heading, float *roll, float *pitch);
1081 
1091  float *getEulerAngles();
1092 
1107  void getQuaternions(float *w, float *x, float *y, float *z);
1108 
1117  float *getQuaternions();
1118 
1132  void getLinearAcceleration(float *x, float *y, float *z);
1133 
1142  float *getLinearAcceleration();
1143 
1157  void getGravityVectors(float *x, float *y, float *z);
1158 
1167  float *getGravityVectors();
1168 
1182  void getAccelerometer(float *x, float *y, float *z);
1183 
1193  float *getAccelerometer();
1194 
1208  void getMagnetometer(float *x, float *y, float *z);
1209 
1219  float *getMagnetometer();
1220 
1234  void getGyroscope(float *x, float *y, float *z);
1235 
1245  float *getGyroscope();
1246 
1256  ACC_PWR_MODE_T pwr);
1257 
1267  MAG_POWER_T pwr);
1268 
1277  void setGyroscopeConfig(GYR_RANGE_T range, GYR_BW_T bw,
1278  GYR_POWER_MODE_T pwr);
1279 
1287  void setAccelerometerUnits(bool mg=false);
1288 
1296  void setGyroscopeUnits(bool radians=false);
1297 
1305  void setEulerUnits(bool radians=false);
1306 
1310  void resetInterruptStatus();
1311 
1318  uint8_t getInterruptStatus();
1319 
1327  uint8_t getInterruptEnable();
1328 
1335  void setInterruptEnable(uint8_t enables);
1336 
1347  uint8_t getInterruptMask();
1348 
1359  void setInterruptMask(uint8_t mask);
1360 
1368 
1377 
1378 
1379 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
1380  void installISR(int gpio, mraa::Edge level, jobject runnable);
1381 #else
1382 
1392  void installISR(int gpio, mraa::Edge level,
1393  void (*isr)(void *), void *arg);
1394 #endif
1395 
1400  void uninstallISR();
1401 
1402  protected:
1403  mraa::I2c m_i2c;
1404  mraa::Gpio *m_gpioIntr;
1405  uint8_t m_addr;
1406 
1407  // always stored in C
1408  float m_temperature;
1409 
1410  // uncompensated data
1411 
1412  // mag data
1413  float m_magX;
1414  float m_magY;
1415  float m_magZ;
1416 
1417  // acc data
1418  float m_accX;
1419  float m_accY;
1420  float m_accZ;
1421 
1422  // acc units
1423  float m_accUnitScale;
1424 
1425  // gyr data
1426  float m_gyrX;
1427  float m_gyrY;
1428  float m_gyrZ;
1429 
1430  // gyr units
1431  float m_gyrUnitScale;
1432 
1433  // eul (euler angle) data
1434  float m_eulHeading;
1435  float m_eulRoll;
1436  float m_eulPitch;
1437 
1438  // eul units
1439  float m_eulUnitScale;
1440 
1441  // qua (quaternion) data
1442  float m_quaW;
1443  float m_quaX;
1444  float m_quaY;
1445  float m_quaZ;
1446 
1447  // lia (linear acceleration) data
1448  float m_liaX;
1449  float m_liaY;
1450  float m_liaZ;
1451 
1452  // grv (gravity vector) data
1453  float m_grvX;
1454  float m_grvY;
1455  float m_grvZ;
1456 
1457  void clearData();
1458  bool updateFusionData();
1459  bool updateNonFusionData();
1460  void setPage(uint8_t page, bool force=false);
1461 
1468  uint8_t readReg(uint8_t reg);
1469 
1476  void readRegs(uint8_t reg, uint8_t *buffer, int len);
1477 
1485  bool writeReg(uint8_t reg, uint8_t val);
1486 
1495  bool writeRegs(uint8_t reg, uint8_t *buffer, int len);
1496 
1497  private:
1498  int m_currentPage;
1499  OPERATION_MODES_T m_currentMode;
1500  bool m_tempIsC;
1501 
1502  // Adding a private function definition for java bindings
1503 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
1504  void installISR(int gpio, mraa::Edge level,
1505  void (*isr)(void *), void *arg);
1506 #endif
1507  };
1508 }
float * getEulerAngles()
Definition: bno055.cxx:602
float * getMagnetometer()
Definition: bno055.cxx:706
void resetSystem()
Definition: bno055.cxx:383
float * getGravityVectors()
Definition: bno055.cxx:665
uint8_t getInterruptStatus()
Definition: bno055.cxx:406
MAG_CONFIG_BITS_T
Definition: bno055.hpp:586
void writeCalibrationData(std::string calibData)
Definition: bno055.cxx:482
ACC_INT_SETTINGS_BITS_T
Definition: bno055.hpp:801
SYS_CLK_STATUS_BITS_T
Definition: bno055.hpp:349
GYR_CONFIG1_BITS_T
Definition: bno055.hpp:685
INT_BITS_T
Definition: bno055.hpp:788
float * getLinearAcceleration()
Definition: bno055.cxx:646
uint8_t getInterruptEnable()
Definition: bno055.cxx:413
ST_RESULT_BITS_T
Definition: bno055.hpp:325
AXIS_MAP_SIGN_BITS_T
Definition: bno055.hpp:516
bool writeRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bno055.cxx:150
REGS_T
Definition: bno055.hpp:123
MAG_ODR_T
Definition: bno055.hpp:608
void setTemperatureSource(TEMP_SOURCES_T src)
Definition: bno055.cxx:242
GYR_CONFIG0_BITS_T
Definition: bno055.hpp:642
void setOperationMode(OPERATION_MODES_T mode)
Definition: bno055.cxx:324
uint8_t readReg(uint8_t reg)
Definition: bno055.cxx:128
void setClockExternal(bool extClock)
Definition: bno055.cxx:221
MAG_OPR_T
Definition: bno055.hpp:622
void readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bno055.cxx:133
SLOPE_SAMPLES_T
Definition: bno055.hpp:887
uint8_t getACCID()
Definition: bno055.cxx:174
MAG_POWER_T
Definition: bno055.hpp:632
ACC_RANGE_T
Definition: bno055.hpp:550
OPERATION_MODES_T
Definition: bno055.hpp:414
GYR_BW_T
Definition: bno055.hpp:671
ACC_SLEEP_CONFIG_BITS_T
Definition: bno055.hpp:708
INT_STA_BITS_T
Definition: bno055.hpp:336
GYR_AM_SET_BITS_T
Definition: bno055.hpp:870
uint8_t getInterruptMask()
Definition: bno055.cxx:427
uint8_t getGYRID()
Definition: bno055.cxx:186
uint16_t getSWRevID()
Definition: bno055.cxx:192
SYS_STATUS_T
Definition: bno055.hpp:357
void uninstallISR()
Definition: bno055.cxx:800
ACC_NM_SET_BITS_T
Definition: bno055.hpp:819
POWER_MODES_T
Definition: bno055.hpp:445
GYR_RANGE_T
Definition: bno055.hpp:660
SYS_ERR_T
Definition: bno055.hpp:370
bool isFullyCalibrated()
Definition: bno055.cxx:370
void installISR(int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: bno055.cxx:786
void setInterruptEnable(uint8_t enables)
Definition: bno055.cxx:420
GYR_INT_SETTING_BITS_T
Definition: bno055.hpp:836
SYS_ERR_T getSystemError()
Definition: bno055.cxx:448
void setAccelerationConfig(ACC_RANGE_T range, ACC_BW_T bw, ACC_PWR_MODE_T pwr)
Definition: bno055.cxx:732
UNIT_SEL_BITS_T
Definition: bno055.hpp:388
void setMagnetometerConfig(MAG_ODR_T odr, MAG_OPR_T opr, MAG_POWER_T pwr)
Definition: bno055.cxx:744
void setInterruptMask(uint8_t mask)
Definition: bno055.cxx:434
float * getQuaternions()
Definition: bno055.cxx:627
GYR_AUTO_SLP_DUR_T
Definition: bno055.hpp:774
uint8_t getBootLoaderID()
Definition: bno055.cxx:202
void resetInterruptStatus()
Definition: bno055.cxx:395
void setEulerUnits(bool radians=false)
Definition: bno055.cxx:304
void setAccelerometerUnits(bool mg=false)
Definition: bno055.cxx:264
void setGyroscopeConfig(GYR_RANGE_T range, GYR_BW_T bw, GYR_POWER_MODE_T pwr)
Definition: bno055.cxx:756
uint8_t getChipID()
Definition: bno055.cxx:168
API for the BNO055 Absolute Orientation 9DOF Fusion Hub.
Definition: bno055.hpp:105
SYS_TRIGGER_BITS_T
Definition: bno055.hpp:454
bool writeReg(uint8_t reg, uint8_t val)
Definition: bno055.cxx:138
ACC_BW_T
Definition: bno055.hpp:560
REMAPPED_AXIS_T
Definition: bno055.hpp:506
float * getGyroscope()
Definition: bno055.cxx:725
AXIS_MAP_CONFIG_BITS_T
Definition: bno055.hpp:484
TEMP_SOURCES_T
Definition: bno055.hpp:476
ACC_CONFIG_BITS_T
Definition: bno055.hpp:528
ACC_SLP_DUR_T
Definition: bno055.hpp:723
std::string readCalibrationData()
Definition: bno055.cxx:455
void setGyroscopeUnits(bool radians=false)
Definition: bno055.cxx:284
void update()
Definition: bno055.cxx:113
float getTemperature(bool fahrenheit=false)
Definition: bno055.cxx:507
void setTemperatureUnits(bool celsius)
Definition: bno055.cxx:248
OPR_MODE_BITS_T
Definition: bno055.hpp:401
TEMP_SOURCE_BITS_T
Definition: bno055.hpp:465
GYR_POWER_MODE_T
Definition: bno055.hpp:697
ACC_PWR_MODE_T
Definition: bno055.hpp:574
BNO055(int bus=BNO055_I2C_BUS, uint8_t addr=BNO055_DEFAULT_ADDR)
Definition: bno055.cxx:48
GYR_HR_XYZ_SET_BITS_T
Definition: bno055.hpp:852
float * getAccelerometer()
Definition: bno055.cxx:684
SYS_STATUS_T getSystemStatus()
Definition: bno055.cxx:441
CALIB_STAT_BITS_T
Definition: bno055.hpp:300
GYR_SLEEP_CONFIG_BITS_T
Definition: bno055.hpp:742
~BNO055()
Definition: bno055.cxx:108
GYR_SLEEP_DUR_T
Definition: bno055.hpp:760
PWR_MODE_BITS_T
Definition: bno055.hpp:434
int * getCalibrationStatus()
Definition: bno055.cxx:362
uint8_t getMAGID()
Definition: bno055.cxx:180