From 78d273fa3482bd48882f7dccfb09eb31889297f5 Mon Sep 17 00:00:00 2001
From: Andrew Tridgell <tridge@samba.org>
Date: Fri, 4 May 2012 10:39:44 +1000
Subject: [PATCH] Telemetry: make it possible to use UART2 on APM2

building with TELEMETRY_UART2=ENABLED allows you to use the solder
bridge on the APM2 to enable telemetry on UART2. This allows both USB
telemetry and a radio at the same time.
---
 ArduPlane/ArduPlane.pde |  7 ++++++-
 ArduPlane/Makefile      |  3 +++
 ArduPlane/config.h      | 10 ++++++++++
 ArduPlane/planner.pde   |  2 +-
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/ArduPlane/ArduPlane.pde b/ArduPlane/ArduPlane.pde
index fcf4af17b..3f3d7e3b9 100644
--- a/ArduPlane/ArduPlane.pde
+++ b/ArduPlane/ArduPlane.pde
@@ -72,7 +72,12 @@ version 2.1 of the License, or (at your option) any later version.
 //
 FastSerialPort0(Serial);        // FTDI/console
 FastSerialPort1(Serial1);       // GPS port
-FastSerialPort3(Serial3);       // Telemetry port
+#if TELEMETRY_UART2 == ENABLED
+ // solder bridge set to enable UART2 instead of USB MUX
+ FastSerialPort2(Serial3);
+#else
+ FastSerialPort3(Serial3);       // Telemetry port for APM1
+#endif
 
 ////////////////////////////////////////////////////////////////////////////////
 // ISR Registry
diff --git a/ArduPlane/Makefile b/ArduPlane/Makefile
index 8205e702f..97c544342 100644
--- a/ArduPlane/Makefile
+++ b/ArduPlane/Makefile
@@ -21,6 +21,9 @@ heli:
 apm2:
 	make -f Makefile EXTRAFLAGS="-DCONFIG_APM_HARDWARE=APM_HARDWARE_APM2"
 
+apm2-uart2:
+	make -f Makefile EXTRAFLAGS="-DCONFIG_APM_HARDWARE=APM_HARDWARE_APM2 -DTELEMETRY_UART2=ENABLED"
+
 apm2beta:
 	make -f Makefile EXTRAFLAGS="-DCONFIG_APM_HARDWARE=APM_HARDWARE_APM2 -DAPM2_BETA_HARDWARE"
 
diff --git a/ArduPlane/config.h b/ArduPlane/config.h
index 79bbc6947..e387d4bb6 100644
--- a/ArduPlane/config.h
+++ b/ArduPlane/config.h
@@ -81,6 +81,12 @@
 # endif
 #endif
 
+// use this to enable telemetry on UART2. This is used
+// when you have setup the solder bridge on an APM2 to enable UART2
+#ifndef TELEMETRY_UART2
+# define TELEMETRY_UART2 DISABLED
+#endif
+
 //////////////////////////////////////////////////////////////////////////////
 // LED and IO Pins
 //
@@ -105,7 +111,11 @@
 # define SLIDE_SWITCH_PIN (-1)
 # define PUSHBUTTON_PIN   (-1)
 # define CLI_SLIDER_ENABLED DISABLED
+#if TELEMETRY_UART2 == ENABLED
+# define USB_MUX_PIN -1
+#else
 # define USB_MUX_PIN 23
+#endif
 # define BATTERY_PIN_1	  1
 # define CURRENT_PIN_1	  2
 #endif
diff --git a/ArduPlane/planner.pde b/ArduPlane/planner.pde
index 86147133d..1a5d8ee4a 100644
--- a/ArduPlane/planner.pde
+++ b/ArduPlane/planner.pde
@@ -27,7 +27,7 @@ planner_gcs(uint8_t argc, const Menu::arg *argv)
 {
   gcs0.init(&Serial);
 
-#if USB_MUX_PIN > 0
+#if USB_MUX_PIN < 0
   // we don't have gcs3 if we have the USB mux setup
   gcs3.init(&Serial3);
 #endif
-- 
GitLab