Skip to content

Commit

Permalink
🚚 (imu): Rename CoreLSM6DSOX to CoreIMU
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed Jul 17, 2024
1 parent 79b6e2a commit 4358c82
Show file tree
Hide file tree
Showing 22 changed files with 149 additions and 149 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 @@ -15,10 +15,10 @@

namespace leka {

class CoreLSM6DSOX : public interface::IMU, 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::IMU, public interface::DeepSleepEnabled
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::IMU::PowerMode::Off);
}

void CoreLSM6DSOX::disableDeepSleep()
void CoreIMU::disableDeepSleep()
{
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::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();
}
2 changes: 1 addition & 1 deletion libs/IMUKit/tests/IMUKit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "IMUKit.hpp"

#include "CoreLSM6DSOX.hpp"
#include "CoreIMU.hpp"
#include "ThisThread.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand Down
8 changes: 4 additions & 4 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ add_subdirectory(${SPIKES_DIR}/lk_qdac)
add_subdirectory(${SPIKES_DIR}/lk_reinforcer)
add_subdirectory(${SPIKES_DIR}/lk_rfid)
add_subdirectory(${SPIKES_DIR}/lk_sensors_battery)
add_subdirectory(${SPIKES_DIR}/lk_sensors_imu_lsm6dsox)
add_subdirectory(${SPIKES_DIR}/lk_sensors_imu_lsm6dsox_fusion_calibration)
add_subdirectory(${SPIKES_DIR}/lk_sensors_imu)
add_subdirectory(${SPIKES_DIR}/lk_sensors_imu_fusion_calibration)
add_subdirectory(${SPIKES_DIR}/lk_sensors_light)
add_subdirectory(${SPIKES_DIR}/lk_sensors_microphone)
add_subdirectory(${SPIKES_DIR}/lk_sensors_temperature_humidity)
Expand Down Expand Up @@ -71,8 +71,8 @@ add_dependencies(spikes_leka
spike_lk_reinforcer
spike_lk_rfid
spike_lk_sensors_battery
spike_lk_sensors_imu_lsm6dsox
spike_lk_sensors_imu_lsm6dsox_fusion_calibration
spike_lk_sensors_imu
spike_lk_sensors_imu_fusion_calibration
spike_lk_sensors_light
spike_lk_sensors_microphone
spike_lk_sensors_temperature_humidity
Expand Down
8 changes: 4 additions & 4 deletions spikes/lk_activity_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
#include "CoreFont.hpp"
#include "CoreGraphics.hpp"
#include "CoreI2C.h"
#include "CoreIMU.hpp"
#include "CoreInterruptIn.h"
#include "CoreJPEG.hpp"
#include "CoreJPEGModeDMA.hpp"
#include "CoreJPEGModePolling.hpp"
#include "CoreLCD.hpp"
#include "CoreLCDDriverOTM8009A.hpp"
#include "CoreLL.h"
#include "CoreLSM6DSOX.hpp"
#include "CoreLTDC.hpp"
#include "CoreMotor.h"
#include "CorePwm.h"
Expand Down Expand Up @@ -195,11 +195,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 @@ -276,7 +276,7 @@ auto main() -> int

sd::init();

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

ledkit.init();
Expand Down
Loading

0 comments on commit 4358c82

Please sign in to comment.