The RTL2832U chip has an 8bit GPIO port that can be used for things like
switching antennas, filters, preamplifiers, attenuators...
(Once upon the time, we used the printer port for that, but these are gone...)
The GPIO port pins are kind of randomly thrown around the RTL2832U package:
P0 = pin 37 P1 = pin 32 P2 = pin 31 P3 = pin 36 P4 = pin 30 P5 = pin 29 P6 = pin 22 P7 = pin 21In my R820T based dongle, none of them is used internally, and the pins are soldered to unconnected pads.
RTLSDR_API void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val); RTLSDR_API void rtlsdr_set_gpio_output(rtlsdr_dev_t *dev, uint8_t gpio);to the include/rtl-sdr.h file, and then do "make" and "make install".
rtlsdr_set_gpio_output(device, pin);where pin is [0...7].
rtlsdr_set_gpio_bit(device, pin, val);where val is [0,1].
void rtlsdr_get_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int *val) { uint16_t r; gpio = 1 << gpio; r = rtlsdr_read_reg(dev, SYSB, GPI, 1); *val = (r & gpio) ? 1 : 0; } void rtlsdr_set_gpio_input(rtlsdr_dev_t *dev, uint8_t gpio) { int r; gpio = 1 << gpio; r = rtlsdr_read_reg(dev, SYSB, GPD, 1); rtlsdr_write_reg(dev, SYSB, GPD, r | gpio, 1); r = rtlsdr_read_reg(dev, SYSB, GPOE, 1); rtlsdr_write_reg(dev, SYSB, GPOE, r & ~gpio, 1); }and, of course into /include/rtl-sdr.h
RTLSDR_API void rtlsdr_get_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int *val); RTLSDR_API void rtlsdr_set_gpio_input(rtlsdr_dev_t *dev, uint8_t gpio);Usage is similar to the output funcions, first set the pin to input mode with
rtlsdr_set_gpio_input(device, pin);where pin is [0...7].
rtlsdr_get_gpio_bit(device, pin, &val);where [0,1] will be returned in &val.
void rtlsdr_get_gpio_byte(rtlsdr_dev_t *dev, int *val) { *val = rtlsdr_read_reg(dev, SYSB, GPI, 1); } void rtlsdr_set_gpio_byte(rtlsdr_dev_t *dev, int val) { rtlsdr_write_reg(dev, SYSB, GPO, val); }