diff --git a/firmware/common/hackrf_core.c b/firmware/common/hackrf_core.c index 16760e17..639b8e70 100644 --- a/firmware/common/hackrf_core.c +++ b/firmware/common/hackrf_core.c @@ -27,6 +27,11 @@ #include "rffc5071.h" #include "sgpio.h" #include "rf_path.h" + +#if HACKRF_ENABLE_UI +#include "hackrf-ui.h" +#endif + #include #include #include @@ -86,6 +91,10 @@ bool sample_rate_frac_set(uint32_t rate_num, uint32_t rate_denom) uint32_t a, b, c; uint32_t rem; +#if HACKRF_ENABLE_UI + hackrf_ui_setSampleRate(rate_num/2); +#endif + /* Find best config */ a = (VCO_FREQ * rate_denom) / rate_num; @@ -169,7 +178,11 @@ bool sample_rate_set(const uint32_t sample_rate_hz) { default: return false; } - + +#if HACKRF_ENABLE_UI + hackrf_ui_setSampleRate(sample_rate_hz); +#endif + /* NOTE: Because MS1, 2, 3 outputs are slaved to PLLA, the p1, p2, p3 * values are irrelevant. */ @@ -250,7 +263,13 @@ bool sample_rate_set(const uint32_t sample_rate_hz) { } bool baseband_filter_bandwidth_set(const uint32_t bandwidth_hz) { - return max2837_set_lpf_bandwidth(bandwidth_hz); + uint32_t bandwidth_hz_real = max2837_set_lpf_bandwidth(bandwidth_hz); + +#if HACKRF_ENABLE_UI + if(bandwidth_hz_real) hackrf_ui_setFilterBW(bandwidth_hz_real); +#endif + + return bandwidth_hz_real != 0; } /* clock startup for Jellybean with Lemondrop attached diff --git a/firmware/common/max2837.c b/firmware/common/max2837.c index 020763d6..6da78dc5 100644 --- a/firmware/common/max2837.c +++ b/firmware/common/max2837.c @@ -425,7 +425,7 @@ static const max2837_ft_t max2837_ft[] = { { 0, 0 }, }; -bool max2837_set_lpf_bandwidth(const uint32_t bandwidth_hz) { +uint32_t max2837_set_lpf_bandwidth(const uint32_t bandwidth_hz) { const max2837_ft_t* p = max2837_ft; while( p->bandwidth_hz != 0 ) { if( p->bandwidth_hz >= bandwidth_hz ) { @@ -437,10 +437,9 @@ bool max2837_set_lpf_bandwidth(const uint32_t bandwidth_hz) { if( p->bandwidth_hz != 0 ) { set_MAX2837_FT(p->ft); max2837_regs_commit(); - return true; - } else { - return false; } + + return p->bandwidth_hz; } bool max2837_set_lna_gain(const uint32_t gain_db) { diff --git a/firmware/common/max2837.h b/firmware/common/max2837.h index 582a0966..6d5bf533 100644 --- a/firmware/common/max2837.h +++ b/firmware/common/max2837.h @@ -59,7 +59,7 @@ extern void max2837_stop(void); /* Set frequency in Hz. Frequency setting is a multi-step function * where order of register writes matters. */ extern void max2837_set_frequency(uint32_t freq); -bool max2837_set_lpf_bandwidth(const uint32_t bandwidth_hz); +uint32_t max2837_set_lpf_bandwidth(const uint32_t bandwidth_hz); bool max2837_set_lna_gain(const uint32_t gain_db); bool max2837_set_vga_gain(const uint32_t gain_db); bool max2837_set_txvga_gain(const uint32_t gain_db); diff --git a/firmware/common/rf_path.c b/firmware/common/rf_path.c index 4eaaf98f..b148c2ad 100644 --- a/firmware/common/rf_path.c +++ b/firmware/common/rf_path.c @@ -27,6 +27,10 @@ #include +#if HACKRF_ENABLE_UI +#include "hackrf-ui.h" +#endif + #include #include #include @@ -392,6 +396,10 @@ void rf_path_set_direction(const rf_path_direction_t direction) { } switchctrl_set(switchctrl); + +#if HACKRF_ENABLE_UI + hackrf_ui_setDirection(direction); +#endif } void rf_path_set_filter(const rf_path_filter_t filter) { @@ -434,6 +442,10 @@ void rf_path_set_lna(const uint_fast8_t enable) { } switchctrl_set(switchctrl); + +#if HACKRF_ENABLE_UI + hackrf_ui_setLNAPower(enable); +#endif } /* antenna port power control */ diff --git a/firmware/common/tuning.c b/firmware/common/tuning.c index 6998cdf5..5c51267f 100644 --- a/firmware/common/tuning.c +++ b/firmware/common/tuning.c @@ -22,6 +22,10 @@ #include "tuning.h" +#if HACKRF_ENABLE_UI +#include "hackrf-ui.h" +#endif + #include #include #include @@ -108,6 +112,9 @@ bool set_freq(const uint64_t freq) max2837_set_mode(prior_max2837_mode); if( success ) { freq_cache = freq; +#if HACKRF_ENABLE_UI + hackrf_ui_setFrequency(freq); +#endif } return success; } diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index e2fbde9c..4eb3c41d 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -48,6 +48,10 @@ #include "usb_bulk_buffer.h" #include "si5351c.h" +#if HACKRF_ENABLE_UI +#include "hackrf-ui.h" +#endif + static volatile transceiver_mode_t _transceiver_mode = TRANSCEIVER_MODE_OFF; void set_transceiver_mode(const transceiver_mode_t new_transceiver_mode) { @@ -246,11 +250,16 @@ int main(void) { nvic_set_priority(NVIC_USB0_IRQ, 255); +#if HACKRF_ENABLE_UI + hackrf_ui_init(); +#endif + usb_run(&usb_device); ssp1_init(); + rf_path_init(); unsigned int phase = 0; diff --git a/firmware/hackrf_usb/usb_api_transceiver.c b/firmware/hackrf_usb/usb_api_transceiver.c index 7ab06376..20357260 100644 --- a/firmware/hackrf_usb/usb_api_transceiver.c +++ b/firmware/hackrf_usb/usb_api_transceiver.c @@ -24,6 +24,10 @@ #include +#if HACKRF_ENABLE_UI +#include "hackrf-ui.h" +#endif + #include #include #include @@ -147,6 +151,9 @@ usb_request_status_t usb_vendor_request_set_lna_gain( if( stage == USB_TRANSFER_STAGE_SETUP ) { const uint8_t value = max2837_set_lna_gain(endpoint->setup.index); endpoint->buffer[0] = value; +#if HACKRF_ENABLE_UI + if(value) hackrf_ui_setBBLNAGain(endpoint->setup.index); +#endif usb_transfer_schedule_block(endpoint->in, &endpoint->buffer, 1, NULL, NULL); usb_transfer_schedule_ack(endpoint->out); @@ -161,6 +168,9 @@ usb_request_status_t usb_vendor_request_set_vga_gain( if( stage == USB_TRANSFER_STAGE_SETUP ) { const uint8_t value = max2837_set_vga_gain(endpoint->setup.index); endpoint->buffer[0] = value; +#if HACKRF_ENABLE_UI + if(value) hackrf_ui_setBBVGAGain(endpoint->setup.index); +#endif usb_transfer_schedule_block(endpoint->in, &endpoint->buffer, 1, NULL, NULL); usb_transfer_schedule_ack(endpoint->out); @@ -175,6 +185,9 @@ usb_request_status_t usb_vendor_request_set_txvga_gain( if( stage == USB_TRANSFER_STAGE_SETUP ) { const uint8_t value = max2837_set_txvga_gain(endpoint->setup.index); endpoint->buffer[0] = value; +#if HACKRF_ENABLE_UI + if(value) hackrf_ui_setBBTXVGAGain(endpoint->setup.index); +#endif usb_transfer_schedule_block(endpoint->in, &endpoint->buffer, 1, NULL, NULL); usb_transfer_schedule_ack(endpoint->out);