librtlsdr  UNKNOWN
RTL-SDR library
rtl-sdr.h
1 /*
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>
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 
20 #ifndef __RTL_SDR_H
21 #define __RTL_SDR_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include <stdint.h>
28 #include <rtl-sdr_export.h>
29 
30 typedef struct rtlsdr_dev rtlsdr_dev_t;
31 
32 RTLSDR_API uint32_t rtlsdr_get_device_count(void);
33 
34 RTLSDR_API const char* rtlsdr_get_device_name(uint32_t index);
35 
47 RTLSDR_API int rtlsdr_get_device_usb_strings(uint32_t index,
48  char *manufact,
49  char *product,
50  char *serial);
51 
61 RTLSDR_API int rtlsdr_get_index_by_serial(const char *serial);
62 
63 RTLSDR_API int rtlsdr_open(rtlsdr_dev_t **dev, uint32_t index);
64 
65 RTLSDR_API int rtlsdr_close(rtlsdr_dev_t *dev);
66 
67 /* configuration functions */
68 
83 RTLSDR_API int rtlsdr_set_xtal_freq(rtlsdr_dev_t *dev, uint32_t rtl_freq,
84  uint32_t tuner_freq);
85 
96 RTLSDR_API int rtlsdr_get_xtal_freq(rtlsdr_dev_t *dev, uint32_t *rtl_freq,
97  uint32_t *tuner_freq);
98 
110 RTLSDR_API int rtlsdr_get_usb_strings(rtlsdr_dev_t *dev, char *manufact,
111  char *product, char *serial);
112 
126 RTLSDR_API int rtlsdr_write_eeprom(rtlsdr_dev_t *dev, uint8_t *data,
127  uint8_t offset, uint16_t len);
128 
142 RTLSDR_API int rtlsdr_read_eeprom(rtlsdr_dev_t *dev, uint8_t *data,
143  uint8_t offset, uint16_t len);
144 
145 RTLSDR_API int rtlsdr_set_center_freq(rtlsdr_dev_t *dev, uint32_t freq);
146 
153 RTLSDR_API uint32_t rtlsdr_get_center_freq(rtlsdr_dev_t *dev);
154 
162 RTLSDR_API int rtlsdr_set_freq_correction(rtlsdr_dev_t *dev, int ppm);
163 
170 RTLSDR_API int rtlsdr_get_freq_correction(rtlsdr_dev_t *dev);
171 
172 enum rtlsdr_tuner {
173  RTLSDR_TUNER_UNKNOWN = 0,
174  RTLSDR_TUNER_E4000,
175  RTLSDR_TUNER_FC0012,
176  RTLSDR_TUNER_FC0013,
177  RTLSDR_TUNER_FC2580,
178  RTLSDR_TUNER_R820T
179 };
180 
187 RTLSDR_API enum rtlsdr_tuner rtlsdr_get_tuner_type(rtlsdr_dev_t *dev);
188 
199 RTLSDR_API int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains);
200 
215 RTLSDR_API int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain);
216 
223 RTLSDR_API int rtlsdr_get_tuner_gain(rtlsdr_dev_t *dev);
224 
233 RTLSDR_API int rtlsdr_set_tuner_if_gain(rtlsdr_dev_t *dev, int stage, int gain);
234 
243 RTLSDR_API int rtlsdr_set_tuner_gain_mode(rtlsdr_dev_t *dev, int manual);
244 
245 /* this will select the baseband filters according to the requested sample rate */
246 RTLSDR_API int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t rate);
247 
254 RTLSDR_API uint32_t rtlsdr_get_sample_rate(rtlsdr_dev_t *dev);
255 
264 RTLSDR_API int rtlsdr_set_testmode(rtlsdr_dev_t *dev, int on);
265 
273 RTLSDR_API int rtlsdr_set_agc_mode(rtlsdr_dev_t *dev, int on);
274 
285 RTLSDR_API int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on);
286 
294 RTLSDR_API int rtlsdr_get_direct_sampling(rtlsdr_dev_t *dev);
295 
304 RTLSDR_API int rtlsdr_set_offset_tuning(rtlsdr_dev_t *dev, int on);
305 
312 RTLSDR_API int rtlsdr_get_offset_tuning(rtlsdr_dev_t *dev);
313 
314 /* streaming functions */
315 
316 RTLSDR_API int rtlsdr_reset_buffer(rtlsdr_dev_t *dev);
317 
318 RTLSDR_API int rtlsdr_read_sync(rtlsdr_dev_t *dev, void *buf, int len, int *n_read);
319 
320 typedef void(*rtlsdr_read_async_cb_t)(unsigned char *buf, uint32_t len, void *ctx);
321 
333 RTLSDR_API int rtlsdr_wait_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx);
334 
348 RTLSDR_API int rtlsdr_read_async(rtlsdr_dev_t *dev,
349  rtlsdr_read_async_cb_t cb,
350  void *ctx,
351  uint32_t buf_num,
352  uint32_t buf_len);
353 
360 RTLSDR_API int rtlsdr_cancel_async(rtlsdr_dev_t *dev);
361 
362 #ifdef __cplusplus
363 }
364 #endif
365 
366 #endif /* __RTL_SDR_H */