Modified for compatibility with Rev.E. hardware
Fork of AkmSensor by
Diff: akmsensormanager.cpp
- Revision:
- 7:e269411568c9
- Parent:
- 6:c4401549d68f
- Child:
- 8:8fa4b81db50b
--- a/akmsensormanager.cpp Fri May 13 23:52:37 2016 +0000 +++ b/akmsensormanager.cpp Thu May 26 21:56:45 2016 +0000 @@ -11,6 +11,7 @@ #ifdef REV_D #include "mcp342x.h" #include "I2CNano.h" +#include "tca9554a.h" #endif #define FIRMWARE_VERSION 0x02 @@ -20,7 +21,7 @@ static char* AKM_PRIMARY_ID_STR[] = { - "AKD Daughter Cards(SPI)", // Temporary + "AKD Daughter Cards(SPI)", "Switch, Unipolar", "Switch, Onmipolar", "Latch, Bipolar", @@ -34,7 +35,7 @@ "Linear Sensor", "TBD3", "IR Sensor", - "Angle Sensor(SPI)", // Temporary + "Angle Sensor(SPI)", "AKD Daughter Cards(I2C)", }; @@ -72,18 +73,30 @@ // primary id check id = AkmSensorManager::getId(ANALOG_SENSOR_ID,4); -// id=14; -// subId=1; switch(id){ + case AkmSensor::AKM_PRIMARY_ID_AKD_SPI: case AkmSensor::AKM_PRIMARY_ID_AKD_I2C: subId = AkmSensorManager::getId(ANALOG_SENSOR_ID_SUB,5); // 5bit sub id AkmAkd* akd; akd = new AkmAkd(); sensor = akd; + + +#ifdef REV_D + { + const int TIME_FOR_OE_MS = 100; + const TCA9554A::Port PORT_OE_LVS2 = TCA9554A::PORT_6; + I2C i2c(I2C_SDA, I2C_SCL); + TCA9554A tca9554a(&i2c, TCA9554A::SLAVE_ADDRESS_38H); + // Makes sure that the OE is low first. + tca9554a.setPortLevel(PORT_OE_LVS2, TCA9554A::LOW); + wait_ms(TIME_FOR_OE_MS); + } +#endif + break; -// case AkmSensor::AKM_PRIMARY_ID_AKD_SPI: // Temporary case AkmSensor::AKM_PRIMARY_ID_ANGLE_SENSOR: subId = AkmSensorManager::getId(ANALOG_SENSOR_ID_SUB,4); // 4bit sub id AkmAngleSensor* angleSensor; @@ -129,6 +142,11 @@ MSG("#Can't find ID=%d SubID=%d %s\r\n", id, subId, AKM_PRIMARY_ID_STR[id]); return NULL; // couldn't find } + +#ifdef REV_D + // I2C turn off + releaseTWI(); +#endif if(sensor->init(id, subId) != AkmSensor::SUCCESS){ MSG("#sensor->init failed. ID=%d SubID=%d %s\r\n", id, subId, AKM_PRIMARY_ID_STR[id]); @@ -203,9 +221,6 @@ uint8_t value = (uint8_t)((val - VAL_MIN)/(float)(VAL_MAX - VAL_MIN) * (1 << bits) + 0.5); MSG("#ID = %d.\n", value); - - // I2C turn off - releaseTWI(); #endif return value; @@ -257,7 +272,6 @@ break; case Message::CMD_GET_ID: // return Primary ID and Sub ID - if(id == 0) id = 0xE; // Temporary for Angle Sensor resMsg.setArgument(0, id); resMsg.setArgument(1, subId); throwMessage(&resMsg);