From aed0bc1d17177b313c59a760eb0da34fa933b307 Mon Sep 17 00:00:00 2001 From: wvarty Date: Mon, 31 Jan 2022 19:56:11 +1000 Subject: [PATCH 1/8] First cut at the backpack for the HDZero VRX --- lib/MSP/msptypes.h | 16 +++++++ platformio.ini | 1 + src/Vrx_main.cpp | 21 +++++++++- src/hdzero.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++ src/hdzero.h | 28 +++++++++++++ src/rapidfire.cpp | 2 - targets/common.ini | 18 +++++--- targets/hdzero.ini | 14 +++++++ 8 files changed, 193 insertions(+), 9 deletions(-) create mode 100644 src/hdzero.cpp create mode 100644 src/hdzero.h create mode 100644 targets/hdzero.ini diff --git a/lib/MSP/msptypes.h b/lib/MSP/msptypes.h index a45d617..5a59156 100644 --- a/lib/MSP/msptypes.h +++ b/lib/MSP/msptypes.h @@ -20,3 +20,19 @@ // CRSF encapsulated msp defines #define ENCAPSULATED_MSP_PAYLOAD_SIZE 4 #define ENCAPSULATED_MSP_FRAME_LEN 8 + +// ELRS backpack protocol opcodes +// See: https://docs.google.com/document/d/1u3c7OTiO4sFL2snI-hIo-uRSLfgBK4h16UrbA08Pd6U/edit#heading=h.1xw7en7jmvsj +#define MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX 0x0300 +#define MSP_ELRS_BACKPACK_SET_CHANNEL_INDEX 0x0301 +#define MSP_ELRS_BACKPACK_GET_FREQUENCY 0x0302 +#define MSP_ELRS_BACKPACK_SET_FREQUENCY 0x0303 +#define MSP_ELRS_BACKPACK_GET_RECORDING_STATE 0x0304 +#define MSP_ELRS_BACKPACK_SET_RECORDING_STATE 0x0305 +#define MSP_ELRS_BACKPACK_GET_VRX_MODE 0x0306 +#define MSP_ELRS_BACKPACK_SET_VRX_MODE 0x0307 +#define MSP_ELRS_BACKPACK_GET_RSSI 0x0308 +#define MSP_ELRS_BACKPACK_GET_BATTERY_VOLTAGE 0x0309 +#define MSP_ELRS_BACKPACK_GET_FIRMWARE 0x030A +#define MSP_ELRS_BACKPACK_SET_BUZZER 0x030B +#define MSP_ELRS_BACKPACK_SET_OSD_ELEMENT 0x030C diff --git a/platformio.ini b/platformio.ini index fc4674b..061ab74 100644 --- a/platformio.ini +++ b/platformio.ini @@ -16,3 +16,4 @@ extra_configs = targets/fusion.ini targets/dupletx_tx.ini targets/radiomaster_tx.ini + targets/hdzero.ini \ No newline at end of file diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp index 850bbcd..325cab0 100644 --- a/src/Vrx_main.cpp +++ b/src/Vrx_main.cpp @@ -22,6 +22,8 @@ #include "steadyview.h" #elif defined(FUSION_BACKPACK) #include "fusion.h" +#elif defined(HDZERO_BACKPACK) + #include "hdzero.h" #endif /////////// DEFINES /////////// @@ -45,6 +47,7 @@ uint8_t cachedIndex = 0; bool sendChangesToVrx = false; bool gotInitialPacket = false; uint32_t lastSentRequest = 0; +uint32_t bootDelay = 0; device_t *ui_devices[] = { #ifdef PIN_LED @@ -71,6 +74,8 @@ VrxBackpackConfig config; SteadyView vrxModule; #elif defined(FUSION_BACKPACK) Fusion vrxModule; +#elif defined(HDZERO_BACKPACK) + HDZero vrxModule; #endif /////////// FUNCTION DEFS /////////// @@ -282,8 +287,20 @@ RF_PRE_INIT() void setup() { + #ifdef HDZERO_BACKPACK + // HDZero VRX sometimes does not seem to boot if the UART is initialised at power-on + // Give it a few seconds to boot up before continuing + bootDelay = 6000; + #elif RAPIDFIRE_BACKPACK + bootDelay = 2000; + #endif + + delay(bootDelay); + #ifdef FUSION_BACKPACK Serial.begin(500000); // fusion uses 500k baud between the ESP8266 and the STM32 + #elif HDZERO_BACKPACK + Serial.begin(115200); // hdzero uses 115k baud between the ESP8285 and the STM32 #else Serial.begin(460800); #endif @@ -364,7 +381,7 @@ void loop() } // spam out a bunch of requests for the desired band/channel for the first 5s - if (!gotInitialPacket && now < 5000 && now - lastSentRequest > 1000 && connectionState != binding) + if (!gotInitialPacket && now - bootDelay < 5000 && now - lastSentRequest > 1000 && connectionState != binding) { DBGLN("RequestVTXPacket..."); RequestVTXPacket(); @@ -377,4 +394,4 @@ void loop() DBGLN("resetBootCounter..."); resetBootCounter(); } -} \ No newline at end of file +} diff --git a/src/hdzero.cpp b/src/hdzero.cpp new file mode 100644 index 0000000..ea08aaf --- /dev/null +++ b/src/hdzero.cpp @@ -0,0 +1,102 @@ +#include "hdzero.h" +#include "logging.h" +#include + +void +HDZero::Init() +{ + DBGLN("HDZero backpack init complete"); +} + +void +HDZero::SendIndexCmd(uint8_t index) +{ + uint8_t retries = 5; + while (GetChannelIndex() != index && retries > 0) + { + SetChannelIndex(index); + retries--; + } +} + +void +HDZero::SetChannelIndex(uint8_t index) +{ + mspPacket_t packet; + packet.reset(); + packet.makeCommand(); + packet.function = MSP_ELRS_BACKPACK_SET_CHANNEL_INDEX; + packet.addByte(index); // payload + + SendMSPViaSerial(&packet); +} + +uint8_t +HDZero::GetChannelIndex() +{ + MSP msp; + uint8_t index = CHANNEL_INDEX_UNKNOWN; + + mspPacket_t packet; + packet.reset(); + packet.makeCommand(); + packet.function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX; + + SendMSPViaSerial(&packet); + + // Wait for a response back from the VRX + + uint32_t timeout = 500; // wait up to milliseconds for a response, then bail out + uint32_t requestTime = millis(); + + while(millis() - requestTime < timeout) + { + while (Serial.available()) + { + uint8_t data = Serial.read(); + if (msp.processReceivedByte(data)) + { + DBGLN("Received an MSP packet from VRX"); + mspPacket_t *receivedPacket = msp.getReceivedPacket(); + if (receivedPacket->function == MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX) + { + DBGLN("Received channel index"); + index = receivedPacket->readByte(); + } + msp.markPacketReceived(); + return index; + } + } + } + DBGLN("Exceeded timeout while waiting for channel index response"); + return CHANNEL_INDEX_UNKNOWN; +} + +void +HDZero::SendMSPViaSerial(mspPacket_t *packet) +{ + MSP msp; + + uint8_t packetSize = msp.getTotalPacketSize(packet); + uint8_t buf[packetSize]; + + uint8_t result = msp.convertToByteArray(packet, buf); + + if (!result) + { + DBGLN("Packet could not be converted to array, bail out"); + return; + } + + for (uint8_t i = 0; i < packetSize; ++i) + { + Serial.write(buf[i]); + } + + // Leaving this in as its useful to debug + // for (uint8_t i = 0; i < pos; ++i) + // { + // Serial.print("0x"); Serial.print(buf[i], HEX); Serial.print(", "); + // } + // Serial.println(""); +} \ No newline at end of file diff --git a/src/hdzero.h b/src/hdzero.h new file mode 100644 index 0000000..2fd4053 --- /dev/null +++ b/src/hdzero.h @@ -0,0 +1,28 @@ +#pragma once + +#include "msp.h" +#include "msptypes.h" +#include + +#define CHANNEL_INDEX_UNKNOWN 255 + +const uint16_t frequencyTable[48] = { + 5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725, // A + 5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866, // B + 5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945, // E + 5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880, // F + 5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917, // R + 5333, 5373, 5413, 5453, 5493, 5533, 5573, 5613 // L +}; + +class HDZero +{ +public: + void Init(); + void SendIndexCmd(uint8_t index); + uint8_t GetChannelIndex(); + void SetChannelIndex(uint8_t index); + +private: + void SendMSPViaSerial(mspPacket_t *packet); +}; diff --git a/src/rapidfire.cpp b/src/rapidfire.cpp index 54f1b0e..25695dc 100644 --- a/src/rapidfire.cpp +++ b/src/rapidfire.cpp @@ -8,8 +8,6 @@ Rapidfire::Init() pinMode(PIN_MOSI, INPUT); pinMode(PIN_CLK, INPUT); pinMode(PIN_CS, INPUT); - - delay(2000); // wait for rapidfire to boot DBGLN("Rapid Fire init"); } diff --git a/targets/common.ini b/targets/common.ini index fc5b705..f3df041 100644 --- a/targets/common.ini +++ b/targets/common.ini @@ -38,7 +38,7 @@ build_flags = build_flags = ${common_env_data.build_flags} -D TARGET_TX_BACKPACK -src_filter = ${common_env_data.src_filter} - - - - - +src_filter = ${common_env_data.src_filter} - - - - - - # ------------------------- COMMON RAPIDFIRE-BACKPACK DEFINITIONS ----------------- [rapidfire_vrx_backpack_common] @@ -46,7 +46,7 @@ build_flags = ${common_env_data.build_flags} -D TARGET_VRX_BACKPACK -D RAPIDFIRE_BACKPACK -src_filter = ${common_env_data.src_filter} - - - - +src_filter = ${common_env_data.src_filter} - - - - - # ------------------------- COMMON RX5808-BACKPACK DEFINITIONS ----------------- [rx5808_vrx_backpack_common] @@ -54,7 +54,7 @@ build_flags = ${common_env_data.build_flags} -D TARGET_VRX_BACKPACK -D RX5808_BACKPACK -src_filter = ${common_env_data.src_filter} - - - - +src_filter = ${common_env_data.src_filter} - - - - - # ------------------------- COMMON STEADYVIEW-BACKPACK DEFINITIONS ----------------- [steadyview_vrx_backpack_common] @@ -62,7 +62,7 @@ build_flags = ${common_env_data.build_flags} -D TARGET_VRX_BACKPACK -D STEADYVIEW_BACKPACK -src_filter = ${common_env_data.src_filter} - - - - +src_filter = ${common_env_data.src_filter} - - - - - # ------------------------- COMMON FUSION-BACKPACK DEFINITIONS ----------------- [fusion_vrx_backpack_common] @@ -70,4 +70,12 @@ build_flags = ${common_env_data.build_flags} -D TARGET_VRX_BACKPACK -D FUSION_BACKPACK -src_filter = ${common_env_data.src_filter} - - - - +src_filter = ${common_env_data.src_filter} - - - - - + +# ------------------------- COMMON HDZERO-BACKPACK DEFINITIONS ----------------- +[hdzero_vrx_backpack_common] +build_flags = + ${common_env_data.build_flags} + -D TARGET_VRX_BACKPACK + -D HDZERO_BACKPACK +src_filter = ${common_env_data.src_filter} - - - - - diff --git a/targets/hdzero.ini b/targets/hdzero.ini new file mode 100644 index 0000000..af0f7e9 --- /dev/null +++ b/targets/hdzero.ini @@ -0,0 +1,14 @@ +# ******************************** +# VRX backpack targets +# ******************************** + +[env:HDZero_Backpack_via_UART] +extends = env_common_esp8285, hdzero_vrx_backpack_common +monitor_speed = 115200 +build_flags = + ${env_common_esp8285.build_flags} + ${hdzero_vrx_backpack_common.build_flags} + -D PIN_LED=16 + +[env:HDZero_Backpack_via_WIFI] +extends = env:HDZero_Backpack_via_UART From e471e669b6c9ba93029c499f9e175bf7730c5be6 Mon Sep 17 00:00:00 2001 From: wvarty Date: Mon, 31 Jan 2022 21:27:37 +1000 Subject: [PATCH 2/8] Removed freq table, and change target name to be more specific --- src/hdzero.h | 9 --------- targets/hdzero.ini | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/hdzero.h b/src/hdzero.h index 2fd4053..8d4e05b 100644 --- a/src/hdzero.h +++ b/src/hdzero.h @@ -6,15 +6,6 @@ #define CHANNEL_INDEX_UNKNOWN 255 -const uint16_t frequencyTable[48] = { - 5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725, // A - 5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866, // B - 5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945, // E - 5740, 5760, 5780, 5800, 5820, 5840, 5860, 5880, // F - 5658, 5695, 5732, 5769, 5806, 5843, 5880, 5917, // R - 5333, 5373, 5413, 5453, 5493, 5533, 5573, 5613 // L -}; - class HDZero { public: diff --git a/targets/hdzero.ini b/targets/hdzero.ini index af0f7e9..d6c2907 100644 --- a/targets/hdzero.ini +++ b/targets/hdzero.ini @@ -2,7 +2,7 @@ # VRX backpack targets # ******************************** -[env:HDZero_Backpack_via_UART] +[env:HDZero_RX5.1_Backpack_via_UART] extends = env_common_esp8285, hdzero_vrx_backpack_common monitor_speed = 115200 build_flags = @@ -10,5 +10,5 @@ build_flags = ${hdzero_vrx_backpack_common.build_flags} -D PIN_LED=16 -[env:HDZero_Backpack_via_WIFI] +[env:HDZero_RX5.1_Backpack_via_WIFI] extends = env:HDZero_Backpack_via_UART From 28dc63402f4afbc9bca641b832cdbfe56090c075 Mon Sep 17 00:00:00 2001 From: wvarty Date: Mon, 14 Feb 2022 09:50:47 +1000 Subject: [PATCH 3/8] WIP - broken --- lib/MSP/msp.cpp | 27 ++++++++++ lib/MSP/msp.h | 1 + lib/WIFI/UpdateWrapper.h | 23 ++++++-- lib/WIFI/devWIFI.cpp | 60 +++++++++++++-------- lib/WIFI/stmUpdateClass.h | 2 + src/Tx_main.cpp | 2 + src/Vrx_main.cpp | 111 +++++++++++++++++++++++++------------- src/fusion.h | 3 ++ src/hdzero.cpp | 105 +++++++++++++++++------------------- src/hdzero.h | 13 ++++- src/rapidfire.h | 2 + targets/common.ini | 14 ++++- targets/hdzero.ini | 10 +++- 13 files changed, 250 insertions(+), 123 deletions(-) diff --git a/lib/MSP/msp.cpp b/lib/MSP/msp.cpp index 8896d2b..aae34c5 100644 --- a/lib/MSP/msp.cpp +++ b/lib/MSP/msp.cpp @@ -284,3 +284,30 @@ MSP::getTotalPacketSize(mspPacket_t* packet) return totalSize; } + +bool +MSP::awaitPacket(mspPacket_t* packet, Stream* port, uint32_t timeoutMillis) +{ + uint32_t requestTime = millis(); + + sendPacket(packet, port); + + // wait up to milliseconds for a response, then bail out + while(millis() - requestTime < timeoutMillis) + { + while (port->available()) + { + uint8_t data = Serial.read(); + if (processReceivedByte(data)) + { + if (m_packet.function == packet->function) + { + packet = &m_packet; + } + return true; + } + } + } + DBGLN("MSP::awaitPacket Exceeded timeout while waiting for packet"); + return false; +} diff --git a/lib/MSP/msp.h b/lib/MSP/msp.h index 48ff907..7637ee8 100644 --- a/lib/MSP/msp.h +++ b/lib/MSP/msp.h @@ -94,6 +94,7 @@ class MSP bool sendPacket(mspPacket_t* packet, Stream* port); uint8_t convertToByteArray(mspPacket_t* packet, uint8_t* byteArray); uint8_t getTotalPacketSize(mspPacket_t* packet); + bool awaitPacket(mspPacket_t* packet, Stream* port, uint32_t timeoutMillis); private: mspState_e m_inputState; diff --git a/lib/WIFI/UpdateWrapper.h b/lib/WIFI/UpdateWrapper.h index f32c306..0a3bb66 100644 --- a/lib/WIFI/UpdateWrapper.h +++ b/lib/WIFI/UpdateWrapper.h @@ -1,3 +1,5 @@ +#pragma once + #ifdef NAMIMNO_TX_BACKPACK #include "stmUpdateClass.h" #endif @@ -8,14 +10,21 @@ class UpdateWrapper { _stmMode = stmMode; } +#ifdef PLATFORM_ESP8266 bool begin(size_t size) { _running = true; -#ifdef NAMIMNO_TX_BACKPACK + return Update.begin(size, U_FLASH); + } +#elif NAMIMNO_TX_BACKPACK + bool begin(size_t size) { if (_stmMode) return STMUpdate.begin(0); // we don't know the size! -#endif - return Update.begin(size, U_FLASH); } +#elif PLATFORM_ESP32 + bool begin() { + return Update.begin(); + } +#endif size_t write(uint8_t *data, size_t len) { #ifdef NAMIMNO_TX_BACKPACK @@ -51,13 +60,21 @@ class UpdateWrapper { } void runAsync(bool async) { + #ifdef PLATFORM_ESP8266 if (!_stmMode) Update.runAsync(async); + #endif } bool isRunning() { return _running; } +#ifdef PLATFORM_ESP32 + void abort() { + if (!_stmMode) Update.abort(); + } +#endif + private: bool _stmMode = false; bool _running = false; diff --git a/lib/WIFI/devWIFI.cpp b/lib/WIFI/devWIFI.cpp index 44539c3..8909b15 100644 --- a/lib/WIFI/devWIFI.cpp +++ b/lib/WIFI/devWIFI.cpp @@ -3,16 +3,22 @@ #if defined(PLATFORM_ESP8266) || defined(PLATFORM_ESP32) +#if defined(PLATFORM_ESP32) +#include +#include +#include +#else #include #include #define wifi_mode_t WiFiMode_t - +#endif #include -#include #include #include +#include + #include "common.h" #include "logging.h" #include "options.h" @@ -345,7 +351,7 @@ static void WebUploadDataHandler(AsyncWebServerRequest *request, const String& f updater.printError(Serial); } #else - if (!updater->begin()) { //start with max available size + if (!updater.begin()) { //start with max available size updater.printError(Serial); } #endif @@ -390,7 +396,7 @@ static void WebUploadForceUpdateHandler(AsyncWebServerRequest *request) { WebUploadResponseHandler(request); } else { #if defined(PLATFORM_ESP32) - updater->abort(); + updater.abort(); #endif request->send(200, "application/json", "{\"status\": \"ok\", \"msg\": \"Update cancelled\"}"); } @@ -452,26 +458,34 @@ static void startMDNS() String instance = String(myHostname) + "_" + WiFi.macAddress(); instance.replace(":", ""); - // We have to do it differently on ESP8266 as setInstanceName has the side-effect of chainging the hostname! - MDNS.setInstanceName(myHostname); - MDNSResponder::hMDNSService service = MDNS.addService(instance.c_str(), "http", "tcp", 80); - MDNS.addServiceTxt(service, "vendor", "elrs"); - MDNS.addServiceTxt(service, "target", (const char *)&target_name[4]); - MDNS.addServiceTxt(service, "version", VERSION); - MDNS.addServiceTxt(service, "options", String(FPSTR(compile_options)).c_str()); - #if defined(TARGET_VRX_BACKPACK) - MDNS.addServiceTxt(service, "type", "vrx"); - #elif defined(TARGET_TX_BACKPACK) - MDNS.addServiceTxt(service, "type", "txbp"); + #ifdef PLATFORM_ESP8266 + // We have to do it differently on ESP8266 as setInstanceName has the side-effect of chainging the hostname! + MDNS.setInstanceName(myHostname); + MDNSResponder::hMDNSService service = MDNS.addService(instance.c_str(), "http", "tcp", 80); + MDNS.addServiceTxt(service, "vendor", "elrs"); + MDNS.addServiceTxt(service, "target", (const char *)&target_name[4]); + MDNS.addServiceTxt(service, "version", VERSION); + MDNS.addServiceTxt(service, "options", String(FPSTR(compile_options)).c_str()); + MDNS.addServiceTxt(service, "type", "rx"); + // If the probe result fails because there is another device on the network with the same name + // use our unique instance name as the hostname. A better way to do this would be to use + // MDNSResponder::indexDomain and change wifi_hostname as well. + MDNS.setHostProbeResultCallback([instance](const char* p_pcDomainName, bool p_bProbeResult) { + if (!p_bProbeResult) { + WiFi.hostname(instance); + MDNS.setInstanceName(instance); + } + }); + #else + MDNS.setInstanceName(instance); + MDNS.addService("http", "tcp", 80); + MDNS.addServiceTxt("http", "tcp", "vendor", "elrs"); + MDNS.addServiceTxt("http", "tcp", "target", (const char *)&target_name[4]); + // MDNS.addServiceTxt("http", "tcp", "device", device_name); + MDNS.addServiceTxt("http", "tcp", "version", VERSION); + MDNS.addServiceTxt("http", "tcp", "options", String(FPSTR(compile_options)).c_str()); + MDNS.addServiceTxt("http", "tcp", "type", "tx"); #endif - // If the probe result fails because there is another device on the network with the same name - // use our unique instance name as the hostname. - MDNS.setHostProbeResultCallback([instance](const char* p_pcDomainName, bool p_bProbeResult) { - if (!p_bProbeResult) { - WiFi.hostname(instance); - MDNS.setInstanceName(instance); - } - }); } static void startServices() diff --git a/lib/WIFI/stmUpdateClass.h b/lib/WIFI/stmUpdateClass.h index c0bf304..6d58b33 100644 --- a/lib/WIFI/stmUpdateClass.h +++ b/lib/WIFI/stmUpdateClass.h @@ -1,3 +1,5 @@ +#pragma once + #include #include diff --git a/src/Tx_main.cpp b/src/Tx_main.cpp index acdfd5e..9f69b0d 100644 --- a/src/Tx_main.cpp +++ b/src/Tx_main.cpp @@ -135,6 +135,8 @@ void ProcessMSPPacketFromTX(mspPacket_t *packet) RebootIntoWifi(); break; default: + // transparently forward MSP packets via espnow to any subscribers + sendMSPViaEspnow(packet); break; } } diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp index 325cab0..6216239 100644 --- a/src/Vrx_main.cpp +++ b/src/Vrx_main.cpp @@ -1,7 +1,15 @@ #include -#include -#include +#if defined(PLATFORM_ESP8266) + #include + #include +#elif defined(PLATFORM_ESP32) + #include + #include + #include +#endif + + #include "msp.h" #include "msptypes.h" #include "logging.h" @@ -32,6 +40,14 @@ #define NO_BINDING_TIMEOUT 120000 #define BINDING_LED_PAUSE 1000 +#if !defined(VRX_BOOT_DELAY) + #define VRX_BOOT_DELAY 0 +#endif + +#if !defined(VRX_UART_BAUD) + #define VRX_UART_BAUD 460800 +#endif + /////////// GLOBALS /////////// #ifdef MY_UID @@ -75,7 +91,7 @@ VrxBackpackConfig config; #elif defined(FUSION_BACKPACK) Fusion vrxModule; #elif defined(HDZERO_BACKPACK) - HDZero vrxModule; + HDZero vrxModule(&Serial); #endif /////////// FUNCTION DEFS /////////// @@ -83,6 +99,7 @@ VrxBackpackConfig config; void ProcessMSPPacket(mspPacket_t *packet); void sendMSPViaEspnow(mspPacket_t *packet); void resetBootCounter(); +void SetupEspNow(); ///////////////////////////////////// @@ -96,7 +113,11 @@ void RebootIntoWifi() } // espnow on-receive callback +#if defined(PLATFORM_ESP8266) void OnDataRecv(uint8_t * mac_addr, uint8_t *data, uint8_t data_len) +#elif defined(PLATFORM_ESP32) +void OnDataRecv(const uint8_t * mac_addr, const uint8_t *data, int data_len) +#endif { DBGLN("ESP NOW DATA:"); for(int i = 0; i < data_len; i++) @@ -173,11 +194,50 @@ void ProcessMSPPacket(mspPacket_t *packet) DBGLN("Processing MSP_ELRS_SET_VRX_BACKPACK_WIFI_MODE..."); RebootIntoWifi(); break; + case MSP_ELRS_BACKPACK_SET_RECORDING_STATE: + DBGLN("Processing MSP_ELRS_BACKPACK_SET_RECORDING_STATE..."); + #if defined(HDZERO_BACKPACK) + { + uint8_t state = packet->readByte(); + uint16_t delay = packet->readByte(); + delay = (delay << 8) | packet->readByte(); + vrxModule.SetRecordingState(state, delay); + } + #endif + break; default: + DBGLN("Unknown command from ESPNOW"); break; } } +void SetupEspNow() +{ + if (esp_now_init() != 0) + { + DBGLN("Error initializing ESP-NOW"); + turnOffLED(); + ESP.restart(); + } + + #if defined(PLATFORM_ESP8266) + esp_now_set_self_role(ESP_NOW_ROLE_COMBO); + esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 1, NULL, 0); + #elif defined(PLATFORM_ESP32) + esp_now_peer_info_t peerInfo; + memcpy(peerInfo.peer_addr, broadcastAddress, 6); + peerInfo.channel = 0; + peerInfo.encrypt = false; + if (esp_now_add_peer(&peerInfo) != ESP_OK) + { + DBGLN("ESP-NOW failed to add peer"); + return; + } + #endif + + esp_now_register_recv_cb(OnDataRecv); +} + void SetSoftMACAddress() { DBGLN("EEPROM MAC = "); @@ -199,7 +259,11 @@ void SetSoftMACAddress() WiFi.disconnect(); // Soft-set the MAC address to the passphrase UID for binding - wifi_set_macaddr(STATION_IF, broadcastAddress); + #if defined(PLATFORM_ESP8266) + wifi_set_macaddr(STATION_IF, broadcastAddress); + #elif defined(PLATFORM_ESP32) + esp_wifi_set_mac(WIFI_IF_STA, broadcastAddress); + #endif } void RequestVTXPacket() @@ -287,24 +351,10 @@ RF_PRE_INIT() void setup() { - #ifdef HDZERO_BACKPACK - // HDZero VRX sometimes does not seem to boot if the UART is initialised at power-on - // Give it a few seconds to boot up before continuing - bootDelay = 6000; - #elif RAPIDFIRE_BACKPACK - bootDelay = 2000; - #endif - - delay(bootDelay); - - #ifdef FUSION_BACKPACK - Serial.begin(500000); // fusion uses 500k baud between the ESP8266 and the STM32 - #elif HDZERO_BACKPACK - Serial.begin(115200); // hdzero uses 115k baud between the ESP8285 and the STM32 - #else - Serial.begin(460800); - #endif - + // VRX module class needs to be initialised first, as it calls delay() + // for some modules that require a boot delay before being operational + vrxModule.Init(); + Serial.begin(VRX_UART_BAUD); eeprom.Begin(); config.SetStorageProvider(&eeprom); config.Load(); @@ -325,21 +375,8 @@ void setup() else { checkIfInBindingMode(); - SetSoftMACAddress(); - - if (esp_now_init() != 0) - { - DBGLN("Error initializing ESP-NOW"); - turnOffLED(); - ESP.restart(); - } - - esp_now_set_self_role(ESP_NOW_ROLE_COMBO); - esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 1, NULL, 0); - esp_now_register_recv_cb(OnDataRecv); - - vrxModule.Init(); + SetupEspNow(); } devicesStart(); @@ -381,7 +418,7 @@ void loop() } // spam out a bunch of requests for the desired band/channel for the first 5s - if (!gotInitialPacket && now - bootDelay < 5000 && now - lastSentRequest > 1000 && connectionState != binding) + if (!gotInitialPacket && now - VRX_BOOT_DELAY < 5000 && now - lastSentRequest > 1000 && connectionState != binding) { DBGLN("RequestVTXPacket..."); RequestVTXPacket(); diff --git a/src/fusion.h b/src/fusion.h index 083c7cb..1ab9927 100644 --- a/src/fusion.h +++ b/src/fusion.h @@ -2,6 +2,9 @@ #include +#define VRX_BOOT_DELAY 1000 +#define VRX_UART_BAUD 500000 // fusion uses 500k baud between the ESP8266 and the STM32 + const uint16_t frequencyTable[48] = { 5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725, // A 5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866, // B diff --git a/src/hdzero.cpp b/src/hdzero.cpp index ea08aaf..46bf6ea 100644 --- a/src/hdzero.cpp +++ b/src/hdzero.cpp @@ -2,16 +2,21 @@ #include "logging.h" #include +HDZero::HDZero(Stream *port) +{ + m_port = port; +} + void HDZero::Init() { - DBGLN("HDZero backpack init complete"); + DBGLN("HDZero module: init complete"); } void HDZero::SendIndexCmd(uint8_t index) { - uint8_t retries = 5; + uint8_t retries = 3; while (GetChannelIndex() != index && retries > 0) { SetChannelIndex(index); @@ -19,84 +24,72 @@ HDZero::SendIndexCmd(uint8_t index) } } +uint8_t +HDZero::GetChannelIndex() +{ + MSP msp; + mspPacket_t packet; + packet.reset(); + packet.makeCommand(); + packet.function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX; + + // Send request, then wait for a response back from the VRX + bool receivedResponse = msp.awaitPacket(&packet, m_port, 500); + + if (receivedResponse) + { + return packet.readByte(); + } + + DBGLN("HDZero module: Exceeded timeout while waiting for channel index response"); + return CHANNEL_INDEX_UNKNOWN; +} + void HDZero::SetChannelIndex(uint8_t index) { + MSP msp; mspPacket_t packet; packet.reset(); packet.makeCommand(); packet.function = MSP_ELRS_BACKPACK_SET_CHANNEL_INDEX; packet.addByte(index); // payload - SendMSPViaSerial(&packet); + msp.sendPacket(&packet, m_port); } uint8_t -HDZero::GetChannelIndex() +HDZero::GetRecordingState() { MSP msp; - uint8_t index = CHANNEL_INDEX_UNKNOWN; - mspPacket_t packet; packet.reset(); packet.makeCommand(); - packet.function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX; - - SendMSPViaSerial(&packet); + packet.function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE; - // Wait for a response back from the VRX + // Send request, then wait for a response back from the VRX + bool receivedResponse = msp.awaitPacket(&packet, m_port, 500); - uint32_t timeout = 500; // wait up to milliseconds for a response, then bail out - uint32_t requestTime = millis(); - - while(millis() - requestTime < timeout) + if (receivedResponse) { - while (Serial.available()) - { - uint8_t data = Serial.read(); - if (msp.processReceivedByte(data)) - { - DBGLN("Received an MSP packet from VRX"); - mspPacket_t *receivedPacket = msp.getReceivedPacket(); - if (receivedPacket->function == MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX) - { - DBGLN("Received channel index"); - index = receivedPacket->readByte(); - } - msp.markPacketReceived(); - return index; - } - } + return packet.readByte(); } - DBGLN("Exceeded timeout while waiting for channel index response"); - return CHANNEL_INDEX_UNKNOWN; + + DBGLN("HDZero module: Exceeded timeout while waiting for recording state response"); + return VRX_DVR_RECORDING_UNKNOWN; } void -HDZero::SendMSPViaSerial(mspPacket_t *packet) +HDZero::SetRecordingState(uint8_t recordingState, uint16_t delay) { MSP msp; - - uint8_t packetSize = msp.getTotalPacketSize(packet); - uint8_t buf[packetSize]; - - uint8_t result = msp.convertToByteArray(packet, buf); - - if (!result) - { - DBGLN("Packet could not be converted to array, bail out"); - return; - } - - for (uint8_t i = 0; i < packetSize; ++i) - { - Serial.write(buf[i]); - } + mspPacket_t packet; + packet.reset(); + packet.makeCommand(); + packet.function = MSP_ELRS_BACKPACK_SET_RECORDING_STATE; + packet.addByte(recordingState); + packet.addByte(delay >> 8); // delay byte 1 + packet.addByte(delay & 0xFF); // delay byte 2 - // Leaving this in as its useful to debug - // for (uint8_t i = 0; i < pos; ++i) - // { - // Serial.print("0x"); Serial.print(buf[i], HEX); Serial.print(", "); - // } - // Serial.println(""); -} \ No newline at end of file + msp.sendPacket(&packet, m_port); +} diff --git a/src/hdzero.h b/src/hdzero.h index 8d4e05b..0aaea98 100644 --- a/src/hdzero.h +++ b/src/hdzero.h @@ -4,16 +4,25 @@ #include "msptypes.h" #include -#define CHANNEL_INDEX_UNKNOWN 255 +#define VRX_BOOT_DELAY 6000 +#define VRX_UART_BAUD 115200 // hdzero uses 115k baud between the ESP8285 and the STM32 + +#define CHANNEL_INDEX_UNKNOWN 255 +#define VRX_DVR_RECORDING_ACTIVE 1 +#define VRX_DVR_RECORDING_INACTIVE 0 +#define VRX_DVR_RECORDING_UNKNOWN 255 class HDZero { public: + HDZero(Stream *port); void Init(); void SendIndexCmd(uint8_t index); uint8_t GetChannelIndex(); void SetChannelIndex(uint8_t index); + uint8_t GetRecordingState(); + void SetRecordingState(uint8_t recordingState, uint16_t delay); private: - void SendMSPViaSerial(mspPacket_t *packet); + Stream *m_port; }; diff --git a/src/rapidfire.h b/src/rapidfire.h index 2674bb5..40c9079 100644 --- a/src/rapidfire.h +++ b/src/rapidfire.h @@ -2,6 +2,8 @@ #include +#define VRX_BOOT_DELAY 2000 + #define BIT_BANG_FREQ 1000 #define SPAM_COUNT 3 diff --git a/targets/common.ini b/targets/common.ini index f3df041..4f79383 100644 --- a/targets/common.ini +++ b/targets/common.ini @@ -33,6 +33,18 @@ board_build.f_cpu = 160000000L build_flags = -D PLATFORM_ESP8266=1 +# ------------------------- COMMON ESP32 DEFINITIONS ----------------- +[env_common_esp32] +platform = espressif32@3.4.0 +board = esp32dev +; board_build.partitions = min_spiffs.csv +upload_speed = 460800 +monitor_speed = 460800 +upload_resetmethod = nodemcu +board_build.f_cpu = 240000000L +build_flags = + -D PLATFORM_ESP32=1 + # ------------------------- COMMON TX-BACKPACK DEFINITIONS ----------------- [tx_backpack_common] build_flags = @@ -78,4 +90,4 @@ build_flags = ${common_env_data.build_flags} -D TARGET_VRX_BACKPACK -D HDZERO_BACKPACK -src_filter = ${common_env_data.src_filter} - - - - - +src_filter = ${common_env_data.src_filter} - - - - - - diff --git a/targets/hdzero.ini b/targets/hdzero.ini index d6c2907..c64c7f2 100644 --- a/targets/hdzero.ini +++ b/targets/hdzero.ini @@ -2,7 +2,7 @@ # VRX backpack targets # ******************************** -[env:HDZero_RX5.1_Backpack_via_UART] +[env:HDZero_RX5.1_ESP8285_Backpack_via_UART] extends = env_common_esp8285, hdzero_vrx_backpack_common monitor_speed = 115200 build_flags = @@ -12,3 +12,11 @@ build_flags = [env:HDZero_RX5.1_Backpack_via_WIFI] extends = env:HDZero_Backpack_via_UART + +[env:HDZero_RX5.1_ESP32_Backpack_via_UART] +extends = env_common_esp32, hdzero_vrx_backpack_common +monitor_speed = 115200 +build_flags = + ${env_common_esp32.build_flags} + ${hdzero_vrx_backpack_common.build_flags} + -D PIN_LED=4 From 6ca7ea60c69e6288ec6e1605d259384201f962ad Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Mon, 14 Feb 2022 13:04:24 +1300 Subject: [PATCH 4/8] Fix ESP32 compiling --- lib/{WIFI => STM32UPDATE}/stmUpdateClass.cpp | 0 lib/{WIFI => STM32UPDATE}/stmUpdateClass.h | 0 targets/hdzero.ini | 1 + 3 files changed, 1 insertion(+) rename lib/{WIFI => STM32UPDATE}/stmUpdateClass.cpp (100%) rename lib/{WIFI => STM32UPDATE}/stmUpdateClass.h (100%) diff --git a/lib/WIFI/stmUpdateClass.cpp b/lib/STM32UPDATE/stmUpdateClass.cpp similarity index 100% rename from lib/WIFI/stmUpdateClass.cpp rename to lib/STM32UPDATE/stmUpdateClass.cpp diff --git a/lib/WIFI/stmUpdateClass.h b/lib/STM32UPDATE/stmUpdateClass.h similarity index 100% rename from lib/WIFI/stmUpdateClass.h rename to lib/STM32UPDATE/stmUpdateClass.h diff --git a/targets/hdzero.ini b/targets/hdzero.ini index c64c7f2..5bd9924 100644 --- a/targets/hdzero.ini +++ b/targets/hdzero.ini @@ -20,3 +20,4 @@ build_flags = ${env_common_esp32.build_flags} ${hdzero_vrx_backpack_common.build_flags} -D PIN_LED=4 +lib_ignore = STM32UPDATE \ No newline at end of file From bff26dd43c44dc10043b0170bab98abdd565de29 Mon Sep 17 00:00:00 2001 From: wvarty Date: Mon, 14 Feb 2022 22:06:55 +1000 Subject: [PATCH 5/8] Working on ESP32 --- lib/MSP/msp.cpp | 6 +----- lib/WIFI/devWIFI.cpp | 13 ++++++++++--- src/Vrx_main.cpp | 8 +++++++- src/fusion.cpp | 1 + src/hdzero.cpp | 28 +++++++++++++++------------- src/hdzero.h | 3 ++- src/rapidfire.cpp | 2 ++ targets/common.ini | 2 +- targets/hdzero.ini | 9 ++++++--- 9 files changed, 45 insertions(+), 27 deletions(-) diff --git a/lib/MSP/msp.cpp b/lib/MSP/msp.cpp index aae34c5..9fe5960 100644 --- a/lib/MSP/msp.cpp +++ b/lib/MSP/msp.cpp @@ -297,13 +297,9 @@ MSP::awaitPacket(mspPacket_t* packet, Stream* port, uint32_t timeoutMillis) { while (port->available()) { - uint8_t data = Serial.read(); + uint8_t data = port->read(); if (processReceivedByte(data)) { - if (m_packet.function == packet->function) - { - packet = &m_packet; - } return true; } } diff --git a/lib/WIFI/devWIFI.cpp b/lib/WIFI/devWIFI.cpp index 8909b15..e283136 100644 --- a/lib/WIFI/devWIFI.cpp +++ b/lib/WIFI/devWIFI.cpp @@ -466,7 +466,11 @@ static void startMDNS() MDNS.addServiceTxt(service, "target", (const char *)&target_name[4]); MDNS.addServiceTxt(service, "version", VERSION); MDNS.addServiceTxt(service, "options", String(FPSTR(compile_options)).c_str()); - MDNS.addServiceTxt(service, "type", "rx"); + #if defined(TARGET_VRX_BACKPACK) + MDNS.addServiceTxt(service, "type", "vrx"); + #elif defined(TARGET_TX_BACKPACK) + MDNS.addServiceTxt(service, "type", "txbp"); + #endif // If the probe result fails because there is another device on the network with the same name // use our unique instance name as the hostname. A better way to do this would be to use // MDNSResponder::indexDomain and change wifi_hostname as well. @@ -481,10 +485,13 @@ static void startMDNS() MDNS.addService("http", "tcp", 80); MDNS.addServiceTxt("http", "tcp", "vendor", "elrs"); MDNS.addServiceTxt("http", "tcp", "target", (const char *)&target_name[4]); - // MDNS.addServiceTxt("http", "tcp", "device", device_name); MDNS.addServiceTxt("http", "tcp", "version", VERSION); MDNS.addServiceTxt("http", "tcp", "options", String(FPSTR(compile_options)).c_str()); - MDNS.addServiceTxt("http", "tcp", "type", "tx"); + #if defined(TARGET_VRX_BACKPACK) + MDNS.addServiceTxt("http", "tcp", "type", "vrx"); + #elif defined(TARGET_TX_BACKPACK) + MDNS.addServiceTxt("http", "tcp", "type", "txbp"); + #endif #endif } diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp index 6216239..1f39cd8 100644 --- a/src/Vrx_main.cpp +++ b/src/Vrx_main.cpp @@ -75,6 +75,13 @@ device_t *ui_devices[] = { &WIFI_device, }; +#if defined(PLATFORM_ESP32) +// This seems to need to be global, as per this page, +// otherwise we get errors about invalid peer: +// https://rntlab.com/question/espnow-peer-interface-is-invalid/ +esp_now_peer_info_t peerInfo; +#endif + /////////// CLASS OBJECTS /////////// MSP msp; @@ -224,7 +231,6 @@ void SetupEspNow() esp_now_set_self_role(ESP_NOW_ROLE_COMBO); esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 1, NULL, 0); #elif defined(PLATFORM_ESP32) - esp_now_peer_info_t peerInfo; memcpy(peerInfo.peer_addr, broadcastAddress, 6); peerInfo.channel = 0; peerInfo.encrypt = false; diff --git a/src/fusion.cpp b/src/fusion.cpp index f0886a4..cc3d251 100644 --- a/src/fusion.cpp +++ b/src/fusion.cpp @@ -9,6 +9,7 @@ GENERIC_CRC8 crsf_crc(CRSF_CRC_POLY); void Fusion::Init() { + delay(VRX_BOOT_DELAY); DBGLN("Fusion backpack init complete"); } diff --git a/src/hdzero.cpp b/src/hdzero.cpp index 46bf6ea..9c3dfb9 100644 --- a/src/hdzero.cpp +++ b/src/hdzero.cpp @@ -10,7 +10,7 @@ HDZero::HDZero(Stream *port) void HDZero::Init() { - DBGLN("HDZero module: init complete"); + delay(VRX_BOOT_DELAY); } void @@ -28,17 +28,18 @@ uint8_t HDZero::GetChannelIndex() { MSP msp; - mspPacket_t packet; - packet.reset(); - packet.makeCommand(); - packet.function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX; + mspPacket_t* packet = new mspPacket_t; + packet->reset(); + packet->makeCommand(); + packet->function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX; // Send request, then wait for a response back from the VRX - bool receivedResponse = msp.awaitPacket(&packet, m_port, 500); + bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT); if (receivedResponse) { - return packet.readByte(); + packet = msp.getReceivedPacket(); + return packet->readByte(); } DBGLN("HDZero module: Exceeded timeout while waiting for channel index response"); @@ -62,17 +63,18 @@ uint8_t HDZero::GetRecordingState() { MSP msp; - mspPacket_t packet; - packet.reset(); - packet.makeCommand(); - packet.function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE; + mspPacket_t* packet = new mspPacket_t; + packet->reset(); + packet->makeCommand(); + packet->function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE; // Send request, then wait for a response back from the VRX - bool receivedResponse = msp.awaitPacket(&packet, m_port, 500); + bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT); if (receivedResponse) { - return packet.readByte(); + packet = msp.getReceivedPacket(); + return packet->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE; } DBGLN("HDZero module: Exceeded timeout while waiting for recording state response"); diff --git a/src/hdzero.h b/src/hdzero.h index 0aaea98..2fc8a8b 100644 --- a/src/hdzero.h +++ b/src/hdzero.h @@ -4,7 +4,8 @@ #include "msptypes.h" #include -#define VRX_BOOT_DELAY 6000 +#define VRX_BOOT_DELAY 7000 +#define VRX_RESPONSE_TIMEOUT 500 #define VRX_UART_BAUD 115200 // hdzero uses 115k baud between the ESP8285 and the STM32 #define CHANNEL_INDEX_UNKNOWN 255 diff --git a/src/rapidfire.cpp b/src/rapidfire.cpp index 25695dc..a9aa65f 100644 --- a/src/rapidfire.cpp +++ b/src/rapidfire.cpp @@ -9,6 +9,8 @@ Rapidfire::Init() pinMode(PIN_CLK, INPUT); pinMode(PIN_CS, INPUT); + delay(VRX_BOOT_DELAY); + DBGLN("Rapid Fire init"); } diff --git a/targets/common.ini b/targets/common.ini index 4f79383..90d8d87 100644 --- a/targets/common.ini +++ b/targets/common.ini @@ -28,7 +28,7 @@ build_flags = board = esp12e board_build.ldscript = eagle.flash.1m144.ld upload_speed = 921600 -monitor_speed = 460800 +monitor_speed = 115200 board_build.f_cpu = 160000000L build_flags = -D PLATFORM_ESP8266=1 diff --git a/targets/hdzero.ini b/targets/hdzero.ini index 5bd9924..323665c 100644 --- a/targets/hdzero.ini +++ b/targets/hdzero.ini @@ -10,8 +10,8 @@ build_flags = ${hdzero_vrx_backpack_common.build_flags} -D PIN_LED=16 -[env:HDZero_RX5.1_Backpack_via_WIFI] -extends = env:HDZero_Backpack_via_UART +[env:HDZero_RX5.1_ESP8285_Backpack_via_WIFI] +extends = env:HDZero_RX5.1_ESP8285_Backpack_via_UART [env:HDZero_RX5.1_ESP32_Backpack_via_UART] extends = env_common_esp32, hdzero_vrx_backpack_common @@ -20,4 +20,7 @@ build_flags = ${env_common_esp32.build_flags} ${hdzero_vrx_backpack_common.build_flags} -D PIN_LED=4 -lib_ignore = STM32UPDATE \ No newline at end of file +lib_ignore = STM32UPDATE + +[env:HDZero_RX5.1_ESP32_Backpack_via_WIFI] +extends = env:HDZero_RX5.1_ESP32_Backpack_via_UART From f0829ccacbd3a234fa6bc7dee47eb106a763f6b8 Mon Sep 17 00:00:00 2001 From: wvarty Date: Wed, 23 Feb 2022 18:14:31 +1000 Subject: [PATCH 6/8] Fix delay parsing --- src/Vrx_main.cpp | 5 +++-- src/hdzero.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp index 1f39cd8..0f6e71a 100644 --- a/src/Vrx_main.cpp +++ b/src/Vrx_main.cpp @@ -206,8 +206,9 @@ void ProcessMSPPacket(mspPacket_t *packet) #if defined(HDZERO_BACKPACK) { uint8_t state = packet->readByte(); - uint16_t delay = packet->readByte(); - delay = (delay << 8) | packet->readByte(); + uint8_t lowByte = packet->readByte(); + uint8_t highByte = packet->readByte(); + uint16_t delay = lowByte | highByte << 8; vrxModule.SetRecordingState(state, delay); } #endif diff --git a/src/hdzero.cpp b/src/hdzero.cpp index 9c3dfb9..44510db 100644 --- a/src/hdzero.cpp +++ b/src/hdzero.cpp @@ -84,14 +84,16 @@ HDZero::GetRecordingState() void HDZero::SetRecordingState(uint8_t recordingState, uint16_t delay) { + DBGLN("SetRecordingState = %d delay = %d", recordingState, delay); + MSP msp; mspPacket_t packet; packet.reset(); packet.makeCommand(); packet.function = MSP_ELRS_BACKPACK_SET_RECORDING_STATE; packet.addByte(recordingState); - packet.addByte(delay >> 8); // delay byte 1 - packet.addByte(delay & 0xFF); // delay byte 2 + packet.addByte(delay & 0xFF); // delay byte 1 + packet.addByte(delay >> 8); // delay byte 2 msp.sendPacket(&packet, m_port); } From 9f43b7a8b4a2759cacc2151a24d8deb5c252d270 Mon Sep 17 00:00:00 2001 From: wvarty Date: Wed, 23 Feb 2022 23:05:45 +1000 Subject: [PATCH 7/8] Remove unused variable --- src/Vrx_main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp index 0f6e71a..b6eadb8 100644 --- a/src/Vrx_main.cpp +++ b/src/Vrx_main.cpp @@ -63,7 +63,6 @@ uint8_t cachedIndex = 0; bool sendChangesToVrx = false; bool gotInitialPacket = false; uint32_t lastSentRequest = 0; -uint32_t bootDelay = 0; device_t *ui_devices[] = { #ifdef PIN_LED From 907f7e768e06235b57d4738e189079fbfd64579e Mon Sep 17 00:00:00 2001 From: wvarty Date: Wed, 23 Feb 2022 23:39:32 +1000 Subject: [PATCH 8/8] Workaround for boot delay affecting 3x reboot to enter wifi / binding --- src/Vrx_main.cpp | 15 +++++++++++---- targets/common.ini | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Vrx_main.cpp b/src/Vrx_main.cpp index b6eadb8..3e3e43d 100644 --- a/src/Vrx_main.cpp +++ b/src/Vrx_main.cpp @@ -357,10 +357,12 @@ RF_PRE_INIT() void setup() { - // VRX module class needs to be initialised first, as it calls delay() - // for some modules that require a boot delay before being operational - vrxModule.Init(); - Serial.begin(VRX_UART_BAUD); + #if !defined(HDZERO_BACKPACK) + // Serial.begin() seems to prevent the HDZ VRX from booting + // If we're not on HDZ, init serial early for debug msgs + // Otherwise, delay it till the end of setup + Serial.begin(VRX_UART_BAUD); + #endif eeprom.Begin(); config.SetStorageProvider(&eeprom); config.Load(); @@ -390,6 +392,11 @@ void setup() { connectionState = running; } + + vrxModule.Init(); + #if defined(HDZERO_BACKPACK) + Serial.begin(VRX_UART_BAUD); + #endif DBGLN("Setup completed"); } diff --git a/targets/common.ini b/targets/common.ini index 90d8d87..4f79383 100644 --- a/targets/common.ini +++ b/targets/common.ini @@ -28,7 +28,7 @@ build_flags = board = esp12e board_build.ldscript = eagle.flash.1m144.ld upload_speed = 921600 -monitor_speed = 115200 +monitor_speed = 460800 board_build.f_cpu = 160000000L build_flags = -D PLATFORM_ESP8266=1