diff options
author | dinashi <dos21h@gmail.com> | 2023-01-06 20:55:52 +0000 |
---|---|---|
committer | dinashi <dos21h@gmail.com> | 2023-01-06 20:55:52 +0000 |
commit | 18e567bd588d9976deefbd0191d495c57a0acd60 (patch) | |
tree | f98b1be9d26e46db30bc390d2a0939fcf9e206fe /src/librtlsdr.c | |
parent | 37b99c704d77c60fa808fd393d17045d1d6cf32e (diff) | |
download | r820t-18e567bd588d9976deefbd0191d495c57a0acd60.tar.gz r820t-18e567bd588d9976deefbd0191d495c57a0acd60.zip |
Diffstat (limited to 'src/librtlsdr.c')
-rw-r--r-- | src/librtlsdr.c | 113 |
1 files changed, 62 insertions, 51 deletions
diff --git a/src/librtlsdr.c b/src/librtlsdr.c index 096abae..538c0dd 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -43,10 +43,10 @@ #define TWO_POW(n) ((double)(1ULL<<(n))) #include "rtl-sdr.h" -#include "tuner_e4k.h" -#include "tuner_fc0012.h" -#include "tuner_fc0013.h" -#include "tuner_fc2580.h" +//#include "tuner_e4k.h" +//#include "tuner_fc0012.h" +//#include "tuner_fc0013.h" +//#include "tuner_fc2580.h" #include "tuner_r82xx.h" typedef struct rtlsdr_tuner_iface { @@ -112,7 +112,7 @@ struct rtlsdr_dev { uint32_t offs_freq; /* Hz */ int corr; /* ppm */ int gain; /* tenth dB */ - struct e4k_state e4k_s; + //struct e4k_state e4k_s; struct r82xx_config r82xx_c; struct r82xx_priv r82xx_p; /* status */ @@ -125,7 +125,7 @@ void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val); static int rtlsdr_set_if_freq(rtlsdr_dev_t *dev, uint32_t freq); /* generic tuner interface functions, shall be moved to the tuner implementations */ -int e4000_init(void *dev) { +/*int e4000_init(void *dev) { rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev; devt->e4k_s.i2c_addr = E4K_I2C_ADDR; rtlsdr_get_xtal_freq(devt, NULL, &devt->e4k_s.vco.fosc); @@ -150,25 +150,26 @@ int e4000_set_bw(void *dev, int bw) { r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_CHAN, bw); return r; -} +}*/ -int e4000_set_gain(void *dev, int gain) { - rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev; - int mixgain = (gain > 340) ? 12 : 4; +//int e4000_set_gain(void *dev, int gain) { +// rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev; +// int mixgain = (gain > 340) ? 12 : 4; #if 0 int enhgain = (gain - 420); #endif - if(e4k_set_lna_gain(&devt->e4k_s, min(300, gain - mixgain * 10)) == -EINVAL) - return -1; - if(e4k_mixer_gain_set(&devt->e4k_s, mixgain) == -EINVAL) - return -1; +// if(e4k_set_lna_gain(&devt->e4k_s, min(300, gain - mixgain * 10)) == -EINVAL) +// return -1; +// if(e4k_mixer_gain_set(&devt->e4k_s, mixgain) == -EINVAL) +// return -1; #if 0 /* enhanced mixer gain seems to have no effect */ if(enhgain >= 0) if(e4k_set_enh_gain(&devt->e4k_s, enhgain) == -EINVAL) return -1; #endif - return 0; -} +// return 0; +//} +/* int e4000_set_if_gain(void *dev, int stage, int gain) { rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev; return e4k_if_gain_set(&devt->e4k_s, (uint8_t)stage, (int8_t)(gain / 10)); @@ -176,36 +177,36 @@ int e4000_set_if_gain(void *dev, int stage, int gain) { int e4000_set_gain_mode(void *dev, int manual) { rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev; return e4k_enable_manual_gain(&devt->e4k_s, manual); -} +}*/ -int _fc0012_init(void *dev) { return fc0012_init(dev); } -int fc0012_exit(void *dev) { return 0; } -int fc0012_set_freq(void *dev, uint32_t freq) { +//int _fc0012_init(void *dev) { return fc0012_init(dev); } +//int fc0012_exit(void *dev) { return 0; } +//int fc0012_set_freq(void *dev, uint32_t freq) { /* select V-band/U-band filter */ - rtlsdr_set_gpio_bit(dev, 6, (freq > 300000000) ? 1 : 0); - return fc0012_set_params(dev, freq, 6000000); -} -int fc0012_set_bw(void *dev, int bw) { return 0; } -int _fc0012_set_gain(void *dev, int gain) { return fc0012_set_gain(dev, gain); } -int fc0012_set_gain_mode(void *dev, int manual) { return 0; } - -int _fc0013_init(void *dev) { return fc0013_init(dev); } -int fc0013_exit(void *dev) { return 0; } -int fc0013_set_freq(void *dev, uint32_t freq) { - return fc0013_set_params(dev, freq, 6000000); -} -int fc0013_set_bw(void *dev, int bw) { return 0; } -int _fc0013_set_gain(void *dev, int gain) { return fc0013_set_lna_gain(dev, gain); } - -int fc2580_init(void *dev) { return fc2580_Initialize(dev); } -int fc2580_exit(void *dev) { return 0; } -int _fc2580_set_freq(void *dev, uint32_t freq) { +// rtlsdr_set_gpio_bit(dev, 6, (freq > 300000000) ? 1 : 0); +// return fc0012_set_params(dev, freq, 6000000); +//} +//int fc0012_set_bw(void *dev, int bw) { return 0; } +//int _fc0012_set_gain(void *dev, int gain) { return fc0012_set_gain(dev, gain); } +//int fc0012_set_gain_mode(void *dev, int manual) { return 0; } + +//int _fc0013_init(void *dev) { return fc0013_init(dev); } +//int fc0013_exit(void *dev) { return 0; } +//int fc0013_set_freq(void *dev, uint32_t freq) { +// return fc0013_set_params(dev, freq, 6000000); +//} +//int fc0013_set_bw(void *dev, int bw) { return 0; } +//int _fc0013_set_gain(void *dev, int gain) { return fc0013_set_lna_gain(dev, gain); } + +//int fc2580_init(void *dev) { return fc2580_Initialize(dev); } +//int fc2580_exit(void *dev) { return 0; } +/*int _fc2580_set_freq(void *dev, uint32_t freq) { return fc2580_SetRfFreqHz(dev, freq); } int fc2580_set_bw(void *dev, int bw) { return fc2580_SetBandwidthMode(dev, 1); } int fc2580_set_gain(void *dev, int gain) { return 0; } int fc2580_set_gain_mode(void *dev, int manual) { return 0; } - +*/ int r820t_init(void *dev) { rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev; devt->r82xx_p.rtl_dev = dev; @@ -263,7 +264,7 @@ static rtlsdr_tuner_iface_t tuners[] = { { 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 @@ -282,7 +283,7 @@ static rtlsdr_tuner_iface_t tuners[] = { fc2580_init, fc2580_exit, _fc2580_set_freq, fc2580_set_bw, fc2580_set_gain, NULL, fc2580_set_gain_mode - }, + },*/ { r820t_init, r820t_exit, r820t_set_freq, r820t_set_bw, r820t_set_gain, NULL, @@ -747,8 +748,10 @@ int rtlsdr_set_xtal_freq(rtlsdr_dev_t *dev, uint32_t rtl_freq, uint32_t tuner_fr dev->tun_xtal = tuner_freq; /* read corrected clock value into e4k and r82xx structure */ - if (rtlsdr_get_xtal_freq(dev, NULL, &dev->e4k_s.vco.fosc) || + /*if (rtlsdr_get_xtal_freq(dev, NULL, &dev->e4k_s.vco.fosc) || rtlsdr_get_xtal_freq(dev, NULL, &dev->r82xx_c.xtal)) + return -3;*/ + if (rtlsdr_get_xtal_freq(dev, NULL, &dev->r82xx_c.xtal)) return -3; /* update xtal-dependent settings */ @@ -925,9 +928,11 @@ int rtlsdr_set_freq_correction(rtlsdr_dev_t *dev, int ppm) r |= rtlsdr_set_sample_freq_correction(dev, ppm); /* read corrected clock value into e4k and r82xx structure */ - if (rtlsdr_get_xtal_freq(dev, NULL, &dev->e4k_s.vco.fosc) || + /*if (rtlsdr_get_xtal_freq(dev, NULL, &dev->e4k_s.vco.fosc) || rtlsdr_get_xtal_freq(dev, NULL, &dev->r82xx_c.xtal)) - return -3; + return -3;*/ + if (rtlsdr_get_xtal_freq(dev, NULL, &dev->r82xx_c.xtal)) + return -3; if (dev->freq) /* retune to apply new correction value */ r |= rtlsdr_set_center_freq(dev, dev->freq); @@ -954,13 +959,13 @@ enum rtlsdr_tuner rtlsdr_get_tuner_type(rtlsdr_dev_t *dev) int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains) { /* all gain values are expressed in tenths of a dB */ - const int e4k_gains[] = { -10, 15, 40, 65, 90, 115, 140, 165, 190, 215, + /*const int e4k_gains[] = { -10, 15, 40, 65, 90, 115, 140, 165, 190, 215, 240, 290, 340, 420 }; const int fc0012_gains[] = { -99, -40, 71, 179, 192 }; const int fc0013_gains[] = { -99, -73, -65, -63, -60, -58, -54, 58, 61, 63, 65, 67, 68, 70, 71, 179, 181, 182, - 184, 186, 188, 191, 197 }; - const int fc2580_gains[] = { 0 /* no gain values */ }; + 184, 186, 188, 191, 197 };*/ + //const int fc2580_gains[] = { 0 /* no gain values */ }; const int r82xx_gains[] = { 0, 9, 14, 27, 37, 77, 87, 125, 144, 157, 166, 197, 207, 229, 254, 280, 297, 328, 338, 364, 372, 386, 402, 421, 434, 439, @@ -974,7 +979,7 @@ int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains) return -1; switch (dev->tuner_type) { - case RTLSDR_TUNER_E4000: + /*case RTLSDR_TUNER_E4000: ptr = e4k_gains; len = sizeof(e4k_gains); break; case RTLSDR_TUNER_FC0012: @@ -985,7 +990,7 @@ int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains) break; case RTLSDR_TUNER_FC2580: ptr = fc2580_gains; len = sizeof(fc2580_gains); - break; + break;*/ case RTLSDR_TUNER_R820T: case RTLSDR_TUNER_R828D: ptr = r82xx_gains; len = sizeof(r82xx_gains); @@ -1531,19 +1536,22 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index) /* Probe tuners */ rtlsdr_set_i2c_repeater(dev, 1); + /* reg = rtlsdr_i2c_read_reg(dev, E4K_I2C_ADDR, E4K_CHECK_ADDR); if (reg == E4K_CHECK_VAL) { fprintf(stderr, "Found Elonics E4000 tuner\n"); dev->tuner_type = RTLSDR_TUNER_E4000; goto found; } + */ + /* reg = rtlsdr_i2c_read_reg(dev, FC0013_I2C_ADDR, FC0013_CHECK_ADDR); if (reg == FC0013_CHECK_VAL) { fprintf(stderr, "Found Fitipower FC0013 tuner\n"); dev->tuner_type = RTLSDR_TUNER_FC0013; goto found; - } + }*/ reg = rtlsdr_i2c_read_reg(dev, R820T_I2C_ADDR, R82XX_CHECK_ADDR); if (reg == R82XX_CHECK_VAL) { @@ -1566,20 +1574,23 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index) rtlsdr_set_gpio_bit(dev, 4, 1); rtlsdr_set_gpio_bit(dev, 4, 0); + /* reg = rtlsdr_i2c_read_reg(dev, FC2580_I2C_ADDR, FC2580_CHECK_ADDR); if ((reg & 0x7f) == FC2580_CHECK_VAL) { fprintf(stderr, "Found FCI 2580 tuner\n"); dev->tuner_type = RTLSDR_TUNER_FC2580; goto found; } + */ + /* reg = rtlsdr_i2c_read_reg(dev, FC0012_I2C_ADDR, FC0012_CHECK_ADDR); if (reg == FC0012_CHECK_VAL) { fprintf(stderr, "Found Fitipower FC0012 tuner\n"); rtlsdr_set_gpio_output(dev, 6); dev->tuner_type = RTLSDR_TUNER_FC0012; goto found; - } + }*/ found: /* use the rtl clock value by default */ |