Reimplemented FXAS21000 library for Freescale Gyro
Fork of FXAS21000 by
FXAS21000.h@4:41bd7f360406, 2015-07-08 (annotated)
- Committer:
- Mashu
- Date:
- Wed Jul 08 13:34:46 2015 +0000
- Revision:
- 4:41bd7f360406
- Parent:
- 3:a8f83b52f4df
Reimplemented FXAS21000 library based on FXOS8700Q and updated MotionSensor data types.
Who changed what in which revision?
User | Revision | Line number | New 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" |
Mashu | 4:41bd7f360406 | 23 | #include "MotionSensor.h" |
JimCarver | 0:4cfc774d6d85 | 24 | |
screamer | 2:cd21ef326977 | 25 | /** |
Mashu | 4:41bd7f360406 | 26 | * FXAS21000 Slave Address |
screamer | 2:cd21ef326977 | 27 | */ |
JimCarver | 0:4cfc774d6d85 | 28 | #define FXAS21000_SLAVE_ADDR 0x40 |
JimCarver | 0:4cfc774d6d85 | 29 | |
Mashu | 4:41bd7f360406 | 30 | // FXAS21000 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 |
Mashu | 4:41bd7f360406 | 37 | #define FXAS21000_OUT_X_MSB 0x01 |
Mashu | 4:41bd7f360406 | 38 | #define FXAS21000_OUT_Y_MSB 0x03 |
Mashu | 4:41bd7f360406 | 39 | #define FXAS21000_OUT_Z_MSB 0x05 |
JimCarver | 0:4cfc774d6d85 | 40 | |
screamer | 2:cd21ef326977 | 41 | /** |
Mashu | 4:41bd7f360406 | 42 | * FXAS21000 driver class |
screamer | 2:cd21ef326977 | 43 | */ |
Mashu | 4:41bd7f360406 | 44 | class FXAS21000 : public MotionSensor |
JimCarver | 0:4cfc774d6d85 | 45 | { |
JimCarver | 0:4cfc774d6d85 | 46 | public: |
Mashu | 4:41bd7f360406 | 47 | |
Mashu | 4:41bd7f360406 | 48 | /** Read a device register |
Mashu | 4:41bd7f360406 | 49 | @param addr The address to read from |
Mashu | 4:41bd7f360406 | 50 | @param data The data to read from it |
Mashu | 4:41bd7f360406 | 51 | @param len The amount of data to read from it |
Mashu | 4:41bd7f360406 | 52 | @return 0 if successful, negative number otherwise |
screamer | 2:cd21ef326977 | 53 | */ |
Mashu | 4:41bd7f360406 | 54 | void readRegs(uint8_t addr, uint8_t *data, uint32_t len) const; |
Mashu | 4:41bd7f360406 | 55 | |
Mashu | 4:41bd7f360406 | 56 | /** Read the ID from a whoAmI register |
Mashu | 4:41bd7f360406 | 57 | @return The device whoAmI register contents |
screamer | 2:cd21ef326977 | 58 | */ |
Mashu | 4:41bd7f360406 | 59 | uint8_t whoAmI(void) const; |
Mashu | 4:41bd7f360406 | 60 | |
Mashu | 4:41bd7f360406 | 61 | virtual void enable(void) const; |
Mashu | 4:41bd7f360406 | 62 | virtual void disable(void) const; |
Mashu | 4:41bd7f360406 | 63 | virtual uint32_t sampleRate(uint32_t frequency) const; |
Mashu | 4:41bd7f360406 | 64 | virtual uint32_t dataReady(void) const; |
JimCarver | 0:4cfc774d6d85 | 65 | |
Mashu | 4:41bd7f360406 | 66 | protected: |
Mashu | 4:41bd7f360406 | 67 | I2C *_i2c; |
Mashu | 4:41bd7f360406 | 68 | uint8_t _addr; |
Mashu | 4:41bd7f360406 | 69 | |
Mashu | 4:41bd7f360406 | 70 | /** FXAS21000 constructor |
Mashu | 4:41bd7f360406 | 71 | @param i2c a configured i2c object |
Mashu | 4:41bd7f360406 | 72 | @param addr addr of the I2C peripheral as wired |
screamer | 2:cd21ef326977 | 73 | */ |
Mashu | 4:41bd7f360406 | 74 | FXAS21000(I2C &i2c, uint8_t addr); |
Mashu | 4:41bd7f360406 | 75 | |
Mashu | 4:41bd7f360406 | 76 | /** FXAS21000 deconstructor |
screamer | 2:cd21ef326977 | 77 | */ |
Mashu | 4:41bd7f360406 | 78 | ~FXAS21000(); |
JimCarver | 0:4cfc774d6d85 | 79 | |
Mashu | 4:41bd7f360406 | 80 | void writeRegs(uint8_t *data, uint32_t len) const; |
Mashu | 4:41bd7f360406 | 81 | int16_t getSensorAxis(uint8_t addr) const; |
Mashu | 4:41bd7f360406 | 82 | }; |
Mashu | 4:41bd7f360406 | 83 | |
Mashu | 4:41bd7f360406 | 84 | /** FXAS21000Gyroscpe interface |
Mashu | 4:41bd7f360406 | 85 | */ |
Mashu | 4:41bd7f360406 | 86 | class FXAS21000Gyroscpe : public FXAS21000 |
Mashu | 4:41bd7f360406 | 87 | { |
Mashu | 4:41bd7f360406 | 88 | public: |
screamer | 2:cd21ef326977 | 89 | |
Mashu | 4:41bd7f360406 | 90 | FXAS21000Gyroscpe(I2C &i2c, uint8_t addr) : FXAS21000(i2c, addr) {} |
Mashu | 4:41bd7f360406 | 91 | |
Mashu | 4:41bd7f360406 | 92 | virtual int16_t getX(int16_t &x) const; |
Mashu | 4:41bd7f360406 | 93 | virtual int16_t getY(int16_t &y) const; |
Mashu | 4:41bd7f360406 | 94 | virtual int16_t getZ(int16_t &z) const; |
Mashu | 4:41bd7f360406 | 95 | virtual float getX(float &x) const; |
Mashu | 4:41bd7f360406 | 96 | virtual float getY(float &y) const; |
Mashu | 4:41bd7f360406 | 97 | virtual float getZ(float &z) const; |
Mashu | 4:41bd7f360406 | 98 | virtual void getAxis(motion_data_counts_t &xyz) const; |
Mashu | 4:41bd7f360406 | 99 | virtual void getAxis(motion_data_units_t &xyz) const; |
Mashu | 4:41bd7f360406 | 100 | |
JimCarver | 0:4cfc774d6d85 | 101 | }; |
JimCarver | 0:4cfc774d6d85 | 102 | |
JimCarver | 0:4cfc774d6d85 | 103 | #endif |