Skip to content

Commit e168cf1

Browse files
committed
Changing the way inv_icm20948_enable_dmp_sensor and inv_icm20948_enable_dmp_sensor_int work
This commit makes inv_icm20948_enable_dmp_sensor and inv_icm20948_enable_dmp_sensor_int more like the InvenSense example. _enabled_Android_0/1 and _enabled_Android_intr_0/1 keep track of which sensors/interrupts are enabled, so that more than one sensor can be enabled. Sensors can now be disabled too if required. Adding ICM_20948_Stat_FIFOIncompleteData as a return value for inv_icm20948_read_dmp_data.
1 parent 9e2b603 commit e168cf1

File tree

6 files changed

+186
-130
lines changed

6 files changed

+186
-130
lines changed

DMP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ The DMP data is returned via the FIFO (First In First Out). ```readDMPdataFromFI
7474
- ```ICM_20948_Stat_FIFONoDataAvail``` if no data or incomplete data is available
7575
- ```ICM_20948_Stat_Ok``` if a valid frame was read
7676
- ```ICM_20948_Stat_FIFOMoreDataAvail``` if a valid frame was read _and_ the FIFO contains more (unread) data
77+
- ```ICM_20948_Stat_FIFOIncompleteData``` if a frame was present in the FIFO but it was incomplete
7778

7879
You can examine the 16-bit ```icm_20948_DMP_data_t data.header``` to see what data the frame contained. ```data.header``` is a bit field; each bit indicates what data is present:
7980
- **DMP_header_bitmap_Compass_Calibr** (0x0020)

keywords.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ ICM_20948_Stat_SensorNotSupported LITERAL1
123123
ICM_20948_Stat_DMPNotSupported LITERAL1
124124
ICM_20948_Stat_DMPVerifyFail LITERAL1
125125
ICM_20948_Stat_FIFONoDataAvail LITERAL1
126+
ICM_20948_Stat_FIFOIncompleteData LITERAL1
126127
ICM_20948_Stat_FIFOMoreDataAvail LITERAL1
127128
ICM_20948_Stat_UnrecognisedDMPHeader LITERAL1
128129
ICM_20948_Stat_UnrecognisedDMPHeader2 LITERAL1
@@ -165,7 +166,6 @@ INV_ICM20948_SENSOR_GRAVITY LITERAL1
165166
INV_ICM20948_SENSOR_LINEAR_ACCELERATION LITERAL1
166167
INV_ICM20948_SENSOR_ORIENTATION LITERAL1
167168
INV_ICM20948_SENSOR_B2S LITERAL1
168-
INV_ICM20948_SENSOR_RAW_MAGNETOMETER LITERAL1
169169
DMP_header_bitmap_Header2 LITERAL1
170170
DMP_header_bitmap_Step_Detector LITERAL1
171171
DMP_header_bitmap_Compass_Calibr LITERAL1

src/ICM_20948.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ void ICM_20948::debugPrintStatus(ICM_20948_Status_e stat)
116116
case ICM_20948_Stat_FIFONoDataAvail:
117117
debugPrint(F("No FIFO Data Available"));
118118
break;
119+
case ICM_20948_Stat_FIFOIncompleteData:
120+
debugPrint(F("DMP data in FIFO was incomplete"));
121+
break;
119122
case ICM_20948_Stat_FIFOMoreDataAvail:
120123
debugPrint(F("More FIFO Data Available"));
121124
break;
@@ -292,6 +295,9 @@ const char *ICM_20948::statusString(ICM_20948_Status_e stat)
292295
case ICM_20948_Stat_FIFONoDataAvail:
293296
return "No FIFO Data Available";
294297
break;
298+
case ICM_20948_Stat_FIFOIncompleteData:
299+
return "DMP data in FIFO was incomplete";
300+
break;
295301
case ICM_20948_Stat_FIFOMoreDataAvail:
296302
return "More FIFO Data Available";
297303
break;
@@ -1026,14 +1032,10 @@ ICM_20948_Status_e ICM_20948::enableDMPSensor(enum inv_icm20948_sensor sensor, b
10261032
if (_device._dmp_firmware_available == true) // Should we attempt to enable the sensor?
10271033
{
10281034
status = inv_icm20948_enable_dmp_sensor(&_device, sensor, enable == true ? 1 : 0);
1029-
debugPrint(F("ICM_20948::enableDMPSensor: _DATA_OUT_CTL1: "));
1030-
debugPrintf((int)_device._DATA_OUT_CTL1);
1031-
debugPrint(F(" _DATA_OUT_CTL2: "));
1032-
debugPrintf((int)_device._DATA_OUT_CTL2);
1033-
debugPrint(F(" _DATA_RDY_STATUS: "));
1034-
debugPrintf((int)_device._DATA_RDY_STATUS);
1035-
debugPrint(F(" _MOTION_EVENT_CTL: "));
1036-
debugPrintf((int)_device._MOTION_EVENT_CTL);
1035+
debugPrint(F("ICM_20948::enableDMPSensor: _enabled_Android_0: "));
1036+
debugPrintf((int)_device._enabled_Android_0);
1037+
debugPrint(F(" _enabled_Android_1: "));
1038+
debugPrintf((int)_device._enabled_Android_1);
10371039
debugPrintln(F(""));
10381040
return status;
10391041
}
@@ -1045,6 +1047,11 @@ ICM_20948_Status_e ICM_20948::enableDMPSensorInt(enum inv_icm20948_sensor sensor
10451047
if (_device._dmp_firmware_available == true) // Should we attempt to enable the sensor interrupt?
10461048
{
10471049
status = inv_icm20948_enable_dmp_sensor_int(&_device, sensor, enable == true ? 1 : 0);
1050+
debugPrint(F("ICM_20948::enableDMPSensorInt: _enabled_Android_intr_0: "));
1051+
debugPrintf((int)_device._enabled_Android_intr_0);
1052+
debugPrint(F(" _enabled_Android_intr_1: "));
1053+
debugPrintf((int)_device._enabled_Android_intr_1);
1054+
debugPrintln(F(""));
10481055
return status;
10491056
}
10501057
return ICM_20948_Stat_DMPNotSupported;
@@ -1161,10 +1168,10 @@ ICM_20948_Status_e ICM_20948_I2C::begin(TwoWire &wirePort, bool ad0val, uint8_t
11611168
_device._last_mems_bank = 255; // Initialize _last_mems_bank. Make it invalid. It will be set by the first call of inv_icm20948_write_mems.
11621169
_device._gyroSF = 0; // Use this to record the GyroSF, calculated by inv_icm20948_set_gyro_sf
11631170
_device._gyroSFpll = 0;
1164-
_device._DATA_OUT_CTL1 = 0; // Keep a record of what sensors are enabled
1165-
_device._DATA_OUT_CTL2 = 0; // Keep a record of what header2 items are enabled
1166-
_device._DATA_RDY_STATUS = 0; // Keep a record of how Data Ready Status is configured
1167-
_device._MOTION_EVENT_CTL = 0; // Keep a record of how Motion Event Ctrl is configured
1171+
_device._enabled_Android_0 = 0; // Keep track of which Android sensors are enabled: 0-31
1172+
_device._enabled_Android_1 = 0; // Keep track of which Android sensors are enabled: 32-
1173+
_device._enabled_Android_intr_0 = 0; // Keep track of which Android sensor interrupts are enabled: 0-31
1174+
_device._enabled_Android_intr_1 = 0; // Keep track of which Android sensor interrupts are enabled: 32-
11681175

11691176
// Perform default startup
11701177
// Do a minimal startupDefault if using the DMP. User can always call startupDefault(false) manually if required.
@@ -1348,10 +1355,10 @@ ICM_20948_Status_e ICM_20948_SPI::begin(uint8_t csPin, SPIClass &spiPort, uint32
13481355
_device._last_mems_bank = 255; // Initialize _last_mems_bank. Make it invalid. It will be set by the first call of inv_icm20948_write_mems.
13491356
_device._gyroSF = 0; // Use this to record the GyroSF, calculated by inv_icm20948_set_gyro_sf
13501357
_device._gyroSFpll = 0;
1351-
_device._DATA_OUT_CTL1 = 0; // Keep a record of what sensors are enabled
1352-
_device._DATA_OUT_CTL2 = 0; // Keep a record of what header2 items are enabled
1353-
_device._DATA_RDY_STATUS = 0; // Keep a record of how Data Ready Status is configured
1354-
_device._MOTION_EVENT_CTL = 0; // Keep a record of how Motion Event Ctrl is configured
1358+
_device._enabled_Android_0 = 0; // Keep track of which Android sensors are enabled: 0-31
1359+
_device._enabled_Android_1 = 0; // Keep track of which Android sensors are enabled: 32-
1360+
_device._enabled_Android_intr_0 = 0; // Keep track of which Android sensor interrupts are enabled: 0-31
1361+
_device._enabled_Android_intr_1 = 0; // Keep track of which Android sensor interrupts are enabled: 32-
13551362

13561363
// Perform default startup
13571364
// Do a minimal startupDefault if using the DMP. User can always call startupDefault(false) manually if required.

src/ICM_20948.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,23 @@ class ICM_20948
180180
// Reset FIFO
181181
// Reset DMP
182182
// Enable DMP interrupt
183-
// Configuring DMP to output data to FIFO: set DATA_OUT_CTL1 and DATA_INTR_CTL
183+
// Configuring DMP to output data to FIFO: set DATA_OUT_CTL1, DATA_OUT_CTL2, DATA_INTR_CTL and MOTION_EVENT_CTL
184184
// Configuring DMP to output data at multiple ODRs
185+
// Configure DATA_RDY_STATUS
186+
// Configuring Accel calibration
187+
// Configuring Compass calibration
188+
// Configuring Gyro gain
189+
// Configuring Accel gain
185190

186191
// To Do:
187-
// Configure DATA_RDY_STATUS
188-
// Additional FIFO output control: DATA_OUT_CTL2, FIFO_WATERMARK, BM_BATCH_MASK, BM_BATCH_CNTR, BM_BATCH_THLD
189-
// Configuring DMP features: MOTION_EVENT_CTL, PED_STD_STEPCTR, PED_STD_TIMECTR
192+
// Additional FIFO output control: FIFO_WATERMARK, BM_BATCH_MASK, BM_BATCH_CNTR, BM_BATCH_THLD
193+
// Configuring DMP features: PED_STD_STEPCTR, PED_STD_TIMECTR
190194
// Enabling Activity Recognition (BAC) feature
191195
// Enabling Significant Motion Detect (SMD) feature
192196
// Enabling Tilt Detector feature
193197
// Enabling Pick Up Gesture feature
194198
// Enabling Fsync detection feature
195-
// Configuring Accel calibration
196-
// Configuring Compass calibration
197-
// Configuring Gyro gain
198-
// Configuring Accel gain
199-
// Biases
199+
// Biases?
200200

201201
ICM_20948_Status_e enableDMP(bool enable = true);
202202
ICM_20948_Status_e resetDMP(void);

0 commit comments

Comments
 (0)