-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathAdafruit_LSM6DS3TRC.cpp
78 lines (63 loc) · 2.35 KB
/
Adafruit_LSM6DS3TRC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*!
* @file Adafruit_LSM6DS3TRC.cpp Adafruit LSM6DS3TR-C 6-DoF Accelerometer
* and Gyroscope library
*
* Written by ladyada for Adafruit Industries
* BSD (see license.txt)
*/
#include "Arduino.h"
#include <Wire.h>
#include "Adafruit_LSM6DS3TRC.h"
/*!
* @brief Instantiates a new LSM6DS3TRC class
*/
Adafruit_LSM6DS3TRC::Adafruit_LSM6DS3TRC(void) {}
bool Adafruit_LSM6DS3TRC::_init(int32_t sensor_id) {
// make sure we're talking to the right chip
if (chipID() != LSM6DS3TRC_CHIP_ID) {
return false;
}
_sensorid_accel = sensor_id;
_sensorid_gyro = sensor_id + 1;
_sensorid_temp = sensor_id + 2;
reset();
// call base class _init()
Adafruit_LSM6DS::_init(sensor_id);
// set the Block Data Update bit
// this prevents MSB/LSB data registers from being updated until both are read
Adafruit_BusIO_Register ctrl3 = Adafruit_BusIO_Register(
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL3_C);
Adafruit_BusIO_RegisterBits bdu = Adafruit_BusIO_RegisterBits(&ctrl3, 1, 6);
bdu.write(1);
return true;
}
/**************************************************************************/
/*!
@brief Enables and disables the pedometer function
@param enable True to turn on the pedometer function, false to turn off
*/
/**************************************************************************/
void Adafruit_LSM6DS3TRC::enablePedometer(bool enable) {
// enable or disable functionality
Adafruit_BusIO_Register ctrl10 = Adafruit_BusIO_Register(
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS_CTRL10_C);
Adafruit_BusIO_RegisterBits ped_en =
Adafruit_BusIO_RegisterBits(&ctrl10, 1, 4);
ped_en.write(enable);
Adafruit_BusIO_RegisterBits func_en =
Adafruit_BusIO_RegisterBits(&ctrl10, 1, 2);
func_en.write(enable);
resetPedometer();
}
/**************************************************************************/
/*!
@brief Enables and disables the I2C master bus pulllups.
@param enable_pullups true to enable the I2C pullups, false to disable.
*/
void Adafruit_LSM6DS3TRC::enableI2CMasterPullups(bool enable_pullups) {
Adafruit_BusIO_Register master_config = Adafruit_BusIO_Register(
i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, LSM6DS3TRC_MASTER_CONFIG);
Adafruit_BusIO_RegisterBits i2c_master_pu_en =
Adafruit_BusIO_RegisterBits(&master_config, 1, 3);
i2c_master_pu_en.write(enable_pullups);
}