upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for bmm150.h:

API Description

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 Intel Corporation.
*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include "upm_utilities.h"
#include "bmm150.h"
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
#if defined(CONFIG_BOARD_ARDUINO_101_SSS)
// ARDUINO_101_SSS (ARC core) must use I2C
// Instantiate a BMM150 instance using default i2c bus and address
bmm150_context sensor = bmm150_init(BMM150_DEFAULT_I2C_BUS,
BMM150_DEFAULT_ADDR, -1);
#elif defined(CONFIG_BOARD_ARDUINO_101)
// ARDUINO_101 (Quark core) where you must use SPI
// Instantiate a BMM150 instance using default SPI bus and pin 10 as CS
bmm150_context sensor = bmm150_init(BMM150_DEFAULT_SPI_BUS,
-1, 10);
#else
// everything else use I2C by default
// Instantiate a BMM150 instance using default i2c bus and address
bmm150_context sensor = bmm150_init(BMM150_DEFAULT_I2C_BUS,
BMM150_DEFAULT_ADDR, -1);
#endif
if (!sensor)
{
printf("bmm150_init() failed.\n");
return 1;
}
// now output data every 250 milliseconds
while (shouldRun)
{
float x, y, z;
if (bmm150_update(sensor))
{
printf("bmm150_update() failed\n");
return 1;
}
bmm150_get_magnetometer(sensor, &x, &y, &z);
printf("Magnetometer x: %f y: %f z: %f uT\n",
x, y, z);
upm_delay_ms(250);
}
printf("Exiting...\n");
bmm150_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _bmm150_context
 

Functions

bmm150_context bmm150_init (int bus, int addr, int cs)
 
void bmm150_close (bmm150_context dev)
 
upm_result_t bmm150_update (const bmm150_context dev)
 
uint8_t bmm150_get_chip_id (const bmm150_context dev)
 
void bmm150_get_magnetometer (const bmm150_context dev, float *x, float *y, float *z)
 
upm_result_t bmm150_devinit (const bmm150_context dev, BMM150_USAGE_PRESETS_T usage)
 
upm_result_t bmm150_set_preset_mode (const bmm150_context dev, BMM150_USAGE_PRESETS_T usage)
 
upm_result_t bmm150_reset (const bmm150_context dev)
 
upm_result_t bmm150_set_output_data_rate (const bmm150_context dev, BMM150_DATA_RATE_T odr)
 
upm_result_t bmm150_set_power_bit (const bmm150_context dev, bool power)
 
upm_result_t bmm150_set_opmode (const bmm150_context dev, BMM150_OPERATION_MODE_T opmode)
 
BMM150_OPERATION_MODE_T bmm150_get_opmode (const bmm150_context dev)
 
uint8_t bmm150_get_interrupt_enable (const bmm150_context dev)
 
upm_result_t bmm150_set_interrupt_enable (const bmm150_context dev, uint8_t bits)
 
uint8_t bmm150_get_interrupt_config (const bmm150_context dev)
 
upm_result_t bmm150_set_interrupt_config (const bmm150_context dev, uint8_t bits)
 
uint8_t bmm150_get_interrupt_status (const bmm150_context dev)
 
upm_result_t bmm150_set_repetitions_xy (const bmm150_context dev, uint8_t reps)
 
upm_result_t bmm150_set_repetitions_z (const bmm150_context dev, uint8_t reps)
 
upm_result_t bmm150_install_isr (const bmm150_context dev, BMM150_INTERRUPT_PINS_T intr, int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
 
void bmm150_uninstall_isr (const bmm150_context dev, BMM150_INTERRUPT_PINS_T intr)
 
uint8_t bmm150_read_reg (const bmm150_context dev, uint8_t reg)
 
int bmm150_read_regs (const bmm150_context dev, uint8_t reg, uint8_t *buffer, int len)
 
upm_result_t bmm150_write_reg (const bmm150_context dev, uint8_t reg, uint8_t val)
 

Typedefs

typedef struct _bmm150_contextbmm150_context
 

Function Documentation

bmm150_context bmm150_init ( int  bus,
int  addr,
int  cs 
)

BMM150 initialization.

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.

Parameters
busI2C or SPI bus to use.
addrThe address for this device, or -1 for SPI.
csThe gpio pin to use for the SPI Chip Select. Use -1 for I2C or for SPI with a hardware controlled pin.
Returns
The device context, or NULL if an error occurred.

Here is the call graph for this function:

void bmm150_close ( bmm150_context  dev)

BMM150 Destructor.

Parameters
devThe device context.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_update ( const bmm150_context  dev)

Update the internal stored values from sensor data.

Parameters
devThe device context.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t bmm150_get_chip_id ( const bmm150_context  dev)

Return the chip ID.

Parameters
devThe device context.
Returns
The chip ID.

Here is the call graph for this function:

Here is the caller graph for this function:

void bmm150_get_magnetometer ( const bmm150_context  dev,
float *  x,
float *  y,
float *  z 
)

Return magnetometer data in micro-Teslas (uT). update() must have been called prior to calling this method.

Parameters
devThe device context.
xPointer to a floating point value that will have the current x component placed into it.
yPointer to a floating point value that will have the current y component placed into it.
zPointer to a floating point value that will have the current z component placed into it.

Here is the caller graph for this function:

upm_result_t bmm150_devinit ( const bmm150_context  dev,
BMM150_USAGE_PRESETS_T  usage 
)

Initialize the device and start operation. This function is called from the constructor so it will not typically need to be called by a user unless the device is reset. This method will call bmm150_set_preset_mode() with the passed parameter.

Parameters
devThe device context.
usageOne of the BMM150_USAGE_PRESETS_T values. The default is BMM150_USAGE_HIGH_ACCURACY.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_set_preset_mode ( const bmm150_context  dev,
BMM150_USAGE_PRESETS_T  usage 
)

Set one of the Bosch recommended preset modes. These modes configure the sensor for varying use cases.

Parameters
devThe device context.
usageOne of the BMM150_USAGE_PRESETS_T values. The default set at initilaization time is BMM150_USAGE_HIGH_ACCURACY.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_reset ( const bmm150_context  dev)

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 bmm150_devinit() will get everything running again.

Parameters
devThe device context.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_set_output_data_rate ( const bmm150_context  dev,
BMM150_DATA_RATE_T  odr 
)

Set the magnetometer Output Data Rate. See the datasheet for details.

Parameters
devThe device context.
odrOne of the BMM150_DATA_RATE_T values.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_set_power_bit ( const bmm150_context  dev,
bool  power 
)

Set or clear the Power bit. When the power bit is cleared, the device enters a deep suspend mode where only the BMM150_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 bmm150_devinit()).

Parameters
devThe device context.
powerTrue to enable the bit, false otherwise.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_set_opmode ( const bmm150_context  dev,
BMM150_OPERATION_MODE_T  opmode 
)

Set the operating mode of the device. See the datasheet for details.

Parameters
devThe device context.
powerOne of the BMM150_POWER_MODE_T values.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

BMM150_OPERATION_MODE_T bmm150_get_opmode ( const bmm150_context  dev)

Get the current operating mode of the device. See the datasheet for details. The power bit must be one for this method to succeed.

Parameters
devThe device context.
Returns
One of the BMM150_OPERATION_MODE_T values.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t bmm150_get_interrupt_enable ( const bmm150_context  dev)

Return the Interrupt Enables register. This register allows you to enable various interrupt conditions. See the datasheet for details.

Parameters
devThe device context.
Returns
A bitmask of BMM150_INT_EN_BITS_T bits.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_set_interrupt_enable ( const bmm150_context  dev,
uint8_t  bits 
)

Set the Interrupt Enables register. See the datasheet for details.

Parameters
devThe device context.
bitsA bitmask of BMM150_INT_EN_BITS_T bits.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t bmm150_get_interrupt_config ( const bmm150_context  dev)

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.

Parameters
devThe device context.
Returns
A bitmask of BMM150_INT_CONFIG_BITS_T bits.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_set_interrupt_config ( const bmm150_context  dev,
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.

Parameters
devThe device context.
bitsA bitmask of BMM150_INT_CONFIG_BITS_T bits.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t bmm150_get_interrupt_status ( const bmm150_context  dev)

Return the interrupt status register. This register indicates which interrupts have been triggered. See the datasheet for details.

Parameters
devThe device context.
Returns
a bitmask of BMM150_INT_STATUS_BITS_T bits.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_set_repetitions_xy ( const bmm150_context  dev,
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.

Parameters
devThe device context.
repsA coefficient for specifying the number of repititions to perform. (1 + 2(reps))
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_set_repetitions_z ( const bmm150_context  dev,
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.

Parameters
devThe device context.
repsA coefficient for specifying the number of repititions to perform. (1 + (reps))
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t bmm150_install_isr ( const bmm150_context  dev,
BMM150_INTERRUPT_PINS_T  intr,
int  gpio,
mraa_gpio_edge_t  level,
void(*)(void *)  isr,
void *  arg 
)

Install an interrupt handler.

Parameters
devThe device context.
intrOne of the BMM150_INTERRUPT_PINS_T values specifying which interrupt pin you are installing.
gpioGPIO pin to use as interrupt pin.
levelThe interrupt trigger level (one of the mraa_gpio_edge_t values). Make sure that you have configured the interrupt pin properly for whatever level you choose.
isrThe interrupt handler, accepting a void * argument
argThe argument to pass the the interrupt handler.
Returns
UPM result.

Here is the call graph for this function:

Here is the caller graph for this function:

void bmm150_uninstall_isr ( const bmm150_context  dev,
BMM150_INTERRUPT_PINS_T  intr 
)

Uninstall a previously installed interrupt handler.

Parameters
devThe device context.
intrOne of the BMM150_INTERRUPT_PINS_T values specifying which interrupt pin you are removing.

Here is the caller graph for this function:

uint8_t bmm150_read_reg ( const bmm150_context  dev,
uint8_t  reg 
)

Read a register.

Parameters
devThe device context.
regThe register to read.
Returns
The value of the register.

Here is the caller graph for this function:

int bmm150_read_regs ( const bmm150_context  dev,
uint8_t  reg,
uint8_t *  buffer,
int  len 
)

Read contiguous registers into a buffer.

Parameters
devThe device context.
bufferThe buffer to store the results.
lenThe number of registers to read.
Returns
The number of bytes read, or -1 on error.

Here is the caller graph for this function:

upm_result_t bmm150_write_reg ( const bmm150_context  dev,
uint8_t  reg,
uint8_t  val 
)

Write to a register.

Parameters
devThe device context.
regThe register to write to.
valThe value to write.
Returns
UPM result.

Here is the caller graph for this function:

Typedef Documentation

typedef struct _bmm150_context * bmm150_context

Device context