@@ -1484,6 +1484,9 @@ ICM_20948_Status_e inv_icm20948_enable_dmp_sensor(ICM_20948_Device_t *pdev, enum
1484
1484
1485
1485
ICM_20948_Status_e result = ICM_20948_Stat_Ok ;
1486
1486
1487
+ uint16_t inv_event_control = 0 ;
1488
+ uint16_t data_rdy_status = 0 ;
1489
+
1487
1490
if (pdev -> _dmp_firmware_available == false)
1488
1491
return ICM_20948_Stat_DMPNotSupported ;
1489
1492
@@ -1540,6 +1543,81 @@ ICM_20948_Status_e inv_icm20948_enable_dmp_sensor(ICM_20948_Device_t *pdev, enum
1540
1543
data_output_control_reg [0 ] = (unsigned char )(delta2 >> 8 );
1541
1544
data_output_control_reg [1 ] = (unsigned char )(delta2 & 0xff );
1542
1545
result = inv_icm20948_write_mems (pdev , DATA_OUT_CTL2 , 2 , (const unsigned char * )& data_output_control_reg );
1546
+ if (result != ICM_20948_Stat_Ok )
1547
+ {
1548
+ return result ;
1549
+ }
1550
+
1551
+ // Check which bits need to be set in the Data Ready Status and Motion Event Control registers
1552
+ // Convert androidSensor into a bit mask and compare to INV_NEEDS_ACCEL_MASK, INV_NEEDS_GYRO_MASK and INV_NEEDS_COMPASS_MASK
1553
+ unsigned long androidSensorAsBitMask ;
1554
+ if (androidSensor < 32 )
1555
+ {
1556
+ androidSensorAsBitMask = 1L << androidSensor ;
1557
+ if ((androidSensorAsBitMask & INV_NEEDS_ACCEL_MASK ) > 0 )
1558
+ {
1559
+ data_rdy_status |= DMP_Data_ready_Accel ;
1560
+ inv_event_control |= DMP_Motion_Event_Control_Accel_Calibr ;
1561
+ }
1562
+ if ((androidSensorAsBitMask & INV_NEEDS_GYRO_MASK ) > 0 )
1563
+ {
1564
+ data_rdy_status |= DMP_Data_ready_Gyro ;
1565
+ inv_event_control |= DMP_Motion_Event_Control_Gyro_Calibr ;
1566
+ }
1567
+ if ((androidSensorAsBitMask & INV_NEEDS_COMPASS_MASK ) > 0 )
1568
+ {
1569
+ data_rdy_status |= DMP_Data_ready_Secondary_Compass ;
1570
+ inv_event_control |= DMP_Motion_Event_Control_Compass_Calibr ;
1571
+ }
1572
+ }
1573
+ else
1574
+ {
1575
+ androidSensorAsBitMask = 1L << (androidSensor - 32 );
1576
+ if ((androidSensorAsBitMask & INV_NEEDS_ACCEL_MASK1 ) > 0 )
1577
+ {
1578
+ data_rdy_status |= DMP_Data_ready_Accel ;
1579
+ inv_event_control |= DMP_Motion_Event_Control_Accel_Calibr ;
1580
+ }
1581
+ if ((androidSensorAsBitMask & INV_NEEDS_GYRO_MASK1 ) > 0 )
1582
+ {
1583
+ data_rdy_status |= DMP_Data_ready_Gyro ;
1584
+ inv_event_control |= DMP_Motion_Event_Control_Gyro_Calibr ;
1585
+ }
1586
+ if ((androidSensorAsBitMask & INV_NEEDS_COMPASS_MASK1 ) > 0 )
1587
+ {
1588
+ data_rdy_status |= DMP_Data_ready_Secondary_Compass ;
1589
+ inv_event_control |= DMP_Motion_Event_Control_Compass_Calibr ;
1590
+ }
1591
+ }
1592
+ data_output_control_reg [0 ] = (unsigned char )(data_rdy_status >> 8 );
1593
+ data_output_control_reg [1 ] = (unsigned char )(data_rdy_status & 0xff );
1594
+ result = inv_icm20948_write_mems (pdev , DATA_RDY_STATUS , 2 , (const unsigned char * )& data_output_control_reg );
1595
+ if (result != ICM_20948_Stat_Ok )
1596
+ {
1597
+ return result ;
1598
+ }
1599
+
1600
+ // Check which extra bits need to be set in the Motion Event Control register
1601
+ if ((delta & DMP_Data_Output_Control_1_Quat9 ) > 0 )
1602
+ {
1603
+ inv_event_control |= DMP_Motion_Event_Control_9axis ;
1604
+ }
1605
+ if (((delta & DMP_Data_Output_Control_1_Step_Detector ) > 0 ) || ((delta & DMP_Data_Output_Control_1_Step_Ind_0 ) > 0 )
1606
+ || ((delta & DMP_Data_Output_Control_1_Step_Ind_1 ) > 0 ) || ((delta & DMP_Data_Output_Control_1_Step_Ind_2 ) > 0 ))
1607
+ {
1608
+ inv_event_control |= DMP_Motion_Event_Control_Pedometer_Interrupt ;
1609
+ }
1610
+ if ((delta & DMP_Data_Output_Control_1_Geomag ) > 0 )
1611
+ {
1612
+ inv_event_control |= DMP_Motion_Event_Control_Geomag ;
1613
+ }
1614
+ data_output_control_reg [0 ] = (unsigned char )(inv_event_control >> 8 );
1615
+ data_output_control_reg [1 ] = (unsigned char )(inv_event_control & 0xff );
1616
+ result = inv_icm20948_write_mems (pdev , MOTION_EVENT_CTL , 2 , (const unsigned char * )& data_output_control_reg );
1617
+ if (result != ICM_20948_Stat_Ok )
1618
+ {
1619
+ return result ;
1620
+ }
1543
1621
1544
1622
// result = ICM_20948_low_power(pdev, true); // Put chip into low power state
1545
1623
// if (result != ICM_20948_Stat_Ok)
0 commit comments