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-2013 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  RTLSDR_TUNER_R828D
180 };
181 
188 RTLSDR_API enum rtlsdr_tuner rtlsdr_get_tuner_type(rtlsdr_dev_t *dev);
189 
200 RTLSDR_API int rtlsdr_get_tuner_gains(rtlsdr_dev_t *dev, int *gains);
201 
216 RTLSDR_API int rtlsdr_set_tuner_gain(rtlsdr_dev_t *dev, int gain);
217 
224 RTLSDR_API int rtlsdr_get_tuner_gain(rtlsdr_dev_t *dev);
225 
234 RTLSDR_API int rtlsdr_set_tuner_if_gain(rtlsdr_dev_t *dev, int stage, int gain);
235 
244 RTLSDR_API int rtlsdr_set_tuner_gain_mode(rtlsdr_dev_t *dev, int manual);
245 
257 RTLSDR_API int rtlsdr_set_sample_rate(rtlsdr_dev_t *dev, uint32_t rate);
258 
265 RTLSDR_API uint32_t rtlsdr_get_sample_rate(rtlsdr_dev_t *dev);
266 
275 RTLSDR_API int rtlsdr_set_testmode(rtlsdr_dev_t *dev, int on);
276 
284 RTLSDR_API int rtlsdr_set_agc_mode(rtlsdr_dev_t *dev, int on);
285 
296 RTLSDR_API int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on);
297 
305 RTLSDR_API int rtlsdr_get_direct_sampling(rtlsdr_dev_t *dev);
306 
315 RTLSDR_API int rtlsdr_set_offset_tuning(rtlsdr_dev_t *dev, int on);
316 
323 RTLSDR_API int rtlsdr_get_offset_tuning(rtlsdr_dev_t *dev);
324 
325 /* streaming functions */
326 
327 RTLSDR_API int rtlsdr_reset_buffer(rtlsdr_dev_t *dev);
328 
329 RTLSDR_API int rtlsdr_read_sync(rtlsdr_dev_t *dev, void *buf, int len, int *n_read);
330 
331 typedef void(*rtlsdr_read_async_cb_t)(unsigned char *buf, uint32_t len, void *ctx);
332 
344 RTLSDR_API int rtlsdr_wait_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx);
345 
360 RTLSDR_API int rtlsdr_read_async(rtlsdr_dev_t *dev,
361  rtlsdr_read_async_cb_t cb,
362  void *ctx,
363  uint32_t buf_num,
364  uint32_t buf_len);
365 
372 RTLSDR_API int rtlsdr_cancel_async(rtlsdr_dev_t *dev);
373 
374 #ifdef __cplusplus
375 }
376 #endif
377 
378 #endif /* __RTL_SDR_H */