From ef1c626ee8f1f3d24b4db3e685128963c63a01d8 Mon Sep 17 00:00:00 2001
From: prog <youssef@airspy.com>
Date: Tue, 17 Apr 2018 15:21:11 +0200
Subject: [PATCH 1/7] Set the device's minimum LO frequency to 300 kHz;

Set the coarse tuning to +/- 500 Hz accuracy when the DSP is disabled;
Added comments to some function prototypes;
Removed some unreferenced defines.
---
 libairspyhf/src/airspyhf.c | 18 +++++++++---------
 libairspyhf/src/airspyhf.h |  4 ++--
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libairspyhf/src/airspyhf.c b/libairspyhf/src/airspyhf.c
index 76579c6..626bfdf 100644
--- a/libairspyhf/src/airspyhf.c
+++ b/libairspyhf/src/airspyhf.c
@@ -62,8 +62,7 @@ typedef int bool;
 
 #define CALIBRATION_MAGIC (0xA5CA71B0)
 
-#define ERASE_FLASH_MAGIC0 (0xC0DE)
-#define ERASE_FLASH_MAGIC1 (0xBABE)
+#define DEFAULT_IF_SHIFT (5000)
 
 #define STR_PREFIX_SERIAL_AIRSPYHF_SIZE (12)
 static const char str_prefix_serial_airspyhf[STR_PREFIX_SERIAL_AIRSPYHF_SIZE] =
@@ -1080,15 +1079,14 @@ int ADDCALL airspyhf_stop(airspyhf_device_t* device)
 int ADDCALL airspyhf_set_freq(airspyhf_device_t* device, const uint32_t freq_hz)
 {
 	const int tuning_alignment = 1000;
-	const int if_shift = 5000;
-	const uint32_t lo_low_khz = 200;
+	const uint32_t lo_low_khz = 300;
 
 	int result;
 	uint8_t buf[4];
-	
-	uint32_t adjusted_freq_hz = (uint32_t) ((int64_t) freq_hz * (int64_t) (1000000000LL + device->calibration_ppb) / 1000000000LL);
+	uint32_t if_shift = device->enable_dsp ? DEFAULT_IF_SHIFT : 0;
+	uint32_t adjusted_freq_hz = (uint32_t) ((int64_t) freq_hz * (int64_t)(1000000000LL + device->calibration_ppb) / 1000000000LL);
 	uint32_t freq_khz = MAX(lo_low_khz, (adjusted_freq_hz + if_shift + tuning_alignment / 2) / tuning_alignment);
-	
+
 	if (device->freq_khz != freq_khz)
 	{
 		buf[0] = (uint8_t) ((freq_khz >> 24) & 0xff);
@@ -1377,8 +1375,10 @@ int ADDCALL airspyhf_set_hf_lna(airspyhf_device_t* device, uint8_t flag)
 	return AIRSPYHF_SUCCESS;
 }
 
-int ADDCALL airspyhf_set_lib_dsp(airspyhf_device_t* device, uint8_t flag)
+int ADDCALL airspyhf_set_lib_dsp(airspyhf_device_t* device, const uint8_t flag)
 {
 	device->enable_dsp = flag;
 	return AIRSPYHF_SUCCESS;
-}
\ No newline at end of file
+}
+
+#include "special.c"
diff --git a/libairspyhf/src/airspyhf.h b/libairspyhf/src/airspyhf.h
index 457b004..b68cbec 100644
--- a/libairspyhf/src/airspyhf.h
+++ b/libairspyhf/src/airspyhf.h
@@ -127,7 +127,7 @@ extern ADDAPI int ADDCALL airspyhf_start(airspyhf_device_t* device, airspyhf_sam
 extern ADDAPI int ADDCALL airspyhf_stop(airspyhf_device_t* device);
 extern ADDAPI int ADDCALL airspyhf_is_streaming(airspyhf_device_t* device);
 extern ADDAPI int ADDCALL airspyhf_set_freq(airspyhf_device_t* device, const uint32_t freq_hz);
-extern ADDAPI int ADDCALL airspyhf_set_lib_dsp(airspyhf_device_t* device, const uint8_t flag);
+extern ADDAPI int ADDCALL airspyhf_set_lib_dsp(airspyhf_device_t* device, const uint8_t flag); /* Enables/Disables the IQ Correction, IF shift and Fine Tuning. */
 extern ADDAPI int ADDCALL airspyhf_get_samplerates(airspyhf_device_t* device, uint32_t* buffer, const uint32_t len);
 extern ADDAPI int ADDCALL airspyhf_set_samplerate(airspyhf_device_t* device, uint32_t samplerate);
 extern ADDAPI int ADDCALL airspyhf_get_calibration(airspyhf_device_t* device, int32_t* ppb);
@@ -139,7 +139,7 @@ extern ADDAPI int ADDCALL airspyhf_version_string_read(airspyhf_device_t* device
 extern ADDAPI int ADDCALL airspyhf_set_user_output(airspyhf_device_t* device, airspyhf_user_output_t pin, airspyhf_user_output_state_t value);
 extern ADDAPI int ADDCALL airspyhf_set_hf_agc(airspyhf_device_t* device, uint8_t flag);
 extern ADDAPI int ADDCALL airspyhf_set_hf_agc_threshold(airspyhf_device_t* device, uint8_t flag);
-extern ADDAPI int ADDCALL airspyhf_set_hf_att(airspyhf_device_t* device, uint8_t value);
+extern ADDAPI int ADDCALL airspyhf_set_hf_att(airspyhf_device_t* device, uint8_t value); /* Possible values: 0..8 Range: 0..48 dB Attenuation with 6 dB steps */
 extern ADDAPI int ADDCALL airspyhf_set_hf_lna(airspyhf_device_t* device, uint8_t flag);
 
 #ifdef __cplusplus
-- 
2.11.0

