PortaPack: Lots of clean-up

Perform PortaPack initialization separately from and earlier than UI initialization. Track if PortaPack was detected, provide (mostly useless) pointer if so. Put "weak" declarations into respective headers. Moving #includes around.
This commit is contained in:
Jared Boone
2019-03-20 10:44:56 -07:00
parent af66a7c076
commit b4d8ee678e
8 changed files with 41 additions and 23 deletions

View File

@ -21,7 +21,7 @@
#include "hackrf-ui.h"
#include "portapack.h"
#include "ui_portapack.h"
#include "ui_rad1o.h"
#include <stddef.h>
@ -60,20 +60,14 @@ static const hackrf_ui_t hackrf_ui_null = {
&hackrf_ui_set_antenna_bias_null,
};
const portapack_t* portapack_init(void) __attribute__((weak));
const hackrf_ui_t* rad1o_ui_setup(void) __attribute__((weak));
static const hackrf_ui_t* ui = NULL;
const hackrf_ui_t* hackrf_ui(void) {
/* Detect on first use. If no UI hardware is detected, use a stub function table. */
if( ui == NULL ) {
#ifdef HACKRF_ONE
if( portapack_init ) {
const portapack_t* const portapack = portapack_init();
if( portapack != NULL ) {
ui = portapack->hackrf_ui;
}
if( portapack_hackrf_ui_init ) {
ui = portapack_hackrf_ui_init();
}
#endif
#ifdef RAD1O

View File

@ -556,19 +556,22 @@ static bool portapack_detect(void) {
return jtag_pp_idcode() == 0x020A50DD;
}
extern const hackrf_ui_t portapack_hackrf_ui;
const portapack_t portapack = {
&portapack_hackrf_ui,
static const portapack_t portapack_instance = {
};
const portapack_t* portapack_init(void) {
static const portapack_t* portapack_pointer = NULL;
const portapack_t* portapack(void) {
return portapack_pointer;
}
void portapack_init(void) {
if( portapack_detect() ) {
portapack_if_init();
portapack_lcd_reset();
portapack_lcd_init();
return &portapack;
portapack_pointer = &portapack_instance;
} else {
return NULL;
portapack_pointer = NULL;
}
}

View File

@ -22,9 +22,9 @@
#ifndef __PORTAPACK_H__
#define __PORTAPACK_H__
#include <stdint.h>
#include <stddef.h>
#include "hackrf-ui.h"
#include <stdbool.h>
#define ARRAY_SIZEOF(x) (sizeof(x) / sizeof(x[0]))
@ -60,11 +60,14 @@ typedef struct ui_font_t {
size_t data_stride;
} ui_font_t;
typedef struct {
const hackrf_ui_t* const hackrf_ui;
typedef struct portapack_t {
} portapack_t;
const portapack_t* portapack_init(void);
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);
void portapack_backlight(const bool on);

View File

@ -500,3 +500,11 @@ const hackrf_ui_t portapack_hackrf_ui = {
&portapack_ui_set_filter,
&portapack_ui_set_antenna_bias,
};
const hackrf_ui_t* portapack_hackrf_ui_init() {
if( portapack() ) {
return &portapack_hackrf_ui;
} else {
return NULL;
}
}

View File

@ -22,4 +22,8 @@
#ifndef __UI_PORTAPACK_H__
#define __UI_PORTAPACK_H__
#include "hackrf-ui.h"
const hackrf_ui_t* portapack_hackrf_ui_init() __attribute__((weak));
#endif/*__UI_PORTAPACK_H__*/

View File

@ -19,7 +19,6 @@
* Boston, MA 02110-1301, USA.
*/
#include "hackrf-ui.h"
#include "ui_rad1o.h"
/* Weak functions from rad1o app */

View File

@ -22,6 +22,8 @@
#ifndef __UI_RAD1O_H__
#define __UI_RAD1O_H__
const hackrf_ui_t* rad1o_ui_setup(void);
#include "hackrf-ui.h"
const hackrf_ui_t* rad1o_ui_setup(void) __attribute__((weak));
#endif/*__UI_RAD1O_H__*/

View File

@ -46,6 +46,7 @@
#include "usb_api_transceiver.h"
#include "usb_bulk_buffer.h"
#include "cpld_xc2c.h"
#include "portapack.h"
#include "hackrf-ui.h"
@ -235,6 +236,10 @@ int main(void) {
halt_and_flash(6000000);
}
#ifdef HACKRF_ONE
portapack_init();
#endif
#ifndef DFU_MODE
usb_set_descriptor_by_serial_number();
#endif