From 0293cf23dbc037da2139a09699edac84b6de6ceb Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Tue, 13 Jul 2021 16:37:22 +0100 Subject: [PATCH 1/3] Opera Cake: use 0-7 instead of I2C addresses & bump USB API version --- firmware/common/operacake.c | 25 +++++++++++++++++++----- firmware/hackrf_usb/usb_descriptor.c | 2 +- host/hackrf-tools/src/hackrf_info.c | 2 +- host/hackrf-tools/src/hackrf_operacake.c | 2 +- host/libhackrf/src/hackrf.c | 10 +++++++--- host/libhackrf/src/hackrf.h | 1 + 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/firmware/common/operacake.c b/firmware/common/operacake.c index b5033b54..5cbf77c8 100644 --- a/firmware/common/operacake.c +++ b/firmware/common/operacake.c @@ -68,14 +68,27 @@ #define OPERACAKE_POLARITY_NORMAL (0x00) -#define OPERACAKE_DEFAULT_ADDRESS 0x18 +#define OPERACAKE_ADDRESS_DEFAULT 0x18 +#define OPERACAKE_ADDRESS_INVALID 0xFF i2c_bus_t* const oc_bus = &i2c0; -uint8_t operacake_boards[8] = {0,0,0,0,0,0,0,0}; +uint8_t operacake_boards[8] = { + OPERACAKE_ADDRESS_INVALID, + OPERACAKE_ADDRESS_INVALID, + OPERACAKE_ADDRESS_INVALID, + OPERACAKE_ADDRESS_INVALID, + OPERACAKE_ADDRESS_INVALID, + OPERACAKE_ADDRESS_INVALID, + OPERACAKE_ADDRESS_INVALID, + OPERACAKE_ADDRESS_INVALID, +}; bool allow_gpio_mode = true; /* read single register */ uint8_t operacake_read_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg) { + // Convert from Opera Cake address (0-7) to I2C address + address += OPERACAKE_ADDRESS_DEFAULT; + const uint8_t data_tx[] = { reg }; uint8_t data_rx[] = { 0x00 }; i2c_bus_transfer(bus, address, data_tx, 1, data_rx, 1); @@ -84,15 +97,17 @@ uint8_t operacake_read_reg(i2c_bus_t* const bus, uint8_t address, uint8_t reg) { /* 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) { + // Convert from Opera Cake address (0-7) to I2C address + address += OPERACAKE_ADDRESS_DEFAULT; + const uint8_t data[] = {reg, value}; i2c_bus_transfer(bus, address, data, 2, NULL, 0); } uint8_t operacake_init(bool allow_gpio) { - uint8_t reg, addr, i, j = 0; + uint8_t reg, addr, j = 0; /* Find connected operacakes */ - for(i=0; i<8; i++) { - addr = OPERACAKE_DEFAULT_ADDRESS | i; + for(addr=0; addr<8; addr++) { operacake_write_reg(oc_bus, addr, OPERACAKE_REG_OUTPUT, OPERACAKE_DEFAULT_OUTPUT); operacake_write_reg(oc_bus, addr, OPERACAKE_REG_CONFIG, diff --git a/firmware/hackrf_usb/usb_descriptor.c b/firmware/hackrf_usb/usb_descriptor.c index fd06a3e2..1d11c275 100644 --- a/firmware/hackrf_usb/usb_descriptor.c +++ b/firmware/hackrf_usb/usb_descriptor.c @@ -36,7 +36,7 @@ #define USB_PRODUCT_ID (0xFFFF) #endif -#define USB_API_VERSION (0x0104) +#define USB_API_VERSION (0x0105) #define USB_WORD(x) (x & 0xFF), ((x >> 8) & 0xFF) diff --git a/host/hackrf-tools/src/hackrf_info.c b/host/hackrf-tools/src/hackrf_info.c index e962f086..c0e51fd0 100644 --- a/host/hackrf-tools/src/hackrf_info.c +++ b/host/hackrf-tools/src/hackrf_info.c @@ -120,7 +120,7 @@ int main(void) } if(result == HACKRF_SUCCESS) { for(j=0; j<8; j++) { - if(operacakes[j] == 0) + if(operacakes[j] == HACKRF_OPERACAKE_ADDRESS_INVALID) break; printf("Operacake found, address: 0x%02x\n", operacakes[j]); } diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c index fd79f10f..7e1f24e9 100644 --- a/host/hackrf-tools/src/hackrf_operacake.c +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -267,7 +267,7 @@ int main(int argc, char** argv) { } printf("Operacakes found: "); for(i=0; i<8; i++) { - if(operacakes[i] !=0) { + if(operacakes[i] != HACKRF_OPERACAKE_ADDRESS_INVALID) { printf("\n%d", operacakes[i]); operacake_count++; } diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 4ccaeb84..aebceb9e 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -2090,12 +2090,16 @@ int ADDCALL hackrf_init_sweep(hackrf_device* device, } } -/* Retrieve list of Operacake board addresses - * boards must be *uint8_t[8] +/** + * Retrieve list of Opera Cake board addresses + * @param[in] device + * @param[out] boards List of board addresses. Must point to a `uint8_t[8]`. If the number of boards is less than 8, extra entries are filled with @ref HACKRF_OPERACAKE_ADDRESS_INVALID. + * @return @ref HACKRF_SUCCESS + * @return @ref HACKRF_ERROR_LIBUSB */ int ADDCALL hackrf_get_operacake_boards(hackrf_device* device, uint8_t* boards) { - USB_API_REQUIRED(device, 0x0102) + USB_API_REQUIRED(device, 0x0105) int result; result = libusb_control_transfer( device->usb_device, diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index 2cbac532..d1cbaea8 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -50,6 +50,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI #define SAMPLES_PER_BLOCK 8192 #define BYTES_PER_BLOCK 16384 #define MAX_SWEEP_RANGES 10 +#define HACKRF_OPERACAKE_ADDRESS_INVALID 0xFF enum hackrf_error { HACKRF_SUCCESS = 0, From 5e2e06b6208157080dfd8f158026a61ba6e24d9a Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Wed, 14 Jul 2021 18:20:04 +0100 Subject: [PATCH 2/3] hackrf_info: display Opera Cake addresses in decimal Fixes #899 --- host/hackrf-tools/src/hackrf_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/hackrf-tools/src/hackrf_info.c b/host/hackrf-tools/src/hackrf_info.c index c0e51fd0..c151d649 100644 --- a/host/hackrf-tools/src/hackrf_info.c +++ b/host/hackrf-tools/src/hackrf_info.c @@ -122,7 +122,7 @@ int main(void) for(j=0; j<8; j++) { if(operacakes[j] == HACKRF_OPERACAKE_ADDRESS_INVALID) break; - printf("Operacake found, address: 0x%02x\n", operacakes[j]); + printf("Opera Cake found, address: %d\n", operacakes[j]); } } From 6aa64a80d521b32755e48b0305274868acb3fbf8 Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Wed, 14 Jul 2021 18:33:37 +0100 Subject: [PATCH 3/3] hackrf_operacake: clarify output of list command Now that addresses are in the range 0-7, this would previously output "Operacakes found: 0" for the default board address. This is confusing as it looks like it found no Opera Cakes. --- host/hackrf-tools/src/hackrf_operacake.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c index 7e1f24e9..a597c29e 100644 --- a/host/hackrf-tools/src/hackrf_operacake.c +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -265,10 +265,10 @@ int main(int argc, char** argv) { hackrf_error_name(result), result); return EXIT_FAILURE; } - printf("Operacakes found: "); + printf("Opera Cakes found: "); for(i=0; i<8; i++) { if(operacakes[i] != HACKRF_OPERACAKE_ADDRESS_INVALID) { - printf("\n%d", operacakes[i]); + printf("\n\tAddress: %d", operacakes[i]); operacake_count++; } }