Utilities for BORCH accelerometer BMA250E

Dependents:   MtConnect04S_Bike_Proximity Mt05_MtSense03

Revision:
0:8273e9b80c39
Child:
1:b6bb47e17a9a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BMA250E.h	Mon Dec 19 06:07:10 2016 +0000
@@ -0,0 +1,54 @@
+/* Copyright (c) 2016 MtM Technology Corporation, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
+ * and associated documentation files (the "Software"), to deal in the Software without restriction, 
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or 
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef BMA250E_h
+#define BMA250E_h
+
+#include "mbed.h"
+
+#define BMA250E_SLAVE_ADDR 0x30
+
+class BMA250E {    
+public:
+    BMA250E(PinName i2c_sda, PinName i2c_scl, PinName int1 = NC, PinName int2 = NC);
+    
+    void ReadXYZ(int16_t *xyz);
+    
+    void NewData                (void(*fptr)(void));
+    void AnyMotion              (void(*fptr)(void));
+    void TapSening              (void(*fptr)(void), bool double_tap);
+    void OrientationRecognition (void(*fptr)(void));
+    void FlatDetection          (void(*fptr)(void));
+    void LowHighGDetection      (void(*fptr)(void), bool high_g);
+    void ShakeDetection         (void(*fptr)(void));
+
+    void EnterStandbyMode(void);
+    void LeaveStandbyMode(void);
+    
+private:
+    I2C i2c_;
+    PinName interrupt1_pinname_;
+    InterruptIn interrupt1_;
+    PinName interrupt2_pinname_;
+    InterruptIn interrupt2_;
+    
+    void RegWrite(char reg, char  val);
+    void RegRead (char reg, char *val, int len);
+    void RegReadModifyWrite(char reg, char clr_mask, char set_mask);
+};
+
+#endif