mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-08-19 06:03:59 +00:00
SYNC
This commit is contained in:
+168
-123
@@ -24,16 +24,16 @@
|
||||
#include "ch.h"
|
||||
|
||||
#include "ff.h"
|
||||
#include "led.hpp"
|
||||
#include "hackrf_gpio.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
#include "radio.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
FRESULT fr; /* FatFs function common result code */
|
||||
|
||||
/* DebugMemoryView *******************************************************/
|
||||
|
||||
DebugMemoryView::DebugMemoryView(NavigationView& nav) {
|
||||
add_children({ {
|
||||
@@ -62,156 +62,186 @@ void DebugMemoryView::focus() {
|
||||
button_done.focus();
|
||||
}
|
||||
|
||||
void DebugRFFC5072RegistersWidget::update() {
|
||||
/* TemperatureWidget *****************************************************/
|
||||
|
||||
void TemperatureWidget::paint(Painter& painter) {
|
||||
const auto logger = portapack::temperature_logger;
|
||||
|
||||
const auto rect = screen_rect();
|
||||
const Color color_background { 0, 0, 64 };
|
||||
const Color color_foreground = Color::green();
|
||||
const Color color_reticle { 128, 128, 128 };
|
||||
|
||||
const auto graph_width = static_cast<int>(logger.capacity()) * bar_width;
|
||||
const Rect graph_rect {
|
||||
rect.left() + (rect.width() - graph_width) / 2, rect.top() + 8,
|
||||
graph_width, rect.height()
|
||||
};
|
||||
const Rect frame_rect {
|
||||
graph_rect.left() - 1, graph_rect.top() - 1,
|
||||
graph_rect.width() + 2, graph_rect.height() + 2
|
||||
};
|
||||
painter.draw_rectangle(frame_rect, color_reticle);
|
||||
painter.fill_rectangle(graph_rect, color_background);
|
||||
|
||||
const auto history = logger.history();
|
||||
for(size_t i=0; i<history.size(); i++) {
|
||||
const Coord x = graph_rect.right() - (history.size() - i) * bar_width;
|
||||
const auto sample = history[i];
|
||||
const auto temp = temperature(sample);
|
||||
const auto y = screen_y(temp, graph_rect);
|
||||
const Dim bar_height = graph_rect.bottom() - y;
|
||||
painter.fill_rectangle({ x, y, bar_width, bar_height }, color_foreground);
|
||||
}
|
||||
|
||||
if( !history.empty() ) {
|
||||
const auto sample = history.back();
|
||||
const auto temp = temperature(sample);
|
||||
const auto last_y = screen_y(temp, graph_rect);
|
||||
const Coord x = graph_rect.right() + 8;
|
||||
const Coord y = last_y - 8;
|
||||
|
||||
painter.draw_string({ x, y }, style(), temperature_str(temp));
|
||||
}
|
||||
|
||||
const auto display_temp_max = display_temp_min + (graph_rect.height() / display_temp_scale);
|
||||
for(auto temp=display_temp_min; temp<=display_temp_max; temp+=10) {
|
||||
const int32_t tick_length = 6;
|
||||
const auto tick_x = graph_rect.left() - tick_length;
|
||||
const auto tick_y = screen_y(temp, graph_rect);
|
||||
painter.fill_rectangle({ tick_x, tick_y, tick_length, 1 }, color_reticle);
|
||||
const auto text_x = graph_rect.left() - temp_len * 8 - 8;
|
||||
const auto text_y = tick_y - 8;
|
||||
painter.draw_string({ text_x, text_y }, style(), temperature_str(temp));
|
||||
}
|
||||
}
|
||||
|
||||
TemperatureWidget::temperature_t TemperatureWidget::temperature(const sample_t sensor_value) const {
|
||||
return -45 + sensor_value * 5;
|
||||
}
|
||||
|
||||
std::string TemperatureWidget::temperature_str(const temperature_t temperature) const {
|
||||
return to_string_dec_int(temperature, temp_len - 1) + "C";
|
||||
}
|
||||
|
||||
Coord TemperatureWidget::screen_y(
|
||||
const temperature_t temperature,
|
||||
const Rect& rect
|
||||
) const {
|
||||
int y_raw = rect.bottom() - ((temperature - display_temp_min) * display_temp_scale);
|
||||
const auto y_limit = std::min(rect.bottom(), std::max(rect.top(), y_raw));
|
||||
return y_limit;
|
||||
}
|
||||
|
||||
/* TemperatureView *******************************************************/
|
||||
|
||||
TemperatureView::TemperatureView(NavigationView& nav) {
|
||||
add_children({ {
|
||||
&text_title,
|
||||
&temperature_widget,
|
||||
&button_done,
|
||||
} });
|
||||
|
||||
button_done.on_select = [&nav](Button&){ nav.pop(); };
|
||||
}
|
||||
|
||||
void TemperatureView::focus() {
|
||||
button_done.focus();
|
||||
}
|
||||
|
||||
/* RegistersWidget *******************************************************/
|
||||
|
||||
RegistersWidget::RegistersWidget(
|
||||
RegistersWidgetConfig&& config,
|
||||
std::function<uint32_t(const size_t register_number)>&& reader
|
||||
) : Widget { },
|
||||
config(std::move(config)),
|
||||
reader(std::move(reader))
|
||||
{
|
||||
}
|
||||
|
||||
void RegistersWidget::update() {
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
void DebugRFFC5072RegistersWidget::paint(Painter& painter) {
|
||||
draw_legend(painter);
|
||||
void RegistersWidget::paint(Painter& painter) {
|
||||
const Coord left = (size().w - config.row_width()) / 2;
|
||||
|
||||
const auto registers = radio::first_if.registers();
|
||||
draw_values(painter, registers);
|
||||
draw_legend(left, painter);
|
||||
draw_values(left, painter);
|
||||
}
|
||||
|
||||
void DebugRFFC5072RegistersWidget::draw_legend(Painter& painter) {
|
||||
for(size_t i=0; i<registers_count; i+=registers_per_row) {
|
||||
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) {
|
||||
const Point offset {
|
||||
0, static_cast<Coord>((i / registers_per_row) * row_height)
|
||||
left, (i / config.registers_per_row) * row_height
|
||||
};
|
||||
|
||||
const auto text = to_string_hex(i, legend_length);
|
||||
const auto text = to_string_hex(i, config.legend_length);
|
||||
painter.draw_string(
|
||||
screen_pos() + offset,
|
||||
style(),
|
||||
pos + offset,
|
||||
style().invert(),
|
||||
text
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugRFFC5072RegistersWidget::draw_values(
|
||||
Painter& painter,
|
||||
const rffc507x::RegisterMap registers
|
||||
void RegistersWidget::draw_values(
|
||||
const Coord left,
|
||||
Painter& painter
|
||||
) {
|
||||
for(size_t i=0; i<registers_count; i++) {
|
||||
const auto pos = screen_pos();
|
||||
|
||||
for(int i=0; i<config.registers_count; i++) {
|
||||
const Point offset = {
|
||||
static_cast<Coord>(legend_width + 8 + (i % registers_per_row) * (value_width + 8)),
|
||||
static_cast<Coord>((i / 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 uint16_t value = registers.w[i];
|
||||
const auto value = reader(i);
|
||||
|
||||
const auto text = to_string_hex(value, value_length);
|
||||
const auto text = to_string_hex(value, config.value_length);
|
||||
painter.draw_string(
|
||||
screen_pos() + offset,
|
||||
pos + offset,
|
||||
style(),
|
||||
text
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
DebugRFFC5072View::DebugRFFC5072View(NavigationView& nav) {
|
||||
/* RegistersView *********************************************************/
|
||||
|
||||
RegistersView::RegistersView(
|
||||
NavigationView& nav,
|
||||
const std::string& title,
|
||||
RegistersWidgetConfig&& config,
|
||||
std::function<uint32_t(const size_t register_number)>&& reader
|
||||
) : registers_widget { std::move(config), std::move(reader) }
|
||||
{
|
||||
add_children({ {
|
||||
&text_title,
|
||||
&widget_registers,
|
||||
®isters_widget,
|
||||
&button_update,
|
||||
&button_done,
|
||||
} });
|
||||
|
||||
button_update.on_select = [this](Button&){
|
||||
this->widget_registers.update();
|
||||
this->registers_widget.update();
|
||||
};
|
||||
button_done.on_select = [&nav](Button&){ nav.pop(); };
|
||||
|
||||
registers_widget.set_parent_rect({ 0, 48, 240, 192 });
|
||||
|
||||
text_title.set_parent_rect({
|
||||
(240 - static_cast<int>(title.size()) * 8) / 2, 16,
|
||||
static_cast<int>(title.size()) * 8, 16
|
||||
});
|
||||
text_title.set(title);
|
||||
}
|
||||
|
||||
void DebugRFFC5072View::focus() {
|
||||
button_done.focus();
|
||||
}
|
||||
|
||||
void DebugSDView::paint(Painter& painter) {
|
||||
const Point offset = {
|
||||
static_cast<Coord>(32),
|
||||
static_cast<Coord>(32)
|
||||
};
|
||||
|
||||
const auto text = to_string_hex(fr, 2);
|
||||
painter.draw_string(
|
||||
screen_pos() + offset,
|
||||
style(),
|
||||
text
|
||||
);
|
||||
}
|
||||
|
||||
DebugSDView::DebugSDView(NavigationView& nav) {
|
||||
add_children({ {
|
||||
&text_title,
|
||||
&text_modules,
|
||||
&button_makefile,
|
||||
&button_done
|
||||
} });
|
||||
|
||||
FIL fdst;
|
||||
char buffer[256];
|
||||
uint8_t mods_version, mods_count;
|
||||
UINT bw;
|
||||
|
||||
const auto open_result = f_open(&fdst, "ppmods.bin", FA_OPEN_EXISTING | FA_READ);
|
||||
if (open_result == FR_OK) {
|
||||
f_read(&fdst, &mods_version, 1, &bw);
|
||||
if (mods_version == 1) {
|
||||
f_read(&fdst, &mods_count, 1, &bw);
|
||||
f_read(&fdst, buffer, 8, &bw);
|
||||
f_read(&fdst, buffer, 16, &bw);
|
||||
buffer[16] = 0;
|
||||
text_modules.set(buffer);
|
||||
} else {
|
||||
text_modules.set("Bad version");
|
||||
}
|
||||
}
|
||||
|
||||
button_makefile.on_select = [this](Button&){
|
||||
FATFS fs; /* Work area (file system object) for logical drives */
|
||||
FIL fdst; /* File objects */
|
||||
int16_t buffer[512]; /* File copy buffer */
|
||||
UINT bw; /* File read/write count */
|
||||
|
||||
sdcConnect(&SDCD1);
|
||||
|
||||
fr = f_mount(&fs, "", 1);
|
||||
|
||||
fr = f_open(&fdst, "TST.SND", FA_OPEN_EXISTING | FA_READ);
|
||||
|
||||
//if (!fr) led_rx.on();
|
||||
|
||||
/*fr = f_read(&fdst, buffer, 512*2, &bw);
|
||||
|
||||
Coord oy,ny;
|
||||
|
||||
oy = 128;
|
||||
|
||||
for (int c=0;c<512;c++) {
|
||||
ny = 128+32-(buffer[c]>>10);
|
||||
portapack::display.draw_line({static_cast<Coord>(c/3),oy},{static_cast<Coord>((c+1)/3),ny},{255,127,0});
|
||||
oy = ny;
|
||||
}*/
|
||||
|
||||
/*
|
||||
//if (fr) return;
|
||||
|
||||
fr = f_write(&fdst, buffer, br, &bw);
|
||||
//if (fr || bw < br) return;*/
|
||||
|
||||
//set_dirty();
|
||||
|
||||
f_close(&fdst);
|
||||
|
||||
f_mount(NULL, "", 0);
|
||||
|
||||
};
|
||||
|
||||
button_done.on_select = [&nav](Button&){ nav.pop(); };
|
||||
}
|
||||
|
||||
void DebugSDView::focus() {
|
||||
void RegistersView::focus() {
|
||||
button_done.focus();
|
||||
}
|
||||
|
||||
@@ -267,15 +297,30 @@ void DebugLCRView::focus() {
|
||||
button_done.focus();
|
||||
}
|
||||
|
||||
/* DebugMenuView *********************************************************/
|
||||
|
||||
DebugMenuView::DebugMenuView(NavigationView& nav) {
|
||||
add_items<7>({ {
|
||||
{ "Memory", ui::Color::white(), [&nav](){ nav.push(new DebugMemoryView { nav }); } },
|
||||
{ "Radio State", ui::Color::white(), [&nav](){ nav.push(new NotImplementedView { nav }); } },
|
||||
{ "SD Card", ui::Color::white(), [&nav](){ nav.push(new DebugSDView { nav }); } },
|
||||
{ "RFFC5072", ui::Color::white(), [&nav](){ nav.push(new DebugRFFC5072View { nav }); } },
|
||||
{ "MAX2837", ui::Color::white(), [&nav](){ nav.push(new NotImplementedView { nav }); } },
|
||||
{ "Si5351C", ui::Color::white(), [&nav](){ nav.push(new NotImplementedView { nav }); } },
|
||||
{ "WM8731", ui::Color::white(), [&nav](){ nav.push(new NotImplementedView { nav }); } },
|
||||
add_items<8>({ {
|
||||
{ "Memory", [&nav](){ nav.push<DebugMemoryView>(); } },
|
||||
{ "Radio State", [&nav](){ nav.push<NotImplementedView>(); } },
|
||||
{ "SD Card", [&nav](){ nav.push<NotImplementedView>(); } },
|
||||
{ "RFFC5072", [&nav](){ nav.push<RegistersView>(
|
||||
"RFFC5072", RegistersWidgetConfig { 31, 2, 4, 4 },
|
||||
[](const size_t register_number) { return radio::first_if.read(register_number); }
|
||||
); } },
|
||||
{ "MAX2837", [&nav](){ nav.push<RegistersView>(
|
||||
"MAX2837", RegistersWidgetConfig { 32, 2, 3, 4 },
|
||||
[](const size_t register_number) { return radio::second_if.read(register_number); }
|
||||
); } },
|
||||
{ "Si5351C", [&nav](){ nav.push<RegistersView>(
|
||||
"Si5351C", RegistersWidgetConfig { 96, 2, 2, 8 },
|
||||
[](const size_t register_number) { return portapack::clock_generator.read_register(register_number); }
|
||||
); } },
|
||||
{ "WM8731", [&nav](){ nav.push<RegistersView>(
|
||||
"WM8731", RegistersWidgetConfig { wolfson::wm8731::reg_count, 1, 3, 4 },
|
||||
[](const size_t register_number) { return portapack::audio_codec.read(register_number); }
|
||||
); } },
|
||||
{ "Temperature", [&nav](){ nav.push<TemperatureView>(); } },
|
||||
} });
|
||||
on_left = [&nav](){ nav.pop(); };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user