|
| 1 | +// I2Cdev library collection - QMC5883L I2C device class header file |
| 2 | +// Based on QST QMC5883L datasheet 1.0, 02/2016 |
| 3 | +/* ============================================ |
| 4 | +I2Cdev device library code is placed under the MIT license |
| 5 | +Copyright (c) 2011 Jeff Rowberg |
| 6 | +
|
| 7 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +of this software and associated documentation files (the "Software"), to deal |
| 9 | +in the Software without restriction, including without limitation the rights |
| 10 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +copies of the Software, and to permit persons to whom the Software is |
| 12 | +furnished to do so, subject to the following conditions: |
| 13 | +
|
| 14 | +The above copyright notice and this permission notice shall be included in |
| 15 | +all copies or substantial portions of the Software. |
| 16 | +
|
| 17 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | +THE SOFTWARE. |
| 24 | +=============================================== |
| 25 | +*/ |
| 26 | + |
| 27 | +#ifndef _QMC5883L_H_ |
| 28 | +#define _QMC5883L_H_ |
| 29 | + |
| 30 | +#include <stdint.h> |
| 31 | +#include <stdbool.h> |
| 32 | + |
| 33 | +#define QMC5883L_DEFAULT_ADDR 0x0D |
| 34 | + |
| 35 | +/* register addresses */ |
| 36 | +#define QMC5883L_REG_DATA_X_LSB 0x00 |
| 37 | +#define QMC5883L_REG_DATA_X_MSB 0x01 |
| 38 | +#define QMC5883L_REG_DATA_Y_LSB 0x02 |
| 39 | +#define QMC5883L_REG_DATA_Y_MSB 0x03 |
| 40 | +#define QMC5883L_REG_DATA_Z_LSB 0x04 |
| 41 | +#define QMC5883L_REG_DATA_Z_MSB 0x05 |
| 42 | +#define QMC5883L_REG_STATUS 0x06 |
| 43 | +#define QMC5883L_REG_TEMP_LSB 0x07 |
| 44 | +#define QMC5883L_REG_TEMP_MSB 0x08 |
| 45 | +#define QMC5883L_REG_CTRL_1 0x09 |
| 46 | +#define QMC5883L_REG_CTRL_2 0x0A |
| 47 | +#define QMC5883L_REG_SR_PERIOD 0x0B |
| 48 | + |
| 49 | +/* values for control_1 register */ |
| 50 | +#define QMC5883L_OVERSAMPLE_512 0b00 |
| 51 | +#define QMC5883L_OVERSAMPLE_256 0b01 |
| 52 | +#define QMC5883L_OVERSAMPLE_128 0b10 |
| 53 | +#define QMC5883L_OVERSAMPLE_64 0b11 |
| 54 | + |
| 55 | +#define QMC5883L_SCALE_2G 0b00 |
| 56 | +#define QMC5883L_SCALE_8G 0b01 |
| 57 | + |
| 58 | +#define QMC5883L_OUTPUT_RATE_10HZ 0b00 |
| 59 | +#define QMC5883L_OUTPUT_RATE_50HZ 0b01 |
| 60 | +#define QMC5883L_OUTPUT_RATE_100HZ 0b10 |
| 61 | +#define QMC5883L_OUTPUT_RATE_200HZ 0b11 |
| 62 | + |
| 63 | +#define QMC5883L_MODE_STBY 0b00 |
| 64 | +#define QMC5883L_MODE_CONT 0b01 |
| 65 | + |
| 66 | +#define QMC5883L_CTRL1_VALUE(_mode_, _output_rate_, _scale_, _oversample_) \ |
| 67 | + ((_mode_) | ((_output_rate_) << 2) | ((_scale_) << 4) | ((_oversample_) << 6)) |
| 68 | + |
| 69 | +/* QMC5883L_soft_reset: does a soft reset */ |
| 70 | +bool QMC5883L_soft_reset(); |
| 71 | + |
| 72 | +/* QMC5883L_fbr_set: SET/RESET Period FBR; recommended value: 1 */ |
| 73 | +bool QMC5883L_fbr_set(uint8_t fbr); |
| 74 | + |
| 75 | +/* QMC5883L_control_1_set: set value for control register (mode, output rate, scale, oversampling) */ |
| 76 | +bool QMC5883L_control_1_set(uint8_t value); |
| 77 | + |
| 78 | +bool QMC5883L_statusGet(uint8_t *data); |
| 79 | + |
| 80 | +/* QMC5883L_magGet: |
| 81 | + * parameters: |
| 82 | + * v_mag: int16_t array of length 3 |
| 83 | + * returns: |
| 84 | + * success: true |
| 85 | + * failure: false |
| 86 | + */ |
| 87 | +bool QMC5883L_magGet(int16_t *v_mag); |
| 88 | + |
| 89 | +bool QMC5883L_tempGet(int16_t *temp); |
| 90 | + |
| 91 | +#endif |
0 commit comments