diff --git a/firmware/application/portapack.cpp b/firmware/application/portapack.cpp index 67ee181f..1491fe6a 100644 --- a/firmware/application/portapack.cpp +++ b/firmware/application/portapack.cpp @@ -27,7 +27,6 @@ #include "hackrf_gpio.hpp" using namespace hackrf::one; -#include "si5351.hpp" #include "clock_manager.hpp" #include "i2c_pp.hpp" diff --git a/firmware/application/portapack.hpp b/firmware/application/portapack.hpp index 939442de..ae424f36 100644 --- a/firmware/application/portapack.hpp +++ b/firmware/application/portapack.hpp @@ -25,6 +25,7 @@ #include "spi_pp.hpp" #include "wm8731.hpp" +#include "si5351.hpp" #include "lcd_ili9341.hpp" #include "radio.hpp" @@ -40,6 +41,8 @@ extern SPI ssp1; extern wolfson::wm8731::WM8731 audio_codec; +extern si5351::Si5351 clock_generator; + extern ReceiverModel receiver_model; void init(); diff --git a/firmware/application/ui_debug.cpp b/firmware/application/ui_debug.cpp index 98d52e91..fd7b9ecd 100644 --- a/firmware/application/ui_debug.cpp +++ b/firmware/application/ui_debug.cpp @@ -155,6 +155,54 @@ void DebugRFFC5072RegistersWidget::draw_values( } } +/* DebugSi5351CRegistersWidget ******************************************/ + +void DebugSi5351CRegistersWidget::update() { + set_dirty(); +} + +void DebugSi5351CRegistersWidget::paint(Painter& painter) { + draw_legend(painter); + + draw_values(painter, portapack::clock_generator); +} + +void DebugSi5351CRegistersWidget::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 DebugSi5351CRegistersWidget::draw_values( + Painter& painter, + si5351::Si5351& device +) { + 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 auto value = device.read_register(i); + + const auto text = to_string_hex(value, value_length); + painter.draw_string( + screen_pos() + offset, + style(), + text + ); + } +} + /* DebugMenuView *********************************************************/ DebugMenuView::DebugMenuView(NavigationView& nav) { @@ -164,7 +212,7 @@ DebugMenuView::DebugMenuView(NavigationView& nav) { { "SD Card", [&nav](){ nav.push(new NotImplementedView { nav }); } }, { "RFFC5072", [&nav](){ nav.push(new DebugRFFC5072View { nav }); } }, { "MAX2837", [&nav](){ nav.push(new DebugMAX2837View { nav }); } }, - { "Si5351C", [&nav](){ nav.push(new NotImplementedView { nav }); } }, + { "Si5351C", [&nav](){ nav.push(new DebugSi5351CView { nav }); } }, { "WM8731", [&nav](){ nav.push(new NotImplementedView { nav }); } }, } }); on_left = [&nav](){ nav.pop(); }; diff --git a/firmware/application/ui_debug.hpp b/firmware/application/ui_debug.hpp index 16906ccd..68871b3c 100644 --- a/firmware/application/ui_debug.hpp +++ b/firmware/application/ui_debug.hpp @@ -30,6 +30,7 @@ #include "rffc507x.hpp" #include "max2837.hpp" +#include "portapack.hpp" namespace ui { @@ -152,6 +153,40 @@ private: void draw_values(Painter& painter, const max2837::RegisterMap registers); }; +class DebugSi5351CRegistersWidget : public Widget { +public: + constexpr DebugSi5351CRegistersWidget( + Rect parent_rect + ) : Widget { parent_rect } + { + } + + void update(); + + void paint(Painter& painter) override; + + static constexpr const char* const name = "Si5351C"; + +private: + static constexpr size_t registers_count = 96; + + static constexpr size_t legend_length = 2; + static constexpr Dim legend_width = legend_length * 8; + + static constexpr size_t value_length = 2; + static constexpr Dim value_width = value_length * 8; + + static constexpr size_t registers_per_row = 8; + 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, si5351::Si5351& device); +}; + template class RegistersView : public View { public: @@ -180,22 +215,23 @@ private: }; RegistersWidget widget_registers { - { 32, 48, 176, 128 } + { 0, 48, 240, 192 } }; Button button_update { - { 16, 192, 96, 24 }, + { 16, 256, 96, 24 }, "Update" }; Button button_done { - { 128, 192, 96, 24 }, + { 128, 256, 96, 24 }, "Done" }; }; using DebugRFFC5072View = RegistersView; using DebugMAX2837View = RegistersView; +using DebugSi5351CView = RegistersView; class DebugMenuView : public MenuView { public: