Merge remote-tracking branch 'mossmann/master' into rad1o

Conflicts:
	host/misc/udev/53-hackrf.rules.in
	host/python/max2837_dump.py
	host/python/set_transceiver_mode.py
This commit is contained in:
Tobias Schneider
2015-12-07 21:05:39 +01:00
21 changed files with 294 additions and 152 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
*.brd linguist-language=KiCad

View File

@ -444,7 +444,9 @@ extern "C"
typedef enum {
TRANSCEIVER_MODE_OFF = 0,
TRANSCEIVER_MODE_RX = 1,
TRANSCEIVER_MODE_TX = 2
TRANSCEIVER_MODE_TX = 2,
TRANSCEIVER_MODE_SS = 3,
TRANSCEIVER_MODE_CPLD_UPDATE = 4
} transceiver_mode_t;
void delay(uint32_t duration);

View File

@ -384,6 +384,7 @@ void rf_path_set_direction(const rf_path_direction_t direction) {
#ifdef HACKRF_ONE
rf_path_set_antenna(0);
#endif
rf_path_set_lna(0);
/* Set RF path to receive direction when "off" */
switchctrl &= ~SWITCHCTRL_TX;
mixer_disable();

View File

@ -240,3 +240,25 @@ void w25q80bv_program(uint32_t addr, uint32_t len, const uint8_t* data)
w25q80bv_page_program(addr, len, data);
}
}
void w25q80bv_read(uint32_t addr, uint32_t len, uint8_t* const data)
{
uint32_t i;
/* do nothing if we would overflow the flash */
if ((len > W25Q80BV_NUM_BYTES) || (addr > W25Q80BV_NUM_BYTES)
|| ((addr + len) > W25Q80BV_NUM_BYTES))
return;
w25q80bv_wait_while_busy();
gpio_clear(PORT_SSP0_SSEL, PIN_SSP0_SSEL);
ssp_transfer(SSP0_NUM, W25Q80BV_FAST_READ);
ssp_transfer(SSP0_NUM, (addr >> 16) & 0xFF);
ssp_transfer(SSP0_NUM, (addr >> 8) & 0xFF);
ssp_transfer(SSP0_NUM, (addr >> 0) & 0xFF);
ssp_transfer(SSP0_NUM, 0xFF);
for (i = 0; i < len; i++)
data[i] = ssp_transfer(SSP0_NUM, 0xFF);
gpio_set(PORT_SSP0_SSEL, PIN_SSP0_SSEL);
}

View File

@ -27,6 +27,8 @@
#define W25Q80BV_NUM_PAGES 4096U
#define W25Q80BV_NUM_BYTES 1048576U
#define W25Q80BV_READ_DATA 0x03
#define W25Q80BV_FAST_READ 0x0b
#define W25Q80BV_WRITE_ENABLE 0x06
#define W25Q80BV_CHIP_ERASE 0xC7
#define W25Q80BV_READ_STATUS1 0x05
@ -52,5 +54,6 @@ void w25q80bv_chip_erase(void);
void w25q80bv_program(uint32_t addr, uint32_t len, const uint8_t* data);
uint8_t w25q80bv_get_device_id(void);
void w25q80bv_get_unique_id(w25q80bv_unique_id_t* unique_id);
void w25q80bv_read(uint32_t addr, uint32_t len, uint8_t* const data);
#endif//__W25Q80BV_H__

View File

@ -47,6 +47,7 @@
#include "sgpio_isr.h"
#include "usb_bulk_buffer.h"
#include "si5351c.h"
#include "w25q80bv.h"
#if HACKRF_ENABLE_UI
#include "hackrf-ui.h"
@ -103,6 +104,11 @@ usb_request_status_t usb_vendor_request_set_transceiver_mode(
set_transceiver_mode(endpoint->setup.value);
usb_transfer_schedule_ack(endpoint->in);
return USB_REQUEST_STATUS_OK;
case TRANSCEIVER_MODE_CPLD_UPDATE:
usb_endpoint_init(&usb_endpoint_bulk_out);
start_cpld_update = true;
usb_transfer_schedule_ack(endpoint->in);
return USB_REQUEST_STATUS_OK;
default:
return USB_REQUEST_STATUS_STALL;
}
@ -233,6 +239,9 @@ int main(void) {
#endif
cpu_clock_init();
/* Code is not running from SPI flash, initialize for flash read/write over USB */
w25q80bv_setup();
usb_set_descriptor_by_serial_number();
usb_set_configuration_changed_cb(usb_configuration_changed);

View File

@ -33,14 +33,10 @@ uint8_t spiflash_buffer[W25Q80BV_PAGE_LEN];
usb_request_status_t usb_vendor_request_erase_spiflash(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{
//FIXME This should refuse to run if executing from SPI flash.
if (stage == USB_TRANSFER_STAGE_SETUP) {
w25q80bv_setup();
/* only chip erase is implemented */
w25q80bv_chip_erase();
usb_transfer_schedule_ack(endpoint->in);
//FIXME probably should undo w25q80bv_setup()
}
return USB_REQUEST_STATUS_OK;
}
@ -51,8 +47,6 @@ usb_request_status_t usb_vendor_request_write_spiflash(
uint32_t addr = 0;
uint16_t len = 0;
//FIXME This should refuse to run if executing from SPI flash.
if (stage == USB_TRANSFER_STAGE_SETUP) {
addr = (endpoint->setup.value << 16) | endpoint->setup.index;
len = endpoint->setup.length;
@ -62,7 +56,6 @@ usb_request_status_t usb_vendor_request_write_spiflash(
} else {
usb_transfer_schedule_block(endpoint->out, &spiflash_buffer[0], len,
NULL, NULL);
w25q80bv_setup();
return USB_REQUEST_STATUS_OK;
}
} else if (stage == USB_TRANSFER_STAGE_DATA) {
@ -75,7 +68,6 @@ usb_request_status_t usb_vendor_request_write_spiflash(
} else {
w25q80bv_program(addr, len, &spiflash_buffer[0]);
usb_transfer_schedule_ack(endpoint->in);
//FIXME probably should undo w25q80bv_setup()
return USB_REQUEST_STATUS_OK;
}
} else {
@ -86,10 +78,8 @@ usb_request_status_t usb_vendor_request_write_spiflash(
usb_request_status_t usb_vendor_request_read_spiflash(
usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage)
{
uint32_t i;
uint32_t addr;
uint16_t len;
uint8_t* u8_addr_pt;
if (stage == USB_TRANSFER_STAGE_SETUP)
{
@ -99,12 +89,7 @@ usb_request_status_t usb_vendor_request_read_spiflash(
|| ((addr + len) > W25Q80BV_NUM_BYTES)) {
return USB_REQUEST_STATUS_STALL;
} else {
/* TODO flush SPIFI "cache" before to read the SPIFI memory */
u8_addr_pt = (uint8_t*)(addr + SPIFI_DATA_UNCACHED_BASE);
for(i=0; i<len; i++)
{
spiflash_buffer[i] = u8_addr_pt[i];
}
w25q80bv_read(addr, len, &spiflash_buffer[0]);
usb_transfer_schedule_block(endpoint->in, &spiflash_buffer[0], len,
NULL, NULL);
return USB_REQUEST_STATUS_OK;

View File

@ -5,7 +5,6 @@ project (hackrf_all)
add_subdirectory(libhackrf)
add_subdirectory(hackrf-tools)
add_subdirectory(misc)
########################################################################
# Create uninstall target

View File

@ -1,6 +1,34 @@
This repository contains host software (Linux/Windows) for HackRF, a project to
produce a low cost, open source software radio platform.
##How to build the host software on Linux:
###Prerequisites for Linux (Debian/Ubuntu):
`sudo apt-get install build-essential cmake libusb-1.0-0-dev pkg-config`
###Build host software on Linux:
`cd host`
`mkdir build`
`cd build`
`cmake ../ -DINSTALL_UDEV_RULES=ON`
`make`
`sudo make install`
`sudo ldconfig`
##Clean CMake temporary files/dirs:
`cd host/build`
`rm -rf *`
##How to build host software on Windows:
###Prerequisites for cygwin or mingw:
@ -51,36 +79,19 @@ Debug version:
`make install`
###For Visual Studio 2012 x64
`c:\hackrf\host\cmake>cmake ../ -G "Visual Studio 11 2012 Win64" -DLIBUSB_INCLUDE_DIR=c:\libusb-1.0.18-win\include\libusb-1.0 -DLIBUSB_LIBRARIES=c:\libusb-1.0.18-win\MS64\static\libusb-1.0.lib -DTHREADS_PTHREADS_INCLUDE_DIR=c:\pthreads-w32-2-9-1-release\Pre-built.2\include -DTHREADS_PTHREADS_WIN32_LIBRARY=c:\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64\pthreadVC2.lib`
##How to build the host software on Linux:
Solution file: `c:\hackrf\host\cmake\hackrf_all.sln`
###Prerequisites for Linux (Debian/Ubuntu):
##How to build host the software on FreeBSD
You can use the binary package:
`# pkg install hackrf`
`sudo apt-get install build-essential cmake libusb-1.0-0-dev`
###Build host software on Linux:
`cd host`
`mkdir build`
`cd build`
`cmake ../ -DINSTALL_UDEV_RULES=ON`
`make`
`sudo make install`
`sudo ldconfig`
##Clean CMake temporary files/dirs:
`cd host/build`
`rm -rf *`
You can build and install from ports:
`# cd /usr/ports/comms/hackrf`
`# make install`
principal author: Michael Ossmann <mike@ossmann.com>

View File

@ -24,10 +24,15 @@ else (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
pkg_check_modules(PC_LIBUSB libusb-1.0)
ENDIF(NOT WIN32)
set(LIBUSB_LIBRARY_NAME usb-1.0)
IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(LIBUSB_LIBRARY_NAME usb)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS})
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES ${LIBUSB_LIBRARY_NAME}
PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS})
include(FindPackageHandleStandardArgs)

View File

@ -24,7 +24,7 @@
cmake_minimum_required(VERSION 2.8)
project(hackrf-tools C)
set(MAJOR_VERSION 0)
set(MINOR_VERSION 3)
set(MINOR_VERSION 4)
set(PACKAGE hackrf-tools)
set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION})
set(VERSION ${VERSION_STRING})

View File

@ -51,6 +51,7 @@ static struct option long_options[] = {
{ "length", required_argument, 0, 'l' },
{ "read", required_argument, 0, 'r' },
{ "write", required_argument, 0, 'w' },
{ "verbose", no_argument, 0, 'v' },
{ 0, 0, 0, 0 },
};
@ -90,6 +91,7 @@ static void usage()
printf("\t-r <filename>: Read data into file.\n");
printf("\t-w <filename>: Write data from file.\n");
printf("\t-d <serialnumber>: Serial number of device, if multiple devices\n");
printf("\t-v: Verbose output.\n");
}
int main(int argc, char** argv)
@ -109,8 +111,9 @@ int main(int argc, char** argv)
FILE* fd = NULL;
bool read = false;
bool write = false;
bool verbose = false;
while ((opt = getopt_long(argc, argv, "a:l:r:w:d:", long_options,
while ((opt = getopt_long(argc, argv, "a:l:r:w:d:v", long_options,
&option_index)) != EOF) {
switch (opt) {
case 'a':
@ -135,6 +138,10 @@ int main(int argc, char** argv)
serial_number = optarg;
break;
case 'v':
verbose = true;
break;
default:
fprintf(stderr, "opt error: %d\n", opt);
usage();
@ -233,7 +240,7 @@ int main(int argc, char** argv)
while (tmp_length)
{
xfer_len = (tmp_length > 256) ? 256 : tmp_length;
printf("Reading %d bytes from 0x%06x.\n", xfer_len, address);
if( verbose ) printf("Reading %d bytes from 0x%06x.\n", xfer_len, address);
result = hackrf_spiflash_read(device, address, xfer_len, pdata);
if (result != HACKRF_SUCCESS) {
fprintf(stderr, "hackrf_spiflash_read() failed: %s (%d)\n",
@ -272,9 +279,10 @@ int main(int argc, char** argv)
fd = NULL;
return EXIT_FAILURE;
}
if( !verbose ) printf("Writing %d bytes at 0x%06x.\n", length, address);
while (length) {
xfer_len = (length > 256) ? 256 : length;
printf("Writing %d bytes at 0x%06x.\n", xfer_len, address);
if( verbose ) printf("Writing %d bytes at 0x%06x.\n", xfer_len, address);
result = hackrf_spiflash_write(device, address, xfer_len, pdata);
if (result != HACKRF_SUCCESS) {
fprintf(stderr, "hackrf_spiflash_write() failed: %s (%d)\n",

View File

@ -168,13 +168,6 @@ t_wav_file_hdr wave_file_hdr =
}
};
typedef enum {
TRANSCEIVER_MODE_OFF = 0,
TRANSCEIVER_MODE_RX = 1,
TRANSCEIVER_MODE_TX = 2,
TRANSCEIVER_MODE_SS = 3
} transceiver_mode_t;
static transceiver_mode_t transceiver_mode = TRANSCEIVER_MODE_RX;
#define U64TOA_MAX_DIGIT (31)
@ -337,6 +330,8 @@ size_t bytes_to_xfer = 0;
bool baseband_filter_bw = false;
uint32_t baseband_filter_bw_hz = 0;
bool repeat = false;
int rx_callback(hackrf_transfer* transfer) {
size_t bytes_to_write;
int i;
@ -392,7 +387,15 @@ int tx_callback(hackrf_transfer* transfer) {
bytes_read = fread(transfer->buffer, 1, bytes_to_read, fd);
if ((bytes_read != bytes_to_read)
|| (limit_num_samples && (bytes_to_xfer == 0))) {
return -1;
if (repeat) {
printf("Input file end reached. Rewind to beginning.\n");
rewind(fd);
fread(transfer->buffer + bytes_read, 1, bytes_to_read - bytes_read, fd);
return 0;
} else {
return -1; // not loopback mode, EOF
}
} else {
return 0;
}
@ -446,6 +449,7 @@ static void usage() {
u64toa((DEFAULT_SAMPLE_RATE_HZ/FREQ_ONE_MHZ),&ascii_u64_data1));
printf("\t[-n num_samples] # Number of samples to transfer (default is unlimited).\n");
printf("\t[-c amplitude] # CW signal source mode, amplitude 0-127 (DC value to DAC).\n");
printf("\t[-R] # Repeat TX mode (default is off) \n");
printf("\t[-b baseband_filter_bw_hz] # Set baseband filter bandwidth in MHz.\n\tPossible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz, default < sample_rate_hz.\n" );
}
@ -488,7 +492,7 @@ int main(int argc, char** argv) {
float time_diff;
unsigned int lna_gain=8, vga_gain=20, txvga_gain=0;
while( (opt = getopt(argc, argv, "wr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:")) != EOF )
while( (opt = getopt(argc, argv, "wr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:R")) != EOF )
{
result = HACKRF_SUCCESS;
switch( opt )
@ -575,6 +579,10 @@ int main(int argc, char** argv) {
result = parse_u32(optarg, &amplitude);
break;
case 'R':
repeat = true;
break;
default:
printf("unknown argument '-%c %s'\n", opt, optarg);
usage();
@ -588,6 +596,12 @@ int main(int argc, char** argv) {
}
}
if (lna_gain % 8)
printf("warning: lna_gain (-l) must be a multiple of 8\n");
if (vga_gain % 2)
printf("warning: vga_gain (-g) must be a multiple of 2\n");
if (samples_to_xfer >= SAMPLES_TO_XFER_MAX) {
printf("argument error: num_samples must be less than %s/%sMio\n",
u64toa(SAMPLES_TO_XFER_MAX,&ascii_u64_data1),
@ -991,7 +1005,7 @@ int main(int argc, char** argv) {
/* Get size of file */
file_pos = ftell(fd);
/* Update Wav Header */
wave_file_hdr.hdr.size = file_pos+8;
wave_file_hdr.hdr.size = file_pos-8;
wave_file_hdr.fmt_chunk.dwSamplesPerSec = sample_rate_hz;
wave_file_hdr.fmt_chunk.dwAvgBytesPerSec = wave_file_hdr.fmt_chunk.dwSamplesPerSec*2;
wave_file_hdr.data_chunk.chunkSize = file_pos - sizeof(t_wav_file_hdr);

View File

@ -2,7 +2,12 @@
ATTR{idVendor}=="1d50", ATTR{idProduct}=="604b", SYMLINK+="hackrf-jawbreaker-%k", MODE="660", GROUP="@HACKRF_GROUP@"
# HackRF One
ATTR{idVendor}=="1d50", ATTR{idProduct}=="6089", SYMLINK+="hackrf-one-%k", MODE="660", GROUP="@HACKRF_GROUP@"
# HackRF One
# rad1o
ATTR{idVendor}=="1d50", ATTR{idProduct}=="cc15", SYMLINK+="rad1o-%k", MODE="660", GROUP="@HACKRF_GROUP@"
# HackRF DFU
# NXP Semiconductors DFU mode (HackRF and rad1o)
ATTR{idVendor}=="1fc9", ATTR{idProduct}=="000c", SYMLINK+="nxp-dfu-%k", MODE="660", GROUP="@HACKRF_GROUP@"
# rad1o "full flash" mode
KERNEL=="sd?", SUBSYSTEM=="block", ENV{ID_VENDOR_ID}=="1fc9", ENV{ID_MODEL_ID}=="0042", SYMLINK+="rad1o-flash-%k", MODE="660", GROUP="@HACKRF_GROUP@"
# rad1o flash disk
KERNEL=="sd?", SUBSYSTEM=="block", ENV{ID_VENDOR_ID}=="1fc9", ENV{ID_MODEL_ID}=="0082", SYMLINK+="rad1o-msc-%k", MODE="660", GROUP="@HACKRF_GROUP@"
#

View File

@ -24,7 +24,7 @@
cmake_minimum_required(VERSION 2.8)
project(libhackrf C)
set(MAJOR_VERSION 0)
set(MINOR_VERSION 3)
set(MINOR_VERSION 4)
set(PACKAGE libhackrf)
set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION})
set(VERSION ${VERSION_STRING})
@ -70,6 +70,11 @@ set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix \${prefix})
set(libdir \${exec_prefix}/lib${LIB_SUFFIX})
set(includedir \${prefix}/include)
set(libpkgdata lib${LIB_SUFFIX})
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(libpkgdata "libdata")
endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/libhackrf.pc.in
@ -78,9 +83,73 @@ CONFIGURE_FILE(
INSTALL(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libhackrf.pc
DESTINATION lib${LIB_SUFFIX}/pkgconfig
DESTINATION ${libpkgdata}/pkgconfig
)
########################################################################
# Create Pkg Config File
########################################################################
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(SYSTEM_IS_LINUX TRUE)
SET(UDEV_OPTION_DEFAULT ON)
else()
SET(SYSTEM_IS_LINUX FALSE)
SET(UDEV_OPTION_DEFAULT OFF)
endif()
option(INSTALL_UDEV_RULES
"Install udev rules for the HackRF"
${UDEV_OPTION_DEFAULT}
)
set(UDEV_RULES_PATH
"/etc/udev/rules.d"
CACHE STRING
"Target directory for udev rule installation. Ensure you have permissions to write to this directory."
)
if(SYSTEM_IS_LINUX)
if(INSTALL_UDEV_RULES)
if(NOT DEFINED UDEV_RULES_GROUP)
foreach(group usb plugdev)
execute_process(COMMAND "getent" group "${group}"
RESULT_VARIABLE _GETENT_RESULT
OUTPUT_QUIET
ERROR_QUIET)
if(NOT _GETENT_RESULT)
message(STATUS "Setting udev rule group to - ${group}")
set(UDEV_RULES_GROUP ${group})
break()
endif(NOT _GETENT_RESULT)
endforeach(group)
endif(NOT DEFINED UDEV_RULES_GROUP)
if(DEFINED UDEV_RULES_GROUP)
set(HACKRF_GROUP "${UDEV_RULES_GROUP}"
CACHE STRING "Group to associate HackRF devices with in udev rules")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/53-hackrf.rules.in
${CMAKE_CURRENT_BINARY_DIR}/53-hackrf.rules
@ONLY
)
message(STATUS "HackRF udev rules will be installed to '${UDEV_RULES_PATH}' upon running 'make install'")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/53-hackrf.rules
DESTINATION ${UDEV_RULES_PATH}
COMPONENT "udev_rules")
else(UDEV_RULES_GROUP)
message(STATUS "HackRF udev rules will not be installed because no suitable group was found")
message(STATUS "A group can be specified with -DUDEV_RULES_GROUP=<group>")
endif(DEFINED UDEV_RULES_GROUP)
else(INSTALL_UDEV_RULES)
message(STATUS
"HackRF udev rules will not be installed because INSTALL_UDEV_RULES=OFF"
)
endif(INSTALL_UDEV_RULES)
else(SYSTEM_IS_LINUX)
if(INSTALL_UDEV_RULES)
message(STATUS "udev rules not supported on this platform. Hide this message via -DINSTALL_UDEV_RULES=Off")
endif(INSTALL_UDEV_RULES)
endif(SYSTEM_IS_LINUX)
########################################################################
# Create uninstall target
########################################################################

View File

@ -69,6 +69,11 @@ typedef enum {
HACKRF_VENDOR_REQUEST_SET_FREQ_EXPLICIT = 24,
} hackrf_vendor_request;
typedef enum {
USB_CONFIG_STANDARD = 0x1,
USB_CONFIG_CPLD_UPDATE = 0x2,
} hackrf_usb_configurations;
typedef enum {
HACKRF_TRANSCEIVER_MODE_OFF = 0,
HACKRF_TRANSCEIVER_MODE_RECEIVE = 1,
@ -234,6 +239,72 @@ static int prepare_transfers(
}
}
static int detach_kernel_drivers(libusb_device_handle* usb_device_handle)
{
int i, num_interfaces, result;
libusb_device* dev;
struct libusb_config_descriptor* config;
dev = libusb_get_device(usb_device_handle);
result = libusb_get_active_config_descriptor(dev, &config);
if( result < 0 )
{
return HACKRF_ERROR_LIBUSB;
}
num_interfaces = config->bNumInterfaces;
libusb_free_config_descriptor(config);
for(i=0; i<num_interfaces; i++)
{
result = libusb_kernel_driver_active(usb_device_handle, i);
if( result < 0 )
{
if( result == LIBUSB_ERROR_NOT_SUPPORTED ) {
return 0;
}
return HACKRF_ERROR_LIBUSB;
} else if( result == 1 ) {
result = libusb_detach_kernel_driver(usb_device_handle, i);
if( result != 0 )
{
return HACKRF_ERROR_LIBUSB;
}
}
}
return HACKRF_SUCCESS;
}
static int set_hackrf_configuration(libusb_device_handle* usb_device, int config)
{
int result, curr_config;
result = libusb_get_configuration(usb_device, &curr_config);
if( result != 0 )
{
return HACKRF_ERROR_LIBUSB;
}
if(curr_config != config)
{
result = detach_kernel_drivers(usb_device);
if( result != 0 )
{
return result;
}
result = libusb_set_configuration(usb_device, config);
if( result != 0 )
{
return HACKRF_ERROR_LIBUSB;
}
}
result = detach_kernel_drivers(usb_device);
if( result != 0 )
{
return result;
}
return LIBUSB_SUCCESS;
}
#ifdef __cplusplus
extern "C"
{
@ -416,15 +487,15 @@ static int hackrf_open_setup(libusb_device_handle* usb_device, hackrf_device** d
//int speed = libusb_get_device_speed(usb_device);
// TODO: Error or warning if not high speed USB?
result = libusb_set_configuration(usb_device, 1);
if( result != 0 )
result = set_hackrf_configuration(usb_device, USB_CONFIG_STANDARD);
if( result != LIBUSB_SUCCESS )
{
libusb_close(usb_device);
return HACKRF_ERROR_LIBUSB;
return result;
}
result = libusb_claim_interface(usb_device, 0);
if( result != 0 )
if( result != LIBUSB_SUCCESS )
{
libusb_close(usb_device);
return HACKRF_ERROR_LIBUSB;
@ -846,21 +917,11 @@ int ADDCALL hackrf_cpld_write(hackrf_device* device,
{
const unsigned int chunk_size = 512;
unsigned int i;
int transferred = 0;
int result = libusb_release_interface(device->usb_device, 0);
if (result != LIBUSB_SUCCESS) {
return HACKRF_ERROR_LIBUSB;
}
int result, transferred = 0;
result = libusb_set_configuration(device->usb_device, 2);
if (result != LIBUSB_SUCCESS) {
return HACKRF_ERROR_LIBUSB;
}
result = libusb_claim_interface(device->usb_device, 0);
if (result != LIBUSB_SUCCESS) {
return HACKRF_ERROR_LIBUSB;
}
result = hackrf_set_transceiver_mode(device, TRANSCEIVER_MODE_CPLD_UPDATE);
if (result != 0)
return result;
for (i = 0; i < total_length; i += chunk_size)
{
@ -1160,6 +1221,7 @@ int ADDCALL hackrf_set_lna_gain(hackrf_device* device, uint32_t value)
return HACKRF_ERROR_INVALID_PARAM;
}
value &= ~0x07;
result = libusb_control_transfer(
device->usb_device,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
@ -1189,6 +1251,7 @@ int ADDCALL hackrf_set_vga_gain(hackrf_device* device, uint32_t value)
return HACKRF_ERROR_INVALID_PARAM;
}
value &= ~0x01;
result = libusb_control_transfer(
device->usb_device,
LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,

View File

@ -82,6 +82,14 @@ enum rf_path_filter {
RF_PATH_FILTER_HIGH_PASS = 2,
};
typedef enum {
TRANSCEIVER_MODE_OFF = 0,
TRANSCEIVER_MODE_RX = 1,
TRANSCEIVER_MODE_TX = 2,
TRANSCEIVER_MODE_SS = 3,
TRANSCEIVER_MODE_CPLD_UPDATE = 4
} transceiver_mode_t;
typedef struct hackrf_device hackrf_device;
typedef struct {
@ -200,4 +208,4 @@ extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t
} // __cplusplus defined.
#endif
#endif//__HACKRF_H__
#endif /*__HACKRF_H__*/

View File

@ -1,2 +0,0 @@
cmake_minimum_required(VERSION 2.8)
add_subdirectory(udev)

View File

@ -1,61 +0,0 @@
cmake_minimum_required(VERSION 2.8)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(SYSTEM_IS_LINUX TRUE)
SET(UDEV_OPTION_DEFAULT ON)
else()
SET(SYSTEM_IS_LINUX FALSE)
SET(UDEV_OPTION_DEFAULT OFF)
endif()
option(INSTALL_UDEV_RULES
"Install udev rules for the HackRF"
${UDEV_OPTION_DEFAULT}
)
set(UDEV_RULES_PATH
"/etc/udev/rules.d"
CACHE STRING
"Target directory for udev rule installation. Ensure you have permissions to write to this directory."
)
if(SYSTEM_IS_LINUX)
if(INSTALL_UDEV_RULES)
if(NOT DEFINED UDEV_RULES_GROUP)
foreach(group usb plugdev)
execute_process(COMMAND "getent" group "${group}"
RESULT_VARIABLE _GETENT_RESULT
OUTPUT_QUIET
ERROR_QUIET)
if(NOT _GETENT_RESULT)
message(STATUS "Setting udev rule group to - ${group}")
set(UDEV_RULES_GROUP ${group})
break()
endif(NOT _GETENT_RESULT)
endforeach(group)
endif(NOT DEFINED UDEV_RULES_GROUP)
if(DEFINED UDEV_RULES_GROUP)
set(HACKRF_GROUP "${UDEV_RULES_GROUP}"
CACHE STRING "Group to associate HackRF devices with in udev rules")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/53-hackrf.rules.in
${CMAKE_CURRENT_BINARY_DIR}/53-hackrf.rules
@ONLY
)
message(STATUS "HackRF udev rules will be installed to '${UDEV_RULES_PATH}' upon running 'make install'")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/53-hackrf.rules
DESTINATION ${UDEV_RULES_PATH}
COMPONENT "udev_rules")
else(UDEV_RULES_GROUP)
message(STATUS "HackRF udev rules will not be installed because no suitable group was found")
message(STATUS "A group can be specified with -DUDEV_RULES_GROUP=<group>")
endif(DEFINED UDEV_RULES_GROUP)
else(INSTALL_UDEV_RULES)
message(STATUS
"HackRF udev rules will not be installed because INSTALL_UDEV_RULES=OFF"
)
endif(INSTALL_UDEV_RULES)
else(SYSTEM_IS_LINUX)
if(INSTALL_UDEV_RULES)
message(STATUS "udev rules not supported on this platform. Hide this message via -DINSTALL_UDEV_RULES=Off")
endif(INSTALL_UDEV_RULES)
endif(SYSTEM_IS_LINUX)

View File

@ -32,9 +32,9 @@ else:
if device:
print 'Find: HackRF One'
else:
device = usb.core.find(idVendor=0x1d50, idProduct=0xCC15)
device = usb.core.find(idVendor=0x1d50, idProduct=0xcc15)
if device:
print 'Find: Rad1o'
print 'Find: rad1o'
else:
print 'Not find any HackRF device.'
sys.exit()

View File

@ -31,9 +31,9 @@ else:
if device:
print 'Find: HackRF One'
else:
device = usb.core.find(idVendor=0x1d50, idProduct=0xCC15)
device = usb.core.find(idVendor=0x1d50, idProduct=0xcc15)
if device:
print 'Find: Rad1o'
print 'Find: rad1o'
else:
print 'Not find any HackRF device.'
sys.exit()