Skip to main content

rtlsdr_nusb/
lib.rs

1//! Native RTL2832U / R820T / R828D driver built on `nusb`.
2//!
3//! Device and stream operations can be awaited, or synchronously executed with
4//! [`MaybeFuture::wait`] on native targets. Enable `smol` or `tokio` when awaiting
5//! native discovery, opening, and endpoint setup; no runtime is required by the
6//! blocking API. WebUSB supports awaiting only and requires
7//! `--cfg=web_sys_unstable_apis` in the application's Rust flags.
8//!
9//! An independently owned [`RxStream`] keeps the hardware alive. Stop preserves
10//! its exclusive claim; consuming close releases it. [`Device::shutdown`] is
11//! terminal and returns [`Error::Busy`] until the stream has been closed/dropped.
12//!
13//! ```no_run
14//! use rtlsdr_nusb::{Complex32, Device, MaybeFuture};
15//! use std::time::Duration;
16//!
17//! let mut device = Device::builder()
18//!     .frequency_hz(100_000_000)
19//!     .sample_rate_hz(2_048_000)
20//!     .open().wait()?;
21//! let mut rx = device.rx_stream()?;
22//! rx.start().wait()?;
23//! let mut samples = [Complex32::default(); 4096];
24//! let count = rx.read(&mut samples, Some(Duration::from_secs(1))).wait()?;
25//! println!("received {count} samples");
26//! rx.close().wait()?;
27//! device.shutdown().wait()?;
28//! # Ok::<(), rtlsdr_nusb::Error>(())
29//! ```
30
31#![deny(missing_docs)]
32
33mod config;
34mod device;
35mod discovery;
36mod errors;
37mod maybe_future;
38mod protocol;
39mod rtl2832u;
40mod rx;
41mod session;
42mod tuners;
43mod usb;
44
45pub use config::{
46    Config, ConfigBuilder, DirectSampling, F32Iq, GainConfig, RawIq, SampleFormat, SampleMode,
47};
48pub use device::{Device, DeviceBuilder, DeviceInfo};
49pub use discovery::DeviceDescriptor;
50pub use errors::{Error, ErrorKind, Result};
51pub use num_complex::Complex32;
52pub use nusb::MaybeFuture;
53pub use rx::{MAX_F32_IQ_SAMPLES_PER_TRANSFER, RxStream, SampleBlock, StreamingStats};
54pub use tuners::TunerKind;
55
56#[cfg(all(test, not(target_arch = "wasm32")))]
57mod test_support;
58
59// Compile the README examples as part of the documentation checks.
60#[cfg(doctest)]
61#[doc = include_str!("../README.md")]
62mod readme {}