32#include "../../../SensorBuildOpt.h"
33#if !SENSORLIB_EXCLUDE_QMI8658
36#include "../../ImuBase.hpp"
37#include "../../../platform/comm/ComplexDeviceWithHal.hpp"
39static constexpr uint8_t QMI8658_L_SLAVE_ADDRESS = 0x6B;
40static constexpr uint8_t QMI8658_H_SLAVE_ADDRESS = 0x6A;
234 bool reset()
override;
380 bool readGyroRaw(int16_t &
x, int16_t &
y, int16_t &z)
override;
400 bool configureFifo(
bool enable, uint8_t watermark_samples = 16)
override;
493 uint8_t watermark_samples = 16);
530 bool calibrate(uint16_t *gyro_x_gain =
nullptr, uint16_t *gyro_y_gain =
nullptr,
531 uint16_t *gyro_z_gain =
nullptr);
540 bool writeCalibration(uint16_t gyro_x_gain, uint16_t gyro_y_gain, uint16_t gyro_z_gain);
584 float threshold_z, uint8_t duration);
618 IntPin pin = IntPin::PIN2);
631 uint8_t default_pin_value, uint8_t blanking_time,
642 uint8_t default_pin_value, uint8_t blanking_time,
658 uint16_t double_tap_window,
float peak_mag_threshold,
float quiet_threshold);
701 bool configPedometer(uint16_t sample_count, uint16_t peak_to_peak, uint16_t peak_threshold,
702 uint16_t time_up, uint8_t time_low = 20, uint8_t entry_count = 10,
703 uint8_t fix_precision = 0, uint8_t sig_count = 4);
860 void axisConvert(int16_t accel_data[3], int16_t gyro_data[3]);
953 bool initImpl(uint8_t param)
override;
OperationMode
Enumeration of sensor operation modes.
GyroFullScaleRange
Enumeration of gyroscope full-scale range settings.
AccelFullScaleRange
Enumeration of accelerometer full-scale range settings.
InterruptPinMap
Enumeration of interrupt pin mapping options.
Abstract IMU device interface for polymorphic IMU sensor implementations.
QMI8658 IMU sensor driver class.
bool configGyro(GyroFullScaleRange range, float data_rate_hz, LpfMode lpf=LpfMode::MODE_0)
Configure the gyroscope with specified parameters.
GyroODR
Gyroscope output data rate enumeration.
static constexpr uint8_t DYN_CAL_BUFFER_SIZE
bool reset() override
Reset the IMU sensor to its default state.
bool _motion_any_configured
bool resetFifo()
Reset the FIFO.
static constexpr uint8_t STATUS_TAP_EVENT
bool configPedometer(uint16_t sample_count, uint16_t peak_to_peak, uint16_t peak_threshold, uint16_t time_up, uint8_t time_low=20, uint8_t entry_count=10, uint8_t fix_precision=0, uint8_t sig_count=4)
Configure pedometer parameters.
uint16_t _static_cali_sample_count
float _accel_speed_buffer[DYN_CAL_BUFFER_SIZE]
bool readGyro(GyroscopeData &out) override
Read gyroscope data.
uint32_t _last_tap_event_ms
bool _static_cali_enabled
void setAccelOffset(int16_t x, int16_t y, int16_t z)
Set accelerometer host delta offsets.
float _hw_st_accel_result[3]
bool _static_cali_complete
float _gyro_static_deviation
bool setOperationMode(OperationMode mode) override
Set IMU operation mode.
bool disableTap()
Disable tap detection.
bool readGyroRaw(int16_t &x, int16_t &y, int16_t &z) override
Read raw gyroscope data without scaling.
float getTemperature() override
Get the temperature reading from the sensor.
uint8_t getInterruptStatus()
Get interrupt status.
static constexpr uint8_t STATUS_WOM_EVENT
float getGyroScaleFromRange(GyroFullScaleRange range)
void getStaticCalibrationOffsets(int16_t accel_offset[3], int16_t gyro_offset[3])
Get static calibration offsets.
int16_t _dyn_gyro_offset[3]
void setSignificantMotionCallback(MotionCallback callback)
Set callback for significant motion event.
bool isGyroEnabled() override
Check if gyroscope is enabled.
bool isDataReady(uint8_t mask=static_cast< uint8_t >(ImuBase::DataReadyMask::BOTH)) override
Check if requested IMU data is available.
uint8_t findClosestAccelLpOdr(float hz)
bool configMotionDetectDefault(MotionType type)
Configure motion detection with default parameters.
static constexpr uint16_t MAX_STATIC_CALI_SAMPLES
uint16_t _motion_sig_wait_window
uint32_t getStepCount()
Get pedometer step count.
int16_t _accel_cali_offset[3]
bool disableMotionDetect()
Disable motion detection.
int writeCommand(uint8_t cmd, uint32_t timeout_ms=1000)
int32_t _accel_cali_sum[3]
bool setAccelOutputDataRate(float data_rate_hz) override
Set accelerometer output data rate.
void setDataLockingCallback(DataReadyCallback callback)
Set callback for data locking.
std::function< void(TapEvent event)> TapCallback
Callback function type for tap events.
uint8_t getAccelRangeRegValue(AccelFullScaleRange range)
bool enableAccel() override
Enable the accelerometer.
static constexpr uint8_t STATUS_SIGNIFICANT_MOTION
GyroFullScaleRange _gyro_range
static constexpr float HW_ST_ACCEL_THRESHOLD_MG
bool configFifo(FifoMode mode, FifoSamples samples=FifoSamples::SAMPLES_16, uint8_t watermark_samples=16)
Configure FIFO with specified mode.
bool isStaticCalibrationComplete() const
Get the current static calibration status.
bool processStaticCalibration(int16_t accel_data[3], int16_t gyro_data[3])
Process static calibration with current sensor data.
float getAccelScale()
Get the accelerometer scale factor.
uint8_t _dyn_cali_sample_count
uint8_t _motion_no_thr[3]
void resetStaticCalibration()
Reset static calibration.
uint8_t getChipID() override
Get the chip ID / WHO_AM_I value.
bool disableSyncMode() override
Disable synchronous sampling mode.
bool _motion_no_configured
bool enableSyncMode() override
Enable synchronous sampling mode.
void setIntPin(int pin)
Backward-compatible alias of setPins.
float odrToFloat(float odr)
float _hw_st_gyro_result[3]
AccelODR
Accelerometer output data rate enumeration.
@ ODR_LP_21Hz
Low power 21 Hz.
@ ODR_LP_11Hz
Low power 11 Hz.
@ ODR_LP_128Hz
Low power 128 Hz.
@ ODR_LP_3Hz
Low power 3 Hz.
bool disableLockingMechanism()
Disable the data locking mechanism.
uint32_t _dyn_static_delay
bool disableAccel() override
Disable the accelerometer.
bool selfTestGyro()
Perform gyroscope self-test.
void processDynamicCalibration(int16_t accel_data[3], int16_t gyro_data[3])
Process dynamic calibration with current sensor data.
bool enableInterrupt(IntPin pin)
Enable interrupt on specified pin.
void enableStaticCalibration(bool enable)
Start static calibration.
bool readAccel(AccelerometerData &out) override
Read accelerometer data.
void getDynamicGyroCalibrationOffsets(int16_t gyro_offset[3])
Get dynamic gyroscope calibration offsets.
uint8_t findClosestAccelOdr(float hz)
bool enablePedometer(IntPin pin=IntPin::DISABLE)
Enable pedometer.
FifoMode
FIFO mode enumeration.
@ STREAM
Stream mode (overwrites oldest)
@ BYPASS
Bypass mode (FIFO disabled)
@ FIFO
FIFO mode (stops when full)
void setTapCallback(TapCallback callback)
Set callback for tap event.
uint16_t _fifo_buffer_size
bool enableGyro() override
Enable the gyroscope.
bool configTap(TapPriority priority, uint8_t peak_window, uint16_t tap_window, uint16_t double_tap_window, float peak_mag_threshold, float quiet_threshold)
Configure tap detection parameters.
bool disableGyro() override
Disable the gyroscope.
~SensorQMI8658() override
Destroy the SensorQMI8658 object.
uint16_t readFromFifo(AccelerometerData *accel_data, uint16_t accel_count, GyroscopeData *gyro_data, uint16_t gyro_count) override
Read data from FIFO buffer.
bool enableDataReadyInterrupt(IntPin pin=IntPin::PIN2)
Enable data ready interrupt.
bool enableLockingMechanism()
Enable the data locking mechanism.
uint32_t getFirmwareVersion() override
Get the firmware version.
void setNoMotionCallback(MotionCallback callback)
Set callback for no-motion event.
static constexpr float HW_ST_GYRO_THRESHOLD_DPS
TapEvent getTapStatus()
Get tap status.
static constexpr uint8_t STATUS_ANY_MOTION_EVENT
uint8_t _dyn_offset_applied
bool isPresent() override
Check if the IMU sensor is responding.
uint8_t getGyroRangeRegValue(GyroFullScaleRange range)
GyroRange
Gyroscope full-scale range enumeration.
@ FS_128DPS
±128 degrees per second
@ FS_512DPS
±512 degrees per second
@ FS_32DPS
±32 degrees per second
@ FS_2048DPS
±2048 degrees per second
@ FS_1024DPS
±1024 degrees per second
@ FS_256DPS
±256 degrees per second
@ FS_64DPS
±64 degrees per second
@ FS_16DPS
±16 degrees per second
bool isAccelEnabled() override
Check if accelerometer is enabled.
bool configureFifo(bool enable, uint8_t watermark_samples=16) override
Configure the FIFO buffer.
EventCallbacks & getCallbacks()
Get current callbacks.
void enableDynamicGyroCalibration(bool enable)
Enable dynamic gyroscope calibration.
Layout getAxisLayout() const
Get the current axis layout setting.
int32_t _gyro_cali_sum[3]
float _gyro_speed_buffer[DYN_CAL_BUFFER_SIZE]
SensorQMI8658()
Construct a new SensorQMI8658 object.
bool enableTap(IntPin pin=IntPin::PIN1)
Enable tap detection.
void setGyroOffset(int16_t x, int16_t y, int16_t z)
Set gyroscope host delta offsets.
float getAccelScaleFromRange(AccelFullScaleRange range)
LpfMode
Low-pass filter mode enumeration.
@ MODE_0
2.66% of output data rate
@ OFF
Disable low-pass filter.
@ MODE_3
13.37% of output data rate
@ MODE_2
5.39% of output data rate
@ MODE_1
3.63% of output data rate
AccelRange
Accelerometer full-scale range enumeration.
bool enableMotionDetect(IntPin pin=IntPin::PIN1)
Enable motion detection on specified pin.
bool _motion_sig_configured
uint8_t findClosestGyroOdr(float hz)
bool initImpl(uint8_t param) override
bool isDynamicGyroCalibrationEnabled() const
Check if dynamic gyro calibration is enabled.
bool setGyroFullScaleRange(GyroFullScaleRange range) override
Set gyroscope full scale range.
MotionType
Motion detection type enumeration.
@ ANY_MOTION
Any motion detection.
@ NO_MOTION
No motion detection.
@ SIGNIFICANT
Significant motion detection.
bool setGyroOutputDataRate(float data_rate_hz) override
Set gyroscope output data rate.
AccelFullScaleRange _accel_range
uint8_t _motion_any_thr[3]
void setAccelDataReadyCallback(DataReadyCallback callback)
Set callback for accelerometer data ready.
void setPedometerCallback(MotionCallback callback)
Set callback for pedometer event.
std::function< void()> DataReadyCallback
Callback function type for data ready events.
int16_t _gyro_cali_offset[3]
uint8_t _motion_any_window
bool selfTest() override
Perform self-test on the IMU sensor.
void setAnyMotionCallback(MotionCallback callback)
Set callback for any-motion event.
void dumpRegisters()
Dump control registers for debugging.
bool resetStepCount()
Reset pedometer counter.
bool configAccel(AccelFullScaleRange range, float data_rate_hz, LpfMode lpf=LpfMode::MODE_0)
Configure the accelerometer with specified parameters.
uint16_t update()
Update sensor status and process events.
float getGyroScale()
Get the gyroscope scale factor.
void getHardwareSelfTestResults(float accel_result[3], float gyro_result[3])
Get hardware self-test results.
static constexpr uint8_t STATUS_PEDOMETER_EVENT
bool configTapDefault(TapPriority priority=TapPriority::X_GT_Y_GT_Z)
Configure tap detection with default parameters.
bool readAccelRaw(int16_t &x, int16_t &y, int16_t &z) override
Read raw accelerometer data without scaling.
uint8_t getFifoStatus()
Get FIFO status.
uint32_t getTimestamp() override
Get the timestamp from the sensor.
std::function< void()> MotionCallback
Callback function type for motion events.
bool setAccelFullScaleRange(AccelFullScaleRange range) override
Set accelerometer full scale range.
void setCallbacks(const EventCallbacks &cbs)
Set all event callbacks at once.
void setPins(int pin)
Set interrupt pin.
bool configWakeOnMotion(uint8_t threshold=200, float odr_hz=128.0f, IntPin pin=IntPin::PIN2)
Configure wake-on-motion (WoM) feature.
bool configPedometerDefault(float odr=125.0f)
Configure pedometer with default parameters.
uint8_t _motion_no_window
bool disablePedometer()
Disable pedometer.
void setGyroDataReadyCallback(DataReadyCallback callback)
Set callback for gyroscope data ready.
bool hardwareSelfTest(bool includeAccel=true, bool includeGyro=true)
Perform hardware self-test on both sensors.
TapPriority
Tap detection axis priority enumeration.
void setAxisLayout(Layout layout)
Set the sensor axis layout for coordinate transformation.
uint16_t _motion_sig_confirm_window
bool configWakeOnMotionAdvanced(uint8_t threshold, float odr_hz, IntPin pin, uint8_t default_pin_value, uint8_t blanking_time, AccelFullScaleRange acc_range)
Configure wake-on-motion (WoM) with full vendor parameters.
bool isStaticCalibrationEnabled() const
Check if static calibration is enabled.
void setWakeOnMotionCallback(MotionCallback callback)
Set callback for wake-on-motion event.
void axisConvert(int16_t accel_data[3], int16_t gyro_data[3])
Apply axis conversion to raw sensor data.
bool selfTestAccel()
Perform accelerometer self-test.
static constexpr uint8_t STATUS_NO_MOTION_EVENT
static constexpr uint8_t DYN_CAL_STATIC_COUNT
bool writeCalibration(uint16_t gyro_x_gain, uint16_t gyro_y_gain, uint16_t gyro_z_gain)
Write previously saved gyro calibration gains.
uint32_t _last_step_count
void getChipUsid(uint8_t *buffer, uint8_t length)
Get sensor USID (unique chip ID).
Layout
Sensor axis layout enumeration for coordinate transformation.
@ LAYOUT_ROTATE_90
Rotated 90 degrees: X=forward, Y=left, Z=up.
@ LAYOUT_FLIP_Z
Flipped: X=right, Y=backward, Z=down.
@ LAYOUT_FLIP_Z_90
Flipped + 90: X=backward, Y=left, Z=down.
@ LAYOUT_FLIP_Z_180
Flipped + 180: X=left, Y=forward, Z=down.
@ LAYOUT_ROTATE_270
Rotated 270 degrees: X=backward, Y=right, Z=up.
@ LAYOUT_ROTATE_180
Rotated 180 degrees: X=left, Y=backward, Z=up.
@ LAYOUT_DEFAULT
Default orientation: X=right, Y=forward, Z=up.
@ LAYOUT_FLIP_Z_270
Flipped + 270: X=forward, Y=right, Z=down.
uint32_t _firmware_version
FifoSamples
FIFO sample count enumeration.
bool configMotionDetect(MotionType type, float threshold_x, float threshold_y, float threshold_z, uint8_t duration)
Configure motion detection parameters.
float _accel_static_deviation
bool disableInterrupt(IntPin pin)
Disable interrupt on specified pin.
uint8_t mgToBytes(float mg)
constexpr uint32_t _bv(uint8_t b)
Structure representing accelerometer data.
Structure representing gyroscope data.
Grouped callbacks for QMI8658 events.
MotionCallback onAnyMotion
DataReadyCallback onAccelDataReady
MotionCallback onSignificantMotion
MotionCallback onNoMotion
DataReadyCallback onGyroDataReady
MotionCallback onPedometer
DataReadyCallback onDataLocking
MotionCallback onWakeOnMotion