diff options
author | Constantin Musca <constantin.musca@intel.com> | 2015-11-19 18:55:32 +0200 |
---|---|---|
committer | Bruce Beare <bruce.j.beare@intel.com> | 2015-12-04 10:47:16 -0800 |
commit | 269a94d72a449d9a20f789b636804be33c74d03c (patch) | |
tree | d5f75193d8519a1a98f0718172529eb8f68814ee /peripheral/sensors | |
parent | 0a9924187ea64e64698d53d86663a625141f8693 (diff) | |
download | intel-269a94d72a449d9a20f789b636804be33c74d03c.tar.gz |
sensors: use i2c-6 for arduino and i2c-1 for others
The SparkFun I2C block for Edison exposes i2c-1, not
i2c-6 like the Arduino board does.
Determine if the board is an Arduino one by checking
the existence of the TriStateAll GPIO and use the correct
i2c bus number.
BUG=25892189
Tracked-On: https://jira01.devtools.intel.com/browse/BP-128
Change-Id: Ia1037f786c483247f1e4d05b768cb80b6f023fde
Reviewed-on: https://android.intel.com/438392
Reviewed-by: Serban, Mihai <mihai.serban@intel.com>
Signed-off-by: Beare, Bruce J <bruce.j.beare@intel.com>
Signed-off-by: Constantin Musca <constantin.musca@intel.com>
Diffstat (limited to 'peripheral/sensors')
3 files changed, 39 insertions, 2 deletions
diff --git a/peripheral/sensors/edison_arduino/SensorDescriptionFactory.cpp b/peripheral/sensors/edison_arduino/SensorDescriptionFactory.cpp index a7385a1..a1ad0e8 100644 --- a/peripheral/sensors/edison_arduino/SensorDescriptionFactory.cpp +++ b/peripheral/sensors/edison_arduino/SensorDescriptionFactory.cpp @@ -15,10 +15,16 @@ */ #include <cutils/log.h> +#include <mraa.hpp> #include "SensorDescriptionFactory.hpp" #include "sensors/Sensors.hpp" +const int kTriStateAllGpioPin = 214; +const int kArduinoI2cBusNumber = 6; +const int kNonArduinoI2cBusNumber = 1; + bool SensorDescriptionFactory::initialized = false; +int SensorDescriptionFactory::i2cBusNumber = -1; struct sensor_t SensorDescriptionFactory::descriptions[Sensor::Type::kNumTypes]; struct sensor_t const * @@ -59,12 +65,32 @@ bool SensorDescriptionFactory::areFlagsSet(int handle, uint32_t flags) { return (descriptions[handle].flags & flags) == flags; } +int SensorDescriptionFactory::getI2cBusNumber() { + init(); + + return i2cBusNumber; +} + void SensorDescriptionFactory::init() { if (!SensorDescriptionFactory::initialized) { + mraa::Gpio *gpio = NULL; + for (int i = 0; i < Sensor::Type::kNumTypes; i++) { descriptions[i] = *SensorDescriptionFactory::getDescription( static_cast<Sensor::Type>(i)); } + + try { + gpio = new mraa::Gpio(kTriStateAllGpioPin); + } catch(...) {} + + if (gpio == NULL) { + i2cBusNumber = kNonArduinoI2cBusNumber; + } else { + delete gpio; + i2cBusNumber = kArduinoI2cBusNumber; + } + SensorDescriptionFactory::initialized = true; } } diff --git a/peripheral/sensors/edison_arduino/SensorDescriptionFactory.hpp b/peripheral/sensors/edison_arduino/SensorDescriptionFactory.hpp index 18807e5..ad49962 100644 --- a/peripheral/sensors/edison_arduino/SensorDescriptionFactory.hpp +++ b/peripheral/sensors/edison_arduino/SensorDescriptionFactory.hpp @@ -49,6 +49,12 @@ class SensorDescriptionFactory { */ static bool areFlagsSet(int handle, uint32_t flags); + /** + * Get sensors i2c bus number + * @return i2c bus number + */ + static int getI2cBusNumber(); + private: /* @@ -58,6 +64,7 @@ class SensorDescriptionFactory { static struct sensor_t descriptions[Sensor::Type::kNumTypes]; static bool initialized; + static int i2cBusNumber; }; #endif // SENSOR_DESCRIPTION_FACTORY_HPP diff --git a/peripheral/sensors/edison_arduino/SensorFactory.cpp b/peripheral/sensors/edison_arduino/SensorFactory.cpp index 1ba30d0..3404133 100644 --- a/peripheral/sensors/edison_arduino/SensorFactory.cpp +++ b/peripheral/sensors/edison_arduino/SensorFactory.cpp @@ -16,6 +16,7 @@ #include <cutils/log.h> #include "SensorFactory.hpp" +#include "SensorDescriptionFactory.hpp" #include "sensors/Sensors.hpp" Sensor * SensorFactory::createSensor(Sensor::Type type) { @@ -23,10 +24,13 @@ Sensor * SensorFactory::createSensor(Sensor::Type type) { switch(type) { case Sensor::Type::kMPU9150Accelerometer: return new MPU9150Accelerometer( - 6, MPU9150_DEFAULT_I2C_ADDR, AK8975_DEFAULT_I2C_ADDR, false); + SensorDescriptionFactory::getI2cBusNumber(), + MPU9150_DEFAULT_I2C_ADDR, AK8975_DEFAULT_I2C_ADDR, false); break; case Sensor::Type::kMMA7660Accelerometer: - return new MMA7660Accelerometer(6, MMA7660_DEFAULT_I2C_ADDR); + return new MMA7660Accelerometer( + SensorDescriptionFactory::getI2cBusNumber(), + MMA7660_DEFAULT_I2C_ADDR); break; case Sensor::Type::kGroveLight: return new GroveLight(0); |