PortaPack: Add check for PortaPack clock reference, use if present.

Wow, it takes a lot of ugly code to keep blinky happy...
This commit is contained in:
Jared Boone
2019-03-20 13:27:20 -07:00
parent 46fd11af5b
commit dccb748216
2 changed files with 28 additions and 2 deletions

View File

@ -39,6 +39,10 @@
#include <libopencm3/lpc43xx/scu.h>
#include <libopencm3/lpc43xx/ssp.h>
#ifdef HACKRF_ONE
#include "portapack.h"
#endif
#include "gpio_lpc.h"
#define WAIT_CPU_CLOCK_INIT_DELAY (10000)
@ -714,9 +718,31 @@ void cpu_clock_init(void)
void activate_best_clock_source(void)
{
#ifdef HACKRF_ONE
/* Ensure PortaPack reference oscillator is off while checking for external clock input. */
if( portapack_reference_oscillator && portapack()) {
portapack_reference_oscillator(false);
}
#endif
/* Check for external clock input. */
if (si5351c_clkin_signal_valid(&clock_gen)) {
si5351c_set_clock_source(&clock_gen, PLL_SOURCE_CLKIN);
} else {
#ifdef HACKRF_ONE
/* Enable PortaPack reference oscillator (if present), and check for valid clock. */
if( portapack_reference_oscillator && portapack() ) {
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;
} 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);
}
}

View File

@ -67,11 +67,11 @@ void portapack_init(void);
/* If the "portapack" symbol is defined, PortaPack support is compiled in */
/* If the portapack() call returns non-NULL, a PortaPack was detected and is initialized. */
const portapack_t* portapack(void);
const portapack_t* portapack(void) __attribute__((weak));
void portapack_backlight(const bool on);
void portapack_reference_oscillator(const bool on);
void portapack_reference_oscillator(const bool on) __attribute__((weak));
void portapack_fill_rectangle(
const ui_rect_t rect,