apply steve-m/librtlsdr/pull/58

master
Ondřej Hruška 3 years ago
parent 7977396669
commit 9fe533c949
  1. 10
      src/librtlsdr.c

@ -537,6 +537,7 @@ uint16_t rtlsdr_demod_read_reg(rtlsdr_dev_t *dev, uint8_t page, uint16_t addr, u
int rtlsdr_demod_write_reg(rtlsdr_dev_t *dev, uint8_t page, uint16_t addr, uint16_t val, uint8_t len) int rtlsdr_demod_write_reg(rtlsdr_dev_t *dev, uint8_t page, uint16_t addr, uint16_t val, uint8_t len)
{ {
int r; int r;
int retries = 2;
unsigned char data[2]; unsigned char data[2];
uint16_t index = 0x10 | page; uint16_t index = 0x10 | page;
addr = (addr << 8) | 0x20; addr = (addr << 8) | 0x20;
@ -548,13 +549,18 @@ int rtlsdr_demod_write_reg(rtlsdr_dev_t *dev, uint8_t page, uint16_t addr, uint1
data[1] = val & 0xff; data[1] = val & 0xff;
r = libusb_control_transfer(dev->devh, CTRL_OUT, 0, addr, index, data, len, CTRL_TIMEOUT); r = libusb_control_transfer(dev->devh, CTRL_OUT, 0, addr, index, data, len, CTRL_TIMEOUT);
do {
r = libusb_control_transfer(dev->devh, CTRL_OUT, 0, addr, index, data, len, CTRL_TIMEOUT);
rtlsdr_demod_read_reg(dev, 0x0a, 0x01, 1);
retries--;
} while (retries > 0 && r < 0);
if (r < 0) if (r < 0)
fprintf(stderr, "%s failed with %d\n", __FUNCTION__, r); fprintf(stderr, "%s failed with %d\n", __FUNCTION__, r);
rtlsdr_demod_read_reg(dev, 0x0a, 0x01, 1);
return (r == len) ? 0 : -1; return (r == len) ? 0 : -1;
} }

Loading…
Cancel
Save