diff --git a/drivers/CoreIMU/source/CoreIMU.cpp b/drivers/CoreIMU/source/CoreIMU.cpp index 4966482e7..4190f4377 100644 --- a/drivers/CoreIMU/source/CoreIMU.cpp +++ b/drivers/CoreIMU/source/CoreIMU.cpp @@ -144,18 +144,21 @@ void CoreIMU::registerOnWakeUpCallback(std::function const &callback) void CoreIMU::enableOnWakeUpInterrupt() { + // ODR = 52Hz for reference + // ? Set filter and disable user offset lsm6dsox_xl_hp_path_internal_set(&_register_io_function, LSM6DSOX_USE_SLOPE); lsm6dsox_xl_usr_offset_on_wkup_set(&_register_io_function, 0); // ? Set Wakeup config - lsm6dsox_wkup_threshold_set(&_register_io_function, 2); - lsm6dsox_wkup_ths_weight_set(&_register_io_function, LSM6DSOX_LSb_FS_DIV_64); - lsm6dsox_wkup_dur_set(&_register_io_function, 0x02); + lsm6dsox_wkup_threshold_set(&_register_io_function, 3); // LSB multiplier / Max: 31 + lsm6dsox_wkup_ths_weight_set(&_register_io_function, + LSM6DSOX_LSb_FS_DIV_64); // 2 Weights, 1 LSB = FS_XL/2^x x:{6,8} + lsm6dsox_wkup_dur_set(&_register_io_function, 1); // 1 LSB = 1*ODR_time / Max: 3 // ? Set Activity config - lsm6dsox_act_sleep_dur_set(&_register_io_function, 0x02); - lsm6dsox_act_mode_set(&_register_io_function, LSM6DSOX_XL_AND_GY_NOT_AFFECTED); + lsm6dsox_act_sleep_dur_set(&_register_io_function, 0); // 1 LSB = 512*ODR / Max: 15 + lsm6dsox_act_mode_set(&_register_io_function, LSM6DSOX_XL_12Hz5_GY_PD); // 4 Modes lsm6dsox_pin_int1_route_t lsm6dsox_int1 { .sleep_change = PROPERTY_ENABLE, diff --git a/spikes/CMakeLists.txt b/spikes/CMakeLists.txt index e2deb2c4b..8dff76157 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 000000000..c99ee2c81 --- /dev/null +++ b/spikes/lk_sensors_imu_wakeup_calibration/CMakeLists.txt @@ -0,0 +1,23 @@ +# Leka - LekaOS +# Copyright 2024 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 + CoreLED +) + +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 000000000..ef9cb07c3 --- /dev/null +++ b/spikes/lk_sensors_imu_wakeup_calibration/main.cpp @@ -0,0 +1,101 @@ +// Leka - LekaOS +// Copyright 2024 APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "rtos/ThisThread.h" + +#include "CoreI2C.h" +#include "CoreIMU.hpp" +#include "CoreLED.h" +#include "CoreSPI.h" +#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 leds { + + namespace internal { + + namespace ears { + + auto spi = CoreSPI {LED_EARS_SPI_MOSI, NC, LED_EARS_SPI_SCK}; + constexpr auto size = 2; + + } // namespace ears + + namespace belt { + + auto spi = CoreSPI {LED_BELT_SPI_MOSI, NC, LED_BELT_SPI_SCK}; + constexpr auto size = 20; + + } // namespace belt + + } // namespace internal + + auto ears = CoreLED {internal::ears::spi}; + auto belt = CoreLED {internal::belt::spi}; + +} // namespace leds + +} // namespace + +void setColor(RGB color) +{ + leds::ears.setColor(color); + leds::belt.setColor(color); + + leds::ears.show(); + leds::belt.show(); +} + +void turnOff() +{ + setColor(RGB::black); +} + +void wakeUpReaction() +{ + setColor(RGB::pure_blue); + rtos::ThisThread::sleep_for(2s); + turnOff(); +} + +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 = [] { wakeUpReaction(); }; + + imu::coreimu.enableOnWakeUpInterrupt(callback); + + while (true) { + rtos::ThisThread::sleep_for(10min); + } +}