upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for lsm6dsl.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 "lsm6dsl.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 LSM6DSL instance using default i2c bus and address
lsm6dsl_context sensor = lsm6dsl_init(LSM6DSL_DEFAULT_I2C_BUS,
LSM6DSL_DEFAULT_I2C_ADDR, -1);
#elif defined(CONFIG_BOARD_ARDUINO_101)
// ARDUINO_101 (Quark core) must use SPI
// Instantiate a LSM6DSL instance using default SPI bus and pin 10 as CS
lsm6dsl_context sensor = lsm6dsl_init(LSM6DSL_DEFAULT_SPI_BUS,
-1, 10);
#else
// everything else use I2C by default
// Instantiate a LSM6DSL instance using default i2c bus and address
lsm6dsl_context sensor = lsm6dsl_init(LSM6DSL_DEFAULT_I2C_BUS,
LSM6DSL_DEFAULT_I2C_ADDR, -1);
#endif
if (!sensor)
{
printf("lsm6dsl_init() failed.\n");
return 1;
}
// now output data every 250 milliseconds
while (shouldRun)
{
float x, y, z;
if (lsm6dsl_update(sensor))
{
printf("lsm6dsl_update() failed\n");
lsm6dsl_close(sensor);
return 1;
}
lsm6dsl_get_accelerometer(sensor, &x, &y, &z);
printf("Acceleration x: %f y: %f z: %f g\n",
x, y, z);
lsm6dsl_get_gyroscope(sensor, &x, &y, &z);
printf("Gyroscope x: %f y: %f z: %f dps\n",
x, y, z);
printf("Compensation Temperature: %f C\n\n",
upm_delay_ms(250);
}
printf("Exiting...\n");
lsm6dsl_close(sensor);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _lsm6dsl_context
 

Functions

lsm6dsl_context lsm6dsl_init (int bus, int addr, int cs)
 
void lsm6dsl_close (lsm6dsl_context dev)
 
upm_result_t lsm6dsl_update (const lsm6dsl_context dev)
 
uint8_t lsm6dsl_get_chip_id (const lsm6dsl_context dev)
 
upm_result_t lsm6dsl_devinit (const lsm6dsl_context dev, LSM6DSL_XL_ODR_T acc_odr, LSM6DSL_XL_FS_T acc_fs, LSM6DSL_G_ODR_T gyr_odr, LSM6DSL_G_FS_T gyr_fs)
 
upm_result_t lsm6dsl_set_acc_odr (const lsm6dsl_context dev, LSM6DSL_XL_ODR_T odr)
 
upm_result_t lsm6dsl_set_gyr_odr (const lsm6dsl_context dev, LSM6DSL_G_ODR_T odr)
 
upm_result_t lsm6dsl_set_acc_full_scale (const lsm6dsl_context dev, LSM6DSL_XL_FS_T fs)
 
upm_result_t lsm6dsl_set_gyr_full_scale (const lsm6dsl_context dev, LSM6DSL_G_FS_T fs)
 
void lsm6dsl_get_accelerometer (const lsm6dsl_context dev, float *x, float *y, float *z)
 
void lsm6dsl_get_gyroscope (const lsm6dsl_context dev, float *x, float *y, float *z)
 
float lsm6dsl_get_temperature (const lsm6dsl_context dev)
 
upm_result_t lsm6dsl_high_performance (const lsm6dsl_context dev, bool enable)
 
upm_result_t lsm6dsl_reset (const lsm6dsl_context dev)
 
upm_result_t lsm6dsl_set_interrupt_active_high (const lsm6dsl_context dev, bool high)
 
upm_result_t lsm6dsl_set_interrupt_push_pull (const lsm6dsl_context dev, bool pp)
 
uint8_t lsm6dsl_get_status (const lsm6dsl_context dev)
 
upm_result_t lsm6dsl_set_acc_offsets (const lsm6dsl_context dev, int x, int y, int z, bool weight)
 
upm_result_t lsm6dsl_install_isr (const lsm6dsl_context dev, LSM6DSL_INTERRUPT_PINS_T intr, int gpio, mraa_gpio_edge_t level, void(*isr)(void *), void *arg)
 
void lsm6dsl_uninstall_isr (const lsm6dsl_context dev, LSM6DSL_INTERRUPT_PINS_T intr)
 
uint8_t lsm6dsl_read_reg (const lsm6dsl_context dev, uint8_t reg)
 
int lsm6dsl_read_regs (const lsm6dsl_context dev, uint8_t reg, uint8_t *buffer, int len)
 
upm_result_t lsm6dsl_write_reg (const lsm6dsl_context dev, uint8_t reg, uint8_t val)
 

Typedefs

typedef struct _lsm6dsl_contextlsm6dsl_context
 

Function Documentation

lsm6dsl_context lsm6dsl_init ( int  bus,
int  addr,
int  cs 
)

LSM6DSL 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 Intel Edison with Arduino breakout), then you can connect the proper pin to the hardware CS pin on your MCU and supply -1 for cs.

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 on error

Here is the call graph for this function:

void lsm6dsl_close ( lsm6dsl_context  dev)

LSM6DSL Destructor

Parameters
devThe device context

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t lsm6dsl_update ( const lsm6dsl_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 lsm6dsl_get_chip_id ( const lsm6dsl_context  dev)

Return the chip ID

Parameters
devThe device context
Returns
The chip ID (LSM6DSL_CHIPID)

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t lsm6dsl_devinit ( const lsm6dsl_context  dev,
LSM6DSL_XL_ODR_T  acc_odr,
LSM6DSL_XL_FS_T  acc_fs,
LSM6DSL_G_ODR_T  gyr_odr,
LSM6DSL_G_FS_T  gyr_fs 
)

Initialize the device and start operation. This function is called from lsm6dsl_init(), so it will not need to be called by a user unless the device is reset. It sets the accelerometer and gyroscope ODR and FS modes, and enables BDU, register auto-increment, and high performance mode.

Parameters
devThe device context
acc_odrOne of the LSM6DSL_XL_ODR_T values
acc_fsOne of the LSM6DSL_XL_FS_T values
gyr_odrOne of the LSM6DSL_G_ODR_T values
gyr_fsOne of the LSM6DSL_G_FS_T values
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t lsm6dsl_set_acc_odr ( const lsm6dsl_context  dev,
LSM6DSL_XL_ODR_T  odr 
)

Set the output data rate (ODR) of the accelerometer

Parameters
devThe device context
odrOne of the LSM6DSL_XL_ODR_T values
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t lsm6dsl_set_gyr_odr ( const lsm6dsl_context  dev,
LSM6DSL_G_ODR_T  odr 
)

Set the output data rate (ODR) of the gyroscope

Parameters
devThe device context
odrOne of the LSM6DSL_G_ODR_T values
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t lsm6dsl_set_acc_full_scale ( const lsm6dsl_context  dev,
LSM6DSL_XL_FS_T  fs 
)

Set the full scale (FS) of the accelerometer. This device supports a full scale of 2, 4, 8, and 16G.

Parameters
devThe device context
fsOne of the LSM6DSL_XL_FS_T values
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t lsm6dsl_set_gyr_full_scale ( const lsm6dsl_context  dev,
LSM6DSL_G_FS_T  fs 
)

Set the full scale (FS) of the gyroscope. This device supports a full scale of 125, 245, 500, 1000, and 2000 degrees per second (DPS)

Parameters
devThe device context
fsOne of the LSM6DSL_G_FS_T values
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

void lsm6dsl_get_accelerometer ( const lsm6dsl_context  dev,
float *  x,
float *  y,
float *  z 
)

Return accelerometer data in gravities (g). lsm6dsl_update() must have been called prior to calling this function.

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:

void lsm6dsl_get_gyroscope ( const lsm6dsl_context  dev,
float *  x,
float *  y,
float *  z 
)

Return gyroscope data in degrees per second (DPS). lsm6dsl_update() must have been called prior to calling this function.

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:

float lsm6dsl_get_temperature ( const lsm6dsl_context  dev)

Return the current measured temperature. Note, this is not ambient temperature. lsm6dsl_update() must have been called prior to calling this function.

Parameters
devThe device context
Returns
The temperature in degrees Celsius

Here is the caller graph for this function:

upm_result_t lsm6dsl_high_performance ( const lsm6dsl_context  dev,
bool  enable 
)

Enable accelerometer and gyroscope high performance modes. These are further defined by the respective ODR settings to allow low power, and normal/high-performance modes.

Parameters
devThe device context
enabletrue to enable high performance mode, false otherwise
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t lsm6dsl_reset ( const lsm6dsl_context  dev)

Reset the device as if during a power on reset. All configured values are lost when this happens. You should call lsm6dsl_devinit() afterwards, or at least perform the same initialization lsm6dsl_devinit() does before continuing.

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 lsm6dsl_set_interrupt_active_high ( const lsm6dsl_context  dev,
bool  high 
)

Indicate whether the interrupt should be active high (default) or active low. See the datasheet for details.

Parameters
devThe device context
hightrue for active high, false for active low
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t lsm6dsl_set_interrupt_push_pull ( const lsm6dsl_context  dev,
bool  pp 
)

Indicate whether interrupts are push-pull (default) or open drain. See the datasheet for details.

Parameters
devThe device context
pptrue for push-pull, false for open-drain
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t lsm6dsl_get_status ( const lsm6dsl_context  dev)

Return the contents of the status register

Parameters
devThe device context
Returns
A bitmask of values from LSM6DSL_STATUS_BITS_T

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t lsm6dsl_set_acc_offsets ( const lsm6dsl_context  dev,
int  x,
int  y,
int  z,
bool  weight 
)

Set accelerometer offsets for each axis. In the case of X and Y, the offsets will be internally added before being placed into the output registers. For the Z offset, the value will be subtracted before being placed into the output registers. The weight is used to determine the weighing of the offset bits. All offsets must be in the range of -127 to 127.

Parameters
devThe device context
xX axis offset in the range -127 to 127
yY axis offset in the range -127 to 127
zZ axis offset in the range -127 to 127
weightWhen true, the the offset will be weighted at 2^-6 g/LSB, when false the weighting will be 2^-10 g/LSB
Returns
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t lsm6dsl_install_isr ( const lsm6dsl_context  dev,
LSM6DSL_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 LSM6DSL_INTERRUPT_PINS_T values specifying which interrupt pin you are installing
gpioGPIO pin to use as interrupt pin
levelThe interrupt trigger level (one of 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 lsm6dsl_uninstall_isr ( const lsm6dsl_context  dev,
LSM6DSL_INTERRUPT_PINS_T  intr 
)

Uninstall a previously installed interrupt handler

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

Here is the caller graph for this function:

uint8_t lsm6dsl_read_reg ( const lsm6dsl_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 lsm6dsl_read_regs ( const lsm6dsl_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 lsm6dsl_write_reg ( const lsm6dsl_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

Device context