Skip to content

Commit 76cf4cf

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents db8f658 + fbb7b02 commit 76cf4cf

File tree

14 files changed

+187
-91
lines changed

14 files changed

+187
-91
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Future upgrades may fail since the internal contents were modified by hand. In
2121
order to recover, shut down the IDE, delete the entire `Arduino15` directory,
2222
then restart the IDE.
2323

24+
# Pull Requests
25+
26+
Before submitting a pull request, please see our
27+
[guidelines](https://github.com/01org/corelibs-arduino101/wiki/Writing-a-commit-message)
28+
for writing a considerate commit message.
29+
2430
# Support & Issues
2531

2632
If you have found a bug, or you believe a new feature should be added, please
@@ -64,4 +70,4 @@ If you want to enable debug trace on Serail1 to debug corelib, follow these ins
6470
* Find `compiler.cpp.flags` and add `-DCONFIGURE_DEBUG_CORELIB_ENABLED` at the end of this line
6571
4. Initial Serial1 in your sketch
6672
* Add `Serial1.begin(115200);` in your `setup()`
67-
5. Adjust the output level at log_init function in log.c
73+
5. Adjust the output level at log_init function in log.c

cores/arduino/i2c.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static void ss_i2c_err(uint32_t dev_id)
4848
i2c_err_source = dev_id;
4949
}
5050

51-
static int wait_rx_or_err(bool no_stop){
51+
static int wait_rx_or_err()
52+
{
5253
uint64_t timeout = TIMEOUT_MS * 200;
5354
while(timeout--) {
5455
if (i2c_err_detect) {
@@ -65,20 +66,17 @@ static int wait_rx_or_err(bool no_stop){
6566
return I2C_ERROR_OTHER; // other error
6667
}
6768
}
68-
if (!no_stop) {
69-
if (i2c_rx_complete) {
70-
return I2C_OK;
71-
}
69+
if (i2c_rx_complete) {
70+
return I2C_OK;
7271
}
7372
delayMicroseconds(10);
7473
}
75-
if (!no_stop)
76-
return I2C_TIMEOUT;
77-
else
78-
return I2C_OK;
74+
75+
return I2C_TIMEOUT;
7976
}
8077

81-
static int wait_tx_or_err(bool no_stop){
78+
static int wait_tx_or_err()
79+
{
8280
uint64_t timeout = TIMEOUT_MS * 200;
8381
while(timeout--) {
8482
if (i2c_err_detect) {
@@ -95,17 +93,12 @@ static int wait_tx_or_err(bool no_stop){
9593
return I2C_ERROR_OTHER; // other error
9694
}
9795
}
98-
if (!no_stop) {
99-
if (i2c_tx_complete) {
96+
if (i2c_tx_complete) {
10097
return I2C_OK;
101-
}
10298
}
10399
delayMicroseconds(10);
104100
}
105-
if (!no_stop)
106-
return I2C_TIMEOUT;
107-
else
108-
return I2C_OK;
101+
return I2C_TIMEOUT;
109102
}
110103

111104
static int wait_dev_ready(I2C_CONTROLLER controller_id, bool no_stop){
@@ -116,9 +109,13 @@ static int wait_dev_ready(I2C_CONTROLLER controller_id, bool no_stop){
116109
if (ret == I2C_OK) {
117110
return I2C_OK;
118111
}
119-
if (ret == I2C_BUSY) {
112+
else if (ret == I2C_BUSY) {
120113
delayMicroseconds(10);
121114
}
115+
else
116+
{
117+
return I2C_TIMEOUT - ret;
118+
}
122119
}
123120
return I2C_TIMEOUT - ret;
124121
}
@@ -202,7 +199,7 @@ int i2c_writebytes(uint8_t *bytes, uint8_t length, bool no_stop)
202199
i2c_err_detect = 0;
203200
i2c_err_source = 0;
204201
ss_i2c_transfer(I2C_SENSING_0, bytes, length, 0, 0, i2c_slave, no_stop);
205-
ret = wait_tx_or_err(no_stop);
202+
ret = wait_tx_or_err();
206203
if (ret)
207204
return ret;
208205
ret = wait_dev_ready(I2C_SENSING_0, no_stop);
@@ -219,7 +216,7 @@ int i2c_readbytes(uint8_t *buf, int length, bool no_stop)
219216
i2c_err_detect = 0;
220217
i2c_err_source = 0;
221218
ss_i2c_transfer(I2C_SENSING_0, 0, 0, buf, length, i2c_slave, no_stop);
222-
ret = wait_rx_or_err(no_stop);
219+
ret = wait_rx_or_err();
223220
if (ret)
224221
return ret;
225222
ret = wait_dev_ready(I2C_SENSING_0, no_stop);

libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@ void setup() {
2323
}
2424

2525
void loop() {
26-
int axRaw, ayRaw, azRaw; // raw accelerometer values
27-
float ax, ay, az;
26+
float ax, ay, az; //scaled accelerometer values
2827

29-
// read raw accelerometer measurements from device
30-
CurieIMU.readAccelerometer(axRaw, ayRaw, azRaw);
31-
32-
// convert the raw accelerometer data to G's
33-
ax = convertRawAcceleration(axRaw);
34-
ay = convertRawAcceleration(ayRaw);
35-
az = convertRawAcceleration(azRaw);
28+
// read accelerometer measurements from device, scaled to the configured range
29+
CurieIMU.readAccelerometerScaled(ax, ay, az);
3630

3731
// display tab-separated accelerometer x/y/z values
3832
Serial.print("a:\t");
@@ -44,16 +38,6 @@ void loop() {
4438
Serial.println();
4539
}
4640

47-
float convertRawAcceleration(int aRaw) {
48-
// since we are using 2G range
49-
// -2g maps to a raw value of -32768
50-
// +2g maps to a raw value of 32767
51-
52-
float a = (aRaw * 2.0) / 32768.0;
53-
54-
return a;
55-
}
56-
5741
/*
5842
Copyright (c) 2016 Intel Corporation. All rights reserved.
5943

libraries/CurieIMU/examples/Gyro/Gyro.ino

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@ void setup() {
2323
}
2424

2525
void loop() {
26-
int gxRaw, gyRaw, gzRaw; // raw gyro values
27-
float gx, gy, gz;
26+
float gx, gy, gz; //scaled Gyro values
2827

29-
// read raw gyro measurements from device
30-
CurieIMU.readGyro(gxRaw, gyRaw, gzRaw);
31-
32-
// convert the raw gyro data to degrees/second
33-
gx = convertRawGyro(gxRaw);
34-
gy = convertRawGyro(gyRaw);
35-
gz = convertRawGyro(gzRaw);
28+
// read gyro measurements from device, scaled to the configured range
29+
CurieIMU.readGyroScaled(gx, gy, gz);
3630

3731
// display tab-separated gyro x/y/z values
3832
Serial.print("g:\t");
@@ -44,16 +38,6 @@ void loop() {
4438
Serial.println();
4539
}
4640

47-
float convertRawGyro(int gRaw) {
48-
// since we are using 250 degrees/seconds range
49-
// -250 maps to a raw value of -32768
50-
// +250 maps to a raw value of 32767
51-
52-
float g = (gRaw * 250.0) / 32768.0;
53-
54-
return g;
55-
}
56-
5741
/*
5842
Copyright (c) 2016 Intel Corporation. All rights reserved.
5943

libraries/CurieIMU/examples/ZeroMotionDetect/ZeroMotionDetect.ino

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,53 @@
99
*/
1010
#include "CurieIMU.h"
1111

12-
boolean blinkState = false; // state of the LED
13-
unsigned long loopTime = 0; // get the time since program started
14-
unsigned long interruptsTime = 0; // get the time when zero motion event is detected
12+
boolean ledState = false; // state of the LED
1513
void setup() {
1614
Serial.begin(9600);
1715
while(!Serial); // wait for the serial port to open
1816

1917
/* Initialise the IMU */
20-
blinkState = CurieIMU.begin();
18+
CurieIMU.begin();
2119
CurieIMU.attachInterrupt(eventCallback);
2220

2321
/* Enable Zero Motion Detection */
24-
CurieIMU.setDetectionThreshold(CURIE_IMU_ZERO_MOTION, 1500); // 1.5g=1500mg
25-
CurieIMU.setDetectionDuration(CURIE_IMU_ZERO_MOTION, 25); // 25s
22+
CurieIMU.setDetectionThreshold(CURIE_IMU_ZERO_MOTION, 50); // 50mg
23+
CurieIMU.setDetectionDuration(CURIE_IMU_ZERO_MOTION, 2); // 2s
2624
CurieIMU.interrupts(CURIE_IMU_ZERO_MOTION);
2725

26+
/* Enable Motion Detection */
27+
CurieIMU.setDetectionThreshold(CURIE_IMU_MOTION, 20); // 20mg
28+
CurieIMU.setDetectionDuration(CURIE_IMU_MOTION, 10); // trigger times of consecutive slope data points
29+
CurieIMU.interrupts(CURIE_IMU_MOTION);
30+
2831
Serial.println("IMU initialisation complete, waiting for events...");
2932
}
3033

3134
void loop() {
32-
//if zero motion is detected in 1500ms, LED will be turned up
33-
loopTime = millis();
34-
if(abs(loopTime -interruptsTime) < 1500)
35-
blinkState = true;
36-
else
37-
blinkState = false;
38-
digitalWrite(13, blinkState);
35+
// if zero motion is detected, LED will be turned up.
36+
digitalWrite(13, ledState);
3937
}
4038

4139
static void eventCallback(void){
4240
if (CurieIMU.getInterruptStatus(CURIE_IMU_ZERO_MOTION)) {
43-
interruptsTime = millis();
41+
ledState = true;
4442
Serial.println("zero motion detected...");
4543
}
44+
if (CurieIMU.getInterruptStatus(CURIE_IMU_MOTION)) {
45+
ledState = false;
46+
if (CurieIMU.motionDetected(X_AXIS, POSITIVE))
47+
Serial.println("Negative motion detected on X-axis");
48+
if (CurieIMU.motionDetected(X_AXIS, NEGATIVE))
49+
Serial.println("Positive motion detected on X-axis");
50+
if (CurieIMU.motionDetected(Y_AXIS, POSITIVE))
51+
Serial.println("Negative motion detected on Y-axis");
52+
if (CurieIMU.motionDetected(Y_AXIS, NEGATIVE))
53+
Serial.println("Positive motion detected on Y-axis");
54+
if (CurieIMU.motionDetected(Z_AXIS, POSITIVE))
55+
Serial.println("Negative motion detected on Z-axis");
56+
if (CurieIMU.motionDetected(Z_AXIS, NEGATIVE))
57+
Serial.println("Positive motion detected on Z-axis");
58+
}
4659
}
4760

4861
/*

libraries/CurieIMU/keywords.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ setStepCountEnabled KEYWORD1
5959
resetStepCount KEYWORD1
6060

6161
readMotionSensor KEYWORD1
62+
readMotionSensorScaled KEYWORD1
6263
readAcceleration KEYWORD1
6364
readRotation KEYWORD1
6465

6566
readAccelerometer KEYWORD1
67+
readAccelerometerScaled KEYWORD1
6668
readGyro KEYWORD1
69+
readGyroScaled KEYWORD1
6770
readTemperature KEYWORD1
6871

6972
shockDetected KEYWORD1

libraries/CurieIMU/src/BMI160.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ THE SOFTWARE.
3535

3636
#include "Arduino.h"
3737

38+
#define BMI160_SENSOR_RANGE 65535.0f
39+
#define BMI160_SENSOR_LOW 32768.0f
40+
3841
#define BMI160_SPI_READ_BIT 7
3942

4043
#define BMI160_RA_CHIP_ID 0x00

0 commit comments

Comments
 (0)