From 00f47250f2bcb48d37672dca4636afa2b7a8acb3 Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Sat, 14 Mar 2026 16:26:03 +0000 Subject: [PATCH] Skip detection of conflicting Opera Cake board if a DA7219 is detected --- firmware/common/da7219.c | 44 ++++++++++++++++++++++++++++++++ firmware/common/da7219.h | 32 +++++++++++++++++++++++ firmware/common/operacake.c | 13 ++++++++++ firmware/common/operacake.h | 1 + firmware/hackrf-common.cmake | 1 + firmware/hackrf_usb/hackrf_usb.c | 4 +++ 6 files changed, 95 insertions(+) create mode 100644 firmware/common/da7219.c create mode 100644 firmware/common/da7219.h diff --git a/firmware/common/da7219.c b/firmware/common/da7219.c new file mode 100644 index 00000000..dd175863 --- /dev/null +++ b/firmware/common/da7219.c @@ -0,0 +1,44 @@ +/* + * Copyright 2026 Great Scott Gadgets + * + * 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 "da7219.h" +#include "hackrf_core.h" +#include "i2c_bus.h" + +#define DA7219_REG_CHIP_ID1 0x81 +#define DA7219_REG_CHIP_ID2 0x82 + +i2c_bus_t* const da7219_bus = &i2c0; + +uint8_t da7219_read_reg(i2c_bus_t* const bus, uint8_t reg) +{ + const uint8_t data_tx[] = {reg}; + uint8_t data_rx[] = {0x00}; + i2c_bus_transfer(bus, DA7219_ADDRESS, data_tx, 1, data_rx, 1); + return data_rx[0]; +} + +bool da7219_detect(void) +{ + uint8_t chip_id1 = da7219_read_reg(da7219_bus, DA7219_REG_CHIP_ID1); + uint8_t chip_id2 = da7219_read_reg(da7219_bus, DA7219_REG_CHIP_ID2); + return (chip_id1 == 0x23) && (chip_id2 == 0x93); +} diff --git a/firmware/common/da7219.h b/firmware/common/da7219.h new file mode 100644 index 00000000..1c255159 --- /dev/null +++ b/firmware/common/da7219.h @@ -0,0 +1,32 @@ +/* + * Copyright 2026 Great Scott Gadgets + * + * 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 __DA7219_H +#define __DA7219_H + +#include +#include + +#define DA7219_ADDRESS 0x1A + +bool da7219_detect(void); + +#endif /* __DA7219_H */ diff --git a/firmware/common/operacake.c b/firmware/common/operacake.c index bc00ff35..7c2e85da 100644 --- a/firmware/common/operacake.c +++ b/firmware/common/operacake.c @@ -77,6 +77,7 @@ #define INVALID_RANGE 0xFF; static uint8_t current_range = INVALID_RANGE; +static uint8_t skip_address = OPERACAKE_ADDRESS_INVALID; i2c_bus_t* const oc_bus = &i2c0; @@ -122,6 +123,9 @@ uint8_t operacake_init(bool allow_gpio) { /* Find connected operacakes */ for (int addr = 0; addr < 8; addr++) { + if (addr + OPERACAKE_ADDRESS_DEFAULT == skip_address) { + continue; + } operacake_write_reg( oc_bus, addr, @@ -146,6 +150,15 @@ uint8_t operacake_init(bool allow_gpio) return 0; } +void operacake_skip_i2c_address(uint8_t address) +{ + skip_address = address; + uint8_t board_addr = address - OPERACAKE_ADDRESS_DEFAULT; + if (board_addr < 8) { + operacake_boards[board_addr].present = false; + } +} + bool operacake_is_board_present(uint8_t address) { if (address >= OPERACAKE_MAX_BOARDS) { diff --git a/firmware/common/operacake.h b/firmware/common/operacake.h index 8183cf2a..ec8bae25 100644 --- a/firmware/common/operacake.h +++ b/firmware/common/operacake.h @@ -43,6 +43,7 @@ extern "C" { #define MAX_OPERACAKE_RANGES 8 uint8_t operacake_init(bool allow_gpio); +void operacake_skip_i2c_address(uint8_t address); bool operacake_is_board_present(uint8_t address); void operacake_get_boards(uint8_t* addresses); bool operacake_set_mode(uint8_t address, uint8_t mode); diff --git a/firmware/hackrf-common.cmake b/firmware/hackrf-common.cmake index 1c6b7d6d..26a24d6e 100644 --- a/firmware/hackrf-common.cmake +++ b/firmware/hackrf-common.cmake @@ -194,6 +194,7 @@ macro(DeclareTargets) ${PATH_HACKRF_FIRMWARE_COMMON}/selftest.c ${PATH_HACKRF_FIRMWARE_COMMON}/m0_state.c ${PATH_HACKRF_FIRMWARE_COMMON}/adc.c + ${PATH_HACKRF_FIRMWARE_COMMON}/da7219.c ) if(BOARD STREQUAL "RAD1O") diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index 64457261..749e188d 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -64,6 +64,7 @@ #include "selftest.h" #include "delay.h" #include "lz4_buf.h" +#include "da7219.h" extern uint32_t __m0_start__; extern uint32_t __m0_end__; @@ -388,6 +389,9 @@ int main(void) fpga_if_xcvr_selftest(); #endif + if (da7219_detect()) { + operacake_skip_i2c_address(DA7219_ADDRESS); + } bool operacake_allow_gpio; if (hackrf_ui()->operacake_gpio_compatible()) { operacake_allow_gpio = true;