Communicate Rx available antenna mode to the Tx (#3039)
[ExpressLRS.git] / src / lib / SerialUpdate / devSerialUpdate.cpp
blob53781ebc4a08b274250625c8b494eba32bbedc14
1 #include "targets.h"
3 #if defined(PLATFORM_ESP32) && defined(TARGET_RX)
4 #include "devSerialUpdate.h"
5 #include "common.h"
6 #include "hwTimer.h"
7 #include "POWERMGNT.h"
8 #include "devVTXSPI.h"
9 #include "devMSPVTX.h"
11 extern void start_esp_upload();
12 extern void stub_handle_rx_byte(char byte);
14 static bool running = false;
16 static bool initialize()
18 running = true;
19 return true;
22 static int event()
24 if (connectionState == serialUpdate && running)
26 running = false;
27 hwTimer::stop();
28 disableVTxSpi();
29 disableMspVtx();
30 POWERMGNT::setPower(MinPower);
31 Radio.End();
32 return DURATION_IMMEDIATELY;
34 return DURATION_NEVER;
37 static int timeout()
39 start_esp_upload();
40 while (true)
42 uint8_t buf[64];
43 int count = Serial.read(buf, sizeof(buf));
44 for (int i=0 ; i<count ; i++)
46 stub_handle_rx_byte(buf[i]);
51 device_t SerialUpdate_device = {
52 .initialize = initialize,
53 .start = nullptr,
54 .event = event,
55 .timeout = timeout,
56 .subscribe = EVENT_CONNECTION_CHANGED
58 #endif