SoapyRTLSDR icon indicating copy to clipboard operation
SoapyRTLSDR copied to clipboard

Adding function to set GPIO pins to the SoapyRTL Driver?

Open bcattle opened this issue 7 years ago • 6 comments

I want to add a GPIO interface to the Soapy RTL-SDR driver. I'm designing an automatic antenna tuner that I want to control using the GPIO pins on the RTL-SDR.

The Blade RF Soapy driver has a GPIO interface. I'd like to implement a similar interface for the RTL-SDR:

void writeGPIO(const std::string &bank, const unsigned value);
void writeGPIO(const std::string &bank, const unsigned value, const unsigned mask);

The issue is that the librtlsdr driver supports these changing these pins with rtlsdr_set_gpio_bit, but this function is not public by default.

So I have a couple questions:

  1. On the Soapy side, does this API make sense?
  2. What should I do about making that function public in the librtlsdr driver? Is there a way to check whether that function is available when compiling, either in a future version of the driver or a custom fork?

Thanks.

bcattle avatar Sep 18 '16 22:09 bcattle

@bcattle interesting; I wasn't aware the RTL-SDR even had GPIO let alone 8 of them.

I'll leave this here for reference: http://lea.hamradio.si/~s57uuu/mischam/rtlsdr/ports.html as it appears to show what's needed; adding the prototypes to link in the functions or adding them ourselves should be trivial.

I'd be interested in modifying one of the dongles I have here to test and implement this.

cjcliffe avatar Sep 18 '16 23:09 cjcliffe

I have the v.3 dongle, and it has 4 of the pins brought out to pads, see http://imgur.com/a/XWGQt. The pads are labelled 29, 30, 31, and 32 corresponding to GPIO P5, P4, P2 and P1 according to http://lea.hamradio.si/~s57uuu/mischam/rtlsdr/ports.html.

I merged the Marko Cebokli / S57UUU code into a forked version of the driver here: https://github.com/bcattle/rtl-sdr. It compiles, but I haven't tested it yet.

bcattle avatar Sep 19 '16 01:09 bcattle

What should I do about making that function public in the librtlsdr driver? Is there a way to check whether that function is available when compiling, either in a future version of the driver or a custom fork?

Take a look at this CMakeLists which searches the header file for features and sets a define for the C++ source to use with ifdef. So basically the SoapyRTL could support the litany of feature branches out there, but always conditional check based on what its compiled against.

guruofquality avatar Sep 19 '16 01:09 guruofquality

If anyone wants to play with this, I added a command line utility to read and write the GPIO pins to a fork of the driver at https://github.com/bcattle/rtl-sdr. I tested it with my dongle and was able to set pins.

To use, run it with -s pin=val. Running it without args just prints the value of the register.

$ ./rtl_gpio
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
GPIO byte is set to: 0x8 (0b1000)

$ ./rtl_gpio -s 1=1
Found 1 device(s):
  0:  Realtek, RTL2838UHIDIR, SN: 00000001

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Setting pin 1 to 0b1
GPIO byte is set to: 0xa (0b1010)

On the Soapy side I added functions to set the pins to https://github.com/bcattle/SoapyRTLSDR.

bcattle avatar Sep 19 '16 07:09 bcattle

On the Soapy side I added functions to set the pins to https://github.com/bcattle/SoapyRTLSDR.

FYI, the GPIO functions need to exactly match the ones in SoapySDR::Device for the overloading to work.

guruofquality avatar Sep 19 '16 07:09 guruofquality

Got it. I'll update. Thanks

bcattle avatar Sep 21 '16 01:09 bcattle