Modified FXAS21000 library. changed _i2c to a pointer allowing you to pass an existing I2C object to the library instead of initializing a new one each time. This is mainly to make this library more practical to use alongside other I2C sensors.

Fork of FXAS21000 by Jim Carver

Committer:
clwillingham
Date:
Mon Aug 17 18:25:11 2015 +0000
Revision:
4:c411fbb2cc2f
Parent:
3:a8f83b52f4df
changed i2c to pointer reference to make initialization more generic and compatible with other sensor libraries

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JimCarver 1:88a036a417bf 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
JimCarver 1:88a036a417bf 2 *
JimCarver 1:88a036a417bf 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
JimCarver 1:88a036a417bf 4 * and associated documentation files (the "Software"), to deal in the Software without
JimCarver 1:88a036a417bf 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
JimCarver 1:88a036a417bf 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
JimCarver 1:88a036a417bf 7 * Software is furnished to do so, subject to the following conditions:
JimCarver 1:88a036a417bf 8 *
JimCarver 1:88a036a417bf 9 * The above copyright notice and this permission notice shall be included in all copies or
JimCarver 1:88a036a417bf 10 * substantial portions of the Software.
JimCarver 1:88a036a417bf 11 *
JimCarver 1:88a036a417bf 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
JimCarver 1:88a036a417bf 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
JimCarver 1:88a036a417bf 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
JimCarver 1:88a036a417bf 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
JimCarver 1:88a036a417bf 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
JimCarver 1:88a036a417bf 17 */
JimCarver 1:88a036a417bf 18
JimCarver 0:4cfc774d6d85 19 #ifndef FXAS21000_H
JimCarver 0:4cfc774d6d85 20 #define FXAS21000_H
JimCarver 0:4cfc774d6d85 21
JimCarver 0:4cfc774d6d85 22 #include "mbed.h"
JimCarver 0:4cfc774d6d85 23
JimCarver 0:4cfc774d6d85 24
screamer 2:cd21ef326977 25 /**
screamer 2:cd21ef326977 26 * MMA8652 Slave Address
screamer 2:cd21ef326977 27 */
JimCarver 0:4cfc774d6d85 28 #define FXAS21000_SLAVE_ADDR 0x40
JimCarver 0:4cfc774d6d85 29
JimCarver 0:4cfc774d6d85 30 // MMA8652 internal register addresses
JimCarver 0:4cfc774d6d85 31 #define FXAS21000_STATUS 0x00
JimCarver 0:4cfc774d6d85 32 #define FXAS21000_WHOAMI 0x0C
JimCarver 0:4cfc774d6d85 33 #define FXAS21000_XYZ_DATA_CFG 0x0E
JimCarver 0:4cfc774d6d85 34 #define FXAS21000_CTRL_REG0 0x0D
JimCarver 0:4cfc774d6d85 35 #define FXAS21000_CTRL_REG1 0x13
JimCarver 0:4cfc774d6d85 36 #define FXAS21000_WHOAMI_VAL 0xD1
JimCarver 0:4cfc774d6d85 37
screamer 2:cd21ef326977 38 /**
screamer 2:cd21ef326977 39 * FXAS21000 gyroscope on I2C
screamer 2:cd21ef326977 40 */
JimCarver 0:4cfc774d6d85 41 class FXAS21000
JimCarver 0:4cfc774d6d85 42 {
JimCarver 0:4cfc774d6d85 43 public:
JimCarver 0:4cfc774d6d85 44 /**
screamer 2:cd21ef326977 45 * FXAS21000 constructor
screamer 2:cd21ef326977 46 *
screamer 2:cd21ef326977 47 * @param sda SDA pin
screamer 2:cd21ef326977 48 * @param sdl SCL pin
screamer 2:cd21ef326977 49 */
JimCarver 0:4cfc774d6d85 50 FXAS21000(PinName sda, PinName scl);
clwillingham 4:c411fbb2cc2f 51 FXAS21000(I2C *i2c);
JimCarver 0:4cfc774d6d85 52
JimCarver 0:4cfc774d6d85 53 /**
screamer 3:a8f83b52f4df 54 * Get the Gyro values as floating point degrees / second
screamer 2:cd21ef326977 55 *
screamer 2:cd21ef326977 56 * @param floating point array where the results will be placed
screamer 2:cd21ef326977 57 */
JimCarver 0:4cfc774d6d85 58 void ReadXYZ(float * a);
JimCarver 0:4cfc774d6d85 59
JimCarver 0:4cfc774d6d85 60 /**
screamer 3:a8f83b52f4df 61 * Get the Gyro values as signed 16 bit value
screamer 2:cd21ef326977 62 *
screamer 2:cd21ef326977 63 * @param int16_t point array where the results will be placed
screamer 2:cd21ef326977 64 */
JimCarver 0:4cfc774d6d85 65 void ReadXYZraw(int16_t * t);
JimCarver 0:4cfc774d6d85 66
JimCarver 0:4cfc774d6d85 67 /**
screamer 2:cd21ef326977 68 * Get the value of the WHO_AM_I register
screamer 2:cd21ef326977 69 *
screamer 2:cd21ef326977 70 * @returns DEVICE_ID value == 0xD1
screamer 2:cd21ef326977 71 */
JimCarver 0:4cfc774d6d85 72 char getWhoAmI(void);
JimCarver 0:4cfc774d6d85 73
JimCarver 0:4cfc774d6d85 74 private:
clwillingham 4:c411fbb2cc2f 75 I2C *_i2c;
screamer 2:cd21ef326977 76
screamer 2:cd21ef326977 77 /**
screamer 2:cd21ef326977 78 * Set the device in active mode
screamer 2:cd21ef326977 79 */
JimCarver 0:4cfc774d6d85 80 void begin( void);
JimCarver 0:4cfc774d6d85 81
JimCarver 0:4cfc774d6d85 82 void RegRead( char reg, char * d, int len);
JimCarver 0:4cfc774d6d85 83 };
JimCarver 0:4cfc774d6d85 84
JimCarver 0:4cfc774d6d85 85 #endif