diff --git a/drivers/CoreIMU/include/CoreLSM6DSOX.hpp b/drivers/CoreIMU/include/CoreLSM6DSOX.hpp index 69d38bca71..818cfd923d 100644 --- a/drivers/CoreIMU/include/CoreLSM6DSOX.hpp +++ b/drivers/CoreIMU/include/CoreLSM6DSOX.hpp @@ -9,12 +9,13 @@ #include "CoreEventQueue.h" #include "CoreInterruptIn.h" #include "interface/LSM6DSOX.hpp" +#include "interface/drivers/DeepSleepEnabled.h" #include "interface/drivers/I2C.h" #include "lsm6dsox_reg.h" namespace leka { -class CoreLSM6DSOX : public interface::LSM6DSOX +class CoreLSM6DSOX : public interface::LSM6DSOX, public interface::DeepSleepEnabled { public: explicit CoreLSM6DSOX(interface::I2C &i2c, CoreInterruptIn &drdy_irq); @@ -25,6 +26,9 @@ class CoreLSM6DSOX : public interface::LSM6DSOX void setPowerMode(PowerMode mode) final; + void enableDeepSleep() final; + void disableDeepSleep() final; + private: auto read(uint8_t register_address, uint16_t number_bytes_to_read, uint8_t *p_buffer) -> int32_t; auto write(uint8_t register_address, uint16_t number_bytes_to_write, uint8_t *p_buffer) -> int32_t; diff --git a/drivers/CoreIMU/source/CoreLSM6DSOX.cpp b/drivers/CoreIMU/source/CoreLSM6DSOX.cpp index 0d33ce3d3b..2396598e43 100644 --- a/drivers/CoreIMU/source/CoreLSM6DSOX.cpp +++ b/drivers/CoreIMU/source/CoreLSM6DSOX.cpp @@ -97,6 +97,16 @@ void CoreLSM6DSOX::onGyrDataReadyHandler(auto timestamp) } } +void CoreLSM6DSOX::enableDeepSleep() +{ + setPowerMode(interface::LSM6DSOX::PowerMode::Off); +} + +void CoreLSM6DSOX::disableDeepSleep() +{ + setPowerMode(interface::LSM6DSOX::PowerMode::Normal); +} + auto CoreLSM6DSOX::read(uint8_t register_address, uint16_t number_bytes_to_read, uint8_t *p_buffer) -> int32_t { // Send component address, without STOP condition diff --git a/drivers/CoreIMU/tests/CoreLSM6DSOX_test.cpp b/drivers/CoreIMU/tests/CoreLSM6DSOX_test.cpp index e1173e9f97..a63bcc635e 100644 --- a/drivers/CoreIMU/tests/CoreLSM6DSOX_test.cpp +++ b/drivers/CoreIMU/tests/CoreLSM6DSOX_test.cpp @@ -86,3 +86,21 @@ TEST_F(CoreLSM6DSOXTest, emptyOnGyrDrdyCallback) auto on_rise_callback = spy_InterruptIn_getRiseCallback(); on_rise_callback(); } + +TEST_F(CoreLSM6DSOXTest, enableDeepSleep) +{ + EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); + EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); + lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Off); + + lsm6dsox.enableDeepSleep(); +} + +TEST_F(CoreLSM6DSOXTest, disableDeepSleep) +{ + EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); + EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); + lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Normal); + + lsm6dsox.disableDeepSleep(); +}