Permalink
Browse files

r82xx: set_dithering()

  • Loading branch information...
keenerd committed Aug 2, 2014
1 parent 3dfa4ad commit 3f2632dcaf5ea2c2f28af99a94c64b804a063bfd
Showing with 46 additions and 3 deletions.
  1. +11 −0 include/rtl-sdr.h
  2. +2 −0 include/tuner_r82xx.h
  3. +8 −0 src/librtlsdr.c
  4. +16 −1 src/rtl_sdr.c
  5. +9 −2 src/tuner_r82xx.c
View
@@ -322,6 +322,17 @@ RTLSDR_API int rtlsdr_set_offset_tuning(rtlsdr_dev_t *dev, int on);
*/
RTLSDR_API int rtlsdr_get_offset_tuning(rtlsdr_dev_t *dev);
/*!
* Enable or disable frequency dithering for r820t tuners.
* Must be performed before freq_set().
* Fails for other tuners.
*
* \param dev the device handle given by rtlsdr_open()
* \param on 0 means disabled, 1 enabled
* \return 0 on success
*/
RTLSDR_API int rtlsdr_set_dithering(rtlsdr_dev_t *dev, int dither);
/* streaming functions */
RTLSDR_API int rtlsdr_reset_buffer(rtlsdr_dev_t *dev);
View
@@ -84,6 +84,7 @@ struct r82xx_priv {
uint8_t input;
int has_lock;
int init_done;
int disable_dither;
/* Store current mode */
uint32_t delsys;
@@ -116,5 +117,6 @@ int r82xx_init(struct r82xx_priv *priv);
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);
#endif
View
@@ -1266,6 +1266,14 @@ int rtlsdr_get_offset_tuning(rtlsdr_dev_t *dev)
return (dev->offs_freq) ? 1 : 0;
}
int rtlsdr_set_dithering(rtlsdr_dev_t *dev, int dither)
{
if (dev->tuner_type == RTLSDR_TUNER_R820T) {
return r82xx_set_dither(&dev->r82xx_p, dither);
}
return 1;
}
static rtlsdr_dongle_t *find_known_device(uint16_t vid, uint16_t pid)
{
unsigned int i;
View
@@ -56,6 +56,7 @@ void usage(void)
"\t[-n number of samples to read (default: 0, infinite)]\n"
"\t[-S force sync output (default: async)]\n"
"\t[-D direct_sampling_mode, 0 (default/off), 1 (I), 2 (Q), 3 (no-mod)]\n"
"\t[-N no dithering (default: use dithering)]\n"
"\tfilename (a '-' dumps samples to stdout)\n\n");
exit(1);
}
@@ -115,6 +116,7 @@ int main(int argc, char **argv)
int ppm_error = 0;
int sync_mode = 0;
int direct_sampling = 0;
int dithering = 1;
FILE *file;
uint8_t *buffer;
int dev_index = 0;
@@ -123,7 +125,7 @@ int main(int argc, char **argv)
uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
uint32_t out_block_size = DEFAULT_BUF_LENGTH;
while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:D:S")) != -1) {
while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:D:SN")) != -1) {
switch (opt) {
case 'd':
dev_index = verbose_device_search(optarg);
@@ -153,6 +155,9 @@ int main(int argc, char **argv)
case 'D':
direct_sampling = atoi(optarg);
break;
case 'N':
dithering = 0;
break;
default:
usage();
break;
@@ -203,6 +208,16 @@ int main(int argc, char **argv)
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE );
#endif
if (!dithering) {
fprintf(stderr, "Disabling dithering... ");
r = rtlsdr_set_dithering(dev, dithering);
if (r) {
fprintf(stderr, "failure\n");
} else {
fprintf(stderr, "success\n");
}
}
if (direct_sampling) {
verbose_direct_sampling(dev, direct_sampling);
}
View
@@ -506,7 +506,10 @@ static int r82xx_set_pll(struct r82xx_priv *priv, uint32_t freq)
else
val = 0x00;
rc = r82xx_write_reg_mask(priv, 0x12, val, 0x08);
if (priv->disable_dither)
val |= 0x10;
rc = r82xx_write_reg_mask(priv, 0x12, val, 0x18);
if (rc < 0)
return rc;
@@ -1142,7 +1145,11 @@ int r82xx_set_nomod(struct r82xx_priv *priv)
return rc;
}
int r82xx_set_dither(struct r82xx_priv *priv, int dither)
{
priv->disable_dither = !dither;
return 0;
}
/*
* r82xx standby logic

0 comments on commit 3f2632d

Please sign in to comment.