Skip to content

add WOMLogic() function #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ intEnableWOF KEYWORD2
intEnableRawDataReady KEYWORD2
intEnableOverflowFIFO KEYWORD2
intEnableWatermarkFIFO KEYWORD2
WOMLogic KEYWORD2
WOMThreshold KEYWORD2
i2cMasterPassthrough KEYWORD2
i2cMasterEnable KEYWORD2
Expand Down
24 changes: 24 additions & 0 deletions src/ICM_20948.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/ICM_20948.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions src/util/ICM_20948_C.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/util/ICM_20948_C.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down