Skip to content

Native Rust async driver for RTL2832U+R82XX #28

Description

@jgraef

Is seify/future-sdr interested in a from-scratch async rust implementation for RTL2832U?

I'm writing one for my SDR framework, but by default it works on its own. The driver was written from scratch, trying not to copy librtlsdr too much, or at least trying to understand what's going on. I found a few bugs, and lots of features that librtlsdr doesn't expose, and that I will definitely experiment with in the future.

Code. It's unpublished - I just got it to work this week.

You can run a test program that runs a rtl_tcp server:

cargo run --release --bin mrrp-rtl-sdr-test -- tcp -l 127.0.0.1:1234

(compilation might take a while since there's a lot of other stuff in the workspace, but the driver crate itself is pretty lightweight)

And usage as a library is also pretty straight-forward:

use mrrp_rtl_sdr::{
    OpenOptions,
    open_any,
};
use tokio::io::AsyncReadExt;

let mut device = open_any(OpenOptions::default()).await?;

// Set sample rate to 2.4 MSa/s
device.set_sample_rate(2_400_000.0).await?;

// Set center frequency to 7 MHz
device.set_center_frequency(7_000_000.0).await?;

// Start sampling and acquire a Reader
let mut reader = device.reader(Default::default()).await?;

// read samples. these are interleaved IQ as pairs of u8, with the equilibrium at 128.
loop {
    let i = reader.read_u8().await?;
    let q = reader.read_u8().await?;
    println!("i=0x{i:02x} q=0x{q:02x}");
}

Noteworthy here is that the Reader is completely separate from the Device. Reader is pretty much just a wrapper around nusb::io::EndpointRead. There's some interaction with the Device, but only when the reader is being closed. Otherwise they don't interact and don't need to synchronize with each other.

Only R82xx tuners are supported right now, and I only tested with R828D, because I only have a RTL-SDR Blog v4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions