diff --git a/README b/README index 3a11c11..d329b20 100644 --- a/README +++ b/README @@ -10,3 +10,5 @@ Modified RTL-SDR Blog Version 1) VCO PLL current fix - Improves stability at frequencies above ~1.5 GHz https://www.rtl-sdr.com/beta-testing-a-modified-rtl-sdr-driver-for-l-band-heat-issues/ 2) RTL_TCP ring buffer enhancement by Stephen Blinick https://www.rtl-sdr.com/significantly-improving-rtl_tcps-performance-with-ring-buffers/ 3) Enabled direct sampling for rtl_tcp +4) rtl_biast program added, including the ability to turn on/off any GPIO +5) Hack to force the bias tee to always be on by setting the unused IR endpoint bit to 0 in the EEPROM with "rtl_eeprom -i 0" diff --git a/build/install_manifest.txt b/build/install_manifest.txt index ce6c476..d22899b 100644 --- a/build/install_manifest.txt +++ b/build/install_manifest.txt @@ -12,4 +12,5 @@ /usr/local/bin/rtl_fm /usr/local/bin/rtl_eeprom /usr/local/bin/rtl_adsb -/usr/local/bin/rtl_power \ No newline at end of file +/usr/local/bin/rtl_power +/usr/local/bin/rtl_biast \ No newline at end of file diff --git a/build/src/librtlsdr.a b/build/src/librtlsdr.a index fb57b96..91ab646 100644 Binary files a/build/src/librtlsdr.a and b/build/src/librtlsdr.a differ diff --git a/build/src/librtlsdr.so.0.6git b/build/src/librtlsdr.so.0.6git index 50250d7..bc14e71 100755 Binary files a/build/src/librtlsdr.so.0.6git and b/build/src/librtlsdr.so.0.6git differ diff --git a/build/src/rtl_adsb b/build/src/rtl_adsb index ba4e9c4..3d041b9 100755 Binary files a/build/src/rtl_adsb and b/build/src/rtl_adsb differ diff --git a/build/src/rtl_biast b/build/src/rtl_biast new file mode 100755 index 0000000..ef777e2 Binary files /dev/null and b/build/src/rtl_biast differ diff --git a/build/src/rtl_eeprom b/build/src/rtl_eeprom index 7f2ea87..7114de2 100755 Binary files a/build/src/rtl_eeprom and b/build/src/rtl_eeprom differ diff --git a/build/src/rtl_fm b/build/src/rtl_fm index 8d1039a..31c245b 100755 Binary files a/build/src/rtl_fm and b/build/src/rtl_fm differ diff --git a/build/src/rtl_power b/build/src/rtl_power index ad3d1b2..3d5c803 100755 Binary files a/build/src/rtl_power and b/build/src/rtl_power differ diff --git a/build/src/rtl_sdr b/build/src/rtl_sdr index 1ae940e..41e5764 100755 Binary files a/build/src/rtl_sdr and b/build/src/rtl_sdr differ diff --git a/build/src/rtl_tcp b/build/src/rtl_tcp index c931d1c..3a9e3df 100755 Binary files a/build/src/rtl_tcp and b/build/src/rtl_tcp differ diff --git a/build/src/rtl_test b/build/src/rtl_test index 58a91a0..28339e2 100755 Binary files a/build/src/rtl_test and b/build/src/rtl_test differ diff --git a/include/rtl-sdr.h b/include/rtl-sdr.h index 3ed13ae..6dd76d7 100644 --- a/include/rtl-sdr.h +++ b/include/rtl-sdr.h @@ -389,6 +389,16 @@ RTLSDR_API int rtlsdr_cancel_async(rtlsdr_dev_t *dev); */ RTLSDR_API int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on); +/*! + * Enable or disable any GPIO. + * \param dev the device handle given by rtlsdr_open() + * \param gpio_pin GPIO pin number for ON + * \param on 1 for GPIO on. 0 for GPIO off. + */ +RTLSDR_API int rtlsdr_set_gpio(rtlsdr_dev_t *dev, int gpio_pin, int on); + + + #ifdef __cplusplus } #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 07d64ab..ac0ff86 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,7 +91,9 @@ add_executable(rtl_fm rtl_fm.c) add_executable(rtl_eeprom rtl_eeprom.c) add_executable(rtl_adsb rtl_adsb.c) add_executable(rtl_power rtl_power.c) -set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power) +add_executable(rtl_biast rtl_biast.c) + +set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power rtl_biast) target_link_libraries(rtl_sdr rtlsdr_shared convenience_static ${LIBUSB_LIBRARIES} @@ -121,6 +123,10 @@ target_link_libraries(rtl_power rtlsdr_shared convenience_static ${LIBUSB_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) +target_link_libraries(rtl_biast rtlsdr_shared convenience_static + ${LIBUSB_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} +) if(UNIX) target_link_libraries(rtl_fm m) target_link_libraries(rtl_adsb m) @@ -140,6 +146,7 @@ target_link_libraries(rtl_fm libgetopt_static) target_link_libraries(rtl_eeprom libgetopt_static) target_link_libraries(rtl_adsb libgetopt_static) target_link_libraries(rtl_power libgetopt_static) +target_link_libraries(rtl_biast libgetopt_static) set_property(TARGET rtl_sdr APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) set_property(TARGET rtl_tcp APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) set_property(TARGET rtl_test APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) @@ -147,6 +154,7 @@ set_property(TARGET rtl_fm APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) set_property(TARGET rtl_eeprom APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) set_property(TARGET rtl_adsb APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) set_property(TARGET rtl_power APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) +set_property(TARGET rtl_biast APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) endif() ######################################################################## # Install built library files & utilities diff --git a/src/librtlsdr.c b/src/librtlsdr.c index 213e96c..aa75415 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -125,6 +125,7 @@ struct rtlsdr_dev { int dev_lost; int driver_active; unsigned int xfer_errors; + int force_bt; }; void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val); @@ -368,6 +369,7 @@ static rtlsdr_dongle_t known_devices[] = { #define BULK_TIMEOUT 0 #define EEPROM_ADDR 0xa0 +#define EEPROM_SIZE 256 enum usb_reg { USB_SYSCTL = 0x2000, @@ -1447,6 +1449,7 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index) struct libusb_device_descriptor dd; uint8_t reg; ssize_t cnt; + uint8_t buf[EEPROM_SIZE]; dev = malloc(sizeof(rtlsdr_dev_t)); if (NULL == dev) @@ -1609,6 +1612,7 @@ found: /* enable spectrum inversion */ rtlsdr_demod_write_reg(dev, 1, 0x15, 0x01, 1); + break; case RTLSDR_TUNER_UNKNOWN: fprintf(stderr, "No supported tuner found\n"); @@ -1618,6 +1622,14 @@ found: break; } + + /* Hack to force the Bias T to always be on if we set the IR-Endpoint bit in the EEPROM to 0. */ + //force_bt = 0; + r = rtlsdr_read_eeprom(dev, buf, 0, EEPROM_SIZE); + dev->force_bt = (buf[7] & 0x02) ? 0 : 1; + if(dev->force_bt) rtlsdr_set_gpio(dev, 0, 1); + + if (dev->tuner->init) r = dev->tuner->init(dev); @@ -2014,8 +2026,24 @@ int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on) if (!dev) return -1; + if(dev->force_bt) return 1; // If force_bt is on from the EEPROM, do not allow bias tee to turn off + rtlsdr_set_gpio_output(dev, 0); rtlsdr_set_gpio_bit(dev, 0, on); return 0; } + +int rtlsdr_set_gpio(rtlsdr_dev_t *dev, int gpio_pin, int on) +{ + if (!dev) + return -1; + + if(dev->force_bt) return 1; // If force_bt is on from the EEPROM, do not allow bias tee to turn off + + rtlsdr_set_gpio_output(dev, gpio_pin); + rtlsdr_set_gpio_bit(dev, gpio_pin, on); + + return 1; +} + diff --git a/src/rtl_biast.c b/src/rtl_biast.c new file mode 100644 index 0000000..6018450 --- /dev/null +++ b/src/rtl_biast.c @@ -0,0 +1,125 @@ +/* + * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver + * rtl_eeprom, EEPROM modification tool + * Copyright (C) 2012 by Steve Markgraf + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#ifndef _WIN32 +#include +#else +#include +#include "getopt/getopt.h" +#endif + +#include "rtl-sdr.h" +#include "convenience/convenience.h" + +#define EEPROM_SIZE 256 +#define MAX_STR_SIZE 256 +#define STR_OFFSET 0x09 + +static rtlsdr_dev_t *dev = NULL; + +typedef struct rtlsdr_config { + uint16_t vendor_id; + uint16_t product_id; + char manufacturer[MAX_STR_SIZE]; + char product[MAX_STR_SIZE]; + char serial[MAX_STR_SIZE]; + int have_serial; + int enable_ir; + int remote_wakeup; +} rtlsdr_config_t; + + +void usage(void) +{ + fprintf(stderr, + "rtl_biast, a tool for turning the RTL-SDR.com \n" + "bias tee or any GPIO ON and OFF. Example to turn on the \n" + "bias tee: rtl_biast -d 0 -b 1\n" + "Any GPIO: rtl_biast -d 0 -g 1 -b 1\n\n" + "Usage:\n" + "\t[-d device_index (default: 0)]\n" + "\t[-b bias_on (default: 0)]\n" + "\t[-g GPIO select (default: 0)]\n"); + exit(1); +} + +int main(int argc, char **argv) +{ + int i, r, opt; + int dev_index = 0; + int dev_given = 0; + uint32_t bias_on = 0; + uint32_t gpio_pin = 0; + int device_count; + char *filename = NULL; + FILE *file = NULL; + char *manuf_str = NULL; + char *product_str = NULL; + char *serial_str = NULL; + uint8_t buf[EEPROM_SIZE]; + rtlsdr_config_t conf; + int flash_file = 0; + int default_config = 0; + int change = 0; + int ir_endpoint = 0; + char ch; + + while ((opt = getopt(argc, argv, "d:b:g:h?")) != -1) { + switch (opt) { + case 'd': + dev_index = verbose_device_search(optarg); + dev_given = 1; + break; + case 'b': + bias_on = atoi(optarg); + break; + case 'g': + gpio_pin = atoi(optarg); + break; + default: + usage(); + break; + } + } + + if (!dev_given) { + dev_index = verbose_device_search("0"); + } + + if (dev_index < 0) { + exit(1); + } + + r = rtlsdr_open(&dev, dev_index); + + rtlsdr_set_gpio(dev, gpio_pin, bias_on); + //rtlsdr_set_bias_tee(dev, bias_on); + + //rtlsdr_set_direct_sampling(dev, 1); + +exit: + rtlsdr_close(dev); + + return r >= 0 ? r : -r; +} +