functions for dealing with the L3GD20 gyro

Dependents:   minimu-9v2 MicroMouse-v1 idd_hw3_ddrew73_fil_clashSword Nucleo_IMU ... more

Committer:
bclaus
Date:
Mon May 22 15:18:15 2017 +0000
Revision:
2:b45dbca259f8
Parent:
0:62dfce144cf7
working commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bclaus 0:62dfce144cf7 1 /* Copyright (c) 2011 Pololu Corporation. For more information, see
bclaus 0:62dfce144cf7 2 *
bclaus 0:62dfce144cf7 3 * http://www.pololu.com/
bclaus 0:62dfce144cf7 4 * http://forum.pololu.com/
bclaus 0:62dfce144cf7 5 *
bclaus 0:62dfce144cf7 6 * Permission is hereby granted, free of charge, to any person
bclaus 0:62dfce144cf7 7 * obtaining a copy of this software and associated documentation
bclaus 0:62dfce144cf7 8 * files (the "Software"), to deal in the Software without
bclaus 0:62dfce144cf7 9 * restriction, including without limitation the rights to use,
bclaus 0:62dfce144cf7 10 * copy, modify, merge, publish, distribute, sublicense, and/or sell
bclaus 0:62dfce144cf7 11 * copies of the Software, and to permit persons to whom the
bclaus 0:62dfce144cf7 12 * Software is furnished to do so, subject to the following
bclaus 0:62dfce144cf7 13 * conditions:
bclaus 0:62dfce144cf7 14 *
bclaus 0:62dfce144cf7 15 * The above copyright notice and this permission notice shall be
bclaus 0:62dfce144cf7 16 * included in all copies or substantial portions of the Software.
bclaus 0:62dfce144cf7 17 *
bclaus 0:62dfce144cf7 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
bclaus 0:62dfce144cf7 19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
bclaus 0:62dfce144cf7 20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bclaus 0:62dfce144cf7 21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
bclaus 0:62dfce144cf7 22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
bclaus 0:62dfce144cf7 23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
bclaus 0:62dfce144cf7 24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
bclaus 0:62dfce144cf7 25 * OTHER DEALINGS IN THE SOFTWARE.
bclaus 0:62dfce144cf7 26 */
bclaus 0:62dfce144cf7 27
bclaus 0:62dfce144cf7 28 #ifndef __L3GD20_H
bclaus 0:62dfce144cf7 29 #define __L3GD20_H
bclaus 0:62dfce144cf7 30
bclaus 0:62dfce144cf7 31 #include "mbed.h"
bclaus 0:62dfce144cf7 32
bclaus 0:62dfce144cf7 33 // register addresses
bclaus 0:62dfce144cf7 34
bclaus 0:62dfce144cf7 35 #define L3GD20_WHO_AM_I 0x0F
bclaus 0:62dfce144cf7 36
bclaus 0:62dfce144cf7 37 #define L3GD20_CTRL_REG1 0x20
bclaus 0:62dfce144cf7 38 #define L3GD20_CTRL_REG2 0x21
bclaus 0:62dfce144cf7 39 #define L3GD20_CTRL_REG3 0x22
bclaus 0:62dfce144cf7 40 #define L3GD20_CTRL_REG4 0x23
bclaus 0:62dfce144cf7 41 #define L3GD20_CTRL_REG5 0x24
bclaus 0:62dfce144cf7 42 #define L3GD20_REFERENCE 0x25
bclaus 0:62dfce144cf7 43 #define L3GD20_OUT_TEMP 0x26
bclaus 0:62dfce144cf7 44 #define L3GD20_STATUS_REG 0x27
bclaus 0:62dfce144cf7 45
bclaus 0:62dfce144cf7 46 #define L3GD20_OUT_X_L 0x28
bclaus 0:62dfce144cf7 47 #define L3GD20_OUT_X_H 0x29
bclaus 0:62dfce144cf7 48 #define L3GD20_OUT_Y_L 0x2A
bclaus 0:62dfce144cf7 49 #define L3GD20_OUT_Y_H 0x2B
bclaus 0:62dfce144cf7 50 #define L3GD20_OUT_Z_L 0x2C
bclaus 0:62dfce144cf7 51 #define L3GD20_OUT_Z_H 0x2D
bclaus 0:62dfce144cf7 52
bclaus 0:62dfce144cf7 53 #define L3GD20_FIFO_CTRL_REG 0x2E
bclaus 0:62dfce144cf7 54 #define L3GD20_FIFO_SRC_REG 0x2F
bclaus 0:62dfce144cf7 55
bclaus 0:62dfce144cf7 56 #define L3GD20_INT1_CFG 0x30
bclaus 0:62dfce144cf7 57 #define L3GD20_INT1_SRC 0x31
bclaus 0:62dfce144cf7 58 #define L3GD20_INT1_THS_XH 0x32
bclaus 0:62dfce144cf7 59 #define L3GD20_INT1_THS_XL 0x33
bclaus 0:62dfce144cf7 60 #define L3GD20_INT1_THS_YH 0x34
bclaus 0:62dfce144cf7 61 #define L3GD20_INT1_THS_YL 0x35
bclaus 0:62dfce144cf7 62 #define L3GD20_INT1_THS_ZH 0x36
bclaus 0:62dfce144cf7 63 #define L3GD20_INT1_THS_ZL 0x37
bclaus 0:62dfce144cf7 64 #define L3GD20_INT1_DURATION 0x38
bclaus 2:b45dbca259f8 65 #define L3GD20_LOW_ODR 0x39 // D20H
bclaus 0:62dfce144cf7 66
bclaus 0:62dfce144cf7 67 /** Interface library for the ST L3GD20 3-axis gyro
bclaus 0:62dfce144cf7 68 *
bclaus 0:62dfce144cf7 69 * Ported from Pololu L3GD20 library for Arduino by
bclaus 0:62dfce144cf7 70 *
bclaus 0:62dfce144cf7 71 * @code
bclaus 0:62dfce144cf7 72 * #include "mbed.h"
bclaus 0:62dfce144cf7 73 * #include "L3GD20.h"
bclaus 0:62dfce144cf7 74 * L3GD20 gyro(p28, p27);
bclaus 0:62dfce144cf7 75 * ...
bclaus 0:62dfce144cf7 76 * int g[3];
bclaus 0:62dfce144cf7 77 * gyro.read(g);
bclaus 0:62dfce144cf7 78 * @endcode
bclaus 0:62dfce144cf7 79 */
bclaus 0:62dfce144cf7 80 class L3GD20
bclaus 0:62dfce144cf7 81 {
bclaus 0:62dfce144cf7 82 public:
bclaus 0:62dfce144cf7 83 /** Create a new L3GD20 I2C interface
bclaus 0:62dfce144cf7 84 * @param sda is the pin for the I2C SDA line
bclaus 0:62dfce144cf7 85 * @param scl is the pin for the I2C SCL line
bclaus 0:62dfce144cf7 86 */
bclaus 0:62dfce144cf7 87 L3GD20(PinName sda, PinName scl);
bclaus 0:62dfce144cf7 88
bclaus 0:62dfce144cf7 89 /** Read gyro values
bclaus 0:62dfce144cf7 90 * @param g Array containing x, y, and z gyro values
bclaus 0:62dfce144cf7 91 * @return g Array containing x, y, and z gyro values
bclaus 0:62dfce144cf7 92 */
bclaus 0:62dfce144cf7 93 bool read(float *gx, float *gy, float *gz);
bclaus 0:62dfce144cf7 94
bclaus 0:62dfce144cf7 95 private:
bclaus 0:62dfce144cf7 96 I2C _L3GD20;
bclaus 0:62dfce144cf7 97 float gx, gy, gz;
bclaus 0:62dfce144cf7 98
bclaus 0:62dfce144cf7 99 bool write_reg(int addr_i2c,int addr_reg, char v);
bclaus 0:62dfce144cf7 100 bool read_reg(int addr_i2c,int addr_reg, char *v);
bclaus 0:62dfce144cf7 101 bool recv(char sad, char sub, char *buf, int length);
bclaus 0:62dfce144cf7 102 };
bclaus 0:62dfce144cf7 103
bclaus 0:62dfce144cf7 104 #endif