Clock reference: Add UI hook. Simplify selection code.

This commit is contained in:
Jared Boone
2019-03-20 20:18:25 -07:00
parent 027a0eca97
commit 190c3972f4
5 changed files with 22 additions and 6 deletions

View File

@ -41,6 +41,7 @@ void hackrf_ui_set_bb_tx_vga_gain_null(const uint32_t gain_db) { UNUSED(gain_db)
void hackrf_ui_set_first_if_frequency_null(const uint64_t frequency) { UNUSED(frequency); }
void hackrf_ui_set_filter_null(const rf_path_filter_t filter) { UNUSED(filter); }
void hackrf_ui_set_antenna_bias_null(bool antenna_bias) { UNUSED(antenna_bias); }
void hackrf_ui_set_clock_source_null(clock_source_t source) { UNUSED(source); }
/* Null UI function table, used if there's no hardware UI detected. Eliminates the
* need to check for null UI before calling a function in the table.
@ -58,6 +59,7 @@ static const hackrf_ui_t hackrf_ui_null = {
&hackrf_ui_set_first_if_frequency_null,
&hackrf_ui_set_filter_null,
&hackrf_ui_set_antenna_bias_null,
&hackrf_ui_set_clock_source_null,
};
static const hackrf_ui_t* ui = NULL;

View File

@ -37,6 +37,7 @@ typedef void (*hackrf_ui_set_bb_tx_vga_gain_fn)(const uint32_t gain_db);
typedef void (*hackrf_ui_set_first_if_frequency_fn)(const uint64_t frequency);
typedef void (*hackrf_ui_set_filter_fn)(const rf_path_filter_t filter);
typedef void (*hackrf_ui_set_antenna_bias_fn)(bool antenna_bias);
typedef void (*hackrf_ui_set_clock_source_fn)(clock_source_t source);
typedef struct {
hackrf_ui_init_fn init;
@ -51,6 +52,7 @@ typedef struct {
hackrf_ui_set_first_if_frequency_fn set_first_if_frequency;
hackrf_ui_set_filter_fn set_filter;
hackrf_ui_set_antenna_bias_fn set_antenna_bias;
hackrf_ui_set_clock_source_fn set_clock_source;
} hackrf_ui_t;
/* TODO: Lame hack to know that PortaPack was detected.

View File

@ -725,10 +725,11 @@ clock_source_t activate_best_clock_source(void)
}
#endif
clock_source_t source = CLOCK_SOURCE_HACKRF;
/* Check for external clock input. */
if (si5351c_clkin_signal_valid(&clock_gen)) {
si5351c_set_clock_source(&clock_gen, PLL_SOURCE_CLKIN);
return CLOCK_SOURCE_EXTERNAL;
source = CLOCK_SOURCE_EXTERNAL;
} else {
#ifdef HACKRF_ONE
/* Enable PortaPack reference oscillator (if present), and check for valid clock. */
@ -736,17 +737,18 @@ clock_source_t activate_best_clock_source(void)
portapack_reference_oscillator(true);
delay(510000); /* loop iterations @ 204MHz for >10ms for oscillator to enable. */
if (si5351c_clkin_signal_valid(&clock_gen)) {
si5351c_set_clock_source(&clock_gen, PLL_SOURCE_CLKIN);
return CLOCK_SOURCE_PORTAPACK;
source = CLOCK_SOURCE_PORTAPACK;
} else {
portapack_reference_oscillator(false);
}
}
#endif
/* No external or PortaPack clock was found. Use HackRF Si5351C crystal. */
si5351c_set_clock_source(&clock_gen, PLL_SOURCE_XTAL);
return CLOCK_SOURCE_HACKRF;
}
si5351c_set_clock_source(&clock_gen, (source == CLOCK_SOURCE_HACKRF) ? PLL_SOURCE_XTAL : PLL_SOURCE_CLKIN);
hackrf_ui()->set_clock_source(source);
return source;
}
void ssp1_set_mode_max2837(void)

View File

@ -502,6 +502,9 @@ static void portapack_ui_set_antenna_bias(bool antenna_bias) {
(void)antenna_bias;
}
static void portapack_ui_set_clock_source(clock_source_t source) {
}
const hackrf_ui_t portapack_hackrf_ui = {
&portapack_ui_init,
&portapack_ui_set_frequency,
@ -515,6 +518,7 @@ const hackrf_ui_t portapack_hackrf_ui = {
&portapack_ui_set_first_if_frequency,
&portapack_ui_set_filter,
&portapack_ui_set_antenna_bias,
&portapack_ui_set_clock_source,
};
const hackrf_ui_t* portapack_hackrf_ui_init() {

View File

@ -34,6 +34,7 @@ void hackrf_ui_setBBTXVGAGain(const uint32_t gain_db) __attribute__((weak));
void hackrf_ui_setFirstIFFrequency(const uint64_t freq) __attribute__((weak));
void hackrf_ui_setFilter(const rf_path_filter_t filter) __attribute__((weak));
void hackrf_ui_setAntennaBias(bool antenna_bias) __attribute__((weak));
void hackrf_ui_setClockSource(clock_source_t source) __attribute__((weak));
static void rad1o_ui_init(void) {
hackrf_ui_init();
@ -83,6 +84,10 @@ static void rad1o_ui_set_antenna_bias(bool antenna_bias) {
hackrf_ui_setAntennaBias(antenna_bias);
}
static void rad1o_ui_set_clock_source(clock_source_t source) {
hackrf_ui_setClockSource(source);
}
static const hackrf_ui_t rad1o_ui = {
&rad1o_ui_init,
&rad1o_ui_set_frequency,
@ -96,6 +101,7 @@ static const hackrf_ui_t rad1o_ui = {
&rad1o_ui_set_first_if_frequency,
&rad1o_ui_set_filter,
&rad1o_ui_set_antenna_bias,
&rad1o_ui_set_clock_source,
};
const hackrf_ui_t* rad1o_ui_setup(void) {