feat(hackrf): Callbacks for a possible UI

This commit is contained in:
Tobias Schneider
2015-12-07 00:29:33 +01:00
parent 9e827b56be
commit 86b424d9d3
7 changed files with 66 additions and 7 deletions

View File

@ -27,6 +27,11 @@
#include "rffc5071.h" #include "rffc5071.h"
#include "sgpio.h" #include "sgpio.h"
#include "rf_path.h" #include "rf_path.h"
#if HACKRF_ENABLE_UI
#include "hackrf-ui.h"
#endif
#include <libopencm3/lpc43xx/i2c.h> #include <libopencm3/lpc43xx/i2c.h>
#include <libopencm3/lpc43xx/cgu.h> #include <libopencm3/lpc43xx/cgu.h>
#include <libopencm3/lpc43xx/gpio.h> #include <libopencm3/lpc43xx/gpio.h>
@ -86,6 +91,10 @@ bool sample_rate_frac_set(uint32_t rate_num, uint32_t rate_denom)
uint32_t a, b, c; uint32_t a, b, c;
uint32_t rem; uint32_t rem;
#if HACKRF_ENABLE_UI
hackrf_ui_setSampleRate(rate_num/2);
#endif
/* Find best config */ /* Find best config */
a = (VCO_FREQ * rate_denom) / rate_num; a = (VCO_FREQ * rate_denom) / rate_num;
@ -169,7 +178,11 @@ bool sample_rate_set(const uint32_t sample_rate_hz) {
default: default:
return false; 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 /* NOTE: Because MS1, 2, 3 outputs are slaved to PLLA, the p1, p2, p3
* values are irrelevant. */ * 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) { 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 /* clock startup for Jellybean with Lemondrop attached

View File

@ -425,7 +425,7 @@ static const max2837_ft_t max2837_ft[] = {
{ 0, 0 }, { 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; const max2837_ft_t* p = max2837_ft;
while( p->bandwidth_hz != 0 ) { while( p->bandwidth_hz != 0 ) {
if( p->bandwidth_hz >= bandwidth_hz ) { 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 ) { if( p->bandwidth_hz != 0 ) {
set_MAX2837_FT(p->ft); set_MAX2837_FT(p->ft);
max2837_regs_commit(); max2837_regs_commit();
return true;
} else {
return false;
} }
return p->bandwidth_hz;
} }
bool max2837_set_lna_gain(const uint32_t gain_db) { bool max2837_set_lna_gain(const uint32_t gain_db) {

View File

@ -59,7 +59,7 @@ extern void max2837_stop(void);
/* Set frequency in Hz. Frequency setting is a multi-step function /* Set frequency in Hz. Frequency setting is a multi-step function
* where order of register writes matters. */ * where order of register writes matters. */
extern void max2837_set_frequency(uint32_t freq); 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_lna_gain(const uint32_t gain_db);
bool max2837_set_vga_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); bool max2837_set_txvga_gain(const uint32_t gain_db);

View File

@ -27,6 +27,10 @@
#include <hackrf_core.h> #include <hackrf_core.h>
#if HACKRF_ENABLE_UI
#include "hackrf-ui.h"
#endif
#include <mixer.h> #include <mixer.h>
#include <max2837.h> #include <max2837.h>
#include <max5864.h> #include <max5864.h>
@ -392,6 +396,10 @@ void rf_path_set_direction(const rf_path_direction_t direction) {
} }
switchctrl_set(switchctrl); switchctrl_set(switchctrl);
#if HACKRF_ENABLE_UI
hackrf_ui_setDirection(direction);
#endif
} }
void rf_path_set_filter(const rf_path_filter_t filter) { 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); switchctrl_set(switchctrl);
#if HACKRF_ENABLE_UI
hackrf_ui_setLNAPower(enable);
#endif
} }
/* antenna port power control */ /* antenna port power control */

View File

@ -22,6 +22,10 @@
#include "tuning.h" #include "tuning.h"
#if HACKRF_ENABLE_UI
#include "hackrf-ui.h"
#endif
#include <mixer.h> #include <mixer.h>
#include <max2837.h> #include <max2837.h>
#include <sgpio.h> #include <sgpio.h>
@ -108,6 +112,9 @@ bool set_freq(const uint64_t freq)
max2837_set_mode(prior_max2837_mode); max2837_set_mode(prior_max2837_mode);
if( success ) { if( success ) {
freq_cache = freq; freq_cache = freq;
#if HACKRF_ENABLE_UI
hackrf_ui_setFrequency(freq);
#endif
} }
return success; return success;
} }

View File

@ -48,6 +48,10 @@
#include "usb_bulk_buffer.h" #include "usb_bulk_buffer.h"
#include "si5351c.h" #include "si5351c.h"
#if HACKRF_ENABLE_UI
#include "hackrf-ui.h"
#endif
static volatile transceiver_mode_t _transceiver_mode = TRANSCEIVER_MODE_OFF; static volatile transceiver_mode_t _transceiver_mode = TRANSCEIVER_MODE_OFF;
void set_transceiver_mode(const transceiver_mode_t new_transceiver_mode) { 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); nvic_set_priority(NVIC_USB0_IRQ, 255);
#if HACKRF_ENABLE_UI
hackrf_ui_init();
#endif
usb_run(&usb_device); usb_run(&usb_device);
ssp1_init(); ssp1_init();
rf_path_init(); rf_path_init();
unsigned int phase = 0; unsigned int phase = 0;

View File

@ -24,6 +24,10 @@
#include <libopencm3/lpc43xx/gpio.h> #include <libopencm3/lpc43xx/gpio.h>
#if HACKRF_ENABLE_UI
#include "hackrf-ui.h"
#endif
#include <max2837.h> #include <max2837.h>
#include <rf_path.h> #include <rf_path.h>
#include <tuning.h> #include <tuning.h>
@ -147,6 +151,9 @@ usb_request_status_t usb_vendor_request_set_lna_gain(
if( stage == USB_TRANSFER_STAGE_SETUP ) { if( stage == USB_TRANSFER_STAGE_SETUP ) {
const uint8_t value = max2837_set_lna_gain(endpoint->setup.index); const uint8_t value = max2837_set_lna_gain(endpoint->setup.index);
endpoint->buffer[0] = value; 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, usb_transfer_schedule_block(endpoint->in, &endpoint->buffer, 1,
NULL, NULL); NULL, NULL);
usb_transfer_schedule_ack(endpoint->out); 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 ) { if( stage == USB_TRANSFER_STAGE_SETUP ) {
const uint8_t value = max2837_set_vga_gain(endpoint->setup.index); const uint8_t value = max2837_set_vga_gain(endpoint->setup.index);
endpoint->buffer[0] = value; 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, usb_transfer_schedule_block(endpoint->in, &endpoint->buffer, 1,
NULL, NULL); NULL, NULL);
usb_transfer_schedule_ack(endpoint->out); 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 ) { if( stage == USB_TRANSFER_STAGE_SETUP ) {
const uint8_t value = max2837_set_txvga_gain(endpoint->setup.index); const uint8_t value = max2837_set_txvga_gain(endpoint->setup.index);
endpoint->buffer[0] = value; 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, usb_transfer_schedule_block(endpoint->in, &endpoint->buffer, 1,
NULL, NULL); NULL, NULL);
usb_transfer_schedule_ack(endpoint->out); usb_transfer_schedule_ack(endpoint->out);