Skip to content

Commit b86b78c

Browse files
author
Adrian Chadd
committed
[librtlsdr] Add a new method to leave the bias tee on; shut it off during close
* Close the biast by default * Track the last used GPIO pin for the biast so we know which pin to close! * Add a new method which tells librtlsdr to leave it on
1 parent e438968 commit b86b78c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

include/rtl-sdr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,14 @@ RTLSDR_API int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on);
399399
*/
400400
RTLSDR_API int rtlsdr_set_bias_tee_gpio(rtlsdr_dev_t *dev, int gpio, int on);
401401

402+
/*!
403+
* Control whether the bias tee is left on after rtlsdr_close() is called.
404+
*
405+
* \param dev the device handle given by rtlsdr_open()
406+
* \param leave_on 1 to leave Bias T on upon library close; 0 otherwise
407+
* \return -1 if device is not initialized. 0 otherwise.
408+
*/
409+
RTLSDR_API int rtlsdr_set_bias_tee_leave_on(rtlsdr_dev_t *dev, int leave_on);
402410

403411
#ifdef __cplusplus
404412
}

src/librtlsdr.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ struct rtlsdr_dev {
104104
enum rtlsdr_async_status async_status;
105105
int async_cancel;
106106
int use_zerocopy;
107+
int keep_biast_on;
108+
int biast_gpio;
107109
/* rtl demod context */
108110
uint32_t rate; /* Hz */
109111
uint32_t rtl_xtal; /* Hz */
@@ -1658,6 +1660,14 @@ int rtlsdr_close(rtlsdr_dev_t *dev)
16581660
rtlsdr_deinit_baseband(dev);
16591661
}
16601662

1663+
/*
1664+
* Disable bias-tee unless we're explicitly asked
1665+
* to keep it on.
1666+
*/
1667+
if (dev->keep_biast_on == 0) {
1668+
rtlsdr_set_bias_tee(dev, 0);
1669+
}
1670+
16611671
libusb_release_interface(dev->devh, 0);
16621672

16631673
#ifdef DETACH_KERNEL_DRIVER
@@ -2014,6 +2024,7 @@ int rtlsdr_set_bias_tee_gpio(rtlsdr_dev_t *dev, int gpio, int on)
20142024
if (!dev)
20152025
return -1;
20162026

2027+
dev->biast_gpio = gpio;
20172028
rtlsdr_set_gpio_output(dev, gpio);
20182029
rtlsdr_set_gpio_bit(dev, gpio, on);
20192030

@@ -2022,5 +2033,17 @@ int rtlsdr_set_bias_tee_gpio(rtlsdr_dev_t *dev, int gpio, int on)
20222033

20232034
int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on)
20242035
{
2036+
if (!dev)
2037+
return -1;
2038+
20252039
return rtlsdr_set_bias_tee_gpio(dev, 0, on);
20262040
}
2041+
2042+
int rtlsdr_set_bias_tee_leave_on(rtlsdr_dev_t *dev, int leave_on)
2043+
{
2044+
if (!dev)
2045+
return -1;
2046+
2047+
dev->keep_biast_on = leave_on;
2048+
return 0;
2049+
}

0 commit comments

Comments
 (0)