STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
sfe_ism330dhcx.cpp
Go to the documentation of this file.
1#include "sfe_ism330dhcx.h"
2
3//////////////////////////////////////////////////////////////////////////////
4// init()
5//
6// init the system
7//
8// Return Value: false on error, true on success
9//
10
12{
13 // do we have a bus yet? is the device connected?
14 if (!_sfeBus->ping(_i2cAddress))
15 return false;
16
17 initCtx((void*)this, &sfe_dev);
18
19 // I2C ready, now check that we're using the correct sensor before moving on.
21 return false;
22
23
24 return true;
25}
26
27
28
29///////////////////////////////////////////////////////////////////////
30// isConnected()
31//
32// Called to determine if a ISM330DHCX device, at the provided i2c address
33// is connected.
34//
35// Parameter Description
36// --------- -----------------------------
37// retVal true if device is connected, false if not connected
38
40{
42 return false;
43 else
44 return true;
45}
46
47
48////////////////////////////////////////////////////////////////////////////////////
49// setCommunicationBus()
50//
51// Method to set the bus object that is used to communicate with the device
52//
53// Parameter Description
54// --------- -----------------------------
55// theBus The communication bus object
56// i2cAddress I2C address for the 6DoF
57
59{
60 _sfeBus = &theBus;
61 _i2cAddress = i2cAddress;
62}
63
64////////////////////////////////////////////////////////////////////////////////////
65// setCommunicationBus()
66//
67// Overloaded option for setting the data bus (theBus) object to a SPI bus object.
68//
69// Parameter Description
70// --------- -----------------------------
71// theBus The communication bus object
72//
73
78
79//////////////////////////////////////////////////////////////////////////////
80// writeRegisterRegion()
81//
82// Writes data to the given register
83//
84// Parameter Description
85// --------- -----------------------------
86// offset The register to be written to
87// data Data to be written
88// length Number of bytes to be written
89
90int32_t QwDevISM330DHCX::writeRegisterRegion(uint8_t offset, uint8_t *data, uint16_t length)
91{
92 return _sfeBus->writeRegisterRegion(_i2cAddress, offset, data, length);
93}
94
95//////////////////////////////////////////////////////////////////////////////
96// readRegisterRegion()
97//
98// Reads data from the given register, auto-incrementing fore each successive read
99//
100// Parameter Description
101// --------- -----------------------------
102// offset The register to be read from
103// data Pointer to where data will be saved
104// length Number of bytes to be read
105
106int32_t QwDevISM330DHCX::readRegisterRegion(uint8_t offset, uint8_t *data, uint16_t length)
107{
108 return _sfeBus->readRegisterRegion(_i2cAddress, offset, data, length);
109}
110
111//////////////////////////////////////////////////////////////////////////////
112// setAccelFullScale()
113//
114// Sets the scale of the acceleromter's readings 2g - 16g
115//
116// Parameter Description
117// --------- -----------------------------
118// val The scale to be applied to the accelerometer (0 - 3)
119//
120// See sfe_ism330dhcx_defs.h for a list of valid arguments
121//
122
124{
125 //0 = 2g, 1 = 16g, 2 = 4g, 3 = 8g
126 if( val > 3 )
127 return false;
128
129 int32_t retVal = (ism330dhcx_xl_full_scale_set(&sfe_dev,
130 (ism330dhcx_fs_xl_t)val));
131
132 fullScaleAccel = val;
133
134 if( retVal != 0 )
135 return false;
136
137 return true;
138}
139
140
141//////////////////////////////////////////////////////////////////////////////
142// setGyroFullScale()
143//
144// Sets the scale of the gyroscopes's readings 125, 250, 500, 1000, 2000, 4000 degrees per second
145//
146// Parameter Description
147// --------- -----------------------------
148// val The scale to be applied to the gyroscope (0,1,2,4,6,12)
149//
150// See sfe_ism330dhcx_defs.h for a list of valid arguments
151//
153{
154 //0,1,2,4,8,12
155 if( val > 12 )
156 return false;
157
158 int32_t retVal = ism330dhcx_gy_full_scale_set(&sfe_dev,
159 (ism330dhcx_fs_g_t)val);
160
161 fullScaleGyro = val;
162
163 if( retVal != 0 )
164 return false;
165
166 return true;
167}
168
169//////////////////////////////////////////////////////////////////////////////
170// getAccelFullScale()
171//
172// Retrieves the scale of the accelerometer's readings
173//
174
176{
177
179 int32_t retVal = ism330dhcx_xl_full_scale_get(&sfe_dev, &val);
180
181 if( retVal != 0 )
182 return -1;
183
184 return (uint8_t)val;
185}
186
187//////////////////////////////////////////////////////////////////////////////
188// getUniqueId()
189//
190// Retrieves the the device's ID: 0x6B for the ISM330DHCX
191//
192
194{
195
196 uint8_t buff = 0;
197 int32_t retVal = (ism330dhcx_device_id_get(&sfe_dev, &buff));
198
199 if(retVal != 0)
200 return 0;
201
202 return buff;
203}
204
205
206//////////////////////////////////////////////////////////////////////////////
207// getTemp()
208//
209// Gets the temperature
210//
211
213{
214
215 int16_t tempVal;
216 int32_t retVal = ism330dhcx_temperature_raw_get(&sfe_dev, &tempVal);
217
218 if( retVal != 0 )
219 return -1;
220
221 return tempVal;
222
223}
224
225
226//////////////////////////////////////////////////////////////////////////////
227// getRawAccel()
228//
229// Retrieves raw register values for accelerometer data
230//
231// Parameter Description
232// --------- -----------------------------
233// accelData Accel data type pointer at which data will be stored.
234
236{
237 int16_t tempVal[3] = {0};
238 int32_t retVal = ism330dhcx_acceleration_raw_get(&sfe_dev, tempVal);
239
240 if( retVal != 0 )
241 return false;
242
243 accelData->xData = tempVal[0];
244 accelData->yData = tempVal[1];
245 accelData->zData = tempVal[2];
246
247 return true;
248
249}
250
251
252//////////////////////////////////////////////////////////////////////////////
253// getRawGyro()
254//
255// Retrieves raw register values for gyroscope data
256//
257// Parameter Description
258// --------- -----------------------------
259// gyroData Gyro data type pointer at which data will be stored.
260//
261
263{
264
265 int16_t tempVal[3] = {0};
266 int32_t retVal = ism330dhcx_angular_rate_raw_get(&sfe_dev, tempVal);
267
268 if( retVal != 0 )
269 return false;
270
271
272 gyroData->xData = tempVal[0];
273 gyroData->yData = tempVal[1];
274 gyroData->zData = tempVal[2];
275
276 return true;
277
278}
279
280
281//////////////////////////////////////////////////////////////////////////////
282// getAccel()
283//
284// Retrieves raw register values and converts them according to the full scale settings
285//
286// Parameter Description
287// --------- -----------------------------
288// accelData Accel data type pointer at which data will be stored.
289//
290
292{
293
294 int16_t tempVal[3] = {0};
295 int32_t retVal = ism330dhcx_acceleration_raw_get(&sfe_dev, tempVal);
296
297 if( retVal != 0 )
298 return false;
299
300 // "fullScaleAccel" is a private variable that keeps track of the users settings
301 // so that the register values can be converted accordingly
302 switch( fullScaleAccel ){
303 case 0:
304 accelData->xData = convert2gToMg(tempVal[0]);
305 accelData->yData = convert2gToMg(tempVal[1]);
306 accelData->zData = convert2gToMg(tempVal[2]);
307 break;
308 case 1:
309 accelData->xData = convert16gToMg(tempVal[0]);
310 accelData->yData = convert16gToMg(tempVal[1]);
311 accelData->zData = convert16gToMg(tempVal[2]);
312 break;
313 case 2:
314 accelData->xData = convert4gToMg(tempVal[0]);
315 accelData->yData = convert4gToMg(tempVal[1]);
316 accelData->zData = convert4gToMg(tempVal[2]);
317 break;
318 case 3:
319 accelData->xData = convert8gToMg(tempVal[0]);
320 accelData->yData = convert8gToMg(tempVal[1]);
321 accelData->zData = convert8gToMg(tempVal[2]);
322 break;
323 default:
324 return false; //Something has gone wrong
325 }
326
327 return true;
328}
329
330//////////////////////////////////////////////////////////////////////////////
331// getGyro()
332//
333// Retrieves raw register values and converts them according to the full scale settings
334//
335// Parameter Description
336// --------- -----------------------------
337// gyroData Gyroscope data type pointer at which data will be stored.
338//
339
340
342{
343
344 int16_t tempVal[3] = {0};
345 int32_t retVal = ism330dhcx_angular_rate_raw_get(&sfe_dev, tempVal);
346
347 if( retVal != 0 )
348 return false;
349
350 // "fullScaleGyro" is a private variable that keeps track of the users settings
351 // so that the register values can be converted accordingly
352 switch( fullScaleGyro ){
353 case 0:
354 gyroData->xData = convert250dpsToMdps(tempVal[0]);
355 gyroData->yData = convert250dpsToMdps(tempVal[1]);
356 gyroData->zData = convert250dpsToMdps(tempVal[2]);
357 break;
358 case 1:
359 gyroData->xData = convert4000dpsToMdps(tempVal[0]);
360 gyroData->yData = convert4000dpsToMdps(tempVal[1]);
361 gyroData->zData = convert4000dpsToMdps(tempVal[2]);
362 break;
363 case 2:
364 gyroData->xData = convert125dpsToMdps(tempVal[0]);
365 gyroData->yData = convert125dpsToMdps(tempVal[1]);
366 gyroData->zData = convert125dpsToMdps(tempVal[2]);
367 break;
368 case 4:
369 gyroData->xData = convert500dpsToMdps(tempVal[0]);
370 gyroData->yData = convert500dpsToMdps(tempVal[1]);
371 gyroData->zData = convert500dpsToMdps(tempVal[2]);
372 break;
373 case 8:
374 gyroData->xData = convert1000dpsToMdps(tempVal[0]);
375 gyroData->yData = convert1000dpsToMdps(tempVal[1]);
376 gyroData->zData = convert1000dpsToMdps(tempVal[2]);
377 break;
378 case 12:
379 gyroData->xData = convert2000dpsToMdps(tempVal[0]);
380 gyroData->yData = convert2000dpsToMdps(tempVal[1]);
381 gyroData->zData = convert2000dpsToMdps(tempVal[2]);
382 break;
383 default:
384 return false; //Something has gone wrong
385 }
386
387 return true;
388}
389
390
391
392//////////////////////////////////////////////////////////////////////////////////
393// Conversions Methods
394//
395//
396
398{
399 return(ism330dhcx_from_fs2g_to_mg(data));
400}
401
403{
404 return(ism330dhcx_from_fs4g_to_mg(data));
405}
406
408{
409 return(ism330dhcx_from_fs8g_to_mg(data));
410}
411
413{
414 return(ism330dhcx_from_fs16g_to_mg(data));
415}
416
418{
420}
421
423{
425}
426
428{
430}
431
433{
435}
436
438{
440}
441
443{
445}
446
448{
449 return(ism330dhcx_from_lsb_to_celsius(data));
450}
451
452//
453//
454//////////////////////////////////////////////////////////////////////////////////
455
456// Register addresses used by the extensions below (not exposed by the ST shim).
457static constexpr uint8_t ISM_REG_ALL_INT_SRC = 0x1A;
458static constexpr uint8_t ISM_REG_FIFO_STATUS1 = 0x3A;
459static constexpr uint8_t ISM_REG_FIFO_STATUS2 = 0x3B;
460static constexpr uint8_t ISM_REG_FIFO_DATA_OUT_TAG = 0x78; // TAG byte (0x78); data follows at 0x79-0x7E
461static constexpr uint8_t ISM_REG_INT2_CTRL = 0x0E; // INT2_FIFO_TH = bit 3 (0x08)
462
463//////////////////////////////////////////////////////////////////////////////
464// getAllIntSrc()
465//
466// Reads the ALL_INT_SRC register (0x1A). Motion/event flags only — not data-ready.
467// Bit 0 = FF_IA (free-fall), bit 1 = WU_IA (wake-up), bit 2 = SINGLE_TAP,
468// bit 3 = DOUBLE_TAP, bit 4 = D6D_IA (orientation change),
469// bit 5 = SLEEP_CHANGE_IA, bit 6 = (reserved), bit 7 = TIMESTAMP_ENDCOUNT.
470//
472{
473 uint8_t val = 0;
475 return val;
476}
477
479{
480 if (!out)
481 return false;
482 out->axisX = false;
483 out->axisY = false;
484 out->axisZ = false;
485
486 // ALL_INT_SRC: WU_IA is bit 1 (see ST ism330dhcx_all_int_src_t, little-endian bitfield order).
487 const uint8_t all = getAllIntSrc();
488 if ((all & 0x02U) == 0)
489 return false;
490
491 // WAKE_UP_SRC: z_wu bit0, y_wu bit1, x_wu bit2 (little-endian layout in register byte).
492 uint8_t wus = 0;
494 out->axisZ = (wus & 0x01U) != 0;
495 out->axisY = (wus & 0x02U) != 0;
496 out->axisX = (wus & 0x04U) != 0;
497 return true;
498}
499
500bool QwDevISM330DHCX::configureWakeUpOnInt1(uint8_t wkThreshold, uint8_t wakeDur,
501 bool routeAccelGyroDrdyToInt1)
502{
503 if (wkThreshold == 0)
504 wkThreshold = 1;
505 if (wkThreshold > 63)
506 wkThreshold = 63;
507 wakeDur &= 0x03U;
508
510 return false;
511 if (ism330dhcx_wkup_threshold_set(&sfe_dev, wkThreshold) != 0)
512 return false;
513 if (ism330dhcx_wkup_dur_set(&sfe_dev, wakeDur) != 0)
514 return false;
515
518 return false;
519
520 route.md1_cfg.int1_wu = PROPERTY_ENABLE;
521 if (!routeAccelGyroDrdyToInt1) {
522 route.int1_ctrl.int1_drdy_xl = PROPERTY_DISABLE;
523 route.int1_ctrl.int1_drdy_g = PROPERTY_DISABLE;
524 }
525
527}
528
529//////////////////////////////////////////////////////////////////////////////
530// configureSensor()
531//
532// One-call init that mirrors the commonInit() pattern from the bring-up script:
533// - Block data update on
534// - Device config on (enables auto-increment)
535// - Accel: 104 Hz, 2 g
536// - Gyro: 104 Hz, 250 dps
537// - Routes DRDY_XL and DRDY_G to INT1
538//
540{
541 if (!setBlockDataUpdate(true)) return false;
542 if (!setDeviceConfig(true)) return false;
543 if (!setAccelDataRate(ISM_XL_ODR_104Hz)) return false;
544 if (!setAccelFullScale(ISM_2g)) return false;
545 if (!setGyroDataRate(ISM_GY_ODR_104Hz)) return false;
546 if (!setGyroFullScale(ISM_250dps)) return false;
547 if (!setAccelStatustoInt1(true)) return false;
548 if (!setGyroStatustoInt1(true)) return false;
549 return true;
550}
551
552//////////////////////////////////////////////////////////////////////////////
553// getFifoLevel()
554//
555// Returns the number of unread samples currently in the FIFO by reading
556// FIFO_STATUS1 (lower 8 bits) and the two LSBs of FIFO_STATUS2.
557//
559{
560 uint8_t buf[2] = {0};
562 return (uint16_t)buf[0] | (((uint16_t)(buf[1] & 0x03)) << 8);
563}
564
565//////////////////////////////////////////////////////////////////////////////
566// readFifoSample()
567//
568// Reads one 7-byte FIFO word from FIFO_DATA_OUT_TAG (0x78).
569// Each word = 1 TAG byte + 6 data bytes (X/Y/Z as 16-bit little-endian pairs).
570// The TAG byte identifies the sensor:
571// 0x01 = gyro, 0x02 = accel, 0x04 = temperature (per datasheet Table 105).
572//
573// The TAG is returned via *tag_out. Callers should check TAG before interpreting
574// the data — gyro and accel words have the same layout but different scale factors.
575//
576// Returns false if the bus read fails.
577//
579{
580 // Read TAG + 6 data bytes as one 7-byte burst starting at 0x78.
581 uint8_t buf[7] = {0};
583 return false;
584
585 if (tag_out)
586 *tag_out = buf[0];
587
588 // buf[1..6] = X_L, X_H, Y_L, Y_H, Z_L, Z_H
589 sfe_ism_raw_data_t* dst = (buf[0] == 0x01) ? gyro : accel;
590 dst->xData = (int16_t)(buf[1] | ((uint16_t)buf[2] << 8));
591 dst->yData = (int16_t)(buf[3] | ((uint16_t)buf[4] << 8));
592 dst->zData = (int16_t)(buf[5] | ((uint16_t)buf[6] << 8));
593
594 return true;
595}
596
597//////////////////////////////////////////////////////////////////////////////
598// setFifoWtmToInt2()
599//
600// Routes (or removes) the FIFO watermark interrupt to the INT2 pin via
601// INT2_FIFO_TH (bit 3) of INT2_CTRL (0x0E). Call after setFifoWatermark()
602// and setFifoMode().
603//
605{
606 uint8_t val = 0;
607 if (readRegisterRegion(ISM_REG_INT2_CTRL, &val, 1) != 0)
608 return false;
609 if (enable)
610 val |= 0x08; // INT2_FIFO_TH = bit 3
611 else
612 val &= ~0x08;
613 return (writeRegisterRegion(ISM_REG_INT2_CTRL, &val, 1) == 0);
614}
615
616//////////////////////////////////////////////////////////////////////////////
617// calibrateBiases()
618//
619// Collects `samples` readings from getAccel() and getGyro() while the sensor
620// is stationary, then stores the average as internal bias values (mg / mdps).
621// Call getAccelCal() / getGyroCal() to retrieve bias-corrected readings.
622//
623// Note: the device must already be configured and the sensor held still.
624//
626{
627 double ax = 0, ay = 0, az = 0;
628 double gx = 0, gy = 0, gz = 0;
629
631 for (uint16_t i = 0; i < samples; ++i) {
632 if (!getAccel(&a) || !getGyro(&g))
633 return false;
634 ax += a.xData; ay += a.yData; az += a.zData;
635 gx += g.xData; gy += g.yData; gz += g.zData;
636 delay(2); // ~2 ms gap; adequate for ODR ≥ 104 Hz
637 }
638
639 _accelBias.xData = (float)(ax / samples);
640 _accelBias.yData = (float)(ay / samples);
641 _accelBias.zData = (float)(az / samples);
642 _gyroBias.xData = (float)(gx / samples);
643 _gyroBias.yData = (float)(gy / samples);
644 _gyroBias.zData = (float)(gz / samples);
645 _biasValid = true;
646
647 return true;
648}
649
650//////////////////////////////////////////////////////////////////////////////
651// getAccelCal()
652//
653// Reads accelerometer data and subtracts the stored bias. Returns false if
654// calibrateBiases() has not been called or if the bus read fails.
655//
657{
658 if (!_biasValid)
659 return false;
660 if (!getAccel(accelData))
661 return false;
662 accelData->xData -= _accelBias.xData;
663 accelData->yData -= _accelBias.yData;
664 accelData->zData -= _accelBias.zData;
665 return true;
666}
667
668//////////////////////////////////////////////////////////////////////////////
669// getGyroCal()
670//
671// Reads gyroscope data and subtracts the stored bias. Returns false if
672// calibrateBiases() has not been called or if the bus read fails.
673//
675{
676 if (!_biasValid)
677 return false;
678 if (!getGyro(gyroData))
679 return false;
680 gyroData->xData -= _gyroBias.xData;
681 gyroData->yData -= _gyroBias.yData;
682 gyroData->zData -= _gyroBias.zData;
683 return true;
684}
685
686
687
688//////////////////////////////////////////////////////////////////////////////////
689// General Settings
690//
691//
692//
693//
694
695
696//////////////////////////////////////////////////////////////////////////////////
697// setDeviceConfig()
698//
699//
700// Parameter Description
701// --------- -----------------------------
702// enable Enable the general device configuration - this is a configuration
703// register in the ISM330DHCX, not a library implementation.
704
706{
707 int32_t retVal;
708
709 retVal = ism330dhcx_device_conf_set(&sfe_dev, (uint8_t)enable);
710
711 if( retVal != 0 )
712 return false;
713
714 return true;
715}
716
717
718//////////////////////////////////////////////////////////////////////////////////
719// deviceReset()
720//
721// Resets the deivice to default settings
722//
723
725{
726 int32_t retVal;
727
728 retVal = ism330dhcx_reset_set(&sfe_dev, 1);
729
730 if( retVal != 0 )
731 return false;
732
733 return true;
734}
735
736//////////////////////////////////////////////////////////////////////////////////
737// getDeviceReset()
738//
739// Checks to see that the reset bit has been set
740//
741
743{
744
745 int32_t retVal;
746 uint8_t tempVal;
747 retVal = ism330dhcx_reset_get(&sfe_dev, &tempVal);
748
749 if( retVal != 0 )
750 return false;
751
752 if( (tempVal & 0x01) == 0x00 ){
753 return true;
754 }
755
756 return false;
757
758}
759
760
761//////////////////////////////////////////////////////////////////////////////////
762// setAccelSlopeFilter()
763//
764// Sets the accelerometer's slope filter
765//
766// Parameter Description
767// --------- -----------------------------
768// val This parameter determines the intensity of the filter - (0x00 - 0x37)
769//
770// See sfe_ism330dhcx_defs.h for a list of valid arguments
771
773{
774 int32_t retVal;
775 if( val > 0x37 )
776 return false;
777
780
781 if( retVal != 0 )
782 return false;
783
784 return true;
785}
786
787
788
789//////////////////////////////////////////////////////////////////////////////////
790// setAccelFilterLP2()
791//
792// Enables the accelerometer's high resolution slope filter
793//
794// Parameter Description
795// --------- -----------------------------
796// enable Enables/Disables the high resolution slope filter
797//
798
800{
801 int32_t retVal;
802
803 retVal = ism330dhcx_xl_filter_lp2_set(&sfe_dev, (uint8_t)enable);
804
805 if( retVal != 0 )
806 return false;
807
808 return true;
809}
810
811
812//////////////////////////////////////////////////////////////////////////////////
813// setGyroFilterLP1()
814//
815// Enables the gyroscope's slope filter
816//
817// Parameter Description
818// --------- -----------------------------
819// enable Enables/Disables the high resolution slope filter
820//
821
823{
824 int32_t retVal;
825
826 retVal = ism330dhcx_gy_filter_lp1_set(&sfe_dev, (uint8_t)enable);
827
828 if( retVal != 0 )
829 return false;
830
831 return true;
832}
833
834//////////////////////////////////////////////////////////////////////////////////
835// setGyroLP1Bandwidth()
836//
837// Sets the low pass filter's bandwidth for the gyroscope
838//
839// Parameter Description
840// --------- -----------------------------
841// val Sets the bandwidth's value
842//
843// See sfe_ism330dhcx_defs.h for a list of valid arguments
844//
845
847{
848 int32_t retVal;
849 if( val > 7 )
850 return false;
851
853 (ism330dhcx_ftype_t)val);
854
855 if( retVal != 0 )
856 return false;
857
858 return true;
859}
860
861
862//////////////////////////////////////////////////////////////////////////////////
863// setBlockDataUpdate()
864//
865// Data is not updated until both MSB and LSB have been read from output registers
866//
867// Parameter Description
868// --------- -----------------------------
869// enable Enable/disables block data update.
870//
871
873{
874
875 int32_t retVal = ism330dhcx_block_data_update_set(&sfe_dev, (uint8_t)enable);
876
877 if( retVal != 0 )
878 return false;
879
880 return true;
881}
882
883
884//////////////////////////////////////////////////////////////////////////////////
885// getBlockDataUpdate()
886//
887// Retrieves the bit indicating whether block data update is enabled.
888//
889//
890
892{
893
894 uint8_t tempVal;
895 int32_t retVal = ism330dhcx_block_data_update_get(&sfe_dev, &tempVal);
896
897 (void)retVal;
898 return tempVal;
899}
900
901
902//////////////////////////////////////////////////////////////////////////////////
903// setAccelDataRate()
904//
905// This sets the data output rate for the accelerometer.
906//
907// Parameter Description
908// --------- -----------------------------
909// rate Sets the output data rate, expects some value < 11.
910//
911// See sfe_ism330dhcx_defs.h for a list of valid arguments
912
914{
915 if( rate > 11 )
916 return false;
917
919
920 if( retVal != 0)
921 return false;
922
923 return true;
924}
925
926
927//////////////////////////////////////////////////////////////////////////////////
928// setGyroDataRate()
929//
930// This sets the data output rate for the gyroscope.
931//
932// Parameter Description
933// --------- -----------------------------
934// rate Sets the output data rate, expects some value < 10.
935//
936// See sfe_ism330dhcx_defs.h for a list of valid arguments
937//
938
940{
941 if( rate > 10 )
942 return false;
943
945
946 if( retVal != 0 )
947 return false;
948
949 return true;
950}
951
952
953
954//////////////////////////////////////////////////////////////////////////////////
955// enableTimestamp()
956//
957// Enables time stamp counter
958//
959// Parameter Description
960// --------- -----------------------------
961// enable Enables/disables time stamp counter
962//
963
965{
966 int32_t retVal;
967
968 retVal = ism330dhcx_timestamp_set(&sfe_dev, (uint8_t)enable);
969
970 if( retVal != 0 )
971 return false;
972
973 return true;
974}
975
976
977//////////////////////////////////////////////////////////////////////////////////
978// resetTimestamp()
979//
980// Resets time stamp counter
981//
982//
983
985{
986 int32_t retVal;
987
989
990 if( retVal != 0 )
991 return false;
992
993 return true;
994}
995//
996//
997//////////////////////////////////////////////////////////////////////////////////
998
999//////////////////////////////////////////////////////////////////////////////////
1000// FIFO Settings
1001//
1002//
1003//
1004//
1005//
1006//
1007
1008//////////////////////////////////////////////////////////////////////////////////
1009// setFifoWatermark()
1010//
1011// Sets the FIFO's watermark
1012//
1013// Parameter Description
1014// --------- -----------------------------
1015// val Sets the watermark, must be some value less than 511 (9 bit value)
1016//
1017
1019{
1020 int32_t retVal;
1021
1022 if( val > 511 )
1023 return false;
1024
1025 retVal = ism330dhcx_fifo_watermark_set(&sfe_dev, val);
1026
1027 if( retVal != 0 )
1028 return false;
1029
1030 return true;
1031}
1032
1033
1034//////////////////////////////////////////////////////////////////////////////////
1035// setFifoMode()
1036//
1037// Sets the FIFO's mode.
1038//
1039// Parameter Description
1040// --------- -----------------------------
1041// val Selects the FIFO's mode
1042//
1043// See sfe_ism330dhcx_defs.h for a list of valid arguments
1044//
1045
1047{
1048 int32_t retVal;
1049
1050 if( val > 7 )
1051 return false;
1052
1055
1056 if( retVal != 0 )
1057 return false;
1058
1059 return true;
1060}
1061
1062
1063//////////////////////////////////////////////////////////////////////////////////
1064// setAccelFifoBatchSet()
1065//
1066// Sets the batch data rate for the accelerometer
1067//
1068// Parameter Description
1069// --------- -----------------------------
1070// val Sets the batch data rate.
1071//
1072// See sfe_ism330dhcx_defs.h for a list of valid arguments
1073//
1074
1076{
1077 int32_t retVal;
1078 if( val > 11)
1079 return false;
1080
1082 (ism330dhcx_bdr_xl_t)val);
1083
1084 if( retVal != 0 )
1085 return false;
1086
1087 return true;
1088}
1089
1090
1091
1092//////////////////////////////////////////////////////////////////////////////////
1093// setGyroFifoBatchSet()
1094//
1095// Sets the batch data rate for the gyroscope
1096//
1097// Parameter Description
1098// --------- -----------------------------
1099// val Sets the batch data rate.
1100//
1101// See sfe_ism330dhcx_defs.h for a list of valid arguments
1102
1104{
1105 int32_t retVal;
1106 if( val > 11)
1107 return false;
1108
1110 (ism330dhcx_bdr_gy_t)val);
1111
1112 if( retVal != 0 )
1113 return false;
1114
1115 return true;
1116}
1117
1118//////////////////////////////////////////////////////////////////////////////////
1119// setFifoTimestampDec()
1120//
1121// Sets the FIFO time stamp decimation rate.
1122//
1123// Parameter Description
1124// --------- -----------------------------
1125// val Sets the time stamp decimation rate,
1126//
1127// See sfe_ism330dhcx_defs.h for a list of valid arguments
1128
1130{
1131 int32_t retVal;
1132 if( val > 3 )
1133 return false;
1134
1137
1138 if( retVal != 0 )
1139 return false;
1140
1141 return true;
1142}
1143
1144//
1145//
1146//////////////////////////////////////////////////////////////////////////////////
1147
1148//////////////////////////////////////////////////////////////////////////////////
1149// Interrupt Settings
1150//
1151//
1152//
1153//
1154//
1155//
1156
1157//////////////////////////////////////////////////////////////////////////////////
1158// setPinMode
1159//
1160// Sets the active state of the interrupt pin - high or low.
1161//
1162// Parameter Description
1163// --------- -----------------------------
1164// openDrain Set true for active low and false for active high
1165//
1166
1167bool QwDevISM330DHCX::setPinMode(bool activeLow )
1168{
1169 int32_t retVal;
1170
1171 //0 = active high : active low, 1
1173
1174 if( retVal != 0 )
1175 return false;
1176
1177 if( activeLow )
1178 // pinmode must be set to push-pull when active low is set.
1179 // See section 9.14 on pg 51 of datasheet for more information
1181
1182 if( retVal != 0 )
1183 return false;
1184
1185 return true;
1186}
1187
1188
1189//////////////////////////////////////////////////////////////////////////////////
1190// setIntNotification
1191//
1192// Sets what the triggers an interrupt
1193//
1194// Parameter Description
1195// --------- -----------------------------
1196// val Sets which event triggers an interrupt.
1197//
1198// See sfe_ism330dhcx_defs.h for a list of valid arguments
1199
1201{
1202 int32_t retVal;
1203 if( val > 4)
1204 return false;
1205
1207 (ism330dhcx_lir_t)val);
1208
1209 if( retVal != 0 )
1210 return false;
1211
1212 return true;
1213}
1214
1215
1216//////////////////////////////////////////////////////////////////////////////////
1217// setAccelStatustoInt1
1218//
1219// Sends the accelerometer's data ready signal to interrupt one.
1220//
1221
1223{
1224
1225 int32_t retVal;
1226
1227 ism330dhcx_pin_int1_route_t int1_route;
1228
1229 retVal = ism330dhcx_pin_int1_route_get(&sfe_dev, &int1_route);
1230
1231 if( retVal != 0 )
1232 return false;
1233
1234 int1_route.int1_ctrl.int1_drdy_xl = (uint8_t)enable;
1235
1236 retVal = ism330dhcx_pin_int1_route_set(&sfe_dev, &int1_route);
1237
1238 if( retVal != 0 )
1239 return false;
1240
1241 return true;
1242}
1243
1244
1245//////////////////////////////////////////////////////////////////////////////////
1246// setAccelStatustoInt2
1247//
1248// Sends the accelerometer's data ready signal to interrupt two.
1249//
1250
1252{
1253
1254 int32_t retVal;
1255
1256 ism330dhcx_pin_int2_route_t int2_route;
1257
1258 retVal = ism330dhcx_pin_int2_route_get(&sfe_dev, &int2_route);
1259
1260 if( retVal != 0 )
1261 return false;
1262
1263 int2_route.int2_ctrl.int2_drdy_xl = (uint8_t)enable;
1264
1265 retVal = ism330dhcx_pin_int2_route_set(&sfe_dev, &int2_route);
1266
1267 if( retVal != 0 )
1268 return false;
1269
1270 return true;
1271}
1272
1273
1274//////////////////////////////////////////////////////////////////////////////////
1275// setGyroStatustoInt1
1276//
1277// Sends the gyroscopes's data ready signal to interrupt one.
1278//
1280{
1281
1282 int32_t retVal;
1283
1284 ism330dhcx_pin_int1_route_t int1_route;
1285
1286 retVal = ism330dhcx_pin_int1_route_get(&sfe_dev, &int1_route);
1287
1288 if( retVal != 0 )
1289 return false;
1290
1291 int1_route.int1_ctrl.int1_drdy_g = (uint8_t)enable;
1292
1293 retVal = ism330dhcx_pin_int1_route_set(&sfe_dev, &int1_route);
1294
1295 if( retVal != 0 )
1296 return false;
1297
1298 return true;
1299}
1300
1301
1302//////////////////////////////////////////////////////////////////////////////////
1303// setGyroStatustoInt2
1304//
1305// Sends the gyroscopes's data ready signal to interrupt two.
1306//
1308{
1309
1310 int32_t retVal;
1311
1312 ism330dhcx_pin_int2_route_t int2_route;
1313
1314 retVal = ism330dhcx_pin_int2_route_get(&sfe_dev, &int2_route);
1315
1316 if( retVal != 0 )
1317 return false;
1318
1319 int2_route.int2_ctrl.int2_drdy_g = (uint8_t)enable;
1320
1321 retVal = ism330dhcx_pin_int2_route_set(&sfe_dev, &int2_route);
1322
1323 if( retVal != 0 )
1324 return false;
1325
1326 return true;
1327}
1328
1329//////////////////////////////////////////////////////////////////////////////////
1330// setDataReadyMode
1331//
1332// Sets how the data ready signal is latched i.e. only return zero after interface reading
1333// OR is pulsed.
1334//
1336{
1337 int32_t retVal;
1338
1339 //0 = Latched, 1 = Pulsed
1340 if( val > 1 )
1341 return false;
1342
1345
1346 if( retVal != 0 )
1347 return false;
1348
1349 return true;
1350}
1351//
1352//
1353//////////////////////////////////////////////////////////////////////////////////
1354
1355//////////////////////////////////////////////////////////////////////////////////
1356// Sensor Hub Settings
1357//
1358//
1359//
1360//
1361//
1362//
1363//
1364
1365
1366//////////////////////////////////////////////////////////////////////////////////
1367// setHubODR
1368//
1369// Sets the output data rate for the Sensor Hub.
1370//
1371// Parameter Description
1372// --------- -----------------------------
1373// rate Selects the rate
1374//
1375// See sfe_ism330dhcx_defs.h for a list of valid arguments
1376
1378{
1379 //0 = 104Hz, 1 = 52Hz, 2 = 26Hz, 3 = 13Hz
1380 if( rate > 3 )
1381 return false;
1382
1384
1385 if( retVal != 0 )
1386 return false;
1387
1388 return true;
1389}
1390
1391
1392//////////////////////////////////////////////////////////////////////////////////
1393// setHubSensorRead
1394//
1395// Sets the general sensor hub settings, which sensor and their I2C address and register
1396// to read.
1397//
1398// Parameter Description
1399// --------- -----------------------------
1400// sensor Selects the external sensor (1-4)
1401// settings The I2C address, register address, and number of reads for the external sensor
1402// that is connected in sensor hub mode.
1403//
1404//
1406{
1407 int32_t retVal;
1408 ism330dhcx_sh_cfg_read_t tempSett;
1409
1410 if( sensor > 3 )
1411 return false;
1412
1413 tempSett.slv_add = settings->address;
1414 tempSett.slv_subadd = settings->subAddress;
1415 tempSett.slv_len = settings->lenData;
1416
1417
1418 switch( sensor )
1419 {
1420 case 0:
1421 retVal = ism330dhcx_sh_slv0_cfg_read(&sfe_dev, &tempSett);
1422 break;
1423 case 1:
1424 retVal = ism330dhcx_sh_slv1_cfg_read(&sfe_dev, &tempSett);
1425 break;
1426 case 2:
1427 retVal = ism330dhcx_sh_slv2_cfg_read(&sfe_dev, &tempSett);
1428 break;
1429 case 3:
1430 retVal = ism330dhcx_sh_slv3_cfg_read(&sfe_dev, &tempSett);
1431 break;
1432 default:
1433 return false;
1434 }
1435
1436
1437 if( retVal != 0 )
1438 return false;
1439
1440 return true;
1441}
1442
1443
1444//////////////////////////////////////////////////////////////////////////////////
1445// setHubSensorWrite
1446//
1447// Gives settings to the 6DoF with regards to the address, register, and data to write to an external
1448// sensor.
1449//
1450// Parameter Description
1451// --------- -----------------------------
1452// settings Struct containing the address, register, and data to write to the external sensor
1453//
1454
1456{
1457 int32_t retVal;
1459
1460 tempSett.slv0_add = settings->address;
1461 tempSett.slv0_subadd = settings->subAddress;
1462 tempSett.slv0_data = settings->lenData;
1463
1464 retVal = ism330dhcx_sh_cfg_write(&sfe_dev, &tempSett);
1465
1466 if( retVal != 0 )
1467 return false;
1468
1469 return true;
1470}
1471
1472//////////////////////////////////////////////////////////////////////////////////
1473// setNumberHubSensors
1474//
1475// Sets the number of external sensor connected to the ISM
1476//
1477// Parameter Description
1478// --------- -----------------------------
1479// numSensor The number of sensors 0 - 3 = 4
1480//
1481
1483{
1484
1485 int32_t retVal;
1486 if( numSensors > 3 )
1487 return false;
1488
1490 (ism330dhcx_aux_sens_on_t)numSensors);
1491
1492 if( retVal != 0 )
1493 return false;
1494
1495 return true;
1496
1497}
1498
1499
1500//////////////////////////////////////////////////////////////////////////////////
1501// enableSensorI2C
1502//
1503// Enables the 6DoF as an I2C sensor controller
1504//
1505
1507{
1508 int32_t retVal;
1509
1510 retVal = ism330dhcx_sh_master_set(&sfe_dev, (uint8_t)enable);
1511
1512 if( retVal != 0 )
1513 return false;
1514
1515 return true;
1516}
1517
1518
1519//////////////////////////////////////////////////////////////////////////////////
1520// readPeripheralSensor
1521//
1522// Read external sensor hub data.
1523//
1524// Parameter Description
1525// --------- -----------------------------
1526// shReg Pointer to store the data to be read.
1527// len Number of reads to be executed.
1528
1529bool QwDevISM330DHCX::readPeripheralSensor(uint8_t* shReg, uint8_t len)
1530{
1531 int32_t retVal;
1532
1534
1535 if( retVal != 0 )
1536 return false;
1537
1538 return true;
1539}
1540
1541
1542//////////////////////////////////////////////////////////////////////////////////
1543// getHubStatus
1544//
1545// Checks whether communication with the external sensor has concluded.
1546//
1547
1549{
1550
1551 int32_t retVal;
1553
1554 retVal = ism330dhcx_sh_status_get(&sfe_dev, &tempVal);
1555
1556 if( retVal != 0 )
1557 return false;
1558
1559 if( tempVal.sens_hub_endop == 1 )
1560 return true;
1561
1562 return false;
1563}
1564
1565//////////////////////////////////////////////////////////////////////////////////
1566// getExternalSensorNack
1567//
1568// Retrieves communication status when communicating with external sensor
1569//
1570// Parameter Description
1571// --------- -----------------------------
1572// sensor The sensor to check, (0-3)
1573
1574
1576{
1577
1578 int32_t retVal;
1580
1581 retVal = ism330dhcx_sh_status_get(&sfe_dev, &tempVal);
1582
1583 if( retVal != 0 )
1584 return false;
1585
1586 switch( sensor ){
1587 case 0:
1588 if( tempVal.slave0_nack == 1 )
1589 return true;
1590 break;
1591 case 1:
1592 if( tempVal.slave1_nack == 1 )
1593 return true;
1594 break;
1595 case 2:
1596 if( tempVal.slave2_nack == 1 )
1597 return true;
1598 break;
1599 case 3:
1600 if( tempVal.slave3_nack == 1 )
1601 return true;
1602 break;
1603 default:
1604 return false;
1605 }
1606
1607 return false;
1608}
1609
1610bool QwDevISM330DHCX::readMMCMagnetometer(uint8_t* magData, uint8_t len)
1611{
1612 return(readPeripheralSensor(magData, len));
1613}
1614
1615
1616//////////////////////////////////////////////////////////////////////////////////
1617// setHubWriteMode
1618//
1619// Sets how often the 6DoF should write to the external sensor: once per cycle i.e. output
1620// data rate, or just once.
1621//
1622// Parameter Description
1623// --------- -----------------------------
1624// config How often to be written
1625
1627{
1628 int32_t retVal;
1629
1630 if( config > 1)
1631 return false;
1632
1633 // 0 = Write each cycle
1634 // 1 = Write once
1637
1638 if( retVal != 0 )
1639 return false;
1640
1641 return true;
1642}
1643
1644
1645//////////////////////////////////////////////////////////////////////////////////
1646// setHubPassThrough
1647//
1648// Allows the primary I2C data lines to communicate through the auxiliary I2C lines.
1649//
1650// Parameter Description
1651// --------- -----------------------------
1652// set Enables/disables pass through
1653//
1654
1656{
1657
1658 int32_t retVal = ism330dhcx_sh_pass_through_set(&sfe_dev, (uint8_t)enable);
1659
1660 if( retVal != 0 )
1661 return false;
1662
1663 return true;
1664}
1665
1666//////////////////////////////////////////////////////////////////////////////////
1667// setHubFifoBatching
1668//
1669// Sets sensor hub FIFO batching
1670//
1671// Parameter Description
1672// --------- -----------------------------
1673// enable Enable/disables fifo batching
1674
1676{
1677 int32_t retVal;
1678
1679 retVal = ism330dhcx_sh_batch_slave_0_set(&sfe_dev, (uint8_t)enable);
1680
1681 if( retVal != 0 )
1682 return false;
1683
1684 return true;
1685}
1686
1687
1688//////////////////////////////////////////////////////////////////////////////////
1689// setHubPullUps
1690//
1691// Enables/Disables internal pullups on SDX/SCX lines
1692//
1693// Parameter Description
1694// --------- -----------------------------
1695// enable Enable/disables internal pullups on SDX/SCX lines
1696
1698{
1699
1700 int32_t retVal;
1701
1703
1704 if( retVal != 0 )
1705 return false;
1706
1707 return true;
1708}
1709
1710
1711//////////////////////////////////////////////////////////////////////////////////
1712// resetSensorHub
1713//
1714// Resets all settings in the "Master Config" register
1715//
1716
1718{
1719
1720 int32_t retVal;
1721
1723
1724 if( retVal != 0 )
1725 return false;
1726
1727 return true;
1728}
1729//
1730//
1731//////////////////////////////////////////////////////////////////////////////////
1732
1733//////////////////////////////////////////////////////////////////////////////////
1734// Self Test
1735//
1736//
1737//
1738//
1739//
1740//
1741//
1742
1744{
1745 int32_t retVal;
1746
1747 if( val > 2)
1748 return false;
1749
1751 (ism330dhcx_st_xl_t)val);
1752
1753 if( retVal != 0 )
1754 return false;
1755
1756 return true;
1757}
1758
1760{
1761 int32_t retVal;
1762
1763 // 0, 1, or 3
1764 if( val > 3)
1765 return false;
1766
1768 (ism330dhcx_st_g_t)val);
1769
1770 if( retVal != 0 )
1771 return false;
1772
1773 return true;
1774}
1775//
1776//
1777//////////////////////////////////////////////////////////////////////////////////
1778
1779//////////////////////////////////////////////////////////////////////////////////
1780// checkStatus
1781//
1782// Checks if data is ready for both the acclerometer and the gyroscope
1783//
1784
1786{
1788 int32_t retVal = ism330dhcx_status_reg_get(&sfe_dev, &tempVal);
1789
1790 if( retVal != 0)
1791 return false;
1792
1793 if( (tempVal.xlda == 1) && (tempVal.gda == 1) )
1794 return true;
1795
1796 return false;
1797
1798}
1799
1800//////////////////////////////////////////////////////////////////////////////////
1801// checkAccelStatus
1802//
1803// Checks if data is ready for the acclerometer
1804
1806{
1808 int32_t retVal = ism330dhcx_status_reg_get(&sfe_dev, &tempVal);
1809
1810 if( retVal != 0)
1811 return false;
1812
1813 if( tempVal.xlda == 1 )
1814 return true;
1815
1816 return false;
1817
1818}
1819
1820//////////////////////////////////////////////////////////////////////////////////
1821// checkAccelStatus
1822//
1823// Checks if data is ready for the gyroscope
1824
1826{
1828 int32_t retVal = ism330dhcx_status_reg_get(&sfe_dev, &tempVal);
1829
1830 if( retVal != 0)
1831 return false;
1832
1833 if( tempVal.gda == 1 )
1834 return true;
1835
1836 return false;
1837
1838}
1839
1840//////////////////////////////////////////////////////////////////////////////////
1841// checkAccelStatus
1842//
1843// Checks if data is ready for the temperature sensor
1844
1846{
1848 int32_t retVal = ism330dhcx_status_reg_get(&sfe_dev, &tempVal);
1849
1850 if( retVal != 0)
1851 return false;
1852
1853 if( tempVal.tda == 1 )
1854 return true;
1855
1856 return false;
1857
1858}
1859
void delay(int ms)
static void enable(board_bringup_t *b, uint16_t device_id)
static const board_spi_route_t * route(board_spi_device_t device)
Definition board_spi.c:49
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)
static sfe_ism_data_t gyroData
Definition main.cpp:10
static sfe_ism_data_t accelData
Definition main.cpp:9
int32_t ism330dhcx_angular_rate_raw_get(stmdev_ctx_t *ctx, int16_t *val)
Angular rate sensor.
int32_t ism330dhcx_temperature_raw_get(stmdev_ctx_t *ctx, int16_t *val)
Temperature data output register (r).
int32_t ism330dhcx_acceleration_raw_get(stmdev_ctx_t *ctx, int16_t *val)
Linear acceleration output register.
float ism330dhcx_from_fs8g_to_mg(int16_t lsb)
float ism330dhcx_from_fs4000dps_to_mdps(int16_t lsb)
float ism330dhcx_from_fs2g_to_mg(int16_t lsb)
float ism330dhcx_from_fs4g_to_mg(int16_t lsb)
float ism330dhcx_from_lsb_to_celsius(int16_t lsb)
float ism330dhcx_from_fs250dps_to_mdps(int16_t lsb)
float ism330dhcx_from_fs125dps_to_mdps(int16_t lsb)
float ism330dhcx_from_fs2000dps_to_mdps(int16_t lsb)
float ism330dhcx_from_fs500dps_to_mdps(int16_t lsb)
float ism330dhcx_from_fs1000dps_to_mdps(int16_t lsb)
float ism330dhcx_from_fs16g_to_mg(int16_t lsb)
int32_t ism330dhcx_sh_status_get(stmdev_ctx_t *ctx, ism330dhcx_status_master_t *val)
Sensor hub source register.
int32_t ism330dhcx_sh_slv2_cfg_read(stmdev_ctx_t *ctx, ism330dhcx_sh_cfg_read_t *val)
Configure slave 2 for perform a write/read.
int32_t ism330dhcx_sh_pin_mode_set(stmdev_ctx_t *ctx, ism330dhcx_shub_pu_en_t val)
Master I2C pull-up enable.
int32_t ism330dhcx_sh_pass_through_set(stmdev_ctx_t *ctx, uint8_t val)
I2C interface pass-through.
int32_t ism330dhcx_sh_data_rate_set(stmdev_ctx_t *ctx, ism330dhcx_shub_odr_t val)
Rate at which the master communicates.
int32_t ism330dhcx_sh_slv1_cfg_read(stmdev_ctx_t *ctx, ism330dhcx_sh_cfg_read_t *val)
Configure slave 0 for perform a write/read.
int32_t ism330dhcx_sh_master_set(stmdev_ctx_t *ctx, uint8_t val)
Sensor hub I2C master enable.
int32_t ism330dhcx_sh_reset_set(stmdev_ctx_t *ctx)
Reset Master logic and output registers.
int32_t ism330dhcx_sh_slv0_cfg_read(stmdev_ctx_t *ctx, ism330dhcx_sh_cfg_read_t *val)
Configure slave 0 for perform a write/read.
int32_t ism330dhcx_sh_write_mode_set(stmdev_ctx_t *ctx, ism330dhcx_write_once_t val)
Slave 0 write operation is performed only at the first sensor hub cycle.
int32_t ism330dhcx_sh_slave_connected_set(stmdev_ctx_t *ctx, ism330dhcx_aux_sens_on_t val)
Number of external sensors to be read by the sensor hub.
int32_t ism330dhcx_sh_slv3_cfg_read(stmdev_ctx_t *ctx, ism330dhcx_sh_cfg_read_t *val)
Configure slave 3 for perform a write/read.
int32_t ism330dhcx_sh_cfg_write(stmdev_ctx_t *ctx, ism330dhcx_sh_cfg_write_t *val)
Configure slave 0 for perform a write.
int32_t ism330dhcx_sh_read_data_raw_get(stmdev_ctx_t *ctx, ism330dhcx_emb_sh_read_t *val, uint8_t len)
Sensor hub output registers.
int32_t ism330dhcx_timestamp_set(stmdev_ctx_t *ctx, uint8_t val)
Enables timestamp counter.
int32_t ism330dhcx_timestamp_rst(stmdev_ctx_t *ctx)
Reset timestamp counter.
int32_t ism330dhcx_wkup_threshold_set(stmdev_ctx_t *ctx, uint8_t val)
Threshold for wakeup: 1 LSB weight depends on WAKE_THS_W in WAKE_UP_DUR.
int32_t ism330dhcx_wkup_ths_weight_set(stmdev_ctx_t *ctx, ism330dhcx_wake_ths_w_t val)
Weight of 1 LSB of wakeup threshold.
int32_t ism330dhcx_wkup_dur_set(stmdev_ctx_t *ctx, uint8_t val)
Wake up duration event(1LSb = 1 / ODR).
int32_t ism330dhcx_device_id_get(stmdev_ctx_t *ctx, uint8_t *buff)
Device Who am I.
int32_t ism330dhcx_reset_get(stmdev_ctx_t *ctx, uint8_t *val)
Software reset.
int32_t ism330dhcx_gy_self_test_set(stmdev_ctx_t *ctx, ism330dhcx_st_g_t val)
Angular rate sensor self-test enable.
int32_t ism330dhcx_data_ready_mode_set(stmdev_ctx_t *ctx, ism330dhcx_dataready_pulsed_t val)
Data-ready pulsed / letched mode.
int32_t ism330dhcx_reset_set(stmdev_ctx_t *ctx, uint8_t val)
Software reset.
int32_t ism330dhcx_xl_self_test_set(stmdev_ctx_t *ctx, ism330dhcx_st_xl_t val)
Linear acceleration sensor self-test enable.
int32_t ism330dhcx_device_conf_set(stmdev_ctx_t *ctx, uint8_t val)
DEVICE_CONF bit configuration[set].
int32_t ism330dhcx_fifo_xl_batch_set(stmdev_ctx_t *ctx, ism330dhcx_bdr_xl_t val)
Selects Batching Data Rate (writing frequency in FIFO) for accelerometer data.
int32_t ism330dhcx_sh_batch_slave_0_set(stmdev_ctx_t *ctx, uint8_t val)
Enable FIFO batching data of first slave.
int32_t ism330dhcx_fifo_gy_batch_set(stmdev_ctx_t *ctx, ism330dhcx_bdr_gy_t val)
Selects Batching Data Rate (writing frequency in FIFO) for gyroscope data.
int32_t ism330dhcx_fifo_watermark_set(stmdev_ctx_t *ctx, uint16_t val)
FIFO watermark level selection.
int32_t ism330dhcx_fifo_timestamp_decimation_set(stmdev_ctx_t *ctx, ism330dhcx_odr_ts_batch_t val)
Selects decimation for timestamp batching in FIFO.
int32_t ism330dhcx_fifo_mode_set(stmdev_ctx_t *ctx, ism330dhcx_fifo_mode_t val)
FIFO mode selection.
int32_t ism330dhcx_gy_filter_lp1_set(stmdev_ctx_t *ctx, uint8_t val)
Enables gyroscope digital LPF1 if auxiliary SPI is disabled; the bandwidth can be selected through FT...
int32_t ism330dhcx_gy_lp1_bandwidth_set(stmdev_ctx_t *ctx, ism330dhcx_ftype_t val)
Gyroscope low pass filter 1 bandwidth.
int32_t ism330dhcx_xl_hp_path_on_out_set(stmdev_ctx_t *ctx, ism330dhcx_hp_slope_xl_en_t val)
Accelerometer slope filter / high-pass filter selection on output.
int32_t ism330dhcx_xl_filter_lp2_set(stmdev_ctx_t *ctx, uint8_t val)
Accelerometer output from LPF2 filtering stage selection.
int32_t ism330dhcx_pin_int2_route_set(stmdev_ctx_t *ctx, ism330dhcx_pin_int2_route_t *val)
Select the signal that need to route on int2 pad[set].
int32_t ism330dhcx_pin_polarity_set(stmdev_ctx_t *ctx, ism330dhcx_h_lactive_t val)
Interrupt active-high/low.
int32_t ism330dhcx_pin_int1_route_get(stmdev_ctx_t *ctx, ism330dhcx_pin_int1_route_t *val)
Select the signal that need to route on int1 pad.
int32_t ism330dhcx_pin_mode_set(stmdev_ctx_t *ctx, ism330dhcx_pp_od_t val)
Push-pull/open drain selection on interrupt pads.
int32_t ism330dhcx_pin_int2_route_get(stmdev_ctx_t *ctx, ism330dhcx_pin_int2_route_t *val)
Select the signal that need to route on int2 pad.
int32_t ism330dhcx_int_notification_set(stmdev_ctx_t *ctx, ism330dhcx_lir_t val)
All interrupt signals notification mode.
int32_t ism330dhcx_pin_int1_route_set(stmdev_ctx_t *ctx, ism330dhcx_pin_int1_route_t *val)
Select the signal that need to route on int1 pad[set].
ism330dhcx_bdr_gy_t
ism330dhcx_aux_sens_on_t
ism330dhcx_fs_g_t
ism330dhcx_odr_g_t
ism330dhcx_ftype_t
ism330dhcx_hp_slope_xl_en_t
ism330dhcx_dataready_pulsed_t
ism330dhcx_fifo_mode_t
ism330dhcx_lir_t
ism330dhcx_shub_odr_t
ism330dhcx_write_once_t
ism330dhcx_shub_pu_en_t
#define ISM330DHCX_WAKE_UP_SRC
ism330dhcx_bdr_xl_t
#define ISM330DHCX_ID
Device Identification (Who am I).
ism330dhcx_odr_xl_t
ism330dhcx_odr_ts_batch_t
ism330dhcx_pp_od_t
ism330dhcx_h_lactive_t
ism330dhcx_fs_xl_t
ism330dhcx_st_g_t
ism330dhcx_st_xl_t
@ ISM330DHCX_LSb_FS_DIV_64
int32_t ism330dhcx_xl_full_scale_get(stmdev_ctx_t *ctx, ism330dhcx_fs_xl_t *val)
Accelerometer full-scale selection.
int32_t ism330dhcx_gy_full_scale_set(stmdev_ctx_t *ctx, ism330dhcx_fs_g_t val)
Gyroscope UI chain full-scale selection.
int32_t ism330dhcx_status_reg_get(stmdev_ctx_t *ctx, ism330dhcx_status_reg_t *val)
The STATUS_REG register is read by the primary interface.
int32_t ism330dhcx_block_data_update_get(stmdev_ctx_t *ctx, uint8_t *val)
Block data update.
int32_t ism330dhcx_xl_full_scale_set(stmdev_ctx_t *ctx, ism330dhcx_fs_xl_t val)
Accelerometer full-scale selection[set].
int32_t ism330dhcx_xl_data_rate_set(stmdev_ctx_t *ctx, ism330dhcx_odr_xl_t val)
Accelerometer UI data rate selection.
int32_t ism330dhcx_gy_data_rate_set(stmdev_ctx_t *ctx, ism330dhcx_odr_g_t val)
Gyroscope data rate.
int32_t ism330dhcx_block_data_update_set(stmdev_ctx_t *ctx, uint8_t val)
Block data update.
#define PROPERTY_ENABLE
#define PROPERTY_DISABLE
static const idle_config_t config
Definition idle_task.c:17
*brief create JSON pointer *sa reference_tokens const string_t & a
Definition json.hpp:13877
static constexpr uint8_t ISM_REG_FIFO_STATUS1
static constexpr uint8_t ISM_REG_ALL_INT_SRC
static constexpr uint8_t ISM_REG_FIFO_STATUS2
static constexpr uint8_t ISM_REG_FIFO_DATA_OUT_TAG
static constexpr uint8_t ISM_REG_INT2_CTRL
#define ISM_250dps
#define ISM_GY_ODR_104Hz
#define ISM_2g
#define ISM_XL_ODR_104Hz
void initCtx(void *handle, stmdev_ctx_t *dev)
ism330dhcx_int1_ctrl_t int1_ctrl
ism330dhcx_int2_ctrl_t int2_ctrl
Filled by serviceWakeUpInterrupt() when INT1 was a wake-up (high-accel) event.
static ArmGate g(kMe)