Permalink
Browse files

r82xx: tejeez's if/bw filters

  • Loading branch information...
keenerd committed Aug 2, 2014
1 parent 3f2632d commit a7caaac7a41ca7f8765fa062170ef51a7d09d7c6
Showing with 139 additions and 175 deletions.
  1. +4 −0 include/rtl-sdr.h
  2. +4 −1 include/tuner_r82xx.h
  3. +38 −11 src/librtlsdr.c
  4. +93 −163 src/tuner_r82xx.c
View
@@ -144,6 +144,10 @@ RTLSDR_API int rtlsdr_read_eeprom(rtlsdr_dev_t *dev, uint8_t *data,
RTLSDR_API int rtlsdr_set_center_freq(rtlsdr_dev_t *dev, uint32_t freq);
RTLSDR_API int rtlsdr_set_if_freq(rtlsdr_dev_t *dev, uint32_t freq);
RTLSDR_API int rtlsdr_set_if_bandwidth(rtlsdr_dev_t *dev, int bw);
/*!
* Get actual frequency the device is tuned to.
*
View
@@ -32,7 +32,8 @@
#define R82XX_CHECK_ADDR 0x00
#define R82XX_CHECK_VAL 0x69
#define R82XX_IF_FREQ 3570000
#define R82XX_DEFAULT_IF_FREQ 6000000
#define R82XX_DEFAULT_IF_BW 2000000
#define REG_SHADOW_START 5
#define NUM_REGS 30
@@ -118,5 +119,7 @@ int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq);
int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain);
int r82xx_set_nomod(struct r82xx_priv *priv);
int r82xx_set_dither(struct r82xx_priv *priv, int dither);
int r82xx_set_bw(struct r82xx_priv *priv, uint32_t bw);
int r82xx_set_if_freq(struct r82xx_priv *priv, uint32_t freq);
#endif
View
@@ -64,6 +64,7 @@ typedef struct rtlsdr_tuner_iface {
int (*set_gain)(void *, int gain /* tenth dB */);
int (*set_if_gain)(void *, int stage, int gain /* tenth dB */);
int (*set_gain_mode)(void *, int manual);
int (*set_if_freq)(void *, uint32_t freq /* Hz */);
} rtlsdr_tuner_iface_t;
enum rtlsdr_async_status {
@@ -123,6 +124,7 @@ struct rtlsdr_dev {
int dev_lost;
int driver_active;
unsigned int xfer_errors;
int tuner_initialized;
};
void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val);
@@ -238,7 +240,17 @@ int r820t_set_freq(void *dev, uint32_t freq) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
return r82xx_set_freq(&devt->r82xx_p, freq);
}
int r820t_set_bw(void *dev, int bw) { return 0; }
int r820t_set_bw(void *dev, int bw) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
return r82xx_set_bw(&devt->r82xx_p, bw);
}
int r820t_set_if_freq(void *dev, uint32_t freq) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
return r82xx_set_if_freq(&devt->r82xx_p, freq);
}
int r820t_set_gain(void *dev, int gain) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
return r82xx_set_gain(&devt->r82xx_p, 1, gain);
@@ -251,37 +263,37 @@ int r820t_set_gain_mode(void *dev, int manual) {
/* definition order must match enum rtlsdr_tuner */
static rtlsdr_tuner_iface_t tuners[] = {
{
NULL, NULL, NULL, NULL, NULL, NULL, NULL /* dummy for unknown tuners */
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* dummy for unknown tuners */
},
{
e4000_init, e4000_exit,
e4000_set_freq, e4000_set_bw, e4000_set_gain, e4000_set_if_gain,
e4000_set_gain_mode
e4000_set_gain_mode, NULL
},
{
_fc0012_init, fc0012_exit,
fc0012_set_freq, fc0012_set_bw, _fc0012_set_gain, NULL,
fc0012_set_gain_mode
fc0012_set_gain_mode, NULL
},
{
_fc0013_init, fc0013_exit,
fc0013_set_freq, fc0013_set_bw, _fc0013_set_gain, NULL,
fc0013_set_gain_mode
fc0013_set_gain_mode, NULL
},
{
fc2580_init, fc2580_exit,
_fc2580_set_freq, fc2580_set_bw, fc2580_set_gain, NULL,
fc2580_set_gain_mode
fc2580_set_gain_mode, NULL
},
{
r820t_init, r820t_exit,
r820t_set_freq, r820t_set_bw, r820t_set_gain, NULL,
r820t_set_gain_mode
r820t_set_gain_mode, r820t_set_if_freq
},
{
r820t_init, r820t_exit,
r820t_set_freq, r820t_set_bw, r820t_set_gain, NULL,
r820t_set_gain_mode
r820t_set_gain_mode, r820t_set_if_freq
},
};
@@ -662,6 +674,7 @@ int rtlsdr_deinit_baseband(rtlsdr_dev_t *dev)
rtlsdr_set_i2c_repeater(dev, 1);
r = dev->tuner->exit(dev); /* deinitialize tuner */
rtlsdr_set_i2c_repeater(dev, 0);
dev->tuner_initialized = 0;
}
/* poweroff demodulator and ADCs */
@@ -693,6 +706,14 @@ int rtlsdr_set_if_freq(rtlsdr_dev_t *dev, uint32_t freq)
tmp = if_freq & 0xff;
r |= rtlsdr_demod_write_reg(dev, 1, 0x1b, tmp, 1);
/* Tell the R820T driver which IF frequency we are currently using
* so that it can choose the optimal IF filter settings.
* Works for normal tuning as well as no-mod direct sampling! */
if(dev->tuner_initialized && dev->tuner && dev->tuner->set_if_freq) {
rtlsdr_set_i2c_repeater(dev, 1);
dev->tuner->set_if_freq(dev, freq);
rtlsdr_set_i2c_repeater(dev, 0);
}
return r;
}
@@ -1144,6 +1165,7 @@ int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on)
rtlsdr_set_i2c_repeater(dev, 1);
r = dev->tuner->exit(dev);
rtlsdr_set_i2c_repeater(dev, 0);
dev->tuner_initialized = 0;
}
}
@@ -1153,6 +1175,7 @@ int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on)
fprintf(stderr, "Tuning E4000 to 3708 MHz\n");
rtlsdr_set_i2c_repeater(dev, 1);
dev->tuner->init(dev);
dev->tuner_initialized = 1;
dev->tuner->set_freq(dev, 3708000000u);
e4000_set_bw(dev, 15000000);
rtlsdr_set_i2c_repeater(dev, 0);
@@ -1161,6 +1184,7 @@ int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on)
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
rtlsdr_set_i2c_repeater(dev, 1);
dev->tuner->init(dev);
dev->tuner_initialized = 1;
r82xx_set_nomod(&devt->r82xx_p);
rtlsdr_set_i2c_repeater(dev, 0);
}
@@ -1190,11 +1214,12 @@ int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on)
rtlsdr_set_i2c_repeater(dev, 1);
r |= dev->tuner->init(dev);
rtlsdr_set_i2c_repeater(dev, 0);
dev->tuner_initialized = 1;
}
if ((dev->tuner_type == RTLSDR_TUNER_R820T) ||
(dev->tuner_type == RTLSDR_TUNER_R828D)) {
r |= rtlsdr_set_if_freq(dev, R82XX_IF_FREQ);
r |= rtlsdr_set_if_freq(dev, R82XX_DEFAULT_IF_FREQ);
/* enable spectrum inversion */
r |= rtlsdr_demod_write_reg(dev, 1, 0x15, 0x01, 1);
@@ -1585,7 +1610,7 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
/* the R82XX use 3.57 MHz IF for the DVB-T 6 MHz mode, and
* 4.57 MHz for the 8 MHz mode */
rtlsdr_set_if_freq(dev, R82XX_IF_FREQ);
rtlsdr_set_if_freq(dev, R82XX_DEFAULT_IF_FREQ);
/* enable spectrum inversion */
rtlsdr_demod_write_reg(dev, 1, 0x15, 0x01, 1);
@@ -1598,8 +1623,10 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
break;
}
if (dev->tuner->init)
if (dev->tuner->init) {
r = dev->tuner->init(dev);
dev->tuner_initialized = 1;
}
rtlsdr_set_i2c_repeater(dev, 0);
Oops, something went wrong.

0 comments on commit a7caaac

Please sign in to comment.