Skip to content

Commit 70559c4

Browse files
committed
Add 'hackrf_radio_set_mode()'
1 parent d4fb086 commit 70559c4

6 files changed

Lines changed: 110 additions & 0 deletions

File tree

firmware/hackrf_usb/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ set(SRC_M4
6060
usb_api_spiflash.c
6161
usb_api_transceiver.c
6262
usb_api_operacake.c
63+
usb_api_radio.c
6364
usb_api_sweep.c
6465
usb_api_selftest.c
6566
usb_api_ui.c

firmware/hackrf_usb/hackrf_usb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include "usb_api_board_info.h"
7676
#include "usb_api_m0_state.h"
7777
#include "usb_api_operacake.h"
78+
#include "usb_api_radio.h"
7879
#include "usb_api_register.h"
7980
#include "usb_api_selftest.h"
8081
#include "usb_api_spiflash.h"
@@ -185,6 +186,7 @@ static usb_request_handler_fn vendor_request_handler[] = {
185186
usb_vendor_request_lock_radio_reg,
186187
usb_vendor_request_open,
187188
usb_vendor_request_close,
189+
usb_vendor_request_set_radio_mode,
188190
};
189191

190192
static const uint32_t vendor_request_handler_count =
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com>
3+
*
4+
* This file is part of HackRF.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2, or (at your option)
9+
* any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; see the file COPYING. If not, write to
18+
* the Free Software Foundation, Inc., 51 Franklin Street,
19+
* Boston, MA 02110-1301, USA.
20+
*/
21+
22+
#include <radio.h>
23+
#include <usb_request.h>
24+
#include <usb_type.h>
25+
26+
#include "usb_queue.h"
27+
28+
usb_request_status_t usb_vendor_request_set_radio_mode(
29+
usb_endpoint_t* const endpoint,
30+
const usb_transfer_stage_t stage)
31+
{
32+
if (stage == USB_TRANSFER_STAGE_SETUP) {
33+
radio_config_mode_t mode = endpoint->setup.value;
34+
if (!radio_set_config_mode(&radio, mode)) {
35+
return USB_REQUEST_STATUS_STALL;
36+
}
37+
usb_transfer_schedule_ack(endpoint->in);
38+
}
39+
40+
return USB_REQUEST_STATUS_OK;
41+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com>
3+
*
4+
* This file is part of HackRF.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 2, or (at your option)
9+
* any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; see the file COPYING. If not, write to
18+
* the Free Software Foundation, Inc., 51 Franklin Street,
19+
* Boston, MA 02110-1301, USA.
20+
*/
21+
22+
#pragma once
23+
24+
#include <usb_request.h>
25+
#include <usb_type.h>
26+
27+
usb_request_status_t usb_vendor_request_set_radio_mode(
28+
usb_endpoint_t* const endpoint,
29+
const usb_transfer_stage_t stage);

host/libhackrf/src/hackrf.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ typedef enum {
123123
HACKRF_VENDOR_REQUEST_RADIO_LOCK_REG = 62,
124124
HACKRF_VENDOR_REQUEST_OPEN = 63,
125125
HACKRF_VENDOR_REQUEST_CLOSE = 64,
126+
HACKRF_VENDOR_REQUEST_RADIO_SET_MODE = 65,
126127
} hackrf_vendor_request;
127128

128129
#define USB_CONFIG_STANDARD 0x1
@@ -3716,6 +3717,30 @@ int ADDCALL hackrf_radio_lock_register(
37163717
return HACKRF_SUCCESS;
37173718
}
37183719

3720+
int ADDCALL hackrf_radio_set_mode(hackrf_device* device, const enum radio_config_mode mode)
3721+
{
3722+
USB_API_REQUIRED(device, 0x0113);
3723+
int result;
3724+
3725+
result = libusb_control_transfer(
3726+
device->usb_device,
3727+
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR |
3728+
LIBUSB_RECIPIENT_DEVICE,
3729+
HACKRF_VENDOR_REQUEST_RADIO_SET_MODE,
3730+
mode,
3731+
0,
3732+
NULL,
3733+
0,
3734+
DEFAULT_REQUEST_TIMEOUT);
3735+
3736+
if (result != 0) {
3737+
last_libusb_error = result;
3738+
return HACKRF_ERROR_LIBUSB;
3739+
}
3740+
3741+
return HACKRF_SUCCESS;
3742+
}
3743+
37193744
#ifdef __cplusplus
37203745
} // __cplusplus defined.
37213746
#endif

host/libhackrf/src/hackrf.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,18 @@ extern ADDAPI int ADDCALL hackrf_radio_lock_register(
24632463
const uint8_t register_number,
24642464
const bool register_locked);
24652465

2466+
/**
2467+
* Switches the radio configuration mode.
2468+
*
2469+
* @param[in] device device to configure
2470+
* @param[in] mode configuration mode. Defaults to RADIO_CONFIG_LEGACY. Available modes are defined in @ref radio_config_mode.
2471+
* @return @ref HACKRF_SUCCESS on success or @ref hackrf_error variant
2472+
* @ingroup configuration
2473+
*/
2474+
extern ADDAPI int ADDCALL hackrf_radio_set_mode(
2475+
hackrf_device* device,
2476+
const enum radio_config_mode mode);
2477+
24662478
#ifdef __cplusplus
24672479
} // __cplusplus defined.
24682480
#endif

0 commit comments

Comments
 (0)