forked from Archive/PX4-Autopilot
isentek/ist8310: support starting with custom i2c address
This commit is contained in:
parent
023f6d3983
commit
af84f449c7
|
@ -40,9 +40,9 @@ static constexpr int16_t combine(uint8_t msb, uint8_t lsb)
|
|||
return (msb << 8u) | lsb;
|
||||
}
|
||||
|
||||
IST8310::IST8310(I2CSPIBusOption bus_option, int bus, int bus_frequency, enum Rotation rotation) :
|
||||
I2C(DRV_MAG_DEVTYPE_IST8310, MODULE_NAME, bus, I2C_ADDRESS_DEFAULT, bus_frequency),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus),
|
||||
IST8310::IST8310(I2CSPIBusOption bus_option, int bus, uint8_t addr, int bus_frequency, enum Rotation rotation) :
|
||||
I2C(DRV_MAG_DEVTYPE_IST8310, MODULE_NAME, bus, addr, bus_frequency),
|
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, addr),
|
||||
_px4_mag(get_device_id(), rotation)
|
||||
{
|
||||
_px4_mag.set_external(external());
|
||||
|
|
|
@ -53,7 +53,7 @@ using namespace iSentek_IST8310;
|
|||
class IST8310 : public device::I2C, public I2CSPIDriver<IST8310>
|
||||
{
|
||||
public:
|
||||
IST8310(I2CSPIBusOption bus_option, int bus, int bus_frequency, enum Rotation rotation = ROTATION_NONE);
|
||||
IST8310(I2CSPIBusOption bus_option, int bus, uint8_t addr, int bus_frequency, enum Rotation rotation = ROTATION_NONE);
|
||||
~IST8310() override;
|
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
I2CSPIDriverBase *IST8310::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||
int runtime_instance)
|
||||
{
|
||||
IST8310 *instance = new IST8310(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency, cli.rotation);
|
||||
IST8310 *instance = new IST8310(iterator.configuredBusOption(), iterator.bus(), cli.i2c_address, cli.bus_frequency,
|
||||
cli.rotation);
|
||||
|
||||
if (!instance) {
|
||||
PX4_ERR("alloc failed");
|
||||
|
@ -61,6 +62,7 @@ void IST8310::print_usage()
|
|||
PRINT_MODULE_USAGE_SUBCATEGORY("magnetometer");
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x0E);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('R', 0, 0, 35, "Rotation", true);
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
}
|
||||
|
@ -70,6 +72,7 @@ extern "C" int ist8310_main(int argc, char *argv[])
|
|||
int ch;
|
||||
using ThisDriver = IST8310;
|
||||
BusCLIArguments cli{true, false};
|
||||
cli.i2c_address = I2C_ADDRESS_DEFAULT;
|
||||
cli.default_i2c_frequency = I2C_SPEED;
|
||||
|
||||
while ((ch = cli.getopt(argc, argv, "R:")) != EOF) {
|
||||
|
|
Loading…
Reference in New Issue