Conversation
Co-authored-by: tkj666 <28040169+tkj666@users.noreply.github.com>
Co-authored-by: tkj666 <28040169+tkj666@users.noreply.github.com>
|
@copilot 1. _xtal_check is used, remove underscore; 2. set_freq needs extra operations for r828d, see https://github.com/osmocom/rtl-sdr/blob/619ac3186ea0ffc092615e1f59f7397e5e6f668c/src/tuner_r82xx.c#L1124 |
Co-authored-by: tkj666 <28040169+tkj666@users.noreply.github.com>
Fixed the underscore issue - renamed For the R828D set_freq extra operations, I cannot access the osmocom reference link directly. Could you please specify what additional operations R828D needs in the set_freq function? Looking at the current implementation, it calls set_mux() and set_pll() but the TODO indicates R828D needs extra steps. |
|
@copilot following is the complete function from osmocom. modify set_freq accordingly. int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq)
{
int rc = -1;
int is_rtlsdr_blog_v4;
uint32_t upconvert_freq;
uint32_t lo_freq;
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);
if (rc < 0)
goto err;
rc = r82xx_set_pll(priv, lo_freq);
if (rc < 0 || !priv->has_lock)
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;
/* Control upconverter GPIO switch on newer batches */
rc = rtlsdr_set_bias_tee_gpio(priv->rtl_dev, 5, !cable_2_in);
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
* R828D tuner. We switch at 345 MHz, because that's where the
* noise-floor has about the same level with identical LNA
* settings. The original driver used 320 MHz. */
air_cable1_in = (freq > MHZ(345)) ? 0x00 : 0x60;
if ((priv->cfg->rafael_chip == CHIP_R828D) &&
(air_cable1_in != priv->input)) {
priv->input = air_cable1_in;
rc = r82xx_write_reg_mask(priv, 0x05, air_cable1_in, 0x60);
}
}
err:
if (rc < 0)
fprintf(stderr, "%s: failed=%d\n", __FUNCTION__, rc);
return rc;
} |
Co-authored-by: tkj666 <28040169+tkj666@users.noreply.github.com>
... Implemented the complete set_freq function according to the osmocom specification you provided. Added RTL-SDR Blog V4 detection, automatic upconversion for frequencies < 28.8 MHz, and notch filter control. The implementation includes PLL lock verification and maintains full backward compatibility. All tests pass (15/15). Commit f259c64. |
|
@copilot 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;
}where manufact and product can be retrieved by rusb::DeviceHandle::read_manufacturer_string_ascii and rusb::DeviceHandle::read_product_string_ascii. |
Co-authored-by: tkj666 <28040169+tkj666@users.noreply.github.com>
... Implemented rtlsdr_check_dongle_model using USB string descriptors instead of vendor/product IDs. The implementation now uses rusb::DeviceHandle::read_manufacturer_string_ascii and rusb::DeviceHandle::read_product_string_ascii to read device strings, matching the osmocom specification exactly. All tests pass (15/15). Commit 1ea5fd4. |
|
@copilot |
…ice struct Co-authored-by: tkj666 <28040169+tkj666@users.noreply.github.com>
Modified Device struct to store manufacturer and product strings instead of vendor_id/product_id. Updated DeviceHandle to read USB string descriptors during device opening and return them to Device. Enhanced check_dongle_model to use stored strings for efficient comparison. All tests pass (15/15). Commit b0e17b8. |
|
@copilot |
…ceHandle::open Co-authored-by: tkj666 <28040169+tkj666@users.noreply.github.com>
Modified DeviceHandle::open to return only DeviceHandle instead of manufacturer/product strings. The strings are now acquired after opening the device handle in Device::new using the existing read_manufacturer_string() and read_product_string() methods. This better separates concerns between DeviceHandle and Device. All tests pass (15/15). Commit 099e7d8. |
This PR implements comprehensive R828D tuner support according to the osmocom/rtl-sdr library specifications, while maintaining full backward compatibility with existing R820T functionality. Additionally, it adds specialized support for RTL-SDR Blog V4 devices with automatic frequency management and notch filter control.
Problem
The library only supported R820T tuners, but many RTL-SDR devices use the R828D variant. The existing code had TODOs indicating awareness of R828D but no actual implementation:
Additionally, the
set_freqfunction lacked the extra operations required for R828D devices, particularly for RTL-SDR Blog V4 dongles which need automatic upconversion and notch filter management.Solution
Implemented a unified R82xx architecture that supports both R820T and R828D variants with automatic differentiation based on tuner detection. The approach follows the osmocom/rtl-sdr library pattern of treating both as R82xx family tuners with variant-specific behaviors.
Unified R82xx Architecture
R82xxVariantenum to differentiate between R820T and R828DR828D-Specific Features
xtal_check()during initialization, R820T does notEnhanced set_freq Implementation
Following the complete osmocom
r82xx_set_freqfunction specification:rusb::DeviceHandle::read_manufacturer_string_asciiandrusb::DeviceHandle::read_product_string_asciiAPI Enhancements
Device Detection
Updated device model detection to use USB string descriptors instead of EEPROM data, following the osmocom
rtlsdr_check_dongle_modelimplementation that compares manufacturer and product strings from USB device descriptors.Testing
Compatibility
This implementation provides complete R828D support with advanced RTL-SDR Blog V4 features while maintaining exact compatibility with the reference C library and preserving all existing functionality.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.