diff --git a/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino b/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino new file mode 100644 index 00000000..87070456 --- /dev/null +++ b/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino @@ -0,0 +1,73 @@ +/* + Copyright (c) 2015 Intel Corporation. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* + This sketch example demonstrates how the BMI160 on the + Intel(R) Curie(TM) module can be used to read accelerometer data +*/ + +#include "CurieIMU.h" + +void setup() { + Serial.begin(9600); // initialize Serial communication + while (!Serial); // wait for the serial port to open + + // initialize device + Serial.println("Initializing IMU device..."); + CurieIMU.begin(); + + // Set the accelerometer range to 2G + CurieIMU.setAccelerometerRange(CURIE_IMU_ACCELEROMETER_RANGE_2G); +} + +void loop() { + int axRaw, ayRaw, azRaw; // raw accelerometer values + float ax, ay, az; + + // read raw accelerometer measurements from device + CurieIMU.readAccelerometer(axRaw, ayRaw, azRaw); + + // convert the raw accelerometer data to G's + ax = convertRawAcceleration(axRaw); + ay = convertRawAcceleration(ayRaw); + az = convertRawAcceleration(azRaw); + + // display tab-separated accelerometer x/y/z values + Serial.print("a:\t"); + Serial.print(ax); + Serial.print("\t"); + Serial.print(ay); + Serial.print("\t"); + Serial.print(az); + Serial.println(); + + // wait 5 seconds + delay(5000); +} + +float convertRawAcceleration(int aRaw) { + // since we are using 2G range + // -2g maps to a raw value of -32768 + // +2g maps to a raw value of 32767 + + float a = (aRaw * 2.0) / 32768.0; + + return a; +} + diff --git a/libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino b/libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino new file mode 100644 index 00000000..a3fcf006 --- /dev/null +++ b/libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino @@ -0,0 +1,100 @@ +/* + Copyright (c) 2015 Intel Corporation. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* + This sketch example demonstrates how the BMI160 on the + Intel(R) Curie(TM) module can be used to read accelerometer data + and translate it to an orientation +*/ + +#include "CurieIMU.h" + +int lastOrientation = - 1; // previous orientation (for comparison) + +void setup() { + Serial.begin(9600); // initialize Serial communication + while (!Serial); // wait for the serial port to open + + // initialize device + Serial.println("Initializing IMU device..."); + CurieIMU.begin(); + + // Set the accelerometer range to 2G + CurieIMU.setAccelerometerRange(CURIE_IMU_ACCELEROMETER_RANGE_2G); +} + +void loop() { +int orientation = - 1; // the board's orientation + String orientationString; // string for printing description of orientation + /* + The orientations of the board: + 0: flat, processor facing up + 1: flat, processor facing down + 2: landscape, analog pins down + 3: landscape, analog pins up + 4: portrait, USB connector up + 5: portrait, USB connector down + */ + // read accelerometer: + int x = CurieIMU.readAccelerometer(X_AXIS); + int y = CurieIMU.readAccelerometer(Y_AXIS); + int z = CurieIMU.readAccelerometer(Z_AXIS); + + // calculate the absolute values, to determine the largest + int absX = abs(x); + int absY = abs(y); + int absZ = abs(z); + + if ( (absZ > absX) && (absZ > absY)) { + // base orientation on Z + if (z > 0) { + orientationString = "up"; + orientation = 0; + } else { + orientationString = "down"; + orientation = 1; + } + } else if ( (absY > absX) && (absY > absZ)) { + // base orientation on Y + if (y > 0) { + orientationString = "digital pins up"; + orientation = 2; + } else { + orientationString = "analog pins up"; + orientation = 3; + } + } else { + // base orientation on X + if (x < 0) { + orientationString = "connector up"; + orientation = 4; + } else { + orientationString = "connector down"; + orientation = 5; + } + } + + // if the orientation has changed, print out a description: + if (orientation != lastOrientation) { + Serial.println(orientationString); + lastOrientation = orientation; + } +} + + diff --git a/libraries/CurieIMU/examples/Gyro/Gyro.ino b/libraries/CurieIMU/examples/Gyro/Gyro.ino new file mode 100644 index 00000000..07371f24 --- /dev/null +++ b/libraries/CurieIMU/examples/Gyro/Gyro.ino @@ -0,0 +1,73 @@ +/* + Copyright (c) 2015 Intel Corporation. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* + This sketch example demonstrates how the BMI160 on the + Intel(R) Curie(TM) module can be used to read gyroscope data +*/ + +#include "CurieIMU.h" + +void setup() { + Serial.begin(9600); // initialize Serial communication + while (!Serial); // wait for the serial port to open + + // initialize device + Serial.println("Initializing IMU device..."); + CurieIMU.begin(); + + // Set the accelerometer range to 250 degrees/second + CurieIMU.setGyroRange(CURIE_IMU_GYRO_RANGE_250); +} + +void loop() { + int gxRaw, gyRaw, gzRaw; // raw gyro values + float gx, gy, gz; + + // read raw gyro measurements from device + CurieIMU.readGyro(gxRaw, gyRaw, gzRaw); + + // convert the raw gyro data to degrees/second + gx = convertRawGyro(gxRaw); + gy = convertRawGyro(gyRaw); + gz = convertRawGyro(gzRaw); + + // display tab-separated gyro x/y/z values + Serial.print("g:\t"); + Serial.print(gx); + Serial.print("\t"); + Serial.print(gy); + Serial.print("\t"); + Serial.print(gz); + Serial.println(); + + // wait 5 seconds + delay(5000); +} + +float convertRawGyro(int gRaw) { + // since we are using 250 degrees/seconds range + // -250 maps to a raw value of -32768 + // +250 maps to a raw value of 32767 + + float g = (gRaw * 250.0) / 32768.0; + + return g; +} + diff --git a/libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino b/libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino new file mode 100644 index 00000000..3ef1ac46 --- /dev/null +++ b/libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino @@ -0,0 +1,155 @@ +/* + =============================================== + Example sketch for CurieIMU library for Intel(R) Curie(TM) devices. + Copyright (c) 2015 Intel Corporation. All rights reserved. + + Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 + class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib + + =============================================== + I2Cdev device library code is placed under the MIT license + Copyright (c) 2011 Jeff Rowberg + + 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 "CurieIMU.h" +int ax, ay, az; // accelerometer values +int gx, gy, gz; // gyrometer values + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + +int calibrateOffsets = 1; // int to determine whether calibration takes place or not + +void setup() { + Serial.begin(9600); // initialize Serial communication + while (!Serial); // wait for the serial port to open + + // initialize device + Serial.println("Initializing IMU device..."); + CurieIMU.begin(); + + // verify connection + Serial.println("Testing device connections..."); + if (CurieIMU.begin()) { + Serial.println("CurieIMU connection successful"); + } else { + Serial.println("CurieIMU connection failed"); + } + + // use the code below to calibrate accel/gyro offset values + if (calibrateOffsets == 1) { + Serial.println("Internal sensor offsets BEFORE calibration..."); + Serial.print(CurieIMU.getAccelerometerOffset(X_AXIS)); + Serial.print("\t"); // -76 + Serial.print(CurieIMU.getAccelerometerOffset(Y_AXIS)); + Serial.print("\t"); // -235 + Serial.print(CurieIMU.getAccelerometerOffset(Z_AXIS)); + Serial.print("\t"); // 168 + Serial.print(CurieIMU.getGyroOffset(X_AXIS)); + Serial.print("\t"); // 0 + Serial.print(CurieIMU.getGyroOffset(Y_AXIS)); + Serial.print("\t"); // 0 + Serial.println(CurieIMU.getGyroOffset(Z_AXIS)); + + // To manually configure offset compensation values, + // use the following methods instead of the autoCalibrate...() methods below + //CurieIMU.setAccelerometerOffset(X_AXIS,128); + //CurieIMU.setAccelerometerOffset(Y_AXIS,-4); + //CurieIMU.setAccelerometerOffset(Z_AXIS,127); + //CurieIMU.setGyroOffset(X_AXIS,129); + //CurieIMU.setGyroOffset(Y_AXIS,-1); + //CurieIMU.setGyroOffset(Z_AXIS, 254); + + Serial.println("About to calibrate. Make sure your board is stable and upright"); + delay(5000); + + // The board must be resting in a horizontal position for + // the following calibration procedure to work correctly! + Serial.print("Starting Gyroscope calibration..."); + CurieIMU.autoCalibrateGyroOffset(); + Serial.println(" Done"); + + Serial.print("Starting Acceleration calibration..."); + CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS, 0); + CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS, 0); + CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS, 1); + Serial.println(" Done"); + + Serial.println("Internal sensor offsets AFTER calibration..."); + Serial.print(CurieIMU.getAccelerometerOffset(X_AXIS)); + Serial.print("\t"); // -76 + Serial.print(CurieIMU.getAccelerometerOffset(Y_AXIS)); + Serial.print("\t"); // -2359 + Serial.print(CurieIMU.getAccelerometerOffset(Z_AXIS)); + Serial.print("\t"); // 1688 + Serial.print(CurieIMU.getGyroOffset(X_AXIS)); + Serial.print("\t"); // 0 + Serial.print(CurieIMU.getGyroOffset(Y_AXIS)); + Serial.print("\t"); // 0 + Serial.println(CurieIMU.getGyroOffset(Z_AXIS)); + + Serial.println("Enabling Gyroscope/Acceleration offset compensation"); + CurieIMU.enableGyroOffset(true); + CurieIMU.enableAccelerometerOffset(true); + + Serial.println(CurieIMU.accelerometerOffsetEnabled()); + Serial.println(CurieIMU.gyroOffsetEnabled()); + } + + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); +} + +void loop() { + // read raw accel/gyro measurements from device + CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz); + + // these methods (and a few others) are also available + + //CurieIMU.readAcceleration(ax, ay, az); + //CurieIMU.readRotation(gx, gy, gz); + + //ax = CurieIMU.readAccelerometer(X_AXIS); + //ay = CurieIMU.readAccelerometer(Y_AXIS); + //az = CurieIMU.readAccelerometer(Z_AXIS); + //gx = CurieIMU.readGyro(X_AXIS); + //gy = CurieIMU.readGyro(Y_AXIS); + //gz = CurieIMU.readGyro(Z_AXIS); + + // display tab-separated accel/gyro x/y/z values + Serial.print("a/g:\t"); + Serial.print(ax); + Serial.print("\t"); + Serial.print(ay); + Serial.print("\t"); + Serial.print(az); + Serial.print("\t"); + Serial.print(gx); + Serial.print("\t"); + Serial.print(gy); + Serial.print("\t"); + Serial.println(gz); + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); +} diff --git a/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino b/libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino similarity index 72% rename from libraries/CurieImu/examples/ShockDetect/ShockDetect.ino rename to libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino index 9e7e352e..fe96941c 100644 --- a/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino +++ b/libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino @@ -22,7 +22,7 @@ Intel(R) Curie(TM) module can be used to detect shocks or sudden movements */ -#include "CurieImu.h" +#include "CurieIMU.h" boolean blinkState = false; // state of the LED @@ -30,16 +30,13 @@ void setup() { Serial.begin(9600); /* Initialise the IMU */ - CurieImu.initialize(); - CurieImu.attachInterrupt(eventCallback); + CurieIMU.begin(); + CurieIMU.attachInterrupt(eventCallback); /* Enable Shock Detection */ - CurieImu.setShockDetectionThreshold(192); // 1.5g - CurieImu.setShockDetectionDuration(11); // 30ms - CurieImu.setIntShockEnabled(true); - - /* Enable Interrupts Notifications */ - CurieImu.setIntEnabled(true); + CurieIMU.setDetectionThreshold(CURIE_IMU_SHOCK, 192); // 1.5g + CurieIMU.setDetectionDuration(CURIE_IMU_SHOCK, CURIE_IMU_TAP_SHOCK_DURATION_50MS); // 50ms + CurieIMU.enableInterrupt(CURIE_IMU_SHOCK, true); Serial.println("IMU initialisation complete, waiting for events..."); } @@ -54,18 +51,18 @@ void loop() { static void eventCallback(void) { - if (CurieImu.getIntShockStatus()) { - if (CurieImu.getXNegShockDetected()) + if (CurieIMU.getInterruptStatus(CURIE_IMU_SHOCK)) { + if (CurieIMU.shockDetected(X_AXIS, POSITIVE)) Serial.println("Negative shock detected on X-axis"); - if (CurieImu.getXPosShockDetected()) + if (CurieIMU.shockDetected(X_AXIS, NEGATIVE)) Serial.println("Positive shock detected on X-axis"); - if (CurieImu.getYNegShockDetected()) + if (CurieIMU.shockDetected(Y_AXIS, POSITIVE)) Serial.println("Negative shock detected on Y-axis"); - if (CurieImu.getYPosShockDetected()) + if (CurieIMU.shockDetected(Y_AXIS, NEGATIVE)) Serial.println("Positive shock detected on Y-axis"); - if (CurieImu.getZNegShockDetected()) + if (CurieIMU.shockDetected(Z_AXIS, POSITIVE)) Serial.println("Negative shock detected on Z-axis"); - if (CurieImu.getZPosShockDetected()) + if (CurieIMU.shockDetected(Z_AXIS, NEGATIVE)) Serial.println("Positive shock detected on Z-axis"); } } diff --git a/libraries/CurieImu/examples/StepCount/StepCount.ino b/libraries/CurieIMU/examples/StepCount/StepCount.ino similarity index 84% rename from libraries/CurieImu/examples/StepCount/StepCount.ino rename to libraries/CurieIMU/examples/StepCount/StepCount.ino index 9686d6b6..664efdb8 100644 --- a/libraries/CurieImu/examples/StepCount/StepCount.ino +++ b/libraries/CurieIMU/examples/StepCount/StepCount.ino @@ -22,7 +22,7 @@ Intel(R) Curie(TM) module can be used as a Step Counter (pedometer) */ -#include "CurieImu.h" +#include "CurieIMU.h" /* To get an interrupt notification for every step detected, set stepEventsEnabeled to true. Otherwise, the main loop will @@ -42,18 +42,17 @@ void setup() { Serial.begin(9600); // pinMode(13, OUTPUT); // intialize the sensor: - CurieImu.initialize(); + CurieIMU.begin(); // turn on step detection mode: - CurieImu.setStepDetectionMode(BMI160_STEP_MODE_NORMAL); + CurieIMU.setStepDetectionMode(CURIE_IMU_STEP_MODE_NORMAL); // enable step counting: - CurieImu.setStepCountEnabled(true); + CurieIMU.setStepCountEnabled(true); if (stepEventsEnabeled) { // attach the eventCallback function as the // step event handler: - CurieImu.attachInterrupt(eventCallback); - CurieImu.setIntStepEnabled(true); // turn on step detection - CurieImu.setIntEnabled(true); // enable interrupts + CurieIMU.attachInterrupt(eventCallback); + CurieIMU.enableInterrupt(CURIE_IMU_STEP, true); // turn on step detection Serial.println("IMU initialisation complete, waiting for events..."); } @@ -72,11 +71,11 @@ void loop() { static void updateStepCount() { // get the step count: - int stepCount = CurieImu.getStepCount(); - + int stepCount = CurieIMU.getStepCount(); + // if the step count has changed, print it: if (stepCount != lastStepCount) { - Serial.print("Step count: "); + Serial.print("Step count: "); Serial.println(stepCount); // save the current count for comparison next check: lastStepCount = stepCount; @@ -84,6 +83,6 @@ static void updateStepCount() { } static void eventCallback(void) { - if (CurieImu.getIntStepStatus()) + if (CurieIMU.stepsDetected()) updateStepCount(); } diff --git a/libraries/CurieIMU/examples/TapDetect/TapDetect.ino b/libraries/CurieIMU/examples/TapDetect/TapDetect.ino new file mode 100644 index 00000000..e0ffa2b4 --- /dev/null +++ b/libraries/CurieIMU/examples/TapDetect/TapDetect.ino @@ -0,0 +1,70 @@ +/* + Copyright (c) 2015 Intel Corporation. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* + This sketch example demonstrates how the BMI160 accelerometer on the + Intel(R) Curie(TM) module can be used to detect tap events +*/ + +#include "CurieIMU.h" + +void setup() { + Serial.begin(9600); + + // Initialise the IMU + CurieIMU.begin(); + CurieIMU.attachInterrupt(eventCallback); + + // Increase Accelerometer range to allow detection of stronger taps (< 4g) + CurieIMU.setAccelerometerRange(CURIE_IMU_ACCELEROMETER_RANGE_4G); + + // Reduce threshold to allow detection of weaker taps (>= 750mg) + CurieIMU.setDetectionThreshold(CURIE_IMU_TAP, 6); // (6 x 125mg) + + // Set the time window for 2 taps to be registered as a double-tap (<= 250 milliseconds) + CurieIMU.setDetectionDuration(CURIE_IMU_DOUBLE_TAP, CURIE_IMU_DOUBLE_TAP_DURATION_250MS); + + // Enable Double-Tap detection + CurieIMU.enableInterrupt(CURIE_IMU_DOUBLE_TAP, true); + + Serial.println("IMU initialisation complete, waiting for events..."); +} + +void loop() { + // nothing happens in the loop because all the action happens + // in the callback function. +} + +static void eventCallback() +{ + if (CurieIMU.getInterruptStatus(CURIE_IMU_DOUBLE_TAP)) { + if (CurieIMU.tapDetected(X_AXIS, NEGATIVE)) + Serial.println("Double Tap detected on negative X-axis"); + if (CurieIMU.tapDetected(X_AXIS, POSITIVE)) + Serial.println("Double Tap detected on positive X-axis"); + if (CurieIMU.tapDetected(Y_AXIS, NEGATIVE)) + Serial.println("Double Tap detected on negative Y-axis"); + if (CurieIMU.tapDetected(Y_AXIS, POSITIVE)) + Serial.println("Double Tap detected on positive Y-axis"); + if (CurieIMU.tapDetected(Z_AXIS, NEGATIVE)) + Serial.println("Double Tap detected on negative Z-axis"); + if (CurieIMU.tapDetected(Z_AXIS, POSITIVE)) + Serial.println("Double Tap detected on positive Z-axis"); + } +} diff --git a/libraries/CurieIMU/keywords.txt b/libraries/CurieIMU/keywords.txt new file mode 100644 index 00000000..f19f4ca8 --- /dev/null +++ b/libraries/CurieIMU/keywords.txt @@ -0,0 +1,190 @@ +####################################### +# Syntax Coloring Map For CureIMU +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +CurieIMUClass KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD1 + +getGyroRate KEYWORD1 +setGyroRate KEYWORD1 +getAccelerometerRate KEYWORD1 +setAccelerometerRate KEYWORD1 + +getGyroRange KEYWORD1 +setGyroRange KEYWORD1 +getAccelerometerRange KEYWORD1 +setAccelerometerRange KEYWORD1 + +autoCalibrateGyroOffset KEYWORD1 +autoCalibrateAccelerometerOffset KEYWORD1 + +enableGyroOffset KEYWORD1 +enableAccelerometerOffset KEYWORD1 +gyroOffsetEnabled KEYWORD1 +accelerometerOffsetEnabled KEYWORD1 + +getGyroOffset KEYWORD1 +getAccelerometerOffset KEYWORD1 + +setGyroOffset KEYWORD1 +setAccelerometerOffset KEYWORD1 + +getDetectionThreshold KEYWORD1 +setDetectionThreshold KEYWORD1 + +getDetectionDuration KEYWORD1 +setDetectionDuration KEYWORD1 + +enableInterrupt KEYWORD1 +interruptEnabled KEYWORD1 + +getInterruptBits KEYWORD1 +getInterruptStatus KEYWORD1 + +getStepDetectionMode KEYWORD1 +setStepDetectionMode KEYWORD1 +getStepCount KEYWORD1 +getStepCountEnabled KEYWORD1 +setStepCountEnabled KEYWORD1 +resetStepCount KEYWORD1 + +readMotionSensor KEYWORD1 +readAcceleration KEYWORD1 +readRotation KEYWORD1 + +readAccelerometer KEYWORD1 +readGyro KEYWORD1 +readTemperature KEYWORD1 + +shockDetected KEYWORD1 +motionDetected KEYWORD1 +tapDetected KEYWORD1 +stepsDetected KEYWORD1 + +####################################### +# Instances (KEYWORD2) +####################################### + +CurieIMU KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + +CURIE_IMU_ACCELEROMETER_RATE_25_2HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_25HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_50HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_100HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_200HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_400HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_800HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_1600HZ LITERAL1 + +CURIE_IMU_GYRO_RATE_25HZ LITERAL1 +CURIE_IMU_GYRO_RATE_50HZ LITERAL1 +CURIE_IMU_GYRO_RATE_100HZ LITERAL1 +CURIE_IMU_GYRO_RATE_200HZ LITERAL1 +CURIE_IMU_GYRO_RATE_400HZ LITERAL1 +CURIE_IMU_GYRO_RATE_800HZ LITERAL1 +CURIE_IMU_GYRO_RATE_1600HZ LITERAL1 +CURIE_IMU_GYRO_RATE_3200HZ LITERAL1 + +CURIE_IMU_GYRO_RANGE_2000 LITERAL1 +CURIE_IMU_GYRO_RANGE_1000 LITERAL1 +CURIE_IMU_GYRO_RANGE_500 LITERAL1 +CURIE_IMU_GYRO_RANGE_250 LITERAL1 +CURIE_IMU_GYRO_RANGE_125 LITERAL1 + +CURIE_IMU_ACCELEROMETER_RANGE_2G LITERAL1 +CURIE_IMU_ACCELEROMETER_RANGE_4G LITERAL1 +CURIE_IMU_ACCELEROMETER_RANGE_8G LITERAL1 +CURIE_IMU_ACCELEROMETER_RANGE_16G LITERAL1 + +CURIE_IMU_STEP_MODE_NORMAL LITERAL1 +CURIE_IMU_STEP_MODE_SENSITIVE LITERAL1 +CURIE_IMU_STEP_MODE_ROBUST LITERAL1 +CURIE_IMU_STEP_MODE_UNKNOWN LITERAL1 + +CURIE_IMU_DOUBLE_TAP_DURATION_50MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_100MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_150MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_200MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_250MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_375MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_500MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_700MS LITERAL1 + + +CURIE_IMU_ZERO_MOTION_DURATION_1_28S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_2_56S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_3_84S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_5_12S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_6_40S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_7_68S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_8_96S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_10_24S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_11_52S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_12_80S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_14_08S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_15_36S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_16_64S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_17_92S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_19_20S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_20_48S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_25_60S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_30_72S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_35_84S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_40_96S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_46_08S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_51_20S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_56_32S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_61_44S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_66_56S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_71_68S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_76_80S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_81_92S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_87_04S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_92_16S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_97_28S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_102_40S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_112_64S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_122_88S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_133_12S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_143_36S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_153_60S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_163_84S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_174_08S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_184_32S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_194_56S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_204_80S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_215_04S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_225_28S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_235_52S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_245_76S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_256_00S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_266_24S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_276_48S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_286_72S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_296_96S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_307_20S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_317_44S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_327_68S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_337_92S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_348_16S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_358_40S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_368_64S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_378_88S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_389_12S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_399_36S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_409_60S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_419_84S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_430_08S LITERAL1 diff --git a/libraries/CurieImu/library.properties b/libraries/CurieIMU/library.properties similarity index 95% rename from libraries/CurieImu/library.properties rename to libraries/CurieIMU/library.properties index b2590fb3..9e82e98a 100644 --- a/libraries/CurieImu/library.properties +++ b/libraries/CurieIMU/library.properties @@ -1,4 +1,4 @@ -name=CurieImu +name=CurieIMU version=1.0 author=Emutex maintainer=Emutex diff --git a/libraries/CurieImu/src/BMI160.cpp b/libraries/CurieIMU/src/BMI160.cpp similarity index 100% rename from libraries/CurieImu/src/BMI160.cpp rename to libraries/CurieIMU/src/BMI160.cpp diff --git a/libraries/CurieImu/src/BMI160.h b/libraries/CurieIMU/src/BMI160.h similarity index 100% rename from libraries/CurieImu/src/BMI160.h rename to libraries/CurieIMU/src/BMI160.h diff --git a/libraries/CurieIMU/src/CurieIMU.cpp b/libraries/CurieIMU/src/CurieIMU.cpp new file mode 100644 index 00000000..39ba0c03 --- /dev/null +++ b/libraries/CurieIMU/src/CurieIMU.cpp @@ -0,0 +1,668 @@ +/* + * Copyright (c) 2015 Intel Corporation. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "CurieIMU.h" +#include "internal/ss_spi.h" +#include "interrupt.h" + +#define CURIE_IMU_CHIP_ID 0xD1 + +#define BMI160_GPIN_AON_PIN 4 + +/******************************************************************************/ + +/** Power on and prepare for general usage. + * This will prepare the SPI communication interface for accessing the BMI160 + * on the Curie module, before calling BMI160::initialize() to activate the + * BMI160 accelerometer and gyroscpoe with default settings. + */ +bool CurieIMUClass::begin() +{ + /* Configure pin-mux settings on the Intel Curie module to + * enable SPI mode usage */ + SET_PIN_MODE(35, QRK_PMUX_SEL_MODEA); // SPI1_SS_MISO + SET_PIN_MODE(36, QRK_PMUX_SEL_MODEA); // SPI1_SS_MOSI + SET_PIN_MODE(37, QRK_PMUX_SEL_MODEA); // SPI1_SS_SCK + SET_PIN_MODE(38, QRK_PMUX_SEL_MODEA); // SPI1_SS_CS_B[0] + + ss_spi_init(); + + /* Perform a dummy read from 0x7f to switch to spi interface */ + uint8_t dummy_reg = 0x7F; + serial_buffer_transfer(&dummy_reg, 1, 1); + + /* The SPI interface is ready - now invoke the base class initialization */ + BMI160Class::initialize(); + + /** Verify the SPI connection. + * MakgetGyroRatee sure the device is connected and responds as expected. + * @return True if connection is valid, false otherwise + */ + return (CURIE_IMU_CHIP_ID == getDeviceID()); +} + +int CurieIMUClass::getGyroRate() +{ + return BMI160Class::getGyroRate(); +} + +void CurieIMUClass::setGyroRate(int rate) +{ + BMI160Class::setGyroRate(rate); +} + +int CurieIMUClass::getAccelerometerRate() +{ + return getAccelRate(); +} + +void CurieIMUClass::setAccelerometerRate(int rate) +{ + setAccelRate(rate); +} + +int CurieIMUClass::getGyroRange() +{ + return getFullScaleGyroRange(); +} + +void CurieIMUClass::setGyroRange(int range) +{ + setFullScaleGyroRange(range); +} + +int CurieIMUClass::getAccelerometerRange() +{ + return getFullScaleAccelRange(); +} + +void CurieIMUClass::setAccelerometerRange(int range) +{ + setFullScaleAccelRange(range); +} + +void CurieIMUClass::autoCalibrateGyroOffset() +{ + BMI160Class::autoCalibrateGyroOffset(); +} + +void CurieIMUClass::autoCalibrateAccelerometerOffset(int axis, int target) +{ + switch (axis) { + case X_AXIS: + autoCalibrateXAccelOffset(target); + break; + + case Y_AXIS: + autoCalibrateYAccelOffset(target); + break; + + case Z_AXIS: + autoCalibrateZAccelOffset(target); + break; + + default: + break; + } +} + +void CurieIMUClass::enableGyroOffset(bool state) +{ + setGyroOffsetEnabled(state); +} + +void CurieIMUClass::enableAccelerometerOffset(bool state) +{ + setAccelOffsetEnabled(state); +} + +bool CurieIMUClass::gyroOffsetEnabled() +{ + return getGyroOffsetEnabled(); +} + +bool CurieIMUClass::accelerometerOffsetEnabled() +{ + return getAccelOffsetEnabled(); +} + +int CurieIMUClass::getGyroOffset(int axis) +{ + if (axis == X_AXIS) { + return getXGyroOffset(); + } else if (axis == Y_AXIS) { + return getYGyroOffset(); + } else if (axis == Z_AXIS) { + return getZGyroOffset(); + } + + return -1; +} + +int CurieIMUClass::getAccelerometerOffset(int axis) +{ + if (axis == X_AXIS) { + return getXAccelOffset(); + } else if (axis == Y_AXIS) { + return getYAccelOffset(); + } else if (axis == Z_AXIS) { + return getZAccelOffset(); + } + + return -1; +} + +void CurieIMUClass::setGyroOffset(int axis, int offset) +{ + if (axis == X_AXIS) { + setXGyroOffset(axis); + } else if (axis == Y_AXIS) { + setYGyroOffset(axis); + } else if (axis == Z_AXIS) { + setZGyroOffset(axis); + } +} + +void CurieIMUClass::setAccelerometerOffset(int axis, int offset) +{ + if (axis == X_AXIS) { + setXAccelOffset(axis); + } else if (axis == Y_AXIS) { + setYAccelOffset(axis); + } else if (axis == Z_AXIS) { + setZAccelOffset(axis); + } +} + +int CurieIMUClass::getDetectionThreshold(int feature) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + return getFreefallDetectionThreshold(); + + case CURIE_IMU_SHOCK: + return getShockDetectionThreshold(); + + case CURIE_IMU_MOTION: + return getMotionDetectionThreshold(); + + case CURIE_IMU_ZERO_MOTION: + return getZeroMotionDetectionThreshold(); + + case CURIE_IMU_TAP: + return getTapDetectionThreshold(); + + case CURIE_IMU_STEP: + case CURIE_IMU_TAP_SHOCK: + case CURIE_IMU_TAP_QUIET: + case CURIE_IMU_DOUBLE_TAP: + case CURIE_IMU_FIFO_FULL: + case CURIE_IMU_DATA_READY: + default: + return -1; + } +} + +void CurieIMUClass::setDetectionThreshold(int feature, int threshold) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + setFreefallDetectionThreshold(threshold); + break; + + case CURIE_IMU_SHOCK: + setShockDetectionThreshold(threshold); + break; + + case CURIE_IMU_MOTION: + setMotionDetectionThreshold(threshold); + break; + + case CURIE_IMU_ZERO_MOTION: + setZeroMotionDetectionThreshold(threshold); + break; + + case CURIE_IMU_TAP: + setTapDetectionThreshold(threshold); + break; + + case CURIE_IMU_STEP: + case CURIE_IMU_TAP_SHOCK: + case CURIE_IMU_TAP_QUIET: + case CURIE_IMU_DOUBLE_TAP: + case CURIE_IMU_FIFO_FULL: + case CURIE_IMU_DATA_READY: + default: + break; + } +} + +int CurieIMUClass::getDetectionDuration(int feature) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + return getFreefallDetectionDuration(); + + case CURIE_IMU_SHOCK: + return getShockDetectionDuration(); + + case CURIE_IMU_MOTION: + return getMotionDetectionDuration(); + + case CURIE_IMU_TAP_SHOCK: + return getTapShockDuration(); + + case CURIE_IMU_ZERO_MOTION: + return getZeroMotionDetectionThreshold(); + + case CURIE_IMU_TAP_QUIET: + return getTapQuietDuration(); + + case CURIE_IMU_DOUBLE_TAP: + return getDoubleTapDetectionDuration(); + + case CURIE_IMU_TAP: + case CURIE_IMU_STEP: + case CURIE_IMU_FIFO_FULL: + case CURIE_IMU_DATA_READY: + default: + return -1; + } +} + +void CurieIMUClass::setDetectionDuration(int feature, int value) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + setFreefallDetectionDuration(value); + break; + + case CURIE_IMU_SHOCK: + setShockDetectionDuration(value); + break; + + case CURIE_IMU_MOTION: + setMotionDetectionDuration(value); + break; + + case CURIE_IMU_TAP_SHOCK: + setTapShockDuration(value); + break; + + case CURIE_IMU_ZERO_MOTION: + setZeroMotionDetectionThreshold(value); + break; + + case CURIE_IMU_TAP_QUIET: + setTapQuietDuration(value); + break; + + case CURIE_IMU_DOUBLE_TAP: + setDoubleTapDetectionDuration(value); + break; + + case CURIE_IMU_TAP: + case CURIE_IMU_STEP: + case CURIE_IMU_FIFO_FULL: + case CURIE_IMU_DATA_READY: + default: + break; + } +} + +void CurieIMUClass::enableInterrupt(int feature, bool enabled) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + setIntFreefallEnabled(enabled); + break; + + case CURIE_IMU_SHOCK: + setIntShockEnabled(enabled); + break; + + case CURIE_IMU_STEP: + setIntStepEnabled(enabled); + break; + + case CURIE_IMU_MOTION: + setIntMotionEnabled(enabled); + break; + + case CURIE_IMU_ZERO_MOTION: + setIntZeroMotionEnabled(enabled); + break; + + case CURIE_IMU_TAP: + setIntTapEnabled(enabled); + break; + + case CURIE_IMU_DOUBLE_TAP: + setIntDoubleTapEnabled(enabled); + break; + + case CURIE_IMU_FIFO_FULL: + setIntFIFOBufferFullEnabled(enabled); + break; + + case CURIE_IMU_DATA_READY: + setIntDataReadyEnabled(enabled); + break; + + case CURIE_IMU_TAP_QUIET: + case CURIE_IMU_TAP_SHOCK: + default: + break; + } +} + +bool CurieIMUClass::interruptEnabled(int feature) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + return getIntFreefallEnabled(); + + case CURIE_IMU_SHOCK: + return getIntShockEnabled(); + + case CURIE_IMU_STEP: + return getIntStepEnabled(); + + case CURIE_IMU_MOTION: + return getIntMotionEnabled(); + + case CURIE_IMU_ZERO_MOTION: + return getIntZeroMotionEnabled(); + + case CURIE_IMU_TAP: + return getIntTapEnabled(); + + case CURIE_IMU_DOUBLE_TAP: + return getIntDoubleTapEnabled(); + + case CURIE_IMU_FIFO_FULL: + return getIntFIFOBufferFullEnabled(); + + case CURIE_IMU_DATA_READY: + return getIntDataReadyEnabled(); + + case CURIE_IMU_TAP_QUIET: + case CURIE_IMU_TAP_SHOCK: + default: + return false; + } +} + +int CurieIMUClass::getInterruptStatus(int feature) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + return getIntFreefallStatus(); + + case CURIE_IMU_SHOCK: + return getIntShockStatus(); + + case CURIE_IMU_STEP: + return getIntStepStatus(); + + case CURIE_IMU_MOTION: + return getIntMotionStatus(); + + case CURIE_IMU_ZERO_MOTION: + return getIntZeroMotionStatus(); + + case CURIE_IMU_TAP: + return getIntTapStatus(); + + case CURIE_IMU_DOUBLE_TAP: + return getIntDoubleTapStatus(); + + case CURIE_IMU_FIFO_FULL: + return getIntFIFOBufferFullStatus(); + + case CURIE_IMU_DATA_READY: + return getIntDataReadyStatus(); + + case CURIE_IMU_TAP_QUIET: + case CURIE_IMU_TAP_SHOCK: + default: + return false; + } +} + +CurieIMUStepMode CurieIMUClass::getStepDetectionMode() +{ + return (CurieIMUStepMode)BMI160Class::getStepDetectionMode(); +} + +void CurieIMUClass::setStepDetectionMode(int mode) +{ + BMI160Class::setStepDetectionMode((BMI160StepMode)mode); +} + +void CurieIMUClass::readMotionSensor(int& ax, int& ay, int& az, int& gx, int& gy, int& gz) +{ + short sax, say, saz, sgx, sgy, sgz; + + getMotion6(&sax, &say, &saz, &sgx, &sgy, &sgz); + + ax = sax; + ay = say; + az = saz; + gx = sgx; + gy = sgy; + gz = sgz; +} + +void CurieIMUClass::readAccelerometer(int& x, int& y, int& z) +{ + short sx, sy, sz; + + getAcceleration(&sx, &sy, &sz); + + x = sx; + y = sy; + z = sz; +} + +void CurieIMUClass::readGyro(int& x, int& y, int& z) +{ + short sx, sy, sz; + + getRotation(&sx, &sy, &sz); + + x = sx; + y = sy; + z = sz; +} + +int CurieIMUClass::readAccelerometer(int axis) +{ + if (axis == X_AXIS) { + return getAccelerationX(); + } else if (axis == Y_AXIS) { + return getAccelerationY(); + } else if (axis == Z_AXIS) { + return getAccelerationZ(); + } + + return 0; +} + +int CurieIMUClass::readGyro(int axis) +{ + if (axis == X_AXIS) { + return getRotationX(); + } else if (axis == Y_AXIS) { + return getRotationY(); + } else if (axis == Z_AXIS) { + return getRotationZ(); + } + + return 0; +} + +int CurieIMUClass::readTemperature() +{ + return getTemperature(); +} + +bool CurieIMUClass::shockDetected(int axis, int direction) +{ + if (direction == POSITIVE) { + if (axis == X_AXIS) { + return getXPosShockDetected(); + } else if (axis == Y_AXIS) { + return getYPosShockDetected(); + } else if (axis == Z_AXIS) { + return getZPosShockDetected(); + } + } else if (direction == NEGATIVE) { + if (axis == X_AXIS) { + return getXNegShockDetected(); + } else if (axis == Y_AXIS) { + return getYNegShockDetected(); + } else if (axis == Z_AXIS) { + return getZNegShockDetected(); + } + } + + return false; +} + +bool CurieIMUClass::motionDetected(int axis, int direction) +{ + if (direction == POSITIVE) { + if (axis == X_AXIS) { + return getXPosMotionDetected(); + } else if (axis == Y_AXIS) { + return getYPosMotionDetected(); + } else if (axis == Z_AXIS) { + return getZPosMotionDetected(); + } + } else if (direction == NEGATIVE) { + if (axis == X_AXIS) { + return getXNegMotionDetected(); + } else if (axis == Y_AXIS) { + return getYNegMotionDetected(); + } else if (axis == Z_AXIS) { + return getZNegMotionDetected(); + } + } + + return false; +} + +bool CurieIMUClass::tapDetected(int axis, int direction) +{ + if (direction == POSITIVE) { + if (axis == X_AXIS) { + return getXPosTapDetected(); + } else if (axis == Y_AXIS) { + return getYPosTapDetected(); + } else if (axis == Z_AXIS) { + return getZPosTapDetected(); + } + } else if (direction == NEGATIVE) { + if (axis == X_AXIS) { + return getXNegTapDetected(); + } else if (axis == Y_AXIS) { + return getYNegTapDetected(); + } else if (axis == Z_AXIS) { + return getZNegTapDetected(); + } + } + + return false; +} + +bool CurieIMUClass::stepsDetected() +{ + return getIntStepStatus(); +} + +/** Provides a serial buffer transfer implementation for the BMI160 base class + * to use for accessing device registers. This implementation uses the SPI + * bus on the Intel Curie module to communicate with the BMI160. + */ +int CurieIMUClass::serial_buffer_transfer(uint8_t *buf, unsigned tx_cnt, unsigned rx_cnt) +{ + int flags, status; + + if (rx_cnt) /* For read transfers, assume 1st byte contains register address */ + buf[0] |= (1 << BMI160_SPI_READ_BIT); + + /* Lock interrupts here to + * - avoid concurrent access to the SPI bus + * - avoid delays in SPI transfer due to unrelated interrupts + */ + flags = interrupt_lock(); + status = ss_spi_xfer(buf, tx_cnt, rx_cnt); + interrupt_unlock(flags); + + return status; +} + +/** Interrupt handler for interrupts from PIN1 on the BMI160 + * Calls a user callback if available. The user callback is + * responsible for checking the source of the interrupt using + * the relevant API functions from the BMI160Class base class. + */ +void bmi160_pin1_isr(void) +{ + soc_gpio_mask_interrupt(SOC_GPIO_AON, BMI160_GPIN_AON_PIN); + if (CurieIMU._user_callback) + CurieIMU._user_callback(); + soc_gpio_unmask_interrupt(SOC_GPIO_AON, BMI160_GPIN_AON_PIN); +} + +/** Stores a user callback, and enables PIN1 interrupts from the + * BMI160 module. + */ +void CurieIMUClass::attachInterrupt(void (*callback)(void)) +{ + gpio_cfg_data_t cfg; + + _user_callback = callback; + + memset(&cfg, 0, sizeof(gpio_cfg_data_t)); + cfg.gpio_type = GPIO_INTERRUPT; + cfg.int_type = EDGE; + cfg.int_polarity = ACTIVE_LOW; + cfg.int_debounce = DEBOUNCE_ON; + cfg.gpio_cb = bmi160_pin1_isr; + soc_gpio_set_config(SOC_GPIO_AON, BMI160_GPIN_AON_PIN, &cfg); + + setInterruptMode(1); // Active-Low + setInterruptDrive(0); // Push-Pull + setInterruptLatch(BMI160_LATCH_MODE_10_MS); // 10ms pulse + setIntEnabled(true); +} + +/** Disables PIN1 interrupts from the BMI160 module. + */ +void CurieIMUClass::detachInterrupt(void) +{ + setIntEnabled(false); + + soc_gpio_deconfig(SOC_GPIO_AON, BMI160_GPIN_AON_PIN); +} + +/* Pre-instantiated Object for this class */ +CurieIMUClass CurieIMU; diff --git a/libraries/CurieIMU/src/CurieIMU.h b/libraries/CurieIMU/src/CurieIMU.h new file mode 100644 index 00000000..31f42e6a --- /dev/null +++ b/libraries/CurieIMU/src/CurieIMU.h @@ -0,0 +1,319 @@ +/* + * BMI160 accelerometer/gyroscope library for Intel(R) Curie(TM) devices. + * + * Copyright (c) 2015 Intel Corporation. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef _CURIEIMU_H_ +#define _CURIEIMU_H_ + +#include "BMI160.h" + +/** + * axis options + *@see autoCalibrateAccelerometerOffset() + *@see get/setGyroOffset() + *@see get/setAccelerometerOffset() + *@see readAcceleration() + *@see readRotation() + *@see shockDetected() + *@see tapDetected() + *@see motionDetected() + */ +typedef enum{ + X_AXIS = 0, + Y_AXIS, + Z_AXIS, +} CurieIMUAxis; + +/** + *direction options + *@see shockDetected() + *@see tapDetected() + *@see motionDetected() + */ +typedef enum{ + POSITIVE, + NEGATIVE, +} CurieIMUDirection; + + /** + * Features for getThreshold(), getDuration() functions, + */ +typedef enum { + CURIE_IMU_FREEFALL = 0, + CURIE_IMU_SHOCK, + CURIE_IMU_MOTION, + CURIE_IMU_ZERO_MOTION, + CURIE_IMU_STEP, + CURIE_IMU_TAP, + CURIE_IMU_TAP_SHOCK, + CURIE_IMU_TAP_QUIET, + CURIE_IMU_DOUBLE_TAP, + CURIE_IMU_FIFO_FULL, + CURIE_IMU_DATA_READY, +} CurieIMUFeature; + +/** + * Accelerometer Sensitivity Range options + * @see setAccelerometerRange() + */ +typedef enum { + CURIE_IMU_ACCELEROMETER_RANGE_2G = BMI160_ACCEL_RANGE_2G, + CURIE_IMU_ACCELEROMETER_RANGE_4G = BMI160_ACCEL_RANGE_4G, + CURIE_IMU_ACCELEROMETER_RANGE_8G = BMI160_ACCEL_RANGE_8G, + CURIE_IMU_ACCEL_RANGE_16G = BMI160_ACCEL_RANGE_16G +} CurieIMUAccelerometerRange; + +/** + * Gyroscope Sensitivity Range options + * @see setGyroRange() + */ +typedef enum { + CURIE_IMU_GYRO_RANGE_2000 = BMI160_GYRO_RANGE_2000, + CURIE_IMU_GYRO_RANGE_1000 = BMI160_GYRO_RANGE_1000, + CURIE_IMU_GYRO_RANGE_500 = BMI160_GYRO_RANGE_500, + CURIE_IMU_GYRO_RANGE_250 = BMI160_GYRO_RANGE_250, + CURIE_IMU_GYRO_RANGE_125 = BMI160_GYRO_RANGE_125 +} CurieIMUGyroRange; + +/** + * Accelerometer Output Data Rate options + * @see setAccelerometerRate() + */ +typedef enum { + CURIE_IMU_ACCELEROMETER_RATE_25_2HZ = BMI160_ACCEL_RATE_25_2HZ, + CURIE_IMU_ACCELEROMETER_RATE_25HZ = BMI160_ACCEL_RATE_25HZ, + CURIE_IMU_ACCELEROMETER_RATE_50HZ = BMI160_ACCEL_RATE_50HZ, + CURIE_IMU_ACCELEROMETER_RATE_100HZ = BMI160_ACCEL_RATE_100HZ, + CURIE_IMU_ACCELEROMETER_RATE_200HZ = BMI160_ACCEL_RATE_200HZ, + CURIE_IMU_ACCELEROMETER_RATE_400HZ = BMI160_ACCEL_RATE_400HZ, + CURIE_IMU_ACCELEROMETER_RATE_800HZ = BMI160_ACCEL_RATE_800HZ, + CURIE_IMU_ACCELEROMETER_RATE_1600HZ = BMI160_ACCEL_RATE_1600HZ +} CurieIMUAccelRate; + +/** + * Gyroscope Output Data Rate options + * @see setGyroRate() + */ +typedef enum { + CURIE_IMU_GYRO_RATE_25HZ = BMI160_GYRO_RATE_25HZ, + CURIE_IMU_GYRO_RATE_50HZ = BMI160_GYRO_RATE_50HZ, + CURIE_IMU_GYRO_RATE_100HZ = BMI160_GYRO_RATE_100HZ, + CURIE_IMU_GYRO_RATE_200HZ = BMI160_GYRO_RATE_200HZ, + CURIE_IMU_GYRO_RATE_400HZ = BMI160_GYRO_RATE_400HZ, + CURIE_IMU_GYRO_RATE_800HZ = BMI160_GYRO_RATE_800HZ, + CURIE_IMU_GYRO_RATE_1600HZ = BMI160_GYRO_RATE_1600HZ, + CURIE_IMU_GYRO_RATE_3200HZ = BMI160_GYRO_RATE_3200HZ +} CurieIMUGyroRate; + +/** + * Step Detection Mode options + * @see setStepDetectionMode() + */ +typedef enum { + CURIE_IMU_STEP_MODE_NORMAL = BMI160_STEP_MODE_NORMAL, + CURIE_IMU_STEP_MODE_SENSITIVE = BMI160_STEP_MODE_SENSITIVE, + CURIE_IMU_STEP_MODE_ROBUST = BMI160_STEP_MODE_ROBUST, + CURIE_IMU_STEP_MODE_UNKNOWN = BMI160_STEP_MODE_UNKNOWN +} CurieIMUStepMode; + +/** + * Tap Detection Shock Duration options + * @see setDetectionThreshold(CURIE_IMU_TAP, ...) + */ +typedef enum { + CURIE_IMU_TAP_SHOCK_DURATION_50MS = BMI160_TAP_SHOCK_DURATION_50MS, + CURIE_IMU_TAP_SHOCK_DURATION_75MS = BMI160_TAP_SHOCK_DURATION_75MS +} CurieIMUTapShockDuration; + +/** + * Tap Detection Quiet Duration options + * @see setDetectionThreshold(CURIE_IMU_TAP_QUIET, ...) + */ +typedef enum { + CURIE_IMU_TAP_QUIET_DURATION_30MS = BMI160_TAP_QUIET_DURATION_30MS, + CURIE_IMU_TAP_QUIET_DURATION_20MS = BMI160_TAP_QUIET_DURATION_20MS +} CurieIMUTapQuietDuration; + +/** + * Double-Tap Detection Duration options + * @see setDetectionThreshold(CURIE_IMU_DOUBLE_TAP, ...) + */ +typedef enum { + CURIE_IMU_DOUBLE_TAP_DURATION_50MS = BMI160_DOUBLE_TAP_DURATION_50MS, + CURIE_IMU_DOUBLE_TAP_DURATION_100MS = BMI160_DOUBLE_TAP_DURATION_100MS, + CURIE_IMU_DOUBLE_TAP_DURATION_150MS = BMI160_DOUBLE_TAP_DURATION_150MS, + CURIE_IMU_DOUBLE_TAP_DURATION_200MS = BMI160_DOUBLE_TAP_DURATION_200MS, + CURIE_IMU_DOUBLE_TAP_DURATION_250MS = BMI160_DOUBLE_TAP_DURATION_250MS, + CURIE_IMU_DOUBLE_TAP_DURATION_375MS = BMI160_DOUBLE_TAP_DURATION_375MS, + CURIE_IMU_DOUBLE_TAP_DURATION_500MS = BMI160_DOUBLE_TAP_DURATION_500MS, + CURIE_IMU_DOUBLE_TAP_DURATION_700MS = BMI160_DOUBLE_TAP_DURATION_700MS +} CurieIMUDoubleTapDuration; + +/** + * Zero-Motion Detection Duration options + * @see setDetectionThreshold(CURIE_IMU_ZERO_MOTION, ...) + */ +typedef enum { + CURIE_IMU_ZERO_MOTION_DURATION_1_28S = BMI160_ZERO_MOTION_DURATION_1_28S, + CURIE_IMU_ZERO_MOTION_DURATION_2_56S = BMI160_ZERO_MOTION_DURATION_2_56S, + CURIE_IMU_ZERO_MOTION_DURATION_3_84S = BMI160_ZERO_MOTION_DURATION_3_84S, + CURIE_IMU_ZERO_MOTION_DURATION_5_12S = BMI160_ZERO_MOTION_DURATION_5_12S, + CURIE_IMU_ZERO_MOTION_DURATION_6_40S = BMI160_ZERO_MOTION_DURATION_6_40S, + CURIE_IMU_ZERO_MOTION_DURATION_7_68S = BMI160_ZERO_MOTION_DURATION_7_68S, + CURIE_IMU_ZERO_MOTION_DURATION_8_96S = BMI160_ZERO_MOTION_DURATION_8_96S, + CURIE_IMU_ZERO_MOTION_DURATION_10_24S = BMI160_ZERO_MOTION_DURATION_10_24S, + CURIE_IMU_ZERO_MOTION_DURATION_11_52S = BMI160_ZERO_MOTION_DURATION_11_52S, + CURIE_IMU_ZERO_MOTION_DURATION_12_80S = BMI160_ZERO_MOTION_DURATION_12_80S, + CURIE_IMU_ZERO_MOTION_DURATION_14_08S = BMI160_ZERO_MOTION_DURATION_14_08S, + CURIE_IMU_ZERO_MOTION_DURATION_15_36S = BMI160_ZERO_MOTION_DURATION_15_36S, + CURIE_IMU_ZERO_MOTION_DURATION_16_64S = BMI160_ZERO_MOTION_DURATION_16_64S, + CURIE_IMU_ZERO_MOTION_DURATION_17_92S = BMI160_ZERO_MOTION_DURATION_17_92S, + CURIE_IMU_ZERO_MOTION_DURATION_19_20S = BMI160_ZERO_MOTION_DURATION_19_20S, + CURIE_IMU_ZERO_MOTION_DURATION_20_48S = BMI160_ZERO_MOTION_DURATION_20_48S, + CURIE_IMU_ZERO_MOTION_DURATION_25_60S = BMI160_ZERO_MOTION_DURATION_25_60S, + CURIE_IMU_ZERO_MOTION_DURATION_30_72S = BMI160_ZERO_MOTION_DURATION_30_72S, + CURIE_IMU_ZERO_MOTION_DURATION_35_84S = BMI160_ZERO_MOTION_DURATION_35_84S, + CURIE_IMU_ZERO_MOTION_DURATION_40_96S = BMI160_ZERO_MOTION_DURATION_40_96S, + CURIE_IMU_ZERO_MOTION_DURATION_46_08S = BMI160_ZERO_MOTION_DURATION_46_08S, + CURIE_IMU_ZERO_MOTION_DURATION_51_20S = BMI160_ZERO_MOTION_DURATION_51_20S, + CURIE_IMU_ZERO_MOTION_DURATION_56_32S = BMI160_ZERO_MOTION_DURATION_56_32S, + CURIE_IMU_ZERO_MOTION_DURATION_61_44S = BMI160_ZERO_MOTION_DURATION_61_44S, + CURIE_IMU_ZERO_MOTION_DURATION_66_56S = BMI160_ZERO_MOTION_DURATION_66_56S, + CURIE_IMU_ZERO_MOTION_DURATION_71_68S = BMI160_ZERO_MOTION_DURATION_71_68S, + CURIE_IMU_ZERO_MOTION_DURATION_76_80S = BMI160_ZERO_MOTION_DURATION_76_80S, + CURIE_IMU_ZERO_MOTION_DURATION_81_92S = BMI160_ZERO_MOTION_DURATION_81_92S, + CURIE_IMU_ZERO_MOTION_DURATION_87_04S = BMI160_ZERO_MOTION_DURATION_87_04S, + CURIE_IMU_ZERO_MOTION_DURATION_92_16S = BMI160_ZERO_MOTION_DURATION_92_16S, + CURIE_IMU_ZERO_MOTION_DURATION_97_28S = BMI160_ZERO_MOTION_DURATION_97_28S, + CURIE_IMU_ZERO_MOTION_DURATION_102_40S = BMI160_ZERO_MOTION_DURATION_102_40S, + CURIE_IMU_ZERO_MOTION_DURATION_112_64S = BMI160_ZERO_MOTION_DURATION_112_64S, + CURIE_IMU_ZERO_MOTION_DURATION_122_88S = BMI160_ZERO_MOTION_DURATION_122_88S, + CURIE_IMU_ZERO_MOTION_DURATION_133_12S = BMI160_ZERO_MOTION_DURATION_133_12S, + CURIE_IMU_ZERO_MOTION_DURATION_143_36S = BMI160_ZERO_MOTION_DURATION_143_36S, + CURIE_IMU_ZERO_MOTION_DURATION_153_60S = BMI160_ZERO_MOTION_DURATION_153_60S, + CURIE_IMU_ZERO_MOTION_DURATION_163_84S = BMI160_ZERO_MOTION_DURATION_163_84S, + CURIE_IMU_ZERO_MOTION_DURATION_174_08S = BMI160_ZERO_MOTION_DURATION_174_08S, + CURIE_IMU_ZERO_MOTION_DURATION_184_32S = BMI160_ZERO_MOTION_DURATION_184_32S, + CURIE_IMU_ZERO_MOTION_DURATION_194_56S = BMI160_ZERO_MOTION_DURATION_194_56S, + CURIE_IMU_ZERO_MOTION_DURATION_204_80S = BMI160_ZERO_MOTION_DURATION_204_80S, + CURIE_IMU_ZERO_MOTION_DURATION_215_04S = BMI160_ZERO_MOTION_DURATION_215_04S, + CURIE_IMU_ZERO_MOTION_DURATION_225_28S = BMI160_ZERO_MOTION_DURATION_225_28S, + CURIE_IMU_ZERO_MOTION_DURATION_235_52S = BMI160_ZERO_MOTION_DURATION_235_52S, + CURIE_IMU_ZERO_MOTION_DURATION_245_76S = BMI160_ZERO_MOTION_DURATION_245_76S, + CURIE_IMU_ZERO_MOTION_DURATION_256_00S = BMI160_ZERO_MOTION_DURATION_256_00S, + CURIE_IMU_ZERO_MOTION_DURATION_266_24S = BMI160_ZERO_MOTION_DURATION_266_24S, + CURIE_IMU_ZERO_MOTION_DURATION_276_48S = BMI160_ZERO_MOTION_DURATION_276_48S, + CURIE_IMU_ZERO_MOTION_DURATION_286_72S = BMI160_ZERO_MOTION_DURATION_286_72S, + CURIE_IMU_ZERO_MOTION_DURATION_296_96S = BMI160_ZERO_MOTION_DURATION_296_96S, + CURIE_IMU_ZERO_MOTION_DURATION_307_20S = BMI160_ZERO_MOTION_DURATION_307_20S, + CURIE_IMU_ZERO_MOTION_DURATION_317_44S = BMI160_ZERO_MOTION_DURATION_317_44S, + CURIE_IMU_ZERO_MOTION_DURATION_327_68S = BMI160_ZERO_MOTION_DURATION_327_68S, + CURIE_IMU_ZERO_MOTION_DURATION_337_92S = BMI160_ZERO_MOTION_DURATION_337_92S, + CURIE_IMU_ZERO_MOTION_DURATION_348_16S = BMI160_ZERO_MOTION_DURATION_348_16S, + CURIE_IMU_ZERO_MOTION_DURATION_358_40S = BMI160_ZERO_MOTION_DURATION_358_40S, + CURIE_IMU_ZERO_MOTION_DURATION_368_64S = BMI160_ZERO_MOTION_DURATION_368_64S, + CURIE_IMU_ZERO_MOTION_DURATION_378_88S = BMI160_ZERO_MOTION_DURATION_378_88S, + CURIE_IMU_ZERO_MOTION_DURATION_389_12S = BMI160_ZERO_MOTION_DURATION_389_12S, + CURIE_IMU_ZERO_MOTION_DURATION_399_36S = BMI160_ZERO_MOTION_DURATION_399_36S, + CURIE_IMU_ZERO_MOTION_DURATION_409_60S = BMI160_ZERO_MOTION_DURATION_409_60S, + CURIE_IMU_ZERO_MOTION_DURATION_419_84S = BMI160_ZERO_MOTION_DURATION_419_84S, + CURIE_IMU_ZERO_MOTION_DURATION_430_08S = BMI160_ZERO_MOTION_DURATION_430_08S +} CurieIMUZeroMotionDuration; + +/* Note that this CurieIMUClass class inherits methods from the BMI160Class which + * is defined in BMI160.h. BMI160Class provides methods for configuring and + * accessing features of the BMI160 IMU device. This CurieIMUClass extends that + * class with implementation of details specific to the integration of the BMI160 + * device on the Intel Curie module, such as the serial communication interface + * and interrupt signalling. + * + * Please refer to the respective .cpp files for documentation on each of the + * methods provided by these classes. + */ +class CurieIMUClass : public BMI160Class { + friend void bmi160_pin1_isr(void); + + public: + bool begin(void); + + int getGyroRate(); + void setGyroRate(int rate); + + int getAccelerometerRate(); + void setAccelerometerRate(int rate); + + int getGyroRange(); + void setGyroRange(int range); + int getAccelerometerRange(); + void setAccelerometerRange(int range); + + void autoCalibrateGyroOffset(); + void autoCalibrateAccelerometerOffset(int axis, int target); + + void enableGyroOffset(bool state); + void enableAccelerometerOffset(bool state); + bool gyroOffsetEnabled(); + bool accelerometerOffsetEnabled(); + + int getGyroOffset(int axis); + int getAccelerometerOffset(int axis); + + void setGyroOffset(int axis, int offset); + void setAccelerometerOffset(int axis, int offset); + + int getDetectionThreshold(int feature); + void setDetectionThreshold(int feature, int threshold); + + int getDetectionDuration(int feature); + void setDetectionDuration(int feature, int value); //value (bool) duration or samples + + void enableInterrupt(int feature, bool enabled); + bool interruptEnabled(int feature); + + int getInterruptStatus(int feature); + + CurieIMUStepMode getStepDetectionMode(); + void setStepDetectionMode(int mode); + + void readMotionSensor(int& ax, int& ay, int& az, int& gx, int& gy, int& gz); + void readAccelerometer(int& x, int& y, int& z); + void readGyro(int& x, int& y, int& z); + + int readAccelerometer(int axis); + int readGyro(int axis); + int readTemperature(); + + bool shockDetected(int axis, int direction); + bool motionDetected(int axis, int direction); + bool tapDetected(int axis, int direction); + bool stepsDetected(); + + void attachInterrupt(void (*callback)(void)); + void detachInterrupt(void); + + private: + int serial_buffer_transfer(uint8_t *buf, unsigned tx_cnt, unsigned rx_cnt); + + void (*_user_callback)(void); +}; + +extern CurieIMUClass CurieIMU; + +#endif /* _CURIEIMU_H_ */ diff --git a/libraries/CurieImu/src/internal/ss_spi.c b/libraries/CurieIMU/src/internal/ss_spi.c similarity index 100% rename from libraries/CurieImu/src/internal/ss_spi.c rename to libraries/CurieIMU/src/internal/ss_spi.c diff --git a/libraries/CurieImu/src/internal/ss_spi.h b/libraries/CurieIMU/src/internal/ss_spi.h similarity index 100% rename from libraries/CurieImu/src/internal/ss_spi.h rename to libraries/CurieIMU/src/internal/ss_spi.h diff --git a/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino b/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino deleted file mode 100644 index 48cc278b..00000000 --- a/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino +++ /dev/null @@ -1,140 +0,0 @@ -/* - =============================================== - Example sketch for CurieImu library for Intel(R) Curie(TM) devices. - Copyright (c) 2015 Intel Corporation. All rights reserved. - - Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 - class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib - - =============================================== - I2Cdev device library code is placed under the MIT license - Copyright (c) 2011 Jeff Rowberg - - 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 "CurieImu.h" - -int16_t ax, ay, az; // accelerometer values -int16_t gx, gy, gz; // gyrometer values - -const int ledPin = 13; // activity LED pin -boolean blinkState = false; // state of the LED - -void setup() { - Serial.begin(9600); // initialize Serial communication - while (!Serial); // wait for the serial port to open - - // initialize device - Serial.println("Initializing IMU device..."); - CurieImu.initialize(); - - // verify connection - Serial.println("Testing device connections..."); - if (CurieImu.testConnection()) { - Serial.println("CurieImu connection successful"); - } else { - Serial.println("CurieImu connection failed"); - } - - // use the code below to calibrate accel/gyro offset values - Serial.println("Internal sensor offsets BEFORE calibration..."); - Serial.print(CurieImu.getXAccelOffset()); - Serial.print("\t"); // -76 - Serial.print(CurieImu.getYAccelOffset()); - Serial.print("\t"); // -235 - Serial.print(CurieImu.getZAccelOffset()); - Serial.print("\t"); // 168 - Serial.print(CurieImu.getXGyroOffset()); - Serial.print("\t"); // 0 - Serial.print(CurieImu.getYGyroOffset()); - Serial.print("\t"); // 0 - Serial.println(CurieImu.getZGyroOffset()); - - // To manually configure offset compensation values, - // use the following methods instead of the autoCalibrate...() methods below - // CurieImu.setXGyroOffset(220); - // CurieImu.setYGyroOffset(76); - // CurieImu.setZGyroOffset(-85); - // CurieImu.setXAccelOffset(-76); - // CurieImu.setYAccelOffset(-235); - // CurieImu.setZAccelOffset(168); - - Serial.println("About to calibrate. Make sure your board is stable and upright"); - delay(5000); - - // The board must be resting in a horizontal position for - // the following calibration procedure to work correctly! - Serial.print("Starting Gyroscope calibration..."); - CurieImu.autoCalibrateGyroOffset(); - Serial.println(" Done"); - Serial.print("Starting Acceleration calibration..."); - CurieImu.autoCalibrateXAccelOffset(0); - CurieImu.autoCalibrateYAccelOffset(0); - CurieImu.autoCalibrateZAccelOffset(1); - Serial.println(" Done"); - - Serial.println("Internal sensor offsets AFTER calibration..."); - Serial.print(CurieImu.getXAccelOffset()); - Serial.print("\t"); // -76 - Serial.print(CurieImu.getYAccelOffset()); - Serial.print("\t"); // -2359 - Serial.print(CurieImu.getZAccelOffset()); - Serial.print("\t"); // 1688 - Serial.print(CurieImu.getXGyroOffset()); - Serial.print("\t"); // 0 - Serial.print(CurieImu.getYGyroOffset()); - Serial.print("\t"); // 0 - Serial.println(CurieImu.getZGyroOffset()); - - Serial.println("Enabling Gyroscope/Acceleration offset compensation"); - CurieImu.setGyroOffsetEnabled(true); - CurieImu.setAccelOffsetEnabled(true); - - // configure Arduino LED for activity indicator - pinMode(ledPin, OUTPUT); -} - -void loop() { - // read raw accel/gyro measurements from device - CurieImu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); - - // these methods (and a few others) are also available - //CurieImu.getAcceleration(&ax, &ay, &az); - //CurieImu.getRotation(&gx, &gy, &gz); - - // display tab-separated accel/gyro x/y/z values - Serial.print("a/g:\t"); - Serial.print(ax); - Serial.print("\t"); - Serial.print(ay); - Serial.print("\t"); - Serial.print(az); - Serial.print("\t"); - Serial.print(gx); - Serial.print("\t"); - Serial.print(gy); - Serial.print("\t"); - Serial.println(gz); - - // blink LED to indicate activity - blinkState = !blinkState; - digitalWrite(ledPin, blinkState); -} diff --git a/libraries/CurieImu/examples/TapDetect/TapDetect.ino b/libraries/CurieImu/examples/TapDetect/TapDetect.ino deleted file mode 100644 index ce56ea0b..00000000 --- a/libraries/CurieImu/examples/TapDetect/TapDetect.ino +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2015 Intel Corporation. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -/* - * This sketch example demonstrates how the BMI160 accelerometer on the - * Intel(R) Curie(TM) module can be used to detect tap events - */ - -#include "CurieImu.h" - -void setup() { - Serial.begin(9600); - - // Initialise the IMU - CurieImu.initialize(); - CurieImu.attachInterrupt(eventCallback); - - // Increase Accelerometer range to allow detection of stronger taps (< 4g) - CurieImu.setFullScaleAccelRange(BMI160_ACCEL_RANGE_4G); - - // Reduce threshold to allow detection of weaker taps (>= 750mg) - CurieImu.setTapDetectionThreshold(6); // (6 x 125mg) - - // Set the time window for 2 taps to be registered as a double-tap (<= 250 milliseconds) - CurieImu.setDoubleTapDetectionDuration(BMI160_DOUBLE_TAP_DURATION_250MS); - - // Enable Double-Tap detection - CurieImu.setIntDoubleTapEnabled(true); - - // Enable Interrupts Notifications - CurieImu.setIntEnabled(true); - - Serial.println("IMU initialisation complete, waiting for events..."); -} - -void loop() { - // nothing happens in the loop because all the action happens - // in the callback function. -} - -static void eventCallback() -{ - if (CurieImu.getIntDoubleTapStatus()) { - if (CurieImu.getXNegTapDetected()) - Serial.println("Double Tap detected on negative X-axis"); - if (CurieImu.getXPosTapDetected()) - Serial.println("Double Tap detected on positive X-axis"); - if (CurieImu.getYNegTapDetected()) - Serial.println("Double Tap detected on negative Y-axis"); - if (CurieImu.getYPosTapDetected()) - Serial.println("Double Tap detected on positive Y-axis"); - if (CurieImu.getZNegTapDetected()) - Serial.println("Double Tap detected on negative Z-axis"); - if (CurieImu.getZPosTapDetected()) - Serial.println("Double Tap detected on positive Z-axis"); - } -} diff --git a/libraries/CurieImu/keywords.txt b/libraries/CurieImu/keywords.txt deleted file mode 100644 index 913434a1..00000000 --- a/libraries/CurieImu/keywords.txt +++ /dev/null @@ -1,293 +0,0 @@ -####################################### -# Syntax Coloring Map For CureImu -####################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -CurieImuClass KEYWORD1 -BMI160Class KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### - -initialize KEYWORD2 -testConnection KEYWORD2 -getGyroRate KEYWORD2 -setGyroRate KEYWORD2 -getAccelRate KEYWORD2 -setAccelRate KEYWORD2 - -getGyroDLPFMode KEYWORD2 -setGyroDLPFMode KEYWORD2 - -getAccelDLPFMode KEYWORD2 -setAccelDLPFMode KEYWORD2 - -getFullScaleGyroRange KEYWORD2 -setFullScaleGyroRange KEYWORD2 -getFullScaleAccelRange KEYWORD2 -setFullScaleAccelRange KEYWORD2 - -autoCalibrateGyroOffset KEYWORD2 -getGyroOffsetEnabled KEYWORD2 -setGyroOffsetEnabled KEYWORD2 - -getXGyroOffset KEYWORD2 -setXGyroOffset KEYWORD2 -getYGyroOffset KEYWORD2 -setYGyroOffset KEYWORD2 -getZGyroOffset KEYWORD2 -setZGyroOffset KEYWORD2 - -autoCalibrateXAccelOffset KEYWORD2 -autoCalibrateYAccelOffset KEYWORD2 -autoCalibrateZAccelOffset KEYWORD2 -getAccelOffsetEnabled KEYWORD2 -setAccelOffsetEnabled KEYWORD2 - -getXAccelOffset KEYWORD2 -setXAccelOffset KEYWORD2 -getYAccelOffset KEYWORD2 -setYAccelOffset KEYWORD2 -getZAccelOffset KEYWORD2 -setZAccelOffset KEYWORD2 - -getFreefallDetectionThreshold KEYWORD2 -setFreefallDetectionThreshold KEYWORD2 - -getFreefallDetectionDuration KEYWORD2 -setFreefallDetectionDuration KEYWORD2 - -getShockDetectionThreshold KEYWORD2 -setShockDetectionThreshold KEYWORD2 - -getShockDetectionDuration KEYWORD2 -setShockDetectionDuration KEYWORD2 - -getMotionDetectionThreshold KEYWORD2 -setMotionDetectionThreshold KEYWORD2 - -getMotionDetectionDuration KEYWORD2 -setMotionDetectionDuration KEYWORD2 - -getZeroMotionDetectionThreshold KEYWORD2 -setZeroMotionDetectionThreshold KEYWORD2 - -getZeroMotionDetectionDuration KEYWORD2 -setZeroMotionDetectionDuration KEYWORD2 - -getTapDetectionThreshold KEYWORD2 -setTapDetectionThreshold KEYWORD2 - -getTapShockDuration KEYWORD2 -setTapShockDuration KEYWORD2 - -getTapQuietDuration KEYWORD2 -setTapQuietDuration KEYWORD2 - -getDoubleTapDetectionDuration KEYWORD2 -setDoubleTapDetectionDuration KEYWORD2 - -setStepDetectionMode KEYWORD2 -getStepCountEnabled KEYWORD2 -setStepCountEnabled KEYWORD2 -getStepCount KEYWORD2 -resetStepCount KEYWORD2 - -getIntFreefallEnabled KEYWORD2 -setIntFreefallEnabled KEYWORD2 -getIntShockEnabled KEYWORD2 -setIntShockEnabled KEYWORD2 -getIntStepEnabled KEYWORD2 -setIntStepEnabled KEYWORD2 -getIntMotionEnabled KEYWORD2 -setIntMotionEnabled KEYWORD2 -getIntZeroMotionEnabled KEYWORD2 -setIntZeroMotionEnabled KEYWORD2 -getIntTapEnabled KEYWORD2 -setIntTapEnabled KEYWORD2 -getIntDoubleTapEnabled KEYWORD2 -setIntDoubleTapEnabled KEYWORD2 - -getGyroFIFOEnabled KEYWORD2 -setGyroFIFOEnabled KEYWORD2 -getAccelFIFOEnabled KEYWORD2 -setAccelFIFOEnabled KEYWORD2 - -getIntFIFOBufferFullEnabled KEYWORD2 -setIntFIFOBufferFullEnabled KEYWORD2 -getIntDataReadyEnabled KEYWORD2 -setIntDataReadyEnabled KEYWORD2 - -getIntStatus0 KEYWORD2 -getIntStatus1 KEYWORD2 -getIntStatus2 KEYWORD2 -getIntStatus3 KEYWORD2 -getIntFreefallStatus KEYWORD2 -getIntShockStatus KEYWORD2 -getIntStepStatus KEYWORD2 -getIntMotionStatus KEYWORD2 -getIntZeroMotionStatus KEYWORD2 -getIntTapStatus KEYWORD2 -getIntDoubleTapStatus KEYWORD2 -getIntFIFOBufferFullStatus KEYWORD2 -getIntDataReadyStatus KEYWORD2 - -getMotion6 KEYWORD2 -getAcceleration KEYWORD2 -getAccelerationX KEYWORD2 -getAccelerationY KEYWORD2 -getAccelerationZ KEYWORD2 - -getTemperature KEYWORD2 -getRotation KEYWORD2 -getRotationX KEYWORD2 -getRotationY KEYWORD2 -getRotationZ KEYWORD2 - -getXNegShockDetected KEYWORD2 -getXPosShockDetected KEYWORD2 -getYNegShockDetected KEYWORD2 -getYPosShockDetected KEYWORD2 -getZNegShockDetected KEYWORD2 -getZPosShockDetected KEYWORD2 -getZeroShockDetected KEYWORD2 - -getXNegMotionDetected KEYWORD2 -getXPosMotionDetected KEYWORD2 -getYNegMotionDetected KEYWORD2 -getYPosMotionDetected KEYWORD2 -getZNegMotionDetected KEYWORD2 -getZPosMotionDetected KEYWORD2 -getZeroMotionDetected KEYWORD2 - -getXNegTapDetected KEYWORD2 -getXPosTapDetected KEYWORD2 -getYNegTapDetected KEYWORD2 -getYPosTapDetected KEYWORD2 -getZNegTapDetected KEYWORD2 -getZPosTapDetected KEYWORD2 - -getFIFOHeaderModeEnabled KEYWORD2 -setFIFOHeaderModeEnabled KEYWORD2 -resetFIFO KEYWORD2 - -getFIFOCount KEYWORD2 -getFIFOBytes KEYWORD2 -getDeviceID KEYWORD2 -getRegister KEYWORD2 -setRegister KEYWORD2 - -getIntEnabled KEYWORD2 -setIntEnabled KEYWORD2 -getInterruptMode KEYWORD2 -setInterruptMode KEYWORD2 -getInterruptDrive KEYWORD2 -setInterruptDrive KEYWORD2 -getInterruptLatch KEYWORD2 -setInterruptLatch KEYWORD2 -resetInterrupt KEYWORD2 - -####################################### -# Instances (KEYWORD2) -####################################### - -CurieImu KEYWORD2 -BMI160 KEYWORD2 - -####################################### -# Constants (LITERAL1) -####################################### - -BMI160_GYRO_RANGE_2000 LITERAL1 -BMI160_GYRO_RANGE_1000 LITERAL1 -BMI160_GYRO_RANGE_500 LITERAL1 -BMI160_GYRO_RANGE_250 LITERAL1 -BMI160_GYRO_RANGE_125 LITERAL1 - -BMI160_ACCEL_RANGE_2G LITERAL1 -BMI160_ACCEL_RANGE_4G LITERAL1 -BMI160_ACCEL_RANGE_8G LITERAL1 -BMI160_ACCEL_RANGE_16G LITERAL1 - -BMI160_STEP_MODE_NORMAL LITERAL1 -BMI160_STEP_MODE_SENSITIVE LITERAL1 -BMI160_STEP_MODE_ROBUST LITERAL1 - -BMI160_DOUBLE_TAP_DURATION_50MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_100MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_150MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_200MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_250MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_375MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_500MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_700MS LITERAL1 - - -BMI160_ZERO_MOTION_DURATION_1_28S LITERAL1 -BMI160_ZERO_MOTION_DURATION_2_56S LITERAL1 -BMI160_ZERO_MOTION_DURATION_3_84S LITERAL1 -BMI160_ZERO_MOTION_DURATION_5_12S LITERAL1 -BMI160_ZERO_MOTION_DURATION_6_40S LITERAL1 -BMI160_ZERO_MOTION_DURATION_7_68S LITERAL1 -BMI160_ZERO_MOTION_DURATION_8_96S LITERAL1 -BMI160_ZERO_MOTION_DURATION_10_24S LITERAL1 -BMI160_ZERO_MOTION_DURATION_11_52S LITERAL1 -BMI160_ZERO_MOTION_DURATION_12_80S LITERAL1 -BMI160_ZERO_MOTION_DURATION_14_08S LITERAL1 -BMI160_ZERO_MOTION_DURATION_15_36S LITERAL1 -BMI160_ZERO_MOTION_DURATION_16_64S LITERAL1 -BMI160_ZERO_MOTION_DURATION_17_92S LITERAL1 -BMI160_ZERO_MOTION_DURATION_19_20S LITERAL1 -BMI160_ZERO_MOTION_DURATION_20_48S LITERAL1 -BMI160_ZERO_MOTION_DURATION_25_60S LITERAL1 -BMI160_ZERO_MOTION_DURATION_30_72S LITERAL1 -BMI160_ZERO_MOTION_DURATION_35_84S LITERAL1 -BMI160_ZERO_MOTION_DURATION_40_96S LITERAL1 -BMI160_ZERO_MOTION_DURATION_46_08S LITERAL1 -BMI160_ZERO_MOTION_DURATION_51_20S LITERAL1 -BMI160_ZERO_MOTION_DURATION_56_32S LITERAL1 -BMI160_ZERO_MOTION_DURATION_61_44S LITERAL1 -BMI160_ZERO_MOTION_DURATION_66_56S LITERAL1 -BMI160_ZERO_MOTION_DURATION_71_68S LITERAL1 -BMI160_ZERO_MOTION_DURATION_76_80S LITERAL1 -BMI160_ZERO_MOTION_DURATION_81_92S LITERAL1 -BMI160_ZERO_MOTION_DURATION_87_04S LITERAL1 -BMI160_ZERO_MOTION_DURATION_92_16S LITERAL1 -BMI160_ZERO_MOTION_DURATION_97_28S LITERAL1 -BMI160_ZERO_MOTION_DURATION_102_40S LITERAL1 -BMI160_ZERO_MOTION_DURATION_112_64S LITERAL1 -BMI160_ZERO_MOTION_DURATION_122_88S LITERAL1 -BMI160_ZERO_MOTION_DURATION_133_12S LITERAL1 -BMI160_ZERO_MOTION_DURATION_143_36S LITERAL1 -BMI160_ZERO_MOTION_DURATION_153_60S LITERAL1 -BMI160_ZERO_MOTION_DURATION_163_84S LITERAL1 -BMI160_ZERO_MOTION_DURATION_174_08S LITERAL1 -BMI160_ZERO_MOTION_DURATION_184_32S LITERAL1 -BMI160_ZERO_MOTION_DURATION_194_56S LITERAL1 -BMI160_ZERO_MOTION_DURATION_204_80S LITERAL1 -BMI160_ZERO_MOTION_DURATION_215_04S LITERAL1 -BMI160_ZERO_MOTION_DURATION_225_28S LITERAL1 -BMI160_ZERO_MOTION_DURATION_235_52S LITERAL1 -BMI160_ZERO_MOTION_DURATION_245_76S LITERAL1 -BMI160_ZERO_MOTION_DURATION_256_00S LITERAL1 -BMI160_ZERO_MOTION_DURATION_266_24S LITERAL1 -BMI160_ZERO_MOTION_DURATION_276_48S LITERAL1 -BMI160_ZERO_MOTION_DURATION_286_72S LITERAL1 -BMI160_ZERO_MOTION_DURATION_296_96S LITERAL1 -BMI160_ZERO_MOTION_DURATION_307_20S LITERAL1 -BMI160_ZERO_MOTION_DURATION_317_44S LITERAL1 -BMI160_ZERO_MOTION_DURATION_327_68S LITERAL1 -BMI160_ZERO_MOTION_DURATION_337_92S LITERAL1 -BMI160_ZERO_MOTION_DURATION_348_16S LITERAL1 -BMI160_ZERO_MOTION_DURATION_358_40S LITERAL1 -BMI160_ZERO_MOTION_DURATION_368_64S LITERAL1 -BMI160_ZERO_MOTION_DURATION_378_88S LITERAL1 -BMI160_ZERO_MOTION_DURATION_389_12S LITERAL1 -BMI160_ZERO_MOTION_DURATION_399_36S LITERAL1 -BMI160_ZERO_MOTION_DURATION_409_60S LITERAL1 -BMI160_ZERO_MOTION_DURATION_419_84S LITERAL1 -BMI160_ZERO_MOTION_DURATION_430_08S LITERAL1 \ No newline at end of file diff --git a/libraries/CurieImu/src/CurieImu.cpp b/libraries/CurieImu/src/CurieImu.cpp deleted file mode 100644 index 82eae2e2..00000000 --- a/libraries/CurieImu/src/CurieImu.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2015 Intel Corporation. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "CurieImu.h" -#include "internal/ss_spi.h" -#include "interrupt.h" - -#define BMI160_GPIN_AON_PIN 4 - -/******************************************************************************/ - -/** Power on and prepare for general usage. - * This will prepare the SPI communication interface for accessing the BMI160 - * on the Curie module, before calling BMI160::initialize() to activate the - * BMI160 accelerometer and gyroscpoe with default settings. - */ -void CurieImuClass::initialize() -{ - /* Configure pin-mux settings on the Intel Curie module to - * enable SPI mode usage */ - SET_PIN_MODE(35, QRK_PMUX_SEL_MODEA); // SPI1_SS_MISO - SET_PIN_MODE(36, QRK_PMUX_SEL_MODEA); // SPI1_SS_MOSI - SET_PIN_MODE(37, QRK_PMUX_SEL_MODEA); // SPI1_SS_SCK - SET_PIN_MODE(38, QRK_PMUX_SEL_MODEA); // SPI1_SS_CS_B[0] - - ss_spi_init(); - - /* Perform a dummy read from 0x7f to switch to spi interface */ - uint8_t dummy_reg = 0x7F; - serial_buffer_transfer(&dummy_reg, 1, 1); - - /* The SPI interface is ready - now invoke the base class initialization */ - BMI160Class::initialize(); -} - -/** Provides a serial buffer transfer implementation for the BMI160 base class - * to use for accessing device registers. This implementation uses the SPI - * bus on the Intel Curie module to communicate with the BMI160. - */ -int CurieImuClass::serial_buffer_transfer(uint8_t *buf, unsigned tx_cnt, unsigned rx_cnt) -{ - int flags, status; - - if (rx_cnt) /* For read transfers, assume 1st byte contains register address */ - buf[0] |= (1 << BMI160_SPI_READ_BIT); - - /* Lock interrupts here to - * - avoid concurrent access to the SPI bus - * - avoid delays in SPI transfer due to unrelated interrupts - */ - flags = interrupt_lock(); - status = ss_spi_xfer(buf, tx_cnt, rx_cnt); - interrupt_unlock(flags); - - return status; -} - -/** Interrupt handler for interrupts from PIN1 on the BMI160 - * Calls a user callback if available. The user callback is - * responsible for checking the source of the interrupt using - * the relevant API functions from the BMI160Class base class. - */ -void bmi160_pin1_isr(void) -{ - soc_gpio_mask_interrupt(SOC_GPIO_AON, BMI160_GPIN_AON_PIN); - if (CurieImu._user_callback) - CurieImu._user_callback(); - soc_gpio_unmask_interrupt(SOC_GPIO_AON, BMI160_GPIN_AON_PIN); -} - -/** Stores a user callback, and enables PIN1 interrupts from the - * BMI160 module. - */ -void CurieImuClass::attachInterrupt(void (*callback)(void)) -{ - gpio_cfg_data_t cfg; - - _user_callback = callback; - - memset(&cfg, 0, sizeof(gpio_cfg_data_t)); - cfg.gpio_type = GPIO_INTERRUPT; - cfg.int_type = EDGE; - cfg.int_polarity = ACTIVE_LOW; - cfg.int_debounce = DEBOUNCE_ON; - cfg.gpio_cb = bmi160_pin1_isr; - soc_gpio_set_config(SOC_GPIO_AON, BMI160_GPIN_AON_PIN, &cfg); - - setInterruptMode(1); // Active-Low - setInterruptDrive(0); // Push-Pull - setInterruptLatch(BMI160_LATCH_MODE_10_MS); // 10ms pulse - setIntEnabled(true); -} - -/** Disables PIN1 interrupts from the BMI160 module. - */ -void CurieImuClass::detachInterrupt(void) -{ - setIntEnabled(false); - - soc_gpio_deconfig(SOC_GPIO_AON, BMI160_GPIN_AON_PIN); -} - -/* Pre-instantiated Object for this class */ -CurieImuClass CurieImu; diff --git a/libraries/CurieImu/src/CurieImu.h b/libraries/CurieImu/src/CurieImu.h deleted file mode 100644 index a6db053a..00000000 --- a/libraries/CurieImu/src/CurieImu.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * BMI160 accelerometer/gyroscope library for Intel(R) Curie(TM) devices. - * - * Copyright (c) 2015 Intel Corporation. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef _CURIEIMU_H_ -#define _CURIEIMU_H_ - -#include "BMI160.h" - -/* Note that this CurieImuClass class inherits methods from the BMI160Class which - * is defined in BMI160.h. BMI160Class provides methods for configuring and - * accessing features of the BMI160 IMU device. This CurieImuClass extends that - * class with implementation of details specific to the integration of the BMI160 - * device on the Intel Curie module, such as the serial communication interface - * and interrupt signalling. - * - * Please refer to the respective .cpp files for documentation on each of the - * methods provided by these classes. - */ -class CurieImuClass : public BMI160Class { - friend void bmi160_pin1_isr(void); - - public: - void initialize(void); - void attachInterrupt(void (*callback)(void)); - void detachInterrupt(void); - - private: - int serial_buffer_transfer(uint8_t *buf, unsigned tx_cnt, unsigned rx_cnt); - - void (*_user_callback)(void); -}; - -extern CurieImuClass CurieImu; - -#endif /* _CURIEIMU_H_ */