Skip to content

Commit

Permalink
AP_HAL_ESP32: add get_device_ptr to HAL I2CDevice API
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Jan 30, 2025
1 parent d5922b2 commit 4697365
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions libraries/AP_HAL_ESP32/I2CDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,16 @@ bool I2CDevice::adjust_periodic_callback(AP_HAL::Device::PeriodicHandle h, uint3
return bus.adjust_timer(h, period_usec);
}

AP_HAL::OwnPtr<AP_HAL::I2CDevice>
I2CDeviceManager::get_device(uint8_t bus, uint8_t address,
uint32_t bus_clock,
bool use_smbus,
uint32_t timeout_ms)
AP_HAL::I2CDevice *
I2CDeviceManager::get_device_ptr(uint8_t bus, uint8_t address,
uint32_t bus_clock,
bool use_smbus,
uint32_t timeout_ms)
{
if (bus >= ARRAY_SIZE(i2c_bus_desc)) {
return AP_HAL::OwnPtr<AP_HAL::I2CDevice>(nullptr);
return nullptr;
}
auto dev = AP_HAL::OwnPtr<AP_HAL::I2CDevice>(NEW_NOTHROW I2CDevice(bus, address, bus_clock, use_smbus, timeout_ms));
return dev;
return NEW_NOTHROW I2CDevice(bus, address, bus_clock, use_smbus, timeout_ms);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion libraries/AP_HAL_ESP32/I2CDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class I2CDeviceManager : public AP_HAL::I2CDeviceManager
return static_cast<I2CDeviceManager*>(i2c_mgr);
}

AP_HAL::OwnPtr<AP_HAL::I2CDevice> get_device(uint8_t bus, uint8_t address,
AP_HAL::I2CDevice *get_device_ptr(uint8_t bus, uint8_t address,
uint32_t bus_clock=400000,
bool use_smbus = false,
uint32_t timeout_ms=4) override;
Expand Down

0 comments on commit 4697365

Please sign in to comment.