summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2021-04-16 15:25:19 +0300
committerYuval Adam <_@yuv.al>2021-04-17 10:33:57 +0300
commit10d566acd2bcd35c8969fc7991b050da01ceb74c (patch)
treea641014fb02c69eabbe1ab1ca1cde19b4179d209
parentef64d358a25e69e440305e1216824921536d5587 (diff)
Pass handle as reference to tuner and implement Drop
-rw-r--r--README.md4
-rw-r--r--src/devices/r820t.rs14
-rw-r--r--src/lib.rs32
3 files changed, 30 insertions, 20 deletions
diff --git a/README.md b/README.md
index 024acb2..94e1af1 100644
--- a/README.md
+++ b/README.md
@@ -42,6 +42,10 @@ $ cargo test -- --nocapture
Since there isn't (?) any good USB device mocking setup, for tests to pass an RTL-SDR device must be connected.
+## Design
+
+Similarly to the original rtl-sdr driver, we use libusb via the `rusb` bindings as the main interface to issue commands to the rtl-sdr USB dongle.
+
## License
[GPLv3](LICENSE)
diff --git a/src/devices/r820t.rs b/src/devices/r820t.rs
index 92ba509..a257b56 100644
--- a/src/devices/r820t.rs
+++ b/src/devices/r820t.rs
@@ -3,9 +3,9 @@ use usb::RtlSdrDeviceHandle;
const R82XX_IF_FREQ: u32 = 3570000;
-pub struct R820T {
+pub struct R820T<'a> {
pub device: DeviceInfo,
- pub handle: RtlSdrDeviceHandle,
+ pub handle: &'a RtlSdrDeviceHandle,
}
pub const DEVICE_INFO: DeviceInfo = DeviceInfo {
@@ -16,8 +16,8 @@ pub const DEVICE_INFO: DeviceInfo = DeviceInfo {
check_val: 0x69,
};
-impl R820T {
- pub fn new(handle: RtlSdrDeviceHandle) -> R820T {
+impl<'a> R820T<'a> {
+ pub fn new(handle: &'a RtlSdrDeviceHandle) -> R820T<'a> {
R820T {
device: DEVICE_INFO,
handle: handle,
@@ -25,7 +25,11 @@ impl R820T {
}
}
-impl Device for R820T {
+impl<'a> Drop for R820T<'a> {
+ fn drop(&mut self) {}
+}
+
+impl<'a> Device for R820T<'a> {
fn init(&self) {
// disable Zero-IF mode
self.handle.demod_write_reg(1, 0xb1, 0x1a, 1);
diff --git a/src/lib.rs b/src/lib.rs
index d32299a..b2e91a3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -47,25 +47,27 @@ impl RtlSdr {
handle.init_baseband();
handle.set_i2c_repeater(true);
- let d = r820t::R820T::new(handle);
- // let _found = match handle.i2c_read_reg(d.device.i2c_addr, d.device.check_addr) {
- // Ok(reg) => {
- // if reg == d.device.check_val {
- // println!("Found {} tuner\n", d.device.name);
- // true
- // } else {
- // false
- // }
- // }
- // Err(_) => false,
- // };
+ {
+ let d = r820t::R820T::new(&handle);
+ // let _found = match handle.i2c_read_reg(d.device.i2c_addr, d.device.check_addr) {
+ // Ok(reg) => {
+ // if reg == d.device.check_val {
+ // println!("Found {} tuner\n", d.device.name);
+ // true
+ // } else {
+ // false
+ // }
+ // }
+ // Err(_) => false,
+ // };
- d.init();
+ d.init();
+ }
- // handle.deinit_baseband();
+ handle.deinit_baseband();
if kernel_driver_attached {
- // handle.attach_kernel_driver();
+ handle.attach_kernel_driver();
}
}
}