mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 03:13:33 +08:00
drivers: use updated I2C SPI driver interface
This commit is contained in:
@@ -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")) {
|
||||
|
||||
@@ -88,14 +88,12 @@ using namespace time_literals;
|
||||
class MB12XX : public device::I2C, public ModuleParams, public I2CSPIDriver<MB12XX>
|
||||
{
|
||||
public:
|
||||
MB12XX(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address);
|
||||
MB12XX(const I2CSPIDriverConfig &config);
|
||||
virtual ~MB12XX();
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
virtual int init() override;
|
||||
int init() override;
|
||||
|
||||
/**
|
||||
* Diagnostics - print some basic information about the driver.
|
||||
@@ -175,10 +173,10 @@ private:
|
||||
);
|
||||
};
|
||||
|
||||
MB12XX::MB12XX(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address) :
|
||||
I2C(DRV_DIST_DEVTYPE_MB12XX, MODULE_NAME, bus, address, bus_frequency),
|
||||
MB12XX::MB12XX(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
ModuleParams(nullptr),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address)
|
||||
I2CSPIDriver(config)
|
||||
{
|
||||
set_device_type(DRV_DIST_DEVTYPE_MB12XX);
|
||||
}
|
||||
@@ -319,12 +317,13 @@ MB12XX::init()
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
// If more than one sonar is detected, adjust the meaure interval to avoid sensor interference.
|
||||
// If more than one sonar is detected, adjust the measure interval to avoid sensor interference.
|
||||
if (_sensor_count > 1) {
|
||||
_measure_interval = MB12XX_INTERVAL_BETWEEN_SUCCESIVE_FIRES;
|
||||
}
|
||||
|
||||
PX4_INFO("Total sensors connected: %i", _sensor_count);
|
||||
start();
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
@@ -407,26 +406,6 @@ MB12XX::custom_method(const BusCLIArguments &cli)
|
||||
set_address(cli.i2c_address);
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *MB12XX::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
MB12XX *instance = new MB12XX(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->start();
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MB12XX::print_usage()
|
||||
{
|
||||
@@ -434,7 +413,6 @@ MB12XX::print_usage()
|
||||
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(0x70);
|
||||
PRINT_MODULE_USAGE_COMMAND("set_address");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x70);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
@@ -444,7 +422,6 @@ extern "C" __EXPORT int mb12xx_main(int argc, char *argv[])
|
||||
{
|
||||
using ThisDriver = MB12XX;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.i2c_address = MB12XX_BASE_ADDR;
|
||||
cli.default_i2c_frequency = MB12XX_BUS_SPEED;
|
||||
|
||||
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||
@@ -454,6 +431,8 @@ extern "C" __EXPORT int mb12xx_main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
cli.i2c_address = MB12XX_BASE_ADDR;
|
||||
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_DIST_DEVTYPE_MB12XX);
|
||||
|
||||
if (!strcmp(verb, "start")) {
|
||||
|
||||
@@ -33,10 +33,10 @@
|
||||
|
||||
#include "SRF02.hpp"
|
||||
|
||||
SRF02::SRF02(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency, int address) :
|
||||
I2C(DRV_DIST_DEVTYPE_SRF02, 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)
|
||||
SRF02::SRF02(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_rangefinder(get_device_id(), config.rotation)
|
||||
{
|
||||
_px4_rangefinder.set_device_type(DRV_DIST_DEVTYPE_SRF02);
|
||||
_px4_rangefinder.set_rangefinder_type(distance_sensor_s::MAV_DISTANCE_SENSOR_ULTRASOUND);
|
||||
@@ -69,7 +69,13 @@ int SRF02::init()
|
||||
// XXX we should find out why we need to wait 200 ms here
|
||||
px4_usleep(200000);
|
||||
|
||||
return measure();
|
||||
int ret = measure();
|
||||
|
||||
if (ret == PX4_OK) {
|
||||
start();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SRF02::collect()
|
||||
|
||||
@@ -65,12 +65,9 @@
|
||||
class SRF02 : public device::I2C, public I2CSPIDriver<SRF02>
|
||||
{
|
||||
public:
|
||||
SRF02(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency,
|
||||
int address = SRF02_BASEADDR);
|
||||
SRF02(const I2CSPIDriverConfig &config);
|
||||
~SRF02() override;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
int init() override;
|
||||
|
||||
@@ -43,41 +43,24 @@ SRF02::print_usage()
|
||||
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(0x70);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('R', 25, 0, 25, "Sensor rotation - downward facing by default", true);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *SRF02::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
SRF02 *instance = new SRF02(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 srf02_main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
using ThisDriver = SRF02;
|
||||
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 = SRF02_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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,10 +73,10 @@ static uint8_t crc8(uint8_t *p, uint8_t len)
|
||||
return crc & 0xFF;
|
||||
}
|
||||
|
||||
TERARANGER::TERARANGER(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency) :
|
||||
I2C(DRV_DIST_DEVTYPE_TERARANGER, MODULE_NAME, bus, TERARANGER_ONE_BASEADDR, bus_frequency),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
|
||||
_px4_rangefinder(get_device_id(), rotation)
|
||||
TERARANGER::TERARANGER(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_rangefinder(get_device_id(), config.rotation)
|
||||
{
|
||||
// up the retries since the device misses the first measure attempts
|
||||
I2C::_retries = 3;
|
||||
@@ -212,6 +212,8 @@ int TERARANGER::init()
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
start();
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,11 +75,9 @@ using namespace time_literals;
|
||||
class TERARANGER : public device::I2C, public I2CSPIDriver<TERARANGER>
|
||||
{
|
||||
public:
|
||||
TERARANGER(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency);
|
||||
TERARANGER(const I2CSPIDriverConfig &config);
|
||||
~TERARANGER() override;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
virtual int init() override;
|
||||
|
||||
@@ -53,41 +53,24 @@ Setup/usage information: https://docs.px4.io/master/en/sensor/rangefinders.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(0x30);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('R', 25, 0, 25, "Sensor rotation - downward facing by default", true);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *TERARANGER::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
TERARANGER *instance = new TERARANGER(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 teraranger_main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
using ThisDriver = TERARANGER;
|
||||
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 = TERARANGER_ONE_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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,10 +59,10 @@
|
||||
|
||||
#define VL53L0X_BUS_CLOCK 400000 // 400kHz bus clock speed
|
||||
|
||||
VL53L0X::VL53L0X(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency, int address) :
|
||||
I2C(DRV_DIST_DEVTYPE_VL53L0X, 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)
|
||||
VL53L0X::VL53L0X(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_rangefinder(get_device_id(), config.rotation)
|
||||
{
|
||||
// VL53L0X typical range 0-2 meters with 25 degree field of view
|
||||
_px4_rangefinder.set_min_distance(0.f);
|
||||
@@ -82,6 +82,18 @@ VL53L0X::~VL53L0X()
|
||||
perf_free(_comms_errors);
|
||||
}
|
||||
|
||||
int VL53L0X::init()
|
||||
{
|
||||
int ret = I2C::init();
|
||||
|
||||
if (ret != PX4_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ScheduleNow();
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
int VL53L0X::collect()
|
||||
{
|
||||
// Read from the sensor.
|
||||
@@ -489,12 +501,6 @@ int VL53L0X::singleRefCalibration(const uint8_t byte)
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
void VL53L0X::start()
|
||||
{
|
||||
// Schedule the first cycle.
|
||||
ScheduleNow();
|
||||
}
|
||||
|
||||
int VL53L0X::writeRegister(const uint8_t reg_address, const uint8_t value)
|
||||
{
|
||||
uint8_t cmd[2] {reg_address, value};
|
||||
@@ -537,41 +543,24 @@ void VL53L0X::print_usage()
|
||||
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(0x29);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('R', 25, 0, 25, "Sensor rotation - downward facing by default", true);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *VL53L0X::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
VL53L0X *instance = new VL53L0X(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 vl53l0x_main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
using ThisDriver = VL53L0X;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.default_i2c_frequency = 400000;
|
||||
cli.orientation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
cli.rotation = (Rotation)distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
cli.i2c_address = VL53L0X_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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,13 +54,10 @@
|
||||
class VL53L0X : public device::I2C, public I2CSPIDriver<VL53L0X>
|
||||
{
|
||||
public:
|
||||
VL53L0X(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency,
|
||||
int address = VL53L0X_BASEADDR);
|
||||
VL53L0X(const I2CSPIDriverConfig &config);
|
||||
|
||||
~VL53L0X() override;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
/**
|
||||
@@ -68,17 +65,14 @@ public:
|
||||
*/
|
||||
void print_status() override;
|
||||
|
||||
/**
|
||||
* Initialise the automatic measurement state machine and start it.
|
||||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Perform a poll cycle; collect from the previous measurement
|
||||
* and start a new one.
|
||||
*/
|
||||
void RunImpl();
|
||||
|
||||
int init() override;
|
||||
|
||||
private:
|
||||
int probe() override;
|
||||
|
||||
|
||||
@@ -140,10 +140,10 @@ static const uint8_t status_rtn[24] = { 255, 255, 255, 5, 2, 4, 1, 7, 3, 0,
|
||||
|
||||
/* end ST */
|
||||
|
||||
VL53L1X::VL53L1X(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency, int address) :
|
||||
I2C(DRV_DIST_DEVTYPE_VL53L1X, 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)
|
||||
VL53L1X::VL53L1X(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
I2CSPIDriver(config),
|
||||
_px4_rangefinder(get_device_id(), config.rotation)
|
||||
{
|
||||
// VL53L1X typical range 0-2 meters with 25 degree field of view
|
||||
_px4_rangefinder.set_min_distance(0.f);
|
||||
@@ -231,12 +231,6 @@ void VL53L1X::RunImpl()
|
||||
ScheduleDelayed(VL53L1X_SAMPLE_RATE);
|
||||
}
|
||||
|
||||
void VL53L1X::start()
|
||||
{
|
||||
// Schedule the first cycle.
|
||||
ScheduleNow();
|
||||
}
|
||||
|
||||
int VL53L1X::init()
|
||||
{
|
||||
int ret = PX4_OK;
|
||||
@@ -258,21 +252,18 @@ int VL53L1X::init()
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
PX4_INFO("vl53l1x init success");
|
||||
PX4_DEBUG("vl53l1x init success");
|
||||
ScheduleNow();
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
void VL53L1X::stop()
|
||||
{
|
||||
VL53L1X_StopRanging();
|
||||
}
|
||||
|
||||
void VL53L1X::print_usage()
|
||||
{
|
||||
PRINT_MODULE_USAGE_NAME("vl53l1x", "driver");
|
||||
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(0x29);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('R', 25, 1, 25, "Sensor rotation - downward facing by default", true);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
@@ -658,37 +649,19 @@ int8_t VL53L1X::VL53L1X_ConfigBig(uint16_t DM, uint16_t TimingBudgetInMs)
|
||||
|
||||
/* end ST */
|
||||
|
||||
I2CSPIDriverBase *VL53L1X::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
VL53L1X *instance = new VL53L1X(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 vl53l1x_main(int argc, char *argv[])
|
||||
{
|
||||
int ch;
|
||||
using ThisDriver = VL53L1X;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.default_i2c_frequency = 400000;
|
||||
cli.orientation = distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
cli.rotation = (Rotation)distance_sensor_s::ROTATION_DOWNWARD_FACING;
|
||||
cli.i2c_address = VL53L1X_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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,13 +98,10 @@
|
||||
class VL53L1X : public device::I2C, public I2CSPIDriver<VL53L1X>
|
||||
{
|
||||
public:
|
||||
VL53L1X(I2CSPIBusOption bus_option, const int bus, const uint8_t rotation, int bus_frequency,
|
||||
int address = VL53L1X_BASEADDR);
|
||||
VL53L1X(const I2CSPIDriverConfig &config);
|
||||
|
||||
~VL53L1X() override;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
/**
|
||||
@@ -112,16 +109,6 @@ public:
|
||||
*/
|
||||
void print_status() override;
|
||||
|
||||
/**
|
||||
* Initialise the automatic measurement state machine and start it.
|
||||
*/
|
||||
void start();
|
||||
|
||||
/**
|
||||
* Stop the automatic measurement state machine.
|
||||
*/
|
||||
void stop();
|
||||
|
||||
virtual int init() override;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user