diff --git a/firmware/application/max2837.cpp b/firmware/application/max2837.cpp index bf040a8f..ca446a0e 100644 --- a/firmware/application/max2837.cpp +++ b/firmware/application/max2837.cpp @@ -251,4 +251,8 @@ reg_t MAX2837::temp_sense() { return value; } +RegisterMap MAX2837::registers() { + return _map; +} + } diff --git a/firmware/application/max2837.hpp b/firmware/application/max2837.hpp index e3e8ce9b..6f21b34e 100644 --- a/firmware/application/max2837.hpp +++ b/firmware/application/max2837.hpp @@ -880,6 +880,8 @@ public: reg_t temp_sense(); + RegisterMap registers(); + private: spi::arbiter::Target& _target; diff --git a/firmware/application/radio.cpp b/firmware/application/radio.cpp index dcb6bfa7..dbb29eac 100644 --- a/firmware/application/radio.cpp +++ b/firmware/application/radio.cpp @@ -22,7 +22,6 @@ #include "radio.hpp" #include "rf_path.hpp" -#include "max2837.hpp" #include "max5864.hpp" #include "baseband_cpld.hpp" #include "baseband_sgpio.hpp" @@ -88,7 +87,7 @@ static spi::arbiter::Target ssp1_target_max5864 { static rf::path::Path rf_path; rffc507x::RFFC507x first_if; -static max2837::MAX2837 second_if { ssp1_target_max2837 }; +max2837::MAX2837 second_if { ssp1_target_max2837 }; static max5864::MAX5864 baseband_codec { ssp1_target_max5864 }; static baseband::CPLD baseband_cpld; static baseband::SGPIO baseband_sgpio; diff --git a/firmware/application/radio.hpp b/firmware/application/radio.hpp index 442968aa..c796963d 100644 --- a/firmware/application/radio.hpp +++ b/firmware/application/radio.hpp @@ -28,6 +28,7 @@ #include #include "rffc507x.hpp" +#include "max2837.hpp" namespace radio { @@ -47,6 +48,7 @@ void streaming_disable(); void disable(); extern rffc507x::RFFC507x first_if; +extern max2837::MAX2837 second_if; } /* namespace radio */ diff --git a/firmware/application/ui_debug.cpp b/firmware/application/ui_debug.cpp index a46e9c84..8e81d6bf 100644 --- a/firmware/application/ui_debug.cpp +++ b/firmware/application/ui_debug.cpp @@ -55,6 +55,53 @@ void DebugMemoryView::focus() { button_done.focus(); } +void DebugMAX2837RegistersWidget::update() { + set_dirty(); +} + +void DebugMAX2837RegistersWidget::paint(Painter& painter) { + draw_legend(painter); + + const auto registers = radio::second_if.registers(); + draw_values(painter, registers); +} + +void DebugMAX2837RegistersWidget::draw_legend(Painter& painter) { + for(size_t i=0; i((i / registers_per_row) * row_height) + }; + + const auto text = to_string_hex(i, legend_length); + painter.draw_string( + screen_pos() + offset, + style(), + text + ); + } +} + +void DebugMAX2837RegistersWidget::draw_values( + Painter& painter, + const max2837::RegisterMap registers +) { + for(size_t i=0; i(legend_width + 8 + (i % registers_per_row) * (value_width + 8)), + static_cast((i / registers_per_row) * row_height) + }; + + const uint16_t value = registers.w[i]; + + const auto text = to_string_hex(value, value_length); + painter.draw_string( + screen_pos() + offset, + style(), + text + ); + } +} + void DebugRFFC5072RegistersWidget::update() { set_dirty(); } @@ -109,7 +156,7 @@ DebugMenuView::DebugMenuView(NavigationView& nav) { { "Radio State", [&nav](){ nav.push(new NotImplementedView { nav }); } }, { "SD Card", [&nav](){ nav.push(new NotImplementedView { nav }); } }, { "RFFC5072", [&nav](){ nav.push(new DebugRFFC5072View { nav }); } }, - { "MAX2837", [&nav](){ nav.push(new NotImplementedView { nav }); } }, + { "MAX2837", [&nav](){ nav.push(new DebugMAX2837View { nav }); } }, { "Si5351C", [&nav](){ nav.push(new NotImplementedView { nav }); } }, { "WM8731", [&nav](){ nav.push(new NotImplementedView { nav }); } }, } }); diff --git a/firmware/application/ui_debug.hpp b/firmware/application/ui_debug.hpp index babab07e..ccba0f26 100644 --- a/firmware/application/ui_debug.hpp +++ b/firmware/application/ui_debug.hpp @@ -29,6 +29,7 @@ #include "ui_navigation.hpp" #include "rffc507x.hpp" +#include "max2837.hpp" namespace ui { @@ -117,6 +118,40 @@ private: void draw_values(Painter& painter, const rffc507x::RegisterMap registers); }; +class DebugMAX2837RegistersWidget : public Widget { +public: + constexpr DebugMAX2837RegistersWidget( + Rect parent_rect + ) : Widget { parent_rect } + { + } + + void update(); + + void paint(Painter& painter) override; + + static constexpr const char* const name = "MAX2837"; + +private: + static constexpr size_t registers_count = 32; + + static constexpr size_t legend_length = 2; + static constexpr Dim legend_width = legend_length * 8; + + static constexpr size_t value_length = 3; + static constexpr Dim value_width = value_length * 8; + + static constexpr size_t registers_per_row = 4; + static constexpr size_t registers_row_length = (registers_per_row * (value_length + 1)) - 1; + static constexpr Dim registers_row_width = registers_row_length * 8; + + static constexpr size_t rows = registers_count / registers_per_row; + static constexpr Dim row_height = 16; + + void draw_legend(Painter& painter); + void draw_values(Painter& painter, const max2837::RegisterMap registers); +}; + template class RegistersView : public View { public: @@ -160,6 +195,7 @@ private: }; using DebugRFFC5072View = RegistersView; +using DebugMAX2837View = RegistersView; class DebugMenuView : public MenuView { public: