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
bma250e.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 BMA250E_I2C_BUS 0
32 #define BMA250E_SPI_BUS 0
33 #define BMA250E_DEFAULT_ADDR 0x18
34 
35 
36 namespace upm {
37 
71  class BMA250E {
72  public:
73  // special reset byte
74  static const uint8_t BMA250E_RESET_BYTE = 0xb6;
75 
76  // NOTE: Reserved registers must not be written into. Reading
77  // from them may return indeterminate values. Registers
78  // containing reserved bitfields must be written as 0. Reading
79  // reserved bitfields may return indeterminate values.
80 
84  typedef enum : uint8_t {
85  REG_CHIP_ID = 0x00,
86 
87  // 0x01 reserved
88 
89  REG_ACCD_X_LSB = 0x02,
90  REG_ACCD_X_MSB = 0x03,
91  REG_ACCD_Y_LSB = 0x04,
92  REG_ACCD_Y_MSB = 0x05,
93  REG_ACCD_Z_LSB = 0x06,
94  REG_ACCD_Z_MSB = 0x07,
95 
96  REG_TEMP = 0x08,
97 
98  REG_INT_STATUS_0 = 0x09,
99  REG_INT_STATUS_1 = 0x0a,
100  REG_INT_STATUS_2 = 0x0b,
101  REG_INT_STATUS_3 = 0x0c,
102 
103  // 0x0d reserved
104 
105  REG_FIFO_STATUS = 0x0e,
106 
107  REG_PMU_RANGE = 0x0f,
108  REG_PMU_BW = 0x10,
109  REG_PMU_LPW = 0x11,
110  REG_PMU_LOW_POWER = 0x12,
111 
112  REG_ACC_HBW = 0x13,
113 
114  REG_SOFTRESET = 0x14,
115 
116  // 0x15 reserved
117 
118  REG_INT_EN_0 = 0x16,
119  REG_INT_EN_1 = 0x17,
120  REG_INT_EN_2 = 0x18,
121 
122  REG_INT_MAP_0 = 0x19,
123  REG_INT_MAP_1 = 0x1a,
124  REG_INT_MAP_2 = 0x1b,
125 
126  // 0x1c-0x1d reserved
127 
128  REG_INT_SRC = 0x1e,
129 
130  // 0x1f reserved
131 
132  REG_INT_OUT_CTRL = 0x20,
133  REG_INT_RST_LATCH = 0x21,
134 
135  REG_INT_0 = 0x22,
136  REG_INT_1 = 0x23,
137  REG_INT_2 = 0x24,
138  REG_INT_3 = 0x25,
139  REG_INT_4 = 0x26,
140  REG_INT_5 = 0x27,
141  REG_INT_6 = 0x28,
142  REG_INT_7 = 0x29,
143  REG_INT_8 = 0x2a,
144  REG_INT_9 = 0x2b,
145  REG_INT_A = 0x2c,
146  REG_INT_B = 0x2d,
147  REG_INT_C = 0x2e,
148  REG_INT_D = 0x2f,
149 
150  REG_FIFO_CONFIG_0 = 0x30,
151 
152  // 0x31 reserved
153 
154  REG_PMU_SELFTEST = 0x32,
155 
156  REG_TRIM_NVM_CTRL = 0x33,
157 
158  REG_SPI3_WDT = 0x34,
159 
160  // 0x35 reserved
161 
162  REG_OFC_CTRL = 0x36,
163  REG_OFC_SETTING = 0x37,
164 
165  REG_OFC_OFFSET_X = 0x38,
166  REG_OFC_OFFSET_Y = 0x39,
167  REG_OFC_OFFSET_Z = 0x3a,
168 
169  REG_TRIM_GP0 = 0x3b,
170  REG_TRIM_GP1 = 0x3c,
171 
172  // 0x3d reserved
173 
174  REG_FIFO_CONFIG_1 = 0x3e,
175  REG_FIFO_DATA = 0x3f
176 
177  } BMA250E_REGS_T;
178 
183  typedef enum {
184  ACCD10_LSB_NEW_DATA = 0x01, // data updated since last read
185 
186  // 0x02-0x20 reserved
187 
188  ACCD10_LSB0 = 0x40, // lower 2 bits of LSB data
189  ACCD10_LSB1 = 0x80,
190  _ACCD10_LSB_MASK = 3,
191  _ACCD10_LSB_SHIFT = 6
193 
198  typedef enum {
199  ACCD12_LSB_NEW_DATA = 0x01, // data updated since last read
200 
201  // 0x02-0x08 reserved
202 
203  ACCD12_LSB0 = 0x10, // lower 4 bits of LSB data
204  ACCD12_LSB1 = 0x20,
205  ACCD12_LSB2 = 0x40,
206  ACCD12_LSB3 = 0x80,
207  _ACCD12_LSB_MASK = 15,
208  _ACCD12_LSB_SHIFT = 4
210 
214  typedef enum {
215  INT_STATUS_0_LOW = 0x01,
216  INT_STATUS_0_HIGH = 0x02,
217  INT_STATUS_0_SLOPE = 0x04,
218  INT_STATUS_0_SLO_NOT_MOT = 0x08,
219  INT_STATUS_0_D_TAP = 0x10,
220  INT_STATUS_0_S_TAP = 0x20,
221  INT_STATUS_0_ORIENT = 0x40,
222  INT_STATUS_0_FLAT = 0x80
224 
228  typedef enum {
229  _INT_STATUS_1_RESERVED_BITS = 0x0f | 0x10,
230  // 0x01-0x10 reserved
231  INT_STATUS_1_FIFO_FULL = 0x20,
232  INT_STATUS_1_FIFO_WM = 0x40,
233  INT_STATUS_1_DATA = 0x80 // data ready int
235 
239  typedef enum {
240  INT_STATUS_2_SLOPE_FIRST_X = 0x01,
241  INT_STATUS_2_SLOPE_FIRST_Y = 0x02,
242  INT_STATUS_2_SLOPE_FIRST_Z = 0x04,
243  INT_STATUS_2_SLOPE_SIGN = 0x08,
244  INT_STATUS_2_TAP_FIRST_X = 0x10,
245  INT_STATUS_2_TAP_FIRST_Y = 0x20,
246  INT_STATUS_2_TAP_FIRST_Z = 0x40,
247  INT_STATUS_2_TAP_SIGN = 0x80
249 
253  typedef enum {
254  INT_STATUS_3_HIGH_FIRST_X = 0x01,
255  INT_STATUS_3_HIGH_FIRST_Y = 0x02,
256  INT_STATUS_3_HIGH_FIRST_Z = 0x04,
257  INT_STATUS_3_HIGH_SIGN = 0x08,
258 
259  INT_STATUS_3_ORIENT0 = 0x10,
260  INT_STATUS_3_ORIENT1 = 0x20,
261  INT_STATUS_3_ORIENT2 = 0x40,
262  _INT_STATUS_3_ORIENT_MASK = 7,
263  _INT_STATUS_3_ORIENT_SHIFT = 4,
264 
265  INT_STATUS_3_FLAT = 0x80
267 
271  typedef enum {
272  ORIENT_POTRAIT_UPRIGHT = 0,
273  ORIENT_POTRAIT_UPSIDE_DOWN = 1,
274  ORIENT_LANDSCAPE_LEFT = 2,
275  ORIENT_LANDSCAPE_RIGHT = 3,
276  } ORIENT_T;
277 
281  typedef enum {
282  FIFO_STATUS_FRAME_COUNTER0 = 0x01,
283  FIFO_STATUS_FRAME_COUNTER1 = 0x02,
284  FIFO_STATUS_FRAME_COUNTER2 = 0x04,
285  FIFO_STATUS_FRAME_COUNTER3 = 0x08,
286  FIFO_STATUS_FRAME_COUNTER4 = 0x10,
287  FIFO_STATUS_FRAME_COUNTER5 = 0x20,
288  FIFO_STATUS_FRAME_COUNTER6 = 0x40,
289  _FIFO_STATUS_FRAME_COUNTER_MASK = 127,
290  _FIFO_STATUS_FRAME_COUNTER_SHIFT = 0,
291 
292  FIFO_STATUS_FIFO_OVERRUN = 0x80
294 
298  typedef enum {
299  PMU_RANGE0 = 0x01,
300  PMU_RANGE1 = 0x02,
301  PMU_RANGE2 = 0x04,
302  PMU_RANGE3 = 0x08,
303  _PMU_RANGE_MASK = 15,
304  _PMU_RANGE_SHIFT = 0
305 
306  // 0x10-0x80 reserved
308 
312  typedef enum {
313  RANGE_2G = 3,
314  RANGE_4G = 5,
315  RANGE_8G = 8,
316  RANGE_16G = 12
317  } RANGE_T;
318 
322  typedef enum {
323  PMU_BW0 = 0x01,
324  PMU_BW1 = 0x02,
325  PMU_BW2 = 0x04,
326  PMU_BW3 = 0x08,
327  PMU_BW4 = 0x10,
328  _PMU_BW_MASK = 31,
329  _PMU_BW_SHIFT = 0
330 
331  // 0x20-0x80 reserved
332  } PMU_BW_BITS_T;
333 
337  typedef enum {
338  BW_7_81 = 8, // 7.81 Hz
339  BW_15_63 = 9,
340  BW_31_25 = 10,
341  BW_62_5 = 11,
342  BW_125 = 12,
343  BW_250 = 13,
344  BW_500 = 14,
345  BW_1000 = 15
346  } BW_T;
347 
351  typedef enum {
352  // 0x01 reserved
353  _PMU_LPW_RESERVED_MASK = 0x01,
354 
355  PMU_LPW_SLEEP_DUR0 = 0x02, // sleep dur in low power mode
356  PMU_LPW_SLEEP_DUR1 = 0x04,
357  PMU_LPW_SLEEP_DUR2 = 0x08,
358  PMU_LPW_SLEEP_DUR3 = 0x10,
359  _PMU_LPW_SLEEP_MASK = 15,
360  _PMU_LPW_SLEEP_SHIFT = 1,
361 
362  // These are separate bits, deep_suspend, lowpower_en and
363  // suspend (and if all 0, normal). Since only specific
364  // combinations are allowed, we will treat this as a 3 bit
365  // bitfield called POWER_MODE.
366  PMU_LPW_POWER_MODE0 = 0x20, // deep_suspend
367  PMU_LPW_POWER_MODE1 = 0x40, // lowpower_en
368  PMU_LPW_POWER_MODE2 = 0x80, // suspend
369  _PMU_LPW_POWER_MODE_MASK = 7,
370  _PMU_LPW_POWER_MODE_SHIFT = 5
371  } PMU_LPW_BITS_T;
372 
376  typedef enum {
377  SLEEP_DUR_0_5 = 0, // 0.5ms
378  SLEEP_DUR_1 = 6,
379  SLEEP_DUR_2 = 7,
380  SLEEP_DUR_4 = 8,
381  SLEEP_DUR_6 = 9,
382  SLEEP_DUR_10 = 10,
383  SLEEP_DUR_25 = 11,
384  SLEEP_DUR_50 = 12,
385  SLEEP_DUR_100 = 13,
386  SLEEP_DUR_500 = 14,
387  SLEEP_DUR_1000 = 15
388  } SLEEP_DUR_T;
389 
393  typedef enum {
394  POWER_MODE_NORMAL = 0,
395  POWER_MODE_DEEP_SUSPEND = 1,
396  POWER_MODE_LOW_POWER = 2,
397  POWER_MODE_SUSPEND = 4
398  } POWER_MODE_T;
399 
403  typedef enum {
404  _LOW_POWER_RESERVED_BITS = 0x0f | 0x10 | 0x80,
405 
406  // 0x01-0x10 reserved
407  LOW_POWER_SLEEPTIMER_MODE = 0x20,
408  LOW_POWER_LOWPOWER_MODE = 0x40 // LPM1 or LPM2 mode. see DS.
409  // 0x80 reserved
411 
415  typedef enum {
416  _ACC_HBW_RESERVED_BITS = 0x0f | 0x10 | 0x20,
417 
418  // 0x01-0x20 reserved
419  ACC_HBW_SHADOW_DIS = 0x40,
420  ACC_HBW_DATA_HIGH_BW = 0x80
421  } ACC_HBW_BITS_T;
422 
426  typedef enum {
427  _INT_EN_0_RESERVED_BITS = 0x08,
428 
429  INT_EN_0_SLOPE_EN_X = 0x01,
430  INT_EN_0_SLOPE_EN_Y = 0x02,
431  INT_EN_0_SLOPE_EN_Z = 0x04,
432 
433  // 0x08 reserved
434 
435  INT_EN_0_D_TAP_EN = 0x10,
436  INT_EN_0_S_TAP_EN = 0x20,
437  INT_EN_0_ORIENT_EN = 0x40,
438  INT_EN_0_FLAT_EN = 0x80
439  } INT_EN_0_BITS_T;
440 
444  typedef enum {
445  _INT_EN_1_RESERVED_BITS = 0x80,
446 
447  INT_EN_1_HIGH_EN_X = 0x01,
448  INT_EN_1_HIGH_EN_Y = 0x02,
449  INT_EN_1_HIGH_EN_Z = 0x04,
450  INT_EN_1_LOW_EN = 0x08,
451  INT_EN_1_DATA_EN = 0x10,
452  INT_EN_1_INT_FFULL_EN = 0x20, // fifo full
453  INT_EN_1_INT_FWM_EN = 0x40 // fifo watermark
454 
455  // 0x80 reserved
456  } INT_EN_1_BITS_T;
457 
461  typedef enum {
462  _INT_EN_2_RESERVED_BITS = 0xf0,
463 
464  INT_EN_2_SLO_NO_MOT_EN_X = 0x01,
465  INT_EN_2_SLO_NO_MOT_EN_Y = 0x02,
466  INT_EN_2_SLO_NO_MOT_EN_Z = 0x04,
467  INT_EN_2_SLO_NO_MOT_SEL = 0x08
468 
469  // 0x10-0x80 reserved
470  } INT_EN_2_BITS_T;
471 
475  typedef enum {
476  INT_MAP_0_INT1_LOW = 0x01,
477  INT_MAP_0_INT1_HIGH = 0x02,
478  INT_MAP_0_INT1_SLOPE = 0x04,
479  INT_MAP_0_INT1_SLO_NO_MOT = 0x08,
480  INT_MAP_0_INT1_D_TAP = 0x10,
481  INT_MAP_0_INT1_S_TAP = 0x20,
482  INT_MAP_0_INT1_ORIENT = 0x40,
483  INT_MAP_0_INT1_FLAT = 0x80
485 
489  typedef enum {
490  _INT_MAP_1_INT1_RESERVED_BITS = 0x08 | 0x10,
491 
492  INT_MAP_1_INT1_DATA = 0x01,
493  INT_MAP_1_INT1_FWM = 0x02,
494  INT_MAP_1_INT1_FFULL = 0x04,
495 
496  // 0x08-0x10 reserved
497 
498  INT_MAP_1_INT2_FFULL = 0x20,
499  INT_MAP_1_INT2_FWM = 0x40,
500  INT_MAP_1_INT2_DATA = 0x80
502 
506  typedef enum {
507  INT_MAP_2_INT2_LOW = 0x01,
508  INT_MAP_2_INT2_HIGH = 0x02,
509  INT_MAP_2_INT2_SLOPE = 0x04,
510  INT_MAP_2_INT2_SLO_NO_MOT = 0x08,
511  INT_MAP_2_INT2_D_TAP = 0x10,
512  INT_MAP_2_INT2_S_TAP = 0x20,
513  INT_MAP_2_INT2_ORIENT = 0x40,
514  INT_MAP_2_INT2_FLAT = 0x80
516 
520  typedef enum {
521  _INT_SRC_RESERVED_BITS = 0x40 | 0x80,
522 
523  INT_SRC_LOW = 0x01,
524  INT_SRC_HIGH = 0x02,
525  INT_SRC_SLO_NO_MOT = 0x04,
526  INT_SRC_SLOPE = 0x08,
527  INT_SRC_TAP = 0x10,
528  INT_SRC_DATA = 0x20
529 
530  // 0x40-0x80 reserved
531  } INT_SRC_BITS_T;
532 
536  typedef enum {
537  _INT_OUT_CTRL_INT1_RESERVED_BITS = 0xf0,
538 
539  INT_OUT_CTRL_INT1_LVL = 0x01, // level or edge
540  INT_OUT_CTRL_INT1_OD = 0x02, // push-pull or open drain
541  INT_OUT_CTRL_INT2_LVL = 0x04,
542  INT_OUT_CTRL_INT2_OD = 0x08
543 
544  // 0x10-0x80 reserved
546 
550  typedef enum {
551  _INT_RST_LATCH_RESERVED_BITS = 0x10 | 0x20 | 0x40,
552 
553  INT_RST_LATCH0 = 0x01,
554  INT_RST_LATCH1 = 0x02,
555  INT_RST_LATCH2 = 0x04,
556  INT_RST_LATCH3 = 0x08,
557  _INT_RST_LATCH_MASK = 15,
558  _INT_RST_LATCH_SHIFT = 0,
559 
560  // 0x10-0x40 reserved
561 
562  INT_RST_LATCH_RESET_INT = 0x80
564 
568  typedef enum {
569  RST_LATCH_NON_LATCHED = 0,
570  RST_LATCH_TEMPORARY_250MS = 1,
571  RST_LATCH_TEMPORARY_500MS = 2,
572  RST_LATCH_TEMPORARY_1S = 3,
573  RST_LATCH_TEMPORARY_2S = 4,
574  RST_LATCH_TEMPORARY_4S = 5,
575  RST_LATCH_TEMPORARY_8S = 6,
576  RST_LATCH_LATCHED = 7,
577 
578  // 8 == non latched
579 
580  RST_LATCH_TEMPORARY_250US = 9,
581  RST_LATCH_TEMPORARY_500US = 10,
582  RST_LATCH_TEMPORARY_1MS = 11,
583  RST_LATCH_TEMPORARY_12_5MS = 12,
584  RST_LATCH_TEMPORARY_25MS = 13,
585  RST_LATCH_TEMPORARY_50MS = 14
586 
587  // 15 == latched
588  } RST_LATCH_T;
589 
593  typedef enum {
594  INT_2_LOW_HY0 = 0x01,
595  INT_2_LOW_HY1 = 0x02,
596  _INT_2_LOW_HY_MASK = 3,
597  _INT_2_LOW_HY_SHIFT = 0,
598 
599  INT_2_LOW_MODE = 0x04,
600 
601  // 0x08-0x20 reserved
602 
603  INT_2_HIGH_HY0 = 0x40,
604  INT_2_HIGH_HY1 = 0x80,
605  _INT_2_HIGH_HY_MASK = 3,
606  _INT_2_HIGH_HY_SHIFT = 6
607  } INT_2_BITS_T;
608 
612  typedef enum {
613  INT_5_SLOPE_DUR0 = 0x01,
614  INT_5_SLOPE_DUR1 = 0x02,
615  _INT_5_SLOPE_DUR_MASK = 3,
616  _INT_5_SLOPE_DUR_SHIFT = 0,
617 
618  INT_5_SLO_NO_MOT_DUR0 = 0x04,
619  INT_5_SLO_NO_MOT_DUR1 = 0x08,
620  INT_5_SLO_NO_MOT_DUR2 = 0x10,
621  INT_5_SLO_NO_MOT_DUR3 = 0x20,
622  INT_5_SLO_NO_MOT_DUR4 = 0x40,
623  INT_5_SLO_NO_MOT_DUR5 = 0x80,
624  _INT_5_SLO_NO_MOT_DUR_MASK = 63,
625  _INT_5_SLO_NO_MOT_DUR_SHIFT = 2
626  } INT_5_BITS_T;
627 
631  typedef enum {
632  INT_8_TAP_DUR0 = 0x01,
633  INT_8_TAP_DUR1 = 0x02,
634  INT_8_TAP_DUR2 = 0x04,
635  _INT_8_TAP_DUR_MASK = 7,
636  _INT_8_TAP_DUR_SHIFT = 0,
637 
638  // 0x08-0x20 reserved
639 
640  INT_8_TAP_SHOCK = 0x40,
641  INT_8_TAP_QUIET = 0x80
642  } INT_8_BITS_T;
643 
647  typedef enum {
648  INT_9_TAP_TH0 = 0x01,
649  INT_9_TAP_TH1 = 0x02,
650  INT_9_TAP_TH2 = 0x04,
651  INT_9_TAP_TH3 = 0x08,
652  INT_9_TAP_TH4 = 0x10,
653  _INT_5_TAP_TH_MASK = 31,
654  _INT_5_TAP_TH_SHIFT = 0,
655 
656  // 0x20 reserved
657 
658  INT_9_TAP_SAMP0 = 0x40,
659  INT_9_TAP_SAMP1 = 0x80,
660  INT_9_TAP_SAMP1_MASK = 3,
661  INT_9_TAP_SAMP1_SHIFT = 6
662  } INT_9_BITS_T;
663 
667  typedef enum {
668  INT_A_ORIENT_MODE0 = 0x01,
669  INT_A_ORIENT_MODE1 = 0x02,
670  _INT_A_ORIENT_MODE_MASK = 3,
671  _INT_A_ORIENT_MODE_SHIFT = 0,
672 
673  INT_A_ORIENT_BLOCKING0 = 0x04,
674  INT_A_ORIENT_BLOCKING1 = 0x08,
675  _INT_A_ORIENT_BLOCKING_MASK = 3,
676  _INT_A_ORIENT_BLOCKING_SHIFT = 2,
677 
678  INT_A_ORIENT_HYST0 = 0x10,
679  INT_A_ORIENT_HYST1 = 0x20,
680  INT_A_ORIENT_HYST2 = 0x40,
681  _INT_A_ORIENT_HYST_MASK = 7,
682  _INT_A_ORIENT_HYST_SHIFT = 4
683 
684  // 0x80 reserved
685  } INT_A_BITS_T;
686 
690  typedef enum {
691  ORIENT_MODE_SYMETRICAL = 0,
692  ORIENT_MODE_HIGH_ASYMETRICAL = 1,
693  ORIENT_MODE_LOW_ASYMETRICAL = 2
694  } ORIENT_MODE_T;
695 
699  typedef enum {
700  ORIENT_BLOCKING_NONE = 0,
701  ORIENT_BLOCKING_THETA_ACC_1_5G = 1,
702  ORIENT_BLOCKING_THETA_ACC_0_2G_1_5G = 2,
703  ORIENT_BLOCKING_THETA_ACC_0_4G_1_5G = 3
705 
709  typedef enum {
710  INT_B_ORIENT_THETA0 = 0x01,
711  INT_B_ORIENT_THETA1 = 0x02,
712  INT_B_ORIENT_THETA2 = 0x04,
713  INT_B_ORIENT_THETA3 = 0x08,
714  INT_B_ORIENT_THETA4 = 0x10,
715  INT_B_ORIENT_THETA5 = 0x20,
716  _INT_B_ORIENT_THETA_MASK = 63,
717  _INT_B_ORIENT_THETA_SHIFT = 0,
718 
719  INT_B_ORIENT_UD_EN = 0x40
720  // 0x80 reserved
721  } INT_B_BITS_T;
722 
726  typedef enum {
727  INT_B_FLAT_THETA0 = 0x01,
728  INT_B_FLAT_THETA1 = 0x02,
729  INT_B_FLAT_THETA2 = 0x04,
730  INT_B_FLAT_THETA3 = 0x08,
731  INT_B_FLAT_THETA4 = 0x10,
732  INT_B_FLAT_THETA5 = 0x20,
733  _INT_B_FLAT_THETA_MASK = 63,
734  _INT_B_FLAT_THETA_SHIFT = 0,
735 
736  // 0x40-0x80 reserved
737  } INT_C_BITS_T;
738 
742  typedef enum {
743  INT_D_FLAT_HY0 = 0x01,
744  INT_D_FLAT_HY1 = 0x02,
745  INT_D_FLAT_HY2 = 0x04,
746  _INT_B_FLAT_HY_MASK = 7,
747  _INT_B_FLAT_HY_SHIFT = 0,
748 
749  // 0x08 reserved
750 
751  INT_D_FLAT_HOLD_TIME0 = 0x10,
752  INT_D_FLAT_HOLD_TIME1 = 0x20,
753  _INT_B_FLAT_HOLD_TIME_MASK = 3,
754  _INT_B_FLAT_HOLD_TIME_SHIFT = 4
755 
756  // 0x40-0x80 reserved
757  } INT_D_BITS_T;
758 
762  typedef enum {
763  _FIFO_CONFIG_0_RESERVED_BITS = 0x80 | 0x40,
764 
765  FIFO_CONFIG_0_WATER_MARK0 = 0x01,
766  FIFO_CONFIG_0_WATER_MARK1 = 0x02,
767  FIFO_CONFIG_0_WATER_MARK2 = 0x04,
768  FIFO_CONFIG_0_WATER_MARK3 = 0x08,
769  FIFO_CONFIG_0_WATER_MARK4 = 0x10,
770  FIFO_CONFIG_0_WATER_MARK5 = 0x20,
771  _FIFO_CONFIG_0_WATER_MARK_MASK = 63,
772  _FIFO_CONFIG_0_WATER_MARK_SHIFT = 0
774 
778  typedef enum {
779  PMU_SELFTTEST_AXIS0 = 0x01,
780  PMU_SELFTTEST_AXIS1 = 0x02,
781  _PMU_SELFTTEST_AXIS_MASK = 3,
782  _PMU_SELFTTEST_AXIS_SHIFT = 0,
783 
784  PMU_SELFTTEST_SIGN = 0x04,
785 
786  // 0x08 reserved
787 
788  PMU_SELFTTEST_AMP = 0x10,
789 
790  // 0x20-0x80 reserved
792 
796  typedef enum {
797  SELFTTEST_AXIS_NONE = 0,
798  SELFTTEST_AXIS_X = 1,
799  SELFTTEST_AXIS_Y = 2,
800  SELFTTEST_AXIS_Z = 3,
802 
806  typedef enum {
807  TRIM_NVM_CTRL_NVM_PROG_MODE = 0x01,
808  TRIM_NVM_CTRL_NVM_PROG_TRIG = 0x02,
809  TRIM_NVM_CTRL_NVM_PROG_RDY = 0x04,
810  TRIM_NVM_CTRL_NVM_PROG_LOAD = 0x08,
811 
812  TRIM_NVM_CTRL_NVM_REMAIN0 = 0x10,
813  TRIM_NVM_CTRL_NVM_REMAIN1 = 0x20,
814  TRIM_NVM_CTRL_NVM_REMAIN2 = 0x40,
815  TRIM_NVM_CTRL_NVM_REMAIN3 = 0x80,
816  _TRIM_NVM_CTRL_NVM_REMAIN_MASK = 15,
817  _TRIM_NVM_CTRL_NVM_REMAIN_SHIFT = 4
819 
823  typedef enum {
824  _SPI3_WDT_RESERVED_BITS = 0xf0 | 0x08,
825 
826  SPI3_WDT_SPI3 = 0x01, // 3-wire SPI - NOT SUPPORTED
827 
828  SPI3_WDT_I2C_WDT_SEL = 0x02,
829  SPI3_WDT_I2C_WDT_EN = 0x04
830 
831  // 0x08-0x80 reserved
832  } SPI3_WDT_BITS_T;
833 
837  typedef enum {
838  OFC_CTRL_HP_X_EN = 0x01,
839  OFC_CTRL_HP_Y_EN = 0x02,
840  OFC_CTRL_HP_Z_EN = 0x04,
841 
842  // 0x08 reserved
843 
844  OFC_CTRL_CAL_RDY = 0x10,
845 
846  OFC_CTRL_CAL_TRIGGER0 = 0x20,
847  OFC_CTRL_CAL_TRIGGER1 = 0x40,
848  _OFC_CTRL_CAL_TRIGGER_MASK = 3,
849  _OFC_CTRL_CAL_TRIGGER_SHIFT = 5,
850 
851  OFC_CTRL_OFFSET_RESET = 0x80
852 
853  } OFC_CTRL_BITS_T;
854 
858  typedef enum {
859  CAL_TRIGGER_NONE = 0,
860  CAL_TRIGGER_X = 1,
861  CAL_TRIGGER_Y = 2,
862  CAL_TRIGGER_Z = 3
863  } CAL_TRIGGER_T;
864 
868  typedef enum {
869  OFC_SETTING_CUT_OFF = 0x01,
870 
871  OFC_SETTING_OFFSET_TARGET_X0 = 0x02,
872  OFC_SETTING_OFFSET_TARGET_X1 = 0x04,
873  _OFC_SETTING_OFFSET_TARGET_X_MASK = 3,
874  _OFC_SETTING_OFFSET_TARGET_X_SHIFT = 1,
875 
876  OFC_SETTING_OFFSET_TARGET_Y0 = 0x08,
877  OFC_SETTING_OFFSET_TARGET_Y1 = 0x10,
878  _OFC_SETTING_OFFSET_TARGET_Y_MASK = 3,
879  _OFC_SETTING_OFFSET_TARGET_Y_SHIFT = 3,
880 
881  OFC_SETTING_OFFSET_TARGET_Z0 = 0x20,
882  OFC_SETTING_OFFSET_TARGET_Z1 = 0x40,
883  _OFC_SETTING_OFFSET_TARGET_Z_MASK = 3,
884  _OFC_SETTING_OFFSET_TARGET_Z_SHIFT = 5
885 
886  // 0x80 reserved
888 
892  typedef enum {
893  OFFSET_TARGET_0G = 0,
894  OFFSET_TARGET_PLUS_1G = 1,
895  OFFSET_TARGET_MINUS_1G = 2,
896  // 3 == 0G
897  } OFFSET_TARGET_T;
898 
902  typedef enum {
903  FIFO_CONFIG_1_FIFO_DATA_SEL0 = 0x01,
904  FIFO_CONFIG_1_FIFO_DATA_SEL1 = 0x02,
905  _FIFO_CONFIG_1_FIFO_DATA_SEL = 3,
906  _FIFO_CONFIG_1_FIFO_DATA_SHIFT = 0,
907 
908  // 0x04-0x20 reserved
909 
910  FIFO_CONFIG_1_FIFO_MODE0 = 0x40,
911  FIFO_CONFIG_1_FIFO_MODE1 = 0x80,
912  _FIFO_CONFIG_1_FIFO_MODE_MASK = 3,
913  _FIFO_CONFIG_1_FIFO_MODE_SHIFT = 5
915 
919  typedef enum {
920  FIFO_DATA_SEL_XYZ = 0,
921  FIFO_DATA_SEL_X = 1,
922  FIFO_DATA_SEL_Y = 2,
923  FIFO_DATA_SEL_Z = 3
924  } FIFO_DATA_SEL_T;
925 
929  typedef enum {
930  FIFO_MODE_BYPASS = 0,
931  FIFO_MODE_FIFO = 1,
932  FIFO_MODE_STREAM = 2
933 
934  // 3 == reserved (execute self-destruct :)
935  } FIFO_MODE_T;
936 
937  // interrupt selection for installISR() and uninstallISR()
938  typedef enum {
939  INTERRUPT_INT1,
940  INTERRUPT_INT2
941  } INTERRUPT_PINS_T;
942 
943  // Different variants of this chip support different resolutions.
944  // The 0xf9 variant supports 10b, while the 0xfa variant (bmx050)
945  // supports 12 bits.
946  typedef enum {
947  RESOLUTION_10BITS,
948  RESOLUTION_12BITS
949  } RESOLUTION_T;
950 
951 
967  BMA250E(int bus=BMA250E_I2C_BUS, int addr=BMA250E_DEFAULT_ADDR,
968  int cs=-1);
969 
973  ~BMA250E();
974 
978  void update();
979 
985  uint8_t getChipID();
986 
998  void getAccelerometer(float *x, float *y, float *z);
999 
1009  float *getAccelerometer();
1010 
1020  float getTemperature(bool fahrenheit=false);
1021 
1034  void init(POWER_MODE_T pwr=POWER_MODE_NORMAL,
1035  RANGE_T range=RANGE_2G, BW_T bw=BW_250);
1036 
1043  void reset();
1044 
1051  void setRange(RANGE_T range);
1052 
1058  void setBandwidth(BW_T bw);
1059 
1077  void setPowerMode(POWER_MODE_T power);
1078 
1096  void enableFIFO(bool useFIFO);
1097 
1105  void fifoSetWatermark(int wm);
1106 
1115  void fifoConfig(FIFO_MODE_T mode, FIFO_DATA_SEL_T axes);
1116 
1127  void setSelfTest(bool sign, bool amp, SELFTTEST_AXIS_T axis);
1128 
1136  uint8_t getInterruptEnable0();
1137 
1144  void setInterruptEnable0(uint8_t bits);
1145 
1152  uint8_t getInterruptEnable1();
1153 
1160  void setInterruptEnable1(uint8_t bits);
1161 
1168  uint8_t getInterruptEnable2();
1169 
1176  void setInterruptEnable2(uint8_t bits);
1177 
1185  uint8_t getInterruptMap0();
1186 
1194  void setInterruptMap0(uint8_t bits);
1195 
1202  uint8_t getInterruptMap1();
1203 
1210  void setInterruptMap1(uint8_t bits);
1211 
1218  uint8_t getInterruptMap2();
1219 
1226  void setInterruptMap2(uint8_t bits);
1227 
1236  uint8_t getInterruptSrc();
1237 
1246  void setInterruptSrc(uint8_t bits);
1247 
1256  uint8_t getInterruptOutputControl();
1257 
1266  void setInterruptOutputControl(uint8_t bits);
1267 
1271  void clearInterruptLatches();
1272 
1280 
1288 
1296  uint8_t getInterruptStatus0();
1297 
1304  uint8_t getInterruptStatus1();
1305 
1312  uint8_t getInterruptStatus2();
1313 
1322  uint8_t getInterruptStatus3Bits();
1323 
1331 
1343  void enableRegisterShadowing(bool shadow);
1344 
1353  void enableOutputFiltering(bool filter);
1354 
1361  void setLowPowerMode2();
1362 
1363 
1364 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
1365  void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
1366  jobject runnable);
1367 #else
1368 
1380  void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
1381  void (*isr)(void *), void *arg);
1382 #endif
1383 
1390  void uninstallISR(INTERRUPT_PINS_T intr);
1391 
1398  uint8_t readReg(uint8_t reg);
1399 
1407  int readRegs(uint8_t reg, uint8_t *buffer, int len);
1408 
1415  void writeReg(uint8_t reg, uint8_t val);
1416 
1417  protected:
1418  mraa::I2c *m_i2c;
1419  mraa::Spi *m_spi;
1420 
1421  // spi chip select
1422  mraa::Gpio *m_gpioCS;
1423 
1424  mraa::Gpio *m_gpioIntr1;
1425  mraa::Gpio *m_gpioIntr2;
1426 
1427  uint8_t m_addr;
1428  RESOLUTION_T m_resolution;
1429 
1430  // does this chip support the fifo?
1431  bool m_fifoAvailable;
1432 
1433  // SPI chip select
1434  void csOn();
1435  void csOff();
1436 
1437  // acc data
1438  float m_accX;
1439  float m_accY;
1440  float m_accZ;
1441 
1442  float m_accScale;
1443 
1444  float m_temperature;
1445 
1446  private:
1447  bool m_isSPI;
1448 
1449  // use the FIFO by default?
1450  bool m_useFIFO;
1451 
1452  // return a reference to a gpio pin pointer depending on intr
1453  mraa::Gpio*& getPin(INTERRUPT_PINS_T intr);
1454 
1455  // Adding a private function definition for java bindings
1456 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
1457  void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level,
1458  void (*isr)(void *), void *arg);
1459 #endif
1460  };
1461 }
INT_STATUS_2_BITS_T
Definition: bma250e.hpp:239
ORIENT_MODE_T
Definition: bma250e.hpp:690
INT_MAP_0_BITS_T
Definition: bma250e.hpp:475
void fifoSetWatermark(int wm)
Definition: bma250e.cxx:458
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bma250e.cxx:279
uint8_t getInterruptEnable0()
Definition: bma250e.cxx:495
INT_5_BITS_T
Definition: bma250e.hpp:612
RST_LATCH_T
Definition: bma250e.hpp:568
void setInterruptSrc(uint8_t bits)
Definition: bma250e.cxx:568
INT_9_BITS_T
Definition: bma250e.hpp:647
INT_EN_1_BITS_T
Definition: bma250e.hpp:444
CAL_TRIGGER_T
Definition: bma250e.hpp:858
void init(POWER_MODE_T pwr=POWER_MODE_NORMAL, RANGE_T range=RANGE_2G, BW_T bw=BW_250)
Definition: bma250e.cxx:144
void setInterruptMap1(uint8_t bits)
Definition: bma250e.cxx:546
ORIENT_T
Definition: bma250e.hpp:271
INT_STATUS_0_BITS_T
Definition: bma250e.hpp:214
uint8_t getInterruptEnable2()
Definition: bma250e.cxx:519
void setBandwidth(BW_T bw)
Definition: bma250e.cxx:442
void enableRegisterShadowing(bool shadow)
Definition: bma250e.cxx:615
void writeReg(uint8_t reg, uint8_t val)
Definition: bma250e.cxx:313
uint8_t readReg(uint8_t reg)
Definition: bma250e.cxx:257
void setInterruptEnable0(uint8_t bits)
Definition: bma250e.cxx:500
uint8_t getInterruptSrc()
Definition: bma250e.cxx:563
BW_T
Definition: bma250e.hpp:337
void setRange(RANGE_T range)
Definition: bma250e.cxx:390
PMU_BW_BITS_T
Definition: bma250e.hpp:322
INT_D_BITS_T
Definition: bma250e.hpp:742
void setInterruptOutputControl(uint8_t bits)
Definition: bma250e.cxx:580
float getTemperature(bool fahrenheit=false)
Definition: bma250e.cxx:376
void setLowPowerMode2()
Definition: bma250e.cxx:672
uint8_t getInterruptMap2()
Definition: bma250e.cxx:553
void setInterruptMap0(uint8_t bits)
Definition: bma250e.cxx:536
ACCD12_LSB_BITS_T
Definition: bma250e.hpp:198
uint8_t getInterruptStatus0()
Definition: bma250e.cxx:639
void reset()
Definition: bma250e.cxx:384
INT_OUT_CTRL_BITS_T
Definition: bma250e.hpp:536
SELFTTEST_AXIS_T
Definition: bma250e.hpp:796
RST_LATCH_T getInterruptLatchBehavior()
Definition: bma250e.cxx:596
POWER_MODE_T
Definition: bma250e.hpp:393
INT_2_BITS_T
Definition: bma250e.hpp:593
INT_C_BITS_T
Definition: bma250e.hpp:726
INT_8_BITS_T
Definition: bma250e.hpp:631
SLEEP_DUR_T
Definition: bma250e.hpp:376
INT_STATUS_1_BITS_T
Definition: bma250e.hpp:228
float * getAccelerometer()
Definition: bma250e.cxx:368
ACCD10_LSB_BITS_T
Definition: bma250e.hpp:183
PMU_RANGE_BITS_T
Definition: bma250e.hpp:298
void setInterruptEnable1(uint8_t bits)
Definition: bma250e.cxx:512
ACC_HBW_BITS_T
Definition: bma250e.hpp:415
uint8_t getInterruptStatus2()
Definition: bma250e.cxx:649
INT_STATUS_3_BITS_T
Definition: bma250e.hpp:253
INT_RST_LATCH_BITS_T
Definition: bma250e.hpp:550
~BMA250E()
Definition: bma250e.cxx:131
OFFSET_TARGET_T
Definition: bma250e.hpp:892
INT_MAP_1_BITS_T
Definition: bma250e.hpp:489
BMA250E_REGS_T
Definition: bma250e.hpp:84
FIFO_STATUS_BITS_T
Definition: bma250e.hpp:281
OFC_CTRL_BITS_T
Definition: bma250e.hpp:837
void clearInterruptLatches()
Definition: bma250e.cxx:587
void setInterruptEnable2(uint8_t bits)
Definition: bma250e.cxx:524
RANGE_T
Definition: bma250e.hpp:312
OFC_SETTING_BITS_T
Definition: bma250e.hpp:868
void setSelfTest(bool sign, bool amp, SELFTTEST_AXIS_T axis)
Definition: bma250e.cxx:482
uint8_t getInterruptStatus1()
Definition: bma250e.cxx:644
void fifoConfig(FIFO_MODE_T mode, FIFO_DATA_SEL_T axes)
Definition: bma250e.cxx:470
void update()
Definition: bma250e.cxx:173
void enableFIFO(bool useFIFO)
Definition: bma250e.cxx:251
PMU_SELFTTEST_BITS_T
Definition: bma250e.hpp:778
FIFO_MODE_T
Definition: bma250e.hpp:929
API for the BMA250E 10 bit Trixial Accelerometer.
Definition: bma250e.hpp:71
void setInterruptLatchBehavior(RST_LATCH_T latch)
Definition: bma250e.cxx:605
ORIENT_T getInterruptStatus3Orientation()
Definition: bma250e.cxx:661
LOW_POWER_BITS_T
Definition: bma250e.hpp:403
PMU_LPW_BITS_T
Definition: bma250e.hpp:351
void setInterruptMap2(uint8_t bits)
Definition: bma250e.cxx:558
void setPowerMode(POWER_MODE_T power)
Definition: bma250e.cxx:447
TRIM_NVM_CTRL_BITS_T
Definition: bma250e.hpp:806
ORIENT_BLOCKING_T
Definition: bma250e.hpp:699
INT_MAP_2_BITS_T
Definition: bma250e.hpp:506
SPI3_WDT_BITS_T
Definition: bma250e.hpp:823
uint8_t getInterruptMap0()
Definition: bma250e.cxx:531
INT_B_BITS_T
Definition: bma250e.hpp:709
void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: bma250e.cxx:700
uint8_t getInterruptStatus3Bits()
Definition: bma250e.cxx:654
uint8_t getChipID()
Definition: bma250e.cxx:351
INT_EN_2_BITS_T
Definition: bma250e.hpp:461
FIFO_DATA_SEL_T
Definition: bma250e.hpp:919
BMA250E(int bus=BMA250E_I2C_BUS, int addr=BMA250E_DEFAULT_ADDR, int cs=-1)
Definition: bma250e.cxx:43
void enableOutputFiltering(bool filter)
Definition: bma250e.cxx:627
INT_SRC_BITS_T
Definition: bma250e.hpp:520
void uninstallISR(INTERRUPT_PINS_T intr)
Definition: bma250e.cxx:714
FIFO_CONFIG_0_BITS_T
Definition: bma250e.hpp:762
uint8_t getInterruptMap1()
Definition: bma250e.cxx:541
FIFO_CONFIG_1_BITS_T
Definition: bma250e.hpp:902
INT_A_BITS_T
Definition: bma250e.hpp:667
uint8_t getInterruptEnable1()
Definition: bma250e.cxx:507
INT_EN_0_BITS_T
Definition: bma250e.hpp:426
uint8_t getInterruptOutputControl()
Definition: bma250e.cxx:575