From ab0e3b6001a04481280770f3db24b41675f52b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Dvo=C5=99=C3=A1k?= Date: Fri, 25 Jun 2021 07:50:31 +0200 Subject: [PATCH] icm20948_i2c_passthrough: allow to configure i2c address --- .../imu/invensense/icm20948/ICM20948_I2C_Passthrough.cpp | 7 ++++--- .../imu/invensense/icm20948/ICM20948_I2C_Passthrough.hpp | 2 +- .../invensense/icm20948/InvenSense_ICM20948_registers.hpp | 4 ++-- .../invensense/icm20948/icm20948_i2c_passthrough_main.cpp | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/drivers/imu/invensense/icm20948/ICM20948_I2C_Passthrough.cpp b/src/drivers/imu/invensense/icm20948/ICM20948_I2C_Passthrough.cpp index a3267f39c3..ebdf3e00b1 100644 --- a/src/drivers/imu/invensense/icm20948/ICM20948_I2C_Passthrough.cpp +++ b/src/drivers/imu/invensense/icm20948/ICM20948_I2C_Passthrough.cpp @@ -40,9 +40,10 @@ static constexpr int16_t combine(uint8_t msb, uint8_t lsb) return (msb << 8u) | lsb; } -ICM20948_I2C_Passthrough::ICM20948_I2C_Passthrough(I2CSPIBusOption bus_option, int bus, int bus_frequency) : - I2C(DRV_IMU_DEVTYPE_ICM20948, MODULE_NAME, bus, I2C_ADDRESS_DEFAULT, bus_frequency), - I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus) +ICM20948_I2C_Passthrough::ICM20948_I2C_Passthrough(I2CSPIBusOption bus_option, int bus, int bus_frequency, + const int address) : + I2C(DRV_IMU_DEVTYPE_ICM20948, MODULE_NAME, bus, address, bus_frequency), + I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address) { } diff --git a/src/drivers/imu/invensense/icm20948/ICM20948_I2C_Passthrough.hpp b/src/drivers/imu/invensense/icm20948/ICM20948_I2C_Passthrough.hpp index c0755a4b7e..76ff259ce0 100644 --- a/src/drivers/imu/invensense/icm20948/ICM20948_I2C_Passthrough.hpp +++ b/src/drivers/imu/invensense/icm20948/ICM20948_I2C_Passthrough.hpp @@ -53,7 +53,7 @@ using namespace InvenSense_ICM20948; class ICM20948_I2C_Passthrough : public device::I2C, public I2CSPIDriver { public: - ICM20948_I2C_Passthrough(I2CSPIBusOption bus_option, int bus, int bus_frequency); + ICM20948_I2C_Passthrough(I2CSPIBusOption bus_option, int bus, int bus_frequency, const int address); ~ICM20948_I2C_Passthrough() override; static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator, diff --git a/src/drivers/imu/invensense/icm20948/InvenSense_ICM20948_registers.hpp b/src/drivers/imu/invensense/icm20948/InvenSense_ICM20948_registers.hpp index c4a26cce6c..12fcbdbd62 100644 --- a/src/drivers/imu/invensense/icm20948/InvenSense_ICM20948_registers.hpp +++ b/src/drivers/imu/invensense/icm20948/InvenSense_ICM20948_registers.hpp @@ -54,8 +54,8 @@ static constexpr uint8_t Bit5 = (1 << 5); static constexpr uint8_t Bit6 = (1 << 6); static constexpr uint8_t Bit7 = (1 << 7); -static constexpr uint32_t I2C_SPEED = 400 * 1000; // 400 kHz I2C serial interface -static constexpr uint8_t I2C_ADDRESS_DEFAULT = 0b1101001; +static constexpr uint32_t I2C_SPEED = 100 * 1000; // 100 kHz I2C serial interface +static constexpr uint8_t I2C_ADDRESS_DEFAULT = 0x69; // 0b1101001 static constexpr uint32_t SPI_SPEED = 7 * 1000 * 1000; // 7 MHz SPI static constexpr uint8_t DIR_READ = 0x80; diff --git a/src/drivers/imu/invensense/icm20948/icm20948_i2c_passthrough_main.cpp b/src/drivers/imu/invensense/icm20948/icm20948_i2c_passthrough_main.cpp index d8f4ffdc07..5230399d51 100644 --- a/src/drivers/imu/invensense/icm20948/icm20948_i2c_passthrough_main.cpp +++ b/src/drivers/imu/invensense/icm20948/icm20948_i2c_passthrough_main.cpp @@ -42,8 +42,7 @@ void ICM20948_I2C_Passthrough::print_usage() PRINT_MODULE_USAGE_SUBCATEGORY("imu"); PRINT_MODULE_USAGE_COMMAND("start"); PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false); - PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x39); - PRINT_MODULE_USAGE_PARAM_INT('R', 0, 0, 35, "Rotation", true); + PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x69); PRINT_MODULE_USAGE_DEFAULT_COMMANDS(); } @@ -51,7 +50,7 @@ I2CSPIDriverBase *ICM20948_I2C_Passthrough::instantiate(const BusCLIArguments &c int runtime_instance) { ICM20948_I2C_Passthrough *instance = new ICM20948_I2C_Passthrough(iterator.configuredBusOption(), iterator.bus(), - cli.bus_frequency); + cli.bus_frequency, cli.i2c_address); if (!instance) { PX4_ERR("alloc failed"); @@ -71,6 +70,7 @@ extern "C" int icm20948_i2c_passthrough_main(int argc, char *argv[]) using ThisDriver = ICM20948_I2C_Passthrough; BusCLIArguments cli{true, false}; cli.default_i2c_frequency = I2C_SPEED; + cli.i2c_address = I2C_ADDRESS_DEFAULT; const char *verb = cli.parseDefaultArguments(argc, argv);