Refactoring Ironcup 2020
Dependencies: mbed mbed-rtos MotionSensor EthernetInterface
SensorsLibrary/FXAS21002.h@0:8f5db5085df7, 2020-09-21 (annotated)
- Committer:
- starling
- Date:
- Mon Sep 21 21:42:07 2020 +0000
- Revision:
- 0:8f5db5085df7
12 mar 2020
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
starling | 0:8f5db5085df7 | 1 | /* Copyright (c) 2015 NXP Semiconductors. MIT License |
starling | 0:8f5db5085df7 | 2 | * |
starling | 0:8f5db5085df7 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
starling | 0:8f5db5085df7 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
starling | 0:8f5db5085df7 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
starling | 0:8f5db5085df7 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
starling | 0:8f5db5085df7 | 7 | * Software is furnished to do so, subject to the following conditions: |
starling | 0:8f5db5085df7 | 8 | * |
starling | 0:8f5db5085df7 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
starling | 0:8f5db5085df7 | 10 | * substantial portions of the Software. |
starling | 0:8f5db5085df7 | 11 | * |
starling | 0:8f5db5085df7 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
starling | 0:8f5db5085df7 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
starling | 0:8f5db5085df7 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
starling | 0:8f5db5085df7 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
starling | 0:8f5db5085df7 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
starling | 0:8f5db5085df7 | 17 | */ |
starling | 0:8f5db5085df7 | 18 | |
starling | 0:8f5db5085df7 | 19 | #ifndef FXAS21002_H |
starling | 0:8f5db5085df7 | 20 | #define FXAS21002_H |
starling | 0:8f5db5085df7 | 21 | #include "mbed.h" |
starling | 0:8f5db5085df7 | 22 | |
starling | 0:8f5db5085df7 | 23 | #define FXAS21002_I2C_ADDRESS 0x40 |
starling | 0:8f5db5085df7 | 24 | |
starling | 0:8f5db5085df7 | 25 | #define FXAS21002_STATUS 0x00 |
starling | 0:8f5db5085df7 | 26 | #define FXAS21002_WHO_AM_I 0x0C |
starling | 0:8f5db5085df7 | 27 | #define FXAS21002_CTRL_REG0 0x0D |
starling | 0:8f5db5085df7 | 28 | #define FXAS21002_CTRL_REG1 0x13 |
starling | 0:8f5db5085df7 | 29 | #define FXAS21002_WHO_AM_I_VALUE 0xD1 |
starling | 0:8f5db5085df7 | 30 | #define GYRO_OFFSET -0.239 //-0.15 //-0.2396875 |
starling | 0:8f5db5085df7 | 31 | /* Gyroscope mechanical modes |
starling | 0:8f5db5085df7 | 32 | * Mode Full-scale range [Deg/s] Sensitivity [(mDeg/s)/LSB] |
starling | 0:8f5db5085df7 | 33 | * 1 +- 2000 62.5 |
starling | 0:8f5db5085df7 | 34 | * 2 +- 1000 31.25 |
starling | 0:8f5db5085df7 | 35 | * 3 +- 500 15.625 |
starling | 0:8f5db5085df7 | 36 | * 4 +- 250 7.8125 |
starling | 0:8f5db5085df7 | 37 | */ |
starling | 0:8f5db5085df7 | 38 | enum gyro_mode |
starling | 0:8f5db5085df7 | 39 | { |
starling | 0:8f5db5085df7 | 40 | MODE_1 = 0x00, |
starling | 0:8f5db5085df7 | 41 | MODE_2 = 0x01, |
starling | 0:8f5db5085df7 | 42 | MODE_3 = 0x02, |
starling | 0:8f5db5085df7 | 43 | MODE_4 = 0x03 |
starling | 0:8f5db5085df7 | 44 | }; |
starling | 0:8f5db5085df7 | 45 | |
starling | 0:8f5db5085df7 | 46 | class FXAS21002 |
starling | 0:8f5db5085df7 | 47 | { |
starling | 0:8f5db5085df7 | 48 | public: |
starling | 0:8f5db5085df7 | 49 | |
starling | 0:8f5db5085df7 | 50 | FXAS21002(PinName sda, PinName scl); |
starling | 0:8f5db5085df7 | 51 | |
starling | 0:8f5db5085df7 | 52 | void gyro_config(void); |
starling | 0:8f5db5085df7 | 53 | void gyro_config(gyro_mode mode); |
starling | 0:8f5db5085df7 | 54 | |
starling | 0:8f5db5085df7 | 55 | void acquire_gyro_data_dps(float * du); |
starling | 0:8f5db5085df7 | 56 | void start_measure(float period_us); |
starling | 0:8f5db5085df7 | 57 | void stop_measure(void); |
starling | 0:8f5db5085df7 | 58 | float get_angle(void); |
starling | 0:8f5db5085df7 | 59 | |
starling | 0:8f5db5085df7 | 60 | private: |
starling | 0:8f5db5085df7 | 61 | void set_gyro(gyro_mode mode); |
starling | 0:8f5db5085df7 | 62 | void integrate_gyro_angle(void); |
starling | 0:8f5db5085df7 | 63 | Ticker interrupt; |
starling | 0:8f5db5085df7 | 64 | I2C gyroi2c; |
starling | 0:8f5db5085df7 | 65 | float sensitivity; |
starling | 0:8f5db5085df7 | 66 | float angle; |
starling | 0:8f5db5085df7 | 67 | float period; |
starling | 0:8f5db5085df7 | 68 | |
starling | 0:8f5db5085df7 | 69 | }; |
starling | 0:8f5db5085df7 | 70 | |
starling | 0:8f5db5085df7 | 71 | #endif |