From 284b415ec33e7ca35510835b5d324be13a77bd5f Mon Sep 17 00:00:00 2001 From: hayati ayguen Date: Wed, 19 Aug 2020 15:06:55 -0700 Subject: [PATCH] lib: Add GPIO version of the bias tee configuration API rtl_biast allows for non-default GPIO pins to be used. Add an API call which allows for that. (cherry picked from commit 5d0735f5dfe276203261b8bcd3817341d4630ab2) fixed conflicts Signed-off-by: hayati ayguen --- include/rtl-sdr.h | 10 ++++++++++ src/librtlsdr.c | 11 ++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/rtl-sdr.h b/include/rtl-sdr.h index 58bf23a..8635bd2 100755 --- a/include/rtl-sdr.h +++ b/include/rtl-sdr.h @@ -535,6 +535,16 @@ RTLSDR_API int rtlsdr_ir_query(rtlsdr_dev_t *dev, uint8_t *buf, size_t buf_len); */ RTLSDR_API int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on); +/*! + * Enable or disable the bias tee on the given GPIO pin. + * + * \param dev the device handle given by rtlsdr_open() + * \param gpio the gpio pin to configure as a Bias T control. + * \param on 1 for Bias T on. 0 for Bias T off. + * \return -1 if device is not initialized. 0 otherwise. + */ +RTLSDR_API int rtlsdr_set_bias_tee_gpio(rtlsdr_dev_t *dev, int gpio, int on); + /*! * Sets multiple options from a string encoded like "bw=300:agc=0:gain=27.3:dagc=0:T=1". * this is a helper function, that programs don't need to implement every single option diff --git a/src/librtlsdr.c b/src/librtlsdr.c index 2cfac04..023b4f0 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -3821,18 +3821,23 @@ err: return ret; } -int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on) +int rtlsdr_set_bias_tee_gpio(rtlsdr_dev_t *dev, int gpio, int on) { if (!dev) return -1; - rtlsdr_set_gpio_output(dev, 0); - rtlsdr_set_gpio_bit(dev, 0, on); + rtlsdr_set_gpio_output(dev, gpio); + rtlsdr_set_gpio_bit(dev, gpio, on); reactivate_softagc(dev, SOFTSTATE_RESET); return 0; } +int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on) +{ + return rtlsdr_set_bias_tee_gpio(dev, 0, on); +} + const char * rtlsdr_get_opt_help(int longInfo) {