From 72d8904a148863be5dd8f1c0ba59d5ecf202ebdc Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 19 Feb 2024 14:23:32 +0100 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=9A=9A=20(imu):=20Rename=20Gy(r)DataR?= =?UTF-8?q?eady=20to=20DataReady?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drivers/CoreIMU/include/CoreIMU.hpp | 8 +++---- drivers/CoreIMU/source/CoreIMU.cpp | 24 +++++++++---------- drivers/CoreIMU/tests/CoreIMU_test.cpp | 8 +++---- include/interface/drivers/IMU.hpp | 6 ++--- libs/IMUKit/source/IMUKit.cpp | 2 +- spikes/lk_sensors_imu/main.cpp | 2 +- .../main.cpp | 2 +- .../tests/core_imu/suite_core_imu.cpp | 2 +- tests/functional/tests/core_imu/utils.h | 2 +- tests/unit/mocks/mocks/leka/IMU.h | 2 +- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/drivers/CoreIMU/include/CoreIMU.hpp b/drivers/CoreIMU/include/CoreIMU.hpp index bed4d3f779..3b877717b9 100644 --- a/drivers/CoreIMU/include/CoreIMU.hpp +++ b/drivers/CoreIMU/include/CoreIMU.hpp @@ -22,7 +22,7 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled void init() final; - void registerOnGyDataReadyCallback(drdy_callback_t const &callback) final; + void registerOnDataReadyCallback(drdy_callback_t const &callback) final; void setPowerMode(PowerMode mode) final; @@ -38,8 +38,8 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled 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); - void setGyrDataReadyInterrupt(); + void onDataReadyHandler(auto timestamp); + void setDataReadyInterrupt(); interface::I2C &_i2c; CoreEventQueue _event_queue {}; @@ -51,7 +51,7 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled std::array data_raw_xl {}; std::array data_raw_gy {}; - drdy_callback_t _on_gy_data_ready_callback {}; + drdy_callback_t _on_data_ready_callback {}; static constexpr uint8_t kMaxBufferLength = 32; std::array _rx_buffer {}; diff --git a/drivers/CoreIMU/source/CoreIMU.cpp b/drivers/CoreIMU/source/CoreIMU.cpp index 2a749aafeb..757f132bbb 100644 --- a/drivers/CoreIMU/source/CoreIMU.cpp +++ b/drivers/CoreIMU/source/CoreIMU.cpp @@ -30,7 +30,7 @@ void CoreIMU::init() lsm6dsox_mode_set(&_register_io_function, nullptr, &_config); - setGyrDataReadyInterrupt(); + setDataReadyInterrupt(); } void CoreIMU::setPowerMode(PowerMode mode) @@ -71,12 +71,12 @@ void CoreIMU::setPowerMode(PowerMode mode) lsm6dsox_gy_data_rate_set(&_register_io_function, gy_odr); } -void CoreIMU::registerOnGyDataReadyCallback(drdy_callback_t const &callback) +void CoreIMU::registerOnDataReadyCallback(drdy_callback_t const &callback) { - _on_gy_data_ready_callback = callback; + _on_data_ready_callback = callback; } -void CoreIMU::onGyrDataReadyHandler(auto timestamp) +void CoreIMU::onDataReadyHandler(auto timestamp) { static constexpr auto _1k = float {1000.F}; @@ -92,8 +92,8 @@ void CoreIMU::onGyrDataReadyHandler(auto timestamp) _sensor_data.xl.y = lsm6dsox_from_fs4_to_mg(data_raw_xl.at(1)) / _1k; _sensor_data.xl.z = lsm6dsox_from_fs4_to_mg(data_raw_xl.at(2)) / _1k; - if (_on_gy_data_ready_callback) { - _on_gy_data_ready_callback(_sensor_data); + if (_on_data_ready_callback) { + _on_data_ready_callback(_sensor_data); } } @@ -143,23 +143,23 @@ auto CoreIMU::ptr_io_read(CoreIMU *handle, uint8_t read_address, uint8_t *p_buff return handle->read(read_address, number_bytes_to_read, p_buffer); } -void CoreIMU::setGyrDataReadyInterrupt() +void CoreIMU::setDataReadyInterrupt() { lsm6dsox_dataready_pulsed_t drdy_pulsed {LSM6DSOX_DRDY_PULSED}; lsm6dsox_data_ready_mode_set(&_register_io_function, drdy_pulsed); - lsm6dsox_pin_int1_route_t gyro_int1 { + lsm6dsox_pin_int1_route_t lsm6dsox_int1 { .drdy_xl = PROPERTY_ENABLE, .den_flag = PROPERTY_ENABLE, }; - lsm6dsox_pin_int1_route_set(&_register_io_function, gyro_int1); + lsm6dsox_pin_int1_route_set(&_register_io_function, lsm6dsox_int1); - auto gyr_drdy_callback = [this] { + auto data_ready_callback = [this] { auto timestamp = rtos::Kernel::Clock::now(); - _event_queue.call([this, timestamp] { onGyrDataReadyHandler(timestamp); }); + _event_queue.call([this, timestamp] { onDataReadyHandler(timestamp); }); }; - _drdy_irq.onRise(gyr_drdy_callback); + _drdy_irq.onRise(data_ready_callback); } } // namespace leka diff --git a/drivers/CoreIMU/tests/CoreIMU_test.cpp b/drivers/CoreIMU/tests/CoreIMU_test.cpp index 5f0136acca..582658e6bd 100644 --- a/drivers/CoreIMU/tests/CoreIMU_test.cpp +++ b/drivers/CoreIMU/tests/CoreIMU_test.cpp @@ -65,7 +65,7 @@ TEST_F(CoreIMUTest, setPowerMode) coreimu.setPowerMode(CoreIMU::PowerMode::High); } -TEST_F(CoreIMUTest, onGyrDRDY) +TEST_F(CoreIMUTest, onDataReady) { MockFunction mock_callback; @@ -73,15 +73,15 @@ TEST_F(CoreIMUTest, onGyrDRDY) EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); EXPECT_CALL(mock_callback, Call).Times(1); - coreimu.registerOnGyDataReadyCallback(mock_callback.AsStdFunction()); + coreimu.registerOnDataReadyCallback(mock_callback.AsStdFunction()); auto on_rise_callback = spy_InterruptIn_getRiseCallback(); on_rise_callback(); } -TEST_F(CoreIMUTest, emptyOnGyrDrdyCallback) +TEST_F(CoreIMUTest, emptyOnDataReadyCallback) { - coreimu.registerOnGyDataReadyCallback({}); + coreimu.registerOnDataReadyCallback({}); auto on_rise_callback = spy_InterruptIn_getRiseCallback(); on_rise_callback(); diff --git a/include/interface/drivers/IMU.hpp b/include/interface/drivers/IMU.hpp index 71d70c798c..76a2cc15d3 100644 --- a/include/interface/drivers/IMU.hpp +++ b/include/interface/drivers/IMU.hpp @@ -47,8 +47,8 @@ class IMU using drdy_callback_t = std::function; - virtual void init() = 0; - virtual void registerOnGyDataReadyCallback(drdy_callback_t const &callback) = 0; - virtual void setPowerMode(PowerMode) = 0; + virtual void init() = 0; + virtual void registerOnDataReadyCallback(drdy_callback_t const &callback) = 0; + virtual void setPowerMode(PowerMode) = 0; }; } // namespace leka::interface diff --git a/libs/IMUKit/source/IMUKit.cpp b/libs/IMUKit/source/IMUKit.cpp index 740ffbf1e2..3b14d155bd 100644 --- a/libs/IMUKit/source/IMUKit.cpp +++ b/libs/IMUKit/source/IMUKit.cpp @@ -57,7 +57,7 @@ void IMUKit::init() auto on_drdy_callback = [this](const interface::IMU::SensorData &data) { drdy_callback(data); }; - _imu.registerOnGyDataReadyCallback(on_drdy_callback); + _imu.registerOnDataReadyCallback(on_drdy_callback); } void IMUKit::start() diff --git a/spikes/lk_sensors_imu/main.cpp b/spikes/lk_sensors_imu/main.cpp index dd011ba1d7..af89b6d26a 100644 --- a/spikes/lk_sensors_imu/main.cpp +++ b/spikes/lk_sensors_imu/main.cpp @@ -51,7 +51,7 @@ auto main() -> int timestamp, xlx, xly, xlz, gx, gy, gz); }; - imu::coreimu.registerOnGyDataReadyCallback(callback); + imu::coreimu.registerOnDataReadyCallback(callback); while (true) { log_info("Setting normal power mode for 5s"); diff --git a/spikes/lk_sensors_imu_fusion_calibration/main.cpp b/spikes/lk_sensors_imu_fusion_calibration/main.cpp index b80691cb6b..57023febf2 100644 --- a/spikes/lk_sensors_imu_fusion_calibration/main.cpp +++ b/spikes/lk_sensors_imu_fusion_calibration/main.cpp @@ -136,7 +136,7 @@ auto main() -> int rtos::ThisThread::sleep_for(1s); - imu::coreimu.registerOnGyDataReadyCallback(fusion::callback); + imu::coreimu.registerOnDataReadyCallback(fusion::callback); imu::coreimu.setPowerMode(CoreIMU::PowerMode::Normal); while (true) { diff --git a/tests/functional/tests/core_imu/suite_core_imu.cpp b/tests/functional/tests/core_imu/suite_core_imu.cpp index 0e35296aef..43d16caeb3 100644 --- a/tests/functional/tests/core_imu/suite_core_imu.cpp +++ b/tests/functional/tests/core_imu/suite_core_imu.cpp @@ -25,7 +25,7 @@ suite suite_coreimu = [] { coreimu.init(); auto sensor_callback = [&](const leka::interface::IMU::SensorData &data) { sensor_data = data; }; - coreimu.registerOnGyDataReadyCallback(sensor_callback); + coreimu.registerOnDataReadyCallback(sensor_callback); }; scenario("imu - power mode") = [&] { diff --git a/tests/functional/tests/core_imu/utils.h b/tests/functional/tests/core_imu/utils.h index cbe25cf7ed..68e1c13394 100644 --- a/tests/functional/tests/core_imu/utils.h +++ b/tests/functional/tests/core_imu/utils.h @@ -23,7 +23,7 @@ inline auto values_did_change_over_time(leka::interface::IMU &imu) auto f_batch = std::vector {}; auto sensor_callback = [&](const leka::interface::IMU::SensorData &data) { sensor_data = data; }; - imu.registerOnGyDataReadyCallback(sensor_callback); + imu.registerOnDataReadyCallback(sensor_callback); for (auto i = 0; i < 10; ++i) { auto [xlx, xly, xlz] = sensor_data.xl; diff --git a/tests/unit/mocks/mocks/leka/IMU.h b/tests/unit/mocks/mocks/leka/IMU.h index bd44872e3c..5a351b8b5a 100644 --- a/tests/unit/mocks/mocks/leka/IMU.h +++ b/tests/unit/mocks/mocks/leka/IMU.h @@ -15,7 +15,7 @@ class IMU : public interface::IMU MOCK_METHOD(void, init, (), (override)); MOCK_METHOD(void, setPowerMode, (PowerMode), (override)); - void registerOnGyDataReadyCallback(drdy_callback_t const &cb) override { drdy_callback = cb; } + void registerOnDataReadyCallback(drdy_callback_t const &cb) override { drdy_callback = cb; } void call_drdy_callback(const SensorData &data) { drdy_callback(data); } From 5d94b3b393b62d1d89438156690cbc9219b3ddc1 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 19 Feb 2024 14:32:03 +0100 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=9A=9A=20(imu):=20Rename=20drdy=5Firq?= =?UTF-8?q?=20by=20irq?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit drdy is confusing since it is not only for data ready --- app/os/main.cpp | 6 +++--- drivers/CoreIMU/include/CoreIMU.hpp | 4 ++-- drivers/CoreIMU/source/CoreIMU.cpp | 4 ++-- drivers/CoreIMU/tests/CoreIMU_test.cpp | 4 ++-- spikes/lk_activity_kit/main.cpp | 6 +++--- spikes/lk_command_kit/main.cpp | 6 +++--- spikes/lk_imu_kit/main.cpp | 6 +++--- spikes/lk_motion_kit/main.cpp | 4 ++-- spikes/lk_reinforcer/main.cpp | 6 +++--- spikes/lk_sensors_imu/main.cpp | 6 +++--- spikes/lk_sensors_imu_fusion_calibration/main.cpp | 6 +++--- tests/functional/tests/core_imu/suite_core_imu.cpp | 4 ++-- tests/functional/tests/imu_kit/suite_imu_kit.cpp | 8 ++++---- 13 files changed, 35 insertions(+), 35 deletions(-) diff --git a/app/os/main.cpp b/app/os/main.cpp index 001bb16e37..f2f2a9cb4b 100644 --- a/app/os/main.cpp +++ b/app/os/main.cpp @@ -260,12 +260,12 @@ namespace imu { namespace internal { - auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); + auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; + auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); } // namespace internal - auto coreimu = CoreIMU(internal::i2c, internal::drdy_irq); + auto coreimu = CoreIMU(internal::i2c, internal::irq); } // namespace imu diff --git a/drivers/CoreIMU/include/CoreIMU.hpp b/drivers/CoreIMU/include/CoreIMU.hpp index 3b877717b9..00fc482801 100644 --- a/drivers/CoreIMU/include/CoreIMU.hpp +++ b/drivers/CoreIMU/include/CoreIMU.hpp @@ -18,7 +18,7 @@ namespace leka { class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled { public: - explicit CoreIMU(interface::I2C &i2c, CoreInterruptIn &drdy_irq); + explicit CoreIMU(interface::I2C &i2c, CoreInterruptIn &irq); void init() final; @@ -46,7 +46,7 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled lsm6dsox_md_t _config {}; stmdev_ctx_t _register_io_function {}; SensorData _sensor_data {}; - CoreInterruptIn &_drdy_irq; + CoreInterruptIn &_irq; const char _address = LSM6DSOX_I2C_ADD_L; std::array data_raw_xl {}; diff --git a/drivers/CoreIMU/source/CoreIMU.cpp b/drivers/CoreIMU/source/CoreIMU.cpp index 757f132bbb..d116bef5b9 100644 --- a/drivers/CoreIMU/source/CoreIMU.cpp +++ b/drivers/CoreIMU/source/CoreIMU.cpp @@ -6,7 +6,7 @@ namespace leka { -CoreIMU::CoreIMU(interface::I2C &i2c, CoreInterruptIn &drdy_irq) : _i2c(i2c), _drdy_irq(drdy_irq) +CoreIMU::CoreIMU(interface::I2C &i2c, CoreInterruptIn &irq) : _i2c(i2c), _irq(irq) { // ? NOLINTNEXTLINE - allow reinterpret_cast as there are no alternatives _register_io_function.write_reg = reinterpret_cast(ptr_io_write); @@ -159,7 +159,7 @@ void CoreIMU::setDataReadyInterrupt() _event_queue.call([this, timestamp] { onDataReadyHandler(timestamp); }); }; - _drdy_irq.onRise(data_ready_callback); + _irq.onRise(data_ready_callback); } } // namespace leka diff --git a/drivers/CoreIMU/tests/CoreIMU_test.cpp b/drivers/CoreIMU/tests/CoreIMU_test.cpp index 582658e6bd..3b1fe2da11 100644 --- a/drivers/CoreIMU/tests/CoreIMU_test.cpp +++ b/drivers/CoreIMU/tests/CoreIMU_test.cpp @@ -31,9 +31,9 @@ class CoreIMUTest : public ::testing::Test // void TearDown() override {} mock::CoreI2C mocki2c {}; - CoreInterruptIn drdy_irq {NC}; + CoreInterruptIn irq {NC}; - CoreIMU coreimu {mocki2c, drdy_irq}; + CoreIMU coreimu {mocki2c, irq}; // ? Instantiation of mock::EventQueue is needed to setup the underlying stubs that will make the mock work // ? correctly. Without it UT are failing diff --git a/spikes/lk_activity_kit/main.cpp b/spikes/lk_activity_kit/main.cpp index cd563f9912..2d1bd5a28b 100644 --- a/spikes/lk_activity_kit/main.cpp +++ b/spikes/lk_activity_kit/main.cpp @@ -190,12 +190,12 @@ namespace imu { namespace internal { - auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); + auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; + auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); } // namespace internal - auto coreimu = CoreIMU(internal::i2c, internal::drdy_irq); + auto coreimu = CoreIMU(internal::i2c, internal::irq); } // namespace imu diff --git a/spikes/lk_command_kit/main.cpp b/spikes/lk_command_kit/main.cpp index f33ff82613..9e5c964266 100644 --- a/spikes/lk_command_kit/main.cpp +++ b/spikes/lk_command_kit/main.cpp @@ -99,12 +99,12 @@ auto right = CoreMotor {internal::right::dir_1, internal::right::dir_2, internal namespace imu { namespace internal { - auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); + auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; + auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); } // namespace internal -CoreIMU coreimu(internal::i2c, internal::drdy_irq); +CoreIMU coreimu(internal::i2c, internal::irq); } // namespace imu diff --git a/spikes/lk_imu_kit/main.cpp b/spikes/lk_imu_kit/main.cpp index fc3c4fc594..eb28c1f104 100644 --- a/spikes/lk_imu_kit/main.cpp +++ b/spikes/lk_imu_kit/main.cpp @@ -19,12 +19,12 @@ namespace imu { namespace internal { - auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); + auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; + auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); } // namespace internal - CoreIMU coreimu(internal::i2c, internal::drdy_irq); + CoreIMU coreimu(internal::i2c, internal::irq); } // namespace imu diff --git a/spikes/lk_motion_kit/main.cpp b/spikes/lk_motion_kit/main.cpp index 7b5b93e3ab..cbd7f8dca2 100644 --- a/spikes/lk_motion_kit/main.cpp +++ b/spikes/lk_motion_kit/main.cpp @@ -59,13 +59,13 @@ namespace imu { namespace internal { - auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; + auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; CoreI2C i2c(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); auto event_queue = CoreEventQueue(); } // namespace internal - CoreIMU coreimu(internal::i2c, internal::drdy_irq); + CoreIMU coreimu(internal::i2c, internal::irq); } // namespace imu diff --git a/spikes/lk_reinforcer/main.cpp b/spikes/lk_reinforcer/main.cpp index 763177c878..912e129672 100644 --- a/spikes/lk_reinforcer/main.cpp +++ b/spikes/lk_reinforcer/main.cpp @@ -137,12 +137,12 @@ namespace imu { namespace internal { - auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); + auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; + auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); } // namespace internal - CoreIMU coreimu(internal::i2c, internal::drdy_irq); + CoreIMU coreimu(internal::i2c, internal::irq); } // namespace imu diff --git a/spikes/lk_sensors_imu/main.cpp b/spikes/lk_sensors_imu/main.cpp index af89b6d26a..ad777e1e57 100644 --- a/spikes/lk_sensors_imu/main.cpp +++ b/spikes/lk_sensors_imu/main.cpp @@ -20,12 +20,12 @@ namespace imu { namespace internal { - auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); + auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; + auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); } // namespace internal - CoreIMU coreimu(internal::i2c, internal::drdy_irq); + CoreIMU coreimu(internal::i2c, internal::irq); } // namespace imu diff --git a/spikes/lk_sensors_imu_fusion_calibration/main.cpp b/spikes/lk_sensors_imu_fusion_calibration/main.cpp index 57023febf2..c39e4bbc49 100644 --- a/spikes/lk_sensors_imu_fusion_calibration/main.cpp +++ b/spikes/lk_sensors_imu_fusion_calibration/main.cpp @@ -26,12 +26,12 @@ namespace imu { namespace internal { - auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); + auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; + auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); } // namespace internal - CoreIMU coreimu(internal::i2c, internal::drdy_irq); + CoreIMU coreimu(internal::i2c, internal::irq); } // namespace imu diff --git a/tests/functional/tests/core_imu/suite_core_imu.cpp b/tests/functional/tests/core_imu/suite_core_imu.cpp index 43d16caeb3..3f4ca2e41c 100644 --- a/tests/functional/tests/core_imu/suite_core_imu.cpp +++ b/tests/functional/tests/core_imu/suite_core_imu.cpp @@ -16,8 +16,8 @@ using namespace boost::ut::bdd; suite suite_coreimu = [] { auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); - auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto coreimu = CoreIMU {i2c, drdy_irq}; + auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; + auto coreimu = CoreIMU {i2c, irq}; auto sensor_data = leka::interface::IMU::SensorData(); "initialization"_test = [&] { diff --git a/tests/functional/tests/imu_kit/suite_imu_kit.cpp b/tests/functional/tests/imu_kit/suite_imu_kit.cpp index 0d1c9ac29b..39325b70a4 100644 --- a/tests/functional/tests/imu_kit/suite_imu_kit.cpp +++ b/tests/functional/tests/imu_kit/suite_imu_kit.cpp @@ -26,10 +26,10 @@ suite suite_imu_kit = [] { constexpr auto maximal_roll_noise_amplitude = 0.5F; constexpr auto maximal_yaw_drift = 15.F; - auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); - auto drdy_irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; - auto coreimu = CoreIMU {i2c, drdy_irq}; - auto imukit = IMUKit {coreimu}; + auto i2c = CoreI2C(PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL); + auto irq = CoreInterruptIn {PinName::SENSOR_IMU_IRQ}; + auto coreimu = CoreIMU {i2c, irq}; + auto imukit = IMUKit {coreimu}; coreimu.init(); From 1c1d018bae997536c7514342eae1b98bc0077bb4 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 19 Feb 2024 14:32:52 +0100 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=9A=9A=20(imu):=20Rename=20drdy=5Fcal?= =?UTF-8?q?lback=20to=20data=5Fready=5Fcallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More explicit and understandable --- drivers/CoreIMU/include/CoreIMU.hpp | 4 ++-- drivers/CoreIMU/source/CoreIMU.cpp | 2 +- include/interface/drivers/IMU.hpp | 8 ++++---- libs/IMUKit/include/IMUKit.hpp | 2 +- libs/IMUKit/source/IMUKit.cpp | 6 +++--- libs/IMUKit/tests/IMUKit_test.cpp | 8 ++++---- tests/unit/mocks/mocks/leka/IMU.h | 6 +++--- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/CoreIMU/include/CoreIMU.hpp b/drivers/CoreIMU/include/CoreIMU.hpp index 00fc482801..a6d8601990 100644 --- a/drivers/CoreIMU/include/CoreIMU.hpp +++ b/drivers/CoreIMU/include/CoreIMU.hpp @@ -22,7 +22,7 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled void init() final; - void registerOnDataReadyCallback(drdy_callback_t const &callback) final; + void registerOnDataReadyCallback(data_ready_callback_t const &callback) final; void setPowerMode(PowerMode mode) final; @@ -51,7 +51,7 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled std::array data_raw_xl {}; std::array data_raw_gy {}; - drdy_callback_t _on_data_ready_callback {}; + data_ready_callback_t _on_data_ready_callback {}; static constexpr uint8_t kMaxBufferLength = 32; std::array _rx_buffer {}; diff --git a/drivers/CoreIMU/source/CoreIMU.cpp b/drivers/CoreIMU/source/CoreIMU.cpp index d116bef5b9..8108f3b6be 100644 --- a/drivers/CoreIMU/source/CoreIMU.cpp +++ b/drivers/CoreIMU/source/CoreIMU.cpp @@ -71,7 +71,7 @@ void CoreIMU::setPowerMode(PowerMode mode) lsm6dsox_gy_data_rate_set(&_register_io_function, gy_odr); } -void CoreIMU::registerOnDataReadyCallback(drdy_callback_t const &callback) +void CoreIMU::registerOnDataReadyCallback(data_ready_callback_t const &callback) { _on_data_ready_callback = callback; } diff --git a/include/interface/drivers/IMU.hpp b/include/interface/drivers/IMU.hpp index 76a2cc15d3..009c6069bd 100644 --- a/include/interface/drivers/IMU.hpp +++ b/include/interface/drivers/IMU.hpp @@ -45,10 +45,10 @@ class IMU time_point_t timestamp {}; }; - using drdy_callback_t = std::function; + using data_ready_callback_t = std::function; - virtual void init() = 0; - virtual void registerOnDataReadyCallback(drdy_callback_t const &callback) = 0; - virtual void setPowerMode(PowerMode) = 0; + virtual void init() = 0; + virtual void registerOnDataReadyCallback(data_ready_callback_t const &callback) = 0; + virtual void setPowerMode(PowerMode) = 0; }; } // namespace leka::interface diff --git a/libs/IMUKit/include/IMUKit.hpp b/libs/IMUKit/include/IMUKit.hpp index 10a459cdc1..e3ac2fd45b 100644 --- a/libs/IMUKit/include/IMUKit.hpp +++ b/libs/IMUKit/include/IMUKit.hpp @@ -23,7 +23,7 @@ class IMUKit : public interface::IMUKit [[nodiscard]] auto getEulerAngles() const -> EulerAngles final; private: - void drdy_callback(interface::IMU::SensorData data); + void data_ready_callback(interface::IMU::SensorData data); interface::IMU &_imu; EulerAngles _euler_angles {}; diff --git a/libs/IMUKit/source/IMUKit.cpp b/libs/IMUKit/source/IMUKit.cpp index 3b14d155bd..d9bbaf3f45 100644 --- a/libs/IMUKit/source/IMUKit.cpp +++ b/libs/IMUKit/source/IMUKit.cpp @@ -55,9 +55,9 @@ void IMUKit::init() FusionOffsetInitialise(&fusion::global_offset, fusion::kODR_HZ); } - auto on_drdy_callback = [this](const interface::IMU::SensorData &data) { drdy_callback(data); }; + auto on_data_ready_callback = [this](const interface::IMU::SensorData &data) { data_ready_callback(data); }; - _imu.registerOnDataReadyCallback(on_drdy_callback); + _imu.registerOnDataReadyCallback(on_data_ready_callback); } void IMUKit::start() @@ -88,7 +88,7 @@ void IMUKit::onEulerAnglesReady(angles_ready_callback_t const &callback) _on_euler_angles_rdy_callback = callback; } -void IMUKit::drdy_callback(const interface::IMU::SensorData data) +void IMUKit::data_ready_callback(const interface::IMU::SensorData data) { // ? Note: For a detailed explanation on the code below, checkout // ? https://github.com/leka/LekaOS/tree/develop/spikes/lk_sensors_imu_imu_fusion_calibration diff --git a/libs/IMUKit/tests/IMUKit_test.cpp b/libs/IMUKit/tests/IMUKit_test.cpp index cd83887f93..71b0e71a9c 100644 --- a/libs/IMUKit/tests/IMUKit_test.cpp +++ b/libs/IMUKit/tests/IMUKit_test.cpp @@ -75,7 +75,7 @@ TEST_F(IMUKitTest, onDataReady) EXPECT_CALL(mock_callback, Call); - mock_imu.call_drdy_callback(data_initial); + mock_imu.call_data_ready_callback(data_initial); const auto angles_initial = imukit.getEulerAngles(); @@ -86,7 +86,7 @@ TEST_F(IMUKitTest, onDataReady) EXPECT_CALL(mock_callback, Call); - mock_imu.call_drdy_callback(data_updated); + mock_imu.call_data_ready_callback(data_updated); auto angles_updated = imukit.getEulerAngles(); @@ -102,7 +102,7 @@ TEST_F(IMUKitTest, onDataReadyEmptyEulerAngleCallback) const auto data_initial = interface::IMU::SensorData {.xl = {.x = 0.F, .y = 0.F, .z = 0.F}, .gy = {.x = 0.F, .y = 0.F, .z = 0.F}}; - mock_imu.call_drdy_callback(data_initial); + mock_imu.call_data_ready_callback(data_initial); const auto angles_initial = imukit.getEulerAngles(); @@ -111,7 +111,7 @@ TEST_F(IMUKitTest, onDataReadyEmptyEulerAngleCallback) const auto data_updated = interface::IMU::SensorData {.xl = {.x = 1.F, .y = 2.F, .z = 3.F}, .gy = {.x = 1.F, .y = 2.F, .z = 3.F}}; - mock_imu.call_drdy_callback(data_updated); + mock_imu.call_data_ready_callback(data_updated); auto angles_updated = imukit.getEulerAngles(); diff --git a/tests/unit/mocks/mocks/leka/IMU.h b/tests/unit/mocks/mocks/leka/IMU.h index 5a351b8b5a..6f8218228d 100644 --- a/tests/unit/mocks/mocks/leka/IMU.h +++ b/tests/unit/mocks/mocks/leka/IMU.h @@ -15,12 +15,12 @@ class IMU : public interface::IMU MOCK_METHOD(void, init, (), (override)); MOCK_METHOD(void, setPowerMode, (PowerMode), (override)); - void registerOnDataReadyCallback(drdy_callback_t const &cb) override { drdy_callback = cb; } + void registerOnDataReadyCallback(data_ready_callback_t const &cb) override { data_ready_callback = cb; } - void call_drdy_callback(const SensorData &data) { drdy_callback(data); } + void call_data_ready_callback(const SensorData &data) { data_ready_callback(data); } private: - drdy_callback_t drdy_callback {}; + data_ready_callback_t data_ready_callback {}; }; } // namespace leka::mock From 90d8a0a7902d828c1babf9955295eea23dc38bff Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 19 Feb 2024 14:34:39 +0100 Subject: [PATCH 4/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(imu):=20No=20abbrevia?= =?UTF-8?q?tion=20for=20drdy,=20use=20data=5Fready?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drivers/CoreIMU/source/CoreIMU.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/CoreIMU/source/CoreIMU.cpp b/drivers/CoreIMU/source/CoreIMU.cpp index 8108f3b6be..80353ac218 100644 --- a/drivers/CoreIMU/source/CoreIMU.cpp +++ b/drivers/CoreIMU/source/CoreIMU.cpp @@ -145,8 +145,8 @@ auto CoreIMU::ptr_io_read(CoreIMU *handle, uint8_t read_address, uint8_t *p_buff void CoreIMU::setDataReadyInterrupt() { - lsm6dsox_dataready_pulsed_t drdy_pulsed {LSM6DSOX_DRDY_PULSED}; - lsm6dsox_data_ready_mode_set(&_register_io_function, drdy_pulsed); + lsm6dsox_dataready_pulsed_t data_ready_pulsed {LSM6DSOX_DRDY_PULSED}; + lsm6dsox_data_ready_mode_set(&_register_io_function, data_ready_pulsed); lsm6dsox_pin_int1_route_t lsm6dsox_int1 { .drdy_xl = PROPERTY_ENABLE, From eb48c4fac389935bf085106157142f4f92f11a13 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 19 Feb 2024 17:16:54 +0100 Subject: [PATCH 5/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(imu):=20Move=20lsm6ds?= =?UTF-8?q?ox=20dataready=20pulsed=20config=20in=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drivers/CoreIMU/source/CoreIMU.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/CoreIMU/source/CoreIMU.cpp b/drivers/CoreIMU/source/CoreIMU.cpp index 80353ac218..d351696ef1 100644 --- a/drivers/CoreIMU/source/CoreIMU.cpp +++ b/drivers/CoreIMU/source/CoreIMU.cpp @@ -30,6 +30,9 @@ void CoreIMU::init() lsm6dsox_mode_set(&_register_io_function, nullptr, &_config); + lsm6dsox_dataready_pulsed_t data_ready_pulsed {LSM6DSOX_DRDY_PULSED}; + lsm6dsox_data_ready_mode_set(&_register_io_function, data_ready_pulsed); + setDataReadyInterrupt(); } @@ -145,9 +148,6 @@ auto CoreIMU::ptr_io_read(CoreIMU *handle, uint8_t read_address, uint8_t *p_buff void CoreIMU::setDataReadyInterrupt() { - lsm6dsox_dataready_pulsed_t data_ready_pulsed {LSM6DSOX_DRDY_PULSED}; - lsm6dsox_data_ready_mode_set(&_register_io_function, data_ready_pulsed); - lsm6dsox_pin_int1_route_t lsm6dsox_int1 { .drdy_xl = PROPERTY_ENABLE, .den_flag = PROPERTY_ENABLE, From 25dfefee4b5dd930371a1f98de4e35c495f07255 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 19 Feb 2024 17:19:23 +0100 Subject: [PATCH 6/6] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(imu):=20Break=20setDa?= =?UTF-8?q?taReadyInterrupt=20in=20multiple=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drivers/CoreIMU/include/CoreIMU.hpp | 5 ++- drivers/CoreIMU/source/CoreIMU.cpp | 46 ++++++++++++++++++-------- drivers/CoreIMU/tests/CoreIMU_test.cpp | 16 +++++++++ include/interface/drivers/IMU.hpp | 9 +++-- tests/unit/mocks/mocks/leka/IMU.h | 2 ++ 5 files changed, 61 insertions(+), 17 deletions(-) diff --git a/drivers/CoreIMU/include/CoreIMU.hpp b/drivers/CoreIMU/include/CoreIMU.hpp index a6d8601990..457ad8aa1b 100644 --- a/drivers/CoreIMU/include/CoreIMU.hpp +++ b/drivers/CoreIMU/include/CoreIMU.hpp @@ -23,6 +23,8 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled void init() final; void registerOnDataReadyCallback(data_ready_callback_t const &callback) final; + void enableOnDataReadyInterrupt() final; + void disableOnDataReadyInterrupt() final; void setPowerMode(PowerMode mode) final; @@ -39,7 +41,8 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled uint16_t number_bytes_to_read) -> int32_t; void onDataReadyHandler(auto timestamp); - void setDataReadyInterrupt(); + + void setDataReadyInterruptCallback(std::function const &callback); interface::I2C &_i2c; CoreEventQueue _event_queue {}; diff --git a/drivers/CoreIMU/source/CoreIMU.cpp b/drivers/CoreIMU/source/CoreIMU.cpp index d351696ef1..46e03c6874 100644 --- a/drivers/CoreIMU/source/CoreIMU.cpp +++ b/drivers/CoreIMU/source/CoreIMU.cpp @@ -33,7 +33,7 @@ void CoreIMU::init() lsm6dsox_dataready_pulsed_t data_ready_pulsed {LSM6DSOX_DRDY_PULSED}; lsm6dsox_data_ready_mode_set(&_register_io_function, data_ready_pulsed); - setDataReadyInterrupt(); + enableOnDataReadyInterrupt(); } void CoreIMU::setPowerMode(PowerMode mode) @@ -100,6 +100,33 @@ void CoreIMU::onDataReadyHandler(auto timestamp) } } +void CoreIMU::enableOnDataReadyInterrupt() +{ + lsm6dsox_pin_int1_route_t lsm6dsox_int1 { + .drdy_xl = PROPERTY_ENABLE, + .den_flag = PROPERTY_ENABLE, + }; + lsm6dsox_pin_int1_route_set(&_register_io_function, lsm6dsox_int1); + + auto on_data_ready_callback = [this] { + auto timestamp = rtos::Kernel::Clock::now(); + _event_queue.call([this, timestamp] { onDataReadyHandler(timestamp); }); + }; + + setDataReadyInterruptCallback(on_data_ready_callback); +} + +void CoreIMU::disableOnDataReadyInterrupt() +{ + lsm6dsox_pin_int1_route_t lsm6dsox_int1 { + .drdy_xl = PROPERTY_DISABLE, + .den_flag = PROPERTY_DISABLE, + }; + lsm6dsox_pin_int1_route_set(&_register_io_function, lsm6dsox_int1); + + setDataReadyInterruptCallback({}); +} + void CoreIMU::enableDeepSleep() { setPowerMode(interface::IMU::PowerMode::Off); @@ -146,20 +173,11 @@ auto CoreIMU::ptr_io_read(CoreIMU *handle, uint8_t read_address, uint8_t *p_buff return handle->read(read_address, number_bytes_to_read, p_buffer); } -void CoreIMU::setDataReadyInterrupt() +void CoreIMU::setDataReadyInterruptCallback(std::function const &callback) { - lsm6dsox_pin_int1_route_t lsm6dsox_int1 { - .drdy_xl = PROPERTY_ENABLE, - .den_flag = PROPERTY_ENABLE, - }; - lsm6dsox_pin_int1_route_set(&_register_io_function, lsm6dsox_int1); - - auto data_ready_callback = [this] { - auto timestamp = rtos::Kernel::Clock::now(); - _event_queue.call([this, timestamp] { onDataReadyHandler(timestamp); }); - }; - - _irq.onRise(data_ready_callback); + if (callback) { + _irq.onRise(callback); + } } } // namespace leka diff --git a/drivers/CoreIMU/tests/CoreIMU_test.cpp b/drivers/CoreIMU/tests/CoreIMU_test.cpp index 3b1fe2da11..fd41505380 100644 --- a/drivers/CoreIMU/tests/CoreIMU_test.cpp +++ b/drivers/CoreIMU/tests/CoreIMU_test.cpp @@ -87,6 +87,22 @@ TEST_F(CoreIMUTest, emptyOnDataReadyCallback) on_rise_callback(); } +TEST_F(CoreIMUTest, enableOnDataReadyInterrupt) +{ + EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); + EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); + + coreimu.enableOnDataReadyInterrupt(); +} + +TEST_F(CoreIMUTest, disableOnDataReadyInterrupt) +{ + EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); + EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); + + coreimu.disableOnDataReadyInterrupt(); +} + TEST_F(CoreIMUTest, enableDeepSleep) { EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); diff --git a/include/interface/drivers/IMU.hpp b/include/interface/drivers/IMU.hpp index 009c6069bd..74ac00f5e3 100644 --- a/include/interface/drivers/IMU.hpp +++ b/include/interface/drivers/IMU.hpp @@ -47,8 +47,13 @@ class IMU using data_ready_callback_t = std::function; - virtual void init() = 0; + virtual void init() = 0; + virtual void registerOnDataReadyCallback(data_ready_callback_t const &callback) = 0; - virtual void setPowerMode(PowerMode) = 0; + + virtual void enableOnDataReadyInterrupt() = 0; + virtual void disableOnDataReadyInterrupt() = 0; + + virtual void setPowerMode(PowerMode) = 0; }; } // namespace leka::interface diff --git a/tests/unit/mocks/mocks/leka/IMU.h b/tests/unit/mocks/mocks/leka/IMU.h index 6f8218228d..0eefe4b80e 100644 --- a/tests/unit/mocks/mocks/leka/IMU.h +++ b/tests/unit/mocks/mocks/leka/IMU.h @@ -16,6 +16,8 @@ class IMU : public interface::IMU MOCK_METHOD(void, setPowerMode, (PowerMode), (override)); void registerOnDataReadyCallback(data_ready_callback_t const &cb) override { data_ready_callback = cb; } + MOCK_METHOD(void, enableOnDataReadyInterrupt, (), (override)); + MOCK_METHOD(void, disableOnDataReadyInterrupt, (), (override)); void call_data_ready_callback(const SensorData &data) { data_ready_callback(data); }