From 7977396669b28014a3f45e65aeb4c6c0947eaf18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 27 Feb 2022 22:40:55 +0100 Subject: [PATCH] apply steve-m/librtlsdr/pull/56 --- src/librtlsdr.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/librtlsdr.c b/src/librtlsdr.c index f567f01..7b35946 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -581,6 +581,7 @@ void rtlsdr_set_gpio_output(rtlsdr_dev_t *dev, uint8_t gpio) void rtlsdr_set_i2c_repeater(rtlsdr_dev_t *dev, int on) { + on = !!on; /* values +2 to force on */ rtlsdr_demod_write_reg(dev, 1, 0x01, on ? 0x18 : 0x10, 1); } @@ -2016,16 +2017,34 @@ uint32_t rtlsdr_get_tuner_clock(void *dev) int rtlsdr_i2c_write_fn(void *dev, uint8_t addr, uint8_t *buf, int len) { - if (dev) - return rtlsdr_i2c_write(((rtlsdr_dev_t *)dev), addr, buf, len); + int r; + int retries = 2; + if (!dev) + return -1; + do { + r = rtlsdr_i2c_write(((rtlsdr_dev_t *)dev), addr, buf, len); + if (r >= 0) + return r; + rtlsdr_set_i2c_repeater(dev, 2); + retries--; + } while (retries > 0); return -1; } int rtlsdr_i2c_read_fn(void *dev, uint8_t addr, uint8_t *buf, int len) { - if (dev) - return rtlsdr_i2c_read(((rtlsdr_dev_t *)dev), addr, buf, len); + int r; + int retries = 2; + if (!dev) + return -1; + do { + r = rtlsdr_i2c_read(((rtlsdr_dev_t *)dev), addr, buf, len); + if (r >= 0) + return r; + rtlsdr_set_i2c_repeater(dev, 2); + retries--; + } while (retries > 0); return -1; }