diff --git a/boards/mro/ctrl-zero-f7/src/board_config.h b/boards/mro/ctrl-zero-f7/src/board_config.h index 5eec0042c0..fce51dcfd4 100644 --- a/boards/mro/ctrl-zero-f7/src/board_config.h +++ b/boards/mro/ctrl-zero-f7/src/board_config.h @@ -109,7 +109,7 @@ #define PX4_SPI_BUS_1_CS_GPIO {GPIO_SPI1_CS1_ICM20602, GPIO_SPI1_CS2_ICM20948} #define PX4_SPIDEV_MEMORY SPIDEV_FLASH(0) -#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(0,DRV_DEVTYPE_DPS310) +#define PX4_SPIDEV_BARO PX4_MK_SPI_SEL(0,DRV_BARO_DEVTYPE_DPS310) #define PX4_SPI_BUS_2_CS_GPIO {GPIO_SPI2_CS1_FRAM, GPIO_SPI2_CS2_BARO} #define PX4_SPIDEV_BMI088_ACC PX4_MK_SPI_SEL(0,DRV_ACC_DEVTYPE_BMI088) diff --git a/boards/mro/ctrl-zero-f7/src/spi.cpp b/boards/mro/ctrl-zero-f7/src/spi.cpp index 90a71ec830..dd5ab9c7db 100644 --- a/boards/mro/ctrl-zero-f7/src/spi.cpp +++ b/boards/mro/ctrl-zero-f7/src/spi.cpp @@ -43,7 +43,7 @@ constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = { }, {GPIO::PortE, GPIO::Pin3}), initSPIBus(2, { initSPIDevice(SPIDEV_FLASH(0), SPI::CS{GPIO::PortD, GPIO::Pin10}), - initSPIDevice(DRV_DEVTYPE_DPS310, SPI::CS{GPIO::PortD, GPIO::Pin7}), + initSPIDevice(DRV_BARO_DEVTYPE_DPS310, SPI::CS{GPIO::PortD, GPIO::Pin7}), }), initSPIBus(5, { initSPIDevice(DRV_GYR_DEVTYPE_BMI088, SPI::CS{GPIO::PortF, GPIO::Pin10}, SPI::DRDY{GPIO::PortF, GPIO::Pin3}), diff --git a/boards/px4/fmu-v5x/src/board_config.h b/boards/px4/fmu-v5x/src/board_config.h index 61ed100e0f..9192f65643 100644 --- a/boards/px4/fmu-v5x/src/board_config.h +++ b/boards/px4/fmu-v5x/src/board_config.h @@ -231,7 +231,7 @@ #define PX4_SPIDEV_ICM_20602 PX4_MK_SPI_SEL(0,DRV_IMU_DEVTYPE_ICM20602) #define PX4_SENSORS1_BUS_CS_GPIO {GPIO_SPI1_nCS1_ICM20602} -#define PX4_SPIDEV_ISM330 PX4_MK_SPI_SEL(0,DRV_DEVTYPE_ST_ISM330DLC) +#define PX4_SPIDEV_ISM330 PX4_MK_SPI_SEL(0,DRV_IMU_DEVTYPE_ST_ISM330DLC) #define PX4_SENSORS2_BUS_CS_GPIO {GPIO_SPI2_nCS1_ISM330} #define PX4_SPIDEV_BMI088_GYR PX4_MK_SPI_SEL(0,DRV_GYR_DEVTYPE_BMI088) diff --git a/boards/px4/fmu-v5x/src/spi.cpp b/boards/px4/fmu-v5x/src/spi.cpp index 4ad043eb17..97b726da10 100644 --- a/boards/px4/fmu-v5x/src/spi.cpp +++ b/boards/px4/fmu-v5x/src/spi.cpp @@ -40,7 +40,7 @@ constexpr px4_spi_bus_t px4_spi_buses[SPI_BUS_MAX_BUS_ITEMS] = { initSPIDevice(DRV_IMU_DEVTYPE_ICM20602, SPI::CS{GPIO::PortI, GPIO::Pin9}, SPI::DRDY{GPIO::PortF, GPIO::Pin2}), }, {GPIO::PortI, GPIO::Pin11}), initSPIBus(2, { - initSPIDevice(DRV_DEVTYPE_ST_ISM330DLC, SPI::CS{GPIO::PortH, GPIO::Pin5}, SPI::DRDY{GPIO::PortH, GPIO::Pin12}), + initSPIDevice(DRV_IMU_DEVTYPE_ST_ISM330DLC, SPI::CS{GPIO::PortH, GPIO::Pin5}, SPI::DRDY{GPIO::PortH, GPIO::Pin12}), }, {GPIO::PortD, GPIO::Pin15}), initSPIBus(3, { initSPIDevice(DRV_GYR_DEVTYPE_BMI088, SPI::CS{GPIO::PortI, GPIO::Pin8}, SPI::DRDY{GPIO::PortI, GPIO::Pin7}), diff --git a/src/drivers/barometer/bmp388/bmp388.cpp b/src/drivers/barometer/bmp388/bmp388.cpp index c6c47e0c80..183e4386eb 100644 --- a/src/drivers/barometer/bmp388/bmp388.cpp +++ b/src/drivers/barometer/bmp388/bmp388.cpp @@ -50,7 +50,7 @@ BMP388::BMP388(IBMP388 *interface) : _measure_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": measure")), _comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors")) { - _px4_baro.set_device_type(DRV_DEVTYPE_BMP388); + _px4_baro.set_device_type(DRV_BARO_DEVTYPE_BMP388); } BMP388::~BMP388() diff --git a/src/drivers/barometer/dps310/DPS310.cpp b/src/drivers/barometer/dps310/DPS310.cpp index c9073af825..df3f95f858 100644 --- a/src/drivers/barometer/dps310/DPS310.cpp +++ b/src/drivers/barometer/dps310/DPS310.cpp @@ -53,7 +53,7 @@ DPS310::DPS310(device::Device *interface) : _sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")), _comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comm errors")) { - _px4_barometer.set_device_type(DRV_DEVTYPE_DPS310); + _px4_barometer.set_device_type(DRV_BARO_DEVTYPE_DPS310); } DPS310::~DPS310() diff --git a/src/drivers/drv_sensor.h b/src/drivers/drv_sensor.h index 93196679b9..6a5bdc20cb 100644 --- a/src/drivers/drv_sensor.h +++ b/src/drivers/drv_sensor.h @@ -61,21 +61,19 @@ #define DRV_MAG_DEVTYPE_RM3100 0x07 #define DRV_MAG_DEVTYPE_QMC5883 0x08 #define DRV_MAG_DEVTYPE_AK09916 0x09 -#define DRV_DEVTYPE_ICM20948 0x0A +#define DRV_IMU_DEVTYPE_ICM20948 0x0A #define DRV_ACC_DEVTYPE_LSM303D 0x11 #define DRV_ACC_DEVTYPE_BMA180 0x12 -#define DRV_ACC_DEVTYPE_MPU6000 0x13 // TODO: remove this +#define DRV_ACC_DEVTYPE_MPU6000_LEGACY 0x13 #define DRV_ACC_DEVTYPE_ACCELSIM 0x14 -#define DRV_ACC_DEVTYPE_MPU9250 0x16 // TOOD: remove this +#define DRV_ACC_DEVTYPE_MPU9250_LEGACY 0x16 #define DRV_ACC_DEVTYPE_BMI160 0x17 -#define DRV_GYR_DEVTYPE_MPU6000 0x21 -#define DRV_IMU_DEVTYPE_MPU6000 DRV_GYR_DEVTYPE_MPU6000 +#define DRV_IMU_DEVTYPE_MPU6000 0x21 #define DRV_GYR_DEVTYPE_L3GD20 0x22 #define DRV_GYR_DEVTYPE_GYROSIM 0x23 -#define DRV_GYR_DEVTYPE_MPU9250 0x24 -#define DRV_IMU_DEVTYPE_MPU9250 DRV_GYR_DEVTYPE_MPU9250 +#define DRV_IMU_DEVTYPE_MPU9250 0x24 #define DRV_GYR_DEVTYPE_BMI160 0x25 #define DRV_RNG_DEVTYPE_MB12XX 0x31 @@ -84,15 +82,12 @@ #define DRV_ACC_DEVTYPE_MPU6500 0x34 #define DRV_GYR_DEVTYPE_MPU6050 0x35 #define DRV_GYR_DEVTYPE_MPU6500 0x36 -#define DRV_ACC_DEVTYPE_ICM20602 0x37 // TODO: remove this -#define DRV_GYR_DEVTYPE_ICM20602 0x38 -#define DRV_IMU_DEVTYPE_ICM20602 DRV_GYR_DEVTYPE_ICM20602 -#define DRV_ACC_DEVTYPE_ICM20608 0x39 -#define DRV_GYR_DEVTYPE_ICM20608 0x3A // TODO: remove this -#define DRV_IMU_DEVTYPE_ICM20608 DRV_GYR_DEVTYPE_ICM20608 -#define DRV_ACC_DEVTYPE_ICM20689 0x3B -#define DRV_GYR_DEVTYPE_ICM20689 0x3C // TODO: remove this -#define DRV_IMU_DEVTYPE_ICM20689 DRV_GYR_DEVTYPE_ICM20689 +#define DRV_ACC_DEVTYPE_ICM20602_LEGACY 0x37 +#define DRV_IMU_DEVTYPE_ICM20602 0x38 +#define DRV_ACC_DEVTYPE_ICM20608_LEGACY 0x39 +#define DRV_IMU_DEVTYPE_ICM20608 0x3A +#define DRV_ACC_DEVTYPE_ICM20689_LEGACY 0x3B +#define DRV_IMU_DEVTYPE_ICM20689 0x3C #define DRV_BARO_DEVTYPE_MS5611 0x3D #define DRV_BARO_DEVTYPE_MS5607 0x3E #define DRV_BARO_DEVTYPE_BMP280 0x3F @@ -126,9 +121,9 @@ #define DRV_GYR_DEVTYPE_ADIS16497 0x64 #define DRV_BARO_DEVTYPE_BAROSIM 0x65 #define DRV_GYR_DEVTYPE_BMI088 0x66 -#define DRV_DEVTYPE_BMP388 0x67 -#define DRV_DEVTYPE_DPS310 0x68 -#define DRV_DEVTYPE_ST_ISM330DLC 0x69 +#define DRV_BARO_DEVTYPE_BMP388 0x67 +#define DRV_BARO_DEVTYPE_DPS310 0x68 +#define DRV_IMU_DEVTYPE_ST_ISM330DLC 0x69 #define DRV_ACC_DEVTYPE_BMI088 0x6a #define DRV_OSD_DEVTYPE_ATXXXX 0x6b #define DRV_FLOW_DEVTYPE_PMW3901 0x6c diff --git a/src/drivers/imu/bmi088/BMI088_accel.cpp b/src/drivers/imu/bmi088/BMI088_accel.cpp index 96182032cd..beb1a31682 100644 --- a/src/drivers/imu/bmi088/BMI088_accel.cpp +++ b/src/drivers/imu/bmi088/BMI088_accel.cpp @@ -62,7 +62,7 @@ BMI088_accel::BMI088_accel(int bus, const char *path_accel, uint32_t device, enu _duplicates(perf_alloc(PC_COUNT, "bmi088_accel_duplicates")), _got_duplicate(false) { - _px4_accel.set_device_type(DRV_GYR_DEVTYPE_BMI088); + _px4_accel.set_device_type(DRV_ACC_DEVTYPE_BMI088); } BMI088_accel::~BMI088_accel() diff --git a/src/drivers/imu/icm20948/icm20948.cpp b/src/drivers/imu/icm20948/icm20948.cpp index 81df4f663f..7011770d71 100644 --- a/src/drivers/imu/icm20948/icm20948.cpp +++ b/src/drivers/imu/icm20948/icm20948.cpp @@ -100,8 +100,8 @@ ICM20948::ICM20948(device::Device *interface, device::Device *mag_interface, enu _good_transfers(perf_alloc(PC_COUNT, MODULE_NAME": good_trans")), _duplicates(perf_alloc(PC_COUNT, MODULE_NAME": dupe")) { - _px4_accel.set_device_type(DRV_DEVTYPE_ICM20948); - _px4_gyro.set_device_type(DRV_DEVTYPE_ICM20948); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_ICM20948); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_ICM20948); } ICM20948::~ICM20948() diff --git a/src/drivers/imu/icm20948/icm20948_i2c.cpp b/src/drivers/imu/icm20948/icm20948_i2c.cpp index 938ebf8d16..3e18e2a34d 100644 --- a/src/drivers/imu/icm20948/icm20948_i2c.cpp +++ b/src/drivers/imu/icm20948/icm20948_i2c.cpp @@ -72,7 +72,7 @@ ICM20948_I2C_interface(int bus, uint32_t address) ICM20948_I2C::ICM20948_I2C(int bus, uint32_t address) : I2C("ICM20948_I2C", nullptr, bus, address, 400000) { - _device_id.devid_s.devtype = DRV_DEVTYPE_ICM20948; + _device_id.devid_s.devtype = DRV_IMU_DEVTYPE_ICM20948; } int diff --git a/src/drivers/imu/icm20948/icm20948_spi.cpp b/src/drivers/imu/icm20948/icm20948_spi.cpp index 94b714e0d4..0b8619e29f 100644 --- a/src/drivers/imu/icm20948/icm20948_spi.cpp +++ b/src/drivers/imu/icm20948/icm20948_spi.cpp @@ -92,7 +92,7 @@ ICM20948_SPI_interface(int bus, uint32_t cs) ICM20948_SPI::ICM20948_SPI(int bus, uint32_t device) : SPI("ICM20948", nullptr, bus, device, SPIDEV_MODE3, ICM20948_LOW_SPI_BUS_SPEED) { - _device_id.devid_s.devtype = DRV_DEVTYPE_ICM20948; + _device_id.devid_s.devtype = DRV_IMU_DEVTYPE_ICM20948; } void diff --git a/src/drivers/imu/icm20948/mag_i2c.cpp b/src/drivers/imu/icm20948/mag_i2c.cpp index 39827b6231..3ac0eb077a 100644 --- a/src/drivers/imu/icm20948/mag_i2c.cpp +++ b/src/drivers/imu/icm20948/mag_i2c.cpp @@ -69,7 +69,7 @@ AK09916_I2C_interface(int bus) AK09916_I2C::AK09916_I2C(int bus) : I2C("AK09916_I2C", nullptr, bus, AK09916_I2C_ADDR, 400000) { - _device_id.devid_s.devtype = DRV_DEVTYPE_ICM20948; + _device_id.devid_s.devtype = DRV_IMU_DEVTYPE_ICM20948; } int diff --git a/src/drivers/imu/invensense/icm20602/ICM20602.cpp b/src/drivers/imu/invensense/icm20602/ICM20602.cpp index 9e6508935c..69d9142ab0 100644 --- a/src/drivers/imu/invensense/icm20602/ICM20602.cpp +++ b/src/drivers/imu/invensense/icm20602/ICM20602.cpp @@ -48,10 +48,9 @@ ICM20602::ICM20602(int bus, uint32_t device, enum Rotation rotation) : _px4_accel(get_device_id(), ORB_PRIO_VERY_HIGH, rotation), _px4_gyro(get_device_id(), ORB_PRIO_VERY_HIGH, rotation) { - set_device_type(DRV_ACC_DEVTYPE_ICM20602); - - _px4_accel.set_device_type(DRV_ACC_DEVTYPE_ICM20602); - _px4_gyro.set_device_type(DRV_GYR_DEVTYPE_ICM20602); + set_device_type(DRV_IMU_DEVTYPE_ICM20602); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_ICM20602); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_ICM20602); ConfigureSampleRate(_px4_gyro.get_max_rate_hz()); } diff --git a/src/drivers/imu/invensense/icm20608g/ICM20608G.cpp b/src/drivers/imu/invensense/icm20608g/ICM20608G.cpp index 811bb3b8d8..d42bab8472 100644 --- a/src/drivers/imu/invensense/icm20608g/ICM20608G.cpp +++ b/src/drivers/imu/invensense/icm20608g/ICM20608G.cpp @@ -48,10 +48,10 @@ ICM20608G::ICM20608G(int bus, uint32_t device, enum Rotation rotation) : _px4_accel(get_device_id(), ORB_PRIO_VERY_HIGH, rotation), _px4_gyro(get_device_id(), ORB_PRIO_VERY_HIGH, rotation) { - set_device_type(DRV_ACC_DEVTYPE_ICM20608); + set_device_type(DRV_IMU_DEVTYPE_ICM20608); - _px4_accel.set_device_type(DRV_ACC_DEVTYPE_ICM20608); - _px4_gyro.set_device_type(DRV_GYR_DEVTYPE_ICM20608); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_ICM20608); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_ICM20608); ConfigureSampleRate(_px4_gyro.get_max_rate_hz()); } diff --git a/src/drivers/imu/invensense/icm20689/ICM20689.cpp b/src/drivers/imu/invensense/icm20689/ICM20689.cpp index e40e5b7b6b..33239604ff 100644 --- a/src/drivers/imu/invensense/icm20689/ICM20689.cpp +++ b/src/drivers/imu/invensense/icm20689/ICM20689.cpp @@ -48,10 +48,9 @@ ICM20689::ICM20689(int bus, uint32_t device, enum Rotation rotation) : _px4_accel(get_device_id(), ORB_PRIO_VERY_HIGH, rotation), _px4_gyro(get_device_id(), ORB_PRIO_VERY_HIGH, rotation) { - set_device_type(DRV_ACC_DEVTYPE_ICM20689); - - _px4_accel.set_device_type(DRV_ACC_DEVTYPE_ICM20689); - _px4_gyro.set_device_type(DRV_GYR_DEVTYPE_ICM20689); + set_device_type(DRV_IMU_DEVTYPE_ICM20689); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_ICM20689); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_ICM20689); ConfigureSampleRate(_px4_gyro.get_max_rate_hz()); } diff --git a/src/drivers/imu/invensense/mpu6000/MPU6000.cpp b/src/drivers/imu/invensense/mpu6000/MPU6000.cpp index d50e37a69e..b40ffdfcc7 100644 --- a/src/drivers/imu/invensense/mpu6000/MPU6000.cpp +++ b/src/drivers/imu/invensense/mpu6000/MPU6000.cpp @@ -54,9 +54,9 @@ MPU6000::MPU6000(int bus, uint32_t device, enum Rotation rotation) : _px4_accel(get_device_id(), ORB_PRIO_VERY_HIGH, rotation), _px4_gyro(get_device_id(), ORB_PRIO_VERY_HIGH, rotation) { - set_device_type(DRV_ACC_DEVTYPE_MPU6000); - _px4_accel.set_device_type(DRV_ACC_DEVTYPE_MPU6000); - _px4_gyro.set_device_type(DRV_GYR_DEVTYPE_MPU6000); + set_device_type(DRV_IMU_DEVTYPE_MPU6000); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_MPU6000); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_MPU6000); _px4_accel.set_update_rate(1000000 / FIFO_INTERVAL); _px4_gyro.set_update_rate(1000000 / FIFO_INTERVAL); diff --git a/src/drivers/imu/invensense/mpu9250/MPU9250.cpp b/src/drivers/imu/invensense/mpu9250/MPU9250.cpp index f459984a79..9b8252aaa4 100644 --- a/src/drivers/imu/invensense/mpu9250/MPU9250.cpp +++ b/src/drivers/imu/invensense/mpu9250/MPU9250.cpp @@ -48,10 +48,9 @@ MPU9250::MPU9250(int bus, uint32_t device, enum Rotation rotation) : _px4_accel(get_device_id(), ORB_PRIO_VERY_HIGH, rotation), _px4_gyro(get_device_id(), ORB_PRIO_VERY_HIGH, rotation) { - set_device_type(DRV_ACC_DEVTYPE_MPU9250); - - _px4_accel.set_device_type(DRV_ACC_DEVTYPE_MPU9250); - _px4_gyro.set_device_type(DRV_GYR_DEVTYPE_MPU9250); + set_device_type(DRV_IMU_DEVTYPE_MPU9250); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_MPU9250); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_MPU9250); ConfigureSampleRate(_px4_gyro.get_max_rate_hz()); } diff --git a/src/drivers/imu/mpu6000/MPU6000.cpp b/src/drivers/imu/mpu6000/MPU6000.cpp index 7bbb0e97e3..2b8e3efffc 100644 --- a/src/drivers/imu/mpu6000/MPU6000.cpp +++ b/src/drivers/imu/mpu6000/MPU6000.cpp @@ -54,23 +54,23 @@ MPU6000::MPU6000(device::Device *interface, enum Rotation rotation, int device_t switch (_device_type) { default: case MPU_DEVICE_TYPE_MPU6000: - _px4_accel.set_device_type(DRV_ACC_DEVTYPE_MPU6000); - _px4_gyro.set_device_type(DRV_GYR_DEVTYPE_MPU6000); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_MPU6000); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_MPU6000); break; case MPU_DEVICE_TYPE_ICM20602: - _px4_accel.set_device_type(DRV_ACC_DEVTYPE_ICM20602); - _px4_gyro.set_device_type(DRV_GYR_DEVTYPE_ICM20602); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_ICM20602); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_ICM20602); break; case MPU_DEVICE_TYPE_ICM20608: - _px4_accel.set_device_type(DRV_ACC_DEVTYPE_ICM20608); - _px4_gyro.set_device_type(DRV_GYR_DEVTYPE_ICM20608); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_ICM20608); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_ICM20608); break; case MPU_DEVICE_TYPE_ICM20689: - _px4_accel.set_device_type(DRV_ACC_DEVTYPE_ICM20689); - _px4_gyro.set_device_type(DRV_GYR_DEVTYPE_ICM20689); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_ICM20689); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_ICM20689); break; } } diff --git a/src/drivers/imu/mpu9250/mpu9250.cpp b/src/drivers/imu/mpu9250/mpu9250.cpp index 39f89c009c..336db75f86 100644 --- a/src/drivers/imu/mpu9250/mpu9250.cpp +++ b/src/drivers/imu/mpu9250/mpu9250.cpp @@ -81,8 +81,8 @@ MPU9250::MPU9250(device::Device *interface, device::Device *mag_interface, enum _bad_registers(perf_alloc(PC_COUNT, MODULE_NAME": bad_reg")), _duplicates(perf_alloc(PC_COUNT, MODULE_NAME": dupe")) { - _px4_accel.set_device_type(DRV_ACC_DEVTYPE_MPU9250); - _px4_gyro.set_device_type(DRV_GYR_DEVTYPE_MPU9250); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_MPU9250); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_MPU9250); } MPU9250::~MPU9250() diff --git a/src/drivers/imu/mpu9250/mpu9250_i2c.cpp b/src/drivers/imu/mpu9250/mpu9250_i2c.cpp index fbd19c2e56..7704838fa1 100644 --- a/src/drivers/imu/mpu9250/mpu9250_i2c.cpp +++ b/src/drivers/imu/mpu9250/mpu9250_i2c.cpp @@ -70,7 +70,7 @@ MPU9250_I2C_interface(int bus, uint32_t address) MPU9250_I2C::MPU9250_I2C(int bus, uint32_t address) : I2C("MPU9250_I2C", nullptr, bus, address, 400000) { - set_device_type(DRV_ACC_DEVTYPE_MPU9250); + set_device_type(DRV_IMU_DEVTYPE_MPU9250); } int diff --git a/src/drivers/imu/mpu9250/mpu9250_spi.cpp b/src/drivers/imu/mpu9250/mpu9250_spi.cpp index 38c25ffe2d..2badcf0f05 100644 --- a/src/drivers/imu/mpu9250/mpu9250_spi.cpp +++ b/src/drivers/imu/mpu9250/mpu9250_spi.cpp @@ -88,7 +88,7 @@ MPU9250_SPI_interface(int bus, uint32_t cs) MPU9250_SPI::MPU9250_SPI(int bus, uint32_t device) : SPI("MPU9250", nullptr, bus, device, SPIDEV_MODE3, MPU9250_LOW_SPI_BUS_SPEED) { - set_device_type(DRV_ACC_DEVTYPE_MPU9250); + set_device_type(DRV_IMU_DEVTYPE_MPU9250); } void diff --git a/src/drivers/imu/st/ism330dlc/ISM330DLC.cpp b/src/drivers/imu/st/ism330dlc/ISM330DLC.cpp index 62cef7de94..68ad0bb2af 100644 --- a/src/drivers/imu/st/ism330dlc/ISM330DLC.cpp +++ b/src/drivers/imu/st/ism330dlc/ISM330DLC.cpp @@ -48,9 +48,9 @@ ISM330DLC::ISM330DLC(int bus, uint32_t device, enum Rotation rotation) : _px4_accel(get_device_id(), ORB_PRIO_DEFAULT, rotation), _px4_gyro(get_device_id(), ORB_PRIO_DEFAULT, rotation) { - set_device_type(DRV_DEVTYPE_ST_ISM330DLC); - _px4_accel.set_device_type(DRV_DEVTYPE_ST_ISM330DLC); - _px4_gyro.set_device_type(DRV_DEVTYPE_ST_ISM330DLC); + set_device_type(DRV_IMU_DEVTYPE_ST_ISM330DLC); + _px4_accel.set_device_type(DRV_IMU_DEVTYPE_ST_ISM330DLC); + _px4_gyro.set_device_type(DRV_IMU_DEVTYPE_ST_ISM330DLC); _px4_accel.set_update_rate(1000000 / FIFO_INTERVAL); _px4_gyro.set_update_rate(1000000 / FIFO_INTERVAL); diff --git a/src/lib/drivers/device/nuttx/SPI.cpp b/src/lib/drivers/device/nuttx/SPI.cpp index 413b717980..d6eab6ebe3 100644 --- a/src/lib/drivers/device/nuttx/SPI.cpp +++ b/src/lib/drivers/device/nuttx/SPI.cpp @@ -67,7 +67,9 @@ SPI::SPI(const char *name, const char *devname, int bus, uint32_t device, enum s // fill in _device_id fields for a SPI device _device_id.devid_s.bus_type = DeviceBusType_SPI; _device_id.devid_s.bus = bus; - _device_id.devid_s.address = (uint8_t)device; + // Use the 2. LSB byte as SPI address. This is currently 0, but will allow to extend + // for multiple instances of the same device on a bus, should that ever be required. + _device_id.devid_s.address = (uint8_t)(device >> 8); // devtype needs to be filled in by the driver _device_id.devid_s.devtype = 0; diff --git a/src/lib/parameters/CMakeLists.txt b/src/lib/parameters/CMakeLists.txt index 6ee0255856..7845e8c2ff 100644 --- a/src/lib/parameters/CMakeLists.txt +++ b/src/lib/parameters/CMakeLists.txt @@ -128,6 +128,11 @@ if ("${CONFIG_SHMEM}" STREQUAL "1") list(APPEND SRCS parameters_shmem.cpp) else() list(APPEND SRCS parameters.cpp) + if(PX4_TESTING) + list(APPEND SRCS param_translation_unit_tests.cpp) + else() + list(APPEND SRCS param_translation.cpp) + endif() endif() if(${PX4_PLATFORM} STREQUAL "nuttx") diff --git a/src/lib/parameters/flashparams/flashparams.cpp b/src/lib/parameters/flashparams/flashparams.cpp index c04f0f8574..561c9bf241 100644 --- a/src/lib/parameters/flashparams/flashparams.cpp +++ b/src/lib/parameters/flashparams/flashparams.cpp @@ -57,6 +57,7 @@ #include #include "flashparams.h" #include "flashfs.h" +#include "../param_translation.h" #if 0 # define debug(fmt, args...) do { warnx(fmt, ##args); } while(0) @@ -300,6 +301,8 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node) goto out; } + param_modify_on_import(node->name, node->type, v); + if (param_set_external(param, v, state->mark_saved, true)) { debug("error setting value for '%s'", node->name); diff --git a/src/lib/parameters/param_translation.cpp b/src/lib/parameters/param_translation.cpp new file mode 100644 index 0000000000..db34a577b0 --- /dev/null +++ b/src/lib/parameters/param_translation.cpp @@ -0,0 +1,126 @@ +/**************************************************************************** + * + * Copyright (c) 2020 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 "param_translation.h" + + +#include +#include +#include + +bool param_modify_on_import(const char *name, bson_type_t type, void *value) +{ + // translate (SPI) calibration ID parameters. This can be removed after the next release (current release=1.10) + + if (type != BSON_INT32) { + return false; + } + + int32_t *ivalue = (int32_t *)value; + + const char *cal_id_params[] = { + "CAL_ACC0_ID", + "CAL_GYRO0_ID", + "CAL_MAG0_ID", + "TC_A0_ID", + "TC_B0_ID", + "TC_G0_ID", + "CAL_ACC1_ID", + "CAL_GYRO1_ID", + "CAL_MAG1_ID", + "TC_A1_ID", + "TC_B1_ID", + "TC_G1_ID", + "CAL_ACC2_ID", + "CAL_GYRO2_ID", + "CAL_MAG2_ID", + "TC_A2_ID", + "TC_B2_ID", + "TC_G2_ID", + "CAL_ACC_PRIME", + "CAL_GYRO_PRIME", + "CAL_MAG_PRIME", + }; + bool found = false; + + for (int i = 0; i < sizeof(cal_id_params) / sizeof(cal_id_params[0]); ++i) { + if (strcmp(cal_id_params[i], name) == 0) { + found = true; + break; + } + } + + if (!found) { + return false; + } + + + device::Device::DeviceId device_id; + device_id.devid = (uint32_t) * ivalue; + + // SPI board config translation + if (device_id.devid_s.bus_type == device::Device::DeviceBusType_SPI) { + device_id.devid_s.address = 0; + } + + // deprecated ACC -> IMU translations + if (device_id.devid_s.devtype == DRV_ACC_DEVTYPE_MPU6000_LEGACY) { + device_id.devid_s.devtype = DRV_IMU_DEVTYPE_MPU6000; + } + + if (device_id.devid_s.devtype == DRV_ACC_DEVTYPE_MPU9250_LEGACY) { + device_id.devid_s.devtype = DRV_IMU_DEVTYPE_MPU9250; + } + + if (device_id.devid_s.devtype == DRV_ACC_DEVTYPE_ICM20602_LEGACY) { + device_id.devid_s.devtype = DRV_IMU_DEVTYPE_ICM20602; + } + + if (device_id.devid_s.devtype == DRV_ACC_DEVTYPE_ICM20608_LEGACY) { + device_id.devid_s.devtype = DRV_IMU_DEVTYPE_ICM20608; + } + + if (device_id.devid_s.devtype == DRV_ACC_DEVTYPE_ICM20689_LEGACY) { + device_id.devid_s.devtype = DRV_IMU_DEVTYPE_ICM20689; + } + + int32_t new_value = (int32_t)device_id.devid; + + if (new_value != *ivalue) { + PX4_INFO("param modify: %s, value=0x%x (old=0x%x)", name, new_value, *ivalue); + *ivalue = new_value; + return true; + } + + return false; +} diff --git a/src/lib/parameters/param_translation.h b/src/lib/parameters/param_translation.h new file mode 100644 index 0000000000..80f0f3e203 --- /dev/null +++ b/src/lib/parameters/param_translation.h @@ -0,0 +1,39 @@ +/**************************************************************************** + * + * Copyright (c) 2020 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 "tinybson/tinybson.h" + +__EXPORT bool param_modify_on_import(const char *name, bson_type_t type, void *value); + diff --git a/src/lib/parameters/param_translation_unit_tests.cpp b/src/lib/parameters/param_translation_unit_tests.cpp new file mode 100644 index 0000000000..7aa3fbe875 --- /dev/null +++ b/src/lib/parameters/param_translation_unit_tests.cpp @@ -0,0 +1,40 @@ +/**************************************************************************** + * + * Copyright (c) 2020 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 "param_translation.h" + +bool param_modify_on_import(const char *name, bson_type_t type, void *value) +{ + // don't modify params for unit tests + return false; +} diff --git a/src/lib/parameters/parameters.cpp b/src/lib/parameters/parameters.cpp index f768d62a31..f7ccfdd8e6 100644 --- a/src/lib/parameters/parameters.cpp +++ b/src/lib/parameters/parameters.cpp @@ -42,6 +42,7 @@ */ #include "param.h" +#include "param_translation.h" #include #include "tinybson/tinybson.h" @@ -1261,6 +1262,8 @@ param_import_callback(bson_decoder_t decoder, void *priv, bson_node_t node) goto out; } + param_modify_on_import(node->name, node->type, v); + if (param_set_internal(param, v, state->mark_saved, true)) { PX4_DEBUG("error setting value for '%s'", node->name); goto out;