adsasda

Committer:
taskintuna35
Date:
Wed Nov 04 10:45:55 2015 +0000
Revision:
1:1b19b88aacfe
Parent:
0:6698f2e69fdc
ty?ty?u

Who changed what in which revision?

UserRevisionLine numberNew contents of line
taskintuna35 0:6698f2e69fdc 1 /**
taskintuna35 0:6698f2e69fdc 2 * @author Uwe Gartmann
taskintuna35 0:6698f2e69fdc 3 * @author Used HMC5883L library developed by Jose R. Padron and Aaron Berk as template
taskintuna35 0:6698f2e69fdc 4 *
taskintuna35 0:6698f2e69fdc 5 * @section LICENSE
taskintuna35 0:6698f2e69fdc 6 *
taskintuna35 0:6698f2e69fdc 7 * Copyright (c) 2010 ARM Limited
taskintuna35 0:6698f2e69fdc 8 *
taskintuna35 0:6698f2e69fdc 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
taskintuna35 0:6698f2e69fdc 10 * of this software and associated documentation files (the "Software"), to deal
taskintuna35 0:6698f2e69fdc 11 * in the Software without restriction, including without limitation the rights
taskintuna35 0:6698f2e69fdc 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
taskintuna35 0:6698f2e69fdc 13 * copies of the Software, and to permit persons to whom the Software is
taskintuna35 0:6698f2e69fdc 14 * furnished to do so, subject to the following conditions:
taskintuna35 0:6698f2e69fdc 15 *
taskintuna35 0:6698f2e69fdc 16 * The above copyright notice and this permission notice shall be included in
taskintuna35 0:6698f2e69fdc 17 * all copies or substantial portions of the Software.
taskintuna35 0:6698f2e69fdc 18 *
taskintuna35 0:6698f2e69fdc 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
taskintuna35 0:6698f2e69fdc 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
taskintuna35 0:6698f2e69fdc 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
taskintuna35 0:6698f2e69fdc 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
taskintuna35 0:6698f2e69fdc 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
taskintuna35 0:6698f2e69fdc 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
taskintuna35 0:6698f2e69fdc 25 * THE SOFTWARE.
taskintuna35 0:6698f2e69fdc 26 *
taskintuna35 0:6698f2e69fdc 27 * @section DESCRIPTION
taskintuna35 0:6698f2e69fdc 28 *
taskintuna35 0:6698f2e69fdc 29 * Honeywell HMC5883L digital compass.
taskintuna35 0:6698f2e69fdc 30 *
taskintuna35 0:6698f2e69fdc 31 * Datasheet:
taskintuna35 0:6698f2e69fdc 32 *
taskintuna35 0:6698f2e69fdc 33 * http://www.ssec.honeywell.com/magnetic/datasheets/HMC5883L.pdf
taskintuna35 0:6698f2e69fdc 34 */
taskintuna35 0:6698f2e69fdc 35
taskintuna35 0:6698f2e69fdc 36 #ifndef HMC5883L_H
taskintuna35 0:6698f2e69fdc 37 #define HMC5883L_H
taskintuna35 0:6698f2e69fdc 38
taskintuna35 0:6698f2e69fdc 39 /**
taskintuna35 0:6698f2e69fdc 40 * Includes
taskintuna35 0:6698f2e69fdc 41 */
taskintuna35 0:6698f2e69fdc 42 #include "mbed.h"
taskintuna35 0:6698f2e69fdc 43
taskintuna35 0:6698f2e69fdc 44 /**
taskintuna35 0:6698f2e69fdc 45 * Defines
taskintuna35 0:6698f2e69fdc 46 */
taskintuna35 0:6698f2e69fdc 47 #define HMC5883L_I2C_ADDRESS 0x1E //7-bit address. 0x3C write, 0x3D read.
taskintuna35 0:6698f2e69fdc 48 #define HMC5883L_I2C_WRITE 0x3C
taskintuna35 0:6698f2e69fdc 49 #define HMC5883L_I2C_READ 0x3D
taskintuna35 0:6698f2e69fdc 50
taskintuna35 0:6698f2e69fdc 51 //Values Config A
taskintuna35 0:6698f2e69fdc 52 #define HMC5883L_0_5HZ_NORMAL 0x00
taskintuna35 0:6698f2e69fdc 53 #define HMC5883L_0_5HZ_POSITIVE 0x01
taskintuna35 0:6698f2e69fdc 54 #define HMC5883L_0_5HZ_NEGATIVE 0x02
taskintuna35 0:6698f2e69fdc 55
taskintuna35 0:6698f2e69fdc 56 #define HMC5883L_1HZ_NORMAL 0x04
taskintuna35 0:6698f2e69fdc 57 #define HMC5883L_1HZ_POSITIVE 0x05
taskintuna35 0:6698f2e69fdc 58 #define HMC5883L_1HZ_NEGATIVE 0x06
taskintuna35 0:6698f2e69fdc 59
taskintuna35 0:6698f2e69fdc 60 #define HMC5883L_2HZ_NORMAL 0x08
taskintuna35 0:6698f2e69fdc 61 #define HMC5883L_2HZ_POSITIVE 0x09
taskintuna35 0:6698f2e69fdc 62 #define HMC5883L_2HZ_NEGATIVE 0x0A
taskintuna35 0:6698f2e69fdc 63
taskintuna35 0:6698f2e69fdc 64 #define HMC5883L_5HZ_NORMAL 0x0C
taskintuna35 0:6698f2e69fdc 65 #define HMC5883L_5HZ_POSITIVE 0x0D
taskintuna35 0:6698f2e69fdc 66 #define HMC5883L_5HZ_NEGATIVE 0x0E
taskintuna35 0:6698f2e69fdc 67
taskintuna35 0:6698f2e69fdc 68 #define HMC5883L_10HZ_NORMAL 0x10
taskintuna35 0:6698f2e69fdc 69 #define HMC5883L_10HZ_POSITIVE 0x11
taskintuna35 0:6698f2e69fdc 70 #define HMC5883L_10HZ_NEGATIVE 0x12
taskintuna35 0:6698f2e69fdc 71
taskintuna35 0:6698f2e69fdc 72 #define HMC5883L_20HZ_NORMAL 0x14
taskintuna35 0:6698f2e69fdc 73 #define HMC5883L_20HZ_POSITIVE 0x15
taskintuna35 0:6698f2e69fdc 74 #define HMC5883L_20HZ_NEGATIVE 0x16
taskintuna35 0:6698f2e69fdc 75
taskintuna35 0:6698f2e69fdc 76 #define HMC5883L_50HZ_NORMAL 0x18
taskintuna35 0:6698f2e69fdc 77 #define HMC5883L_50HZ_POSITIVE 0x19
taskintuna35 0:6698f2e69fdc 78 #define HMC5883L_50HZ_NEGATIVE 0x1A
taskintuna35 0:6698f2e69fdc 79
taskintuna35 0:6698f2e69fdc 80 //Values Config B
taskintuna35 0:6698f2e69fdc 81 #define HMC5883L_0_7GA 0x00
taskintuna35 0:6698f2e69fdc 82 #define HMC5883L_1_0GA 0x20
taskintuna35 0:6698f2e69fdc 83 #define HMC5883L_1_5GA 0x40
taskintuna35 0:6698f2e69fdc 84 #define HMC5883L_2_0GA 0x60
taskintuna35 0:6698f2e69fdc 85 #define HMC5883L_3_2GA 0x80
taskintuna35 0:6698f2e69fdc 86 #define HMC5883L_3_8GA 0xA0
taskintuna35 0:6698f2e69fdc 87 #define HMC5883L_4_5GA 0xC0
taskintuna35 0:6698f2e69fdc 88 #define HMC5883L_6_5GA 0xE0
taskintuna35 0:6698f2e69fdc 89
taskintuna35 0:6698f2e69fdc 90 //Values MODE
taskintuna35 0:6698f2e69fdc 91 #define HMC5883L_CONTINUOUS 0x00
taskintuna35 0:6698f2e69fdc 92 #define HMC5883L_SINGLE 0x01
taskintuna35 0:6698f2e69fdc 93 #define HMC5883L_IDLE 0x02
taskintuna35 0:6698f2e69fdc 94 #define HMC5883L_SLEEP 0x03
taskintuna35 0:6698f2e69fdc 95
taskintuna35 0:6698f2e69fdc 96
taskintuna35 0:6698f2e69fdc 97
taskintuna35 0:6698f2e69fdc 98 #define HMC5883L_CONFIG_A 0x00
taskintuna35 0:6698f2e69fdc 99 #define HMC5883L_CONFIG_B 0x01
taskintuna35 0:6698f2e69fdc 100 #define HMC5883L_MODE 0x02
taskintuna35 0:6698f2e69fdc 101 #define HMC5883L_X_MSB 0x03
taskintuna35 0:6698f2e69fdc 102 #define HMC5883L_X_LSB 0x04
taskintuna35 0:6698f2e69fdc 103 #define HMC5883L_Z_MSB 0x05
taskintuna35 0:6698f2e69fdc 104 #define HMC5883L_Z_LSB 0x06
taskintuna35 0:6698f2e69fdc 105 #define HMC5883L_Y_MSB 0x07
taskintuna35 0:6698f2e69fdc 106 #define HMC5883L_Y_LSB 0x08
taskintuna35 0:6698f2e69fdc 107 #define HMC5883L_STATUS 0x09
taskintuna35 0:6698f2e69fdc 108 #define HMC5883L_IDENT_A 0x0A
taskintuna35 0:6698f2e69fdc 109 #define HMC5883L_IDENT_B 0x0B
taskintuna35 0:6698f2e69fdc 110 #define HMC5883L_IDENT_C 0x0C
taskintuna35 0:6698f2e69fdc 111
taskintuna35 0:6698f2e69fdc 112
taskintuna35 0:6698f2e69fdc 113
taskintuna35 0:6698f2e69fdc 114 /**
taskintuna35 0:6698f2e69fdc 115 * Honeywell HMC5883L digital compass.
taskintuna35 0:6698f2e69fdc 116 */
taskintuna35 0:6698f2e69fdc 117 00117 class HMC5883L {
taskintuna35 0:6698f2e69fdc 118
taskintuna35 0:6698f2e69fdc 119 public:
taskintuna35 0:6698f2e69fdc 120
taskintuna35 0:6698f2e69fdc 121 /**
taskintuna35 0:6698f2e69fdc 122 * Constructor.
taskintuna35 0:6698f2e69fdc 123 *
taskintuna35 0:6698f2e69fdc 124 * @param sda mbed pin to use for SDA line of I2C interface.
taskintuna35 0:6698f2e69fdc 125 * @param scl mbed pin to use for SCL line of I2C interface.
taskintuna35 0:6698f2e69fdc 126 */
taskintuna35 0:6698f2e69fdc 127 HMC5883L(PinName sda, PinName scl);
taskintuna35 0:6698f2e69fdc 128
taskintuna35 0:6698f2e69fdc 129
taskintuna35 0:6698f2e69fdc 130 /**
taskintuna35 0:6698f2e69fdc 131 * Enter into sleep mode.
taskintuna35 0:6698f2e69fdc 132 *
taskintuna35 0:6698f2e69fdc 133 */
taskintuna35 0:6698f2e69fdc 134 void setSleepMode();
taskintuna35 0:6698f2e69fdc 135
taskintuna35 0:6698f2e69fdc 136
taskintuna35 0:6698f2e69fdc 137 /**
taskintuna35 0:6698f2e69fdc 138 * Set Device in Default Mode.
taskintuna35 0:6698f2e69fdc 139 * HMC5883L_CONTINUOUS, HMC5883L_10HZ_NORMAL HMC5883L_1_0GA
taskintuna35 0:6698f2e69fdc 140 */
taskintuna35 0:6698f2e69fdc 141 void setDefault();
taskintuna35 0:6698f2e69fdc 142
taskintuna35 0:6698f2e69fdc 143
taskintuna35 0:6698f2e69fdc 144 /**
taskintuna35 0:6698f2e69fdc 145 * Read the memory location on the device which contains the address.
taskintuna35 0:6698f2e69fdc 146 *
taskintuna35 0:6698f2e69fdc 147 * @param Pointer to a buffer to hold the address value
taskintuna35 0:6698f2e69fdc 148 * Expected H, 4 and 3.
taskintuna35 0:6698f2e69fdc 149 */
taskintuna35 0:6698f2e69fdc 150 void getAddress(char * address);
taskintuna35 0:6698f2e69fdc 151
taskintuna35 0:6698f2e69fdc 152
taskintuna35 0:6698f2e69fdc 153
taskintuna35 0:6698f2e69fdc 154 /**
taskintuna35 0:6698f2e69fdc 155 * Set the operation mode.
taskintuna35 0:6698f2e69fdc 156 *
taskintuna35 0:6698f2e69fdc 157 * @param mode 0x00 -> Continuous
taskintuna35 0:6698f2e69fdc 158 * 0x01 -> Single
taskintuna35 0:6698f2e69fdc 159 * 0x02 -> Idle
taskintuna35 0:6698f2e69fdc 160 * @param ConfigA values
taskintuna35 0:6698f2e69fdc 161 * @param ConfigB values
taskintuna35 0:6698f2e69fdc 162 */
taskintuna35 0:6698f2e69fdc 163 void setOpMode(int mode, int ConfigA, int ConfigB);
taskintuna35 0:6698f2e69fdc 164
taskintuna35 0:6698f2e69fdc 165 /**
taskintuna35 0:6698f2e69fdc 166 * Write to on the device.
taskintuna35 0:6698f2e69fdc 167 *
taskintuna35 0:6698f2e69fdc 168 * @param address Address to write to.
taskintuna35 0:6698f2e69fdc 169 * @param data Data to write.
taskintuna35 0:6698f2e69fdc 170 */
taskintuna35 0:6698f2e69fdc 171
taskintuna35 0:6698f2e69fdc 172 void write(int address, int data);
taskintuna35 0:6698f2e69fdc 173
taskintuna35 0:6698f2e69fdc 174 /**
taskintuna35 0:6698f2e69fdc 175 * Get the output of all three axes.
taskintuna35 0:6698f2e69fdc 176 *
taskintuna35 0:6698f2e69fdc 177 * @param Pointer to a buffer to hold the magnetics value for the
taskintuna35 0:6698f2e69fdc 178 * x-axis, y-axis and z-axis [in that order].
taskintuna35 0:6698f2e69fdc 179 */
taskintuna35 0:6698f2e69fdc 180 void readData(int* getMag);
taskintuna35 0:6698f2e69fdc 181
taskintuna35 0:6698f2e69fdc 182 /**
taskintuna35 0:6698f2e69fdc 183 * Get the output of X axis.
taskintuna35 0:6698f2e69fdc 184 *
taskintuna35 0:6698f2e69fdc 185 * @return x-axis magnetic value
taskintuna35 0:6698f2e69fdc 186 */
taskintuna35 0:6698f2e69fdc 187 int getMx();
taskintuna35 0:6698f2e69fdc 188
taskintuna35 0:6698f2e69fdc 189 /**
taskintuna35 0:6698f2e69fdc 190 * Get the output of Y axis.
taskintuna35 0:6698f2e69fdc 191 *
taskintuna35 0:6698f2e69fdc 192 * @return y-axis magnetic value
taskintuna35 0:6698f2e69fdc 193 */
taskintuna35 0:6698f2e69fdc 194 int getMy();
taskintuna35 0:6698f2e69fdc 195
taskintuna35 0:6698f2e69fdc 196 /**
taskintuna35 0:6698f2e69fdc 197 * Get the output of Z axis.
taskintuna35 0:6698f2e69fdc 198 *
taskintuna35 0:6698f2e69fdc 199 * @return z-axis magnetic value
taskintuna35 0:6698f2e69fdc 200 */
taskintuna35 0:6698f2e69fdc 201 int getMz();
taskintuna35 0:6698f2e69fdc 202
taskintuna35 0:6698f2e69fdc 203
taskintuna35 0:6698f2e69fdc 204 /**
taskintuna35 0:6698f2e69fdc 205 * Get the current operation mode.
taskintuna35 0:6698f2e69fdc 206 *
taskintuna35 0:6698f2e69fdc 207 * @return Status register values
taskintuna35 0:6698f2e69fdc 208 */
taskintuna35 0:6698f2e69fdc 209 int getStatus(void);
taskintuna35 0:6698f2e69fdc 210
taskintuna35 0:6698f2e69fdc 211
taskintuna35 0:6698f2e69fdc 212
taskintuna35 0:6698f2e69fdc 213 I2C* i2c_;
taskintuna35 0:6698f2e69fdc 214
taskintuna35 0:6698f2e69fdc 215
taskintuna35 0:6698f2e69fdc 216
taskintuna35 0:6698f2e69fdc 217 };
taskintuna35 0:6698f2e69fdc 218
taskintuna35 0:6698f2e69fdc 219 #endif /* HMC5883L_H */