Skip to content

Commit 76598a3

Browse files
committed
add WOMLogic() function
to configure the WOM algorithm
1 parent f0b90f4 commit 76598a3

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

examples/Arduino/Example4_WakeOnMotion/Example4_WakeOnMotion.ino

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ void setup()
221221
SERIAL_PORT.print(F("Set threshold returned: "));
222222
SERIAL_PORT.println(myICM.statusString());
223223

224+
myICM.WOMLogic(true, 1); // enable WoM Logic mode 1
225+
224226
myICM.intEnableWOM(true); // enable interrupts on WakeOnMotion
225227
SERIAL_PORT.print(F("intEnableWOM returned: "));
226228
SERIAL_PORT.println(myICM.statusString());

keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ intEnableWOF KEYWORD2
6565
intEnableRawDataReady KEYWORD2
6666
intEnableOverflowFIFO KEYWORD2
6767
intEnableWatermarkFIFO KEYWORD2
68+
WOMLogic KEYWORD2
6869
WOMThreshold KEYWORD2
6970
i2cMasterPassthrough KEYWORD2
7071
i2cMasterEnable KEYWORD2

src/ICM_20948.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,30 @@ ICM_20948_Status_e ICM_20948::intEnableWatermarkFIFO(uint8_t bm_enable)
10171017
return status;
10181018
}
10191019

1020+
ICM_20948_Status_e ICM_20948::WOMLogic(uint8_t enable, uint8_t mode)
1021+
{
1022+
ICM_20948_ACCEL_INTEL_CTRL_t ctrl; // storage
1023+
status = ICM_20948_wom_logic(&_device, NULL, &ctrl); // read phase
1024+
if (status != ICM_20948_Stat_Ok)
1025+
{
1026+
return status;
1027+
}
1028+
ctrl.ACCEL_INTEL_EN = enable; // enable the WOM logic
1029+
ctrl.ACCEL_INTEL_MODE_INT = mode; // config mode
1030+
1031+
status = ICM_20948_wom_logic(&_device, &ctrl, &ctrl); // write new config
1032+
if (status != ICM_20948_Stat_Ok)
1033+
{
1034+
return status;
1035+
}
1036+
if (ctrl.ACCEL_INTEL_MODE_INT != mode)
1037+
{
1038+
status = ICM_20948_Stat_Err;
1039+
return status;
1040+
}
1041+
return status;
1042+
}
1043+
10201044
ICM_20948_Status_e ICM_20948::WOMThreshold(uint8_t threshold)
10211045
{
10221046
ICM_20948_ACCEL_WOM_THR_t thr; // storage

src/ICM_20948.h

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class ICM_20948
130130
ICM_20948_Status_e intEnableOverflowFIFO(uint8_t bm_enable);
131131
ICM_20948_Status_e intEnableWatermarkFIFO(uint8_t bm_enable);
132132

133+
ICM_20948_Status_e WOMLogic(uint8_t enable, uint8_t mode);
133134
ICM_20948_Status_e WOMThreshold(uint8_t threshold);
134135

135136
// Interface Options

src/util/ICM_20948_C.c

+35
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,41 @@ ICM_20948_Status_e ICM_20948_int_enable(ICM_20948_Device_t *pdev, ICM_20948_INT_
555555
return retval;
556556
}
557557

558+
ICM_20948_Status_e ICM_20948_wom_logic(ICM_20948_Device_t *pdev, ICM_20948_ACCEL_INTEL_CTRL_t *write, ICM_20948_ACCEL_INTEL_CTRL_t *read)
559+
{
560+
ICM_20948_Status_e retval = ICM_20948_Stat_Ok;
561+
562+
ICM_20948_ACCEL_INTEL_CTRL_t ctrl;
563+
564+
retval = ICM_20948_set_bank(pdev, 2); // Must be in the right bank
565+
566+
if (write != NULL)
567+
{ // If the write pointer is not NULL then write to the registers BEFORE reading
568+
ctrl.ACCEL_INTEL_EN = write->ACCEL_INTEL_EN;
569+
ctrl.ACCEL_INTEL_MODE_INT = write->ACCEL_INTEL_MODE_INT;
570+
571+
retval = ICM_20948_execute_w(pdev, AGB2_REG_ACCEL_INTEL_CTRL, (uint8_t *)&ctrl, sizeof(ICM_20948_ACCEL_INTEL_CTRL_t));
572+
if (retval != ICM_20948_Stat_Ok)
573+
{
574+
return retval;
575+
}
576+
}
577+
578+
if (read != NULL)
579+
{ // If read pointer is not NULL then read the registers (if write is not NULL then this should read back the results of write into read)
580+
retval = ICM_20948_execute_r(pdev, AGB2_REG_ACCEL_INTEL_CTRL, (uint8_t *)&ctrl, sizeof(ICM_20948_ACCEL_INTEL_CTRL_t));
581+
if (retval != ICM_20948_Stat_Ok)
582+
{
583+
return retval;
584+
}
585+
586+
read->ACCEL_INTEL_EN = ctrl.ACCEL_INTEL_EN;
587+
read->ACCEL_INTEL_MODE_INT = ctrl.ACCEL_INTEL_MODE_INT;
588+
}
589+
590+
return retval;
591+
}
592+
558593
ICM_20948_Status_e ICM_20948_wom_threshold(ICM_20948_Device_t *pdev, ICM_20948_ACCEL_WOM_THR_t *write, ICM_20948_ACCEL_WOM_THR_t *read)
559594
{
560595
ICM_20948_Status_e retval = ICM_20948_Stat_Ok;

src/util/ICM_20948_C.h

+3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ extern int memcmp(const void *, const void *, size_t); // Avoid compiler warning
213213
ICM_20948_Status_e ICM_20948_int_pin_cfg(ICM_20948_Device_t *pdev, ICM_20948_INT_PIN_CFG_t *write, ICM_20948_INT_PIN_CFG_t *read); // Set the INT pin configuration
214214
ICM_20948_Status_e ICM_20948_int_enable(ICM_20948_Device_t *pdev, ICM_20948_INT_enable_t *write, ICM_20948_INT_enable_t *read); // Write and or read the interrupt enable information. If non-null the write operation occurs before the read, so as to verify that the write was successful
215215

216+
// WoM Enable Logic configuration
217+
ICM_20948_Status_e ICM_20948_wom_logic(ICM_20948_Device_t *pdev, ICM_20948_ACCEL_INTEL_CTRL_t *write, ICM_20948_ACCEL_INTEL_CTRL_t *read); //Enable or disable WoM Logic
218+
216219
// WoM Threshold Level Configuration
217220
ICM_20948_Status_e ICM_20948_wom_threshold(ICM_20948_Device_t *pdev, ICM_20948_ACCEL_WOM_THR_t *write, ICM_20948_ACCEL_WOM_THR_t *read); // Write and or read the Wake on Motion threshold. If non-null the write operation occurs before the read, so as to verify that the write was successful
218221

0 commit comments

Comments
 (0)