Library for MMA7660FC Accelerometer device

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MMA7660FC.h Source File

MMA7660FC.h

00001 // Author: Edoardo De Marchi 
00002 /* Copyright (C) 2012 mbed.org, MIT License
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00005  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00006  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00007  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The above copyright notice and this permission notice shall be included in all copies or
00011  * substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00014  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00015  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00016  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018  */
00019  
00020  
00021 #ifndef MBED_MMA7660FC_H
00022 #define MBED_MMA7660FC_H
00023  
00024 #include "mbed.h"
00025 
00026 
00027 #define OUT_X 0x00              // [6:0] are Read Only 6-bit output value X (XOUT[5] is 0 if the g direction is positive, 1 is negative)
00028 #define OUT_Y 0x01              // [6:0] are Read Only 6-bit output value Y (YOUT[5] is 0 if the g direction is positive, 1 is negative)
00029 #define OUT_Z 0x02              // [6:0] are Read Only 6-bit output value Z (ZOUT[5] is 0 if the g direction is positive, 1 is negative)
00030 #define TILT_STATUS 0x03        // Tilt Status (Read only)
00031 #define SRST_STATUS 0x04        // Sample Rate Status Register (Read only)
00032 #define SPCNT_STATUS 0x05       // Sleep Count Register (Read/Write)
00033 #define INTSU_STATUS 0x06       // Interrupt Setup Register
00034 #define MODE_STATUS 0x07        // Mode Register (Read/Write)
00035 #define SR_STATUS 0x08          // Auto-Wake and Active Mode Portrait/Landscape Samples per Seconds Register (Read/Write)
00036 #define PDET_STATUS 0x09        // Tap/Pulse Detection Register (Read/Write)
00037 #define PD_STATUS 0xA           // Tap/Pulse Debounce Count Register (Read/Write)
00038 
00039 
00040 
00041 
00042  
00043 /** Accelerometer MMA7660FC class 
00044  *
00045  * Example:
00046  * @code
00047  * 
00048  * #include "mbed.h"
00049  * #include "MMA7660FC.h"
00050  * 
00051  * #define ADDR_MMA7660 0x98
00052  * 
00053  * MMA7660FC Acc(p28, p27, ADDR_MMA7660);
00054  * serial pc(USBTX, USBRX);
00055  *
00056  * int main() 
00057  * {
00058  *   Acc.init(); 
00059  *      while(1)
00060  *      {
00061  *          int x=0, y=0, z=0;
00062  *          Acc.read_Tilt(&x, &y, &z);
00063  *          pc.printf("Tilt x: %2.2f degree \n", x);                    // Print the tilt orientation of the X axis
00064  *          pc.printf("Tilt y: %2.2f degree \n", y);                    // Print the tilt orientation of the Y axis
00065  *          pc.printf("Tilt z: %2.2f degree \n", z);                    // Print the tilt orientation of the Z axis
00066  *          wait(1);       
00067  *      }
00068  * }
00069  * @endcode
00070  */ 
00071 class MMA7660FC         
00072 {        
00073     public:
00074         
00075         
00076        /** Creates an MMA7660FC object connected to the specified I2C object
00077         *
00078         * @param sda I2C data port
00079         * @param scl I2C clock port
00080         * @param addr The address of the MMA7660FC
00081         */ 
00082       MMA7660FC(PinName sda, PinName scl, int addr);
00083        
00084        /** Destroys an MMA7660FC object
00085         *
00086         */
00087       ~MMA7660FC();
00088       
00089        /** Initialization of device MMA7660FC (required)
00090         *
00091         */
00092       void init();
00093     
00094        /** Read the Tilt Angle using Three Axis
00095         *
00096         * @param *x Value of x tilt
00097         * @param *y Value of y tilt
00098         * @param *z Value of z tilt
00099         */
00100       void read_Tilt(float *x, float *y, float *z);
00101       
00102       /** Reads the x register of the MMA7660FC
00103         *
00104         * @returns The value of x acceleration
00105         */
00106       int read_x();
00107       
00108       /** Reads the y register of the MMA7660FC
00109         *
00110         * @returns The value of y acceleration
00111         */
00112       int read_y();
00113       
00114       /** Reads the z register of the MMA7660FC
00115         *
00116         * @returns The value of z acceleration
00117         */
00118        int read_z();
00119        
00120       /** Reads the Front or Back position of the device
00121         *
00122         * @returns The Front or Back position
00123         */       
00124        char const* read_Side();
00125        
00126       /** Reads the Orientation of the device
00127         *
00128         * @returns The Left or Right or Down or Up Orientation
00129         */       
00130        char const* read_Orientation();
00131             
00132         /** Reads from specified MMA7660FC register
00133          *
00134          * @param addr The internal registeraddress of the MMA7660FC
00135          * @returns The value of the register
00136          */
00137       char read_reg(char addr);
00138         
00139         /** Writes to specified MMA7660FC register
00140         *
00141         * @param addr The internal registeraddress of the MMA7660FC
00142         * @param data New value of the register
00143         */    
00144       void write_reg(char addr, char data); 
00145       
00146         /** Checks if the address exist on an I2C bus 
00147         *
00148         * @returns 0 on success, or non-0 on failure
00149         */    
00150       int check();
00151       
00152    
00153     private:
00154       I2C m_i2c;
00155       //int m_addr;   
00156       char SPI_R_Address;
00157       char SPI_W_Address; 
00158 };
00159 
00160 #endif