Skip to content

Commit

Permalink
Merge branch 'master' into hygiene
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicgs authored Mar 3, 2019
2 parents 24fe561 + a4c1ab6 commit 19f073f
Show file tree
Hide file tree
Showing 18 changed files with 347 additions and 234 deletions.
5 changes: 0 additions & 5 deletions firmware/README
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ $ hackrf_spiflash -w hackrf_usb.bin
If you have a Jawbreaker, add -DBOARD=JAWBREAKER to the cmake command.
If you have a rad1o, use -DBOARD=RAD1O instead.

If you have a HackRF One and want to build optional PortaPack display support,
also specify -DUSER_INTERFACE=PORTAPACK. If PortaPack hardware is not detected
by hardware probing at start-up, the HackRF firmware will run without UI
support.

It is possible to use a USB Device Firmware Upgrade (DFU) method to load
firmware into RAM. This is normally only required to recover a device that has
had faulty firmware loaded, but it can also be useful for firmware developers.
Expand Down
6 changes: 3 additions & 3 deletions firmware/common/cpld_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ void cpld_jtag_take(jtag_t* const jtag) {
/* Set initial GPIO state to the voltages of the internal or external pull-ups/downs,
* to avoid any glitches.
*/
#ifdef USER_INTERFACE_PORTAPACK
#ifdef HACKRF_ONE
gpio_set(gpio->gpio_pp_tms);
#endif
gpio_set(gpio->gpio_tms);
gpio_set(gpio->gpio_tdi);
gpio_clear(gpio->gpio_tck);

#ifdef USER_INTERFACE_PORTAPACK
#ifdef HACKRF_ONE
/* Do not drive PortaPack-specific TMS pin initially, just to be cautious. */
gpio_input(gpio->gpio_pp_tms);
gpio_input(gpio->gpio_pp_tdo);
Expand All @@ -59,7 +59,7 @@ void cpld_jtag_release(jtag_t* const jtag) {
/* Make all pins inputs when JTAG interface not active.
* Let the pull-ups/downs do the work.
*/
#ifdef USER_INTERFACE_PORTAPACK
#ifdef HACKRF_ONE
/* Do not drive PortaPack-specific pins, initially, just to be cautious. */
gpio_input(gpio->gpio_pp_tms);
gpio_input(gpio->gpio_pp_tdo);
Expand Down
4 changes: 2 additions & 2 deletions firmware/common/cpld_jtag.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ typedef struct jtag_gpio_t {
gpio_t gpio_tck;
gpio_t gpio_tdi;
gpio_t gpio_tdo;
#ifdef USER_INTERFACE_PORTAPACK
#ifdef HACKRF_ONE
gpio_t gpio_pp_tms;
gpio_t gpio_pp_tdo;
#endif
#endif
} jtag_gpio_t;

typedef struct jtag_t {
Expand Down
87 changes: 87 additions & 0 deletions firmware/common/hackrf-ui.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (C) 2019 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of HackRF.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/

#include "hackrf-ui.h"

#include "ui_portapack.h"
#include "ui_rad1o.h"

#include <stddef.h>

#define UNUSED(x) (void)(x)

/* Stub functions for null UI function table */
void hackrf_ui_init_null(void) { }
void hackrf_ui_set_frequency_null(uint64_t frequency) { UNUSED(frequency); }
void hackrf_ui_set_sample_rate_null(uint32_t sample_rate) { UNUSED(sample_rate); }
void hackrf_ui_set_direction_null(const rf_path_direction_t direction) { UNUSED(direction); }
void hackrf_ui_set_filter_bw_null(uint32_t bandwidth) { UNUSED(bandwidth); }
void hackrf_ui_set_lna_power_null(bool lna_on) { UNUSED(lna_on); }
void hackrf_ui_set_bb_lna_gain_null(const uint32_t gain_db) { UNUSED(gain_db); }
void hackrf_ui_set_bb_vga_gain_null(const uint32_t gain_db) { UNUSED(gain_db); }
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); }

/* 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.
*/
static const hackrf_ui_t hackrf_ui_null = {
&hackrf_ui_init_null,
&hackrf_ui_set_frequency_null,
&hackrf_ui_set_sample_rate_null,
&hackrf_ui_set_direction_null,
&hackrf_ui_set_filter_bw_null,
&hackrf_ui_set_lna_power_null,
&hackrf_ui_set_bb_lna_gain_null,
&hackrf_ui_set_bb_vga_gain_null,
&hackrf_ui_set_bb_tx_vga_gain_null,
&hackrf_ui_set_first_if_frequency_null,
&hackrf_ui_set_filter_null,
&hackrf_ui_set_antenna_bias_null,
};

const hackrf_ui_t* portapack_detect(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_detect ) {
ui = portapack_detect();
}
#endif
#ifdef RAD1O
if( rad1o_ui_setup ) {
ui = rad1o_ui_setup();
}
#endif
}

if( ui == NULL ) {
ui = &hackrf_ui_null;
}
return ui;
}
37 changes: 22 additions & 15 deletions firmware/common/hackrf-ui.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
* Copyright (C) 2018 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of HackRF.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/

#ifndef HACKRF_UI_H
#define HACKRF_UI_H

Expand Down Expand Up @@ -36,20 +57,6 @@ typedef struct {
* In the future, whatever UI was detected will be returned here,
* or NULL if no UI was detected.
*/
const hackrf_ui_t* hackrf_ui(void) __attribute__((weak));

void hackrf_ui_init(void) __attribute__((weak));
void hackrf_ui_setFrequency(uint64_t _freq) __attribute__((weak));
void hackrf_ui_setSampleRate(uint32_t _sample_rate) __attribute__((weak));
void hackrf_ui_setDirection(const rf_path_direction_t _direction) __attribute__((weak));
void hackrf_ui_setFilterBW(uint32_t bw) __attribute__((weak));
void hackrf_ui_setLNAPower(bool _lna_on) __attribute__((weak));
void hackrf_ui_setBBLNAGain(const uint32_t gain_db) __attribute__((weak));
void hackrf_ui_setBBVGAGain(const uint32_t gain_db) __attribute__((weak));
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));
const hackrf_ui_t* hackrf_ui(void);

#endif
Loading

0 comments on commit 19f073f

Please sign in to comment.