Ironcup Mar 2020

Dependencies:   mbed mbed-rtos MotionSensor EthernetInterface

Committer:
starling
Date:
Mon Sep 21 21:45:08 2020 +0000
Revision:
22:b7cca3089dfe
Parent:
20:7138ab2f93f7
01 mar 2020

Who changed what in which revision?

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