add force bias tee via EEPROM

This commit is contained in:
rtlsdrblog 2023-08-24 00:49:45 +12:00
parent 1b2dcbf1be
commit 2f87dd0130
2 changed files with 35 additions and 17 deletions

View File

@ -121,6 +121,7 @@ struct rtlsdr_dev {
unsigned int xfer_errors; unsigned int xfer_errors;
char manufact[256]; char manufact[256];
char product[256]; char product[256];
int force_bt;
}; };
void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val); void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val);
@ -365,6 +366,7 @@ static rtlsdr_dongle_t known_devices[] = {
#define BULK_TIMEOUT 0 #define BULK_TIMEOUT 0
#define EEPROM_ADDR 0xa0 #define EEPROM_ADDR 0xa0
#define EEPROM_SIZE 256
enum usb_reg { enum usb_reg {
USB_SYSCTL = 0x2000, USB_SYSCTL = 0x2000,
@ -1496,6 +1498,7 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
struct libusb_device_descriptor dd; struct libusb_device_descriptor dd;
uint8_t reg; uint8_t reg;
ssize_t cnt; ssize_t cnt;
uint8_t buf[EEPROM_SIZE];
dev = malloc(sizeof(rtlsdr_dev_t)); dev = malloc(sizeof(rtlsdr_dev_t));
if (NULL == dev) if (NULL == dev)
@ -1677,6 +1680,14 @@ found:
break; break;
} }
/* Hack to force the Bias T to always be on if we set the IR-Endpoint
* bit in the EEPROM to 0. Default on EEPROM is 1.
*/
r = rtlsdr_read_eeprom(dev, buf, 0, EEPROM_SIZE);
dev->force_bt = (buf[7] & 0x02) ? 0 : 1;
if(dev->force_bt)
rtlsdr_set_bias_tee(dev, 1);
if (dev->tuner->init) if (dev->tuner->init)
r = dev->tuner->init(dev); r = dev->tuner->init(dev);
@ -2076,6 +2087,12 @@ int rtlsdr_set_bias_tee_gpio(rtlsdr_dev_t *dev, int gpio, int on)
if (!dev) if (!dev)
return -1; return -1;
/* If it's the bias tee GPIO, and force bias tee is on
* don't allow the bias tee to turn off. Prevents software
* that initializes with the bias tee off from turning it off */
if(gpio == 0 && dev->force_bt)
on = 1;
rtlsdr_set_gpio_output(dev, gpio); rtlsdr_set_gpio_output(dev, gpio);
rtlsdr_set_gpio_bit(dev, gpio, on); rtlsdr_set_gpio_bit(dev, gpio, on);

View File

@ -43,7 +43,7 @@ typedef struct rtlsdr_config {
char product[MAX_STR_SIZE]; char product[MAX_STR_SIZE];
char serial[MAX_STR_SIZE]; char serial[MAX_STR_SIZE];
int have_serial; int have_serial;
int enable_ir; int enable_bt;
int remote_wakeup; int remote_wakeup;
} rtlsdr_config_t; } rtlsdr_config_t;
@ -57,8 +57,8 @@ void dump_config(rtlsdr_config_t *conf)
fprintf(stderr, "Serial number:\t\t%s\n", conf->serial); fprintf(stderr, "Serial number:\t\t%s\n", conf->serial);
fprintf(stderr, "Serial number enabled:\t"); fprintf(stderr, "Serial number enabled:\t");
fprintf(stderr, conf->have_serial ? "yes\n": "no\n"); fprintf(stderr, conf->have_serial ? "yes\n": "no\n");
fprintf(stderr, "IR endpoint enabled:\t"); fprintf(stderr, "Bias Tee always on:\t");
fprintf(stderr, conf->enable_ir ? "yes\n": "no\n"); fprintf(stderr, conf->enable_bt ? "no\n": "yes\n"); // 0 is ON for enable_bt
fprintf(stderr, "Remote wakeup enabled:\t"); fprintf(stderr, "Remote wakeup enabled:\t");
fprintf(stderr, conf->remote_wakeup ? "yes\n": "no\n"); fprintf(stderr, conf->remote_wakeup ? "yes\n": "no\n");
fprintf(stderr, "__________________________________________\n"); fprintf(stderr, "__________________________________________\n");
@ -74,7 +74,7 @@ void usage(void)
"\t[-m <str> set manufacturer string]\n" "\t[-m <str> set manufacturer string]\n"
"\t[-p <str> set product string]\n" "\t[-p <str> set product string]\n"
"\t[-s <str> set serial number string]\n" "\t[-s <str> set serial number string]\n"
"\t[-i <0,1> disable/enable IR-endpoint]\n" "\t[-b <0,1> disable/enable force bias tee always on (0: OFF, 1: ON)]\n"
"\t[-g <conf> generate default config and write to device]\n" "\t[-g <conf> generate default config and write to device]\n"
"\t[ <conf> can be one of:]\n" "\t[ <conf> can be one of:]\n"
"\t[ realtek\t\tRealtek default (as without EEPROM)]\n" "\t[ realtek\t\tRealtek default (as without EEPROM)]\n"
@ -140,7 +140,7 @@ int parse_eeprom_to_conf(rtlsdr_config_t *conf, uint8_t *dat)
conf->product_id = dat[4] | (dat[5] << 8); conf->product_id = dat[4] | (dat[5] << 8);
conf->have_serial = (dat[6] == 0xa5) ? 1 : 0; conf->have_serial = (dat[6] == 0xa5) ? 1 : 0;
conf->remote_wakeup = (dat[7] & 0x01) ? 1 : 0; conf->remote_wakeup = (dat[7] & 0x01) ? 1 : 0;
conf->enable_ir = (dat[7] & 0x02) ? 1 : 0; conf->enable_bt = (dat[7] & 0x02) ? 1 : 0;
pos = get_string_descriptor(STR_OFFSET, dat, conf->manufacturer); pos = get_string_descriptor(STR_OFFSET, dat, conf->manufacturer);
pos = get_string_descriptor(pos, dat, conf->product); pos = get_string_descriptor(pos, dat, conf->product);
@ -162,7 +162,7 @@ int gen_eeprom_from_conf(rtlsdr_config_t *conf, uint8_t *dat)
dat[6] = conf->have_serial ? 0xa5 : 0x00; dat[6] = conf->have_serial ? 0xa5 : 0x00;
dat[7] = 0x14; dat[7] = 0x14;
dat[7] |= conf->remote_wakeup ? 0x01 : 0x00; dat[7] |= conf->remote_wakeup ? 0x01 : 0x00;
dat[7] |= conf->enable_ir ? 0x02 : 0x00; dat[7] |= conf->enable_bt ? 0x02 : 0x00;
dat[8] = 0x02; dat[8] = 0x02;
pos = set_string_descriptor(STR_OFFSET, dat, conf->manufacturer); pos = set_string_descriptor(STR_OFFSET, dat, conf->manufacturer);
@ -194,7 +194,7 @@ void gen_default_conf(rtlsdr_config_t *conf, int config)
strcpy(conf->product, "RTL2832U DVB-T"); strcpy(conf->product, "RTL2832U DVB-T");
strcpy(conf->serial, "0"); strcpy(conf->serial, "0");
conf->have_serial = 1; conf->have_serial = 1;
conf->enable_ir = 0; conf->enable_bt = 0;
conf->remote_wakeup = 1; conf->remote_wakeup = 1;
break; break;
case REALTEK_EEPROM: case REALTEK_EEPROM:
@ -205,7 +205,7 @@ void gen_default_conf(rtlsdr_config_t *conf, int config)
strcpy(conf->product, "RTL2838UHIDIR"); strcpy(conf->product, "RTL2838UHIDIR");
strcpy(conf->serial, "00000001"); strcpy(conf->serial, "00000001");
conf->have_serial = 1; conf->have_serial = 1;
conf->enable_ir = 1; conf->enable_bt = 1;
conf->remote_wakeup = 0; conf->remote_wakeup = 0;
break; break;
case TERRATEC_NOXON: case TERRATEC_NOXON:
@ -216,7 +216,7 @@ void gen_default_conf(rtlsdr_config_t *conf, int config)
strcpy(conf->product, "DAB Stick"); strcpy(conf->product, "DAB Stick");
strcpy(conf->serial, "0"); strcpy(conf->serial, "0");
conf->have_serial = 1; conf->have_serial = 1;
conf->enable_ir = 0; conf->enable_bt = 0;
conf->remote_wakeup = 1; conf->remote_wakeup = 1;
break; break;
case TERRATEC_T_BLACK: case TERRATEC_T_BLACK:
@ -227,7 +227,7 @@ void gen_default_conf(rtlsdr_config_t *conf, int config)
strcpy(conf->product, "RTL2838UHIDIR"); strcpy(conf->product, "RTL2838UHIDIR");
strcpy(conf->serial, "00000001"); strcpy(conf->serial, "00000001");
conf->have_serial = 1; conf->have_serial = 1;
conf->enable_ir = 1; conf->enable_bt = 1;
conf->remote_wakeup = 0; conf->remote_wakeup = 0;
break; break;
case TERRATEC_T_PLUS: case TERRATEC_T_PLUS:
@ -238,7 +238,7 @@ void gen_default_conf(rtlsdr_config_t *conf, int config)
strcpy(conf->product, "RTL2838UHIDIR"); strcpy(conf->product, "RTL2838UHIDIR");
strcpy(conf->serial, "00000001"); strcpy(conf->serial, "00000001");
conf->have_serial = 1; conf->have_serial = 1;
conf->enable_ir = 1; conf->enable_bt = 1;
conf->remote_wakeup = 0; conf->remote_wakeup = 0;
break; break;
default: default:
@ -261,10 +261,10 @@ int main(int argc, char **argv)
int flash_file = 0; int flash_file = 0;
int default_config = 0; int default_config = 0;
int change = 0; int change = 0;
int ir_endpoint = 0; int enable_bt = 0;
char ch; char ch;
while ((opt = getopt(argc, argv, "d:m:p:s:i:g:w:r:h?")) != -1) { while ((opt = getopt(argc, argv, "d:m:p:s:b:g:w:r:h?")) != -1) {
switch (opt) { switch (opt) {
case 'd': case 'd':
dev_index = atoi(optarg); dev_index = atoi(optarg);
@ -281,8 +281,9 @@ int main(int argc, char **argv)
serial_str = optarg; serial_str = optarg;
change = 1; change = 1;
break; break;
case 'i': case 'b':
ir_endpoint = (atoi(optarg) > 0) ? 1 : -1; enable_bt = (atoi(optarg) > 0) ? -1 : 1;
//ir_endpoint = (atoi(optarg) > 0) ? 1 : -1;
change = 1; change = 1;
break; break;
case 'g': case 'g':
@ -380,8 +381,8 @@ int main(int argc, char **argv)
strncpy((char*)&conf.serial, serial_str, MAX_STR_SIZE - 1); strncpy((char*)&conf.serial, serial_str, MAX_STR_SIZE - 1);
} }
if (ir_endpoint != 0) if (enable_bt != 0)
conf.enable_ir = (ir_endpoint > 0) ? 1 : 0; conf.enable_bt = (enable_bt > 0) ? 1 : 0;
if (!change) if (!change)
goto exit; goto exit;