From 8c06e6cddcf7ee779316295a6c2306876b7a0dd4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 11 May 2016 12:14:27 +1000 Subject: [PATCH] Revert "AP_HAL_PX4: embed PX4_I2C object into I2CDevice" This reverts commit 54fd3702c3c834b901377aaf36857697e021666b. These commits broke startup on PX4 --- libraries/AP_HAL_PX4/I2CDevice.cpp | 34 ++++++++++++++++-------------- libraries/AP_HAL_PX4/I2CDevice.h | 15 ++++++------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/libraries/AP_HAL_PX4/I2CDevice.cpp b/libraries/AP_HAL_PX4/I2CDevice.cpp index a1c6d18923..636b9fe66f 100644 --- a/libraries/AP_HAL_PX4/I2CDevice.cpp +++ b/libraries/AP_HAL_PX4/I2CDevice.cpp @@ -4,29 +4,26 @@ namespace PX4 { -I2CDevice::PX4_I2C::PX4_I2C(uint8_t bus) - : I2C("AP_I2C", "/dev/api2c", bus, 0, 400000UL) +class PX4_I2C : public device::I2C { +public: + PX4_I2C(uint8_t bus); + bool do_transfer(uint8_t address, const uint8_t *send, uint32_t send_len, + uint8_t *recv, uint32_t recv_len); +}; + +PX4_I2C::PX4_I2C(uint8_t bus) : + I2C("AP_I2C", "/dev/api2c", bus, 0, 400000UL) { init(); } -bool I2CDevice::PX4_I2C::do_transfer(uint8_t address, const uint8_t *send, uint32_t send_len, - uint8_t *recv, uint32_t recv_len) +bool PX4_I2C::do_transfer(uint8_t address, const uint8_t *send, uint32_t send_len, + uint8_t *recv, uint32_t recv_len) { set_address(address); return transfer(send, send_len, recv, recv_len) == OK; } -I2CDevice::I2CDevice(uint8_t bus, uint8_t address) - : _device(bus) - , _address(address) -{ -} - -I2CDevice::~I2CDevice() -{ -} - bool I2CDevice::transfer(const uint8_t *send, uint32_t send_len, uint8_t *recv, uint32_t recv_len) { @@ -57,6 +54,10 @@ AP_HAL::Semaphore *I2CDevice::get_semaphore() return &semaphore; } +I2CDevice::~I2CDevice() +{ +} + I2CDeviceManager::I2CDeviceManager() { } @@ -64,8 +65,9 @@ I2CDeviceManager::I2CDeviceManager() AP_HAL::OwnPtr I2CDeviceManager::get_device(uint8_t bus, uint8_t address) { - auto dev = AP_HAL::OwnPtr(new I2CDevice(bus, address)); + AP_HAL::OwnPtr i2c { new PX4_I2C(bus) }; + auto dev = AP_HAL::OwnPtr(new I2CDevice(*i2c, address)); + return dev; } - } diff --git a/libraries/AP_HAL_PX4/I2CDevice.h b/libraries/AP_HAL_PX4/I2CDevice.h index 819f5f41ef..9bad240e68 100644 --- a/libraries/AP_HAL_PX4/I2CDevice.h +++ b/libraries/AP_HAL_PX4/I2CDevice.h @@ -21,7 +21,11 @@ public: } /* AP_HAL::I2CDevice implementation */ - I2CDevice(uint8_t bus, uint8_t address); + I2CDevice(PX4_I2C &device, uint8_t address) + : _device(device) + , _address(address) + { + } ~I2CDevice(); @@ -57,14 +61,7 @@ public: int get_fd() override; protected: - class PX4_I2C : public device::I2C { - public: - PX4_I2C(uint8_t bus); - bool do_transfer(uint8_t address, const uint8_t *send, uint32_t send_len, - uint8_t *recv, uint32_t recv_len); - }; - - PX4_I2C _device; + PX4_I2C &_device; uint8_t _address; uint8_t _retries = 0;