mirror of
https://github.com/eclipse/upm.git
synced 2025-03-14 20:47:30 +03:00
lsm6dsl: Initial implementation; C; C++ wraps C; FTI; examples
Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
parent
27eec52e29
commit
274fd9b608
88
examples/c++/lsm6dsl.cxx
Normal file
88
examples/c++/lsm6dsl.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* 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 <iostream>
|
||||
#include <signal.h>
|
||||
#include "lsm6dsl.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate an LSM6DSL using default I2C parameters
|
||||
upm::LSM6DSL sensor;
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin
|
||||
// for CS: LSM6DSL(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
while (shouldRun)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
sensor.update();
|
||||
|
||||
sensor.getAccelerometer(&x, &y, &z);
|
||||
cout << "Accelerometer x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " g"
|
||||
<< endl;
|
||||
|
||||
sensor.getGyroscope(&x, &y, &z);
|
||||
cout << "Gyroscope x: " << x
|
||||
<< " y: " << y
|
||||
<< " z: " << z
|
||||
<< " dps"
|
||||
<< endl;
|
||||
|
||||
// we show both C and F for temperature
|
||||
cout << "Compensation Temperature: " << sensor.getTemperature()
|
||||
<< " C / " << sensor.getTemperature(true) << " F"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
return 0;
|
||||
}
|
104
examples/c/lsm6dsl.c
Normal file
104
examples/c/lsm6dsl.c
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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);
|
||||
//! [Interesting]
|
||||
|
||||
#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",
|
||||
lsm6dsl_get_temperature(sensor));
|
||||
|
||||
upm_delay_ms(250);
|
||||
}
|
||||
|
||||
printf("Exiting...\n");
|
||||
|
||||
lsm6dsl_close(sensor);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
@ -192,6 +192,7 @@ add_example(VEML6070Sample veml6070)
|
||||
add_example(RN2903_Example rn2903)
|
||||
add_example(LIS2DS12_Example lis2ds12)
|
||||
add_example(LSM6DS3H_Example lsm6ds3h)
|
||||
add_example(LSM6DSL_Example lsm6dsl)
|
||||
|
||||
add_example_with_path(Jhd1313m1_lcdSample jhd1313m1 jhd1313m1)
|
||||
add_example_with_path(Jhd1313m1Sample jhd1313m1 jhd1313m1)
|
||||
|
71
examples/java/LSM6DSL_Example.java
Normal file
71
examples/java/LSM6DSL_Example.java
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import upm_lsm6dsl.*;
|
||||
|
||||
public class LSM6DSL_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
|
||||
// Instantiate a LSM6DSL instance using default i2c bus and address
|
||||
LSM6DSL sensor = new LSM6DSL();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a
|
||||
// valid pin for CS:
|
||||
// LSM6DSL(0, -1, 10);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
floatVector data = sensor.getAccelerometer();
|
||||
|
||||
System.out.println("Accelerometer x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " g");
|
||||
|
||||
data = sensor.getGyroscope();
|
||||
|
||||
System.out.println("Gyroscope x: " + data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " dps");
|
||||
|
||||
System.out.println("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(250);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
72
examples/javascript/lsm6dsl.js
Normal file
72
examples/javascript/lsm6dsl.js
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016-2017 Intel Corporation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_lsm6dsl');
|
||||
|
||||
// Instantiate a LSM6DSL instance using default i2c bus and address
|
||||
var sensor = new sensorObj.LSM6DSL();
|
||||
|
||||
// For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
// LSM6DSL(0, -1, 10);
|
||||
|
||||
// now output data every 250 milliseconds
|
||||
setInterval(function()
|
||||
{
|
||||
// update our values from the sensor
|
||||
sensor.update();
|
||||
|
||||
var data = sensor.getAccelerometer();
|
||||
console.log("Accelerometer x: "
|
||||
+ data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " g");
|
||||
|
||||
data = sensor.getGyroscope();
|
||||
console.log("Gyroscope x: "
|
||||
+ data.get(0)
|
||||
+ " y: " + data.get(1)
|
||||
+ " z: " + data.get(2)
|
||||
+ " dps");
|
||||
|
||||
// we show both C and F for temperature
|
||||
console.log("Compensation Temperature: "
|
||||
+ sensor.getTemperature()
|
||||
+ " C / "
|
||||
+ sensor.getTemperature(true)
|
||||
+ " F");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 250);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
74
examples/python/lsm6dsl.py
Executable file
74
examples/python/lsm6dsl.py
Executable file
@ -0,0 +1,74 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016-2017 Intel Corporation.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from __future__ import print_function
|
||||
import time, sys, signal, atexit
|
||||
from upm import pyupm_lsm6dsl as sensorObj
|
||||
|
||||
def main():
|
||||
# Instantiate a BMP250E instance using default i2c bus and address
|
||||
sensor = sensorObj.LSM6DSL()
|
||||
|
||||
# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
|
||||
# LSM6DSL(0, -1, 10);
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you
|
||||
# hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print("Exiting")
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# now output data every 250 milliseconds
|
||||
while (1):
|
||||
sensor.update()
|
||||
|
||||
data = sensor.getAccelerometer()
|
||||
print("Accelerometer x:", data[0], end=' ')
|
||||
print(" y:", data[1], end=' ')
|
||||
print(" z:", data[2], end=' ')
|
||||
print(" g")
|
||||
|
||||
data = sensor.getGyroscope()
|
||||
print("Gyroscope x:", data[0], end=' ')
|
||||
print(" y:", data[1], end=' ')
|
||||
print(" z:", data[2], end=' ')
|
||||
print(" dps")
|
||||
|
||||
# we show both C and F for temperature
|
||||
print("Compensation Temperature:", sensor.getTemperature(), "C /", end=' ')
|
||||
print(sensor.getTemperature(True), "F")
|
||||
|
||||
print()
|
||||
time.sleep(.250)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
9
src/lsm6dsl/CMakeLists.txt
Normal file
9
src/lsm6dsl/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
upm_mixed_module_init (NAME lsm6dsl
|
||||
DESCRIPTION "3-Axis Digital Accelerometer and Gyroscope"
|
||||
C_HDR lsm6dsl.h lsm6dsl_defs.h
|
||||
C_SRC lsm6dsl.c
|
||||
CPP_HDR lsm6dsl.hpp
|
||||
CPP_SRC lsm6dsl.cxx
|
||||
FTI_SRC lsm6dsl_fti.c
|
||||
CPP_WRAPS_C
|
||||
REQUIRES mraa utilities-c)
|
24
src/lsm6dsl/javaupm_lsm6dsl.i
Normal file
24
src/lsm6dsl/javaupm_lsm6dsl.i
Normal file
@ -0,0 +1,24 @@
|
||||
%module javaupm_lsm6dsl
|
||||
%include "../upm.i"
|
||||
%include "typemaps.i"
|
||||
%include "../upm_vectortypes.i"
|
||||
|
||||
%ignore getAccelerometer(float *, float *, float *);
|
||||
%ignore getGyroscope(float *, float *, float *);
|
||||
|
||||
%include "lsm6dsl_defs.h"
|
||||
%include "lsm6dsl.hpp"
|
||||
%{
|
||||
#include "lsm6dsl.hpp"
|
||||
%}
|
||||
|
||||
%pragma(java) jniclasscode=%{
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("javaupm_lsm6dsl");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. \n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
%}
|
10
src/lsm6dsl/jsupm_lsm6dsl.i
Normal file
10
src/lsm6dsl/jsupm_lsm6dsl.i
Normal file
@ -0,0 +1,10 @@
|
||||
%module jsupm_lsm6dsl
|
||||
%include "../upm.i"
|
||||
%include "../upm_vectortypes.i"
|
||||
|
||||
|
||||
%include "lsm6dsl_defs.h"
|
||||
%include "lsm6dsl.hpp"
|
||||
%{
|
||||
#include "lsm6dsl.hpp"
|
||||
%}
|
670
src/lsm6dsl/lsm6dsl.c
Normal file
670
src/lsm6dsl/lsm6dsl.c
Normal file
@ -0,0 +1,670 @@
|
||||
/*
|
||||
* 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 <assert.h>
|
||||
|
||||
#include "upm_utilities.h"
|
||||
#include "lsm6dsl.h"
|
||||
|
||||
// macro for converting a uint8_t low/high pair into a float
|
||||
#define INT16_TO_FLOAT(h, l) \
|
||||
(float)( (int16_t)( (l) | ((h) << 8) ) )
|
||||
|
||||
// some useful macros to save on typing and text wrapping
|
||||
#undef _SHIFT
|
||||
#define _SHIFT(x) (_LSM6DSL_##x##_SHIFT)
|
||||
|
||||
#undef _MASK
|
||||
#define _MASK(x) (_LSM6DSL_##x##_MASK)
|
||||
|
||||
#undef _SHIFTMASK
|
||||
#define _SHIFTMASK(x) (_MASK(x) << _SHIFT(x))
|
||||
|
||||
// SPI CS on and off functions
|
||||
static void _csOn(const lsm6dsl_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (dev->gpioCS)
|
||||
mraa_gpio_write(dev->gpioCS, 0);
|
||||
}
|
||||
|
||||
static void _csOff(const lsm6dsl_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (dev->gpioCS)
|
||||
mraa_gpio_write(dev->gpioCS, 1);
|
||||
}
|
||||
|
||||
// init
|
||||
lsm6dsl_context lsm6dsl_init(int bus, int addr, int cs)
|
||||
{
|
||||
lsm6dsl_context dev =
|
||||
(lsm6dsl_context)malloc(sizeof(struct _lsm6dsl_context));
|
||||
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
// zero out context
|
||||
memset((void *)dev, 0, sizeof(struct _lsm6dsl_context));
|
||||
|
||||
// make sure MRAA is initialized
|
||||
if (mraa_init() != MRAA_SUCCESS)
|
||||
{
|
||||
printf("%s: mraa_init() failed.\n", __FUNCTION__);
|
||||
lsm6dsl_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (addr < 0)
|
||||
{
|
||||
// SPI
|
||||
if (!(dev->spi = mraa_spi_init(bus)))
|
||||
{
|
||||
printf("%s: mraa_spi_init() failed.\n", __FUNCTION__);
|
||||
lsm6dsl_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Only create cs context if we are actually using a valid pin.
|
||||
// A hardware controlled pin should specify cs as -1.
|
||||
if (cs >= 0)
|
||||
{
|
||||
if (!(dev->gpioCS = mraa_gpio_init(cs)))
|
||||
{
|
||||
printf("%s: mraa_gpio_init() failed.\n", __FUNCTION__);
|
||||
lsm6dsl_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
mraa_gpio_dir(dev->gpioCS, MRAA_GPIO_OUT);
|
||||
}
|
||||
|
||||
mraa_spi_mode(dev->spi, MRAA_SPI_MODE0);
|
||||
if (mraa_spi_frequency(dev->spi, 5000000))
|
||||
{
|
||||
printf("%s: mraa_spi_frequency() failed.\n", __FUNCTION__);
|
||||
lsm6dsl_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// I2C
|
||||
if (!(dev->i2c = mraa_i2c_init(bus)))
|
||||
{
|
||||
printf("%s: mraa_i2c_init() failed.\n", __FUNCTION__);
|
||||
lsm6dsl_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mraa_i2c_address(dev->i2c, addr))
|
||||
{
|
||||
printf("%s: mraa_i2c_address() failed.\n", __FUNCTION__);
|
||||
lsm6dsl_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// check the chip id
|
||||
|
||||
uint8_t chipID = lsm6dsl_get_chip_id(dev);
|
||||
if (chipID != LSM6DSL_CHIPID)
|
||||
{
|
||||
printf("%s: invalid chip id: %02x. Expected %02x\n",
|
||||
__FUNCTION__, chipID, LSM6DSL_CHIPID);
|
||||
lsm6dsl_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// reset
|
||||
if (lsm6dsl_reset(dev))
|
||||
{
|
||||
printf("%s: lsm6dsl_reset() failed.\n", __FUNCTION__);
|
||||
lsm6dsl_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// call devinit with default options
|
||||
if (lsm6dsl_devinit(dev, LSM6DSL_XL_ODR_104HZ, LSM6DSL_XL_FS_2G,
|
||||
LSM6DSL_G_ODR_104HZ, LSM6DSL_G_FS_245DPS))
|
||||
{
|
||||
printf("%s: lsm6dsl_devinit() failed.\n", __FUNCTION__);
|
||||
lsm6dsl_close(dev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
void lsm6dsl_close(lsm6dsl_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
lsm6dsl_uninstall_isr(dev, LSM6DSL_INTERRUPT_INT1);
|
||||
lsm6dsl_uninstall_isr(dev, LSM6DSL_INTERRUPT_INT2);
|
||||
|
||||
if (dev->i2c)
|
||||
mraa_i2c_stop(dev->i2c);
|
||||
if (dev->spi)
|
||||
mraa_spi_stop(dev->spi);
|
||||
if (dev->gpioCS)
|
||||
mraa_gpio_close(dev->gpioCS);
|
||||
|
||||
free(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)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
// enable register auto-increment and BDU (block data update)
|
||||
uint8_t reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL3_C);
|
||||
reg |= (LSM6DSL_CTRL3_IF_INC | LSM6DSL_CTRL3_BDU);
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL3_C, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
// set our ODR, FS, and HP mode
|
||||
if (lsm6dsl_set_acc_odr(dev, acc_odr)
|
||||
|| lsm6dsl_set_acc_full_scale(dev, acc_fs)
|
||||
|| lsm6dsl_set_gyr_odr(dev, gyr_odr)
|
||||
|| lsm6dsl_set_gyr_full_scale(dev, gyr_fs)
|
||||
|| lsm6dsl_high_performance(dev, true))
|
||||
{
|
||||
printf("%s: failed to set configuration parameters.\n",
|
||||
__FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
// settle
|
||||
upm_delay_ms(50);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_set_acc_odr(const lsm6dsl_context dev,
|
||||
LSM6DSL_XL_ODR_T odr)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
uint8_t reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL1_XL);
|
||||
|
||||
// mask out ODR bits, add our own
|
||||
reg &= ~_SHIFTMASK(CTRL1_XL_ODR);
|
||||
reg |= (odr << _SHIFT(CTRL1_XL_ODR));
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL1_XL, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_set_gyr_odr(const lsm6dsl_context dev,
|
||||
LSM6DSL_G_ODR_T odr)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
uint8_t reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL2_G);
|
||||
|
||||
// mask out ODR bits, add our own
|
||||
reg &= ~_SHIFTMASK(CTRL2_G_ODR);
|
||||
reg |= (odr << _SHIFT(CTRL2_G_ODR));
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL2_G, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_set_acc_full_scale(const lsm6dsl_context dev,
|
||||
LSM6DSL_XL_FS_T fs)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
uint8_t reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL1_XL);
|
||||
|
||||
// mask out FS bits, add our own
|
||||
reg &= ~_SHIFTMASK(CTRL1_XL_FS);
|
||||
reg |= (fs << _SHIFT(CTRL1_XL_FS));
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL1_XL, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
// 16b resolution
|
||||
switch(fs)
|
||||
{
|
||||
case LSM6DSL_XL_FS_2G:
|
||||
dev->accScale = 0.061;
|
||||
break;
|
||||
|
||||
case LSM6DSL_XL_FS_4G:
|
||||
dev->accScale = 0.122;
|
||||
break;
|
||||
|
||||
case LSM6DSL_XL_FS_8G:
|
||||
dev->accScale = 0.244;
|
||||
break;
|
||||
|
||||
case LSM6DSL_XL_FS_16G:
|
||||
dev->accScale = 0.488;
|
||||
break;
|
||||
}
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_set_gyr_full_scale(const lsm6dsl_context dev,
|
||||
LSM6DSL_G_FS_T fs)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
uint8_t reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL2_G);
|
||||
|
||||
// mask out FS bits, add our own
|
||||
reg &= ~_SHIFTMASK(CTRL2_G_FS);
|
||||
|
||||
if ((int)fs > (int)_MASK(CTRL2_G_FS))
|
||||
reg |= LSM6DSL_CTRL2_G_FS_125;
|
||||
else
|
||||
reg &= ~LSM6DSL_CTRL2_G_FS_125;
|
||||
|
||||
// mask off the virtual bit. The end result will be 245dps (0),
|
||||
// if it was tagged with the virtual bit.
|
||||
fs &= _MASK(CTRL2_G_FS);
|
||||
// add it to the register
|
||||
reg |= (fs << _SHIFT(CTRL2_G_FS));
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL2_G, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_update(const lsm6dsl_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
int bufLen = 14;
|
||||
uint8_t buf[bufLen];
|
||||
|
||||
if (lsm6dsl_read_regs(dev, LSM6DSL_REG_OUT_TEMP_L,
|
||||
buf, bufLen) != bufLen)
|
||||
{
|
||||
printf("%s: lsm6dsl_read_regs() failed to read %d bytes\n",
|
||||
__FUNCTION__, bufLen);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
// temperature is first msb lsb
|
||||
dev->temperature = INT16_TO_FLOAT(buf[1], buf[0]);
|
||||
|
||||
// gyroscope
|
||||
dev->gyrX = INT16_TO_FLOAT(buf[3], buf[2]);
|
||||
dev->gyrY = INT16_TO_FLOAT(buf[5], buf[4]);
|
||||
dev->gyrZ = INT16_TO_FLOAT(buf[7], buf[6]);
|
||||
|
||||
// accelerometer
|
||||
dev->accX = INT16_TO_FLOAT(buf[9], buf[8]);
|
||||
dev->accY = INT16_TO_FLOAT(buf[11], buf[10]);
|
||||
dev->accZ = INT16_TO_FLOAT(buf[13], buf[12]);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t lsm6dsl_read_reg(const lsm6dsl_context dev, uint8_t reg)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (dev->spi)
|
||||
{
|
||||
reg |= 0x80; // needed for read
|
||||
uint8_t pkt[2] = {reg, 0};
|
||||
|
||||
_csOn(dev);
|
||||
if (mraa_spi_transfer_buf(dev->spi, pkt, pkt, 2))
|
||||
{
|
||||
_csOff(dev);
|
||||
printf("%s: mraa_spi_transfer_buf() failed.\n", __FUNCTION__);
|
||||
return 0xff;
|
||||
}
|
||||
_csOff(dev);
|
||||
|
||||
return pkt[1];
|
||||
}
|
||||
else
|
||||
return (uint8_t)mraa_i2c_read_byte_data(dev->i2c, reg);
|
||||
}
|
||||
|
||||
int lsm6dsl_read_regs(const lsm6dsl_context dev, uint8_t reg,
|
||||
uint8_t *buffer, int len)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (dev->spi)
|
||||
{
|
||||
reg |= 0x80; // needed for read
|
||||
|
||||
uint8_t sbuf[len + 1];
|
||||
memset((char *)sbuf, 0, len + 1);
|
||||
sbuf[0] = reg;
|
||||
|
||||
_csOn(dev);
|
||||
if (mraa_spi_transfer_buf(dev->spi, sbuf, sbuf, len + 1))
|
||||
{
|
||||
_csOff(dev);
|
||||
printf("%s: mraa_spi_transfer_buf() failed.\n", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
_csOff(dev);
|
||||
|
||||
// now copy it into user buffer
|
||||
for (int i=0; i<len; i++)
|
||||
buffer[i] = sbuf[i + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mraa_i2c_read_bytes_data(dev->i2c, reg, buffer, len) != len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_write_reg(const lsm6dsl_context dev,
|
||||
uint8_t reg, uint8_t val)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (dev->spi)
|
||||
{
|
||||
reg &= 0x7f; // mask off 0x80 for writing
|
||||
uint8_t pkt[2] = {reg, val};
|
||||
|
||||
_csOn(dev);
|
||||
if (mraa_spi_transfer_buf(dev->spi, pkt, NULL, 2))
|
||||
{
|
||||
_csOff(dev);
|
||||
printf("%s: mraa_spi_transfer_buf() failed.",
|
||||
__FUNCTION__);
|
||||
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
_csOff(dev);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mraa_i2c_write_byte_data(dev->i2c, val, reg))
|
||||
{
|
||||
printf("%s: mraa_i2c_write_byte_data() failed.",
|
||||
__FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t lsm6dsl_get_chip_id(const lsm6dsl_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
return lsm6dsl_read_reg(dev, LSM6DSL_REG_WHO_AM_I);
|
||||
}
|
||||
|
||||
void lsm6dsl_get_accelerometer(const lsm6dsl_context dev,
|
||||
float *x, float *y, float *z)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (x)
|
||||
*x = dev->accX * dev->accScale / 1000.00;
|
||||
|
||||
if (y)
|
||||
*y = dev->accY * dev->accScale / 1000.00;
|
||||
|
||||
if (z)
|
||||
*z = dev->accZ * dev->accScale / 1000.00;
|
||||
}
|
||||
|
||||
void lsm6dsl_get_gyroscope(const lsm6dsl_context dev,
|
||||
float *x, float *y, float *z)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
if (x)
|
||||
*x = dev->gyrX / 1000.00;
|
||||
|
||||
if (y)
|
||||
*y = dev->gyrY / 1000.00;
|
||||
|
||||
if (z)
|
||||
*z = dev->gyrZ / 1000.00;
|
||||
}
|
||||
|
||||
float lsm6dsl_get_temperature(const lsm6dsl_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
// this seems to work, but I sure wish they would document this in
|
||||
// their DS's
|
||||
return (dev->temperature / 65536.0) + 25.0;
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_high_performance(const lsm6dsl_context dev,
|
||||
bool enable)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
uint8_t reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL6_C);
|
||||
|
||||
// acc
|
||||
if (enable)
|
||||
reg &= ~LSM6DSL_CTRL6_XL_HM_MODE;
|
||||
else
|
||||
reg |= LSM6DSL_CTRL6_XL_HM_MODE;
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL6_C, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
// gyr
|
||||
reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL7_G);
|
||||
|
||||
if (enable)
|
||||
reg &= ~LSM6DSL_CTRL7_G_HM_MODE;
|
||||
else
|
||||
reg |= LSM6DSL_CTRL7_G_HM_MODE;
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL7_G, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
upm_delay_ms(100);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_reset(const lsm6dsl_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
uint8_t reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL3_C);
|
||||
|
||||
reg |= LSM6DSL_CTRL3_SW_RESET;
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL3_C, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
upm_delay_ms(100);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_set_interrupt_active_high(const lsm6dsl_context dev,
|
||||
bool high)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
uint8_t reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL3_C);
|
||||
|
||||
if (high)
|
||||
reg &= ~LSM6DSL_CTRL3_H_LACTIVE;
|
||||
else
|
||||
reg |= LSM6DSL_CTRL3_H_LACTIVE;
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL3_C, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_set_interrupt_push_pull(const lsm6dsl_context dev,
|
||||
bool pp)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
uint8_t reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL3_C);
|
||||
|
||||
if (pp)
|
||||
reg &= ~LSM6DSL_CTRL3_PP_OD;
|
||||
else
|
||||
reg |= LSM6DSL_CTRL3_PP_OD;
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL3_C, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t lsm6dsl_get_status(const lsm6dsl_context dev)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
return lsm6dsl_read_reg(dev, LSM6DSL_REG_STATUS);
|
||||
}
|
||||
|
||||
upm_result_t lsm6dsl_set_acc_offsets(const lsm6dsl_context dev,
|
||||
int x, int y, int z, bool weight)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
// narrowing conversion to int8_t
|
||||
int8_t ix = (int8_t)x;
|
||||
int8_t iy = (int8_t)y;
|
||||
int8_t iz = (int8_t)z;
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_X_OFS_USR, (uint8_t)ix))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_Y_OFS_USR, (uint8_t)iy))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_Z_OFS_USR, (uint8_t)iz))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
// now set the weighting...
|
||||
uint8_t reg = lsm6dsl_read_reg(dev, LSM6DSL_REG_CTRL6_C);
|
||||
if (weight)
|
||||
reg |= LSM6DSL_CTRL6_USR_OFF_W;
|
||||
else
|
||||
reg &= ~LSM6DSL_CTRL6_USR_OFF_W;
|
||||
|
||||
if (lsm6dsl_write_reg(dev, LSM6DSL_REG_CTRL6_C, reg))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
// delete any existing ISR and GPIO context for this interrupt
|
||||
lsm6dsl_uninstall_isr(dev, intr);
|
||||
|
||||
mraa_gpio_context gpio_isr = NULL;
|
||||
|
||||
// create gpio context
|
||||
if (!(gpio_isr = mraa_gpio_init(gpio)))
|
||||
{
|
||||
printf("%s: mraa_gpio_init() failed.\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
mraa_gpio_dir(gpio_isr, MRAA_GPIO_IN);
|
||||
|
||||
if (mraa_gpio_isr(gpio_isr, level, isr, arg))
|
||||
{
|
||||
mraa_gpio_close(gpio_isr);
|
||||
printf("%s: mraa_gpio_isr() failed.\n", __FUNCTION__);
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
switch (intr)
|
||||
{
|
||||
case LSM6DSL_INTERRUPT_INT1:
|
||||
dev->gpioINT1 = gpio_isr;
|
||||
break;
|
||||
|
||||
case LSM6DSL_INTERRUPT_INT2:
|
||||
dev->gpioINT2 = gpio_isr;
|
||||
break;
|
||||
}
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
void lsm6dsl_uninstall_isr(const lsm6dsl_context dev,
|
||||
LSM6DSL_INTERRUPT_PINS_T intr)
|
||||
{
|
||||
assert(dev != NULL);
|
||||
|
||||
switch (intr)
|
||||
{
|
||||
case LSM6DSL_INTERRUPT_INT1:
|
||||
if (dev->gpioINT1)
|
||||
{
|
||||
mraa_gpio_isr_exit(dev->gpioINT1);
|
||||
mraa_gpio_close(dev->gpioINT1);
|
||||
dev->gpioINT1 = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case LSM6DSL_INTERRUPT_INT2:
|
||||
if (dev->gpioINT2)
|
||||
{
|
||||
mraa_gpio_isr_exit(dev->gpioINT2);
|
||||
mraa_gpio_close(dev->gpioINT2);
|
||||
dev->gpioINT2 = NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
215
src/lsm6dsl/lsm6dsl.cxx
Normal file
215
src/lsm6dsl/lsm6dsl.cxx
Normal file
@ -0,0 +1,215 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016-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 <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "lsm6dsl.hpp"
|
||||
|
||||
using namespace upm;
|
||||
using namespace std;
|
||||
|
||||
// conversion from Celsius to Fahrenheit
|
||||
|
||||
static float c2f(float c)
|
||||
{
|
||||
return (c * (9.0 / 5.0) + 32.0);
|
||||
}
|
||||
|
||||
LSM6DSL::LSM6DSL(int bus, int addr, int cs) :
|
||||
m_lsm6dsl(lsm6dsl_init(bus, addr, cs))
|
||||
{
|
||||
if (!m_lsm6dsl)
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_init() failed");
|
||||
}
|
||||
|
||||
LSM6DSL::~LSM6DSL()
|
||||
{
|
||||
lsm6dsl_close(m_lsm6dsl);
|
||||
}
|
||||
|
||||
void LSM6DSL::init(LSM6DSL_XL_ODR_T acc_odr, LSM6DSL_XL_FS_T acc_fs,
|
||||
LSM6DSL_G_ODR_T gyr_odr, LSM6DSL_G_FS_T gyr_fs)
|
||||
{
|
||||
if (lsm6dsl_devinit(m_lsm6dsl, acc_odr, acc_fs, gyr_odr, gyr_fs))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_devinit() failed");
|
||||
}
|
||||
|
||||
void LSM6DSL::update()
|
||||
{
|
||||
if (lsm6dsl_update(m_lsm6dsl))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_update() failed");
|
||||
}
|
||||
|
||||
uint8_t LSM6DSL::readReg(uint8_t reg)
|
||||
{
|
||||
return lsm6dsl_read_reg(m_lsm6dsl, reg);
|
||||
}
|
||||
|
||||
int LSM6DSL::readRegs(uint8_t reg, uint8_t *buffer, int len)
|
||||
{
|
||||
int rv = lsm6dsl_read_regs(m_lsm6dsl, reg, buffer, len);
|
||||
if (rv != len)
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_read_regs() failed");
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void LSM6DSL::writeReg(uint8_t reg, uint8_t val)
|
||||
{
|
||||
if (lsm6dsl_write_reg(m_lsm6dsl, reg, val))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_write_reg() failed");
|
||||
}
|
||||
|
||||
uint8_t LSM6DSL::getChipID()
|
||||
{
|
||||
return lsm6dsl_get_chip_id(m_lsm6dsl);
|
||||
}
|
||||
|
||||
void LSM6DSL::getAccelerometer(float *x, float *y, float *z)
|
||||
{
|
||||
lsm6dsl_get_accelerometer(m_lsm6dsl, x, y, z);
|
||||
}
|
||||
|
||||
std::vector<float> LSM6DSL::getAccelerometer()
|
||||
{
|
||||
float v[3];
|
||||
|
||||
getAccelerometer(&v[0], &v[1], &v[2]);
|
||||
return std::vector<float>(v, v+3);
|
||||
}
|
||||
|
||||
void LSM6DSL::getGyroscope(float *x, float *y, float *z)
|
||||
{
|
||||
lsm6dsl_get_gyroscope(m_lsm6dsl, x, y, z);
|
||||
}
|
||||
|
||||
std::vector<float> LSM6DSL::getGyroscope()
|
||||
{
|
||||
float v[3];
|
||||
|
||||
getGyroscope(&v[0], &v[1], &v[2]);
|
||||
return std::vector<float>(v, v+3);
|
||||
}
|
||||
|
||||
float LSM6DSL::getTemperature(bool fahrenheit)
|
||||
{
|
||||
float temperature = lsm6dsl_get_temperature(m_lsm6dsl);
|
||||
if (fahrenheit)
|
||||
return c2f(temperature);
|
||||
else
|
||||
return temperature;
|
||||
}
|
||||
|
||||
void LSM6DSL::reset()
|
||||
{
|
||||
if (lsm6dsl_reset(m_lsm6dsl))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_reset() failed");
|
||||
}
|
||||
|
||||
void LSM6DSL::setAccelerometerODR(LSM6DSL_XL_ODR_T odr)
|
||||
{
|
||||
if (lsm6dsl_set_acc_odr(m_lsm6dsl, odr))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_set_acc_odr() failed");
|
||||
}
|
||||
|
||||
void LSM6DSL::setAccelerometerFullScale(LSM6DSL_XL_FS_T fs)
|
||||
{
|
||||
if (lsm6dsl_set_acc_full_scale(m_lsm6dsl, fs))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_set_acc_full_scale() failed");
|
||||
}
|
||||
|
||||
void LSM6DSL::setGyroscopeODR(LSM6DSL_G_ODR_T odr)
|
||||
{
|
||||
if (lsm6dsl_set_gyr_odr(m_lsm6dsl, odr))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_set_gyr_odr() failed");
|
||||
}
|
||||
|
||||
void LSM6DSL::setGyroscopeFullScale(LSM6DSL_G_FS_T fs)
|
||||
{
|
||||
if (lsm6dsl_set_gyr_full_scale(m_lsm6dsl, fs))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_set_gyr_full_scale() failed");
|
||||
}
|
||||
|
||||
void LSM6DSL::setHighPerformance(bool enable)
|
||||
{
|
||||
if (lsm6dsl_high_performance(m_lsm6dsl, enable))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_high_performance() failed");
|
||||
}
|
||||
|
||||
void LSM6DSL::setInterruptActiveHigh(bool high)
|
||||
{
|
||||
if (lsm6dsl_set_interrupt_active_high(m_lsm6dsl, high))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_set_interrupt_active_high() failed");
|
||||
}
|
||||
|
||||
void LSM6DSL::setInterruptPushPull(bool pp)
|
||||
{
|
||||
if (lsm6dsl_set_interrupt_push_pull(m_lsm6dsl, pp))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_set_interrupt_push_pull() failed");
|
||||
}
|
||||
|
||||
uint8_t LSM6DSL::getStatus()
|
||||
{
|
||||
return lsm6dsl_get_status(m_lsm6dsl);
|
||||
}
|
||||
|
||||
void LSM6DSL::setAccelerometerOffsets(int x, int y, int z, bool weight)
|
||||
{
|
||||
if (lsm6dsl_set_acc_offsets(m_lsm6dsl, x, y, z, weight))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_set_acc_offsets() failed");
|
||||
}
|
||||
|
||||
void LSM6DSL::installISR(LSM6DSL_INTERRUPT_PINS_T intr, int gpio,
|
||||
mraa::Edge level,
|
||||
void (*isr)(void *), void *arg)
|
||||
{
|
||||
if (lsm6dsl_install_isr(m_lsm6dsl, intr, gpio,
|
||||
(mraa_gpio_edge_t)level, isr, arg))
|
||||
throw std::runtime_error(string(__FUNCTION__)
|
||||
+ ": lsm6dsl_install_isr() failed");
|
||||
}
|
||||
|
||||
void LSM6DSL::uninstallISR(LSM6DSL_INTERRUPT_PINS_T intr)
|
||||
{
|
||||
lsm6dsl_uninstall_isr(m_lsm6dsl, intr);
|
||||
}
|
360
src/lsm6dsl/lsm6dsl.h
Normal file
360
src/lsm6dsl/lsm6dsl.h
Normal file
@ -0,0 +1,360 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mraa/i2c.h>
|
||||
#include <mraa/spi.h>
|
||||
#include <mraa/gpio.h>
|
||||
|
||||
#include "upm.h"
|
||||
|
||||
#include "lsm6dsl_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @file lsm6dsl.h
|
||||
* @library lsm6dsl
|
||||
* @brief C API for the lsm6dsl driver
|
||||
*
|
||||
* @include lsm6dsl.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* Device context
|
||||
*/
|
||||
typedef struct _lsm6dsl_context {
|
||||
mraa_i2c_context i2c;
|
||||
mraa_spi_context spi;
|
||||
|
||||
mraa_gpio_context gpioCS; // SPI CS pin
|
||||
mraa_gpio_context gpioINT1; // intr 1
|
||||
mraa_gpio_context gpioINT2; // intr 2
|
||||
|
||||
// uncompensated temperature
|
||||
float temperature;
|
||||
|
||||
// uncompensated acc data
|
||||
float accX;
|
||||
float accY;
|
||||
float accZ;
|
||||
|
||||
// uncompensated gyr data
|
||||
float gyrX;
|
||||
float gyrY;
|
||||
float gyrZ;
|
||||
|
||||
// acc scaling
|
||||
float accScale;
|
||||
} *lsm6dsl_context;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param bus I2C or SPI bus to use
|
||||
* @param addr The address for this device, or -1 for SPI
|
||||
* @param cs The gpio pin to use for the SPI Chip Select. Use -1 for
|
||||
* I2C or for SPI with a hardware controlled pin.
|
||||
* @return The device context, or NULL on error
|
||||
*/
|
||||
lsm6dsl_context lsm6dsl_init(int bus, int addr, int cs);
|
||||
|
||||
/**
|
||||
* LSM6DSL Destructor
|
||||
*
|
||||
* @param dev The device context
|
||||
*/
|
||||
void lsm6dsl_close(lsm6dsl_context dev);
|
||||
|
||||
/**
|
||||
* Update the internal stored values from sensor data
|
||||
*
|
||||
* @param dev The device context
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_update(const lsm6dsl_context dev);
|
||||
|
||||
/**
|
||||
* Return the chip ID
|
||||
*
|
||||
* @param dev The device context
|
||||
* @return The chip ID (LSM6DSL_CHIPID)
|
||||
*/
|
||||
uint8_t lsm6dsl_get_chip_id(const lsm6dsl_context dev);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param acc_odr One of the LSM6DSL_XL_ODR_T values
|
||||
* @param acc_fs One of the LSM6DSL_XL_FS_T values
|
||||
* @param gyr_odr One of the LSM6DSL_G_ODR_T values
|
||||
* @param gyr_fs One of the LSM6DSL_G_FS_T values
|
||||
* @return UPM result
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Set the output data rate (ODR) of the accelerometer
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param odr One of the LSM6DSL_XL_ODR_T values
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_set_acc_odr(const lsm6dsl_context dev,
|
||||
LSM6DSL_XL_ODR_T odr);
|
||||
|
||||
/**
|
||||
* Set the output data rate (ODR) of the gyroscope
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param odr One of the LSM6DSL_G_ODR_T values
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_set_gyr_odr(const lsm6dsl_context dev,
|
||||
LSM6DSL_G_ODR_T odr);
|
||||
|
||||
/**
|
||||
* Set the full scale (FS) of the accelerometer. This device
|
||||
* supports a full scale of 2, 4, 8, and 16G.
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param fs One of the LSM6DSL_XL_FS_T values
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_set_acc_full_scale(const lsm6dsl_context dev,
|
||||
LSM6DSL_XL_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)
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param fs One of the LSM6DSL_G_FS_T values
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_set_gyr_full_scale(const lsm6dsl_context dev,
|
||||
LSM6DSL_G_FS_T fs);
|
||||
|
||||
/**
|
||||
* Return accelerometer data in gravities (g). lsm6dsl_update()
|
||||
* must have been called prior to calling this function.
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param x Pointer to a floating point value that will have the
|
||||
* current x component placed into it
|
||||
* @param y Pointer to a floating point value that will have the
|
||||
* current y component placed into it
|
||||
* @param z Pointer to a floating point value that will have the
|
||||
* current z component placed into it
|
||||
*/
|
||||
void lsm6dsl_get_accelerometer(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.
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param x Pointer to a floating point value that will have the
|
||||
* current x component placed into it
|
||||
* @param y Pointer to a floating point value that will have the
|
||||
* current y component placed into it
|
||||
* @param z Pointer to a floating point value that will have the
|
||||
* current z component placed into it
|
||||
*/
|
||||
void lsm6dsl_get_gyroscope(const lsm6dsl_context dev,
|
||||
float *x, float *y, float *z);
|
||||
|
||||
/**
|
||||
* Return the current measured temperature. Note, this is not
|
||||
* ambient temperature. lsm6dsl_update() must have been called
|
||||
* prior to calling this function.
|
||||
*
|
||||
* @param dev The device context
|
||||
* @return The temperature in degrees Celsius
|
||||
*/
|
||||
float lsm6dsl_get_temperature(const lsm6dsl_context dev);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param enable true to enable high performance mode, false otherwise
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_high_performance(const lsm6dsl_context dev,
|
||||
bool enable);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param dev The device context
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_reset(const lsm6dsl_context dev);
|
||||
|
||||
/**
|
||||
* Indicate whether the interrupt should be active high (default)
|
||||
* or active low. See the datasheet for details.
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param high true for active high, false for active low
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_set_interrupt_active_high(const lsm6dsl_context dev,
|
||||
bool high);
|
||||
|
||||
/**
|
||||
* Indicate whether interrupts are push-pull (default) or open
|
||||
* drain. See the datasheet for details.
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param pp true for push-pull, false for open-drain
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_set_interrupt_push_pull(const lsm6dsl_context dev,
|
||||
bool pp);
|
||||
|
||||
/**
|
||||
* Return the contents of the status register
|
||||
*
|
||||
* @param dev The device context
|
||||
* @return A bitmask of values from LSM6DSL_STATUS_BITS_T
|
||||
*/
|
||||
uint8_t lsm6dsl_get_status(const lsm6dsl_context dev);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param x X axis offset in the range -127 to 127
|
||||
* @param y Y axis offset in the range -127 to 127
|
||||
* @param z Z axis offset in the range -127 to 127
|
||||
* @param weight When true, the the offset will be weighted at
|
||||
* 2^-6 g/LSB, when false the weighting will be 2^-10 g/LSB
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_set_acc_offsets(const lsm6dsl_context dev,
|
||||
int x, int y, int z, bool weight);
|
||||
|
||||
|
||||
/**
|
||||
* Install an interrupt handler
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param intr One of the LSM6DSL_INTERRUPT_PINS_T values
|
||||
* specifying which interrupt pin you are installing
|
||||
* @param gpio GPIO pin to use as interrupt pin
|
||||
* @param level The 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.
|
||||
* @param isr The interrupt handler, accepting a void * argument
|
||||
* @param arg The argument to pass the the interrupt handler
|
||||
* @return UPM result
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Uninstall a previously installed interrupt handler
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param intr One of the LSM6DSL_INTERRUPT_PINS_T values
|
||||
* specifying which interrupt pin you are removing
|
||||
*/
|
||||
void lsm6dsl_uninstall_isr(const lsm6dsl_context dev,
|
||||
LSM6DSL_INTERRUPT_PINS_T intr);
|
||||
|
||||
/**
|
||||
* Read a register
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param reg The register to read
|
||||
* @return The value of the register
|
||||
*/
|
||||
uint8_t lsm6dsl_read_reg(const lsm6dsl_context dev, uint8_t reg);
|
||||
|
||||
/**
|
||||
* Read contiguous registers into a buffer
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param buffer The buffer to store the results
|
||||
* @param len The number of registers to read
|
||||
* @return The number of bytes read, or -1 on error
|
||||
*/
|
||||
int lsm6dsl_read_regs(const lsm6dsl_context dev, uint8_t reg,
|
||||
uint8_t *buffer, int len);
|
||||
|
||||
/**
|
||||
* Write to a register
|
||||
*
|
||||
* @param dev The device context
|
||||
* @param reg The register to write to
|
||||
* @param val The value to write
|
||||
* @return UPM result
|
||||
*/
|
||||
upm_result_t lsm6dsl_write_reg(const lsm6dsl_context dev,
|
||||
uint8_t reg, uint8_t val);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
353
src/lsm6dsl/lsm6dsl.hpp
Normal file
353
src/lsm6dsl/lsm6dsl.hpp
Normal file
@ -0,0 +1,353 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016-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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <mraa/gpio.hpp>
|
||||
#include "lsm6dsl.h"
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief ST Micro 3-axis Accelerometer
|
||||
* @defgroup lsm6dsl libupm-lsm6dsl
|
||||
* @ingroup i2c spi gpio stmicro accelerometer
|
||||
*/
|
||||
|
||||
/**
|
||||
* @library lsm6dsl
|
||||
* @sensor lsm6dsl
|
||||
* @comname Digital 3-axis Accelerometer and Gyroscope
|
||||
* @type accelerometer gyro
|
||||
* @man stmicro
|
||||
* @con i2c spi gpio
|
||||
* @web http://www.st.com/en/mems-and-sensors/lsm6dsl.html
|
||||
*
|
||||
* @brief API for the LSM6DSL 3-axis Accelerometer and Gyroscope
|
||||
*
|
||||
* The LSM6DSL is a system-in-package featuring a 3D digital
|
||||
* accelerometer and a 3D digital gyroscope performing at 0.65 mA
|
||||
* in high performance mode and enabling always-on low-power
|
||||
* features for an optimal motion experience for the consumer.
|
||||
|
||||
* 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.
|
||||
*
|
||||
* @snippet lsm6dsl.cxx Interesting
|
||||
*/
|
||||
|
||||
class LSM6DSL {
|
||||
public:
|
||||
|
||||
/**
|
||||
* LSM6DSL 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.
|
||||
*
|
||||
* @param bus I2C or SPI bus to use
|
||||
* @param addr The address for this device. -1 for SPI
|
||||
* @param cs The gpio pin to use for the SPI Chip Select. -1 for
|
||||
* I2C or for SPI with a hardware controlled pin.
|
||||
* @throws std::runtime_error on initialization failure
|
||||
*/
|
||||
LSM6DSL(int bus=LSM6DSL_DEFAULT_I2C_BUS,
|
||||
int addr=LSM6DSL_DEFAULT_I2C_ADDR,
|
||||
int cs=-1);
|
||||
|
||||
/**
|
||||
* LSM6DSL destructor
|
||||
*/
|
||||
virtual ~LSM6DSL();
|
||||
|
||||
/**
|
||||
* Update the internal stored values from sensor data
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Return the chip ID
|
||||
*
|
||||
* @return The chip ID
|
||||
*/
|
||||
uint8_t getChipID();
|
||||
|
||||
/**
|
||||
* Return accelerometer data in gravities. update() must have
|
||||
* been called prior to calling this method.
|
||||
*
|
||||
* @param x Pointer to a floating point value that will have the
|
||||
* current x component placed into it
|
||||
* @param y Pointer to a floating point value that will have the
|
||||
* current y component placed into it
|
||||
* @param z Pointer to a floating point value that will have the
|
||||
* current z component placed into it
|
||||
*/
|
||||
void getAccelerometer(float *x, float *y, float *z);
|
||||
|
||||
/**
|
||||
* Return accelerometer data in gravities in the form of a
|
||||
* floating point vector. update() must have been called
|
||||
* prior to calling this method.
|
||||
*
|
||||
* @return A floating point vector containing x, y, and z in
|
||||
* that order
|
||||
*/
|
||||
std::vector<float> getAccelerometer();
|
||||
|
||||
/**
|
||||
* Return gyroscope data in degrees per second (DPS).
|
||||
* update() must have been called prior to calling this
|
||||
* method.
|
||||
*
|
||||
* @param x Pointer to a floating point value that will have the
|
||||
* current x component placed into it
|
||||
* @param y Pointer to a floating point value that will have the
|
||||
* current y component placed into it
|
||||
* @param z Pointer to a floating point value that will have the
|
||||
* current z component placed into it
|
||||
*/
|
||||
void getGyroscope(float *x, float *y, float *z);
|
||||
|
||||
/**
|
||||
* Return gyroscope data in degrees per second in the form of
|
||||
* a floating point vector. update() must have been called
|
||||
* prior to calling this method.
|
||||
*
|
||||
* @return A floating point vector containing x, y, and z in
|
||||
* that order
|
||||
*/
|
||||
std::vector<float> getGyroscope();
|
||||
|
||||
/**
|
||||
* Return the current measured temperature. Note, this is not
|
||||
* ambient temperature. update() must have been called prior to
|
||||
* calling this method.
|
||||
*
|
||||
* @param fahrenheit true to return data in Fahrenheit, false for
|
||||
* Celicus. Celsius is the default.
|
||||
* @return The temperature in degrees Celsius or Fahrenheit
|
||||
*/
|
||||
float getTemperature(bool fahrenheit=false);
|
||||
|
||||
/**
|
||||
* Initialize the device and start operation. This function
|
||||
* is called from the constructor, 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.
|
||||
*
|
||||
* @param acc_odr One of the LSM6DSL_XL_ODR_T values
|
||||
* @param acc_fs One of the LSM6DSL_XL_FS_T values
|
||||
* @param gyr_odr One of the LSM6DSL_G_ODR_T values
|
||||
* @param gyr_fs One of the LSM6DSL_G_FS_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void init(LSM6DSL_XL_ODR_T acc_odr=LSM6DSL_XL_ODR_104HZ,
|
||||
LSM6DSL_XL_FS_T acc_fs=LSM6DSL_XL_FS_2G,
|
||||
LSM6DSL_G_ODR_T gyr_odr=LSM6DSL_G_ODR_104HZ,
|
||||
LSM6DSL_G_FS_T gyr_fs=LSM6DSL_G_FS_245DPS);
|
||||
|
||||
/**
|
||||
* Reset the device as if during a power on reset. All configured
|
||||
* values are lost when this happens. You should call init()
|
||||
* afterwards, or at least perform the same initialization init()
|
||||
* does before continuing.
|
||||
*
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* Set the output data rate (ODR) of the accelerometer
|
||||
*
|
||||
* @param odr One of the LSM6DSL_XL_ODR_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void setAccelerometerODR(LSM6DSL_XL_ODR_T odr);
|
||||
|
||||
/**
|
||||
* Set the full scale (FS) of the accelerometer. This device
|
||||
* supports a full scale of 2, 4, 8, and 16G.
|
||||
*
|
||||
* @param fs One of the LSM6DSL_XL_FS_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void setAccelerometerFullScale(LSM6DSL_XL_FS_T fs);
|
||||
|
||||
/**
|
||||
* Set the output data rate (ODR) of the gyroscope
|
||||
*
|
||||
* @param odr One of the LSM6DSL_G_ODR_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void setGyroscopeODR(LSM6DSL_G_ODR_T odr);
|
||||
|
||||
/**
|
||||
* Set the full scale (FS) of the gyroscope
|
||||
*
|
||||
* @param fs One of the LSM6DSL_G_FS_T values
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void setGyroscopeFullScale(LSM6DSL_G_FS_T fs);
|
||||
|
||||
/**
|
||||
* 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. This
|
||||
* is enabled by default in init().
|
||||
*
|
||||
* @param enable true to enable high performance mode, false otherwise
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void setHighPerformance(bool enable);
|
||||
|
||||
/**
|
||||
* Indicate whether the interrupt should be active high (default)
|
||||
* or active low. See the datasheet for details.
|
||||
*
|
||||
* @param high true for active high, false for active low
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void setInterruptActiveHigh(bool high);
|
||||
|
||||
/**
|
||||
* Indicate whether interrupts are push-pull (default) or open
|
||||
* drain. See the datasheet for details.
|
||||
*
|
||||
* @param pp true for push-pull, false for open-drain
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void setInterruptPushPull(bool pp);
|
||||
|
||||
/**
|
||||
* Return the contents of the status register
|
||||
*
|
||||
* @return A bitmask of values from LSM6DSL_STATUS_BITS_T
|
||||
*/
|
||||
uint8_t getStatus();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @param x X axis offset in the range -127 to 127
|
||||
* @param y Y axis offset in the range -127 to 127
|
||||
* @param z Z axis offset in the range -127 to 127
|
||||
* @param weight When true, the the offset will be weighted at
|
||||
* 2^-6 g/LSB, when false the weighting will be 2^-10 g/LSB
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void setAccelerometerOffsets(int x, int y, int z, bool weight);
|
||||
|
||||
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
void installISR(LSM6DSL_INTERRUPT_PINS_T intr, int gpio,
|
||||
mraa::Edge level, jobject runnable)
|
||||
{
|
||||
installISR(intr, gpio, level, mraa_java_isr_callback,
|
||||
runnable);
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* install an interrupt handler
|
||||
*
|
||||
* @param intr One of the LSM6DSL_INTERRUPT_PINS_T values
|
||||
* specifying which interrupt pin you are installing
|
||||
* @param gpio GPIO pin to use as interrupt pin
|
||||
* @param 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.
|
||||
* @param isr The interrupt handler, accepting a void * argument
|
||||
* @param arg The argument to pass the the interrupt handler
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void installISR(LSM6DSL_INTERRUPT_PINS_T intr, int gpio,
|
||||
mraa::Edge level,
|
||||
void (*isr)(void *), void *arg);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* uninstall a previously installed interrupt handler
|
||||
*
|
||||
* @param intr One of the LSM6DSL_INTERRUPT_PINS_T values
|
||||
* specifying which interrupt pin you are removing
|
||||
*/
|
||||
void uninstallISR(LSM6DSL_INTERRUPT_PINS_T intr);
|
||||
|
||||
/**
|
||||
* Read a register
|
||||
*
|
||||
* @param reg The register to read
|
||||
* @return The value of the register
|
||||
*/
|
||||
uint8_t readReg(uint8_t reg);
|
||||
|
||||
/**
|
||||
* Read contiguous registers into a buffer
|
||||
*
|
||||
* @param buffer The buffer to store the results
|
||||
* @param len The number of registers to read
|
||||
* @return The number of bytes read
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
int readRegs(uint8_t reg, uint8_t *buffer, int len);
|
||||
|
||||
/**
|
||||
* Write to a register
|
||||
*
|
||||
* @param reg The register to write to
|
||||
* @param val The value to write
|
||||
* @throws std::runtime_error on failure
|
||||
*/
|
||||
void writeReg(uint8_t reg, uint8_t val);
|
||||
|
||||
protected:
|
||||
lsm6dsl_context m_lsm6dsl;
|
||||
|
||||
private:
|
||||
// Adding a private function definition for java bindings
|
||||
#if defined(SWIGJAVA) || defined(JAVACALLBACK)
|
||||
void installISR(LSM6DSL_INTERRUPT_PINS_T intr, int gpio,
|
||||
mraa::Edge level,
|
||||
void (*isr)(void *), void *arg);
|
||||
#endif
|
||||
};
|
||||
}
|
685
src/lsm6dsl/lsm6dsl_defs.h
Normal file
685
src/lsm6dsl/lsm6dsl_defs.h
Normal file
@ -0,0 +1,685 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#define LSM6DSL_DEFAULT_I2C_BUS 0
|
||||
#define LSM6DSL_DEFAULT_SPI_BUS 0
|
||||
#define LSM6DSL_DEFAULT_I2C_ADDR 0x6a
|
||||
|
||||
#define LSM6DSL_CHIPID 0x6a
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// NOTE: Reserved registers must not be written into or permanent
|
||||
// damage can result. Reading from them may return indeterminate
|
||||
// values. Registers containing reserved bitfields must be
|
||||
// written as 0.
|
||||
|
||||
// This register map is not complete -- all registers are
|
||||
// enumerated, however not all register bitmaps are enumerated
|
||||
// here. Feel free to add any you need that are missing.
|
||||
|
||||
/**
|
||||
* LSM6DSL registers
|
||||
*/
|
||||
typedef enum {
|
||||
// 0x00 reserved
|
||||
|
||||
LSM6DSL_REG_FUNC_CFG_ACCESS = 0x01,
|
||||
|
||||
// 0x02-0x03 reserved
|
||||
|
||||
LSM6DSL_REG_SENSOR_SYNC_TIME_FRAME = 0x04,
|
||||
|
||||
LSM6DSL_REG_SENSOR_SYNC_RES_RATIO = 0x05,
|
||||
|
||||
LSM6DSL_REG_FIFO_CTRL1 = 0x06,
|
||||
LSM6DSL_REG_FIFO_CTRL2 = 0x07,
|
||||
LSM6DSL_REG_FIFO_CTRL3 = 0x08,
|
||||
LSM6DSL_REG_FIFO_CTRL4 = 0x09,
|
||||
LSM6DSL_REG_FIFO_CTRL5 = 0x0a,
|
||||
|
||||
LSM6DSL_REG_DRDY_PULSE_CFG_G = 0x0b,
|
||||
|
||||
// 0x0c reserved
|
||||
|
||||
LSM6DSL_REG_INT1_CTRL = 0x0d,
|
||||
LSM6DSL_REG_INT2_CTRL = 0x0e,
|
||||
|
||||
LSM6DSL_REG_WHO_AM_I = 0x0f,
|
||||
|
||||
LSM6DSL_REG_CTRL1_XL = 0x10,
|
||||
LSM6DSL_REG_CTRL2_G = 0x11,
|
||||
LSM6DSL_REG_CTRL3_C = 0x12,
|
||||
LSM6DSL_REG_CTRL4_C = 0x13,
|
||||
LSM6DSL_REG_CTRL5_C = 0x14,
|
||||
LSM6DSL_REG_CTRL6_C = 0x15,
|
||||
LSM6DSL_REG_CTRL7_G = 0x16,
|
||||
LSM6DSL_REG_CTRL8_XL = 0x17,
|
||||
LSM6DSL_REG_CTRL9_XL = 0x18,
|
||||
LSM6DSL_REG_CTRL10_C = 0x19,
|
||||
|
||||
LSM6DSL_REG_MASTER_CFG = 0x1a,
|
||||
LSM6DSL_REG_WAKE_UP_SRC = 0x1b,
|
||||
LSM6DSL_REG_TAP_SRC = 0x1c,
|
||||
LSM6DSL_REG_D6D_SRC = 0x1d,
|
||||
|
||||
LSM6DSL_REG_STATUS = 0x1e,
|
||||
|
||||
// 0x1f reserved
|
||||
|
||||
LSM6DSL_REG_OUT_TEMP_L = 0x20,
|
||||
LSM6DSL_REG_OUT_TEMP_H = 0x21,
|
||||
|
||||
LSM6DSL_REG_OUTX_L_G = 0x22,
|
||||
LSM6DSL_REG_OUTX_H_G = 0x23,
|
||||
LSM6DSL_REG_OUTY_L_G = 0x24,
|
||||
LSM6DSL_REG_OUTY_H_G = 0x25,
|
||||
LSM6DSL_REG_OUTZ_L_G = 0x26,
|
||||
LSM6DSL_REG_OUTZ_H_G = 0x27,
|
||||
|
||||
LSM6DSL_REG_OUTX_L_XL = 0x28,
|
||||
LSM6DSL_REG_OUTX_H_XL = 0x29,
|
||||
LSM6DSL_REG_OUTY_L_XL = 0x2a,
|
||||
LSM6DSL_REG_OUTY_H_XL = 0x2b,
|
||||
LSM6DSL_REG_OUTZ_L_XL = 0x2c,
|
||||
LSM6DSL_REG_OUTZ_H_XL = 0x2d,
|
||||
|
||||
LSM6DSL_REG_SENSORHUB1_REG = 0x2e,
|
||||
LSM6DSL_REG_SENSORHUB2_REG = 0x2f,
|
||||
LSM6DSL_REG_SENSORHUB3_REG = 0x30,
|
||||
LSM6DSL_REG_SENSORHUB4_REG = 0x31,
|
||||
LSM6DSL_REG_SENSORHUB5_REG = 0x32,
|
||||
LSM6DSL_REG_SENSORHUB6_REG = 0x33,
|
||||
LSM6DSL_REG_SENSORHUB7_REG = 0x34,
|
||||
LSM6DSL_REG_SENSORHUB8_REG = 0x35,
|
||||
LSM6DSL_REG_SENSORHUB9_REG = 0x36,
|
||||
LSM6DSL_REG_SENSORHUB10_REG = 0x37,
|
||||
LSM6DSL_REG_SENSORHUB11_REG = 0x38,
|
||||
LSM6DSL_REG_SENSORHUB12_REG = 0x39,
|
||||
|
||||
LSM6DSL_REG_FIFO_STATUS1 = 0x3a,
|
||||
LSM6DSL_REG_FIFO_STATUS2 = 0x3b,
|
||||
LSM6DSL_REG_FIFO_STATUS3 = 0x3c,
|
||||
LSM6DSL_REG_FIFO_STATUS4 = 0x3d,
|
||||
|
||||
LSM6DSL_REG_FIFO_DATA_OUT_L = 0x3e,
|
||||
LSM6DSL_REG_FIFO_DATA_OUT_H = 0x3f,
|
||||
|
||||
LSM6DSL_REG_TIMESTAMP0_REG = 0x40,
|
||||
LSM6DSL_REG_TIMESTAMP1_REG = 0x41,
|
||||
LSM6DSL_REG_TIMESTAMP2_REG = 0x42,
|
||||
|
||||
// 0x43-0x48 reserved
|
||||
|
||||
LSM6DSL_REG_STEP_TIMESTAMP_L = 0x49,
|
||||
LSM6DSL_REG_STEP_TIMESTAMP_H = 0x4a,
|
||||
|
||||
LSM6DSL_REG_STEP_COUNTER_L = 0x4b,
|
||||
LSM6DSL_REG_STEP_COUNTER_H = 0x4c,
|
||||
|
||||
LSM6DSL_REG_SENSORHUB13_REG = 0x4d,
|
||||
LSM6DSL_REG_SENSORHUB14_REG = 0x4e,
|
||||
LSM6DSL_REG_SENSORHUB15_REG = 0x4f,
|
||||
LSM6DSL_REG_SENSORHUB16_REG = 0x50,
|
||||
LSM6DSL_REG_SENSORHUB17_REG = 0x51,
|
||||
LSM6DSL_REG_SENSORHUB18_REG = 0x52,
|
||||
|
||||
LSM6DSL_REG_FUNC_SRC1 = 0x53,
|
||||
LSM6DSL_REG_FUNC_SRC2 = 0x54,
|
||||
|
||||
LSM6DSL_REG_WRIST_TILT_IA = 0x55,
|
||||
|
||||
// 0x56-0x57 reserved
|
||||
|
||||
LSM6DSL_REG_TAP_CFG = 0x58,
|
||||
LSM6DSL_REG_TAP_THS_6D = 0x59,
|
||||
|
||||
LSM6DSL_REG_INT_DUR2 = 0x5a,
|
||||
|
||||
LSM6DSL_REG_WAKE_UP_THS = 0x5b,
|
||||
LSM6DSL_REG_WAKE_UP_DUR = 0x5c,
|
||||
|
||||
LSM6DSL_REG_FREE_FALL = 0x5d,
|
||||
|
||||
LSM6DSL_REG_MD1_CFG = 0x5e,
|
||||
LSM6DSL_REG_MD2_CFG = 0x5f,
|
||||
|
||||
LSM6DSL_REG_MASTER_CMD_CODE = 0x60,
|
||||
LSM6DSL_REG_SENS_SYNC_SPI_ERROR_CODE = 0x61,
|
||||
|
||||
// 0x62-0x65 reserved
|
||||
|
||||
LSM6DSL_REG_OUT_MAG_RAW_X_L = 0x66,
|
||||
LSM6DSL_REG_OUT_MAG_RAW_X_H = 0x67,
|
||||
LSM6DSL_REG_OUT_MAG_RAW_Y_L = 0x68,
|
||||
LSM6DSL_REG_OUT_MAG_RAW_Y_H = 0x69,
|
||||
LSM6DSL_REG_OUT_MAG_RAW_Z_L = 0x6a,
|
||||
LSM6DSL_REG_OUT_MAG_RAW_Z_H = 0x6b,
|
||||
|
||||
// 0x6c-0x72 reserved
|
||||
|
||||
LSM6DSL_REG_X_OFS_USR = 0x73,
|
||||
LSM6DSL_REG_Y_OFS_USR = 0x74,
|
||||
LSM6DSL_REG_Z_OFS_USR = 0x75,
|
||||
|
||||
// 0x76-0x7f reserved
|
||||
} LSM6DSL_REGS_T;
|
||||
|
||||
/**
|
||||
* REG_FUNC_CFG_ACCESS bits
|
||||
*/
|
||||
typedef enum {
|
||||
// 0x00-0x10 reserved
|
||||
|
||||
LSM6DSL_FUNC_CFG_EN_B = 0x20,
|
||||
|
||||
// 0x4 reserved
|
||||
|
||||
LSM6DSL_FUNC_CFG_EN = 0x80,
|
||||
} LSM6DSL_FUNC_CFG_ACCESS_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_SENSOR_SYNC_TIME_FRAME bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_SENSOR_SYNC_TIME_FRAME0 = 0x01,
|
||||
LSM6DSL_SENSOR_SYNC_TIME_FRAME1 = 0x02,
|
||||
LSM6DSL_SENSOR_SYNC_TIME_FRAME2 = 0x04,
|
||||
LSM6DSL_SENSOR_SYNC_TIME_FRAME3 = 0x08,
|
||||
_LSM6DSL_SENSOR_SYNC_TIME_MASK = 15,
|
||||
_LSM6DSL_SENSOR_SYNC_TIME_SHIFT = 0,
|
||||
|
||||
// 0x10-0x80 reserved
|
||||
} LSM6DSL_SENSOR_SYNC_TIME_FRAME_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_DRDY_PULSE_CFG_G bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_DRDY_PULSE_CFG_G_INT2_WRIST_TILT = 0x01,
|
||||
|
||||
// 0x02-0x40 reserved
|
||||
|
||||
LSM6DSL_DRDY_PULSE_CFG_G_DRDY_PULSED = 0x80,
|
||||
} LSM6DSL_DRDY_PULSE_CFG_G_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_INT1_CTRL bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_INT1_CTRL_DRDY_XL = 0x01,
|
||||
LSM6DSL_INT1_CTRL_DRDY_G = 0x02,
|
||||
LSM6DSL_INT1_CTRL_BOOT = 0x04,
|
||||
LSM6DSL_INT1_CTRL_FTH = 0x08,
|
||||
LSM6DSL_INT1_CTRL_FIFO_OVR = 0x10,
|
||||
LSM6DSL_INT1_CTRL_FULL_FLAG = 0x20,
|
||||
LSM6DSL_INT1_CTRL_SIGN_MOT = 0x40,
|
||||
LSM6DSL_INT1_CTRL_STEP_DETECTOR = 0x80,
|
||||
} LSM6DSL_INT1_CTRL_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_INT2_CTRL bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_INT2_CTRL_DRDY_XL = 0x01,
|
||||
LSM6DSL_INT2_CTRL_DRDY_G = 0x02,
|
||||
LSM6DSL_INT2_CTRL_DRDY_TEMP = 0x04,
|
||||
LSM6DSL_INT2_CTRL_FTH = 0x08,
|
||||
LSM6DSL_INT2_CTRL_FIFO_OVR = 0x10,
|
||||
LSM6DSL_INT2_CTRL_FULL_FLAG = 0x20,
|
||||
LSM6DSL_INT2_CTRL_COUNT_OV = 0x40,
|
||||
LSM6DSL_INT2_CTRL_STEP_DELTA = 0x80,
|
||||
} LSM6DSL_INT2_CTRL_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_CTRL1_XL (accelerometer) bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_CTRL1_XL_BW0 = 0x01,
|
||||
LSM6DSL_CTRL1_XL_LPF1_BW_SEL = 0x02,
|
||||
|
||||
LSM6DSL_CTRL1_XL_FS0 = 0x04,
|
||||
LSM6DSL_CTRL1_XL_FS1 = 0x08,
|
||||
_LSM6DSL_CTRL1_XL_FS_MASK = 3,
|
||||
_LSM6DSL_CTRL1_XL_FS_SHIFT = 2,
|
||||
|
||||
LSM6DSL_CTRL1_XL_ODR0 = 0x10,
|
||||
LSM6DSL_CTRL1_XL_ODR1 = 0x20,
|
||||
LSM6DSL_CTRL1_XL_ODR2 = 0x40,
|
||||
LSM6DSL_CTRL1_XL_ODR3 = 0x80,
|
||||
_LSM6DSL_CTRL1_XL_ODR_MASK = 15,
|
||||
_LSM6DSL_CTRL1_XL_ODR_SHIFT = 4,
|
||||
} LSM6DSL_CTRL1_XL_BITS_T;
|
||||
|
||||
/**
|
||||
* CTRL1_XL_FS values (full scale)
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_XL_FS_2G = 0,
|
||||
LSM6DSL_XL_FS_16G = 1,
|
||||
LSM6DSL_XL_FS_4G = 2,
|
||||
LSM6DSL_XL_FS_8G = 3,
|
||||
} LSM6DSL_XL_FS_T;
|
||||
|
||||
/**
|
||||
* CTRL1_XL_ODR values (output data rate)
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_XL_ODR_POWER_DOWN = 0,
|
||||
LSM6DSL_XL_ODR_12_5HZ = 1,
|
||||
LSM6DSL_XL_ODR_26HZ = 2,
|
||||
LSM6DSL_XL_ODR_52HZ = 3,
|
||||
LSM6DSL_XL_ODR_104HZ = 4,
|
||||
LSM6DSL_XL_ODR_208HZ = 5,
|
||||
LSM6DSL_XL_ODR_416HZ = 6,
|
||||
LSM6DSL_XL_ODR_833HZ = 7,
|
||||
LSM6DSL_XL_ODR_1_66KHZ = 8,
|
||||
LSM6DSL_XL_ODR_3_33KHZ = 9,
|
||||
LSM6DSL_XL_ODR_6_66KHZ = 10,
|
||||
} LSM6DSL_XL_ODR_T;
|
||||
|
||||
/**
|
||||
* REG_CTRL2_G (gyroscope) bits
|
||||
*/
|
||||
typedef enum {
|
||||
// 0x01 reserved
|
||||
|
||||
LSM6DSL_CTRL2_G_FS_125 = 0x02,
|
||||
|
||||
LSM6DSL_CTRL2_G_FS0 = 0x04,
|
||||
LSM6DSL_CTRL2_G_FS1 = 0x08,
|
||||
_LSM6DSL_CTRL2_G_FS_MASK = 3,
|
||||
_LSM6DSL_CTRL2_G_FS_SHIFT = 2,
|
||||
|
||||
LSM6DSL_CTRL2_G_ODR0 = 0x10,
|
||||
LSM6DSL_CTRL2_G_ODR1 = 0x20,
|
||||
LSM6DSL_CTRL2_G_ODR2 = 0x40,
|
||||
LSM6DSL_CTRL2_G_ODR3 = 0x80,
|
||||
_LSM6DSL_CTRL2_G_ODR_MASK = 0x15,
|
||||
_LSM6DSL_CTRL2_G_ODR_SHIFT = 0x4,
|
||||
} LSM6DSL_CTRL2_G_BITS_T;
|
||||
|
||||
/**
|
||||
* CTRL2_G_FS values (full scale)
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_G_FS_245DPS = 0, // degrees per second
|
||||
LSM6DSL_G_FS_500DPS = 1,
|
||||
LSM6DSL_G_FS_1000DPS = 2,
|
||||
LSM6DSL_G_FS_2000DPS = 3,
|
||||
|
||||
// 125dps is a special case - it's just a bit you set or clear
|
||||
// to enable 125 or disable it. We add a virtual bit 3 (4)
|
||||
// here as a flag to the driver to enable/disable this
|
||||
// "special" FS setting.
|
||||
LSM6DSL_G_FS_125DPS = (4 + 0),
|
||||
} LSM6DSL_G_FS_T;
|
||||
|
||||
/**
|
||||
* CTRL2_G_ODR values (output data rate)
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_G_ODR_POWER_DOWN = 0,
|
||||
LSM6DSL_G_ODR_12_5HZ = 1,
|
||||
LSM6DSL_G_ODR_26HZ = 2,
|
||||
LSM6DSL_G_ODR_52HZ = 3,
|
||||
LSM6DSL_G_ODR_104HZ = 4,
|
||||
LSM6DSL_G_ODR_208HZ = 5,
|
||||
LSM6DSL_G_ODR_416HZ = 6,
|
||||
LSM6DSL_G_ODR_833HZ = 7,
|
||||
LSM6DSL_G_ODR_1_66KHZ = 8,
|
||||
LSM6DSL_G_ODR_3_33KHZ = 9,
|
||||
LSM6DSL_G_ODR_6_66KHZ = 10,
|
||||
} LSM6DSL_G_ODR_T;
|
||||
|
||||
/**
|
||||
* REG_CTRL3 (_C, common) bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_CTRL3_SW_RESET = 0x01,
|
||||
LSM6DSL_CTRL3_BLE = 0x02,
|
||||
LSM6DSL_CTRL3_IF_INC = 0x04,
|
||||
LSM6DSL_CTRL3_SIM = 0x08,
|
||||
LSM6DSL_CTRL3_PP_OD = 0x10,
|
||||
LSM6DSL_CTRL3_H_LACTIVE = 0x20,
|
||||
LSM6DSL_CTRL3_BDU = 0x40,
|
||||
LSM6DSL_CTRL3_BOOT = 0x80,
|
||||
} LSM6DSL_CTRL3_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_CTRL4 (_C, common) bits
|
||||
*/
|
||||
typedef enum {
|
||||
// 0x01 reserved
|
||||
|
||||
LSM6DSL_CTRL4_LPF1_SEL_G = 0x02,
|
||||
LSM6DSL_CTRL4_I2C_DISABLE = 0x04,
|
||||
LSM6DSL_CTRL4_DRDY_MASK = 0x08,
|
||||
LSM6DSL_CTRL4_DEN_SRSY_INT1 = 0x10,
|
||||
LSM6DSL_CTRL4_INT2_ON_INT1 = 0x20,
|
||||
LSM6DSL_CTRL4_SLEEP = 0x40,
|
||||
LSM6DSL_CTRL4_DEN_XL_EN = 0x80,
|
||||
} LSM6DSL_CTRL4_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_CTRL5 (_C, common) bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_CTRL5_ST_XL0 = 0x01,
|
||||
LSM6DSL_CTRL5_ST_XL1 = 0x02,
|
||||
_LSM6DSL_CTRL5_ST_XL_MASK = 3,
|
||||
_LSM6DSL_CTRL5_ST_XL_SHIFT = 0,
|
||||
|
||||
LSM6DSL_CTRL5_ST_G0 = 0x04,
|
||||
LSM6DSL_CTRL5_ST_G1 = 0x08,
|
||||
_LSM6DSL_CTRL5_ST_G_MASK = 3,
|
||||
_LSM6DSL_CTRL5_ST_G_SHIFT = 2,
|
||||
|
||||
LSM6DSL_CTRL5_DEN_LH = 0x10,
|
||||
|
||||
LSM6DSL_CTRL5_ROUNDING0 = 0x20,
|
||||
LSM6DSL_CTRL5_ROUNDING1 = 0x40,
|
||||
LSM6DSL_CTRL5_ROUNDING2 = 0x80,
|
||||
_LSM6DSL_CTRL5_ROUNDING_MASK = 7,
|
||||
_LSM6DSL_CTRL5_ROUNDING_SHIFT = 5,
|
||||
} LSM6DSL_CTRL5_BITS_T;
|
||||
|
||||
/**
|
||||
* CTRL5_ST_XL values (self test accelerometer)
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_ST_XL_NORMAL = 0,
|
||||
LSM6DSL_ST_XL_POSITIVE = 1,
|
||||
LSM6DSL_ST_XL_NEGATIVE = 2,
|
||||
} LSM6DSL_ST_XL_T;
|
||||
|
||||
/**
|
||||
* CTRL5_ST_G values (self test gyroscope)
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_ST_G_NORMAL = 0,
|
||||
LSM6DSL_ST_G_POSITIVE = 1,
|
||||
LSM6DSL_ST_G_NEGATIVE = 3,
|
||||
} LSM6DSL_ST_G_T;
|
||||
|
||||
/**
|
||||
* REG_CTRL6 (_C, common) bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_CTRL6_FTYPE0 = 0x01, // gyr lp filter
|
||||
LSM6DSL_CTRL6_FTYPE1 = 0x02,
|
||||
_LSM6DSL_CTRL6_FTYPE_MASK = 3,
|
||||
_LSM6DSL_CTRL6_FTYPE_SHIFT = 0,
|
||||
|
||||
// 0x04 reserved
|
||||
|
||||
LSM6DSL_CTRL6_USR_OFF_W = 0x08,
|
||||
|
||||
LSM6DSL_CTRL6_XL_HM_MODE = 0x10,
|
||||
LSM6DSL_CTRL6_LVL2_EN = 0x20,
|
||||
LSM6DSL_CTRL6_LVLEN = 0x40,
|
||||
LSM6DSL_CTRL6_TRIG_EN = 0x80,
|
||||
} LSM6DSL_CTRL6_BITS_T;
|
||||
|
||||
/**
|
||||
* CTRL6_FTYPE values (see table 68 in the datasheet, depends on ODR)
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_FTYPE_00 = 0,
|
||||
LSM6DSL_FTYPE_01 = 1,
|
||||
LSM6DSL_FTYPE_10 = 2,
|
||||
LSM6DSL_FTYPE_11 = 3,
|
||||
} LSM6DSL_FTYPE_T;
|
||||
|
||||
/**
|
||||
* REG_CTRL7_G bits
|
||||
*/
|
||||
typedef enum {
|
||||
// 0x01-0x02 reserved
|
||||
|
||||
LSM6DSL_CTRL7_G_ROUNDING_STATUS = 0x04,
|
||||
|
||||
// 0x08 reserved
|
||||
|
||||
LSM6DSL_CTRL7_G_HPM0 = 0x10,
|
||||
LSM6DSL_CTRL7_G_HPM1 = 0x20,
|
||||
_LSM6DSL_CTRL7_G_HPM_MASK = 3,
|
||||
_LSM6DSL_CTRL7_G_HPM_SHIFT = 4,
|
||||
|
||||
LSM6DSL_CTRL7_G_HP_EN = 0x40,
|
||||
LSM6DSL_CTRL7_G_HM_MODE = 0x80,
|
||||
} LSM6DSL_CTRL7_G_BITS_T;
|
||||
|
||||
/**
|
||||
* CTRL7_G_HPM values (high pass cutoff, in high performance mode only)
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_G_HPM_16MHZ = 0, // 16 mHZ
|
||||
LSM6DSL_G_HPM_65MHZ = 1,
|
||||
LSM6DSL_G_HPM_260MHZ = 2,
|
||||
LSM6DSL_G_HPM_1_04HZ = 3, // 1.04HZ
|
||||
} LSM6DSL_G_HPM_T;
|
||||
|
||||
/**
|
||||
* REG_CTRL8_XL bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_CTRL8_XL_LOW_PASS_ON_6D = 0x01,
|
||||
|
||||
// 0x02 reserved
|
||||
|
||||
LSM6DSL_CTRL8_XL_HP_SLOPE_EN = 0x04,
|
||||
|
||||
LSM6DSL_CTRL8_INPUT_COMPOSITE = 0x08,
|
||||
|
||||
LSM6DSL_CTRL8_HP_REF_MODE = 0x10,
|
||||
|
||||
LSM6DSL_CTRL8_XL_HPCF0 = 0x20,
|
||||
LSM6DSL_CTRL8_XL_HPCF1 = 0x40,
|
||||
_LSM6DSL_CTRL8_XL_HPCF_MASK = 3,
|
||||
_LSM6DSL_CTRL8_XL_HPCF_SHIFT = 5,
|
||||
|
||||
LSM6DSL_CTRL8_XL_LPF2_EN = 0x80,
|
||||
} LSM6DSL_CTRL8_XL_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_CTRL9_XL bits
|
||||
*/
|
||||
typedef enum {
|
||||
// 0x01-0x02 reserved
|
||||
|
||||
LSM6DSL_CTRL9_XL_SOFT_EN = 0x04,
|
||||
|
||||
// 0x08 reserved
|
||||
|
||||
LSM6DSL_CTRL9_XL_DEN_XL_G = 0x10,
|
||||
LSM6DSL_CTRL9_XL_DEN_Z = 0x20,
|
||||
LSM6DSL_CTRL9_XL_DEN_Y = 0x40,
|
||||
LSM6DSL_CTRL9_XL_DEN_X = 0x80,
|
||||
} LSM6DSL_CTRL9_XL_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_CTRL10_C bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_CTRL10_C_SIGN_MOT_EN = 0x01,
|
||||
LSM6DSL_CTRL10_C_PEDO_RST_STEP = 0x02,
|
||||
LSM6DSL_CTRL10_C_FUNC_EN = 0x04,
|
||||
LSM6DSL_CTRL10_C_TILT_EN = 0x08,
|
||||
LSM6DSL_CTRL10_C_PEDO_EN = 0x10,
|
||||
LSM6DSL_CTRL10_C_TIMER_EN = 0x20,
|
||||
|
||||
// 0x40 reserved
|
||||
|
||||
LSM6DSL_CTRL10_C_WRIST_TILT_EN = 0x80,
|
||||
} LSM6DSL_CTRL10_G_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_MASTER_CONFIG bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_MASTER_CONFIG_MASTER_ON = 0x01,
|
||||
LSM6DSL_MASTER_CONFIG_IRON_EN = 0x02,
|
||||
LSM6DSL_MASTER_CONFIG_PASS_THROUGH_MODE = 0x04,
|
||||
LSM6DSL_MASTER_CONFIG_PULL_UP_EN = 0x08,
|
||||
LSM6DSL_MASTER_CONFIG_START_CONFIG = 0x10,
|
||||
|
||||
// 0x20 reserved
|
||||
|
||||
LSM6DSL_MASTER_CONFIG_DATA_VALID_SEL_FIFO = 0x40,
|
||||
LSM6DSL_MASTER_CONFIG_DRDY_ON_INT1 = 0x80,
|
||||
} LSM6DSL_MASTER_CONFIG_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_WAKE_UP_SRC bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_WAKE_UP_SRC_Z_WU = 0x01,
|
||||
LSM6DSL_WAKE_UP_SRC_Y_WU = 0x02,
|
||||
LSM6DSL_WAKE_UP_SRC_X_WU = 0x04,
|
||||
LSM6DSL_WAKE_UP_SRC_WU_IA = 0x08,
|
||||
LSM6DSL_WAKE_UP_SRC_SLEEP_STATE_IA = 0x10,
|
||||
LSM6DSL_WAKE_UP_SRC_FF_AA = 0x20,
|
||||
|
||||
// 0x40-0x80 reserved
|
||||
} LSM6DSL_WAKE_UP_SRC_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_TAP_SRC bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_TAP_SRC_Z_TAP = 0x01,
|
||||
LSM6DSL_TAP_SRC_Y_TAP = 0x02,
|
||||
LSM6DSL_TAP_SRC_X_TAP = 0x04,
|
||||
LSM6DSL_TAP_SRC_TAP_SIGN = 0x08,
|
||||
LSM6DSL_TAP_SRC_DOUBLE_TAP = 0x10,
|
||||
LSM6DSL_TAP_SRC_SINGLE_TAP = 0x20,
|
||||
LSM6DSL_TAP_SRC_TAP_IA = 0x40,
|
||||
|
||||
// 0x80 reserved
|
||||
} LSM6DSL_TAP_SRC_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_D6D_SRC bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_D6D_SRC_XL = 0x01,
|
||||
LSM6DSL_D6D_SRC_XH = 0x02,
|
||||
LSM6DSL_D6D_SRC_YL = 0x04,
|
||||
LSM6DSL_D6D_SRC_YH = 0x08,
|
||||
LSM6DSL_D6D_SRC_ZL = 0x10,
|
||||
LSM6DSL_D6D_SRC_ZH = 0x20,
|
||||
LSM6DSL_D6D_SRC_D6D_IA = 0x40,
|
||||
|
||||
// 0x80 reserved
|
||||
} LSM6DSL_D6D_SRC_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_STATUS bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_STATUS_XLDA = 0x01, // acc data avail
|
||||
LSM6DSL_STATUS_GDA = 0x02, // gyr data avail
|
||||
LSM6DSL_STATUS_TDA = 0x04, // temp data avail
|
||||
|
||||
// 0x08-0x80 reserved
|
||||
} LSM6DSL_STATUS_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_FUNC_SRC1 bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_FUNC_SRC1_SENSORHUB_END_OP = 0x01,
|
||||
LSM6DSL_FUNC_SRC1_SI_END_OP = 0x02,
|
||||
|
||||
LSM6DSL_FUNC_SRC1_HI_FAIL = 0x04,
|
||||
|
||||
LSM6DSL_FUNC_SRC1_STEP_OVERFLOW = 0x08,
|
||||
LSM6DSL_FUNC_SRC1_STEP_DETECTED = 0x10,
|
||||
LSM6DSL_FUNC_SRC1_TILT_IA = 0x20,
|
||||
LSM6DSL_FUNC_SRC1_SIGN_MOTION_IA = 0x40,
|
||||
LSM6DSL_FUNC_SRC1_STEP_COUNT_DELTA_IA = 0x80,
|
||||
} LSM6DSL_FUNC_SRC1_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_FUNC_SRC2 bits
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_FUNC_SRC2_WRIST_TILT_IA = 0x01,
|
||||
|
||||
// 0x02-0x04 reserved
|
||||
|
||||
LSM6DSL_FUNC_SRC2_SLAVE0_NACK = 0x08,
|
||||
LSM6DSL_FUNC_SRC2_SLAVE1_NACK = 0x10,
|
||||
LSM6DSL_FUNC_SRC2_SLAVE2_NACK = 0x20,
|
||||
LSM6DSL_FUNC_SRC2_SLAVE3_NACK = 0x40,
|
||||
|
||||
// 0x80 reserved
|
||||
} LSM6DSL_FUNC_SRC2_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_MD1_CFG bits (function routing to INT1). We are omitting
|
||||
* the "INT1" redundancy in these item names.
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_MD1_CFG_TIMER = 0x01,
|
||||
LSM6DSL_MD1_CFG_TILT = 0x02,
|
||||
LSM6DSL_MD1_CFG_6D = 0x04,
|
||||
LSM6DSL_MD1_CFG_DOUBLE_TAP = 0x08,
|
||||
LSM6DSL_MD1_CFG_FF = 0x10,
|
||||
LSM6DSL_MD1_CFG_WU = 0x20,
|
||||
LSM6DSL_MD1_CFG_SINGLE_TAP = 0x40,
|
||||
LSM6DSL_MD1_CFG_INACT_STATE = 0x80,
|
||||
} LSM6DSL_MD1_CFG_BITS_T;
|
||||
|
||||
/**
|
||||
* REG_MD2_CFG bits (function routing to INT2). We are omitting
|
||||
* the "INT2" redundancy in these item names.
|
||||
*/
|
||||
typedef enum {
|
||||
LSM6DSL_MD2_CFG_IRON = 0x01,
|
||||
LSM6DSL_MD2_CFG_TILT = 0x02,
|
||||
LSM6DSL_MD2_CFG_6D = 0x04,
|
||||
LSM6DSL_MD2_CFG_DOUBLE_TAP = 0x08,
|
||||
LSM6DSL_MD2_CFG_FF = 0x10,
|
||||
LSM6DSL_MD2_CFG_WU = 0x20,
|
||||
LSM6DSL_MD2_CFG_SINGLE_TAP = 0x40,
|
||||
LSM6DSL_MD2_CFG_INACT_STATE = 0x80,
|
||||
} LSM6DSL_MD2_CFG_BITS_T;
|
||||
|
||||
// interrupt selection for installISR() and uninstallISR()
|
||||
typedef enum {
|
||||
LSM6DSL_INTERRUPT_INT1,
|
||||
LSM6DSL_INTERRUPT_INT2
|
||||
} LSM6DSL_INTERRUPT_PINS_T;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
127
src/lsm6dsl/lsm6dsl_fti.c
Normal file
127
src/lsm6dsl/lsm6dsl_fti.c
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 "lsm6dsl.h"
|
||||
#include "upm_fti.h"
|
||||
|
||||
/**
|
||||
* This file implements the Function Table Interface (FTI) for this sensor
|
||||
*/
|
||||
|
||||
const char upm_lsm6dsl_name[] = "LSM6DSL";
|
||||
const char upm_lsm6dsl_description[] =
|
||||
"Triple Axis Digital Accelerometer and Gyroscope";
|
||||
const upm_protocol_t upm_lsm6dsl_protocol[] = {UPM_I2C, UPM_SPI, UPM_GPIO};
|
||||
const upm_sensor_t upm_lsm6dsl_category[] = {UPM_ACCELEROMETER,
|
||||
UPM_GYROSCOPE};
|
||||
|
||||
// forward declarations
|
||||
const void *upm_lsm6dsl_get_ft(upm_sensor_t sensor_type);
|
||||
void *upm_lsm6dsl_init_name();
|
||||
void upm_lsm6dsl_close(void *dev);
|
||||
upm_result_t upm_lsm6dsl_get_acc_value(void *dev, float *value,
|
||||
upm_acceleration_u unit);
|
||||
upm_result_t upm_lsm6dsl_get_gyr_value(void *dev, float *value);
|
||||
|
||||
const upm_sensor_descriptor_t upm_lsm6dsl_get_descriptor()
|
||||
{
|
||||
upm_sensor_descriptor_t usd;
|
||||
usd.name = upm_lsm6dsl_name;
|
||||
usd.description = upm_lsm6dsl_description;
|
||||
usd.protocol_size = 3;
|
||||
usd.protocol = upm_lsm6dsl_protocol;
|
||||
usd.category_size = 2;
|
||||
usd.category = upm_lsm6dsl_category;
|
||||
return usd;
|
||||
}
|
||||
|
||||
static const upm_sensor_ft ft =
|
||||
{
|
||||
.upm_sensor_init_name = upm_lsm6dsl_init_name,
|
||||
.upm_sensor_close = upm_lsm6dsl_close,
|
||||
};
|
||||
|
||||
static const upm_acceleration_ft aft =
|
||||
{
|
||||
.upm_acceleration_get_value = upm_lsm6dsl_get_acc_value
|
||||
};
|
||||
|
||||
static const upm_gyroscope_ft gft =
|
||||
{
|
||||
.upm_gyroscope_get_value = upm_lsm6dsl_get_gyr_value
|
||||
};
|
||||
|
||||
const void *upm_lsm6dsl_get_ft(upm_sensor_t sensor_type)
|
||||
{
|
||||
switch(sensor_type)
|
||||
{
|
||||
case UPM_SENSOR:
|
||||
return &ft;
|
||||
|
||||
case UPM_ACCELEROMETER:
|
||||
return &aft;
|
||||
|
||||
case UPM_GYROSCOPE:
|
||||
return &gft;
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void *upm_lsm6dsl_init_name()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void upm_lsm6dsl_close(void *dev)
|
||||
{
|
||||
lsm6dsl_close((lsm6dsl_context)dev);
|
||||
}
|
||||
|
||||
upm_result_t upm_lsm6dsl_get_acc_value(void *dev, float *value,
|
||||
upm_acceleration_u unit)
|
||||
{
|
||||
if (lsm6dsl_update((lsm6dsl_context)dev))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
// no conversion facility in place yet, so we don't do anything
|
||||
// with units
|
||||
|
||||
lsm6dsl_get_accelerometer(dev, &value[0], &value[1], &value[2]);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
||||
|
||||
upm_result_t upm_lsm6dsl_get_gyr_value(void *dev, float *value)
|
||||
{
|
||||
if (lsm6dsl_update((lsm6dsl_context)dev))
|
||||
return UPM_ERROR_OPERATION_FAILED;
|
||||
|
||||
lsm6dsl_get_gyroscope(dev, &value[0], &value[1], &value[2]);
|
||||
|
||||
return UPM_SUCCESS;
|
||||
}
|
17
src/lsm6dsl/pyupm_lsm6dsl.i
Normal file
17
src/lsm6dsl/pyupm_lsm6dsl.i
Normal file
@ -0,0 +1,17 @@
|
||||
// Include doxygen-generated documentation
|
||||
%include "pyupm_doxy2swig.i"
|
||||
%module pyupm_lsm6dsl
|
||||
%include "../upm.i"
|
||||
%include "../upm_vectortypes.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
#ifdef DOXYGEN
|
||||
%include "lsm6dsl_doc.i"
|
||||
#endif
|
||||
|
||||
%include "lsm6dsl_defs.h"
|
||||
%include "lsm6dsl.hpp"
|
||||
%{
|
||||
#include "lsm6dsl.hpp"
|
||||
%}
|
Loading…
x
Reference in New Issue
Block a user