test

Committer:
aberk
Date:
Sat Nov 27 12:15:03 2010 +0000
Revision:
0:83c0cb554099
Child:
1:b53ae9d2ceae
Version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aberk 0:83c0cb554099 1 /**
aberk 0:83c0cb554099 2 * @author Aaron Berk
aberk 0:83c0cb554099 3 *
aberk 0:83c0cb554099 4 * @section LICENSE
aberk 0:83c0cb554099 5 *
aberk 0:83c0cb554099 6 * Copyright (c) 2010 ARM Limited
aberk 0:83c0cb554099 7 *
aberk 0:83c0cb554099 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
aberk 0:83c0cb554099 9 * of this software and associated documentation files (the "Software"), to deal
aberk 0:83c0cb554099 10 * in the Software without restriction, including without limitation the rights
aberk 0:83c0cb554099 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
aberk 0:83c0cb554099 12 * copies of the Software, and to permit persons to whom the Software is
aberk 0:83c0cb554099 13 * furnished to do so, subject to the following conditions:
aberk 0:83c0cb554099 14 *
aberk 0:83c0cb554099 15 * The above copyright notice and this permission notice shall be included in
aberk 0:83c0cb554099 16 * all copies or substantial portions of the Software.
aberk 0:83c0cb554099 17 *
aberk 0:83c0cb554099 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
aberk 0:83c0cb554099 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
aberk 0:83c0cb554099 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
aberk 0:83c0cb554099 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
aberk 0:83c0cb554099 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
aberk 0:83c0cb554099 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
aberk 0:83c0cb554099 24 * THE SOFTWARE.
aberk 0:83c0cb554099 25 *
aberk 0:83c0cb554099 26 * @section DESCRIPTION
aberk 0:83c0cb554099 27 *
aberk 0:83c0cb554099 28 * Honeywell HMC6352 digital compass.
aberk 0:83c0cb554099 29 *
aberk 0:83c0cb554099 30 * Datasheet:
aberk 0:83c0cb554099 31 *
aberk 0:83c0cb554099 32 * http://www.ssec.honeywell.com/magnetic/datasheets/HMC6352.pdf
aberk 0:83c0cb554099 33 */
aberk 0:83c0cb554099 34
aberk 0:83c0cb554099 35 #ifndef HMC6352_H
aberk 0:83c0cb554099 36 #define HMC6352_H
aberk 0:83c0cb554099 37
aberk 0:83c0cb554099 38 /**
aberk 0:83c0cb554099 39 * Includes
aberk 0:83c0cb554099 40 */
aberk 0:83c0cb554099 41 #include "mbed.h"
aberk 0:83c0cb554099 42
aberk 0:83c0cb554099 43 /**
aberk 0:83c0cb554099 44 * Defines
aberk 0:83c0cb554099 45 */
aberk 0:83c0cb554099 46 #define HMC6352_I2C_ADDRESS 0x21 //7-bit address. 0x43 write, 0x42 read.
aberk 0:83c0cb554099 47
aberk 0:83c0cb554099 48 //Commands.
aberk 0:83c0cb554099 49 #define HMC6352_EEPROM_WRITE 0x77
aberk 0:83c0cb554099 50 #define HMC6352_EEPROM_READ 0x72
aberk 0:83c0cb554099 51 #define HMC6352_RAM_WRITE 0x47
aberk 0:83c0cb554099 52 #define HMC6352_RAM_READ 0x67
aberk 0:83c0cb554099 53 #define HMC6352_ENTER_SLEEP 0x53
aberk 0:83c0cb554099 54 #define HMC6352_EXIT_SLEEP 0x57
aberk 0:83c0cb554099 55 #define HMC6352_SET_RESET 0x4F
aberk 0:83c0cb554099 56 #define HMC6352_ENTER_CALIB 0x43
aberk 0:83c0cb554099 57 #define HMC6352_EXIT_CALIB 0x45
aberk 0:83c0cb554099 58 #define HMC6352_SAVE_OPMODE 0x4C
aberk 0:83c0cb554099 59 #define HMC6352_GET_DATA 0x41
aberk 0:83c0cb554099 60
aberk 0:83c0cb554099 61 //EEPROM locations.
aberk 0:83c0cb554099 62 #define HMC6352_SLAVE_ADDR 0x00
aberk 0:83c0cb554099 63 #define HMC6352_MX_OFF_MSB 0x01
aberk 0:83c0cb554099 64 #define HMC6352_MX_OFF_LSB 0x02
aberk 0:83c0cb554099 65 #define HMC6352_MY_OFF_MSB 0x03
aberk 0:83c0cb554099 66 #define HMC6352_MY_OFF_LSB 0x04
aberk 0:83c0cb554099 67 #define HMC6352_TIME_DELAY 0x05
aberk 0:83c0cb554099 68 #define HMC6352_SUMMED 0x06
aberk 0:83c0cb554099 69 #define HMC6352_SOFT_VER 0x07
aberk 0:83c0cb554099 70 #define HMC6352_OPMODE 0x08
aberk 0:83c0cb554099 71
aberk 0:83c0cb554099 72 //RAM registers.
aberk 0:83c0cb554099 73 #define HMC6352_RAM_OPMODE 0x74
aberk 0:83c0cb554099 74 #define HMC6352_RAM_OUTPUT 0x4E
aberk 0:83c0cb554099 75
aberk 0:83c0cb554099 76 #define HMC6352_MX_OFFSET 0x00
aberk 0:83c0cb554099 77 #define HMC6352_MY_OFFSET 0x01
aberk 0:83c0cb554099 78
aberk 0:83c0cb554099 79 #define HMC6352_HEADING_MODE 0x00
aberk 0:83c0cb554099 80 #define HMC6352_RAWMAGX_MODE 0x01
aberk 0:83c0cb554099 81 #define HMC6352_RAWMAGY_MODE 0x02
aberk 0:83c0cb554099 82 #define HMC6352_MAGX_MODE 0x03
aberk 0:83c0cb554099 83 #define HMC6352_MAGY_MODE 0x04
aberk 0:83c0cb554099 84
aberk 0:83c0cb554099 85 //Operational mode register masks.
aberk 0:83c0cb554099 86 #define HMC6352_CM_MR_1HZ 0x00
aberk 0:83c0cb554099 87 #define HMC6352_CM_MR_5HZ 0x20
aberk 0:83c0cb554099 88 #define HMC6352_CM_MR_10HZ 0x40
aberk 0:83c0cb554099 89 #define HMC6352_CM_MR_20HZ 0x60
aberk 0:83c0cb554099 90
aberk 0:83c0cb554099 91 #define HMC6352_PERIODIC_SR 0x10
aberk 0:83c0cb554099 92
aberk 0:83c0cb554099 93 #define HMC6352_STANDBY 0x00
aberk 0:83c0cb554099 94 #define HMC6352_QUERY 0x01
aberk 0:83c0cb554099 95 #define HMC6352_CONTINUOUS 0x02
aberk 0:83c0cb554099 96
aberk 0:83c0cb554099 97 /**
aberk 0:83c0cb554099 98 * Honeywell HMC6352 digital compass.
aberk 0:83c0cb554099 99 */
aberk 0:83c0cb554099 100 class HMC6352 {
aberk 0:83c0cb554099 101
aberk 0:83c0cb554099 102 public:
aberk 0:83c0cb554099 103
aberk 0:83c0cb554099 104 /**
aberk 0:83c0cb554099 105 * Constructor.
aberk 0:83c0cb554099 106 *
aberk 0:83c0cb554099 107 * @param sda mbed pin to use for SDA line of I2C interface.
aberk 0:83c0cb554099 108 * @param scl mbed pin to use for SCL line of I2C interface.
aberk 0:83c0cb554099 109 */
aberk 0:83c0cb554099 110 HMC6352(PinName sda, PinName scl);
aberk 0:83c0cb554099 111
aberk 0:83c0cb554099 112 /**
aberk 0:83c0cb554099 113 * Sample the device and return the result.
aberk 0:83c0cb554099 114 *
aberk 0:83c0cb554099 115 * @return In heading output mode, the current heading as a number between
aberk 0:83c0cb554099 116 * 0-3599, representing 0-359.9 degrees.
aberk 0:83c0cb554099 117 * In raw magnetometer X output mode, the raw output of the X-axis
aberk 0:83c0cb554099 118 * magnetometer.
aberk 0:83c0cb554099 119 * In raw magnetometer Y mode, the raw output of the Y-axis
aberk 0:83c0cb554099 120 * magnetometer.
aberk 0:83c0cb554099 121 * In magnetometer X mode, the corrected output of the X-axis
aberk 0:83c0cb554099 122 * magnetometer.
aberk 0:83c0cb554099 123 * In magnetometer Y mode, the corrected output of the Y-axis
aberk 0:83c0cb554099 124 * magnetometer.
aberk 0:83c0cb554099 125 */
aberk 0:83c0cb554099 126 int sample(void);
aberk 0:83c0cb554099 127
aberk 0:83c0cb554099 128 /**
aberk 0:83c0cb554099 129 * Enter into or exit from sleep mode.
aberk 0:83c0cb554099 130 *
aberk 0:83c0cb554099 131 * @param enterOrExit 0x57 -> Exit sleep mode
aberk 0:83c0cb554099 132 * 0x53 -> Enter
aberk 0:83c0cb554099 133 */
aberk 0:83c0cb554099 134 void setSleepMode(int enterOrExit);
aberk 0:83c0cb554099 135
aberk 0:83c0cb554099 136 /**
aberk 0:83c0cb554099 137 * Update bridge offsets.
aberk 0:83c0cb554099 138 *
aberk 0:83c0cb554099 139 * Performs a set/reset immediately.
aberk 0:83c0cb554099 140 */
aberk 0:83c0cb554099 141 void setReset(void);
aberk 0:83c0cb554099 142
aberk 0:83c0cb554099 143 /**
aberk 0:83c0cb554099 144 * Enter into or exit from calibration mode.
aberk 0:83c0cb554099 145 *
aberk 0:83c0cb554099 146 * @param enterOrExit 0x45 -> Exit
aberk 0:83c0cb554099 147 * 0x43 -> Enter
aberk 0:83c0cb554099 148 */
aberk 0:83c0cb554099 149 void setCalibrationMode(int enterOrExit);
aberk 0:83c0cb554099 150
aberk 0:83c0cb554099 151 /**
aberk 0:83c0cb554099 152 * Save the current operation mode byte to EEPROM.
aberk 0:83c0cb554099 153 */
aberk 0:83c0cb554099 154 void saveOpMode(void);
aberk 0:83c0cb554099 155
aberk 0:83c0cb554099 156 /**
aberk 0:83c0cb554099 157 * Read the memory location on the device which contains the slave address.
aberk 0:83c0cb554099 158 *
aberk 0:83c0cb554099 159 * @return The slave address of the device.
aberk 0:83c0cb554099 160 */
aberk 0:83c0cb554099 161 int getSlaveAddress(void);
aberk 0:83c0cb554099 162
aberk 0:83c0cb554099 163 /**
aberk 0:83c0cb554099 164 * Read the current offset for X or Y axis magnetometer.
aberk 0:83c0cb554099 165 *
aberk 0:83c0cb554099 166 * @param axis 0x00 -> X-axis
aberk 0:83c0cb554099 167 * 0x01 -> Y-axis
aberk 0:83c0cb554099 168 * @return The current offset for the axis as a 16-bit number.
aberk 0:83c0cb554099 169 */
aberk 0:83c0cb554099 170 int getOffset(int axis);
aberk 0:83c0cb554099 171
aberk 0:83c0cb554099 172 /**
aberk 0:83c0cb554099 173 * Set the offset for X or Y axis magnetometer.
aberk 0:83c0cb554099 174 *
aberk 0:83c0cb554099 175 * @param axis 0x00 -> X-axis
aberk 0:83c0cb554099 176 * 0x01 -> Y-axis
aberk 0:83c0cb554099 177 * @param offset The offset to set for the axis (set to a 16-bit number).
aberk 0:83c0cb554099 178 */
aberk 0:83c0cb554099 179 void setOffset(int axis, int offset);
aberk 0:83c0cb554099 180
aberk 0:83c0cb554099 181 /**
aberk 0:83c0cb554099 182 * Get the current time delay.
aberk 0:83c0cb554099 183 *
aberk 0:83c0cb554099 184 * @return The time delay in milliseconds.
aberk 0:83c0cb554099 185 */
aberk 0:83c0cb554099 186 int getTimeDelay(void);
aberk 0:83c0cb554099 187
aberk 0:83c0cb554099 188 /**
aberk 0:83c0cb554099 189 * Set the time delay of the device.
aberk 0:83c0cb554099 190 *
aberk 0:83c0cb554099 191 * @param delay The time delay to set in milliseconds (between 0-255);
aberk 0:83c0cb554099 192 */
aberk 0:83c0cb554099 193 void setTimeDelay(int delay);
aberk 0:83c0cb554099 194
aberk 0:83c0cb554099 195 /**
aberk 0:83c0cb554099 196 * Get the number of measurements being summed each sample.
aberk 0:83c0cb554099 197 *
aberk 0:83c0cb554099 198 * @return The number of summed measurement.
aberk 0:83c0cb554099 199 */
aberk 0:83c0cb554099 200 int getSumNumber(void);
aberk 0:83c0cb554099 201
aberk 0:83c0cb554099 202 /**
aberk 0:83c0cb554099 203 * Set the number of measurements being summed each sample.
aberk 0:83c0cb554099 204 *
aberk 0:83c0cb554099 205 * @param sum The number of measurements to be summed (between 0-16);
aberk 0:83c0cb554099 206 */
aberk 0:83c0cb554099 207 void setSumNumber(int sum);
aberk 0:83c0cb554099 208
aberk 0:83c0cb554099 209 /**
aberk 0:83c0cb554099 210 * Get the software version on the device.
aberk 0:83c0cb554099 211 *
aberk 0:83c0cb554099 212 * @return The software version number.
aberk 0:83c0cb554099 213 */
aberk 0:83c0cb554099 214 int getSoftwareVersion(void);
aberk 0:83c0cb554099 215
aberk 0:83c0cb554099 216 /**
aberk 0:83c0cb554099 217 * Get the current operation mode.
aberk 0:83c0cb554099 218 *
aberk 0:83c0cb554099 219 * @return 0x00 -> Standby mode
aberk 0:83c0cb554099 220 * 0x01 -> Query mode
aberk 0:83c0cb554099 221 * 0x02 -> Continuous mode
aberk 0:83c0cb554099 222 */
aberk 0:83c0cb554099 223 int getOpMode(void);
aberk 0:83c0cb554099 224
aberk 0:83c0cb554099 225 /**
aberk 0:83c0cb554099 226 * Set the operation mode.
aberk 0:83c0cb554099 227 *
aberk 0:83c0cb554099 228 * @param mode 0x00 -> Standby mode
aberk 0:83c0cb554099 229 * 0x01 -> Query mode
aberk 0:83c0cb554099 230 * 0x02 -> Continuous mode
aberk 0:83c0cb554099 231 * @param periodicSetReset 0x00 -> No periodic set/reset
aberk 0:83c0cb554099 232 * 0x01 -> Periodic set/reset
aberk 0:83c0cb554099 233 * @measurementRate Measurement rate in Hz for continuous rate.
aberk 0:83c0cb554099 234 * Possible rates: {1, 5, 10, 20}Hz.
aberk 0:83c0cb554099 235 */
aberk 0:83c0cb554099 236 void setOpMode(int mode, int periodicSetReset, int measurementRate = 0);
aberk 0:83c0cb554099 237
aberk 0:83c0cb554099 238 /**
aberk 0:83c0cb554099 239 * Get the current output mode of the device.
aberk 0:83c0cb554099 240 *
aberk 0:83c0cb554099 241 * @return The current output mode.
aberk 0:83c0cb554099 242 */
aberk 0:83c0cb554099 243 int getOutputMode(void);
aberk 0:83c0cb554099 244
aberk 0:83c0cb554099 245 /**
aberk 0:83c0cb554099 246 * Set the output mode of the device.
aberk 0:83c0cb554099 247 *
aberk 0:83c0cb554099 248 * @param mode 0x00 -> Heading mode
aberk 0:83c0cb554099 249 * 0x01 -> Raw magnetometer X mode
aberk 0:83c0cb554099 250 * 0x02 -> Raw magnetometer Y mode
aberk 0:83c0cb554099 251 * 0x03 -> Magnetometer X mode
aberk 0:83c0cb554099 252 * 0x04 -> Magnetometer Y mode
aberk 0:83c0cb554099 253 */
aberk 0:83c0cb554099 254 void setOutputMode(int mode);
aberk 0:83c0cb554099 255
aberk 0:83c0cb554099 256 private:
aberk 0:83c0cb554099 257
aberk 0:83c0cb554099 258 I2C* i2c_;
aberk 0:83c0cb554099 259 int operationMode_;
aberk 0:83c0cb554099 260
aberk 0:83c0cb554099 261 /**
aberk 0:83c0cb554099 262 * Write to EEPROM or RAM on the device.
aberk 0:83c0cb554099 263 *
aberk 0:83c0cb554099 264 * @param EepromOrRam 0x77 -> Writing to EEPROM
aberk 0:83c0cb554099 265 * 0x47 -> Writing to RAM
aberk 0:83c0cb554099 266 * @param address Address to write to.
aberk 0:83c0cb554099 267 * @param data Data to write.
aberk 0:83c0cb554099 268 */
aberk 0:83c0cb554099 269 void write(int EepromOrRam, int address, int data);
aberk 0:83c0cb554099 270
aberk 0:83c0cb554099 271 /**
aberk 0:83c0cb554099 272 * Read EEPROM or RAM on the device.
aberk 0:83c0cb554099 273 *
aberk 0:83c0cb554099 274 * @param EepromOrRam 0x72 -> Reading from EEPROM
aberk 0:83c0cb554099 275 * 0x67 -> Reading from RAM
aberk 0:83c0cb554099 276 * @param address Address to read from.
aberk 0:83c0cb554099 277 * @return The contents of the memory address.
aberk 0:83c0cb554099 278 */
aberk 0:83c0cb554099 279 int read(int EepromOrRam, int address);
aberk 0:83c0cb554099 280
aberk 0:83c0cb554099 281 };
aberk 0:83c0cb554099 282
aberk 0:83c0cb554099 283 #endif /* HMC6352_H */