From 76598a33da53bfcba704bfa98cb0676e2cf14aab Mon Sep 17 00:00:00 2001 From: Diego Alfonzo Escobar Date: Wed, 14 Jun 2023 16:30:51 -0500 Subject: [PATCH 1/2] add WOMLogic() function to configure the WOM algorithm --- .../Example4_WakeOnMotion.ino | 2 ++ keywords.txt | 1 + src/ICM_20948.cpp | 24 +++++++++++++ src/ICM_20948.h | 1 + src/util/ICM_20948_C.c | 35 +++++++++++++++++++ src/util/ICM_20948_C.h | 3 ++ 6 files changed, 66 insertions(+) diff --git a/examples/Arduino/Example4_WakeOnMotion/Example4_WakeOnMotion.ino b/examples/Arduino/Example4_WakeOnMotion/Example4_WakeOnMotion.ino index 6a1ca00..6295695 100644 --- a/examples/Arduino/Example4_WakeOnMotion/Example4_WakeOnMotion.ino +++ b/examples/Arduino/Example4_WakeOnMotion/Example4_WakeOnMotion.ino @@ -221,6 +221,8 @@ void setup() SERIAL_PORT.print(F("Set threshold returned: ")); SERIAL_PORT.println(myICM.statusString()); + myICM.WOMLogic(true, 1); // enable WoM Logic mode 1 + myICM.intEnableWOM(true); // enable interrupts on WakeOnMotion SERIAL_PORT.print(F("intEnableWOM returned: ")); SERIAL_PORT.println(myICM.statusString()); diff --git a/keywords.txt b/keywords.txt index 1912684..09fae5b 100644 --- a/keywords.txt +++ b/keywords.txt @@ -65,6 +65,7 @@ intEnableWOF KEYWORD2 intEnableRawDataReady KEYWORD2 intEnableOverflowFIFO KEYWORD2 intEnableWatermarkFIFO KEYWORD2 +WOMLogic KEYWORD2 WOMThreshold KEYWORD2 i2cMasterPassthrough KEYWORD2 i2cMasterEnable KEYWORD2 diff --git a/src/ICM_20948.cpp b/src/ICM_20948.cpp index a73f23a..4c57755 100644 --- a/src/ICM_20948.cpp +++ b/src/ICM_20948.cpp @@ -1017,6 +1017,30 @@ ICM_20948_Status_e ICM_20948::intEnableWatermarkFIFO(uint8_t bm_enable) return status; } +ICM_20948_Status_e ICM_20948::WOMLogic(uint8_t enable, uint8_t mode) +{ + ICM_20948_ACCEL_INTEL_CTRL_t ctrl; // storage + status = ICM_20948_wom_logic(&_device, NULL, &ctrl); // read phase + if (status != ICM_20948_Stat_Ok) + { + return status; + } + ctrl.ACCEL_INTEL_EN = enable; // enable the WOM logic + ctrl.ACCEL_INTEL_MODE_INT = mode; // config mode + + status = ICM_20948_wom_logic(&_device, &ctrl, &ctrl); // write new config + if (status != ICM_20948_Stat_Ok) + { + return status; + } + if (ctrl.ACCEL_INTEL_MODE_INT != mode) + { + status = ICM_20948_Stat_Err; + return status; + } + return status; +} + ICM_20948_Status_e ICM_20948::WOMThreshold(uint8_t threshold) { ICM_20948_ACCEL_WOM_THR_t thr; // storage diff --git a/src/ICM_20948.h b/src/ICM_20948.h index b625db3..bbde34c 100644 --- a/src/ICM_20948.h +++ b/src/ICM_20948.h @@ -130,6 +130,7 @@ class ICM_20948 ICM_20948_Status_e intEnableOverflowFIFO(uint8_t bm_enable); ICM_20948_Status_e intEnableWatermarkFIFO(uint8_t bm_enable); + ICM_20948_Status_e WOMLogic(uint8_t enable, uint8_t mode); ICM_20948_Status_e WOMThreshold(uint8_t threshold); // Interface Options diff --git a/src/util/ICM_20948_C.c b/src/util/ICM_20948_C.c index eaa7826..6a98a51 100644 --- a/src/util/ICM_20948_C.c +++ b/src/util/ICM_20948_C.c @@ -555,6 +555,41 @@ ICM_20948_Status_e ICM_20948_int_enable(ICM_20948_Device_t *pdev, ICM_20948_INT_ return retval; } +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) +{ + ICM_20948_Status_e retval = ICM_20948_Stat_Ok; + + ICM_20948_ACCEL_INTEL_CTRL_t ctrl; + + retval = ICM_20948_set_bank(pdev, 2); // Must be in the right bank + + if (write != NULL) + { // If the write pointer is not NULL then write to the registers BEFORE reading + ctrl.ACCEL_INTEL_EN = write->ACCEL_INTEL_EN; + ctrl.ACCEL_INTEL_MODE_INT = write->ACCEL_INTEL_MODE_INT; + + retval = ICM_20948_execute_w(pdev, AGB2_REG_ACCEL_INTEL_CTRL, (uint8_t *)&ctrl, sizeof(ICM_20948_ACCEL_INTEL_CTRL_t)); + if (retval != ICM_20948_Stat_Ok) + { + return retval; + } + } + + if (read != NULL) + { // 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) + retval = ICM_20948_execute_r(pdev, AGB2_REG_ACCEL_INTEL_CTRL, (uint8_t *)&ctrl, sizeof(ICM_20948_ACCEL_INTEL_CTRL_t)); + if (retval != ICM_20948_Stat_Ok) + { + return retval; + } + + read->ACCEL_INTEL_EN = ctrl.ACCEL_INTEL_EN; + read->ACCEL_INTEL_MODE_INT = ctrl.ACCEL_INTEL_MODE_INT; + } + + return retval; +} + 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) { ICM_20948_Status_e retval = ICM_20948_Stat_Ok; diff --git a/src/util/ICM_20948_C.h b/src/util/ICM_20948_C.h index 934f8d3..3e61d76 100644 --- a/src/util/ICM_20948_C.h +++ b/src/util/ICM_20948_C.h @@ -213,6 +213,9 @@ extern int memcmp(const void *, const void *, size_t); // Avoid compiler warning 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 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 + // WoM Enable Logic configuration + 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 + // WoM Threshold Level Configuration 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 From b249f132d1db49d5df1b0024c71b2183e94805c9 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 18 Jun 2023 08:26:48 +0100 Subject: [PATCH 2/2] v1.2.12 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index a70d2c9..e832dd0 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun 9DoF IMU Breakout - ICM 20948 - Arduino Library -version=1.2.11 +version=1.2.12 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Use the low-power high-resolution ICM 20948 9 DoF IMU from Invensense with I2C or SPI. Version 1.2 of the library includes support for the InvenSense Digital Motion Processor (DMP™).