A pure-Rust HackRF driver, receive and transmit, over nusb. No libusb, no libhackrf: this crate → nusb → the OS, or WebUSB in a browser.
- Open by spec:
HackRf::open("")(first found) orHackRf::open("serial=…"); in a browserHackRf::request()(the device chooser). - Tuning, sample rate (with the baseband filter tracking it), and gain as one number or per stage: the RF amp (off / +14 dB), the IF LNA (0–40 dB in 8 dB steps), the baseband VGA (0–62 dB in 2 dB steps); transmit VGA 0–47 dB.
- Receive by becoming a
Stream(into_stream): the wire bytes (signed 8-bit I then Q, ashackrf_transferwrites) orIqsamples; split into aReadHalfand aControlfor two threads or tasks. A change made while samples flow is placed in the stream by the firmware's own byte count (aBreak), andfinishreports the firmware's count of shortfalls. - Transmit by becoming a
TxStream(into_tx_stream): wire bytes orIqsamples written, keyed when the queue first fills; split into aWriteHalfand aTxControl.finishwaits until the radio has sent every sample and reports its underruns. - The firmware runs one transceiver mode at a time: a radio is receiving
or transmitting, and each stream owns it until
finishhands it back. - Async at its core (WebUSB in a browser); natively
blockingwraps every call, its streamsstd::io::Readandstd::io::Write.no_stdwithallocwithout the defaultstdfeature (the protocol's encodings and the gain steps).
use std::io::Read;
use sdr_core::TuneRequest;
use sdr_hackrf::blocking::HackRf;
let mut hackrf = HackRf::open("")?;
hackrf.set_rate(10e6)?;
hackrf.set_freq(&TuneRequest::auto(446.0e6))?;
hackrf.set_gain(40.0)?;
let (mut reader, control) = hackrf.into_stream(0, 0).map_err(|e| e.error)?.split();
let mut buf = [0u8; 65536];
let n = reader.read(&mut buf)?;bench/README.md (in the repository) records the measurements the
streams rest on; web/ is a page that runs the driver in a browser.
License: MIT OR Apache-2.0.