mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-24 16:01:53 +08:00
feat(drivers/imu): add ICM-56686 driver and enable it on GA1 (#28677)
feat(drivers/imu): add ICM-56686 driver and enable GA1 alternate IMUs Add an InvenSense ICM-56686 SPI FIFO driver (WHO_AM_I 0x08, DEVTYPE 0x39, DS-000563 v1.1 register map, 6400 Hz FIFO). It publishes the 16-bit FIFO fields at full scale (as in #28134) and passes config.external to the publishers (as in #28352). GA1 (accton-godwit): - Each internal SPI socket can hold an ICM-42688P, ICM-45686, ICM-56686 or LSM6DSV32X/LSM6DSK320X. Probe them in an if/fi chain and stop at the first one found. SPI2 is probed first so the heater binds to the heated instance. - The LSM6DSV now uses the same rotation as the Invensense parts on each socket (-R 6 on SPI2, -R 14 on SPI1), following #27625. - The ICM-42688P and ICM-45686 on SPI2 are polled instead of using DRDY, because only INT2 is routed to the MCU there. This removes the missed-DRDY counts. - Drop six drivers that nothing starts at boot (BMP388, MS5611, BMM150, MMC5983MA, MCP23009, landing target estimator). Flash use: 98.67% -> 97.52%. Tested on GA1 hardware with a v1.17-based build: SPI2 polling and the driver cleanup. Not yet tested on hardware: the ICM-56686 decode change and the LSM6DSV rotation. Assisted-by: Grok:grok-4.6 Assisted-by: Kiro:claude-opus-5.5 Signed-off-by: g945643frankie <g945643@oz.nthu.edu.tw> Co-authored-by: Farhang <46557204+farhangnaderi@users.noreply.github.com>
This commit is contained in:
1 parent
cd0e647af5
commit
56ebfa63c8
10 files changed
+1539
-16
No files matched your search
@@ -9,10 +9,8 @@ CONFIG_BOARD_SERIAL_TEL3="/dev/ttyS1"
|
||||
CONFIG_BOARD_SERIAL_EXT2="/dev/ttyS3"
|
||||
CONFIG_DRIVERS_ADC_ADS1115=y
|
||||
CONFIG_DRIVERS_ADC_BOARD_ADC=y
|
||||
CONFIG_DRIVERS_BAROMETER_BMP388=y
|
||||
CONFIG_DRIVERS_BAROMETER_DPS310=y
|
||||
CONFIG_DRIVERS_BAROMETER_INVENSENSE_ICP201XX=y
|
||||
CONFIG_DRIVERS_BAROMETER_MS5611=y
|
||||
CONFIG_DRIVERS_CAMERA_CAPTURE=y
|
||||
CONFIG_DRIVERS_CAMERA_TRIGGER=y
|
||||
CONFIG_DRIVERS_CDCACM_AUTOSTART=y
|
||||
@@ -20,17 +18,16 @@ CONFIG_COMMON_DIFFERENTIAL_PRESSURE=y
|
||||
CONFIG_COMMON_DISTANCE_SENSOR=y
|
||||
CONFIG_DRIVERS_DSHOT=y
|
||||
CONFIG_DRIVERS_GNSS_SEPTENTRIO=y
|
||||
CONFIG_DRIVERS_GPIO_MCP23009=y
|
||||
CONFIG_DRIVERS_GPS=y
|
||||
CONFIG_DRIVERS_HEATER=y
|
||||
CONFIG_DRIVERS_IMU_BOSCH_BMI088=y
|
||||
CONFIG_DRIVERS_IMU_INVENSENSE_ICM42688P=y
|
||||
CONFIG_DRIVERS_IMU_INVENSENSE_ICM45686=y
|
||||
CONFIG_DRIVERS_IMU_INVENSENSE_ICM56686=y
|
||||
CONFIG_DRIVERS_IMU_ST_LSM6DSV=y
|
||||
CONFIG_COMMON_LIGHT=y
|
||||
CONFIG_DRIVERS_MAGNETOMETER_BOSCH_BMM150=y
|
||||
CONFIG_DRIVERS_MAGNETOMETER_ISENTEK_IST8308=y
|
||||
CONFIG_DRIVERS_MAGNETOMETER_ISENTEK_IST8310=y
|
||||
CONFIG_DRIVERS_MAGNETOMETER_MEMSIC_MMC5983MA=y
|
||||
CONFIG_DRIVERS_MAGNETOMETER_RM3100=y
|
||||
CONFIG_DRIVERS_OSD_MSP_OSD=y
|
||||
CONFIG_DRIVERS_POWER_MONITOR_INA226=y
|
||||
@@ -62,7 +59,6 @@ CONFIG_MODULES_GIMBAL=y
|
||||
CONFIG_MODULES_GYRO_CALIBRATION=y
|
||||
CONFIG_MODULES_HARDFAULT_STREAM=y
|
||||
CONFIG_MODULES_LAND_DETECTOR=y
|
||||
CONFIG_MODULES_LANDING_TARGET_ESTIMATOR=y
|
||||
CONFIG_MODULES_LOAD_MON=y
|
||||
CONFIG_MODULES_LOGGER=y
|
||||
CONFIG_MODULES_MAG_BIAS_ESTIMATOR=y
|
||||
|
||||
@@ -65,18 +65,38 @@ then
|
||||
fi
|
||||
fi
|
||||
|
||||
# Internal SPI IMUs: each socket carries one of ICM-42688P, ICM-45686,
|
||||
# ICM-56686 or LSM6DSV, so start the first one that probes.
|
||||
# SPI2 (heated socket) goes first so it is the heater's sensor_accel instance 0.
|
||||
|
||||
# SPI2 socket (ICM-56686 data ready is on INT2)
|
||||
if ! icm42688p -R 6 -s -b 2 -q start
|
||||
then
|
||||
if ! icm45686 -R 6 -s -b 2 -q start
|
||||
then
|
||||
if ! icm56686 -2 -R 6 -s -b 2 -q start
|
||||
then
|
||||
lsm6dsv -R 6 -s -b 2 start
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# SPI1 socket
|
||||
if ! icm42688p -R 14 -s -b 1 -q start
|
||||
then
|
||||
if ! icm45686 -R 14 -s -b 1 -q start
|
||||
then
|
||||
if ! icm56686 -R 14 -s -b 1 -q start
|
||||
then
|
||||
lsm6dsv -R 14 -s -b 1 start
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Internal SPI BMI088
|
||||
bmi088 -A -R 4 -s start
|
||||
bmi088 -G -R 4 -s start
|
||||
|
||||
# Internal SPI bus ICM42688p
|
||||
icm42688p -R 6 -s -b 2 start
|
||||
icm42688p -R 14 -s -b 1 start
|
||||
|
||||
# Internal SPI bus ICM45686
|
||||
icm45686 -R 6 -s -b 2 start
|
||||
icm45686 -R 14 -s -b 1 start
|
||||
|
||||
# Internal magnetometer on I2c
|
||||
rm3100 -I -b 4 start
|
||||
|
||||
|
||||
@@ -39,10 +39,17 @@ constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = {
|
||||
initSPIBus(SPI::Bus::SPI1, {
|
||||
initSPIDevice(DRV_IMU_DEVTYPE_ICM42688P, SPI::CS{GPIO::PortI, GPIO::Pin9}, SPI::DRDY{GPIO::PortF, GPIO::Pin2}),
|
||||
initSPIDevice(DRV_IMU_DEVTYPE_ICM45686, SPI::CS{GPIO::PortI, GPIO::Pin9}, SPI::DRDY{GPIO::PortF, GPIO::Pin2}),
|
||||
initSPIDevice(DRV_IMU_DEVTYPE_ICM56686, SPI::CS{GPIO::PortI, GPIO::Pin9}, SPI::DRDY{GPIO::PortF, GPIO::Pin2}),
|
||||
// LSM6DSV: polled, INT1 mapping unconfirmed
|
||||
initSPIDevice(DRV_IMU_DEVTYPE_ST_LSM6DSV, SPI::CS{GPIO::PortI, GPIO::Pin9}),
|
||||
}, {GPIO::PortI, GPIO::Pin11}),
|
||||
initSPIBus(SPI::Bus::SPI2, {
|
||||
initSPIDevice(DRV_IMU_DEVTYPE_ICM42688P, SPI::CS{GPIO::PortH, GPIO::Pin5}, SPI::DRDY{GPIO::PortA, GPIO::Pin10}),
|
||||
initSPIDevice(DRV_IMU_DEVTYPE_ICM45686, SPI::CS{GPIO::PortH, GPIO::Pin5}, SPI::DRDY{GPIO::PortA, GPIO::Pin10}),
|
||||
// Only INT2 reaches the MCU (PA10), so the INT1-only drivers are polled
|
||||
initSPIDevice(DRV_IMU_DEVTYPE_ICM42688P, SPI::CS{GPIO::PortH, GPIO::Pin5}),
|
||||
initSPIDevice(DRV_IMU_DEVTYPE_ICM45686, SPI::CS{GPIO::PortH, GPIO::Pin5}),
|
||||
// icm56686 is started with -2 (INT2)
|
||||
initSPIDevice(DRV_IMU_DEVTYPE_ICM56686, SPI::CS{GPIO::PortH, GPIO::Pin5}, SPI::DRDY{GPIO::PortA, GPIO::Pin10}),
|
||||
initSPIDevice(DRV_IMU_DEVTYPE_ST_LSM6DSV, SPI::CS{GPIO::PortH, GPIO::Pin5}),
|
||||
}, {GPIO::PortF, GPIO::Pin4}),
|
||||
initSPIBus(SPI::Bus::SPI3, {
|
||||
initSPIDevice(DRV_GYR_DEVTYPE_BMI088, SPI::CS{GPIO::PortI, GPIO::Pin8}, SPI::DRDY{GPIO::PortI, GPIO::Pin7}),
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
#define DRV_IMU_DEVTYPE_MPU6500 0x36
|
||||
#define DRV_IMU_DEVTYPE_BMI270 0x37
|
||||
#define DRV_IMU_DEVTYPE_ICM20602 0x38
|
||||
#define DRV_IMU_DEVTYPE_ICM56686 0x39
|
||||
|
||||
#define DRV_IMU_DEVTYPE_ICM20608G 0x3A
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2026 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name PX4 nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
px4_add_module(
|
||||
MODULE drivers__imu__invensense__icm56686
|
||||
MAIN icm56686
|
||||
COMPILE_FLAGS
|
||||
${MAX_CUSTOM_OPT_LEVEL}
|
||||
#-DDEBUG_BUILD
|
||||
SRCS
|
||||
icm56686_main.cpp
|
||||
ICM56686.cpp
|
||||
ICM56686.hpp
|
||||
InvenSense_ICM56686_registers.hpp
|
||||
DEPENDS
|
||||
px4_work_queue
|
||||
drivers_accelerometer
|
||||
drivers_gyroscope
|
||||
)
|
||||
@@ -0,0 +1,837 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2026 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "ICM56686.hpp"
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
static constexpr int16_t combine(const uint8_t high, const uint8_t low)
|
||||
{
|
||||
return static_cast<int16_t>((static_cast<uint16_t>(high) << 8) | low);
|
||||
}
|
||||
|
||||
static constexpr uint16_t combineUnsigned(const uint8_t high, const uint8_t low)
|
||||
{
|
||||
return (static_cast<uint16_t>(high) << 8) | low;
|
||||
}
|
||||
|
||||
ICM56686::ICM56686(const I2CSPIDriverConfig &config) :
|
||||
SPI(config),
|
||||
I2CSPIDriver(config),
|
||||
_drdy_gpio(config.drdy_gpio),
|
||||
_fifo_interrupt_config0(config.custom1 == 2 ? Register::BANK_0::INT2_CONFIG0 : Register::BANK_0::INT1_CONFIG0),
|
||||
_fifo_interrupt_config2(config.custom1 == 2 ? Register::BANK_0::INT2_CONFIG2 : Register::BANK_0::INT1_CONFIG2),
|
||||
_px4_accel(get_device_id(), config.rotation, config.external),
|
||||
_px4_gyro(get_device_id(), config.rotation, config.external)
|
||||
{
|
||||
if (_fifo_interrupt_config0 == Register::BANK_0::INT2_CONFIG0) {
|
||||
for (auto ®_cfg : _register_cfg) {
|
||||
if (reg_cfg.reg == Register::BANK_0::INT1_CONFIG0) {
|
||||
reg_cfg.reg = Register::BANK_0::INT2_CONFIG0;
|
||||
|
||||
} else if (reg_cfg.reg == Register::BANK_0::INT1_CONFIG2) {
|
||||
reg_cfg.reg = Register::BANK_0::INT2_CONFIG2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_drdy_gpio != 0) {
|
||||
_drdy_missed_perf = perf_alloc(PC_COUNT, MODULE_NAME": DRDY missed");
|
||||
|
||||
} else {
|
||||
for (auto ®_cfg : _register_cfg) {
|
||||
if (reg_cfg.reg == _fifo_interrupt_config0) {
|
||||
reg_cfg.value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigureSampleRate(_px4_gyro.get_max_rate_hz());
|
||||
}
|
||||
|
||||
ICM56686::~ICM56686()
|
||||
{
|
||||
DataReadyInterruptDisable();
|
||||
perf_free(_bad_register_perf);
|
||||
perf_free(_bad_transfer_perf);
|
||||
perf_free(_fifo_empty_perf);
|
||||
perf_free(_fifo_overflow_perf);
|
||||
perf_free(_fifo_reset_perf);
|
||||
perf_free(_drdy_missed_perf);
|
||||
}
|
||||
|
||||
int ICM56686::init()
|
||||
{
|
||||
const int ret = SPI::init();
|
||||
|
||||
if (ret != PX4_OK) {
|
||||
DEVICE_DEBUG("SPI::init failed (%i)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return Reset() ? PX4_OK : PX4_ERROR;
|
||||
}
|
||||
|
||||
bool ICM56686::Reset()
|
||||
{
|
||||
_state = STATE::RESET;
|
||||
ScheduleClear();
|
||||
ScheduleNow();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ICM56686::exit_and_cleanup()
|
||||
{
|
||||
DataReadyInterruptDisable();
|
||||
I2CSPIDriverBase::exit_and_cleanup();
|
||||
}
|
||||
|
||||
void ICM56686::print_status()
|
||||
{
|
||||
I2CSPIDriverBase::print_status();
|
||||
|
||||
PX4_INFO("FIFO empty interval: %" PRIu32 " us (%.1f Hz)", _fifo_empty_interval_us,
|
||||
1e6 / _fifo_empty_interval_us);
|
||||
PX4_INFO("DRDY interrupt: %s", _data_ready_interrupt_enabled ? "enabled" : "disabled");
|
||||
|
||||
perf_print_counter(_bad_register_perf);
|
||||
perf_print_counter(_bad_transfer_perf);
|
||||
perf_print_counter(_fifo_empty_perf);
|
||||
perf_print_counter(_fifo_overflow_perf);
|
||||
perf_print_counter(_fifo_reset_perf);
|
||||
perf_print_counter(_drdy_missed_perf);
|
||||
}
|
||||
|
||||
int ICM56686::probe()
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
uint8_t whoami{0};
|
||||
|
||||
if (RegisterRead(Register::BANK_0::WHO_AM_I, whoami) && whoami == WHOAMI) {
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
DEVICE_DEBUG("unexpected WHO_AM_I 0x%02x", whoami);
|
||||
}
|
||||
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
void ICM56686::RunImpl()
|
||||
{
|
||||
const hrt_abstime now = hrt_absolute_time();
|
||||
|
||||
switch (_state) {
|
||||
case STATE::RESET:
|
||||
DataReadyInterruptDisable();
|
||||
_data_ready_interrupt_enabled = false;
|
||||
|
||||
// Soft reset restores INTF_CONFIG1_OVRD / DRIVE_CONFIG0 to OTP defaults (SPI
|
||||
// 4-wire / slew). Save them so WAIT_FOR_RESET can put the board's pad config back
|
||||
// before the next WHO_AM_I read.
|
||||
if (!RegisterRead(Register::BANK_0::INTF_CONFIG1_OVRD, _intf_config1_ovrd)
|
||||
|| !RegisterRead(Register::BANK_0::DRIVE_CONFIG0, _drive_config0)) {
|
||||
ScheduleDelayed(10_ms);
|
||||
break;
|
||||
}
|
||||
|
||||
// INT1_STATUS0 only latches the reset done status while its source is enabled in
|
||||
// INT1_CONFIG0 (reset value 0x80). Configure() disables all INT1 sources, so the source
|
||||
// is re-enabled here to keep WAIT_FOR_RESET working on a runtime re-reset, independent
|
||||
// of whether the soft reset restores the register defaults.
|
||||
if (!RegisterWrite(Register::BANK_0::INT1_CONFIG0, INT_CONFIG0_BIT::INT1_STATUS_EN_RESET_DONE)
|
||||
|| !RegisterWrite(Register::BANK_0::REG_MISC2, REG_MISC2_BIT::SOFT_RST)) {
|
||||
ScheduleDelayed(10_ms);
|
||||
break;
|
||||
}
|
||||
|
||||
_reset_timestamp = now;
|
||||
_failure_count = 0;
|
||||
_state = STATE::WAIT_FOR_RESET;
|
||||
ScheduleDelayed(10_ms);
|
||||
break;
|
||||
|
||||
case STATE::WAIT_FOR_RESET: {
|
||||
uint8_t whoami{0};
|
||||
uint8_t status{0};
|
||||
|
||||
if (!RegisterWrite(Register::BANK_0::DRIVE_CONFIG0, _drive_config0)
|
||||
|| !RegisterWrite(Register::BANK_0::INTF_CONFIG1_OVRD, _intf_config1_ovrd)) {
|
||||
ScheduleDelayed(10_ms);
|
||||
break;
|
||||
}
|
||||
|
||||
// INT1_STATUS_RESET_DONE is cleared on read, so it is only read once WHO_AM_I matches.
|
||||
if (RegisterRead(Register::BANK_0::WHO_AM_I, whoami)
|
||||
&& whoami == WHOAMI
|
||||
&& RegisterRead(Register::BANK_0::INT1_STATUS0, status)
|
||||
&& (status & INT1_STATUS0_BIT::INT1_STATUS_RESET_DONE)) {
|
||||
_state = STATE::CONFIGURE;
|
||||
ScheduleNow();
|
||||
|
||||
} else if (hrt_elapsed_time(&_reset_timestamp) > 100_ms) {
|
||||
PX4_DEBUG("Reset failed, retrying");
|
||||
_state = STATE::RESET;
|
||||
ScheduleDelayed(100_ms);
|
||||
|
||||
} else {
|
||||
ScheduleDelayed(10_ms);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case STATE::CONFIGURE:
|
||||
if (Configure()) {
|
||||
_state = STATE::FIFO_RESET;
|
||||
// 35 ms gyro start-up time, 10 ms accel from sleep to valid data
|
||||
ScheduleDelayed(50_ms);
|
||||
|
||||
} else if (hrt_elapsed_time(&_reset_timestamp) > 1000_ms) {
|
||||
PX4_DEBUG("Configure failed, resetting");
|
||||
_state = STATE::RESET;
|
||||
ScheduleDelayed(100_ms);
|
||||
|
||||
} else {
|
||||
PX4_DEBUG("Configure failed, retrying");
|
||||
ScheduleDelayed(100_ms);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case STATE::FIFO_RESET:
|
||||
if (!FIFOReset()) {
|
||||
_state = STATE::RESET;
|
||||
ScheduleDelayed(100_ms);
|
||||
break;
|
||||
}
|
||||
|
||||
_state = STATE::FIFO_READ;
|
||||
|
||||
if (DataReadyInterruptConfigure()) {
|
||||
_data_ready_interrupt_enabled = true;
|
||||
ScheduleDelayed(100_ms);
|
||||
|
||||
} else {
|
||||
_data_ready_interrupt_enabled = false;
|
||||
ScheduleOnInterval(_fifo_empty_interval_us, _fifo_empty_interval_us);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case STATE::FIFO_READ: {
|
||||
hrt_abstime timestamp_sample = now;
|
||||
|
||||
if (_data_ready_interrupt_enabled) {
|
||||
const hrt_abstime drdy_timestamp_sample = _drdy_timestamp_sample.fetch_and(0);
|
||||
|
||||
if ((now - drdy_timestamp_sample) < (_fifo_empty_interval_us * 2)) {
|
||||
timestamp_sample = drdy_timestamp_sample;
|
||||
|
||||
} else {
|
||||
perf_count(_drdy_missed_perf);
|
||||
}
|
||||
|
||||
ScheduleDelayed(_fifo_empty_interval_us * 2);
|
||||
}
|
||||
|
||||
if (FIFORead(timestamp_sample)) {
|
||||
if (_failure_count > 0) {
|
||||
_failure_count--;
|
||||
}
|
||||
|
||||
} else if (++_failure_count > 10) {
|
||||
Reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (hrt_elapsed_time(&_last_config_check_timestamp) > 100_ms) {
|
||||
if (RegisterCheck(_register_cfg[_checked_register])) {
|
||||
_last_config_check_timestamp = now;
|
||||
_checked_register = (_checked_register + 1) % REGISTER_CFG_COUNT;
|
||||
|
||||
} else {
|
||||
perf_count(_bad_register_perf);
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ICM56686::ConfigureSampleRate(const int sample_rate)
|
||||
{
|
||||
const float minimum_interval = FIFO_SAMPLE_DT;
|
||||
_fifo_empty_interval_us = math::max(roundf((1e6f / sample_rate) / minimum_interval) * minimum_interval,
|
||||
minimum_interval);
|
||||
_fifo_samples = roundf(math::min(_fifo_empty_interval_us / FIFO_SAMPLE_DT,
|
||||
static_cast<float>(FIFO_MAX_SAMPLES)));
|
||||
_fifo_empty_interval_us = roundf(_fifo_samples * FIFO_SAMPLE_DT);
|
||||
ConfigureFIFOWatermark(static_cast<uint8_t>(_fifo_samples));
|
||||
}
|
||||
|
||||
void ICM56686::ConfigureFIFOWatermark(const uint8_t samples)
|
||||
{
|
||||
for (auto &config : _register_cfg) {
|
||||
if (config.reg == Register::BANK_0::FIFO_CONFIG1_0) {
|
||||
config.value = samples;
|
||||
|
||||
} else if (config.reg == Register::BANK_0::FIFO_CONFIG1_1) {
|
||||
config.value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ICM56686::Configure()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
// Registers without dynamic-change support must be configured with both sensors off.
|
||||
success &= RegisterWrite(Register::BANK_0::INT1_CONFIG0, 0);
|
||||
|
||||
if (_fifo_interrupt_config0 != Register::BANK_0::INT1_CONFIG0) {
|
||||
success &= RegisterWrite(_fifo_interrupt_config0, 0);
|
||||
}
|
||||
|
||||
success &= RegisterWrite(Register::BANK_0::PWR_MGMT0, 0);
|
||||
success &= RegisterWrite(Register::BANK_0::PWR_MGMT_AUX1, 0);
|
||||
|
||||
success &= FIFOBypass();
|
||||
|
||||
success &= RegisterConfigure(Register::BANK_0::ACCEL_CONFIG0);
|
||||
success &= RegisterConfigure(Register::BANK_0::GYRO_CONFIG0);
|
||||
success &= RegisterConfigure(Register::BANK_0::FIFO_CONFIG4);
|
||||
|
||||
// FIFO_HIRES_EN, FIFO_GYRO_EN and FIFO_ACCEL_EN do not support dynamic change, so they are
|
||||
// configured here while both sensors are off. ConfigureFIFO() only touches the fields that
|
||||
// may be changed at runtime (FIFO_MODE, FIFO_WM_TH, FIFO_FLUSH, FIFO_IF_EN).
|
||||
success &= RegisterWrite(Register::BANK_0::FIFO_CONFIG3,
|
||||
FIFO_CONFIG3_BIT::FIFO_HIRES_EN | FIFO_CONFIG3_BIT::FIFO_GYRO_EN |
|
||||
FIFO_CONFIG3_BIT::FIFO_ACCEL_EN);
|
||||
|
||||
// Select 20-bit sensor/FIFO data in little-endian format.
|
||||
success &= IregSetAndClearBits(IREG::SREG_CTRL, SREG_CTRL_BIT::SREG_SIFS_20BITS_EN,
|
||||
SREG_CTRL_BIT::SREG_DATA_ENDIAN_BIG);
|
||||
success &= IregSetAndClearBits(IREG::SMC_CONTROL_0, SMC_CONTROL_0_BIT::TMST_EN, 0);
|
||||
|
||||
// ODRs at or above 4 kHz require an 8 us interrupt pulse.
|
||||
success &= IregSetAndClearBits(IREG::INT_PULSE_MIN_ON_INTF0,
|
||||
INTF0_PULSE_BIT::DURATION_8_US,
|
||||
INTF0_PULSE_BIT::DURATION_MASK);
|
||||
success &= IregSetAndClearBits(IREG::INT_PULSE_MIN_OFF_INTF0,
|
||||
INTF0_PULSE_BIT::DURATION_8_US,
|
||||
INTF0_PULSE_BIT::DURATION_MASK);
|
||||
|
||||
// Run both UI paths with the sample rate converter and the pre-filter enabled, and with the
|
||||
// UI low pass filter bypassed (ODR/2) to get the full bandwidth. The datasheet gives no
|
||||
// recommendation for the SRC fields (reset default is off), so they are kept explicit here and
|
||||
// have to be re-checked against the InvenSense reference driver if the ODR is changed.
|
||||
// NOTE: IREG contents are not covered by the periodic register check in RunImpl().
|
||||
success &= IregSetAndClearBits(IREG::GYRO_SRC_CTRL,
|
||||
GYRO_SRC_CTRL_BIT::GYRO_SRC_CTRL_SRC_ON_PREFILTER_ON,
|
||||
GYRO_SRC_CTRL_BIT::GYRO_SRC_CTRL_MASK);
|
||||
success &= IregSetAndClearBits(IREG::GYRO_UI_LPF_CFG,
|
||||
GYRO_UI_LPF_CFG_BIT::GYRO_UI_LPFBW_ODR_DIV_2,
|
||||
GYRO_UI_LPF_CFG_BIT::GYRO_UI_LPFBW_MASK);
|
||||
success &= IregSetAndClearBits(IREG::ACCEL_SRC_CTRL,
|
||||
ACCEL_SRC_CTRL_BIT::ACCEL_SRC_CTRL_SRC_ON_PREFILTER_ON,
|
||||
ACCEL_SRC_CTRL_BIT::ACCEL_SRC_CTRL_MASK);
|
||||
success &= IregSetAndClearBits(IREG::ACCEL_UI_LPF_CFG,
|
||||
ACCEL_UI_LPF_CFG_BIT::ACCEL_UI_LPFBW_ODR_DIV_2,
|
||||
ACCEL_UI_LPF_CFG_BIT::ACCEL_UI_LPFBW_MASK);
|
||||
|
||||
success &= RegisterConfigure(Register::BANK_0::PWR_MGMT0);
|
||||
|
||||
// data is published from the 16 bit FIFO fields (data[19:4]), which always span the full range
|
||||
_px4_accel.set_range(32.f * CONSTANTS_ONE_G);
|
||||
_px4_gyro.set_range(math::radians(4000.f));
|
||||
_px4_accel.set_scale(32.f * CONSTANTS_ONE_G / 32768.f);
|
||||
_px4_gyro.set_scale(math::radians(4000.f / 32768.f));
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool ICM56686::FIFOBypass()
|
||||
{
|
||||
// Disable the SREG-FIFO interface before the FIFO itself, then switch to bypass mode.
|
||||
bool success = RegisterSetAndClearBits(Register::BANK_0::FIFO_CONFIG3, 0, FIFO_CONFIG3_BIT::FIFO_IF_EN);
|
||||
success &= RegisterSetAndClearBits(Register::BANK_0::FIFO_CONFIG0, FIFO_CONFIG0_BIT::FIFO_MODE_BYPASS,
|
||||
FIFO_CONFIG0_BIT::FIFO_MODE_MASK);
|
||||
|
||||
// FIFO_DEPTH may only be written while the FIFO is disabled (bypass mode).
|
||||
success &= RegisterSetAndClearBits(Register::BANK_0::FIFO_CONFIG0, FIFO_CONFIG0_BIT::FIFO_DEPTH_2K,
|
||||
static_cast<uint8_t>(FIFO_CONFIG0_BIT::FIFO_DEPTH_MASK & ~FIFO_CONFIG0_BIT::FIFO_DEPTH_2K));
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool ICM56686::ConfigureFIFO()
|
||||
{
|
||||
bool success = FIFOBypass();
|
||||
|
||||
// The watermark threshold latches on the FIFO_CONFIG1_1 write pulse. Write the LSByte first
|
||||
// and force both writes, because skipping an unchanged MSByte would leave the threshold at
|
||||
// its disabled reset value.
|
||||
success &= RegisterForceWrite(Register::BANK_0::FIFO_CONFIG1_0);
|
||||
success &= RegisterForceWrite(Register::BANK_0::FIFO_CONFIG1_1);
|
||||
|
||||
// FIFO_INT_OVFL and FIFO_WR_WM_GT_TH may only be written while the FIFO is in bypass mode.
|
||||
success &= RegisterConfigure(Register::BANK_0::FIFO_CONFIG2);
|
||||
|
||||
success &= FIFOFlush();
|
||||
|
||||
// Enable the FIFO first, the SREG-FIFO interface (FIFO_IF_EN) last.
|
||||
success &= RegisterConfigure(Register::BANK_0::FIFO_CONFIG0);
|
||||
success &= RegisterConfigure(Register::BANK_0::FIFO_CONFIG3);
|
||||
success &= RegisterConfigure(_fifo_interrupt_config2);
|
||||
success &= RegisterConfigure(_fifo_interrupt_config0);
|
||||
|
||||
for (const auto &config : _register_cfg) {
|
||||
success &= RegisterCheck(config);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool ICM56686::FIFOFlush()
|
||||
{
|
||||
uint8_t fifo_config2{0};
|
||||
|
||||
if (!RegisterRead(Register::BANK_0::FIFO_CONFIG2, fifo_config2)
|
||||
|| !RegisterWrite(Register::BANK_0::FIFO_CONFIG2, fifo_config2 | FIFO_CONFIG2_BIT::FIFO_FLUSH)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
px4_udelay(10);
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
if (!RegisterRead(Register::BANK_0::FIFO_CONFIG2, fifo_config2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((fifo_config2 & FIFO_CONFIG2_BIT::FIFO_FLUSH) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
px4_udelay(10);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ICM56686::RegisterCheck(const register_config_t ®_cfg)
|
||||
{
|
||||
uint8_t value{0};
|
||||
|
||||
if (!RegisterRead(reg_cfg.reg, value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (value & reg_cfg.mask) == (reg_cfg.value & reg_cfg.mask);
|
||||
}
|
||||
|
||||
bool ICM56686::RegisterConfigure(const register_config_t ®_cfg)
|
||||
{
|
||||
return RegisterSetAndClearBits(reg_cfg.reg, reg_cfg.value & reg_cfg.mask,
|
||||
static_cast<uint8_t>(~reg_cfg.value) & reg_cfg.mask);
|
||||
}
|
||||
|
||||
bool ICM56686::RegisterConfigure(const Register::BANK_0 reg)
|
||||
{
|
||||
for (const auto &config : _register_cfg) {
|
||||
if (config.reg == reg) {
|
||||
return RegisterConfigure(config);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ICM56686::RegisterForceWrite(const Register::BANK_0 reg)
|
||||
{
|
||||
for (const auto &config : _register_cfg) {
|
||||
if (config.reg == reg) {
|
||||
return RegisterWrite(config.reg, config.value);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ICM56686::RegisterRead(const Register::BANK_0 reg, uint8_t &value)
|
||||
{
|
||||
uint8_t cmd[2] {static_cast<uint8_t>(static_cast<uint8_t>(reg) | DIR_READ), 0};
|
||||
|
||||
if (transfer(cmd, cmd, sizeof(cmd)) != PX4_OK) {
|
||||
perf_count(_bad_transfer_perf);
|
||||
return false;
|
||||
}
|
||||
|
||||
value = cmd[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ICM56686::RegisterWrite(const Register::BANK_0 reg, const uint8_t value)
|
||||
{
|
||||
uint8_t cmd[2] {static_cast<uint8_t>(reg), value};
|
||||
|
||||
if (transfer(cmd, cmd, sizeof(cmd)) != PX4_OK) {
|
||||
perf_count(_bad_transfer_perf);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ICM56686::RegisterSetAndClearBits(const Register::BANK_0 reg, const uint8_t set_bits,
|
||||
const uint8_t clear_bits)
|
||||
{
|
||||
uint8_t value{0};
|
||||
|
||||
if (!RegisterRead(reg, value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint8_t new_value = (value & ~clear_bits) | set_bits;
|
||||
return value == new_value || RegisterWrite(reg, new_value);
|
||||
}
|
||||
|
||||
bool ICM56686::WaitForIregReady()
|
||||
{
|
||||
// IREG_DONE reads 1 at idle. Honour the datasheet 4 us gap first or a poll can
|
||||
// observe a stale "done" from the previous access.
|
||||
px4_udelay(4);
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
uint8_t status{0};
|
||||
|
||||
if (!RegisterRead(Register::BANK_0::REG_MISC2, status)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (status & REG_MISC2_BIT::IREG_DONE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
px4_udelay(10);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ICM56686::IregRead(const uint16_t reg, uint8_t &value)
|
||||
{
|
||||
if (!WaitForIregReady()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t address[3] {
|
||||
static_cast<uint8_t>(Register::BANK_0::IREG_ADDR_15_8),
|
||||
static_cast<uint8_t>(reg >> 8),
|
||||
static_cast<uint8_t>(reg & 0xFF)
|
||||
};
|
||||
|
||||
if (transfer(address, address, sizeof(address)) != PX4_OK) {
|
||||
perf_count(_bad_transfer_perf);
|
||||
return false;
|
||||
}
|
||||
|
||||
px4_udelay(10);
|
||||
|
||||
if (!WaitForIregReady() || !RegisterRead(Register::BANK_0::IREG_DATA, value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reading IREG_DATA starts a prefetch of the next indirect address.
|
||||
px4_udelay(10);
|
||||
return WaitForIregReady();
|
||||
}
|
||||
|
||||
bool ICM56686::IregWrite(const uint16_t reg, const uint8_t value)
|
||||
{
|
||||
if (!WaitForIregReady()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t cmd[4] {
|
||||
static_cast<uint8_t>(Register::BANK_0::IREG_ADDR_15_8),
|
||||
static_cast<uint8_t>(reg >> 8),
|
||||
static_cast<uint8_t>(reg & 0xFF),
|
||||
value
|
||||
};
|
||||
|
||||
if (transfer(cmd, cmd, sizeof(cmd)) != PX4_OK) {
|
||||
perf_count(_bad_transfer_perf);
|
||||
return false;
|
||||
}
|
||||
|
||||
px4_udelay(10);
|
||||
return WaitForIregReady();
|
||||
}
|
||||
|
||||
bool ICM56686::IregSetAndClearBits(const uint16_t reg, const uint8_t set_bits, const uint8_t clear_bits)
|
||||
{
|
||||
uint8_t value{0};
|
||||
|
||||
if (!IregRead(reg, value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint8_t new_value = (value & ~clear_bits) | set_bits;
|
||||
|
||||
if (value != new_value && !IregWrite(reg, new_value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t check{0};
|
||||
return IregRead(reg, check) && check == new_value;
|
||||
}
|
||||
|
||||
uint16_t ICM56686::FIFOReadCount()
|
||||
{
|
||||
uint8_t fifo_count[3] {
|
||||
static_cast<uint8_t>(static_cast<uint8_t>(Register::BANK_0::FIFO_COUNT_0) | DIR_READ), 0, 0
|
||||
};
|
||||
|
||||
if (transfer(fifo_count, fifo_count, sizeof(fifo_count)) != PX4_OK) {
|
||||
perf_count(_bad_transfer_perf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// FIFO_COUNT_0 is documented as FIFO_DATA_CNT[15:8] and FIFO_COUNT_1 as [7:0], but the
|
||||
// SREG_CTRL little-endian selection applies to the count registers as well, so the burst
|
||||
// returns the LSByte first (same behaviour as the ICM-45686). Verified on hardware: the
|
||||
// resulting frame count tracks the configured ODR (6344 Hz measured against 6400 Hz nominal,
|
||||
// within the +-1.25% internal clock tolerance) and never trips the overflow path.
|
||||
return combineUnsigned(fifo_count[2], fifo_count[1]);
|
||||
}
|
||||
|
||||
bool ICM56686::FIFORead(const hrt_abstime ×tamp_sample)
|
||||
{
|
||||
const uint16_t fifo_frames = FIFOReadCount();
|
||||
|
||||
if (fifo_frames == 0) {
|
||||
perf_count(_fifo_empty_perf);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fifo_frames >= FIFO::MAX_FRAMES) {
|
||||
perf_count(_fifo_overflow_perf);
|
||||
|
||||
if (!FIFOReset()) {
|
||||
PX4_DEBUG("FIFO reset failed");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint8_t frames = math::min(static_cast<uint16_t>(FIFO_MAX_SAMPLES), fifo_frames);
|
||||
FIFOTransferBuffer buffer{};
|
||||
const size_t transfer_size = 1 + frames * sizeof(FIFO::DATA);
|
||||
|
||||
if (transfer(reinterpret_cast<uint8_t *>(&buffer), reinterpret_cast<uint8_t *>(&buffer), transfer_size) != PX4_OK) {
|
||||
perf_count(_bad_transfer_perf);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only the leading frames with a valid header are used. An invalid header means the FIFO stream
|
||||
// is out of sync, the remaining frames of this transfer are dropped and the next transfer will
|
||||
// start on a bad header again, which resets the FIFO below.
|
||||
uint8_t samples = 0;
|
||||
|
||||
while ((samples < frames) && ((buffer.samples[samples].header & FIFO::HEADER_MASK) == FIFO::HEADER)) {
|
||||
samples++;
|
||||
}
|
||||
|
||||
if (samples < frames) {
|
||||
perf_count(_bad_transfer_perf);
|
||||
}
|
||||
|
||||
if (samples == 0) {
|
||||
if (!FIFOReset()) {
|
||||
PX4_DEBUG("FIFO reset failed");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ProcessTemperature(buffer.samples, samples)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ProcessGyro(timestamp_sample, buffer.samples, samples);
|
||||
ProcessAccel(timestamp_sample, buffer.samples, samples);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ICM56686::FIFOReset()
|
||||
{
|
||||
perf_count(_fifo_reset_perf);
|
||||
_drdy_timestamp_sample.store(0);
|
||||
return ConfigureFIFO();
|
||||
}
|
||||
|
||||
void ICM56686::ProcessAccel(const hrt_abstime ×tamp_sample, const FIFO::DATA fifo[], const uint8_t samples)
|
||||
{
|
||||
sensor_accel_fifo_s accel{};
|
||||
accel.timestamp_sample = timestamp_sample;
|
||||
accel.dt = FIFO_SAMPLE_DT;
|
||||
|
||||
for (int i = 0; i < samples; i++) {
|
||||
// The 16 bit FIFO fields hold data[19:4] of the 20 bit high resolution sample, which always
|
||||
// spans the full range (scale set in Configure()). The extension nibble is unused so the
|
||||
// published scale stays constant instead of toggling with batch content.
|
||||
const int16_t x = FIFO::accelX(fifo[i]);
|
||||
const int16_t y = FIFO::accelY(fifo[i]);
|
||||
const int16_t z = FIFO::accelZ(fifo[i]);
|
||||
|
||||
if ((x != FIFO::INVALID_SAMPLE) && (y != FIFO::INVALID_SAMPLE) && (z != FIFO::INVALID_SAMPLE)) {
|
||||
// the sensor frame is +x forward, +y left, +z up, flip y & z for the FRD board frame
|
||||
accel.x[accel.samples] = x;
|
||||
accel.y[accel.samples] = math::negate(y);
|
||||
accel.z[accel.samples] = math::negate(z);
|
||||
accel.samples++;
|
||||
}
|
||||
}
|
||||
|
||||
_px4_accel.set_error_count(perf_event_count(_bad_register_perf) + perf_event_count(_bad_transfer_perf) +
|
||||
perf_event_count(_fifo_empty_perf) + perf_event_count(_fifo_overflow_perf));
|
||||
|
||||
if (accel.samples > 0) {
|
||||
_px4_accel.updateFIFO(accel);
|
||||
}
|
||||
}
|
||||
|
||||
void ICM56686::ProcessGyro(const hrt_abstime ×tamp_sample, const FIFO::DATA fifo[], const uint8_t samples)
|
||||
{
|
||||
sensor_gyro_fifo_s gyro{};
|
||||
gyro.timestamp_sample = timestamp_sample;
|
||||
gyro.dt = FIFO_SAMPLE_DT;
|
||||
|
||||
for (int i = 0; i < samples; i++) {
|
||||
// The 16 bit FIFO fields hold data[19:4] of the 20 bit high resolution sample, which always
|
||||
// spans the full range (scale set in Configure()). The extension nibble is unused so the
|
||||
// published scale stays constant instead of toggling with batch content.
|
||||
const int16_t x = FIFO::gyroX(fifo[i]);
|
||||
const int16_t y = FIFO::gyroY(fifo[i]);
|
||||
const int16_t z = FIFO::gyroZ(fifo[i]);
|
||||
|
||||
if ((x != FIFO::INVALID_SAMPLE) && (y != FIFO::INVALID_SAMPLE) && (z != FIFO::INVALID_SAMPLE)) {
|
||||
// the sensor frame is +x forward, +y left, +z up, flip y & z for the FRD board frame
|
||||
gyro.x[gyro.samples] = x;
|
||||
gyro.y[gyro.samples] = math::negate(y);
|
||||
gyro.z[gyro.samples] = math::negate(z);
|
||||
gyro.samples++;
|
||||
}
|
||||
}
|
||||
|
||||
_px4_gyro.set_error_count(perf_event_count(_bad_register_perf) + perf_event_count(_bad_transfer_perf) +
|
||||
perf_event_count(_fifo_empty_perf) + perf_event_count(_fifo_overflow_perf));
|
||||
|
||||
if (gyro.samples > 0) {
|
||||
_px4_gyro.updateFIFO(gyro);
|
||||
}
|
||||
}
|
||||
|
||||
bool ICM56686::ProcessTemperature(const FIFO::DATA fifo[], const uint8_t samples)
|
||||
{
|
||||
int16_t temperature_samples[FIFO_MAX_SAMPLES] {};
|
||||
float temperature_sum{0};
|
||||
int valid_samples{0};
|
||||
|
||||
for (int i = 0; i < samples; i++) {
|
||||
const int16_t temperature = combine(fifo[i].temperature_h, fifo[i].temperature_l);
|
||||
|
||||
if (temperature != FIFO::INVALID_TEMPERATURE) {
|
||||
temperature_sum += temperature;
|
||||
temperature_samples[valid_samples] = temperature;
|
||||
valid_samples++;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid_samples == 0) {
|
||||
perf_count(_bad_transfer_perf);
|
||||
return false;
|
||||
}
|
||||
|
||||
const float temperature_average = temperature_sum / valid_samples;
|
||||
|
||||
for (int i = 0; i < valid_samples; i++) {
|
||||
// A temperature jump within one FIFO transfer is an indication of a transfer error.
|
||||
if (fabsf(temperature_samples[i] - temperature_average) > 1000.f) {
|
||||
perf_count(_bad_transfer_perf);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const float temperature = (temperature_average / TEMPERATURE_SENSITIVITY) + TEMPERATURE_OFFSET;
|
||||
|
||||
if (!PX4_ISFINITE(temperature)) {
|
||||
perf_count(_bad_transfer_perf);
|
||||
return false;
|
||||
}
|
||||
|
||||
_px4_accel.set_temperature(temperature);
|
||||
_px4_gyro.set_temperature(temperature);
|
||||
return true;
|
||||
}
|
||||
|
||||
int ICM56686::DataReadyInterruptCallback(int irq, void *context, void *arg)
|
||||
{
|
||||
static_cast<ICM56686 *>(arg)->DataReady();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ICM56686::DataReady()
|
||||
{
|
||||
_drdy_timestamp_sample.store(hrt_absolute_time());
|
||||
ScheduleNow();
|
||||
}
|
||||
|
||||
bool ICM56686::DataReadyInterruptConfigure()
|
||||
{
|
||||
if (_drdy_gpio == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return px4_arch_gpiosetevent(_drdy_gpio, true, false, true, &DataReadyInterruptCallback, this) == 0;
|
||||
}
|
||||
|
||||
bool ICM56686::DataReadyInterruptDisable()
|
||||
{
|
||||
if (_drdy_gpio == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return px4_arch_gpiosetevent(_drdy_gpio, false, false, false, nullptr, nullptr) == 0;
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2026 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file ICM56686.hpp
|
||||
*
|
||||
* Driver for the InvenSense ICM56686 connected via SPI.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "InvenSense_ICM56686_registers.hpp"
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/drivers/accelerometer/PX4Accelerometer.hpp>
|
||||
#include <lib/drivers/device/spi.h>
|
||||
#include <lib/drivers/gyroscope/PX4Gyroscope.hpp>
|
||||
#include <lib/geo/geo.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <px4_platform_common/atomic.h>
|
||||
#include <px4_platform_common/i2c_spi_buses.h>
|
||||
|
||||
using namespace InvenSense_ICM56686;
|
||||
|
||||
class ICM56686 : public device::SPI, public I2CSPIDriver<ICM56686>
|
||||
{
|
||||
public:
|
||||
ICM56686(const I2CSPIDriverConfig &config);
|
||||
~ICM56686() override;
|
||||
|
||||
static void print_usage();
|
||||
|
||||
void RunImpl();
|
||||
|
||||
int init() override;
|
||||
void print_status() override;
|
||||
|
||||
private:
|
||||
void exit_and_cleanup() override;
|
||||
|
||||
static constexpr float FIFO_SAMPLE_DT{1e6f / 6400.f};
|
||||
|
||||
static constexpr size_t GYRO_FIFO_MAX_SAMPLES{
|
||||
sizeof(sensor_gyro_fifo_s::x) / sizeof(sensor_gyro_fifo_s::x[0])
|
||||
};
|
||||
static constexpr size_t ACCEL_FIFO_MAX_SAMPLES{
|
||||
sizeof(sensor_accel_fifo_s::x) / sizeof(sensor_accel_fifo_s::x[0])
|
||||
};
|
||||
static constexpr int32_t FIFO_MAX_SAMPLES{
|
||||
static_cast<int32_t>(math::min(static_cast<size_t>(FIFO::MAX_FRAMES),
|
||||
math::min(GYRO_FIFO_MAX_SAMPLES, ACCEL_FIFO_MAX_SAMPLES)))
|
||||
};
|
||||
|
||||
struct FIFOTransferBuffer {
|
||||
uint8_t cmd{static_cast<uint8_t>(static_cast<uint8_t>(Register::BANK_0::FIFO_DATA) | DIR_READ)};
|
||||
FIFO::DATA samples[FIFO_MAX_SAMPLES] {};
|
||||
} __attribute__((packed));
|
||||
|
||||
static_assert(sizeof(FIFOTransferBuffer) == (1 + FIFO_MAX_SAMPLES *sizeof(FIFO::DATA)));
|
||||
|
||||
struct register_config_t {
|
||||
Register::BANK_0 reg;
|
||||
uint8_t value;
|
||||
uint8_t mask;
|
||||
};
|
||||
|
||||
int probe() override;
|
||||
|
||||
bool Reset();
|
||||
bool Configure();
|
||||
bool ConfigureFIFO();
|
||||
bool FIFOBypass();
|
||||
bool FIFOFlush();
|
||||
void ConfigureSampleRate(const int sample_rate);
|
||||
void ConfigureFIFOWatermark(const uint8_t samples);
|
||||
|
||||
bool RegisterCheck(const register_config_t ®_cfg);
|
||||
bool RegisterConfigure(const register_config_t ®_cfg);
|
||||
bool RegisterConfigure(const Register::BANK_0 reg);
|
||||
bool RegisterForceWrite(const Register::BANK_0 reg);
|
||||
bool RegisterRead(const Register::BANK_0 reg, uint8_t &value);
|
||||
bool RegisterWrite(const Register::BANK_0 reg, const uint8_t value);
|
||||
bool RegisterSetAndClearBits(const Register::BANK_0 reg, const uint8_t set_bits, const uint8_t clear_bits);
|
||||
|
||||
bool WaitForIregReady();
|
||||
bool IregRead(const uint16_t reg, uint8_t &value);
|
||||
bool IregWrite(const uint16_t reg, const uint8_t value);
|
||||
bool IregSetAndClearBits(const uint16_t reg, const uint8_t set_bits, const uint8_t clear_bits);
|
||||
|
||||
uint16_t FIFOReadCount();
|
||||
bool FIFORead(const hrt_abstime ×tamp_sample);
|
||||
bool FIFOReset();
|
||||
|
||||
void ProcessAccel(const hrt_abstime ×tamp_sample, const FIFO::DATA fifo[], const uint8_t samples);
|
||||
void ProcessGyro(const hrt_abstime ×tamp_sample, const FIFO::DATA fifo[], const uint8_t samples);
|
||||
bool ProcessTemperature(const FIFO::DATA fifo[], const uint8_t samples);
|
||||
|
||||
static int DataReadyInterruptCallback(int irq, void *context, void *arg);
|
||||
void DataReady();
|
||||
bool DataReadyInterruptConfigure();
|
||||
bool DataReadyInterruptDisable();
|
||||
|
||||
const spi_drdy_gpio_t _drdy_gpio;
|
||||
const Register::BANK_0 _fifo_interrupt_config0;
|
||||
const Register::BANK_0 _fifo_interrupt_config2;
|
||||
|
||||
PX4Accelerometer _px4_accel;
|
||||
PX4Gyroscope _px4_gyro;
|
||||
|
||||
perf_counter_t _bad_register_perf{perf_alloc(PC_COUNT, MODULE_NAME": bad register")};
|
||||
perf_counter_t _bad_transfer_perf{perf_alloc(PC_COUNT, MODULE_NAME": bad transfer")};
|
||||
perf_counter_t _fifo_empty_perf{perf_alloc(PC_COUNT, MODULE_NAME": FIFO empty")};
|
||||
perf_counter_t _fifo_overflow_perf{perf_alloc(PC_COUNT, MODULE_NAME": FIFO overflow")};
|
||||
perf_counter_t _fifo_reset_perf{perf_alloc(PC_COUNT, MODULE_NAME": FIFO reset")};
|
||||
perf_counter_t _drdy_missed_perf{nullptr};
|
||||
|
||||
hrt_abstime _reset_timestamp{0};
|
||||
hrt_abstime _last_config_check_timestamp{0};
|
||||
int _failure_count{0};
|
||||
|
||||
px4::atomic<hrt_abstime> _drdy_timestamp_sample{0};
|
||||
bool _data_ready_interrupt_enabled{false};
|
||||
|
||||
uint8_t _intf_config1_ovrd{0};
|
||||
uint8_t _drive_config0{0};
|
||||
|
||||
enum class STATE : uint8_t {
|
||||
RESET,
|
||||
WAIT_FOR_RESET,
|
||||
CONFIGURE,
|
||||
FIFO_RESET,
|
||||
FIFO_READ,
|
||||
} _state{STATE::RESET};
|
||||
|
||||
uint32_t _fifo_empty_interval_us{1250};
|
||||
int32_t _fifo_samples{static_cast<int32_t>(_fifo_empty_interval_us / FIFO_SAMPLE_DT)};
|
||||
|
||||
uint8_t _checked_register{0};
|
||||
static constexpr uint8_t REGISTER_CFG_COUNT{11};
|
||||
register_config_t _register_cfg[REGISTER_CFG_COUNT] {
|
||||
{
|
||||
Register::BANK_0::INT1_CONFIG0,
|
||||
INT_CONFIG0_BIT::STATUS_EN_FIFO_THS | INT_CONFIG0_BIT::STATUS_EN_FIFO_FULL, 0xFF
|
||||
},
|
||||
{Register::BANK_0::INT1_CONFIG2, INT_CONFIG2_BIT::ACTIVE_HIGH, INT_CONFIG2_BIT::CONFIG_MASK},
|
||||
{
|
||||
Register::BANK_0::PWR_MGMT0,
|
||||
PWR_MGMT0_BIT::GYRO_MODE_LOW_NOISE | PWR_MGMT0_BIT::ACCEL_MODE_LOW_NOISE, 0x0F
|
||||
},
|
||||
{
|
||||
Register::BANK_0::ACCEL_CONFIG0,
|
||||
ACCEL_CONFIG0_BIT::ACCEL_UI_FS_SEL_32_G | ACCEL_CONFIG0_BIT::ACCEL_ODR_6400_HZ,
|
||||
ACCEL_CONFIG0_BIT::ACCEL_CONFIG0_MASK
|
||||
},
|
||||
{
|
||||
Register::BANK_0::GYRO_CONFIG0,
|
||||
GYRO_CONFIG0_BIT::GYRO_UI_FS_SEL_4000_DPS | GYRO_CONFIG0_BIT::GYRO_ODR_6400_HZ,
|
||||
GYRO_CONFIG0_BIT::GYRO_CONFIG0_MASK
|
||||
},
|
||||
{Register::BANK_0::FIFO_CONFIG0, FIFO_CONFIG0_BIT::FIFO_MODE_STOP_ON_FULL | FIFO_CONFIG0_BIT::FIFO_DEPTH_2K, 0xFF},
|
||||
// FIFO watermark threshold, set by ConfigureFIFOWatermark(). The datasheet does not
|
||||
// document the unit, the FIFO count is in frames so the threshold is programmed in
|
||||
// frames as well.
|
||||
{Register::BANK_0::FIFO_CONFIG1_0, 0, 0xFF},
|
||||
{Register::BANK_0::FIFO_CONFIG1_1, 0, 0xFF},
|
||||
{
|
||||
Register::BANK_0::FIFO_CONFIG2,
|
||||
FIFO_CONFIG2_BIT::FIFO_WR_WM_GT_TH | FIFO_CONFIG2_BIT::FIFO_RESERVED_RESET,
|
||||
FIFO_CONFIG2_BIT::FIFO_CONFIG2_MASK
|
||||
},
|
||||
{
|
||||
Register::BANK_0::FIFO_CONFIG3,
|
||||
FIFO_CONFIG3_BIT::FIFO_HIRES_EN | FIFO_CONFIG3_BIT::FIFO_GYRO_EN |
|
||||
FIFO_CONFIG3_BIT::FIFO_ACCEL_EN | FIFO_CONFIG3_BIT::FIFO_IF_EN,
|
||||
FIFO_CONFIG3_BIT::FIFO_CONFIG3_MASK
|
||||
},
|
||||
{
|
||||
Register::BANK_0::FIFO_CONFIG4,
|
||||
FIFO_CONFIG4_BIT::FIFO_TMST_FSYNC_EN,
|
||||
FIFO_CONFIG4_BIT::FIFO_CONFIG4_MASK
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,304 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2026 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file InvenSense_ICM56686_registers.hpp
|
||||
*
|
||||
* InvenSense ICM-56686 registers.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace InvenSense_ICM56686
|
||||
{
|
||||
|
||||
static constexpr uint8_t Bit0 = (1 << 0);
|
||||
static constexpr uint8_t Bit1 = (1 << 1);
|
||||
static constexpr uint8_t Bit2 = (1 << 2);
|
||||
static constexpr uint8_t Bit3 = (1 << 3);
|
||||
static constexpr uint8_t Bit4 = (1 << 4);
|
||||
static constexpr uint8_t Bit5 = (1 << 5);
|
||||
static constexpr uint8_t Bit6 = (1 << 6);
|
||||
static constexpr uint8_t Bit7 = (1 << 7);
|
||||
|
||||
// Staying below 10 MHz avoids the additional FIFO data-to-count tBUF requirement.
|
||||
static constexpr uint32_t SPI_SPEED = 8 * 1000 * 1000;
|
||||
static constexpr uint8_t DIR_READ = Bit7;
|
||||
|
||||
static constexpr uint8_t WHOAMI = 0x08;
|
||||
|
||||
// Sensitivity of the 16 bit temperature data, which is what the 20 byte high resolution FIFO packet
|
||||
// carries. The 8 bit temperature of the 8/16 byte packets uses 2 LSB/degC instead.
|
||||
static constexpr float TEMPERATURE_SENSITIVITY = 128.f; // LSB/degC
|
||||
static constexpr float TEMPERATURE_OFFSET = 25.f; // degC
|
||||
|
||||
namespace Register
|
||||
{
|
||||
|
||||
enum class BANK_0 : uint8_t {
|
||||
PWR_MGMT0 = 0x14,
|
||||
FIFO_COUNT_0 = 0x16,
|
||||
FIFO_COUNT_1 = 0x17,
|
||||
FIFO_DATA = 0x18,
|
||||
INT1_CONFIG0 = 0x1A,
|
||||
INT1_CONFIG2 = 0x1C,
|
||||
INT1_STATUS0 = 0x1D,
|
||||
ACCEL_CONFIG0 = 0x1F,
|
||||
GYRO_CONFIG0 = 0x20,
|
||||
FIFO_CONFIG0 = 0x21,
|
||||
FIFO_CONFIG1_0 = 0x22,
|
||||
FIFO_CONFIG1_1 = 0x23,
|
||||
FIFO_CONFIG2 = 0x24,
|
||||
FIFO_CONFIG3 = 0x25,
|
||||
FIFO_CONFIG4 = 0x26,
|
||||
INTF_CONFIG1_OVRD = 0x31,
|
||||
DRIVE_CONFIG0 = 0x36,
|
||||
PWR_MGMT_AUX1 = 0x58,
|
||||
INT2_CONFIG0 = 0x5A,
|
||||
INT2_CONFIG2 = 0x5C,
|
||||
WHO_AM_I = 0x72,
|
||||
IREG_ADDR_15_8 = 0x7C,
|
||||
IREG_ADDR_7_0 = 0x7D,
|
||||
IREG_DATA = 0x7E,
|
||||
REG_MISC2 = 0x7F,
|
||||
};
|
||||
|
||||
} // namespace Register
|
||||
|
||||
namespace IREG
|
||||
{
|
||||
|
||||
static constexpr uint16_t SMC_CONTROL_0 = 0xA258;
|
||||
static constexpr uint16_t SREG_CTRL = 0xA260;
|
||||
static constexpr uint16_t INT_PULSE_MIN_ON_INTF0 = 0xA262;
|
||||
static constexpr uint16_t INT_PULSE_MIN_OFF_INTF0 = 0xA264;
|
||||
static constexpr uint16_t GYRO_SRC_CTRL = 0xA49A;
|
||||
static constexpr uint16_t GYRO_UI_LPF_CFG = 0xA49E;
|
||||
static constexpr uint16_t ACCEL_SRC_CTRL = 0xA56D;
|
||||
static constexpr uint16_t ACCEL_UI_LPF_CFG = 0xA570;
|
||||
|
||||
} // namespace IREG
|
||||
|
||||
enum PWR_MGMT0_BIT : uint8_t {
|
||||
GYRO_MODE_LOW_NOISE = Bit3 | Bit2,
|
||||
ACCEL_MODE_LOW_NOISE = Bit1 | Bit0,
|
||||
};
|
||||
|
||||
enum INT_CONFIG0_BIT : uint8_t {
|
||||
INT1_STATUS_EN_RESET_DONE = Bit7,
|
||||
STATUS_EN_FIFO_THS = Bit1,
|
||||
STATUS_EN_FIFO_FULL = Bit0,
|
||||
};
|
||||
|
||||
enum INT_CONFIG2_BIT : uint8_t {
|
||||
ACTIVE_HIGH = Bit0,
|
||||
CONFIG_MASK = Bit2 | Bit1 | Bit0,
|
||||
};
|
||||
|
||||
enum INT1_STATUS0_BIT : uint8_t {
|
||||
INT1_STATUS_RESET_DONE = Bit7,
|
||||
INT1_STATUS_FIFO_THS = Bit1,
|
||||
INT1_STATUS_FIFO_FULL = Bit0,
|
||||
};
|
||||
|
||||
enum ACCEL_CONFIG0_BIT : uint8_t {
|
||||
ACCEL_UI_FS_SEL_32_G = 0,
|
||||
ACCEL_ODR_6400_HZ = Bit1 | Bit0,
|
||||
ACCEL_CONFIG0_MASK = Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0,
|
||||
};
|
||||
|
||||
enum GYRO_CONFIG0_BIT : uint8_t {
|
||||
GYRO_UI_FS_SEL_4000_DPS = 0,
|
||||
GYRO_ODR_6400_HZ = Bit1 | Bit0,
|
||||
GYRO_CONFIG0_MASK = 0xFF,
|
||||
};
|
||||
|
||||
enum FIFO_CONFIG0_BIT : uint8_t {
|
||||
FIFO_MODE_BYPASS = 0,
|
||||
FIFO_MODE_STOP_ON_FULL = Bit7,
|
||||
FIFO_MODE_MASK = Bit7 | Bit6,
|
||||
FIFO_DEPTH_2K = Bit2 | Bit1 | Bit0,
|
||||
FIFO_DEPTH_MASK = Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0,
|
||||
};
|
||||
|
||||
enum FIFO_CONFIG2_BIT : uint8_t {
|
||||
FIFO_FLUSH = Bit7,
|
||||
FIFO_RESERVED_RESET = Bit5, // reset 0x20, bits [6:5] reserved (DS-000563 v1.1 §23.34)
|
||||
FIFO_INT_OVFL = Bit4,
|
||||
FIFO_WR_WM_GT_TH = Bit3,
|
||||
FIFO_CONFIG2_MASK = Bit6 | Bit5 | Bit4 | Bit3,
|
||||
};
|
||||
|
||||
enum FIFO_CONFIG3_BIT : uint8_t {
|
||||
FIFO_HIRES_EN = Bit3,
|
||||
FIFO_GYRO_EN = Bit2,
|
||||
FIFO_ACCEL_EN = Bit1,
|
||||
FIFO_IF_EN = Bit0,
|
||||
FIFO_CONFIG3_MASK = Bit3 | Bit2 | Bit1 | Bit0,
|
||||
};
|
||||
|
||||
enum FIFO_CONFIG4_BIT : uint8_t {
|
||||
FIFO_COMP_NC_FLOW_CFG_MASK = Bit4 | Bit3 | Bit2,
|
||||
FIFO_COMP_EN = Bit1,
|
||||
FIFO_TMST_FSYNC_EN = Bit0,
|
||||
FIFO_CONFIG4_MASK = FIFO_COMP_NC_FLOW_CFG_MASK | FIFO_COMP_EN | FIFO_TMST_FSYNC_EN,
|
||||
};
|
||||
|
||||
enum REG_MISC2_BIT : uint8_t {
|
||||
SOFT_RST = Bit1,
|
||||
IREG_DONE = Bit0,
|
||||
};
|
||||
|
||||
enum INTF0_PULSE_BIT : uint8_t {
|
||||
DURATION_8_US = Bit0,
|
||||
DURATION_MASK = Bit2 | Bit1 | Bit0,
|
||||
};
|
||||
|
||||
enum SREG_CTRL_BIT : uint8_t {
|
||||
SREG_SIFS_20BITS_EN = Bit3,
|
||||
SREG_DATA_ENDIAN_BIG = Bit1,
|
||||
SREG_CTRL_MASK = Bit3 | Bit1,
|
||||
};
|
||||
|
||||
enum SMC_CONTROL_0_BIT : uint8_t {
|
||||
TMST_EN = Bit0,
|
||||
};
|
||||
|
||||
enum GYRO_SRC_CTRL_BIT : uint8_t {
|
||||
GYRO_SRC_CTRL_MASK = Bit3 | Bit2,
|
||||
GYRO_SRC_CTRL_SRC_ON_PREFILTER_ON = Bit3,
|
||||
};
|
||||
|
||||
enum GYRO_UI_LPF_CFG_BIT : uint8_t {
|
||||
GYRO_UI_LPFBW_ODR_DIV_2 = 0,
|
||||
GYRO_UI_LPFBW_MASK = Bit6 | Bit5 | Bit4,
|
||||
};
|
||||
|
||||
enum ACCEL_SRC_CTRL_BIT : uint8_t {
|
||||
ACCEL_SRC_CTRL_MASK = Bit1 | Bit0,
|
||||
ACCEL_SRC_CTRL_SRC_ON_PREFILTER_ON = Bit1,
|
||||
};
|
||||
|
||||
enum ACCEL_UI_LPF_CFG_BIT : uint8_t {
|
||||
ACCEL_UI_LPFBW_ODR_DIV_2 = 0,
|
||||
ACCEL_UI_LPFBW_MASK = Bit2 | Bit1 | Bit0,
|
||||
};
|
||||
|
||||
namespace FIFO
|
||||
{
|
||||
|
||||
static constexpr size_t SIZE = 2048;
|
||||
|
||||
struct DATA {
|
||||
uint8_t header;
|
||||
uint8_t accel_x_l;
|
||||
uint8_t accel_x_h;
|
||||
uint8_t accel_y_l;
|
||||
uint8_t accel_y_h;
|
||||
uint8_t accel_z_l;
|
||||
uint8_t accel_z_h;
|
||||
uint8_t gyro_x_l;
|
||||
uint8_t gyro_x_h;
|
||||
uint8_t gyro_y_l;
|
||||
uint8_t gyro_y_h;
|
||||
uint8_t gyro_z_l;
|
||||
uint8_t gyro_z_h;
|
||||
uint8_t temperature_l;
|
||||
uint8_t temperature_h;
|
||||
uint8_t timestamp_l;
|
||||
uint8_t timestamp_h;
|
||||
uint8_t highres_x;
|
||||
uint8_t highres_y;
|
||||
uint8_t highres_z;
|
||||
} __attribute__((packed));
|
||||
|
||||
static_assert(sizeof(DATA) == 20);
|
||||
|
||||
// The FIFO count reports the number of unread frames, a full 2K FIFO holds this many.
|
||||
static constexpr uint16_t MAX_FRAMES = SIZE / sizeof(DATA);
|
||||
|
||||
// A 20 bit sample of exactly negative full scale (-524288) marks invalid sensor data, its 16 bit
|
||||
// field (data[19:4]) reads INT16_MIN.
|
||||
static constexpr int16_t INVALID_SAMPLE = INT16_MIN;
|
||||
static constexpr int16_t INVALID_TEMPERATURE = INT16_MIN;
|
||||
|
||||
static constexpr uint8_t HEADER = Bit6 | Bit5 | Bit4 | Bit3;
|
||||
static constexpr uint8_t HEADER_MASK = Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2;
|
||||
|
||||
static constexpr int16_t field16(const uint8_t high, const uint8_t low)
|
||||
{
|
||||
return static_cast<int16_t>((static_cast<uint16_t>(high) << 8) | low);
|
||||
}
|
||||
|
||||
static_assert(field16(0x7F, 0xFF) == INT16_MAX);
|
||||
static_assert(field16(0x80, 0x00) == INVALID_SAMPLE);
|
||||
static_assert(field16(0xFF, 0xFF) == -1);
|
||||
|
||||
// The sensor data is byte swapped, SREG_DATA_ENDIAN_SEL selects little endian. In high resolution
|
||||
// mode each 16 bit field holds data[19:4] of the 20 bit sample, which always spans the full range,
|
||||
// and the highres_* bytes hold the data[3:0] extension nibbles, which are not used.
|
||||
static constexpr int16_t accelX(const DATA &sample)
|
||||
{
|
||||
return field16(sample.accel_x_h, sample.accel_x_l);
|
||||
}
|
||||
|
||||
static constexpr int16_t accelY(const DATA &sample)
|
||||
{
|
||||
return field16(sample.accel_y_h, sample.accel_y_l);
|
||||
}
|
||||
|
||||
static constexpr int16_t accelZ(const DATA &sample)
|
||||
{
|
||||
return field16(sample.accel_z_h, sample.accel_z_l);
|
||||
}
|
||||
|
||||
static constexpr int16_t gyroX(const DATA &sample)
|
||||
{
|
||||
return field16(sample.gyro_x_h, sample.gyro_x_l);
|
||||
}
|
||||
|
||||
static constexpr int16_t gyroY(const DATA &sample)
|
||||
{
|
||||
return field16(sample.gyro_y_h, sample.gyro_y_l);
|
||||
}
|
||||
|
||||
static constexpr int16_t gyroZ(const DATA &sample)
|
||||
{
|
||||
return field16(sample.gyro_z_h, sample.gyro_z_l);
|
||||
}
|
||||
|
||||
} // namespace FIFO
|
||||
} // namespace InvenSense_ICM56686
|
||||
@@ -0,0 +1,5 @@
|
||||
menuconfig DRIVERS_IMU_INVENSENSE_ICM56686
|
||||
bool "icm56686"
|
||||
default n
|
||||
---help---
|
||||
Enable support for icm56686
|
||||
@@ -0,0 +1,92 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2026 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "ICM56686.hpp"
|
||||
|
||||
#include <px4_platform_common/getopt.h>
|
||||
#include <px4_platform_common/module.h>
|
||||
|
||||
void ICM56686::print_usage()
|
||||
{
|
||||
PRINT_MODULE_USAGE_NAME("icm56686", "driver");
|
||||
PRINT_MODULE_USAGE_SUBCATEGORY("imu");
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(false, true);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('R', 0, 0, 35, "Rotation", true);
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('2', "Route the FIFO interrupt to INT2 instead of INT1", true);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
extern "C" int icm56686_main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
using ThisDriver = ICM56686;
|
||||
BusCLIArguments cli{false, true};
|
||||
cli.default_spi_frequency = SPI_SPEED;
|
||||
|
||||
while ((ch = cli.getOpt(argc, argv, "R:2")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'R':
|
||||
cli.rotation = (enum Rotation)atoi(cli.optArg());
|
||||
break;
|
||||
|
||||
case '2':
|
||||
cli.custom1 = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const char *verb = cli.optArg();
|
||||
|
||||
if (!verb) {
|
||||
ThisDriver::print_usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_IMU_DEVTYPE_ICM56686);
|
||||
|
||||
if (!strcmp(verb, "start")) {
|
||||
return ThisDriver::module_start(cli, iterator);
|
||||
}
|
||||
|
||||
if (!strcmp(verb, "stop")) {
|
||||
return ThisDriver::module_stop(iterator);
|
||||
}
|
||||
|
||||
if (!strcmp(verb, "status")) {
|
||||
return ThisDriver::module_status(iterator);
|
||||
}
|
||||
|
||||
ThisDriver::print_usage();
|
||||
return -1;
|
||||
}
|
||||
Reference in new issue
Block a user