Partial check-in of R820T tuner controller. Tuning is not yet functional.

This commit is contained in:
dennis.sheirer
2014-05-16 20:13:41 +00:00
parent 39a6868519
commit f70fca55b7
8 changed files with 947 additions and 545 deletions

View File

@@ -24,6 +24,7 @@ import java.util.List;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeNode;
public class BaseNode extends DefaultMutableTreeNode public class BaseNode extends DefaultMutableTreeNode
implements Comparable<BaseNode> implements Comparable<BaseNode>
@@ -103,7 +104,16 @@ public class BaseNode extends DefaultMutableTreeNode
{ {
if( mModel == null ) if( mModel == null )
{ {
return ((BaseNode)getParent()).getModel(); TreeNode parent = getParent();
if( parent != null )
{
return ((BaseNode)parent).getModel();
}
else
{
return null;
}
} }
else else
{ {

View File

@@ -292,37 +292,37 @@ public class TunerManager
} }
break; break;
case RAFAELMICRO_R820T: case RAFAELMICRO_R820T:
// try try
// { {
// R820TTunerController controller = R820TTunerController controller =
// new R820TTunerController( device ); new R820TTunerController( device );
//
// controller.init(); controller.init();
//
// RTL2832Tuner rtlTuner = RTL2832Tuner rtlTuner =
// new RTL2832Tuner( tunerClass, controller ); new RTL2832Tuner( tunerClass, controller );
//
//
// TunerConfiguration config = TunerConfiguration config =
// getTunerConfiguration( rtlTuner ); getTunerConfiguration( rtlTuner );
//
// if( config != null ) if( config != null )
// { {
// rtlTuner.apply( config ); rtlTuner.apply( config );
// } }
//
// mTuners.add( rtlTuner ); mTuners.add( rtlTuner );
// status = sLOADED; status = sLOADED;
// name = rtlTuner.getName(); name = rtlTuner.getName();
// reason = null; reason = null;
// } }
// catch( SourceException se ) catch( SourceException se )
// { {
// status = sNOT_LOADED; status = sNOT_LOADED;
// reason = "Error constructing E4K tuner " reason = "Error constructing E4K tuner "
// + "controller - " + se.getLocalizedMessage(); + "controller - " + se.getLocalizedMessage();
// } }
// break; break;
case FITIPOWER_FC0012: case FITIPOWER_FC0012:
case FITIPOWER_FC0013: case FITIPOWER_FC0013:
case RAFAELMICRO_R828D: case RAFAELMICRO_R828D:

View File

@@ -142,7 +142,6 @@ public abstract class RTL2832TunerController extends TunerController
private Descriptor mDescriptor; private Descriptor mDescriptor;
public static final int sTWO_TO_22_POWER = 4194304; public static final int sTWO_TO_22_POWER = 4194304;
public static final int sOSCILLATOR_FREQUENCY = 28800000; //28.8 MHz
public static final SampleRate sDEFAULT_SAMPLE_RATE = SampleRate.RATE_1_200MHZ; public static final SampleRate sDEFAULT_SAMPLE_RATE = SampleRate.RATE_1_200MHZ;
private SampleRate mSampleRate = sDEFAULT_SAMPLE_RATE; private SampleRate mSampleRate = sDEFAULT_SAMPLE_RATE;
@@ -159,6 +158,7 @@ public abstract class RTL2832TunerController extends TunerController
private AtomicInteger mSampleCounter = new AtomicInteger(); private AtomicInteger mSampleCounter = new AtomicInteger();
private double mSampleRateAverageSum; private double mSampleRateAverageSum;
private int mSampleRateAverageCount; private int mSampleRateAverageCount;
protected int mOscillatorFrequency = 28800000; //28.8 MHz
/** /**
* Abstract tuner controller device. Use the static getTunerClass() method * Abstract tuner controller device. Use the static getTunerClass() method
@@ -304,7 +304,7 @@ public abstract class RTL2832TunerController extends TunerController
public void setIFFrequency( int frequency ) throws UsbException public void setIFFrequency( int frequency ) throws UsbException
{ {
long ifFrequency = ( (long)sTWO_TO_22_POWER * (long)frequency ) / long ifFrequency = ( (long)sTWO_TO_22_POWER * (long)frequency ) /
(long)sOSCILLATOR_FREQUENCY * -1; (long)mOscillatorFrequency * -1;
/* Write byte 2 (high) */ /* Write byte 2 (high) */
writeDemodRegister( mUSBDevice, writeDemodRegister( mUSBDevice,
@@ -1080,7 +1080,7 @@ public abstract class RTL2832TunerController extends TunerController
int ratio = Integer.rotateLeft( high, 16 ) | low; int ratio = Integer.rotateLeft( high, 16 ) | low;
int rate = (int)( sOSCILLATOR_FREQUENCY * sTWO_TO_22_POWER / ratio ); int rate = (int)( mOscillatorFrequency * sTWO_TO_22_POWER / ratio );
SampleRate sampleRate = SampleRate.getClosest( rate ); SampleRate sampleRate = SampleRate.getClosest( rate );
@@ -1479,7 +1479,7 @@ public abstract class RTL2832TunerController extends TunerController
{ {
if( mRunning.compareAndSet( false, true ) ) if( mRunning.compareAndSet( false, true ) )
{ {
Log.debug( "RTL2832TunerController [" + mDescriptor.getSerial() + "] - starting sample fetch thread" ); Log.debug( "RTL2832TunerController [" + getUniqueID() + "] - starting sample fetch thread" );
ArrayList<UsbIrp> irps = new ArrayList<UsbIrp>(); ArrayList<UsbIrp> irps = new ArrayList<UsbIrp>();

View File

@@ -0,0 +1,4 @@
[Dolphin]
Timestamp=2014,5,10,7,19,1
Version=3
ViewMode=1

View File

@@ -22,14 +22,18 @@ import javax.xml.bind.annotation.XmlAttribute;
import source.tuner.TunerConfiguration; import source.tuner.TunerConfiguration;
import source.tuner.TunerType; import source.tuner.TunerType;
import source.tuner.rtl.RTL2832TunerController.SampleRate; import source.tuner.rtl.RTL2832TunerController.SampleRate;
import source.tuner.rtl.r820t.R820TTunerController.R820TGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TLNAGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TMixerGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TVGAGain;
public class R820TTunerConfiguration extends TunerConfiguration public class R820TTunerConfiguration extends TunerConfiguration
{ {
// private R820TGain mMasterGain = R820TGain.AUTOMATIC; private R820TGain mMasterGain = R820TGain.GAIN_36;
// private R820TMixerGain mMixerGain = R820TMixerGain.AUTOMATIC; private R820TMixerGain mMixerGain = R820TMixerGain.GAIN_15;
// private R820TLNAGain mLNAGain = R820TLNAGain.AUTOMATIC; private R820TLNAGain mLNAGain = R820TLNAGain.GAIN_21;
// private R820TEnhanceGain mEnhanceGain = R820TEnhanceGain.AUTOMATIC; private R820TVGAGain mVGAGain = R820TVGAGain.GAIN_210;
private double mFrequencyCorrection = -12.0d; private double mFrequencyCorrection = 0.0d;
private SampleRate mSampleRate = SampleRate.RATE_1_200MHZ; private SampleRate mSampleRate = SampleRate.RATE_1_200MHZ;
/** /**
@@ -48,53 +52,53 @@ public class R820TTunerConfiguration extends TunerConfiguration
@Override @Override
public TunerType getTunerType() public TunerType getTunerType()
{ {
return TunerType.ELONICS_E4000; return TunerType.RAFAELMICRO_R820T;
} }
// @XmlAttribute( name = "master_gain" ) @XmlAttribute( name = "master_gain" )
// public R820TGain getMasterGain() public R820TGain getMasterGain()
// { {
// return mMasterGain; return mMasterGain;
// } }
//
// public void setMasterGain( R820TGain gain ) public void setMasterGain( R820TGain gain )
// { {
// mMasterGain = gain; mMasterGain = gain;
// } }
//
// @XmlAttribute( name = "mixer_gain" ) @XmlAttribute( name = "mixer_gain" )
// public R820TMixerGain getMixerGain() public R820TMixerGain getMixerGain()
// { {
// return mMixerGain; return mMixerGain;
// } }
//
// public void setMixerGain( R820TMixerGain mixerGain ) public void setMixerGain( R820TMixerGain mixerGain )
// { {
// mMixerGain = mixerGain; mMixerGain = mixerGain;
// } }
//
// @XmlAttribute( name = "lna_gain" ) @XmlAttribute( name = "lna_gain" )
// public R820TLNAGain getLNAGain() public R820TLNAGain getLNAGain()
// { {
// return mLNAGain; return mLNAGain;
// } }
//
// public void setLNAGain( R820TLNAGain lnaGain ) public void setLNAGain( R820TLNAGain lnaGain )
// { {
// mLNAGain = lnaGain; mLNAGain = lnaGain;
// } }
//
// @XmlAttribute( name = "enhance_gain" ) @XmlAttribute( name = "vga_gain" )
// public R820TEnhanceGain getEnhanceGain() public R820TVGAGain getVGAGain()
// { {
// return mEnhanceGain; return mVGAGain;
// } }
//
// public void setEnhanceGain( R820TEnhanceGain enhanceGain ) public void setVGAGain( R820TVGAGain vgaGain )
// { {
// mEnhanceGain = enhanceGain; mVGAGain = vgaGain;
// } }
//
@XmlAttribute( name = "frequency_correction" ) @XmlAttribute( name = "frequency_correction" )
public double getFrequencyCorrection() public double getFrequencyCorrection()
{ {

View File

@@ -49,11 +49,17 @@ import source.tuner.TunerConfiguration;
import source.tuner.TunerConfigurationAssignment; import source.tuner.TunerConfigurationAssignment;
import source.tuner.TunerType; import source.tuner.TunerType;
import source.tuner.rtl.RTL2832TunerController.SampleRate; import source.tuner.rtl.RTL2832TunerController.SampleRate;
import source.tuner.rtl.r820t.R820TTunerController.R820TGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TLNAGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TMixerGain;
import source.tuner.rtl.r820t.R820TTunerController.R820TVGAGain;
import controller.ResourceManager; import controller.ResourceManager;
public class R820TTunerConfigurationPanel extends JPanel public class R820TTunerConfigurationPanel extends JPanel
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final R820TGain DEFAULT_GAIN = R820TGain.GAIN_279;
private ResourceManager mResourceManager; private ResourceManager mResourceManager;
private R820TTunerController mController; private R820TTunerController mController;
private R820TTunerConfiguration mSelectedConfig; private R820TTunerConfiguration mSelectedConfig;
@@ -65,10 +71,10 @@ public class R820TTunerConfigurationPanel extends JPanel
private JTextField mName; private JTextField mName;
private JSpinner mFrequencyCorrection; private JSpinner mFrequencyCorrection;
// private JComboBox<R820TGain> mComboMasterGain; private JComboBox<R820TGain> mComboMasterGain;
// private JComboBox<R820TMixerGain> mComboMixerGain; private JComboBox<R820TMixerGain> mComboMixerGain;
// private JComboBox<R820TLNAGain> mComboLNAGain; private JComboBox<R820TLNAGain> mComboLNAGain;
// private JComboBox<R820TEnhanceGain> mComboEnhanceGain; private JComboBox<R820TVGAGain> mComboVGAGain;
private JComboBox<SampleRate> mComboSampleRate; private JComboBox<SampleRate> mComboSampleRate;
@@ -122,21 +128,21 @@ public class R820TTunerConfigurationPanel extends JPanel
mComboConfigurations.setSelectedItem( mSelectedConfig ); mComboConfigurations.setSelectedItem( mSelectedConfig );
// mComboConfigurations.addActionListener( new ActionListener() mComboConfigurations.addActionListener( new ActionListener()
// { {
// @Override @Override
// public void actionPerformed( ActionEvent e ) public void actionPerformed( ActionEvent e )
// { {
// R820TTunerConfiguration selected = R820TTunerConfiguration selected =
// (R820TTunerConfiguration)mComboConfigurations (R820TTunerConfiguration)mComboConfigurations
// .getItemAt( mComboConfigurations.getSelectedIndex() ); .getItemAt( mComboConfigurations.getSelectedIndex() );
//
// if( selected != null ) if( selected != null )
// { {
// update( selected ); update( selected );
// } }
// } }
// }); });
add( mComboConfigurations, "span 2,wrap" ); add( mComboConfigurations, "span 2,wrap" );
@@ -205,11 +211,11 @@ public class R820TTunerConfigurationPanel extends JPanel
{ {
JOptionPane.showMessageDialog( JOptionPane.showMessageDialog(
R820TTunerConfigurationPanel.this, R820TTunerConfigurationPanel.this,
"E4K Tuner Controller - couldn't apply " "R820T Tuner Controller - couldn't apply "
+ "frequency correction value: " + value + + "frequency correction value: " + value +
e1.getLocalizedMessage() ); e1.getLocalizedMessage() );
Log.error( "E4K Tuner Controller - couldn't apply " Log.error( "R820T Tuner Controller - couldn't apply "
+ "frequency correction value: " + value + + "frequency correction value: " + value +
e1.getLocalizedMessage() ); e1.getLocalizedMessage() );
} }
@@ -245,11 +251,11 @@ public class R820TTunerConfigurationPanel extends JPanel
{ {
JOptionPane.showMessageDialog( JOptionPane.showMessageDialog(
R820TTunerConfigurationPanel.this, R820TTunerConfigurationPanel.this,
"E4K Tuner Controller - couldn't apply the sample " "R820T Tuner Controller - couldn't apply the sample "
+ "rate setting [" + sampleRate.getLabel() + "] " + + "rate setting [" + sampleRate.getLabel() + "] " +
eSampleRate.getLocalizedMessage() ); eSampleRate.getLocalizedMessage() );
Log.error( "E4K Tuner Controller - couldn't apply sample " Log.error( "R820T Tuner Controller - couldn't apply sample "
+ "rate setting [" + sampleRate.getLabel() + "] " + + "rate setting [" + sampleRate.getLabel() + "] " +
eSampleRate.getLocalizedMessage() ); eSampleRate.getLocalizedMessage() );
} }
@@ -266,301 +272,317 @@ public class R820TTunerConfigurationPanel extends JPanel
gainPanel.setBorder( BorderFactory.createTitledBorder( "Gain" ) ); gainPanel.setBorder( BorderFactory.createTitledBorder( "Gain" ) );
/* Master Gain Control */ /* Master Gain Control */
// mComboMasterGain = new JComboBox<R820TGain>( R820TGain.values() ); mComboMasterGain = new JComboBox<R820TGain>( R820TGain.values() );
// mComboMasterGain.setSelectedItem( mSelectedConfig.getMasterGain() ); mComboMasterGain.setSelectedItem( mSelectedConfig.getMasterGain() );
//
// mComboMasterGain.addActionListener( new ActionListener() mComboMasterGain.addActionListener( new ActionListener()
// { {
// @Override @Override
// public void actionPerformed( ActionEvent arg0 ) public void actionPerformed( ActionEvent arg0 )
// { {
// try try
// { {
// R820TGain gain = (R820TGain)mComboMasterGain.getSelectedItem(); R820TGain gain = (R820TGain)mComboMasterGain.getSelectedItem();
//
// mController.setGain( (R820TGain)mComboMasterGain.getSelectedItem(), true ); mController.setGain( (R820TGain)mComboMasterGain.getSelectedItem(), true );
//
// if( gain == R820TGain.MANUAL ) if( gain == R820TGain.MANUAL )
// { {
// mComboMixerGain.setSelectedItem( mComboMixerGain.setSelectedItem(
// mController.getMixerGain( true ) ); mController.getMixerGain( true ) );
// mComboMixerGain.setEnabled( true ); mComboMixerGain.setEnabled( true );
//
// mComboLNAGain.setSelectedItem( mComboLNAGain.setSelectedItem(
// mController.getLNAGain( true ) ); mController.getLNAGain( true ) );
// mComboLNAGain.setEnabled( true ); mComboLNAGain.setEnabled( true );
//
// mComboEnhanceGain.setEnabled( true ); mComboVGAGain.setEnabled( true );
// mComboEnhanceGain.setSelectedItem( mComboVGAGain.setSelectedItem(
// mController.getEnhanceGain( true ) ); mController.getVGAGain( true ) );
// } }
// else else
// { {
// mComboMixerGain.setEnabled( false ); mComboMixerGain.setEnabled( false );
// mComboMixerGain.setSelectedItem( gain.getMixerGain() ); mComboMixerGain.setSelectedItem( gain.getMixerGain() );
//
// mComboLNAGain.setEnabled( false ); mComboLNAGain.setEnabled( false );
// mComboLNAGain.setSelectedItem( gain.getLNAGain() ); mComboLNAGain.setSelectedItem( gain.getLNAGain() );
//
// mComboEnhanceGain.setEnabled( false ); mComboVGAGain.setEnabled( false );
// mComboEnhanceGain.setSelectedItem( gain.getEnhanceGain() ); mComboVGAGain.setSelectedItem( gain.getVGAGain() );
// } }
//
// mSelectedConfig.setMasterGain( gain ); mSelectedConfig.setMasterGain( gain );
// save(); save();
// } }
// catch ( UsbException e ) catch ( UsbException e )
// { {
// JOptionPane.showMessageDialog( JOptionPane.showMessageDialog(
// R820TTunerConfigurationPanel.this, R820TTunerConfigurationPanel.this,
// "E4K Tuner Controller - couldn't apply the gain " "R820T Tuner Controller - couldn't apply the gain "
// + "setting - " + e.getLocalizedMessage() ); + "setting - " + e.getLocalizedMessage() );
//
// Log.error( "E4K Tuner Controller - couldn't apply " Log.error( "R820T Tuner Controller - couldn't apply "
// + "gain setting - " + e.getLocalizedMessage() ); + "gain setting - " + e.getLocalizedMessage() );
// } }
// } }
// } ); } );
// mComboMasterGain.setToolTipText( "<html>Select <b>AUTOMATIC</b> for auto " mComboMasterGain.setToolTipText( "<html>Select <b>AUTOMATIC</b> for auto "
// + "gain, <b>MANUAL</b> to enable<br> independent control of " + "gain, <b>MANUAL</b> to enable<br> independent control of "
// + "<i>Mixer</i>, <i>LNA</i> and <i>Enhance</i> gain<br>" + "<i>Mixer</i>, <i>LNA</i> and <i>Enhance</i> gain<br>"
// + "settings, or one of the individual gain settings for<br>" + "settings, or one of the individual gain settings for<br>"
// + "semi-manual gain control</html>" ); + "semi-manual gain control</html>" );
// gainPanel.add( mComboMasterGain ); gainPanel.add( mComboMasterGain );
// gainPanel.add( new JLabel( "Master" ), "wrap" ); gainPanel.add( new JLabel( "Master" ), "wrap" );
//
// /* Mixer Gain Control */ /* Mixer Gain Control */
// mComboMixerGain = new JComboBox<R820TMixerGain>( R820TMixerGain.values() ); mComboMixerGain = new JComboBox<R820TMixerGain>( R820TMixerGain.values() );
// mComboMixerGain.setSelectedItem( mSelectedConfig.getMixerGain() ); mComboMixerGain.setSelectedItem( mSelectedConfig.getMixerGain() );
// mComboMixerGain.addActionListener( new ActionListener() mComboMixerGain.addActionListener( new ActionListener()
// { {
// @Override @Override
// public void actionPerformed( ActionEvent arg0 ) public void actionPerformed( ActionEvent arg0 )
// { {
// EventQueue.invokeLater( new Runnable() EventQueue.invokeLater( new Runnable()
// { {
// @Override @Override
// public void run() public void run()
// { {
// try try
// { {
// R820TMixerGain mixerGain = R820TMixerGain mixerGain =
// (R820TMixerGain)mComboMixerGain.getSelectedItem(); (R820TMixerGain)mComboMixerGain.getSelectedItem();
//
// if( mComboMixerGain.isEnabled() ) if( mixerGain == null )
// { {
// mController.setMixerGain( mixerGain, true ); mixerGain = DEFAULT_GAIN.getMixerGain();
// } }
//
// mSelectedConfig.setMixerGain( mixerGain ); if( mComboMixerGain.isEnabled() )
// save(); {
// } mController.setMixerGain( mixerGain, true );
// catch ( UsbException e ) }
// {
// JOptionPane.showMessageDialog( mSelectedConfig.setMixerGain( mixerGain );
// R820TTunerConfigurationPanel.this, save();
// "E4K Tuner Controller - couldn't apply the mixer " }
// + "gain setting - " + e.getLocalizedMessage() ); catch ( UsbException e )
// {
// Log.error( "E4K Tuner Controller - couldn't apply mixer " JOptionPane.showMessageDialog(
// + "gain setting - " + e.getLocalizedMessage() ); R820TTunerConfigurationPanel.this,
// } "R820T Tuner Controller - couldn't apply the mixer "
// } + "gain setting - " + e.getLocalizedMessage() );
// } );
// } Log.error( "R820T Tuner Controller - couldn't apply mixer "
// } ); + "gain setting - " + e.getLocalizedMessage() );
// mComboMixerGain.setToolTipText( "<html>Mixer Gain. Set master gain " }
// + "to <b>MASTER</b> to enable adjustment</html>" ); }
// mComboMixerGain.setEnabled( false ); } );
// gainPanel.add( mComboMixerGain ); }
// gainPanel.add( new JLabel( "Mixer" ), "wrap" ); } );
// mComboMixerGain.setToolTipText( "<html>Mixer Gain. Set master gain "
// /* LNA Gain Control */ + "to <b>MASTER</b> to enable adjustment</html>" );
// mComboLNAGain = new JComboBox<R820TLNAGain>( R820TLNAGain.values() ); mComboMixerGain.setEnabled( false );
// mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() ); gainPanel.add( mComboMixerGain );
// mComboLNAGain.addActionListener( new ActionListener() gainPanel.add( new JLabel( "Mixer" ), "wrap" );
// {
// @Override /* LNA Gain Control */
// public void actionPerformed( ActionEvent arg0 ) mComboLNAGain = new JComboBox<R820TLNAGain>( R820TLNAGain.values() );
// { mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() );
// try mComboLNAGain.addActionListener( new ActionListener()
// { {
// R820TLNAGain lnaGain = (R820TLNAGain)mComboLNAGain.getSelectedItem(); @Override
// public void actionPerformed( ActionEvent arg0 )
// if( mComboLNAGain.isEnabled() ) {
// { try
// mController.setLNAGain( lnaGain, true ); {
// } R820TLNAGain lnaGain =
// (R820TLNAGain)mComboLNAGain.getSelectedItem();
// mSelectedConfig.setLNAGain( lnaGain );
// save(); if ( lnaGain == null )
// } {
// catch ( UsbException e ) lnaGain = DEFAULT_GAIN.getLNAGain();
// { }
// JOptionPane.showMessageDialog(
// R820TTunerConfigurationPanel.this, if( mComboLNAGain.isEnabled() )
// "E4K Tuner Controller - couldn't apply the LNA " {
// + "gain setting - " + e.getLocalizedMessage() ); mController.setLNAGain( lnaGain, true );
// }
// Log.error( "E4K Tuner Controller - couldn't apply LNA "
// + "gain setting - " + e.getLocalizedMessage() ); mSelectedConfig.setLNAGain( lnaGain );
// } save();
// } }
// } ); catch ( UsbException e )
// mComboLNAGain.setToolTipText( "<html>LNA Gain. Set master gain " {
// + "to <b>MANUAL</b> to enable adjustment</html>" ); JOptionPane.showMessageDialog(
// mComboLNAGain.setEnabled( false ); R820TTunerConfigurationPanel.this,
// gainPanel.add( mComboLNAGain ); "R820T Tuner Controller - couldn't apply the LNA "
// gainPanel.add( new JLabel( "LNA" ), "wrap" ); + "gain setting - " + e.getLocalizedMessage() );
//
// /* Enhance Gain Control */ Log.error( "R820T Tuner Controller - couldn't apply LNA "
// mComboEnhanceGain = new JComboBox<R820TEnhanceGain>( R820TEnhanceGain.values() ); + "gain setting - " + e.getLocalizedMessage() );
// mComboEnhanceGain.setSelectedItem( mSelectedConfig.getEnhanceGain() ); }
// mComboEnhanceGain.addActionListener( new ActionListener() }
// { } );
// @Override mComboLNAGain.setToolTipText( "<html>LNA Gain. Set master gain "
// public void actionPerformed( ActionEvent arg0 ) + "to <b>MANUAL</b> to enable adjustment</html>" );
// { mComboLNAGain.setEnabled( false );
// try gainPanel.add( mComboLNAGain );
// { gainPanel.add( new JLabel( "LNA" ), "wrap" );
// R820TEnhanceGain enhanceGain =
// (R820TEnhanceGain)mComboEnhanceGain.getSelectedItem(); /* VGA Gain Control */
// mComboVGAGain = new JComboBox<R820TVGAGain>( R820TVGAGain.values() );
// if( mComboEnhanceGain.isEnabled() ) mComboVGAGain.setSelectedItem( mSelectedConfig.getVGAGain() );
// { mComboVGAGain.addActionListener( new ActionListener()
// mController.setEnhanceGain( enhanceGain, true ); {
// } @Override
// public void actionPerformed( ActionEvent arg0 )
// mSelectedConfig.setEnhanceGain( enhanceGain ); {
// save(); try
// } {
// catch ( UsbException e ) R820TVGAGain vgaGain =
// { (R820TVGAGain)mComboVGAGain.getSelectedItem();
// JOptionPane.showMessageDialog(
// R820TTunerConfigurationPanel.this, if( vgaGain == null )
// "E4K Tuner Controller - couldn't apply the enhance " {
// + "gain setting - " + e.getLocalizedMessage() ); vgaGain = DEFAULT_GAIN.getVGAGain();
// }
// Log.error( "E4K Tuner Controller - couldn't apply enhance "
// + "gain setting - " + e.getLocalizedMessage() ); if( mComboVGAGain.isEnabled() )
// } {
// } mController.setVGAGain( vgaGain, true );
// } ); }
// mComboEnhanceGain.setToolTipText( "<html>Enhance Gain. Set master gain "
// + "to <b>MANUAL</b> to enable adjustment</html>" ); mSelectedConfig.setVGAGain( vgaGain );
// mComboEnhanceGain.setEnabled( false ); save();
// gainPanel.add( mComboEnhanceGain ); }
// gainPanel.add( new JLabel( "Enhance" ), "wrap" ); catch ( UsbException e )
// {
// add( gainPanel, "span" ); JOptionPane.showMessageDialog(
// R820TTunerConfigurationPanel.this,
// /** "R820T Tuner Controller - couldn't apply the VGA "
// * Create a new configuration + "gain setting - " + e.getLocalizedMessage() );
// */
// mNewConfiguration = new JButton( "New" ); Log.error( "R820T Tuner Controller - couldn't apply VGA "
// + "gain setting - " + e.getLocalizedMessage() );
// mNewConfiguration.addActionListener( new ActionListener() }
// { }
// @Override } );
// public void actionPerformed( ActionEvent e ) mComboVGAGain.setToolTipText( "<html>VGA Gain. Set master gain "
// { + "to <b>MANUAL</b> to enable adjustment</html>" );
// TunerConfiguration config = mComboVGAGain.setEnabled( false );
// mResourceManager.getSettingsManager() gainPanel.add( mComboVGAGain );
// .addNewTunerConfiguration( gainPanel.add( new JLabel( "VGA" ), "wrap" );
// TunerType.ELONICS_E4000,
// "New Configuration" ); add( gainPanel, "span" );
//
// mComboConfigurations.setModel( getModel() ); /**
// * Create a new configuration
// mComboConfigurations.setSelectedItem( config ); */
// mNewConfiguration = new JButton( "New" );
// repaint();
// } mNewConfiguration.addActionListener( new ActionListener()
// } ); {
// @Override
// add( mNewConfiguration ); public void actionPerformed( ActionEvent e )
// {
// /** TunerConfiguration config =
// * Delete the currently selected configuration mResourceManager.getSettingsManager()
// */ .addNewTunerConfiguration(
// mDeleteConfiguration = new JButton( "Delete" ); TunerType.RAFAELMICRO_R820T,
// "New Configuration" );
// mDeleteConfiguration.addActionListener( new ActionListener()
// { mComboConfigurations.setModel( getModel() );
// @Override
// public void actionPerformed( ActionEvent e ) mComboConfigurations.setSelectedItem( config );
// {
// R820TTunerConfiguration selected = repaint();
// (R820TTunerConfiguration)mComboConfigurations }
// .getItemAt( mComboConfigurations.getSelectedIndex() ); } );
//
// if( selected != null ) add( mNewConfiguration );
// {
// int n = JOptionPane.showConfirmDialog( /**
// R820TTunerConfigurationPanel.this, * Delete the currently selected configuration
// "Are you sure you want to delete '" */
// + selected.getName() + "'?", mDeleteConfiguration = new JButton( "Delete" );
// "Are you sure?",
// JOptionPane.YES_NO_OPTION ); mDeleteConfiguration.addActionListener( new ActionListener()
// {
// if( n == JOptionPane.YES_OPTION ) @Override
// { public void actionPerformed( ActionEvent e )
// mResourceManager.getSettingsManager() {
// .deleteTunerConfiguration( selected ); R820TTunerConfiguration selected =
// (R820TTunerConfiguration)mComboConfigurations
// mComboConfigurations.setModel( getModel() ); .getItemAt( mComboConfigurations.getSelectedIndex() );
//
// mComboConfigurations.setSelectedIndex( 0 ); if( selected != null )
// {
// repaint(); int n = JOptionPane.showConfirmDialog(
// } R820TTunerConfigurationPanel.this,
// } "Are you sure you want to delete '"
// } + selected.getName() + "'?",
// } ); "Are you sure?",
// JOptionPane.YES_NO_OPTION );
// add( mDeleteConfiguration, "wrap" );
// } if( n == JOptionPane.YES_OPTION )
// {
// /** mResourceManager.getSettingsManager()
// * Updates gui controls with the values from the tuner configuration .deleteTunerConfiguration( selected );
// * @param config - tuner configuration
// */ mComboConfigurations.setModel( getModel() );
// private void update( R820TTunerConfiguration config )
// { mComboConfigurations.setSelectedIndex( 0 );
// mSelectedConfig = config;
// repaint();
// try }
// { }
// mController.apply( config ); }
// } );
// mName.setText( config.getName() );
// mFrequencyCorrection.setValue( config.getFrequencyCorrection() ); add( mDeleteConfiguration, "wrap" );
// }
// mComboMixerGain.setSelectedItem( mSelectedConfig.getMixerGain() );
// mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() ); /**
// mComboEnhanceGain.setSelectedItem( mSelectedConfig.getEnhanceGain() ); * Updates gui controls with the values from the tuner configuration
// * @param config - tuner configuration
// /* Apply master gain last so that the Mixer, LNA, and Enhance gain */
// * settings are updated with the master setting where necessary */ private void update( R820TTunerConfiguration config )
// mComboMasterGain.setSelectedItem( mSelectedConfig.getMasterGain() ); {
// mSelectedConfig = config;
// mComboSampleRate.setSelectedItem( mSelectedConfig.getSampleRate() );
// try
// mResourceManager.getSettingsManager().setSelectedTunerConfiguration( {
// TunerType.ELONICS_E4000, mController.getUniqueID(), config ); mController.apply( config );
// }
// catch ( SourceException e1 ) mName.setText( config.getName() );
// { mFrequencyCorrection.setValue( config.getFrequencyCorrection() );
// JOptionPane.showMessageDialog(
// R820TTunerConfigurationPanel.this, mComboMixerGain.setSelectedItem( mSelectedConfig.getMixerGain() );
// "E4K Tuner Controller - couldn't " mComboLNAGain.setSelectedItem( mSelectedConfig.getLNAGain() );
// + "apply the tuner configuration settings - " + mComboVGAGain.setSelectedItem( mSelectedConfig.getVGAGain() );
// e1.getLocalizedMessage() );
// /* Apply master gain last so that the Mixer, LNA, and VGA gain
// Log.error( "E4K Tuner Controller - couldn't apply " * settings are updated with the master setting where necessary */
// + "config [" + config.getName() + "] - " + mComboMasterGain.setSelectedItem( mSelectedConfig.getMasterGain() );
// e1.getLocalizedMessage() );
// } mComboSampleRate.setSelectedItem( mSelectedConfig.getSampleRate() );
mResourceManager.getSettingsManager().setSelectedTunerConfiguration(
TunerType.RAFAELMICRO_R820T, mController.getUniqueID(), config );
}
catch ( SourceException e1 )
{
JOptionPane.showMessageDialog(
R820TTunerConfigurationPanel.this,
"R820T Tuner Controller - couldn't "
+ "apply the tuner configuration settings - " +
e1.getLocalizedMessage() );
Log.error( "R820T Tuner Controller - couldn't apply "
+ "config [" + config.getName() + "] - " +
e1.getLocalizedMessage() );
}
} }
/** /**

View File

@@ -30,13 +30,15 @@ import source.SourceException;
import source.tuner.TunerConfiguration; import source.tuner.TunerConfiguration;
import source.tuner.TunerType; import source.tuner.TunerType;
import source.tuner.rtl.RTL2832TunerController; import source.tuner.rtl.RTL2832TunerController;
import source.tuner.rtl.RTL2832TunerController.Address;
import source.tuner.rtl.RTL2832TunerController.Block;
import source.tuner.usb.USBTunerDevice; import source.tuner.usb.USBTunerDevice;
import controller.ResourceManager; import controller.ResourceManager;
public class R820TTunerController extends RTL2832TunerController public class R820TTunerController extends RTL2832TunerController
{ {
public static final int MIN_FREQUENCY = 24000000; public static final int MIN_FREQUENCY = 24000000;
public static final int MAX_FREQUENCY = 176600000; public static final int MAX_FREQUENCY = 1766000000;
public static final byte VERSION = (byte)49; public static final byte VERSION = (byte)49;
private byte mI2CAddress = (byte)0x34; private byte mI2CAddress = (byte)0x34;
@@ -70,25 +72,44 @@ public class R820TTunerController extends RTL2832TunerController
} }
@Override @Override
public void apply( TunerConfiguration config ) throws SourceException public void apply( TunerConfiguration tunerConfig ) throws SourceException
{ {
Log.error( "********* Apply tuner config not yet implemented - R820T tuner controller" ); if( tunerConfig != null &&
tunerConfig instanceof R820TTunerConfiguration )
{
R820TTunerConfiguration config = (R820TTunerConfiguration)tunerConfig;
try
{
SampleRate sampleRate = config.getSampleRate();
setSampleRate( sampleRate );
double correction = config.getFrequencyCorrection();
setFrequencyCorrection( correction );
R820TGain masterGain = config.getMasterGain();
setGain( masterGain, true );
if( masterGain == R820TGain.MANUAL )
{
R820TMixerGain mixerGain = config.getMixerGain();
setMixerGain( mixerGain, true );
R820TLNAGain lnaGain = config.getLNAGain();
setLNAGain( lnaGain, true );
R820TVGAGain vgaGain = config.getVGAGain();
setVGAGain( vgaGain, true );
}
}
catch( UsbException e )
{
throw new SourceException( "R820TTunerController - usb error "
+ "while applying tuner config", e );
}
}
} }
public void init() throws SourceException
{
try
{
initializeRegisters();
}
catch( UsbException e )
{
throw new SourceException( "R820TTunerController - error setting "
+ "registers to initial startup value", e );
}
}
public JPanel getEditor( ResourceManager resourceManager ) public JPanel getEditor( ResourceManager resourceManager )
{ {
return new R820TTunerEditorPanel( this, resourceManager ); return new R820TTunerEditorPanel( this, resourceManager );
@@ -103,67 +124,263 @@ public class R820TTunerController extends RTL2832TunerController
@Override @Override
public void setTunedFrequency( int frequency ) throws SourceException public void setTunedFrequency( int frequency ) throws SourceException
{ {
} Log.info( "R820T - setting frequency to " + frequency );
try
public void initTuner( boolean controlI2CRepeater ) throws UsbException
{
if( controlI2CRepeater )
{ {
enableI2CRepeater( mUSBDevice, true ); enableI2CRepeater( mUSBDevice, true );
}
boolean i2CRepeaterControl = false; boolean controlI2C = false;
setMux( frequency, controlI2C );
setPLL( frequency, controlI2C );
if( controlI2CRepeater )
{
enableI2CRepeater( mUSBDevice, false ); enableI2CRepeater( mUSBDevice, false );
} }
catch( UsbException e )
{
throw new SourceException( "R820TTunerController - exception "
+ "while setting frequency [" + frequency + "] - " +
e.getLocalizedMessage() );
}
}
private void setMux( int frequency, boolean controlI2C ) throws UsbException
{
FrequencyRange range = FrequencyRange.getRangeForFrequency( frequency );
/* Set open drain */
writeR820TRegister( Register.DRAIN, range.getOpenDrain(), controlI2C );
/* RF_MUX, Polymux */
writeR820TRegister( Register.RF_POLY_MUX, range.getRFMuxPolyMux(), controlI2C );
/* TF Band */
writeR820TRegister( Register.TF_BAND, range.getTFC(), controlI2C );
/* XTAL CAP & Drive */
writeR820TRegister( Register.PLL_XTAL_CAPACITOR_AND_DRIVE,
range.getXTALHighCap0P(), controlI2C );
/* Register 8 - what is it? */
writeR820TRegister( Register.UNKNOWN_REGISTER_8, (byte)0x00, controlI2C );
/* Register 9 - what is it? */
writeR820TRegister( Register.UNKNOWN_REGISTER_9, (byte)0x00, controlI2C );
}
public void init() throws SourceException
{
try
{
/* Dummy write to test USB interface */
writeRegister( mUSBDevice, Block.USB,
Address.USB_SYSCTL.getAddress(), (short)0x09, 1 );
initBaseband( mUSBDevice );
enableI2CRepeater( mUSBDevice, true );
boolean i2CRepeaterControl = false;
initTuner( i2CRepeaterControl );
enableI2CRepeater( mUSBDevice, false );
/* Initialize the super class */
super.init();
}
catch( UsbException e )
{
e.printStackTrace();
throw new SourceException( "E4K Tuner Controller - error during "
+ "init()", e );
}
}
public void initTuner( boolean controlI2C ) throws UsbException
{
initializeRegisters( controlI2C );
setTVStandard( controlI2C );
systemFrequencySelect( 0, controlI2C );
getGain();
} }
/** /**
* Partially implements the r82xx_set_tv_standard() method from librtlsdr. * Partially implements the r82xx_set_tv_standard() method from librtlsdr.
* Sets standard to digital tv to support sdr operations only. * Sets standard to digital tv to support sdr operations only.
*/ */
private void setTVStandard() throws UsbException private void setTVStandard( boolean controlI2C ) throws UsbException
{ {
enableI2CRepeater( mUSBDevice, true ); Log.info( "Setting TV Standard" );
/* Init Flag & Xtal check Result */ /* Init Flag & Xtal check Result */
writeR820TRegister( Register.XTAL_CHECK, (byte)0x00, false ); writeR820TRegister( Register.XTAL_CHECK, (byte)0x00, controlI2C );
/* Set version */ /* Set version */
writeR820TRegister( Register.VERSION, VERSION, false ); writeR820TRegister( Register.VERSION, VERSION, controlI2C );
/* LT Gain Test */ /* LT Gain Test */
writeR820TRegister( Register.LNA_TOP, (byte)0x00, false ); writeR820TRegister( Register.LNA_TOP, (byte)0x00, controlI2C );
int calibrationCode = 0;
for( int x = 0; x < 2; x++ ) for( int x = 0; x < 2; x++ )
{ {
/* Set filter cap */ /* Set filter cap */
writeR820TRegister( Register.FILTER_CAPACITOR, (byte)0x6B, false ); writeR820TRegister( Register.FILTER_CAPACITOR, (byte)0x6B, controlI2C );
/* Set calibration clock on */ /* Set calibration clock on */
writeR820TRegister( Register.CALIBRATION_CLOCK, (byte)0x04, false ); writeR820TRegister( Register.CALIBRATION_CLOCK, (byte)0x04, controlI2C );
/* XTAL capacitor 0pF for PLL */ /* XTAL capacitor 0pF for PLL */
writeR820TRegister( Register.PLL_XTAL_CAPACITOR, (byte)0x00, false ); writeR820TRegister( Register.PLL_XTAL_CAPACITOR, (byte)0x00, controlI2C );
setPLL( 5600 * 1000, false ); setPLL( 5600 * 1000, controlI2C );
/* Start trigger */
writeR820TRegister( Register.CALIBRATION_TRIGGER, (byte)0x10, controlI2C );
/* Stop trigger */
writeR820TRegister( Register.CALIBRATION_TRIGGER, (byte)0x00, controlI2C );
/* Set calibration clock off */
writeR820TRegister( Register.CALIBRATION_CLOCK, (byte)0x00, controlI2C );
calibrationCode = getCalibrationCode( controlI2C );
if( calibrationSuccessful( calibrationCode ) )
{
Log.info( "Calibration successful!!" );
break;
}
else
{
Log.info( "Calibration NOT successful!!" );
}
} }
enableI2CRepeater( mUSBDevice, false ); if( calibrationCode == 0x0F )
{
calibrationCode = 0;
}
/* Write calibration code */
writeR820TRegister( Register.FILTER_CALIBRATION_CODE,
(byte)calibrationCode, controlI2C );
/* Set BW, Filter gain & HP Corner */
writeR820TRegister( Register.BANDWIDTH_FILTER_GAIN_HIGHPASS_FILTER_CORNER,
(byte)0x6B, controlI2C );
/* Set Image_R */
writeR820TRegister( Register.IMAGE_REVERSE, (byte)0x00, controlI2C );
/* Set filter_3db, V6MHz */
writeR820TRegister( Register.FILTER_GAIN, (byte)0x10, controlI2C );
/* Channel filter extension */
writeR820TRegister( Register.CHANNEL_FILTER_EXTENSION, (byte)0x60, controlI2C );
/* Loop through */
writeR820TRegister( Register.LOOP_THROUGH, (byte)0x00, controlI2C );
/* Loop through attenuation */
writeR820TRegister( Register.LOOP_THROUGH_ATTENUATION, (byte)0x00, controlI2C );
/* Filter extension widest */
writeR820TRegister( Register.FILTER_EXTENSION_WIDEST, (byte)0x00, controlI2C );
/* RF poly filter current */
writeR820TRegister( Register.RF_POLY_FILTER_CURRENT, (byte)0x60, controlI2C );
Log.info( "Done Setting TV Standard" );
}
private boolean calibrationSuccessful( int calibrationCode )
{
return calibrationCode != 0 && calibrationCode != 0x0F;
}
private int getCalibrationCode( boolean controlI2C ) throws UsbException
{
return getStatusRegister( 4, controlI2C ) & 0x0F;
}
private void systemFrequencySelect( int frequency, boolean controlI2C )
throws UsbException
{
/* Set pre_detect to off */
writeR820TRegister( Register.PRE_DETECT, (byte)0x00, controlI2C );
/* LNA top? */
writeR820TRegister( Register.LNA_TOP, (byte)0xE5, controlI2C );
byte mixer_top;
byte cp_cur;
byte div_buf_cur;
if( frequency == 506000000 ||
frequency == 666000000 ||
frequency == 818000000 )
{
mixer_top = (byte)0x14;
cp_cur = (byte)0x28;
div_buf_cur = (byte)0x20;
}
else
{
mixer_top = (byte)0x24;
cp_cur = (byte)0x38;
div_buf_cur = (byte)0x30;
}
writeR820TRegister( Register.MIXER_TOP, mixer_top, controlI2C );
writeR820TRegister( Register.LNA_VTH_L, (byte)0x53, controlI2C );
writeR820TRegister( Register.MIXER_VTH_L, (byte)0x76, controlI2C );
/* Air-In only for Astrometa */
writeR820TRegister( Register.AIR_CABLE1_INPUT_SELECTOR, (byte)0x00, controlI2C );
writeR820TRegister( Register.CABLE2_INPUT_SELECTOR, (byte)0x00, controlI2C );
writeR820TRegister( Register.CP_CUR, cp_cur, controlI2C );
writeR820TRegister( Register.DIVIDER_BUFFER_CURRENT, div_buf_cur, controlI2C );
writeR820TRegister( Register.FILTER_CURRENT, (byte)0x40, controlI2C );
/* Set LNA - omitted, because this is redundant to first 2 writes */
/* Write discharge mode */
writeR820TRegister( Register.MIXER_TOP2, mixer_top, controlI2C );
/* LNA discharge current */
writeR820TRegister( Register.LNA_DISCHARGE_CURRENT, (byte)0x14, controlI2C );
/* AGC clock 1 khz, external det1 cap 1u */
writeR820TRegister( Register.AGC_CLOCK, (byte)0x00, controlI2C );
writeR820TRegister( Register.UNKNOWN_REGISTER_10, (byte)0x00, controlI2C );
} }
private void setPLL( int frequency, boolean controlI2C ) throws UsbException private void setPLL( int frequency, boolean controlI2C ) throws UsbException
{ {
/* Set reference divider to 0 */ /* Set reference divider to 0 */
writeR820TRegister( Register.PLL_XTAL_CAPACITOR, (byte)0x00, false ); writeR820TRegister( Register.PLL_XTAL_CAPACITOR, (byte)0x00, controlI2C );
/* Set PLL autotune to 128kHz */ /* Set PLL autotune to 128kHz */
writeR820TRegister( Register.PLL_AUTOTUNE, (byte)0x00, false ); writeR820TRegister( Register.PLL_AUTOTUNE, (byte)0x00, controlI2C );
/* Set VCO current to 100 */ /* Set VCO current to 100 */
writeR820TRegister( Register.VCO_CURRENT, (byte)0x80, false ); writeR820TRegister( Register.VCO_CURRENT, (byte)0x80, controlI2C );
/* Calculate divider */ /* Calculate divider */
int mix_div =2; int mix_div =2;
@@ -171,8 +388,11 @@ public class R820TTunerController extends RTL2832TunerController
int div_num = 0; int div_num = 0;
int vco_min = 1770000; int vco_min = 1770000;
int vco_max = vco_min * 2; int vco_max = vco_min * 2;
int vco_power_ref = 2;
int freq_khz = (int)( ( frequency + 500 ) / 1000 ); int freq_khz = (int)( ( frequency + 500 ) / 1000 );
int pll_ref = mOscillatorFrequency;
int pll_ref_khz = ( mOscillatorFrequency + 500 ) / 1000;
while( mix_div <= 64 ) while( mix_div <= 64 )
{ {
@@ -193,6 +413,95 @@ public class R820TTunerController extends RTL2832TunerController
mix_div = mix_div << 1; mix_div = mix_div << 1;
} }
int statusRegister4 = getStatusRegister( 4, controlI2C );
int vco_fine_tune = ( statusRegister4 & 0x30 ) >> 4;
if( vco_fine_tune > vco_power_ref )
{
div_num--;
}
else if( vco_fine_tune < vco_power_ref )
{
div_num++;
}
writeR820TRegister( Register.DIVIDER, (byte)( div_num << 5 ), controlI2C );
long vco_freq = (long)frequency * (long)mix_div;
int nint = (int)( vco_freq / ( 2 * pll_ref ) );
int vco_fra = (int)( ( vco_freq - ( 2 * pll_ref * nint ) ) / 1000 );
if( nint > (( 128 / vco_power_ref ) - 1 ) )
{
Log.error( "R820T Tuner Controller - no valid PLL value for frequency [" + frequency + "]" );
}
int ni = ( nint - 13 ) / 4;
int si = nint - ( 4 * ni ) - 13;
writeR820TRegister( Register.UNKNOWN_REGISTER_14, (byte)ni, controlI2C );
/* PW_SDM */
if( vco_fra > 0 )
{
writeR820TRegister( Register.PW_SDM, (byte)0x08, controlI2C );
}
else
{
writeR820TRegister( Register.PW_SDM, (byte)0x00, controlI2C );
}
/* sdm calculator */
int n_sdm = 2;
int sdm = 0;
while( vco_fra > 1 )
{
if( vco_fra > ( 2 * pll_ref_khz / n_sdm ) )
{
sdm+= 32768 / ( n_sdm / 2 );
vco_fra -= 2 * pll_ref_khz / n_sdm;
if( n_sdm >= 0x8000 )
{
break;
}
}
n_sdm <<= 1;
}
writeR820TRegister( Register.SDM_MSB, (byte)( sdm >> 8 ), controlI2C );
writeR820TRegister( Register.SDM_LSB, (byte)( sdm & 0xFF ), controlI2C );
if( !isPLLLocked( controlI2C ) )
{
/* Increase VCO current */
writeR820TRegister( Register.VCO_CURRENT, (byte)0x60, controlI2C );
if( !isPLLLocked( controlI2C ) )
{
throw new UsbException( "R820T Tuner Controller - couldn't "
+ "achieve PLL lock on frequency [" + frequency + "]" );
}
}
/* set pll autotune to 8kHz */
writeR820TRegister( Register.PLL_AUTOTUNE, (byte)0x08, controlI2C );
}
/**
* Indicates if the Phase Locked Loop (PLL) is locked. Checks status
* register 2 to see if the PLL locked indicator bit is set.
*/
private boolean isPLLLocked( boolean controlI2C ) throws UsbException
{
int register = getStatusRegister( 2, controlI2C );
return ( register & 0x40 ) == 0x40;
} }
/** /**
@@ -201,35 +510,29 @@ public class R820TTunerController extends RTL2832TunerController
* needs to be called once, upon initialization. * needs to be called once, upon initialization.
* @throws UsbException * @throws UsbException
*/ */
private void initializeRegisters() throws UsbException private void initializeRegisters( boolean controlI2C ) throws UsbException
{ {
enableI2CRepeater( mUSBDevice, true );
for( int x = 5; x < mShadowRegister.length; x++ ) for( int x = 5; x < mShadowRegister.length; x++ )
{ {
writeI2CRegister( mUSBDevice, writeI2CRegister( mUSBDevice,
mI2CAddress, mI2CAddress,
(byte)x, (byte)x,
(byte)mShadowRegister[ x ], (byte)mShadowRegister[ x ],
false ); controlI2C );
} }
enableI2CRepeater( mUSBDevice, false );
} }
private void readStatusRegisters( boolean controlI2C ) throws UsbException private int getStatusRegister( int register, boolean controlI2C ) throws UsbException
{ {
/* Set the I2C bus to register 0 to read 5 bytes */ if( 0 <= register && register <= 4 )
writeI2CRegister( mUSBDevice, mI2CAddress, (byte)0, (byte)5, controlI2C ); {
return readI2CRegister( mUSBDevice, mI2CAddress, (byte)register, controlI2C );
byte[] data = new byte[ 5 ]; }
else
byte[] status = read( mUSBDevice, Block.IIC, (byte)0, data ); {
throw new IllegalArgumentException( "R820T Tuner Controller - "
for( int x = 0; x < 5; x++ ) + "attempt to read unknown status register #" + register );
{ }
mShadowRegister[ x ] = status[ x ];
}
} }
public void writeR820TRegister( Register register, public void writeR820TRegister( Register register,
@@ -259,7 +562,55 @@ public class R820TTunerController extends RTL2832TunerController
controlI2C ); controlI2C );
} }
public enum VGAGain private void getGain() throws UsbException
{
int gain = getStatusRegister( 3, true );
Log.info( "Gain original value is [" + gain + "]" );
int converted = ( ( gain & 0x0F ) << 1 ) + ( ( gain & 0xF0 ) >> 4 );
Log.info( "Gain converted value is [" + converted + "]" );
}
public void setGain( R820TGain gain, boolean controlI2C ) throws UsbException
{
setLNAGain( gain.getLNAGain(), controlI2C );
setMixerGain( gain.getMixerGain(), controlI2C );
setVGAGain( gain.getVGAGain(), controlI2C );
}
public void setLNAGain( R820TLNAGain gain, boolean controlI2C ) throws UsbException
{
writeR820TRegister( Register.LNA_GAIN, gain.getSetting(), controlI2C );
}
public R820TLNAGain getLNAGain( boolean controlI2C ) throws UsbException
{
return null;
}
public void setMixerGain( R820TMixerGain gain, boolean controlI2C ) throws UsbException
{
writeR820TRegister( Register.MIXER_GAIN, gain.getSetting(), controlI2C );
}
public R820TMixerGain getMixerGain( boolean controlI2C ) throws UsbException
{
return null;
}
public void setVGAGain( R820TVGAGain gain, boolean controlI2C ) throws UsbException
{
writeR820TRegister( Register.VGA_GAIN, gain.getSetting(), controlI2C );
}
public R820TVGAGain getVGAGain( boolean controlI2C ) throws UsbException
{
return null;
}
public enum R820TVGAGain
{ {
GAIN_0( "0", 0x00 ), GAIN_0( "0", 0x00 ),
GAIN_26( "26", 0x01 ), GAIN_26( "26", 0x01 ),
@@ -281,7 +632,7 @@ public class R820TTunerController extends RTL2832TunerController
private String mLabel; private String mLabel;
private int mSetting; private int mSetting;
private VGAGain( String label, int setting ) private R820TVGAGain( String label, int setting )
{ {
mLabel = label; mLabel = label;
mSetting = setting; mSetting = setting;
@@ -298,7 +649,7 @@ public class R820TTunerController extends RTL2832TunerController
} }
} }
public enum LNAGain public enum R820TLNAGain
{ {
AUTOMATIC( "Automatic", 0x00 ), AUTOMATIC( "Automatic", 0x00 ),
GAIN_0( "0", 0x10 ), GAIN_0( "0", 0x10 ),
@@ -321,7 +672,7 @@ public class R820TTunerController extends RTL2832TunerController
private String mLabel; private String mLabel;
private int mSetting; private int mSetting;
private LNAGain( String label, int setting ) private R820TLNAGain( String label, int setting )
{ {
mLabel = label; mLabel = label;
mSetting = setting; mSetting = setting;
@@ -338,7 +689,7 @@ public class R820TTunerController extends RTL2832TunerController
} }
} }
public enum MixerGain public enum R820TMixerGain
{ {
AUTOMATIC( "Automatic", 0x10 ), AUTOMATIC( "Automatic", 0x10 ),
GAIN_0( "0", 0x00 ), GAIN_0( "0", 0x00 ),
@@ -361,7 +712,7 @@ public class R820TTunerController extends RTL2832TunerController
private String mLabel; private String mLabel;
private int mSetting; private int mSetting;
private MixerGain( String label, int setting ) private R820TMixerGain( String label, int setting )
{ {
mLabel = label; mLabel = label;
mSetting = setting; mSetting = setting;
@@ -378,47 +729,47 @@ public class R820TTunerController extends RTL2832TunerController
} }
} }
public enum Gain public enum R820TGain
{ {
AUTOMATIC( "Automatic", VGAGain.GAIN_312, LNAGain.AUTOMATIC, MixerGain.AUTOMATIC ), AUTOMATIC( "Automatic", R820TVGAGain.GAIN_312, R820TLNAGain.AUTOMATIC, R820TMixerGain.AUTOMATIC ),
MANUAL( "Manual", VGAGain.GAIN_210, LNAGain.GAIN_112, MixerGain.GAIN_105 ), MANUAL( "Manual", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_112, R820TMixerGain.GAIN_105 ),
GAIN_0( "0", VGAGain.GAIN_210, LNAGain.GAIN_0, MixerGain.GAIN_0 ), GAIN_0( "0", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_0, R820TMixerGain.GAIN_0 ),
GAIN_9( "9", VGAGain.GAIN_210, LNAGain.GAIN_9, MixerGain.GAIN_0 ), GAIN_9( "9", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_9, R820TMixerGain.GAIN_0 ),
GAIN_14( "14", VGAGain.GAIN_210, LNAGain.GAIN_9, MixerGain.GAIN_5 ), GAIN_14( "14", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_9, R820TMixerGain.GAIN_5 ),
GAIN_26( "26", VGAGain.GAIN_210, LNAGain.GAIN_21, MixerGain.GAIN_5 ), GAIN_26( "26", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_21, R820TMixerGain.GAIN_5 ),
GAIN_36( "36", VGAGain.GAIN_210, LNAGain.GAIN_21, MixerGain.GAIN_15 ), GAIN_36( "36", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_21, R820TMixerGain.GAIN_15 ),
GAIN_76( "76", VGAGain.GAIN_210, LNAGain.GAIN_61, MixerGain.GAIN_15 ), GAIN_76( "76", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_61, R820TMixerGain.GAIN_15 ),
GAIN_86( "86", VGAGain.GAIN_210, LNAGain.GAIN_61, MixerGain.GAIN_25 ), GAIN_86( "86", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_61, R820TMixerGain.GAIN_25 ),
GAIN_124( "124", VGAGain.GAIN_210, LNAGain.GAIN_99, MixerGain.GAIN_25 ), GAIN_124( "124", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_99, R820TMixerGain.GAIN_25 ),
GAIN_143( "143", VGAGain.GAIN_210, LNAGain.GAIN_99, MixerGain.GAIN_44 ), GAIN_143( "143", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_99, R820TMixerGain.GAIN_44 ),
GAIN_156( "156", VGAGain.GAIN_210, LNAGain.GAIN_112, MixerGain.GAIN_44 ), GAIN_156( "156", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_112, R820TMixerGain.GAIN_44 ),
GAIN_165( "165", VGAGain.GAIN_210, LNAGain.GAIN_112, MixerGain.GAIN_53 ), GAIN_165( "165", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_112, R820TMixerGain.GAIN_53 ),
GAIN_196( "196", VGAGain.GAIN_210, LNAGain.GAIN_143, MixerGain.GAIN_53 ), GAIN_196( "196", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_143, R820TMixerGain.GAIN_53 ),
GAIN_208( "208", VGAGain.GAIN_210, LNAGain.GAIN_143, MixerGain.GAIN_63 ), GAIN_208( "208", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_143, R820TMixerGain.GAIN_63 ),
GAIN_228( "228", VGAGain.GAIN_210, LNAGain.GAIN_165, MixerGain.GAIN_63 ), GAIN_228( "228", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_165, R820TMixerGain.GAIN_63 ),
GAIN_253( "253", VGAGain.GAIN_210, LNAGain.GAIN_165, MixerGain.GAIN_88 ), GAIN_253( "253", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_165, R820TMixerGain.GAIN_88 ),
GAIN_279( "279", VGAGain.GAIN_210, LNAGain.GAIN_191, MixerGain.GAIN_88 ), GAIN_279( "279", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_191, R820TMixerGain.GAIN_88 ),
GAIN_296( "296", VGAGain.GAIN_210, LNAGain.GAIN_191, MixerGain.GAIN_105 ), GAIN_296( "296", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_191, R820TMixerGain.GAIN_105 ),
GAIN_327( "327", VGAGain.GAIN_210, LNAGain.GAIN_222, MixerGain.GAIN_105 ), GAIN_327( "327", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_222, R820TMixerGain.GAIN_105 ),
GAIN_337( "337", VGAGain.GAIN_210, LNAGain.GAIN_222, MixerGain.GAIN_115 ), GAIN_337( "337", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_222, R820TMixerGain.GAIN_115 ),
GAIN_363( "363", VGAGain.GAIN_210, LNAGain.GAIN_248, MixerGain.GAIN_115 ), GAIN_363( "363", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_248, R820TMixerGain.GAIN_115 ),
GAIN_371( "371", VGAGain.GAIN_210, LNAGain.GAIN_248, MixerGain.GAIN_123 ), GAIN_371( "371", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_248, R820TMixerGain.GAIN_123 ),
GAIN_385( "385", VGAGain.GAIN_210, LNAGain.GAIN_262, MixerGain.GAIN_123 ), GAIN_385( "385", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_262, R820TMixerGain.GAIN_123 ),
GAIN_401( "401", VGAGain.GAIN_210, LNAGain.GAIN_262, MixerGain.GAIN_139 ), GAIN_401( "401", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_262, R820TMixerGain.GAIN_139 ),
GAIN_420( "420", VGAGain.GAIN_210, LNAGain.GAIN_281, MixerGain.GAIN_139 ), GAIN_420( "420", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_281, R820TMixerGain.GAIN_139 ),
GAIN_433( "433", VGAGain.GAIN_210, LNAGain.GAIN_281, MixerGain.GAIN_152 ), GAIN_433( "433", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_281, R820TMixerGain.GAIN_152 ),
GAIN_438( "438", VGAGain.GAIN_210, LNAGain.GAIN_286, MixerGain.GAIN_152 ), GAIN_438( "438", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_286, R820TMixerGain.GAIN_152 ),
GAIN_444( "444", VGAGain.GAIN_210, LNAGain.GAIN_286, MixerGain.GAIN_158 ), GAIN_444( "444", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_286, R820TMixerGain.GAIN_158 ),
GAIN_479( "479", VGAGain.GAIN_210, LNAGain.GAIN_321, MixerGain.GAIN_158 ), GAIN_479( "479", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_321, R820TMixerGain.GAIN_158 ),
GAIN_482( "482", VGAGain.GAIN_210, LNAGain.GAIN_321, MixerGain.GAIN_161 ), GAIN_482( "482", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_321, R820TMixerGain.GAIN_161 ),
GAIN_495( "495", VGAGain.GAIN_210, LNAGain.GAIN_334, MixerGain.GAIN_161 ); GAIN_495( "495", R820TVGAGain.GAIN_210, R820TLNAGain.GAIN_334, R820TMixerGain.GAIN_161 );
private String mLabel; private String mLabel;
private VGAGain mVGAGain; private R820TVGAGain mVGAGain;
private LNAGain mLNAGain; private R820TLNAGain mLNAGain;
private MixerGain mMixerGain; private R820TMixerGain mMixerGain;
private Gain( String label, VGAGain vga, LNAGain lna, MixerGain mixer ) private R820TGain( String label, R820TVGAGain vga, R820TLNAGain lna, R820TMixerGain mixer )
{ {
mLabel = label; mLabel = label;
mVGAGain = vga; mVGAGain = vga;
@@ -431,17 +782,17 @@ public class R820TTunerController extends RTL2832TunerController
return mLabel; return mLabel;
} }
public VGAGain getVGAGain() public R820TVGAGain getVGAGain()
{ {
return mVGAGain; return mVGAGain;
} }
public LNAGain getLNAGain() public R820TLNAGain getLNAGain()
{ {
return mLNAGain; return mLNAGain;
} }
public MixerGain getMixerGain() public R820TMixerGain getMixerGain()
{ {
return mMixerGain; return mMixerGain;
} }
@@ -526,46 +877,52 @@ public class R820TTunerController extends RTL2832TunerController
public enum FrequencyRange public enum FrequencyRange
{ {
BAND_024( 24000000, 49999999, 0x08, 0x02, 0xDF, 0x02, 0x01 ), RANGE_024( 24000000, 49999999, 0x08, 0x02, 0xDF, 0x02, 0x01 ),
BAND_050( 50000000, 54999999, 0x08, 0x02, 0xBE, 0x02, 0x01 ), RANGE_050( 50000000, 54999999, 0x08, 0x02, 0xBE, 0x02, 0x01 ),
BAND_055( 55000000, 59999999, 0x08, 0x02, 0x8B, 0x02, 0x01 ), RANGE_055( 55000000, 59999999, 0x08, 0x02, 0x8B, 0x02, 0x01 ),
BAND_060( 60000000, 64999999, 0x08, 0x02, 0x7B, 0x02, 0x01 ), RANGE_060( 60000000, 64999999, 0x08, 0x02, 0x7B, 0x02, 0x01 ),
BAND_065( 65000000, 69999999, 0x08, 0x02, 0x69, 0x02, 0x01 ), RANGE_065( 65000000, 69999999, 0x08, 0x02, 0x69, 0x02, 0x01 ),
BAND_070( 70000000, 74999999, 0x08, 0x02, 0x58, 0x02, 0x01 ), RANGE_070( 70000000, 74999999, 0x08, 0x02, 0x58, 0x02, 0x01 ),
BAND_075( 75000000, 79999999, 0x00, 0x02, 0x44, 0x02, 0x01 ), RANGE_075( 75000000, 79999999, 0x00, 0x02, 0x44, 0x02, 0x01 ),
BAND_080( 80000000, 89999999, 0x00, 0x02, 0x44, 0x02, 0x01 ), RANGE_080( 80000000, 89999999, 0x00, 0x02, 0x44, 0x02, 0x01 ),
BAND_090( 90000000, 99999999, 0x00, 0x02, 0x34, 0x01, 0x01 ), RANGE_090( 90000000, 99999999, 0x00, 0x02, 0x34, 0x01, 0x01 ),
BAND_100( 100000000, 109999999, 0x00, 0x02, 0x34, 0x01, 0x01 ), RANGE_100( 100000000, 109999999, 0x00, 0x02, 0x34, 0x01, 0x01 ),
BAND_110( 110000000, 119999999, 0x00, 0x02, 0x24, 0x01, 0x01 ), RANGE_110( 110000000, 119999999, 0x00, 0x02, 0x24, 0x01, 0x01 ),
BAND_120( 120000000, 139999999, 0x00, 0x02, 0x24, 0x01, 0x01 ), RANGE_120( 120000000, 139999999, 0x00, 0x02, 0x24, 0x01, 0x01 ),
BAND_140( 140000000, 179999999, 0x00, 0x02, 0x14, 0x01, 0x01 ), RANGE_140( 140000000, 179999999, 0x00, 0x02, 0x14, 0x01, 0x01 ),
BAND_180( 180000000, 219999999, 0x00, 0x02, 0x13, 0x00, 0x00 ), RANGE_180( 180000000, 219999999, 0x00, 0x02, 0x13, 0x00, 0x00 ),
BAND_220( 220000000, 249999999, 0x00, 0x02, 0x13, 0x00, 0x00 ), RANGE_220( 220000000, 249999999, 0x00, 0x02, 0x13, 0x00, 0x00 ),
BAND_250( 250000000, 279999999, 0x00, 0x02, 0x11, 0x00, 0x00 ), RANGE_250( 250000000, 279999999, 0x00, 0x02, 0x11, 0x00, 0x00 ),
BAND_280( 280000000, 309999999, 0x00, 0x02, 0x00, 0x00, 0x00 ), RANGE_280( 280000000, 309999999, 0x00, 0x02, 0x00, 0x00, 0x00 ),
BAND_310( 310000000, 449999999, 0x00, 0x41, 0x00, 0x00, 0x00 ), RANGE_310( 310000000, 449999999, 0x00, 0x41, 0x00, 0x00, 0x00 ),
BAND_450( 450000000, 587999999, 0x00, 0x41, 0x00, 0x00, 0x00 ), RANGE_450( 450000000, 587999999, 0x00, 0x41, 0x00, 0x00, 0x00 ),
BAND_588( 588000000, 649999999, 0x00, 0x40, 0x00, 0x00, 0x00 ), RANGE_588( 588000000, 649999999, 0x00, 0x40, 0x00, 0x00, 0x00 ),
BAND_650( 650000000, 1766000000, 0x00, 0x40, 0x00, 0x00, 0x00 ), RANGE_650( 650000000, 1766000000, 0x00, 0x40, 0x00, 0x00, 0x00 ),
BAND_UNK( 0, 0, 0, 0, 0, 0, 0 ); RANGE_UNK( 0, 0, 0, 0, 0, 0, 0 );
private int mMinFrequency; private int mMinFrequency;
private int mMaxFrequency; private int mMaxFrequency;
private int mOpenD; private int mOpenDrain;
private int mRFMuxPloy; private int mRFMux_PolyMux;
private int mTF_c; private int mTF_c;
private int mXtalCap20p; private int mXtalCap20p;
private int mXtalCap10p; private int mXtalCap10p;
private FrequencyRange( int minFrequency, private FrequencyRange( int minFrequency,
int maxFrequency, int maxFrequency,
int openD, int openDrain,
int rfMuxPloy, int rfMuxPloy,
int tf_c, int tf_c,
int xtalCap20p, int xtalCap20p,
int xtalCap10p ) int xtalCap10p )
{ {
mMinFrequency = minFrequency;
mMaxFrequency = maxFrequency;
mOpenDrain = openDrain;
mRFMux_PolyMux = rfMuxPloy;
mTF_c = tf_c;
mXtalCap20p = xtalCap20p;
mXtalCap10p = xtalCap10p;
} }
public boolean contains( int frequency ) public boolean contains( int frequency )
@@ -583,7 +940,7 @@ public class R820TTunerController extends RTL2832TunerController
} }
} }
return BAND_UNK; return RANGE_UNK;
} }
public int getMinFrequency() public int getMinFrequency()
@@ -596,14 +953,14 @@ public class R820TTunerController extends RTL2832TunerController
return mMaxFrequency; return mMaxFrequency;
} }
public byte getOpenD() public byte getOpenDrain()
{ {
return (byte)mOpenD; return (byte)mOpenDrain;
} }
public byte getRFMuxPloy() public byte getRFMuxPolyMux()
{ {
return (byte)mRFMuxPloy; return (byte)mRFMux_PolyMux;
} }
public byte getTFC() public byte getTFC()
@@ -621,9 +978,14 @@ public class R820TTunerController extends RTL2832TunerController
return (byte)mXtalCap10p; return (byte)mXtalCap10p;
} }
public byte getXTALCap0P() public byte getXTALLowCap0P()
{ {
return (byte)0x0; return (byte)0x08;
}
public byte getXTALHighCap0P()
{
return (byte)0x10;
} }
} }

View File

@@ -84,7 +84,7 @@ public class R820TTunerEditorPanel extends JPanel implements FrequencyChangeList
} }
catch ( SourceException e ) catch ( SourceException e )
{ {
Log.error( "E4KTunerController - error setting frequency [" + Log.error( "R820T Tuner Controller - error setting frequency [" +
frequency + "] - " + e.getLocalizedMessage() ); frequency + "] - " + e.getLocalizedMessage() );
} }
} }