Yehowshua Immanuel / MMA8452

Dependents:   Generic_Platformer

Files at this revision

API Documentation at this revision

Comitter:
ashleymills
Date:
Tue Mar 04 11:14:34 2014 +0000
Parent:
9:dfb0f6a7a455
Child:
11:dfd1e0afcb7b
Commit message:
Some minor changes

Changed in this revision

MMA8452.cpp Show annotated file Show diff for this revision Revisions of this file
MMA8452.h Show annotated file Show diff for this revision Revisions of this file
--- a/MMA8452.cpp	Thu Oct 17 10:21:37 2013 +0000
+++ b/MMA8452.cpp	Tue Mar 04 11:14:34 2014 +0000
@@ -20,8 +20,7 @@
 # include "MMA8452.h"
 
 // Connect module at I2C address using I2C port pins sda and scl
-Accelerometer_MMA8452::Accelerometer_MMA8452(PinName sda, PinName scl,int frequency) : m_i2c(sda, scl) , m_frequency(frequency)
-{
+MMA8452::MMA8452(PinName sda, PinName scl,int frequency) : m_i2c(sda, scl) , m_frequency(frequency) {
     //m_i2c.frequency(m_frequency);
     
     // setup read and write addresses to avoid duplication
@@ -31,14 +30,10 @@
 
 
 // Destroys instance
-Accelerometer_MMA8452::~Accelerometer_MMA8452() 
-{
-
-}
+MMA8452::~MMA8452() {}
 
 // Setting the control register bit 1 to true to activate the MMA8452
-int Accelerometer_MMA8452::activate()
-{
+int MMA8452::activate() {
     // set control register 1 to active
     char init[2] = {CTRL_REG_1,ACTIVE};
     
@@ -50,13 +45,13 @@
 // Get 'Fast Read Mode' called F_READ. If bit 1 is set '1' then F_READ is active. Fast read will skip LSB when reading xyz
 // resisters from 0x01 to 0x06. When F_READ is '0' then all 6 registers will be read.
 
-int Accelerometer_MMA8452::get_CTRL_Reg1(int* dst)
+int MMA8452::get_CTRL_Reg1(int* dst)
 {   
-   return read_reg(CTRL_REG_1,dst); 
+   return readRegister(CTRL_REG_1,dst); 
 }
 
 // Setting the control register bit 1 to true to activate the MMA8452
-int Accelerometer_MMA8452::standby()
+int MMA8452::standby()
 {
     // set control register 1 to standby
     char init[2] = {CTRL_REG_1,STANDBY};
@@ -68,40 +63,40 @@
 
 
 // Device initialization
-void Accelerometer_MMA8452::init()
+void MMA8452::init()
 {
     
-    write_reg(INTSU_STATUS, 0x10);      // automatic interrupt after every measurement
-    write_reg(SR_STATUS, 0x00);         // 120 Samples/Second
-    write_reg(MODE_STATUS, 0x01);       // Active Mode
+    writeRegister(INTSU_STATUS, 0x10);      // automatic interrupt after every measurement
+    writeRegister(SR_STATUS, 0x00);         // 120 Samples/Second
+    writeRegister(MODE_STATUS, 0x01);       // Active Mode
     
 }
 
 // Get real time status of device - it can be STANDBY, WAKE or SLEEP
-int Accelerometer_MMA8452::get_SystemMode(int *dst)
+int MMA8452::getSystemMode(int *dst)
 {
-    return read_reg(SYSMOD,dst);
+    return readRegister(SYSMOD,dst);
 }
 
 
 
 // Get real time status of device - it can be STANDBY, WAKE or SLEEP
-int Accelerometer_MMA8452::get_Status(int* dst)
+int MMA8452::getStatus(int* dst)
 {
-    return read_reg(STATUS,dst);
+    return readRegister(STATUS,dst);
 }
 
 
 // Get device ID 
-int Accelerometer_MMA8452::get_DeviceID(int *dst)
+int MMA8452::getDeviceID(int *dst)
 {
-    return read_reg(WHO_AM_I,dst);
+    return readRegister(WHO_AM_I,dst);
 }
 
 
 /*
 // Reads x data
-int Accelerometer_MMA8452::read_x(int& xaxisLSB)
+int MMA8452::read_x(int& xaxisLSB)
 {
     char mcu_address = (MMA8452_ADDRESS<<1);
     m_i2c.start();
@@ -124,7 +119,7 @@
 }
 */
 
-int Accelerometer_MMA8452::read_raw(char src, char *dst, int len) {
+int MMA8452::readRaw(char src, char *dst, int len) {
     // this is the register we want to get data from               
     char register_address[1];
     register_address[0] = src;
@@ -148,10 +143,10 @@
 // It takes a 2 byte char array and copies the register values into the buffer. If it fails the char array
 // is set to '0'. It returns '0' success '1' fail. This method does nothing to the registers - just returns
 // the raw data.
-//int Accelerometer_MMA8452::read_x(int& xaxisLSB)
-int Accelerometer_MMA8452::read_x_raw(char *xaxis)
+//int MMA8452::read_x(int& xaxisLSB)
+int MMA8452::readRawX(char *xaxis)
 {   
-    return read_raw(OUT_X_MSB,xaxis,2);  
+    return readRaw(OUT_X_MSB,xaxis,2);  
 }
 
 
@@ -160,8 +155,8 @@
 // is set to '0'. It returns '0' success '1' fail. This method does nothing to the registers - just returns
 // the raw data.
 
-int Accelerometer_MMA8452::read_y_raw(char *yaxis) {
-   return read_raw(OUT_Y_MSB,yaxis,2);
+int MMA8452::readRawY(char *yaxis) {
+   return readRaw(OUT_Y_MSB,yaxis,2);
 }
 
 
@@ -171,15 +166,15 @@
 // is set to '0'. It returns '0' success '1' fail. This method does nothing to the registers - just returns
 // the raw data.
 
-int Accelerometer_MMA8452::read_z_raw(char *zaxis)
+int MMA8452::readRawZ(char *zaxis)
 {
-   return read_raw(OUT_Z_MSB,zaxis,2);
+   return readRaw(OUT_Z_MSB,zaxis,2);
 }
 
 
 
 // Reads y data
-int Accelerometer_MMA8452::read_y()
+int MMA8452::read_y()
 {
     char mcu_address = (MMA8452_ADDRESS <<1);
 
@@ -197,7 +192,7 @@
 
 
 // Reads z data
-int Accelerometer_MMA8452::read_z()
+int MMA8452::read_z()
 {
     char mcu_address = (MMA8452_ADDRESS <<1);
     
@@ -215,7 +210,7 @@
 
 
 // Reads xyz
-int Accelerometer_MMA8452::read_xyz(char *x, char *y, char *z) 
+int MMA8452::readRawXYZ(char *x, char *y, char *z) 
 {
     
     
@@ -247,7 +242,7 @@
 }
 
         // Write register (The device must be placed in Standby Mode to change the value of the registers) 
-void Accelerometer_MMA8452::write_reg(char addr, char data)
+void MMA8452::writeRegister(char addr, char data)
 {
 
     char cmd[2] = {0, 0};
@@ -266,10 +261,8 @@
                   
 }
 
-
-
         // Read from specified MMA7660FC register
-int Accelerometer_MMA8452::read_reg(char addr, int *dst)
+int MMA8452::readRegister(char addr, int *dst)
 {
     
     m_i2c.start();
@@ -292,9 +285,3 @@
     return 0;
     
 }
-
-
-
-
-
-
--- a/MMA8452.h	Thu Oct 17 10:21:37 2013 +0000
+++ b/MMA8452.h	Tue Mar 04 11:14:34 2014 +0000
@@ -1,4 +1,4 @@
-// Author: Nicholas Herriot
+// Author: Nicholas Herriot, Ashley Mills
 /* Copyright (c) 2013 Vodafone, MIT License
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
@@ -116,10 +116,21 @@
 #define PDET_STATUS 0x09        // Tap/Pulse Detection Register (Read/Write)
 #define PD_STATUS 0xA           // Tap/Pulse Debounce Count Register (Read/Write)
  
-class Accelerometer_MMA8452         
+class MMA8452         
 {        
     public:
+    
+       enum OperationalMode {
+           MODE_STANDBY,
+           MODE_ACTIVE_2G,
+           MODE_ACTIVE_4G,
+           MODE_ACTIVE_8G
+       };
         
+       enum BitDepth {
+           BIT_DEPTH_8,
+           BIT_DEPTH_12
+       };
         
        /** Create an accelerometer object connected to the specified I2C object
         *
@@ -127,13 +138,13 @@
         * @param scl I2C8452 clock port
         * 
         */ 
-      Accelerometer_MMA8452(PinName sda, PinName scl, int frequency);
+      MMA8452(PinName sda, PinName scl, int frequency);
       //Accelerometer_MMA8452(PinName sda, PinName scl);
        
        /** Destroys an MMA8452 object
         *
         */
-      ~Accelerometer_MMA8452();
+      ~MMA8452();
             
       /** Get system mode of the MMA8452 (not required)
         *   returns 0 for success in reading the system mode of the chip
@@ -142,8 +153,7 @@
         *
         *   This method is used to find out the system mode of the chip ACTIVE = 0x00 or STANDBY = 0x01
       */
-      int get_SystemMode(int *dst);
-      
+      int getSystemMode(int *dst);    
       
       /** Get status of the MMA8452 (not required)
         *   returns 0 for success in reading the status of the chip
@@ -154,7 +164,7 @@
         *   x,y and z values have been overwritten before they have been read since a change happened.
         *   
       */
-      int get_Status(int *dst);
+      int getStatus(int *dst);
       
       
       /** Activate the MMA8452 (required)
@@ -198,7 +208,7 @@
         * return 0 for success or
         * return 1 for failure.
         */        
-      int get_DeviceID(int *dst);  
+      int getDeviceID(int *dst);  
       
       int read_y();
       
@@ -208,19 +218,19 @@
         *
         * @returns The value of x acceleration
         */
-      int read_x_raw(char *xaxis);
+      int readRawX(char *xaxis);
       //int read_x(int& xaxisLSB);
       /** Read the y register of the MMA8452
         *
         * @returns The value of y acceleration
         */
-      int read_y_raw(char *yaxis);
+      int readRawY(char *yaxis);
       
       /** Read the z register of the MMA8452
         *
         * @returns The value of z acceleration
         */
-       int read_z_raw(char * zaxis);
+       int readRawZ(char * zaxis);
       
       /** Read the x,y and z registers of the MMA8452
        *
@@ -229,25 +239,27 @@
        * returns 0 for success, and 1 for failure
        *
        */ 
-      int read_xyz(char *x, char *y, char *z); 
+      int readRawXYZ(char *x, char *y, char *z); 
             
         /** Read from specified MMA8452 register
          *
          * @param addr The internal registeraddress of the MMA8452
          * @returns The value of the register
          */
-      int read_reg(char addr, int *dst);
+      int readRegister(char addr, int *dst);
         
         /** Write to specified MMA8452 register
         *
         * @param addr The internal registeraddress of the MMA8452
         * @param data New value of the register
         */    
-      void write_reg(char addr, char data); 
+      void writeRegister(char addr, char data);
       
+      int setOperationalMode(OperationalMode m);
+      int setBitDepth(BitDepth b);
    
     private:
-      int read_raw(char src, char *dst, int len);
+      int readRaw(char src, char *dst, int len);
     
     
       I2C m_i2c;