drivers/imu: new Murata SCH16T IMU driver (#22914)

---------

Co-authored-by: alexklimaj <alex@arkelectron.com>
This commit is contained in:
Jacob Dahl
2024-05-20 12:38:19 -06:00
committed by GitHub
parent 70304fe715
commit e72ecdbefb
12 changed files with 976 additions and 0 deletions
+6
View File
@@ -138,6 +138,12 @@ then
adis16507 -S start adis16507 -S start
fi fi
# SCH16T spi external IMU
if param compare -s SENS_EN_SCH16T 1
then
sch16t -S start
fi
# Eagle Tree airspeed sensor external I2C # Eagle Tree airspeed sensor external I2C
if param compare -s SENS_EN_ETSASPD 1 if param compare -s SENS_EN_ETSASPD 1
then then
+1
View File
@@ -20,6 +20,7 @@ CONFIG_DRIVERS_DSHOT=y
CONFIG_DRIVERS_GPS=y CONFIG_DRIVERS_GPS=y
CONFIG_DRIVERS_HEATER=y CONFIG_DRIVERS_HEATER=y
CONFIG_DRIVERS_IMU_ANALOG_DEVICES_ADIS16507=y CONFIG_DRIVERS_IMU_ANALOG_DEVICES_ADIS16507=y
CONFIG_DRIVERS_IMU_MURATA_SCH16T=y
CONFIG_DRIVERS_IMU_INVENSENSE_ICM42688P=y CONFIG_DRIVERS_IMU_INVENSENSE_ICM42688P=y
CONFIG_DRIVERS_IMU_INVENSENSE_IIM42652=y CONFIG_DRIVERS_IMU_INVENSENSE_IIM42652=y
CONFIG_DRIVERS_IMU_INVENSENSE_IIM42653=y CONFIG_DRIVERS_IMU_INVENSENSE_IIM42653=y
+2
View File
@@ -133,6 +133,8 @@
#define DRV_IMU_DEVTYPE_ADIS16477 0x59 #define DRV_IMU_DEVTYPE_ADIS16477 0x59
#define DRV_IMU_DEVTYPE_ADIS16507 0x5A #define DRV_IMU_DEVTYPE_ADIS16507 0x5A
#define DRV_IMU_DEVTYPE_SCH16T 0x5B
#define DRV_BARO_DEVTYPE_MPC2520 0x5F #define DRV_BARO_DEVTYPE_MPC2520 0x5F
#define DRV_BARO_DEVTYPE_LPS22HB 0x60 #define DRV_BARO_DEVTYPE_LPS22HB 0x60
+1
View File
@@ -8,6 +8,7 @@ menu "IMU"
select DRIVERS_IMU_ANALOG_DEVICES_ADIS16470 select DRIVERS_IMU_ANALOG_DEVICES_ADIS16470
select DRIVERS_IMU_BOSCH_BMI055 select DRIVERS_IMU_BOSCH_BMI055
select DRIVERS_IMU_BOSCH_BMI088 select DRIVERS_IMU_BOSCH_BMI088
select DRIVERS_IMU_MURATA_SCH16T
select DRIVERS_IMU_NXP_FXAS21002C select DRIVERS_IMU_NXP_FXAS21002C
select DRIVERS_IMU_NXP_FXOS8701CQ select DRIVERS_IMU_NXP_FXOS8701CQ
select DRIVERS_IMU_INVENSENSE_ICM20602 select DRIVERS_IMU_INVENSENSE_ICM20602
+3
View File
@@ -0,0 +1,3 @@
menu "Murata"
rsource "*/Kconfig"
endmenu #Murata
@@ -0,0 +1,47 @@
############################################################################
#
# Copyright (c) 2022 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__murata__sch16t
MAIN sch16t
COMPILE_FLAGS
SRCS
SCH16T.cpp
SCH16T.hpp
sch16t_main.cpp
Murata_SCH16T_registers.hpp
DEPENDS
drivers_accelerometer
drivers_gyroscope
px4_work_queue
)
+5
View File
@@ -0,0 +1,5 @@
menuconfig DRIVERS_IMU_MURATA_SCH16T
bool "SCH16T"
default n
---help---
Enable support for murata SCH16T
@@ -0,0 +1,115 @@
/****************************************************************************
*
* Copyright (c) 2024 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.
*
****************************************************************************/
#pragma once
#include <cstdint>
namespace Murata_SCH16T
{
static constexpr uint32_t SPI_SPEED = 5 * 1000 * 1000; // 5 MHz SPI serial interface
static constexpr uint32_t SAMPLE_INTERVAL_US = 678; // 1500 Hz -- decimation factor 8, F_PRIM/16, 1.475 kHz
static constexpr uint16_t EOI = (1 << 1); // End of Initialization
static constexpr uint16_t EN_SENSOR = (1 << 0); // Enable RATE and ACC measurement
static constexpr uint16_t DRY_DRV_EN = (1 << 5); // Enables Data ready function
static constexpr uint16_t FILTER_BYPASS = (0b111); // Bypass filter
static constexpr uint16_t RATE_300DPS_1475HZ = 0b0'001'001'011'011'011; // Gyro XYZ range 300 deg/s @ 1475Hz
static constexpr uint16_t ACC12_8G_1475HZ = 0b0'001'001'011'011'011; // Acc XYZ range 8 G and 1475 update rate
static constexpr uint16_t ACC3_26G = (0b000 << 0);
static constexpr uint16_t SPI_SOFT_RESET = (0b1010);
// Data registers
#define RATE_X1 0x01 // 20 bit
#define RATE_Y1 0x02 // 20 bit
#define RATE_Z1 0x03 // 20 bit
#define ACC_X1 0x04 // 20 bit
#define ACC_Y1 0x05 // 20 bit
#define ACC_Z1 0x06 // 20 bit
#define ACC_X3 0x07 // 20 bit
#define ACC_Y3 0x08 // 20 bit
#define ACC_Z3 0x09 // 20 bit
#define RATE_X2 0x0A // 20 bit
#define RATE_Y2 0x0B // 20 bit
#define RATE_Z2 0x0C // 20 bit
#define ACC_X2 0x0D // 20 bit
#define ACC_Y2 0x0E // 20 bit
#define ACC_Z2 0x0F // 20 bit
#define TEMP 0x10 // 16 bit
// Status registers
#define STAT_SUM 0x14 // 16 bit
#define STAT_SUM_SAT 0x15 // 16 bit
#define STAT_COM 0x16 // 16 bit
#define STAT_RATE_COM 0x17 // 16 bit
#define STAT_RATE_X 0x18 // 16 bit
#define STAT_RATE_Y 0x19 // 16 bit
#define STAT_RATE_Z 0x1A // 16 bit
#define STAT_ACC_X 0x1B // 16 bit
#define STAT_ACC_Y 0x1C // 16 bit
#define STAT_ACC_Z 0x1D // 16 bit
// Control registers
#define CTRL_FILT_RATE 0x25 // 9 bit
#define CTRL_FILT_ACC12 0x26 // 9 bit
#define CTRL_FILT_ACC3 0x27 // 9 bit
#define CTRL_RATE 0x28 // 15 bit
#define CTRL_ACC12 0x29 // 15 bit
#define CTRL_ACC3 0x2A // 3 bit
#define CTRL_USER_IF 0x33 // 16 bit
#define CTRL_ST 0x34 // 13 bit
#define CTRL_MODE 0x35 // 4 bit
#define CTRL_RESET 0x36 // 4 bit
// Misc registers
#define ASIC_ID 0x3B // 12 bit
#define COMP_ID 0x3C // 16 bit
#define SN_ID1 0x3D // 16 bit
#define SN_ID2 0x3E // 16 bit
#define SN_ID3 0x3F // 16 bit
// STAT_SUM_SAT bits
#define STAT_SUM_SAT_RSVD (1 << 15)
#define STAT_SUM_SAT_RATE_X1 (1 << 14)
#define STAT_SUM_SAT_RATE_Y1 (1 << 13)
#define STAT_SUM_SAT_RATE_Z1 (1 << 12)
#define STAT_SUM_SAT_ACC_X1 (1 << 11)
#define STAT_SUM_SAT_ACC_Y1 (1 << 10)
#define STAT_SUM_SAT_ACC_Z1 (1 << 9)
#define STAT_SUM_SAT_ACC_X3 (1 << 8)
#define STAT_SUM_SAT_ACC_Y3 (1 << 7)
#define STAT_SUM_SAT_ACC_Z3 (1 << 6)
#define STAT_SUM_SAT_RATE_X2 (1 << 5)
#define STAT_SUM_SAT_RATE_Y2 (1 << 4)
#define STAT_SUM_SAT_RATE_Z2 (1 << 3)
#define STAT_SUM_SAT_ACC_X2 (1 << 2)
#define STAT_SUM_SAT_ACC_Y2 (1 << 1)
#define STAT_SUM_SAT_ACC_Z2 (1 << 0)
} // namespace Murata_SCH16T
File diff suppressed because it is too large Load Diff
+149
View File
@@ -0,0 +1,149 @@
/****************************************************************************
*
* Copyright (c) 2024 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.
*
****************************************************************************/
#pragma once
#include "Murata_SCH16T_registers.hpp"
#include <px4_platform_common/i2c_spi_buses.h>
#include <lib/drivers/accelerometer/PX4Accelerometer.hpp>
#include <lib/drivers/gyroscope/PX4Gyroscope.hpp>
using namespace Murata_SCH16T;
class SCH16T : public device::SPI, public I2CSPIDriver<SCH16T>
{
public:
SCH16T(const I2CSPIDriverConfig &config);
~SCH16T() override;
static void print_usage();
void RunImpl();
int init() override;
void print_status() override;
private:
struct SensorData {
int32_t acc_x;
int32_t acc_y;
int32_t acc_z;
int32_t gyro_x;
int32_t gyro_y;
int32_t gyro_z;
int32_t temp;
};
struct SensorStatus {
uint16_t summary;
uint16_t saturation;
uint16_t common;
uint16_t rate_common;
uint16_t rate_x;
uint16_t rate_y;
uint16_t rate_z;
uint16_t acc_x;
uint16_t acc_y;
uint16_t acc_z;
};
struct RegisterConfig {
RegisterConfig(uint16_t a, uint16_t v)
: addr(a)
, value(v)
{};
uint8_t addr;
uint16_t value;
};
int probe() override;
void exit_and_cleanup() override;
bool ValidateSensorStatus();
bool ValidateRegisterConfiguration();
void Reset();
void ResetSpi6(bool reset);
uint8_t CalculateCRC8(uint64_t frame);
bool ReadData(SensorData *data);
void ReadStatusRegisters();
void Configure();
void SoftwareReset();
void RegisterWrite(uint8_t addr, uint16_t value);
uint64_t RegisterRead(uint8_t addr);
uint64_t TransferSpiFrame(uint64_t frame);
static int DataReadyInterruptCallback(int irq, void *context, void *arg);
void DataReady();
bool DataReadyInterruptConfigure();
bool DataReadyInterruptDisable();
private:
PX4Accelerometer _px4_accel;
PX4Gyroscope _px4_gyro;
SensorStatus _sensor_status{};
int _failure_count{0};
px4::atomic<hrt_abstime> _drdy_timestamp_sample{0};
const spi_drdy_gpio_t _drdy_gpio;
bool _hardware_reset_available{false};
enum class STATE : uint8_t {
RESET_INIT,
RESET_HARD,
CONFIGURE,
LOCK_CONFIGURATION,
VALIDATE,
READ,
} _state{STATE::RESET_INIT};
RegisterConfig _registers[6] = {
RegisterConfig(CTRL_FILT_RATE, FILTER_BYPASS), // Bypass filter
RegisterConfig(CTRL_FILT_ACC12, FILTER_BYPASS), // Bypass filter
RegisterConfig(CTRL_FILT_ACC3, FILTER_BYPASS), // Bypass filter
RegisterConfig(CTRL_RATE, RATE_300DPS_1475HZ), // +/- 300 deg/s, 1600 LSB/(deg/s) -- default, Decimation 8, 1475Hz
RegisterConfig(CTRL_ACC12, ACC12_8G_1475HZ), // +/- 80 m/s^2, 3200 LSB/(m/s^2) -- default, Decimation 8, 1475Hz
RegisterConfig(CTRL_ACC3, ACC3_26G) // +/- 260 m/s^2, 1600 LSB/(m/s^2) -- default
};
perf_counter_t _reset_perf{perf_alloc(PC_COUNT, MODULE_NAME": reset")};
perf_counter_t _bad_transfer_perf{perf_alloc(PC_COUNT, MODULE_NAME": bad transfer")};
perf_counter_t _perf_crc_bad{perf_counter_t(perf_alloc(PC_COUNT, MODULE_NAME": CRC8 bad"))};
perf_counter_t _perf_frame_bad{perf_counter_t(perf_alloc(PC_COUNT, MODULE_NAME": Frame bad"))};
perf_counter_t _drdy_missed_perf{nullptr};
};
@@ -0,0 +1,44 @@
/****************************************************************************
*
* Copyright (c) 2024 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.
*
****************************************************************************/
/**
* Murata SCH16T IMU (external SPI)
*
* @reboot_required true
* @min 0
* @max 1
* @group Sensors
* @value 0 Disabled
* @value 1 Enabled
*/
PARAM_DEFINE_INT32(SENS_EN_SCH16T, 0);
@@ -0,0 +1,87 @@
/****************************************************************************
*
* Copyright (c) 2024 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 "SCH16T.hpp"
#include <px4_platform_common/module.h>
void SCH16T::print_usage()
{
PRINT_MODULE_USAGE_NAME("sch16t", "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_DEFAULT_COMMANDS();
}
extern "C" int sch16t_main(int argc, char *argv[])
{
int ch;
using ThisDriver = SCH16T;
BusCLIArguments cli{false, true};
cli.default_spi_frequency = SPI_SPEED;
cli.spi_mode = SPIDEV_MODE0;
while ((ch = cli.getOpt(argc, argv, "R:")) != EOF) {
switch (ch) {
case 'R':
cli.rotation = (enum Rotation)atoi(cli.optArg());
break;
}
}
const char *verb = cli.optArg();
if (!verb) {
ThisDriver::print_usage();
return -1;
}
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_IMU_DEVTYPE_SCH16T);
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;
}