From c0403a72322c47810d867ccc5b17aa9b405c9c81 Mon Sep 17 00:00:00 2001 From: faragher Date: Mon, 21 Oct 2024 20:15:19 -0500 Subject: [PATCH] Preliminary GPS control/build support --- Framing.h | 3 +++ Makefile | 15 ++++++++++++--- Power.h | 19 +++++++++++++------ RNode_Firmware.ino | 25 +++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/Framing.h b/Framing.h index efa4b31..79a5b38 100644 --- a/Framing.h +++ b/Framing.h @@ -77,6 +77,9 @@ #define CMD_RESET 0x55 #define CMD_RESET_BYTE 0xF8 + #define CMD_GPS_CMD 0xA0 + #define CMD_GPS_RATE 0xA1 + #define DETECT_REQ 0x73 #define DETECT_RESP 0x46 diff --git a/Makefile b/Makefile index 0d0fb51..dceb08d 100644 --- a/Makefile +++ b/Makefile @@ -130,15 +130,15 @@ firmware-rak4631: arduino-cli compile --log --fqbn rakwireless:nrf52:WisCoreRAK4631Board -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x51\"" upload: - arduino-cli upload -p /dev/ttyUSB0 --fqbn unsignedio:avr:rnode + arduino-cli upload -p /dev/ttyACM0 --fqbn unsignedio:avr:rnode upload-mega2560: arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:mega upload-tbeam: - arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:t-beam + arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:t-beam @sleep 1 - rnodeconf /dev/ttyUSB0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.t-beam/RNode_Firmware.ino.bin) + rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.t-beam/RNode_Firmware.ino.bin) @sleep 3 python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin @@ -252,6 +252,15 @@ release-tbeam: check_bt_buffers zip --junk-paths ./Release/rnode_firmware_tbeam.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_tbeam.boot_app0 build/rnode_firmware_tbeam.bin build/rnode_firmware_tbeam.bootloader build/rnode_firmware_tbeam.partitions rm -r build +release-tbeam_GPS: check_bt_buffers + arduino-cli compile --fqbn esp32:esp32:t-beam -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\" \"-DENABLE_GPS\"" + cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_tbeam_GPS.boot_app0 + cp build/esp32.esp32.t-beam/RNode_Firmware.ino.bin build/rnode_firmware_tbeam_GPS.bin + cp build/esp32.esp32.t-beam/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_tbeam_GPS.bootloader + cp build/esp32.esp32.t-beam/RNode_Firmware.ino.partitions.bin build/rnode_firmware_tbeam_GPS.partitions + zip --junk-paths ./Release/rnode_firmware_tbeam_GPS.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_tbeam_GPS.boot_app0 build/rnode_firmware_tbeam_GPS.bin build/rnode_firmware_tbeam_GPS.bootloader build/rnode_firmware_tbeam_GPS.partitions + rm -r build + release-tbeam_sx1262: check_bt_buffers arduino-cli compile --fqbn esp32:esp32:t-beam -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\" \"-DMODEM=0x03\"" cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_tbeam_sx1262.boot_app0 diff --git a/Power.h b/Power.h index 1d1dfb8..124d7f2 100644 --- a/Power.h +++ b/Power.h @@ -344,7 +344,10 @@ bool init_pmu() { PMU->enablePowerOutput(XPOWERS_LDO2); // Turn on GPS - //PMU->enablePowerOutput(XPOWERS_LDO3); + #if defined(ENABLE_GPS) + PMU->enablePowerOutput(XPOWERS_LDO3); + PMU->enablePowerOutput(XPOWERS_VBACKUP); // RTC/GPS battery charging + #endif // protected oled power source PMU->setProtectedChannel(XPOWERS_DCDC1); @@ -385,7 +388,7 @@ bool init_pmu() { // Set the power of LoRa and GPS module to 3.3V // LoRa PMU->setPowerChannelVoltage(XPOWERS_ALDO2, 3300); - // GPS + // GPS Voltage PMU->setPowerChannelVoltage(XPOWERS_ALDO3, 3300); PMU->setPowerChannelVoltage(XPOWERS_VBACKUP, 3300); @@ -398,11 +401,15 @@ bool init_pmu() { // LoRa VDD PMU->enablePowerOutput(XPOWERS_ALDO2); - // GNSS VDD - //PMU->enablePowerOutput(XPOWERS_ALDO3); + // GPS/GNSS VDD + #if defined(ENABLE_GPS) + PMU->enablePowerOutput(XPOWERS_ALDO3); + #endif - // GNSS RTC PowerVDD - //PMU->enablePowerOutput(XPOWERS_VBACKUP); + // GNSS RTC Power - Enables charging onboard battery + #if defined(ENABLE_GPS) + PMU->enablePowerOutput(XPOWERS_VBACKUP); + #endif } PMU->enableSystemVoltageMeasure(); diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index 57a7f2f..aba530f 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -41,6 +41,10 @@ volatile bool serial_buffering = false; #include "Console.h" #endif +#if defined(ENABLE_GPS) + #include "GPS.h" +#endif + #if PLATFORM == PLATFORM_ESP32 || PLATFORM == PLATFORM_NRF52 #define MODEM_QUEUE_SIZE 4 typedef struct { @@ -228,6 +232,10 @@ void setup() { kiss_indicate_reset(); } #endif + + #if defined(ENABLE_GPS) + GPS_init(); + #endif // Validate board health, EEPROM and config validate_status(); @@ -1054,6 +1062,17 @@ void serialCallback(uint8_t sbyte) { } } #endif + } else if (command == CMD_GPS_CMD) { + #if defined(ENABLE_GPS) + GPS_handler(sbyte); + #endif + } else if (command == CMD_GPS_RATE) { + #if defined(ENABLE_GPS) + if(frame_len < CMD_L) cmdbuf[frame_len++] = sbyte; + if(frame_len == 2){ + GPS_poling(cmdbuf[0],int(cmdbuf[1])); + } + #endif } else if (command == CMD_DISP_INT) { #if HAS_DISPLAY if (sbyte == FESC) { @@ -1475,6 +1494,12 @@ void loop() { #if HAS_INPUT input_read(); #endif + + #if defined(ENABLE_GPS) + if(hw_ready){ + GPS_process(); + } + #endif if (memory_low) { #if PLATFORM == PLATFORM_ESP32