No changes

Dependencies:   BLE_API mbed nRF51822

Fork of SDP_Version3_Abdul by Michael Galis

Committer:
galism
Date:
Sun Feb 26 03:24:30 2017 +0000
Revision:
5:fd83a2ac378e
No changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
galism 5:fd83a2ac378e 1 // Library for our MMA8452Q 3-axis accelerometer
galism 5:fd83a2ac378e 2 // Based on the MMA8452Q Arduino Library by Jim Lindblom (SparkFun Electronics)
galism 5:fd83a2ac378e 3
galism 5:fd83a2ac378e 4 #ifndef MMA8452Q_H
galism 5:fd83a2ac378e 5 #define MMA8452Q_H
galism 5:fd83a2ac378e 6
galism 5:fd83a2ac378e 7 #include "mbed.h"
galism 5:fd83a2ac378e 8
galism 5:fd83a2ac378e 9 // Register definitions
galism 5:fd83a2ac378e 10 #define REG_STATUS 0x00
galism 5:fd83a2ac378e 11 #define OUT_X_MSB 0x01
galism 5:fd83a2ac378e 12 #define OUT_X_LSB 0x02
galism 5:fd83a2ac378e 13 #define OUT_Y_MSB 0x03
galism 5:fd83a2ac378e 14 #define OUT_Y_LSB 0x04
galism 5:fd83a2ac378e 15 #define OUT_Z_MSB 0x05
galism 5:fd83a2ac378e 16 #define OUT_Z_LSB 0x06
galism 5:fd83a2ac378e 17 #define REG_WHO_AM_I 0x0D
galism 5:fd83a2ac378e 18 #define REG_XYZ_DATA_CFG 0x0E
galism 5:fd83a2ac378e 19 #define REG_CTRL_REG1 0x2A
galism 5:fd83a2ac378e 20 #define MMA8452_STATUS_ZYXDR_MASK 0x08
galism 5:fd83a2ac378e 21
galism 5:fd83a2ac378e 22 // WHO_AM_I check
galism 5:fd83a2ac378e 23 #define FACTORY_ID 0x2A
galism 5:fd83a2ac378e 24
galism 5:fd83a2ac378e 25 // Scale definitions
galism 5:fd83a2ac378e 26 #define SCALE_2G 2
galism 5:fd83a2ac378e 27 #define SCALE_4G 4
galism 5:fd83a2ac378e 28 #define SCALE_8G 8
galism 5:fd83a2ac378e 29
galism 5:fd83a2ac378e 30 // Data rates
galism 5:fd83a2ac378e 31 #define ODR_800HZ 0
galism 5:fd83a2ac378e 32 #define ODR_400HZ 1
galism 5:fd83a2ac378e 33 #define ODR_200HZ 2
galism 5:fd83a2ac378e 34 #define ODR_100HZ 3
galism 5:fd83a2ac378e 35 #define ODR_50HZ 4
galism 5:fd83a2ac378e 36 #define ODR_12_5HZ 5
galism 5:fd83a2ac378e 37 #define ODR_6_25HZ 6
galism 5:fd83a2ac378e 38 #define ODR_1_56HZ 7
galism 5:fd83a2ac378e 39
galism 5:fd83a2ac378e 40 // Init values
galism 5:fd83a2ac378e 41 #define DEFAULT_FSR SCALE_2G
galism 5:fd83a2ac378e 42 #define DEFAULT_ODR ODR_800HZ
galism 5:fd83a2ac378e 43
galism 5:fd83a2ac378e 44
galism 5:fd83a2ac378e 45 // Class declaration
galism 5:fd83a2ac378e 46 class MMA8452Q
galism 5:fd83a2ac378e 47 {
galism 5:fd83a2ac378e 48 public:
galism 5:fd83a2ac378e 49 MMA8452Q(PinName sda, PinName scl, int addr);
galism 5:fd83a2ac378e 50 ~MMA8452Q();
galism 5:fd83a2ac378e 51 bool init();
galism 5:fd83a2ac378e 52 //uint8_t available();
galism 5:fd83a2ac378e 53 bool available();
galism 5:fd83a2ac378e 54 void setScale(uint8_t fsr);
galism 5:fd83a2ac378e 55 void setODR(uint8_t odr);
galism 5:fd83a2ac378e 56 void standby();
galism 5:fd83a2ac378e 57 void active();
galism 5:fd83a2ac378e 58 float readX();
galism 5:fd83a2ac378e 59 float readY();
galism 5:fd83a2ac378e 60 float readZ();
galism 5:fd83a2ac378e 61 int isXYZReady();
galism 5:fd83a2ac378e 62 //char available();
galism 5:fd83a2ac378e 63 char getMaskedRegister(int addr, char mask);
galism 5:fd83a2ac378e 64 uint8_t readRegister(uint8_t reg);
galism 5:fd83a2ac378e 65 void writeRegister(uint8_t reg, uint8_t data);
galism 5:fd83a2ac378e 66
galism 5:fd83a2ac378e 67 private:
galism 5:fd83a2ac378e 68 I2C m_i2c;
galism 5:fd83a2ac378e 69 int m_addr;
galism 5:fd83a2ac378e 70 int scale;
galism 5:fd83a2ac378e 71 };
galism 5:fd83a2ac378e 72
galism 5:fd83a2ac378e 73 #endif