From 40836c59d35d989fe00ac12ef774df736a36c6e4 Mon Sep 17 00:00:00 2001 From: Youssef Date: Wed, 25 Jan 2023 01:26:31 +0100 Subject: [PATCH 25/46] Added VC-TCXO calibration option. --- libairspyhf/src/airspyhf.c | 51 +++++++++++++++++++++++++---- libairspyhf/src/airspyhf.h | 6 ++-- libairspyhf/src/airspyhf_commands.h | 5 +-- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/libairspyhf/src/airspyhf.c b/libairspyhf/src/airspyhf.c index 49ebf1b..47e6a70 100644 --- a/libairspyhf/src/airspyhf.c +++ b/libairspyhf/src/airspyhf.c @@ -102,6 +102,7 @@ typedef struct airspyhf_device volatile double freq_delta_hz; volatile double freq_shift; volatile int32_t calibration_ppb; + volatile int32_t calibration_vctcxo; volatile float optimal_point; uint8_t enable_dsp; uint8_t is_low_if; @@ -127,6 +128,7 @@ typedef struct calibration_record { uint32_t magic_number; int32_t calibration_ppb; + int32_t calibration_vctcxo; } calibration_record_t; static const uint16_t airspyhf_usb_vid = 0x03EB; @@ -1012,15 +1014,18 @@ static int airspyhf_open_init(airspyhf_device_t** device, uint64_t serial_number if (record.magic_number == CALIBRATION_MAGIC) { lib_device->calibration_ppb = record.calibration_ppb; + airspyhf_set_vctcxo_calibration(lib_device, record.calibration_vctcxo); } else { lib_device->calibration_ppb = 0; + lib_device->calibration_vctcxo = 0; } } else { lib_device->calibration_ppb = 0; + lib_device->calibration_vctcxo = 0; } lib_device->iq_balancer = iq_balancer_create(INITIAL_PHASE, INITIAL_AMPLITUDE); @@ -1405,11 +1410,51 @@ int ADDCALL airspyhf_get_calibration(airspyhf_device_t* device, int32_t* ppb) return AIRSPYHF_ERROR; } +int ADDCALL airspyhf_set_calibration(airspyhf_device_t* device, int32_t ppb) +{ + device->calibration_ppb = ppb; + return airspyhf_set_freq_double(device, device->freq_hz); +} + +int ADDCALL airspyhf_get_vctcxo_calibration(airspyhf_device_t* device, uint16_t* vc) +{ + if (vc) + { + *vc = device->calibration_vctcxo; + return AIRSPYHF_SUCCESS; + } + + return AIRSPYHF_ERROR; +} + +int ADDCALL airspyhf_set_vctcxo_calibration(airspyhf_device_t* device, uint16_t vc) +{ + int result; + device->calibration_vctcxo = vc; + + result = libusb_control_transfer( + device->usb_device, + LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, + AIRSPYHF_SET_VCTCXO_CALIBRATION, + vc, + 0, + NULL, + 0, + 0); + + if (result < 0) + { + return AIRSPYHF_ERROR; + } + return AIRSPYHF_SUCCESS; +} + int ADDCALL airspyhf_flash_calibration(airspyhf_device_t* device) { calibration_record_t record; record.magic_number = CALIBRATION_MAGIC; record.calibration_ppb = device->calibration_ppb; + record.calibration_vctcxo = device->calibration_vctcxo; if (airspyhf_is_streaming(device)) { @@ -1424,12 +1469,6 @@ int ADDCALL airspyhf_flash_calibration(airspyhf_device_t* device) return AIRSPYHF_SUCCESS; } -int ADDCALL airspyhf_set_calibration(airspyhf_device_t* device, int32_t ppb) -{ - device->calibration_ppb = ppb; - return airspyhf_set_freq_double(device, device->freq_hz); -} - int ADDCALL airspyhf_set_optimal_iq_correction_point(airspyhf_device_t* device, float w) { device->optimal_point = w; diff --git a/libairspyhf/src/airspyhf.h b/libairspyhf/src/airspyhf.h index 5fd5d95..1f5088a 100644 --- a/libairspyhf/src/airspyhf.h +++ b/libairspyhf/src/airspyhf.h @@ -28,10 +28,10 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI #include -#define AIRSPYHF_VERSION "1.7.0" +#define AIRSPYHF_VERSION "1.7.1" #define AIRSPYHF_VER_MAJOR 1 #define AIRSPYHF_VER_MINOR 7 -#define AIRSPYHF_VER_REVISION 0 +#define AIRSPYHF_VER_REVISION 1 #define AIRSPYHF_ENDPOINT_IN (1) @@ -138,6 +138,8 @@ extern ADDAPI int ADDCALL airspyhf_get_samplerates(airspyhf_device_t* device, ui 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); extern ADDAPI int ADDCALL airspyhf_set_calibration(airspyhf_device_t* device, int32_t ppb); +extern ADDAPI int ADDCALL airspyhf_get_vctcxo_calibration(airspyhf_device_t* device, uint16_t* vc); +extern ADDAPI int ADDCALL airspyhf_set_vctcxo_calibration(airspyhf_device_t* device, uint16_t vc); extern ADDAPI int ADDCALL airspyhf_set_optimal_iq_correction_point(airspyhf_device_t* device, float w); extern ADDAPI int ADDCALL airspyhf_iq_balancer_configure(airspyhf_device_t* device, int buffers_to_skip, int fft_integration, int fft_overlap, int correlation_integration); extern ADDAPI int ADDCALL airspyhf_flash_calibration(airspyhf_device_t* device); /* streaming needs to be stopped */ diff --git a/libairspyhf/src/airspyhf_commands.h b/libairspyhf/src/airspyhf_commands.h index 70f0187..177ff19 100644 --- a/libairspyhf/src/airspyhf_commands.h +++ b/libairspyhf/src/airspyhf_commands.h @@ -32,7 +32,7 @@ typedef enum RECEIVER_MODE_ON = 1 } receiver_mode_t; -#define AIRSPYHF_CMD_MAX (16) +#define AIRSPYHF_CMD_MAX (17) typedef enum { AIRSPYHF_INVALID = 0, @@ -51,7 +51,8 @@ typedef enum AIRSPYHF_SET_HF_LNA = 13, AIRSPYHF_GET_SAMPLERATE_ARCHITECTURES = 14, AIRSPYHF_GET_FILTER_GAIN = 15, - AIRSPYHF_GET_FREQ_DELTA = AIRSPYHF_CMD_MAX, + AIRSPYHF_GET_FREQ_DELTA = 16, + AIRSPYHF_SET_VCTCXO_CALIBRATION = AIRSPYHF_CMD_MAX, } airspyhf_vendor_request; #endif -- 2.47.3