icm20948_i2c_passthrough: allow to configure i2c address

This commit is contained in:
Roman Dvořák 2021-06-25 07:50:31 +02:00 committed by GitHub
parent d79229f958
commit ab0e3b6001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 9 deletions

View File

@ -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)
{
}

View File

@ -53,7 +53,7 @@ using namespace InvenSense_ICM20948;
class ICM20948_I2C_Passthrough : public device::I2C, public I2CSPIDriver<ICM20948_I2C_Passthrough>
{
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,

View File

@ -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;

View File

@ -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);