diff --git a/firmware/application/external/external.cmake b/firmware/application/external/external.cmake index be87d0374..cb919f43d 100644 --- a/firmware/application/external/external.cmake +++ b/firmware/application/external/external.cmake @@ -192,6 +192,10 @@ set(EXTCPPSRC external/doom/main.cpp external/doom/ui_doom.cpp + #scanner + external/scanner/main.cpp + external/scanner/ui_scanner.cpp + #debug_pmem external/debug_pmem/main.cpp external/debug_pmem/ui_debug_pmem.cpp @@ -246,4 +250,5 @@ set(EXTAPPLIST breakout doom debug_pmem + scanner ) diff --git a/firmware/application/external/external.ld b/firmware/application/external/external.ld index c782f9898..7c4152613 100644 --- a/firmware/application/external/external.ld +++ b/firmware/application/external/external.ld @@ -70,6 +70,7 @@ MEMORY ram_external_app_breakout (rwx) : org = 0xADDD0000, len = 32k ram_external_app_doom (rwx) : org = 0xADDE0000, len = 32k ram_external_app_debug_pmem (rwx) : org = 0xADDF0000, len = 32k + ram_external_app_scanner (rwx) : org = 0xADE00000, len = 32k } SECTIONS @@ -354,4 +355,11 @@ SECTIONS KEEP(*(.external_app.app_debug_pmem.application_information)); *(*ui*external_app*debug_pmem*); } > ram_external_app_debug_pmem + + .external_app_scanner : ALIGN(4) SUBALIGN(4) + { + KEEP(*(.external_app.app_scanner.application_information)); + *(*ui*external_app*scanner*); + } > ram_external_app_scanner + } diff --git a/firmware/application/external/scanner/main.cpp b/firmware/application/external/scanner/main.cpp new file mode 100644 index 000000000..20596a216 --- /dev/null +++ b/firmware/application/external/scanner/main.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2023 Bernd Herzog + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "ui.hpp" +#include "ui_scanner.hpp" +#include "ui_navigation.hpp" +#include "external_app.hpp" + +namespace ui::external_app::scanner { +void initialize_app(ui::NavigationView& nav) { + nav.push(); +} +} // namespace ui::external_app::scanner + +extern "C" { + +__attribute__((section(".external_app.app_scanner.application_information"), used)) application_information_t _application_information_scanner = { + /*.memory_location = */ (uint8_t*)0x00000000, + /*.externalAppEntry = */ ui::external_app::scanner::initialize_app, + /*.header_version = */ CURRENT_HEADER_VERSION, + /*.app_version = */ VERSION_MD5, + + /*.app_name = */ "Scanner", + /*.bitmap_data = */ {0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x03, 0x01, 0x80, 0x01, 0xC3, 0x00, 0xE0, 0xFF, 0xEF, 0xFF, 0xC0, 0x00, 0x83, 0x01, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00}, + /*.icon_color = */ ui::Color::green().v, + /*.menu_location = */ app_location_t::RX, + /*.desired_menu_position = */ -1, + + // this has to be the biggest baseband used by the app. Scanner is using AM,WFM,NFM and NFM is the biggest + /*.m4_app_tag = portapack::spi_flash::image_tag_scanner */ {'P', 'N', 'F', 'M'}, + /*.m4_app_offset = */ 0x00000000, // will be filled at compile time +}; +} diff --git a/firmware/application/apps/ui_scanner.cpp b/firmware/application/external/scanner/ui_scanner.cpp similarity index 99% rename from firmware/application/apps/ui_scanner.cpp rename to firmware/application/external/scanner/ui_scanner.cpp index 7c5ea1266..65cb9341a 100644 --- a/firmware/application/apps/ui_scanner.cpp +++ b/firmware/application/external/scanner/ui_scanner.cpp @@ -28,10 +28,11 @@ #include "ui_freqman.hpp" #include "file_path.hpp" +using namespace ui; using namespace portapack; namespace fs = std::filesystem; -namespace ui { +namespace ui::external_app::scanner { ScannerThread::ScannerThread(std::vector frequency_list) : frequency_list_{std::move(frequency_list)} { @@ -451,13 +452,14 @@ ScannerView::ScannerView( // Mode field was changed (AM/NFM/WFM) field_mode.on_change = [this](size_t, OptionsField::value_t v) { - static freqman_index_t last_mode = AM_MODULATION; + // initialize to a value under SPEC + static freqman_index_t last_mode = WFM_MODULATION; // unsupported SPEC mode fix if (v == SPEC_MODULATION) { - if (last_mode == AM_MODULATION) - v = WFM_MODULATION; + if (last_mode == WFM_MODULATION) + v = AMFM_MODULATION; else - v = AM_MODULATION; + v = WFM_MODULATION; field_mode.set_selected_index(v); } last_mode = v; @@ -773,5 +775,4 @@ void ScannerView::restart_scan() { start_scan_thread(); // RESTART SCANNER THREAD in selected mode } - -} /* namespace ui */ +} // namespace ui::external_app::scanner diff --git a/firmware/application/apps/ui_scanner.hpp b/firmware/application/external/scanner/ui_scanner.hpp similarity index 98% rename from firmware/application/apps/ui_scanner.hpp rename to firmware/application/external/scanner/ui_scanner.hpp index 4ba52bc45..588f62010 100644 --- a/firmware/application/apps/ui_scanner.hpp +++ b/firmware/application/external/scanner/ui_scanner.hpp @@ -35,12 +35,14 @@ #include "ui_mictx.hpp" #include "ui_receiver.hpp" +using namespace ui; + +namespace ui::external_app::scanner { + #define SCANNER_SLEEP_MS 50 // ms that Scanner Thread sleeps per loop #define STATISTICS_UPDATES_PER_SEC 10 #define MAX_FREQ_LOCK 10 // # of 50ms cycles scanner locks into freq when signal detected, to verify signal is not spurious -namespace ui { - // TODO: There is too much duplicated data in these classes. // ScannerThread should just use more from the View. // Or perhaps ScannerThread should just be in the View. @@ -314,5 +316,4 @@ class ScannerView : public View { this->on_statistics_update(static_cast(p)->statistics); }}; }; - -} /* namespace ui */ +} // namespace ui::external_app::scanner