Using the RTL2832 GPIO port

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 21

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);

rtlsdr_set_gpio_output(device, pin);

rtlsdr_set_gpio_bit(device, pin, val);

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); }

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);

rtlsdr_set_gpio_input(device, pin);

rtlsdr_get_gpio_bit(device, pin, &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); }