From 803858ab0a0ec94f7108b62c5f3ad45eeeab1c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 9 Nov 2022 11:50:13 +0100 Subject: [PATCH 01/24] change default pins for codec2 to work on TLORA 2.1-1.8 --- src/modules/esp32/AudioModule.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index 7147db43c..c37a1b2a8 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -21,8 +21,9 @@ 1) Enable the module by setting audio.codec2_enabled to 1. 2) Set the pins (audio.mic_pin / audio.amp_pin) for your preferred microphone and amplifier GPIO pins. On tbeam, recommend to use: - audio.mic_chan 7 (GPIO 35) - audio.amp_pin 25 (GPIO 25) + audio.mic_chan 6 (GPIO 34) + audio.amp_pin 14 + audio.ptt_pin 39 3) Set audio.timeout to the amount of time to wait before we consider your voice stream as "done". 4) Set audio.bitrate to the desired codec2 rate (CODEC2_3200, CODEC2_2400, CODEC2_1600, CODEC2_1400, CODEC2_1300, CODEC2_1200, CODEC2_700, CODEC2_700B) @@ -33,8 +34,8 @@ * Will not work on NRF and the Linux device targets. */ -#define AMIC 7 -#define AAMP 25 +#define AMIC 6 +#define AAMP 14 #define PTT_PIN 39 #define AUDIO_MODULE_RX_BUFFER 128 From 0249eb1307359e3dc2576a6b31efec8dab04332a Mon Sep 17 00:00:00 2001 From: thebentern Date: Tue, 8 Nov 2022 22:51:44 +0000 Subject: [PATCH 02/24] [create-pull-request] automated change --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index da0d02a6d..6f548b7bd 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 0 -build = 1 +build = 2 From c4951b123640c5497b1ac68c620755cd2a43e90d Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 9 Nov 2022 07:14:08 -0600 Subject: [PATCH 03/24] Build cleanup and update deprecated platformio cmd --- bin/build-all.sh.legacy | 109 ---------------------------------------- bin/build-esp32.sh | 2 +- bin/build-native.sh | 2 +- bin/build-nrf52.sh | 2 +- bin/build-rpi2040.sh | 2 +- 5 files changed, 4 insertions(+), 113 deletions(-) delete mode 100755 bin/build-all.sh.legacy diff --git a/bin/build-all.sh.legacy b/bin/build-all.sh.legacy deleted file mode 100755 index 55c151da1..000000000 --- a/bin/build-all.sh.legacy +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env bash - -set -e - -VERSION=`bin/buildinfo.py long` -SHORT_VERSION=`bin/buildinfo.py short` - -BOARDS_ESP32="rak11200 tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1 nano-g1 station-g1 m5stack-core m5stack-coreink" -#BOARDS_ESP32=tbeam - -# FIXME note nrf52840dk build is for some reason only generating a BIN file but not a HEX file nrf52840dk-geeksville is fine -BOARDS_NRF52="rak4631 rak4631_eink t-echo pca10059_diy_eink" -#BOARDS_NRF52="" - -OUTDIR=release/latest - -# We keep all old builds (and their map files in the archive dir) -ARCHIVEDIR=release/archive - -rm -f $OUTDIR/firmware* - -mkdir -p $OUTDIR/bins $ARCHIVEDIR -rm -r $OUTDIR/bins/* || true -mkdir -p $OUTDIR/bins/universal $OUTDIR/elfs/universal - -# build the named environment and copy the bins to the release directory -function do_build() { - BOARD=$1 - isNrf=$3 - - echo "Building for $BOARD ($isNrf) with $PLATFORMIO_BUILD_FLAGS" - rm -f .pio/build/$BOARD/firmware.* - - # The shell vars the build tool expects to find - export APP_VERSION=$VERSION - - basename=universal/firmware-$BOARD-$VERSION - - pio run --environment $BOARD # -v - SRCELF=.pio/build/$BOARD/firmware.elf - cp $SRCELF $OUTDIR/elfs/$basename.elf - - if [ "$isNrf" = "false" ] - then - echo "Copying ESP32 bin file" - SRCBIN=.pio/build/$BOARD/firmware.bin - cp $SRCBIN $OUTDIR/bins/$basename.bin - else - echo "Generating NRF52 uf2 file" - SRCHEX=.pio/build/$BOARD/firmware.hex - bin/uf2conv.py $SRCHEX -c -o $OUTDIR/bins/$basename.uf2 -f 0xADA52840 - fi -} - -function do_boards() { - declare boards=$1 - declare isNrf=$2 - for board in $boards; do - # Build universal - echo "about to build $board $isNrf" - do_build $board "" "$isNrf" - done -} - -# Make sure our submodules are current -git submodule update - -# Important to pull latest version of libs into all device flavors, otherwise some devices might be stale -platformio lib update - -do_boards "$BOARDS_ESP32" "false" -do_boards "$BOARDS_NRF52" "true" - -pio run --environment native -cp .pio/build/native/program $OUTDIR/bins/universal/meshtasticd_linux_amd64 - -echo "Building Filesystem for ESP32 targets" -pio run --environment tbeam -t buildfs -cp .pio/build/tbeam/spiffs.bin $OUTDIR/bins/universal/littlefs-$VERSION.bin - -# keep the bins in archive also -cp $OUTDIR/bins/universal/littlefs* $OUTDIR/bins/universal/firmware* $OUTDIR/elfs/universal/firmware* $ARCHIVEDIR - -echo Updating android bins $OUTDIR/forandroid -rm -rf $OUTDIR/forandroid -mkdir -p $OUTDIR/forandroid -cp -a $OUTDIR/bins/universal/*.bin $OUTDIR/forandroid/ - -cat >$OUTDIR/curfirmwareversion.xml < - - - - - $VERSION - $SHORT_VERSION - -XML - -echo Generating $ARCHIVEDIR/firmware-$VERSION.zip -rm -f $ARCHIVEDIR/firmware-$VERSION.zip -zip --junk-paths $ARCHIVEDIR/firmware-$VERSION.zip $ARCHIVEDIR/littlefs-$VERSION.bin $OUTDIR/bins/universal/firmware-*-$VERSION.* $OUTDIR/bins/universal/meshtasticd* images/system-info.bin bin/device-install.* bin/device-update.* -echo Generating $ARCHIVEDIR/elfs-$VERSION.zip -rm -f $ARCHIVEDIR/elfs-$VERSION.zip -zip --junk-paths $ARCHIVEDIR/elfs-$VERSION.zip $OUTDIR/elfs/universal/firmware-*-$VERSION.* - -echo BUILT ALL diff --git a/bin/build-esp32.sh b/bin/build-esp32.sh index 40a6c3aee..12961864f 100755 --- a/bin/build-esp32.sh +++ b/bin/build-esp32.sh @@ -14,7 +14,7 @@ rm -r $OUTDIR/* || true git submodule update # Important to pull latest version of libs into all device flavors, otherwise some devices might be stale -platformio lib update +platformio pkg update echo "Building for $1 with $PLATFORMIO_BUILD_FLAGS" rm -f .pio/build/$1/firmware.* diff --git a/bin/build-native.sh b/bin/build-native.sh index 31ef01155..b620a01d8 100755 --- a/bin/build-native.sh +++ b/bin/build-native.sh @@ -16,7 +16,7 @@ rm -r $OUTDIR/* || true git submodule update # Important to pull latest version of libs into all device flavors, otherwise some devices might be stale -platformio lib update +platformio pkg update pio run --environment native cp .pio/build/native/program $OUTDIR/meshtasticd_linux_amd64 diff --git a/bin/build-nrf52.sh b/bin/build-nrf52.sh index 76972b100..6c723e28f 100755 --- a/bin/build-nrf52.sh +++ b/bin/build-nrf52.sh @@ -14,7 +14,7 @@ rm -r $OUTDIR/* || true git submodule update # Important to pull latest version of libs into all device flavors, otherwise some devices might be stale -platformio lib update +platformio pkg update echo "Building for $1 with $PLATFORMIO_BUILD_FLAGS" rm -f .pio/build/$1/firmware.* diff --git a/bin/build-rpi2040.sh b/bin/build-rpi2040.sh index 04fe7106b..670f570f1 100755 --- a/bin/build-rpi2040.sh +++ b/bin/build-rpi2040.sh @@ -14,7 +14,7 @@ rm -r $OUTDIR/* || true git submodule update # Important to pull latest version of libs into all device flavors, otherwise some devices might be stale -platformio lib update +platformio pkg update echo "Building for $1 with $PLATFORMIO_BUILD_FLAGS" rm -f .pio/build/$1/firmware.* From 87c555bde3b494de1c50fe80a18b4c0dd2284222 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 9 Nov 2022 07:20:53 -0600 Subject: [PATCH 04/24] Changed retention policy --- .github/workflows/main_matrix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index aacdc72af..62a2477bf 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -410,7 +410,7 @@ jobs: with: name: debug-elfs-${{ steps.version.outputs.version }}.zip path: ./*.elf - retention-days: 90 + retention-days: 30 - name: Create request artifacts if: ${{ github.event_name == 'pull_request_target' || github.event_name == 'pull_request' }} From 4dd140a88718730b20f0d0788bba48f439d38509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 9 Nov 2022 15:12:57 +0100 Subject: [PATCH 05/24] fix #1914 and clean up rangetest a bit --- src/modules/esp32/RangeTestModule.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/modules/esp32/RangeTestModule.cpp b/src/modules/esp32/RangeTestModule.cpp index c9713d94e..b4cd9254e 100644 --- a/src/modules/esp32/RangeTestModule.cpp +++ b/src/modules/esp32/RangeTestModule.cpp @@ -12,7 +12,7 @@ //#include /* - As a sender, I can send packets every n-seonds. These packets include an incramented PacketID. + As a sender, I can send packets every n seconds. These packets include an incremented PacketID. As a receiver, I can receive packets from multiple senders. These packets can be saved to the Filesystem. */ @@ -36,12 +36,12 @@ int32_t RangeTestModule::runOnce() without having to configure it from the PythonAPI or WebUI. */ - //moduleConfig.range_test.enabled = 1; - //moduleConfig.range_test.sender = 30; + // moduleConfig.range_test.enabled = 1; + // moduleConfig.range_test.sender = 30; // moduleConfig.range_test.save = 1; // Fixed position is useful when testing indoors. - // radioConfig.preferences.fixed_position = 1; + // config.position.fixed_position = 1; uint32_t senderHeartbeat = moduleConfig.range_test.sender * 1000; @@ -57,7 +57,8 @@ int32_t RangeTestModule::runOnce() return (5000); // Sending first message 5 seconds after initilization. } else { DEBUG_MSG("Initializing Range Test Module -- Receiver\n"); - return (500); + return (INT32_MAX); + // This thread does not need to run as a receiver } } else { @@ -70,8 +71,7 @@ int32_t RangeTestModule::runOnce() DEBUG_MSG("gpsStatus->getLongitude() %d\n", gpsStatus->getLongitude()); DEBUG_MSG("gpsStatus->getHasLock() %d\n", gpsStatus->getHasLock()); DEBUG_MSG("gpsStatus->getDOP() %d\n", gpsStatus->getDOP()); - DEBUG_MSG("gpsStatus->getHasLock() %d\n", gpsStatus->getHasLock()); - DEBUG_MSG("pref.fixed_position() %d\n", config.position.fixed_position); + DEBUG_MSG("fixed_position() %d\n", config.position.fixed_position); // Only send packets if the channel is less than 25% utilized. if (airTime->channelUtilizationPercent() < 25) { @@ -82,11 +82,11 @@ int32_t RangeTestModule::runOnce() return (senderHeartbeat); } else { - // Otherwise, we're a receiver. - - return (500); + return (INT32_MAX); + // This thread does not need to run as a receiver } - // TBD + + } } else { @@ -221,6 +221,8 @@ bool RangeTestModuleRadio::appendFile(const MeshPacket &mp) return 0; } + FSCom.mkdir("/static"); + // If the file doesn't exist, write the header. if (!FSCom.exists("/static/rangetest.csv")) { //--------- Write to file From b004706eff44db32e2a1f048040322876f906e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 9 Nov 2022 23:42:52 +0100 Subject: [PATCH 06/24] fix #1928 valid NMEA sentences --- src/gps/NMEAWPL.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 222a2d04c..48f528f52 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -17,7 +17,10 @@ uint32_t printWPL(char *buf, const Position &pos, const char *name) { - uint32_t len = sprintf(buf, "$GNWPL,%07.2f,%c,%08.2f,%c,%s", pos.latitude_i * 1e-5, pos.latitude_i < 0 ? 'S' : 'N', pos.longitude_i * 1e-5, pos.longitude_i < 0 ? 'W' : 'E', name); + uint32_t len = sprintf(buf, "$GNWPL,%07.2f,%c,%08.2f,%c,%s", + abs(pos.latitude_i) * 1e-5, pos.latitude_i < 0 ? 'S' : 'N', + abs(pos.longitude_i) * 1e-5, pos.longitude_i < 0 ? 'W' : 'E', + name); uint32_t chk = 0; for (uint32_t i = 1; i < len; i++) { chk ^= buf[i]; @@ -55,8 +58,8 @@ uint32_t printGGA(char *buf, const Position &pos) uint32_t len = sprintf(buf, "$GNGGA,%06u.%03u,%07.2f,%c,%08.2f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", pos.time / 1000, pos.time % 1000, - pos.latitude_i * 1e-5, pos.latitude_i < 0 ? 'S' : 'N', - pos.longitude_i * 1e-5, pos.longitude_i < 0 ? 'W' : 'E', + abs(pos.latitude_i) * 1e-5, pos.latitude_i < 0 ? 'S' : 'N', + abs(pos.longitude_i) * 1e-5, pos.longitude_i < 0 ? 'W' : 'E', pos.fix_type, pos.sats_in_view, pos.HDOP, From de0954f3070671c72ff58c723d6199d7c4907237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 10 Nov 2022 09:35:56 +0100 Subject: [PATCH 07/24] switch to upstream Ethernet lib --- variants/rak4631/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index 3521a43ff..e08b54dae 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -8,7 +8,7 @@ lib_deps = ${nrf52840_base.lib_deps} ${networking_base.lib_deps} melopero/Melopero RV3028@^1.1.0 - https://github.com/meshtastic/RAK13800-W5100S.git#b680706eb8006cd62c919ac74c8af1950eb82c81 + https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink \ No newline at end of file From d1acf02ee860691a3670f689c1dc52d838dda275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 10 Nov 2022 11:01:36 +0100 Subject: [PATCH 08/24] Master Merge --- src/mesh/RadioInterface.h | 2 +- version.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mesh/RadioInterface.h b/src/mesh/RadioInterface.h index 8570d7b39..e9f725c89 100644 --- a/src/mesh/RadioInterface.h +++ b/src/mesh/RadioInterface.h @@ -65,7 +65,7 @@ class RadioInterface - Tx/Rx turnaround time (maximum of SX126x and SX127x); - MAC processing time (measured on T-beam) */ uint32_t slotTimeMsec = 8.5 * pow(2, sf)/bw + 0.2 + 0.4 + 7; - uint16_t preambleLength = 8; // 8 is default + uint16_t preambleLength = 32; // 8 is default, but we use longer to increase the amount of sleep time when receiving const uint32_t PROCESSING_TIME_MSEC = 4500; // time to construct, process and construct a packet again (empirically determined) const uint8_t CWmin = 2; // minimum CWsize const uint8_t CWmax = 8; // maximum CWsize diff --git a/version.properties b/version.properties index 6f548b7bd..303bb9783 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 2 minor = 0 -build = 2 +build = 3 From f7d8885257217f36fa5aecc71742e1a55a032ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 10 Nov 2022 13:50:38 +0100 Subject: [PATCH 09/24] update coordinates for DMS display too --- src/graphics/Screen.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index d6e90c6f9..277127d53 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -538,9 +538,10 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(displayLine))) / 2, y, displayLine); } else { + geoCoord.updateCoords(int32_t(gps->getLatitude()), int32_t(gps->getLongitude()), int32_t(gps->getAltitude())); + if (gpsFormat != Config_DisplayConfig_GpsCoordinateFormat_DMS) { char coordinateLine[22]; - geoCoord.updateCoords(int32_t(gps->getLatitude()), int32_t(gps->getLongitude()), int32_t(gps->getAltitude())); if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_DEC) { // Decimal Degrees sprintf(coordinateLine, "%f %f", geoCoord.getLatitude() * 1e-7, geoCoord.getLongitude() * 1e-7); } else if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_UTM) { // Universal Transverse Mercator From 87f7a60f7190954d274ca12cb06943ced19d8585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 10 Nov 2022 13:51:22 +0100 Subject: [PATCH 10/24] fix #1931 coordinates inserted into NMES stream --- src/gps/NMEAWPL.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 48f528f52..1570ed5fe 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -1,4 +1,5 @@ #include "NMEAWPL.h" +#include "GeoCoord.h" /* ------------------------------------------- * 1 2 3 4 5 6 @@ -17,9 +18,14 @@ uint32_t printWPL(char *buf, const Position &pos, const char *name) { - uint32_t len = sprintf(buf, "$GNWPL,%07.2f,%c,%08.2f,%c,%s", - abs(pos.latitude_i) * 1e-5, pos.latitude_i < 0 ? 'S' : 'N', - abs(pos.longitude_i) * 1e-5, pos.longitude_i < 0 ? 'W' : 'E', + GeoCoord geoCoord(pos.latitude_i,pos.longitude_i,pos.altitude); + uint32_t len = sprintf(buf, "$GNWPL,%02d%10.7f,%c,%03d%10.7f,%c,%s", + geoCoord.getDMSLatDeg(), + (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, + geoCoord.getDMSLatCP(), + geoCoord.getDMSLatDeg(), + (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, + geoCoord.getDMSLonCP(), name); uint32_t chk = 0; for (uint32_t i = 1; i < len; i++) { @@ -55,15 +61,20 @@ uint32_t printWPL(char *buf, const Position &pos, const char *name) uint32_t printGGA(char *buf, const Position &pos) { - uint32_t len = sprintf(buf, "$GNGGA,%06u.%03u,%07.2f,%c,%08.2f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", + GeoCoord geoCoord(pos.latitude_i,pos.longitude_i,pos.altitude); + uint32_t len = sprintf(buf, "$GNGGA,%06u.%03u,%02d%10.7f,%c,%03d%10.7f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", pos.time / 1000, pos.time % 1000, - abs(pos.latitude_i) * 1e-5, pos.latitude_i < 0 ? 'S' : 'N', - abs(pos.longitude_i) * 1e-5, pos.longitude_i < 0 ? 'W' : 'E', + geoCoord.getDMSLatDeg(), + (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, + geoCoord.getDMSLatCP(), + geoCoord.getDMSLonDeg(), + (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, + geoCoord.getDMSLonCP(), pos.fix_type, pos.sats_in_view, pos.HDOP, - pos.altitude, + geoCoord.getAltitude(), 'M', pos.altitude_geoidal_separation, 'M', @@ -77,3 +88,11 @@ uint32_t printGGA(char *buf, const Position &pos) len += sprintf(buf + len, "*%02X\r\n", chk); return len; } + +/* + +(location.lat() - location.rawLat().deg) * 60, + +double latMin = ; + +*/ \ No newline at end of file From 5c59c8d701f35462740d3d75876c913cb164db31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 10 Nov 2022 22:21:07 +0100 Subject: [PATCH 11/24] GPS Update --- platformio.ini | 2 +- src/gps/NMEAWPL.cpp | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/platformio.ini b/platformio.ini index 0021350dd..68492f520 100644 --- a/platformio.ini +++ b/platformio.ini @@ -50,7 +50,7 @@ lib_deps = https://github.com/meshtastic/esp8266-oled-ssd1306.git#53580644255b48ebb7a737343c6b4e71c7e11cf2 ; ESP8266_SSD1306 mathertel/OneButton@^2.0.3 ; OneButton library for non-blocking button debounce https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 - https://github.com/meshtastic/TinyGPSPlus.git#2f0d0528d737000043e949f4c3bdfb623cf0b902 + https://github.com/meshtastic/TinyGPSPlus.git#127ad674ef85f0201cb68a065879653ed94792c4 https://github.com/meshtastic/ArduinoThread.git#72921ac222eed6f526ba1682023cee290d9aa1b3 nanopb/Nanopb@^0.4.6 erriez/ErriezCRC32@^1.0.1 diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 1570ed5fe..06c77980e 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -19,7 +19,7 @@ uint32_t printWPL(char *buf, const Position &pos, const char *name) { GeoCoord geoCoord(pos.latitude_i,pos.longitude_i,pos.altitude); - uint32_t len = sprintf(buf, "$GNWPL,%02d%10.7f,%c,%03d%10.7f,%c,%s", + uint32_t len = sprintf(buf, "$GNWPL,%02d%07.4f,%c,%03d%07.4f,%c,%s", geoCoord.getDMSLatDeg(), (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, geoCoord.getDMSLatCP(), @@ -62,7 +62,7 @@ uint32_t printWPL(char *buf, const Position &pos, const char *name) uint32_t printGGA(char *buf, const Position &pos) { GeoCoord geoCoord(pos.latitude_i,pos.longitude_i,pos.altitude); - uint32_t len = sprintf(buf, "$GNGGA,%06u.%03u,%02d%10.7f,%c,%03d%10.7f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", + uint32_t len = sprintf(buf, "$GNGGA,%06u.%03u,%02d%07.4f,%c,%03d%07.4f,%c,%u,%02u,%04u,%04d,%c,%04d,%c,%d,%04d", pos.time / 1000, pos.time % 1000, geoCoord.getDMSLatDeg(), @@ -87,12 +87,4 @@ uint32_t printGGA(char *buf, const Position &pos) } len += sprintf(buf + len, "*%02X\r\n", chk); return len; -} - -/* - -(location.lat() - location.rawLat().deg) * 60, - -double latMin = ; - -*/ \ No newline at end of file +} \ No newline at end of file From 74f31d7d68eedd222f43c7b75cd990d5c0e1e990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 10 Nov 2022 23:00:01 +0100 Subject: [PATCH 12/24] Fix SX1280 init --- src/main.cpp | 3 --- src/main.h | 1 - src/mesh/RadioInterface.cpp | 24 ++++++++++++++++-------- src/mesh/SX128xInterface.cpp | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e0f0783d3..0f2e575c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,8 +87,6 @@ uint8_t kb_model; // The I2C address of the RTC Module (if found) uint8_t rtc_found; -bool rIf_wide_lora = false; - // Keystore Chips uint8_t keystore_found; #ifndef ARCH_PORTDUINO @@ -385,7 +383,6 @@ void setup() rIf = NULL; } else { DEBUG_MSG("SX1280 Radio init succeeded, using SX1280 radio\n"); - rIf_wide_lora = true; } } #endif diff --git a/src/main.h b/src/main.h index bd24dec76..3744c8acd 100644 --- a/src/main.h +++ b/src/main.h @@ -17,7 +17,6 @@ extern uint8_t kb_model; extern uint8_t rtc_found; extern uint8_t keystore_found; -extern bool rIf_wide_lora; extern bool eink_found; extern bool pmu_found; extern bool isCharging; diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 97dd66fae..4d24b40c4 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -365,37 +365,37 @@ void RadioInterface::applyModemConfig() switch (loraConfig.modem_preset) { case Config_LoRaConfig_ModemPreset_SHORT_FAST: - bw = (myRegion->wideLora && rIf_wide_lora) ? 800 : 250; + bw = (myRegion->wideLora) ? 812.5 : 250; cr = 8; sf = 7; break; case Config_LoRaConfig_ModemPreset_SHORT_SLOW: - bw = (myRegion->wideLora && rIf_wide_lora) ? 800 : 250; + bw = (myRegion->wideLora) ? 812.5 : 250; cr = 8; sf = 8; break; case Config_LoRaConfig_ModemPreset_MEDIUM_FAST: - bw = (myRegion->wideLora && rIf_wide_lora) ? 800 : 250; + bw = (myRegion->wideLora) ? 812.5 : 250; cr = 8; sf = 9; break; case Config_LoRaConfig_ModemPreset_MEDIUM_SLOW: - bw = (myRegion->wideLora && rIf_wide_lora) ? 800 : 250; + bw = (myRegion->wideLora) ? 812.5 : 250; cr = 8; sf = 10; break; case Config_LoRaConfig_ModemPreset_LONG_FAST: - bw = (myRegion->wideLora && rIf_wide_lora) ? 800 : 250; + bw = (myRegion->wideLora) ? 812.5 : 250; cr = 8; sf = 11; break; case Config_LoRaConfig_ModemPreset_LONG_SLOW: - bw = (myRegion->wideLora && rIf_wide_lora) ? 400 : 125; + bw = (myRegion->wideLora) ? 406.25 : 125; cr = 8; sf = 12; break; case Config_LoRaConfig_ModemPreset_VERY_LONG_SLOW: - bw = (myRegion->wideLora && rIf_wide_lora) ? 200 : 31.25; + bw = (myRegion->wideLora) ? 203.125 : 31.25; cr = 8; sf = 12; break; @@ -411,6 +411,14 @@ void RadioInterface::applyModemConfig() bw = 31.25; if (bw == 62) // Fix for 62.5Khz bandwidth bw = 62.5; + if (bw == 200) + bw = 203.125; + if (bw == 400) + bw = 406.25; + if (bw == 800) + bw = 812.5; + if (bw == 1600) + bw = 1625.0; } power = loraConfig.tx_power; @@ -443,7 +451,7 @@ void RadioInterface::applyModemConfig() DEBUG_MSG("Set radio: region=%s, name=%s, config=%u, ch=%d, power=%d\n", myRegion->name, channelName, loraConfig.modem_preset, channel_num, power); DEBUG_MSG("Radio myRegion->freqStart / myRegion->freqEnd: %f -> %f (%f mhz)\n", myRegion->freqStart, myRegion->freqEnd, myRegion->freqEnd - myRegion->freqStart); - DEBUG_MSG("Radio myRegion->numChannels: %d\n", numChannels); + DEBUG_MSG("Radio myRegion->numChannels: %d x %.3fkHz\n", numChannels, bw); DEBUG_MSG("Radio channel_num: %d\n", channel_num); DEBUG_MSG("Radio frequency: %f\n", getFreq()); DEBUG_MSG("Slot time: %u msec\n", slotTimeMsec); diff --git a/src/mesh/SX128xInterface.cpp b/src/mesh/SX128xInterface.cpp index 10d791847..d717f3b65 100644 --- a/src/mesh/SX128xInterface.cpp +++ b/src/mesh/SX128xInterface.cpp @@ -61,7 +61,7 @@ bool SX128xInterface::init() #endif if (res == RADIOLIB_ERR_NONE) - res = lora.setCRC(RADIOLIB_SX128X_LORA_CRC_ON); + res = lora.setCRC(2); if (res == RADIOLIB_ERR_NONE) startReceive(); // start receiving From 222424a80cf2dcc32e17ec364d44b02a5d6857ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 10 Nov 2022 23:06:37 +0100 Subject: [PATCH 13/24] no excuses, this was a SNAFU --- src/gps/NMEAWPL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gps/NMEAWPL.cpp b/src/gps/NMEAWPL.cpp index 06c77980e..70812e87b 100644 --- a/src/gps/NMEAWPL.cpp +++ b/src/gps/NMEAWPL.cpp @@ -23,7 +23,7 @@ uint32_t printWPL(char *buf, const Position &pos, const char *name) geoCoord.getDMSLatDeg(), (abs(geoCoord.getLatitude()) - geoCoord.getDMSLatDeg() * 1e+7) * 6e-6, geoCoord.getDMSLatCP(), - geoCoord.getDMSLatDeg(), + geoCoord.getDMSLonDeg(), (abs(geoCoord.getLongitude()) - geoCoord.getDMSLonDeg() * 1e+7) * 6e-6, geoCoord.getDMSLonCP(), name); From a6ea5496b43814936bdf710d7b709989d25d51cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 10 Nov 2022 23:26:31 +0100 Subject: [PATCH 14/24] Fixed DIO Pin mapping. SX1280 is working --- variants/tlora_v2_1_18/variant.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/variants/tlora_v2_1_18/variant.h b/variants/tlora_v2_1_18/variant.h index cd693a3d2..dd94847be 100644 --- a/variants/tlora_v2_1_18/variant.h +++ b/variants/tlora_v2_1_18/variant.h @@ -12,20 +12,17 @@ #define I2C_SDA 21 // I2C pins for this board #define I2C_SCL 22 -// #define RESET_OLED 16 // If defined, this pin will be used to reset the display controller. Crashes on newer ESP-IDF and not needed per schematic - -#define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost #define LED_PIN 25 // If defined we will blink this LED #define BUTTON_PIN 12 // If defined, this will be used for user button presses, #define BUTTON_NEED_PULLUP #define USE_SX1280 -#define LORA_DIO0 26 // a No connect on the SX1262 module #define LORA_RESET 23 #define SX128X_CS 18 // FIXME - we really should define LORA_CS instead -#define SX128X_DIO1 33 +#define SX128X_DIO1 26 +#define SX128X_DIO2 33 #define SX128X_BUSY 32 #define SX128X_RESET LORA_RESET #define SX128X_E22 // Not really an E22 but TTGO seems to be trying to clone that From f25f902c209ff9c7bda71b66f3d362862c785701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 11 Nov 2022 08:59:16 +0100 Subject: [PATCH 15/24] max power for the 1280 is +13dBm --- src/mesh/SX128xInterface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/SX128xInterface.cpp b/src/mesh/SX128xInterface.cpp index d717f3b65..0044ae7e5 100644 --- a/src/mesh/SX128xInterface.cpp +++ b/src/mesh/SX128xInterface.cpp @@ -6,7 +6,7 @@ // Particular boards might define a different max power based on what their hardware can do #ifndef SX128X_MAX_POWER -#define SX128X_MAX_POWER 22 +#define SX128X_MAX_POWER 13 #endif template From 65197a8e485c3c81f459ce4b1fe98b68e98598e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 12 Nov 2022 11:03:29 +0100 Subject: [PATCH 16/24] - Add new Compass Sensor - speed up I2C Scanning - make adding sensors less error prone --- platformio.ini | 1 + protobufs | 2 +- src/configuration.h | 1 + src/detect/i2cScan.h | 102 ++++++++++++++++-------------- src/main.cpp | 6 +- src/main.h | 2 +- src/mesh/generated/telemetry.pb.h | 16 +++-- 7 files changed, 71 insertions(+), 59 deletions(-) diff --git a/platformio.ini b/platformio.ini index 68492f520..618c7cddb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -69,6 +69,7 @@ lib_deps = ${env.lib_deps} ; Portduino is using meshtastic fork for now jgromes/RadioLib@5.4.1 + mprograms/QMC5883LCompass@^1.1.1 https://github.com/meshtastic/SparkFun_ATECCX08a_Arduino_Library.git#52b5282639d08a8cbd4b748363089eed6102dc76 build_flags = ${env.build_flags} -Os diff --git a/protobufs b/protobufs index c82c15aac..f7d11572b 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit c82c15aac71b9134d96c03dbe319916739cc8314 +Subproject commit f7d11572b436d1078222ba27892ac73b7a9842ba diff --git a/src/configuration.h b/src/configuration.h index 4b157611d..e68bd8d16 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -110,6 +110,7 @@ along with this program. If not, see . #define INA_ADDR_ALTERNATE 0x41 #define QMC6310_ADDR 0x1C #define QMI8658_ADDR 0x6B +#define QMC5883L_ADDR 0x1E #define SHTC3_ADDR 0x70 #define LPS22HB_ADDR 0x5C #define LPS22HB_ADDR_ALT 0x5D diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 6fc9d67d3..0b8f59c14 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -90,12 +90,14 @@ uint8_t oled_probe(byte addr) return o_probe; } -void scanI2Cdevice(void) +void scanI2Cdevice(bool partial) { 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(); if (err == 0) { @@ -106,16 +108,16 @@ void scanI2Cdevice(void) if (addr == SSD1306_ADDRESS) { screen_found = addr; screen_model = oled_probe(addr); - if (screen_model == 1){ + if (screen_model == 1) { DEBUG_MSG("ssd1306 display found\n"); - } else if (screen_model == 2){ + } else if (screen_model == 2) { DEBUG_MSG("sh1106 display found\n"); } else { DEBUG_MSG("unknown display found\n"); } } #ifndef ARCH_PORTDUINO - if (addr == ATECC608B_ADDR){ + if (addr == ATECC608B_ADDR) { keystore_found = addr; if (atecc.begin(keystore_found) == true) { DEBUG_MSG("ATECC608B initialized\n"); @@ -163,50 +165,56 @@ void scanI2Cdevice(void) DEBUG_MSG("axp192/axp2101 PMU found\n"); } #endif - if (addr == BME_ADDR || addr == BME_ADDR_ALTERNATE) { - registerValue = getRegisterValue(addr, 0xD0, 1); // GET_ID - if (registerValue == 0x61) { - DEBUG_MSG("BME-680 sensor found at address 0x%x\n", (uint8_t)addr); - nodeTelemetrySensorsMap[TelemetrySensorType_BME680] = addr; - } else if (registerValue == 0x60) { - DEBUG_MSG("BME-280 sensor found at address 0x%x\n", (uint8_t)addr); - nodeTelemetrySensorsMap[TelemetrySensorType_BME280] = addr; - } else { - DEBUG_MSG("BMP-280 sensor found at address 0x%x\n", (uint8_t)addr); - nodeTelemetrySensorsMap[TelemetrySensorType_BMP280] = addr; + if (addr == BME_ADDR || addr == BME_ADDR_ALTERNATE) { + registerValue = getRegisterValue(addr, 0xD0, 1); // GET_ID + if (registerValue == 0x61) { + DEBUG_MSG("BME-680 sensor found at address 0x%x\n", (uint8_t)addr); + nodeTelemetrySensorsMap[TelemetrySensorType_BME680] = addr; + } else if (registerValue == 0x60) { + DEBUG_MSG("BME-280 sensor found at address 0x%x\n", (uint8_t)addr); + nodeTelemetrySensorsMap[TelemetrySensorType_BME280] = addr; + } else { + DEBUG_MSG("BMP-280 sensor found at address 0x%x\n", (uint8_t)addr); + nodeTelemetrySensorsMap[TelemetrySensorType_BMP280] = addr; + } } - } - if (addr == INA_ADDR || addr == INA_ADDR_ALTERNATE) { - registerValue = getRegisterValue(addr, 0xFE, 2); - 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); - nodeTelemetrySensorsMap[TelemetrySensorType_INA260] = addr; - } else { // Assume INA219 if INA260 ID is not found - DEBUG_MSG("INA219 sensor found at address 0x%x\n", (uint8_t)addr); - nodeTelemetrySensorsMap[TelemetrySensorType_INA219] = addr; + if (addr == INA_ADDR || addr == INA_ADDR_ALTERNATE) { + registerValue = getRegisterValue(addr, 0xFE, 2); + 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); + nodeTelemetrySensorsMap[TelemetrySensorType_INA260] = addr; + } else { // Assume INA219 if INA260 ID is not found + DEBUG_MSG("INA219 sensor found at address 0x%x\n", (uint8_t)addr); + nodeTelemetrySensorsMap[TelemetrySensorType_INA219] = addr; + } + } + if (addr == MCP9808_ADDR) { + nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = addr; + DEBUG_MSG("MCP9808 sensor found\n"); + } + if (addr == SHTC3_ADDR) { + DEBUG_MSG("SHTC3 sensor found\n"); + nodeTelemetrySensorsMap[TelemetrySensorType_SHTC3] = addr; + } + if (addr == LPS22HB_ADDR || addr == LPS22HB_ADDR_ALT) { + DEBUG_MSG("LPS22HB sensor found\n"); + nodeTelemetrySensorsMap[TelemetrySensorType_LPS22] = addr; + } + + // High rate sensors, will be processed internally + if (addr == QMC6310_ADDR) { + DEBUG_MSG("QMC6310 Highrate 3-Axis magnetic sensor found\n"); + nodeTelemetrySensorsMap[TelemetrySensorType_QMC6310] = addr; + } + if (addr == QMI8658_ADDR) { + DEBUG_MSG("QMI8658 Highrate 6-Axis inertial measurement sensor found\n"); + nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658] = addr; + } + if (addr == QMC5883L_ADDR) { + DEBUG_MSG("QMC5883L Highrate 3-Axis magnetic sensor found\n"); + nodeTelemetrySensorsMap[TelemetrySensorType_QMC5883L] = addr; } - } - if (addr == MCP9808_ADDR) { - nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = addr; - DEBUG_MSG("MCP9808 sensor found at address 0x%x\n", (uint8_t)addr); - } - if (addr == QMC6310_ADDR) { - DEBUG_MSG("QMC6310 3-Axis magnetic sensor found at address 0x%x\n", (uint8_t)addr); - nodeTelemetrySensorsMap[TelemetrySensorType_QMC6310] = addr; - } - if (addr == QMI8658_ADDR) { - DEBUG_MSG("QMI8658 6-Axis inertial measurement sensor found at address 0x%x\n", (uint8_t)addr); - nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658] = addr; - } - if (addr == SHTC3_ADDR) { - DEBUG_MSG("SHTC3 sensor found at address 0x%x\n", (uint8_t)addr); - nodeTelemetrySensorsMap[TelemetrySensorType_SHTC3] = addr; - } - if (addr == LPS22HB_ADDR || addr == LPS22HB_ADDR_ALT) { - DEBUG_MSG("LPS22HB sensor found at address 0x%x\n", (uint8_t)addr); - nodeTelemetrySensorsMap[TelemetrySensorType_LPS22] = addr; - } } else if (err == 4) { DEBUG_MSG("Unknow error at address 0x%x\n", addr); } @@ -218,5 +226,5 @@ void scanI2Cdevice(void) DEBUG_MSG("%i I2C devices found\n",nDevices); } #else -void scanI2Cdevice(void) {} +void scanI2Cdevice(bool partial) {} #endif diff --git a/src/main.cpp b/src/main.cpp index 0f2e575c1..1e95b08ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,7 +100,7 @@ uint32_t serialSinceMsec; 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_QMI8658+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +uint8_t nodeTelemetrySensorsMap[_TelemetrySensorType_MAX + 1] = { 0 }; // one is enough, missing elements will be initialized to 0 anyway. Router *router = NULL; // Users of router don't care what sort of subclass implements that API @@ -245,7 +245,7 @@ void setup() #endif // We need to scan here to decide if we have a screen for nodeDB.init() - scanI2Cdevice(); + scanI2Cdevice(true); #ifdef RAK4630 // scanEInkDevice(); #endif @@ -290,7 +290,7 @@ void setup() * 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(); + scanI2Cdevice(false); // fixed screen override? if (config.display.oled != Config_DisplayConfig_OledType_OLED_AUTO) diff --git a/src/main.h b/src/main.h index 3744c8acd..b7b41c250 100644 --- a/src/main.h +++ b/src/main.h @@ -26,7 +26,7 @@ extern bool isUSBPowered; extern ATECCX08A atecc; #endif -extern uint8_t nodeTelemetrySensorsMap[TelemetrySensorType_QMI8658+1]; +extern uint8_t nodeTelemetrySensorsMap[_TelemetrySensorType_MAX + 1]; extern int TCPPort; // set by Portduino diff --git a/src/mesh/generated/telemetry.pb.h b/src/mesh/generated/telemetry.pb.h index 38f4f9ca8..16e69f442 100644 --- a/src/mesh/generated/telemetry.pb.h +++ b/src/mesh/generated/telemetry.pb.h @@ -33,7 +33,9 @@ typedef enum _TelemetrySensorType { /* 3-Axis magnetic sensor */ TelemetrySensorType_QMC6310 = 9, /* 6-Axis inertial measurement sensor */ - TelemetrySensorType_QMI8658 = 10 + TelemetrySensorType_QMI8658 = 10, + /* 3-Axis magnetic sensor */ + TelemetrySensorType_QMC5883L = 11 } TelemetrySensorType; /* Struct definitions */ @@ -67,10 +69,10 @@ typedef struct _EnvironmentMetrics { /* Types of Measurements the telemetry module is equipped to handle */ typedef struct _Telemetry { - /* This is usually not sent over the mesh (to save space), but it is sent - from the phone so that the local device can set its RTC If it is sent over - the mesh (because there are devices on the mesh without GPS), it will only - be sent by devices which has a hardware GPS clock (IE Mobile Phone). + /* This is usually not sent over the mesh (to save space), but it is sent + from the phone so that the local device can set its RTC If it is sent over + the mesh (because there are devices on the mesh without GPS), it will only + be sent by devices which has a hardware GPS clock (IE Mobile Phone). seconds since 1970 */ uint32_t time; pb_size_t which_variant; @@ -85,8 +87,8 @@ typedef struct _Telemetry { /* Helper constants for enums */ #define _TelemetrySensorType_MIN TelemetrySensorType_SENSOR_UNSET -#define _TelemetrySensorType_MAX TelemetrySensorType_QMI8658 -#define _TelemetrySensorType_ARRAYSIZE ((TelemetrySensorType)(TelemetrySensorType_QMI8658+1)) +#define _TelemetrySensorType_MAX TelemetrySensorType_QMC5883L +#define _TelemetrySensorType_ARRAYSIZE ((TelemetrySensorType)(TelemetrySensorType_QMC5883L+1)) #ifdef __cplusplus 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 17/24] 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); From 52cf530356c800042c9c096660ee82c09c544de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 12 Nov 2022 17:18:17 +0100 Subject: [PATCH 18/24] missing 2 sensor changes --- src/modules/Telemetry/Sensor/INA219Sensor.cpp | 2 +- src/modules/Telemetry/Sensor/SHTC3Sensor.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/Telemetry/Sensor/INA219Sensor.cpp b/src/modules/Telemetry/Sensor/INA219Sensor.cpp index 04e0356b4..5fab3c2e1 100644 --- a/src/modules/Telemetry/Sensor/INA219Sensor.cpp +++ b/src/modules/Telemetry/Sensor/INA219Sensor.cpp @@ -14,8 +14,8 @@ 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]); + if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { #ifdef I2C_SDA1 status = ina219.begin(&Wire1); #endif diff --git a/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp b/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp index bbc7b8479..3516a80a0 100644 --- a/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp +++ b/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp @@ -14,11 +14,11 @@ int32_t SHTC3Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - if (i2cScanMap[SHTC3_ADDR].addr == 0) { + if (i2cScanMap[nodeTelemetrySensorsMap[sensorType]].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) { + if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { #ifdef I2C_SDA1 status = shtc3.begin(&Wire1); #endif From b6de79b21a2f2c403fb04028236f6fcdc8476a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sat, 12 Nov 2022 17:50:33 +0100 Subject: [PATCH 19/24] fix build for RP2040 which actually has 2 TwoWire interfaces. --- src/detect/i2cScan.h | 2 +- src/platform/rp2040/architecture.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index d44c52199..8b8bb647b 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -221,5 +221,5 @@ void scanI2Cdevice(TwoWire myWire, uint8_t busnum) DEBUG_MSG("%i I2C devices found\n",nDevices); } #else -void scanI2Cdevice() {} +void scanI2Cdevice(TwoWire myWire, uint8_t busnum) {} #endif diff --git a/src/platform/rp2040/architecture.h b/src/platform/rp2040/architecture.h index 35d163e4a..857569b99 100644 --- a/src/platform/rp2040/architecture.h +++ b/src/platform/rp2040/architecture.h @@ -2,6 +2,13 @@ #define ARCH_RP2040 +#ifndef HAS_SCREEN + #define HAS_SCREEN 1 +#endif +#ifndef HAS_WIRE + #define HAS_WIRE 1 +#endif + #if defined(PRIVATE_HW) #define HW_VENDOR HardwareModel_PRIVATE_HW #endif \ No newline at end of file From 037d6c253bd42584961b9d6c6550ad40ae687776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 13 Nov 2022 11:58:02 +0100 Subject: [PATCH 20/24] fix portduino --- src/detect/i2cScan.h | 2 +- src/input/cardKbI2cImpl.cpp | 4 ++++ src/input/kbI2cBase.cpp | 3 +++ src/main.cpp | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 8b8bb647b..d44c52199 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -221,5 +221,5 @@ void scanI2Cdevice(TwoWire myWire, uint8_t busnum) DEBUG_MSG("%i I2C devices found\n",nDevices); } #else -void scanI2Cdevice(TwoWire myWire, uint8_t busnum) {} +void scanI2Cdevice() {} #endif diff --git a/src/input/cardKbI2cImpl.cpp b/src/input/cardKbI2cImpl.cpp index bef99f4c3..b19820920 100644 --- a/src/input/cardKbI2cImpl.cpp +++ b/src/input/cardKbI2cImpl.cpp @@ -1,6 +1,8 @@ #include "cardKbI2cImpl.h" #include "InputBroker.h" +#if HAS_WIRE + CardKbI2cImpl *cardKbI2cImpl; CardKbI2cImpl::CardKbI2cImpl() : @@ -18,3 +20,5 @@ void CardKbI2cImpl::init() inputBroker->registerSource(this); } + +#endif \ No newline at end of file diff --git a/src/input/kbI2cBase.cpp b/src/input/kbI2cBase.cpp index 7285d3919..5f362f480 100644 --- a/src/input/kbI2cBase.cpp +++ b/src/input/kbI2cBase.cpp @@ -3,6 +3,7 @@ #include "main.h" #include +#if HAS_WIRE KbI2cBase::KbI2cBase(const char *name) : concurrency::OSThread(name) { @@ -120,3 +121,5 @@ int32_t KbI2cBase::runOnce() } return 500; } + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 195be3edc..27b16a96b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -247,8 +247,10 @@ void setup() powerStatus->observe(&power->newStatus); power->setup(); // Must be after status handler is installed, so that handler gets notified of the initial configuration +#if HAS_WIRE // We need to scan here to decide if we have a screen for nodeDB.init() scanI2Cdevice(Wire,0); +#endif #ifdef I2C_SDA1 scanI2Cdevice(Wire1,1); From 6a696af8f635bdef3faba15c16a72eaacfff527e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 13 Nov 2022 14:56:52 +0100 Subject: [PATCH 21/24] Revert "remember which devices were scanned on which bus and set them accordingly." - this is not working at all. --- 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 | 6 +- src/input/kbI2cBase.cpp | 48 ++++++-------- 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/rp2040/architecture.h | 7 -- 23 files changed, 117 insertions(+), 191 deletions(-) diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index d44c52199..0b8f59c14 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, TwoWire myWire) { +uint16_t getRegisterValue(uint8_t address, uint8_t reg, uint8_t length) { uint16_t value = 0x00; - myWire.beginTransmission(address); - myWire.write(reg); - myWire.endTransmission(); + Wire.beginTransmission(address); + Wire.write(reg); + Wire.endTransmission(); delay(20); - myWire.requestFrom(address, length); - DEBUG_MSG("Wire.available() = %d\n", myWire.available()); - if (myWire.available() == 2) { + Wire.requestFrom(address, length); + DEBUG_MSG("Wire.available() = %d\n", Wire.available()); + if (Wire.available() == 2) { // Read MSB, then LSB - value = (uint16_t)myWire.read() << 8; - value |= myWire.read(); - } else if (myWire.available()) { - value = myWire.read(); + value = (uint16_t)Wire.read() << 8; + value |= Wire.read(); + } else if (Wire.available()) { + value = Wire.read(); } return value; } -uint8_t oled_probe(byte addr, TwoWire myWire) +uint8_t oled_probe(byte addr) { uint8_t r = 0; uint8_t r_prev = 0; @@ -70,12 +70,12 @@ uint8_t oled_probe(byte addr, TwoWire myWire) uint8_t o_probe = 0; do { r_prev = r; - myWire.beginTransmission(addr); - myWire.write(0x00); - myWire.endTransmission(); - myWire.requestFrom((int)addr, 1); - if (myWire.available()) { - r = myWire.read(); + Wire.beginTransmission(addr); + Wire.write(0x00); + Wire.endTransmission(); + Wire.requestFrom((int)addr, 1); + if (Wire.available()) { + r = Wire.read(); } r &= 0x0f; @@ -90,24 +90,24 @@ uint8_t oled_probe(byte addr, TwoWire myWire) return o_probe; } -void scanI2Cdevice(TwoWire myWire, uint8_t busnum) +void scanI2Cdevice(bool partial) { byte err, addr; uint16_t registerValue = 0x00; int nDevices = 0; for (addr = 1; addr < 127; addr++) { - myWire.beginTransmission(addr); - err = myWire.endTransmission(); + if (partial && addr != SSD1306_ADDRESS && addr != ST7567_ADDRESS && addr != XPOWERS_AXP192_AXP2101_ADDRESS) + continue; + Wire.beginTransmission(addr); + err = Wire.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, myWire); + screen_model = oled_probe(addr); if (screen_model == 1) { DEBUG_MSG("ssd1306 display found\n"); } else if (screen_model == 2) { @@ -118,7 +118,8 @@ void scanI2Cdevice(TwoWire myWire, uint8_t busnum) } #ifndef ARCH_PORTDUINO if (addr == ATECC608B_ADDR) { - if (atecc.begin(ATECC608B_ADDR) == true) { + keystore_found = addr; + if (atecc.begin(keystore_found) == true) { DEBUG_MSG("ATECC608B initialized\n"); } else { DEBUG_MSG("ATECC608B initialization failed\n"); @@ -128,21 +129,24 @@ void scanI2Cdevice(TwoWire myWire, uint8_t busnum) #endif #ifdef RV3028_RTC if (addr == RV3028_RTC){ + rtc_found = addr; DEBUG_MSG("RV3028 RTC found\n"); Melopero_RV3028 rtc; - rtc.initI2C(myWire); + rtc.initI2C(); 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, myWire); + registerValue = getRegisterValue(addr, 0x04, 1); if (registerValue == 0x02) { // KEYPAD_VERSION DEBUG_MSG("RAK14004 found\n"); kb_model = 0x02; @@ -157,11 +161,12 @@ void scanI2Cdevice(TwoWire myWire, uint8_t busnum) } #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, myWire); // GET_ID + registerValue = getRegisterValue(addr, 0xD0, 1); // GET_ID if (registerValue == 0x61) { DEBUG_MSG("BME-680 sensor found at address 0x%x\n", (uint8_t)addr); nodeTelemetrySensorsMap[TelemetrySensorType_BME680] = addr; @@ -174,7 +179,7 @@ void scanI2Cdevice(TwoWire myWire, uint8_t busnum) } } if (addr == INA_ADDR || addr == INA_ADDR_ALTERNATE) { - registerValue = getRegisterValue(addr, 0xFE, 2, myWire); + registerValue = getRegisterValue(addr, 0xFE, 2); 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); @@ -221,5 +226,5 @@ void scanI2Cdevice(TwoWire myWire, uint8_t busnum) DEBUG_MSG("%i I2C devices found\n",nDevices); } #else -void scanI2Cdevice() {} +void scanI2Cdevice(bool partial) {} #endif diff --git a/src/gps/RTC.cpp b/src/gps/RTC.cpp index b46db9bc5..e04f903ee 100644 --- a/src/gps/RTC.cpp +++ b/src/gps/RTC.cpp @@ -20,16 +20,10 @@ void readFromRTC() { struct timeval tv; /* btw settimeofday() is helpfull here too*/ #ifdef RV3028_RTC - if(i2cScanMap[RV3028_RTC].addr == RV3028_RTC) { + if(rtc_found == RV3028_RTC) { uint32_t now = millis(); Melopero_RV3028 rtc; - if (i2cScanMap[RV3028_RTC].bus == 1) { -#ifdef I2C_SDA1 - rtc.initI2C(Wire1); -#endif - } else { - rtc.initI2C(); - } + rtc.initI2C(); tm t; t.tm_year = rtc.getYear() - 1900; t.tm_mon = rtc.getMonth() - 1; @@ -47,16 +41,14 @@ void readFromRTC() } } #elif defined(PCF8563_RTC) - if(i2cScanMap[PCF8563_RTC].addr == PCF8563_RTC) { + if(rtc_found == PCF8563_RTC) { uint32_t now = millis(); PCF8563_Class rtc; - if (i2cScanMap[PCF8563_RTC].bus == 1) { -#ifdef I2C_SDA1 - rtc.begin(Wire1); +#ifdef RTC_USE_WIRE1 + rtc.begin(Wire1); +#else + rtc.begin(); #endif - } else { - rtc.begin(); - } auto tc = rtc.getDateTime(); tm t; t.tm_year = tc.year - 1900; @@ -112,29 +104,21 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv) // If this platform has a setable RTC, set it #ifdef RV3028_RTC - if(i2cScanMap[RV3028_RTC].addr == RV3028_RTC) { + if(rtc_found == RV3028_RTC) { Melopero_RV3028 rtc; - if (i2cScanMap[RV3028_RTC].bus == 1) { -#ifdef I2C_SDA1 - rtc.initI2C(Wire1); -#endif - } else { - rtc.initI2C(); - } + 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(i2cScanMap[PCF8563_RTC].addr == PCF8563_RTC) { + if(rtc_found == PCF8563_RTC) { PCF8563_Class rtc; - if (i2cScanMap[PCF8563_RTC].bus == 1) { -#ifdef I2C_SDA1 - rtc.begin(Wire1); +#ifdef RTC_USE_WIRE1 + rtc.begin(Wire1); +#else + rtc.begin(); #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 03b57babd..9e0834954 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, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus) +EInkDisplay::EInkDisplay(uint8_t address, int sda, int scl) { #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 a8cc4f1fa..727132d0e 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, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus); + EInkDisplay(uint8_t address, int sda, int scl); // 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 0833dda93..277127d53 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, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus) : OSThread("Screen"), cmdQueue(32), dispdev(address, sda, scl, g, i2cBus), ui(&dispdev) +Screen::Screen(uint8_t address, int sda, int scl) : OSThread("Screen"), cmdQueue(32), dispdev(address, sda, scl), ui(&dispdev) { address_found = address; cmdQueue.setReader(this); diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 1483e8261..23828b3ee 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,OLEDDISPLAY_GEOMETRY g = GEOMETRY_128_64, HW_I2C i2cBus = I2C_ONE); + explicit Screen(uint8_t address, int sda = -1, int scl = -1); Screen(const Screen &) = delete; Screen &operator=(const Screen &) = delete; diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 5786a0ba1..1d5f43cd1 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, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus) +TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl) { #ifdef SCREEN_ROTATE setGeometry(GEOMETRY_RAWMODE, TFT_HEIGHT, TFT_WIDTH); diff --git a/src/graphics/TFTDisplay.h b/src/graphics/TFTDisplay.h index d201839b9..c9749d9a8 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, OLEDDISPLAY_GEOMETRY g, HW_I2C i2cBus); + TFTDisplay(uint8_t address, int sda, int scl); // 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 b19820920..de0fbbd38 100644 --- a/src/input/cardKbI2cImpl.cpp +++ b/src/input/cardKbI2cImpl.cpp @@ -1,8 +1,6 @@ #include "cardKbI2cImpl.h" #include "InputBroker.h" -#if HAS_WIRE - CardKbI2cImpl *cardKbI2cImpl; CardKbI2cImpl::CardKbI2cImpl() : @@ -12,7 +10,7 @@ CardKbI2cImpl::CardKbI2cImpl() : void CardKbI2cImpl::init() { - if (i2cScanMap[CARDKB_ADDR].addr != CARDKB_ADDR) + if (cardkb_found != CARDKB_ADDR) { // Input device is not detected. return; @@ -20,5 +18,3 @@ void CardKbI2cImpl::init() inputBroker->registerSource(this); } - -#endif \ No newline at end of file diff --git a/src/input/kbI2cBase.cpp b/src/input/kbI2cBase.cpp index 5f362f480..332dfde0d 100644 --- a/src/input/kbI2cBase.cpp +++ b/src/input/kbI2cBase.cpp @@ -1,60 +1,52 @@ #include "kbI2cBase.h" #include "configuration.h" -#include "main.h" #include -#if HAS_WIRE +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, TwoWire myWire) +uint8_t read_from_14004(uint8_t reg, uint8_t *data, uint8_t length) { uint8_t readflag = 0; - myWire.beginTransmission(CARDKB_ADDR); - myWire.write(reg); - myWire.endTransmission(); // stop transmitting + Wire.beginTransmission(CARDKB_ADDR); + Wire.write(reg); + Wire.endTransmission(); // stop transmitting delay(20); - myWire.requestFrom(CARDKB_ADDR, (int)length); + Wire.requestFrom(CARDKB_ADDR, (int)length); int i = 0; - while ( myWire.available() ) // slave may send less than requested + while ( Wire.available() ) // slave may send less than requested { - data[i++] = myWire.read(); // receive a byte as a proper uint8_t + data[i++] = Wire.read(); // receive a byte as a proper uint8_t readflag = 1; } return readflag; } -void write_to_14004(uint8_t reg, uint8_t data, TwoWire myWire) +void write_to_14004(uint8_t reg, uint8_t data) { - myWire.beginTransmission(CARDKB_ADDR); - myWire.write(reg); - myWire.write(data); - myWire.endTransmission(); // stop transmitting + Wire.beginTransmission(CARDKB_ADDR); + Wire.write(reg); + Wire.write(data); + Wire.endTransmission(); // stop transmitting } int32_t KbI2cBase::runOnce() { - if (i2cScanMap[CARDKB_ADDR].addr != CARDKB_ADDR) { + if (cardkb_found != 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, myWire) == 1) { + if (read_from_14004(0x01, rDataBuf, 0x04) == 1) { for (uint8_t aCount = 0; aCount < 0x04; aCount++) { for (uint8_t bCount = 0; bCount < 0x04; bCount++ ) { if (((rDataBuf[aCount] >> bCount) & 0x01) == 0x01) { @@ -73,10 +65,10 @@ int32_t KbI2cBase::runOnce() } } else { // m5 cardkb - myWire.requestFrom(CARDKB_ADDR, 1); + Wire.requestFrom(CARDKB_ADDR, 1); - while (myWire.available()) { - char c = myWire.read(); + while (Wire.available()) { + char c = Wire.read(); InputEvent e; e.inputEvent = ModuleConfig_CannedMessageConfig_InputEventChar_NONE; e.source = this->_originName; @@ -121,5 +113,3 @@ int32_t KbI2cBase::runOnce() } return 500; } - -#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 27b16a96b..2bf2a0de1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,9 +79,16 @@ 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 @@ -95,8 +102,6 @@ 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() @@ -174,8 +179,7 @@ void setup() initDeepSleep(); -// 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 + // Testing this fix für erratic T-Echo boot behaviour #if defined(TTGO_T_ECHO) && defined(PIN_EINK_PWR_ON) pinMode(PIN_EINK_PWR_ON, OUTPUT); digitalWrite(PIN_EINK_PWR_ON, HIGH); @@ -212,6 +216,7 @@ void setup() fsInit(); + // router = new DSRRouter(); router = new ReliableRouter(); #ifdef I2C_SDA1 @@ -247,14 +252,19 @@ void setup() powerStatus->observe(&power->newStatus); power->setup(); // Must be after status handler is installed, so that handler gets notified of the initial configuration -#if HAS_WIRE - // We need to scan here to decide if we have a screen for nodeDB.init() - scanI2Cdevice(Wire,0); + +#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 -#ifdef I2C_SDA1 - scanI2Cdevice(Wire1,1); -#endif + // We need to scan here to decide if we have a screen for nodeDB.init() + scanI2Cdevice(); #ifdef HAS_SDCARD setupSDCard(); @@ -294,6 +304,13 @@ 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; @@ -329,7 +346,7 @@ void setup() // Do this after service.init (because that clears error_code) #ifdef HAS_PMU - if (i2cScanMap[XPOWERS_AXP192_AXP2101_ADDRESS].addr == 0) + if (!pmu_found) RECORD_CRITICALERROR(CriticalErrorCode_NO_AXP192); // Record a hardware fault for missing hardware #endif diff --git a/src/main.h b/src/main.h index 2387f21c2..b7b41c250 100644 --- a/src/main.h +++ b/src/main.h @@ -12,7 +12,10 @@ 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; @@ -23,13 +26,6 @@ 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 64a9df445..b00dfb796 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -5,7 +5,6 @@ #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 @@ -36,6 +35,8 @@ // 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; @@ -52,7 +53,7 @@ CannedMessageModule::CannedMessageModule() { if (moduleConfig.canned_message.enabled) { this->loadProtoForModule(); - if ((this->splitConfiguredMessages() <= 0) && (i2cScanMap[CARDKB_ADDR].addr != CARDKB_ADDR)) { + if ((this->splitConfiguredMessages() <= 0) && (cardkb_found != 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 655356363..4b6a50091 100644 --- a/src/modules/Telemetry/Sensor/BME280Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BME280Sensor.cpp @@ -15,14 +15,8 @@ int32_t BME280Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { -#ifdef I2C_SDA1 - status = bme280.begin(nodeTelemetrySensorsMap[sensorType], &Wire1); -#endif - } else { - status = bme280.begin(nodeTelemetrySensorsMap[sensorType], &Wire); - } - + status = bme280.begin(nodeTelemetrySensorsMap[sensorType]); + 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 9cc2f6430..a9171facf 100644 --- a/src/modules/Telemetry/Sensor/BME680Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BME680Sensor.cpp @@ -14,13 +14,6 @@ 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 2abbb2927..917c40d6f 100644 --- a/src/modules/Telemetry/Sensor/BMP280Sensor.cpp +++ b/src/modules/Telemetry/Sensor/BMP280Sensor.cpp @@ -15,14 +15,6 @@ 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 5fab3c2e1..3e280c526 100644 --- a/src/modules/Telemetry/Sensor/INA219Sensor.cpp +++ b/src/modules/Telemetry/Sensor/INA219Sensor.cpp @@ -15,13 +15,7 @@ int32_t INA219Sensor::runOnce() { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } ina219 = Adafruit_INA219(nodeTelemetrySensorsMap[sensorType]); - if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { -#ifdef I2C_SDA1 - status = ina219.begin(&Wire1); -#endif - } else { - status = ina219.begin(&Wire); - } + status = ina219.begin(); return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/INA260Sensor.cpp b/src/modules/Telemetry/Sensor/INA260Sensor.cpp index 3d34344a0..1c924ad71 100644 --- a/src/modules/Telemetry/Sensor/INA260Sensor.cpp +++ b/src/modules/Telemetry/Sensor/INA260Sensor.cpp @@ -14,13 +14,7 @@ int32_t INA260Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { -#ifdef I2C_SDA1 - status = ina260.begin(nodeTelemetrySensorsMap[sensorType], &Wire1); -#endif - } else { - status = ina260.begin(nodeTelemetrySensorsMap[sensorType], &Wire); - } + status = ina260.begin(nodeTelemetrySensorsMap[sensorType]); return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp b/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp index dad1895b6..1209c1435 100644 --- a/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp +++ b/src/modules/Telemetry/Sensor/LPS22HBSensor.cpp @@ -15,13 +15,7 @@ int32_t LPS22HBSensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - 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); - } + status = lps22hb.begin_I2C(nodeTelemetrySensorsMap[sensorType]); return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp b/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp index 29aa16009..57092d285 100644 --- a/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp +++ b/src/modules/Telemetry/Sensor/MCP9808Sensor.cpp @@ -14,13 +14,7 @@ int32_t MCP9808Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { -#ifdef I2C_SDA1 - status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType], &Wire1); -#endif - } else { - status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType], &Wire); - } + status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType]); return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp b/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp index 3516a80a0..b3a76ba91 100644 --- a/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp +++ b/src/modules/Telemetry/Sensor/SHTC3Sensor.cpp @@ -14,18 +14,7 @@ int32_t SHTC3Sensor::runOnce() { if (!hasSensor()) { return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; } - if (i2cScanMap[nodeTelemetrySensorsMap[sensorType]].addr == 0) { - DEBUG_MSG("SHTC3 not found on i2c bus\n"); - return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; - } - if(i2cScanMap[nodeTelemetrySensorsMap[sensorType]].bus == 1) { -#ifdef I2C_SDA1 - status = shtc3.begin(&Wire1); -#endif - } else { - status = shtc3.begin(&Wire); - } - + status = shtc3.begin(); return initI2CSensor(); } diff --git a/src/modules/Telemetry/Sensor/TelemetrySensor.h b/src/modules/Telemetry/Sensor/TelemetrySensor.h index 772744449..12bf17e56 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 detected i2c bus\n", sensorName); + DEBUG_MSG("Opened %s sensor on default i2c bus\n", sensorName); setup(); } return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS; diff --git a/src/platform/rp2040/architecture.h b/src/platform/rp2040/architecture.h index 857569b99..35d163e4a 100644 --- a/src/platform/rp2040/architecture.h +++ b/src/platform/rp2040/architecture.h @@ -2,13 +2,6 @@ #define ARCH_RP2040 -#ifndef HAS_SCREEN - #define HAS_SCREEN 1 -#endif -#ifndef HAS_WIRE - #define HAS_WIRE 1 -#endif - #if defined(PRIVATE_HW) #define HW_VENDOR HardwareModel_PRIVATE_HW #endif \ No newline at end of file From 401b92bdbb6f8f503f11ec81d4a676fc36fa8a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 13 Nov 2022 15:28:43 +0100 Subject: [PATCH 22/24] reverted too much --- src/detect/i2cScan.h | 4 +--- src/main.cpp | 9 +-------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 0b8f59c14..8ea1d7df3 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -90,14 +90,12 @@ uint8_t oled_probe(byte addr) return o_probe; } -void scanI2Cdevice(bool partial) +void scanI2Cdevice() { 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(); if (err == 0) { diff --git a/src/main.cpp b/src/main.cpp index 2bf2a0de1..f83909869 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -303,14 +303,7 @@ void setup() nodeDB.init(); 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; From 263a421c4ab186d0a237006bd3096f5e1def9837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 13 Nov 2022 15:35:18 +0100 Subject: [PATCH 23/24] fix pico build --- src/detect/i2cScan.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detect/i2cScan.h b/src/detect/i2cScan.h index 8ea1d7df3..19e405133 100644 --- a/src/detect/i2cScan.h +++ b/src/detect/i2cScan.h @@ -224,5 +224,5 @@ void scanI2Cdevice() DEBUG_MSG("%i I2C devices found\n",nDevices); } #else -void scanI2Cdevice(bool partial) {} +void scanI2Cdevice() {} #endif From 916f3cac41809a590d466795b9658644fb36905d Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 13 Nov 2022 14:40:18 -0600 Subject: [PATCH 24/24] Sync protos --- protobufs | 2 +- src/mesh/generated/mesh.pb.h | 4 ++++ src/mesh/generated/telemetry.pb.h | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/protobufs b/protobufs index f7d11572b..da9bba9c5 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit f7d11572b436d1078222ba27892ac73b7a9842ba +Subproject commit da9bba9c5dd43a98d431cb7a95159b145f0483c4 diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index 8e73a0972..8d96960d1 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -78,6 +78,10 @@ typedef enum _HardwareModel { HardwareModel_DR_DEV = 41, /* M5 esp32 based MCU modules with enclosure, TFT and LORA Shields. All Variants (Basic, Core, Fire, Core2, Paper) https://m5stack.com/ */ HardwareModel_M5STACK = 42, + /* New Heltec LoRA32 with ESP32-S3 CPU */ + HardwareModel_HELTEC_V3 = 43, + /* New Heltec Wireless Stick Lite with ESP32-S3 CPU */ + HardwareModel_HELTEC_WSL_V3 = 44, /* Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. */ HardwareModel_PRIVATE_HW = 255 } HardwareModel; diff --git a/src/mesh/generated/telemetry.pb.h b/src/mesh/generated/telemetry.pb.h index 16e69f442..8c5c68bfa 100644 --- a/src/mesh/generated/telemetry.pb.h +++ b/src/mesh/generated/telemetry.pb.h @@ -69,10 +69,10 @@ typedef struct _EnvironmentMetrics { /* Types of Measurements the telemetry module is equipped to handle */ typedef struct _Telemetry { - /* This is usually not sent over the mesh (to save space), but it is sent - from the phone so that the local device can set its RTC If it is sent over - the mesh (because there are devices on the mesh without GPS), it will only - be sent by devices which has a hardware GPS clock (IE Mobile Phone). + /* This is usually not sent over the mesh (to save space), but it is sent + from the phone so that the local device can set its RTC If it is sent over + the mesh (because there are devices on the mesh without GPS), it will only + be sent by devices which has a hardware GPS clock (IE Mobile Phone). seconds since 1970 */ uint32_t time; pb_size_t which_variant;