Library for MMA7660FC Accelerometer device

Dependents:   TestCode_MMA7660FC 3D_Accelerometer_Tester RTOS-aap-board-modules embed_Grove_3-Axis_Digital_Accelerometer ... more

Revision:
0:eb135a8de811
Child:
1:6e7a2df4f149
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA7660FC.h	Sat Jun 30 10:08:19 2012 +0000
@@ -0,0 +1,105 @@
+// Author: Edoardo De Marchi 
+/* Copyright (C) 2012 mbed.org, 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 MBED_MMA7660FC_H
+#define MBED_MMA7660FC_H
+ 
+#include "mbed.h"
+ 
+/** Accelerometer MMA7660FC class 
+ *
+ * Example:
+ * @code
+ * 
+ * #include "mbed.h"
+ * #include "MMA7660FC.h"
+ * 
+ * #define ADDR_MMA7660 0x98
+ * 
+ * MMA7660FC Acc(p28, p27, ADDR_MMA7660);
+ * serial pc(USBTX, USBRX);
+ *
+ * int main() 
+ * {
+ *   Acc.init(); 
+ *      while(1)
+ *      {
+ *          int x=0, y=0, z=0;
+ *          Acc.read_g(&x, &y, &z);
+ *          pc.printf("x: \n", x);
+ *          pc.printf("x: \n", y);
+ *          pc.printf("x: \n", z);
+ *          wait(1);       
+ *      }
+ * }
+ * @endcode
+ */ 
+class MMA7660FC         
+{        
+    public:
+        
+        
+       /** Create an MMA7660FC object connected to the specified I2C object
+        *
+        * @param sda I2C data port
+        * @param scl I2C clock port
+        * @param addr The address of the MMA7660FC
+        */ 
+      MMA7660FC(PinName sda, PinName scl, int addr);
+       
+       /** Destroys an MMA7660FC object
+        *
+        */
+      ~MMA7660FC();
+      
+       /** Initialization of device MMA7660FC
+        *
+        */
+      void init();
+    
+       /** Read the x,y,z axes acceleration
+        *
+        * @param *x Value of X acceleration
+        * @param *y Value of Y acceleration
+        * @param *z Value of Z acceleration
+        */
+      void read_g(int *x, int *y, int *z);
+            
+        /** Read from specified MMA7660FC register
+         *
+         * @param addr The internal registeraddress of the MMA7660FC
+         * @returns The value of the register
+         */
+      char read_reg(char addr);
+        
+        /** Write to specified MMA7660FC register
+        *
+        * @param addr The internal registeraddress of the MMA7660FC
+        * @param data New value of the register
+        */    
+      void write_reg(char addr, char data); 
+      
+   
+    private:
+      I2C m_i2c;
+      int m_addr;   
+};
+
+#endif 
\ No newline at end of file