2 * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver
3 * Copyright (C) 2012 by Steve Markgraf <steve@steve-m.de>
4 * Copyright (C) 2012 by Dimitri Stolnikov <horiz0n@gmx.net>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #define min(a, b) (((a) < (b)) ? (a) : (b))
33 * All libusb callback functions should be marked with the LIBUSB_CALL macro
34 * to ensure that they are compiled with the same calling convention as libusb.
36 * If the macro isn't available in older libusb versions, we simply define it.
42 /* two raised to the power of n */
43 #define TWO_POW(n) ((double)(1ULL<<(n)))
46 #include "tuner_e4k.h"
47 #include "tuner_fc0012.h"
48 #include "tuner_fc0013.h"
49 #include "tuner_fc2580.h"
50 #include "tuner_r820t.h"
52 typedef struct rtlsdr_tuner_iface {
56 int (*set_freq)(void *, uint32_t freq /* Hz */);
57 int (*set_bw)(void *, int bw /* Hz */);
58 int (*set_gain)(void *, int gain /* tenth dB */);
59 int (*set_if_gain)(void *, int stage, int gain /* tenth dB */);
60 int (*set_gain_mode)(void *, int manual);
61 } rtlsdr_tuner_iface_t;
63 enum rtlsdr_async_status {
71 struct libusb_device_handle *devh;
72 uint32_t xfer_buf_num;
73 uint32_t xfer_buf_len;
74 struct libusb_transfer **xfer;
75 unsigned char **xfer_buf;
76 rtlsdr_read_async_cb_t cb;
78 enum rtlsdr_async_status async_status;
79 /* rtl demod context */
80 uint32_t rate; /* Hz */
81 uint32_t rtl_xtal; /* Hz */
84 enum rtlsdr_tuner tuner_type;
85 rtlsdr_tuner_iface_t *tuner;
86 uint32_t tun_xtal; /* Hz */
87 uint32_t freq; /* Hz */
88 uint32_t offs_freq; /* Hz */
90 int gain; /* tenth dB */
91 struct e4k_state e4k_s;
94 void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val);
96 /* generic tuner interface functions, shall be moved to the tuner implementations */
97 int e4000_init(void *dev) {
98 rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
99 devt->e4k_s.i2c_addr = E4K_I2C_ADDR;
100 rtlsdr_get_xtal_freq(devt, NULL, &devt->e4k_s.vco.fosc);
101 devt->e4k_s.rtl_dev = dev;
102 return e4k_init(&devt->e4k_s);
104 int e4000_exit(void *dev) { return 0; }
105 int e4000_set_freq(void *dev, uint32_t freq) {
106 rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
107 return e4k_tune_freq(&devt->e4k_s, freq);
110 int e4000_set_bw(void *dev, int bw) {
112 rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
114 r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_MIX, bw);
115 r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_RC, bw);
116 r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_CHAN, bw);
121 int e4000_set_gain(void *dev, int gain) {
122 rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
123 int mixgain = (gain > 340) ? 12 : 4;
125 int enhgain = (gain - 420);
127 if(e4k_set_lna_gain(&devt->e4k_s, min(300, gain - mixgain * 10)) == -EINVAL)
129 if(e4k_mixer_gain_set(&devt->e4k_s, mixgain) == -EINVAL)
131 #if 0 /* enhanced mixer gain seems to have no effect */
133 if(e4k_set_enh_gain(&devt->e4k_s, enhgain) == -EINVAL)
138 int e4000_set_if_gain(void *dev, int stage, int gain) {
139 rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
140 return e4k_if_gain_set(&devt->e4k_s, (uint8_t)stage, (int8_t)(gain / 10));
142 int e4000_set_gain_mode(void *dev, int manual) {
143 rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
144 return e4k_enable_manual_gain(&devt->e4k_s, manual);
147 int _fc0012_init(void *dev) { return fc0012_init(dev); }
148 int fc0012_exit(void *dev) { return 0; }
149 int fc0012_set_freq(void *dev, uint32_t freq) {
150 /* select V-band/U-band filter */
151 rtlsdr_set_gpio_bit(dev, 6, (freq > 300000000) ? 1 : 0);
152 return fc0012_set_params(dev, freq, 6000000);
154 int fc0012_set_bw(void *dev, int bw) { return 0; }
155 int _fc0012_set_gain(void *dev, int gain) { return fc0012_set_gain(dev, gain); }
156 int fc0012_set_gain_mode(void *dev, int manual) { return 0; }
158 int _fc0013_init(void *dev) { return fc0013_init(dev); }
159 int fc0013_exit(void *dev) { return 0; }
160 int fc0013_set_freq(void *dev, uint32_t freq) {
161 return fc0013_set_params(dev, freq, 6000000);
163 int fc0013_set_bw(void *dev, int bw) { return 0; }
164 int _fc0013_set_gain(void *dev, int gain) { return fc0013_set_lna_gain(dev, gain); }
166 int fc2580_init(void *dev) { return fc2580_Initialize(dev); }
167 int fc2580_exit(void *dev) { return 0; }
168 int _fc2580_set_freq(void *dev, uint32_t freq) {
169 return fc2580_SetRfFreqHz(dev, freq);
171 int fc2580_set_bw(void *dev, int bw) { return fc2580_SetBandwidthMode(dev, 1); }
172 int fc2580_set_gain(void *dev, int gain) { return 0; }
173 int fc2580_set_gain_mode(void *dev, int manual) { return 0; }
175 int r820t_init(void *dev) {
176 int r = R828_Init(dev);
177 r820t_SetStandardMode(dev, DVB_T_6M);
180 int r820t_exit(void *dev) { return 0; }
181 int r820t_set_freq(void *dev, uint32_t freq) { return r820t_SetRfFreqHz(dev, freq); }
182 int r820t_set_bw(void *dev, int bw) { return 0; }
183 int r820t_set_gain(void *dev, int gain) { return R828_SetRfGain(dev, gain); }
184 int r820t_set_gain_mode(void *dev, int manual) { return R828_RfGainMode(dev, manual); }
186 /* definition order must match enum rtlsdr_tuner */
187 static rtlsdr_tuner_iface_t tuners[] = {
189 NULL, NULL, NULL, NULL, NULL, NULL, NULL /* dummy for unknown tuners */
192 e4000_init, e4000_exit,
193 e4000_set_freq, e4000_set_bw, e4000_set_gain, e4000_set_if_gain,
197 _fc0012_init, fc0012_exit,
198 fc0012_set_freq, fc0012_set_bw, _fc0012_set_gain, NULL,
202 _fc0013_init, fc0013_exit,
203 fc0013_set_freq, fc0013_set_bw, _fc0013_set_gain, NULL,
207 fc2580_init, fc2580_exit,
208 _fc2580_set_freq, fc2580_set_bw, fc2580_set_gain, NULL,
212 r820t_init, r820t_exit,
213 r820t_set_freq, r820t_set_bw, r820t_set_gain, NULL,
218 typedef struct rtlsdr_dongle {
225 * Please add your device here and send a patch to osmocom-sdr@lists.osmocom.org
227 static rtlsdr_dongle_t known_devices[] = {
228 { 0x0bda, 0x2832, "Generic RTL2832U (e.g. hama nano)" },
229 { 0x0bda, 0x2838, "ezcap USB 2.0 DVB-T/DAB/FM dongle" },
230 { 0x0ccd, 0x00a9, "Terratec Cinergy T Stick Black (rev 1)" },
231 { 0x0ccd, 0x00b3, "Terratec NOXON DAB/DAB+ USB dongle (rev 1)" },
232 { 0x0ccd, 0x00b4, "Terratec NOXON DAB/DAB+ USB dongle (rev 1)" },
233 { 0x0ccd, 0x00b7, "Terratec NOXON DAB/DAB+ USB dongle (rev 1)" },
234 { 0x0ccd, 0x00c6, "Terratec NOXON DAB/DAB+ USB dongle (rev 1)" },
235 { 0x0ccd, 0x00d3, "Terratec Cinergy T Stick RC (Rev.3)" },
236 { 0x0ccd, 0x00d7, "Terratec T Stick PLUS" },
237 { 0x0ccd, 0x00e0, "Terratec NOXON DAB/DAB+ USB dongle (rev 2)" },
238 { 0x1554, 0x5020, "PixelView PV-DT235U(RN)" },
239 { 0x185b, 0x0620, "Compro Videomate U620F"},
240 { 0x185b, 0x0650, "Compro Videomate U650F"},
241 { 0x185b, 0x0680, "Compro Videomate U680F"},
242 { 0x1f4d, 0xa803, "Sweex DVB-T USB" },
243 { 0x1f4d, 0xb803, "GTek T803" },
244 { 0x1f4d, 0xc803, "Lifeview LV5TDeluxe" },
245 { 0x1f4d, 0xd286, "MyGica TD312" },
246 { 0x1f4d, 0xd803, "PROlectrix DV107669" },
247 { 0x1b80, 0xd398, "Zaapa ZT-MINDVBZP" },
248 { 0x1b80, 0xd3a4, "Twintech UT-40" },
249 { 0x1d19, 0x1101, "Dexatek DK DVB-T Dongle (Logilink VG0002A)" },
250 { 0x1d19, 0x1102, "Dexatek DK DVB-T Dongle (MSI DigiVox mini II V3.0)" },
251 { 0x1d19, 0x1103, "Dexatek Technology Ltd. DK 5217 DVB-T Dongle" },
252 { 0x1d19, 0x1104, "MSI DigiVox Micro HD" },
253 { 0x0458, 0x707f, "Genius TVGo DVB-T03 USB dongle (Ver. B)" },
254 { 0x1b80, 0xd393, "GIGABYTE GT-U7300" },
255 { 0x1b80, 0xd394, "DIKOM USB-DVBT HD" },
256 { 0x1b80, 0xd395, "Peak 102569AGPK" },
257 { 0x1b80, 0xd39d, "SVEON STV20 DVB-T USB & FM" },
260 #define DEFAULT_BUF_NUMBER 32
261 #define DEFAULT_BUF_LENGTH (16 * 32 * 512)
263 #define DEF_RTL_XTAL_FREQ 28800000
264 #define MIN_RTL_XTAL_FREQ (DEF_RTL_XTAL_FREQ - 1000)
265 #define MAX_RTL_XTAL_FREQ (DEF_RTL_XTAL_FREQ + 1000)
267 #define MAX_SAMP_RATE 3200000
269 #define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN)
270 #define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT)
271 #define CTRL_TIMEOUT 300
272 #define BULK_TIMEOUT 0
274 #define EEPROM_ADDR 0xa0
280 USB_EPA_CFG = 0x2144,
281 USB_EPA_CTL = 0x2148,
282 USB_EPA_MAXPKT = 0x2158,
283 USB_EPA_MAXPKT_2 = 0x215a,
284 USB_EPA_FIFO_CFG = 0x2160,
299 DEMOD_CTL_1 = 0x300b,
313 int rtlsdr_read_array(rtlsdr_dev_t *dev, uint8_t block, uint16_t addr, uint8_t *array, uint8_t len)
316 uint16_t index = (block << 8);
318 r = libusb_control_transfer(dev->devh, CTRL_IN, 0, addr, index, array, len, CTRL_TIMEOUT);
321 fprintf(stderr, "%s failed with %d\n", __FUNCTION__, r);
326 int rtlsdr_write_array(rtlsdr_dev_t *dev, uint8_t block, uint16_t addr, uint8_t *array, uint8_t len)
329 uint16_t index = (block << 8) | 0x10;
331 r = libusb_control_transfer(dev->devh, CTRL_OUT, 0, addr, index, array, len, CTRL_TIMEOUT);
334 fprintf(stderr, "%s failed with %d\n", __FUNCTION__, r);
339 int rtlsdr_i2c_write_reg(rtlsdr_dev_t *dev, uint8_t i2c_addr, uint8_t reg, uint8_t val)
341 uint16_t addr = i2c_addr;
346 return rtlsdr_write_array(dev, IICB, addr, (uint8_t *)&data, 2);
349 uint8_t rtlsdr_i2c_read_reg(rtlsdr_dev_t *dev, uint8_t i2c_addr, uint8_t reg)
351 uint16_t addr = i2c_addr;
354 rtlsdr_write_array(dev, IICB, addr, ®, 1);
355 rtlsdr_read_array(dev, IICB, addr, &data, 1);
360 /* TODO clean this up again */
361 int e4k_reg_write(struct e4k_state *e4k, uint8_t reg, uint8_t val)
363 return rtlsdr_i2c_write_reg((rtlsdr_dev_t*)e4k->rtl_dev, e4k->i2c_addr, reg, val);}
365 uint8_t e4k_reg_read(struct e4k_state *e4k, uint8_t reg)
367 return rtlsdr_i2c_read_reg((rtlsdr_dev_t*)e4k->rtl_dev, e4k->i2c_addr, reg);
370 int rtlsdr_i2c_write(rtlsdr_dev_t *dev, uint8_t i2c_addr, uint8_t *buffer, int len)
372 uint16_t addr = i2c_addr;
377 return rtlsdr_write_array(dev, IICB, addr, buffer, len);
380 int rtlsdr_i2c_read(rtlsdr_dev_t *dev, uint8_t i2c_addr, uint8_t *buffer, int len)
382 uint16_t addr = i2c_addr;
387 return rtlsdr_read_array(dev, IICB, addr, buffer, len);
390 uint16_t rtlsdr_read_reg(rtlsdr_dev_t *dev, uint8_t block, uint16_t addr, uint8_t len)
393 unsigned char data[2];
394 uint16_t index = (block << 8);
397 r = libusb_control_transfer(dev->devh, CTRL_IN, 0, addr, index, data, len, CTRL_TIMEOUT);
400 fprintf(stderr, "%s failed with %d\n", __FUNCTION__, r);
402 reg = (data[1] << 8) | data[0];
407 int rtlsdr_write_reg(rtlsdr_dev_t *dev, uint8_t block, uint16_t addr, uint16_t val, uint8_t len)
410 unsigned char data[2];
412 uint16_t index = (block << 8) | 0x10;
415 data[0] = val & 0xff;
419 data[1] = val & 0xff;
421 r = libusb_control_transfer(dev->devh, CTRL_OUT, 0, addr, index, data, len, CTRL_TIMEOUT);
424 fprintf(stderr, "%s failed with %d\n", __FUNCTION__, r);
429 uint16_t rtlsdr_demod_read_reg(rtlsdr_dev_t *dev, uint8_t page, uint16_t addr, uint8_t len)
432 unsigned char data[2];
434 uint16_t index = page;
436 addr = (addr << 8) | 0x20;
438 r = libusb_control_transfer(dev->devh, CTRL_IN, 0, addr, index, data, len, CTRL_TIMEOUT);
441 fprintf(stderr, "%s failed with %d\n", __FUNCTION__, r);
443 reg = (data[1] << 8) | data[0];
448 int rtlsdr_demod_write_reg(rtlsdr_dev_t *dev, uint8_t page, uint16_t addr, uint16_t val, uint8_t len)
451 unsigned char data[2];
452 uint16_t index = 0x10 | page;
453 addr = (addr << 8) | 0x20;
456 data[0] = val & 0xff;
460 data[1] = val & 0xff;
462 r = libusb_control_transfer(dev->devh, CTRL_OUT, 0, addr, index, data, len, CTRL_TIMEOUT);
465 fprintf(stderr, "%s failed with %d\n", __FUNCTION__, r);
467 rtlsdr_demod_read_reg(dev, 0x0a, 0x01, 1);
469 return (r == len) ? 0 : -1;
472 void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val)
477 r = rtlsdr_read_reg(dev, SYSB, GPO, 1);
478 r = val ? (r | gpio) : (r & ~gpio);
479 rtlsdr_write_reg(dev, SYSB, GPO, r, 1);
482 void rtlsdr_set_gpio_output(rtlsdr_dev_t *dev, uint8_t gpio)
487 r = rtlsdr_read_reg(dev, SYSB, GPD, 1);
488 rtlsdr_write_reg(dev, SYSB, GPO, r & ~gpio, 1);
489 r = rtlsdr_read_reg(dev, SYSB, GPOE, 1);
490 rtlsdr_write_reg(dev, SYSB, GPOE, r | gpio, 1);
493 void rtlsdr_set_i2c_repeater(rtlsdr_dev_t *dev, int on)
495 rtlsdr_demod_write_reg(dev, 1, 0x01, on ? 0x18 : 0x10, 1);
498 void rtlsdr_init_baseband(rtlsdr_dev_t *dev)
502 /* default FIR coefficients used for DAB/FM by the Windows driver,
503 * the DVB driver uses different ones */
504 uint8_t fir_coeff[] = {
505 0xca, 0xdc, 0xd7, 0xd8, 0xe0, 0xf2, 0x0e, 0x35, 0x06, 0x50,
506 0x9c, 0x0d, 0x71, 0x11, 0x14, 0x71, 0x74, 0x19, 0x41, 0xa5,
510 rtlsdr_write_reg(dev, USBB, USB_SYSCTL, 0x09, 1);
511 rtlsdr_write_reg(dev, USBB, USB_EPA_MAXPKT, 0x0002, 2);
512 rtlsdr_write_reg(dev, USBB, USB_EPA_CTL, 0x1002, 2);
515 rtlsdr_write_reg(dev, SYSB, DEMOD_CTL_1, 0x22, 1);
516 rtlsdr_write_reg(dev, SYSB, DEMOD_CTL, 0xe8, 1);
518 /* reset demod (bit 3, soft_rst) */
519 rtlsdr_demod_write_reg(dev, 1, 0x01, 0x14, 1);
520 rtlsdr_demod_write_reg(dev, 1, 0x01, 0x10, 1);
522 /* disable spectrum inversion and adjacent channel rejection */
523 rtlsdr_demod_write_reg(dev, 1, 0x15, 0x00, 1);
524 rtlsdr_demod_write_reg(dev, 1, 0x16, 0x0000, 2);
526 /* clear both DDC shift and IF frequency registers */
527 for (i = 0; i < 6; i++)
528 rtlsdr_demod_write_reg(dev, 1, 0x16 + i, 0x00, 1);
530 /* set FIR coefficients */
531 for (i = 0; i < sizeof (fir_coeff); i++)
532 rtlsdr_demod_write_reg(dev, 1, 0x1c + i, fir_coeff[i], 1);
534 /* enable SDR mode, disable DAGC (bit 5) */
535 rtlsdr_demod_write_reg(dev, 0, 0x19, 0x05, 1);
537 /* init FSM state-holding register */
538 rtlsdr_demod_write_reg(dev, 1, 0x93, 0xf0, 1);
539 rtlsdr_demod_write_reg(dev, 1, 0x94, 0x0f, 1);
541 /* disable AGC (en_dagc, bit 0) (this seems to have no effect) */
542 rtlsdr_demod_write_reg(dev, 1, 0x11, 0x00, 1);
544 /* disable RF and IF AGC loop */
545 rtlsdr_demod_write_reg(dev, 1, 0x04, 0x00, 1);
547 /* disable PID filter (enable_PID = 0) */
548 rtlsdr_demod_write_reg(dev, 0, 0x61, 0x60, 1);
550 /* opt_adc_iq = 0, default ADC_I/ADC_Q datapath */
551 rtlsdr_demod_write_reg(dev, 0, 0x06, 0x80, 1);
553 /* Enable Zero-IF mode (en_bbin bit), DC cancellation (en_dc_est),
554 * IQ estimation/compensation (en_iq_comp, en_iq_est) */
555 rtlsdr_demod_write_reg(dev, 1, 0xb1, 0x1b, 1);
557 /* disable 4.096 MHz clock output on pin TP_CK0 */
558 rtlsdr_demod_write_reg(dev, 0, 0x0d, 0x83, 1);
561 int rtlsdr_deinit_baseband(rtlsdr_dev_t *dev)
568 if (dev->tuner && dev->tuner->exit) {
569 rtlsdr_set_i2c_repeater(dev, 1);
570 r = dev->tuner->exit(dev); /* deinitialize tuner */
571 rtlsdr_set_i2c_repeater(dev, 0);
574 /* poweroff demodulator and ADCs */
575 rtlsdr_write_reg(dev, SYSB, DEMOD_CTL, 0x20, 1);
580 int rtlsdr_set_if_freq(rtlsdr_dev_t *dev, uint32_t freq)
590 /* read corrected clock value */
591 if (rtlsdr_get_xtal_freq(dev, &rtl_xtal, NULL))
594 if_freq = ((freq * TWO_POW(22)) / rtl_xtal) * (-1);
596 tmp = (if_freq >> 16) & 0x3f;
597 r = rtlsdr_demod_write_reg(dev, 1, 0x19, tmp, 1);
598 tmp = (if_freq >> 8) & 0xff;
599 r |= rtlsdr_demod_write_reg(dev, 1, 0x1a, tmp, 1);
600 tmp = if_freq & 0xff;
601 r |= rtlsdr_demod_write_reg(dev, 1, 0x1b, tmp, 1);
606 int rtlsdr_set_sample_freq_correction(rtlsdr_dev_t *dev, int ppm)
610 int16_t offs = ppm * (-1) * TWO_POW(24) / 1000000;
613 r |= rtlsdr_demod_write_reg(dev, 1, 0x3f, tmp, 1);
614 tmp = (offs >> 8) & 0x3f;
615 r |= rtlsdr_demod_write_reg(dev, 1, 0x3e, tmp, 1);
620 int rtlsdr_set_xtal_freq(rtlsdr_dev_t *dev, uint32_t rtl_freq, uint32_t tuner_freq)
628 (rtl_freq < MIN_RTL_XTAL_FREQ || rtl_freq > MAX_RTL_XTAL_FREQ))
631 if (rtl_freq > 0 && dev->rtl_xtal != rtl_freq) {
632 dev->rtl_xtal = rtl_freq;
634 /* update xtal-dependent settings */
636 r = rtlsdr_set_sample_rate(dev, dev->rate);
639 if (dev->tun_xtal != tuner_freq) {
641 dev->tun_xtal = dev->rtl_xtal;
643 dev->tun_xtal = tuner_freq;
645 /* read corrected clock value into e4k structure */
646 if (rtlsdr_get_xtal_freq(dev, NULL, &dev->e4k_s.vco.fosc))
649 /* update xtal-dependent settings */
651 r = rtlsdr_set_center_freq(dev, dev->freq);
657 int rtlsdr_get_xtal_freq(rtlsdr_dev_t *dev, uint32_t *rtl_freq, uint32_t *tuner_freq)
662 #define APPLY_PPM_CORR(val,ppm) (((val) * (1.0 + (ppm) / 1e6)))
665 *rtl_freq = (uint32_t) APPLY_PPM_CORR(dev->rtl_xtal, dev->corr);
668 *tuner_freq = (uint32_t) APPLY_PPM_CORR(dev->tun_xtal, dev->corr);
673 int rtlsdr_get_usb_strings(rtlsdr_dev_t *dev, char *manufact, char *product,
676 struct libusb_device_descriptor dd;
677 libusb_device *device = NULL;
678 const int buf_max = 256;
681 if (!dev || !dev->devh)
684 device = libusb_get_device(dev->devh);
686 r = libusb_get_device_descriptor(device, &dd);
691 memset(manufact, 0, buf_max);
692 libusb_get_string_descriptor_ascii(dev->devh, dd.iManufacturer,
693 (unsigned char *)manufact,
698 memset(product, 0, buf_max);
699 libusb_get_string_descriptor_ascii(dev->devh, dd.iProduct,
700 (unsigned char *)product,
705 memset(serial, 0, buf_max);
706 libusb_get_string_descriptor_ascii(dev->devh, dd.iSerialNumber,
707 (unsigned char *)serial,
714 int rtlsdr_write_eeprom(rtlsdr_dev_t *dev, uint8_t *data, uint8_t offset, uint16_t len)
723 if ((len + offset) > 256)
726 for (i = 0; i < len; i++) {
728 r = rtlsdr_write_array(dev, IICB, EEPROM_ADDR, cmd, 1);
729 r = rtlsdr_read_array(dev, IICB, EEPROM_ADDR, &cmd[1], 1);
731 /* only write the byte if it differs */
732 if (cmd[1] == data[i])
736 r = rtlsdr_write_array(dev, IICB, EEPROM_ADDR, cmd, 2);
737 if (r != sizeof(cmd))
740 /* for some EEPROMs (e.g. ATC 240LC02) we need a delay
741 * between write operations, otherwise they will fail */
752 int rtlsdr_read_eeprom(rtlsdr_dev_t *dev, uint8_t *data, uint8_t offset, uint16_t len)
760 if ((len + offset) > 256)
763 r = rtlsdr_write_array(dev, IICB, EEPROM_ADDR, &offset, 1);
767 for (i = 0; i < len; i++) {
768 r = rtlsdr_read_array(dev, IICB, EEPROM_ADDR, data + i, 1);
777 int rtlsdr_set_center_freq(rtlsdr_dev_t *dev, uint32_t freq)
781 if (!dev || !dev->tuner)
784 if (dev->direct_sampling) {
785 r = rtlsdr_set_if_freq(dev, freq);
786 } else if (dev->tuner && dev->tuner->set_freq) {
787 rtlsdr_set_i2c_repeater(dev, 1);
788 r = dev->tuner->set_freq(dev, freq - dev->offs_freq);
789 rtlsdr_set_i2c_repeater(dev, 0);
800 uint32_t rtlsdr_get_center_freq(rtlsdr_dev_t *dev)
808 int rtlsdr_set_freq_correction(rtlsdr_dev_t *dev, int ppm)
815 if (dev->corr == ppm)
820 r |= rtlsdr_set_sample_freq_correction(dev, ppm);
822 /* read corrected clock value into e4k structure */
823 if (rtlsdr_get_xtal_freq(dev, NULL, &dev->e4k_s.vco.fosc))
826 if (dev->freq) /* retune to apply new correction value */
827 r |= rtlsdr_set_center_freq(dev, dev->freq);
832 int rtlsdr_get_freq_correction(rtlsdr_dev_t *dev)
840 enum rtlsdr_tuner rtlsdr_get_tuner_type(rtlsdr_dev_t *dev)
843 return RTLSDR_TUNER_UNKNOWN;
845 return dev->tuner_type;
848 int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains)
850 /* all gain values are expressed in tenths of a dB */
851 const int e4k_gains[] = { -10, 15, 40, 65, 90, 115, 140, 165, 190, 215,
852 240, 290, 340, 420 };
853 const int fc0012_gains[] = { -99, -40, 71, 179, 192 };
854 const int fc0013_gains[] = { -99, -73, -65, -63, -60, -58, -54, 58, 61,
855 63, 65, 67, 68, 70, 71, 179, 181, 182,
856 184, 186, 188, 191, 197 };
857 const int fc2580_gains[] = { 0 /* no gain values */ };
858 const int r820t_gains[] = { 0, 9, 14, 27, 37, 77, 87, 125, 144, 157,
859 166, 197, 207, 229, 254, 280, 297, 328,
860 338, 364, 372, 386, 402, 421, 434, 439,
862 const int unknown_gains[] = { 0 /* no gain values */ };
864 const int *ptr = NULL;
870 switch (dev->tuner_type) {
871 case RTLSDR_TUNER_E4000:
872 ptr = e4k_gains; len = sizeof(e4k_gains);
874 case RTLSDR_TUNER_FC0012:
875 ptr = fc0012_gains; len = sizeof(fc0012_gains);
877 case RTLSDR_TUNER_FC0013:
878 ptr = fc0013_gains; len = sizeof(fc0013_gains);
880 case RTLSDR_TUNER_FC2580:
881 ptr = fc2580_gains; len = sizeof(fc2580_gains);
883 case RTLSDR_TUNER_R820T:
884 ptr = r820t_gains; len = sizeof(r820t_gains);
887 ptr = unknown_gains; len = sizeof(unknown_gains);
891 if (!gains) { /* no buffer provided, just return the count */
892 return len / sizeof(int);
895 memcpy(gains, ptr, len);
897 return len / sizeof(int);
901 int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain)
905 if (!dev || !dev->tuner)
908 if (dev->tuner->set_gain) {
909 rtlsdr_set_i2c_repeater(dev, 1);
910 r = dev->tuner->set_gain((void *)dev, gain);
911 rtlsdr_set_i2c_repeater(dev, 0);
922 int rtlsdr_get_tuner_gain(rtlsdr_dev_t *dev)
930 int rtlsdr_set_tuner_if_gain(rtlsdr_dev_t *dev, int stage, int gain)
934 if (!dev || !dev->tuner)
937 if (dev->tuner->set_if_gain) {
938 rtlsdr_set_i2c_repeater(dev, 1);
939 r = dev->tuner->set_if_gain(dev, stage, gain);
940 rtlsdr_set_i2c_repeater(dev, 0);
946 int rtlsdr_set_tuner_gain_mode(rtlsdr_dev_t *dev, int mode)
950 if (!dev || !dev->tuner)
953 if (dev->tuner->set_gain_mode) {
954 rtlsdr_set_i2c_repeater(dev, 1);
955 r = dev->tuner->set_gain_mode((void *)dev, mode);
956 rtlsdr_set_i2c_repeater(dev, 0);
962 int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate)
966 uint32_t rsamp_ratio;
972 /* check for the maximum rate the resampler supports */
973 if (samp_rate > MAX_SAMP_RATE)
974 samp_rate = MAX_SAMP_RATE;
976 rsamp_ratio = (dev->rtl_xtal * TWO_POW(22)) / samp_rate;
979 real_rate = (dev->rtl_xtal * TWO_POW(22)) / rsamp_ratio;
981 if ( ((double)samp_rate) != real_rate )
982 fprintf(stderr, "Exact sample rate is: %f Hz\n", real_rate);
984 if (dev->tuner && dev->tuner->set_bw) {
985 rtlsdr_set_i2c_repeater(dev, 1);
986 dev->tuner->set_bw(dev, (int)real_rate);
987 rtlsdr_set_i2c_repeater(dev, 0);
990 dev->rate = (uint32_t)real_rate;
992 tmp = (rsamp_ratio >> 16);
993 r |= rtlsdr_demod_write_reg(dev, 1, 0x9f, tmp, 2);
994 tmp = rsamp_ratio & 0xffff;
995 r |= rtlsdr_demod_write_reg(dev, 1, 0xa1, tmp, 2);
997 r |= rtlsdr_set_sample_freq_correction(dev, dev->corr);
999 /* reset demod (bit 3, soft_rst) */
1000 r |= rtlsdr_demod_write_reg(dev, 1, 0x01, 0x14, 1);
1001 r |= rtlsdr_demod_write_reg(dev, 1, 0x01, 0x10, 1);
1003 /* recalculate offset frequency if offset tuning is enabled */
1005 rtlsdr_set_offset_tuning(dev, 1);
1010 uint32_t rtlsdr_get_sample_rate(rtlsdr_dev_t *dev)
1018 int rtlsdr_set_testmode(rtlsdr_dev_t *dev, int on)
1023 return rtlsdr_demod_write_reg(dev, 0, 0x19, on ? 0x03 : 0x05, 1);
1026 int rtlsdr_set_agc_mode(rtlsdr_dev_t *dev, int on)
1031 return rtlsdr_demod_write_reg(dev, 0, 0x19, on ? 0x25 : 0x05, 1);
1034 int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on)
1042 if (dev->tuner && dev->tuner->exit) {
1043 rtlsdr_set_i2c_repeater(dev, 1);
1044 r = dev->tuner->exit(dev);
1045 rtlsdr_set_i2c_repeater(dev, 0);
1048 /* disable Zero-IF mode */
1049 r |= rtlsdr_demod_write_reg(dev, 1, 0xb1, 0x1a, 1);
1051 /* disable spectrum inversion */
1052 r |= rtlsdr_demod_write_reg(dev, 1, 0x15, 0x00, 1);
1054 /* only enable In-phase ADC input */
1055 r |= rtlsdr_demod_write_reg(dev, 0, 0x08, 0x4d, 1);
1057 /* swap I and Q ADC, this allows to select between two inputs */
1058 r |= rtlsdr_demod_write_reg(dev, 0, 0x06, (on > 1) ? 0x90 : 0x80, 1);
1060 fprintf(stderr, "Enabled direct sampling mode, input %i\n", on);
1061 dev->direct_sampling = on;
1063 if (dev->tuner && dev->tuner->init) {
1064 rtlsdr_set_i2c_repeater(dev, 1);
1065 r |= dev->tuner->init(dev);
1066 rtlsdr_set_i2c_repeater(dev, 0);
1069 if (dev->tuner_type == RTLSDR_TUNER_R820T) {
1070 r |= rtlsdr_set_if_freq(dev, R820T_IF_FREQ);
1072 /* enable spectrum inversion */
1073 r |= rtlsdr_demod_write_reg(dev, 1, 0x15, 0x01, 1);
1075 r |= rtlsdr_set_if_freq(dev, 0);
1077 /* enable In-phase + Quadrature ADC input */
1078 r |= rtlsdr_demod_write_reg(dev, 0, 0x08, 0xcd, 1);
1080 /* Enable Zero-IF mode */
1081 r |= rtlsdr_demod_write_reg(dev, 1, 0xb1, 0x1b, 1);
1084 /* opt_adc_iq = 0, default ADC_I/ADC_Q datapath */
1085 r |= rtlsdr_demod_write_reg(dev, 0, 0x06, 0x80, 1);
1087 fprintf(stderr, "Disabled direct sampling mode\n");
1088 dev->direct_sampling = 0;
1091 r |= rtlsdr_set_center_freq(dev, dev->freq);
1096 int rtlsdr_get_direct_sampling(rtlsdr_dev_t *dev)
1101 return dev->direct_sampling;
1104 int rtlsdr_set_offset_tuning(rtlsdr_dev_t *dev, int on)
1111 if (dev->tuner_type == RTLSDR_TUNER_R820T)
1114 if (dev->direct_sampling)
1117 /* based on keenerds 1/f noise measurements */
1118 dev->offs_freq = on ? ((dev->rate / 2) * 170 / 100) : 0;
1119 r |= rtlsdr_set_if_freq(dev, dev->offs_freq);
1121 if (dev->tuner && dev->tuner->set_bw) {
1122 rtlsdr_set_i2c_repeater(dev, 1);
1123 dev->tuner->set_bw(dev, on ? (2 * dev->offs_freq) : dev->rate);
1124 rtlsdr_set_i2c_repeater(dev, 0);
1127 if (dev->freq > dev->offs_freq)
1128 r |= rtlsdr_set_center_freq(dev, dev->freq);
1133 int rtlsdr_get_offset_tuning(rtlsdr_dev_t *dev)
1138 return (dev->offs_freq) ? 1 : 0;
1141 static rtlsdr_dongle_t *find_known_device(uint16_t vid, uint16_t pid)
1144 rtlsdr_dongle_t *device = NULL;
1146 for (i = 0; i < sizeof(known_devices)/sizeof(rtlsdr_dongle_t); i++ ) {
1147 if (known_devices[i].vid == vid && known_devices[i].pid == pid) {
1148 device = &known_devices[i];
1156 uint32_t rtlsdr_get_device_count(void)
1159 libusb_context *ctx;
1160 libusb_device **list;
1161 uint32_t device_count = 0;
1162 struct libusb_device_descriptor dd;
1167 cnt = libusb_get_device_list(ctx, &list);
1169 for (i = 0; i < cnt; i++) {
1170 libusb_get_device_descriptor(list[i], &dd);
1172 if (find_known_device(dd.idVendor, dd.idProduct))
1176 libusb_free_device_list(list, 1);
1180 return device_count;
1183 const char *rtlsdr_get_device_name(uint32_t index)
1186 libusb_context *ctx;
1187 libusb_device **list;
1188 struct libusb_device_descriptor dd;
1189 rtlsdr_dongle_t *device = NULL;
1190 uint32_t device_count = 0;
1195 cnt = libusb_get_device_list(ctx, &list);
1197 for (i = 0; i < cnt; i++) {
1198 libusb_get_device_descriptor(list[i], &dd);
1200 device = find_known_device(dd.idVendor, dd.idProduct);
1205 if (index == device_count - 1)
1210 libusb_free_device_list(list, 1);
1215 return device->name;
1220 int rtlsdr_get_device_usb_strings(uint32_t index, char *manufact,
1221 char *product, char *serial)
1225 libusb_context *ctx;
1226 libusb_device **list;
1227 struct libusb_device_descriptor dd;
1228 rtlsdr_dongle_t *device = NULL;
1230 uint32_t device_count = 0;
1235 cnt = libusb_get_device_list(ctx, &list);
1237 for (i = 0; i < cnt; i++) {
1238 libusb_get_device_descriptor(list[i], &dd);
1240 device = find_known_device(dd.idVendor, dd.idProduct);
1245 if (index == device_count - 1) {
1246 r = libusb_open(list[i], &devt.devh);
1248 r = rtlsdr_get_usb_strings(&devt,
1252 libusb_close(devt.devh);
1259 libusb_free_device_list(list, 1);
1266 int rtlsdr_get_index_by_serial(const char *serial)
1274 cnt = rtlsdr_get_device_count();
1279 for (i = 0; i < cnt; i++) {
1280 r = rtlsdr_get_device_usb_strings(i, NULL, NULL, str);
1281 if (!r && !strcmp(serial, str))
1288 int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
1292 libusb_device **list;
1293 rtlsdr_dev_t *dev = NULL;
1294 libusb_device *device = NULL;
1295 uint32_t device_count = 0;
1296 struct libusb_device_descriptor dd;
1300 dev = malloc(sizeof(rtlsdr_dev_t));
1304 memset(dev, 0, sizeof(rtlsdr_dev_t));
1306 libusb_init(&dev->ctx);
1308 cnt = libusb_get_device_list(dev->ctx, &list);
1310 for (i = 0; i < cnt; i++) {
1313 libusb_get_device_descriptor(list[i], &dd);
1315 if (find_known_device(dd.idVendor, dd.idProduct)) {
1319 if (index == device_count - 1)
1330 r = libusb_open(device, &dev->devh);
1332 libusb_free_device_list(list, 1);
1333 fprintf(stderr, "usb_open error %d\n", r);
1337 libusb_free_device_list(list, 1);
1339 r = libusb_claim_interface(dev->devh, 0);
1341 fprintf(stderr, "usb_claim_interface error %d\n", r);
1345 dev->rtl_xtal = DEF_RTL_XTAL_FREQ;
1347 /* perform a dummy write, if it fails, reset the device */
1348 if (rtlsdr_write_reg(dev, USBB, USB_SYSCTL, 0x09, 1) < 0) {
1349 fprintf(stderr, "Resetting device...\n");
1350 libusb_reset_device(dev->devh);
1353 rtlsdr_init_baseband(dev);
1356 rtlsdr_set_i2c_repeater(dev, 1);
1358 reg = rtlsdr_i2c_read_reg(dev, E4K_I2C_ADDR, E4K_CHECK_ADDR);
1359 if (reg == E4K_CHECK_VAL) {
1360 fprintf(stderr, "Found Elonics E4000 tuner\n");
1361 dev->tuner_type = RTLSDR_TUNER_E4000;
1365 reg = rtlsdr_i2c_read_reg(dev, FC0013_I2C_ADDR, FC0013_CHECK_ADDR);
1366 if (reg == FC0013_CHECK_VAL) {
1367 fprintf(stderr, "Found Fitipower FC0013 tuner\n");
1368 dev->tuner_type = RTLSDR_TUNER_FC0013;
1372 reg = rtlsdr_i2c_read_reg(dev, R820T_I2C_ADDR, R820T_CHECK_ADDR);
1373 if (reg == R820T_CHECK_VAL) {
1374 fprintf(stderr, "Found Rafael Micro R820T tuner\n");
1375 dev->tuner_type = RTLSDR_TUNER_R820T;
1377 /* disable Zero-IF mode */
1378 rtlsdr_demod_write_reg(dev, 1, 0xb1, 0x1a, 1);
1380 /* only enable In-phase ADC input */
1381 rtlsdr_demod_write_reg(dev, 0, 0x08, 0x4d, 1);
1383 /* the R820T uses 3.57 MHz IF for the DVB-T 6 MHz mode, and
1384 * 4.57 MHz for the 8 MHz mode */
1385 rtlsdr_set_if_freq(dev, R820T_IF_FREQ);
1387 /* enable spectrum inversion */
1388 rtlsdr_demod_write_reg(dev, 1, 0x15, 0x01, 1);
1393 /* initialise GPIOs */
1394 rtlsdr_set_gpio_output(dev, 5);
1396 /* reset tuner before probing */
1397 rtlsdr_set_gpio_bit(dev, 5, 1);
1398 rtlsdr_set_gpio_bit(dev, 5, 0);
1400 reg = rtlsdr_i2c_read_reg(dev, FC2580_I2C_ADDR, FC2580_CHECK_ADDR);
1401 if ((reg & 0x7f) == FC2580_CHECK_VAL) {
1402 fprintf(stderr, "Found FCI 2580 tuner\n");
1403 dev->tuner_type = RTLSDR_TUNER_FC2580;
1407 reg = rtlsdr_i2c_read_reg(dev, FC0012_I2C_ADDR, FC0012_CHECK_ADDR);
1408 if (reg == FC0012_CHECK_VAL) {
1409 fprintf(stderr, "Found Fitipower FC0012 tuner\n");
1410 rtlsdr_set_gpio_output(dev, 6);
1411 dev->tuner_type = RTLSDR_TUNER_FC0012;
1416 if (dev->tuner_type == RTLSDR_TUNER_UNKNOWN) {
1417 fprintf(stderr, "No supported tuner found\n");
1418 rtlsdr_set_direct_sampling(dev, 1);
1421 dev->tuner = &tuners[dev->tuner_type];
1422 dev->tun_xtal = dev->rtl_xtal; /* use the rtl clock value by default */
1424 if (dev->tuner->init)
1425 r = dev->tuner->init(dev);
1427 rtlsdr_set_i2c_repeater(dev, 0);
1435 libusb_exit(dev->ctx);
1443 int rtlsdr_close(rtlsdr_dev_t *dev)
1448 /* block until all async operations have been completed (if any) */
1449 while (RTLSDR_INACTIVE != dev->async_status) {
1457 rtlsdr_deinit_baseband(dev);
1459 libusb_release_interface(dev->devh, 0);
1460 libusb_close(dev->devh);
1462 libusb_exit(dev->ctx);
1469 int rtlsdr_reset_buffer(rtlsdr_dev_t *dev)
1474 rtlsdr_write_reg(dev, USBB, USB_EPA_CTL, 0x1002, 2);
1475 rtlsdr_write_reg(dev, USBB, USB_EPA_CTL, 0x0000, 2);
1480 int rtlsdr_read_sync(rtlsdr_dev_t *dev, void *buf, int len, int *n_read)
1485 return libusb_bulk_transfer(dev->devh, 0x81, buf, len, n_read, BULK_TIMEOUT);
1488 static void LIBUSB_CALL _libusb_callback(struct libusb_transfer *xfer)
1490 rtlsdr_dev_t *dev = (rtlsdr_dev_t *)xfer->user_data;
1492 if (LIBUSB_TRANSFER_COMPLETED == xfer->status) {
1494 dev->cb(xfer->buffer, xfer->actual_length, dev->cb_ctx);
1496 libusb_submit_transfer(xfer); /* resubmit transfer */
1497 } else if (LIBUSB_TRANSFER_CANCELLED == xfer->status) {
1500 /*fprintf(stderr, "transfer status: %d\n", xfer->status);*/
1504 int rtlsdr_wait_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx)
1506 return rtlsdr_read_async(dev, cb, ctx, 0, 0);
1509 static int _rtlsdr_alloc_async_buffers(rtlsdr_dev_t *dev)
1517 dev->xfer = malloc(dev->xfer_buf_num *
1518 sizeof(struct libusb_transfer *));
1520 for(i = 0; i < dev->xfer_buf_num; ++i)
1521 dev->xfer[i] = libusb_alloc_transfer(0);
1524 if (!dev->xfer_buf) {
1525 dev->xfer_buf = malloc(dev->xfer_buf_num *
1526 sizeof(unsigned char *));
1528 for(i = 0; i < dev->xfer_buf_num; ++i)
1529 dev->xfer_buf[i] = malloc(dev->xfer_buf_len);
1535 static int _rtlsdr_free_async_buffers(rtlsdr_dev_t *dev)
1543 for(i = 0; i < dev->xfer_buf_num; ++i) {
1545 libusb_free_transfer(dev->xfer[i]);
1553 if (dev->xfer_buf) {
1554 for(i = 0; i < dev->xfer_buf_num; ++i) {
1555 if (dev->xfer_buf[i])
1556 free(dev->xfer_buf[i]);
1559 free(dev->xfer_buf);
1560 dev->xfer_buf = NULL;
1566 int rtlsdr_read_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx,
1567 uint32_t buf_num, uint32_t buf_len)
1571 struct timeval tv = { 1, 0 };
1572 enum rtlsdr_async_status next_status = RTLSDR_INACTIVE;
1577 if (RTLSDR_INACTIVE != dev->async_status)
1580 dev->async_status = RTLSDR_RUNNING;
1586 dev->xfer_buf_num = buf_num;
1588 dev->xfer_buf_num = DEFAULT_BUF_NUMBER;
1590 if (buf_len > 0 && buf_len % 512 == 0) /* len must be multiple of 512 */
1591 dev->xfer_buf_len = buf_len;
1593 dev->xfer_buf_len = DEFAULT_BUF_LENGTH;
1595 _rtlsdr_alloc_async_buffers(dev);
1597 for(i = 0; i < dev->xfer_buf_num; ++i) {
1598 libusb_fill_bulk_transfer(dev->xfer[i],
1607 libusb_submit_transfer(dev->xfer[i]);
1610 while (RTLSDR_INACTIVE != dev->async_status) {
1611 r = libusb_handle_events_timeout(dev->ctx, &tv);
1613 /*fprintf(stderr, "handle_events returned: %d\n", r);*/
1614 if (r == LIBUSB_ERROR_INTERRUPTED) /* stray signal */
1619 if (RTLSDR_CANCELING == dev->async_status) {
1620 next_status = RTLSDR_INACTIVE;
1625 for(i = 0; i < dev->xfer_buf_num; ++i) {
1629 if (LIBUSB_TRANSFER_CANCELLED !=
1630 dev->xfer[i]->status) {
1631 libusb_cancel_transfer(dev->xfer[i]);
1632 next_status = RTLSDR_CANCELING;
1636 if (RTLSDR_INACTIVE == next_status)
1641 _rtlsdr_free_async_buffers(dev);
1643 dev->async_status = next_status;
1648 int rtlsdr_cancel_async(rtlsdr_dev_t *dev)
1653 /* if streaming, try to cancel gracefully */
1654 if (RTLSDR_RUNNING == dev->async_status) {
1655 dev->async_status = RTLSDR_CANCELING;
1659 /* if called while in pending state, change the state forcefully */
1660 if (RTLSDR_INACTIVE != dev->async_status) {
1661 dev->async_status = RTLSDR_INACTIVE;
1668 uint32_t rtlsdr_get_tuner_clock(void *dev)
1670 uint32_t tuner_freq;
1675 /* read corrected clock value */
1676 if (rtlsdr_get_xtal_freq((rtlsdr_dev_t *)dev, NULL, &tuner_freq))
1682 int rtlsdr_i2c_write_fn(void *dev, uint8_t addr, uint8_t *buf, int len)
1685 return rtlsdr_i2c_write(((rtlsdr_dev_t *)dev), addr, buf, len);
1690 int rtlsdr_i2c_read_fn(void *dev, uint8_t addr, uint8_t *buf, int len)
1693 return rtlsdr_i2c_read(((rtlsdr_dev_t *)dev), addr, buf, len);