Merge pull request #1698 from miek/da7219_detection

Skip detection of conflicting Opera Cake board if a DA7219 is detected
This commit is contained in:
Michael Ossmann
2026-03-23 12:58:28 -04:00
committed by GitHub
6 changed files with 95 additions and 0 deletions

44
firmware/common/da7219.c Normal file
View File

@@ -0,0 +1,44 @@
/*
* Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com>
*
* 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);
}

32
firmware/common/da7219.h Normal file
View File

@@ -0,0 +1,32 @@
/*
* Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com>
*
* 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 <stdint.h>
#include <stdbool.h>
#define DA7219_ADDRESS 0x1A
bool da7219_detect(void);
#endif /* __DA7219_H */

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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")

View File

@@ -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;