mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 02:13:33 +08:00
drivers: use updated I2C SPI driver interface
This commit is contained in:
@@ -46,25 +46,14 @@
|
||||
|
||||
extern "C" __EXPORT int batmon_main(int argc, char *argv[]);
|
||||
|
||||
Batmon::Batmon(I2CSPIBusOption bus_option, const int bus, SMBus *interface):
|
||||
SMBUS_SBS_BaseClass(bus_option, bus, interface)
|
||||
Batmon::Batmon(const I2CSPIDriverConfig &config, SMBus *interface):
|
||||
SMBUS_SBS_BaseClass(config, interface)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Batmon::~Batmon()
|
||||
I2CSPIDriverBase *Batmon::instantiate(const I2CSPIDriverConfig &config, int runtime_instance)
|
||||
{
|
||||
// Needn't change the parameter since there are other modules that may use it.
|
||||
//int battsource = 0;
|
||||
//param_set(param_find("BAT_SOURCE"), &battsource);
|
||||
}
|
||||
|
||||
I2CSPIDriverBase *Batmon::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
|
||||
{
|
||||
//TODO there may be a better way to pass the driver ID, since iterator object should have it
|
||||
SMBus *interface = new SMBus(DRV_BAT_DEVTYPE_BATMON_SMBUS, iterator.bus(), cli.i2c_address);
|
||||
SMBus *interface = new SMBus(config.devid_driver_index, config.bus, config.i2c_address);
|
||||
|
||||
int32_t batmon_en_param = 0;
|
||||
param_get(param_find("BATMON_DRIVER_EN"), &batmon_en_param);
|
||||
@@ -78,7 +67,7 @@ I2CSPIDriverBase *Batmon::instantiate(const BusCLIArguments &cli, const BusInsta
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Batmon *instance = new Batmon(iterator.configuredBusOption(), iterator.bus(), interface);
|
||||
Batmon *instance = new Batmon(config, interface);
|
||||
|
||||
if (instance == nullptr) {
|
||||
PX4_ERR("alloc failed");
|
||||
|
||||
@@ -54,16 +54,16 @@ class Batmon : public SMBUS_SBS_BaseClass<Batmon>
|
||||
{
|
||||
|
||||
public:
|
||||
Batmon(I2CSPIBusOption bus_option, const int bus, SMBus *interface);
|
||||
~Batmon();
|
||||
Batmon(const I2CSPIDriverConfig &config, SMBus *interface);
|
||||
~Batmon() = default;
|
||||
|
||||
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();
|
||||
|
||||
void RunImpl();
|
||||
enum {
|
||||
|
||||
enum BATMON_REGISTERS {
|
||||
BATT_SMBUS_TEMP_EXTERNAL_1 = 0x48,
|
||||
BATT_SMBUS_TEMP_EXTERNAL_2 = 0x49,
|
||||
BATT_SMBUS_CELL_1_VOLTAGE = 0x3F,
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
BATT_SMBUS_CELL_15_VOLTAGE = 0x31,
|
||||
BATT_SMBUS_CELL_16_VOLTAGE = 0x30,
|
||||
BATT_SMBUS_CELL_COUNT = 0x40
|
||||
} BATMON_REGISTERS;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user