upm
1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
|
API for the BMM150 3-Axis Geomagnetic Sensor. More...
The BMM150 is a standalone geomagnetic sensor for consumer market applications. It allows measurements of the magnetic field in three perpendicular axes. Based on Bosch's proprietary FlipCore technology, performance and features of BMM150 are carefully tuned and perfectly match the demanding requirements of all 3-axis mobile applications such as electronic compass, navigation or augmented reality.
An evaluation circuitry (ASIC) converts the output of the geomagnetic sensor to digital results which can be read out over the industry standard digital interfaces (SPI and I2C).
Not all functionality of this chip has been implemented in this driver, however all the pieces are present to add any desired functionality. This driver supports both I2C (default) and SPI operation.
This device requires 3.3v operation.
Public Member Functions | |
BMM150 (int bus=BMM150_DEFAULT_I2C_BUS, int addr=BMM150_DEFAULT_ADDR, int cs=-1) | |
~BMM150 () | |
void | update () |
uint8_t | getChipID () |
void | getMagnetometer (float *x, float *y, float *z) |
std::vector< float > | getMagnetometer () |
void | init (BMM150_USAGE_PRESETS_T usage=BMM150_USAGE_HIGH_ACCURACY) |
void | setPresetMode (BMM150_USAGE_PRESETS_T usage) |
void | reset () |
void | setOutputDataRate (BMM150_DATA_RATE_T odr) |
void | setPowerBit (bool power) |
void | setOpmode (BMM150_OPERATION_MODE_T opmode) |
BMM150_OPERATION_MODE_T | getOpmode () |
uint8_t | getInterruptEnable () |
void | setInterruptEnable (uint8_t bits) |
uint8_t | getInterruptConfig () |
void | setInterruptConfig (uint8_t bits) |
uint8_t | getInterruptStatus () |
void | setRepetitionsXY (uint8_t reps) |
void | setRepetitionsZ (uint8_t reps) |
void | installISR (BMM150_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg) |
void | uninstallISR (BMM150_INTERRUPT_PINS_T intr) |
uint8_t | readReg (uint8_t reg) |
int | readRegs (uint8_t reg, uint8_t *buffer, int len) |
void | writeReg (uint8_t reg, uint8_t val) |
Protected Attributes | |
bmm150_context | m_bmm150 |
BMM150 | ( | int | bus = BMM150_DEFAULT_I2C_BUS , |
int | addr = BMM150_DEFAULT_ADDR , |
||
int | cs = -1 |
||
) |
BMM150 constructor.
This device can support both I2C and SPI. For SPI, set the addr to -1, and specify a positive integer representing the Chip Select (CS) pin for the cs argument. If you are using a hardware CS pin (like edison with arduino breakout), then you can connect the proper pin to the hardware CS pin on your MCU and supply -1 for cs. The default operating mode is I2C.
bus | I2C or SPI bus to use. |
addr | The address for this device. -1 for SPI. |
cs | The gpio pin to use for the SPI Chip Select. -1 for I2C or for SPI with a hardware controlled pin. |
std::runtime_error | on failure. |
void update | ( | void | ) |
Update the internal stored values from sensor data.
std::runtime_error | on failure. |
uint8_t getChipID | ( | ) |
Return the chip ID.
void getMagnetometer | ( | float * | x, |
float * | y, | ||
float * | z | ||
) |
Return magnetometer data in micro-Teslas (uT). update() must have been called prior to calling this method.
x | Pointer to a floating point value that will have the current x component placed into it. |
y | Pointer to a floating point value that will have the current y component placed into it. |
z | Pointer to a floating point value that will have the current z component placed into it. |
std::vector< float > getMagnetometer | ( | ) |
Return magnetometer data in micro-Teslas (uT) in the form of a floating point vector. update() must have been called prior to calling this method.
void init | ( | BMM150_USAGE_PRESETS_T | usage = BMM150_USAGE_HIGH_ACCURACY | ) |
Initialize the device and start operation. This function is called from the constructor so will not typically need to be called by a user unless the device is reset. This method will call setPresetMode() with the passed parameter.
usage | One of the BMM150_USAGE_PRESETS_T values. The default is BMM150_USAGE_HIGH_ACCURACY. |
std::runtime_error | on failure. |
void setPresetMode | ( | BMM150_USAGE_PRESETS_T | usage | ) |
Set one of the Bosch recommended preset modes. These modes configure the sensor for varying use cases.
usage | One of the BMM150_USAGE_PRESETS_T values. The default is BMM150_USAGE_HIGH_ACCURACY. |
std::runtime_error | on failure. |
void reset | ( | ) |
Perform a device soft-reset. The device will be placed in SUSPEND mode afterward with all configured setting lost, so some re-initialization will be required to get data from the sensor. Calling init() will get everything running again.
std::runtime_error | on failure. |
void setOutputDataRate | ( | BMM150_DATA_RATE_T | odr | ) |
Set the magnetometer Output Data Rate. See the datasheet for details.
odr | One of the BMM150_DATA_RATE_T values. |
std::runtime_error | on failure. |
void setPowerBit | ( | bool | power | ) |
Set or clear the Power bit. When the power bit is cleared, the device enters a deep suspend mode where only the REG_POWER_CTRL register can be accessed. This bit needs to be enabled for the device to operate. See the datasheet for details. The constructor enables this by default. After a deep suspend mode has been entered, all configured data is lost and the device must be reconfigured (as via init()).
power | true to enable the bit, false otherwise. |
std::runtime_error | on failure. |
void setOpmode | ( | BMM150_OPERATION_MODE_T | opmode | ) |
Set the operating mode of the device. See the datasheet for details.
opmode | One of the BMM150_OPERATION_MODE_T values. |
std::runtime_error | on failure. |
BMM150_OPERATION_MODE_T getOpmode | ( | ) |
Get the current operating mode of the device. See the datasheet for details. The power bit must be one for this method to succeed.
uint8_t getInterruptEnable | ( | ) |
Return the Interrupt Enables register. This register allows you to enable various interrupt conditions. See the datasheet for details.
void setInterruptEnable | ( | uint8_t | bits | ) |
Set the Interrupt Enables register. See the datasheet for details.
bits | A bitmask of BMM150_INT_EN_BITS_T bits. |
std::runtime_error | on failure. |
uint8_t getInterruptConfig | ( | ) |
Return the Interrupt Config register. This register allows determining the electrical characteristics of the 2 interrupt pins (open-drain/push-pull and level/edge triggering) as well as other options. See the datasheet for details.
void setInterruptConfig | ( | uint8_t | bits | ) |
Set the Interrupt Config register. This register allows determining the electrical characteristics of the 2 interrupt pins (open-drain/push-pull and level/edge triggering). See the datasheet for details.
bits | A bitmask of BMM150_INT_CONFIG_BITS_T bits. |
std::runtime_error | on failure. |
uint8_t getInterruptStatus | ( | ) |
Return the interrupt status register. This register indicates which interrupts have been triggered. See the datasheet for details.
void setRepetitionsXY | ( | uint8_t | reps | ) |
Set the repetition counter for the X and Y axes. This allows the device to average a number of measurements for a more stable output. See the datasheet for details.
reps | A coefficient for specifying the number of repititions to perform. (1 + 2(reps)) |
std::runtime_error | on failure. |
void setRepetitionsZ | ( | uint8_t | reps | ) |
Set the repetition counter for the Z axis. This allows the device to average a number of measurements for a more stable output. See the datasheet for details.
reps | A coefficient for specifying the number of repititions to perform. (1 + (reps)) |
std::runtime_error | on failure. |
void installISR | ( | BMM150_INTERRUPT_PINS_T | intr, |
int | gpio, | ||
mraa::Edge | level, | ||
void(*)(void *) | isr, | ||
void * | arg | ||
) |
Install an interrupt handler.
intr | One of the BMM150_INTERRUPT_PINS_T values specifying which interrupt pin you are installing. |
gpio | GPIO pin to use as interrupt pin. |
level | The interrupt trigger level (one of mraa::Edge values). Make sure that you have configured the interrupt pin properly for whatever level you choose. |
isr | The interrupt handler, accepting a void * argument. |
arg | The argument to pass the the interrupt handler. |
std::runtime_error | on failure. |
void uninstallISR | ( | BMM150_INTERRUPT_PINS_T | intr | ) |
Uninstall a previously installed interrupt handler.
intr | One of the BMM150_INTERRUPT_PINS_T values specifying which interrupt pin you are removing. |
uint8_t readReg | ( | uint8_t | reg | ) |
Read a register.
reg | The register to read. |
int readRegs | ( | uint8_t | reg, |
uint8_t * | buffer, | ||
int | len | ||
) |
Read contiguous registers into a buffer.
buffer | The buffer to store the results. |
len | The number of registers to read. |
std::runtime_error | on failure. |
void writeReg | ( | uint8_t | reg, |
uint8_t | val | ||
) |
Write to a register.
reg | The register to write to. |
val | The value to write. |
std::runtime_error | on failure. |