my own one
Fork of FXAS21002 by
FXAS21002.cpp@2:504e7f1bbf11, 2017-04-24 (annotated)
- Committer:
- AswinSivakumar
- Date:
- Mon Apr 24 19:07:18 2017 +0000
- Revision:
- 2:504e7f1bbf11
- Parent:
- 1:b774372b3913
updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AswinSivakumar | 2:504e7f1bbf11 | 1 | /* |
AswinSivakumar | 2:504e7f1bbf11 | 2 | * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. |
AswinSivakumar | 2:504e7f1bbf11 | 3 | * Copyright 2016-2017 NXP |
AswinSivakumar | 2:504e7f1bbf11 | 4 | * |
AswinSivakumar | 2:504e7f1bbf11 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
AswinSivakumar | 2:504e7f1bbf11 | 6 | * are permitted provided that the following conditions are met: |
AswinSivakumar | 2:504e7f1bbf11 | 7 | * |
AswinSivakumar | 2:504e7f1bbf11 | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
AswinSivakumar | 2:504e7f1bbf11 | 9 | * of conditions and the following disclaimer. |
AswinSivakumar | 2:504e7f1bbf11 | 10 | * |
AswinSivakumar | 2:504e7f1bbf11 | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
AswinSivakumar | 2:504e7f1bbf11 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
AswinSivakumar | 2:504e7f1bbf11 | 13 | * other materials provided with the distribution. |
AswinSivakumar | 2:504e7f1bbf11 | 14 | * |
AswinSivakumar | 2:504e7f1bbf11 | 15 | * o Neither the name of the copyright holder nor the names of its |
AswinSivakumar | 2:504e7f1bbf11 | 16 | * contributors may be used to endorse or promote products derived from this |
AswinSivakumar | 2:504e7f1bbf11 | 17 | * software without specific prior written permission. |
AswinSivakumar | 2:504e7f1bbf11 | 18 | * |
AswinSivakumar | 2:504e7f1bbf11 | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
AswinSivakumar | 2:504e7f1bbf11 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
AswinSivakumar | 2:504e7f1bbf11 | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
AswinSivakumar | 2:504e7f1bbf11 | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
AswinSivakumar | 2:504e7f1bbf11 | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
AswinSivakumar | 2:504e7f1bbf11 | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
AswinSivakumar | 2:504e7f1bbf11 | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
AswinSivakumar | 2:504e7f1bbf11 | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
AswinSivakumar | 2:504e7f1bbf11 | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
AswinSivakumar | 2:504e7f1bbf11 | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
AswinSivakumar | 2:504e7f1bbf11 | 29 | */ |
AswinSivakumar | 0:9c9e8aaad4ff | 30 | |
AswinSivakumar | 0:9c9e8aaad4ff | 31 | #include "FXAS21002.h" |
AswinSivakumar | 0:9c9e8aaad4ff | 32 | #include "mbed.h" |
AswinSivakumar | 0:9c9e8aaad4ff | 33 | |
AswinSivakumar | 0:9c9e8aaad4ff | 34 | FXAS21002::FXAS21002(PinName sda, PinName scl) : gyroi2c(sda,scl) |
AswinSivakumar | 0:9c9e8aaad4ff | 35 | { |
AswinSivakumar | 0:9c9e8aaad4ff | 36 | |
AswinSivakumar | 0:9c9e8aaad4ff | 37 | } |
AswinSivakumar | 0:9c9e8aaad4ff | 38 | |
AswinSivakumar | 0:9c9e8aaad4ff | 39 | void FXAS21002::gyro_config(void) |
AswinSivakumar | 0:9c9e8aaad4ff | 40 | { |
AswinSivakumar | 0:9c9e8aaad4ff | 41 | char d[2]; |
AswinSivakumar | 0:9c9e8aaad4ff | 42 | d[0] = FXAS21002_CTRL_REG1; //Puts device in standby mode |
AswinSivakumar | 0:9c9e8aaad4ff | 43 | d[1] = 0x08; |
AswinSivakumar | 0:9c9e8aaad4ff | 44 | gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2); |
AswinSivakumar | 0:9c9e8aaad4ff | 45 | |
AswinSivakumar | 0:9c9e8aaad4ff | 46 | |
AswinSivakumar | 0:9c9e8aaad4ff | 47 | d[0] = FXAS21002_CTRL_REG0; //sets FS =+/- 2000 dps |
AswinSivakumar | 0:9c9e8aaad4ff | 48 | d[1] = 0x00; |
AswinSivakumar | 0:9c9e8aaad4ff | 49 | gyroi2c.write(FXAS21002_I2C_ADDRESS, d, 2); |
AswinSivakumar | 0:9c9e8aaad4ff | 50 | |
AswinSivakumar | 0:9c9e8aaad4ff | 51 | |
AswinSivakumar | 0:9c9e8aaad4ff | 52 | d[0] = FXAS21002_CTRL_REG1; //Puts device in active mode |
AswinSivakumar | 0:9c9e8aaad4ff | 53 | d[1] = 0x0A; |
AswinSivakumar | 0:9c9e8aaad4ff | 54 | gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2); |
AswinSivakumar | 0:9c9e8aaad4ff | 55 | |
AswinSivakumar | 0:9c9e8aaad4ff | 56 | } |
AswinSivakumar | 0:9c9e8aaad4ff | 57 | |
AswinSivakumar | 0:9c9e8aaad4ff | 58 | void FXAS21002::acquire_gyro_data_dps(float * g_data) |
AswinSivakumar | 0:9c9e8aaad4ff | 59 | { |
AswinSivakumar | 0:9c9e8aaad4ff | 60 | |
AswinSivakumar | 0:9c9e8aaad4ff | 61 | char data_bytes[7]; |
AswinSivakumar | 0:9c9e8aaad4ff | 62 | gyroi2c.write(FXAS21002_I2C_ADDRESS,FXAS21002_STATUS,1,true); // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes. |
AswinSivakumar | 0:9c9e8aaad4ff | 63 | gyroi2c.read(FXAS21002_I2C_ADDRESS,data_bytes,7); |
AswinSivakumar | 0:9c9e8aaad4ff | 64 | |
AswinSivakumar | 0:9c9e8aaad4ff | 65 | g_data[0] = (float)((int16_t)((data_bytes[1]*256) + (data_bytes[2]))) * 0.0625; |
AswinSivakumar | 0:9c9e8aaad4ff | 66 | g_data[1] = (float)((int16_t)((data_bytes[3]*256) + (data_bytes[4]))) * 0.0625; |
AswinSivakumar | 0:9c9e8aaad4ff | 67 | g_data[2] = (float)((int16_t)((data_bytes[5]*256) + (data_bytes[6]))) * 0.0625; |
AswinSivakumar | 0:9c9e8aaad4ff | 68 | |
AswinSivakumar | 0:9c9e8aaad4ff | 69 | } |
AswinSivakumar | 0:9c9e8aaad4ff | 70 | |
AswinSivakumar | 0:9c9e8aaad4ff | 71 | |
AswinSivakumar | 0:9c9e8aaad4ff | 72 | |
AswinSivakumar | 0:9c9e8aaad4ff | 73 |