From a792fa11bea0bde00aa9aaf0aa6c2640bdb633a3 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Fri, 3 Aug 2018 16:19:11 +0300 Subject: Implement r820t init --- src/devices/mod.rs | 4 +++- src/devices/r820t.rs | 18 ++++++++++++++++-- src/usb.rs | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/devices/mod.rs b/src/devices/mod.rs index 05dd2a3..659b131 100644 --- a/src/devices/mod.rs +++ b/src/devices/mod.rs @@ -1,3 +1,5 @@ +use usb::Usb; + pub mod fc0013; pub mod r820t; @@ -10,5 +12,5 @@ pub struct DeviceInfo { } pub trait Device { - fn init(&self); + fn init(&self, &Usb); } diff --git a/src/devices/r820t.rs b/src/devices/r820t.rs index fec572c..46046bc 100644 --- a/src/devices/r820t.rs +++ b/src/devices/r820t.rs @@ -1,4 +1,7 @@ use super::{DeviceInfo, Device}; +use usb::Usb; + +const R82XX_IF_FREQ: u32 = 3570000; pub struct R820T { pub device: DeviceInfo @@ -21,7 +24,18 @@ impl R820T { } impl Device for R820T { - fn init(&self) { - println!("Init {}", self.device.name); + fn init(&self, usb: &Usb) { + // disable Zero-IF mode + usb.demod_write_reg(1, 0xb1, 0x1a, 1); + + // only enable In-phase ADC input + 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); + + // enable spectrum inversion + usb.demod_write_reg(1, 0x15, 0x01, 1); } } diff --git a/src/usb.rs b/src/usb.rs index fdae356..035786e 100644 --- a/src/usb.rs +++ b/src/usb.rs @@ -28,6 +28,9 @@ const FIR_DEFAULT: [u8; FIR_LENGTH] = [ 0x9c, 0x0d, 0x71, 0x11, 0x14, 0x71, 0x74, 0x19, 0x41, 0xa5, ]; +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 CTRL_TIMEOUT: Duration = Duration::from_millis(300); @@ -181,6 +184,19 @@ impl<'a> Usb<'a> { self.demod_write_reg(0, 0x0d, 0x83, 1); } + pub fn set_if_freq(&self, freq: u32) { + let rtl_xtal: u32 = DEF_RTL_XTAL_FREQ; // need to apply PPM correction + let base = 1u32 << 22; + let if_freq: i32 = (freq as f64 * base as f64 / rtl_xtal as f64 * -1f64) as i32; + + let tmp = ((if_freq >> 16) as u16) & 0x3f; + self.demod_write_reg(1, 0x19, tmp, 1); + let tmp = ((if_freq >> 8) as u16) & 0xff; + self.demod_write_reg(1, 0x1a, tmp, 1); + let tmp = if_freq as u16 & 0xff; + self.demod_write_reg(1, 0x1b, tmp, 1); + } + pub fn deinit_baseband(&self) { // deinit tuner? -- cgit v1.3.1