Dependencies:   FatFileSystem mbed

Committer:
higedura
Date:
Sat Apr 21 14:07:27 2012 +0000
Revision:
2:307500c991dd
Parent:
0:813b917360ac

        

Who changed what in which revision?

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