From b54d52e5722352c203d8ec724555f5dbaff68dac Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Tue, 20 Feb 2024 11:47:25 +0100 Subject: [PATCH] :sparkles: (imu): Add basic spike for imu --- spikes/CMakeLists.txt | 2 + .../CMakeLists.txt | 22 ++++++++ .../main.cpp | 54 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 spikes/lk_sensors_imu_wakeup_calibration/CMakeLists.txt create mode 100644 spikes/lk_sensors_imu_wakeup_calibration/main.cpp diff --git a/spikes/CMakeLists.txt b/spikes/CMakeLists.txt index e2deb2c4b9..8dff76157f 100644 --- a/spikes/CMakeLists.txt +++ b/spikes/CMakeLists.txt @@ -30,6 +30,7 @@ add_subdirectory(${SPIKES_DIR}/lk_rfid) add_subdirectory(${SPIKES_DIR}/lk_sensors_battery) add_subdirectory(${SPIKES_DIR}/lk_sensors_imu) add_subdirectory(${SPIKES_DIR}/lk_sensors_imu_fusion_calibration) +add_subdirectory(${SPIKES_DIR}/lk_sensors_imu_wakeup_calibration) add_subdirectory(${SPIKES_DIR}/lk_sensors_light) add_subdirectory(${SPIKES_DIR}/lk_sensors_microphone) add_subdirectory(${SPIKES_DIR}/lk_sensors_temperature_humidity) @@ -73,6 +74,7 @@ add_dependencies(spikes_leka spike_lk_sensors_battery spike_lk_sensors_imu spike_lk_sensors_imu_fusion_calibration + spike_lk_sensors_imu_wakeup_calibration spike_lk_sensors_light spike_lk_sensors_microphone spike_lk_sensors_temperature_humidity diff --git a/spikes/lk_sensors_imu_wakeup_calibration/CMakeLists.txt b/spikes/lk_sensors_imu_wakeup_calibration/CMakeLists.txt new file mode 100644 index 0000000000..785ac7296a --- /dev/null +++ b/spikes/lk_sensors_imu_wakeup_calibration/CMakeLists.txt @@ -0,0 +1,22 @@ +# Leka - LekaOS +# Copyright 2022 APF France handicap +# SPDX-License-Identifier: Apache-2.0 + +add_mbed_executable(spike_lk_sensors_imu_wakeup_calibration) + +target_include_directories(spike_lk_sensors_imu_wakeup_calibration + PRIVATE + . +) + +target_sources(spike_lk_sensors_imu_wakeup_calibration + PRIVATE + main.cpp +) + +target_link_libraries(spike_lk_sensors_imu_wakeup_calibration + CoreIMU + CoreI2C +) + +target_link_custom_leka_targets(spike_lk_sensors_imu_wakeup_calibration) diff --git a/spikes/lk_sensors_imu_wakeup_calibration/main.cpp b/spikes/lk_sensors_imu_wakeup_calibration/main.cpp new file mode 100644 index 0000000000..522fd0158a --- /dev/null +++ b/spikes/lk_sensors_imu_wakeup_calibration/main.cpp @@ -0,0 +1,54 @@ +// Leka - LekaOS +// Copyright 2022 APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "rtos/ThisThread.h" + +#include "CoreI2C.h" +#include "CoreIMU.hpp" +#include "HelloWorld.h" +#include "LogKit.h" + +using namespace std::chrono; +using namespace leka; + +namespace { + +namespace imu { + + namespace internal { + + 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::irq); + +} // namespace imu + +} // namespace + +auto main() -> int +{ + logger::init(); + + log_info("Hello, World!\n\n"); + + HelloWorld hello; + hello.start(); + + imu::coreimu.init(); + imu::coreimu.setPowerMode(CoreIMU::PowerMode::Normal); + + auto callback = [] {}; + + imu::coreimu.registerOnWakeUpCallback(callback); + imu::coreimu.enableOnWakeUpInterrupt(); + + while (true) { + rtos::ThisThread::sleep_for(10min); + } +}