Skip to content

Commit

Permalink
only enable auto-ds switching if ds mode from a UI is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
rtlsdrblog committed Aug 27, 2023
1 parent ef7651c commit c79775f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions include/rtl-sdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ extern "C" {

typedef struct rtlsdr_dev rtlsdr_dev_t;

enum rtlsdr_ds_mode {
RTLSDR_DS_IQ = 0, /* I/Q quadrature sampling of tuner output */
RTLSDR_DS_I, /* 1: direct sampling on I branch: usually not connected */
RTLSDR_DS_Q, /* 2: direct sampling on Q branch: HF on rtl-sdr v3 dongle */
};


RTLSDR_API uint32_t rtlsdr_get_device_count(void);

RTLSDR_API const char* rtlsdr_get_device_name(uint32_t index);
Expand Down Expand Up @@ -302,6 +309,7 @@ RTLSDR_API int rtlsdr_set_agc_mode(rtlsdr_dev_t *dev, int on);
* \param on 0 means disabled, 1 I-ADC input enabled, 2 Q-ADC input enabled
* \return 0 on success
*/
int _rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on);
RTLSDR_API int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on);

/*!
Expand Down
19 changes: 16 additions & 3 deletions src/librtlsdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ struct rtlsdr_dev {
char manufact[256];
char product[256];
int force_bt;
enum rtlsdr_ds_mode direct_sampling_mode;
};

void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val);
Expand Down Expand Up @@ -896,8 +897,12 @@ int rtlsdr_set_center_freq(rtlsdr_dev_t *dev, uint32_t freq)
if (last_ds < 0)
return 1;

/* Check if direct sampling should be enabled */
dev->direct_sampling = (freq < 28800000 && dev->tuner_type == RTLSDR_TUNER_R820T) ? 2 : 0;
/* Check if direct sampling should be enabled.
* Also only enable auto switch if ds mode is 0 (aka None, or standard mode)
*/
if(dev->direct_sampling_mode == 0) {
dev->direct_sampling = (freq < 28800000 && dev->tuner_type == RTLSDR_TUNER_R820T) ? 2 : 0;
}

if (dev->direct_sampling) {
rtlsdr_set_i2c_repeater(dev, 0);
Expand All @@ -917,7 +922,7 @@ int rtlsdr_set_center_freq(rtlsdr_dev_t *dev, uint32_t freq)
* the previous frequency back again
*/
if (last_ds != dev->direct_sampling) {
return rtlsdr_set_direct_sampling(dev, dev->direct_sampling);
return _rtlsdr_set_direct_sampling(dev, dev->direct_sampling);
}

return r;
Expand Down Expand Up @@ -1191,7 +1196,15 @@ int rtlsdr_set_agc_mode(rtlsdr_dev_t *dev, int on)
return rtlsdr_demod_write_reg(dev, 0, 0x19, on ? 0x25 : 0x05, 1);
}


int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on)
{
/* When the UI sets the ds mode, remember the mode set */
dev->direct_sampling_mode = (enum rtlsdr_ds_mode)on;
return _rtlsdr_set_direct_sampling(dev, on);
}

int _rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on)
{
int r = 0;

Expand Down

0 comments on commit c79775f

Please sign in to comment.