13static constexpr uint8_t BMM150_DEFAULT_I2C_ADDRESS = 0x10;
14static constexpr uint8_t BMM150_REG_CHIP_ID = 0x40;
15static constexpr uint8_t BMM150_REG_DATA_X_LSB = 0x42;
16static constexpr uint8_t BMM150_REG_POWER_CONTROL = 0x4B;
17static constexpr uint8_t BMM150_REG_OP_MODE = 0x4C;
18static constexpr uint8_t BMM150_CHIP_ID_VALUE = 0x32;
19static constexpr uint8_t BMM150_CMD_POWER_ON = 0x01;
20static constexpr uint8_t BMM150_CMD_SOFT_RESET = 0x83;
21static constexpr uint8_t BMM150_CMD_NORMAL_MODE_ODR_30HZ = 0x38;
22static constexpr uint32_t BMM150_START_UP_TIME_MS = 3;
23static constexpr uint32_t BMM150_SOFT_RESET_TIME_MS = 1;
26static constexpr uint8_t BMM150_REG_TRIM_START = 0x5D;
27static constexpr uint8_t BMM150_TRIM_BLOCK_LEN = 8;
28static constexpr uint8_t BMM150_TRIM_BLOCKS = 3;
29static constexpr uint8_t BMM150_TRIM_X1 = 0x5D;
30static constexpr uint8_t BMM150_TRIM_Y1 = 0x5E;
31static constexpr uint8_t BMM150_TRIM_Z4 = 0x62;
32static constexpr uint8_t BMM150_TRIM_X2 = 0x64;
33static constexpr uint8_t BMM150_TRIM_Y2 = 0x65;
34static constexpr uint8_t BMM150_TRIM_Z2 = 0x68;
35static constexpr uint8_t BMM150_TRIM_Z1 = 0x6A;
36static constexpr uint8_t BMM150_TRIM_XYZ1 = 0x6C;
37static constexpr uint8_t BMM150_TRIM_Z3 = 0x6E;
38static constexpr uint8_t BMM150_TRIM_XY2 = 0x70;
39static constexpr uint8_t BMM150_TRIM_XY1 = 0x71;
40static constexpr uint16_t BMM150_TRIM_XYZ1_MASK = 0x7FFF;
43static constexpr int16_t BMM150_XY_OVERFLOW_ADCVAL = -4096;
44static constexpr int16_t BMM150_Z_OVERFLOW_ADCVAL = -16384;
63 const uint8_t offset = reg - BMM150_REG_TRIM_START;
70 trim.
x1 =
static_cast<int8_t
>(regs[BMM150_TRIM_X1 - BMM150_REG_TRIM_START]);
71 trim.
y1 =
static_cast<int8_t
>(regs[BMM150_TRIM_Y1 - BMM150_REG_TRIM_START]);
73 trim.
x2 =
static_cast<int8_t
>(regs[BMM150_TRIM_X2 - BMM150_REG_TRIM_START]);
74 trim.
y2 =
static_cast<int8_t
>(regs[BMM150_TRIM_Y2 - BMM150_REG_TRIM_START]);
79 trim.
xy2 =
static_cast<int8_t
>(regs[BMM150_TRIM_XY2 - BMM150_REG_TRIM_START]);
80 trim.
xy1 = regs[BMM150_TRIM_XY1 - BMM150_REG_TRIM_START];
86 if (
raw == BMM150_XY_OVERFLOW_ADCVAL || rhall == 0 || trim.
xyz1 == 0)
88 float retval = (float) trim.
xyz1 * 16384.0f / (
float) rhall - 16384.0f;
89 float comp1 = (float) trim.
xy2 * (retval * retval / 268435456.0f);
90 float comp2 = comp1 + retval * (float) trim.
xy1 / 16384.0f;
91 float comp3 = (float) trim_b + 160.0f;
92 float comp4 = (float)
raw * ((comp2 + 256.0f) * comp3);
93 return ((comp4 / 8192.0f) + (
float) trim_a * 8.0f) / 16.0f;
98 if (
raw == BMM150_Z_OVERFLOW_ADCVAL || trim.
z2 == 0 || trim.
z1 == 0 || trim.
xyz1 == 0 || rhall == 0)
100 float comp0 = (float)
raw - (
float) trim.
z4;
101 float comp1 = (float) rhall - (
float) trim.
xyz1;
102 float comp2 = (float) trim.
z3 * comp1;
103 float comp3 = (float) trim.
z1 * (
float) rhall / 32768.0f;
104 float comp4 = (float) trim.
z2 + comp3;
105 float comp5 = comp0 * 131072.0f - comp2;
106 return (comp5 / (comp4 * 4.0f)) / 16.0f;
112 int16_t
x = (int16_t) (((int16_t) (int8_t)
raw[1] * 32) | (
raw[0] >> 3));
113 int16_t
y = (int16_t) (((int16_t) (int8_t)
raw[3] * 32) | (
raw[2] >> 3));
114 int16_t
z = (int16_t) (((int16_t) (int8_t)
raw[5] * 128) | (
raw[4] >> 1));
115 uint16_t rhall = (uint16_t) (((uint16_t)
raw[7] << 6) | (
raw[6] >> 2));