diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d6f873..f441c28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,10 +81,22 @@ jobs: uses: ilammy/msvc-dev-cmd@v1 - run: cmake --preset dev - run: cmake --build --preset dev + - name: EmbLinkRTOS, for stage S2's golden test + uses: actions/checkout@v7 + with: + repository: EmbLinkOs/EmbLinkRTOS + # The same revision as the core's acceptance tests. + ref: a2cb045cf27a0f53bc53ce110d3bffc4d381817f + path: rtos + persist-credentials: false - run: ctest --preset dev + env: + EMBLINK_STUDIO_TEST_RTOS: ${{ github.workspace }}/rtos - name: Failed tests, again, with their full output if: failure() run: ctest --preset dev --rerun-failed --extra-verbose + env: + EMBLINK_STUDIO_TEST_RTOS: ${{ github.workspace }}/rtos format: name: clang-format diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index c589148..f04a4d9 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -35,8 +35,12 @@ qt_add_library(emblink_studio_ui STATIC src/segmentedcontrol.cpp src/segmentedcontrol.h src/language.cpp src/language.h src/settingsdialog.cpp src/settingsdialog.h + src/format.cpp src/format.h src/boardview.cpp src/boardview.h src/problemsview.cpp src/problemsview.h + src/clocktreeview.cpp src/clocktreeview.h + src/memoryview.cpp src/memoryview.h + src/devicesview.cpp src/devicesview.h ) target_include_directories(emblink_studio_ui PUBLIC src) target_link_libraries(emblink_studio_ui PUBLIC Qt6::Widgets) @@ -110,8 +114,13 @@ if(EMBLINK_STUDIO_BUILD_TESTS) EMBLINK_STUDIO_FAKE_HWGEN="${PROJECT_SOURCE_DIR}/core/tests/fake_hwgen.py") add_test(NAME tst_session COMMAND tst_session) + # Stage S2's golden test, against a real EmbLinkRTOS checkout (EMBLINK_STUDIO_TEST_RTOS). + qt_add_executable(tst_golden tests/tst_golden.cpp) + target_link_libraries(tst_golden PRIVATE emblink_studio_corelink emblink_studio_ui Qt6::Test) + add_test(NAME tst_golden COMMAND tst_golden) + set_target_properties(tst_framing tst_coreclient tst_workbench tst_theme tst_segmentedcontrol - tst_language tst_session PROPERTIES WIN32_EXECUTABLE OFF MACOSX_BUNDLE OFF) + tst_language tst_session tst_golden PROPERTIES WIN32_EXECUTABLE OFF MACOSX_BUNDLE OFF) target_compile_definitions(tst_theme PRIVATE EMBLINK_STUDIO_TOKENS="${PROJECT_SOURCE_DIR}/docs/design/tokens.json") endif() diff --git a/app/i18n/emblinkstudio_fr.ts b/app/i18n/emblinkstudio_fr.ts index 795a0af..3f954df 100644 --- a/app/i18n/emblinkstudio_fr.ts +++ b/app/i18n/emblinkstudio_fr.ts @@ -124,6 +124,73 @@ Dispositifs + + emblinkstudio::ClockTreeView + + Open a generated board to see its clock tree. + Ouvrez une carte générée pour voir son arbre d’horloges. + + + Source + Source + + + bypass + bypass + + + PLL input + Entrée de la PLL + + + VCO + VCO + + + PLL Q output + Sortie Q de la PLL + + + System clock + Horloge système + + + CPU and AHB + CPU et AHB + + + CPU · AHB %1 + CPU · AHB %1 + + + Bus %1 + Bus %1 + + + limit %1 + limite %1 + + + Flash wait states: %1. + États d’attente de la flash : %1. + + + Regulator: %1 (VOS %2), over-drive %3. + Régulateur : %1 (VOS %2), over-drive %3. + + + on + activé + + + off + désactivé + + + Kernel tick timer: %1 at %2. + Timer du tick du noyau : %1 à %2. + + emblinkstudio::CoreClient @@ -163,6 +230,41 @@ EmbLink Studio Core s’est arrêté (code %1) avant son initialisation. + + emblinkstudio::DevicesView + + Device + Dispositif + + + Class + Classe + + + Compatible + Compatible + + + Level + Niveau + + + Depends on + Dépend de + + + Field + Champ + + + Value + Valeur + + + Open a generated board to see its devices. + Ouvrez une carte générée pour voir ses dispositifs. + + emblinkstudio::MainWindow @@ -213,6 +315,18 @@ Board Carte + + Clock tree + Arbre d’horloges + + + Memory + Mémoire + + + Devices + Dispositifs + Problems Problèmes @@ -350,6 +464,37 @@ Nom de cette disposition, par exemple Débogage : + + emblinkstudio::MemoryView + + Open a generated board to see its memory. + Ouvrez une carte générée pour voir sa mémoire. + + + Memory map + Carte mémoire + + + sectors %1 + secteurs %1 + + + pages %1 to %2 + pages %1 à %2 + + + %1 (reserved) + %1 (réservée) + + + Flash partitions + Partitions de la flash + + + Image layout + Disposition de l’image + + emblinkstudio::ProblemsView diff --git a/app/i18n/emblinkstudio_zh_CN.ts b/app/i18n/emblinkstudio_zh_CN.ts index 587f951..7801cf0 100644 --- a/app/i18n/emblinkstudio_zh_CN.ts +++ b/app/i18n/emblinkstudio_zh_CN.ts @@ -124,6 +124,73 @@ 设备 + + emblinkstudio::ClockTreeView + + Open a generated board to see its clock tree. + 打开已生成的开发板以查看其时钟树。 + + + Source + 时钟源 + + + bypass + 旁路 + + + PLL input + PLL 输入 + + + VCO + VCO + + + PLL Q output + PLL Q 输出 + + + System clock + 系统时钟 + + + CPU and AHB + CPU 和 AHB + + + CPU · AHB %1 + CPU · AHB %1 + + + Bus %1 + 总线 %1 + + + limit %1 + 上限 %1 + + + Flash wait states: %1. + 闪存等待周期:%1。 + + + Regulator: %1 (VOS %2), over-drive %3. + 稳压器:%1(VOS %2),超频驱动%3。 + + + on + 开启 + + + off + 关闭 + + + Kernel tick timer: %1 at %2. + 内核节拍定时器:%1,%2。 + + emblinkstudio::CoreClient @@ -163,6 +230,41 @@ EmbLink Studio Core 在初始化之前退出(代码 %1)。 + + emblinkstudio::DevicesView + + Device + 设备 + + + Class + 类别 + + + Compatible + 兼容 + + + Level + 级别 + + + Depends on + 依赖 + + + Field + 字段 + + + Value + 值 + + + Open a generated board to see its devices. + 打开已生成的开发板以查看其设备。 + + emblinkstudio::MainWindow @@ -213,6 +315,18 @@ Board 开发板 + + Clock tree + 时钟树 + + + Memory + 内存 + + + Devices + 设备 + Problems 问题 @@ -350,6 +464,37 @@ 此布局的名称,例如“调试”: + + emblinkstudio::MemoryView + + Open a generated board to see its memory. + 打开已生成的开发板以查看其内存。 + + + Memory map + 内存映射 + + + sectors %1 + 扇区 %1 + + + pages %1 to %2 + 页 %1 到 %2 + + + %1 (reserved) + %1(保留) + + + Flash partitions + 闪存分区 + + + Image layout + 镜像布局 + + emblinkstudio::ProblemsView diff --git a/app/src/boardview.cpp b/app/src/boardview.cpp index c36c2d4..c6d0146 100644 --- a/app/src/boardview.cpp +++ b/app/src/boardview.cpp @@ -51,36 +51,8 @@ QString text(const QJsonValue &v) return dash(); } -QString hex(double value) -{ - return QStringLiteral("0x%1") - .arg(qulonglong(value), 8, 16, QLatin1Char('0')) - .toUpper() - .replace(QStringLiteral("0X"), QStringLiteral("0x")); -} - } // namespace -QString formatHz(double hz) -{ - const QLocale locale; - if (hz >= 1e6) - return locale.toString(hz / 1e6, 'g', 6) + QStringLiteral(" MHz"); - if (hz >= 1e3) - return locale.toString(hz / 1e3, 'g', 6) + QStringLiteral(" kHz"); - return locale.toString(hz, 'g', 6) + QStringLiteral(" Hz"); -} - -QString formatBytes(double bytes) -{ - const QLocale locale; - if (bytes >= 1024.0 * 1024.0) - return locale.toString(bytes / (1024.0 * 1024.0), 'g', 4) + QStringLiteral(" MB"); - if (bytes >= 1024.0) - return locale.toString(bytes / 1024.0, 'g', 4) + QStringLiteral(" KB"); - return locale.toString(bytes, 'g', 6) + QStringLiteral(" B"); -} - BoardView::BoardView(QWidget *parent) : QScrollArea(parent) { setObjectName(QStringLiteral("viewContent")); @@ -234,7 +206,7 @@ void BoardView::render() {tr("Console"), tr("%1 at %2 baud") .arg(console.value(QStringLiteral("device")).toString(), - QLocale().toString(console.value(QStringLiteral("baud")).toInt()))}); + QString::number(console.value(QStringLiteral("baud")).toInt()))}); for (const QJsonValue &led : board.value(QStringLiteral("leds")).toArray()) boardRows.append({tr("LED %1").arg(led.toObject().value(QStringLiteral("name")).toString()), led.toObject().value(QStringLiteral("gpio")).toString()}); @@ -246,7 +218,7 @@ void BoardView::render() if (!probe.isEmpty()) { QStringList ways; for (auto it = probe.begin(); it != probe.end(); ++it) - ways.append(it.key() + QStringLiteral(" ") + text(it.value())); + ways.append(it.key() + QStringLiteral(" ") + formatField(it.key(), it.value())); boardRows.append({tr("Debug probe"), ways.join(QStringLiteral("\n"))}); } addGroup(tr("Board"), boardRows); @@ -277,24 +249,33 @@ void BoardView::render() memoryRows.append({region.value(QStringLiteral("name")).toString(), tr("%1 at %2") .arg(formatBytes(region.value(QStringLiteral("size")).toDouble()), - hex(region.value(QStringLiteral("base")).toDouble()))}); + formatHex(region.value(QStringLiteral("base")).toDouble()))}); } for (const QJsonValue &v : m_memory.value(QStringLiteral("partitions")).toArray()) { const QJsonObject part = v.toObject(); memoryRows.append({tr("Partition %1").arg(part.value(QStringLiteral("name")).toString()), tr("%1 at %2") .arg(formatBytes(part.value(QStringLiteral("size")).toDouble()), - hex(part.value(QStringLiteral("base")).toDouble()))}); + formatHex(part.value(QStringLiteral("base")).toDouble()))}); } addGroup(tr("Memory"), memoryRows); QList> pinRows; for (const QJsonValue &v : m_pins.value(QStringLiteral("assigned")).toArray()) { const QJsonObject pin = v.toObject(); + // The mode as the generator writes it (board.md): af7 (usart2_tx), fixed (...), output. + const QString mode = pin.value(QStringLiteral("mode")).toString(); const QString signal = pin.value(QStringLiteral("signal")).toString(); - pinRows.append({pin.value(QStringLiteral("pin")).toString(), - (signal.isEmpty() ? pin.value(QStringLiteral("mode")).toString() : signal) + - QStringLiteral(" · ") + pin.value(QStringLiteral("owner")).toString()}); + QString how = mode; + if (mode == QStringLiteral("af")) + how = QStringLiteral("af%1 (%2)") + .arg(pin.value(QStringLiteral("af")).toInt()) + .arg(signal); + else if (mode == QStringLiteral("fixed")) + how = QStringLiteral("fixed (%1)").arg(signal); + pinRows.append( + {pin.value(QStringLiteral("pin")).toString(), + how + QStringLiteral(" · ") + pin.value(QStringLiteral("owner")).toString()}); } addGroup(tr("Pins in use"), pinRows); diff --git a/app/src/boardview.h b/app/src/boardview.h index 8ffa877..78d00ee 100644 --- a/app/src/boardview.h +++ b/app/src/boardview.h @@ -24,6 +24,8 @@ #pragma once +#include "format.h" + #include #include #include @@ -72,9 +74,4 @@ class BoardView : public QScrollArea QHash m_values; }; -// "180 MHz", "8 MHz", "32.768 kHz": a frequency in the interface's language. -QString formatHz(double hz); -// "512 KB", "16 KB", "1.5 MB". -QString formatBytes(double bytes); - } // namespace emblinkstudio diff --git a/app/src/clocktreeview.cpp b/app/src/clocktreeview.cpp new file mode 100644 index 0000000..7e67bac --- /dev/null +++ b/app/src/clocktreeview.cpp @@ -0,0 +1,383 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file clocktreeview.cpp + * @brief Implementation of ClockTreeView: the graph from board.clocks, and its drawing. + * + * @details + * build() turns the generator's resolved clock tree into nodes in columns and edges + * between them; the canvas lays the columns out at a fixed pitch and draws each node + * as a card (design tokens: radius.group, fill.group), the main path in the accent + * colour, each factor in a pill on its edge. The canvas is as large as the tree and + * scrolls inside the view. + * + * @see clocktreeview.h + * @author Junior Deogracias + * @date 2026-11-13 (created) + */ + +#include "clocktreeview.h" +#include "format.h" +#include "theme.h" + +#include +#include +#include +#include +#include +#include + +namespace emblinkstudio +{ + +namespace +{ + +constexpr double kNodeW = 178; +constexpr double kNodeH = 74; +constexpr double kColumnPitch = 244; +constexpr double kRowPitch = 92; +constexpr double kMargin = 24; + +QString factor(const QJsonValue &v) +{ + return QString::number(v.toDouble(), 'g', 10); +} + +} // namespace + +class ClockTreeView::Canvas : public QWidget +{ + public: + explicit Canvas(ClockTreeView *view) : QWidget(view), m_view(view) + { + setMouseTracking(true); + } + + QRectF rectOf(const Node &n) const + { + return QRectF(kMargin + n.column * kColumnPitch, m_top + n.row * kRowPitch, kNodeW, kNodeH); + } + + void relayout() + { + double minRow = 0; + double maxRow = 0; + int columns = 1; + for (const Node &n : m_view->m_nodes) { + minRow = qMin(minRow, n.row); + maxRow = qMax(maxRow, n.row); + columns = qMax(columns, n.column + 1); + } + m_top = kMargin + 10 - minRow * kRowPitch; + const double notesH = 22.0 * m_view->m_notes.size(); + setMinimumSize(int(kMargin * 2 + (columns - 1) * kColumnPitch + kNodeW), + int(m_top + maxRow * kRowPitch + kNodeH + 28 + notesH + kMargin)); + update(); + } + + protected: + bool event(QEvent *e) override + { + if (e->type() == QEvent::ToolTip) { + const auto *help = static_cast(e); + for (const Node &n : m_view->m_nodes) + if (rectOf(n).contains(help->pos()) && !n.tooltip.isEmpty()) { + QToolTip::showText(help->globalPos(), n.tooltip, this); + return true; + } + QToolTip::hideText(); + return true; + } + return QWidget::event(e); + } + + void paintEvent(QPaintEvent *) override + { + const Theme &theme = Theme::current(); + QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); + const QColor accent = theme.color(QStringLiteral("accent.base")); + const QColor line = theme.color(QStringLiteral("line.strong")); + + QHash byId; + for (const Node &n : m_view->m_nodes) + byId.insert(n.id, n); + + // Edges first, under the cards: elbows from the right of one card to the left of the next. + QFont labelFont = theme.font(QStringLiteral("codeMeta")); + for (const Edge &e : m_view->m_edges) { + if (!byId.contains(e.from) || !byId.contains(e.to)) + continue; + const QRectF a = rectOf(byId.value(e.from)); + const QRectF b = rectOf(byId.value(e.to)); + QPainterPath path; + QPointF labelAt; + if (qFuzzyCompare(a.left(), b.left())) { // same column: straight down + path.moveTo(a.center().x(), a.bottom()); + path.lineTo(b.center().x(), b.top()); + labelAt = QPointF(a.center().x() + 26, (a.bottom() + b.top()) / 2); + } else { + const double midX = (a.right() + b.left()) / 2; + path.moveTo(a.right(), a.center().y()); + path.lineTo(midX, a.center().y()); + path.lineTo(midX, b.center().y()); + path.lineTo(b.left(), b.center().y()); + labelAt = QPointF( + qFuzzyCompare(a.center().y(), b.center().y()) ? midX : (midX + b.left()) / 2, + b.center().y()); + } + const bool main = e.to == QStringLiteral("sys") || e.to == QStringLiteral("vco") || + e.to == QStringLiteral("pll_in"); + p.setPen(QPen(main ? accent : line, 1.6)); + p.setBrush(Qt::NoBrush); + p.drawPath(path); + if (!e.label.isEmpty()) { + p.setFont(labelFont); + const QFontMetricsF fm(labelFont); + const QRectF pill(labelAt.x() - fm.horizontalAdvance(e.label) / 2 - 7, + labelAt.y() - 10, fm.horizontalAdvance(e.label) + 14, 20); + QPainterPath bg; + bg.addRoundedRect(pill, 10, 10); + p.fillPath(bg, theme.color(QStringLiteral("surface.card"))); + p.setPen(QPen(main ? accent : line, 1)); + p.drawPath(bg); + p.setPen(theme.color(QStringLiteral("accent.text"))); + p.drawText(pill, Qt::AlignCenter, e.label); + } + } + + // Cards. + const QFont titleFont = theme.font(QStringLiteral("caption")); + const QFont valueFont = theme.font(QStringLiteral("title2")); + const QFont detailFont = theme.font(QStringLiteral("codeMeta")); + const double radius = theme.number(QStringLiteral("radius.group")); + for (const Node &n : m_view->m_nodes) { + const QRectF r = rectOf(n); + QPainterPath card; + card.addRoundedRect(r, radius, radius); + p.fillPath(card, Theme::flattened(theme.color(QStringLiteral("fill.group")), + theme.color(QStringLiteral("surface.card")))); + const bool sys = n.id == QStringLiteral("sys"); + p.setPen( + QPen(sys ? accent : theme.color(QStringLiteral("line.control")), sys ? 1.5 : 1)); + p.drawPath(card); + + p.setFont(titleFont); + p.setPen(theme.color(QStringLiteral("text.tertiary"))); + p.drawText(r.adjusted(12, 9, -12, 0), Qt::AlignLeft | Qt::AlignTop, n.title); + p.setFont(valueFont); + p.setPen(theme.color(QStringLiteral("text.strong"))); + p.drawText(r.adjusted(12, 24, -12, 0), Qt::AlignLeft | Qt::AlignTop, n.value); + p.setFont(detailFont); + p.setPen(theme.color(QStringLiteral("text.quiet"))); + p.drawText( + r.adjusted(12, 0, -12, -10), Qt::AlignLeft | Qt::AlignBottom, + QFontMetricsF(detailFont).elidedText(n.detail, Qt::ElideRight, r.width() - 24)); + + if (n.load >= 0) { // how close the bus runs to its limit + const QRectF track(r.left() + 12, r.bottom() - 5, r.width() - 24, 2.5); + p.fillRect(track, theme.color(QStringLiteral("fill.control"))); + QRectF fill = track; + fill.setWidth(track.width() * qMin(1.0, n.load)); + p.fillRect(fill, theme.color(n.load > 1.0 ? QStringLiteral("state.danger.base") + : QStringLiteral("state.success.base"))); + } + } + + // The generator's notes, under the tree. + double y = 0; + for (const Node &n : m_view->m_nodes) + y = qMax(y, rectOf(n).bottom()); + p.setFont(theme.font(QStringLiteral("small"))); + p.setPen(theme.color(QStringLiteral("text.secondary"))); + y += 28; + for (const QString ¬e : std::as_const(m_view->m_notes)) { + p.drawText(QPointF(kMargin, y), note); + y += 22; + } + } + + private: + ClockTreeView *m_view; + double m_top = kMargin; +}; + +ClockTreeView::ClockTreeView(QWidget *parent) : QScrollArea(parent) +{ + setObjectName(QStringLiteral("viewContent")); + setAttribute(Qt::WA_StyledBackground, true); + setFrameShape(QFrame::NoFrame); + m_canvas = new Canvas(this); + m_canvas->setObjectName(QStringLiteral("viewContent")); + m_canvas->setAttribute(Qt::WA_StyledBackground, true); + setWidget(m_canvas); + setWidgetResizable(true); +} + +ClockTreeView::Node ClockTreeView::node(const QString &id) const +{ + for (const Node &n : m_nodes) + if (n.id == id) + return n; + return {}; +} + +void ClockTreeView::setClocks(const QJsonObject &clocks) +{ + m_clocks = clocks; + build(); +} + +void ClockTreeView::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + build(); + QScrollArea::changeEvent(event); +} + +void ClockTreeView::build() +{ + m_nodes.clear(); + m_edges.clear(); + m_notes.clear(); + const QJsonObject r = m_clocks.value(QStringLiteral("resolved")).toObject(); + const QJsonObject limits = m_clocks.value(QStringLiteral("limits")).toObject(); + if (r.isEmpty()) { + m_notes.append(tr("Open a generated board to see its clock tree.")); + m_canvas->relayout(); + return; + } + + // The source oscillator, with the SoC's words for it. + const QString sourceName = r.value(QStringLiteral("source")).toString(); + QString sourceDoc; + for (const QJsonValue &v : limits.value(QStringLiteral("sources")).toArray()) + if (v.toObject().value(QStringLiteral("name")).toString() == sourceName) + sourceDoc = v.toObject().value(QStringLiteral("doc")).toString(); + Node source{QStringLiteral("source"), tr("Source"), + formatHz(r.value(QStringLiteral("source_hz")).toDouble()), + sourceName + (r.value(QStringLiteral("bypass")).toBool() + ? QStringLiteral(" · ") + tr("bypass") + : QString()), + sourceDoc}; + m_nodes.append(source); + + int column = 1; + QString last = QStringLiteral("source"); + QString sysLabel; + const QJsonObject pll = r.value(QStringLiteral("pll")).toObject(); + if (!pll.isEmpty()) { + const QString pllName = pll.value(QStringLiteral("name")).toString(); + m_nodes.append({QStringLiteral("pll_in"), + tr("PLL input"), + formatHz(pll.value(QStringLiteral("vco_in_hz")).toDouble()), + pllName, + {}, + -1, + column, + 0}); + m_edges.append({QStringLiteral("source"), QStringLiteral("pll_in"), + QStringLiteral("÷ ") + factor(pll.value(QStringLiteral("m")))}); + ++column; + m_nodes.append({QStringLiteral("vco"), + tr("VCO"), + formatHz(pll.value(QStringLiteral("vco_hz")).toDouble()), + pllName, + {}, + -1, + column, + 0}); + m_edges.append({QStringLiteral("pll_in"), QStringLiteral("vco"), + QStringLiteral("× ") + factor(pll.value(QStringLiteral("n")))}); + if (pll.contains(QStringLiteral("q_hz"))) { + m_nodes.append({QStringLiteral("pll_q"), + tr("PLL Q output"), + formatHz(pll.value(QStringLiteral("q_hz")).toDouble()), + pllName, + {}, + -1, + column, + 1}); + m_edges.append({QStringLiteral("vco"), QStringLiteral("pll_q"), + QStringLiteral("÷ ") + factor(pll.value(QStringLiteral("q")))}); + } + sysLabel = pll.contains(QStringLiteral("postdiv1")) + ? QStringLiteral("÷ %1 ÷ %2") + .arg(factor(pll.value(QStringLiteral("postdiv1"))), + factor(pll.value(QStringLiteral("postdiv2")))) + : QStringLiteral("÷ ") + factor(pll.value(QStringLiteral("p"))); + last = QStringLiteral("vco"); + ++column; + } + + const double cpuHz = r.value(QStringLiteral("cpu_hz")).toDouble(); + const double hclkHz = r.value(QStringLiteral("hclk_hz")).toDouble(); + m_nodes.append({QStringLiteral("sys"), + tr("System clock"), + formatHz(cpuHz), + qFuzzyCompare(cpuHz, hclkHz) || hclkHz == 0 + ? tr("CPU and AHB") + : tr("CPU · AHB %1").arg(formatHz(hclkHz)), + {}, + -1, + column, + 0}); + m_edges.append({last, QStringLiteral("sys"), sysLabel}); + ++column; + + // The buses, with the SoC's limit where it gives one. + const QJsonObject busHz = r.value(QStringLiteral("bus_hz")).toObject(); + QList buses; + for (const QJsonValue &v : limits.value(QStringLiteral("buses")).toArray()) + buses.append(v.toObject()); + if (buses.isEmpty()) + for (auto it = busHz.begin(); it != busHz.end(); ++it) + buses.append(QJsonObject{{QStringLiteral("name"), it.key()}}); + const double first = -(buses.size() - 1) / 2.0; + for (int i = 0; i < buses.size(); ++i) { + const QJsonObject bus = buses.at(i); + const QString name = bus.value(QStringLiteral("name")).toString(); + const double hz = busHz.value(name).toDouble(); + const double max = bus.value(QStringLiteral("max_hz")).toDouble(); + const QString from = bus.value(QStringLiteral("from")).toString(); + QString divider; + if (!from.isEmpty() && from != QStringLiteral("hclk") && + r.contains(from + QStringLiteral("_div"))) + divider = QStringLiteral("÷ ") + factor(r.value(from + QStringLiteral("_div"))); + else if (r.value(QStringLiteral("ahb_div")).toDouble() > 1) + divider = QStringLiteral("÷ ") + factor(r.value(QStringLiteral("ahb_div"))); + m_nodes.append({QStringLiteral("bus:") + name, + tr("Bus %1").arg(name.toUpper()), + formatHz(hz), + max > 0 ? tr("limit %1").arg(formatHz(max)) : QString(), + {}, + max > 0 ? hz / max : -1, + column, + first + i}); + m_edges.append({QStringLiteral("sys"), QStringLiteral("bus:") + name, divider}); + } + + if (r.contains(QStringLiteral("flash_wait_states"))) + m_notes.append( + tr("Flash wait states: %1.").arg(factor(r.value(QStringLiteral("flash_wait_states"))))); + const QJsonObject scale = r.value(QStringLiteral("voltage_scale")).toObject(); + if (!scale.isEmpty()) + m_notes.append( + tr("Regulator: %1 (VOS %2), over-drive %3.") + .arg(scale.value(QStringLiteral("name")).toString(), + factor(scale.value(QStringLiteral("vos"))), + scale.value(QStringLiteral("overdrive")).toBool() ? tr("on") : tr("off"))); + const QJsonObject timer = m_clocks.value(QStringLiteral("timer")).toObject(); + if (!timer.isEmpty()) + m_notes.append(tr("Kernel tick timer: %1 at %2.") + .arg(timer.value(QStringLiteral("source")).toString(), + formatHz(timer.value(QStringLiteral("hz")).toDouble()))); + m_canvas->relayout(); +} + +} // namespace emblinkstudio diff --git a/app/src/clocktreeview.h b/app/src/clocktreeview.h new file mode 100644 index 0000000..3128046 --- /dev/null +++ b/app/src/clocktreeview.h @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file clocktreeview.h + * @brief ClockTreeView: the clock tree the generator resolved, drawn (spec section 7). + * + * @details + * Draws the path from the source oscillator to the buses, left to right: the source, + * then the PLL when there is one (its input after the M divider, the VCO after the N + * multiplier, and its Q output), the system clock after the P divider (or the + * RP2350's two post-dividers), and each bus with its divider and its limit, a bar + * showing how close the bus runs to it. Boards without a PLL go from the source + * straight to the system clock. Below, the generator's notes: flash wait states, the + * regulator, the kernel's tick timer. + * + * Every frequency, factor and limit is the generator's (board.clocks: resolved, + * limits, timer); nothing is computed here. nodes(), edges() and notes() give what is + * drawn, for the golden tests of stage S2. + * + * @see format.h; build_report.md's "Clock tree" in each board's generated/ + * @author Junior Deogracias + * @date 2026-11-13 (created) + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace emblinkstudio +{ + +class ClockTreeView : public QScrollArea +{ + Q_OBJECT + + public: + struct Node { + QString id; // "source", "pll_in", "vco", "pll_q", "sys", "bus:" + QString title; + QString value; + QString detail; + QString tooltip; + double load = -1; // the frequency over its limit, when there is one + int column = 0; + double row = 0; + }; + struct Edge { + QString from; + QString to; + QString label; // "÷ 8", "× 360" + }; + + explicit ClockTreeView(QWidget *parent = nullptr); + + void setClocks(const QJsonObject &clocks); + + QList nodes() const + { + return m_nodes; + } + QList edges() const + { + return m_edges; + } + QStringList notes() const + { + return m_notes; + } + // The node with `id`, or an empty one. + Node node(const QString &id) const; + + protected: + void changeEvent(QEvent *event) override; + + private: + class Canvas; + void build(); + + Canvas *m_canvas = nullptr; + QJsonObject m_clocks; + QList m_nodes; + QList m_edges; + QStringList m_notes; +}; + +} // namespace emblinkstudio diff --git a/app/src/devicesview.cpp b/app/src/devicesview.cpp new file mode 100644 index 0000000..bdcc023 --- /dev/null +++ b/app/src/devicesview.cpp @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file devicesview.cpp + * @brief Implementation of DevicesView: the list, and the chosen device's fields. + * + * @details + * The list keeps the generator's order, which is the initialization order; it is not + * sortable, so that order is never lost. The level is written in capitals, EARLY or + * KERNEL, as the kernel's names for the levels are. A device with no dependency shows a + * dash. + * + * @see devicesview.h + * @author Junior Deogracias + * @date 2026-11-13 (created) + */ + +#include "devicesview.h" +#include "format.h" +#include "theme.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace emblinkstudio +{ + +DevicesView::DevicesView(QWidget *parent) : QWidget(parent) +{ + setObjectName(QStringLiteral("viewContent")); + setAttribute(Qt::WA_StyledBackground, true); + const Theme &theme = Theme::current(); + + auto *layout = new QHBoxLayout(this); + layout->setContentsMargins(8, 8, 8, 8); + auto *split = new QSplitter(Qt::Horizontal, this); + layout->addWidget(split); + + m_list = new QTreeWidget(split); + m_list->setObjectName(QStringLiteral("problems")); // the same quiet list style + m_list->setColumnCount(5); + m_list->setRootIsDecorated(false); + m_list->setUniformRowHeights(true); + m_list->setSortingEnabled(false); + m_list->setFont(theme.font(QStringLiteral("bodySmall"))); + m_list->header()->setSectionResizeMode(QHeaderView::ResizeToContents); + m_list->header()->setStretchLastSection(true); + + auto *side = new QWidget(split); + auto *sideLayout = new QVBoxLayout(side); + sideLayout->setContentsMargins(12, 4, 4, 4); + m_title = new QLabel(side); + m_title->setFont(theme.font(QStringLiteral("title3"))); + sideLayout->addWidget(m_title); + m_fields = new QTreeWidget(side); + m_fields->setObjectName(QStringLiteral("problems")); + m_fields->setColumnCount(2); + m_fields->setRootIsDecorated(false); + m_fields->setFont(theme.font(QStringLiteral("codeMeta"))); + m_fields->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + m_fields->header()->setStretchLastSection(true); + sideLayout->addWidget(m_fields, 1); + split->setStretchFactor(0, 3); + split->setStretchFactor(1, 2); + + connect(m_list, &QTreeWidget::currentItemChanged, this, [this] { showFields(); }); + render(); +} + +void DevicesView::setDevices(const QJsonArray &devices) +{ + m_devices = devices; + render(); +} + +QList DevicesView::rows() const +{ + QList out; + for (int i = 0; i < m_list->topLevelItemCount(); ++i) { + QStringList cells; + for (int c = 0; c < m_list->columnCount(); ++c) + cells.append(m_list->topLevelItem(i)->text(c)); + out.append(cells); + } + return out; +} + +QList DevicesView::fields() const +{ + QList out; + for (int i = 0; i < m_fields->topLevelItemCount(); ++i) + out.append({m_fields->topLevelItem(i)->text(0), m_fields->topLevelItem(i)->text(1)}); + return out; +} + +void DevicesView::select(int row) +{ + if (row >= 0 && row < m_list->topLevelItemCount()) + m_list->setCurrentItem(m_list->topLevelItem(row)); +} + +void DevicesView::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + render(); + QWidget::changeEvent(event); +} + +void DevicesView::render() +{ + const int current = m_list->indexOfTopLevelItem(m_list->currentItem()); + m_list->setHeaderLabels( + {tr("Device"), tr("Class"), tr("Compatible"), tr("Level"), tr("Depends on")}); + m_fields->setHeaderLabels({tr("Field"), tr("Value")}); + m_list->clear(); + const Theme &theme = Theme::current(); + for (const QJsonValue &v : std::as_const(m_devices)) { + const QJsonObject d = v.toObject(); + const QString name = d.value(QStringLiteral("name")).toString(); + const QString peripheral = d.value(QStringLiteral("peripheral")).toString(); + QString compatible = d.value(QStringLiteral("compatible")).toString(); + if (!peripheral.isEmpty() && peripheral != name) + compatible += QStringLiteral(" (%1)").arg(peripheral); + QStringList deps; + for (const QJsonValue &dep : d.value(QStringLiteral("deps")).toArray()) + deps.append(dep.toString()); + auto *item = new QTreeWidgetItem( + {name, d.value(QStringLiteral("class")).toString(), compatible, + d.value(QStringLiteral("level")).toString().toUpper(), + deps.isEmpty() ? QStringLiteral("—") : deps.join(QStringLiteral(", "))}); + item->setFont(2, theme.font(QStringLiteral("codeMeta"))); + item->setForeground(2, theme.color(QStringLiteral("text.secondary"))); + m_list->addTopLevelItem(item); + } + if (m_list->topLevelItemCount() > 0) + m_list->setCurrentItem( + m_list->topLevelItem(qBound(0, current, m_list->topLevelItemCount() - 1))); + showFields(); +} + +void DevicesView::showFields() +{ + m_fields->clear(); + const int row = m_list->indexOfTopLevelItem(m_list->currentItem()); + if (row < 0 || row >= m_devices.size()) { + m_title->setText(m_devices.isEmpty() ? tr("Open a generated board to see its devices.") + : QString()); + return; + } + const QJsonObject d = m_devices.at(row).toObject(); + m_title->setText(d.value(QStringLiteral("name")).toString()); + const QJsonObject fields = d.value(QStringLiteral("fields")).toObject(); + for (auto it = fields.begin(); it != fields.end(); ++it) + m_fields->addTopLevelItem( + new QTreeWidgetItem({it.key(), formatField(it.key(), it.value())})); +} + +} // namespace emblinkstudio diff --git a/app/src/devicesview.h b/app/src/devicesview.h new file mode 100644 index 0000000..786e875 --- /dev/null +++ b/app/src/devicesview.h @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file devicesview.h + * @brief DevicesView: the board's devices in initialization order (spec section 7). + * + * @details + * A list of the devices the generator resolved (board.describe: devices), in the order + * the kernel initializes them (SPEC-016 §4): each device's name, class, compatible + * string (with its peripheral when it is not the device's own name, as board.md writes + * it), level and the devices it depends on. Choosing one shows its binding fields + * beside the list: addresses in hexadecimal, frequencies in Hz units, DMA channels and + * pins as the generator gives them. rows() gives the list's cells, for the golden + * tests of stage S2. + * + * @see format.h; board.md's "Devices" + * @author Junior Deogracias + * @date 2026-11-13 (created) + */ + +#pragma once + +#include "format.h" + +#include +#include +#include +#include + +class QLabel; +class QTreeWidget; + +namespace emblinkstudio +{ + +class DevicesView : public QWidget +{ + Q_OBJECT + + public: + explicit DevicesView(QWidget *parent = nullptr); + + void setDevices(const QJsonArray &devices); + + // Each device's cells: name, class, compatible, level, depends on. + QList rows() const; + // The chosen device's fields, as shown: (field, value). + QList fields() const; + void select(int row); + + protected: + void changeEvent(QEvent *event) override; + + private: + void render(); + void showFields(); + + QJsonArray m_devices; + QTreeWidget *m_list = nullptr; + QTreeWidget *m_fields = nullptr; + QLabel *m_title = nullptr; +}; + +} // namespace emblinkstudio diff --git a/app/src/format.cpp b/app/src/format.cpp new file mode 100644 index 0000000..a2fc103 --- /dev/null +++ b/app/src/format.cpp @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file format.cpp + * @brief Implementation of the views' number formats. + * + * @details + * Uses the default QLocale, which Language sets with the interface's language, so a + * change of language rewrites every value the next time a view renders. + * + * @see format.h + * @author Junior Deogracias + * @date 2026-11-13 (created) + */ + +#include "format.h" + +#include +#include +#include + +namespace emblinkstudio +{ + +namespace +{ + +// The interface's locale, for its decimal mark, without group separators: 1500 MHz, as +// datasheets and the generator write technical values. +QLocale technical() +{ + QLocale locale; + locale.setNumberOptions(QLocale::OmitGroupSeparator); + return locale; +} + +} // namespace + +QString formatHz(double hz) +{ + const QLocale locale = technical(); + if (hz >= 1e6) + return locale.toString(hz / 1e6, 'g', 6) + QStringLiteral(" MHz"); + if (hz >= 1e3) + return locale.toString(hz / 1e3, 'g', 6) + QStringLiteral(" kHz"); + return locale.toString(hz, 'g', 6) + QStringLiteral(" Hz"); +} + +QString formatBytes(double bytes) +{ + const QLocale locale = technical(); + if (bytes >= 1024.0 * 1024.0) + return locale.toString(bytes / (1024.0 * 1024.0), 'g', 4) + QStringLiteral(" MB"); + if (bytes >= 1024.0) + return locale.toString(bytes / 1024.0, 'g', 4) + QStringLiteral(" KB"); + return locale.toString(bytes, 'g', 6) + QStringLiteral(" B"); +} + +QString formatHex(double value) +{ + return QStringLiteral("0x") + + QStringLiteral("%1").arg(qulonglong(value), 8, 16, QLatin1Char('0')).toUpper(); +} + +QString formatField(const QString &key, const QJsonValue &value) +{ + if (value.isObject()) { + QStringList parts; + const QJsonObject o = value.toObject(); + for (auto it = o.begin(); it != o.end(); ++it) + parts.append(it.key() + QLatin1Char(' ') + formatField(it.key(), it.value())); + return parts.join(QStringLiteral(", ")); + } + if (value.isArray()) { + QStringList parts; + for (const QJsonValue &v : value.toArray()) + parts.append(formatField(key, v)); + return parts.join(QStringLiteral(", ")); + } + if (value.isBool()) + return value.toBool() ? QStringLiteral("true") : QStringLiteral("false"); + if (value.isDouble()) { + if (key == QStringLiteral("base") || key.endsWith(QStringLiteral("_base"))) + return formatHex(value.toDouble()); + if (key.endsWith(QStringLiteral("_hz")) || key == QStringLiteral("hz")) + return formatHz(value.toDouble()); + return QString::number(value.toDouble(), 'g', 12); + } + if (value.isNull()) + return QStringLiteral("—"); + return value.toString(); +} + +} // namespace emblinkstudio diff --git a/app/src/format.h b/app/src/format.h new file mode 100644 index 0000000..c5ec3e2 --- /dev/null +++ b/app/src/format.h @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file format.h + * @brief How the views write the core's numbers: frequencies, sizes and addresses. + * + * @details + * The views compute nothing (spec section 4); they only write the generator's values + * for reading. Frequencies and sizes follow the interface's language (180 MHz, 1,5 MB + * in French); addresses are hexadecimal and the same in every language (tokens: + * locale.numbers). + * + * @see boardview.h, clocktreeview.h, memoryview.h, devicesview.h + * @author Junior Deogracias + * @date 2026-11-13 (created) + */ + +#pragma once + +#include +#include + +namespace emblinkstudio +{ + +// "180 MHz", "8 MHz", "32.768 kHz". +QString formatHz(double hz); +// "512 KB", "16 KB", "1.5 MB", "512 B" (1 KB is 1,024 bytes, as the generator counts). +QString formatBytes(double bytes); +// "0x08000000": eight hexadecimal digits, more when the value needs them. +QString formatHex(double value); +// A field of the generator's model as the views write it: base addresses in hexadecimal, +// *_hz as a frequency, objects as "key value" pairs, lists joined with commas. +QString formatField(const QString &key, const QJsonValue &value); + +} // namespace emblinkstudio diff --git a/app/src/main.cpp b/app/src/main.cpp index 97833e0..02c2142 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -19,6 +19,7 @@ * --language use this language for this run, without saving it * --stage open on this stage * --open open this board of an EmbLinkRTOS checkout + * --view bring a view to the front: board, clocks, memory, devices * --screenshot save a picture of the window to , then quit * * @see mainwindow.h, theme.h, language.h @@ -58,7 +59,11 @@ int main(int argc, char *argv[]) QStringLiteral("open"), QStringLiteral("Open , a board directory of an EmbLinkRTOS checkout."), QStringLiteral("board")); - parser.addOptions({languageOption, stageOption, openOption, screenshotOption}); + const QCommandLineOption viewOption( + QStringLiteral("view"), + QStringLiteral("Bring the view to the front: board, clocks, memory, devices."), + QStringLiteral("id")); + parser.addOptions({languageOption, stageOption, openOption, viewOption, screenshotOption}); parser.process(app); emblinkstudio::Language language(&app); @@ -81,6 +86,8 @@ int main(int argc, char *argv[]) window.setStage(parser.value(stageOption)); if (parser.isSet(openOption)) window.openBoard(parser.value(openOption)); + if (parser.isSet(viewOption)) + window.showView(parser.value(viewOption)); window.show(); if (parser.isSet(screenshotOption)) { diff --git a/app/src/mainwindow.cpp b/app/src/mainwindow.cpp index 9aaf60f..69ae81a 100644 --- a/app/src/mainwindow.cpp +++ b/app/src/mainwindow.cpp @@ -28,8 +28,11 @@ */ #include "boardview.h" +#include "clocktreeview.h" +#include "devicesview.h" #include "language.h" #include "mainwindow.h" +#include "memoryview.h" #include "problemsview.h" #include "segmentedcontrol.h" #include "session.h" @@ -114,11 +117,21 @@ MainWindow::MainWindow(Language *language, QWidget *parent) m_session = new Session(&m_core, this); m_boardView = new BoardView; + m_clockView = new ClockTreeView; + m_memoryView = new MemoryView; + m_devicesView = new DevicesView; m_problems = new ProblemsView; // The ids name the views in saved layouts: keep them stable. - m_workbench->addView(QStringLiteral("board"), QString(), m_boardView, - ads::CenterDockWidgetArea); + ads::CDockWidget *board = m_workbench->addView(QStringLiteral("board"), QString(), m_boardView, + ads::CenterDockWidgetArea); + m_workbench->addView(QStringLiteral("clocks"), QString(), m_clockView, + ads::CenterDockWidgetArea, board); + m_workbench->addView(QStringLiteral("memory"), QString(), m_memoryView, + ads::CenterDockWidgetArea, board); + m_workbench->addView(QStringLiteral("devices"), QString(), m_devicesView, + ads::CenterDockWidgetArea, board); + board->setAsCurrentTab(); ads::CDockWidget *problems = m_workbench->addView(QStringLiteral("problems"), QString(), m_problems, ads::BottomDockWidgetArea); m_workbench->addView(QStringLiteral("coreLog"), QString(), m_log, ads::BottomDockWidgetArea, @@ -126,6 +139,8 @@ MainWindow::MainWindow(Language *language, QWidget *parent) m_workbench->addView(QStringLiteral("core"), QString(), coreView, ads::BottomDockWidgetArea, problems); problems->setAsCurrentTab(); + // The board's views take most of the height; the panel below, a third of it at most. + m_workbench->manager()->setSplitterSizes(board->dockAreaWidget(), {560, 220}); m_workbench->captureDefaultLayout(); buildStageBar(); @@ -298,9 +313,12 @@ void MainWindow::retranslate() const QList views = m_workbench->views(); views.at(0)->setWindowTitle(tr("Board")); - views.at(1)->setWindowTitle(tr("Problems")); - views.at(2)->setWindowTitle(tr("Core log")); - views.at(3)->setWindowTitle(tr("Core")); + views.at(1)->setWindowTitle(tr("Clock tree")); + views.at(2)->setWindowTitle(tr("Memory")); + views.at(3)->setWindowTitle(tr("Devices")); + views.at(4)->setWindowTitle(tr("Problems")); + views.at(5)->setWindowTitle(tr("Core log")); + views.at(6)->setWindowTitle(tr("Core")); for (ads::CDockWidget *v : views) v->toggleViewAction()->setText(v->windowTitle()); m_restart->setText(tr("&Restart the core")); @@ -354,6 +372,15 @@ void MainWindow::openBoard(const QString &path) m_pendingOpen = path; } +void MainWindow::showView(const QString &id) +{ + for (ads::CDockWidget *view : m_workbench->views()) + if (view->objectName() == id) { + view->toggleView(true); + view->setAsCurrentTab(); + } +} + void MainWindow::chooseBoard() { QSettings settings; @@ -413,6 +440,9 @@ void MainWindow::showModel() { m_boardView->setModel(m_session->status(), m_session->describe(), m_session->clocks(), m_session->memory(), m_session->pins()); + m_clockView->setClocks(m_session->clocks()); + m_memoryView->setMemory(m_session->memory()); + m_devicesView->setDevices(m_session->describe().value(QStringLiteral("devices")).toArray()); } void MainWindow::startCore() diff --git a/app/src/mainwindow.h b/app/src/mainwindow.h index f4b65b3..8ad1584 100644 --- a/app/src/mainwindow.h +++ b/app/src/mainwindow.h @@ -15,7 +15,8 @@ * (Ctrl elsewhere); and below it the Workbench, where every view is a card. Each stage * keeps its own layout. * - * The views so far: Board, the open board's model; Problems, the generator's + * The views so far: Board, the open board's model; Clock tree, Memory and Devices, + * drawn from the generator's model (stage S2); Problems, the generator's * diagnostics, each linked to its file; Core, whether EmbLink Studio Core is connected, * with a restart when it fails or stops; and the core's log. The window owns the * CoreClient and the Session (the open board) for the life of the application. Open @@ -50,7 +51,10 @@ namespace emblinkstudio { class BoardView; +class ClockTreeView; +class DevicesView; class Language; +class MemoryView; class ProblemsView; class SegmentedControl; class Session; @@ -69,6 +73,8 @@ class MainWindow : public QMainWindow QString stage() const; // Opens a board directory of an EmbLinkRTOS checkout, once the core is ready. void openBoard(const QString &path); + // Brings the view with this id to the front: "board", "clocks", "memory", "devices", ... + void showView(const QString &id); Session *session() const { return m_session; @@ -131,6 +137,9 @@ class MainWindow : public QMainWindow QPlainTextEdit *m_log = nullptr; Session *m_session = nullptr; BoardView *m_boardView = nullptr; + ClockTreeView *m_clockView = nullptr; + MemoryView *m_memoryView = nullptr; + DevicesView *m_devicesView = nullptr; ProblemsView *m_problems = nullptr; QString m_pendingOpen; std::function m_statusText; diff --git a/app/src/memoryview.cpp b/app/src/memoryview.cpp new file mode 100644 index 0000000..a5cb7ad --- /dev/null +++ b/app/src/memoryview.cpp @@ -0,0 +1,256 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file memoryview.cpp + * @brief Implementation of MemoryView: the groups, and the partition strip. + * + * @details + * Each row is a name on the left and its cells on the right in the code font. The + * partition strip gives each partition a share of its width equal to its share of the + * partitions' total, a reserved one striped; the shares are drawn, not shown as + * numbers. + * + * @see memoryview.h + * @author Junior Deogracias + * @date 2026-11-13 (created) + */ + +#include "format.h" +#include "memoryview.h" +#include "theme.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace emblinkstudio +{ + +namespace +{ + +// The partitions, side by side, each as wide as its share of the whole. +class PartitionStrip : public QWidget +{ + public: + struct Part { + QString name; + double size; + bool reserved; + }; + + PartitionStrip(QList parts, QWidget *parent) : QWidget(parent), m_parts(std::move(parts)) + { + setMinimumHeight(40); + } + + protected: + void paintEvent(QPaintEvent *) override + { + const Theme &theme = Theme::current(); + QPainter p(this); + p.setRenderHint(QPainter::Antialiasing); + double total = 0; + for (const Part &part : m_parts) + total += part.size; + if (total <= 0) + return; + const QColor colors[] = {theme.color(QStringLiteral("accent.base")), + theme.color(QStringLiteral("peripheral.i2c")), + theme.color(QStringLiteral("peripheral.gpioOut")), + theme.color(QStringLiteral("peripheral.spi"))}; + const QRectF area = QRectF(rect()).adjusted(4, 6, -4, -6); + double x = area.left(); + p.setFont(theme.font(QStringLiteral("codeMeta"))); + for (int i = 0; i < m_parts.size(); ++i) { + const double w = area.width() * m_parts.at(i).size / total; + const QRectF r(x, area.top(), qMax(2.0, w - 2), area.height()); + QPainterPath path; + path.addRoundedRect(r, 6, 6); + QColor fill = colors[i % 4]; + fill.setAlphaF(0.22); + p.fillPath(path, fill); + if (m_parts.at(i).reserved) { + p.save(); + p.setClipPath(path); + p.setPen(QPen(theme.color(QStringLiteral("line.strong")), 1)); + for (double s = r.left() - r.height(); s < r.right(); s += 6) + p.drawLine(QPointF(s, r.bottom()), QPointF(s + r.height(), r.top())); + p.restore(); + } + p.setPen(QPen(colors[i % 4], 1)); + p.drawPath(path); + p.setPen(theme.color(QStringLiteral("text.primary"))); + p.drawText(r.adjusted(8, 0, -8, 0), Qt::AlignVCenter | Qt::AlignLeft, + QFontMetricsF(p.font()).elidedText(m_parts.at(i).name, Qt::ElideRight, + r.width() - 16)); + x += w; + } + } + + private: + QList m_parts; +}; + +QString joined(const QJsonValue &v, const QString &sep = QStringLiteral(", ")) +{ + QStringList out; + for (const QJsonValue &item : v.toArray()) + out.append(item.isString() ? item.toString() : QString::number(item.toDouble(), 'g', 12)); + return out.join(sep); +} + +} // namespace + +MemoryView::MemoryView(QWidget *parent) : QScrollArea(parent) +{ + setObjectName(QStringLiteral("viewContent")); + setAttribute(Qt::WA_StyledBackground, true); + setWidgetResizable(true); + setFrameShape(QFrame::NoFrame); + m_content = new QWidget(this); + m_content->setObjectName(QStringLiteral("viewContent")); + m_content->setAttribute(Qt::WA_StyledBackground, true); + m_layout = new QVBoxLayout(m_content); + m_layout->setContentsMargins(18, 10, 18, 20); + m_layout->setSpacing(6); + setWidget(m_content); + render(); +} + +void MemoryView::setMemory(const QJsonObject &memory) +{ + m_memory = memory; + render(); +} + +void MemoryView::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + render(); + QScrollArea::changeEvent(event); +} + +void MemoryView::addGroup(const QString &title, Group group, const QList &rows, + QWidget *above) +{ + m_rows.insert(int(group), rows); + if (rows.isEmpty()) + return; + const Theme &theme = Theme::current(); + auto *caption = new QLabel(title, m_content); + caption->setProperty("role", QStringLiteral("caption")); + caption->setFont(theme.font(QStringLiteral("caption"))); + caption->setContentsMargins(4, 12, 0, 4); + m_layout->addWidget(caption); + if (above) + m_layout->addWidget(above); + + auto *frame = new QFrame(m_content); + frame->setProperty("role", QStringLiteral("group")); + auto *column = new QVBoxLayout(frame); + column->setContentsMargins(0, 0, 0, 0); + column->setSpacing(0); + for (int i = 0; i < rows.size(); ++i) { + const QStringList &cells = rows.at(i); + auto *row = new QWidget(frame); + row->setProperty("role", QStringLiteral("row")); + row->setProperty("first", i == 0); + row->setAttribute(Qt::WA_StyledBackground, true); + auto *line = new QHBoxLayout(row); + line->setContentsMargins(12, 8, 12, 8); + line->setSpacing(18); + auto *name = new QLabel(cells.value(0), row); + name->setFont(theme.font(QStringLiteral("bodySmall"))); + line->addWidget(name, 1); + for (int c = 1; c < cells.size(); ++c) { + auto *cell = new QLabel(cells.at(c), row); + cell->setFont(theme.font(QStringLiteral("codeMeta"))); + cell->setProperty("role", + c == 1 ? QStringLiteral("secondary") : QStringLiteral("quiet")); + cell->setTextInteractionFlags(Qt::TextSelectableByMouse); + cell->setAlignment(Qt::AlignRight | Qt::AlignVCenter); + cell->setMinimumWidth(c == cells.size() - 1 ? 150 : 90); + line->addWidget(cell); + } + column->addWidget(row); + } + m_layout->addWidget(frame); +} + +void MemoryView::render() +{ + while (QLayoutItem *item = m_layout->takeAt(0)) { + delete item->widget(); + delete item; + } + m_rows.clear(); + if (m_memory.isEmpty()) { + auto *empty = new QLabel(tr("Open a generated board to see its memory."), m_content); + empty->setProperty("role", QStringLiteral("secondary")); + m_layout->addWidget(empty); + m_layout->addStretch(); + return; + } + + QList regions; + for (const QJsonValue &v : m_memory.value(QStringLiteral("regions")).toArray()) { + const QJsonObject region = v.toObject(); + regions.append({region.value(QStringLiteral("name")).toString(), + formatHex(region.value(QStringLiteral("base")).toDouble()), + formatBytes(region.value(QStringLiteral("size")).toDouble()), + joined(region.value(QStringLiteral("attrs")))}); + } + addGroup(tr("Memory map"), Group::Regions, regions); + + QList partitions; + QList parts; + for (const QJsonValue &v : m_memory.value(QStringLiteral("partitions")).toArray()) { + const QJsonObject part = v.toObject(); + QString units; + if (part.contains(QStringLiteral("sectors"))) + units = tr("sectors %1").arg(joined(part.value(QStringLiteral("sectors")))); + else if (part.value(QStringLiteral("pages")).toArray().size() == 2) + units = tr("pages %1 to %2") + .arg(part.value(QStringLiteral("pages")).toArray().at(0).toInt()) + .arg(part.value(QStringLiteral("pages")).toArray().at(1).toInt()); + if (units.isEmpty()) + units = QStringLiteral("—"); // no erase units given, as board.md writes it + const QString name = part.value(QStringLiteral("name")).toString(); + const bool reserved = part.value(QStringLiteral("reserved")).toBool(); + partitions.append({reserved ? tr("%1 (reserved)").arg(name) : name, + formatHex(part.value(QStringLiteral("base")).toDouble()), + formatBytes(part.value(QStringLiteral("size")).toDouble()), units}); + parts.append({name, part.value(QStringLiteral("size")).toDouble(), reserved}); + } + addGroup(tr("Flash partitions"), Group::Partitions, partitions, + parts.isEmpty() ? nullptr : new PartitionStrip(parts, m_content)); + + QList image; + const QJsonObject linker = m_memory.value(QStringLiteral("linker")).toObject(); + const QJsonObject flash = linker.value(QStringLiteral("flash")).toObject(); + if (!flash.isEmpty()) + image.append({QStringLiteral("FLASH"), + formatHex(flash.value(QStringLiteral("origin")).toDouble()), + formatBytes(flash.value(QStringLiteral("length")).toDouble())}); + const QJsonObject ram = linker.value(QStringLiteral("ram")).toObject(); + if (!ram.isEmpty()) { + const QString spans = joined(ram.value(QStringLiteral("regions")), QStringLiteral(" + ")); + image.append( + {spans.isEmpty() ? QStringLiteral("RAM") : QStringLiteral("RAM (%1)").arg(spans), + formatHex(ram.value(QStringLiteral("origin")).toDouble()), + formatBytes(ram.value(QStringLiteral("length")).toDouble())}); + } + addGroup(tr("Image layout"), Group::Image, image); + m_layout->addStretch(); +} + +} // namespace emblinkstudio diff --git a/app/src/memoryview.h b/app/src/memoryview.h new file mode 100644 index 0000000..404c107 --- /dev/null +++ b/app/src/memoryview.h @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file memoryview.h + * @brief MemoryView: the chip's memory, its flash partitions and the image layout. + * + * @details + * Three groups, from board.memory: the chip's regions (name, base address, size and + * attributes); the flash partitions, drawn as a strip in proportion to their sizes, + * each with its erase units (sectors, or a range of pages); and the image layout the + * linker uses (FLASH and RAM, with the regions RAM spans). Every value is the + * generator's, written as board.md and build_report.md write it. rows() gives each + * group's rows, for the golden tests of stage S2. The Memory view of spec section 7. + * + * @see format.h; board.md's "Memory map" and "Flash partitions", build_report.md's + * "Image layout" + * @author Junior Deogracias + * @date 2026-11-13 (created) + */ + +#pragma once + +#include +#include +#include +#include +#include + +class QVBoxLayout; + +namespace emblinkstudio +{ + +class MemoryView : public QScrollArea +{ + Q_OBJECT + + public: + enum class Group { + Regions, + Partitions, + Image + }; + + explicit MemoryView(QWidget *parent = nullptr); + + void setMemory(const QJsonObject &memory); + + // Each row's cells, as shown: Regions (name, base, size, attributes), Partitions (name, + // base, size, erase units), Image (memory, origin, length). + QList rows(Group group) const + { + return m_rows.value(int(group)); + } + + protected: + void changeEvent(QEvent *event) override; + + private: + void render(); + void addGroup(const QString &title, Group group, const QList &rows, + QWidget *above = nullptr); + + QWidget *m_content = nullptr; + QVBoxLayout *m_layout = nullptr; + QJsonObject m_memory; + QHash> m_rows; +}; + +} // namespace emblinkstudio diff --git a/app/src/theme.cpp b/app/src/theme.cpp index 0c7d641..aa5e732 100644 --- a/app/src/theme.cpp +++ b/app/src/theme.cpp @@ -315,9 +315,11 @@ QString Theme::styleSheet() const s += QStringLiteral("QTreeWidget#problems { background: transparent; border: 0; }\n" "QTreeWidget#problems::item { padding: 4px 2px; border-radius: 6px; }\n" "QTreeWidget#problems::item:selected { background: %1; color: %2; }\n" + "QTreeWidget#problems QHeaderView { background: transparent; border: 0; " + "border-bottom: 1px solid %4; }\n" "QTreeWidget#problems QHeaderView::section { background: transparent; " - "color: %3; border: 0; padding: 2px 4px; }\n") - .arg(c("fill.selected"), c("text.strong"), c("text.quiet")); + "color: %3; border: 0; padding: 3px 6px; }\n") + .arg(c("fill.selected"), c("text.strong"), c("text.quiet"), c("line.hairline")); s += QStringLiteral("QMenu { background: %1; border: 1px solid %2; border-radius: %3px; " "padding: 6px; }\n" "QMenu::item { padding: 5px 14px; border-radius: 6px; }\n" diff --git a/app/src/workbench.h b/app/src/workbench.h index 142de21..ad996a0 100644 --- a/app/src/workbench.h +++ b/app/src/workbench.h @@ -89,7 +89,7 @@ class Workbench : public QObject } // Bumped when a change to the views would make old saved layouts misleading. - static constexpr int kLayoutVersion = 2; // 2: Board and Problems join the views + static constexpr int kLayoutVersion = 3; // 3: Clock tree, Memory and Devices join the views signals: void namedLayoutsChanged(); diff --git a/app/tests/tst_golden.cpp b/app/tests/tst_golden.cpp new file mode 100644 index 0000000..52017d4 --- /dev/null +++ b/app/tests/tst_golden.cpp @@ -0,0 +1,303 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2026 Junior Deogracias +// +// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS. +// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root. + +/** + * @file tst_golden.cpp + * @brief Stage S2's golden test: every value the views show is the generator's. + * + * @details + * "For both boards, a golden test finds every value in the views equal to hw.json and + * to the generator's board.md and build_report.md" (spec section 8, S2). + * + * For the RTOS's nucleo_f446re and pico2_w, the test opens the board through the real + * core, as the application does, renders the Board, Clock tree, Memory and Devices + * views, and compares what each shows with the board's hw.json and with the tables + * and lines of its board.md and build_report.md, which the generator writes from the + * same model. EMBLINK_STUDIO_TEST_RTOS names the checkout; CI checks the RTOS out at a + * pinned commit, and the test is skipped where it is not set. Runs in English. + * + * @see boardview.h, clocktreeview.h, memoryview.h, devicesview.h + * @author Junior Deogracias + * @date 2026-11-13 (created) + */ + +#include "boardview.h" +#include "clocktreeview.h" +#include "coreclient.h" +#include "devicesview.h" +#include "format.h" +#include "memoryview.h" +#include "session.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace emblinkstudio; + +namespace +{ + +constexpr int kTimeoutMs = 20000; + +QString rtos() +{ + return qEnvironmentVariable("EMBLINK_STUDIO_TEST_RTOS"); +} + +QString read(const QString &path) +{ + QFile file(path); + // A checkout made on Windows may have CRLF line ends. + return file.open(QIODevice::ReadOnly) + ? QString::fromUtf8(file.readAll()) + .replace(QStringLiteral("\r\n"), QStringLiteral("\n")) + : QString(); +} + +// The rows of the Markdown table under `heading`, without its header, backticks removed. +QList table(const QString &markdown, const QString &heading) +{ + QList rows; + const QStringList lines = markdown.split(QLatin1Char('\n')); + int i = int(lines.indexOf(heading)); + if (i < 0) + return rows; + while (++i < lines.size() && !lines.at(i).startsWith(QLatin1Char('|'))) + ; + i += 2; // the header and its separator + for (; i < lines.size() && lines.at(i).startsWith(QLatin1Char('|')); ++i) { + QStringList cells = lines.at(i).split(QLatin1Char('|')); + cells.removeFirst(); + cells.removeLast(); + for (QString &c : cells) + c = c.trimmed().remove(QLatin1Char('`')); + rows.append(cells); + } + return rows; +} + +// "512K", "16M", "4032K" as board.md writes sizes. +double bytes(const QString &size) +{ + if (size.endsWith(QLatin1Char('K'))) + return size.chopped(1).toDouble() * 1024; + if (size.endsWith(QLatin1Char('M'))) + return size.chopped(1).toDouble() * 1024 * 1024; + return size.toDouble(); +} + +QJsonObject at(const QJsonObject &o, const QString &path) +{ + QJsonObject node = o; + for (const QString &part : path.split(QLatin1Char('.'))) + node = node.value(part).toObject(); + return node; +} + +} // namespace + +class TestGolden : public QObject +{ + Q_OBJECT + + private: + QTemporaryDir m_config; + CoreClient *m_core = nullptr; + Session *m_session = nullptr; + QJsonObject m_hw; + QString m_boardMd; + QString m_report; + + void open(const QString &board) + { + const QString dir = rtos() + QStringLiteral("/boards/") + board; + m_hw = QJsonDocument::fromJson(read(dir + QStringLiteral("/generated/hw.json")).toUtf8()) + .object(); + m_boardMd = read(dir + QStringLiteral("/generated/board.md")); + m_report = read(dir + QStringLiteral("/generated/build_report.md")); + QVERIFY(!m_hw.isEmpty() && !m_boardMd.isEmpty() && !m_report.isEmpty()); + QSignalSpy model(m_session, &Session::modelChanged); + m_session->open(dir); + QVERIFY(model.wait(kTimeoutMs)); + QVERIFY(!m_session->describe().isEmpty()); + } + + private slots: + void initTestCase() + { + if (rtos().isEmpty()) + QSKIP("EMBLINK_STUDIO_TEST_RTOS is not set"); + QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); + QVERIFY(m_config.isValid()); + m_core = new CoreClient(this); + CoreClient::Launch launch = CoreClient::defaultLaunch(); + launch.environment.insert(QStringLiteral("EMBLINK_STUDIO_CONFIG_DIR"), m_config.path()); + QSignalSpy ready(m_core, &CoreClient::ready); + m_core->start(launch); + QVERIFY(ready.wait(kTimeoutMs)); + m_session = new Session(m_core, this); + } + + void cleanupTestCase() + { + if (m_core) + m_core->stop(); + } + + void views_data() + { + QTest::addColumn("board"); + QTest::newRow("nucleo_f446re") << QStringLiteral("st/nucleo_f446re"); + QTest::newRow("pico2_w") << QStringLiteral("rpi/pico2_w"); + } + + void views() + { + QFETCH(QString, board); + open(board); + const QJsonObject clock = at(m_hw, QStringLiteral("derived.clock")); + + // -- Board: board.md's first table and its pins ----------------------------------- + BoardView boardView; + boardView.setModel(m_session->status(), m_session->describe(), m_session->clocks(), + m_session->memory(), m_session->pins()); + QHash fact; // board.md's first table: | Field | Value | + for (const QString &line : m_boardMd.split(QLatin1Char('\n'))) + if (line.startsWith(QStringLiteral("| ")) && line.count(QLatin1Char('|')) == 3) { + const QStringList cells = line.split(QLatin1Char('|')); + fact.insert(cells.at(1).trimmed(), cells.at(2).trimmed().remove(QLatin1Char('`'))); + } + const QString soc = fact.value(QStringLiteral("SoC")); // "STM32F446RE (lqfp64)" + QCOMPARE(boardView.value(QStringLiteral("Chip"), QStringLiteral("Part")), + soc.section(QLatin1Char(' '), 0, 0)); + QCOMPARE(boardView.value(QStringLiteral("Chip"), QStringLiteral("Package")), + soc.section(QLatin1Char('('), 1).chopped(1).toUpper()); + QVERIFY( + fact.value(QStringLiteral("CPU clock")) + .startsWith(boardView.value(QStringLiteral("Chip"), QStringLiteral("CPU clock")))); + QCOMPARE(boardView.value(QStringLiteral("Board"), QStringLiteral("Console")), + fact.value(QStringLiteral("Console"))); + for (const QStringList &pin : table(m_boardMd, QStringLiteral("## Pins"))) { + // | PA2 | pins.usart2.tx | af7 (usart2_tx) |, | PA5 | leds.user | output | + QCOMPARE(boardView.value(QStringLiteral("Pins in use"), pin.at(0)), + pin.at(2) + QStringLiteral(" · ") + pin.at(1)); + } + + // -- Clock tree: build_report.md's clock line, bus table and notes ---------------- + ClockTreeView clocks; + clocks.setClocks(m_session->clocks()); + QCOMPARE(clocks.node(QStringLiteral("sys")).value, + formatHz(clock.value(QStringLiteral("cpu_hz")).toDouble())); + QCOMPARE(clocks.node(QStringLiteral("source")).value, + formatHz(clock.value(QStringLiteral("source_hz")).toDouble())); + // "hse 8 MHz / M 8 = 1 MHz VCO input, x N 360 = 360 MHz, / P 2 = 180 MHz, Q 7 (51.4286 + // MHz)" + static const QRegularExpression line(QStringLiteral( + R"((\w+) (\S+ \w?Hz) / M (\d+) = (\S+ \w?Hz) VCO input, x N (\d+) = (\S+ \w?Hz), / P (\d+) = (\S+ \w?Hz)(?:, Q (\d+) \((\S+ \w?Hz)\))?)")); + const QRegularExpressionMatch m = line.match(m_report); + QVERIFY2(m.hasMatch(), "build_report.md has no clock line"); + QCOMPARE(clocks.node(QStringLiteral("source")).detail.section(QLatin1Char(' '), 0, 0), + m.captured(1)); + QCOMPARE(clocks.node(QStringLiteral("source")).value, m.captured(2)); + QCOMPARE(clocks.node(QStringLiteral("pll_in")).value, m.captured(4)); + QCOMPARE(clocks.node(QStringLiteral("vco")).value, m.captured(6)); + QCOMPARE(clocks.node(QStringLiteral("sys")).value, m.captured(8)); + QHash label; + for (const ClockTreeView::Edge &e : clocks.edges()) + label.insert(e.to, e.label); + QCOMPARE(label.value(QStringLiteral("pll_in")), QStringLiteral("÷ ") + m.captured(3)); + QCOMPARE(label.value(QStringLiteral("vco")), QStringLiteral("× ") + m.captured(5)); + // P, or the RP2350's two post-dividers whose product is P. + static const QRegularExpression divs(QStringLiteral(R"(\d+)")); + int p = 1; + for (const QRegularExpressionMatch &d : + divs.globalMatch(label.value(QStringLiteral("sys")))) + p *= d.captured(0).toInt(); + QCOMPARE(p, m.captured(7).toInt()); + if (!m.captured(9).isEmpty()) { + QCOMPARE(label.value(QStringLiteral("pll_q")), QStringLiteral("÷ ") + m.captured(9)); + QCOMPARE(clocks.node(QStringLiteral("pll_q")).value, m.captured(10)); + } + const QList buses = table(m_report, QStringLiteral("## Clock tree")); + QVERIFY(!buses.isEmpty()); + for (const QStringList &bus : buses) { + const ClockTreeView::Node n = clocks.node(QStringLiteral("bus:") + bus.at(0)); + QCOMPARE(n.value, bus.at(1)); + QCOMPARE(n.detail, QStringLiteral("limit ") + bus.at(2)); + } + for (const QString ¬e : + {QStringLiteral("Flash wait states"), QStringLiteral("Regulator")}) { + const int i = int(m_report.indexOf(note + QStringLiteral(":"))); + if (i < 0) + continue; + const QString wanted = m_report.mid(i, m_report.indexOf(QLatin1Char('\n'), i) - i); + QVERIFY2(clocks.notes().contains(wanted), qPrintable(wanted)); + } + + // -- Memory: board.md's memory map and partitions, build_report.md's image layout -- + MemoryView memory; + memory.setMemory(m_session->memory()); + const QJsonArray regions = + at(m_hw, QStringLiteral("soc.memory")).value(QStringLiteral("regions")).toArray(); + const QList map = table(m_boardMd, QStringLiteral("## Memory map")); + const QList shown = memory.rows(MemoryView::Group::Regions); + QCOMPARE(shown.size(), map.size()); + QCOMPARE(shown.size(), regions.size()); + for (int i = 0; i < map.size(); ++i) { + QCOMPARE(shown.at(i).at(0), map.at(i).at(0)); + QCOMPARE(shown.at(i).at(1), map.at(i).at(1)); + QCOMPARE(bytes(map.at(i).at(2)), + regions.at(i).toObject().value(QStringLiteral("size")).toDouble()); + QCOMPARE(shown.at(i).at(2), formatBytes(bytes(map.at(i).at(2)))); + QCOMPARE(shown.at(i).at(3), map.at(i).at(3)); + } + const QList parts = table(m_boardMd, QStringLiteral("## Flash partitions")); + const QList shownParts = memory.rows(MemoryView::Group::Partitions); + QCOMPARE(shownParts.size(), parts.size()); + for (int i = 0; i < parts.size(); ++i) { + QCOMPARE(shownParts.at(i).at(0).section(QLatin1Char(' '), 0, 0), parts.at(i).at(0)); + QCOMPARE(shownParts.at(i).at(1), parts.at(i).at(1)); + QCOMPARE(shownParts.at(i).at(2), formatBytes(bytes(parts.at(i).at(2)))); + QCOMPARE( + QString(shownParts.at(i).at(3)).replace(QStringLiteral("—"), QStringLiteral("-")), + parts.at(i).at(3)); + } + const QList image = table(m_report, QStringLiteral("## Image layout")); + const QList shownImage = memory.rows(MemoryView::Group::Image); + QCOMPARE(shownImage.size(), image.size()); + for (int i = 0; i < image.size(); ++i) { + QCOMPARE(shownImage.at(i).at(0), image.at(i).at(0)); + QCOMPARE(shownImage.at(i).at(1), image.at(i).at(1)); + QCOMPARE(shownImage.at(i).at(2), formatBytes(bytes(image.at(i).at(2)))); + } + + // -- Devices: board.md's devices, in initialization order --------------------------- + DevicesView devices; + devices.setDevices(m_session->describe().value(QStringLiteral("devices")).toArray()); + const QList listed = table(m_boardMd, QStringLiteral("## Devices")); + const QList rows = devices.rows(); + QCOMPARE(rows.size(), listed.size()); + for (int i = 0; i < listed.size(); ++i) { + // board.md: Device | Compatible | Class | Level | Depends on + QCOMPARE(rows.at(i).at(0), listed.at(i).at(0)); + QCOMPARE(rows.at(i).at(1), listed.at(i).at(2)); + QCOMPARE(rows.at(i).at(2), listed.at(i).at(1)); + QCOMPARE(rows.at(i).at(3), listed.at(i).at(3)); + QCOMPARE(QString(rows.at(i).at(4)).replace(QStringLiteral("—"), QStringLiteral("-")), + listed.at(i).at(4)); + } + } +}; + +QTEST_MAIN(TestGolden) +#include "tst_golden.moc" diff --git a/app/tests/tst_session.cpp b/app/tests/tst_session.cpp index 5197773..610c894 100644 --- a/app/tests/tst_session.cpp +++ b/app/tests/tst_session.cpp @@ -168,7 +168,7 @@ class TestSession : public QObject QCOMPARE(view.value(QStringLiteral("Clocks"), QStringLiteral("CPU")), QStringLiteral("48 MHz")); QCOMPARE(view.value(QStringLiteral("Pins in use"), QStringLiteral("PA0")), - QStringLiteral("uart0_tx · pins.uart0.tx")); + QStringLiteral("af1 (uart0_tx) · pins.uart0.tx")); core.stop(); } diff --git a/docs/development.md b/docs/development.md index b0953b5..e73e70f 100644 --- a/docs/development.md +++ b/docs/development.md @@ -24,8 +24,10 @@ core/.venv/bin/pytest core # the core's tests, including the protocol schemas core/.venv/bin/ruff check . && core/.venv/bin/ruff format --check . ``` -The core's acceptance tests run against a real EmbLinkRTOS checkout: set `EMBLINK_STUDIO_TEST_RTOS` to it, as -CI does with the RTOS at a pinned commit; without it they are skipped. +The core's acceptance tests and the application's golden test (`tst_golden`: every value the Board, Clock +tree, Memory and Devices views show equals the board's `hw.json`, `board.md` and `build_report.md`) run against +a real EmbLinkRTOS checkout: set `EMBLINK_STUDIO_TEST_RTOS` to it, as CI does with the RTOS at a pinned commit; +without it they are skipped. `EMBLINK_STUDIO_TEST_RTOS=~/EmbLinkRTOS ctest --preset dev` runs it. ```sh EMBLINK_STUDIO_TEST_RTOS=~/EmbLinkRTOS core/.venv/bin/pytest core @@ -45,7 +47,8 @@ Open a board with File › Open Board (⌘O): a board directory of an EmbLinkRTO `~/EmbLinkRTOS/boards/st/nucleo_f446re`. Validating and generating run the checkout's generator, so the application asks once to trust the checkout. -Options for a run: `--open ` opens that board, `--language en|fr|zh_CN` uses that language without saving it, `--stage +Options for a run: `--open ` opens that board, `--view clocks|memory|devices|board` brings that view to +the front, `--language en|fr|zh_CN` uses that language without saving it, `--stage configure|code|debug|verify` opens on that stage, and `--screenshot ` saves a picture of the window and quits. diff --git a/docs/specification.md b/docs/specification.md index a0efa8f..81e9fb9 100644 --- a/docs/specification.md +++ b/docs/specification.md @@ -277,7 +277,7 @@ Ten stages, each ending in something usable and demonstrated. S0 is done: CI bui | --- | --- | --- | --- | --- | | **S0 Setup** | The EmbLink Studio repository, its licence files and contributor agreement, CI on Windows, Linux and macOS, a Qt application that starts and talks to a stub core | CI builds and tests on all three systems; `initialize` and `shutdown` succeed; the notices list is generated | Nothing | Done | | **S1 Core foundation** | `emblink-studio-core serve`, `project.open` and `validate`, `board.*` from `hw.json`, `generate.run` | Opening the RTOS's `nucleo_f446re` and `pico2_w` boards shows their model; validation reports the generator's errors with their locations | JSON diagnostics from `emb-hwgen`; a versioned `hw.json` | Done (2026-11-12) | -| **S2 Read-only views** | Board, pin map, clock tree, devices, memory, RTOS, problems | For both boards, a golden test finds every value in the views equal to `hw.json` and to the generator's `board.md` and `build_report.md` | Existing outputs | Not started | +| **S2 Read-only views** | Board, pin map, clock tree, devices, memory, RTOS, problems | For both boards, a golden test finds every value in the views equal to `hw.json` and to the generator's `board.md` and `build_report.md` | Existing outputs | In progress | | **S3 Editing** | `config.preview`, `apply`, `undo`; pins, devices and threads editable; live diagnostics | A pin conflict is refused with the generator's message; an edit's `git diff` touches only the lines it must; generation stays clean | `system.yaml` (E3) for threads | Not started | | **S4 Build, flash, console** | Toolchain discovery, CMake build, flash by OpenOCD and picotool, serial console | A project is created, built, flashed and seen running on the NUCLEO-F446RE and the Pico 2 W; in CI, on EmbSIM's `nucleo_f446re` | The CMake package (A91) | Not started | | **S5 Debugging** | DAP sessions; the RTOS-aware views; crash decoding | Breakpoints and stepping on both boards; threads and their states shown; a crash record decoded | The debug descriptor (A107), crashdec | Not started |