Skip to content

Commit

Permalink
✨ (imu): Add DeepSleepEnabled to CoreLSM6DSOX
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed Jul 10, 2024
1 parent f8bd18c commit 57583db
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/CoreIMU/include/CoreLSM6DSOX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions drivers/CoreIMU/source/CoreLSM6DSOX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions drivers/CoreIMU/tests/CoreLSM6DSOX_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 57583db

Please sign in to comment.