27 #include <mraa/i2c.hpp>
28 #include <mraa/spi.hpp>
29 #include <mraa/gpio.hpp>
31 #define BMM150_I2C_BUS 0
32 #define BMM150_SPI_BUS 0
33 #define BMM150_DEFAULT_ADDR 0x10
82 typedef enum : uint8_t {
97 REG_INT_STATUS = 0x4a,
99 REG_POWER_CTRL = 0x4b,
104 REG_INT_CONFIG = 0x4e,
106 REG_LOW_THRES = 0x4f,
107 REG_HIGH_THRES = 0x50,
115 REG_TRIM_DIG_X1 = 0x5d,
116 REG_TRIM_DIG_Y1 = 0x5e,
118 REG_TRIM_DIG_Z4_LSB = 0x62,
119 REG_TRIM_DIG_Z4_MSB = 0x63,
120 REG_TRIM_DIG_X2 = 0x64,
121 REG_TRIM_DIG_Y2 = 0x65,
123 REG_TRIM_DIG_Z2_LSB = 0x68,
124 REG_TRIM_DIG_Z2_MSB = 0x69,
125 REG_TRIM_DIG_Z1_LSB = 0x6a,
126 REG_TRIM_DIG_Z1_MSB = 0x6b,
127 REG_TRIM_DIG_XYZ1_LSB = 0x6c,
128 REG_TRIM_DIG_XYZ1_MSB = 0x6d,
129 REG_TRIM_DIG_Z3_LSB = 0x6e,
130 REG_TRIM_DIG_Z3_MSB = 0x6f,
131 REG_TRIM_DIG_XY2 = 0x70,
132 REG_TRIM_DIG_XY1 = 0x71
140 _MAG_XY_LSB_RESERVED_BITS = 0x02 | 0x04,
142 MAG_XY_LSB_SELFTEST_XY = 0x01,
144 MAG_XY_LSB_LSB0 = 0x08,
145 MAG_XY_LSB_LSB1 = 0x10,
146 MAG_XY_LSB_LSB2 = 0x20,
147 MAG_XY_LSB_LSB3 = 0x40,
148 MAG_XY_LSB_LSB4 = 0x80,
149 _MAG_XY_LSB_LSB_MASK = 31,
150 _MAG_XY_LSB_LSB_SHIFT = 3
157 MAG_Z_LSB_SELFTEST_Z = 0x01,
159 MAG_Z_LSB_LSB0 = 0x02,
160 MAG_Z_LSB_LSB1 = 0x04,
161 MAG_Z_LSB_LSB2 = 0x08,
162 MAG_Z_LSB_LSB3 = 0x10,
163 MAG_Z_LSB_LSB4 = 0x20,
164 MAG_Z_LSB_LSB5 = 0x40,
165 MAG_Z_LSB_LSB6 = 0x80,
166 _MAG_Z_LSB_LSB_MASK = 127,
167 _MAG_Z_LSB_LSB_SHIFT = 1
174 _MAG_RHALL_LSB_RESERVED_BITS = 0x02,
176 MAG_RHALL_LSB_DATA_READY_STATUS = 0x01,
178 MAG_RHALL_LSB_LSB0 = 0x04,
179 MAG_RHALL_LSB_LSB1 = 0x08,
180 MAG_RHALL_LSB_LSB2 = 0x10,
181 MAG_RHALL_LSB_LSB3 = 0x20,
182 MAG_RHALL_LSB_LSB4 = 0x40,
183 MAG_RHALL_LSB_LSB5 = 0x80,
184 _MAG_RHALL_LSB_LSB_MASK = 63,
185 _MAG_RHALL_LSB_LSB_SHIFT = 2
192 INT_STATUS_LOW_INT_X = 0x01,
193 INT_STATUS_LOW_INT_Y = 0x02,
194 INT_STATUS_LOW_INT_Z = 0x04,
195 INT_STATUS_HIGH_INT_X = 0x08,
196 INT_STATUS_HIGH_INT_Y = 0x10,
197 INT_STATUS_HIGH_INT_Z = 0x20,
198 INT_STATUS_OVERFLOW = 0x40,
199 INT_STATUS_DATA_OVERRUN = 0x80
206 _POWER_CTRL_RESERVED_BITS = 0x40 | 0x20 | 0x10 | 0x08,
208 POWER_CTRL_POWER_CTRL_BIT = 0x01,
209 POWER_CTRL_SOFT_RESET0 = 0x02,
210 POWER_CTRL_SPI3EN = 0x04,
212 POWER_CTRL_SOFT_RESET1 = 0x80
219 OPMODE_SELFTTEST = 0x01,
221 OPMODE_OPERATION_MODE0 = 0x02,
222 OPMODE_OPERATION_MODE1 = 0x04,
223 _OPMODE_OPERATION_MODE_MASK = 3,
224 _OPMODE_OPERATION_MODE_SHIFT = 1,
226 OPMODE_DATA_RATE0 = 0x08,
227 OPMODE_DATA_RATE1 = 0x10,
228 OPMODE_DATA_RATE2 = 0x20,
229 _OPMODE_DATA_RATE_MASK = 7,
230 _OPMODE_DATA_RATE_SHIFT = 3,
232 OPMODE_ADV_SELFTEST0 = 0x40,
233 OPMODE_ADV_SELFTEST1 = 0x80,
234 _OPMODE_ADV_SELFTEST_MASK = 3,
235 _OPMODE_ADV_SELFTEST_SHIFT = 6
242 OPERATION_MODE_NORMAL = 0,
243 OPERATION_MODE_FORCED = 1,
244 OPERATION_MODE_SLEEP = 3
265 INT_EN_LOW_INT_X_EN = 0x01,
266 INT_EN_LOW_INT_Y_EN = 0x02,
267 INT_EN_LOW_INT_Z_EN = 0x04,
268 INT_EN_HIGH_INT_X_EN = 0x08,
269 INT_EN_HIGH_INT_Y_EN = 0x10,
270 INT_EN_HIGH_INT_Z_EN = 0x20,
271 INT_EN_OVERFLOW_INT_EN = 0x40,
272 INT_EN_DATA_OVERRUN_INT_EN = 0x80
279 INT_CONFIG_INT_POLARITY = 0x01,
280 INT_CONFIG_INT_LATCH = 0x02,
281 INT_CONFIG_DR_POLARITY = 0x04,
282 INT_CONFIG_CHANNEL_X = 0x08,
283 INT_CONFIG_CHANNEL_Y = 0x10,
284 INT_CONFIG_CHANNEL_Z = 0x20,
285 INT_CONFIG_INT_PIN_EN = 0x40,
286 INT_CONFIG_DR_PIN_EN = 0x80
303 USAGE_ENHANCED_REGULAR,
323 BMM150(
int bus=BMM150_I2C_BUS,
int addr=BMM150_DEFAULT_ADDR,
498 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
515 void (*isr)(
void *),
void *arg);
541 int readRegs(uint8_t reg, uint8_t *buffer,
int len);
549 void writeReg(uint8_t reg, uint8_t val);
556 mraa::Gpio *m_gpioCS;
558 mraa::Gpio *m_gpioIntr;
559 mraa::Gpio *m_gpioDR;
604 #if defined(SWIGJAVA) || defined(JAVACALLBACK)
606 void (*isr)(
void *),
void *arg);
610 float bmm050_compensate_X_float(int16_t mag_data_x, uint16_t data_r);
611 float bmm050_compensate_Y_float(int16_t mag_data_y, uint16_t data_r);
612 float bmm050_compensate_Z_float(int16_t mag_data_z, uint16_t data_r);
uint8_t getChipID()
Definition: bmm150.cxx:361
OPERATION_MODE_T getOpmode()
Definition: bmm150.cxx:432
uint8_t getInterruptEnable()
Definition: bmm150.cxx:442
void setPowerBit(bool power)
Definition: bmm150.cxx:408
BMM150_REGS_T
Definition: bmm150.hpp:82
void setOutputDataRate(DATA_RATE_T odr)
Definition: bmm150.cxx:398
DATA_RATE_T
Definition: bmm150.hpp:250
void writeReg(uint8_t reg, uint8_t val)
Definition: bmm150.cxx:321
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bmm150.cxx:287
void reset()
Definition: bmm150.cxx:386
void setOpmode(OPERATION_MODE_T opmode)
Definition: bmm150.cxx:421
API for the BMM150 3-Axis Geomagnetic Sensor.
Definition: bmm150.hpp:71
OPERATION_MODE_T
Definition: bmm150.hpp:241
float * getMagnetometer()
Definition: bmm150.cxx:378
MAG_Z_LSB_BITS_T
Definition: bmm150.hpp:156
~BMM150()
Definition: bmm150.cxx:182
INT_STATUS_BITS_T
Definition: bmm150.hpp:191
BMM150(int bus=BMM150_I2C_BUS, int addr=BMM150_DEFAULT_ADDR, int cs=-1)
Definition: bmm150.cxx:95
void setRepetitionsXY(uint8_t reps)
Definition: bmm150.cxx:496
void setRepetitionsZ(uint8_t reps)
Definition: bmm150.cxx:501
void init(USAGE_PRESETS_T usage=USAGE_HIGH_ACCURACY)
Definition: bmm150.cxx:195
POWER_CTRL_BITS_T
Definition: bmm150.hpp:205
INT_EN_T
Definition: bmm150.hpp:264
void setInterruptConfig(uint8_t bits)
Definition: bmm150.cxx:457
void uninstallISR(INTERRUPT_PINS_T intr)
Definition: bmm150.cxx:574
uint8_t getInterruptConfig()
Definition: bmm150.cxx:452
MAG_XY_LSB_BITS_T
Definition: bmm150.hpp:139
void setPresetMode(USAGE_PRESETS_T usage)
Definition: bmm150.cxx:506
USAGE_PRESETS_T
Definition: bmm150.hpp:300
void setInterruptEnable(uint8_t bits)
Definition: bmm150.cxx:447
uint8_t getInterruptStatus()
Definition: bmm150.cxx:462
MAG_RHALL_LSB_BITS_T
Definition: bmm150.hpp:173
INTERRUPT_PINS_T
Definition: bmm150.hpp:292
OPMODE_BITS_T
Definition: bmm150.hpp:218
INT_CONFIG_T
Definition: bmm150.hpp:278
uint8_t readReg(uint8_t reg)
Definition: bmm150.cxx:265
void installISR(INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)
Definition: bmm150.cxx:560
void update()
Definition: bmm150.cxx:208