From 650d299c99ac320d02cd81354f7ac669b4d473b5 Mon Sep 17 00:00:00 2001 From: Kyle Reed <3761006+kallanreed@users.noreply.github.com> Date: Sat, 17 Jun 2023 07:54:52 -0700 Subject: [PATCH] Don't update radio directly when saving/restoring tx/rx model settings. (#1160) * Set rf direction in RadioState * centralize cpld load for TX->RX * Remove calls to load_sram from all apps * re-add CPLD hack, don't set radio values directly. --------- Co-authored-by: kallanreed --- firmware/application/app_settings.cpp | 8 ++-- firmware/application/apps/capture_app.cpp | 40 +++++++----------- firmware/application/apps/capture_app.hpp | 42 ++++++++++--------- firmware/application/apps/gps_sim_app.cpp | 4 +- firmware/application/apps/lge_app.cpp | 4 +- firmware/application/apps/replay_app.cpp | 5 +-- firmware/application/apps/soundboard_app.cpp | 4 +- firmware/application/apps/ui_adsb_tx.cpp | 4 +- firmware/application/apps/ui_aprs_tx.cpp | 4 +- firmware/application/apps/ui_bht_tx.cpp | 4 +- firmware/application/apps/ui_coasterp.cpp | 4 +- firmware/application/apps/ui_encoders.cpp | 4 +- firmware/application/apps/ui_jammer.cpp | 4 +- firmware/application/apps/ui_keyfob.cpp | 4 +- firmware/application/apps/ui_lcr.cpp | 4 +- firmware/application/apps/ui_mictx.cpp | 5 +-- firmware/application/apps/ui_morse.cpp | 4 +- firmware/application/apps/ui_pocsag_tx.cpp | 4 +- firmware/application/apps/ui_rds.cpp | 4 +- .../application/apps/ui_spectrum_painter.cpp | 2 - firmware/application/apps/ui_sstvtx.cpp | 4 +- firmware/application/apps/ui_touchtunes.cpp | 4 +- firmware/application/radio.cpp | 17 ++++---- firmware/application/radio_state.hpp | 10 ++--- firmware/application/receiver_model.cpp | 19 ++++++--- firmware/application/receiver_model.hpp | 17 +++++--- firmware/application/transmitter_model.cpp | 7 ++++ firmware/application/transmitter_model.hpp | 5 +++ firmware/common/cpld_update.cpp | 8 ++-- firmware/common/cpld_update.hpp | 2 +- 30 files changed, 114 insertions(+), 137 deletions(-) diff --git a/firmware/application/app_settings.cpp b/firmware/application/app_settings.cpp index 9439cb8d..dc0c8dd7 100644 --- a/firmware/application/app_settings.cpp +++ b/firmware/application/app_settings.cpp @@ -94,8 +94,6 @@ constexpr std::string_view volume = "volume="sv; // TODO: Maybe just use a dictionary which would allow for custom settings. // TODO: Create a control value binding which will allow controls to // be declaratively bound to a setting and persistence will be magic. -// TODO: radio settings should be pushed and popped to prevent cross-app -// radio bugs caused by sharing a global model. ResultCode load_settings(const std::string& app_name, AppSettings& settings) { if (!portapack::persistent_memory::load_app_settings()) @@ -178,17 +176,17 @@ void copy_to_radio_model(const AppSettings& settings) { if (flags_enabled(settings.mode, Mode::TX)) { if (!flags_enabled(settings.options, Options::UseGlobalTargetFrequency)) - transmitter_model.set_target_frequency(settings.tx_frequency); + persistent_memory::set_target_frequency(settings.tx_frequency); transmitter_model.configure_from_app_settings(settings); } if (flags_enabled(settings.mode, Mode::RX)) { if (!flags_enabled(settings.options, Options::UseGlobalTargetFrequency)) - transmitter_model.set_target_frequency(settings.rx_frequency); + persistent_memory::set_target_frequency(settings.rx_frequency); receiver_model.configure_from_app_settings(settings); - receiver_model.set_configuration_without_init( + receiver_model.set_configuration_without_update( static_cast(settings.modulation), settings.step, settings.am_config_index, diff --git a/firmware/application/apps/capture_app.cpp b/firmware/application/apps/capture_app.cpp index f2267c39..20846326 100644 --- a/firmware/application/apps/capture_app.cpp +++ b/firmware/application/apps/capture_app.cpp @@ -21,10 +21,9 @@ */ #include "capture_app.hpp" - #include "baseband_api.hpp" - #include "portapack.hpp" + using namespace portapack; namespace ui { @@ -49,13 +48,12 @@ CaptureAppView::CaptureAppView(NavigationView& nav) { field_frequency.set_value(receiver_model.target_frequency()); field_frequency.set_step(receiver_model.frequency_step()); field_frequency.on_change = [this](rf::Frequency f) { - this->on_target_frequency_changed(f); + receiver_model.set_target_frequency(f); }; field_frequency.on_edit = [this, &nav]() { // TODO: Provide separate modal method/scheme? auto new_view = nav.push(receiver_model.target_frequency()); new_view->on_changed = [this](rf::Frequency f) { - this->on_target_frequency_changed(f); this->field_frequency.set_value(f); }; }; @@ -68,15 +66,12 @@ CaptureAppView::CaptureAppView(NavigationView& nav) { option_bandwidth.on_change = [this](size_t, uint32_t base_rate) { sampling_rate = 8 * base_rate; // Decimation by 8 done on baseband side - /* base_rate is used for FFT calculation and display LCD, and also in recording writing SD Card rate. */ - /* ex. sampling_rate values, 4Mhz, when recording 500 kHz (BW) and fs 8 Mhz , when selected 1 Mhz BW ...*/ - /* ex. recording 500kHz BW to .C16 file, base_rate clock 500kHz x2(I,Q) x 2 bytes (int signed) =2MB/sec rate SD Card */ - + /* base_rate is used for FFT calculation and display LCD, and also in recording writing SD Card rate. */ + /* ex. sampling_rate values, 4Mhz, when recording 500 kHz (BW) and fs 8 Mhz, when selected 1 Mhz BW ... */ + /* ex. recording 500kHz BW to .C16 file, base_rate clock 500kHz x2(I,Q) x 2 bytes (int signed) =2MB/sec rate SD Card */ waterfall.on_hide(); - record_view.set_sampling_rate(sampling_rate); - receiver_model.set_sampling_rate(sampling_rate); - /* Set up proper anti aliasing BPF bandwith in MAX2837 before ADC sampling according to the new added BW Options . */ + /* Set up proper anti aliasing BPF bandwith in MAX2837 before ADC sampling according to the new added BW Options . */ switch (sampling_rate) { // we use the var fs (sampling_rate) , to set up BPF aprox < fs_max/2 by Nyquist theorem. case 0 ... 2000000: // BW Captured range (0 <= 250kHz max ) fs = 8 x 250 kHz @@ -93,30 +88,33 @@ CaptureAppView::CaptureAppView(NavigationView& nav) { break; case 14000000: // BW capture 1,75Mhz , fs = 8 x 1,75Mhz = 14Mhz - // good BPF ,good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture + // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture anti_alias_baseband_bandwidth_filter = 5000000; break; case 16000000: // BW capture 2Mhz , fs = 8 x 2Mhz = 16Mhz - // good BPF ,good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture + // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture anti_alias_baseband_bandwidth_filter = 6000000; break; case 20000000: // BW capture 2,5Mhz , fs= 8 x 2,5 Mhz = 20Mhz - // good BPF ,good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture + // good BPF, good matching, but LCD making flicker , refresh rate should be < 20 Hz , but reasonable picture anti_alias_baseband_bandwidth_filter = 7000000; break; - default: // BW capture 2,75Mhz, fs = 8 x 2,75Mhz= 22Mhz max ADC sampling) and others. - // We tested also 9Mhz FPB stightly too much noise floor , better 8Mhz + default: // BW capture 2,75Mhz, fs = 8 x 2,75Mhz= 22Mhz max ADC sampling) and others. + // We tested also 9Mhz FPB stightly too much noise floor, better 8Mhz anti_alias_baseband_bandwidth_filter = 8000000; } + + record_view.set_sampling_rate(sampling_rate); + receiver_model.set_sampling_rate(sampling_rate); receiver_model.set_baseband_bandwidth(anti_alias_baseband_bandwidth_filter); waterfall.on_show(); }; - option_bandwidth.set_selected_index(7); // 500k, Preselected starting default option 500kHz + option_bandwidth.set_selected_index(7); // Preselected default option 500kHz. receiver_model.set_modulation(ReceiverModel::Mode::Capture); receiver_model.enable(); @@ -132,8 +130,6 @@ CaptureAppView::~CaptureAppView() { } void CaptureAppView::on_hide() { - // TODO: Terrible kludge because widget system doesn't notify Waterfall that - // it's being shown or hidden. waterfall.on_hide(); View::on_hide(); } @@ -141,7 +137,7 @@ void CaptureAppView::on_hide() { void CaptureAppView::set_parent_rect(const Rect new_parent_rect) { View::set_parent_rect(new_parent_rect); - const ui::Rect waterfall_rect{0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height}; + ui::Rect waterfall_rect{0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height}; waterfall.set_parent_rect(waterfall_rect); } @@ -149,8 +145,4 @@ void CaptureAppView::focus() { record_view.focus(); } -void CaptureAppView::on_target_frequency_changed(rf::Frequency f) { - receiver_model.set_target_frequency(f); -} - } /* namespace ui */ diff --git a/firmware/application/apps/capture_app.hpp b/firmware/application/apps/capture_app.hpp index 63ed85be..6eeeac85 100644 --- a/firmware/application/apps/capture_app.hpp +++ b/firmware/application/apps/capture_app.hpp @@ -28,24 +28,25 @@ #include "ui_receiver.hpp" #include "ui_record_view.hpp" #include "ui_spectrum.hpp" +#include "app_settings.hpp" #include "radio_state.hpp" -#define BW_OPTIONS \ - {" 8k5", 8500}, \ - {" 11k", 11000}, \ - {" 16k", 16000}, \ - {" 25k", 25000}, \ - {" 50k", 50000}, \ - {" 100k", 100000}, \ - {" 250k", 250000}, \ - {" 500k", 500000}, /* Previous Limit bandwith Option with perfect micro SD write .C16 format operaton.*/ \ - {" 600k", 600000}, /* That extended option is still possible to record with FW version Mayhem v1.41 (< 2,5MB/sec) */ \ - {" 750k", 750000}, /* From that BW onwards, the LCD is ok, but the recorded file is auto decimated,(not real file size) */ \ - {"1100k", 1100000}, \ - {"1750k", 1750000}, \ - {"2000k", 2000000}, \ - {"2500k", 2500000}, \ - {"2750k", 2750000}, // That is our max Capture option , to keep using later / 8 decimation (22Mhz sampling ADC) +#define BW_OPTIONS \ + {" 8k5", 8500}, \ + {" 11k", 11000}, \ + {" 16k", 16000}, \ + {" 25k", 25000}, \ + {" 50k", 50000}, \ + {" 100k", 100000}, \ + {" 250k", 250000}, \ + {" 500k", 500000}, /* Previous Limit bandwith Option with perfect micro SD write .C16 format operaton.*/ \ + {" 600k", 600000}, /* That extended option is still possible to record with FW version Mayhem v1.41 (< 2,5MB/sec) */ \ + {" 750k", 750000}, /* From this BW onwards, the LCD is ok, but the recorded file is decimated, (not real file size) */ \ + {"1100k", 1100000}, \ + {"1750k", 1750000}, \ + {"2000k", 2000000}, \ + {"2500k", 2500000}, \ + {"2750k", 2750000}, // That is our max Capture option, to keep using later / 8 decimation (22Mhz sampling ADC) namespace ui { @@ -55,10 +56,8 @@ class CaptureAppView : public View { ~CaptureAppView(); void on_hide() override; - - void set_parent_rect(const Rect new_parent_rect) override; - void focus() override; + void set_parent_rect(const Rect new_parent_rect) override; std::string title() const override { return "Capture"; }; @@ -66,9 +65,12 @@ class CaptureAppView : public View { static constexpr ui::Dim header_height = 3 * 16; RxRadioState radio_state_{}; + app_settings::SettingsManager settings_{ + "rx_capture", app_settings::Mode::RX, + app_settings::Options::UseGlobalTargetFrequency}; uint32_t sampling_rate = 0; - uint32_t anti_alias_baseband_bandwidth_filter = 2500000; // we rename the previous var , and change type static constexpr to normal var. + uint32_t anti_alias_baseband_bandwidth_filter = 2500000; void on_target_frequency_changed(rf::Frequency f); diff --git a/firmware/application/apps/gps_sim_app.cpp b/firmware/application/apps/gps_sim_app.cpp index 59c0bdd8..089f7a22 100644 --- a/firmware/application/apps/gps_sim_app.cpp +++ b/firmware/application/apps/gps_sim_app.cpp @@ -29,7 +29,6 @@ #include "baseband_api.hpp" #include "portapack.hpp" -#include "cpld_update.hpp" #include "portapack_persistent_memory.hpp" using namespace portapack; @@ -214,8 +213,7 @@ GpsSimAppView::GpsSimAppView( GpsSimAppView::~GpsSimAppView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit . - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void GpsSimAppView::on_hide() { diff --git a/firmware/application/apps/lge_app.cpp b/firmware/application/apps/lge_app.cpp index 12ef5c94..9754f83c 100644 --- a/firmware/application/apps/lge_app.cpp +++ b/firmware/application/apps/lge_app.cpp @@ -27,7 +27,6 @@ #include "lge_app.hpp" #include "baseband_api.hpp" -#include "cpld_update.hpp" #include "ui_textentry.hpp" #include "string_format.hpp" @@ -45,8 +44,7 @@ void LGEView::focus() { LGEView::~LGEView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit . - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void LGEView::generate_lge_frame(const uint8_t command, const uint16_t address_a, const uint16_t address_b, std::vector& data) { diff --git a/firmware/application/apps/replay_app.cpp b/firmware/application/apps/replay_app.cpp index fd77d72f..2202f88b 100644 --- a/firmware/application/apps/replay_app.cpp +++ b/firmware/application/apps/replay_app.cpp @@ -26,7 +26,6 @@ #include "ui_fileman.hpp" #include "io_file.hpp" -#include "cpld_update.hpp" #include "baseband_api.hpp" #include "portapack.hpp" #include "portapack_persistent_memory.hpp" @@ -226,9 +225,7 @@ ReplayAppView::~ReplayAppView() { display.fill_rectangle({0, 0, 240, 320}, Color::black()); // Solving sometimes visible bottom waterfall artifacts, clearing all LCD pixels. chThdSleepMilliseconds(40); // (that happened sometimes if we interrupt the waterfall play at the beggining of the play around 25% and exit ) - hackrf::cpld::load_sram_no_verify(); // to leave all RX reception ok, without "ghost interference signal problem" at the exit . - - baseband::shutdown(); // better this function at the end, after load_sram(). If not , sometimes produced hang up (now not , it is ok). + baseband::shutdown(); } void ReplayAppView::on_hide() { diff --git a/firmware/application/apps/soundboard_app.cpp b/firmware/application/apps/soundboard_app.cpp index 7c3386fa..b5f50c83 100644 --- a/firmware/application/apps/soundboard_app.cpp +++ b/firmware/application/apps/soundboard_app.cpp @@ -25,7 +25,6 @@ #include "soundboard_app.hpp" #include "string_format.hpp" #include "tonesets.hpp" -#include "cpld_update.hpp" using namespace tonekey; using namespace portapack; @@ -275,8 +274,7 @@ SoundBoardView::SoundBoardView( SoundBoardView::~SoundBoardView() { stop(); transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit. - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } } // namespace ui diff --git a/firmware/application/apps/ui_adsb_tx.cpp b/firmware/application/apps/ui_adsb_tx.cpp index 65282869..40758145 100644 --- a/firmware/application/apps/ui_adsb_tx.cpp +++ b/firmware/application/apps/ui_adsb_tx.cpp @@ -26,7 +26,6 @@ #include "manchester.hpp" #include "string_format.hpp" #include "portapack.hpp" -#include "cpld_update.hpp" #include "baseband_api.hpp" #include @@ -274,8 +273,7 @@ void ADSBTxView::focus() { ADSBTxView::~ADSBTxView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, withouth ghost signal problem at the exit. - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void ADSBTxView::generate_frames() { diff --git a/firmware/application/apps/ui_aprs_tx.cpp b/firmware/application/apps/ui_aprs_tx.cpp index 2e9a5cc3..339ce22a 100644 --- a/firmware/application/apps/ui_aprs_tx.cpp +++ b/firmware/application/apps/ui_aprs_tx.cpp @@ -26,7 +26,6 @@ #include "aprs.hpp" #include "string_format.hpp" #include "portapack.hpp" -#include "cpld_update.hpp" #include "baseband_api.hpp" #include "portapack_shared_memory.hpp" #include "portapack_persistent_memory.hpp" @@ -45,8 +44,7 @@ void APRSTXView::focus() { APRSTXView::~APRSTXView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit. - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void APRSTXView::start_tx() { diff --git a/firmware/application/apps/ui_bht_tx.cpp b/firmware/application/apps/ui_bht_tx.cpp index e8c61856..f830f767 100644 --- a/firmware/application/apps/ui_bht_tx.cpp +++ b/firmware/application/apps/ui_bht_tx.cpp @@ -24,7 +24,6 @@ #include "string_format.hpp" #include "baseband_api.hpp" -#include "cpld_update.hpp" #include "portapack_persistent_memory.hpp" using namespace portapack; @@ -138,8 +137,7 @@ void BHTView::on_tx_progress(const uint32_t progress, const bool done) { BHTView::~BHTView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit . - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } BHTView::BHTView(NavigationView& nav) { diff --git a/firmware/application/apps/ui_coasterp.cpp b/firmware/application/apps/ui_coasterp.cpp index 403f0d76..25a51c83 100644 --- a/firmware/application/apps/ui_coasterp.cpp +++ b/firmware/application/apps/ui_coasterp.cpp @@ -23,7 +23,6 @@ #include "ui_coasterp.hpp" #include "baseband_api.hpp" -#include "cpld_update.hpp" #include "portapack_persistent_memory.hpp" #include @@ -39,8 +38,7 @@ void CoasterPagerView::focus() { CoasterPagerView::~CoasterPagerView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit . - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void CoasterPagerView::generate_frame() { diff --git a/firmware/application/apps/ui_encoders.cpp b/firmware/application/apps/ui_encoders.cpp index 74103ad5..2857aa1d 100644 --- a/firmware/application/apps/ui_encoders.cpp +++ b/firmware/application/apps/ui_encoders.cpp @@ -24,7 +24,6 @@ #include "baseband_api.hpp" #include "string_format.hpp" -#include "cpld_update.hpp" using namespace portapack; @@ -201,8 +200,7 @@ void EncodersView::focus() { EncodersView::~EncodersView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // ghost signal c/m to the problem at the exit . - baseband::shutdown(); // better this function after load_sram() + baseband::shutdown(); } void EncodersView::update_progress() { diff --git a/firmware/application/apps/ui_jammer.cpp b/firmware/application/apps/ui_jammer.cpp index 1f1a6fae..36fe9171 100644 --- a/firmware/application/apps/ui_jammer.cpp +++ b/firmware/application/apps/ui_jammer.cpp @@ -25,7 +25,6 @@ #include "ui_freqman.hpp" #include "baseband_api.hpp" -#include "cpld_update.hpp" #include "string_format.hpp" using namespace portapack; @@ -180,8 +179,7 @@ void JammerView::focus() { JammerView::~JammerView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit . - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void JammerView::on_retune(const rf::Frequency freq, const uint32_t range) { diff --git a/firmware/application/apps/ui_keyfob.cpp b/firmware/application/apps/ui_keyfob.cpp index db0f7261..98e1bc70 100644 --- a/firmware/application/apps/ui_keyfob.cpp +++ b/firmware/application/apps/ui_keyfob.cpp @@ -23,7 +23,6 @@ #include "ui_keyfob.hpp" #include "baseband_api.hpp" -#include "cpld_update.hpp" #include "string_format.hpp" using namespace portapack; @@ -141,8 +140,7 @@ KeyfobView::~KeyfobView() { settings.save("tx_keyfob", &app_settings); transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit . - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void KeyfobView::update_progress(const uint32_t progress) { diff --git a/firmware/application/apps/ui_lcr.cpp b/firmware/application/apps/ui_lcr.cpp index 94256fc1..ef49d5ff 100644 --- a/firmware/application/apps/ui_lcr.cpp +++ b/firmware/application/apps/ui_lcr.cpp @@ -26,7 +26,6 @@ #include "lcr.hpp" #include "baseband_api.hpp" #include "string_format.hpp" -#include "cpld_update.hpp" #include "serializer.hpp" @@ -40,8 +39,7 @@ void LCRView::focus() { LCRView::~LCRView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit. - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } /* diff --git a/firmware/application/apps/ui_mictx.cpp b/firmware/application/apps/ui_mictx.cpp index 07e6b819..7dedbbdd 100644 --- a/firmware/application/apps/ui_mictx.cpp +++ b/firmware/application/apps/ui_mictx.cpp @@ -30,7 +30,6 @@ using wolfson::wm8731::WM8731; #include "tonesets.hpp" #include "portapack_hal.hpp" -#include "cpld_update.hpp" #include "string_format.hpp" #include "irq_controls.hpp" @@ -172,7 +171,6 @@ void MicTXView::rxaudio(bool is_on) { receiver_model.set_vga(rx_vga); receiver_model.set_rf_amp(rx_amp); receiver_model.enable(); - hackrf::cpld::load_sram_no_verify(); // to have a good RX without any ghost inside Mic App audio::output::start(); } else { // These incredibly convoluted steps are required for the vumeter to reappear when stopping RX. receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio); // This fixes something with AM RX... @@ -609,8 +607,7 @@ MicTXView::~MicTXView() { transmitter_model.disable(); if (rx_enabled) // Also turn off audio rx if enabled rxaudio(false); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit . - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } } // namespace ui diff --git a/firmware/application/apps/ui_morse.cpp b/firmware/application/apps/ui_morse.cpp index a05b91f0..82ddfe67 100644 --- a/firmware/application/apps/ui_morse.cpp +++ b/firmware/application/apps/ui_morse.cpp @@ -26,7 +26,6 @@ #include "baseband_api.hpp" #include "hackrf_gpio.hpp" #include "portapack_shared_memory.hpp" -#include "cpld_update.hpp" #include "ui_textentry.hpp" #include "string_format.hpp" @@ -99,8 +98,7 @@ void MorseView::focus() { MorseView::~MorseView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit . - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void MorseView::paint(Painter&) { diff --git a/firmware/application/apps/ui_pocsag_tx.cpp b/firmware/application/apps/ui_pocsag_tx.cpp index efa2d0f6..69f7cbd2 100644 --- a/firmware/application/apps/ui_pocsag_tx.cpp +++ b/firmware/application/apps/ui_pocsag_tx.cpp @@ -23,7 +23,6 @@ #include "ui_pocsag_tx.hpp" #include "baseband_api.hpp" -#include "cpld_update.hpp" #include "string_format.hpp" #include "ui_textentry.hpp" @@ -40,8 +39,7 @@ void POCSAGTXView::focus() { POCSAGTXView::~POCSAGTXView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void POCSAGTXView::on_tx_progress(const uint32_t progress, const bool done) { diff --git a/firmware/application/apps/ui_rds.cpp b/firmware/application/apps/ui_rds.cpp index 7a813ef9..ee63099a 100644 --- a/firmware/application/apps/ui_rds.cpp +++ b/firmware/application/apps/ui_rds.cpp @@ -24,7 +24,6 @@ #include "portapack.hpp" #include "baseband_api.hpp" -#include "cpld_update.hpp" #include "portapack_shared_memory.hpp" #include @@ -161,8 +160,7 @@ void RDSView::focus() { RDSView::~RDSView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit. - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void RDSView::start_tx() { diff --git a/firmware/application/apps/ui_spectrum_painter.cpp b/firmware/application/apps/ui_spectrum_painter.cpp index 408fd775..97385d86 100644 --- a/firmware/application/apps/ui_spectrum_painter.cpp +++ b/firmware/application/apps/ui_spectrum_painter.cpp @@ -20,7 +20,6 @@ */ #include "ui_spectrum_painter.hpp" -#include "cpld_update.hpp" #include "bmp.hpp" #include "baseband_api.hpp" @@ -176,7 +175,6 @@ void SpectrumPainterView::frame_sync() { SpectrumPainterView::~SpectrumPainterView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); baseband::shutdown(); } diff --git a/firmware/application/apps/ui_sstvtx.cpp b/firmware/application/apps/ui_sstvtx.cpp index a37ec674..90d1a1d3 100644 --- a/firmware/application/apps/ui_sstvtx.cpp +++ b/firmware/application/apps/ui_sstvtx.cpp @@ -25,7 +25,6 @@ #include "portapack.hpp" #include "hackrf_hal.hpp" -#include "cpld_update.hpp" #include #include @@ -89,8 +88,7 @@ void SSTVTXView::paint(Painter&) { SSTVTXView::~SSTVTXView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit. - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void SSTVTXView::prepare_scanline() { diff --git a/firmware/application/apps/ui_touchtunes.cpp b/firmware/application/apps/ui_touchtunes.cpp index 662ee105..16cf8ebe 100644 --- a/firmware/application/apps/ui_touchtunes.cpp +++ b/firmware/application/apps/ui_touchtunes.cpp @@ -26,7 +26,6 @@ #include "baseband_api.hpp" #include "string_format.hpp" -#include "cpld_update.hpp" using namespace portapack; using namespace encoders; @@ -39,8 +38,7 @@ void TouchTunesView::focus() { TouchTunesView::~TouchTunesView() { transmitter_model.disable(); - hackrf::cpld::load_sram_no_verify(); // to leave all RX ok, without ghost signal problem at the exit. - baseband::shutdown(); // better this function at the end, not load_sram() that sometimes produces hang up. + baseband::shutdown(); } void TouchTunesView::stop_tx() { diff --git a/firmware/application/radio.cpp b/firmware/application/radio.cpp index 0b4a800e..2fc79b99 100644 --- a/firmware/application/radio.cpp +++ b/firmware/application/radio.cpp @@ -92,7 +92,8 @@ max2839::MAX2839 second_if_max2839{ssp1_target_max283x}; static max5864::MAX5864 baseband_codec{ssp1_target_max5864}; static baseband::CPLD baseband_cpld; -static rf::Direction direction{rf::Direction::Receive}; +// Set invalid to force the set_direction CPLD workaround to run. +static rf::Direction direction{-1}; static bool baseband_invert = false; static bool mixer_invert = false; @@ -115,15 +116,15 @@ void set_direction(const rf::Direction new_direction) { /* TODO: Refactor all the various "Direction" enumerations into one. */ /* TODO: Only make changes if direction changes, but beware of clock enabling. */ - // Hack to fix the CPLD (clocking ?) bug: toggle CPLD SRAM overlay depending on new direction + // Hack to fix the CPLD (clocking ?) bug: toggle CPLD SRAM overlay depending on new direction. // Use CPLD's EEPROM config when transmitting // Use the SRAM overlay when receiving - - // teixeluis: undone "Hack to fix the CPLD (clocking ?) bug". - // Apparently with current CPLD code from the hackrf repo, - // toggling CPLD overlay should no longer be necessary: - if (direction != new_direction && new_direction == rf::Direction::Transmit) { - hackrf::cpld::init_from_eeprom(); + if (direction != new_direction) { + if (new_direction == rf::Direction::Transmit) + hackrf::cpld::init_from_eeprom(); + else + // Prevents ghosting when switching back to RX from TX mode. + hackrf::cpld::load_sram_no_verify(); } direction = new_direction; diff --git a/firmware/application/radio_state.hpp b/firmware/application/radio_state.hpp index c47aa114..026cf06b 100644 --- a/firmware/application/radio_state.hpp +++ b/firmware/application/radio_state.hpp @@ -41,13 +41,13 @@ class RadioState { RadioState(uint32_t new_bandwidth, uint32_t new_sampling_rate) : prev_bandwidth_{model->baseband_bandwidth()}, prev_sampling_rate_{model->sampling_rate()} { - model->set_baseband_bandwidth(new_bandwidth); - model->set_sampling_rate(new_sampling_rate); + model->set_configuration_without_update( + new_bandwidth, new_sampling_rate); } ~RadioState() { - model->set_baseband_bandwidth(prev_bandwidth_); - model->set_sampling_rate(prev_sampling_rate_); + model->set_configuration_without_update( + prev_bandwidth_, prev_sampling_rate_); } private: @@ -58,4 +58,4 @@ class RadioState { using RxRadioState = RadioState; using TxRadioState = RadioState; -#endif // __RADIO_STATE_H__ \ No newline at end of file +#endif // __RADIO_STATE_H__ diff --git a/firmware/application/receiver_model.cpp b/firmware/application/receiver_model.cpp index e4559829..675206d8 100644 --- a/firmware/application/receiver_model.cpp +++ b/firmware/application/receiver_model.cpp @@ -248,12 +248,19 @@ void ReceiverModel::set_wfm_configuration(const size_t n) { } } -void ReceiverModel::set_configuration_without_init( - const Mode new_mode, - const rf::Frequency new_frequency_step, - const size_t new_am_config_index, - const size_t new_nbfm_config_index, - const size_t new_wfm_config_index, +void ReceiverModel::set_configuration_without_update( + uint32_t baseband_bandwidth, + uint32_t sampling_rate) { + baseband_bandwidth_ = baseband_bandwidth; + sampling_rate_ = sampling_rate; +} + +void ReceiverModel::set_configuration_without_update( + Mode new_mode, + rf::Frequency new_frequency_step, + size_t new_am_config_index, + size_t new_nbfm_config_index, + size_t new_wfm_config_index, uint8_t new_squelch_level) { mode_ = new_mode; frequency_step_ = new_frequency_step; diff --git a/firmware/application/receiver_model.hpp b/firmware/application/receiver_model.hpp index d3cc19ee..a7262372 100644 --- a/firmware/application/receiver_model.hpp +++ b/firmware/application/receiver_model.hpp @@ -92,12 +92,17 @@ class ReceiverModel { size_t wfm_configuration() const; void set_wfm_configuration(const size_t n); - void set_configuration_without_init( - const Mode new_mode, - const rf::Frequency new_frequency_step, - const size_t new_am_config_index, - const size_t new_nbfm_config_index, - const size_t new_wfm_config_index, + /* Sets the model values without updating the radio. */ + void set_configuration_without_update( + uint32_t baseband_bandwidth, + uint32_t sampling_rate); + + void set_configuration_without_update( + Mode new_mode, + rf::Frequency new_frequency_step, + size_t new_am_config_index, + size_t new_nbfm_config_index, + size_t new_wfm_config_index, uint8_t new_squelch_level); void configure_from_app_settings(const app_settings::AppSettings& settings); diff --git a/firmware/application/transmitter_model.cpp b/firmware/application/transmitter_model.cpp index e626f353..b38ea121 100644 --- a/firmware/application/transmitter_model.cpp +++ b/firmware/application/transmitter_model.cpp @@ -147,6 +147,13 @@ void TransmitterModel::disable() { led_tx.off(); } +void TransmitterModel::set_configuration_without_update( + uint32_t baseband_bandwidth, + uint32_t sampling_rate) { + baseband_bandwidth_ = baseband_bandwidth; + sampling_rate_ = sampling_rate; +} + void TransmitterModel::configure_from_app_settings( const app_settings::AppSettings& settings) { baseband_bandwidth_ = settings.baseband_bandwidth; diff --git a/firmware/application/transmitter_model.hpp b/firmware/application/transmitter_model.hpp index 77b46acc..8718b407 100644 --- a/firmware/application/transmitter_model.hpp +++ b/firmware/application/transmitter_model.hpp @@ -70,6 +70,11 @@ class TransmitterModel { void enable(); void disable(); + /* Sets the model values without updating the radio. */ + void set_configuration_without_update( + uint32_t baseband_bandwidth, + uint32_t sampling_rate); + void configure_from_app_settings(const app_settings::AppSettings& settings); private: diff --git a/firmware/common/cpld_update.cpp b/firmware/common/cpld_update.cpp index ce1fe84e..225754e1 100644 --- a/firmware/common/cpld_update.cpp +++ b/firmware/common/cpld_update.cpp @@ -113,10 +113,10 @@ bool load_sram() { } void load_sram_no_verify() { - // CoolRunner II family has Hybrid memory CPLD arquitecture (SRAM+NVM) - // It seems that after using TX App somehow , I do not why , the CPLD_SRAM part needs to be re_loaded to solve #637 ghost beat - // load_sram() it is already called at each boot in portapack.cpp ,including verify CPLD part. - // Here we skipped CPLD verify part,just to be quicker (in case any CPLD problem it will be detected in the boot process). + // CoolRunner II family has Hybrid memory CPLD architecture (SRAM+NVM) + // It seems that after using a TX App the CPLD_SRAM part needs to be re_loaded to solve #637 ghost beat. + // load_sram() it is already called at each boot in portapack.cpp, including verify CPLD part. + // Here we skipped CPLD verify part, just to be quicker (in case any CPLD problem it will be detected in the boot process). auto jtag_target_hackrf_cpld = jtag_target_hackrf(); hackrf::one::cpld::CPLD hackrf_cpld{jtag_target_hackrf_cpld}; diff --git a/firmware/common/cpld_update.hpp b/firmware/common/cpld_update.hpp index 0d1f6946..a03d3cbd 100644 --- a/firmware/common/cpld_update.hpp +++ b/firmware/common/cpld_update.hpp @@ -44,7 +44,7 @@ namespace hackrf { namespace cpld { bool load_sram(); -void load_sram_no_verify(); // added to solve issue #637 , "ghost" signal at RX , after using any TX App +void load_sram_no_verify(); // Added to solve issue #637, "ghost" signal at RX, after using any TX App. bool verify_eeprom(); void init_from_eeprom();