Skip to content

Commit

Permalink
🔀️ Merge branch 'yann/rename/imu/rename-corelsm6dsox-into-coreimu' in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
ladislas committed Jul 18, 2024
2 parents f0da19a + 2270bd0 commit b90bc51
Show file tree
Hide file tree
Showing 27 changed files with 190 additions and 190 deletions.
10 changes: 5 additions & 5 deletions app/os/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#include "CoreFont.hpp"
#include "CoreGraphics.hpp"
#include "CoreI2C.h"
#include "CoreIMU.hpp"
#include "CoreInterruptIn.h"
#include "CoreJPEG.hpp"
#include "CoreJPEGModeDMA.hpp"
#include "CoreLCD.hpp"
#include "CoreLCDDriverOTM8009A.hpp"
#include "CoreLL.h"
#include "CoreLSM6DSOX.hpp"
#include "CoreLTDC.hpp"
#include "CoreMCU.h"
#include "CoreMotor.h"
Expand Down Expand Up @@ -265,11 +265,11 @@ namespace imu {

} // namespace internal

auto lsm6dsox = CoreLSM6DSOX(internal::i2c, internal::drdy_irq);
auto coreimu = CoreIMU(internal::i2c, internal::drdy_irq);

} // namespace imu

auto imukit = IMUKit {imu::lsm6dsox};
auto imukit = IMUKit {imu::coreimu};

namespace motion::internal {

Expand Down Expand Up @@ -540,7 +540,7 @@ namespace deep_sleep {
&motors::right::motor,
&display::internal::corelcd,
&rfid::reader,
&imu::lsm6dsox,
&imu::coreimu,
});
}

Expand Down Expand Up @@ -578,7 +578,7 @@ auto main() -> int
commandkit.registerCommand(command::list);
activitykit.registerActivities(activities::activities);

imu::lsm6dsox.init();
imu::coreimu.init();
imukit.init();

robot::controller.initializeComponents();
Expand Down
4 changes: 2 additions & 2 deletions drivers/CoreIMU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ target_include_directories(CoreIMU
target_sources(CoreIMU
PRIVATE
extern/source/lsm6dsox_reg.c
source/CoreLSM6DSOX.cpp
source/CoreIMU.cpp
)

target_link_libraries(CoreIMU
Expand All @@ -23,6 +23,6 @@ target_link_libraries(CoreIMU

if(${CMAKE_PROJECT_NAME} STREQUAL "LekaOSUnitTests")
leka_unit_tests_sources(
tests/CoreLSM6DSOX_test.cpp
tests/CoreIMU_test.cpp
)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@

#include "CoreEventQueue.h"
#include "CoreInterruptIn.h"
#include "interface/LSM6DSOX.hpp"
#include "interface/drivers/DeepSleepEnabled.h"
#include "interface/drivers/I2C.h"
#include "interface/drivers/IMU.hpp"
#include "lsm6dsox_reg.h"

namespace leka {

class CoreLSM6DSOX : public interface::LSM6DSOX, public interface::DeepSleepEnabled
class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled
{
public:
explicit CoreLSM6DSOX(interface::I2C &i2c, CoreInterruptIn &drdy_irq);
explicit CoreIMU(interface::I2C &i2c, CoreInterruptIn &drdy_irq);

void init() final;

Expand All @@ -33,9 +33,9 @@ class CoreLSM6DSOX : public interface::LSM6DSOX, public interface::DeepSleepEnab
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;

static auto ptr_io_write(CoreLSM6DSOX *handle, uint8_t write_address, uint8_t *p_buffer,
static auto ptr_io_write(CoreIMU *handle, uint8_t write_address, uint8_t *p_buffer,
uint16_t number_bytes_to_write) -> int32_t;
static auto ptr_io_read(CoreLSM6DSOX *handle, uint8_t read_address, uint8_t *p_buffer,
static auto ptr_io_read(CoreIMU *handle, uint8_t read_address, uint8_t *p_buffer,
uint16_t number_bytes_to_read) -> int32_t;

void onGyrDataReadyHandler(auto timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "CoreLSM6DSOX.hpp"
#include "CoreIMU.hpp"

namespace leka {

CoreLSM6DSOX::CoreLSM6DSOX(interface::I2C &i2c, CoreInterruptIn &drdy_irq) : _i2c(i2c), _drdy_irq(drdy_irq)
CoreIMU::CoreIMU(interface::I2C &i2c, CoreInterruptIn &drdy_irq) : _i2c(i2c), _drdy_irq(drdy_irq)
{
// ? NOLINTNEXTLINE - allow reinterpret_cast as there are no alternatives
_register_io_function.write_reg = reinterpret_cast<stmdev_write_ptr>(ptr_io_write);
Expand All @@ -15,7 +15,7 @@ CoreLSM6DSOX::CoreLSM6DSOX(interface::I2C &i2c, CoreInterruptIn &drdy_irq) : _i2
_register_io_function.handle = static_cast<void *>(this);
}

void CoreLSM6DSOX::init()
void CoreIMU::init()
{
_event_queue.dispatch_forever();

Expand All @@ -33,7 +33,7 @@ void CoreLSM6DSOX::init()
setGyrDataReadyInterrupt();
}

void CoreLSM6DSOX::setPowerMode(PowerMode mode)
void CoreIMU::setPowerMode(PowerMode mode)
{
auto xl_power_mode = lsm6dsox_xl_hm_mode_t {};
auto gy_power_mode = lsm6dsox_g_hm_mode_t {};
Expand Down Expand Up @@ -71,12 +71,12 @@ void CoreLSM6DSOX::setPowerMode(PowerMode mode)
lsm6dsox_gy_data_rate_set(&_register_io_function, gy_odr);
}

void CoreLSM6DSOX::registerOnGyDataReadyCallback(drdy_callback_t const &callback)
void CoreIMU::registerOnGyDataReadyCallback(drdy_callback_t const &callback)
{
_on_gy_data_ready_callback = callback;
}

void CoreLSM6DSOX::onGyrDataReadyHandler(auto timestamp)
void CoreIMU::onGyrDataReadyHandler(auto timestamp)
{
static constexpr auto _1k = float {1000.F};

Expand All @@ -97,17 +97,17 @@ void CoreLSM6DSOX::onGyrDataReadyHandler(auto timestamp)
}
}

void CoreLSM6DSOX::enableDeepSleep()
void CoreIMU::enableDeepSleep()
{
setPowerMode(interface::LSM6DSOX::PowerMode::Off);
setPowerMode(interface::IMU::PowerMode::Off);
}

void CoreLSM6DSOX::disableDeepSleep()
void CoreIMU::disableDeepSleep()
{
setPowerMode(interface::LSM6DSOX::PowerMode::Normal);
setPowerMode(interface::IMU::PowerMode::Normal);
}

auto CoreLSM6DSOX::read(uint8_t register_address, uint16_t number_bytes_to_read, uint8_t *p_buffer) -> int32_t
auto CoreIMU::read(uint8_t register_address, uint16_t number_bytes_to_read, uint8_t *p_buffer) -> int32_t
{
// Send component address, without STOP condition
auto ret = _i2c.write(_address, &register_address, 1, true);
Expand All @@ -119,7 +119,7 @@ auto CoreLSM6DSOX::read(uint8_t register_address, uint16_t number_bytes_to_read,
return ret;
}

auto CoreLSM6DSOX::write(uint8_t register_address, uint16_t number_bytes_to_write, uint8_t *p_buffer) -> int32_t
auto CoreIMU::write(uint8_t register_address, uint16_t number_bytes_to_write, uint8_t *p_buffer) -> int32_t
{
if (number_bytes_to_write >= kMaxBufferLength) {
return 1;
Expand All @@ -131,19 +131,19 @@ auto CoreLSM6DSOX::write(uint8_t register_address, uint16_t number_bytes_to_writ
return ret;
}

auto CoreLSM6DSOX::ptr_io_write(CoreLSM6DSOX *handle, uint8_t write_address, uint8_t *p_buffer,
uint16_t number_bytes_to_write) -> int32_t
auto CoreIMU::ptr_io_write(CoreIMU *handle, uint8_t write_address, uint8_t *p_buffer,
uint16_t number_bytes_to_write) -> int32_t
{
return handle->write(write_address, number_bytes_to_write, p_buffer);
}

auto CoreLSM6DSOX::ptr_io_read(CoreLSM6DSOX *handle, uint8_t read_address, uint8_t *p_buffer,
uint16_t number_bytes_to_read) -> int32_t
auto CoreIMU::ptr_io_read(CoreIMU *handle, uint8_t read_address, uint8_t *p_buffer,
uint16_t number_bytes_to_read) -> int32_t
{
return handle->read(read_address, number_bytes_to_read, p_buffer);
}

void CoreLSM6DSOX::setGyrDataReadyInterrupt()
void CoreIMU::setGyrDataReadyInterrupt()
{
lsm6dsox_dataready_pulsed_t drdy_pulsed {LSM6DSOX_DRDY_PULSED};
lsm6dsox_data_ready_mode_set(&_register_io_function, drdy_pulsed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <vector>

#include "CoreLSM6DSOX.hpp"
#include "CoreIMU.hpp"
#include "gtest/gtest.h"
#include "mocks/leka/CoreI2C.h"
#include "mocks/leka/EventQueue.h"
Expand All @@ -16,91 +16,91 @@ using testing::_;
using testing::AtLeast;
using testing::MockFunction;

class CoreLSM6DSOXTest : public ::testing::Test
class CoreIMUTest : public ::testing::Test
{
protected:
CoreLSM6DSOXTest() = default;
CoreIMUTest() = default;

void SetUp() override
{
EXPECT_CALL(mocki2c, write).Times(AtLeast(1));
EXPECT_CALL(mocki2c, read).Times(AtLeast(1));

lsm6dsox.init();
coreimu.init();
}
// void TearDown() override {}

mock::CoreI2C mocki2c {};
CoreInterruptIn drdy_irq {NC};

CoreLSM6DSOX lsm6dsox {mocki2c, drdy_irq};
CoreIMU coreimu {mocki2c, drdy_irq};

// ? Instantiation of mock::EventQueue is needed to setup the underlying stubs that will make the mock work
// ? correctly. Without it UT are failing
// TODO (@ladislas) - review mocks/stubs to remove the need of the object, replace with setup/teardown functions
mock::EventQueue _ {};
};

TEST_F(CoreLSM6DSOXTest, initialization)
TEST_F(CoreIMUTest, initialization)
{
ASSERT_NE(&lsm6dsox, nullptr);
ASSERT_NE(&coreimu, nullptr);
}

TEST_F(CoreLSM6DSOXTest, setPowerMode)
TEST_F(CoreIMUTest, setPowerMode)
{
EXPECT_CALL(mocki2c, write).Times(AtLeast(1));
EXPECT_CALL(mocki2c, read).Times(AtLeast(1));
lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Off);
coreimu.setPowerMode(CoreIMU::PowerMode::Off);

EXPECT_CALL(mocki2c, write).Times(AtLeast(1));
EXPECT_CALL(mocki2c, read).Times(AtLeast(1));
lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::UltraLow);
coreimu.setPowerMode(CoreIMU::PowerMode::UltraLow);

EXPECT_CALL(mocki2c, write).Times(AtLeast(1));
EXPECT_CALL(mocki2c, read).Times(AtLeast(1));
lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Normal);
coreimu.setPowerMode(CoreIMU::PowerMode::Normal);

EXPECT_CALL(mocki2c, write).Times(AtLeast(1));
EXPECT_CALL(mocki2c, read).Times(AtLeast(1));
lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::High);
coreimu.setPowerMode(CoreIMU::PowerMode::High);
}

TEST_F(CoreLSM6DSOXTest, onGyrDRDY)
TEST_F(CoreIMUTest, onGyrDRDY)
{
MockFunction<void(const leka::interface::LSM6DSOX::SensorData &data)> mock_callback;
MockFunction<void(const leka::interface::IMU::SensorData &data)> mock_callback;

EXPECT_CALL(mocki2c, write).Times(AtLeast(1));
EXPECT_CALL(mocki2c, read).Times(AtLeast(1));
EXPECT_CALL(mock_callback, Call).Times(1);

lsm6dsox.registerOnGyDataReadyCallback(mock_callback.AsStdFunction());
coreimu.registerOnGyDataReadyCallback(mock_callback.AsStdFunction());

auto on_rise_callback = spy_InterruptIn_getRiseCallback();
on_rise_callback();
}

TEST_F(CoreLSM6DSOXTest, emptyOnGyrDrdyCallback)
TEST_F(CoreIMUTest, emptyOnGyrDrdyCallback)
{
lsm6dsox.registerOnGyDataReadyCallback({});
coreimu.registerOnGyDataReadyCallback({});

auto on_rise_callback = spy_InterruptIn_getRiseCallback();
on_rise_callback();
}

TEST_F(CoreLSM6DSOXTest, enableDeepSleep)
TEST_F(CoreIMUTest, enableDeepSleep)
{
EXPECT_CALL(mocki2c, write).Times(AtLeast(1));
EXPECT_CALL(mocki2c, read).Times(AtLeast(1));
lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Off);
coreimu.setPowerMode(CoreIMU::PowerMode::Off);

lsm6dsox.enableDeepSleep();
coreimu.enableDeepSleep();
}

TEST_F(CoreLSM6DSOXTest, disableDeepSleep)
TEST_F(CoreIMUTest, disableDeepSleep)
{
EXPECT_CALL(mocki2c, write).Times(AtLeast(1));
EXPECT_CALL(mocki2c, read).Times(AtLeast(1));
lsm6dsox.setPowerMode(CoreLSM6DSOX::PowerMode::Normal);
coreimu.setPowerMode(CoreIMU::PowerMode::Normal);

lsm6dsox.disableDeepSleep();
coreimu.disableDeepSleep();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

namespace leka::interface {

class LSM6DSOX
class IMU
{
public:
virtual ~LSM6DSOX() = default;
virtual ~IMU() = default;

enum class PowerMode
{
Expand Down
8 changes: 4 additions & 4 deletions libs/IMUKit/include/IMUKit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

#pragma once

#include "interface/LSM6DSOX.hpp"
#include "interface/drivers/IMU.hpp"
#include "interface/libs/IMUKit.hpp"

namespace leka {

class IMUKit : public interface::IMUKit
{
public:
explicit IMUKit(interface::LSM6DSOX &lsm6dsox) : _lsm6dsox(lsm6dsox) {}
explicit IMUKit(interface::IMU &imu) : _imu(imu) {}

void init();
void start() final;
Expand All @@ -23,9 +23,9 @@ class IMUKit : public interface::IMUKit
[[nodiscard]] auto getEulerAngles() const -> EulerAngles final;

private:
void drdy_callback(interface::LSM6DSOX::SensorData data);
void drdy_callback(interface::IMU::SensorData data);

interface::LSM6DSOX &_lsm6dsox;
interface::IMU &_imu;
EulerAngles _euler_angles {};
angles_ready_callback_t _on_euler_angles_rdy_callback {};
};
Expand Down
Loading

0 comments on commit b90bc51

Please sign in to comment.