STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
sfe_ism330dhcx.h
Go to the documentation of this file.
1#include "sfe_bus.h"
2#include "sfe_ism_shim.h"
4
5
6#define ISM330DHCX_ADDRESS_LOW 0x6A
7#define ISM330DHCX_ADDRESS_HIGH 0x6B
8
10{
11 int16_t xData;
12 int16_t yData;
13 int16_t zData;
14};
15
17{
18 float xData;
19 float yData;
20 float zData;
21};
22
23
25{
26 uint8_t address;
27 uint8_t subAddress;
28 uint8_t lenData;
29};
30
31/** Filled by serviceWakeUpInterrupt() when INT1 was a wake-up (high-accel) event. */
33{
34 bool axisX;
35 bool axisY;
36 bool axisZ;
37};
38
39
41{
42 public:
43
45
46
47 ///////////////////////////////////////////////////////////////////////
48 // init()
49 //
50 // Called to init the system. Connects to the device and sets it up for
51 // operation
52
53 bool init();
54
55 ///////////////////////////////////////////////////////////////////////
56 // isConnected()
57 //
58 //
59 // Parameter Description
60 // --------- -----------------------------
61 // retval true if device is connected, false if not connected
62
63 bool isConnected(); // Checks if sensor ack's the I2C request
64
65 int32_t writeRegisterRegion(uint8_t reg, uint8_t *data, uint16_t length);
66
67 //////////////////////////////////////////////////////////////////////////////////
68 // readRegisterRegion()
69 //
70 //
71 // Parameter Description
72 // --------- -----------------------------
73 // reg register to read from
74 // data Array to store data in
75 // length Length of the data to read
76 // retval -1 = error, 0 = success
77
78 int32_t readRegisterRegion(uint8_t reg, uint8_t *data, uint16_t length);
79
80 //////////////////////////////////////////////////////////////////////////////////
81 // setCommunicationBus()
82 //
83 // Called to set the Communication Bus object to use
84 //
85 // Parameter Description
86 // --------- -----------------------------
87 // theBus The Bus object to use
88 // idBus The bus ID for the target device.
89 //
90
91 void setCommunicationBus(sfe_ISM330DHCX::QwIDeviceBus &theBus, uint8_t i2cAddress);
93
94 bool setAccelFullScale(uint8_t val);
95 bool setGyroFullScale(uint8_t val);
96 uint8_t getAccelFullScale();
97
98 uint8_t getUniqueId();
99
100 // Linear, Angular, and Temp Data retrieval
101 int16_t getTemp();
106
107 // General Settings
108 bool setDeviceConfig(bool enable = true);
109 bool deviceReset();
110 bool getDeviceReset();
111 bool setAccelSlopeFilter(uint8_t val);
112 bool setAccelFilterLP2(bool enable = true);
113 bool setGyroFilterLP1(bool enable = true);
114 bool setGyroLP1Bandwidth(uint8_t val);
115 bool setBlockDataUpdate(bool enable = true);
116 uint8_t getBlockDataUpdate();
117 bool setAccelDataRate(uint8_t rate);
118 bool setGyroDataRate(uint8_t rate);
119 bool enableTimestamp(bool enable = true);
120 bool resetTimestamp();
121
122 // Interrupt Settings
123 bool setAccelStatustoInt1(bool enable = true);
124 bool setAccelStatustoInt2(bool enable = true);
125 bool setGyroStatustoInt1(bool enable = true);
126 bool setGyroStatustoInt2(bool enable = true);
127 bool setIntNotification(uint8_t val);
128 bool setDataReadyMode(uint8_t val);
129 bool setPinMode(bool activeLow = true);
130
131 // FIFO Settings
132 bool setFifoWatermark(uint16_t val);
133 bool setFifoMode(uint8_t val);
134 bool setAccelFifoBatchSet(uint8_t val);
135 bool setGyroFifoBatchSet(uint8_t val);
136 bool setFifoTimestampDec(uint8_t val);
137
138 // Sensor Hub Settings
139 bool setHubODR(uint8_t rate);
140 bool setHubSensorRead(uint8_t sensor, sfe_hub_sensor_settings_t* settings);
142 bool setNumberHubSensors(uint8_t numSensors);
143 bool enableSensorI2C(bool enable);
144 bool readPeripheralSensor(uint8_t* shReg, uint8_t len);
145 bool setHubWriteMode(uint8_t config);
146 bool readMMCMagnetometer(uint8_t* magData, uint8_t len);
147 bool setHubPassThrough(bool enable = true);
148 bool setHubFifoBatching(bool enable = true);
149 bool setHubPullUps(bool enable = true);
150 bool getHubStatus();
151 bool getExternalSensorNack(uint8_t sensor);
152 bool resetSensorHub();
153
154 // Self Test
155 bool setAccelSelfTest(uint8_t val);
156 bool setGyroSelfTest(uint8_t val);
157
158 // Status
159 bool checkStatus();
160 bool checkAccelStatus();
161 bool checkGyroStatus();
162 bool checkTempStatus();
163
164 // Wake-up (high-accel) on INT1: uses ST wake-up detector. Threshold LSB weight is FS/64
165 // (call after setAccelFullScale). wakeDur is 0–3 (ODR periods). If routeAccelGyroDrdyToInt1
166 // is false, XL/GYRO data-ready are not routed to INT1 (only wake-up pulses).
167 bool configureWakeUpOnInt1(uint8_t wkThreshold, uint8_t wakeDur,
168 bool routeAccelGyroDrdyToInt1 = false);
169
170 // After INT1 fires: returns true if the source was a wake-up event; reads status registers
171 // on the part so flags clear as the datasheet describes. Otherwise returns false.
173
174 // One-call sensor init with sensible defaults:
175 // BDU on, 104 Hz ODR, 2g / 250dps FS, DRDY_XL + DRDY_G routed to INT1.
176 bool configureSensor();
177
178 // FIFO helpers
179 uint16_t getFifoLevel();
180 bool readFifoSample(sfe_ism_raw_data_t* gyro, sfe_ism_raw_data_t* accel, uint8_t* tag_out = nullptr);
181 bool setFifoWtmToInt2(bool enable = true);
182
183 // Bias calibration — hold the sensor still while calling this.
184 // Collects `samples` readings from getAccel()/getGyro() and stores the
185 // average as an internal bias (units: mg / mdps, matching getAccel/getGyro).
186 bool calibrateBiases(uint16_t samples = 256);
189
190 // Conversions
191 float convert2gToMg(int16_t data);
192 float convert4gToMg(int16_t data);
193 float convert8gToMg(int16_t data);
194 float convert16gToMg(int16_t data);
195 float convert125dpsToMdps(int16_t data);
196 float convert250dpsToMdps(int16_t data);
197 float convert500dpsToMdps(int16_t data);
198 float convert1000dpsToMdps(int16_t data);
199 float convert2000dpsToMdps(int16_t data);
200 float convert4000dpsToMdps(int16_t data);
201 float convertToCelsius(int16_t data);
202
203 private:
204
205 uint8_t getAllIntSrc();
206
208 uint8_t _i2cAddress;
209 uint8_t _cs;
211 uint8_t fullScaleAccel = 0; //Powered down by default
212 uint8_t fullScaleGyro = 0; //Powered down by default
213
214 // Stored calibration biases in mg / mdps (same units as getAccel/getGyro).
215 sfe_ism_data_t _accelBias{0.0f, 0.0f, 0.0f};
216 sfe_ism_data_t _gyroBias{0.0f, 0.0f, 0.0f};
217 bool _biasValid = false;
218};
219
static void enable(board_bringup_t *b, uint16_t device_id)
bool readPeripheralSensor(uint8_t *shReg, uint8_t len)
bool getRawAccel(sfe_ism_raw_data_t *accelData)
bool getGyroCal(sfe_ism_data_t *gyroData)
stmdev_ctx_t sfe_dev
bool enableTimestamp(bool enable=true)
bool setGyroStatustoInt2(bool enable=true)
float convert2000dpsToMdps(int16_t data)
float convert4000dpsToMdps(int16_t data)
float convert1000dpsToMdps(int16_t data)
uint8_t getBlockDataUpdate()
float convert500dpsToMdps(int16_t data)
bool configureWakeUpOnInt1(uint8_t wkThreshold, uint8_t wakeDur, bool routeAccelGyroDrdyToInt1=false)
bool readMMCMagnetometer(uint8_t *magData, uint8_t len)
bool setNumberHubSensors(uint8_t numSensors)
bool setDeviceConfig(bool enable=true)
float convertToCelsius(int16_t data)
bool setHubWriteMode(uint8_t config)
bool setHubPullUps(bool enable=true)
float convert16gToMg(int16_t data)
bool getExternalSensorNack(uint8_t sensor)
bool setDataReadyMode(uint8_t val)
bool setHubPassThrough(bool enable=true)
bool setIntNotification(uint8_t val)
float convert4gToMg(int16_t data)
int32_t writeRegisterRegion(uint8_t reg, uint8_t *data, uint16_t length)
bool setHubSensorRead(uint8_t sensor, sfe_hub_sensor_settings_t *settings)
bool setFifoTimestampDec(uint8_t val)
bool setPinMode(bool activeLow=true)
bool setGyroFifoBatchSet(uint8_t val)
bool getAccel(sfe_ism_data_t *accelData)
bool setAccelSelfTest(uint8_t val)
bool setGyroStatustoInt1(bool enable=true)
bool setHubFifoBatching(bool enable=true)
bool setFifoWtmToInt2(bool enable=true)
bool setAccelFullScale(uint8_t val)
bool setGyroSelfTest(uint8_t val)
bool readFifoSample(sfe_ism_raw_data_t *gyro, sfe_ism_raw_data_t *accel, uint8_t *tag_out=nullptr)
bool setFifoWatermark(uint16_t val)
sfe_ism_data_t _accelBias
bool getRawGyro(sfe_ism_raw_data_t *gyroData)
bool setGyroLP1Bandwidth(uint8_t val)
bool setAccelFilterLP2(bool enable=true)
bool setAccelStatustoInt1(bool enable=true)
bool setAccelSlopeFilter(uint8_t val)
float convert125dpsToMdps(int16_t data)
float convert250dpsToMdps(int16_t data)
bool setHubSensorWrite(sfe_hub_sensor_settings_t *settings)
bool setAccelStatustoInt2(bool enable=true)
sfe_ISM330DHCX::QwIDeviceBus * _sfeBus
bool getAccelCal(sfe_ism_data_t *accelData)
uint16_t getFifoLevel()
int32_t readRegisterRegion(uint8_t reg, uint8_t *data, uint16_t length)
float convert2gToMg(int16_t data)
bool calibrateBiases(uint16_t samples=256)
bool setGyroFilterLP1(bool enable=true)
bool setAccelFifoBatchSet(uint8_t val)
bool setAccelDataRate(uint8_t rate)
sfe_ism_data_t _gyroBias
float convert8gToMg(int16_t data)
uint8_t getAccelFullScale()
bool setGyroFullScale(uint8_t val)
bool getGyro(sfe_ism_data_t *gyroData)
bool setGyroDataRate(uint8_t rate)
bool setBlockDataUpdate(bool enable=true)
bool setHubODR(uint8_t rate)
void setCommunicationBus(sfe_ISM330DHCX::QwIDeviceBus &theBus, uint8_t i2cAddress)
bool enableSensorI2C(bool enable)
bool setFifoMode(uint8_t val)
bool serviceWakeUpInterrupt(sfe_ism330_wake_event_t *out)
uint8_t reg
static sfe_ism_data_t gyroData
Definition main.cpp:10
static sfe_ism_data_t accelData
Definition main.cpp:9
static const idle_config_t config
Definition idle_task.c:17
Filled by serviceWakeUpInterrupt() when INT1 was a wake-up (high-accel) event.