diff --git a/ROMFS/px4fmu_common/init.d/rc.sensors b/ROMFS/px4fmu_common/init.d/rc.sensors index 2694eb3c64..3931af6ebd 100644 --- a/ROMFS/px4fmu_common/init.d/rc.sensors +++ b/ROMFS/px4fmu_common/init.d/rc.sensors @@ -191,7 +191,10 @@ then ist8308 -X -q start ist8310 -X -q start lis2mdl -X -q start - lis3mdl -X -q start + if ! lis3mdl -X -q start + then + lis3mdl -X -q -a 0x1c start + fi qmc5883l -X -q start rm3100 -X -q start diff --git a/src/drivers/magnetometer/lis2mdl/lis2mdl.h b/src/drivers/magnetometer/lis2mdl/lis2mdl.h index 197739b2ca..1296ddfa4d 100644 --- a/src/drivers/magnetometer/lis2mdl/lis2mdl.h +++ b/src/drivers/magnetometer/lis2mdl/lis2mdl.h @@ -80,8 +80,8 @@ #define CFG_REG_C_BDU (1 << 4) /* avoids reading of incorrect data due to async reads */ /* interface factories */ -extern device::Device *LIS2MDL_SPI_interface(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode); -extern device::Device *LIS2MDL_I2C_interface(int bus, int bus_frequency); +extern device::Device *LIS2MDL_SPI_interface(const I2CSPIDriverConfig &config); +extern device::Device *LIS2MDL_I2C_interface(const I2CSPIDriverConfig &config); #define LIS2MDLL_ADDRESS 0x1e diff --git a/src/drivers/magnetometer/lis2mdl/lis2mdl_i2c.cpp b/src/drivers/magnetometer/lis2mdl/lis2mdl_i2c.cpp index 6bbfe0dede..3dcc472e60 100644 --- a/src/drivers/magnetometer/lis2mdl/lis2mdl_i2c.cpp +++ b/src/drivers/magnetometer/lis2mdl/lis2mdl_i2c.cpp @@ -56,7 +56,7 @@ class LIS2MDL_I2C : public device::I2C { public: - LIS2MDL_I2C(int bus, int bus_frequency); + LIS2MDL_I2C(const I2CSPIDriverConfig &config); virtual ~LIS2MDL_I2C() = default; virtual int read(unsigned address, void *data, unsigned count); @@ -68,16 +68,16 @@ protected: }; device::Device * -LIS2MDL_I2C_interface(int bus, int bus_frequency); +LIS2MDL_I2C_interface(const I2CSPIDriverConfig &config); device::Device * -LIS2MDL_I2C_interface(int bus, int bus_frequency) +LIS2MDL_I2C_interface(const I2CSPIDriverConfig &config) { - return new LIS2MDL_I2C(bus, bus_frequency); + return new LIS2MDL_I2C(config); } -LIS2MDL_I2C::LIS2MDL_I2C(int bus, int bus_frequency) : - I2C(DRV_MAG_DEVTYPE_LIS2MDL, "LIS2MDL_I2C", bus, LIS2MDLL_ADDRESS, bus_frequency) +LIS2MDL_I2C::LIS2MDL_I2C(const I2CSPIDriverConfig &config) : + I2C(config) { } diff --git a/src/drivers/magnetometer/lis2mdl/lis2mdl_main.cpp b/src/drivers/magnetometer/lis2mdl/lis2mdl_main.cpp index 11f8c8f3d4..d04435b50f 100644 --- a/src/drivers/magnetometer/lis2mdl/lis2mdl_main.cpp +++ b/src/drivers/magnetometer/lis2mdl/lis2mdl_main.cpp @@ -46,10 +46,10 @@ I2CSPIDriverBase *LIS2MDL::instantiate(const I2CSPIDriverConfig &config, int run device::Device *interface = nullptr; if (config.bus_type == BOARD_I2C_BUS) { - interface = LIS2MDL_I2C_interface(config.bus, config.bus_frequency); + interface = LIS2MDL_I2C_interface(config); } else if (config.bus_type == BOARD_SPI_BUS) { - interface = LIS2MDL_SPI_interface(config.bus, config.spi_devid, config.bus_frequency, config.spi_mode); + interface = LIS2MDL_SPI_interface(config); } if (interface == nullptr) { @@ -94,6 +94,7 @@ extern "C" int lis2mdl_main(int argc, char *argv[]) using ThisDriver = LIS2MDL; int ch; BusCLIArguments cli{true, true}; + cli.i2c_address = LIS2MDLL_ADDRESS; cli.default_i2c_frequency = 400000; cli.default_spi_frequency = 11 * 1000 * 1000; @@ -112,8 +113,6 @@ extern "C" int lis2mdl_main(int argc, char *argv[]) return -1; } - cli.i2c_address = LIS2MDLL_ADDRESS; - BusInstanceIterator iterator(MODULE_NAME, cli, DRV_MAG_DEVTYPE_LIS2MDL); if (!strcmp(verb, "start")) { diff --git a/src/drivers/magnetometer/lis2mdl/lis2mdl_spi.cpp b/src/drivers/magnetometer/lis2mdl/lis2mdl_spi.cpp index 54e5a24b61..b017ad4afe 100644 --- a/src/drivers/magnetometer/lis2mdl/lis2mdl_spi.cpp +++ b/src/drivers/magnetometer/lis2mdl/lis2mdl_spi.cpp @@ -61,7 +61,7 @@ class LIS2MDL_SPI : public device::SPI { public: - LIS2MDL_SPI(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode); + LIS2MDL_SPI(const I2CSPIDriverConfig &config); virtual ~LIS2MDL_SPI() = default; virtual int init(); @@ -70,16 +70,16 @@ public: }; device::Device * -LIS2MDL_SPI_interface(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode); +LIS2MDL_SPI_interface(const I2CSPIDriverConfig &config); device::Device * -LIS2MDL_SPI_interface(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode) +LIS2MDL_SPI_interface(const I2CSPIDriverConfig &config) { - return new LIS2MDL_SPI(bus, devid, bus_frequency, spi_mode); + return new LIS2MDL_SPI(config); } -LIS2MDL_SPI::LIS2MDL_SPI(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode) : - SPI(DRV_MAG_DEVTYPE_LIS2MDL, "LIS2MDL_SPI", bus, devid, spi_mode, bus_frequency) +LIS2MDL_SPI::LIS2MDL_SPI(const I2CSPIDriverConfig &config) : + SPI(config) { } diff --git a/src/drivers/magnetometer/lis3mdl/lis3mdl.h b/src/drivers/magnetometer/lis3mdl/lis3mdl.h index f36d99972d..cff8c9466f 100644 --- a/src/drivers/magnetometer/lis3mdl/lis3mdl.h +++ b/src/drivers/magnetometer/lis3mdl/lis3mdl.h @@ -84,8 +84,8 @@ #define CNTL_REG5_DEFAULT 0x00 /* interface factories */ -extern device::Device *LIS3MDL_SPI_interface(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode); -extern device::Device *LIS3MDL_I2C_interface(int bus, int bus_frequency); +extern device::Device *LIS3MDL_SPI_interface(const I2CSPIDriverConfig &config); +extern device::Device *LIS3MDL_I2C_interface(const I2CSPIDriverConfig &config); enum OPERATING_MODE { CONTINUOUS = 0, diff --git a/src/drivers/magnetometer/lis3mdl/lis3mdl_i2c.cpp b/src/drivers/magnetometer/lis3mdl/lis3mdl_i2c.cpp index c85c03b752..a0957cff3c 100644 --- a/src/drivers/magnetometer/lis3mdl/lis3mdl_i2c.cpp +++ b/src/drivers/magnetometer/lis3mdl/lis3mdl_i2c.cpp @@ -56,7 +56,7 @@ class LIS3MDL_I2C : public device::I2C { public: - LIS3MDL_I2C(int bus, int bus_frequency); + LIS3MDL_I2C(const I2CSPIDriverConfig &config); virtual ~LIS3MDL_I2C() = default; virtual int read(unsigned address, void *data, unsigned count); @@ -68,16 +68,16 @@ protected: }; device::Device * -LIS3MDL_I2C_interface(int bus, int bus_frequency); +LIS3MDL_I2C_interface(const I2CSPIDriverConfig &config); device::Device * -LIS3MDL_I2C_interface(int bus, int bus_frequency) +LIS3MDL_I2C_interface(const I2CSPIDriverConfig &config) { - return new LIS3MDL_I2C(bus, bus_frequency); + return new LIS3MDL_I2C(config); } -LIS3MDL_I2C::LIS3MDL_I2C(int bus, int bus_frequency) : - I2C(DRV_MAG_DEVTYPE_LIS3MDL, MODULE_NAME, bus, LIS3MDLL_ADDRESS, bus_frequency) +LIS3MDL_I2C::LIS3MDL_I2C(const I2CSPIDriverConfig &config) : + I2C(config) { } diff --git a/src/drivers/magnetometer/lis3mdl/lis3mdl_main.cpp b/src/drivers/magnetometer/lis3mdl/lis3mdl_main.cpp index edd1f280f3..7bdb49908a 100644 --- a/src/drivers/magnetometer/lis3mdl/lis3mdl_main.cpp +++ b/src/drivers/magnetometer/lis3mdl/lis3mdl_main.cpp @@ -46,10 +46,10 @@ I2CSPIDriverBase *LIS3MDL::instantiate(const I2CSPIDriverConfig &config, int run device::Device *interface = nullptr; if (config.bus_type == BOARD_I2C_BUS) { - interface = LIS3MDL_I2C_interface(config.bus, config.bus_frequency); + interface = LIS3MDL_I2C_interface(config); } else if (config.bus_type == BOARD_SPI_BUS) { - interface = LIS3MDL_SPI_interface(config.bus, config.spi_devid, config.bus_frequency, config.spi_mode); + interface = LIS3MDL_SPI_interface(config); } if (interface == nullptr) { @@ -90,6 +90,7 @@ void LIS3MDL::print_usage() PRINT_MODULE_USAGE_SUBCATEGORY("magnetometer"); PRINT_MODULE_USAGE_COMMAND("start"); PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, true); + PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x1e); PRINT_MODULE_USAGE_PARAM_INT('R', 0, 0, 35, "Rotation", true); PRINT_MODULE_USAGE_COMMAND("reset"); PRINT_MODULE_USAGE_DEFAULT_COMMANDS(); @@ -100,6 +101,7 @@ extern "C" int lis3mdl_main(int argc, char *argv[]) using ThisDriver = LIS3MDL; int ch; BusCLIArguments cli{true, true}; + cli.i2c_address = LIS3MDLL_ADDRESS; cli.default_i2c_frequency = 400000; cli.default_spi_frequency = 11 * 1000 * 1000; @@ -118,8 +120,6 @@ extern "C" int lis3mdl_main(int argc, char *argv[]) return -1; } - cli.i2c_address = LIS3MDLL_ADDRESS; - BusInstanceIterator iterator(MODULE_NAME, cli, DRV_MAG_DEVTYPE_LIS3MDL); if (!strcmp(verb, "start")) { diff --git a/src/drivers/magnetometer/lis3mdl/lis3mdl_spi.cpp b/src/drivers/magnetometer/lis3mdl/lis3mdl_spi.cpp index af9f99d776..9646259b63 100644 --- a/src/drivers/magnetometer/lis3mdl/lis3mdl_spi.cpp +++ b/src/drivers/magnetometer/lis3mdl/lis3mdl_spi.cpp @@ -61,7 +61,7 @@ class LIS3MDL_SPI : public device::SPI { public: - LIS3MDL_SPI(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode); + LIS3MDL_SPI(const I2CSPIDriverConfig &config); virtual ~LIS3MDL_SPI() = default; virtual int init(); @@ -70,16 +70,16 @@ public: }; device::Device * -LIS3MDL_SPI_interface(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode); +LIS3MDL_SPI_interface(const I2CSPIDriverConfig &config); device::Device * -LIS3MDL_SPI_interface(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode) +LIS3MDL_SPI_interface(const I2CSPIDriverConfig &config) { - return new LIS3MDL_SPI(bus, devid, bus_frequency, spi_mode); + return new LIS3MDL_SPI(config); } -LIS3MDL_SPI::LIS3MDL_SPI(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode) : - SPI(DRV_MAG_DEVTYPE_LIS3MDL, MODULE_NAME, bus, devid, spi_mode, bus_frequency) +LIS3MDL_SPI::LIS3MDL_SPI(const I2CSPIDriverConfig &config) : + SPI(config) { }