A pure Rust implementation of the RTL-SDR driver, for shits and giggles.
This is mostly an exercise in writing low-level driver code.
Unusable, and highly unlikely to ever become usable. But it's fun.
For real alternatives check out the original librtlsdr implementation or the high-level rtlsdr_mt Rust bindings.
Install the crate in your Cargo.toml
:
[dependencies]
rustl-sdr = "0.2"
Use in your code:
extern crate rustl_sdr;
fn foo() {
rtlsdr = rustl_sdr::RtlSdr::new(&ctx);
rtlsdr.init();
rtlsdr.do_stuff();
}
Or run one of the example binaries:
$ RUST_LOG=info cargo run --bin rustl_fm
The usual:
$ cargo build
$ cargo test -- --nocapture
Since there isn't (?) any good USB device mocking setup, for tests to pass an RTL-SDR device must be connected.
RusTL-SDR is very similar to the original rtl-sdr driver. It uses libusb, via the rusb bindings, as the main interface to issue commands to the rtl-sdr USB dongle.
Devices generally go through the following lifecycle:
- Get a libusb context/handle, and find a compatible and supported RTL-SDR device
- Initialize the device baseband
- Probe the device for known tuners via the I2C interface
- Run any special initialization required for the detected tuner
- Interact with the device, usually this is where samples are read
- Deinitialize the tuner
- Deinitialize the baseband
- Close the USB handle