diff --git a/firmware/application/CMakeLists.txt b/firmware/application/CMakeLists.txt index 1b144c28..faa3140b 100644 --- a/firmware/application/CMakeLists.txt +++ b/firmware/application/CMakeLists.txt @@ -174,7 +174,7 @@ set(CPPSRC ui_record_view.cpp ui_rssi.cpp ui_sd_card_status_view.cpp - ui_sd_card_debug.cpp + # ui_sd_card_debug.cpp ui_setup.cpp ui_soundboard.cpp ui_spectrum.cpp diff --git a/firmware/application/Makefile b/firmware/application/Makefile index 853f5ee1..09da00dd 100644 --- a/firmware/application/Makefile +++ b/firmware/application/Makefile @@ -4811,33 +4811,6 @@ ui_rssi.cpp.s: cd /home/furrtek/portapack-hackrf && $(MAKE) -f firmware/application/CMakeFiles/application.elf.dir/build.make firmware/application/CMakeFiles/application.elf.dir/ui_rssi.cpp.s .PHONY : ui_rssi.cpp.s -ui_sd_card_debug.obj: ui_sd_card_debug.cpp.obj - -.PHONY : ui_sd_card_debug.obj - -# target to build an object file -ui_sd_card_debug.cpp.obj: - cd /home/furrtek/portapack-hackrf && $(MAKE) -f firmware/application/CMakeFiles/application.elf.dir/build.make firmware/application/CMakeFiles/application.elf.dir/ui_sd_card_debug.cpp.obj -.PHONY : ui_sd_card_debug.cpp.obj - -ui_sd_card_debug.i: ui_sd_card_debug.cpp.i - -.PHONY : ui_sd_card_debug.i - -# target to preprocess a source file -ui_sd_card_debug.cpp.i: - cd /home/furrtek/portapack-hackrf && $(MAKE) -f firmware/application/CMakeFiles/application.elf.dir/build.make firmware/application/CMakeFiles/application.elf.dir/ui_sd_card_debug.cpp.i -.PHONY : ui_sd_card_debug.cpp.i - -ui_sd_card_debug.s: ui_sd_card_debug.cpp.s - -.PHONY : ui_sd_card_debug.s - -# target to generate assembly for a file -ui_sd_card_debug.cpp.s: - cd /home/furrtek/portapack-hackrf && $(MAKE) -f firmware/application/CMakeFiles/application.elf.dir/build.make firmware/application/CMakeFiles/application.elf.dir/ui_sd_card_debug.cpp.s -.PHONY : ui_sd_card_debug.cpp.s - ui_sd_card_status_view.obj: ui_sd_card_status_view.cpp.obj .PHONY : ui_sd_card_status_view.obj @@ -5610,9 +5583,6 @@ help: @echo "... ui_rssi.obj" @echo "... ui_rssi.i" @echo "... ui_rssi.s" - @echo "... ui_sd_card_debug.obj" - @echo "... ui_sd_card_debug.i" - @echo "... ui_sd_card_debug.s" @echo "... ui_sd_card_status_view.obj" @echo "... ui_sd_card_status_view.i" @echo "... ui_sd_card_status_view.s" diff --git a/firmware/application/freqman.cpp b/firmware/application/freqman.cpp index 8d5bfd19..1774e193 100644 --- a/firmware/application/freqman.cpp +++ b/firmware/application/freqman.cpp @@ -74,8 +74,7 @@ bool save_freqman_file(std::vector &frequencies) { size_t n; std::string item_string; - auto result = freqs_file.create("freqman.txt"); - if (result.is_valid()) return false; + if (!create_freqman_file(freqs_file)) return false; for (n = 0; n < frequencies.size(); n++) { item_string = "f=" + to_string_dec_uint(frequencies[n].value); @@ -89,6 +88,13 @@ bool save_freqman_file(std::vector &frequencies) { return true; } +bool create_freqman_file(File &freqs_file) { + auto result = freqs_file.create("freqman.txt"); + if (result.is_valid()) return false; + + return true; +} + std::string freqman_item_string(freqman_entry &entry) { std::string item_string, frequency_str, description; char temp_buffer[32]; diff --git a/firmware/application/freqman.hpp b/firmware/application/freqman.hpp index 6523b3af..157f9c1e 100644 --- a/firmware/application/freqman.hpp +++ b/firmware/application/freqman.hpp @@ -39,6 +39,7 @@ struct freqman_entry { bool load_freqman_file(std::vector &frequencies); bool save_freqman_file(std::vector &frequencies); +bool create_freqman_file(File &freqs_file); std::string freqman_item_string(freqman_entry &frequencies); #endif/*__FREQMAN_H__*/ diff --git a/firmware/application/main.cpp b/firmware/application/main.cpp index e14348d6..47f5fcbc 100755 --- a/firmware/application/main.cpp +++ b/firmware/application/main.cpp @@ -26,7 +26,7 @@ //TEST: Imperial in whipcalc //TEST: Numbers //TEST: Jammer -//TEST: Frequency manager + save/load +//TODO: Frequency manager auto-remove duplicates //TODO: "TX box" view or composite widget with frequency and bw settings, simple and advanced setup TX buttons... //TODO: Morse coder for foxhunts @@ -57,7 +57,6 @@ //TODO: CTCSS detector //TODO: DMR detector -//TODO: SD card wiper //TODO: GSM channel detector //TODO: SIGFOX RX/TX //TODO: Bodet :) diff --git a/firmware/application/sd_card.cpp b/firmware/application/sd_card.cpp index ed2a90b2..78e3da0f 100644 --- a/firmware/application/sd_card.cpp +++ b/firmware/application/sd_card.cpp @@ -27,14 +27,14 @@ namespace sd_card { +FATFS fs; + namespace { bool card_present = false; Status status_ { Status::NotPresent }; -FATFS fs; - FRESULT mount() { return f_mount(&fs, "", 0); } diff --git a/firmware/application/sd_card.hpp b/firmware/application/sd_card.hpp index 1989f465..8fbbc7ae 100644 --- a/firmware/application/sd_card.hpp +++ b/firmware/application/sd_card.hpp @@ -24,9 +24,12 @@ #include +#include "ff.h" #include "signal.hpp" namespace sd_card { + +extern FATFS fs; enum class Status : int32_t { IOError = -3, diff --git a/firmware/application/ui_debug.cpp b/firmware/application/ui_debug.cpp index 4dd1c189..0c937419 100644 --- a/firmware/application/ui_debug.cpp +++ b/firmware/application/ui_debug.cpp @@ -28,7 +28,7 @@ #include "audio.hpp" -#include "ui_sd_card_debug.hpp" +// #include "ui_sd_card_debug.hpp" namespace ui { @@ -271,10 +271,10 @@ DebugPeripheralsMenuView::DebugPeripheralsMenuView(NavigationView& nav) { /* DebugMenuView *********************************************************/ DebugMenuView::DebugMenuView(NavigationView& nav) { - add_items<5>({ { + add_items<4>({ { { "Memory", ui::Color::white(), nullptr, [&nav](){ nav.push(); } }, { "Radio State", ui::Color::white(), nullptr, [&nav](){ nav.push(); } }, - { "SD Card", ui::Color::white(), nullptr, [&nav](){ nav.push(); } }, + //{ "SD Card", ui::Color::white(), nullptr, [&nav](){ nav.push(); } }, { "Peripherals", ui::Color::white(), nullptr, [&nav](){ nav.push(); } }, { "Temperature", ui::Color::white(), nullptr, [&nav](){ nav.push(); } }, } }); diff --git a/firmware/application/ui_freqman.cpp b/firmware/application/ui_freqman.cpp index 3a8d1eda..8bc3b7e1 100644 --- a/firmware/application/ui_freqman.cpp +++ b/firmware/application/ui_freqman.cpp @@ -65,7 +65,11 @@ FrequencySaveView::FrequencySaveView( ) : nav_ (nav), value_ (value) { - error = !load_freqman_file(frequencies); + File freqs_file; + + if (!load_freqman_file(frequencies)) { + if (!create_freqman_file(freqs_file)) error = true; + } signal_token_tick_second = time::signal_tick_second += [this]() { this->on_tick_second(); diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index b2e75941..c76e7d4c 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -317,10 +317,11 @@ TransmitterAudioMenuView::TransmitterAudioMenuView(NavigationView& nav) { /* UtilitiesView *****************************************************************/ UtilitiesView::UtilitiesView(NavigationView& nav) { - add_items<3>({ { - { "Frequency manager", ui::Color::red(), nullptr, [&nav](){ nav.push(); } }, - { "Whip antenna length", ui::Color::green(), nullptr, [&nav](){ nav.push(); } }, + add_items<4>({ { + { "Frequency manager", ui::Color::green(), nullptr, [&nav](){ nav.push(); } }, + { "Whip antenna length", ui::Color::yellow(),nullptr, [&nav](){ nav.push(); } }, { "Notepad", ui::Color::grey(), nullptr, [&nav](){ nav.push(); } }, + { "Wipe SD card", ui::Color::red(), nullptr, [&nav](){ nav.push(); } }, } }); on_left = [&nav](){ nav.pop(); }; } @@ -348,7 +349,7 @@ SystemMenuView::SystemMenuView(NavigationView& nav) { { "Utilities", ui::Color::purple(),nullptr, [&nav](){ nav.push(); } }, //{ "Analyze", ui::Color::white(), [&nav](){ nav.push(); } }, { "Setup", ui::Color::white(), nullptr, [&nav](){ nav.push(); } }, - //{ "Debug", ui::Color::white(), [&nav](){ nav.push(); } }, + //{ "Debug", ui::Color::white(), nullptr, [&nav](){ nav.push(); } }, { "HackRF mode", ui::Color::white(), &bitmap_icon_hackrf, [this, &nav](){ hackrf_mode(nav); } }, { "About", ui::Color::white(), nullptr, [&nav](){ nav.push(); } } } }); @@ -433,6 +434,45 @@ void BMPView::paint(Painter&) { portapack::display.drawBMP({(240 - 185) / 2, 0}, splash_bmp, false); } +/* WipeSDView ************************************************************/ + +WipeSDView::WipeSDView(NavigationView& nav) : nav_ (nav) { + add_children({ { + &text_info, + &progress, + &dummy + } }); +} + +WipeSDView::~WipeSDView() { + if (thread) chThdTerminate(thread); +} + +Thread* WipeSDView::thread { nullptr }; + +void WipeSDView::focus() { + BlockDeviceInfo block_device_info; + + dummy.focus(); + + if (!confirmed) { + nav_.push("Warning !", "Wipe first 32MB of SD card ?", YESCANCEL, [this](bool choice) { + if (choice) + confirmed = true; + } + ); + } else { + if (sdcGetInfo(&SDCD1, &block_device_info) == CH_SUCCESS) { + blocks = 32; // Only erase first 32MB (block_device_info.blk_size * uint64_t(block_device_info.blk_num)) / (1024 * 1024); + progress.set_max(blocks); + + thread = chThdCreateFromHeap(NULL, 2048, NORMALPRIO + 10, WipeSDView::static_fn, this); + } else { + nav_.pop(); // Just silently abort for now + } + } +} + /* PlayDeadView **********************************************************/ void PlayDeadView::focus() { @@ -450,6 +490,8 @@ void PlayDeadView::paint(Painter& painter) { } PlayDeadView::PlayDeadView(NavigationView& nav) { + rtc::RTC datetime; + portapack::persistent_memory::set_playing_dead(0x5920C1DF); // Enable add_children({ { @@ -459,6 +501,10 @@ PlayDeadView::PlayDeadView(NavigationView& nav) { &button_seq_entry, } }); + // Seed from RTC + rtcGetTime(&RTCD1, &datetime); + text_playdead2.set("0x" + to_string_hex(lfsr_iterate(datetime.second()), 6) + "00"); + text_playdead3.hidden(true); button_seq_entry.on_dir = [this](Button&, KeyEvent key){ @@ -532,7 +578,21 @@ ModalMessageView::ModalMessageView( if (on_choice_) on_choice_(false); nav.pop(); }; - } else { + } else if (type == YESCANCEL) { + add_children({ { + &button_yes, + &button_no + } }); + + button_yes.on_select = [this, &nav](Button&){ + if (on_choice_) on_choice_(true); + nav.pop(); + }; + button_no.on_select = [this, &nav](Button&){ + //if (on_choice_) on_choice_(false); + nav.pop_modal(); + }; + } else { // ABORT add_child(&button_ok); button_ok.on_select = [this, &nav](Button&){ @@ -554,7 +614,7 @@ void ModalMessageView::paint(Painter&) { } void ModalMessageView::focus() { - if (type_ == YESNO) { + if ((type_ == YESNO) || (type_ == YESCANCEL)) { button_yes.focus(); } else { button_ok.focus(); diff --git a/firmware/application/ui_navigation.hpp b/firmware/application/ui_navigation.hpp index f942eeb4..0e5a07d9 100644 --- a/firmware/application/ui_navigation.hpp +++ b/firmware/application/ui_navigation.hpp @@ -34,15 +34,22 @@ #include "ui_sd_card_status_view.hpp" #include "bitmap.hpp" +#include "ff.h" +#include "diskio.h" +#include "lfsr_random.hpp" +#include "sd_card.hpp" #include #include +using namespace sd_card; + namespace ui { enum modal_t { INFO = 0, YESNO, + YESCANCEL, ABORT }; @@ -167,6 +174,62 @@ private: }; }; +class WipeSDView : public View { +public: + WipeSDView(NavigationView& nav); + ~WipeSDView(); + void focus() override; + + std::string title() const override { return "SD card wipe"; }; + +private: + NavigationView& nav_; + + bool confirmed = false; + uint32_t blocks; + static Thread* thread; + + static msg_t static_fn(void* arg) { + auto obj = static_cast(arg); + obj->run(); + return 0; + } + + void run() { + uint32_t n, b; + lfsr_word_t v = 1; + const auto buffer = std::make_unique>(); + + for (b = 0; b < blocks; b++) { + progress.set_value(b); + + lfsr_fill(v, + reinterpret_cast(buffer->data()), + sizeof(*buffer.get()) / sizeof(lfsr_word_t)); + + // 1MB + for (n = 0; n < 64; n++) { + if (disk_write(sd_card::fs.drv, buffer->data(), n + (b * 64), 16384 / 512) != RES_OK) nav_.pop(); + } + } + nav_.pop(); + } + + Text text_info { + { 10 * 8, 16 * 8, 10 * 8, 16 }, + "Working..." + }; + + ProgressBar progress { + { 2 * 8, 19 * 8, 26 * 8, 24 } + }; + + Button dummy { + { 240, 0, 0, 0 }, + "" + }; +}; + class PlayDeadView : public View { public: PlayDeadView(NavigationView& nav); @@ -179,11 +242,11 @@ private: Text text_playdead1 { { 6 * 8, 7 * 16, 14 * 8, 16 }, - "Firmware error" + "\x46irmwa" "re " "er\x72o\x72" }; Text text_playdead2 { { 6 * 8, 9 * 16, 16 * 8, 16 }, - "0x1400_0000 : 2C" + "" }; Text text_playdead3 { { 6 * 8, 12 * 16, 16 * 8, 16 }, diff --git a/firmware/application/ui_nuoptix.cpp b/firmware/application/ui_nuoptix.cpp index 119d8cd8..0f44e3a6 100644 --- a/firmware/application/ui_nuoptix.cpp +++ b/firmware/application/ui_nuoptix.cpp @@ -53,6 +53,7 @@ void NuoptixView::transmit(bool setup) { uint8_t mod, tone_code; uint8_t c; uint8_t dtmf_message[6]; + rtc::RTC datetime; if (!tx_mode) { transmitter_model.disable(); diff --git a/firmware/application/ui_nuoptix.hpp b/firmware/application/ui_nuoptix.hpp index 6afe5462..c496094b 100644 --- a/firmware/application/ui_nuoptix.hpp +++ b/firmware/application/ui_nuoptix.hpp @@ -90,7 +90,6 @@ private: void transmit(bool setup); uint32_t timecode; - rtc::RTC datetime; FrequencyField field_frequency { { 1 * 8, 4 }, diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index c934e738..c791f097 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -459,7 +459,7 @@ void ProgressBar::set_value(const uint32_t value) { } void ProgressBar::paint(Painter& painter) { - uint16_t v_sized; + uint32_t v_sized; const auto rect = screen_rect(); const auto s = style(); diff --git a/graphics/PP_ADSB.png b/firmware/graphics/PP_ADSB.png similarity index 100% rename from graphics/PP_ADSB.png rename to firmware/graphics/PP_ADSB.png diff --git a/graphics/PP_AIS.png b/firmware/graphics/PP_AIS.png similarity index 100% rename from graphics/PP_AIS.png rename to firmware/graphics/PP_AIS.png diff --git a/graphics/PP_AUDIOTX.png b/firmware/graphics/PP_AUDIOTX.png similarity index 100% rename from graphics/PP_AUDIOTX.png rename to firmware/graphics/PP_AUDIOTX.png diff --git a/graphics/PP_BHT.png b/firmware/graphics/PP_BHT.png similarity index 100% rename from graphics/PP_BHT.png rename to firmware/graphics/PP_BHT.png diff --git a/graphics/PP_CAPTURE.png b/firmware/graphics/PP_CAPTURE.png similarity index 100% rename from graphics/PP_CAPTURE.png rename to firmware/graphics/PP_CAPTURE.png diff --git a/graphics/PP_CLOSECALL.png b/firmware/graphics/PP_CLOSECALL.png similarity index 100% rename from graphics/PP_CLOSECALL.png rename to firmware/graphics/PP_CLOSECALL.png diff --git a/graphics/PP_CODETX.png b/firmware/graphics/PP_CODETX.png similarity index 100% rename from graphics/PP_CODETX.png rename to firmware/graphics/PP_CODETX.png diff --git a/graphics/PP_ERT.png b/firmware/graphics/PP_ERT.png similarity index 100% rename from graphics/PP_ERT.png rename to firmware/graphics/PP_ERT.png diff --git a/graphics/PP_FOXHUNT.png b/firmware/graphics/PP_FOXHUNT.png similarity index 100% rename from graphics/PP_FOXHUNT.png rename to firmware/graphics/PP_FOXHUNT.png diff --git a/graphics/PP_HACKRF.png b/firmware/graphics/PP_HACKRF.png similarity index 100% rename from graphics/PP_HACKRF.png rename to firmware/graphics/PP_HACKRF.png diff --git a/graphics/PP_JAMMER.png b/firmware/graphics/PP_JAMMER.png similarity index 100% rename from graphics/PP_JAMMER.png rename to firmware/graphics/PP_JAMMER.png diff --git a/graphics/PP_LCR.png b/firmware/graphics/PP_LCR.png similarity index 100% rename from graphics/PP_LCR.png rename to firmware/graphics/PP_LCR.png diff --git a/graphics/PP_MICROPHONE.png b/firmware/graphics/PP_MICROPHONE.png similarity index 100% rename from graphics/PP_MICROPHONE.png rename to firmware/graphics/PP_MICROPHONE.png diff --git a/graphics/PP_MORSE.png b/firmware/graphics/PP_MORSE.png similarity index 100% rename from graphics/PP_MORSE.png rename to firmware/graphics/PP_MORSE.png diff --git a/graphics/PP_NORDIC.png b/firmware/graphics/PP_NORDIC.png similarity index 100% rename from graphics/PP_NORDIC.png rename to firmware/graphics/PP_NORDIC.png diff --git a/graphics/PP_NUMBERS.png b/firmware/graphics/PP_NUMBERS.png similarity index 100% rename from graphics/PP_NUMBERS.png rename to firmware/graphics/PP_NUMBERS.png diff --git a/graphics/PP_NUOPTIX.png b/firmware/graphics/PP_NUOPTIX.png similarity index 100% rename from graphics/PP_NUOPTIX.png rename to firmware/graphics/PP_NUOPTIX.png diff --git a/graphics/PP_PLAYDEAD.png b/firmware/graphics/PP_PLAYDEAD.png similarity index 100% rename from graphics/PP_PLAYDEAD.png rename to firmware/graphics/PP_PLAYDEAD.png diff --git a/graphics/PP_RDS.png b/firmware/graphics/PP_RDS.png similarity index 100% rename from graphics/PP_RDS.png rename to firmware/graphics/PP_RDS.png diff --git a/graphics/PP_RECEIVER.png b/firmware/graphics/PP_RECEIVER.png similarity index 100% rename from graphics/PP_RECEIVER.png rename to firmware/graphics/PP_RECEIVER.png diff --git a/graphics/PP_REMOTE.png b/firmware/graphics/PP_REMOTE.png similarity index 100% rename from graphics/PP_REMOTE.png rename to firmware/graphics/PP_REMOTE.png diff --git a/graphics/PP_SOUNDBOARD.png b/firmware/graphics/PP_SOUNDBOARD.png similarity index 100% rename from graphics/PP_SOUNDBOARD.png rename to firmware/graphics/PP_SOUNDBOARD.png diff --git a/graphics/PP_TPMS.png b/firmware/graphics/PP_TPMS.png similarity index 100% rename from graphics/PP_TPMS.png rename to firmware/graphics/PP_TPMS.png diff --git a/graphics/PP_WHISTLE.png b/firmware/graphics/PP_WHISTLE.png similarity index 100% rename from graphics/PP_WHISTLE.png rename to firmware/graphics/PP_WHISTLE.png diff --git a/firmware/application/bitmaps/bulb_ignore.bmp b/firmware/graphics/bulb_ignore.bmp similarity index 100% rename from firmware/application/bitmaps/bulb_ignore.bmp rename to firmware/graphics/bulb_ignore.bmp diff --git a/firmware/application/bitmaps/bulb_off.bmp b/firmware/graphics/bulb_off.bmp similarity index 100% rename from firmware/application/bitmaps/bulb_off.bmp rename to firmware/graphics/bulb_off.bmp diff --git a/firmware/application/bitmaps/bulb_on.bmp b/firmware/graphics/bulb_on.bmp similarity index 100% rename from firmware/application/bitmaps/bulb_on.bmp rename to firmware/graphics/bulb_on.bmp diff --git a/firmware/application/bitmaps/fox.bmp b/firmware/graphics/fox.bmp similarity index 100% rename from firmware/application/bitmaps/fox.bmp rename to firmware/graphics/fox.bmp diff --git a/firmware/application/bitmaps/splash.bmp b/firmware/graphics/havoc_splash.bmp old mode 100644 new mode 100755 similarity index 100% rename from firmware/application/bitmaps/splash.bmp rename to firmware/graphics/havoc_splash.bmp diff --git a/firmware/application/bitmaps/modal_warning.bmp b/firmware/graphics/modal_warning.bmp similarity index 100% rename from firmware/application/bitmaps/modal_warning.bmp rename to firmware/graphics/modal_warning.bmp diff --git a/firmware/graphics/splash.bmp b/firmware/graphics/splash.bmp new file mode 100644 index 00000000..be597b16 Binary files /dev/null and b/firmware/graphics/splash.bmp differ diff --git a/firmware/portapack-h1-havoc.bin b/firmware/portapack-h1-havoc.bin index 26295fb4..136c127b 100644 Binary files a/firmware/portapack-h1-havoc.bin and b/firmware/portapack-h1-havoc.bin differ