From cde5ef5bb707979a3cd1c1263f97ae2c477c8237 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Tue, 13 Dec 2016 19:05:49 -0700 Subject: [PATCH 01/10] Fix multibyte reads over i2c --- firmware/common/i2c_lpc.c | 20 +++++++++++++------- firmware/libopencm3 | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/firmware/common/i2c_lpc.c b/firmware/common/i2c_lpc.c index f7bf4393..607a1a0a 100644 --- a/firmware/common/i2c_lpc.c +++ b/firmware/common/i2c_lpc.c @@ -44,17 +44,23 @@ void i2c_lpc_transfer(i2c_bus_t* const bus, uint8_t* const data_rx, const size_t count_rx ) { const uint32_t port = (uint32_t)bus->obj; - i2c_tx_start(port); - i2c_tx_byte(port, (slave_address << 1) | I2C_WRITE); - for(size_t i=0; i 0)) { + i2c_tx_start(port); + i2c_tx_byte(port, (slave_address << 1) | I2C_WRITE); + for(i=0; i 0)) { i2c_tx_start(port); i2c_tx_byte(port, (slave_address << 1) | I2C_READ); - for(size_t i=0; i Date: Tue, 13 Dec 2016 19:07:11 -0700 Subject: [PATCH 02/10] Add initial operacake support --- firmware/common/hackrf_core.h | 1 + firmware/common/operacake.c | 99 +++++++++++++++++++++++++ firmware/common/operacake.h | 40 ++++++++++ firmware/hackrf_usb/CMakeLists.txt | 2 + firmware/hackrf_usb/hackrf_usb.c | 4 + firmware/hackrf_usb/usb_api_operacake.c | 37 +++++++++ firmware/hackrf_usb/usb_api_operacake.h | 31 ++++++++ 7 files changed, 214 insertions(+) create mode 100644 firmware/common/operacake.c create mode 100644 firmware/common/operacake.h create mode 100644 firmware/hackrf_usb/usb_api_operacake.c create mode 100644 firmware/hackrf_usb/usb_api_operacake.h diff --git a/firmware/common/hackrf_core.h b/firmware/common/hackrf_core.h index a1b9b00f..974fa5ee 100644 --- a/firmware/common/hackrf_core.h +++ b/firmware/common/hackrf_core.h @@ -240,6 +240,7 @@ extern w25q80bv_driver_t spi_flash; extern sgpio_config_t sgpio_config; extern rf_path_t rf_path; extern jtag_t jtag_cpld; +extern i2c_bus_t i2c0; void cpu_clock_init(void); void cpu_clock_pll1_low_speed(void); diff --git a/firmware/common/operacake.c b/firmware/common/operacake.c new file mode 100644 index 00000000..9ec35b1f --- /dev/null +++ b/firmware/common/operacake.c @@ -0,0 +1,99 @@ +/* + * Copyright 2016 Dominic Spill + * + * 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 "operacake.h" +#include "hackrf_core.h" + +#define OPERACAKE_PIN_OE (1<<7) +#define OPERACAKE_PIN_U2CTRL1 (1<<6) +#define OPERACAKE_PIN_U2CTRL0 (1<<5) +#define OPERACAKE_PIN_U3CTRL1 (1<<4) +#define OPERACAKE_PIN_U3CTRL0 (1<<3) +#define OPERACAKE_PIN_U1CTRL (1<<2) +#define OPERACAKE_PIN_LEDEN2 (1<<1) +#define OPERACAKE_PIN_LEDEN (1<<0) + +#define OPERACAKE_PA1 (!OPERACAKE_PIN_U2CTRL0 | !OPERACAKE_PIN_U2CTRL1) +#define OPERACAKE_PA2 (OPERACAKE_PIN_U2CTRL0 | !OPERACAKE_PIN_U2CTRL1) +#define OPERACAKE_PA3 (!OPERACAKE_PIN_U2CTRL0 | OPERACAKE_PIN_U2CTRL1) +#define OPERACAKE_PA4 (OPERACAKE_PIN_U2CTRL0 | OPERACAKE_PIN_U2CTRL1) + +#define OPERACAKE_PB1 (!OPERACAKE_PIN_U3CTRL0 | !OPERACAKE_PIN_U3CTRL1) +#define OPERACAKE_PB2 (OPERACAKE_PIN_U3CTRL0 | !OPERACAKE_PIN_U3CTRL1) +#define OPERACAKE_PB3 (!OPERACAKE_PIN_U3CTRL0 | OPERACAKE_PIN_U3CTRL1) +#define OPERACAKE_PB4 (OPERACAKE_PIN_U3CTRL0 | OPERACAKE_PIN_U3CTRL1) + +#define OPERACAKE_CROSSOVER (!OPERACAKE_PIN_U1CTRL) +#define OPERACAKE_EN_LEDS (OPERACAKE_PIN_LEDEN2 | !OPERACAKE_PIN_LEDEN) + +#define OPERACAKE_REG_INPUT 0x00 +#define OPERACAKE_REG_OUTPUT 0x01 +#define OPERACAKE_REG_POLARITY 0x02 +#define OPERACAKE_REG_CONFIG 0x03 + +#define OPERACAKE_DEFAULT_OUTPUT (!OPERACAKE_PIN_OE | OPERACAKE_PA1 | OPERACAKE_PB1 | OPERACAKE_EN_LEDS) +#define OPERACAKE_DEFAULT_POLARITY (0x00)//(OPERACAKE_PIN_OE | OPERACAKE_PIN_LEDEN) +#define OPERACAKE_CONFIG_ALL_OUTPUT (0x00) + +typedef struct { + i2c_bus_t* const bus; + uint8_t i2c_address; +} operacake_driver_t; + +operacake_driver_t operacake_driver = { + .bus = &i2c0, + .i2c_address = 0x18, +}; + +uint8_t operacake_read_single(operacake_driver_t* drv, uint8_t reg); +void operacake_write(operacake_driver_t* drv, const uint8_t* const data, const size_t data_count); + + +uint8_t operacake_init(void) { + /* TODO: detect Operacake */ + uint8_t polarity_data[] = {OPERACAKE_REG_POLARITY, + OPERACAKE_DEFAULT_POLARITY}; + operacake_write(&operacake_driver, polarity_data, 2); + uint8_t output_data[] = {OPERACAKE_REG_OUTPUT, + OPERACAKE_DEFAULT_OUTPUT}; + operacake_write(&operacake_driver, output_data, 2); + const uint8_t config_data[] = {OPERACAKE_REG_CONFIG, + OPERACAKE_CONFIG_ALL_OUTPUT}; + operacake_write(&operacake_driver, config_data, 2); + return 0; +} + +uint8_t operacake_set_ports(uint8_t PA, uint8_t PB) { + return PA | PB; +} + +/* read single register */ +uint8_t operacake_read_single(operacake_driver_t* drv, uint8_t reg) { + const uint8_t data_tx[] = { reg }; + uint8_t data_rx[] = { 0x00 }; + i2c_bus_transfer(drv->bus, drv->i2c_address, data_tx, 1, data_rx, 1); + return data_rx[0]; +} + +/* Write to one of the PCA9557 registers */ +void operacake_write(operacake_driver_t* drv, const uint8_t* const data, const size_t data_count) { + i2c_bus_transfer(drv->bus, drv->i2c_address, data, data_count, NULL, 0); +} diff --git a/firmware/common/operacake.h b/firmware/common/operacake.h new file mode 100644 index 00000000..33c35a4f --- /dev/null +++ b/firmware/common/operacake.h @@ -0,0 +1,40 @@ +/* + * Copyright 2016 Dominic Spill + * + * 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 __OPERACAKE_H +#define __OPERACAKE_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include +#include "i2c_bus.h" + +uint8_t operacake_init(void); +uint8_t operacake_set_ports(uint8_t PA, uint8_t PB); + +#ifdef __cplusplus +} +#endif + +#endif /* __OPERACAKE_H */ diff --git a/firmware/hackrf_usb/CMakeLists.txt b/firmware/hackrf_usb/CMakeLists.txt index 10ee4ffb..5f2252aa 100644 --- a/firmware/hackrf_usb/CMakeLists.txt +++ b/firmware/hackrf_usb/CMakeLists.txt @@ -42,6 +42,8 @@ set(SRC_M4 usb_api_register.c usb_api_spiflash.c usb_api_transceiver.c + "${PATH_HACKRF_FIRMWARE_COMMON}/operacake.c" + usb_api_operacake.c "${PATH_HACKRF_FIRMWARE_COMMON}/usb_queue.c" "${PATH_HACKRF_FIRMWARE_COMMON}/fault_handler.c" "${PATH_HACKRF_FIRMWARE_COMMON}/cpld_jtag.c" diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index 2c5ec3d0..bea6add6 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -40,6 +40,8 @@ #include "usb_api_cpld.h" #include "usb_api_register.h" #include "usb_api_spiflash.h" +#include "usb_api_operacake.h" +#include "operacake.h" #include "usb_api_transceiver.h" #include "sgpio_isr.h" @@ -140,6 +142,7 @@ static const usb_request_handler_fn vendor_request_handler[] = { #endif usb_vendor_request_set_freq_explicit, usb_vendor_request_read_wcid, // USB_WCID_VENDOR_REQ + usb_vendor_request_operacake_set_ports }; static const uint32_t vendor_request_handler_count = @@ -237,6 +240,7 @@ int main(void) { usb_run(&usb_device); rf_path_init(&rf_path); + operacake_init(); unsigned int phase = 0; while(true) { diff --git a/firmware/hackrf_usb/usb_api_operacake.c b/firmware/hackrf_usb/usb_api_operacake.c new file mode 100644 index 00000000..7ac4da81 --- /dev/null +++ b/firmware/hackrf_usb/usb_api_operacake.c @@ -0,0 +1,37 @@ +/* + * Copyright 2016 Dominic Spill + * + * 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 "usb_api_operacake.h" +#include "usb_queue.h" + +#include +#include +#include + +usb_request_status_t usb_vendor_request_operacake_set_ports( + usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) +{ + if (stage == USB_TRANSFER_STAGE_SETUP) { + /* TODO: implement something */ + usb_transfer_schedule_ack(endpoint->in); + } + return USB_REQUEST_STATUS_OK; +} diff --git a/firmware/hackrf_usb/usb_api_operacake.h b/firmware/hackrf_usb/usb_api_operacake.h new file mode 100644 index 00000000..b2f4f890 --- /dev/null +++ b/firmware/hackrf_usb/usb_api_operacake.h @@ -0,0 +1,31 @@ +/* + * Copyright 2016 Dominic Spill + * + * 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 __USB_API_OPERACAKE_H__ +#define __USB_API_OPERACAKE_H__ + +#include +#include + +usb_request_status_t usb_vendor_request_operacake_set_ports( + usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); + +#endif /* end of include guard: __USB_API_OPERACAKE_H__ */ From bd1111a2e3645c80fafc62441cd42be5635f5ada Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Tue, 13 Dec 2016 19:23:19 -0700 Subject: [PATCH 03/10] Fix silly polarity issues --- firmware/common/operacake.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/firmware/common/operacake.c b/firmware/common/operacake.c index 9ec35b1f..50bc9339 100644 --- a/firmware/common/operacake.c +++ b/firmware/common/operacake.c @@ -31,26 +31,27 @@ #define OPERACAKE_PIN_LEDEN2 (1<<1) #define OPERACAKE_PIN_LEDEN (1<<0) -#define OPERACAKE_PA1 (!OPERACAKE_PIN_U2CTRL0 | !OPERACAKE_PIN_U2CTRL1) -#define OPERACAKE_PA2 (OPERACAKE_PIN_U2CTRL0 | !OPERACAKE_PIN_U2CTRL1) -#define OPERACAKE_PA3 (!OPERACAKE_PIN_U2CTRL0 | OPERACAKE_PIN_U2CTRL1) +#define OPERACAKE_PA1 (0) +#define OPERACAKE_PA2 (OPERACAKE_PIN_U2CTRL0) +#define OPERACAKE_PA3 (OPERACAKE_PIN_U2CTRL1) #define OPERACAKE_PA4 (OPERACAKE_PIN_U2CTRL0 | OPERACAKE_PIN_U2CTRL1) -#define OPERACAKE_PB1 (!OPERACAKE_PIN_U3CTRL0 | !OPERACAKE_PIN_U3CTRL1) -#define OPERACAKE_PB2 (OPERACAKE_PIN_U3CTRL0 | !OPERACAKE_PIN_U3CTRL1) -#define OPERACAKE_PB3 (!OPERACAKE_PIN_U3CTRL0 | OPERACAKE_PIN_U3CTRL1) +#define OPERACAKE_PB1 (0) +#define OPERACAKE_PB2 (OPERACAKE_PIN_U3CTRL0) +#define OPERACAKE_PB3 (OPERACAKE_PIN_U3CTRL1) #define OPERACAKE_PB4 (OPERACAKE_PIN_U3CTRL0 | OPERACAKE_PIN_U3CTRL1) -#define OPERACAKE_CROSSOVER (!OPERACAKE_PIN_U1CTRL) -#define OPERACAKE_EN_LEDS (OPERACAKE_PIN_LEDEN2 | !OPERACAKE_PIN_LEDEN) +#define OPERACAKE_CROSSOVER (0) +#define OPERACAKE_EN_LEDS (OPERACAKE_PIN_LEDEN2) #define OPERACAKE_REG_INPUT 0x00 #define OPERACAKE_REG_OUTPUT 0x01 #define OPERACAKE_REG_POLARITY 0x02 #define OPERACAKE_REG_CONFIG 0x03 -#define OPERACAKE_DEFAULT_OUTPUT (!OPERACAKE_PIN_OE | OPERACAKE_PA1 | OPERACAKE_PB1 | OPERACAKE_EN_LEDS) -#define OPERACAKE_DEFAULT_POLARITY (0x00)//(OPERACAKE_PIN_OE | OPERACAKE_PIN_LEDEN) +#define OPERACAKE_DEFAULT_OUTPUT (OPERACAKE_PIN_OE | OPERACAKE_PIN_U1CTRL | \ + OPERACAKE_PA1 | OPERACAKE_PB1 | \ + OPERACAKE_EN_LEDS) #define OPERACAKE_CONFIG_ALL_OUTPUT (0x00) typedef struct { @@ -69,9 +70,6 @@ void operacake_write(operacake_driver_t* drv, const uint8_t* const data, const s uint8_t operacake_init(void) { /* TODO: detect Operacake */ - uint8_t polarity_data[] = {OPERACAKE_REG_POLARITY, - OPERACAKE_DEFAULT_POLARITY}; - operacake_write(&operacake_driver, polarity_data, 2); uint8_t output_data[] = {OPERACAKE_REG_OUTPUT, OPERACAKE_DEFAULT_OUTPUT}; operacake_write(&operacake_driver, output_data, 2); From 1cec9ad4db974612ca241028fe26844c0f6a3e17 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Mon, 19 Dec 2016 21:50:29 -0700 Subject: [PATCH 04/10] Add Operacake USB API (firmware) --- firmware/common/operacake.c | 103 +++++++++++++++++------- firmware/common/operacake.h | 10 +++ firmware/hackrf_usb/usb_api_operacake.c | 4 +- 3 files changed, 85 insertions(+), 32 deletions(-) diff --git a/firmware/common/operacake.c b/firmware/common/operacake.c index 50bc9339..02d16851 100644 --- a/firmware/common/operacake.c +++ b/firmware/common/operacake.c @@ -22,36 +22,39 @@ #include "operacake.h" #include "hackrf_core.h" -#define OPERACAKE_PIN_OE (1<<7) -#define OPERACAKE_PIN_U2CTRL1 (1<<6) -#define OPERACAKE_PIN_U2CTRL0 (1<<5) -#define OPERACAKE_PIN_U3CTRL1 (1<<4) -#define OPERACAKE_PIN_U3CTRL0 (1<<3) -#define OPERACAKE_PIN_U1CTRL (1<<2) -#define OPERACAKE_PIN_LEDEN2 (1<<1) -#define OPERACAKE_PIN_LEDEN (1<<0) +#define OPERACAKE_PIN_OE(x) (x<<7) +#define OPERACAKE_PIN_U2CTRL1(x) (x<<6) +#define OPERACAKE_PIN_U2CTRL0(x) (x<<5) +#define OPERACAKE_PIN_U3CTRL1(x) (x<<4) +#define OPERACAKE_PIN_U3CTRL0(x) (x<<3) +#define OPERACAKE_PIN_U1CTRL(x) (x<<2) +#define OPERACAKE_PIN_LEDEN2(x) (x<<1) +#define OPERACAKE_PIN_LEDEN(x) (x<<0) -#define OPERACAKE_PA1 (0) -#define OPERACAKE_PA2 (OPERACAKE_PIN_U2CTRL0) -#define OPERACAKE_PA3 (OPERACAKE_PIN_U2CTRL1) -#define OPERACAKE_PA4 (OPERACAKE_PIN_U2CTRL0 | OPERACAKE_PIN_U2CTRL1) +#define OPERACAKE_PORT_A1 (OPERACAKE_PIN_U2CTRL0(0) | OPERACAKE_PIN_U2CTRL1(0)) +#define OPERACAKE_PORT_A2 (OPERACAKE_PIN_U2CTRL0(1) | OPERACAKE_PIN_U2CTRL1(0)) +#define OPERACAKE_PORT_A3 (OPERACAKE_PIN_U2CTRL0(0) | OPERACAKE_PIN_U2CTRL1(1)) +#define OPERACAKE_PORT_A4 (OPERACAKE_PIN_U2CTRL0(1) | OPERACAKE_PIN_U2CTRL1(1)) -#define OPERACAKE_PB1 (0) -#define OPERACAKE_PB2 (OPERACAKE_PIN_U3CTRL0) -#define OPERACAKE_PB3 (OPERACAKE_PIN_U3CTRL1) -#define OPERACAKE_PB4 (OPERACAKE_PIN_U3CTRL0 | OPERACAKE_PIN_U3CTRL1) +#define OPERACAKE_PORT_B1 (OPERACAKE_PIN_U3CTRL0(0) | OPERACAKE_PIN_U3CTRL1(0)) +#define OPERACAKE_PORT_B2 (OPERACAKE_PIN_U3CTRL0(1) | OPERACAKE_PIN_U3CTRL1(0)) +#define OPERACAKE_PORT_B3 (OPERACAKE_PIN_U3CTRL0(0) | OPERACAKE_PIN_U3CTRL1(1)) +#define OPERACAKE_PORT_B4 (OPERACAKE_PIN_U3CTRL0(1) | OPERACAKE_PIN_U3CTRL1(1)) -#define OPERACAKE_CROSSOVER (0) -#define OPERACAKE_EN_LEDS (OPERACAKE_PIN_LEDEN2) +#define OPERACAKE_SAMESIDE OPERACAKE_PIN_U1CTRL(1) +#define OPERACAKE_CROSSOVER OPERACAKE_PIN_U1CTRL(0) +#define OPERACAKE_EN_LEDS (OPERACAKE_PIN_LEDEN2(1) | OPERACAKE_PIN_LEDEN2(0)) +#define OPERACAKE_GPIO_EN OPERACAKE_PIN_OE(0) +#define OPERACAKE_GPIO_DISABLE OPERACAKE_PIN_OE(1) #define OPERACAKE_REG_INPUT 0x00 #define OPERACAKE_REG_OUTPUT 0x01 #define OPERACAKE_REG_POLARITY 0x02 #define OPERACAKE_REG_CONFIG 0x03 -#define OPERACAKE_DEFAULT_OUTPUT (OPERACAKE_PIN_OE | OPERACAKE_PIN_U1CTRL | \ - OPERACAKE_PA1 | OPERACAKE_PB1 | \ - OPERACAKE_EN_LEDS) +#define OPERACAKE_DEFAULT_OUTPUT (OPERACAKE_GPIO_DISABLE | OPERACAKE_SAMESIDE \ + | OPERACAKE_PORT_A1 | OPERACAKE_PORT_B1 \ + | OPERACAKE_EN_LEDS) #define OPERACAKE_CONFIG_ALL_OUTPUT (0x00) typedef struct { @@ -79,16 +82,58 @@ uint8_t operacake_init(void) { return 0; } -uint8_t operacake_set_ports(uint8_t PA, uint8_t PB) { - return PA | PB; +uint8_t port_to_pins(uint8_t port) { + switch(port) { + case OPERACAKE_PA1: + return OPERACAKE_PORT_A1; + case OPERACAKE_PA2: + return OPERACAKE_PORT_A2; + case OPERACAKE_PA3: + return OPERACAKE_PORT_A3; + case OPERACAKE_PA4: + return OPERACAKE_PORT_A4; + + case OPERACAKE_PB1: + return OPERACAKE_PORT_B1; + case OPERACAKE_PB2: + return OPERACAKE_PORT_B2; + case OPERACAKE_PB3: + return OPERACAKE_PORT_B3; + case OPERACAKE_PB4: + return OPERACAKE_PORT_B4; + } + return 0xFF; } -/* read single register */ -uint8_t operacake_read_single(operacake_driver_t* drv, uint8_t reg) { - const uint8_t data_tx[] = { reg }; - uint8_t data_rx[] = { 0x00 }; - i2c_bus_transfer(drv->bus, drv->i2c_address, data_tx, 1, data_rx, 1); - return data_rx[0]; +uint8_t operacake_set_ports(uint8_t PA, uint8_t PB) { + uint8_t side, pa, pb; + uint8_t output_data[2]; + /* Start with some error checking, + * which should have been done either + * on the host or elsewhere in firmware + */ + if((PA > OPERACAKE_PB4) || (PB > OPERACAKE_PB4)) { + return 1; + } + /* Check which side PA and PB are on */ + if(((PA <= OPERACAKE_PA4) && (PB <= OPERACAKE_PA4)) + || ((PA > OPERACAKE_PA4) && (PB > OPERACAKE_PA4))) { + return 1; + } + + if(PA > OPERACAKE_PA4) + side = OPERACAKE_CROSSOVER; + else + side = OPERACAKE_SAMESIDE; + + pa = port_to_pins(PA); + pb = port_to_pins(PB); + + output_data[0] = OPERACAKE_REG_OUTPUT; + output_data[1] = (OPERACAKE_GPIO_DISABLE | side + | pa | pb | OPERACAKE_EN_LEDS); + operacake_write(&operacake_driver, output_data, 2); + return 0; } /* Write to one of the PCA9557 registers */ diff --git a/firmware/common/operacake.h b/firmware/common/operacake.h index 33c35a4f..20a9a998 100644 --- a/firmware/common/operacake.h +++ b/firmware/common/operacake.h @@ -30,6 +30,16 @@ extern "C" #include #include "i2c_bus.h" +#define OPERACAKE_PA1 0 +#define OPERACAKE_PA2 1 +#define OPERACAKE_PA3 2 +#define OPERACAKE_PA4 3 + +#define OPERACAKE_PB1 4 +#define OPERACAKE_PB2 5 +#define OPERACAKE_PB3 6 +#define OPERACAKE_PB4 7 + uint8_t operacake_init(void); uint8_t operacake_set_ports(uint8_t PA, uint8_t PB); diff --git a/firmware/hackrf_usb/usb_api_operacake.c b/firmware/hackrf_usb/usb_api_operacake.c index 7ac4da81..c93ec494 100644 --- a/firmware/hackrf_usb/usb_api_operacake.c +++ b/firmware/hackrf_usb/usb_api_operacake.c @@ -22,15 +22,13 @@ #include "usb_api_operacake.h" #include "usb_queue.h" -#include -#include #include usb_request_status_t usb_vendor_request_operacake_set_ports( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { if (stage == USB_TRANSFER_STAGE_SETUP) { - /* TODO: implement something */ + operacake_set_ports(endpoint->setup.index, endpoint->setup.value); usb_transfer_schedule_ack(endpoint->in); } return USB_REQUEST_STATUS_OK; From 9d7b55ccb19072e029cfd2d84442bb0f8fb7e70d Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Thu, 22 Dec 2016 17:22:04 +0000 Subject: [PATCH 05/10] Add host functions to set operacake ports --- host/libhackrf/src/hackrf.c | 37 +++++++++++++++++++++++++++++++++++++ host/libhackrf/src/hackrf.h | 11 +++++++++++ 2 files changed, 48 insertions(+) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index a759fb3a..c9ccd858 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -67,6 +67,9 @@ typedef enum { HACKRF_VENDOR_REQUEST_SET_TXVGA_GAIN = 21, HACKRF_VENDOR_REQUEST_ANTENNA_ENABLE = 23, HACKRF_VENDOR_REQUEST_SET_FREQ_EXPLICIT = 24, + HACKRF_VENDOR_REQUEST_READ_WCID = 25, + HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS = 26, + HACKRF_VENDOR_REQUEST_GET_OPERACAKES = 27, } hackrf_vendor_request; typedef enum { @@ -1695,6 +1698,40 @@ uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz) return p->bandwidth_hz; } +/* Set Operacake ports */ +int ADDCALL hackrf_set_operacake_ports(hackrf_device* device, + const uint8_t port_a, + const uint8_t port_b) +{ + int result; + /* Error checking */ + if((port_a > OPERACAKE_PB4) || (port_b > OPERACAKE_PB4)) { + return HACKRF_ERROR_INVALID_PARAM; + } + /* Check which side PA and PB are on */ + if(((port_a <= OPERACAKE_PA4) && (port_b <= OPERACAKE_PA4)) + || ((port_a > OPERACAKE_PA4) && (port_b > OPERACAKE_PA4))) { + return HACKRF_ERROR_INVALID_PARAM; + } + result = libusb_control_transfer( + device->usb_device, + LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, + HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS, + port_a, + port_b, + NULL, + 0, + 0 + ); + + if (result != 0) + { + return HACKRF_ERROR_LIBUSB; + } else { + return HACKRF_SUCCESS; + } +} + #ifdef __cplusplus } // __cplusplus defined. #endif diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index 7ac0530f..e4e0d1c9 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -83,6 +83,17 @@ enum rf_path_filter { RF_PATH_FILTER_HIGH_PASS = 2, }; +enum operacake_ports { + OPERACAKE_PA1 = 0, + OPERACAKE_PA2 = 1, + OPERACAKE_PA3 = 2, + OPERACAKE_PA4 = 3, + OPERACAKE_PB1 = 4, + OPERACAKE_PB2 = 5, + OPERACAKE_PB3 = 6, + OPERACAKE_PB4 = 7, +}; + typedef struct hackrf_device hackrf_device; typedef struct { From c54e31f397efed25d46e691c02d23b0cbb168800 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 23 Dec 2016 21:59:45 +0000 Subject: [PATCH 06/10] Add support for multiple operacake boards connected to one HackRF --- firmware/common/operacake.c | 65 +++++++++++++++---------- firmware/common/operacake.h | 3 ++ firmware/hackrf_usb/hackrf_usb.c | 1 + firmware/hackrf_usb/usb_api_operacake.c | 12 ++++- firmware/hackrf_usb/usb_api_operacake.h | 3 ++ host/hackrf-tools/src/hackrf_info.c | 18 ++++++- host/libhackrf/src/hackrf.c | 29 ++++++++++- host/libhackrf/src/hackrf.h | 6 +++ 8 files changed, 106 insertions(+), 31 deletions(-) diff --git a/firmware/common/operacake.c b/firmware/common/operacake.c index 02d16851..3dad30c9 100644 --- a/firmware/common/operacake.c +++ b/firmware/common/operacake.c @@ -57,31 +57,50 @@ | OPERACAKE_EN_LEDS) #define OPERACAKE_CONFIG_ALL_OUTPUT (0x00) -typedef struct { - i2c_bus_t* const bus; - uint8_t i2c_address; -} operacake_driver_t; +#define OPERACAKE_DEFAULT_ADDRESS 0x18 -operacake_driver_t operacake_driver = { - .bus = &i2c0, - .i2c_address = 0x18, -}; +i2c_bus_t* const oc_bus = &i2c0; +uint8_t operacake_boards[8] = {0,0,0,0,0,0,0,0}; -uint8_t operacake_read_single(operacake_driver_t* drv, uint8_t reg); -void operacake_write(operacake_driver_t* drv, const uint8_t* const data, const size_t data_count); +/* read single register */ +uint8_t operacake_read_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg) { + const uint8_t data_tx[] = { reg }; + uint8_t data_rx[] = { 0x00 }; + i2c_bus_transfer(bus, address, data_tx, 1, data_rx, 1); + return data_rx[0]; +} +/* Write to one of the PCA9557 registers */ +void operacake_write_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg, uint8_t value) { + const uint8_t data[] = {reg, value}; + i2c_bus_transfer(bus, address, data, 2, NULL, 0); +} uint8_t operacake_init(void) { - /* TODO: detect Operacake */ - uint8_t output_data[] = {OPERACAKE_REG_OUTPUT, - OPERACAKE_DEFAULT_OUTPUT}; - operacake_write(&operacake_driver, output_data, 2); - const uint8_t config_data[] = {OPERACAKE_REG_CONFIG, - OPERACAKE_CONFIG_ALL_OUTPUT}; - operacake_write(&operacake_driver, config_data, 2); + int reg, addr, i, j = 0; + /* Find connected operacakes */ + for(i=0; i<8; i++) { + addr = OPERACAKE_DEFAULT_ADDRESS | i; + operacake_write_reg(oc_bus, addr, OPERACAKE_REG_OUTPUT, + OPERACAKE_DEFAULT_OUTPUT); + operacake_write_reg(oc_bus, addr, OPERACAKE_REG_CONFIG, + OPERACAKE_CONFIG_ALL_OUTPUT); + reg = operacake_read_reg(oc_bus, addr, OPERACAKE_REG_CONFIG); + if(reg==OPERACAKE_CONFIG_ALL_OUTPUT) + operacake_boards[j++] = addr; + } return 0; } +// uint8_t operacake_get_boards(uint8_t *boards) { +// int i, j = 0; +// for(i=0; i<8; i++) { +// if(operacake_boards & (1<bus, drv->i2c_address, data, data_count, NULL, 0); -} diff --git a/firmware/common/operacake.h b/firmware/common/operacake.h index 20a9a998..78dba000 100644 --- a/firmware/common/operacake.h +++ b/firmware/common/operacake.h @@ -40,6 +40,9 @@ extern "C" #define OPERACAKE_PB3 6 #define OPERACAKE_PB4 7 +/* 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_set_ports(uint8_t PA, uint8_t PB); diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index bea6add6..2d5fd2ff 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -142,6 +142,7 @@ static const usb_request_handler_fn vendor_request_handler[] = { #endif usb_vendor_request_set_freq_explicit, usb_vendor_request_read_wcid, // USB_WCID_VENDOR_REQ + usb_vendor_request_operacake_get_boards, usb_vendor_request_operacake_set_ports }; diff --git a/firmware/hackrf_usb/usb_api_operacake.c b/firmware/hackrf_usb/usb_api_operacake.c index c93ec494..ce420860 100644 --- a/firmware/hackrf_usb/usb_api_operacake.c +++ b/firmware/hackrf_usb/usb_api_operacake.c @@ -24,8 +24,18 @@ #include +usb_request_status_t usb_vendor_request_operacake_get_boards( + usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) +{ + if (stage == USB_TRANSFER_STAGE_SETUP) { + usb_transfer_schedule_block(endpoint->in, operacake_boards, 8, NULL, NULL); + usb_transfer_schedule_ack(endpoint->out); + } + return USB_REQUEST_STATUS_OK; +} + usb_request_status_t usb_vendor_request_operacake_set_ports( - usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) + usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { if (stage == USB_TRANSFER_STAGE_SETUP) { operacake_set_ports(endpoint->setup.index, endpoint->setup.value); diff --git a/firmware/hackrf_usb/usb_api_operacake.h b/firmware/hackrf_usb/usb_api_operacake.h index b2f4f890..4339488d 100644 --- a/firmware/hackrf_usb/usb_api_operacake.h +++ b/firmware/hackrf_usb/usb_api_operacake.h @@ -25,6 +25,9 @@ #include #include +usb_request_status_t usb_vendor_request_operacake_get_boards( + usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); + usb_request_status_t usb_vendor_request_operacake_set_ports( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); diff --git a/host/hackrf-tools/src/hackrf_info.c b/host/hackrf-tools/src/hackrf_info.c index eed24c37..def5371d 100644 --- a/host/hackrf-tools/src/hackrf_info.c +++ b/host/hackrf-tools/src/hackrf_info.c @@ -32,9 +32,10 @@ int main(void) uint8_t board_id = BOARD_ID_INVALID; char version[255 + 1]; read_partid_serialno_t read_partid_serialno; + uint8_t operacakes[8]; hackrf_device_list_t *list; hackrf_device* device; - int i; + int i, j; result = hackrf_init(); if (result != HACKRF_SUCCESS) { @@ -98,7 +99,20 @@ int main(void) read_partid_serialno.serial_no[1], read_partid_serialno.serial_no[2], read_partid_serialno.serial_no[3]); - + + result = hackrf_get_operacake_boards(device, &operacakes[0]); + if (result != HACKRF_SUCCESS) { + fprintf(stderr, "hackrf_get_operacake_boards() failed: %s (%d)\n", + hackrf_error_name(result), result); + return EXIT_FAILURE; + } + for(j=0; j<8; j++) { + if(operacakes[j] == 0) + break; + printf("Operacake found, address: 0x%02x\n", operacakes[j]); + + } + result = hackrf_close(device); if (result != HACKRF_SUCCESS) { fprintf(stderr, "hackrf_close() failed: %s (%d)\n", diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index c9ccd858..dc7edec3 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -68,8 +68,8 @@ typedef enum { HACKRF_VENDOR_REQUEST_ANTENNA_ENABLE = 23, HACKRF_VENDOR_REQUEST_SET_FREQ_EXPLICIT = 24, HACKRF_VENDOR_REQUEST_READ_WCID = 25, - HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS = 26, - HACKRF_VENDOR_REQUEST_GET_OPERACAKES = 27, + HACKRF_VENDOR_REQUEST_OPERACAKE_GET_BOARDS = 26, + HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS = 27, } hackrf_vendor_request; typedef enum { @@ -1698,6 +1698,31 @@ uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz) return p->bandwidth_hz; } +/* Retrieve list of Operacake board addresses + * boards must be *uint8_t[8] + */ +int ADDCALL hackrf_get_operacake_boards(hackrf_device* device, uint8_t* boards) +{ + int result; + result = libusb_control_transfer( + device->usb_device, + LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, + HACKRF_VENDOR_REQUEST_OPERACAKE_GET_BOARDS, + 0, + 0, + boards, + 8, + 0 + ); + + if (result < 8) + { + return HACKRF_ERROR_LIBUSB; + } else { + return HACKRF_SUCCESS; + } +} + /* Set Operacake ports */ int ADDCALL hackrf_set_operacake_ports(hackrf_device* device, const uint8_t port_a, diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index e4e0d1c9..87e9556b 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -208,6 +208,12 @@ extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw_round_down_lt(c /* Compute best default value depending on sample rate (auto filter) */ extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz); +/* Operacake functions */ +int ADDCALL hackrf_get_operacake_boards(hackrf_device* device, uint8_t* boards); +int ADDCALL hackrf_set_operacake_ports(hackrf_device* device, + const uint8_t port_a, + const uint8_t port_b); + #ifdef __cplusplus } // __cplusplus defined. #endif From b528af46c1e647841709aaa729db238f724cd273 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Sun, 25 Dec 2016 11:01:55 +0000 Subject: [PATCH 07/10] Tidy unused operacake code and use addresses to refer to boards --- firmware/common/operacake.c | 15 +++------------ firmware/common/operacake.h | 2 +- firmware/hackrf_usb/usb_api_operacake.c | 6 +++++- host/libhackrf/src/hackrf.c | 9 +++++---- host/libhackrf/src/hackrf.h | 5 +++-- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/firmware/common/operacake.c b/firmware/common/operacake.c index 3dad30c9..ec7df4ba 100644 --- a/firmware/common/operacake.c +++ b/firmware/common/operacake.c @@ -77,7 +77,7 @@ void operacake_write_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg, uin } uint8_t operacake_init(void) { - int reg, addr, i, j = 0; + uint8_t reg, addr, i, j = 0; /* Find connected operacakes */ for(i=0; i<8; i++) { addr = OPERACAKE_DEFAULT_ADDRESS | i; @@ -92,15 +92,6 @@ uint8_t operacake_init(void) { return 0; } -// uint8_t operacake_get_boards(uint8_t *boards) { -// int i, j = 0; -// for(i=0; i<8; i++) { -// if(operacake_boards & (1<setup.index & 0xFF; + port_a = endpoint->setup.value & 0xFF; + port_b = (endpoint->setup.value >> 8) & 0xFF; if (stage == USB_TRANSFER_STAGE_SETUP) { - operacake_set_ports(endpoint->setup.index, endpoint->setup.value); + operacake_set_ports(address, port_a, port_b); usb_transfer_schedule_ack(endpoint->in); } return USB_REQUEST_STATUS_OK; diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index dc7edec3..61824cf1 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -1725,8 +1725,9 @@ int ADDCALL hackrf_get_operacake_boards(hackrf_device* device, uint8_t* boards) /* Set Operacake ports */ int ADDCALL hackrf_set_operacake_ports(hackrf_device* device, - const uint8_t port_a, - const uint8_t port_b) + uint8_t address, + uint8_t port_a, + uint8_t port_b) { int result; /* Error checking */ @@ -1742,8 +1743,8 @@ int ADDCALL hackrf_set_operacake_ports(hackrf_device* device, device->usb_device, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, HACKRF_VENDOR_REQUEST_OPERACAKE_SET_PORTS, - port_a, - port_b, + address, + port_a | (port_b<<8), NULL, 0, 0 diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index 87e9556b..ef7f0958 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -211,8 +211,9 @@ extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t /* Operacake functions */ int ADDCALL hackrf_get_operacake_boards(hackrf_device* device, uint8_t* boards); int ADDCALL hackrf_set_operacake_ports(hackrf_device* device, - const uint8_t port_a, - const uint8_t port_b); + uint8_t address, + uint8_t port_a, + uint8_t port_b); #ifdef __cplusplus } // __cplusplus defined. From 8e4850d36eb9161811f543b2a0768cb1541ef87f Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Thu, 19 Jan 2017 16:12:05 -0700 Subject: [PATCH 08/10] Add HackRF tool to change operacake ports --- firmware/hackrf_usb/usb_api_operacake.c | 6 +- host/hackrf-tools/src/CMakeLists.txt | 4 + host/hackrf-tools/src/hackrf_operacake.c | 158 +++++++++++++++++++++++ 3 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 host/hackrf-tools/src/hackrf_operacake.c diff --git a/firmware/hackrf_usb/usb_api_operacake.c b/firmware/hackrf_usb/usb_api_operacake.c index 0f46b677..d9e5affa 100644 --- a/firmware/hackrf_usb/usb_api_operacake.c +++ b/firmware/hackrf_usb/usb_api_operacake.c @@ -38,9 +38,9 @@ usb_request_status_t usb_vendor_request_operacake_set_ports( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { uint8_t address, port_a, port_b; - address = endpoint->setup.index & 0xFF; - port_a = endpoint->setup.value & 0xFF; - port_b = (endpoint->setup.value >> 8) & 0xFF; + address = endpoint->setup.value & 0xFF; + port_a = endpoint->setup.index & 0xFF; + port_b = (endpoint->setup.index >> 8) & 0xFF; if (stage == USB_TRANSFER_STAGE_SETUP) { operacake_set_ports(address, port_a, port_b); usb_transfer_schedule_ack(endpoint->in); diff --git a/host/hackrf-tools/src/CMakeLists.txt b/host/hackrf-tools/src/CMakeLists.txt index 373e36b4..58fa23c5 100644 --- a/host/hackrf-tools/src/CMakeLists.txt +++ b/host/hackrf-tools/src/CMakeLists.txt @@ -50,6 +50,9 @@ install(TARGETS hackrf_cpldjtag RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR}) add_executable(hackrf_info hackrf_info.c) install(TARGETS hackrf_info RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR}) +add_executable(hackrf_operacake hackrf_operacake.c) +install(TARGETS hackrf_operacake RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR}) + if(NOT libhackrf_SOURCE_DIR) include_directories(${LIBHACKRF_INCLUDE_DIR}) LIST(APPEND TOOLS_LINK_LIBS ${LIBHACKRF_LIBRARIES}) @@ -69,3 +72,4 @@ target_link_libraries(hackrf_rffc5071 ${TOOLS_LINK_LIBS}) target_link_libraries(hackrf_spiflash ${TOOLS_LINK_LIBS}) target_link_libraries(hackrf_cpldjtag ${TOOLS_LINK_LIBS}) target_link_libraries(hackrf_info ${TOOLS_LINK_LIBS}) +target_link_libraries(hackrf_operacake ${TOOLS_LINK_LIBS}) diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c new file mode 100644 index 00000000..086af5cb --- /dev/null +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -0,0 +1,158 @@ +/* + * Copyright 2016 Dominic Spill + * + * 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 + +#include +#include +#include + +#ifndef bool +typedef int bool; +#define true 1 +#define false 0 +#endif + +static void usage() { + printf("\nUsage:\n"); + printf("\t-s, --serial : specify a particular device by serial number\n"); + printf("\t-d, --device : specify a particular device by number\n"); + printf("\t-o, --address : specify a particular operacake by address [default: 0x00]\n"); + printf("\t-a : set port A connection\n"); + printf("\t-b : set port B connection\n"); + printf("\t-v: verbose, list available operacake boards\n"); +} + +static struct option long_options[] = { + { "device", no_argument, 0, 'd' }, + { "serial", no_argument, 0, 's' }, + { "address", no_argument, 0, 'o' }, + { 0, 0, 0, 0 }, +}; + +int parse_int(char* const s, uint16_t* const value) { + char* s_end = s; + const long long_value = strtol(s, &s_end, 10); + if( (s != s_end) && (*s_end == 0) ) { + *value = (uint16_t)long_value; + return HACKRF_SUCCESS; + } else { + return HACKRF_ERROR_INVALID_PARAM; + } +} + +int main(int argc, char** argv) { + int opt; + const char* serial_number = NULL; + int device_index = 0; + int operacake_address = 0; + int port_a = 0; + int port_b = 0; + int verbose = 0; + uint8_t operacakes[8]; + int i = 0; + hackrf_device* device = NULL; + int option_index = 0; + + int result = hackrf_init(); + if( result ) { + printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result); + return -1; + } + + while( (opt = getopt_long(argc, argv, "d:s:o:a:b:v", long_options, &option_index)) != EOF ) { + switch( opt ) { + case 'd': + device_index = atoi(optarg); + break; + + case 's': + serial_number = optarg; + break; + + case 'o': + operacake_address = atoi(optarg); + break; + + case 'a': + port_a = atoi(optarg); + break; + + case 'b': + port_b = atoi(optarg); + break; + + case 'v': + verbose = 1; + break; + + default: + usage(); + } + + if( result != HACKRF_SUCCESS ) { + printf("argument error: %s (%d)\n", hackrf_error_name(result), result); + break; + } + } + + if(serial_number != NULL) { + result = hackrf_open_by_serial(serial_number, &device); + } else { + hackrf_device_list_t* device_list = hackrf_device_list(); + if(device_list->devicecount <= 0) { + result = HACKRF_ERROR_NOT_FOUND; + } else { + result = hackrf_device_list_open(device_list, device_index, &device); + } + } + + if( result ) { + printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); + return -1; + } + + if(verbose) { + hackrf_get_operacake_boards(device, operacakes); + printf("Operacakes found:\n"); + for(i=0; i<8; i++) { + if(operacakes[i] !=0) + printf("%d\n", operacakes[i]); + } + printf("\n"); + } + + result = hackrf_set_operacake_ports(device, operacake_address, port_a, port_b); + if( result ) { + printf("hackrf_set_operacake_ports() failed: %s (%d)\n", hackrf_error_name(result), result); + return -1; + } + + result = hackrf_close(device); + if( result ) { + printf("hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result); + return -1; + } + + hackrf_exit(); + + return 0; +} From 18f014e11f143b424aa3e8d9988335519f241318 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Mon, 23 Jan 2017 16:11:47 -0700 Subject: [PATCH 09/10] Remove duplicate hackrf_operacake definition --- host/hackrf-tools/src/CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/host/hackrf-tools/src/CMakeLists.txt b/host/hackrf-tools/src/CMakeLists.txt index 0896990a..a006c6ac 100644 --- a/host/hackrf-tools/src/CMakeLists.txt +++ b/host/hackrf-tools/src/CMakeLists.txt @@ -37,12 +37,9 @@ SET(TOOLS hackrf_spiflash hackrf_cpldjtag hackrf_info - hackrf_operacake + hackrf_operacake ) -add_executable(hackrf_operacake hackrf_operacake.c) -install(TARGETS hackrf_operacake RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR}) - if(NOT libhackrf_SOURCE_DIR) include_directories(${LIBHACKRF_INCLUDE_DIR}) LIST(APPEND TOOLS_LINK_LIBS ${LIBHACKRF_LIBRARIES}) From b7edf86afd4d68b8a0f15dbe222a6a5c4975ba68 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Mon, 23 Jan 2017 17:52:27 -0700 Subject: [PATCH 10/10] Remove duplicate hackrf_sweep definition --- host/hackrf-tools/src/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/host/hackrf-tools/src/CMakeLists.txt b/host/hackrf-tools/src/CMakeLists.txt index 692e843f..6450623f 100644 --- a/host/hackrf-tools/src/CMakeLists.txt +++ b/host/hackrf-tools/src/CMakeLists.txt @@ -41,9 +41,6 @@ SET(TOOLS hackrf_sweep ) -add_executable(hackrf_sweep hackrf_sweep.c) -install(TARGETS hackrf_sweep RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR}) - if(NOT libhackrf_SOURCE_DIR) include_directories(${LIBHACKRF_INCLUDE_DIR}) LIST(APPEND TOOLS_LINK_LIBS ${LIBHACKRF_LIBRARIES})