Skip to main content

hackrf_nusb/
lib.rs

1//! Rust-native RX-only HackRF driver built on [`nusb`].
2//!
3//! One-shot operations and receive-stream operations implement [`MaybeFuture`]:
4//! await them in asynchronous code, or call [`MaybeFuture::wait`] on native
5//! targets. The receive stream owns its USB endpoint and transfer queue, so the
6//! steady-state read path does not lock shared device state.
7//!
8//! # Synchronous example
9//!
10//! ```no_run
11//! use hackrf_nusb::{Complex32, Device, MaybeFuture};
12//! use std::time::Duration;
13//!
14//! fn main() -> hackrf_nusb::Result<()> {
15//!     let mut device = Device::builder()
16//!         .frequency_hz(100_000_000)
17//!         .sample_rate_hz(10_000_000)
18//!         .open()
19//!         .wait()?;
20//!     let mut rx = device.rx_stream()?;
21//!     rx.start().wait()?;
22//!     let mut samples = [Complex32::default(); 1024];
23//!     let count = rx.read(&mut samples, Some(Duration::from_secs(1))).wait()?;
24//!     println!("received {count} IQ samples");
25//!     rx.stop().wait()?;
26//!     drop(rx);
27//!     device.shutdown().wait()?;
28//!     Ok(())
29//! }
30//! ```
31//!
32//! On `wasm32`, call `Device::request_permission` from a browser-window user
33//! gesture before opening the device. WebUSB operations are asynchronous only.
34
35#![deny(missing_docs)]
36
37mod commands;
38mod config;
39mod constants;
40mod device;
41mod discovery;
42mod errors;
43mod high_level;
44mod maybe_future;
45mod streaming;
46mod types;
47mod usb;
48
49pub use config::{Config, ConfigBuilder};
50pub use constants::MAX_COMPLEX_SAMPLES_PER_TRANSFER;
51pub use discovery::DeviceDescriptor;
52pub use errors::{Error, ErrorKind, Result};
53pub use high_level::{Device, DeviceBuilder, RxStream};
54pub use num_complex::Complex32;
55pub use nusb::MaybeFuture;
56pub use streaming::StreamingStats;
57pub use types::{BoardId, DeviceInfo};