Merge pull request #607 from dominicgs/portapack_ui_opera_cake_coexistence

Allow portapack and opera cake to coexist and still enable the PP UI
This commit is contained in:
Michael Ossmann
2020-01-06 16:28:58 -07:00
committed by GitHub
6 changed files with 28 additions and 51 deletions

View File

@ -23,6 +23,7 @@
#include "hackrf_core.h"
#include "gpio.h"
#include "gpio_lpc.h"
#include "i2c_bus.h"
#include <libopencm3/lpc43xx/scu.h>
/*
@ -71,6 +72,7 @@
i2c_bus_t* const oc_bus = &i2c0;
uint8_t operacake_boards[8] = {0,0,0,0,0,0,0,0};
bool allow_gpio_mode = true;
/* read single register */
uint8_t operacake_read_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg) {
@ -86,7 +88,7 @@ void operacake_write_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg, uin
i2c_bus_transfer(bus, address, data, 2, NULL, 0);
}
uint8_t operacake_init(void) {
uint8_t operacake_init(bool allow_gpio) {
uint8_t reg, addr, i, j = 0;
/* Find connected operacakes */
for(i=0; i<8; i++) {
@ -99,6 +101,7 @@ uint8_t operacake_init(void) {
if(reg==OPERACAKE_CONFIG_ALL_OUTPUT)
operacake_boards[j++] = addr;
}
allow_gpio_mode = allow_gpio;
return 0;
}
@ -215,7 +218,9 @@ uint16_t gpio_test(uint8_t address)
{
uint8_t i, reg, bit_mask, gpio_mask = 0x1F;
uint16_t result = 0;
operacake_init();
if(!allow_gpio_mode)
return 0xFFFF;
scu_pinmux(SCU_PINMUX_GPIO3_8, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(SCU_PINMUX_GPIO3_12, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(SCU_PINMUX_GPIO3_13, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);

View File

@ -28,7 +28,7 @@ extern "C"
#endif
#include <stdint.h>
#include "i2c_bus.h"
#include <stdbool.h>
#define OPERACAKE_PA1 0
#define OPERACAKE_PA2 1
@ -45,7 +45,7 @@ extern "C"
/* Up to 8 Operacake boards can be used with one HackRF */
extern uint8_t operacake_boards[8];
uint8_t operacake_init(void);
uint8_t operacake_init(bool allow_gpio);
uint8_t operacake_set_ports(uint8_t address, uint8_t PA, uint8_t PB);
uint8_t operacake_add_range(uint16_t freq_min, uint16_t freq_max, uint8_t port);
uint8_t operacake_set_range(uint32_t freq_mhz);

View File

@ -236,6 +236,13 @@ macro(DeclareTargets)
COMMAND rm -f _tmp.dfu _header.bin
)
# Program / flash targets
add_custom_target(
${PROJECT_NAME}-flash
DEPENDS ${PROJECT_NAME}.bin
COMMAND hackrf_spiflash -Rw ${PROJECT_NAME}.bin
)
add_custom_target(
${PROJECT_NAME}-program
DEPENDS ${PROJECT_NAME}.dfu

View File

@ -49,51 +49,6 @@
#include "hackrf-ui.h"
// TODO: Duplicate code/knowledge, copied from /host/libhackrf/src/hackrf.c
// TODO: Factor this into a shared #include so that firmware can use
// the same values.
typedef enum {
HACKRF_VENDOR_REQUEST_SET_TRANSCEIVER_MODE = 1,
HACKRF_VENDOR_REQUEST_MAX2837_WRITE = 2,
HACKRF_VENDOR_REQUEST_MAX2837_READ = 3,
HACKRF_VENDOR_REQUEST_SI5351C_WRITE = 4,
HACKRF_VENDOR_REQUEST_SI5351C_READ = 5,
HACKRF_VENDOR_REQUEST_SAMPLE_RATE_SET = 6,
HACKRF_VENDOR_REQUEST_BASEBAND_FILTER_BANDWIDTH_SET = 7,
HACKRF_VENDOR_REQUEST_RFFC5071_WRITE = 8,
HACKRF_VENDOR_REQUEST_RFFC5071_READ = 9,
HACKRF_VENDOR_REQUEST_SPIFLASH_ERASE = 10,
HACKRF_VENDOR_REQUEST_SPIFLASH_WRITE = 11,
HACKRF_VENDOR_REQUEST_SPIFLASH_READ = 12,
_HACKRF_VENDOR_REQUEST_WRITE_CPLD = 13,
HACKRF_VENDOR_REQUEST_BOARD_ID_READ = 14,
HACKRF_VENDOR_REQUEST_VERSION_STRING_READ = 15,
HACKRF_VENDOR_REQUEST_SET_FREQ = 16,
HACKRF_VENDOR_REQUEST_AMP_ENABLE = 17,
HACKRF_VENDOR_REQUEST_BOARD_PARTID_SERIALNO_READ = 18,
HACKRF_VENDOR_REQUEST_SET_LNA_GAIN = 19,
HACKRF_VENDOR_REQUEST_SET_VGA_GAIN = 20,
HACKRF_VENDOR_REQUEST_SET_TXVGA_GAIN = 21,
_HACKRF_VENDOR_REQUEST_SET_IF_FREQ = 22,
HACKRF_VENDOR_REQUEST_ANTENNA_ENABLE = 23,
HACKRF_VENDOR_REQUEST_SET_FREQ_EXPLICIT = 24,
HACKRF_VENDOR_REQUEST_USB_WCID_VENDOR_REQ = 25,
HACKRF_VENDOR_REQUEST_INIT_SWEEP = 26,
HACKRF_VENDOR_REQUEST_OPERACAKE_GET_BOARDS = 27,
HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS = 28,
HACKRF_VENDOR_REQUEST_SET_HW_SYNC_MODE = 29,
HACKRF_VENDOR_REQUEST_RESET = 30,
HACKRF_VENDOR_REQUEST_OPERACAKE_SET_RANGES = 31,
HACKRF_VENDOR_REQUEST_CLKOUT_ENABLE = 32,
HACKRF_VENDOR_REQUEST_SPIFLASH_STATUS = 33,
HACKRF_VENDOR_REQUEST_SPIFLASH_CLEAR_STATUS = 34,
HACKRF_VENDOR_REQUEST_OPERACAKE_GPIO_TEST = 35,
HACKRF_VENDOR_REQUEST_CPLD_CHECKSUM = 36,
/* Update to be the next integer after the highest-numbered request. */
_HACKRF_VENDOR_REQUEST_ARRAY_SIZE
} hackrf_vendor_request;
static usb_request_handler_fn vendor_request_handler[] = {
NULL,
usb_vendor_request_set_transceiver_mode,
@ -221,6 +176,7 @@ static bool cpld_jtag_sram_load(jtag_t* const jtag) {
}
int main(void) {
bool operacake_allow_gpio;
pin_setup();
enable_1v8_power();
#if (defined HACKRF_ONE || defined RAD1O)
@ -261,8 +217,11 @@ int main(void) {
rf_path_init(&rf_path);
if( hackrf_ui() == NULL ) {
operacake_init();
operacake_allow_gpio = true;
} else {
operacake_allow_gpio = false;
}
operacake_init(operacake_allow_gpio);
unsigned int phase = 0;

View File

@ -22,6 +22,7 @@
#include "usb_api_operacake.h"
#include "usb_queue.h"
#include <stddef.h>
#include <operacake.h>
usb_request_status_t usb_vendor_request_operacake_get_boards(

View File

@ -39,6 +39,8 @@ typedef int bool;
#define INVALID_ADDRESS 0xFF
#define INVALID_PORT 0xFF
#define GPIO_TEST_DISABLED 0xFFFF
static void usage() {
printf("\nUsage:\n");
printf("\t-h, --help: this help\n");
@ -285,7 +287,10 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}
if(test_result) {
if(test_result == GPIO_TEST_DISABLED) {
fprintf(stderr, "GPIO mode diabled.\n");
fprintf(stderr, "Remove additional addon boards and retry.\n");
}else if(test_result) {
fprintf(stderr, "GPIO test failed\n");
fprintf(stderr, "Pin\tHigh\tShorts\tLow\n");
reg = test_result & mask;