-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathF_LSM6DSL.hpp
More file actions
140 lines (122 loc) · 4.25 KB
/
F_LSM6DSL.hpp
File metadata and controls
140 lines (122 loc) · 4.25 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once
#ifndef _F_LSM6DSL_H_
#define _F_LSM6DSL_H_
#include "IMUBase.hpp"
/*
LSM6DSL REGISTERS
*/
#define LSM6DSL_FUNC_CFG_ACCESS 0x01
#define LSM6DSL_SENSOR_SYNC_TIME_FRAME 0x04
#define LSM6DSL_FIFO_CTRL1 0x06
#define LSM6DSL_FIFO_CTRL2 0x07
#define LSM6DSL_FIFO_CTRL3 0x08
#define LSM6DSL_FIFO_CTRL4 0x09
#define LSM6DSL_FIFO_CTRL5 0x0A
#define LSM6DSL_ORIENT_CFG_G 0x0B
#define LSM6DSL_INT1_CTRL 0x0D
#define LSM6DSL_INT2_CTRL 0x0E
#define LSM6DSL_WHO_AM_I 0x0F
#define LSM6DSL_CTRL1_XL 0x10
#define LSM6DSL_CTRL2_G 0x11
#define LSM6DSL_CTRL3_C 0x12
#define LSM6DSL_CTRL4_C 0x13
#define LSM6DSL_CTRL5_C 0x14
#define LSM6DSL_CTRL6_C 0x15
#define LSM6DSL_CTRL7_G 0x16
#define LSM6DSL_CTRL8_XL 0x17
#define LSM6DSL_CTRL9_XL 0x18
#define LSM6DSL_CTRL10_C 0x19
#define LSM6DSL_MASTER_CONFIG 0x1A
#define LSM6DSL_WAKE_UP_SRC 0x1B
#define LSM6DSL_TAP_SRC 0x1C
#define LSM6DSL_D6D_SRC 0x1D
#define LSM6DSL_STATUS_REG 0x1E
#define LSM6DSL_OUT_TEMP_L 0x20
#define LSM6DSL_OUT_TEMP_H 0x21
#define LSM6DSL_OUTX_L_G 0x22
#define LSM6DSL_OUTX_H_G 0x23
#define LSM6DSL_OUTY_L_G 0x24
#define LSM6DSL_OUTY_H_G 0x25
#define LSM6DSL_OUTZ_L_G 0x26
#define LSM6DSL_OUTZ_H_G 0x27
#define LSM6DSL_OUTX_L_XL 0x28
#define LSM6DSL_OUTX_H_XL 0x29
#define LSM6DSL_OUTY_L_XL 0x2A
#define LSM6DSL_OUTY_H_XL 0x2B
#define LSM6DSL_OUTZ_L_XL 0x2C
#define LSM6DSL_OUTZ_H_XL 0x2D
#define LSM6DSL_WHOAMI_DEFAULT_VALUE_A 0x6A
#define LSM6DSL_WHOAMI_DEFAULT_VALUE_B 0x6B
class LSM6DSL : public IMUBase {
public:
LSM6DSL() {};
// Inherited via IMUBase
int init(calData cal, uint8_t address) override;
void update() override;
void getAccel(AccelData* out) override;
void getGyro(GyroData* out) override;
void getMag(MagData* out) override {};
void getQuat(Quaternion* out) override {};
float getTemp() override { return temperature; };
int setGyroRange(int range) override;
int setAccelRange(int range) override;
int setIMUGeometry(int index) override { geometryIndex = index; return 0; };
void calibrateAccelGyro(calData* cal) override;
virtual void calibrateMag(calData* cal) override {};
bool hasMagnetometer() override {
return false;
}
bool hasTemperature() override {
return true;
}
bool hasQuatOutput() override {
return false;
}
String IMUName() override {
return "LSM6DSL";
}
String IMUType() override {
return "LSM6DSL";
}
String IMUManufacturer() override {
return "ST";
}
private:
float aRes = 16.0 / 32768.0; //ares value for full range (16g) readings
float gRes = 2000.0 / 32768.0; //gres value for full range (2000dps) readings
int geometryIndex = 0;
float temperature = 0.f;
AccelData accel = { 0, 0, 0 };
GyroData gyro = { 0, 0, 0 };
calData calibration;
uint8_t IMUAddress;
void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.write(data); // Put data in Tx buffer
Wire.endTransmission(); // Send the Tx buffer
}
uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, (uint8_t)1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}
void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t* dest)
{
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
uint8_t i = 0;
Wire.requestFrom(address, count); // Read bytes from slave register address
while (Wire.available()) {
dest[i++] = Wire.read();
} // Put read results in the Rx buffer
}
};
#endif /* _F_LSM6DSL_H_ */