From 861ded37db9ece62699722928b2581a225348115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 12 Nov 2022 17:12:40 +0100 Subject: [PATCH] remember which devices were scanned on which bus and set them accordingly. --- src/detect/i2cScan.h | 65 +++++++++---------- src/gps/RTC.cpp | 44 +++++++++---- src/graphics/EInkDisplay2.cpp | 2 +- src/graphics/EInkDisplay2.h | 2 +- src/graphics/Screen.cpp | 2 +- src/graphics/Screen.h | 2 +- src/graphics/TFTDisplay.cpp | 2 +- src/graphics/TFTDisplay.h | 2 +- src/input/cardKbI2cImpl.cpp | 2 +- src/input/kbI2cBase.cpp | 45 +++++++------ src/main.cpp | 39 +++-------- src/main.h | 10 ++- src/modules/CannedMessageModule.cpp | 5 +- src/modules/Telemetry/Sensor/BME280Sensor.cpp | 10 ++- src/modules/Telemetry/Sensor/BME680Sensor.cpp | 7 ++ src/modules/Telemetry/Sensor/BMP280Sensor.cpp | 8 +++ src/modules/Telemetry/Sensor/INA219Sensor.cpp | 8 ++- src/modules/Telemetry/Sensor/INA260Sensor.cpp | 8 ++- .../Telemetry/Sensor/LPS22HBSensor.cpp | 8 ++- .../Telemetry/Sensor/MCP9808Sensor.cpp | 8 ++- src/modules/Telemetry/Sensor/SHTC3Sensor.cpp | 13 +++- .../Telemetry/Sensor/TelemetrySensor.h | 2 +- src/platform/esp32/main-esp32.cpp | 2 +- 23 files changed, 177 insertions(+), 119 deletions(-) diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 0b8f59c14..d44c52199 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -44,25 +44,25 @@ void printATECCInfo() #endif } -uint16_t getRegisterValue(uint8_t address, uint8_t reg, uint8_t length) { +uint16_t getRegisterValue(uint8_t address, uint8_t reg, uint8_t length, TwoWire myWire) { uint16_t value = 0x00; - Wire.beginTransmission(address); - Wire.write(reg); - Wire.endTransmission(); + myWire.beginTransmission(address); + myWire.write(reg); + myWire.endTransmission(); delay(20); - Wire.requestFrom(address, length); - DEBUG_MSG("Wire.available() = %d\n", Wire.available()); - if (Wire.available() == 2) { + myWire.requestFrom(address, length); + DEBUG_MSG("Wire.available() = %d\n", myWire.available()); + if (myWire.available() == 2) { // Read MSB, then LSB - value = (uint16_t)Wire.read() << 8; - value |= Wire.read(); - } else if (Wire.available()) { - value = Wire.read(); + value = (uint16_t)myWire.read() << 8; + value |= myWire.read(); + } else if (myWire.available()) { + value = myWire.read(); } return value; } -uint8_t oled_probe(byte addr) +uint8_t oled_probe(byte addr, TwoWire myWire) { uint8_t r = 0; uint8_t r_prev = 0; @@ -70,12 +70,12 @@ uint8_t oled_probe(byte addr) uint8_t o_probe = 0; do { r_prev = r; - Wire.beginTransmission(addr); - Wire.write(0x00); - Wire.endTransmission(); - Wire.requestFrom((int)addr, 1); - if (Wire.available()) { - r = Wire.read(); + myWire.beginTransmission(addr); + myWire.write(0x00); + myWire.endTransmission(); + myWire.requestFrom((int)addr, 1); + if (myWire.available()) { + r = myWire.read(); } r &= 0x0f; @@ -90,24 +90,24 @@ uint8_t oled_probe(byte addr) return o_probe; } -void scanI2Cdevice(bool partial) +void scanI2Cdevice(TwoWire myWire, uint8_t busnum) { byte err, addr; uint16_t registerValue = 0x00; int nDevices = 0; for (addr = 1; addr < 127; addr++) { - if (partial && addr != SSD1306_ADDRESS && addr != ST7567_ADDRESS && addr != XPOWERS_AXP192_AXP2101_ADDRESS) - continue; - Wire.beginTransmission(addr); - err = Wire.endTransmission(); + myWire.beginTransmission(addr); + err = myWire.endTransmission(); if (err == 0) { DEBUG_MSG("I2C device found at address 0x%x\n", addr); + i2cScanMap[addr] = {addr, busnum}; + nDevices++; if (addr == SSD1306_ADDRESS) { screen_found = addr; - screen_model = oled_probe(addr); + screen_model = oled_probe(addr, myWire); if (screen_model == 1) { DEBUG_MSG("ssd1306 display found\n"); } else if (screen_model == 2) { @@ -118,8 +118,7 @@ void scanI2Cdevice(bool partial) } #ifndef ARCH_PORTDUINO if (addr == ATECC608B_ADDR) { - keystore_found = addr; - if (atecc.begin(keystore_found) == true) { + if (atecc.begin(ATECC608B_ADDR) == true) { DEBUG_MSG("ATECC608B initialized\n"); } else { DEBUG_MSG("ATECC608B initialization failed\n"); @@ -129,24 +128,21 @@ void scanI2Cdevice(bool partial) #endif #ifdef RV3028_RTC if (addr == RV3028_RTC){ - rtc_found = addr; DEBUG_MSG("RV3028 RTC found\n"); Melopero_RV3028 rtc; - rtc.initI2C(); + rtc.initI2C(myWire); rtc.writeToRegister(0x35,0x07); // no Clkout rtc.writeToRegister(0x37,0xB4); } #endif #ifdef PCF8563_RTC if (addr == PCF8563_RTC){ - rtc_found = addr; DEBUG_MSG("PCF8563 RTC found\n"); } #endif if (addr == CARDKB_ADDR) { - cardkb_found = addr; // Do we have the RAK14006 instead? - registerValue = getRegisterValue(addr, 0x04, 1); + registerValue = getRegisterValue(addr, 0x04, 1, myWire); if (registerValue == 0x02) { // KEYPAD_VERSION DEBUG_MSG("RAK14004 found\n"); kb_model = 0x02; @@ -161,12 +157,11 @@ void scanI2Cdevice(bool partial) } #ifdef HAS_PMU if (addr == XPOWERS_AXP192_AXP2101_ADDRESS) { - pmu_found = true; DEBUG_MSG("axp192/axp2101 PMU found\n"); } #endif if (addr == BME_ADDR || addr == BME_ADDR_ALTERNATE) { - registerValue = getRegisterValue(addr, 0xD0, 1); // GET_ID + registerValue = getRegisterValue(addr, 0xD0, 1, myWire); // GET_ID if (registerValue == 0x61) { DEBUG_MSG("BME-680 sensor found at address 0x%x\n", (uint8_t)addr); nodeTelemetrySensorsMap[TelemetrySensorType_BME680] = addr; @@ -179,7 +174,7 @@ void scanI2Cdevice(bool partial) } } if (addr == INA_ADDR || addr == INA_ADDR_ALTERNATE) { - registerValue = getRegisterValue(addr, 0xFE, 2); + registerValue = getRegisterValue(addr, 0xFE, 2, myWire); DEBUG_MSG("Register MFG_UID: 0x%x\n", registerValue); if (registerValue == 0x5449) { DEBUG_MSG("INA260 sensor found at address 0x%x\n", (uint8_t)addr); @@ -226,5 +221,5 @@ void scanI2Cdevice(bool partial) DEBUG_MSG("%i I2C devices found\n",nDevices); } #else -void scanI2Cdevice(bool partial) {} +void scanI2Cdevice() {} #endif diff --git a/src/gps/RTC.cpp b/src/gps/RTC.cpp index e04f903ee..b46db9bc5 100644 --- a/src/gps/RTC.cpp +++ b/src/gps/RTC.cpp @@ -20,10 +20,16 @@ void readFromRTC() { struct timeval tv; /* btw settimeofday() is helpfull here too*/ #ifdef RV3028_RTC - if(rtc_found == RV3028_RTC) { + if(i2cScanMap[RV3028_RTC].addr == RV3028_RTC) { uint32_t now = millis(); Melopero_RV3028 rtc; - rtc.initI2C(); + if (i2cScanMap[RV3028_RTC].bus == 1) { +#ifdef I2C_SDA1 + rtc.initI2C(Wire1); +#endif + } else { + rtc.initI2C(); + } tm t; t.tm_year = rtc.getYear() - 1900; t.tm_mon = rtc.getMonth() - 1; @@ -41,14 +47,16 @@ void readFromRTC() } } #elif defined(PCF8563_RTC) - if(rtc_found == PCF8563_RTC) { + if(i2cScanMap[PCF8563_RTC].addr == PCF8563_RTC) { uint32_t now = millis(); PCF8563_Class rtc; -#ifdef RTC_USE_WIRE1 - rtc.begin(Wire1); -#else - rtc.begin(); + if (i2cScanMap[PCF8563_RTC].bus == 1) { +#ifdef I2C_SDA1 + rtc.begin(Wire1); #endif + } else { + rtc.begin(); + } auto tc = rtc.getDateTime(); tm t; t.tm_year = tc.year - 1900; @@ -104,21 +112,29 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv) // If this platform has a setable RTC, set it #ifdef RV3028_RTC - if(rtc_found == RV3028_RTC) { + if(i2cScanMap[RV3028_RTC].addr == RV3028_RTC) { Melopero_RV3028 rtc; - rtc.initI2C(); + if (i2cScanMap[RV3028_RTC].bus == 1) { +#ifdef I2C_SDA1 + rtc.initI2C(Wire1); +#endif + } else { + rtc.initI2C(); + } tm *t = localtime(&tv->tv_sec); rtc.setTime(t->tm_year + 1900, t->tm_mon + 1, t->tm_wday, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); DEBUG_MSG("RV3028_RTC setTime %02d-%02d-%02d %02d:%02d:%02d %ld\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv->tv_sec); } #elif defined(PCF8563_RTC) - if(rtc_found == PCF8563_RTC) { + if(i2cScanMap[PCF8563_RTC].addr == PCF8563_RTC) { PCF8563_Class rtc; -#ifdef RTC_USE_WIRE1 - rtc.begin(Wire1); -#else - rtc.begin(); + if (i2cScanMap[PCF8563_RTC].bus == 1) { +#ifdef I2C_SDA1 + rtc.begin(Wire1); #endif + } else { + rtc.begin(); + } tm *t = localtime(&tv->tv_sec); rtc.setDateTime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); DEBUG_MSG("PCF8563_RTC setDateTime %02d-%02d-%02d %02d:%02d:%02d %ld\n", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv->tv_sec); diff --git a/src/graphics/EInkDisplay2.cpp b/src/graphics/EInkDisplay2.cpp index 9e0834954..03b57babd 100644 --- a/src/graphics/EInkDisplay2.cpp +++ b/src/graphics/EInkDisplay2.cpp @@ -40,7 +40,7 @@ GxEPD2_BW *adafruitDisplay; -EInkDisplay::EInkDisplay(uint8_t address, int sda, int scl) +EInkDisplay::EInkDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus) { #if defined(TTGO_T_ECHO) setGeometry(GEOMETRY_RAWMODE, TECHO_DISPLAY_MODEL::WIDTH, TECHO_DISPLAY_MODEL::HEIGHT); diff --git a/src/graphics/EInkDisplay2.h b/src/graphics/EInkDisplay2.h index 727132d0e..a8cc4f1fa 100644 --- a/src/graphics/EInkDisplay2.h +++ b/src/graphics/EInkDisplay2.h @@ -22,7 +22,7 @@ class EInkDisplay : public OLEDDisplay /* constructor FIXME - the parameters are not used, just a temporary hack to keep working like the old displays */ - EInkDisplay(uint8_t address, int sda, int scl); + EInkDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus); // Write the buffer to the display memory (for eink we only do this occasionally) virtual void display(void) override; diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 277127d53..0833dda93 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -872,7 +872,7 @@ void _screen_header() // } // } // #else -Screen::Screen(uint8_t address, int sda, int scl) : OSThread("Screen"), cmdQueue(32), dispdev(address, sda, scl), ui(&dispdev) +Screen::Screen(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus) : OSThread("Screen"), cmdQueue(32), dispdev(address, sda, scl, g, i2cBus), ui(&dispdev) { address_found = address; cmdQueue.setReader(this); diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 23828b3ee..1483e8261 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -115,7 +115,7 @@ class Screen : public concurrency::OSThread CallbackObserver(this, &Screen::handleUIFrameEvent); public: - explicit Screen(uint8_t address, int sda = -1, int scl = -1); + explicit Screen(uint8_t address, int sda = -1, int scl = -1,OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64, HW_I2C i2cBus = I2C_ONE); Screen(const Screen &) = delete; Screen &operator=(const Screen &) = delete; diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 1d5f43cd1..5786a0ba1 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -8,7 +8,7 @@ static TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h -TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl) +TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus) { #ifdef SCREEN_ROTATE setGeometry(GEOMETRY_RAWMODE, TFT_HEIGHT, TFT_WIDTH); diff --git a/src/graphics/TFTDisplay.h b/src/graphics/TFTDisplay.h index c9749d9a8..d201839b9 100644 --- a/src/graphics/TFTDisplay.h +++ b/src/graphics/TFTDisplay.h @@ -18,7 +18,7 @@ class TFTDisplay : public OLEDDisplay /* constructor FIXME - the parameters are not used, just a temporary hack to keep working like the old displays */ - TFTDisplay(uint8_t address, int sda, int scl); + TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus); // Write the buffer to the display memory virtual void display(void) override; diff --git a/src/input/cardKbI2cImpl.cpp b/src/input/cardKbI2cImpl.cpp index de0fbbd38..bef99f4c3 100644 --- a/src/input/cardKbI2cImpl.cpp +++ b/src/input/cardKbI2cImpl.cpp @@ -10,7 +10,7 @@ CardKbI2cImpl::CardKbI2cImpl() : void CardKbI2cImpl::init() { - if (cardkb_found != CARDKB_ADDR) + if (i2cScanMap[CARDKB_ADDR].addr != CARDKB_ADDR) { // Input device is not detected. return; diff --git a/src/input/kbI2cBase.cpp b/src/input/kbI2cBase.cpp index 332dfde0d..7285d3919 100644 --- a/src/input/kbI2cBase.cpp +++ b/src/input/kbI2cBase.cpp @@ -1,52 +1,59 @@ #include "kbI2cBase.h" #include "configuration.h" +#include "main.h" #include -extern uint8_t cardkb_found; -extern uint8_t kb_model; KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name) { this->_originName = name; } -uint8_t read_from_14004(uint8_t reg, uint8_t *data, uint8_t length) +uint8_t read_from_14004(uint8_t reg, uint8_t *data, uint8_t length, TwoWire myWire) { uint8_t readflag = 0; - Wire.beginTransmission(CARDKB_ADDR); - Wire.write(reg); - Wire.endTransmission(); // stop transmitting + myWire.beginTransmission(CARDKB_ADDR); + myWire.write(reg); + myWire.endTransmission(); // stop transmitting delay(20); - Wire.requestFrom(CARDKB_ADDR, (int)length); + myWire.requestFrom(CARDKB_ADDR, (int)length); int i = 0; - while ( Wire.available() ) // slave may send less than requested + while ( myWire.available() ) // slave may send less than requested { - data[i++] = Wire.read(); // receive a byte as a proper uint8_t + data[i++] = myWire.read(); // receive a byte as a proper uint8_t readflag = 1; } return readflag; } -void write_to_14004(uint8_t reg, uint8_t data) +void write_to_14004(uint8_t reg, uint8_t data, TwoWire myWire) { - Wire.beginTransmission(CARDKB_ADDR); - Wire.write(reg); - Wire.write(data); - Wire.endTransmission(); // stop transmitting + myWire.beginTransmission(CARDKB_ADDR); + myWire.write(reg); + myWire.write(data); + myWire.endTransmission(); // stop transmitting } int32_t KbI2cBase::runOnce() { - if (cardkb_found != CARDKB_ADDR){ + if (i2cScanMap[CARDKB_ADDR].addr != CARDKB_ADDR) { // Input device is not detected. return INT32_MAX; } + TwoWire myWire = Wire; + + if (i2cScanMap[CARDKB_ADDR].bus == 1) { +#ifdef I2C_SDA1 + myWire = Wire1; +#endif + } + if (kb_model == 0x02) { // RAK14004 uint8_t rDataBuf[8] = {0}; uint8_t PrintDataBuf = 0; - if (read_from_14004(0x01, rDataBuf, 0x04) == 1) { + if (read_from_14004(0x01, rDataBuf, 0x04, myWire) == 1) { for (uint8_t aCount = 0; aCount < 0x04; aCount++) { for (uint8_t bCount = 0; bCount < 0x04; bCount++ ) { if (((rDataBuf[aCount] >> bCount) & 0x01) == 0x01) { @@ -65,10 +72,10 @@ int32_t KbI2cBase::runOnce() } } else { // m5 cardkb - Wire.requestFrom(CARDKB_ADDR, 1); + myWire.requestFrom(CARDKB_ADDR, 1); - while (Wire.available()) { - char c = Wire.read(); + while (myWire.available()) { + char c = myWire.read(); InputEvent e; e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_NONE; e.source = this->_originName; diff --git a/src/main.cpp b/src/main.cpp index 2bf2a0de1..195be3edc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,16 +79,9 @@ meshtastic::NodeStatus *nodeStatus = new meshtastic::NodeStatus(); uint8_t screen_found; uint8_t screen_model; -// The I2C address of the cardkb or RAK14004 (if found) -uint8_t cardkb_found; // 0x02 for RAK14004 and 0x00 for cardkb uint8_t kb_model; -// The I2C address of the RTC Module (if found) -uint8_t rtc_found; - -// Keystore Chips -uint8_t keystore_found; #ifndef ARCH_PORTDUINO ATECCX08A atecc; #endif @@ -102,6 +95,8 @@ bool pmu_found; // Array map of sensor types (as array index) and i2c address as value we'll find in the i2c scan uint8_t nodeTelemetrySensorsMap[_TelemetrySensorType_MAX + 1] = { 0 }; // one is enough, missing elements will be initialized to 0 anyway. +scanmap i2cScanMap[128] = { 0 }; + Router *router = NULL; // Users of router don't care what sort of subclass implements that API const char *getDeviceName() @@ -179,7 +174,8 @@ void setup() initDeepSleep(); - // Testing this fix für erratic T-Echo boot behaviour +// The T-Echo needs to switch the peripheral power rail on before we can do anything else +// this controls much more than just the display, so we do it first #if defined(TTGO_T_ECHO) && defined(PIN_EINK_PWR_ON) pinMode(PIN_EINK_PWR_ON, OUTPUT); digitalWrite(PIN_EINK_PWR_ON, HIGH); @@ -216,7 +212,6 @@ void setup() fsInit(); - // router = new DSRRouter(); router = new ReliableRouter(); #ifdef I2C_SDA1 @@ -252,19 +247,12 @@ void setup() powerStatus->observe(&power->newStatus); power->setup(); // Must be after status handler is installed, so that handler gets notified of the initial configuration - -#ifdef LILYGO_TBEAM_S3_CORE - // In T-Beam-S3-core, the I2C device cannot be scanned before power initialization, otherwise the device will be stuck - // PCF8563 RTC in tbeam-s3 uses Wire1 to share I2C bus - Wire1.beginTransmission(PCF8563_RTC); - if (Wire1.endTransmission() == 0){ - rtc_found = PCF8563_RTC; - DEBUG_MSG("PCF8563 RTC found\n"); - } -#endif - // We need to scan here to decide if we have a screen for nodeDB.init() - scanI2Cdevice(); + scanI2Cdevice(Wire,0); + +#ifdef I2C_SDA1 + scanI2Cdevice(Wire1,1); +#endif #ifdef HAS_SDCARD setupSDCard(); @@ -304,13 +292,6 @@ void setup() playStartMelody(); - - /* - * Repeat the scanning for I2C devices after power initialization or look for 'latecomers'. - * Boards with an PMU need to be powered on to correctly scan to the device address, such as t-beam-s3-core - */ - // scanI2Cdevice(); - // fixed screen override? if (config.display.oled != Config_DisplayConfig_OledType_OLED_AUTO) screen_model = config.display.oled; @@ -346,7 +327,7 @@ void setup() // Do this after service.init (because that clears error_code) #ifdef HAS_PMU - if (!pmu_found) + if (i2cScanMap[XPOWERS_AXP192_AXP2101_ADDRESS].addr == 0) RECORD_CRITICALERROR(CriticalErrorCode_NO_AXP192); // Record a hardware fault for missing hardware #endif diff --git a/src/main.h b/src/main.h index b7b41c250..2387f21c2 100644 --- a/src/main.h +++ b/src/main.h @@ -12,10 +12,7 @@ extern uint8_t screen_found; extern uint8_t screen_model; -extern uint8_t cardkb_found; extern uint8_t kb_model; -extern uint8_t rtc_found; -extern uint8_t keystore_found; extern bool eink_found; extern bool pmu_found; @@ -26,6 +23,13 @@ extern bool isUSBPowered; extern ATECCX08A atecc; #endif +typedef struct _scanmap { + uint8_t addr; + uint8_t bus; +} scanmap; + +extern scanmap i2cScanMap[128]; + extern uint8_t nodeTelemetrySensorsMap[_TelemetrySensorType_MAX + 1]; extern int TCPPort; // set by Portduino diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index b00dfb796..64a9df445 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -5,6 +5,7 @@ #include "NodeDB.h" #include "MeshService.h" #include "PowerFSM.h" // neede for button bypass +#include "main.h" #include "mesh/generated/cannedmessages.pb.h" #ifdef OLED_RU @@ -35,8 +36,6 @@ // Remove Canned message screen if no action is taken for some milliseconds #define INACTIVATE_AFTER_MS 20000 -extern uint8_t cardkb_found; - static const char *cannedMessagesConfigFile = "/prefs/cannedConf.proto"; CannedMessageModuleConfig cannedMessageModuleConfig; @@ -53,7 +52,7 @@ CannedMessageModule::CannedMessageModule() { if (moduleConfig.canned_message.enabled) { this->loadProtoForModule(); - if ((this->splitConfiguredMessages() <= 0) && (cardkb_found != CARDKB_ADDR)) { + if ((this->splitConfiguredMessages() <= 0) && (i2cScanMap[CARDKB_ADDR].addr != CARDKB_ADDR)) { DEBUG_MSG("CannedMessageModule: No messages are configured. Module is disabled\n"); this->runState = CANNED_MESSAGE_RUN_STATE_DISABLED; } else { diff --git a/src/modules/Telemetry/Sensor/BME280Sensor.cpp b/src/modules/Telemetry/Sensor/BME280Sensor.cpp index 4b6a50091..655356363 100644 --- a/src/modules/Telemetry/Sensor/BME280Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BME280Sensor.cpp @@ -15,8 +15,14 @@ int32_t BME280Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = bme280.begin(nodeTelemetrySensorsMap[sensorType]); - + if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { +#ifdef I2C_SDA1 + status = bme280.begin(nodeTelemetrySensorsMap[sensorType], &Wire1); +#endif + } else { + status = bme280.begin(nodeTelemetrySensorsMap[sensorType], &Wire); + } + bme280.setSampling( Adafruit_BME280::MODE_FORCED, Adafruit_BME280::SAMPLING_X1, // Temp. oversampling Adafruit_BME280::SAMPLING_X1, // Pressure oversampling diff --git a/src/modules/Telemetry/Sensor/BME680Sensor.cpp b/src/modules/Telemetry/Sensor/BME680Sensor.cpp index a9171facf..9cc2f6430 100644 --- a/src/modules/Telemetry/Sensor/BME680Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BME680Sensor.cpp @@ -14,6 +14,13 @@ int32_t BME680Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } + if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { +#ifdef I2C_SDA1 + bme680 = Adafruit_BME680(&Wire1); +#endif + } else { + bme680 = Adafruit_BME680(&Wire); + } status = bme680.begin(nodeTelemetrySensorsMap[sensorType]); return initI2CSensor(); diff --git a/src/modules/Telemetry/Sensor/BMP280Sensor.cpp b/src/modules/Telemetry/Sensor/BMP280Sensor.cpp index 917c40d6f..2abbb2927 100644 --- a/src/modules/Telemetry/Sensor/BMP280Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BMP280Sensor.cpp @@ -15,6 +15,14 @@ int32_t BMP280Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } + if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { +#ifdef I2C_SDA1 + bmp280 = Adafruit_BMP280(&Wire1); +#endif + } else { + bmp280 = Adafruit_BMP280(&Wire); + } + status = bmp280.begin(nodeTelemetrySensorsMap[sensorType]); bmp280.setSampling( Adafruit_BMP280::MODE_FORCED, diff --git a/src/modules/Telemetry/Sensor/INA219Sensor.cpp b/src/modules/Telemetry/Sensor/INA219Sensor.cpp index 3e280c526..04e0356b4 100644 --- a/src/modules/Telemetry/Sensor/INA219Sensor.cpp +++ b/src/modules/Telemetry/Sensor/INA219Sensor.cpp @@ -14,8 +14,14 @@ int32_t INA219Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } + if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { ina219 = Adafruit_INA219(nodeTelemetrySensorsMap[sensorType]); - status = ina219.begin(); +#ifdef I2C_SDA1 + status = ina219.begin(&Wire1); +#endif + } else { + status = ina219.begin(&Wire); + } return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/INA260Sensor.cpp b/src/modules/Telemetry/Sensor/INA260Sensor.cpp index 1c924ad71..3d34344a0 100644 --- a/src/modules/Telemetry/Sensor/INA260Sensor.cpp +++ b/src/modules/Telemetry/Sensor/INA260Sensor.cpp @@ -14,7 +14,13 @@ int32_t INA260Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = ina260.begin(nodeTelemetrySensorsMap[sensorType]); + if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { +#ifdef I2C_SDA1 + status = ina260.begin(nodeTelemetrySensorsMap[sensorType], &Wire1); +#endif + } else { + status = ina260.begin(nodeTelemetrySensorsMap[sensorType], &Wire); + } return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp b/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp index 1209c1435..dad1895b6 100644 --- a/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp +++ b/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp @@ -15,7 +15,13 @@ int32_t LPS22HBSensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType]); + if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { +#ifdef I2C_SDA1 + status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType], &Wire1); +#endif + } else { + status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType], &Wire); + } return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp b/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp index 57092d285..29aa16009 100644 --- a/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp +++ b/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp @@ -14,7 +14,13 @@ int32_t MCP9808Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType]); + if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { +#ifdef I2C_SDA1 + status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType], &Wire1); +#endif + } else { + status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType], &Wire); + } return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp b/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp index b3a76ba91..bbc7b8479 100644 --- a/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp +++ b/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp @@ -14,7 +14,18 @@ int32_t SHTC3Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - status = shtc3.begin(); + if (i2cScanMap[SHTC3_ADDR].addr == 0) { + DEBUG_MSG("SHTC3 not found on i2c bus\n"); + return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; + } + if(i2cScanMap[SHTC3_ADDR].bus == 1) { +#ifdef I2C_SDA1 + status = shtc3.begin(&Wire1); +#endif + } else { + status = shtc3.begin(&Wire); + } + return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/TelemetrySensor.h b/src/modules/Telemetry/Sensor/TelemetrySensor.h index 12bf17e56..772744449 100644 --- a/src/modules/Telemetry/Sensor/TelemetrySensor.h +++ b/src/modules/Telemetry/Sensor/TelemetrySensor.h @@ -24,7 +24,7 @@ class TelemetrySensor DEBUG_MSG("Could not connect to detected %s sensor.\n Removing from nodeTelemetrySensorsMap.\n", sensorName); nodeTelemetrySensorsMap[sensorType] = 0; } else { - DEBUG_MSG("Opened %s sensor on default i2c bus\n", sensorName); + DEBUG_MSG("Opened %s sensor on detected i2c bus\n", sensorName); setup(); } return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index c5c493997..aaa4f4efe 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -43,7 +43,7 @@ void setBluetoothEnable(bool on) { static uint32_t calibrate_one(rtc_cal_sel_t cal_clk, const char *name) { const uint32_t cal_count = 1000; - const float factor = (1 << 19) * 1000.0f; + // const float factor = (1 << 19) * 1000.0f; unused var? uint32_t cali_val; for (int i = 0; i < 5; ++i) { cali_val = rtc_clk_cal(cal_clk, cal_count);