From c4e6d1c6df06492c39b8a8b6c7542ba2a13281a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 14 Mar 2024 16:44:02 +0100 Subject: [PATCH 1/5] (3/3) Add variant for pico with waveshare and GPS hat, utilizing slow clock. --- src/configuration.h | 1 + src/detect/ScanI2CTwoWire.cpp | 3 +- src/modules/Telemetry/Sensor/INA219Sensor.cpp | 6 +- variants/rpipico-slowclock/platformio.ini | 28 ++++++ variants/rpipico-slowclock/variant.h | 87 +++++++++++++++++++ 5 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 variants/rpipico-slowclock/platformio.ini create mode 100644 variants/rpipico-slowclock/variant.h diff --git a/src/configuration.h b/src/configuration.h index ac8f9435a7..ec32c72d1d 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -111,6 +111,7 @@ along with this program. If not, see . #define MCP9808_ADDR 0x18 #define INA_ADDR 0x40 #define INA_ADDR_ALTERNATE 0x41 +#define INA_ADDR_WAVESHARE_UPS 0x43 #define INA3221_ADDR 0x42 #define QMC6310_ADDR 0x1C #define QMI8658_ADDR 0x6B diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index b6eca5fa4c..b6fafe4577 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -184,7 +184,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port) #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) case ATECC608B_ADDR: type = ATECC608B; - if (atecc.begin(addr.address) == true) { + if (atecc.begin(addr.address, Wire, Serial2) == true) { LOG_INFO("ATECC608B initialized\n"); } else { LOG_WARN("ATECC608B initialization failed\n"); @@ -254,6 +254,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port) case INA_ADDR: case INA_ADDR_ALTERNATE: + case INA_ADDR_WAVESHARE_UPS: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFE), 2); LOG_DEBUG("Register MFG_UID: 0x%x\n", registerValue); if (registerValue == 0x5449) { diff --git a/src/modules/Telemetry/Sensor/INA219Sensor.cpp b/src/modules/Telemetry/Sensor/INA219Sensor.cpp index 5a1faa99ff..ecb5643686 100644 --- a/src/modules/Telemetry/Sensor/INA219Sensor.cpp +++ b/src/modules/Telemetry/Sensor/INA219Sensor.cpp @@ -4,6 +4,10 @@ #include "configuration.h" #include +#ifndef INA219_MULTIPLIER +#define INA219_MULTIPLIER 1.0f +#endif + INA219Sensor::INA219Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_INA219, "INA219") {} int32_t INA219Sensor::runOnce() @@ -26,7 +30,7 @@ void INA219Sensor::setup() {} bool INA219Sensor::getMetrics(meshtastic_Telemetry *measurement) { measurement->variant.environment_metrics.voltage = ina219.getBusVoltage_V(); - measurement->variant.environment_metrics.current = ina219.getCurrent_mA(); + measurement->variant.environment_metrics.current = ina219.getCurrent_mA() * INA219_MULTIPLIER; return true; } diff --git a/variants/rpipico-slowclock/platformio.ini b/variants/rpipico-slowclock/platformio.ini new file mode 100644 index 0000000000..e583c4b0d5 --- /dev/null +++ b/variants/rpipico-slowclock/platformio.ini @@ -0,0 +1,28 @@ +[env:pico_slowclock] +extends = rp2040_base +board = rpipico +upload_protocol = jlink +# debug settings for external openocd with RP2040 support (custom build) +debug_tool = custom +debug_init_cmds = + target extended-remote localhost:3333 + $INIT_BREAK + monitor reset halt + $LOAD_CMDS + monitor init + monitor reset halt + +# add our variants files to the include and src paths +build_flags = ${rp2040_base.build_flags} + -DRPI_PICO + -Ivariants/rpipico_slowclock + -DDEBUG_RP2040_PORT=Serial2 + -DHW_SPI1_DEVICE + -L "${platformio.libdeps_dir}/${this.__env__}/BSEC2 Software Library/src/cortex-m0plus" + -g + -DNO_USB +lib_deps = + ${rp2040_base.lib_deps} +debug_build_flags = ${rp2040_base.build_flags} + -g + -DNO_USB \ No newline at end of file diff --git a/variants/rpipico-slowclock/variant.h b/variants/rpipico-slowclock/variant.h new file mode 100644 index 0000000000..fb97ec0fbf --- /dev/null +++ b/variants/rpipico-slowclock/variant.h @@ -0,0 +1,87 @@ +#define ARDUINO_ARCH_AVR + +// Build with slow system clock enabled to reduce power consumption. +#define RP2040_SLOW_CLOCK + +#ifdef RP2040_SLOW_CLOCK +// Redefine UART1 serial log output to avoid collision with UART0 for GPS. +#define SERIAL2_TX 4 +#define SERIAL2_RX 5 +// Reroute log output in SensorLib when USB is not available +#define log_e(...) Serial2.printf(__VA_ARGS__) +#define log_i(...) Serial2.printf(__VA_ARGS__) +#define log_d(...) Serial2.printf(__VA_ARGS__) +#endif + +// Expecting the Waveshare Pico GPS hat +#define HAS_GPS 1 + +// Enable OLED Screen +#define HAS_SCREEN 1 +#define USE_SH1106 1 +#define RESET_OLED 13 + +// Redefine I2C0 pins to avoid collision with UART1/Serial2. +#define I2C_SDA 8 +#define I2C_SCL 9 + +// Redefine Waveshare UPS-A/B I2C_1 pins: +#define I2C_SDA1 6 +#define I2C_SCL1 7 +// Waveshare UPS-A/B uses a 0.01 Ohm shunt for the INA219 sensor +#define INA219_MULTIPLIER 10.0f + +// Waveshare Pico GPS L76B pins: +#define GPS_RX_PIN 1 +#define GPS_TX_PIN 0 + +// Wakeup from backup mode +// #define PIN_GPS_FORCE_ON 14 +// No GPS reset available +#undef PIN_GPS_RESET +/* + * For PPS output the resistor R20 needs to be populated with 0 Ohm + * on the Waveshare Pico GPS board. + */ +#define PIN_GPS_PPS 16 +/* + * For standby mode switching the resistor R18 needs to be populated + * with 0 Ohm on the Waveshare Pico GPS board. + */ +#define PIN_GPS_STANDBY 17 + +#define BUTTON_PIN 18 +#define EXT_NOTIFY_OUT 22 +#define LED_PIN PIN_LED + +#define BATTERY_PIN 26 +// ratio of voltage divider = 3.0 (R17=200k, R18=100k) +#define ADC_MULTIPLIER 3.1 // 3.0 + a bit for being optimistic +#define BATTERY_SENSE_RESOLUTION_BITS ADC_RESOLUTION + +#define USE_SX1262 + +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS + +#define LORA_SCK 10 +#define LORA_MISO 12 +#define LORA_MOSI 11 +#define LORA_CS 3 + +#define LORA_DIO0 RADIOLIB_NC +#define LORA_RESET 15 +#define LORA_DIO1 20 +#define LORA_DIO2 2 +#define LORA_DIO3 RADIOLIB_NC + +#ifdef USE_SX1262 +#define SX126X_CS LORA_CS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#endif \ No newline at end of file From 669f7b9b8dadfafd6e18689edae8a2f6ca5843c2 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 15 Mar 2024 19:04:43 -0500 Subject: [PATCH 2/5] Not everybody has Serial2 --- src/detect/ScanI2CTwoWire.cpp | 120 ++++++++++++++++++++++++---------- 1 file changed, 84 insertions(+), 36 deletions(-) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index b6fafe4577..b4c43791b0 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -30,10 +30,12 @@ ScanI2C::FoundDevice ScanI2CTwoWire::firstOfOrNONE(size_t count, DeviceType type { concurrency::LockGuard guard((concurrency::Lock *)&lock); - for (size_t k = 0; k < count; k++) { + for (size_t k = 0; k < count; k++) + { ScanI2C::DeviceType current = types[k]; - if (exists(current)) { + if (exists(current)) + { return ScanI2C::FoundDevice(current, deviceAddresses.at(current)); } } @@ -49,21 +51,26 @@ ScanI2C::DeviceType ScanI2CTwoWire::probeOLED(ScanI2C::DeviceAddress addr) const uint8_t r_prev = 0; uint8_t c = 0; ScanI2C::DeviceType o_probe = ScanI2C::DeviceType::SCREEN_UNKNOWN; - do { + do + { r_prev = r; i2cBus->beginTransmission(addr.address); i2cBus->write((uint8_t)0x00); i2cBus->endTransmission(); i2cBus->requestFrom((int)addr.address, 1); - if (i2cBus->available()) { + if (i2cBus->available()) + { r = i2cBus->read(); } r &= 0x0f; - if (r == 0x08 || r == 0x00) { + if (r == 0x08 || r == 0x00) + { LOG_INFO("sh1106 display found\n"); o_probe = SCREEN_SH1106; // SH1106 - } else if (r == 0x03 || r == 0x04 || r == 0x06 || r == 0x07) { + } + else if (r == 0x03 || r == 0x04 || r == 0x06 || r == 0x07) + { LOG_INFO("ssd1306 display found\n"); o_probe = SCREEN_SSD1306; // SSD1306 } @@ -79,12 +86,14 @@ void ScanI2CTwoWire::printATECCInfo() const atecc.readConfigZone(false); LOG_DEBUG("ATECC608B Serial Number: "); - for (int i = 0; i < 9; i++) { + for (int i = 0; i < 9; i++) + { LOG_DEBUG("%02x", atecc.serialNumber[i]); } LOG_DEBUG(", Rev Number: "); - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) + { LOG_DEBUG("%02x", atecc.revisionNumber[i]); } LOG_DEBUG("\n"); @@ -93,12 +102,17 @@ void ScanI2CTwoWire::printATECCInfo() const LOG_DEBUG(", Data %s", atecc.dataOTPLockStatus ? "Locked" : "Unlocked"); LOG_DEBUG(", Slot 0 %s\n", atecc.slot0LockStatus ? "Locked" : "Unlocked"); - if (atecc.configLockStatus && atecc.dataOTPLockStatus && atecc.slot0LockStatus) { - if (atecc.generatePublicKey() == false) { + if (atecc.configLockStatus && atecc.dataOTPLockStatus && atecc.slot0LockStatus) + { + if (atecc.generatePublicKey() == false) + { LOG_DEBUG("ATECC608B Error generating public key\n"); - } else { + } + else + { LOG_DEBUG("ATECC608B Public Key: "); - for (int i = 0; i < 64; i++) { + for (int i = 0; i < 64; i++) + { LOG_DEBUG("%02x", atecc.publicKey64Bytes[i]); } LOG_DEBUG("\n"); @@ -119,20 +133,23 @@ uint16_t ScanI2CTwoWire::getRegisterValue(const ScanI2CTwoWire::RegisterLocation delay(20); i2cBus->requestFrom(registerLocation.i2cAddress.address, responseWidth); LOG_DEBUG("Wire.available() = %d\n", i2cBus->available()); - if (i2cBus->available() == 2) { + if (i2cBus->available() == 2) + { // Read MSB, then LSB value = (uint16_t)i2cBus->read() << 8; value |= i2cBus->read(); - } else if (i2cBus->available()) { + } + else if (i2cBus->available()) + { value = i2cBus->read(); } return value; } -#define SCAN_SIMPLE_CASE(ADDR, T, ...) \ - case ADDR: \ - LOG_INFO(__VA_ARGS__); \ - type = T; \ +#define SCAN_SIMPLE_CASE(ADDR, T, ...) \ + case ADDR: \ + LOG_INFO(__VA_ARGS__); \ + type = T; \ break; void ScanI2CTwoWire::scanPort(I2CPort port) @@ -153,16 +170,20 @@ void ScanI2CTwoWire::scanPort(I2CPort port) #endif #ifdef I2C_SDA1 - if (port == I2CPort::WIRE1) { + if (port == I2CPort::WIRE1) + { i2cBus = &Wire1; - } else { + } + else + { #endif i2cBus = &Wire; #ifdef I2C_SDA1 } #endif - for (addr.address = 1; addr.address < 127; addr.address++) { + for (addr.address = 1; addr.address < 127; addr.address++) + { i2cBus->beginTransmission(addr.address); #ifdef ARCH_PORTDUINO if (i2cBus->read() != -1) @@ -173,10 +194,12 @@ void ScanI2CTwoWire::scanPort(I2CPort port) err = i2cBus->endTransmission(); #endif type = NONE; - if (err == 0) { + if (err == 0) + { LOG_DEBUG("I2C device found at address 0x%x\n", addr.address); - switch (addr.address) { + switch (addr.address) + { case SSD1306_ADDRESS: type = probeOLED(addr); break; @@ -184,9 +207,18 @@ void ScanI2CTwoWire::scanPort(I2CPort port) #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) case ATECC608B_ADDR: type = ATECC608B; - if (atecc.begin(addr.address, Wire, Serial2) == true) { + bool ateccInit = false; +#ifdef RP2040_SLOW_CLOCK + ateccInit = atecc.begin(addr.address, Wire, Serial2); +#else + ateccInit = atecc.begin(addr.address) == true; +#endif + if (ateccInit == true) + { LOG_INFO("ATECC608B initialized\n"); - } else { + } + else + { LOG_WARN("ATECC608B initialization failed\n"); } printATECCInfo(); @@ -211,11 +243,14 @@ void ScanI2CTwoWire::scanPort(I2CPort port) case CARDKB_ADDR: // Do we have the RAK14006 instead? registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x04), 1); - if (registerValue == 0x02) { + if (registerValue == 0x02) + { // KEYPAD_VERSION LOG_INFO("RAK14004 found\n"); type = RAK14004; - } else { + } + else + { LOG_INFO("m5 cardKB found\n"); type = CARDKB; } @@ -233,7 +268,8 @@ void ScanI2CTwoWire::scanPort(I2CPort port) case BME_ADDR: case BME_ADDR_ALTERNATE: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xD0), 1); // GET_ID - switch (registerValue) { + switch (registerValue) + { case 0x61: LOG_INFO("BME-680 sensor found at address 0x%x\n", (uint8_t)addr.address); type = BME_680; @@ -257,10 +293,13 @@ void ScanI2CTwoWire::scanPort(I2CPort port) case INA_ADDR_WAVESHARE_UPS: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFE), 2); LOG_DEBUG("Register MFG_UID: 0x%x\n", registerValue); - if (registerValue == 0x5449) { + if (registerValue == 0x5449) + { LOG_INFO("INA260 sensor found at address 0x%x\n", (uint8_t)addr.address); type = INA260; - } else { // Assume INA219 if INA260 ID is not found + } + else + { // Assume INA219 if INA260 ID is not found LOG_INFO("INA219 sensor found at address 0x%x\n", (uint8_t)addr.address); type = INA219; } @@ -271,10 +310,13 @@ void ScanI2CTwoWire::scanPort(I2CPort port) break; case MCP9808_ADDR: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x07), 2); - if (registerValue == 0x0400) { + if (registerValue == 0x0400) + { type = MCP9808; LOG_INFO("MCP9808 sensor found\n"); - } else { + } + else + { type = LIS3DH; LOG_INFO("LIS3DH accelerometer found\n"); } @@ -298,12 +340,15 @@ void ScanI2CTwoWire::scanPort(I2CPort port) default: LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address); } - } else if (err == 4) { + } + else if (err == 4) + { LOG_ERROR("Unknown error at address 0x%x\n", addr); } // Check if a type was found for the enumerated device - save, if so - if (type != NONE) { + if (type != NONE) + { deviceAddresses[type] = addr; foundDevices[addr] = type; } @@ -312,9 +357,12 @@ void ScanI2CTwoWire::scanPort(I2CPort port) TwoWire *ScanI2CTwoWire::fetchI2CBus(ScanI2C::DeviceAddress address) const { - if (address.port == ScanI2C::I2CPort::WIRE) { + if (address.port == ScanI2C::I2CPort::WIRE) + { return &Wire; - } else { + } + else + { #ifdef I2C_SDA1 return &Wire1; #else From 7478a32e7ad8cca33de107497b28b3dedae45b5e Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 15 Mar 2024 19:18:26 -0500 Subject: [PATCH 3/5] Trunk --- src/detect/ScanI2CTwoWire.cpp | 114 +++++++++++----------------------- 1 file changed, 36 insertions(+), 78 deletions(-) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index b4c43791b0..78fec4a15f 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -30,12 +30,10 @@ ScanI2C::FoundDevice ScanI2CTwoWire::firstOfOrNONE(size_t count, DeviceType type { concurrency::LockGuard guard((concurrency::Lock *)&lock); - for (size_t k = 0; k < count; k++) - { + for (size_t k = 0; k < count; k++) { ScanI2C::DeviceType current = types[k]; - if (exists(current)) - { + if (exists(current)) { return ScanI2C::FoundDevice(current, deviceAddresses.at(current)); } } @@ -51,26 +49,21 @@ ScanI2C::DeviceType ScanI2CTwoWire::probeOLED(ScanI2C::DeviceAddress addr) const uint8_t r_prev = 0; uint8_t c = 0; ScanI2C::DeviceType o_probe = ScanI2C::DeviceType::SCREEN_UNKNOWN; - do - { + do { r_prev = r; i2cBus->beginTransmission(addr.address); i2cBus->write((uint8_t)0x00); i2cBus->endTransmission(); i2cBus->requestFrom((int)addr.address, 1); - if (i2cBus->available()) - { + if (i2cBus->available()) { r = i2cBus->read(); } r &= 0x0f; - if (r == 0x08 || r == 0x00) - { + if (r == 0x08 || r == 0x00) { LOG_INFO("sh1106 display found\n"); o_probe = SCREEN_SH1106; // SH1106 - } - else if (r == 0x03 || r == 0x04 || r == 0x06 || r == 0x07) - { + } else if (r == 0x03 || r == 0x04 || r == 0x06 || r == 0x07) { LOG_INFO("ssd1306 display found\n"); o_probe = SCREEN_SSD1306; // SSD1306 } @@ -86,14 +79,12 @@ void ScanI2CTwoWire::printATECCInfo() const atecc.readConfigZone(false); LOG_DEBUG("ATECC608B Serial Number: "); - for (int i = 0; i < 9; i++) - { + for (int i = 0; i < 9; i++) { LOG_DEBUG("%02x", atecc.serialNumber[i]); } LOG_DEBUG(", Rev Number: "); - for (int i = 0; i < 4; i++) - { + for (int i = 0; i < 4; i++) { LOG_DEBUG("%02x", atecc.revisionNumber[i]); } LOG_DEBUG("\n"); @@ -102,17 +93,12 @@ void ScanI2CTwoWire::printATECCInfo() const LOG_DEBUG(", Data %s", atecc.dataOTPLockStatus ? "Locked" : "Unlocked"); LOG_DEBUG(", Slot 0 %s\n", atecc.slot0LockStatus ? "Locked" : "Unlocked"); - if (atecc.configLockStatus && atecc.dataOTPLockStatus && atecc.slot0LockStatus) - { - if (atecc.generatePublicKey() == false) - { + if (atecc.configLockStatus && atecc.dataOTPLockStatus && atecc.slot0LockStatus) { + if (atecc.generatePublicKey() == false) { LOG_DEBUG("ATECC608B Error generating public key\n"); - } - else - { + } else { LOG_DEBUG("ATECC608B Public Key: "); - for (int i = 0; i < 64; i++) - { + for (int i = 0; i < 64; i++) { LOG_DEBUG("%02x", atecc.publicKey64Bytes[i]); } LOG_DEBUG("\n"); @@ -133,23 +119,20 @@ uint16_t ScanI2CTwoWire::getRegisterValue(const ScanI2CTwoWire::RegisterLocation delay(20); i2cBus->requestFrom(registerLocation.i2cAddress.address, responseWidth); LOG_DEBUG("Wire.available() = %d\n", i2cBus->available()); - if (i2cBus->available() == 2) - { + if (i2cBus->available() == 2) { // Read MSB, then LSB value = (uint16_t)i2cBus->read() << 8; value |= i2cBus->read(); - } - else if (i2cBus->available()) - { + } else if (i2cBus->available()) { value = i2cBus->read(); } return value; } -#define SCAN_SIMPLE_CASE(ADDR, T, ...) \ - case ADDR: \ - LOG_INFO(__VA_ARGS__); \ - type = T; \ +#define SCAN_SIMPLE_CASE(ADDR, T, ...) \ + case ADDR: \ + LOG_INFO(__VA_ARGS__); \ + type = T; \ break; void ScanI2CTwoWire::scanPort(I2CPort port) @@ -170,20 +153,16 @@ void ScanI2CTwoWire::scanPort(I2CPort port) #endif #ifdef I2C_SDA1 - if (port == I2CPort::WIRE1) - { + if (port == I2CPort::WIRE1) { i2cBus = &Wire1; - } - else - { + } else { #endif i2cBus = &Wire; #ifdef I2C_SDA1 } #endif - for (addr.address = 1; addr.address < 127; addr.address++) - { + for (addr.address = 1; addr.address < 127; addr.address++) { i2cBus->beginTransmission(addr.address); #ifdef ARCH_PORTDUINO if (i2cBus->read() != -1) @@ -194,12 +173,10 @@ void ScanI2CTwoWire::scanPort(I2CPort port) err = i2cBus->endTransmission(); #endif type = NONE; - if (err == 0) - { + if (err == 0) { LOG_DEBUG("I2C device found at address 0x%x\n", addr.address); - switch (addr.address) - { + switch (addr.address) { case SSD1306_ADDRESS: type = probeOLED(addr); break; @@ -213,12 +190,9 @@ void ScanI2CTwoWire::scanPort(I2CPort port) #else ateccInit = atecc.begin(addr.address) == true; #endif - if (ateccInit == true) - { + if (ateccInit == true) { LOG_INFO("ATECC608B initialized\n"); - } - else - { + } else { LOG_WARN("ATECC608B initialization failed\n"); } printATECCInfo(); @@ -243,14 +217,11 @@ void ScanI2CTwoWire::scanPort(I2CPort port) case CARDKB_ADDR: // Do we have the RAK14006 instead? registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x04), 1); - if (registerValue == 0x02) - { + if (registerValue == 0x02) { // KEYPAD_VERSION LOG_INFO("RAK14004 found\n"); type = RAK14004; - } - else - { + } else { LOG_INFO("m5 cardKB found\n"); type = CARDKB; } @@ -268,8 +239,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port) case BME_ADDR: case BME_ADDR_ALTERNATE: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xD0), 1); // GET_ID - switch (registerValue) - { + switch (registerValue) { case 0x61: LOG_INFO("BME-680 sensor found at address 0x%x\n", (uint8_t)addr.address); type = BME_680; @@ -293,13 +263,10 @@ void ScanI2CTwoWire::scanPort(I2CPort port) case INA_ADDR_WAVESHARE_UPS: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFE), 2); LOG_DEBUG("Register MFG_UID: 0x%x\n", registerValue); - if (registerValue == 0x5449) - { + if (registerValue == 0x5449) { LOG_INFO("INA260 sensor found at address 0x%x\n", (uint8_t)addr.address); type = INA260; - } - else - { // Assume INA219 if INA260 ID is not found + } else { // Assume INA219 if INA260 ID is not found LOG_INFO("INA219 sensor found at address 0x%x\n", (uint8_t)addr.address); type = INA219; } @@ -310,13 +277,10 @@ void ScanI2CTwoWire::scanPort(I2CPort port) break; case MCP9808_ADDR: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x07), 2); - if (registerValue == 0x0400) - { + if (registerValue == 0x0400) { type = MCP9808; LOG_INFO("MCP9808 sensor found\n"); - } - else - { + } else { type = LIS3DH; LOG_INFO("LIS3DH accelerometer found\n"); } @@ -340,15 +304,12 @@ void ScanI2CTwoWire::scanPort(I2CPort port) default: LOG_INFO("Device found at address 0x%x was not able to be enumerated\n", addr.address); } - } - else if (err == 4) - { + } else if (err == 4) { LOG_ERROR("Unknown error at address 0x%x\n", addr); } // Check if a type was found for the enumerated device - save, if so - if (type != NONE) - { + if (type != NONE) { deviceAddresses[type] = addr; foundDevices[addr] = type; } @@ -357,12 +318,9 @@ void ScanI2CTwoWire::scanPort(I2CPort port) TwoWire *ScanI2CTwoWire::fetchI2CBus(ScanI2C::DeviceAddress address) const { - if (address.port == ScanI2C::I2CPort::WIRE) - { + if (address.port == ScanI2C::I2CPort::WIRE) { return &Wire; - } - else - { + } else { #ifdef I2C_SDA1 return &Wire1; #else From 414cb95d5c363bf17fa98d6d99803c48f4eae450 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 15 Mar 2024 19:58:07 -0500 Subject: [PATCH 4/5] Push it real gud --- src/detect/ScanI2CTwoWire.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 78fec4a15f..82d4ddef99 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -183,12 +183,10 @@ void ScanI2CTwoWire::scanPort(I2CPort port) #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) case ATECC608B_ADDR: - type = ATECC608B; - bool ateccInit = false; #ifdef RP2040_SLOW_CLOCK - ateccInit = atecc.begin(addr.address, Wire, Serial2); + bool ateccInit = atecc.begin(addr.address, Wire, Serial2); #else - ateccInit = atecc.begin(addr.address) == true; + bool ateccInit = atecc.begin(addr.address); #endif if (ateccInit == true) { LOG_INFO("ATECC608B initialized\n"); From 2f13904d35586824608d251f2cfa462ff3f73cb0 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 15 Mar 2024 20:23:51 -0500 Subject: [PATCH 5/5] No init --- src/detect/ScanI2CTwoWire.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 82d4ddef99..146daa3dcf 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -184,11 +184,12 @@ void ScanI2CTwoWire::scanPort(I2CPort port) #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) case ATECC608B_ADDR: #ifdef RP2040_SLOW_CLOCK - bool ateccInit = atecc.begin(addr.address, Wire, Serial2); + if (atecc.begin(addr.address, Wire, Serial2) == true) #else - bool ateccInit = atecc.begin(addr.address); + if (atecc.begin(addr.address) == true) #endif - if (ateccInit == true) { + + { LOG_INFO("ATECC608B initialized\n"); } else { LOG_WARN("ATECC608B initialization failed\n");