From 700edd241fdc8a6be56eac42a3a1252db3e18f8a Mon Sep 17 00:00:00 2001 From: Scott Parlane Date: Wed, 11 Aug 2021 21:51:32 +1200 Subject: [PATCH] AP_InertialSensor: BMI160: Make it possible to use I2C The BMI160 chip talks the same protocol over SPI and I2C, so simply allowing I2C in hwdef is sufficient to allow it to be used. --- .../AP_InertialSensor_BMI160.cpp | 21 +++++++++++++++++++ .../AP_InertialSensor_BMI160.h | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/libraries/AP_InertialSensor/AP_InertialSensor_BMI160.cpp b/libraries/AP_InertialSensor/AP_InertialSensor_BMI160.cpp index 7e7522c147..76a8b9f348 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor_BMI160.cpp +++ b/libraries/AP_InertialSensor/AP_InertialSensor_BMI160.cpp @@ -146,6 +146,27 @@ AP_InertialSensor_BMI160::probe(AP_InertialSensor &imu, return sensor; } +AP_InertialSensor_Backend * +AP_InertialSensor_BMI160::probe(AP_InertialSensor &imu, + AP_HAL::OwnPtr dev) +{ + if (!dev) { + return nullptr; + } + auto sensor = new AP_InertialSensor_BMI160(imu, std::move(dev)); + + if (!sensor) { + return nullptr; + } + + if (!sensor->_init()) { + delete sensor; + return nullptr; + } + + return sensor; +} + void AP_InertialSensor_BMI160::start() { bool r; diff --git a/libraries/AP_InertialSensor/AP_InertialSensor_BMI160.h b/libraries/AP_InertialSensor/AP_InertialSensor_BMI160.h index f4fb8a187a..2264a9d2b8 100644 --- a/libraries/AP_InertialSensor/AP_InertialSensor_BMI160.h +++ b/libraries/AP_InertialSensor/AP_InertialSensor_BMI160.h @@ -17,6 +17,8 @@ #pragma once #include +#include +#include #include "AP_InertialSensor.h" #include "AP_InertialSensor_Backend.h" @@ -26,6 +28,9 @@ public: static AP_InertialSensor_Backend *probe(AP_InertialSensor &imu, AP_HAL::OwnPtr dev); + static AP_InertialSensor_Backend *probe(AP_InertialSensor &imu, + AP_HAL::OwnPtr dev); + /** * Configure the sensors and start reading routine. */