From a919b84fe97da5d85180f633158d9206e92687d3 Mon Sep 17 00:00:00 2001
From: c vw <dl1ycf@darc.de>
Date: Thu, 19 Mar 2020 11:23:14 +0100
Subject: [PATCH] CW GPIO lines: new default values. Enable 6m band for STEMlab

---
 gpio.c          | 18 ++++++++++++++----
 old_discovery.c |  4 +++-
 receiver.c      |  2 ++
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/gpio.c b/gpio.c
index 653a78f..e37d90a 100644
--- a/gpio.c
+++ b/gpio.c
@@ -124,9 +124,14 @@ int ENABLE_FUNCTION_BUTTON;
 int FUNCTION_BUTTON;
 
 #ifdef LOCALCW
-int CWL_BUTTON=14;
-int CWR_BUTTON=15;
-int SIDETONE_GPIO=8;
+//
+// WiringPi pins #12, 13, 14 are not used
+// by Controller1 and Controller2_V1
+// (and keep #8,9 reserved for I2C extensions)
+//
+int CWL_BUTTON=13;
+int CWR_BUTTON=14;
+int SIDETONE_GPIO=12;
 int ENABLE_GPIO_SIDETONE=0;
 int ENABLE_CW_BUTTONS=1;
 int CW_ACTIVE_LOW=1;
@@ -1310,8 +1315,13 @@ void gpio_restore_state() {
   }
 
   if(controller==CONTROLLER2_V2) {
-    // turn off as clash of use of pin 14 (WPi)
+    //
+    // In Controller2 V2, no 'free' GPIO pins
+    // are available, so one cannot use any of
+    // of these for CW in the standard setup
+    //
     ENABLE_CW_BUTTONS=0;
+    ENABLE_GPIO_SIDETONE=0;
   }
 
 
diff --git a/old_discovery.c b/old_discovery.c
index 9d53a32..c6f1039 100644
--- a/old_discovery.c
+++ b/old_discovery.c
@@ -462,9 +462,11 @@ fprintf(stderr,"discover_receive_thread\n");
 			case DEVICE_STEMLAB:
 			    // This is in principle the same as HERMES but has two ADCs
 			    // (and therefore, can do DIVERSITY).
+			    // There are some problems with the 6m band on the RedPitaya
+			    // but with additional filtering it can be used.
                             strcpy(discovered[devices].name,"STEMlab");
                             discovered[devices].frequency_min=0.0;
-                            discovered[devices].frequency_max=30720000.0;
+                            discovered[devices].frequency_max=61440000.0;
                             break;
                         default:
                             strcpy(discovered[devices].name,"Unknown");
diff --git a/receiver.c b/receiver.c
index 5f9b518..f4a9e22 100644
--- a/receiver.c
+++ b/receiver.c
@@ -1337,6 +1337,7 @@ static void process_rx_buffer(RECEIVER *rx) {
 void full_rx_buffer(RECEIVER *rx) {
   int error;
 
+  g_mutex_lock(&rx->mutex);
   // noise blanker works on original IQ samples
   if(rx->nb) {
      xanbEXT (rx->id, rx->iq_input_buffer, rx->iq_input_buffer);
@@ -1359,6 +1360,7 @@ void full_rx_buffer(RECEIVER *rx) {
 
 //g_print("full_rx_buffer: rx=%d buffer_size=%d samples=%d\n",rx->id,rx->buffer_size,rx->samples);
   process_rx_buffer(rx);
+  g_mutex_unlock(&rx->mutex);
 }
 
 static int rx_buffer_seen=0;
-- 
2.45.2