ms5611: fix start_bus() logic to work on linux and add RPi I2C bus config (#13814)

This commit is contained in:
SalimTerryLi
2019-12-30 16:16:56 -05:00
committed by Daniel Agar
parent c8fb3c589a
commit 87e5da189b
4 changed files with 23 additions and 16 deletions
+4 -2
View File
@@ -48,8 +48,10 @@
/*
* I2C busses
*/
#define PX4_I2C_BUS_EXPANSION 1
#define PX4_NUMBER_I2C_BUSES 1
#define PX4_I2C_BUS_ONBOARD 1
#define PX4_I2C_BUS_EXPANSION 0
#define PX4_NUMBER_I2C_BUSES 2
#define ADC_BATTERY_VOLTAGE_CHANNEL 0
#define ADC_BATTERY_CURRENT_CHANNEL 1
+6 -6
View File
@@ -96,12 +96,12 @@ class MS5611 : public cdev::CDev, public px4::ScheduledWorkItem
{
public:
MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const char *path, enum MS56XX_DEVICE_TYPES device_type);
~MS5611();
~MS5611() override;
virtual int init();
int init() override;
virtual ssize_t read(cdev::file_t *filp, char *buffer, size_t buflen);
virtual int ioctl(cdev::file_t *filp, int cmd, unsigned long arg);
ssize_t read(cdev::file_t *filp, char *buffer, size_t buflen) override;
int ioctl(cdev::file_t *filp, int cmd, unsigned long arg) override;
/**
* Diagnostics - print some basic information about the driver.
@@ -168,10 +168,10 @@ protected:
*
* @return OK if the measurement command was successful.
*/
virtual int measure();
int measure();
/**
* Collect the result of the most recent measurement.
*/
virtual int collect();
int collect();
};
+5 -5
View File
@@ -50,13 +50,13 @@ class MS5611_I2C : public device::I2C
{
public:
MS5611_I2C(uint8_t bus, ms5611::prom_u &prom_buf);
virtual ~MS5611_I2C() = default;
~MS5611_I2C() override = default;
virtual int read(unsigned offset, void *data, unsigned count);
virtual int ioctl(unsigned operation, unsigned &arg);
int read(unsigned offset, void *data, unsigned count) override;
int ioctl(unsigned operation, unsigned &arg) override;
protected:
virtual int probe();
int probe() override;
private:
ms5611::prom_u &_prom;
@@ -240,7 +240,7 @@ MS5611_I2C::_read_prom()
last_val = prom_buf[0];
}
if (prom_buf[0] != last_val || prom_buf[1] != last_val) {
if ((prom_buf[0] != last_val) || (prom_buf[1] != last_val)) {
bits_stuck = false;
}
+8 -3
View File
@@ -111,9 +111,14 @@ start_bus(struct ms5611_bus_option &bus, enum MS56XX_DEVICE_TYPES device_type)
bus.dev = new MS5611(interface, prom_buf, bus.devpath, device_type);
if (bus.dev != nullptr && OK != bus.dev->init()) {
if (bus.dev == nullptr) {
PX4_ERR("alloc failed");
return false;
}
if (bus.dev->init() != PX4_OK) {
delete bus.dev;
bus.dev = NULL;
bus.dev = nullptr;
return false;
}
@@ -125,7 +130,7 @@ start_bus(struct ms5611_bus_option &bus, enum MS56XX_DEVICE_TYPES device_type)
return false;
}
if (ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
px4_close(fd);
PX4_ERR("failed setting default poll rate");
return false;