diff --git a/firmware/application/apps/ui_debug.cpp b/firmware/application/apps/ui_debug.cpp index b907663d..b9467eb4 100644 --- a/firmware/application/apps/ui_debug.cpp +++ b/firmware/application/apps/ui_debug.cpp @@ -381,10 +381,54 @@ DebugMenuView::DebugMenuView(NavigationView& nav) { {"Peripherals", ui::Color::dark_cyan(), &bitmap_icon_peripherals, [&nav]() { nav.push(); }}, {"Temperature", ui::Color::dark_cyan(), &bitmap_icon_temperature, [&nav]() { nav.push(); }}, {"Buttons Test", ui::Color::dark_cyan(), &bitmap_icon_controls, [&nav]() { nav.push(); }}, + {"Pmem", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { nav.push(); }}, }); set_max_rows(2); // allow wider buttons } +/* DebugPmemView *********************************************************/ + +DebugPmemView::DebugPmemView(NavigationView& nav) + : data{*reinterpret_cast(memory::map::backup_ram.base())}, registers_widget(RegistersWidgetConfig{page_size, 8}, std::bind(&DebugPmemView::registers_widget_feed, this, std::placeholders::_1)) { + static_assert(sizeof(pmem_data) == memory::map::backup_ram.size()); + + add_children({&text_page, ®isters_widget, &text_checksum, &button_ok}); + + registers_widget.set_parent_rect({0, 32, 240, 192}); + + text_checksum.set("Size: " + to_string_dec_uint(portapack::persistent_memory::data_size()) + " CRC: " + to_string_hex(data.check_value, 8)); + + button_ok.on_select = [&nav](Button&) { + nav.pop(); + }; + + update(); +} + +bool DebugPmemView::on_encoder(const EncoderEvent delta) { + page = std::max(0l, std::min((int32_t)page_max, page + delta)); + + update(); + + return true; +} + +void DebugPmemView::focus() { + button_ok.focus(); +} + +void DebugPmemView::update() { + text_page.set(to_string_hex(page_size * page, 2) + "+"); + registers_widget.update(); +} + +uint32_t DebugPmemView::registers_widget_feed(const size_t register_number) { + if (page_size * page + register_number >= memory::map::backup_ram.size()) { + return 0xff; + } + return data.regfile[(page_size * page + register_number) / 4] >> (register_number % 4 * 8); +} + /*DebugLCRView::DebugLCRView(NavigationView& nav, std::string lcr_string) { std::string debug_text; diff --git a/firmware/application/apps/ui_debug.hpp b/firmware/application/apps/ui_debug.hpp index b2a593b6..31158d6c 100644 --- a/firmware/application/apps/ui_debug.hpp +++ b/firmware/application/apps/ui_debug.hpp @@ -30,6 +30,7 @@ #include "rffc507x.hpp" #include "portapack.hpp" +#include "memory_map.hpp" #include #include @@ -263,6 +264,41 @@ class DebugControlsView : public View { "Done"}; }; +class DebugPmemView : public View { + public: + DebugPmemView(NavigationView& nav); + void focus() override; + bool on_encoder(const EncoderEvent delta) override; + std::string title() const override { return "Pmem"; } + + private: + struct pmem_data { + uint32_t regfile[63]; + uint32_t check_value; + }; + + static constexpr uint8_t page_size{96}; // Must be multiply of 4 otherwise bit shifting for register view wont work properly + static constexpr uint8_t page_max{(portapack::memory::map::backup_ram.size() + page_size - 1) / page_size - 1}; + + int32_t page{0}; + + const pmem_data& data; + + Text text_page{{16, 16, 208, 16}}; + + RegistersWidget registers_widget; + + Text text_checksum{{16, 240, 208, 16}}; + + Button button_ok{ + {240 / 3, 270, 240 / 3, 24}, + "OK", + }; + + void update(); + uint32_t registers_widget_feed(const size_t register_number); +}; + /*class DebugLCRView : public View { public: DebugLCRView(NavigationView& nav, std::string lcrstring); diff --git a/firmware/common/portapack_persistent_memory.cpp b/firmware/common/portapack_persistent_memory.cpp index bbff5c5c..ca5e5b08 100644 --- a/firmware/common/portapack_persistent_memory.cpp +++ b/firmware/common/portapack_persistent_memory.cpp @@ -867,5 +867,9 @@ int load_persistent_settings_from_file() { return false; } +size_t data_size() { + return sizeof(data_t); +} + } /* namespace persistent_memory */ } /* namespace portapack */ diff --git a/firmware/common/portapack_persistent_memory.hpp b/firmware/common/portapack_persistent_memory.hpp index 653025e3..d1eb3990 100644 --- a/firmware/common/portapack_persistent_memory.hpp +++ b/firmware/common/portapack_persistent_memory.hpp @@ -257,6 +257,8 @@ bool should_use_sdcard_for_pmem(); int save_persistent_settings_to_file(); int load_persistent_settings_from_file(); +size_t data_size(); + } /* namespace persistent_memory */ } /* namespace portapack */