mirror of
https://github.com/rtlsdrblog/rtl-sdr-blog.git
synced 2024-11-10 04:37:37 +01:00
add rtl-sdr blog v4 support
This commit is contained in:
parent
142325a93c
commit
1261fbb285
@ -1,6 +1,7 @@
|
|||||||
#ifndef __I2C_H
|
#ifndef __I2C_H
|
||||||
#define __I2C_H
|
#define __I2C_H
|
||||||
|
|
||||||
|
int rtlsdr_check_dongle_model(void *dev, char *manufact_check, char *product_check);
|
||||||
uint32_t rtlsdr_get_tuner_clock(void *dev);
|
uint32_t rtlsdr_get_tuner_clock(void *dev);
|
||||||
int rtlsdr_i2c_write_fn(void *dev, uint8_t addr, uint8_t *buf, int len);
|
int rtlsdr_i2c_write_fn(void *dev, uint8_t addr, uint8_t *buf, int len);
|
||||||
int rtlsdr_i2c_read_fn(void *dev, uint8_t addr, uint8_t *buf, int len);
|
int rtlsdr_i2c_read_fn(void *dev, uint8_t addr, uint8_t *buf, int len);
|
||||||
|
@ -119,6 +119,8 @@ struct rtlsdr_dev {
|
|||||||
int dev_lost;
|
int dev_lost;
|
||||||
int driver_active;
|
int driver_active;
|
||||||
unsigned int xfer_errors;
|
unsigned int xfer_errors;
|
||||||
|
char manufact[256];
|
||||||
|
char product[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
@ -1430,6 +1432,16 @@ int rtlsdr_get_index_by_serial(const char *serial)
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns true if the manufact_check and product_check strings match what is in the dongles EEPROM */
|
||||||
|
int rtlsdr_check_dongle_model(void *dev, char *manufact_check, char *product_check)
|
||||||
|
{
|
||||||
|
if ((strcmp(((rtlsdr_dev_t *)dev)->manufact, manufact_check) == 0&& strcmp(((rtlsdr_dev_t *)dev)->product, product_check) == 0))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
|
int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
@ -1528,6 +1540,9 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
|
|||||||
rtlsdr_init_baseband(dev);
|
rtlsdr_init_baseband(dev);
|
||||||
dev->dev_lost = 0;
|
dev->dev_lost = 0;
|
||||||
|
|
||||||
|
/* Get device manufacturer and product id */
|
||||||
|
r = rtlsdr_get_usb_strings(dev, dev->manufact, dev->product, NULL);
|
||||||
|
|
||||||
/* Probe tuners */
|
/* Probe tuners */
|
||||||
rtlsdr_set_i2c_repeater(dev, 1);
|
rtlsdr_set_i2c_repeater(dev, 1);
|
||||||
|
|
||||||
@ -1555,6 +1570,10 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
|
|||||||
reg = rtlsdr_i2c_read_reg(dev, R828D_I2C_ADDR, R82XX_CHECK_ADDR);
|
reg = rtlsdr_i2c_read_reg(dev, R828D_I2C_ADDR, R82XX_CHECK_ADDR);
|
||||||
if (reg == R82XX_CHECK_VAL) {
|
if (reg == R82XX_CHECK_VAL) {
|
||||||
fprintf(stderr, "Found Rafael Micro R828D tuner\n");
|
fprintf(stderr, "Found Rafael Micro R828D tuner\n");
|
||||||
|
|
||||||
|
if (rtlsdr_check_dongle_model(dev, "RTLSDRBlog", "Blog V4"))
|
||||||
|
fprintf(stderr, "RTL-SDR Blog V4 Detected\n");
|
||||||
|
|
||||||
dev->tuner_type = RTLSDR_TUNER_R828D;
|
dev->tuner_type = RTLSDR_TUNER_R828D;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
@ -1588,7 +1607,10 @@ found:
|
|||||||
|
|
||||||
switch (dev->tuner_type) {
|
switch (dev->tuner_type) {
|
||||||
case RTLSDR_TUNER_R828D:
|
case RTLSDR_TUNER_R828D:
|
||||||
|
/* If NOT an RTL-SDR Blog V4, set typical R828D 16 MHz freq. Otherwise, keep at 28.8 MHz. */
|
||||||
|
if (!(rtlsdr_check_dongle_model(dev, "RTLSDRBlog", "Blog V4"))) {
|
||||||
dev->tun_xtal = R828D_XTAL_FREQ;
|
dev->tun_xtal = R828D_XTAL_FREQ;
|
||||||
|
}
|
||||||
/* fall-through */
|
/* fall-through */
|
||||||
case RTLSDR_TUNER_R820T:
|
case RTLSDR_TUNER_R820T:
|
||||||
/* disable Zero-IF mode */
|
/* disable Zero-IF mode */
|
||||||
|
@ -33,6 +33,10 @@
|
|||||||
#define MHZ(x) ((x)*1000*1000)
|
#define MHZ(x) ((x)*1000*1000)
|
||||||
#define KHZ(x) ((x)*1000)
|
#define KHZ(x) ((x)*1000)
|
||||||
|
|
||||||
|
#define HF 1
|
||||||
|
#define VHF 2
|
||||||
|
#define UHF 3
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Static constants
|
* Static constants
|
||||||
*/
|
*/
|
||||||
@ -1098,8 +1102,23 @@ int r82xx_set_bandwidth(struct r82xx_priv *priv, int bw, uint32_t rate)
|
|||||||
int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq)
|
int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq)
|
||||||
{
|
{
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
uint32_t lo_freq = freq + priv->int_freq;
|
int is_rtlsdr_blog_v4;
|
||||||
|
uint32_t upconvert_freq;
|
||||||
|
uint32_t lo_freq;
|
||||||
uint8_t air_cable1_in;
|
uint8_t air_cable1_in;
|
||||||
|
uint8_t open_d;
|
||||||
|
uint8_t band;
|
||||||
|
uint8_t cable_2_in;
|
||||||
|
uint8_t cable_1_in;
|
||||||
|
uint8_t air_in;
|
||||||
|
|
||||||
|
is_rtlsdr_blog_v4 = rtlsdr_check_dongle_model(priv->rtl_dev, "RTLSDRBlog", "Blog V4");
|
||||||
|
|
||||||
|
/* if it's an RTL-SDR Blog V4, automatically upconvert by 28.8 MHz if we tune to HF
|
||||||
|
* so that we don't need to manually set any upconvert offset in the SDR software */
|
||||||
|
upconvert_freq = is_rtlsdr_blog_v4 ? ((freq < MHZ(28.8)) ? (freq + MHZ(28.8)) : freq) : freq;
|
||||||
|
|
||||||
|
lo_freq = upconvert_freq + priv->int_freq;
|
||||||
|
|
||||||
rc = r82xx_set_mux(priv, lo_freq);
|
rc = r82xx_set_mux(priv, lo_freq);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
@ -1109,6 +1128,49 @@ int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq)
|
|||||||
if (rc < 0 || !priv->has_lock)
|
if (rc < 0 || !priv->has_lock)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
|
if (is_rtlsdr_blog_v4) {
|
||||||
|
/* determine if notch filters should be on or off notches are turned OFF
|
||||||
|
* when tuned within the notch band and ON when tuned outside the notch band.
|
||||||
|
*/
|
||||||
|
open_d = (freq <= MHZ(2.2) || (freq >= MHZ(85) && freq <= MHZ(112)) || (freq >= MHZ(172) && freq <= MHZ(242))) ? 0x00 : 0x08;
|
||||||
|
rc = r82xx_write_reg_mask(priv, 0x17, open_d, 0x08);
|
||||||
|
|
||||||
|
if (rc < 0)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
/* select tuner band based on frequency and only switch if there is a band change
|
||||||
|
*(to avoid excessive register writes when tuning rapidly)
|
||||||
|
*/
|
||||||
|
band = (freq <= MHZ(28.8)) ? HF : ((freq > MHZ(28.8) && freq < MHZ(250)) ? VHF : UHF);
|
||||||
|
|
||||||
|
/* switch between tuner inputs on the RTL-SDR Blog V4 */
|
||||||
|
if (band != priv->input) {
|
||||||
|
priv->input = band;
|
||||||
|
|
||||||
|
/* activate cable 2 (HF input) */
|
||||||
|
cable_2_in = (band == HF) ? 0x08 : 0x00;
|
||||||
|
rc = r82xx_write_reg_mask(priv, 0x06, cable_2_in, 0x08);
|
||||||
|
|
||||||
|
if (rc < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* activate cable 1 (VHF input) */
|
||||||
|
cable_1_in = (band == VHF) ? 0x40 : 0x00;
|
||||||
|
rc = r82xx_write_reg_mask(priv, 0x05, cable_1_in, 0x40);
|
||||||
|
|
||||||
|
if (rc < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* activate air_in (UHF input) */
|
||||||
|
air_in = (band == UHF) ? 0x00 : 0x20;
|
||||||
|
rc = r82xx_write_reg_mask(priv, 0x05, air_in, 0x20);
|
||||||
|
|
||||||
|
if (rc < 0)
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* Standard R828D dongle*/
|
||||||
|
{
|
||||||
/* switch between 'Cable1' and 'Air-In' inputs on sticks with
|
/* switch between 'Cable1' and 'Air-In' inputs on sticks with
|
||||||
* R828D tuner. We switch at 345 MHz, because that's where the
|
* R828D tuner. We switch at 345 MHz, because that's where the
|
||||||
* noise-floor has about the same level with identical LNA
|
* noise-floor has about the same level with identical LNA
|
||||||
@ -1120,6 +1182,7 @@ int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq)
|
|||||||
priv->input = air_cable1_in;
|
priv->input = air_cable1_in;
|
||||||
rc = r82xx_write_reg_mask(priv, 0x05, air_cable1_in, 0x60);
|
rc = r82xx_write_reg_mask(priv, 0x05, air_cable1_in, 0x60);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user