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