Skip to main content

Crate hackrf_nusb

Crate hackrf_nusb 

Source
Expand description

Rust-native RX-only HackRF driver built on nusb.

One-shot operations and receive-stream operations implement MaybeFuture: await them in asynchronous code, or call MaybeFuture::wait on native targets. The receive stream owns its USB endpoint and transfer queue, so the steady-state read path does not lock shared device state.

§Synchronous example

use hackrf_nusb::{Complex32, Device, MaybeFuture};
use std::time::Duration;

fn main() -> hackrf_nusb::Result<()> {
    let mut device = Device::builder()
        .frequency_hz(100_000_000)
        .sample_rate_hz(10_000_000)
        .open()
        .wait()?;
    let mut rx = device.rx_stream()?;
    rx.start().wait()?;
    let mut samples = [Complex32::default(); 1024];
    let count = rx.read(&mut samples, Some(Duration::from_secs(1))).wait()?;
    println!("received {count} IQ samples");
    rx.stop().wait()?;
    drop(rx);
    device.shutdown().wait()?;
    Ok(())
}

On wasm32, call Device::request_permission from a browser-window user gesture before opening the device. WebUSB operations are asynchronous only.

Structs§

Config
Validated HackRF RX configuration.
ConfigBuilder
Builder for Config.
Device
High-level owned HackRF device handle.
DeviceBuilder
Builder for opening and initially configuring a Device.
DeviceDescriptor
HackRF information available from USB discovery without claiming it.
DeviceInfo
Device metadata collected while opening a HackRF.
RxStream
Owned HackRF receive stream.
StreamingStats
Counters collected during a receive-stream lifetime.

Enums§

BoardId
HackRF board identity reported by firmware.
Error
Error returned by a HackRF operation.
ErrorKind
Stable high-level error category.

Constants§

MAX_COMPLEX_SAMPLES_PER_TRANSFER
Maximum number of complex IQ samples in one HackRF USB transfer.

Traits§

MaybeFuture
IO that may be performed synchronously or asynchronously.

Type Aliases§

Complex32
Alias for a Complex<f32>
Result
Crate result alias using Error.