drivers: use updated I2C SPI driver interface

This commit is contained in:
Beat Küng
2021-07-08 12:59:35 -04:00
committed by Daniel Agar
parent c5aef9d512
commit e644036325
218 changed files with 812 additions and 2001 deletions
@@ -33,8 +33,6 @@
#include "MPL3115A2.hpp"
#define MPL3115A2_ADDRESS 0x60
#define MPL3115A2_REG_WHO_AM_I 0x0c
#define MPL3115A2_WHO_AM_I 0xC4
@@ -54,9 +52,9 @@
#define MPL3115A2_OSR 2 /* Over Sample rate of 4 18MS Minimum time between data samples */
#define MPL3115A2_CTRL_TRIGGER (CTRL_REG1_OST | CTRL_REG1_OS(MPL3115A2_OSR))
MPL3115A2::MPL3115A2(I2CSPIBusOption bus_option, const int bus, int bus_frequency) :
I2C(DRV_BARO_DEVTYPE_MPL3115A2, MODULE_NAME, bus, MPL3115A2_ADDRESS, bus_frequency),
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
MPL3115A2::MPL3115A2(const I2CSPIDriverConfig &config) :
I2C(config),
I2CSPIDriver(config),
_px4_barometer(get_device_id()),
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
_measure_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": measure")),
@@ -48,14 +48,14 @@
#include <px4_platform_common/log.h>
#include <px4_platform_common/i2c_spi_buses.h>
#define MPL3115A2_ADDRESS 0x60
class MPL3115A2 : public device::I2C, public I2CSPIDriver<MPL3115A2>
{
public:
MPL3115A2(I2CSPIBusOption bus_option, const int bus, int bus_frequency);
MPL3115A2(const I2CSPIDriverConfig &config);
~MPL3115A2() override;
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
int runtime_instance);
static void print_usage();
@@ -43,31 +43,16 @@ MPL3115A2::print_usage()
PRINT_MODULE_USAGE_SUBCATEGORY("baro");
PRINT_MODULE_USAGE_COMMAND("start");
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x60);
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
}
I2CSPIDriverBase *MPL3115A2::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
int runtime_instance)
{
MPL3115A2 *dev = new MPL3115A2(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency);
if (dev == nullptr) {
return nullptr;
}
if (OK != dev->init()) {
delete dev;
return nullptr;
}
return dev;
}
extern "C" int mpl3115a2_main(int argc, char *argv[])
{
using ThisDriver = MPL3115A2;
BusCLIArguments cli{true, false};
cli.default_i2c_frequency = 400000;
cli.i2c_address = MPL3115A2_ADDRESS;
const char *verb = cli.parseDefaultArguments(argc, argv);