mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
icm20948_i2c_passthrough: allow to configure i2c address
This commit is contained in:
@@ -40,9 +40,10 @@ static constexpr int16_t combine(uint8_t msb, uint8_t lsb)
|
|||||||
return (msb << 8u) | lsb;
|
return (msb << 8u) | lsb;
|
||||||
}
|
}
|
||||||
|
|
||||||
ICM20948_I2C_Passthrough::ICM20948_I2C_Passthrough(I2CSPIBusOption bus_option, int bus, int bus_frequency) :
|
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),
|
const int address) :
|
||||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus)
|
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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ using namespace InvenSense_ICM20948;
|
|||||||
class ICM20948_I2C_Passthrough : public device::I2C, public I2CSPIDriver<ICM20948_I2C_Passthrough>
|
class ICM20948_I2C_Passthrough : public device::I2C, public I2CSPIDriver<ICM20948_I2C_Passthrough>
|
||||||
{
|
{
|
||||||
public:
|
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;
|
~ICM20948_I2C_Passthrough() override;
|
||||||
|
|
||||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ static constexpr uint8_t Bit5 = (1 << 5);
|
|||||||
static constexpr uint8_t Bit6 = (1 << 6);
|
static constexpr uint8_t Bit6 = (1 << 6);
|
||||||
static constexpr uint8_t Bit7 = (1 << 7);
|
static constexpr uint8_t Bit7 = (1 << 7);
|
||||||
|
|
||||||
static constexpr uint32_t I2C_SPEED = 400 * 1000; // 400 kHz I2C serial interface
|
static constexpr uint32_t I2C_SPEED = 100 * 1000; // 100 kHz I2C serial interface
|
||||||
static constexpr uint8_t I2C_ADDRESS_DEFAULT = 0b1101001;
|
static constexpr uint8_t I2C_ADDRESS_DEFAULT = 0x69; // 0b1101001
|
||||||
|
|
||||||
static constexpr uint32_t SPI_SPEED = 7 * 1000 * 1000; // 7 MHz SPI
|
static constexpr uint32_t SPI_SPEED = 7 * 1000 * 1000; // 7 MHz SPI
|
||||||
static constexpr uint8_t DIR_READ = 0x80;
|
static constexpr uint8_t DIR_READ = 0x80;
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ void ICM20948_I2C_Passthrough::print_usage()
|
|||||||
PRINT_MODULE_USAGE_SUBCATEGORY("imu");
|
PRINT_MODULE_USAGE_SUBCATEGORY("imu");
|
||||||
PRINT_MODULE_USAGE_COMMAND("start");
|
PRINT_MODULE_USAGE_COMMAND("start");
|
||||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x39);
|
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x69);
|
||||||
PRINT_MODULE_USAGE_PARAM_INT('R', 0, 0, 35, "Rotation", true);
|
|
||||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +50,7 @@ I2CSPIDriverBase *ICM20948_I2C_Passthrough::instantiate(const BusCLIArguments &c
|
|||||||
int runtime_instance)
|
int runtime_instance)
|
||||||
{
|
{
|
||||||
ICM20948_I2C_Passthrough *instance = new ICM20948_I2C_Passthrough(iterator.configuredBusOption(), iterator.bus(),
|
ICM20948_I2C_Passthrough *instance = new ICM20948_I2C_Passthrough(iterator.configuredBusOption(), iterator.bus(),
|
||||||
cli.bus_frequency);
|
cli.bus_frequency, cli.i2c_address);
|
||||||
|
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
PX4_ERR("alloc failed");
|
PX4_ERR("alloc failed");
|
||||||
@@ -71,6 +70,7 @@ extern "C" int icm20948_i2c_passthrough_main(int argc, char *argv[])
|
|||||||
using ThisDriver = ICM20948_I2C_Passthrough;
|
using ThisDriver = ICM20948_I2C_Passthrough;
|
||||||
BusCLIArguments cli{true, false};
|
BusCLIArguments cli{true, false};
|
||||||
cli.default_i2c_frequency = I2C_SPEED;
|
cli.default_i2c_frequency = I2C_SPEED;
|
||||||
|
cli.i2c_address = I2C_ADDRESS_DEFAULT;
|
||||||
|
|
||||||
const char *verb = cli.parseDefaultArguments(argc, argv);
|
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user