Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding function to set GPIO pins to the SoapyRTL Driver? #23

Open
bcattle opened this issue Sep 18, 2016 · 6 comments
Open

Adding function to set GPIO pins to the SoapyRTL Driver? #23

bcattle opened this issue Sep 18, 2016 · 6 comments
Assignees

Comments

@bcattle
Copy link

bcattle commented Sep 18, 2016

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.

@cjcliffe
Copy link
Contributor

@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.

@bcattle
Copy link
Author

bcattle commented Sep 19, 2016

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.

@guruofquality
Copy link
Contributor

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.

@bcattle
Copy link
Author

bcattle commented Sep 19, 2016

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.

@guruofquality
Copy link
Contributor

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.

@bcattle
Copy link
Author

bcattle commented Sep 21, 2016

Got it. I'll update. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants