Compare commits

...

2 Commits

Author SHA1 Message Date
Daniel Agar fd014acd47 WIP: adis16477 debug 2022-08-09 11:13:17 -04:00
Daniel Agar e992757fb3 mpu9250: try all I2C addresses if not manually specified 2022-08-09 10:05:33 -04:00
4 changed files with 21 additions and 4 deletions
+2
View File
@@ -62,6 +62,8 @@ ADIS16477::ADIS16477(const I2CSPIDriverConfig &config) :
_bad_transfers(perf_alloc(PC_COUNT, MODULE_NAME": bad transfers")),
_drdy_gpio(config.drdy_gpio)
{
_debug_enabled = true;
#ifdef GPIO_SPI1_RESET_ADIS16477
// Configure hardware reset line
px4_arch_configgpio(GPIO_SPI1_RESET_ADIS16477);
+1
View File
@@ -35,6 +35,7 @@ px4_add_module(
MAIN adis16477
COMPILE_FLAGS
-Wno-cast-align # TODO: fix and enable
-DDEBUG_BUILD
SRCS
ADIS16477.cpp
adis16477_main.cpp
@@ -54,7 +54,7 @@ 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_ADDRESS_DEFAULT = 0x69; // 0b110100X
static constexpr uint8_t I2C_ADDRESSES[] {0b110'1000, 0b110'1001}; // 0b110'100x (0x68 or 0x69)
static constexpr uint32_t I2C_SPEED = 400 * 1000;
static constexpr uint32_t SPI_SPEED = 1 * 1000 * 1000;
@@ -42,7 +42,7 @@ void MPU9250_I2C::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_PARAMS_I2C_ADDRESS(0x68);
PRINT_MODULE_USAGE_PARAM_INT('R', 0, 0, 35, "Rotation", true);
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
}
@@ -53,7 +53,7 @@ extern "C" int mpu9250_i2c_main(int argc, char *argv[])
using ThisDriver = MPU9250_I2C;
BusCLIArguments cli{true, false};
cli.default_i2c_frequency = I2C_SPEED;
cli.i2c_address = I2C_ADDRESS_DEFAULT;
cli.i2c_address = 0;
while ((ch = cli.getOpt(argc, argv, "R:")) != EOF) {
switch (ch) {
@@ -73,7 +73,21 @@ extern "C" int mpu9250_i2c_main(int argc, char *argv[])
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_IMU_DEVTYPE_MPU9250);
if (!strcmp(verb, "start")) {
return ThisDriver::module_start(cli, iterator);
if (cli.i2c_address != 0) {
return ThisDriver::module_start(cli, iterator);
} else {
// otherwise try all I2C addresses
for (auto &i2c_address : I2C_ADDRESSES) {
cli.i2c_address = i2c_address;
if (ThisDriver::module_start(cli, iterator) == PX4_OK) {
return PX4_OK;
}
}
return PX4_ERROR;
}
}
if (!strcmp(verb, "stop")) {