From 7e8bb3e0b2ff5bb7dcc9a1b7f1a01d79620c7849 Mon Sep 17 00:00:00 2001 From: hayati ayguen Date: Sun, 12 Nov 2023 03:23:10 +0100 Subject: [PATCH] fix verbose_list_gains() in rtl_test and e4000_set_bw() applied_bw Signed-off-by: hayati ayguen --- include/tuner_e4k.h | 2 +- src/convenience/rtl_convenience.c | 2 +- src/librtlsdr.c | 17 ++++++++++++----- src/tuner_e4k.c | 23 ++++++++++++++++------- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/include/tuner_e4k.h b/include/tuner_e4k.h index 36f6aa19..87c4f459 100644 --- a/include/tuner_e4k.h +++ b/include/tuner_e4k.h @@ -208,7 +208,7 @@ int e4k_tune_params(struct e4k_state *e4k, struct e4k_pll_params *p); uint32_t e4k_compute_pll_params(struct e4k_pll_params *oscp, uint32_t fosc, uint32_t intended_flo); int e4k_if_filter_bw_get(struct e4k_state *e4k, enum e4k_if_filter filter); int e4k_if_filter_bw_set(struct e4k_state *e4k, enum e4k_if_filter filter, - uint32_t bandwidth); + uint32_t bandwidth, int apply, uint32_t *applied_bw); int e4k_if_filter_chan_enable(struct e4k_state *e4k, int on); int e4k_rf_filter_set(struct e4k_state *e4k); diff --git a/src/convenience/rtl_convenience.c b/src/convenience/rtl_convenience.c index c7927b29..c409a368 100644 --- a/src/convenience/rtl_convenience.c +++ b/src/convenience/rtl_convenience.c @@ -90,7 +90,7 @@ void verbose_list_bandwidths(rtlsdr_dev_t *dev) int r; uint32_t in_bw, out_bw, last_bw = 0; fprintf(stderr, "Supported bandwidth values in kHz: "); - for ( in_bw = 1; in_bw < 3200; ++in_bw ) + for ( in_bw = 1; in_bw < 5500; ++in_bw ) { r = rtlsdr_set_and_get_tuner_bandwidth(dev, in_bw*1000, &out_bw, 0 /* =apply_bw */); if ( r == 0 && out_bw != 0 && ( out_bw != last_bw || in_bw == 1 ) ) diff --git a/src/librtlsdr.c b/src/librtlsdr.c index 906c1364..7ffaa26e 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -315,13 +315,20 @@ int e4000_set_freq(void *dev, uint32_t freq) { int e4000_set_bw(void *dev, int bw, uint32_t *applied_bw, int apply) { int r = 0; + uint32_t abw, abw_min = (uint32_t)-1; rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev; - if(!apply) - return 0; - r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_MIX, bw); - r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_RC, bw); - r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_CHAN, bw); + r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_MIX, bw, apply, &abw); + abw_min = (abw < abw_min) ? abw : abw_min; + + r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_RC, bw, apply, &abw); + abw_min = (abw < abw_min) ? abw : abw_min; + + r |= e4k_if_filter_bw_set(&devt->e4k_s, E4K_IF_FILTER_CHAN, bw, apply, &abw); + abw_min = (abw < abw_min) ? abw : abw_min; + + if (applied_bw) + *applied_bw = abw_min; return r; } diff --git a/src/tuner_e4k.c b/src/tuner_e4k.c index 35be253e..d5814ec9 100644 --- a/src/tuner_e4k.c +++ b/src/tuner_e4k.c @@ -277,23 +277,29 @@ static const struct reg_field if_filter_fields[] = { } }; -static int find_if_bw(enum e4k_if_filter filter, uint32_t bw) +static int find_if_bw(enum e4k_if_filter filter, uint32_t bw, uint32_t *applied_bw) { + int idx; if (filter >= ARRAY_SIZE(if_filter_bw)) return -EINVAL; - return closest_arr_idx(if_filter_bw[filter], + idx = closest_arr_idx(if_filter_bw[filter], if_filter_bw_len[filter], bw); + if (applied_bw) + *applied_bw = if_filter_bw[filter][idx]; + return idx; } /*! \brief Set the filter band-width of any of the IF filters * \param[in] e4k reference to the tuner chip * \param[in] filter filter to be configured * \param[in] bandwidth bandwidth to be configured + * \param[in] apply flag (0/1), if bandwidth should be applied - or just get applied_bw + * \param[out] effectıvely configured bandwidth * \returns positive actual filter band-width, negative in case of error */ int e4k_if_filter_bw_set(struct e4k_state *e4k, enum e4k_if_filter filter, - uint32_t bandwidth) + uint32_t bandwidth, int apply, uint32_t *applied_bw) { int bw_idx; const struct reg_field *field; @@ -301,7 +307,10 @@ int e4k_if_filter_bw_set(struct e4k_state *e4k, enum e4k_if_filter filter, if (filter >= ARRAY_SIZE(if_filter_bw)) return -EINVAL; - bw_idx = find_if_bw(filter, bandwidth); + bw_idx = find_if_bw(filter, bandwidth, applied_bw); + + if (!apply) + return 0; field = &if_filter_fields[filter]; @@ -991,9 +1000,9 @@ int e4k_init(struct e4k_state *e4k) e4k_if_gain_set(e4k, 6, 9); /* Set the most narrow filter we can possibly use */ - e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_MIX, KHZ(1900)); - e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_RC, KHZ(1000)); - e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_CHAN, KHZ(2150)); + e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_MIX, KHZ(1900), 1, NULL); + e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_RC, KHZ(1000), 1, NULL); + e4k_if_filter_bw_set(e4k, E4K_IF_FILTER_CHAN, KHZ(2150), 1, NULL); e4k_if_filter_chan_enable(e4k, 1); /* Disable time variant DC correction and LUT */