Expand description
Rust-native half-duplex HackRF driver built on nusb.
One-shot and streaming operations implement MaybeFuture: await them in
asynchronous code, or call MaybeFuture::wait on native targets. Do not
mix execution styles across RX and TX streams. HackRF direction changes are
explicit: start one stream, use it, stop it, then start the other. 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 transceiver configuration.
- Config
Builder - Builder for
Config. - Device
- High-level owned HackRF device handle.
- Device
Builder - Builder for opening and initially configuring a
Device. - Device
Descriptor - HackRF information available from USB discovery without claiming it.
- Device
Info - Device metadata collected while opening a HackRF.
- RxStream
- Owned HackRF receive stream.
- Streaming
Stats - Counters collected during one RX
start/stopperiod. - TxStream
- Owned HackRF transmit stream.
- TxStreaming
Stats - Counters collected during one TX
start/stopperiod.
Enums§
- BoardId
- HackRF board identity reported by firmware.
- Error
- Error returned by a HackRF operation.
- Error
Kind - Stable high-level error category.
Constants§
- MAX_
COMPLEX_ SAMPLES_ PER_ TRANSFER - Maximum number of complex IQ samples in one HackRF USB transfer.
Traits§
- Maybe
Future - IO that may be performed synchronously or asynchronously.
Type Aliases§
- Complex32
- Alias for a
Complex<f32> - Result
- Crate result alias using
Error.