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
bmg160.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/spi.hpp>
29 #include <mraa/gpio.hpp>
30 
31 #define BMG160_I2C_BUS 0
32 #define BMG160_SPI_BUS 0
33 #define BMG160_DEFAULT_ADDR 0x68
34 
35 
36 namespace upm {
37 
69  class BMG160 {
70  public:
71  // special reset byte
72  static const uint8_t BMG160_RESET_BYTE = 0xb6;
73 
74  // NOTE: Reserved registers must not be written into. Reading
75  // from them may return indeterminate values. Registers
76  // containing reserved bitfields must be written as 0. Reading
77  // reserved bitfields may return indeterminate values.
78 
82  typedef enum : uint8_t {
83  REG_CHIP_ID = 0x00,
84 
85  // 0x01 reserved
86 
87  REG_RATE_X_LSB = 0x02,
88  REG_RATE_X_MSB = 0x03,
89  REG_RATE_Y_LSB = 0x04,
90  REG_RATE_Y_MSB = 0x05,
91  REG_RATE_Z_LSB = 0x06,
92  REG_RATE_Z_MSB = 0x07,
93 
94  REG_TEMP = 0x08,
95 
96  REG_INT_STATUS_0 = 0x09,
97  REG_INT_STATUS_1 = 0x0a,
98  REG_INT_STATUS_2 = 0x0b,
99  REG_INT_STATUS_3 = 0x0c,
100 
101  // 0x0d reserved
102 
103  REG_FIFO_STATUS = 0x0e,
104 
105  REG_GYR_RANGE = 0x0f,
106  REG_GYR_BW = 0x10,
107  REG_LPM1 = 0x11,
108  REG_LPM2 = 0x12,
109 
110  REG_RATE_HBW = 0x13,
111 
112  REG_SOFTRESET = 0x14,
113 
114  REG_INT_EN_0 = 0x15,
115  REG_INT_EN_1 = 0x16,
116 
117  REG_INT_MAP_0 = 0x17,
118  REG_INT_MAP_1 = 0x18,
119  REG_INT_MAP_2 = 0x19,
120 
121  REG_INT_1A = 0x1a,
122  REG_INT_1B = 0x1b,
123  REG_INT_1C = 0x1c,
124 
125  // 0x1d reserved
126 
127  REG_INT_1E = 0x1e,
128 
129  // 0x1f-0x20 reserved
130 
131  REG_INT_RST_LATCH = 0x21,
132 
133  REG_HIGH_TH_X = 0x22,
134  REG_HIGH_DUR_X = 0x23,
135  REG_HIGH_TH_Y = 0x24,
136  REG_HIGH_DUR_Y = 0x25,
137  REG_HIGH_TH_Z = 0x26,
138  REG_HIGH_DUR_Z = 0x27,
139 
140  // 0x28-0x30 reserved
141 
142  REG_SOC = 0x31,
143  REG_A_FOC = 0x32,
144 
145  REG_TRIM_NVM_CTRL = 0x33,
146 
147  REG_SPI3_WDT = 0x34,
148 
149  // 0x35 reserved
150 
151  REG_OFC1 = 0x36,
152  REG_OFC2 = 0x37,
153  REG_OFC3 = 0x38,
154  REG_OFC4 = 0x39,
155 
156  REG_TRIM_GP0 = 0x3a,
157  REG_TRIM_GP1 = 0x3b,
158 
159  REG_BIST = 0x3c,
160 
161  REG_FIFO_CONFIG_0 = 0x3d,
162  REG_FIFO_CONFIG_1 = 0x3e,
163 
164  REG_FIFO_DATA = 0x3f
165 
166  } BMG160_REGS_T;
167 
171  typedef enum {
172  _INT_STATUS_0_RESERVED_BITS = 0xf0 | 0x08 | 0x01,
173 
174  INT_STATUS_0_HIGH_INT = 0x02,
175  INT_STATUS_0_ANY_INT = 0x04
177 
181  typedef enum {
182  _INT_STATUS_1_RESERVED_BITS = 0x0f,
183 
184  INT_STATUS_1_FIFO_INT = 0x10,
185  INT_STATUS_1_FAST_OFFSET_INT = 0x20,
186  INT_STATUS_1_AUTO_OFFSET_INT = 0x40,
187  INT_STATUS_1_DATA_INT = 0x80
189 
193  typedef enum {
194  _INT_STATUS_2_RESERVED_BITS = 0xf0,
195 
196  INT_STATUS_2_ANY_FIRST_X = 0x01,
197  INT_STATUS_2_ANY_FIRST_Y = 0x02,
198  INT_STATUS_2_ANY_FIRST_Z = 0x04,
199  INT_STATUS_2_ANY_SIGN = 0x08
201 
205  typedef enum {
206  _INT_STATUS_3_RESERVED_BITS = 0xf0,
207 
208  INT_STATUS_3_HIGH_FIRST_X = 0x01,
209  INT_STATUS_3_HIGH_FIRST_Y = 0x02,
210  INT_STATUS_3_HIGH_FIRST_Z = 0x04,
211  INT_STATUS_3_HIGH_SIGN = 0x08
213 
217  typedef enum {
218  FIFO_STATUS_FRAME_COUNTER0 = 0x01,
219  FIFO_STATUS_FRAME_COUNTER1 = 0x02,
220  FIFO_STATUS_FRAME_COUNTER2 = 0x04,
221  FIFO_STATUS_FRAME_COUNTER3 = 0x08,
222  FIFO_STATUS_FRAME_COUNTER4 = 0x10,
223  FIFO_STATUS_FRAME_COUNTER5 = 0x20,
224  FIFO_STATUS_FRAME_COUNTER6 = 0x40,
225  _FIFO_STATUS_FRAME_COUNTER_MASK = 127,
226  _FIFO_STATUS_FRAME_COUNTER_SHIFT = 0,
227 
228  FIFO_STATUS_FIFO_OVERRUN = 0x80
230 
234  typedef enum {
235  _GYR_RANGE_RESERVED_BITS = 0x20 | 0x10 | 0x08,
236 
237  GYR_RANGE0 = 0x01,
238  GYR_RANGE1 = 0x02,
239  GYR_RANGE2 = 0x04,
240  _GYR_RANGE_MASK = 7,
241  _GYR_RANGE_SHIFT = 0,
242 
243  GYR_RANGE_FIXED0 = 0x40, // bits need hardcoding to 0b10
244  GYR_RANGE_FIXED1 = 0x80, // for some odd reason...
245  _GYR_RANGE_FIXED_MASK = 3,
246  _GYR_RANGE_FIXED_SHIFT = 6,
247  _GYR_RANGE_FIXED_VALUE = 2 // 0b10
249 
253  typedef enum {
254  RANGE_2000 = 0, // degrees/sec
255  RANGE_1000 = 1,
256  RANGE_500 = 2,
257  RANGE_250 = 3,
258  RANGE_125 = 4
259  } RANGE_T;
260 
264  typedef enum {
265  _GYR_BW_RESERVED_BITS = 0xf0,
266 
267  GYR_BW0 = 0x01,
268  GYR_BW1 = 0x02,
269  GYR_BW2 = 0x04,
270  GYR_BW3 = 0x08,
271  _GYR_BW_MASK = 15,
272  _GYR_BW_SHIFT = 0
273  } GYR_BW_BITS_T;
274 
278  typedef enum {
279  BW_2000_UNFILTERED = 0, // ODR/Filter BW
280  BW_2000_230 = 1, // ODR 2000Hz, Filter BW 230Hz
281  BW_1000_116 = 2,
282  BW_400_47 = 3,
283  BW_200_23 = 4,
284  BW_100_12 = 5,
285  BW_200_64 = 6,
286  BW_100_32 = 7
287  } BW_T;
288 
292  typedef enum {
293  // 0x01 reserved
294  _LPM1_RESERVED_MASK = 0x40 | 0x10 | 0x01,
295 
296  LPM1_SLEEP_DUR0 = 0x02, // sleep dur in low power mode
297  LPM1_SLEEP_DUR1 = 0x04,
298  LPM1_SLEEP_DUR2 = 0x08,
299  _LPM1_SLEEP_MASK = 7,
300  _LPM1_SLEEP_SHIFT = 1,
301 
302  // These are separate bits, deep_suspend and suspend (and if all
303  // 0, normal). Since only specific combinations are allowed, we
304  // will treat this as a 3 bit bitfield called POWER_MODE.
305  LPM1_POWER_MODE0 = 0x20, // deep_suspend
306  LPM1_POWER_MODE1 = 0x40, // must always be 0!
307  LPM1_POWER_MODE2 = 0x80, // suspend
308  _LPM1_POWER_MODE_MASK = 7,
309  _LPM1_POWER_MODE_SHIFT = 5
310  } LPM1_BITS_T;
311 
315  typedef enum {
316  SLEEP_DUR_2 = 0, // 2ms
317  SLEEP_DUR_4 = 1,
318  SLEEP_DUR_5 = 2,
319  SLEEP_DUR_8 = 3,
320  SLEEP_DUR_10 = 4,
321  SLEEP_DUR_15 = 5,
322  SLEEP_DUR_18 = 6,
323  SLEEP_DUR_20 = 7
324  } SLEEP_DUR_T;
325 
329  typedef enum {
330  POWER_MODE_NORMAL = 0,
331  POWER_MODE_DEEP_SUSPEND = 1,
332  POWER_MODE_SUSPEND = 4
333  } POWER_MODE_T;
334 
338  typedef enum {
339  _LPM2_RESERVED_BITS = 0x08,
340 
341  LPM2_AUTOSLEEP_DUR0 = 0x01,
342  LPM2_AUTOSLEEP_DUR1 = 0x02,
343  LPM2_AUTOSLEEP_DUR2 = 0x04,
344  _LPM2_AUTOSLEEP_DUR_MASK = 7,
345  _LPM2_AUTOSLEEP_DUR_SHIFT = 0,
346 
347  LPM2_EXT_TRIG_SEL0 = 0x10,
348  LPM2_EXT_TRIG_SEL1 = 0x20,
349  _LPM2_EXT_TRIG_SEL_MASK = 3,
350  _LPM2_EXT_TRIG_SEL_SHIFT = 4,
351 
352  LPM2_POWER_SAVE_MODE = 0x40,
353  LPM2_FAST_POWERUP = 0x80
354  } LPM2_BITS_T;
355 
356 
360  typedef enum {
361  AUTOSLEEP_DUR_NONE = 0,
362  AUTOSLEEP_DUR_4MS = 1,
363  AUTOSLEEP_DUR_5MS = 2,
364  AUTOSLEEP_DUR_8MS = 3,
365  AUTOSLEEP_DUR_10MS = 4,
366  AUTOSLEEP_DUR_15MS = 5,
367  AUTOSLEEP_DUR_20MS = 6,
368  AUTOSLEEP_DUR_40MS = 7
369  } AUTOSLEEP_DUR_T;
370 
374  typedef enum {
375  EXT_TRIG_SEL_NONE = 0,
376  EXT_TRIG_SEL_INT1 = 1,
377  EXT_TRIG_SEL_INT2 = 2,
378  EXT_TRIG_SEL_SDO = 3 // if SPI3 mode (unsupported)
379  } EXT_TRIG_SEL_T;
380 
384  typedef enum {
385  _RATE_HBW_RESERVED_BITS = 0x0f | 0x10 | 0x20,
386 
387  RATE_HBW_SHADOW_DIS = 0x40,
388  RATE_HBW_DATA_HIGH_BW = 0x80
389  } RATE_HBW_BITS_T;
390 
394  typedef enum {
395  _INT_EN_0_RESERVED_BITS = 0x20 | 0x10 | 0x08 | 0x02 | 0x01,
396 
397  INT_EN_0_AUTO_OFFSET_EN = 0x04,
398 
399  INT_EN_0_FIFO_EN = 0x40,
400  INT_EN_0_DATA_EN = 0x80
401  } INT_EN_0_BITS_T;
402 
406  typedef enum {
407  _INT_EN_1_INT1_RESERVED_BITS = 0xf0,
408 
409  INT_EN_1_INT1_LVL = 0x01, // level or edge
410  INT_EN_1_INT1_OD = 0x02, // push-pull or open drain
411  INT_EN_1_INT2_LVL = 0x04,
412  INT_EN_1_INT2_OD = 0x08
413  } INT_EN_1_BITS_T;
414 
418  typedef enum {
419  _INT_MAP_0_RESERVED_BITS = 0xf0 | 0x04 | 0x01,
420 
421  INT_MAP_0_INT1_ANY = 0x02,
422  INT_MAP_0_INT1_HIGH = 0x08
424 
428  typedef enum {
429  INT_MAP_1_INT1_DATA = 0x01,
430  INT_MAP_1_INT1_FAST_OFFSET = 0x02,
431  INT_MAP_1_INT1_FIFO = 0x04,
432  INT_MAP_1_INT1_AUTO_OFFSET = 0x08,
433  INT_MAP_1_INT2_AUTO_OFFSET = 0x10,
434  INT_MAP_1_INT2_FIFO = 0x20,
435  INT_MAP_1_INT2_FAST_OFFSET = 0x40,
436  INT_MAP_1_INT2_DATA = 0x80
438 
442  typedef enum {
443  _INT_1A_RESERVED_BITS = 0xd5,
444 
445  INT_1A_ANY_UNFILT_DATA = 0x02,
446  INT_1A_HIGH_UNFILT_DATA = 0x08,
447  INT_1A_SLOW_OFFSET_UNFILT = 0x20
448  } INT_1A_BITS_T;
449 
453  typedef enum {
454  INT_1B_ANY_TH0 = 0x01,
455  INT_1B_ANY_TH1 = 0x02,
456  INT_1B_ANY_TH2 = 0x04,
457  INT_1B_ANY_TH3 = 0x08,
458  INT_1B_ANY_TH4 = 0x10,
459  INT_1B_ANY_TH5 = 0x20,
460  INT_1B_ANY_TH6 = 0x40,
461  _INT_1B_ANY_TH_MASK = 127,
462  _INT_1B_ANY_TH_SHIFT = 0,
463 
464  INT_1B_FAST_OFFSET_UNFILT = 0x80
465  } INT_1B_BITS_T;
466 
470  typedef enum {
471  _INT_1C_RESERVED_BITS = 0x08,
472 
473  INT_1C_ANY_EN_X = 0x01,
474  INT_1C_ANY_EN_Y = 0x02,
475  INT_1C_ANY_EN_Z = 0x04,
476 
477  INT_1C_ANY_DUR_SAMPLE0 = 0x10,
478  INT_1C_ANY_DUR_SAMPLE1 = 0x20,
479  INT_1C_ANY_DUR_SAMPLE_MASK = 3,
480  INT_1C_ANY_DUR_SAMPLE_SHIFT = 4,
481 
482  INT_1C_AWAKE_DUR0 = 0x40,
483  INT_1C_AWAKE_DUR1 = 0x80,
484  INT_1C_AWAKE_DUR_MASK = 3,
485  INT_1C_AWAKE_DUR_SHIFT = 6
486  } INT_1C_BITS_T;
487 
491  typedef enum {
492  ANY_DUR_SAMPLE_4 = 0, // samples
493  ANY_DUR_SAMPLE_8 = 1,
494  ANY_DUR_SAMPLE_12 = 2,
495  ANY_DUR_SAMPLE_16 = 3
497 
501  typedef enum {
502  AWAKE_DUR_SAMPLE_8 = 0, // samples
503  AWAKE_DUR_SAMPLE_16 = 1,
504  AWAKE_DUR_SAMPLE_32 = 2,
505  AWAKE_DUR_SAMPLE_64 = 3
507 
511  typedef enum {
512  _INT_1E_RESERVED_BITS = 0x7f,
513 
514  INT_1E_FIFO_WM_EN = 0x80
515  } INT_1E_BITS_T;
516 
520  typedef enum {
521  _INT_RST_LATCH_RESERVED_BITS = 0x20,
522 
523  INT_RST_LATCH0 = 0x01,
524  INT_RST_LATCH1 = 0x02,
525  INT_RST_LATCH2 = 0x04,
526  INT_RST_LATCH3 = 0x08,
527  _INT_RST_LATCH_MASK = 15,
528  _INT_RST_LATCH_SHIFT = 0,
529 
530  INT_RST_LATCH_STATUS_BIT = 0x10,
531 
532  INT_RST_LATCH_OFFSET_RESET = 0x40,
533  INT_RST_LATCH_RESET_INT = 0x80
535 
539  typedef enum {
540  RST_LATCH_NON_LATCHED = 0,
541  RST_LATCH_TEMPORARY_250MS = 1,
542  RST_LATCH_TEMPORARY_500MS = 2,
543  RST_LATCH_TEMPORARY_1S = 3,
544  RST_LATCH_TEMPORARY_2S = 4,
545  RST_LATCH_TEMPORARY_4S = 5,
546  RST_LATCH_TEMPORARY_8S = 6,
547  RST_LATCH_LATCHED = 7,
548 
549  // 8 == non latched
550 
551  RST_LATCH_TEMPORARY_250US = 9,
552  RST_LATCH_TEMPORARY_500US = 10,
553  RST_LATCH_TEMPORARY_1MS = 11,
554  RST_LATCH_TEMPORARY_12_5MS = 12,
555  RST_LATCH_TEMPORARY_25MS = 13,
556  RST_LATCH_TEMPORARY_50MS = 14
557 
558  // 15 == latched
559  } RST_LATCH_T;
560 
564  typedef enum {
565  HIGH_TH_EN = 0x01,
566 
567  HIGH_TH_TH0 = 0x02,
568  HIGH_TH_TH1 = 0x04,
569  HIGH_TH_TH2 = 0x08,
570  HIGH_TH_TH3 = 0x10,
571  HIGH_TH_TH4 = 0x20,
572  _HIGH_TH_TH_MASK = 31,
573  _HIGH_TH_TH_SHIFT = 1,
574 
575  HIGH_TH_HY0 = 0x40,
576  HIGH_TH_HY1 = 0x80,
577  _HIGH_TH_HY_MASK = 3,
578  _HIGH_TH_HY_SHIFT = 6
579  } HIGH_TH_BITS_T;
580 
584  typedef enum {
585  SOC_SLOW_OFFSET_EN_X = 0x01,
586  SOC_SLOW_OFFSET_EN_Y = 0x02,
587  SOC_SLOW_OFFSET_EN_Z = 0x04,
588 
589  SOC_SLOW_OFFSET_DUR0 = 0x08,
590  SOC_SLOW_OFFSET_DUR1 = 0x10,
591  SOC_SLOW_OFFSET_DUR2 = 0x20,
592  _SOC_SLOW_OFFSET_DUR_MASK = 7,
593  _SOC_SLOW_OFFSET_DUR_SHIFT = 3,
594 
595  SOC_SLOW_OFFSET_TH0 = 0x40,
596  SOC_SLOW_OFFSET_TH1 = 0x80,
597  _SOC_SLOW_OFFSET_TH_MASK = 3,
598  _SOC_SLOW_OFFSET_TH_SHIFT = 6
599  } SOC_BITS_T;
600 
604  typedef enum {
605  SLOW_OFFSET_DUR_40MS = 0, // 40ms
606  SLOW_OFFSET_DUR_80MS = 1,
607  SLOW_OFFSET_DUR_160MS = 2,
608  SLOW_OFFSET_DUR_320MS = 3,
609  SLOW_OFFSET_DUR_640MS = 4,
610  SLOW_OFFSET_DUR_1280MS = 5
612 
616  typedef enum {
617  SLOW_OFFSET_TH_0_1 = 0, // 0.1 degree/s
618  SLOW_OFFSET_TH_0_2 = 1,
619  SLOW_OFFSET_TH_0_5 = 2,
620  SLOW_OFFSET_TH_1 = 3
622 
626  typedef enum {
627  A_FOC_FAST_OFFSET_EN_X = 0x01,
628  A_FOC_FAST_OFFSET_EN_Y = 0x02,
629  A_FOC_FAST_OFFSET_EN_Z = 0x04,
630 
631  A_FOC_FAST_OFFSET_EN = 0x08,
632 
633  A_FOC_FAST_OFFSET_WORDLENGTH0 = 0x10,
634  A_FOC_FAST_OFFSET_WORDLENGTH1 = 0x20,
635  _A_FOC_FAST_OFFSET_WORDLENGTH_MASK = 3,
636  _A_FOC_FAST_OFFSET_WORDLENGTH_SHIFT = 4,
637 
638  A_FOC_AUTO_OFFSET_WORDLENGTH0 = 0x40,
639  A_FOC_AUTO_OFFSET_WORDLENGTH1 = 0x80,
640  _A_FOC_AUTO_OFFSET_WORDLENGTH_MASK = 3,
641  _A_FOC_AUTO_OFFSET_WORDLENGTH_SHIFT = 6
642  } A_FOC_BITS_T;
643 
647  typedef enum {
648  FAST_OFFSET_WORDLENGTH_32 = 0, // samples
649  FAST_OFFSET_WORDLENGTH_64 = 1,
650  FAST_OFFSET_WORDLENGTH_128 = 2,
651  FAST_OFFSET_WORDLENGTH_256 = 3
653 
657  typedef enum {
658  AUTO_OFFSET_WORDLENGTH_32 = 0, // samples
659  AUTO_OFFSET_WORDLENGTH_64 = 1,
660  AUTO_OFFSET_WORDLENGTH_128 = 2,
661  AUTO_OFFSET_WORDLENGTH_256 = 3
663 
667  typedef enum {
668  TRIM_NVM_CTRL_NVM_PROG_MODE = 0x01,
669  TRIM_NVM_CTRL_NVM_PROG_TRIG = 0x02,
670  TRIM_NVM_CTRL_NVM_PROG_RDY = 0x04,
671  TRIM_NVM_CTRL_NVM_PROG_LOAD = 0x08,
672 
673  TRIM_NVM_CTRL_NVM_REMAIN0 = 0x10,
674  TRIM_NVM_CTRL_NVM_REMAIN1 = 0x20,
675  TRIM_NVM_CTRL_NVM_REMAIN2 = 0x40,
676  TRIM_NVM_CTRL_NVM_REMAIN3 = 0x80,
677  _TRIM_NVM_CTRL_NVM_REMAIN_MASK = 15,
678  _TRIM_NVM_CTRL_NVM_REMAIN_SHIFT = 4
680 
684  typedef enum {
685  _SPI3_WDT_RESERVED_BITS = 0xf0 | 0x08,
686 
687  SPI3_WDT_SPI3 = 0x01, // 3-wire SPI - NOT SUPPORTED
688 
689  SPI3_WDT_I2C_WDT_SEL = 0x02,
690  SPI3_WDT_I2C_WDT_EN = 0x04
691 
692  // 0x08-0x80 reserved
693  } SPI3_WDT_BITS_T;
694 
698  typedef enum {
699  OFC1_OFFSET_Z0 = 0x01, // Z lsb (3:1)
700  OFC1_OFFSET_Z1 = 0x02,
701  OFC1_OFFSET_Z2 = 0x04,
702  _OFC1_OFFSET_Z_MASK = 7,
703  _OFC1_OFFSET_Z_SHIFT = 0,
704 
705  OFC1_OFFSET_Y0 = 0x08, // Y lsb (3:1)
706  OFC1_OFFSET_Y1 = 0x10,
707  OFC1_OFFSET_Y2 = 0x20,
708  _OFC1_OFFSET_Y_MASK = 7,
709  _OFC1_OFFSET_Y_SHIFT = 3,
710 
711  OFC1_OFFSET_X0 = 0x08, // bits 3:2 of X lsb. geez
712  OFC1_OFFSET_X1 = 0x10,
713  _OFC1_OFFSET_X_MASK = 3,
714  _OFC1_OFFSET_X_SHIFT = 6
716 
720  typedef enum {
721  GP0_OFFSET_Z = 0x01, // Z llsb (bit 0)
722  GP0_OFFSET_Y = 0x02, // Y llsb (bit 0)
723 
724  GP0_OFFSET_X0 = 0x04, // X llsbs (bits 1:0)
725  GP0_OFFSET_X1 = 0x08,
726  _GP0_OFFSET_X_MASK = 3,
727  _GP0_OFFSET_X_SHIFT = 2,
728 
729  GP0_GP00 = 0x10,
730  GP0_GP01 = 0x20,
731  GP0_GP02 = 0x40,
732  GP0_GP03 = 0x80,
733  _GP0_GP0_MASK = 15,
734  _GP0_GP0_SHIFT = 4
735  } GP0_BITS_T;
736 
740  typedef enum {
741  _BIST_RESERVED_BITS = 0x80 | 0x40 | 0x20 | 0x08,
742 
743  BIST_TRIG_BIST = 0x01,
744  BIST_BIST_RDY = 0x02,
745  BIST_BIST_FAIL = 0x04,
746 
747  BIST_RATE_OK = 0x10
748  } BIST_BITS_T;
749 
753  typedef enum {
754  FIFO_CONFIG_0_WATER_MARK0 = 0x01,
755  FIFO_CONFIG_0_WATER_MARK1 = 0x02,
756  FIFO_CONFIG_0_WATER_MARK2 = 0x04,
757  FIFO_CONFIG_0_WATER_MARK3 = 0x08,
758  FIFO_CONFIG_0_WATER_MARK4 = 0x10,
759  FIFO_CONFIG_0_WATER_MARK5 = 0x20,
760  FIFO_CONFIG_0_WATER_MARK6 = 0x40,
761  _FIFO_CONFIG_0_WATER_MARK_MASK = 127,
762  _FIFO_CONFIG_0_WATER_MARK_SHIFT = 0,
763 
764  FIFO_CONFIG_0_TAG = 0x80
766 
770  typedef enum {
771  _FIFO_CONFIG_1_RESERVED_BITS = 0x20 | 0x10 |0x08 | 0x04,
772 
773  FIFO_CONFIG_1_FIFO_DATA_SEL0 = 0x01,
774  FIFO_CONFIG_1_FIFO_DATA_SEL1 = 0x02,
775  _FIFO_CONFIG_1_FIFO_DATA_SEL = 3,
776  _FIFO_CONFIG_1_FIFO_DATA_SHIFT = 0,
777 
778  FIFO_CONFIG_1_FIFO_MODE0 = 0x40,
779  FIFO_CONFIG_1_FIFO_MODE1 = 0x80,
780  _FIFO_CONFIG_1_FIFO_MODE_MASK = 3,
781  _FIFO_CONFIG_1_FIFO_MODE_SHIFT = 6
783 
787  typedef enum {
788  FIFO_DATA_SEL_XYZ = 0,
789  FIFO_DATA_SEL_X = 1,
790  FIFO_DATA_SEL_Y = 2,
791  FIFO_DATA_SEL_Z = 3
792  } FIFO_DATA_SEL_T;
793 
797  typedef enum {
798  FIFO_MODE_BYPASS = 0,
799  FIFO_MODE_FIFO = 1,
800  FIFO_MODE_STREAM = 2
801  } FIFO_MODE_T;
802 
803  // interrupt selection for installISR() and uninstallISR()
804  typedef enum {
805  INTERRUPT_INT1,
806  INTERRUPT_INT2
807  } INTERRUPT_PINS_T;
808 
809 
826  BMG160(int bus=BMG160_I2C_BUS, int addr=BMG160_DEFAULT_ADDR,
827  int cs=-1);
828 
832  ~BMG160();
833 
837  void update();
838 
844  uint8_t getChipID();
845 
857  void getGyroscope(float *x, float *y, float *z);
858 
868  float *getGyroscope();
869 
879  float getTemperature(bool fahrenheit=false);
880 
893  void init(POWER_MODE_T pwr=POWER_MODE_NORMAL,
894  RANGE_T range=RANGE_250, BW_T bw=BW_400_47);
895 
902  void reset();
903 
910  void setRange(RANGE_T range);
911 
917  void setBandwidth(BW_T bw);
918 
927  void setPowerMode(POWER_MODE_T power);
928 
944  void enableFIFO(bool useFIFO);
945 
952  void fifoSetWatermark(int wm);
953 
961  void fifoConfig(FIFO_MODE_T mode, FIFO_DATA_SEL_T axes);
962 
970  uint8_t getInterruptEnable0();
971 
978  void setInterruptEnable0(uint8_t bits);
979 
987  uint8_t getInterruptMap0();
988 
996  void setInterruptMap0(uint8_t bits);
997 
1004  uint8_t getInterruptMap1();
1005 
1012  void setInterruptMap1(uint8_t bits);
1013 
1022  uint8_t getInterruptSrc();
1023 
1032  void setInterruptSrc(uint8_t bits);
1033 
1042  uint8_t getInterruptOutputControl();
1043 
1052  void setInterruptOutputControl(uint8_t bits);
1053 
1057  void clearInterruptLatches();
1058 
1066 
1074 
1082  uint8_t getInterruptStatus0();
1083 
1090  uint8_t getInterruptStatus1();
1091 
1098  uint8_t getInterruptStatus2();
1099 
1106  uint8_t getInterruptStatus3();
1107 
1119  void enableRegisterShadowing(bool shadow);
1120 
1129  void enableOutputFiltering(bool filter);
1130 
1131 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
1132  void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
1133  jobject runnable);
1134 #else
1135 
1147  void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
1148  void (*isr)(void *), void *arg);
1149 #endif
1150 
1157  void uninstallISR(INTERRUPT_PINS_T intr);
1158 
1165  uint8_t readReg(uint8_t reg);
1166 
1174  int readRegs(uint8_t reg, uint8_t *buffer, int len);
1175 
1182  void writeReg(uint8_t reg, uint8_t val);
1183 
1184  protected:
1185  mraa::I2c *m_i2c;
1186  mraa::Spi *m_spi;
1187 
1188  // spi chip select
1189  mraa::Gpio *m_gpioCS;
1190 
1191  mraa::Gpio *m_gpioIntr1;
1192  mraa::Gpio *m_gpioIntr2;
1193 
1194  uint8_t m_addr;
1195 
1196  // SPI chip select
1197  void csOn();
1198  void csOff();
1199 
1200  // acc data
1201  float m_gyrX;
1202  float m_gyrY;
1203  float m_gyrZ;
1204 
1205  float m_gyrScale;
1206 
1207  float m_temperature;
1208 
1209  private:
1210  bool m_isSPI;
1211  // use the FIFO by default?
1212  bool m_useFIFO;
1213 
1214  // return a reference to a gpio pin pointer depending on intr
1215  mraa::Gpio*& getPin(INTERRUPT_PINS_T intr);
1216 
1217  // Adding a private function definition for java bindings
1218 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
1219  void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
1220  void (*isr)(void *), void *arg);
1221 #endif
1222  };
1223 }
void clearInterruptLatches()
Definition: bmg160.cxx:460
INT_MAP_1_BITS_T
Definition: bmg160.hpp:428
BIST_BITS_T
Definition: bmg160.hpp:740
BMG160_REGS_T
Definition: bmg160.hpp:82
INT_1C_BITS_T
Definition: bmg160.hpp:470
INT_EN_0_BITS_T
Definition: bmg160.hpp:394
HIGH_TH_BITS_T
Definition: bmg160.hpp:564
void setBandwidth(BW_T bw)
Definition: bmg160.cxx:369
uint8_t getInterruptStatus3()
Definition: bmg160.cxx:527
RATE_HBW_BITS_T
Definition: bmg160.hpp:384
void enableRegisterShadowing(bool shadow)
Definition: bmg160.cxx:488
float getTemperature(bool fahrenheit=false)
Definition: bmg160.cxx:324
RST_LATCH_T getInterruptLatchBehavior()
Definition: bmg160.cxx:469
LPM1_BITS_T
Definition: bmg160.hpp:292
POWER_MODE_T
Definition: bmg160.hpp:329
A_FOC_BITS_T
Definition: bmg160.hpp:626
float * getGyroscope()
Definition: bmg160.cxx:316
OFC1_OFFSET_BITS_T
Definition: bmg160.hpp:698
SLOW_OFFSET_TH_T
Definition: bmg160.hpp:616
uint8_t getInterruptStatus0()
Definition: bmg160.cxx:512
void setInterruptMap0(uint8_t bits)
Definition: bmg160.cxx:418
uint8_t readReg(uint8_t reg)
Definition: bmg160.cxx:203
uint8_t getInterruptOutputControl()
Definition: bmg160.cxx:448
GP0_BITS_T
Definition: bmg160.hpp:720
RST_LATCH_T
Definition: bmg160.hpp:539
uint8_t getChipID()
Definition: bmg160.cxx:299
BW_T
Definition: bmg160.hpp:278
API for the BMG160 16 bit Trixial Gyroscope.
Definition: bmg160.hpp:69
FIFO_CONFIG_1_BITS_T
Definition: bmg160.hpp:770
void writeReg(uint8_t reg, uint8_t val)
Definition: bmg160.cxx:259
ANY_DUR_SAMPLE_T
Definition: bmg160.hpp:491
uint8_t getInterruptEnable0()
Definition: bmg160.cxx:401
SPI3_WDT_BITS_T
Definition: bmg160.hpp:684
INT_STATUS_0_BITS_T
Definition: bmg160.hpp:171
LPM2_BITS_T
Definition: bmg160.hpp:338
void setInterruptLatchBehavior(RST_LATCH_T latch)
Definition: bmg160.cxx:478
void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: bmg160.cxx:546
void uninstallISR(INTERRUPT_PINS_T intr)
Definition: bmg160.cxx:560
SLOW_OFFSET_DUR_T
Definition: bmg160.hpp:604
~BMG160()
Definition: bmg160.cxx:109
FIFO_MODE_T
Definition: bmg160.hpp:797
uint8_t getInterruptStatus1()
Definition: bmg160.cxx:517
uint8_t getInterruptStatus2()
Definition: bmg160.cxx:522
INT_1E_BITS_T
Definition: bmg160.hpp:511
INT_STATUS_3_BITS_T
Definition: bmg160.hpp:205
void setInterruptEnable0(uint8_t bits)
Definition: bmg160.cxx:406
void setInterruptSrc(uint8_t bits)
Definition: bmg160.cxx:441
void enableFIFO(bool useFIFO)
Definition: bmg160.cxx:198
SOC_BITS_T
Definition: bmg160.hpp:584
INT_EN_1_BITS_T
Definition: bmg160.hpp:406
FIFO_STATUS_BITS_T
Definition: bmg160.hpp:217
INT_STATUS_1_BITS_T
Definition: bmg160.hpp:181
AWAKE_DUR_SAMPLE_T
Definition: bmg160.hpp:501
INT_MAP_0_BITS_T
Definition: bmg160.hpp:418
void enableOutputFiltering(bool filter)
Definition: bmg160.cxx:500
void reset()
Definition: bmg160.cxx:332
INT_STATUS_2_BITS_T
Definition: bmg160.hpp:193
INT_1B_BITS_T
Definition: bmg160.hpp:453
BMG160(int bus=BMG160_I2C_BUS, int addr=BMG160_DEFAULT_ADDR, int cs=-1)
Definition: bmg160.cxx:45
void setPowerMode(POWER_MODE_T power)
Definition: bmg160.cxx:374
FIFO_DATA_SEL_T
Definition: bmg160.hpp:787
uint8_t getInterruptMap0()
Definition: bmg160.cxx:413
AUTOSLEEP_DUR_T
Definition: bmg160.hpp:360
uint8_t getInterruptMap1()
Definition: bmg160.cxx:425
FAST_OFFSET_WORDLENGTH_T
Definition: bmg160.hpp:647
void setRange(RANGE_T range)
Definition: bmg160.cxx:338
GYR_RANGE_BITS_T
Definition: bmg160.hpp:234
uint8_t getInterruptSrc()
Definition: bmg160.cxx:436
void update()
Definition: bmg160.cxx:145
AUTO_OFFSET_WORDLENGTH_T
Definition: bmg160.hpp:657
GYR_BW_BITS_T
Definition: bmg160.hpp:264
TRIM_NVM_CTRL_BITS_T
Definition: bmg160.hpp:667
SLEEP_DUR_T
Definition: bmg160.hpp:315
void init(POWER_MODE_T pwr=POWER_MODE_NORMAL, RANGE_T range=RANGE_250, BW_T bw=BW_400_47)
Definition: bmg160.cxx:122
FIFO_CONFIG_0_BITS_T
Definition: bmg160.hpp:753
RANGE_T
Definition: bmg160.hpp:253
void setInterruptOutputControl(uint8_t bits)
Definition: bmg160.cxx:453
void setInterruptMap1(uint8_t bits)
Definition: bmg160.cxx:430
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bmg160.cxx:225
void fifoSetWatermark(int wm)
Definition: bmg160.cxx:385
EXT_TRIG_SEL_T
Definition: bmg160.hpp:374
INT_RST_LATCH_BITS_T
Definition: bmg160.hpp:520
void fifoConfig(FIFO_MODE_T mode, FIFO_DATA_SEL_T axes)
Definition: bmg160.cxx:393
INT_1A_BITS_T
Definition: bmg160.hpp:442