mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-24 15:15:55 +08:00
drivers: use updated I2C SPI driver interface
This commit is contained in:
@@ -47,7 +47,18 @@ int ADS1115::init()
|
||||
config[0] = CONFIG_HIGH_OS_NOACT | CONFIG_HIGH_MUX_P0NG | CONFIG_HIGH_PGA_6144 | CONFIG_HIGH_MODE_SS;
|
||||
config[1] = CONFIG_LOW_DR_250SPS | CONFIG_LOW_COMP_MODE_TRADITIONAL | CONFIG_LOW_COMP_POL_RESET |
|
||||
CONFIG_LOW_COMP_LAT_NONE | CONFIG_LOW_COMP_QU_DISABLE;
|
||||
return writeReg(ADDRESSPOINTER_REG_CONFIG, config, 2);
|
||||
ret = writeReg(ADDRESSPOINTER_REG_CONFIG, config, 2);
|
||||
|
||||
if (ret != PX4_OK) {
|
||||
PX4_ERR("writeReg failed (%i)", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
setChannel(ADS1115::A0); // prepare for the first measure.
|
||||
|
||||
ScheduleOnInterval(SAMPLE_INTERVAL / 4, SAMPLE_INTERVAL / 4);
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
int ADS1115::setChannel(ADS1115::ChannelSelection ch)
|
||||
@@ -194,4 +205,4 @@ int ADS1115::writeReg(uint8_t addr, uint8_t *buf, size_t len)
|
||||
buffer[0] = addr;
|
||||
memcpy(buffer + 1, buf, sizeof(uint8_t)*len);
|
||||
return transfer(buffer, len + 1, nullptr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,24 +105,17 @@ using namespace time_literals;
|
||||
class ADS1115 : public device::I2C, public I2CSPIDriver<ADS1115>
|
||||
{
|
||||
public:
|
||||
ADS1115(I2CSPIBusOption bus_option, int bus, int addr, int bus_frequency);
|
||||
ADS1115(const I2CSPIDriverConfig &config);
|
||||
~ADS1115() override;
|
||||
|
||||
int Begin();
|
||||
|
||||
int init() override;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
|
||||
static void print_usage();
|
||||
|
||||
void RunImpl();
|
||||
|
||||
protected:
|
||||
|
||||
adc_report_s _adc_report = {};
|
||||
|
||||
void print_status() override;
|
||||
|
||||
void exit_and_cleanup() override;
|
||||
@@ -133,9 +126,11 @@ private:
|
||||
|
||||
static const hrt_abstime SAMPLE_INTERVAL{50_ms};
|
||||
|
||||
adc_report_s _adc_report{};
|
||||
|
||||
perf_counter_t _cycle_perf;
|
||||
|
||||
int _channel_cycle_count = 0;
|
||||
int _channel_cycle_count{0};
|
||||
|
||||
// ADS1115 logic part
|
||||
enum ChannelSelection {
|
||||
@@ -159,4 +154,4 @@ private:
|
||||
|
||||
int writeReg(uint8_t addr, uint8_t *buf, size_t len);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@@ -42,9 +42,9 @@
|
||||
#include <px4_platform_common/module.h>
|
||||
#include <drivers/drv_adc.h>
|
||||
|
||||
ADS1115::ADS1115(I2CSPIBusOption bus_option, int bus, int addr, int bus_frequency) :
|
||||
I2C(DRV_ADC_DEVTYPE_ADS1115, nullptr, bus, addr, bus_frequency),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, addr),
|
||||
ADS1115::ADS1115(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_cycle_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": single-sample"))
|
||||
{
|
||||
_adc_report.device_id = this->get_device_id();
|
||||
@@ -63,22 +63,6 @@ ADS1115::~ADS1115()
|
||||
perf_free(_cycle_perf);
|
||||
}
|
||||
|
||||
int ADS1115::Begin()
|
||||
{
|
||||
int ret = init();
|
||||
|
||||
if (ret != PX4_OK) {
|
||||
PX4_ERR("ADS1115 init failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
setChannel(ADS1115::A0); // prepare for the first measure.
|
||||
|
||||
ScheduleOnInterval(SAMPLE_INTERVAL / 4, SAMPLE_INTERVAL / 4);
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
void ADS1115::exit_and_cleanup()
|
||||
{
|
||||
I2CSPIDriverBase::exit_and_cleanup(); // nothing to do
|
||||
@@ -140,25 +124,6 @@ void ADS1115::RunImpl()
|
||||
perf_end(_cycle_perf);
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *ADS1115::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
ADS1115 *instance = new ADS1115(iterator.configuredBusOption(), iterator.bus(), cli.i2c_address,
|
||||
cli.bus_frequency);
|
||||
|
||||
if (!instance) {
|
||||
PX4_ERR("alloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (OK != instance->Begin()) {
|
||||
delete instance;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
void ADS1115::print_usage()
|
||||
{
|
||||
PRINT_MODULE_USAGE_NAME("ads1115", "driver");
|
||||
@@ -176,17 +141,12 @@ void ADS1115::print_status()
|
||||
|
||||
extern "C" int ads1115_main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
using ThisDriver = ADS1115;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.default_i2c_frequency = 400000;
|
||||
cli.i2c_address = 0x48;
|
||||
|
||||
while ((ch = cli.getOpt(argc, argv, "")) != EOF) {
|
||||
|
||||
}
|
||||
|
||||
const char *verb = cli.optArg();
|
||||
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||
|
||||
if (!verb) {
|
||||
ThisDriver::print_usage();
|
||||
|
||||
@@ -33,9 +33,8 @@
|
||||
|
||||
#include "BMP280.hpp"
|
||||
|
||||
BMP280::BMP280(I2CSPIBusOption bus_option, int bus, bmp280::IBMP280 *interface) :
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(interface->get_device_id()), bus_option, bus,
|
||||
interface->get_device_address()),
|
||||
BMP280::BMP280(const I2CSPIDriverConfig &config, bmp280::IBMP280 *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_baro(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": sample")),
|
||||
|
||||
@@ -45,11 +45,10 @@
|
||||
class BMP280 : public I2CSPIDriver<BMP280>
|
||||
{
|
||||
public:
|
||||
BMP280(I2CSPIBusOption bus_option, int bus, bmp280::IBMP280 *interface);
|
||||
BMP280(const I2CSPIDriverConfig &config, bmp280::IBMP280 *interface);
|
||||
virtual ~BMP280();
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static I2CSPIDriverBase *instantiate(const I2CSPIDriverConfig &config, int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
int init();
|
||||
|
||||
@@ -50,30 +50,29 @@ BMP280::print_usage()
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *BMP280::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
I2CSPIDriverBase *BMP280::instantiate(const I2CSPIDriverConfig &config, int runtime_instance)
|
||||
{
|
||||
bmp280::IBMP280 *interface = nullptr;
|
||||
|
||||
if (iterator.busType() == BOARD_I2C_BUS) {
|
||||
interface = bmp280_i2c_interface(iterator.bus(), cli.i2c_address, cli.bus_frequency);
|
||||
if (config.bus_type == BOARD_I2C_BUS) {
|
||||
interface = bmp280_i2c_interface(config.bus, config.i2c_address, config.bus_frequency);
|
||||
|
||||
} else if (iterator.busType() == BOARD_SPI_BUS) {
|
||||
interface = bmp280_spi_interface(iterator.bus(), iterator.devid(), cli.bus_frequency, cli.spi_mode);
|
||||
} else if (config.bus_type == BOARD_SPI_BUS) {
|
||||
interface = bmp280_spi_interface(config.bus, config.spi_devid, config.bus_frequency, config.spi_mode);
|
||||
}
|
||||
|
||||
if (interface == nullptr) {
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (interface->init() != OK) {
|
||||
delete interface;
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BMP280 *dev = new BMP280(iterator.configuredBusOption(), iterator.bus(), interface);
|
||||
BMP280 *dev = new BMP280(config, interface);
|
||||
|
||||
if (dev == nullptr) {
|
||||
delete interface;
|
||||
|
||||
@@ -41,9 +41,8 @@
|
||||
|
||||
#include "bmp388.h"
|
||||
|
||||
BMP388::BMP388(I2CSPIBusOption bus_option, int bus, IBMP388 *interface) :
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(interface->get_device_id()), bus_option, bus,
|
||||
interface->get_device_address()),
|
||||
BMP388::BMP388(const I2CSPIDriverConfig &config, IBMP388 *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_baro(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
|
||||
@@ -308,11 +308,10 @@ public:
|
||||
class BMP388 : public I2CSPIDriver<BMP388>
|
||||
{
|
||||
public:
|
||||
BMP388(I2CSPIBusOption bus_option, int bus, IBMP388 *interface);
|
||||
BMP388(const I2CSPIDriverConfig &config, IBMP388 *interface);
|
||||
virtual ~BMP388();
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static I2CSPIDriverBase *instantiate(const I2CSPIDriverConfig &config, int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
virtual int init();
|
||||
|
||||
@@ -48,30 +48,29 @@ BMP388::print_usage()
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *BMP388::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
I2CSPIDriverBase *BMP388::instantiate(const I2CSPIDriverConfig &config, int runtime_instance)
|
||||
{
|
||||
IBMP388 *interface = nullptr;
|
||||
|
||||
if (iterator.busType() == BOARD_I2C_BUS) {
|
||||
interface = bmp388_i2c_interface(iterator.bus(), cli.i2c_address, cli.bus_frequency);
|
||||
if (config.bus_type == BOARD_I2C_BUS) {
|
||||
interface = bmp388_i2c_interface(config.bus, config.i2c_address, config.bus_frequency);
|
||||
|
||||
} else if (iterator.busType() == BOARD_SPI_BUS) {
|
||||
interface = bmp388_spi_interface(iterator.bus(), iterator.devid(), cli.bus_frequency, cli.spi_mode);
|
||||
} else if (config.bus_type == BOARD_SPI_BUS) {
|
||||
interface = bmp388_spi_interface(config.bus, config.spi_devid, config.bus_frequency, config.spi_mode);
|
||||
}
|
||||
|
||||
if (interface == nullptr) {
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (interface->init() != OK) {
|
||||
delete interface;
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BMP388 *dev = new BMP388(iterator.configuredBusOption(), iterator.bus(), interface);
|
||||
BMP388 *dev = new BMP388(config, interface);
|
||||
|
||||
if (dev == nullptr) {
|
||||
delete interface;
|
||||
|
||||
@@ -46,9 +46,8 @@ static void getTwosComplement(T &raw, uint8_t length)
|
||||
}
|
||||
}
|
||||
|
||||
DPS310::DPS310(I2CSPIBusOption bus_option, int bus, device::Device *interface) :
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(interface->get_device_id()), bus_option, bus,
|
||||
interface->get_device_address()),
|
||||
DPS310::DPS310(const I2CSPIDriverConfig &config, device::Device *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_barometer(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
|
||||
@@ -56,11 +56,10 @@ using Infineon_DPS310::Register;
|
||||
class DPS310 : public I2CSPIDriver<DPS310>
|
||||
{
|
||||
public:
|
||||
DPS310(I2CSPIBusOption bus_option, int bus, device::Device *interface);
|
||||
DPS310(const I2CSPIDriverConfig &config, device::Device *interface);
|
||||
virtual ~DPS310();
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static I2CSPIDriverBase *instantiate(const I2CSPIDriverConfig &config, int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
int init();
|
||||
|
||||
@@ -55,30 +55,29 @@ DPS310::print_usage()
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *DPS310::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
I2CSPIDriverBase *DPS310::instantiate(const I2CSPIDriverConfig &config, int runtime_instance)
|
||||
{
|
||||
device::Device *interface = nullptr;
|
||||
|
||||
if (iterator.busType() == BOARD_I2C_BUS) {
|
||||
interface = DPS310_I2C_interface(iterator.bus(), cli.i2c_address, cli.bus_frequency);
|
||||
if (config.bus_type == BOARD_I2C_BUS) {
|
||||
interface = DPS310_I2C_interface(config.bus, config.i2c_address, config.bus_frequency);
|
||||
|
||||
} else if (iterator.busType() == BOARD_SPI_BUS) {
|
||||
interface = DPS310_SPI_interface(iterator.bus(), iterator.devid(), cli.bus_frequency, cli.spi_mode);
|
||||
} else if (config.bus_type == BOARD_SPI_BUS) {
|
||||
interface = DPS310_SPI_interface(config.bus, config.spi_devid, config.bus_frequency, config.spi_mode);
|
||||
}
|
||||
|
||||
if (interface == nullptr) {
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (interface->init() != OK) {
|
||||
delete interface;
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DPS310 *dev = new DPS310(iterator.configuredBusOption(), iterator.bus(), interface);
|
||||
DPS310 *dev = new DPS310(config, interface);
|
||||
|
||||
if (dev == nullptr) {
|
||||
delete interface;
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
/* Max measurement rate is 25Hz */
|
||||
#define LPS22HB_CONVERSION_INTERVAL (1000000 / 25) /* microseconds */
|
||||
|
||||
LPS22HB::LPS22HB(I2CSPIBusOption bus_option, int bus, device::Device *interface) :
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(interface->get_device_id()), bus_option, bus),
|
||||
LPS22HB::LPS22HB(const I2CSPIDriverConfig &config, device::Device *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_baro(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
|
||||
@@ -70,6 +70,8 @@ static constexpr uint8_t PRESS_OUT_H = 0x2A;
|
||||
static constexpr uint8_t TEMP_OUT_L = 0x2B;
|
||||
static constexpr uint8_t TEMP_OUT_H = 0x2C;
|
||||
|
||||
#define LPS22HB_ADDRESS 0x5D
|
||||
|
||||
/* interface factories */
|
||||
extern device::Device *LPS22HB_SPI_interface(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode);
|
||||
extern device::Device *LPS22HB_I2C_interface(int bus, int bus_frequency);
|
||||
@@ -77,11 +79,10 @@ extern device::Device *LPS22HB_I2C_interface(int bus, int bus_frequency);
|
||||
class LPS22HB : public I2CSPIDriver<LPS22HB>
|
||||
{
|
||||
public:
|
||||
LPS22HB(I2CSPIBusOption bus_option, int bus, device::Device *interface);
|
||||
LPS22HB(const I2CSPIDriverConfig &config, device::Device *interface);
|
||||
virtual ~LPS22HB();
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static I2CSPIDriverBase *instantiate(const I2CSPIDriverConfig &config, int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
int init();
|
||||
|
||||
@@ -41,8 +41,6 @@
|
||||
|
||||
#include <drivers/device/i2c.h>
|
||||
|
||||
#define LPS22HB_ADDRESS 0x5D
|
||||
|
||||
device::Device *LPS22HB_I2C_interface(int bus, int bus_frequency);
|
||||
|
||||
class LPS22HB_I2C : public device::I2C
|
||||
|
||||
@@ -43,30 +43,29 @@ void LPS22HB::print_usage()
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *LPS22HB::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
I2CSPIDriverBase *LPS22HB::instantiate(const I2CSPIDriverConfig &config, int runtime_instance)
|
||||
{
|
||||
device::Device *interface = nullptr;
|
||||
|
||||
if (iterator.busType() == BOARD_I2C_BUS) {
|
||||
interface = LPS22HB_I2C_interface(iterator.bus(), cli.bus_frequency);
|
||||
if (config.bus_type == BOARD_I2C_BUS) {
|
||||
interface = LPS22HB_I2C_interface(config.bus, config.bus_frequency);
|
||||
|
||||
} else if (iterator.busType() == BOARD_SPI_BUS) {
|
||||
interface = LPS22HB_SPI_interface(iterator.bus(), iterator.devid(), cli.bus_frequency, cli.spi_mode);
|
||||
} else if (config.bus_type == BOARD_SPI_BUS) {
|
||||
interface = LPS22HB_SPI_interface(config.bus, config.spi_devid, config.bus_frequency, config.spi_mode);
|
||||
}
|
||||
|
||||
if (interface == nullptr) {
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (interface->init() != OK) {
|
||||
delete interface;
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LPS22HB *dev = new LPS22HB(iterator.configuredBusOption(), iterator.bus(), interface);
|
||||
LPS22HB *dev = new LPS22HB(config, interface);
|
||||
|
||||
if (dev == nullptr) {
|
||||
delete interface;
|
||||
@@ -95,6 +94,8 @@ extern "C" __EXPORT int lps22hb_main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
cli.i2c_address = LPS22HB_ADDRESS;
|
||||
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_BARO_DEVTYPE_LPS22HB);
|
||||
|
||||
if (!strcmp(verb, "start")) {
|
||||
|
||||
@@ -33,8 +33,8 @@
|
||||
|
||||
#include "LPS25H.hpp"
|
||||
|
||||
LPS25H::LPS25H(I2CSPIBusOption bus_option, int bus, device::Device *interface) :
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(interface->get_device_id()), bus_option, bus),
|
||||
LPS25H::LPS25H(const I2CSPIDriverConfig &config, device::Device *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_barometer(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
|
||||
@@ -155,11 +155,10 @@
|
||||
class LPS25H : public I2CSPIDriver<LPS25H>
|
||||
{
|
||||
public:
|
||||
LPS25H(I2CSPIBusOption bus_option, int bus, device::Device *interface);
|
||||
LPS25H(const I2CSPIDriverConfig &config, device::Device *interface);
|
||||
~LPS25H() override;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static I2CSPIDriverBase *instantiate(const I2CSPIDriverConfig &config, int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
int init();
|
||||
|
||||
@@ -50,6 +50,8 @@
|
||||
|
||||
#define ID_WHO_AM_I 0xBD
|
||||
|
||||
#define LPS25H_ADDRESS 0x5D
|
||||
|
||||
/* interface factories */
|
||||
extern device::Device *LPS25H_SPI_interface(int bus, uint32_t devid, int bus_frequency, spi_mode_e spi_mode);
|
||||
extern device::Device *LPS25H_I2C_interface(int bus, int bus_frequency);
|
||||
|
||||
@@ -41,8 +41,6 @@
|
||||
|
||||
#include <drivers/device/i2c.h>
|
||||
|
||||
#define LPS25H_ADDRESS 0x5D
|
||||
|
||||
device::Device *LPS25H_I2C_interface(int bus, int bus_frequency);
|
||||
|
||||
class LPS25H_I2C : public device::I2C
|
||||
|
||||
@@ -47,30 +47,29 @@ LPS25H::print_usage()
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *LPS25H::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
I2CSPIDriverBase *LPS25H::instantiate(const I2CSPIDriverConfig &config, int runtime_instance)
|
||||
{
|
||||
device::Device *interface = nullptr;
|
||||
|
||||
if (iterator.busType() == BOARD_I2C_BUS) {
|
||||
interface = LPS25H_I2C_interface(iterator.bus(), cli.bus_frequency);
|
||||
if (config.bus_type == BOARD_I2C_BUS) {
|
||||
interface = LPS25H_I2C_interface(config.bus, config.bus_frequency);
|
||||
|
||||
} else if (iterator.busType() == BOARD_SPI_BUS) {
|
||||
interface = LPS25H_SPI_interface(iterator.bus(), iterator.devid(), cli.bus_frequency, cli.spi_mode);
|
||||
} else if (config.bus_type == BOARD_SPI_BUS) {
|
||||
interface = LPS25H_SPI_interface(config.bus, config.spi_devid, config.bus_frequency, config.spi_mode);
|
||||
}
|
||||
|
||||
if (interface == nullptr) {
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (interface->init() != OK) {
|
||||
delete interface;
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LPS25H *dev = new LPS25H(iterator.configuredBusOption(), iterator.bus(), interface);
|
||||
LPS25H *dev = new LPS25H(config, interface);
|
||||
|
||||
if (dev == nullptr) {
|
||||
delete interface;
|
||||
@@ -99,6 +98,8 @@ extern "C" int lps25h_main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
cli.i2c_address = LPS25H_ADDRESS;
|
||||
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_BARO_DEVTYPE_LPS25H);
|
||||
|
||||
if (!strcmp(verb, "start")) {
|
||||
|
||||
@@ -47,14 +47,13 @@ static void getTwosComplement(T &raw, uint8_t length)
|
||||
}
|
||||
}
|
||||
|
||||
LPS33HW::LPS33HW(I2CSPIBusOption bus_option, int bus, device::Device *interface, bool keep_retrying) :
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(interface->get_device_id()), bus_option, bus,
|
||||
interface->get_device_address()),
|
||||
LPS33HW::LPS33HW(const I2CSPIDriverConfig &config, device::Device *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_barometer(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comm errors")),
|
||||
_keep_retrying(keep_retrying)
|
||||
_keep_retrying(config.keep_running)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -55,11 +55,10 @@ using ST_LPS33HW::Register;
|
||||
class LPS33HW : public I2CSPIDriver<LPS33HW>
|
||||
{
|
||||
public:
|
||||
LPS33HW(I2CSPIBusOption bus_option, int bus, device::Device *interface, bool keep_retrying);
|
||||
LPS33HW(const I2CSPIDriverConfig &config, device::Device *interface);
|
||||
virtual ~LPS33HW();
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static I2CSPIDriverBase *instantiate(const I2CSPIDriverConfig &config, int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
int init();
|
||||
|
||||
@@ -56,30 +56,29 @@ LPS33HW::print_usage()
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *LPS33HW::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
I2CSPIDriverBase *LPS33HW::instantiate(const I2CSPIDriverConfig &config, int runtime_instance)
|
||||
{
|
||||
device::Device *interface = nullptr;
|
||||
|
||||
if (iterator.busType() == BOARD_I2C_BUS) {
|
||||
interface = LPS33HW_I2C_interface(iterator.bus(), cli.i2c_address, cli.bus_frequency);
|
||||
if (config.bus_type == BOARD_I2C_BUS) {
|
||||
interface = LPS33HW_I2C_interface(config.bus, config.i2c_address, config.bus_frequency);
|
||||
|
||||
} else if (iterator.busType() == BOARD_SPI_BUS) {
|
||||
interface = LPS33HW_SPI_interface(iterator.bus(), iterator.devid(), cli.bus_frequency, cli.spi_mode);
|
||||
} else if (config.bus_type == BOARD_SPI_BUS) {
|
||||
interface = LPS33HW_SPI_interface(config.bus, config.spi_devid, config.bus_frequency, config.spi_mode);
|
||||
}
|
||||
|
||||
if (interface == nullptr) {
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_ERR("failed creating interface for bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (interface->init() != OK) {
|
||||
delete interface;
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", iterator.bus(), iterator.devid());
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%" PRIx32 ")", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LPS33HW *dev = new LPS33HW(iterator.configuredBusOption(), iterator.bus(), interface, cli.keep_running);
|
||||
LPS33HW *dev = new LPS33HW(config, interface);
|
||||
|
||||
if (dev == nullptr) {
|
||||
delete interface;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -87,12 +87,10 @@ enum MS56XX_DEVICE_TYPES {
|
||||
class MS5611 : public I2CSPIDriver<MS5611>
|
||||
{
|
||||
public:
|
||||
MS5611(device::Device *interface, ms5611::prom_u &prom_buf, enum MS56XX_DEVICE_TYPES device_type,
|
||||
I2CSPIBusOption bus_option, int bus);
|
||||
MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const I2CSPIDriverConfig &config);
|
||||
~MS5611() override;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static I2CSPIDriverBase *instantiate(const I2CSPIDriverConfig &config, int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
int init();
|
||||
|
||||
@@ -41,17 +41,25 @@
|
||||
|
||||
#include <cdev/CDev.hpp>
|
||||
|
||||
MS5611::MS5611(device::Device *interface, ms5611::prom_u &prom_buf, enum MS56XX_DEVICE_TYPES device_type,
|
||||
I2CSPIBusOption bus_option, int bus) :
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(interface->get_device_id()), bus_option, bus, 0, device_type),
|
||||
MS5611::MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const I2CSPIDriverConfig &config) :
|
||||
I2CSPIDriver(config),
|
||||
_px4_barometer(interface->get_device_id()),
|
||||
_interface(interface),
|
||||
_prom(prom_buf.s),
|
||||
_device_type(device_type),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": read")),
|
||||
_measure_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": measure")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": com_err"))
|
||||
{
|
||||
switch (config.devid_driver_index) {
|
||||
case DRV_BARO_DEVTYPE_MS5611:
|
||||
_device_type = MS5611_DEVICE;
|
||||
break;
|
||||
|
||||
case DRV_BARO_DEVTYPE_MS5607:
|
||||
default:
|
||||
_device_type = MS5607_DEVICE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MS5611::~MS5611()
|
||||
|
||||
@@ -58,6 +58,10 @@
|
||||
#define IOCTL_RESET 2
|
||||
#define IOCTL_MEASURE 3
|
||||
|
||||
#define MS5611_ADDRESS_1 0x76 /* address select pins pulled high (PX4FMU series v1.6+) */
|
||||
#define MS5611_ADDRESS_2 0x77 /* address select pins pulled low (PX4FMU prototypes) */
|
||||
|
||||
|
||||
namespace ms5611
|
||||
{
|
||||
|
||||
|
||||
@@ -41,9 +41,6 @@
|
||||
|
||||
#include "ms5611.h"
|
||||
|
||||
#define MS5611_ADDRESS_1 0x76 /* address select pins pulled high (PX4FMU series v1.6+) */
|
||||
#define MS5611_ADDRESS_2 0x77 /* address select pins pulled low (PX4FMU prototypes) */
|
||||
|
||||
class MS5611_I2C : public device::I2C
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -40,17 +40,16 @@
|
||||
#include "MS5611.hpp"
|
||||
#include "ms5611.h"
|
||||
|
||||
I2CSPIDriverBase *MS5611::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
I2CSPIDriverBase *MS5611::instantiate(const I2CSPIDriverConfig &config, int runtime_instance)
|
||||
{
|
||||
ms5611::prom_u prom_buf;
|
||||
device::Device *interface = nullptr;
|
||||
|
||||
if (iterator.busType() == BOARD_I2C_BUS) {
|
||||
interface = MS5611_i2c_interface(prom_buf, iterator.devid(), iterator.bus(), cli.bus_frequency);
|
||||
if (config.bus_type == BOARD_I2C_BUS) {
|
||||
interface = MS5611_i2c_interface(prom_buf, config.spi_devid, config.bus, config.bus_frequency);
|
||||
|
||||
} else if (iterator.busType() == BOARD_SPI_BUS) {
|
||||
interface = MS5611_spi_interface(prom_buf, iterator.devid(), iterator.bus(), cli.bus_frequency, cli.spi_mode);
|
||||
} else if (config.bus_type == BOARD_SPI_BUS) {
|
||||
interface = MS5611_spi_interface(prom_buf, config.spi_devid, config.bus, config.bus_frequency, config.spi_mode);
|
||||
}
|
||||
|
||||
if (interface == nullptr) {
|
||||
@@ -60,12 +59,11 @@ I2CSPIDriverBase *MS5611::instantiate(const BusCLIArguments &cli, const BusInsta
|
||||
|
||||
if (interface->init() != OK) {
|
||||
delete interface;
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%x)", iterator.bus(), iterator.devid());
|
||||
PX4_DEBUG("no device on bus %i (devid 0x%x)", config.bus, config.spi_devid);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MS5611 *dev = new MS5611(interface, prom_buf, (MS56XX_DEVICE_TYPES)cli.type, iterator.configuredBusOption(),
|
||||
iterator.bus());
|
||||
MS5611 *dev = new MS5611(interface, prom_buf, config);
|
||||
|
||||
if (dev == nullptr) {
|
||||
delete interface;
|
||||
@@ -95,7 +93,6 @@ extern "C" int ms5611_main(int argc, char *argv[])
|
||||
using ThisDriver = MS5611;
|
||||
int ch;
|
||||
BusCLIArguments cli{true, true};
|
||||
cli.type = MS5611_DEVICE;
|
||||
cli.default_i2c_frequency = 400000;
|
||||
cli.default_spi_frequency = 20 * 1000 * 1000;
|
||||
uint16_t dev_type_driver = DRV_BARO_DEVTYPE_MS5611;
|
||||
@@ -106,11 +103,9 @@ extern "C" int ms5611_main(int argc, char *argv[])
|
||||
int val = atoi(cli.optArg());
|
||||
|
||||
if (val == 5611) {
|
||||
cli.type = MS5611_DEVICE;
|
||||
dev_type_driver = DRV_BARO_DEVTYPE_MS5611;
|
||||
|
||||
} else if (val == 5607) {
|
||||
cli.type = MS5607_DEVICE;
|
||||
dev_type_driver = DRV_BARO_DEVTYPE_MS5607;
|
||||
}
|
||||
}
|
||||
@@ -125,6 +120,8 @@ extern "C" int ms5611_main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
cli.i2c_address = MS5611_ADDRESS_1;
|
||||
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli, dev_type_driver);
|
||||
|
||||
if (!strcmp(verb, "start")) {
|
||||
|
||||
@@ -47,9 +47,8 @@
|
||||
|
||||
extern "C" __EXPORT int batt_smbus_main(int argc, char *argv[]);
|
||||
|
||||
BATT_SMBUS::BATT_SMBUS(I2CSPIBusOption bus_option, const int bus, SMBus *interface) :
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(interface->get_device_id()), bus_option, bus,
|
||||
interface->get_device_address()),
|
||||
BATT_SMBUS::BATT_SMBUS(const I2CSPIDriverConfig &config, SMBus *interface) :
|
||||
I2CSPIDriver(config),
|
||||
_interface(interface)
|
||||
{
|
||||
int32_t battsource = 1;
|
||||
@@ -534,15 +533,14 @@ $ batt_smbus -X write_flash 19069 2 27 0
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *BATT_SMBUS::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
I2CSPIDriverBase *BATT_SMBUS::instantiate(const I2CSPIDriverConfig &config, int runtime_instance)
|
||||
{
|
||||
SMBus *interface = new SMBus(DRV_BAT_DEVTYPE_SMBUS, iterator.bus(), cli.i2c_address);
|
||||
SMBus *interface = new SMBus(DRV_BAT_DEVTYPE_SMBUS, config.bus, config.i2c_address);
|
||||
if (interface == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
BATT_SMBUS *instance = new BATT_SMBUS(iterator.configuredBusOption(), iterator.bus(), interface);
|
||||
BATT_SMBUS *instance = new BATT_SMBUS(config, interface);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
|
||||
@@ -127,12 +127,11 @@ enum class SMBUS_DEVICE_TYPE {
|
||||
class BATT_SMBUS : public I2CSPIDriver<BATT_SMBUS>
|
||||
{
|
||||
public:
|
||||
BATT_SMBUS(I2CSPIBusOption bus_option, const int bus, SMBus *interface);
|
||||
BATT_SMBUS(const I2CSPIDriverConfig &config, SMBus *interface);
|
||||
|
||||
~BATT_SMBUS();
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static I2CSPIDriverBase *instantiate(const I2CSPIDriverConfig &config, int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
friend SMBus;
|
||||
|
||||
@@ -63,15 +63,15 @@
|
||||
class ETSAirspeed : public Airspeed, public I2CSPIDriver<ETSAirspeed>
|
||||
{
|
||||
public:
|
||||
ETSAirspeed(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address = I2C_ADDRESS);
|
||||
ETSAirspeed(const I2CSPIDriverConfig &config);
|
||||
|
||||
virtual ~ETSAirspeed() = default;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
void RunImpl();
|
||||
|
||||
int init() override;
|
||||
protected:
|
||||
int measure() override;
|
||||
int collect() override;
|
||||
@@ -82,13 +82,25 @@ protected:
|
||||
*/
|
||||
extern "C" __EXPORT int ets_airspeed_main(int argc, char *argv[]);
|
||||
|
||||
ETSAirspeed::ETSAirspeed(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address)
|
||||
: Airspeed(bus, bus_frequency, address, CONVERSION_INTERVAL),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address)
|
||||
ETSAirspeed::ETSAirspeed(const I2CSPIDriverConfig &config)
|
||||
: Airspeed(config.bus, config.bus_frequency, config.i2c_address, CONVERSION_INTERVAL),
|
||||
I2CSPIDriver(config)
|
||||
{
|
||||
_device_id.devid_s.devtype = DRV_DIFF_PRESS_DEVTYPE_MS4525;
|
||||
}
|
||||
|
||||
int ETSAirspeed::init()
|
||||
{
|
||||
int ret = Airspeed::init();
|
||||
|
||||
if (ret == PX4_OK) {
|
||||
ScheduleNow();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ETSAirspeed::measure()
|
||||
{
|
||||
@@ -209,26 +221,6 @@ ETSAirspeed::RunImpl()
|
||||
ScheduleDelayed(CONVERSION_INTERVAL);
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *ETSAirspeed::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
ETSAirspeed *instance = new ETSAirspeed(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (instance->init() != PX4_OK) {
|
||||
delete instance;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
instance->ScheduleNow();
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ETSAirspeed::print_usage()
|
||||
{
|
||||
@@ -236,6 +228,7 @@ ETSAirspeed::print_usage()
|
||||
PRINT_MODULE_USAGE_SUBCATEGORY("airspeed_sensor");
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x75);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
@@ -245,6 +238,7 @@ ets_airspeed_main(int argc, char *argv[])
|
||||
using ThisDriver = ETSAirspeed;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.default_i2c_frequency = 100000;
|
||||
cli.i2c_address = I2C_ADDRESS;
|
||||
|
||||
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||
|
||||
|
||||
@@ -77,16 +77,16 @@ enum MS_DEVICE_TYPE {
|
||||
class MEASAirspeed : public Airspeed, public I2CSPIDriver<MEASAirspeed>
|
||||
{
|
||||
public:
|
||||
MEASAirspeed(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address = I2C_ADDRESS_MS4525DO);
|
||||
MEASAirspeed(const I2CSPIDriverConfig &config);
|
||||
|
||||
virtual ~MEASAirspeed() = default;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
void RunImpl();
|
||||
|
||||
int init() override;
|
||||
|
||||
protected:
|
||||
|
||||
int measure() override;
|
||||
@@ -100,13 +100,24 @@ protected:
|
||||
*/
|
||||
extern "C" __EXPORT int ms4525_airspeed_main(int argc, char *argv[]);
|
||||
|
||||
MEASAirspeed::MEASAirspeed(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address)
|
||||
: Airspeed(bus, bus_frequency, address, CONVERSION_INTERVAL),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address)
|
||||
MEASAirspeed::MEASAirspeed(const I2CSPIDriverConfig &config)
|
||||
: Airspeed(config.bus, config.bus_frequency, config.i2c_address, CONVERSION_INTERVAL),
|
||||
I2CSPIDriver(config)
|
||||
{
|
||||
_device_id.devid_s.devtype = DRV_DIFF_PRESS_DEVTYPE_MS4525;
|
||||
}
|
||||
|
||||
int MEASAirspeed::init()
|
||||
{
|
||||
int ret = Airspeed::init();
|
||||
|
||||
if (ret == PX4_OK) {
|
||||
ScheduleNow();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
MEASAirspeed::measure()
|
||||
{
|
||||
@@ -266,27 +277,6 @@ MEASAirspeed::RunImpl()
|
||||
ScheduleDelayed(CONVERSION_INTERVAL);
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *MEASAirspeed::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
MEASAirspeed *instance = new MEASAirspeed(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency,
|
||||
cli.i2c_address);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (instance->init() != PX4_OK) {
|
||||
delete instance;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
instance->ScheduleNow();
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MEASAirspeed::print_usage()
|
||||
{
|
||||
@@ -329,8 +319,7 @@ ms4525_airspeed_main(int argc, char *argv[])
|
||||
cli.i2c_address = I2C_ADDRESS_MS4515DO;
|
||||
}
|
||||
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli,
|
||||
DRV_DIFF_PRESS_DEVTYPE_MS4525);
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_DIFF_PRESS_DEVTYPE_MS4525);
|
||||
|
||||
if (!strcmp(verb, "start")) {
|
||||
return ThisDriver::module_start(cli, iterator);
|
||||
|
||||
@@ -33,6 +33,17 @@
|
||||
|
||||
#include "MS5525.hpp"
|
||||
|
||||
int MS5525::init()
|
||||
{
|
||||
int ret = Airspeed::init();
|
||||
|
||||
if (ret == PX4_OK) {
|
||||
ScheduleNow();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
MS5525::measure()
|
||||
{
|
||||
|
||||
@@ -51,20 +51,20 @@ static constexpr int64_t CONVERSION_INTERVAL = (1000000 / MEAS_RATE); /* microse
|
||||
class MS5525 : public Airspeed, public I2CSPIDriver<MS5525>
|
||||
{
|
||||
public:
|
||||
MS5525(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address = I2C_ADDRESS_1_MS5525DSO) :
|
||||
Airspeed(bus, bus_frequency, address, CONVERSION_INTERVAL),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address)
|
||||
MS5525(const I2CSPIDriverConfig &config) :
|
||||
Airspeed(config.bus, config.bus_frequency, config.i2c_address, CONVERSION_INTERVAL),
|
||||
I2CSPIDriver(config)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~MS5525() = default;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
void RunImpl();
|
||||
|
||||
int init() override;
|
||||
|
||||
private:
|
||||
|
||||
int measure() override;
|
||||
|
||||
@@ -35,26 +35,6 @@
|
||||
|
||||
extern "C" __EXPORT int ms5525_airspeed_main(int argc, char *argv[]);
|
||||
|
||||
I2CSPIDriverBase *MS5525::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
MS5525 *instance = new MS5525(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (instance->init() != PX4_OK) {
|
||||
delete instance;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
instance->ScheduleNow();
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MS5525::print_usage()
|
||||
{
|
||||
@@ -62,6 +42,7 @@ MS5525::print_usage()
|
||||
PRINT_MODULE_USAGE_SUBCATEGORY("airspeed_sensor");
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x76);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
@@ -71,6 +52,7 @@ ms5525_airspeed_main(int argc, char *argv[])
|
||||
using ThisDriver = MS5525;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.default_i2c_frequency = 100000;
|
||||
cli.i2c_address = I2C_ADDRESS_1_MS5525DSO;
|
||||
|
||||
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||
|
||||
@@ -79,8 +61,7 @@ ms5525_airspeed_main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli,
|
||||
DRV_DIFF_PRESS_DEVTYPE_MS5525);
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_DIFF_PRESS_DEVTYPE_MS5525);
|
||||
|
||||
if (!strcmp(verb, "start")) {
|
||||
return ThisDriver::module_start(cli, iterator);
|
||||
|
||||
@@ -124,10 +124,16 @@ SDP3X::read_scale()
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
void SDP3X::start()
|
||||
int SDP3X::init()
|
||||
{
|
||||
// make sure to wait 10ms after configuring the measurement mode
|
||||
ScheduleDelayed(10_ms);
|
||||
int ret = Airspeed::init();
|
||||
|
||||
if (ret == PX4_OK) {
|
||||
// make sure to wait 10ms after configuring the measurement mode
|
||||
ScheduleDelayed(10_ms);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -69,23 +69,20 @@
|
||||
class SDP3X : public Airspeed, public I2CSPIDriver<SDP3X>
|
||||
{
|
||||
public:
|
||||
SDP3X(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address = I2C_ADDRESS_1_SDP3X,
|
||||
bool keep_retrying = false) :
|
||||
Airspeed(bus, bus_frequency, address, CONVERSION_INTERVAL),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address),
|
||||
_keep_retrying{keep_retrying}
|
||||
SDP3X(const I2CSPIDriverConfig &config) :
|
||||
Airspeed(config.bus, config.bus_frequency, config.i2c_address, CONVERSION_INTERVAL),
|
||||
I2CSPIDriver(config),
|
||||
_keep_retrying{config.keep_running}
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~SDP3X() = default;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
void RunImpl();
|
||||
|
||||
void start();
|
||||
int init() override;
|
||||
|
||||
private:
|
||||
enum class State {
|
||||
|
||||
@@ -35,27 +35,6 @@
|
||||
|
||||
extern "C" __EXPORT int sdp3x_airspeed_main(int argc, char *argv[]);
|
||||
|
||||
I2CSPIDriverBase *SDP3X::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
SDP3X *instance = new SDP3X(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency, cli.i2c_address,
|
||||
cli.keep_running);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (instance->init() != PX4_OK) {
|
||||
delete instance;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
instance->start();
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SDP3X::print_usage()
|
||||
{
|
||||
|
||||
@@ -33,10 +33,10 @@
|
||||
|
||||
#include "GY_US42.hpp"
|
||||
|
||||
GY_US42::GY_US42(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency, int address) :
|
||||
I2C(DRV_DIST_DEVTYPE_GY_US42, MODULE_NAME, bus, address, bus_frequency),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
|
||||
_px4_rangefinder(get_device_id(), rotation)
|
||||
GY_US42::GY_US42(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_rangefinder(get_device_id(), config.rotation)
|
||||
{
|
||||
_px4_rangefinder.set_max_distance(GY_US42_MAX_DISTANCE);
|
||||
_px4_rangefinder.set_min_distance(GY_US42_MIN_DISTANCE);
|
||||
|
||||
@@ -63,12 +63,9 @@
|
||||
class GY_US42 : public device::I2C, public I2CSPIDriver<GY_US42>
|
||||
{
|
||||
public:
|
||||
GY_US42(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency,
|
||||
int address = GY_US42_BASEADDR);
|
||||
GY_US42(const I2CSPIDriverConfig &config);
|
||||
~GY_US42() override;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
int init() override;
|
||||
|
||||
@@ -47,36 +47,18 @@ GY_US42::print_usage()
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *GY_US42::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
GY_US42 *instance = new GY_US42(iterator.configuredBusOption(), iterator.bus(), cli.orientation, cli.bus_frequency);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (instance->init() != PX4_OK) {
|
||||
delete instance;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
extern "C" __EXPORT int gy_us42_main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
using ThisDriver = GY_US42;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.orientation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
cli.rotation = (Rotation)distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
cli.default_i2c_frequency = 100000;
|
||||
|
||||
while ((ch = cli.getOpt(argc, argv, "R:")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'R':
|
||||
cli.orientation = atoi(cli.optArg());
|
||||
cli.rotation = (Rotation)atoi(cli.optArg());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,13 +60,10 @@ using namespace time_literals;
|
||||
class LightwareLaser : public device::I2C, public I2CSPIDriver<LightwareLaser>
|
||||
{
|
||||
public:
|
||||
LightwareLaser(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency,
|
||||
int address = LIGHTWARE_LASER_BASEADDR);
|
||||
LightwareLaser(const I2CSPIDriverConfig &config);
|
||||
|
||||
~LightwareLaser() override;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
int init() override;
|
||||
@@ -132,11 +129,10 @@ private:
|
||||
int _consecutive_errors{0};
|
||||
};
|
||||
|
||||
LightwareLaser::LightwareLaser(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency,
|
||||
int address) :
|
||||
I2C(DRV_DIST_DEVTYPE_LIGHTWARE_LASER, MODULE_NAME, bus, address, bus_frequency),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
|
||||
_px4_rangefinder(get_device_id(), rotation)
|
||||
LightwareLaser::LightwareLaser(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_rangefinder(get_device_id(), config.rotation)
|
||||
{
|
||||
_px4_rangefinder.set_device_type(DRV_DIST_DEVTYPE_LIGHTWARE_LASER);
|
||||
}
|
||||
@@ -205,7 +201,13 @@ int LightwareLaser::init()
|
||||
}
|
||||
|
||||
/* do I2C init (and probe) first */
|
||||
return I2C::init();
|
||||
ret = I2C::init();
|
||||
|
||||
if (ret == PX4_OK) {
|
||||
start();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int LightwareLaser::readRegister(Register reg, uint8_t *data, int len)
|
||||
@@ -422,41 +424,24 @@ Setup/usage information: https://docs.px4.io/master/en/sensor/sfxx_lidar.html
|
||||
PRINT_MODULE_USAGE_SUBCATEGORY("distance_sensor");
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x66);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('R', 25, 0, 25, "Sensor rotation - downward facing by default", true);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *LightwareLaser::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
LightwareLaser* instance = new LightwareLaser(iterator.configuredBusOption(), iterator.bus(), cli.orientation, cli.bus_frequency);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (instance->init() != PX4_OK) {
|
||||
delete instance;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
instance->start();
|
||||
return instance;
|
||||
}
|
||||
|
||||
extern "C" __EXPORT int lightware_laser_i2c_main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
using ThisDriver = LightwareLaser;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.orientation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
cli.rotation = (Rotation)distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
cli.default_i2c_frequency = 400000;
|
||||
cli.i2c_address = LIGHTWARE_LASER_BASEADDR;
|
||||
|
||||
while ((ch = cli.getOpt(argc, argv, "R:")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'R':
|
||||
cli.orientation = atoi(cli.optArg());
|
||||
cli.rotation = (Rotation)atoi(cli.optArg());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,11 +41,10 @@
|
||||
|
||||
#include "LidarLiteI2C.h"
|
||||
|
||||
LidarLiteI2C::LidarLiteI2C(I2CSPIBusOption bus_option, const int bus, const uint8_t orientation, int bus_frequency,
|
||||
const int address) :
|
||||
I2C(DRV_RNG_DEVTYPE_LL40LS, MODULE_NAME, bus, address, bus_frequency),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
|
||||
_px4_rangefinder(get_device_id(), orientation)
|
||||
LidarLiteI2C::LidarLiteI2C(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_rangefinder(get_device_id(), config.rotation)
|
||||
{
|
||||
_px4_rangefinder.set_min_distance(LL40LS_MIN_DISTANCE);
|
||||
_px4_rangefinder.set_max_distance(LL40LS_MAX_DISTANCE);
|
||||
@@ -72,6 +71,7 @@ LidarLiteI2C::init()
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
start();
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,12 +94,9 @@ static constexpr uint32_t LL40LS_CONVERSION_TIMEOUT{100_ms};
|
||||
class LidarLiteI2C : public device::I2C, public I2CSPIDriver<LidarLiteI2C>
|
||||
{
|
||||
public:
|
||||
LidarLiteI2C(I2CSPIBusOption bus_option, const int bus, const uint8_t orientation, int bus_frequency,
|
||||
const int address = LL40LS_BASEADDR);
|
||||
LidarLiteI2C(const I2CSPIDriverConfig &config);
|
||||
virtual ~LidarLiteI2C();
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
|
||||
|
||||
@@ -64,30 +64,12 @@ Setup/usage information: https://docs.px4.io/master/en/sensor/lidar_lite.html
|
||||
PRINT_MODULE_USAGE_SUBCATEGORY("distance_sensor");
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x62);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('R', 25, 0, 25, "Sensor rotation - downward facing by default", true);
|
||||
PRINT_MODULE_USAGE_COMMAND("regdump");
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *LidarLiteI2C::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
LidarLiteI2C* instance = new LidarLiteI2C(iterator.configuredBusOption(), iterator.bus(), cli.orientation, cli.bus_frequency);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (instance->init() != PX4_OK) {
|
||||
delete instance;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
instance->start();
|
||||
return instance;
|
||||
}
|
||||
|
||||
void
|
||||
LidarLiteI2C::custom_method(const BusCLIArguments &cli)
|
||||
{
|
||||
@@ -99,13 +81,14 @@ extern "C" __EXPORT int ll40ls_main(int argc, char *argv[])
|
||||
int ch;
|
||||
using ThisDriver = LidarLiteI2C;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.orientation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
cli.rotation = (Rotation)distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
cli.default_i2c_frequency = 100000;
|
||||
cli.i2c_address = LL40LS_BASEADDR;
|
||||
|
||||
while ((ch = cli.getOpt(argc, argv, "R:")) != EOF) {
|
||||
switch (ch) {
|
||||
case 'R':
|
||||
cli.orientation = (enum Rotation)atoi(cli.optArg());
|
||||
cli.rotation = (enum Rotation)atoi(cli.optArg());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,11 +144,9 @@ using namespace time_literals;
|
||||
class MappyDot : public device::I2C, public ModuleParams, public I2CSPIDriver<MappyDot>
|
||||
{
|
||||
public:
|
||||
MappyDot(I2CSPIBusOption bus_option, const int bus, int bus_frequency);
|
||||
MappyDot(const I2CSPIDriverConfig &config);
|
||||
virtual ~MappyDot();
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
/**
|
||||
@@ -221,10 +219,10 @@ private:
|
||||
};
|
||||
|
||||
|
||||
MappyDot::MappyDot(I2CSPIBusOption bus_option, const int bus, int bus_frequency) :
|
||||
I2C(DRV_DIST_DEVTYPE_MAPPYDOT, MODULE_NAME, bus, MAPPYDOT_BASE_ADDR, bus_frequency),
|
||||
MappyDot::MappyDot(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
ModuleParams(nullptr),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus)
|
||||
I2CSPIDriver(config)
|
||||
{
|
||||
set_device_type(DRV_DIST_DEVTYPE_MAPPYDOT);
|
||||
}
|
||||
@@ -382,6 +380,7 @@ MappyDot::init()
|
||||
|
||||
PX4_INFO("%i sensors connected", _sensor_count);
|
||||
|
||||
start();
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
@@ -417,9 +416,6 @@ MappyDot::RunImpl()
|
||||
void
|
||||
MappyDot::start()
|
||||
{
|
||||
// Fetch parameter values.
|
||||
ModuleParams::updateParams();
|
||||
|
||||
// Schedule the driver to run on a set interval
|
||||
ScheduleOnInterval(MAPPYDOT_MEASUREMENT_INTERVAL_USEC, 10000);
|
||||
}
|
||||
@@ -434,25 +430,6 @@ MappyDot::print_usage()
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *MappyDot::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
MappyDot *instance = new MappyDot(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (instance->init() != PX4_OK) {
|
||||
delete instance;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
instance->start();
|
||||
return instance;
|
||||
}
|
||||
|
||||
extern "C" __EXPORT int mappydot_main(int argc, char *argv[])
|
||||
{
|
||||
using ThisDriver = MappyDot;
|
||||
@@ -466,6 +443,8 @@ extern "C" __EXPORT int mappydot_main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
cli.i2c_address = MAPPYDOT_BASE_ADDR;
|
||||
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_DIST_DEVTYPE_MAPPYDOT);
|
||||
|
||||
if (!strcmp(verb, "start")) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user