Modify registers widget to simplify configuration.

Now specify number of registers and register bits, and the widget figures out the rest.
This commit is contained in:
Jared Boone 2017-05-31 11:12:56 -07:00
parent b3ee884f16
commit 5da64ab069
2 changed files with 28 additions and 18 deletions

View File

@ -173,12 +173,12 @@ void RegistersWidget::paint(Painter& painter) {
void RegistersWidget::draw_legend(const Coord left, Painter& painter) {
const auto pos = screen_pos();
for(int i=0; i<config.registers_count; i+=config.registers_per_row) {
for(int i=0; i<config.registers_count; i+=config.registers_per_row()) {
const Point offset {
left, (i / config.registers_per_row) * row_height
left, (i / config.registers_per_row()) * row_height
};
const auto text = to_string_hex(i, config.legend_length);
const auto text = to_string_hex(i, config.legend_length());
painter.draw_string(
pos + offset,
style().invert(),
@ -195,13 +195,13 @@ void RegistersWidget::draw_values(
for(int i=0; i<config.registers_count; i++) {
const Point offset = {
left + config.legend_width() + 8 + (i % config.registers_per_row) * (config.value_width() + 8),
(i / config.registers_per_row) * row_height
left + config.legend_width() + 8 + (i % config.registers_per_row()) * (config.value_width() + 8),
(i / config.registers_per_row()) * row_height
};
const auto value = reader(i);
const auto text = to_string_hex(value, config.value_length);
const auto text = to_string_hex(value, config.value_length());
painter.draw_string(
pos + offset,
style(),
@ -249,19 +249,19 @@ void RegistersView::focus() {
DebugPeripheralsMenuView::DebugPeripheralsMenuView(NavigationView& nav) {
add_items({
{ "RFFC5072", [&nav](){ nav.push<RegistersView>(
"RFFC5072", RegistersWidgetConfig { 31, 2, 4, 4 },
"RFFC5072", RegistersWidgetConfig { 31, 16 },
[](const size_t register_number) { return radio::debug::first_if::register_read(register_number); }
); } },
{ "MAX2837", [&nav](){ nav.push<RegistersView>(
"MAX2837", RegistersWidgetConfig { 32, 2, 3, 4 },
"MAX2837", RegistersWidgetConfig { 32, 10 },
[](const size_t register_number) { return radio::debug::second_if::register_read(register_number); }
); } },
{ "Si5351C", [&nav](){ nav.push<RegistersView>(
"Si5351C", RegistersWidgetConfig { 96, 2, 2, 8 },
"Si5351C", RegistersWidgetConfig { 96, 8 },
[](const size_t register_number) { return portapack::clock_generator.read_register(register_number); }
); } },
{ "WM8731", [&nav](){ nav.push<RegistersView>(
"WM8731", RegistersWidgetConfig { audio::debug::reg_count(), 1, 3, 4 },
"WM8731", RegistersWidgetConfig { audio::debug::reg_count(), 9 },
[](const size_t register_number) { return audio::debug::reg_read(register_number); }
); } },
});

View File

@ -131,20 +131,30 @@ private:
struct RegistersWidgetConfig {
int registers_count;
int legend_length;
int value_length;
int registers_per_row;
int register_bits;
constexpr int legend_length() const {
return (registers_count >= 0x10) ? 2 : 1;
}
constexpr int legend_width() const {
return legend_length * 8;
return legend_length() * 8;
}
constexpr int value_length() const {
return (register_bits + 3) / 4;
}
constexpr int value_width() const {
return value_length * 8;
return value_length() * 8;
}
constexpr int registers_per_row() const {
return (value_length() >= 3) ? 4 : 8;
}
constexpr int registers_row_length() const {
return (registers_per_row * (value_length + 1)) - 1;
return (registers_per_row() * (value_length() + 1)) - 1;
}
constexpr int registers_row_width() const {
@ -156,7 +166,7 @@ struct RegistersWidgetConfig {
}
constexpr int rows() const {
return registers_count / registers_per_row;
return registers_count / registers_per_row();
}
};