diff --git a/.vscode/launch.json b/.vscode/launch.json index 2e1ab296a..914831d68 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,7 +12,7 @@ "type": "platformio-debug", "request": "launch", "name": "PIO Debug", - "executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/esp32/firmware.elf", + "executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/tbeam/firmware.elf", "toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-xtensa32/bin", "preLaunchTask": { "type": "PlatformIO", @@ -24,7 +24,7 @@ "type": "platformio-debug", "request": "launch", "name": "PIO Debug (skip Pre-Debug)", - "executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/esp32/firmware.elf", + "executable": "/home/kevinh/development/meshtastic/meshtastic-esp32/.pio/build/tbeam/firmware.elf", "toolchainBinDir": "/home/kevinh/.platformio/packages/toolchain-xtensa32/bin", "internalConsoleOptions": "openOnSessionStart" } diff --git a/bin/build-all.sh b/bin/build-all.sh index 9dbc2fb48..b7eccd59e 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -7,9 +7,6 @@ source bin/version.sh COUNTRIES="US EU433 EU865 CN JP" #COUNTRIES=US -SRCMAP=.pio/build/esp32/output.map -SRCBIN=.pio/build/esp32/firmware.bin -SRCELF=.pio/build/esp32/firmware.elf OUTDIR=release/latest # We keep all old builds (and their map files in the archive dir) @@ -17,25 +14,28 @@ ARCHIVEDIR=release/archive rm -f $OUTDIR/firmware* +# build the named environment and copy the bins to the release directory +function do_build { + ENV_NAME=$1 + echo "Building for $ENV_NAME with $PLATFORMIO_BUILD_FLAGS" + SRCBIN=.pio/build/$ENV_NAME/firmware.bin + SRCELF=.pio/build/$ENV_NAME/firmware.elf + rm -f $SRCBIN + pio run --environment $ENV_NAME # -v + cp $SRCBIN $OUTDIR/firmware-$ENV_NAME-$COUNTRY-$VERSION.bin + cp $SRCELF $OUTDIR/firmware-$ENV_NAME-$COUNTRY-$VERSION.elf +} + for COUNTRY in $COUNTRIES; do HWVERSTR="1.0-$COUNTRY" - COMMONOPTS="-DAPP_VERSION=$VERSION -DHW_VERSION_$COUNTRY -DHW_VERSION=$HWVERSTR -Wall -Wextra -Wno-missing-field-initializers -Isrc -Os -Wl,-Map,.pio/build/esp32/output.map -DAXP_DEBUG_PORT=Serial" + COMMONOPTS="-DAPP_VERSION=$VERSION -DHW_VERSION_$COUNTRY -DHW_VERSION=$HWVERSTR -Wall -Wextra -Wno-missing-field-initializers -Isrc -Os -DAXP_DEBUG_PORT=Serial" - export PLATFORMIO_BUILD_FLAGS="-DT_BEAM_V10 $COMMONOPTS" - echo "Building with $PLATFORMIO_BUILD_FLAGS" - rm -f $SRCBIN $SRCMAP - pio run # -v - cp $SRCBIN $OUTDIR/firmware-TBEAM-$COUNTRY-$VERSION.bin - cp $SRCELF $OUTDIR/firmware-TBEAM-$COUNTRY-$VERSION.elf - #cp $SRCMAP $ARCHIVEDIR/firmware-TBEAM-$COUNTRY-$VERSION.map + export PLATFORMIO_BUILD_FLAGS="$COMMONOPTS" - export PLATFORMIO_BUILD_FLAGS="-DHELTEC_LORA32 $COMMONOPTS" - rm -f $SRCBIN $SRCMAP - pio run # -v - cp $SRCBIN $OUTDIR/firmware-HELTEC-$COUNTRY-$VERSION.bin - cp $SRCELF $OUTDIR/firmware-HELTEC-$COUNTRY-$VERSION.elf - #cp $SRCMAP $ARCHIVEDIR/firmware-HELTEC-$COUNTRY-$VERSION.map + do_build "ttgo-lora32-v1" + do_build "tbeam" + do_build "heltec" done # keep the bins in archive also diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 01a939fe1..38523a33b 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -17,6 +17,7 @@ Items to complete soon (next couple of alpha releases). Items to complete before the first beta release. +- possibly switch to https://github.com/SlashDevin/NeoGPS for gps comms - good source of battery/signal/gps icons https://materialdesignicons.com/ - research and implement better mesh algorithm - investigate changing routing to https://github.com/sudomesh/LoRaLayer2 ? - check fcc rules on duty cycle. we might not need to freq hop. https://www.sunfiretesting.com/LoRa-FCC-Certification-Guide/ diff --git a/docs/software/build-instructions.md b/docs/software/build-instructions.md index 624becd17..073ce4e8e 100644 --- a/docs/software/build-instructions.md +++ b/docs/software/build-instructions.md @@ -6,19 +6,15 @@ in these instructions I describe use of their command line tool. 1. Purchase a suitable radio (see above) 2. Install [PlatformIO](https://platformio.org/platformio-ide) 3. Download this git repo and cd into it -4. Edit configuration.h and comment out *one* of the following two lines (depending on which board you are using): -``` -// #define T_BEAM_V10 -#define HELTEC_LORA32 -``` +4. If you are outside the USA, edit [platformio.ini](/platformio.ini) to set the correct frequency range for your country. The line you need to change starts with "hw_version" and instructions are provided above that line. Options are provided for EU433, EU835, CN, JP and US. Pull-requests eagerly accepted for other countries. 5. Plug the radio into your USB port -6. Type "pio run -t upload" (This command will fetch dependencies, build the project and install it on the board via USB) -7. Platform IO also installs a very nice VisualStudio Code based IDE, see their [tutorial](https://docs.platformio.org/en/latest/tutorials/espressif32/arduino_debugging_unit_testing.html) if you'd like to use it - +6. Type "pio run --environment XXX -t upload" (This command will fetch dependencies, build the project and install it on the board via USB). For XXX, use the board type you have (either tbeam, heltec, ttgo-lora32-v1, ttgo-lora32-v2). +7. Platform IO also installs a very nice VisualStudio Code based IDE, see their [tutorial](https://docs.platformio.org/en/latest/tutorials/espressif32/arduino_debugging_unit_testing.html) if you'd like to use it. ## Decoding stack traces If you get a crash, you can decode the addresses from the `Backtrace:` line: + 1. Save the `Backtrace: 0x....` line to a file, e.g., `backtrace.txt`. 2. Run `bin/exception_decoder.py backtrace.txt` (this uses symbols from the last `firmware.elf`, so you must be running the same binary that's still in diff --git a/docs/software/mesh-alg.md b/docs/software/mesh-alg.md index 193f0aef9..d0935d34f 100644 --- a/docs/software/mesh-alg.md +++ b/docs/software/mesh-alg.md @@ -10,7 +10,7 @@ TODO: * DONE read about mesh routing solutions (DSR and AODV) * DONE read about general mesh flooding solutions (naive, MPR, geo assisted) * DONE reread the disaster radio protocol docs - seems based on Babel (which is AODVish) -* possibly dash7? https://www.slideshare.net/MaartenWeyn1/dash7-alliance-protocol-technical-presentation https://github.com/MOSAIC-LoPoW/dash7-ap-open-source-stack +* possibly dash7? https://www.slideshare.net/MaartenWeyn1/dash7-alliance-protocol-technical-presentation https://github.com/MOSAIC-LoPoW/dash7-ap-open-source-stack - does the opensource stack implement multihop routing? flooding? their discussion mailing list looks dead-dead * update duty cycle spreadsheet for our typical usecase * generalize naive flooding on top of radiohead or disaster.radio? (and fix radiohead to use my new driver) diff --git a/platformio.ini b/platformio.ini index 2ab626f1f..f8de66947 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,11 +9,14 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] +default_envs = tbeam -[env:esp32] +[common] +; default to a US frequency range, change it as needed for your region and hardware (CN, JP, EU433, EU865) +hw_version = US + +[env] platform = espressif32 -board = ttgo-t-beam -; board = heltec_wifi_lora_32_V2 framework = arduino ; customize the partition table @@ -22,14 +25,13 @@ board_build.partitions = partition-table.csv ; note: we add src to our include search path so that lmic_project_config can override ; FIXME: fix lib/BluetoothOTA dependency back on src/ so we can remove -Isrc -build_flags = -Wall -Wextra -Wno-missing-field-initializers -Isrc -Os -Wl,-Map,.pio/build/esp32/output.map -DAXP_DEBUG_PORT=Serial +build_flags = -Wall -Wextra -Wno-missing-field-initializers -Isrc -Os -Wl,-Map,.pio/build/output.map -DAXP_DEBUG_PORT=Serial -DHW_VERSION_${common.hw_version} ; not needed included in ttgo-t-beam board file ; also to use PSRAM https://docs.platformio.org/en/latest/platforms/espressif32.html#external-ram-psram ; -DBOARD_HAS_PSRAM ; -mfix-esp32-psram-cache-issue - ; -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG upload_speed = 921600 @@ -55,8 +57,6 @@ debug_tool = jlink debug_init_break = tbreak setup -; Note: some libraries are specified by #ID where there are conflicting library -; names. lib_deps = https://github.com/meshtastic/RadioHead.git https://github.com/meshtastic/esp8266-oled-ssd1306.git ; ESP8266_SSD1306 @@ -68,9 +68,19 @@ lib_deps = https://github.com/meshtastic/arduino-fsm.git https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git -;[env:tbeam] -;board = ttgo-t-beam +[env:tbeam] +board = ttgo-t-beam +lib_deps = + ${env.lib_deps} + AXP202X_Library -;[env:heltec] +[env:heltec] ;build_type = debug ; to make it possible to step through our jtag debugger -;board = heltec_wifi_lora_32_V2 +board = heltec_wifi_lora_32_V2 + +[env:ttgo-lora32-v1] +board = ttgo-lora32-v1 + +; note: the platformio definition for lora32-v2 seems stale, it is missing a pins_arduino.h file, therefore I don't think it works +; [env:ttgo-lora32-v2] +; board = ttgo-lora32-v2 \ No newline at end of file diff --git a/src/MeshService.cpp b/src/MeshService.cpp index 02ce6a090..bf1702389 100644 --- a/src/MeshService.cpp +++ b/src/MeshService.cpp @@ -151,7 +151,7 @@ void MeshService::handleFromRadio(MeshPacket *mp) mp->rx_time = gps.getValidTime(); // store the arrival timestamp for the phone // If it is a position packet, perhaps set our clock (if we don't have a GPS of our own, otherwise wait for that to work) - if (!myNodeInfo.has_gps) + if (!gps.isConnected) handleIncomingPosition(mp); else { DEBUG_MSG("Ignoring incoming time, because we have a GPS\n"); @@ -263,7 +263,7 @@ void MeshService::sendToMesh(MeshPacket *p) // nodes shouldn't trust it anyways) Note: for now, we allow a device with a local GPS to include the time, so that gpsless // devices can get time. if (p->has_payload && p->payload.which_variant == SubPacket_position_tag) { - if (!myNodeInfo.has_gps) { + if (!gps.isConnected) { DEBUG_MSG("Stripping time %u from position send\n", p->payload.variant.position.time); p->payload.variant.position.time = 0; } else diff --git a/src/configuration.h b/src/configuration.h index 00b04fcf5..a0bbdbe97 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -39,18 +39,9 @@ along with this program. If not, see . // Configuration // ----------------------------------------------------------------------------- -// Select which board is being used. If the outside build environment has sent a choice, just use that -#if !defined(T_BEAM_V10) && !defined(HELTEC_LORA32) -#define T_BEAM_V10 // AKA Rev1 (second board released) -// #define HELTEC_LORA32 - -#define HW_VERSION_US // We encode the hardware freq range in the hw version string, so sw update can eventually install the - // correct build -#endif - // If we are using the JTAG port for debugging, some pins must be left free for that (and things like GPS have to be disabled) // we don't support jtag on the ttgo - access to gpio 12 is a PITA -#ifdef HELTEC_LORA32 +#ifdef ARDUINO_HELTEC_WIFI_LORA_32_V2 //#define USE_JTAG #endif @@ -105,9 +96,9 @@ along with this program. If not, see . #define MOSI_GPIO 27 #define NSS_GPIO 18 -#if defined(T_BEAM_V10) +#if defined(ARDUINO_T_Beam) // This string must exactly match the case used in release file names or the android updater won't work -#define HW_VENDOR "TBEAM" +#define HW_VENDOR "tbeam" // #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep @@ -126,27 +117,61 @@ along with this program. If not, see . // Leave undefined to disable our PMU IRQ handler #define PMU_IRQ 35 -#elif defined(HELTEC_LORA32) +#elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V2) // This string must exactly match the case used in release file names or the android updater won't work -#define HW_VENDOR "HELTEC" +#define HW_VENDOR "heltec" -#ifndef USE_JTAG // gpio15 is TDO for JTAG, so no I2C on this board while doing jtag -#define I2C_SDA 4 +#ifndef USE_JTAG // gpio15 is TDO for JTAG, so no I2C on this board while doing jtag +#define I2C_SDA 4 // I2C pins for this board #define I2C_SCL 15 #endif -#define RESET_OLED 16 +#define RESET_OLED 16 // If defined, this pin will be used to reset the display controller #define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost -#define LED_PIN 25 -#define BUTTON_PIN 0 +#define LED_PIN 25 // If defined we will blink this LED +#define BUTTON_PIN 0 // If defined, this will be used for user button presses #ifndef USE_JTAG -#define RESET_GPIO 14 +#define RESET_GPIO 14 // If defined, this pin will be used to reset the LORA radio #endif #define DIO0_GPIO 26 -#define DIO1_GPIO 35 -#define DIO2_GPIO 34 +#define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number +#define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number +#elif defined(ARDUINO_TTGO_LoRa32_V1) +// This string must exactly match the case used in release file names or the android updater won't work +#define HW_VENDOR "ttgo-lora32-v1" + +#define I2C_SDA 4 // I2C pins for this board +#define I2C_SCL 15 + +#define RESET_OLED 16 // If defined, this pin will be used to reset the display controller + +// #define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost +#define LED_PIN 2 // If defined we will blink this LED +#define BUTTON_PIN 0 // If defined, this will be used for user button presses + +#define RESET_GPIO 23 // If defined, this pin will be used to reset the LORA radio +#define DIO0_GPIO 26 // IRQ line for the LORA radio +#define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number +#define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number +#elif defined(ARDUINO_TTGO_LoRa32_V2) +// This string must exactly match the case used in release file names or the android updater won't work +#define HW_VENDOR "ttgo-lora32-v2" + +#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 + +#define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost +#define LED_PIN 2 // If defined we will blink this LED +#define BUTTON_PIN 0 // If defined, this will be used for user button presses + +#define RESET_GPIO 23 // If defined, this pin will be used to reset the LORA radio +#define DIO0_GPIO 26 // IRQ line for the LORA radio +#define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number +#define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number #endif // ----------------------------------------------------------------------------- diff --git a/src/main.cpp b/src/main.cpp index 8196fb558..f1965fbac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,7 +39,7 @@ #include #include -#ifdef T_BEAM_V10 +#ifdef ARDUINO_T_Beam #include "axp20x.h" AXP20X_Class axp; bool pmu_irq = false; @@ -81,7 +81,7 @@ void scanI2Cdevice(void) ssd1306_found = true; DEBUG_MSG("ssd1306 display found\n"); } -#ifdef T_BEAM_V10 +#ifdef ARDUINO_T_Beam if (addr == AXP192_SLAVE_ADDRESS) { axp192_found = true; DEBUG_MSG("axp192 PMU found\n"); @@ -97,7 +97,7 @@ void scanI2Cdevice(void) DEBUG_MSG("done\n"); } -#ifdef T_BEAM_V10 +#ifdef ARDUINO_T_Beam /// Reads power status to powerStatus singleton. // // TODO(girts): move this and other axp stuff to power.h/power.cpp. @@ -110,7 +110,7 @@ void readPowerStatus() powerStatus.usb = axp.isVBUSPlug(); powerStatus.charging = axp.isChargeing(); } -#endif // T_BEAM_V10 +#endif // ARDUINO_T_Beam /** * Init the power manager chip @@ -123,7 +123,7 @@ void readPowerStatus() */ void axp192Init() { -#ifdef T_BEAM_V10 +#ifdef ARDUINO_T_Beam if (axp192_found) { if (!axp.begin(Wire, AXP192_SLAVE_ADDRESS)) { DEBUG_MSG("AXP192 Begin PASS\n"); @@ -173,13 +173,15 @@ void axp192Init() axp.debugCharging(); #ifdef PMU_IRQ - pinMode(PMU_IRQ, INPUT_PULLUP); + pinMode(PMU_IRQ, INPUT); attachInterrupt( - PMU_IRQ, [] { pmu_irq = true; }, RISING); + PMU_IRQ, [] { pmu_irq = true; }, FALLING); axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1); - axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ, + axp.enableIRQ(AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ | AXP202_CHARGING_FINISHED_IRQ | AXP202_CHARGING_IRQ | + AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_PEK_SHORTPRESS_IRQ, 1); + axp.clearIRQ(); #endif readPowerStatus(); @@ -355,23 +357,37 @@ void loop() // for debug printing // service.radio.rf95.canSleep(); -#ifdef T_BEAM_V10 - if (axp192_found) { #ifdef PMU_IRQ - if (pmu_irq) { - pmu_irq = false; - axp.readIRQ(); + if (pmu_irq) { + pmu_irq = false; + axp.readIRQ(); - DEBUG_MSG("pmu irq!\n"); + DEBUG_MSG("pmu irq!\n"); - readPowerStatus(); - - axp.clearIRQ(); + if (axp.isChargingIRQ()) { + DEBUG_MSG("Battery start charging\n"); + } + if (axp.isChargingDoneIRQ()) { + DEBUG_MSG("Battery fully charged\n"); + } + if (axp.isVbusRemoveIRQ()) { + DEBUG_MSG("USB unplugged\n"); + } + if (axp.isVbusPlugInIRQ()) { + DEBUG_MSG("USB plugged In\n"); + } + if (axp.isBattPlugInIRQ()) { + DEBUG_MSG("Battery inserted\n"); + } + if (axp.isBattRemoveIRQ()) { + DEBUG_MSG("Battery removed\n"); + } + if (axp.isPEKShortPressIRQ()) { + DEBUG_MSG("PEK short button press\n"); } - // FIXME AXP192 interrupt is not firing, remove this temporary polling of battery state readPowerStatus(); -#endif // PMU_IRQ + axp.clearIRQ(); } #endif // T_BEAM_V10 diff --git a/src/sleep.cpp b/src/sleep.cpp index f69ab5ce8..9894e6299 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -14,7 +14,7 @@ #include #include -#ifdef T_BEAM_V10 +#ifdef ARDUINO_T_Beam #include "axp20x.h" extern AXP20X_Class axp; #endif @@ -48,7 +48,7 @@ void setLed(bool ledOn) digitalWrite(LED_PIN, ledOn); #endif -#ifdef T_BEAM_V10 +#ifdef ARDUINO_T_Beam if (axp192_found) { // blink the axp led axp.setChgLEDMode(ledOn ? AXP20X_LED_LOW_LEVEL : AXP20X_LED_OFF); @@ -60,7 +60,7 @@ void setGPSPower(bool on) { DEBUG_MSG("Setting GPS power=%d\n", on); -#ifdef T_BEAM_V10 +#ifdef ARDUINO_T_Beam if (axp192_found) axp.setPowerOutPut(AXP192_LDO3, on ? AXP202_ON : AXP202_OFF); // GPS main power #endif @@ -124,7 +124,7 @@ void doDeepSleep(uint64_t msecToWake) setLed(false); -#ifdef T_BEAM_V10 +#ifdef ARDUINO_T_Beam if (axp192_found) { // No need to turn this off if the power draw in sleep mode really is just 0.2uA and turning it off would // leave floating input for the IRQ line @@ -155,17 +155,11 @@ void doDeepSleep(uint64_t msecToWake) static const uint8_t rtcGpios[] = {/* 0, */ 2, /* 4, */ #ifndef USE_JTAG - 12, - 13, - /* 14, */ /* 15, */ + 12, 13, + /* 14, */ /* 15, */ #endif /* 25, */ 26, /* 27, */ - 32, - 33, - 34, - 35, - 36, - 37, + 32, 33, 34, 35, 36, 37, /* 38, */ 39}; for (int i = 0; i < sizeof(rtcGpios); i++) @@ -222,7 +216,8 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r gpio_wakeup_enable((gpio_num_t)DIO0_GPIO, GPIO_INTR_HIGH_LEVEL); // RF95 interrupt, active high #ifdef PMU_IRQ // FIXME, disable wake due to PMU because it seems to fire all the time? - // gpio_wakeup_enable((gpio_num_t)PMU_IRQ, GPIO_INTR_HIGH_LEVEL); // pmu irq + if (axp192_found) + gpio_wakeup_enable((gpio_num_t)PMU_IRQ, GPIO_INTR_LOW_LEVEL); // pmu irq #endif assert(esp_sleep_enable_gpio_wakeup() == ESP_OK); assert(esp_sleep_enable_timer_wakeup(sleepUsec) == ESP_OK);