diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index 25753dd3..83524804 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -426,22 +426,6 @@ usb_request_status_t usb_vendor_request_read_si5351c( } } -usb_request_status_t usb_vendor_request_set_sample_rate( - usb_endpoint_t* const endpoint, - const usb_transfer_stage_t stage -) { - if( stage == USB_TRANSFER_STAGE_SETUP ) { - const uint32_t sample_rate = (endpoint->setup.index << 16) | endpoint->setup.value; - if( sample_rate_set(sample_rate) ) { - usb_endpoint_schedule_ack(endpoint->in); - return USB_REQUEST_STATUS_OK; - } - return USB_REQUEST_STATUS_STALL; - } else { - return USB_REQUEST_STATUS_OK; - } -} - usb_request_status_t usb_vendor_request_set_baseband_filter_bandwidth( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage @@ -835,7 +819,7 @@ static const usb_request_handler_fn vendor_request_handler[] = { usb_vendor_request_read_max2837, usb_vendor_request_write_si5351c, usb_vendor_request_read_si5351c, - usb_vendor_request_set_sample_rate, + usb_vendor_request_set_sample_rate_frac, usb_vendor_request_set_baseband_filter_bandwidth, usb_vendor_request_write_rffc5071, usb_vendor_request_read_rffc5071, @@ -851,7 +835,6 @@ static const usb_request_handler_fn vendor_request_handler[] = { usb_vendor_request_set_lna_gain, usb_vendor_request_set_vga_gain, usb_vendor_request_set_txvga_gain, - usb_vendor_request_set_sample_rate_frac }; static const uint32_t vendor_request_handler_count = diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 3423c8f0..98de34be 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -591,7 +591,7 @@ int main(int argc, char** argv) { signal(SIGABRT, &sigint_callback_handler); #endif printf("call hackrf_sample_rate_set(%u Hz/%.03f MHz)\n", sample_rate_hz,((float)sample_rate_hz/(float)FREQ_ONE_MHZ)); - result = hackrf_sample_rate_set(device, sample_rate_hz); + result = hackrf_set_sample_rate_manual(device, sample_rate_hz, 1); if( result != HACKRF_SUCCESS ) { printf("hackrf_sample_rate_set() failed: %s (%d)\n", hackrf_error_name(result), result); usage(); @@ -600,7 +600,7 @@ int main(int argc, char** argv) { printf("call hackrf_baseband_filter_bandwidth_set(%d Hz/%.03f MHz)\n", baseband_filter_bw_hz, ((float)baseband_filter_bw_hz/(float)FREQ_ONE_MHZ)); - result = hackrf_baseband_filter_bandwidth_set(device, baseband_filter_bw_hz); + result = hackrf_set_baseband_filter_bandwidth(device, baseband_filter_bw_hz); if( result != HACKRF_SUCCESS ) { printf("hackrf_baseband_filter_bandwidth_set() failed: %s (%d)\n", hackrf_error_name(result), result); usage(); diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 6d08f276..06a3a62f 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -64,7 +64,6 @@ typedef enum { HACKRF_VENDOR_REQUEST_SET_LNA_GAIN = 19, HACKRF_VENDOR_REQUEST_SET_VGA_GAIN = 20, HACKRF_VENDOR_REQUEST_SET_TXVGA_GAIN = 21, - HACKRF_VENDOR_REQUEST_SET_FRACRATE = 22, } hackrf_vendor_request; typedef enum { @@ -473,29 +472,7 @@ int ADDCALL hackrf_si5351c_write(hackrf_device* device, uint16_t register_number } } -int ADDCALL hackrf_sample_rate_set(hackrf_device* device, const uint32_t sampling_rate_hz) -{ - int result; - result = libusb_control_transfer( - device->usb_device, - LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, - HACKRF_VENDOR_REQUEST_SAMPLE_RATE_SET, - sampling_rate_hz & 0xffff, - sampling_rate_hz >> 16, - NULL, - 0, - 0 - ); - - if( result != 0 ) - { - return HACKRF_ERROR_LIBUSB; - } else { - return HACKRF_SUCCESS; - } -} - -int ADDCALL hackrf_baseband_filter_bandwidth_set(hackrf_device* device, const uint32_t bandwidth_hz) +int ADDCALL hackrf_set_baseband_filter_bandwidth(hackrf_device* device, const uint32_t bandwidth_hz) { int result; result = libusb_control_transfer( @@ -769,7 +746,7 @@ typedef struct { } set_fracrate_params_t; -int ADDCALL hackrf_set_fracrate_manual(hackrf_device* device, +int ADDCALL hackrf_set_sample_rate_manual(hackrf_device* device, const uint32_t freq_hz, uint32_t divider) { set_fracrate_params_t set_fracrate_params; @@ -783,7 +760,7 @@ int ADDCALL hackrf_set_fracrate_manual(hackrf_device* device, result = libusb_control_transfer( device->usb_device, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, - HACKRF_VENDOR_REQUEST_SET_FRACRATE, + HACKRF_VENDOR_REQUEST_SAMPLE_RATE_SET, 0, 0, (unsigned char*)&set_fracrate_params, @@ -799,7 +776,7 @@ int ADDCALL hackrf_set_fracrate_manual(hackrf_device* device, } } -int ADDCALL hackrf_set_fracrate(hackrf_device* device, const double freq) +int ADDCALL hackrf_set_sample_rate(hackrf_device* device, const double freq) { const int MAX_N = 32; uint32_t freq_hz, divider; @@ -831,7 +808,7 @@ int ADDCALL hackrf_set_fracrate(hackrf_device* device, const double freq) freq_hz = (uint32_t)(freq * i + 0.5); divider = i; - return hackrf_set_fracrate_manual(device, freq_hz, divider); + return hackrf_set_sample_rate_manual(device, freq_hz, divider); } int ADDCALL hackrf_set_amp_enable(hackrf_device* device, const uint8_t value) diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index 70e09e1d..b79c7499 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -112,8 +112,7 @@ extern ADDAPI int ADDCALL hackrf_max2837_write(hackrf_device* device, uint8_t re extern ADDAPI int ADDCALL hackrf_si5351c_read(hackrf_device* device, uint16_t register_number, uint16_t* value); extern ADDAPI int ADDCALL hackrf_si5351c_write(hackrf_device* device, uint16_t register_number, uint16_t value); -extern ADDAPI int ADDCALL hackrf_sample_rate_set(hackrf_device* device, const uint32_t sampling_rate_hz); -extern ADDAPI int ADDCALL hackrf_baseband_filter_bandwidth_set(hackrf_device* device, const uint32_t bandwidth_hz); +extern ADDAPI int ADDCALL hackrf_set_baseband_filter_bandwidth(hackrf_device* device, const uint32_t bandwidth_hz); extern ADDAPI int ADDCALL hackrf_rffc5071_read(hackrf_device* device, uint8_t register_number, uint16_t* value); extern ADDAPI int ADDCALL hackrf_rffc5071_write(hackrf_device* device, uint8_t register_number, uint16_t value); @@ -129,8 +128,11 @@ extern ADDAPI int ADDCALL hackrf_board_id_read(hackrf_device* device, uint8_t* v extern ADDAPI int ADDCALL hackrf_version_string_read(hackrf_device* device, char* version, uint8_t length); extern ADDAPI int ADDCALL hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz); -extern ADDAPI int ADDCALL hackrf_set_fracrate_manual(hackrf_device* device, const uint32_t freq_hz, const uint32_t divider); -extern ADDAPI int ADDCALL hackrf_set_fracrate(hackrf_device* device, const double freq_hz); + +/* currently 8-20Mhz - either as a fraction, i.e. freq 20000000hz divider 2 -> 10Mhz or as plain old 10000000hz (double) + preferred rates are 8, 10, 12.5, 16, 20Mhz due to less jitter */ +extern ADDAPI int ADDCALL hackrf_set_sample_rate_manual(hackrf_device* device, const uint32_t freq_hz, const uint32_t divider); +extern ADDAPI int ADDCALL hackrf_set_sample_rate(hackrf_device* device, const double freq_hz); /* external amp, bool on/off */ extern ADDAPI int ADDCALL hackrf_set_amp_enable(hackrf_device* device, const uint8_t value);