mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-16 23:33:34 +08:00
drivers: use updated I2C SPI driver interface
This commit is contained in:
@@ -33,17 +33,15 @@
|
||||
|
||||
#include "PCF8583.hpp"
|
||||
|
||||
PCF8583::PCF8583(I2CSPIBusOption bus_option, const int bus, int bus_frequency) :
|
||||
I2C(DRV_SENS_DEVTYPE_PCF8583, MODULE_NAME, bus, PCF8583_BASEADDR_DEFAULT, bus_frequency),
|
||||
PCF8583::PCF8583(const I2CSPIDriverConfig &config) :
|
||||
I2C(config),
|
||||
ModuleParams(nullptr),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus)
|
||||
I2CSPIDriver(config)
|
||||
{
|
||||
}
|
||||
|
||||
int PCF8583::init()
|
||||
{
|
||||
set_device_address(_param_pcf8583_addr.get());
|
||||
|
||||
if (I2C::init() != PX4_OK) {
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
@@ -57,11 +57,9 @@
|
||||
class PCF8583 : public device::I2C, public ModuleParams, public I2CSPIDriver<PCF8583>
|
||||
{
|
||||
public:
|
||||
PCF8583(I2CSPIBusOption bus_option, const int bus, int bus_frequency);
|
||||
PCF8583(const I2CSPIDriverConfig &config);
|
||||
~PCF8583() override = default;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance);
|
||||
static void print_usage();
|
||||
|
||||
void RunImpl();
|
||||
@@ -85,7 +83,6 @@ private:
|
||||
uORB::Publication<rpm_s> _rpm_pub{ORB_ID(rpm)};
|
||||
|
||||
DEFINE_PARAMETERS(
|
||||
(ParamInt<px4::params::PCF8583_ADDR>) _param_pcf8583_addr,
|
||||
(ParamInt<px4::params::PCF8583_POOL>) _param_pcf8583_pool,
|
||||
(ParamInt<px4::params::PCF8583_RESET>) _param_pcf8583_reset,
|
||||
(ParamInt<px4::params::PCF8583_MAGNET>) _param_pcf8583_magnet
|
||||
|
||||
@@ -42,32 +42,20 @@ PCF8583::print_usage()
|
||||
PRINT_MODULE_USAGE_NAME("pcf8583", "driver");
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(80);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *PCF8583::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
PCF8583 *instance = new PCF8583(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;
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
extern "C" __EXPORT int pcf8583_main(int argc, char *argv[])
|
||||
{
|
||||
using ThisDriver = PCF8583;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.default_i2c_frequency = 400000;
|
||||
|
||||
int32_t addr{80};
|
||||
param_get(param_find("PCF8583_ADDR"), &addr);
|
||||
cli.i2c_address = addr;
|
||||
|
||||
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||
|
||||
if (!verb) {
|
||||
|
||||
Reference in New Issue
Block a user