summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2018-08-03 16:28:09 +0300
committerYuval Adam <_@yuv.al>2018-08-03 16:29:28 +0300
commit68f050c9e90a5a34e84d2f9d71a977e0551f211d (patch)
treee8b70159534089184d0a7910fb91027e17969af1
parenta792fa11bea0bde00aa9aaf0aa6c2640bdb633a3 (diff)
Add device methods
-rw-r--r--src/devices/fc0013.rs27
-rw-r--r--src/devices/mod.rs10
-rw-r--r--src/devices/r820t.rs49
-rw-r--r--src/lib.rs4
-rw-r--r--src/usb.rs4
5 files changed, 74 insertions, 20 deletions
diff --git a/src/devices/fc0013.rs b/src/devices/fc0013.rs
index d2f6062..8404b90 100644
--- a/src/devices/fc0013.rs
+++ b/src/devices/fc0013.rs
@@ -1,5 +1,4 @@
use super::{DeviceInfo, Device};
-use usb::Usb;
#[allow(dead_code)]
pub struct FC0013 {
@@ -25,7 +24,31 @@ impl FC0013 {
}
impl Device for FC0013 {
- fn init(&self, _usb: &Usb) {
+ fn init(&self) {
println!("Init {}", self.device.name);
}
+
+ fn exit(&self){
+ unimplemented!()
+ }
+
+ fn set_freq(&self, _freq: u32){
+ unimplemented!()
+ }
+
+ fn set_bw(&self, _bw: u32){
+ unimplemented!()
+ }
+
+ fn set_gain(&self, _gain: u32){
+ unimplemented!()
+ }
+
+ fn set_if_gain(&self, _if_gain: u32){
+ unimplemented!()
+ }
+
+ fn set_gain_mode(&self, _mode: bool){
+ unimplemented!()
+ }
}
diff --git a/src/devices/mod.rs b/src/devices/mod.rs
index 659b131..18f08e6 100644
--- a/src/devices/mod.rs
+++ b/src/devices/mod.rs
@@ -1,5 +1,3 @@
-use usb::Usb;
-
pub mod fc0013;
pub mod r820t;
@@ -12,5 +10,11 @@ pub struct DeviceInfo {
}
pub trait Device {
- fn init(&self, &Usb);
+ fn init(&self);
+ fn exit(&self);
+ fn set_freq(&self, freq: u32);
+ fn set_bw(&self, bw: u32);
+ fn set_gain(&self, gain: u32);
+ fn set_if_gain(&self, if_gain: u32);
+ fn set_gain_mode(&self, mode: bool);
}
diff --git a/src/devices/r820t.rs b/src/devices/r820t.rs
index 46046bc..d08fc76 100644
--- a/src/devices/r820t.rs
+++ b/src/devices/r820t.rs
@@ -3,8 +3,9 @@ use usb::Usb;
const R82XX_IF_FREQ: u32 = 3570000;
-pub struct R820T {
- pub device: DeviceInfo
+pub struct R820T<'a> {
+ pub device: DeviceInfo,
+ pub usb: &'a Usb<'a>
}
pub const DEVICE_INFO: DeviceInfo = DeviceInfo {
@@ -15,27 +16,53 @@ pub const DEVICE_INFO: DeviceInfo = DeviceInfo {
check_val: 0x69
};
-impl R820T {
- pub fn new() -> R820T {
+impl<'a> R820T<'a> {
+ pub fn new(usb: &'a Usb) -> R820T<'a> {
R820T {
- device: DEVICE_INFO
+ device: DEVICE_INFO,
+ usb
}
}
}
-impl Device for R820T {
- fn init(&self, usb: &Usb) {
+impl<'a> Device for R820T<'a> {
+ fn init(&self) {
// disable Zero-IF mode
- usb.demod_write_reg(1, 0xb1, 0x1a, 1);
+ self.usb.demod_write_reg(1, 0xb1, 0x1a, 1);
// only enable In-phase ADC input
- usb.demod_write_reg(0, 0x08, 0x4d, 1);
+ self.usb.demod_write_reg(0, 0x08, 0x4d, 1);
// the R82XX use 3.57 MHz IF for the DVB-T 6 MHz mode, and
// 4.57 MHz for the 8 MHz mode
- usb.set_if_freq(R82XX_IF_FREQ);
+ self.usb.set_if_freq(R82XX_IF_FREQ);
// enable spectrum inversion
- usb.demod_write_reg(1, 0x15, 0x01, 1);
+ self.usb.demod_write_reg(1, 0x15, 0x01, 1);
}
+
+ fn exit(&self){
+ unimplemented!()
+ }
+
+ fn set_freq(&self, _freq: u32){
+ unimplemented!()
+ }
+
+ fn set_bw(&self, _bw: u32){
+ unimplemented!()
+ }
+
+ fn set_gain(&self, _gain: u32){
+ unimplemented!()
+ }
+
+ fn set_if_gain(&self, _if_gain: u32){
+ unimplemented!()
+ }
+
+ fn set_gain_mode(&self, _mode: bool){
+ unimplemented!()
+ }
+
}
diff --git a/src/lib.rs b/src/lib.rs
index a796c8b..a1c93c7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -56,7 +56,7 @@ impl<'a> RtlSdr<'a> {
usb.init_baseband();
usb.set_i2c_repeater( true);
- let d = r820t::R820T::new();
+ let d = r820t::R820T::new(&usb);
let _found = match usb.i2c_read_reg(d.device.i2c_addr, d.device.check_addr) {
Ok(reg) => {
if reg == d.device.check_val {
@@ -70,7 +70,7 @@ impl<'a> RtlSdr<'a> {
Err(_) => false
};
- d.init(&usb);
+ d.init();
usb.deinit_baseband();
}
diff --git a/src/usb.rs b/src/usb.rs
index 035786e..2767d3d 100644
--- a/src/usb.rs
+++ b/src/usb.rs
@@ -29,8 +29,8 @@ const FIR_DEFAULT: [u8; FIR_LENGTH] = [
];
const DEF_RTL_XTAL_FREQ: u32 = 28800000;
-const MIN_RTL_XTAL_FREQ: u32 = DEF_RTL_XTAL_FREQ - 1000;
-const MAX_RTL_XTAL_FREQ: u32 = DEF_RTL_XTAL_FREQ + 1000;
+// const MIN_RTL_XTAL_FREQ: u32 = DEF_RTL_XTAL_FREQ - 1000;
+// const MAX_RTL_XTAL_FREQ: u32 = DEF_RTL_XTAL_FREQ + 1000;
const CTRL_TIMEOUT: Duration = Duration::from_millis(300);